через дефайн убран поток приложения мк

This commit is contained in:
2025-03-31 16:29:01 +03:00
parent 87c9cd01ff
commit f856b33e1c
5 changed files with 60 additions and 26 deletions

View File

@@ -21,6 +21,7 @@ SIM__MCUHandleTypeDef hmcu; ///< Хендл для управления
//-------------------------------------------------------------//
//-----------------CONTROLLER SIMULATE FUNCTIONS---------------//
/* THREAD FOR MCU APP */
#ifdef RUN_APP_MAIN_FUNC_THREAD
/**
* @brief Главная функция приложения МК.
* @details Функция с которой начинается выполнение кода МК. Выход из данной функции происходит только в конце симуляции @ref mdlTerminate
@@ -35,6 +36,7 @@ unsigned __stdcall MCU_App_Thread(void) {
return 0; // end thread
// note: this return will reached only at the end of simulation, when all whiles will be skipped due to @ref sim_while
}
#endif //RUN_APP_MAIN_FUNC_THREAD
/* SIMULATE MCU FOR ONE SIMULATION STEP */
/**
* @brief Симуляция МК на один такт симуляции.
@@ -56,11 +58,15 @@ void MCU_Step_Simulation(SimStruct* S, time_T time)
MCU_Periph_Simulation(); // simulate peripheral
extern void Periph_reInit(void);
Periph_reInit();
#ifdef RUN_APP_MAIN_FUNC_THREAD
ResumeThread(hmcu.hMCUThread);
for (int i = DEKSTOP_CYCLES_FOR_MCU_APP; i > 0; i--)
{
}
SuspendThread(hmcu.hMCUThread);
#endif //RUN_APP_MAIN_FUNC_THREAD
MCU_writeOutputs(S); // запись портов (по факту запись в буфер. запись в порты в mdlOutputs)
}
@@ -142,13 +148,15 @@ void SIM_writeOutputs(SimStruct* S)
*/
void SIM_Initialize_Simulation(void)
{
#ifdef RUN_APP_MAIN_FUNC_THREAD
// инициализация потока, который будет выполнять код МК
hmcu.hMCUThread = (HANDLE)CreateThread(NULL, 0, MCU_App_Thread, 0, CREATE_SUSPENDED, &hmcu.idMCUThread);
#endif //RUN_APP_MAIN_FUNC_THREAD
/* user initialization */
Initialize_Periph_Sim();
extern int main_init(void);
main_init();
/* wrapper initialization */
hmcu.SystemClock_step = MCU_CORE_CLOCK * hmcu.SIM_Sample_Time; // set system clock step
}

View File

@@ -21,8 +21,8 @@
- для S-Function "simstruc.h"
- для потоков <process.h>
**************************************************************************/
#ifndef _CONTROLLER_H_
#define _CONTROLLER_H_
#ifndef _WRAPPER_CONF_H_
#define _WRAPPER_CONF_H_
// Includes
#include "stm32f4xx_matlab_conf.h" // For stm simulate functions
@@ -44,12 +44,13 @@
*/
// Parametrs of MCU simulator
#define CREATE_SUSPENDED 0x00000004 ///< define from WinBase.h. We dont wanna include "Windows.h" or smth like this, because of HAL there are a lot of redefine errors.
//#define RUN_APP_MAIN_FUNC_THREAD ///< Enable using thread for MCU main() func
#define DEKSTOP_CYCLES_FOR_MCU_APP 0xFF ///< number of for() cycles after which MCU thread would be suspended
#define MCU_CORE_CLOCK 150000000 ///< MCU clock rate for simulation
#define PORT_WIDTH 16 ///< width of one port
#define PORT_NUMB 3 ///< amount of ports
// Parameters of S_Function
#define NPARAMS 1 ///< number of input parametrs (only Ts)
#define IN_PORT_WIDTH (9) ///< width of input ports
@@ -69,6 +70,14 @@
* @{
*/
// Fixed parameters(?) of S_Function
#define NPARAMS 1 ///< number of input parametrs (only Ts)
#define DISC_STATES_WIDTH OUT_PORT_WIDTH*OUT_PORT_NUMB ///< width of discrete states array (outbup buffer)
/**
* @brief Define for creating thread in suspended state.
* @details Define from WinBase.h. We dont wanna include "Windows.h" or smth like this, because of HAL there are a lot of redefine errors.
*/
#define CREATE_SUSPENDED 0x00000004
typedef void* HANDLE; ///< MCU handle typedef
/**
@@ -92,6 +101,7 @@ extern SIM__MCUHandleTypeDef hmcu; // extern для видимос
//-------------------------------------------------------------//
//------------------ SIMULINK WHILE DEFINES -----------------//
#ifdef RUN_APP_MAIN_FUNC_THREAD
/* DEFINE TO WHILE WITH SIMULINK WHILE */
/**
* @brief Redefine C while statement with sim_while() macro.
@@ -99,7 +109,7 @@ extern SIM__MCUHandleTypeDef hmcu; // extern для видимос
* @details Это while который будет использоваться в симулинке @ref sim_while для подробностей.
*/
#define while(_expression_) sim_while(_expression_)
#endif
/* SIMULINK WHILE */
/**
* @brief While statement for emulate MCU code in Simulink.
@@ -152,7 +162,7 @@ void SIM_writeOutput(SimStruct* S);
/** MCU_WRAPPER
* @}
*/
#endif // _CONTROLLER_H_
#endif // _WRAPPER_CONF_H_
//-------------------------------------------------------------//