/* * 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" #include "spi_devs.h" #endif /* %%%-SFUNWIZ_wrapper_includes_Changes_END --- EDIT HERE TO _BEGIN */ #define u_width 1 #define y_width 1 /* * Create external references here. * */ /* %%%-SFUNWIZ_wrapper_externs_Changes_BEGIN --- EDIT HERE TO _END */ void UART_reconf(UART_HandleTypeDef *huart, uint32_t baud, uint8_t wordlen, uint8_t stopbits, uint8_t parity) { huart->Init.BaudRate = baud; switch (wordlen) { case 7: huart->Init.WordLength = UART_WORDLENGTH_7B; break; case 9: huart->Init.WordLength = UART_WORDLENGTH_9B; break; default: huart->Init.WordLength = UART_WORDLENGTH_8B; break; } switch (stopbits) { case 2: huart->Init.StopBits = UART_STOPBITS_2; break; default: huart->Init.StopBits = UART_STOPBITS_1; break; } switch (parity) { case 1: huart->Init.Parity = UART_PARITY_ODD; break; case 2: huart->Init.Parity = UART_PARITY_EVEN; break; default: huart->Init.Parity = UART_PARITY_NONE; break; } if (HAL_UART_Init(huart) != HAL_OK) { Error_Handler(); } } /* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */ /* * Start function * */ void hal_uart_init_Start_wrapper(const uint8_T *uart_id, const int_T p_width0) { /* %%%-SFUNWIZ_wrapper_Start_Changes_BEGIN --- EDIT HERE TO _END */ /* %%%-SFUNWIZ_wrapper_Start_Changes_END --- EDIT HERE TO _BEGIN */ } /* * Output function * */ void hal_uart_init_Outputs_wrapper(const uint32_T *baudrate, const uint8_T *wordlen, const uint8_T *stopbits, const uint8_T *parity, const uint16_T *buff_rx, const uint16_T *buff_tx, const uint32_T *opts, int32_T *ErrCode, const uint8_T *uart_id, const int_T p_width0) { /* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */ #ifdef HAL_IMPL /******************************* * config code for No.uart_id uart FIFO device; * which is called as initialization code for the first time, * then as func-call for update uart config, such as baud/stopbits/parity/... * * inputs: * baudrate[0] - config uart baudrate (115200 for default) * wordlen[0] - word length (7/8/9, 8 for 8bits in default) * stopbits[0] - stop bits (1/2, 1 stop bits for default) * parity[0] - parity check (0 for None, 1 for Odd and 2 for Even) * buff_rx[0] - buffer length for RX, set zero for disable RX * buff_tx[0] - buffer length for TX, set zero for disable TX * opts[0] - option flags for advance setting * * output: * ErrCode[0] - return zero for success, others for failures. * * parameter: * uart_id - uart device id (start from zero) *********************************/ ErrCode[0] = -1; switch (uart_id[0]) { case 0: UART_reconf(uart1_RS422_1_rx.huart,baudrate[0],wordlen[0], stopbits[0], parity[0]); break; case 1: UART_reconf(uart2_RS422_2_rx.huart,baudrate[0],wordlen[0], stopbits[0], parity[0]); break; case 2: UART_reconf(uart3_IMU_NAV_rx.huart,baudrate[0],wordlen[0], stopbits[0], parity[0]); break; case 3: UART_reconf(uart4_TTL_1_rx.huart,baudrate[0],wordlen[0], stopbits[0], parity[0]); break; case 4: UART_reconf(uart5_STORE_tx.huart,baudrate[0],wordlen[0], stopbits[0], parity[0]); break; case 5: UART_reconf(uart6_RS485_1_rx.huart,baudrate[0],wordlen[0], stopbits[0], parity[0]); break; case 6: UART_reconf(uart7_RS232_1_rx.huart,baudrate[0],wordlen[0], stopbits[0], parity[0]); break; case 7: UART_reconf(uart8_RS232_2_rx.huart,baudrate[0],wordlen[0], stopbits[0], parity[0]); break; case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: { uint8_t buff[6]; buff[0] = uart_id[0]-7; buff[1] = ((baudrate[0])&0xFF); buff[2] = ((baudrate[0] >> 8)&0xFF); buff[3] = wordlen[0]; buff[4] = stopbits[0]; buff[5] = parity[0]; SPI_Bridge_pack(&bdg, 0, (uint8_t *)buff, sizeof(buff), 1); } break; } #else /* dummy function for generate mex file for sim*/ ErrCode[0] = 0; #endif /* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */ }