/************************************************************************** Главный заголовочный файл для матлаба. Включает дейфайны для S-Function, объявляет базовые функции для симуляции МК и подключает базовые библиотеки: для симуляции "stm32fxxx_matlab_conf.h" для S-Function "simstruc.h" для потоков **************************************************************************/ #ifndef _CONTROLLER_H_ #define _CONTROLLER_H_ // Includes #include "stm32f4xx_matlab_conf.h" // For stm simulate functions #include "simstruc.h" // For S-Function variables #include // For threads /** * @addtogroup MCU_WRAPPER * @brief Stuff for running MCU app in MATLAB */ /** * @addtogroup WRAPPER_CONF * @ingroup MCU_WRAPPER * @brief Configurations for wrapper to simulating MCU * @details Здесь дефайнами задается параметры оболочки, которая управляет кодом МК * @{ */ // 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 DEKSTOP_CYCLES_FOR_MCU_APP 0xFFFF ///< number of for() cycles after which MCU thread would be suspended #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 (8) ///< width of input ports #define IN_PORT_NUMB 1 ///< number of input ports #define OUT_PORT_WIDTH PORT_WIDTH ///< width of output ports #define OUT_PORT_NUMB PORT_NUMB ///< number of output ports #define DISC_STATES_WIDTH PORT_WIDTH*PORT_NUMB ///< width of discrete states array /** WRAPPER_CONF * @} */ /** * @ingroup MCU_WRAPPER * @{ */ typedef void* HANDLE; ///< MCU handle typedef /** * @brief MCU handle Structure definition. * @note Prefixes: h - handle, s - settings, f - flag */ typedef struct { // MCU Thread HANDLE hMCUThread; ///< Хендл для потока МК uint32_t idMCUThread; ///< id потока МК (unused) // Flags unsigned fMCU_Stop : 1; ///< флаг для выхода из потока программы МК double SIM_Sample_Time; ///< sample time of simulation }SIM__MCUHandleTypeDef; extern SIM__MCUHandleTypeDef hmcu; ///< extern для видимости переменной во всех файлах //-------------------------------------------------------------// //------------------ SIMULINK WHILE DEFINES -----------------// /* DEFINE TO WHILE WITH SIMULINK WHILE */ /** * @brief Redefine C while statement with sim_while() macro. * @param _expression_ - expression for while. * @details Это while который будет использоваться в симулинке @ref sim_while для подробностей. */ #define while(_expression_) sim_while(_expression_) /* SIMULINK WHILE */ /** * @brief While statement for emulate MCU code in Simulink. * @param _expression_ - expression for while. * @details Данный while необходим, чтобы в конце симуляции, завершить поток МК: * При выставлении флага окончания симуляции, все while будут пропускаться * и поток сможет дойти до конца функции main и завершить себя. */ #define sim_while(_expression_) while((_expression_)&&(hmcu.MCU_Stop == 0)) /* DEFAULT WHILE */ /** * @brief Default/Native C while statement. * @param _expression_ - expression for while. * @details Данный while - аналог обычного while, без дополнительного функционала. */ #define native_while(_expression_) for(; (_expression_); ) /***************************************************************/ //------------------ SIMULINK WHILE DEFINES -----------------// //-------------------------------------------------------------// //-------------------------------------------------------------// //---------------- SIMULATE FUNCTIONS PROTOTYPES -------------// /* step simulation */ void MCU_Step_Simulation(SimStruct *S, time_T time); /* MCU peripheral simulation */ void MCU_Periph_Simulation(void); /* initialize MCU simulation */ void SIM_Initialize_Simulation(void); /* deinitialize MCU simulation */ void SIM_deInitialize_Simulation(void); /* read inputs S-function */ void MCU_readInputs(real_T* in); /* write outputs S-function (disc states) */ void MCU_writeOutputs(real_T* disc); /* write outputs of block of S-Function*/ void SIM_writeOutput(SimStruct* S); //---------------- SIMULATE FUNCTIONS PROTOTYPES -------------// //-------------------------------------------------------------// /** MCU_WRAPPER * @} */ #endif // _CONTROLLER_H_