matlab_stm_emulate/App_Wrapper/app_io.c

65 lines
1.5 KiB
C

#include "stm32f1xx_matlab_gpio.h"
#include "upp.h"
void WriteFromSFunc(real_T* disc)
{
for (int i = 0; i < PORT_WIDTH; i++)
{
if (GPIOA->ODR & (1 << i))
{
disc[i] = 1;
}
if (GPIOB->ODR & (1 << i))
{
disc[PORT_WIDTH + i] = 1;
}
}
disc[2 * PORT_WIDTH + 0] = phase_A.ctrl.f.EnableTiristor;
disc[2 * PORT_WIDTH + 1] = phase_A.ctrl.f.TiristorIsEnable;
disc[2 * PORT_WIDTH + 2] = uwTick - phase_A.ctrl.enable_start_tick;
disc[2 * PORT_WIDTH + 3] = phase_A.ctrl.angle.start_delay_us;
disc[2 * PORT_WIDTH + 4] = (uint16_t)((uint16_t)TIMER->CNT - phase_A.ctrl.angle.start_delay_us);
}
void ReadToSFunc(real_T* in)
{
static real_T in_prev[3];
if ((in[0] > 0.5) && (in_prev[0] <= 0.5))
{
phase_A.zc_detector.f.EXTIZeroCrossDetected = 1;
}
else if ((in[0] < 0.5) && (in_prev[0] >= 0.5))
{
phase_A.zc_detector.f.EXTIZeroCrossDetected = 1;
}
if ((in[1] > 0.5) && (in_prev[1] <= 0.5))
{
phase_B.zc_detector.f.EXTIZeroCrossDetected = 1;
}
else if ((in[1] < 0.5) && (in_prev[1] >= 0.5))
{
phase_B.zc_detector.f.EXTIZeroCrossDetected = 1;
}
if ((in[2] > 0.5) && (in_prev[2] <= 0.5))
{
phase_C.zc_detector.f.EXTIZeroCrossDetected = 1;
}
else if ((in[2] < 0.5) && (in_prev[2] >= 0.5))
{
phase_C.zc_detector.f.EXTIZeroCrossDetected = 1;
}
in_prev[0] = in[0];
in_prev[1] = in[1];
in_prev[2] = in[2];
}