From d073c6be9c0cde0e8a22f618cbd7d738930b85a9 Mon Sep 17 00:00:00 2001 From: matt Date: Sun, 6 Sep 2020 22:23:09 +0800 Subject: [PATCH] support two boards --- B3_AP_lite/hal_ai_wrapper.c | 85 +++++++++++++++++++++ B3_AP_lite/hal_di_wrapper.c | 84 ++++++++++++++++++++ B3_AP_lite/hal_do_wrapper.c | 85 +++++++++++++++++++++ B3_AP_lite/hal_pwm_in_wrapper.c | 91 ++++++++++++++++++++++ B3_AP_lite/hal_pwm_out_wrapper.c | 81 ++++++++++++++++++++ B3_AP_lite/hal_uart_in_wrapper.c | 103 +++++++++++++++++++++++++ B3_AP_lite/hal_uart_out_wrapper.c | 122 ++++++++++++++++++++++++++++++ fmc41/hal_ai_wrapper.c | 85 +++++++++++++++++++++ fmc41/hal_di_wrapper.c | 84 ++++++++++++++++++++ fmc41/hal_do_wrapper.c | 85 +++++++++++++++++++++ fmc41/hal_uart_in_wrapper.c | 103 +++++++++++++++++++++++++ fmc41/hal_uart_out_wrapper.c | 122 ++++++++++++++++++++++++++++++ 12 files changed, 1130 insertions(+) create mode 100644 B3_AP_lite/hal_ai_wrapper.c create mode 100644 B3_AP_lite/hal_di_wrapper.c create mode 100644 B3_AP_lite/hal_do_wrapper.c create mode 100644 B3_AP_lite/hal_pwm_in_wrapper.c create mode 100644 B3_AP_lite/hal_pwm_out_wrapper.c create mode 100644 B3_AP_lite/hal_uart_in_wrapper.c create mode 100644 B3_AP_lite/hal_uart_out_wrapper.c create mode 100644 fmc41/hal_ai_wrapper.c create mode 100644 fmc41/hal_di_wrapper.c create mode 100644 fmc41/hal_do_wrapper.c create mode 100644 fmc41/hal_uart_in_wrapper.c create mode 100644 fmc41/hal_uart_out_wrapper.c diff --git a/B3_AP_lite/hal_ai_wrapper.c b/B3_AP_lite/hal_ai_wrapper.c new file mode 100644 index 0000000..c442421 --- /dev/null +++ b/B3_AP_lite/hal_ai_wrapper.c @@ -0,0 +1,85 @@ + +/* + * 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 "param_mgr.h" +#include "adc_devs.h" +#endif +/* %%%-SFUNWIZ_wrapper_includes_Changes_END --- EDIT HERE TO _BEGIN */ +#define u_width 1 + +/* + * Create external references here. + * + */ +/* %%%-SFUNWIZ_wrapper_externs_Changes_BEGIN --- EDIT HERE TO _END */ +int is_analog_input_init = 0; + +void analog_input_init() +{ + if (!is_analog_input_init) + { +#ifdef HAL_IMPL + //TODO + is_analog_input_init = 1; +#endif + } +} +/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */ + +/* + * Start function + * + */ +void hal_ai_Start_wrapper(void) +{ +/* %%%-SFUNWIZ_wrapper_Start_Changes_BEGIN --- EDIT HERE TO _END */ +analog_input_init(); +/* %%%-SFUNWIZ_wrapper_Start_Changes_END --- EDIT HERE TO _BEGIN */ +} +/* + * Output function + * + */ +void hal_ai_Outputs_wrapper(const uint16_T *start_idx, + uint16_T *AI, + int32_T *ErrorCode, + const int_T y_width) +{ +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */ +ErrorCode[0] = -1; + if (is_analog_input_init) + { +#ifdef HAL_IMPL + /* + * input *AI* from ADC channels from *start_idx* to *start_idx*+y_width-1. + * + * ErrorCode - return zero on success, otherwise nonzero on failures. + */ + // TODO set analog inputs + for (int_T i=0; i +/* %%%-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 */ +int is_pwm_out_init = 0; + +void pwm_out_init() +{ + if (!is_pwm_out_init) + { +#ifdef HAL_IMPL + is_pwm_out_init = 1; +#endif + } +} +/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */ + +/* + * Start function + * + */ +void hal_pwm_out_Start_wrapper(void) +{ +/* %%%-SFUNWIZ_wrapper_Start_Changes_BEGIN --- EDIT HERE TO _END */ +pwm_out_init(); +/* %%%-SFUNWIZ_wrapper_Start_Changes_END --- EDIT HERE TO _BEGIN */ +} +/* + * Output function + * + */ +void hal_pwm_out_Outputs_wrapper(const uint16_T *pwm, + const uint16_T *start_idx, + int32_T *ErrorCode, + const int_T u_width) +{ +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */ +ErrorCode[0] = -1; + if (is_pwm_out_init) + { +#ifdef HAL_IMPL + /* + * output *pwm* to pwm devices from *start_idx* to *start_idx*+u_width-1. + * + * ErrorCode - return zero on success, otherwise nonzero on failures. + */ + for (int i = 0; i< u_width; ++i) + { + set_pwm(start_idx[0]+i, pwm[i]); + } + + ErrorCode[0] = 0; +#endif + } +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */ +} + + diff --git a/B3_AP_lite/hal_uart_in_wrapper.c b/B3_AP_lite/hal_uart_in_wrapper.c new file mode 100644 index 0000000..ac30182 --- /dev/null +++ b/B3_AP_lite/hal_uart_in_wrapper.c @@ -0,0 +1,103 @@ + +/* + * 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" +#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 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_IMU_NAV_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; + } +#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 */ +} + + diff --git a/B3_AP_lite/hal_uart_out_wrapper.c b/B3_AP_lite/hal_uart_out_wrapper.c new file mode 100644 index 0000000..d8b2a51 --- /dev/null +++ b/B3_AP_lite/hal_uart_out_wrapper.c @@ -0,0 +1,122 @@ + +/* + * 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" +#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 */ + +/* %%%-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[16]; + 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_RS422_2_tx, (uint8_t *)buff, len[0])) + { + seq_last[uart_id[0]] = sep[0]; + ErrorCode[0] = 0; + } + break; + case 4: + if (sep[0] != seq_last[uart_id[0]] && UART_TX_FIFO_write(&uart5_STORE_tx, (uint8_t *)buff, len[0])) + { + seq_last[uart_id[0]] = sep[0]; + ErrorCode[0] = 0; + } + break; + case 5: + if (sep[0] != seq_last[uart_id[0]] && UART_TX_FIFO_write(&uart6_IMU_NAV_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_RS232_1_tx, (uint8_t *)buff, len[0])) + { + seq_last[uart_id[0]] = sep[0]; + ErrorCode[0] = 0; + } + break; + case 7: + if (sep[0] != seq_last[uart_id[0]] && UART_TX_FIFO_write(&uart8_RS232_2_tx, (uint8_t *)buff, len[0])) + { + seq_last[uart_id[0]] = sep[0]; + ErrorCode[0] = 0; + } + break; + } +#else +/* dummy function for generate mex file for sim*/ +ErrorCode[0] = 0; +#endif +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */ +} + + diff --git a/fmc41/hal_ai_wrapper.c b/fmc41/hal_ai_wrapper.c new file mode 100644 index 0000000..c442421 --- /dev/null +++ b/fmc41/hal_ai_wrapper.c @@ -0,0 +1,85 @@ + +/* + * 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 "param_mgr.h" +#include "adc_devs.h" +#endif +/* %%%-SFUNWIZ_wrapper_includes_Changes_END --- EDIT HERE TO _BEGIN */ +#define u_width 1 + +/* + * Create external references here. + * + */ +/* %%%-SFUNWIZ_wrapper_externs_Changes_BEGIN --- EDIT HERE TO _END */ +int is_analog_input_init = 0; + +void analog_input_init() +{ + if (!is_analog_input_init) + { +#ifdef HAL_IMPL + //TODO + is_analog_input_init = 1; +#endif + } +} +/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */ + +/* + * Start function + * + */ +void hal_ai_Start_wrapper(void) +{ +/* %%%-SFUNWIZ_wrapper_Start_Changes_BEGIN --- EDIT HERE TO _END */ +analog_input_init(); +/* %%%-SFUNWIZ_wrapper_Start_Changes_END --- EDIT HERE TO _BEGIN */ +} +/* + * Output function + * + */ +void hal_ai_Outputs_wrapper(const uint16_T *start_idx, + uint16_T *AI, + int32_T *ErrorCode, + const int_T y_width) +{ +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */ +ErrorCode[0] = -1; + if (is_analog_input_init) + { +#ifdef HAL_IMPL + /* + * input *AI* from ADC channels from *start_idx* to *start_idx*+y_width-1. + * + * ErrorCode - return zero on success, otherwise nonzero on failures. + */ + // TODO set analog inputs + for (int_T i=0; i