STM MATLAB Simulator
Loading...
Searching...
No Matches
mcu_wrapper_conf.h
Go to the documentation of this file.
1/**
2**************************************************************************
3* @dir ../MCU_Wrapper
4* @brief <b> Папка с исходным кодом оболочки МК. </b>
5* @details
6В этой папке содержаться оболочка(англ. wrapper) для запуска и контроля
7эмуляции микроконтроллеров в MATLAB (любого МК, не только STM).
8Оболочка представляет собой S-Function - блок в Simulink, который работает
9по скомпилированому коду. Компиляция происходит с помощью MSVC-компилятора.
10**************************************************************************/
11
12/**
13**************************************************************************
14* @file mcu_wrapper_conf.h
15* @brief Заголовочный файл для оболочки МК.
16**************************************************************************
17@details
18Главный заголовочный файл для матлаба. Включает дейфайны для S-Function,
19объявляет базовые функции для симуляции МК и подключает базовые библиотеки:
20- для симуляции "stm32fxxx_matlab_conf.h"
21- для S-Function "simstruc.h"
22- для потоков <process.h>
23**************************************************************************/
24#ifndef _CONTROLLER_H_
25#define _CONTROLLER_H_
26
27// Includes
28#include "stm32f4xx_matlab_conf.h" // For stm simulate functions
29#include "simstruc.h" // For S-Function variables
30#include <process.h> // For threads
31
32
33/**
34 * @defgroup MCU_WRAPPER MCU Wrapper
35 * @brief Всякое для оболочки МК
36 */
37
38/**
39 * @addtogroup WRAPPER_CONF Wrapper Configuration
40 * @ingroup MCU_WRAPPER
41 * @brief Параметры конфигурации для оболочки МК
42 * @details Здесь дефайнами задается параметры оболочки, которые определяют как она будет работать
43 * @{
44 */
45
46// Parametrs of MCU simulator
47#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.
48
49#define DEKSTOP_CYCLES_FOR_MCU_APP 0xFFFF ///< number of for() cycles after which MCU thread would be suspended
50#define PORT_WIDTH 16 ///< width of one port
51#define PORT_NUMB 3 ///< amount of ports
52
53// Parameters of S_Function
54#define NPARAMS 1 ///< number of input parametrs (only Ts)
55#define IN_PORT_WIDTH (8) ///< width of input ports
56#define IN_PORT_NUMB 1 ///< number of input ports
57#define OUT_PORT_WIDTH PORT_WIDTH ///< width of output ports
58#define OUT_PORT_NUMB PORT_NUMB ///< number of output ports
59#define DISC_STATES_WIDTH PORT_WIDTH*PORT_NUMB ///< width of discrete states array
60
61/** WRAPPER_CONF
62 * @}
63 */
64
65
66/**
67 * @addtogroup MCU_WRAPPER
68 * @{
69 */
70
71typedef void* HANDLE; ///< MCU handle typedef
72
73/**
74 * @brief MCU handle Structure definition.
75 * @note Prefixes: h - handle, s - settings, f - flag
76 */
77typedef struct {
78 // MCU Thread
79 HANDLE hMCUThread; ///< Хендл для потока МК
80 uint32_t idMCUThread; ///< id потока МК (unused)
81 // Flags
82 unsigned fMCU_Stop : 1; ///< флаг для выхода из потока программы МК
83 double SIM_Sample_Time; ///< sample time of simulation
84
86extern SIM__MCUHandleTypeDef hmcu; // extern для видимости переменной во всех файлах
87
88//-------------------------------------------------------------//
89//------------------ SIMULINK WHILE DEFINES -----------------//
90/* DEFINE TO WHILE WITH SIMULINK WHILE */
91/**
92 * @brief Redefine C while statement with sim_while() macro.
93 * @param _expression_ - expression for while.
94 * @details Это while который будет использоваться в симулинке @ref sim_while для подробностей.
95 */
96#define while(_expression_) sim_while(_expression_)
97
98/* SIMULINK WHILE */
99/**
100 * @brief While statement for emulate MCU code in Simulink.
101 * @param _expression_ - expression for while.
102 * @details Данный while необходим, чтобы в конце симуляции, завершить поток МК:
103 * При выставлении флага окончания симуляции, все while будут пропускаться
104 * и поток сможет дойти до конца функции main и завершить себя.
105 */
106#define sim_while(_expression_) while((_expression_)&&(hmcu.fMCU_Stop == 0))
107
108/* DEFAULT WHILE */
109/**
110 * @brief Default/Native C while statement.
111 * @param _expression_ - expression for while.
112 * @details Данный while - аналог обычного while, без дополнительного функционала.
113 */
114#define native_while(_expression_) for(; (_expression_); )
115 /***************************************************************/
116
117//------------------ SIMULINK WHILE DEFINES -----------------//
118//-------------------------------------------------------------//
119
120
121
122//-------------------------------------------------------------//
123//---------------- SIMULATE FUNCTIONS PROTOTYPES -------------//
124/* Step simulation */
125void MCU_Step_Simulation(SimStruct *S, time_T time);
126
127/* MCU peripheral simulation */
128void MCU_Periph_Simulation(void);
129
130/* Initialize MCU simulation */
131void SIM_Initialize_Simulation(void);
132
133/* Deinitialize MCU simulation */
135
136/* Read inputs S-function */
137void MCU_readInputs(SimStruct* S);
138
139/* Write pre-outputs S-function (out_buff states) */
140void MCU_writeOutputs(SimStruct* S);
141
142/* Write outputs of block of S-Function*/
143void SIM_writeOutput(SimStruct* S);
144//---------------- SIMULATE FUNCTIONS PROTOTYPES -------------//
145//-------------------------------------------------------------//
146
147/** MCU_WRAPPER
148 * @}
149 */
150#endif // _CONTROLLER_H_
151
152
153//-------------------------------------------------------------//
154//---------------------BAT FILE DESCRIBTION--------------------//
155/**
156 * @file run_mex.bat
157 * @brief Батник для компиляции оболочки МК.
158 * @details
159 * Вызывается в матлабе из mexing.m.
160 *
161 * Исходный код батника:
162 * @include F:\Work\Projects\MATLAB\matlab_stm_emulate\MCU_Wrapper\run_mex.bat
163 */
void MCU_readInputs(SimStruct *S)
Считывание входов S-Function в порты ввода-вывода.
Definition mcu_wrapper.c:88
void SIM_Initialize_Simulation(void)
Инициализация симуляции МК.
void SIM_deInitialize_Simulation(void)
Деинициализация симуляции МК.
SIM__MCUHandleTypeDef hmcu
Хендл для управления потоком программы МК
Definition mcu_wrapper.c:16
void * HANDLE
MCU handle typedef.
void MCU_Periph_Simulation(void)
Симуляция периферии МК
Definition mcu_wrapper.c:73
void SIM_writeOutput(SimStruct *S)
void MCU_Step_Simulation(SimStruct *S, time_T time)
Симуляция МК на один такт симуляции.
Definition mcu_wrapper.c:53
void MCU_writeOutputs(SimStruct *S)
Запись портов ввода-вывода в буфер выхода S-Function.
Заголовочный файл для конфигурации симулятора МК.
MCU handle Structure definition.
uint32_t idMCUThread
id потока МК (unused)
double SIM_Sample_Time
sample time of simulation
unsigned fMCU_Stop
флаг для выхода из потока программы МК
HANDLE hMCUThread
Хендл для потока МК