Files
slhal/B3_AP/hal_uart_in_wrapper.c
T
2020-07-28 11:39:26 +08:00

135 lines
3.3 KiB
C

/*
* 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"
extern uint8_t queue_in[8][256];
extern uint8_t queue_hdr[8];
extern uint8_t queue_tal[8];
#endif
/* %%%-SFUNWIZ_wrapper_includes_Changes_END --- EDIT HERE TO _BEGIN */
/*
* Create external references here.
*
*/
/* %%%-SFUNWIZ_wrapper_externs_Changes_BEGIN --- EDIT HERE TO _END */
/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */
/*
* Start function
*
*/
void hal_uart_in_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_in_Outputs_wrapper(uint8_T *Data,
uint16_T *Data_len,
int32_T *ErrorCode,
const uint8_T *uart_id, const int_T p_width0,
const int_T y_width)
{
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */
#ifdef HAL_IMPL
/* **********************************************************
* collect all data from this uart and push to Data buffer;
*
* parameter:
* uart_id - uart FIFO device to read
*
* outputs:
* Data - read all FIFO data and write to Data array
* Data_len[0] - the number of written data
* ErrorCode[0] - return zero for success, others for failail.
*
* constant:
* y_width - maximum length to write to Data array
************************************************************/
Data_len[0] = 0u;
ErrorCode[0] = -1;
switch (uart_id[0])
{
case 0:
Data_len[0] = UART_RX_FIFO_read(&uart1_RS422_1_rx, Data, y_width);
ErrorCode[0] = 0;
break;
case 1:
Data_len[0] = UART_RX_FIFO_read(&uart2_RS422_2_rx, Data, y_width);
ErrorCode[0] = 0;
break;
case 2:
Data_len[0] = UART_RX_FIFO_read(&uart3_IMU_NAV_rx, Data, y_width);
ErrorCode[0] = 0;
break;
case 3:
Data_len[0] = UART_RX_FIFO_read(&uart4_TTL_1_rx, Data, y_width);
ErrorCode[0] = 0;
break;
case 4:
Data_len[0] = UART_RX_FIFO_read(&uart5_STORE_rx, Data, y_width);
ErrorCode[0] = 0;
break;
case 5:
Data_len[0] = UART_RX_FIFO_read(&uart6_RS485_1_rx, Data, y_width);
ErrorCode[0] = 0;
break;
case 6:
Data_len[0] = UART_RX_FIFO_read(&uart7_RS232_1_rx, Data, y_width);
ErrorCode[0] = 0;
break;
case 7:
Data_len[0] = UART_RX_FIFO_read(&uart8_RS232_2_rx, Data, y_width);
ErrorCode[0] = 0;
break;
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
{
int id = uart_id[0]-8;
Data_len[0] = 0;
while (queue_tal[id] != queue_hdr[id])
{
Data[Data_len[0]++] = queue_in[id][queue_tal[id]++];
}
}
ErrorCode[0] = 0;
break;
}
#else
/* dummy function for generate mex file for sim*/
Data_len[0] = 0u;
ErrorCode[0] = 0;
#endif
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */
}