Files
slhal/fmc41/hal_uart_out_wrapper.c
T

186 lines
4.5 KiB
C
Raw Normal View History

2020-09-06 22:23:09 +08:00
/*
* Include Files
*
*/
#if defined(MATLAB_MEX_FILE)
#include "tmwtypes.h"
#include "simstruc_types.h"
#else
#include "rtwtypes.h"
#endif
/* %%%-SFUNWIZ_wrapper_includes_Changes_BEGIN --- EDIT HERE TO _END */
#ifdef HAL_IMPL
#include "uart_fifos.h"
2020-09-27 05:59:45 +08:00
#include "param_pre.h"
#include "fatfs.h"
2020-09-06 22:23:09 +08:00
#endif
/* %%%-SFUNWIZ_wrapper_includes_Changes_END --- EDIT HERE TO _BEGIN */
#define y_width 1
/*
* Create external references here.
*
*/
/* %%%-SFUNWIZ_wrapper_externs_Changes_BEGIN --- EDIT HERE TO _END */
2020-09-27 05:59:45 +08:00
int is_fat_rec_init = 0;
FIL *rec_pf;
static int FAT_REC_write(uint8_t *buff, const uint16_t len)
{
int rslt;
FRESULT res;
if (is_fat_rec_init == 1)
{
UINT bw;
res = f_write(rec_pf, buff, len, &bw);
f_sync(rec_pf);
if (res != FR_OK)
{
rslt = -1;
}
else
{
rslt = 0;
}
}
2020-09-29 11:18:50 +08:00
else if (is_fat_rec_init == 0 && ap_U.sens.gps_fixtype >= ENUM_GPS_FIXTYPE_FIX_2D)
2020-09-27 05:59:45 +08:00
{
res = f_mount(&SDFatFS, SDPath, 1);
if (res != FR_OK)
{
is_fat_rec_init = -1;
rslt = -1;
}
rec_pf = &SDFile;
long path_len;
char path[80];
strncpy(path, SDPath, 3);
2020-09-29 11:18:50 +08:00
sprintf(&path[3], "R%d.dat", (ap_U.sens.TOW / 1000));
2020-09-27 05:59:45 +08:00
res = f_open(rec_pf, path, FA_OPEN_ALWAYS | FA_WRITE);
if (res == FR_OK)
{
is_fat_rec_init = 1;
rslt = 0;
}
else
{
is_fat_rec_init = -1;
rslt = -1;
}
}
return rslt;
}
2020-09-06 22:23:09 +08:00
/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */
/*
* Start function
*
*/
void hal_uart_out_Start_wrapper(const uint8_T *uart_id, const int_T p_width0)
{
/* %%%-SFUNWIZ_wrapper_Start_Changes_BEGIN --- EDIT HERE TO _END */
#ifdef HAL_IMPL
//initialize_uart_device(uart_id[0]);
#endif
/* %%%-SFUNWIZ_wrapper_Start_Changes_END --- EDIT HERE TO _BEGIN */
}
/*
* Output function
*
*/
void hal_uart_out_Outputs_wrapper(const uint8_T *buff,
const uint16_T *len,
const uint8_T *sep,
int32_T *ErrorCode,
const uint8_T *uart_id, const int_T p_width0,
const int_T u_width)
{
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */
#ifdef HAL_IMPL
/* ***********************************************
* push all data to this uart output queue;
*
* inputs:
* buff - data array to be sent
* len[0] - available length in the data array
* sep[0] - it means the data array updated when sep[0] changed,
* uart_id[0] - uart FIFO device which is required to send data
*
* output:
* ErrorCode[0] - return zero for success, others for failail.
*
* constant:
* u_width - the maximum size of buff, do not read buff out of range.
*************************************************/
ErrorCode[0] = -1;
static uint8_T seq_last[8];
switch (uart_id[0])
{
case 0:
if (sep[0] != seq_last[uart_id[0]] && UART_TX_FIFO_write(&uart1_RS422_1_tx, (uint8_t *)buff, len[0]))
{
seq_last[uart_id[0]] = sep[0];
ErrorCode[0] = 0;
}
break;
case 1:
if (sep[0] != seq_last[uart_id[0]] && UART_TX_FIFO_write(&uart2_RS232_1_tx, (uint8_t *)buff, len[0]))
{
seq_last[uart_id[0]] = sep[0];
ErrorCode[0] = 0;
}
break;
case 2:
if (sep[0] != seq_last[uart_id[0]] && UART_TX_FIFO_write(&uart3_RS422_2_tx, (uint8_t *)buff, len[0]))
{
seq_last[uart_id[0]] = sep[0];
ErrorCode[0] = 0;
}
break;
case 3:
if (sep[0] != seq_last[uart_id[0]] && UART_TX_FIFO_write(&uart4_tx, (uint8_t *)buff, len[0]))
{
seq_last[uart_id[0]] = sep[0];
ErrorCode[0] = 0;
}
break;
2020-09-27 05:59:45 +08:00
case 4:
if (sep[0] != seq_last[uart_id[0]] && FAT_REC_write((uint8_t *)buff, len[0]))
{
seq_last[uart_id[0]] = sep[0];
ErrorCode[0] = 0;
}
break;
2020-09-06 22:23:09 +08:00
case 5:
if (sep[0] != seq_last[uart_id[0]] && UART_TX_FIFO_write(&uart6_RS422_3_tx, (uint8_t *)buff, len[0]))
{
seq_last[uart_id[0]] = sep[0];
ErrorCode[0] = 0;
}
break;
case 6:
if (sep[0] != seq_last[uart_id[0]] && UART_TX_FIFO_write(&uart7_tx, (uint8_t *)buff, len[0]))
{
seq_last[uart_id[0]] = sep[0];
ErrorCode[0] = 0;
}
break;
2020-09-29 11:18:50 +08:00
case 255:
if (sep[0] != seq_last[4] && FAT_REC_write((uint8_t *)buff, len[0]))
{
seq_last[4] = sep[0];
ErrorCode[0] = 0;
}
break;
2020-09-06 22:23:09 +08:00
}
#else
/* dummy function for generate mex file for sim*/
ErrorCode[0] = 0;
#endif
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */
}