From e8940d1a31179b74f2a8f50a12762628478d9cdf Mon Sep 17 00:00:00 2001 From: matt Date: Wed, 23 Sep 2020 17:27:03 +0800 Subject: [PATCH] support EF3Lite --- EF3Lite/hal_3axis_magn_wrapper.c | 133 ++++++++++ EF3Lite/hal_6axis_imu_wrapper.c | 149 ++++++++++++ EF3Lite/hal_ai_wrapper.c | 88 +++++++ EF3Lite/hal_ao_wrapper.c | 77 ++++++ EF3Lite/hal_can_receive_wrapper.c | 47 ++++ EF3Lite/hal_can_transfer_wrapper.c | 42 ++++ EF3Lite/hal_clock_wrapper.c | 77 ++++++ EF3Lite/hal_di_wrapper.c | 77 ++++++ EF3Lite/hal_do_wrapper.c | 78 ++++++ EF3Lite/hal_general_in_wrapper.c | 97 ++++++++ EF3Lite/hal_general_out_wrapper.c | 93 +++++++ EF3Lite/hal_gps_wrapper.c | 253 +++++++++++++++++++ EF3Lite/hal_ins_wrapper.c | 119 +++++++++ EF3Lite/hal_led_set_wrapper.c | 91 +++++++ EF3Lite/hal_nvram_cancel_wrapper.c | 91 +++++++ EF3Lite/hal_nvram_read_wrapper.c | 126 ++++++++++ EF3Lite/hal_nvram_write_wrapper.c | 104 ++++++++ EF3Lite/hal_pressure_wrapper.c | 126 ++++++++++ EF3Lite/hal_pwm_in_wrapper.c | 77 ++++++ EF3Lite/hal_pwm_out_wrapper.c | 112 +++++++++ EF3Lite/hal_rec_wrapper.c | 49 ++++ EF3Lite/hal_sbus_in_wrapper.c | 99 ++++++++ EF3Lite/hal_sen_read_wrapper.c | 275 +++++++++++++++++++++ EF3Lite/hal_uart_in_wrapper.c | 99 ++++++++ EF3Lite/hal_uart_init_wrapper.c | 375 +++++++++++++++++++++++++++++ EF3Lite/hal_uart_out_wrapper.c | 98 ++++++++ 26 files changed, 3052 insertions(+) create mode 100644 EF3Lite/hal_3axis_magn_wrapper.c create mode 100644 EF3Lite/hal_6axis_imu_wrapper.c create mode 100644 EF3Lite/hal_ai_wrapper.c create mode 100644 EF3Lite/hal_ao_wrapper.c create mode 100644 EF3Lite/hal_can_receive_wrapper.c create mode 100644 EF3Lite/hal_can_transfer_wrapper.c create mode 100644 EF3Lite/hal_clock_wrapper.c create mode 100644 EF3Lite/hal_di_wrapper.c create mode 100644 EF3Lite/hal_do_wrapper.c create mode 100644 EF3Lite/hal_general_in_wrapper.c create mode 100644 EF3Lite/hal_general_out_wrapper.c create mode 100644 EF3Lite/hal_gps_wrapper.c create mode 100644 EF3Lite/hal_ins_wrapper.c create mode 100644 EF3Lite/hal_led_set_wrapper.c create mode 100644 EF3Lite/hal_nvram_cancel_wrapper.c create mode 100644 EF3Lite/hal_nvram_read_wrapper.c create mode 100644 EF3Lite/hal_nvram_write_wrapper.c create mode 100644 EF3Lite/hal_pressure_wrapper.c create mode 100644 EF3Lite/hal_pwm_in_wrapper.c create mode 100644 EF3Lite/hal_pwm_out_wrapper.c create mode 100644 EF3Lite/hal_rec_wrapper.c create mode 100644 EF3Lite/hal_sbus_in_wrapper.c create mode 100644 EF3Lite/hal_sen_read_wrapper.c create mode 100644 EF3Lite/hal_uart_in_wrapper.c create mode 100644 EF3Lite/hal_uart_init_wrapper.c create mode 100644 EF3Lite/hal_uart_out_wrapper.c diff --git a/EF3Lite/hal_3axis_magn_wrapper.c b/EF3Lite/hal_3axis_magn_wrapper.c new file mode 100644 index 0000000..6290269 --- /dev/null +++ b/EF3Lite/hal_3axis_magn_wrapper.c @@ -0,0 +1,133 @@ + +/* + * Include Files + * + */ +#if defined(MATLAB_MEX_FILE) +#include "tmwtypes.h" +#include "simstruc_types.h" +#else +#include "rtwtypes.h" +#endif + +#include "hal_api.h" + +/* %%%-SFUNWIZ_wrapper_includes_Changes_BEGIN --- EDIT HERE TO _END */ +#ifdef HAL_IMPL +/* TODO include files */ + +#include "AppMagnetic.h" + +#endif +#include +/* %%%-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 magn_inited[3]; + +void initialize_3axis_magn(uint8_t id) +{ + switch (id) + { + case 0: + if (!magn_inited[0]) + { +#ifdef HAL_IMPL + // TODO initialize 3axis-magn No.0 + magn_inited[0] = 1; +#endif + } + break; + + case 1: + if (!magn_inited[1]) + { +#ifdef HAL_IMPL + // TODO initialize 3axis-magn No.1 + magn_inited[1] = 1; +#endif + } + break; + + case 2: + if (!magn_inited[2]) + { +#ifdef HAL_IMPL + // TODO initialize 3axis-magn No.2 + magn_inited[2] = 1; +#endif + } + break; + + default: + break; + } +} +/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */ + +/* + * Start function + * + */ +void hal_3axis_magn_Start_wrapper(const uint8_T *id, const int_T p_width0) +{ + /* %%%-SFUNWIZ_wrapper_Start_Changes_BEGIN --- EDIT HERE TO _END */ + initialize_3axis_magn(id[0]); + /* %%%-SFUNWIZ_wrapper_Start_Changes_END --- EDIT HERE TO _BEGIN */ +} +/* + * Output function + * + */ +void hal_3axis_magn_Outputs_wrapper(HAL_magn_mG_t *magn, + int32_T *ErrorCode, + const uint8_T *id, const int_T p_width0) +{ + /* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */ + ErrorCode[0] = -1; + switch (id[0]) + { + case 0: + if (magn_inited[0]) + { +#ifdef HAL_IMPL + if(AppMagGetRawData(id[0], &magn->x, &magn->y, &magn->z, &magn->seq)) + ErrorCode[0] = 0; + else + ErrorCode[0] = -1; +#endif + } + break; + + case 1: + if (magn_inited[1]) + { +#ifdef HAL_IMPL + if(AppMagGetRawData(id[0], &magn->x, &magn->y, &magn->z, &magn->seq)) + ErrorCode[0] = 0; + else + ErrorCode[0] = -1; +#endif + } + break; + case 2: + if (magn_inited[2]) + { +#ifdef HAL_IMPL + if(AppMagGetRawData(id[0], &magn->x, &magn->y, &magn->z, &magn->seq)) + ErrorCode[0] = 0; + else + ErrorCode[0] = -1; +#endif + } + break; + default: + break; + } + /* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */ +} diff --git a/EF3Lite/hal_6axis_imu_wrapper.c b/EF3Lite/hal_6axis_imu_wrapper.c new file mode 100644 index 0000000..72f6444 --- /dev/null +++ b/EF3Lite/hal_6axis_imu_wrapper.c @@ -0,0 +1,149 @@ + +/* + * Include Files + * + */ +#if defined(MATLAB_MEX_FILE) +#include "tmwtypes.h" +#include "simstruc_types.h" +#else +#include "rtwtypes.h" +#endif + +#include "hal_api.h" + + +/* %%%-SFUNWIZ_wrapper_includes_Changes_BEGIN --- EDIT HERE TO _END */ +#ifdef HAL_IMPL +#include "AppProcessQEkff.h" +//#include "SEGGER_RTT.h" +//#include "SEGGER_RTT_Conf.h" +#endif +#include +/* %%%-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 imu_inited[3]; + +void initialize_6axis_imu(uint8_t id) +{ + switch (id) + { + case 0: + if (!imu_inited[0]) + { +#ifdef HAL_IMPL + // TODO initialize 6axis-IMU No.0 + imu_inited[0] = 1; +#endif + } + break; + + case 1: + if (!imu_inited[1]) + { +#ifdef HAL_IMPL + // TODO initialize 6axis-IMU No.1 + imu_inited[1] = 1; +#endif + } + break; + + case 2: + if (!imu_inited[2]) + { +#ifdef HAL_IMPL + // TODO initialize 6axis-IMU No.2 + imu_inited[2] = 1; +#endif + } + break; + + default: + break; + } +} +/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */ + +/* + * Start function + * + */ +void hal_6axis_imu_Start_wrapper(const uint8_T *id, const int_T p_width0) +{ +/* %%%-SFUNWIZ_wrapper_Start_Changes_BEGIN --- EDIT HERE TO _END */ +initialize_6axis_imu(id[0]); +/* %%%-SFUNWIZ_wrapper_Start_Changes_END --- EDIT HERE TO _BEGIN */ +} +/* + * Output function + * + */ +void hal_6axis_imu_Outputs_wrapper(HAL_acc_SI_t *acc, + HAL_gyro_SI_t *gyro, + int32_T *ErrorCode, + const uint8_T *id, const int_T p_width0) +{ +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */ + ErrorCode[0] = -1; + switch (id[0]) + { + case 0: + if (imu_inited[0]) + { +#ifdef HAL_IMPL + // TODO read 6axis-IMU + //SEGGER_RTT_printf(0, "AppImuGetRawData = %d \n",id[0]); + if(AppImuGetRawData(id[0], &acc->x, &acc->y, &acc->z, &gyro->x, &gyro->y, &gyro->z, &acc->seq, &gyro->seq)) + { + ErrorCode[0] = 0; + } + else + ErrorCode[0] = -1; +#endif + } + break; + + case 1: + if (imu_inited[1]) + { +#ifdef HAL_IMPL + // TODO read 6axis-IMU + //SEGGER_RTT_printf(0, "AppImuGetRawData = %d \n",id[0]); + if(AppImuGetRawData(id[0], &acc->x, &acc->y, &acc->z, &gyro->x, &gyro->y, &gyro->z, &acc->seq, &gyro->seq)) + { + ErrorCode[0] = 0; + } + else + ErrorCode[0] = -1; +#endif + } + break; + + case 2: + if (imu_inited[2]) + { +#ifdef HAL_IMPL + // TODO read 6axis-IMU + //SEGGER_RTT_printf(0, "AppImuGetRawData = %d \n",id[0]); + if(AppImuGetRawData(id[0], &acc->x, &acc->y, &acc->z, &gyro->x, &gyro->y, &gyro->z, &acc->seq, &gyro->seq)) + { + ErrorCode[0] = 0; + } + else + ErrorCode[0] = -1; +#endif + } + break; + default: + break; + } +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */ +} + + diff --git a/EF3Lite/hal_ai_wrapper.c b/EF3Lite/hal_ai_wrapper.c new file mode 100644 index 0000000..100948b --- /dev/null +++ b/EF3Lite/hal_ai_wrapper.c @@ -0,0 +1,88 @@ + +/* + * 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 "DrvAdcEx.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 + if(start_idx[0]+y_width-1 > 4) + ErrorCode[0] = 1; + else + { + for(uint8_T i = start_idx[0]; i < start_idx[0]+y_width; i++) + { + AI[i] = g_Voltage[i]*100; //单位 0.01v g_Voltage0-4分别代表:排线AD1-AD4电压、飞控电压 + ErrorCode[0] = 0; + } + } + +#endif + } +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */ +} + + diff --git a/EF3Lite/hal_ao_wrapper.c b/EF3Lite/hal_ao_wrapper.c new file mode 100644 index 0000000..71a5165 --- /dev/null +++ b/EF3Lite/hal_ao_wrapper.c @@ -0,0 +1,77 @@ + +/* + * 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" +#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 */ +int is_analog_output_init = 0; + +void analog_output_init() +{ + if (!is_analog_output_init) + { +#ifdef HAL_IMPL + //TODO + is_analog_output_init = 1; +#endif + } +} +/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */ + +/* + * Start function + * + */ +void hal_ao_Start_wrapper(void) +{ +/* %%%-SFUNWIZ_wrapper_Start_Changes_BEGIN --- EDIT HERE TO _END */ +analog_output_init(); +/* %%%-SFUNWIZ_wrapper_Start_Changes_END --- EDIT HERE TO _BEGIN */ +} +/* + * Output function + * + */ +void hal_ao_Outputs_wrapper(const uint16_T *AO, + 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_analog_output_init) + { +#ifdef HAL_IMPL + /* + * output *AO* to analog output devices from *start_idx* to *start_idx*+u_width-1. + * + * ErrorCode - return zero on success, otherwise nonzero on failures. + */ + // TODO set AO to DAC channels + ErrorCode[0] = 0; +#endif + } +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */ +} + + diff --git a/EF3Lite/hal_can_receive_wrapper.c b/EF3Lite/hal_can_receive_wrapper.c new file mode 100644 index 0000000..5cf0160 --- /dev/null +++ b/EF3Lite/hal_can_receive_wrapper.c @@ -0,0 +1,47 @@ + +/* + * Include Files + * + */ +#if defined(MATLAB_MEX_FILE) +#include "tmwtypes.h" +#include "simstruc_types.h" +#else +#include "rtwtypes.h" +#endif + +#include "hal_can_receive_bus.h" + +/* %%%-SFUNWIZ_wrapper_includes_Changes_BEGIN --- EDIT HERE TO _END */ +#include +/* %%%-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 */ +/* extern double func(double a); */ +/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */ + +/* + * Output function + * + */ +void hal_can_receive_Outputs_wrapper(CAN_MESSAGE_BUS *msg, + int32_T *ErrorCode, + const uint8_T *canbus_id, const int_T p_width0) +{ +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */ +/* This sample sets the output equal to the input + y0[0] = u0[0]; + For complex signals use: y0[0].re = u0[0].re; + y0[0].im = u0[0].im; + y1[0].re = u1[0].re; + y1[0].im = u1[0].im; + */ +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */ +} + + diff --git a/EF3Lite/hal_can_transfer_wrapper.c b/EF3Lite/hal_can_transfer_wrapper.c new file mode 100644 index 0000000..262262a --- /dev/null +++ b/EF3Lite/hal_can_transfer_wrapper.c @@ -0,0 +1,42 @@ + +/* + * Include Files + * + */ +#if defined(MATLAB_MEX_FILE) +#include "tmwtypes.h" +#include "simstruc_types.h" +#else +#include "rtwtypes.h" +#endif + +#include "hal_can_transfer_bus.h" + +/* %%%-SFUNWIZ_wrapper_includes_Changes_BEGIN --- EDIT HERE TO _END */ +#include +/* %%%-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 */ +/* extern double func(double a); */ +/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */ + +/* + * Output function + * + */ +void hal_can_transfer_Outputs_wrapper(const CAN_MESSAGE_BUS *msg, + int32_T *ErrorCode, + const uint8_T *canbus_id, const int_T p_width0) +{ +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */ +ErrorCode[0] = 0; +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */ +} + + diff --git a/EF3Lite/hal_clock_wrapper.c b/EF3Lite/hal_clock_wrapper.c new file mode 100644 index 0000000..5230e56 --- /dev/null +++ b/EF3Lite/hal_clock_wrapper.c @@ -0,0 +1,77 @@ + +/* + * 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 +/* TODO include files */ +#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 */ +int is_init = 0; + +static void initialize_clock() +{ + if (!is_init) + { +#ifdef HAL_IMPL + /* TODO setup clock */ + is_init = 1; +#endif + } +} +/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */ + +/* + * Start function + * + */ +void hal_clock_Start_wrapper(const uint8_T *typ, const int_T p_width0) +{ +/* %%%-SFUNWIZ_wrapper_Start_Changes_BEGIN --- EDIT HERE TO _END */ +initialize_clock(); +/* %%%-SFUNWIZ_wrapper_Start_Changes_END --- EDIT HERE TO _BEGIN */ +} +/* + * Output function + * + */ +void hal_clock_Outputs_wrapper(uint32_T *boot_time, + const uint8_T *typ, const int_T p_width0) +{ +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */ +if (is_init) +{ +#ifdef HAL_IMPL +//TODO get clock + // typ: 0 - msec; 1 - usec; + if(typ[0] == 0) + { + boot_time[0] = get_milliseconds(); + } + else if(typ[0] == 1) + { + boot_time[0] = get_mircoseconds(); + } +#endif +} +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */ +} + + diff --git a/EF3Lite/hal_di_wrapper.c b/EF3Lite/hal_di_wrapper.c new file mode 100644 index 0000000..12ba359 --- /dev/null +++ b/EF3Lite/hal_di_wrapper.c @@ -0,0 +1,77 @@ + +/* + * 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" +#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_discrete_input_init = 0; + +void discrete_input_init() +{ + if (!is_discrete_input_init) + { +#ifdef HAL_IMPL + //TODO + is_discrete_input_init = 1; +#endif + } +} +/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */ + +/* + * Start function + * + */ +void hal_di_Start_wrapper(void) +{ +/* %%%-SFUNWIZ_wrapper_Start_Changes_BEGIN --- EDIT HERE TO _END */ +discrete_input_init(); +/* %%%-SFUNWIZ_wrapper_Start_Changes_END --- EDIT HERE TO _BEGIN */ +} +/* + * Output function + * + */ +void hal_di_Outputs_wrapper(const uint16_T *start_idx, + boolean_T *DI, + int32_T *ErrorCode, + const int_T y_width) +{ +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */ +ErrorCode[0] = -1; + if (is_discrete_input_init) + { +#ifdef HAL_IMPL + /* + * input *DI* from DI devices from *start_idx* to *start_idx*+y_width-1. + * + * ErrorCode - return zero on success, otherwise nonzero on failures. + */ + // TODO set pwm outputs + ErrorCode[0] = -1; +#endif + } +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */ +} + + diff --git a/EF3Lite/hal_do_wrapper.c b/EF3Lite/hal_do_wrapper.c new file mode 100644 index 0000000..79057ed --- /dev/null +++ b/EF3Lite/hal_do_wrapper.c @@ -0,0 +1,78 @@ + +/* + * 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" +#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 */ +int is_discrete_output_init = 0; + +void discrete_output_init() +{ + if (!is_discrete_output_init) + { +#ifdef HAL_IMPL + + //TODO + is_discrete_output_init = 1; +#endif + } +} +/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */ + +/* + * Start function + * + */ +void hal_do_Start_wrapper(void) +{ +/* %%%-SFUNWIZ_wrapper_Start_Changes_BEGIN --- EDIT HERE TO _END */ +discrete_output_init(); +/* %%%-SFUNWIZ_wrapper_Start_Changes_END --- EDIT HERE TO _BEGIN */ +} +/* + * Output function + * + */ +void hal_do_Outputs_wrapper(const boolean_T *DO, + 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_discrete_output_init) + { +#ifdef HAL_IMPL + /* + * output *DO* to digital output devices from *start_idx* to *start_idx*+u_width-1. + * + * ErrorCode - return zero on success, otherwise nonzero on failures. + */ + // TODO set DOs + ErrorCode[0] = 0; +#endif + } +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */ +} + + diff --git a/EF3Lite/hal_general_in_wrapper.c b/EF3Lite/hal_general_in_wrapper.c new file mode 100644 index 0000000..4b9563c --- /dev/null +++ b/EF3Lite/hal_general_in_wrapper.c @@ -0,0 +1,97 @@ + +/* + * 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" +#endif +#include +#include +/* %%%-SFUNWIZ_wrapper_includes_Changes_END --- EDIT HERE TO _BEGIN */ + +/* + * Create external references here. + * + */ +/* %%%-SFUNWIZ_wrapper_externs_Changes_BEGIN --- EDIT HERE TO _END */ +typedef int (*genral_in_ptr)(uint8_t *packed_in, const int y_width, void **pW); + +//Demo +int demo_init_func(void **pW) +{ + static int is_init = 0; + if (!is_init) + { + is_init = 1; + } + return 0; +} + +int demo_in_func(uint8_t *packed_in, const int y_width, void **pW) +{ + + return 0; +} + +//TODO add other init/input functions +/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */ + +/* + * Start function + * + */ +void hal_general_in_Start_wrapper(void **pW, + const uint8_T *device_id, const int_T p_width0) +{ +/* %%%-SFUNWIZ_wrapper_Start_Changes_BEGIN --- EDIT HERE TO _END */ +int *valid = (int *)&pW[0]; /* 0-invalid; 1-valid; */ + genral_in_ptr *func = (genral_in_ptr *)&pW[1]; + + valid[0] = 0; + if (strncmp(device_id, "demo", p_width0)) + { + if (!demo_init_func(&pW[2])) + { + *valid = 1; + *func = &demo_in_func; + } + } + //TODO add other cases +/* %%%-SFUNWIZ_wrapper_Start_Changes_END --- EDIT HERE TO _BEGIN */ +} +/* + * Output function + * + */ +void hal_general_in_Outputs_wrapper(uint8_T *packed_in, + int32_T *ErrorCode, + void **pW, + const uint8_T *device_id, const int_T p_width0, + const int_T y_width) +{ +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */ +int *valid = (int *)&pW[0]; /* 0-invalid; 1-valid; */ + if (valid[0]) + { + genral_in_ptr func = (genral_in_ptr)pW[1]; + ErrorCode[0] = (*func)(packed_in, y_width, &pW[2]); + } + else + { + ErrorCode[0] = -1; + } +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */ +} + + diff --git a/EF3Lite/hal_general_out_wrapper.c b/EF3Lite/hal_general_out_wrapper.c new file mode 100644 index 0000000..aff1aa0 --- /dev/null +++ b/EF3Lite/hal_general_out_wrapper.c @@ -0,0 +1,93 @@ + +/* + * 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" +#endif +#include +#include +/* %%%-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 */ +typedef int (*genral_out_ptr)(const uint8_t *packed_out, const int u_width, void **pW); + +#ifdef HAL_IMPL +extern int demo_init_func(void **pW); +#else +int demo_init_func(void **pW) +{ +} +#endif + +int demo_out_func(const uint8_t *packed_out, const int u_width, void **pW) +{ + return 0; +} +//TODO add other init/output functions +/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */ + +/* + * Start function + * + */ +void hal_general_out_Start_wrapper(void **pW, + const uint8_T *device_id, const int_T p_width0) +{ +/* %%%-SFUNWIZ_wrapper_Start_Changes_BEGIN --- EDIT HERE TO _END */ +int *valid = (int *)&pW[0]; /* 0-invalid; 1-valid; */ + genral_out_ptr *func = (genral_out_ptr *)&pW[1]; + + valid[0] = 0; + if (strncmp(device_id, "demo", p_width0)) + { + if (!demo_init_func(&pW[2])) + { + *valid = 1; + *func = &demo_out_func; + } + } + //TODO add other cases +/* %%%-SFUNWIZ_wrapper_Start_Changes_END --- EDIT HERE TO _BEGIN */ +} +/* + * Output function + * + */ +void hal_general_out_Outputs_wrapper(const uint8_T *packed_out, + int32_T *ErrorCode, + void **pW, + const uint8_T *device_id, const int_T p_width0, + const int_T u_width) +{ +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */ +int *valid = (int *)&pW[0]; /* 0-invalid; 1-valid; */ + if (valid[0]) + { + genral_out_ptr func = (genral_out_ptr)pW[1]; + ErrorCode[0] = (*func)(packed_out, u_width, &pW[2]); + } + else + { + ErrorCode[0] = -1; + } +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */ +} + + diff --git a/EF3Lite/hal_gps_wrapper.c b/EF3Lite/hal_gps_wrapper.c new file mode 100644 index 0000000..7967f45 --- /dev/null +++ b/EF3Lite/hal_gps_wrapper.c @@ -0,0 +1,253 @@ + +/* + * Include Files + * + */ +#if defined(MATLAB_MEX_FILE) +#include "tmwtypes.h" +#include "simstruc_types.h" +#else +#include "rtwtypes.h" +#endif + +#include "hal_api.h" + + +/* %%%-SFUNWIZ_wrapper_includes_Changes_BEGIN --- EDIT HERE TO _END */ +#ifdef HAL_IMPL + +uint32_t g_gps_seq = 0; +uint32_t g_rtk_seq = 0; + +#include "uavcan_main.h" +/* TODO include files */ +#define PI (3.1415926535897932) /* pi */ +#define D2R (PI/180.0) /* deg to rad */ + +unsigned char DayOfMon[12] = {31,28,31,30,31,30,31,31,30,31,30,31}; +//Timestamp --> DataTime --------------------------------------------------------------------- +#define SECOND_OF_DAY 86400 //1天的秒数 +#define SECOND_OF_WEEK (SECOND_OF_DAY*7) + +/** UTC->总秒数 iYear是20xx年 */ +static unsigned int GetMilSecondTime(unsigned short iYear, unsigned short iMon, unsigned short iDay, unsigned short iHour, unsigned short iMin, unsigned short iSec ) +{ + unsigned short i, Cyear=0; + unsigned int CountDay=0; + + for(i=1980; 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 gps_inited[4]; + +void initialize_gps(uint8_t id) //应该定期执行,防止中途插拔GPS模块 by LQH +{ + switch (id) + { + case 0: + if (!gps_inited[0]) + { +#ifdef HAL_IMPL + // TODO initialize GPS No.0 + if(gps_info.num_valid >= 1) + gps_inited[0] = 1; + else + gps_inited[0] = 0; +#endif + } + break; + + case 1: + if (!gps_inited[1]) + { +#ifdef HAL_IMPL + // TODO initialize GPS No.0 + if(gps_info.num_valid >= 2) + gps_inited[1] = 1; + else + gps_inited[1] = 0; +#endif + } + break; + + case 2: + if (!gps_inited[2]) + { +#ifdef HAL_IMPL + // TODO initialize GPS No.0 + if(gps_info.num_valid >= 3) + gps_inited[2] = 1; + else + gps_inited[2] = 0; +#endif + } + break; + + case 3: + if (!gps_inited[3]) + { +#ifdef HAL_IMPL + // TODO initialize GPS No.0 + if(g_RtkAll.num_valid >= 1) + gps_inited[3] = 1; + else + gps_inited[3] = 0; +#endif + } + break; + default: + break; + } +} +/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */ + +/* + * Start function + * + */ +void hal_gps_Start_wrapper(const uint8_T *id, const int_T p_width0) +{ +/* %%%-SFUNWIZ_wrapper_Start_Changes_BEGIN --- EDIT HERE TO _END */ +initialize_gps(id[0]); +/* %%%-SFUNWIZ_wrapper_Start_Changes_END --- EDIT HERE TO _BEGIN */ +} +/* + * Output function + * + */ +void hal_gps_Outputs_wrapper(HAL_GPS_SI_t *gps, + int32_T *ErrorCode, + const uint8_T *id, const int_T p_width0) +{ +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */ +ErrorCode[0] = -1; + switch (id[0]) + { + case 0: //普通GPS通过id[0]来区分index + case 1: + case 2: + if (gps_inited[id[0]]) + { +#ifdef HAL_IMPL + // TODO read pressure + gps->latitude = gps_info.gps_info_s[id[0]].LatDeg; ///< Unit is degree + gps->longitude = gps_info.gps_info_s[id[0]].LonDeg; ///< Unit is degree + gps->altitude = gps_info.gps_info_s[id[0]].height; ///< aititude from MSL, Unit is meter + + gps->vel_north = gps_info.gps_info_s[id[0]].VelNorth; ///< Unit is meter per second, in NED axes + gps->vel_east = gps_info.gps_info_s[id[0]].VelEast; ///< Unit is meter per second, in NED axes + gps->vel_down = gps_info.gps_info_s[id[0]].VelDown; ///< Unit is meter per second, in NED axes + + gps->heading = gps_info.gps_info_s[id[0]].HeadingMotionDeg * D2R; ///< Unit is radian, valid when fixtype_att>1 + gps->pitch = 0; ///< Unit is radian, valid when fixtype_att>1 + + /** 待确定 + float h_acc; ///< Unit is meter, Position uncertainty + float v_acc; ///< Unit is meter, Altitude uncertainty + float vel_acc; ///< Unit is m/s, velocity uncertainty + float att_acc; ///< Unit is radian, attitude uncertainty when fixtype_att>1 + */ + + SecondFromUTC = GetMilSecondTime(gps_info.gps_info_s[id[0]].year, gps_info.gps_info_s[id[0]].month, gps_info.gps_info_s[id[0]].day, + gps_info.gps_info_s[id[0]].hour, gps_info.gps_info_s[id[0]].min, gps_info.gps_info_s[id[0]].isec); + gps->TOW = (SecondFromUTC % SECOND_OF_WEEK)*1000 + gps_info.gps_info_s[id[0]].msec; ///< Unit is millisecond, Time of Week + gps->WN = SecondFromUTC / SECOND_OF_WEEK; ///< Week Number of GPS + gps->seq = g_gps_seq; + gps->seq_att = g_gps_seq; + gps->HDOP = gps_info.gps_info_s[id[0]].pdop; //RTK传过来的只有pdop + gps->VDOP = gps_info.gps_info_s[id[0]].pdop; //RTK传过来的只有pdop + gps->fixtype = gps_info.gps_info_s[id[0]].FixType; + gps->fixtype_att = 0; //普通GPS没意义 赋值0 + gps->satnum = gps_info.gps_info_s[id[0]].SvNum; + + + ErrorCode[0] = 0; +#endif + } + else + ErrorCode[0] = 1; + + break; + + case 4: + if (gps_inited[3]) + { +#ifdef HAL_IMPL + // TODO read pressure + if(g_RtkAll.num_valid > 0) + { + gps->latitude = g_RtkAll.rtk[0].pvt.LatDeg; ///< Unit is degree + gps->longitude = g_RtkAll.rtk[0].pvt.LonDeg; ///< Unit is degree + gps->altitude = g_RtkAll.rtk[0].pvt.height; ///< aititude from MSL, Unit is meter + + gps->vel_north = g_RtkAll.rtk[0].pvt.Vn; ///< Unit is meter per second, in NED axes + gps->vel_east = g_RtkAll.rtk[0].pvt.Ve; ///< Unit is meter per second, in NED axes + gps->vel_down = g_RtkAll.rtk[0].pvt.Vd; ///< Unit is meter per second, in NED axes + + gps->heading = g_RtkAll.rtk[0].att.heading* D2R/ 100.0f; ///< Unit is radian, valid when fixtype_att>1 + gps->pitch = g_RtkAll.rtk[0].att.pitch* D2R/ 100.0f; ///< Unit is radian, valid when fixtype_att>1 + + /** 待确定 + float h_acc; ///< Unit is meter, Position uncertainty + float v_acc; ///< Unit is meter, Altitude uncertainty + float vel_acc; ///< Unit is m/s, velocity uncertainty + float att_acc; ///< Unit is radian, attitude uncertainty when fixtype_att>1 + */ + + SecondFromUTC = GetMilSecondTime(g_RtkAll.rtk[0].pvt.year+2000, g_RtkAll.rtk[0].pvt.month, g_RtkAll.rtk[0].pvt.day, + g_RtkAll.rtk[0].pvt.hour, g_RtkAll.rtk[0].pvt.min, g_RtkAll.rtk[0].pvt.sec); + gps->TOW = (SecondFromUTC % SECOND_OF_WEEK)*1000 + g_RtkAll.rtk[0].pvt.msec; ///< Unit is millisecond, Time of Week + gps->WN = SecondFromUTC / SECOND_OF_WEEK; ///< Week Number of GPS + gps->seq = g_rtk_seq; //待测试一下 + gps->seq_att = g_rtk_seq; + gps->HDOP = g_RtkAll.rtk[0].pvt.pdop; //RTK传过来的只有pdop + gps->VDOP = g_RtkAll.rtk[0].pvt.pdop; //RTK传过来的只有pdop + gps->fixtype = g_RtkAll.rtk[0].pvt.FixType; //存在对应关系的定义 可能要改进 + gps->fixtype_att = g_RtkAll.rtk[0].att.AttType; + gps->satnum = g_RtkAll.rtk[0].pvt.SvNum; + + ErrorCode[0] = 0; + } + else + ErrorCode[0] = 1; +#endif + } + break; + default: + break; + } +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */ +} + + diff --git a/EF3Lite/hal_ins_wrapper.c b/EF3Lite/hal_ins_wrapper.c new file mode 100644 index 0000000..39fdb0c --- /dev/null +++ b/EF3Lite/hal_ins_wrapper.c @@ -0,0 +1,119 @@ + +/* + * Include Files + * + */ +#if defined(MATLAB_MEX_FILE) +#include "tmwtypes.h" +#include "simstruc_types.h" +#else +#include "rtwtypes.h" +#endif + +#include "hal_api.h" + + +/* %%%-SFUNWIZ_wrapper_includes_Changes_BEGIN --- EDIT HERE TO _END */ +#ifdef HAL_IMPL +/* TODO include files */ +#include "fuckQvar.h" +uint32_t g_ins_seq = 0; + +#endif +#include +/* %%%-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 ins_inited[1]; + +void initialize_ins(uint8_t id) +{ + switch (id) + { + case 0: + if (!ins_inited[0]) + { +#ifdef HAL_IMPL + // TODO initialize GPS No.0 + ins_inited[0] = 1; +#endif + } + break; + default: + break; + } +} +/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */ + +/* + * Start function + * + */ +void hal_ins_Start_wrapper(const uint8_T *id, const int_T p_width0) +{ +/* %%%-SFUNWIZ_wrapper_Start_Changes_BEGIN --- EDIT HERE TO _END */ +initialize_ins(id[0]); +/* %%%-SFUNWIZ_wrapper_Start_Changes_END --- EDIT HERE TO _BEGIN */ +} +/* + * Output function + * + */ +void hal_ins_Outputs_wrapper(HAL_INS_SI_t *ins, + int32_T *ErrorCode, + const uint8_T *id, const int_T p_width0) +{ +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */ +ErrorCode[0] = -1; + switch (id[0]) + { + case 0: + if (ins_inited[0]) + { +#ifdef HAL_IMPL + // TODO read pressure + ins->latitude = Pack_EKF[EKF_for_FC].alldata.gps_latti; ///< Unit is degree + ins->longitude = Pack_EKF[EKF_for_FC].alldata.gps_longi; + ins->altitude = Pack_EKF[EKF_for_FC].alldata.gps_high; + + ins->vel_north = Pack_EKF[EKF_for_FC].xEKF[3]; ///< Unit is meter per second, in NED axes + ins->vel_east = Pack_EKF[EKF_for_FC].xEKF[4]; + ins->vel_down = Pack_EKF[EKF_for_FC].xEKF[5]; + + ins->roll = Pack_EKF[EKF_for_FC].alldata.true_roll/ deg; ///< Unit is radian + ins->pitch = Pack_EKF[EKF_for_FC].alldata.true_pitch/ deg; + ins->yaw = Pack_EKF[EKF_for_FC].alldata.true_yaw / deg; + + ins->seq = g_ins_seq; + + /** 下面这几项待实现 */ + ins->status = 0xff; ///< working status + ///< bit0 - attitude valid + ///< bit1 - speed valid + ///< bit2 - position valid + ///< bit7 - calibration + + ins->integration_status = 0xff; ///< integration method + ///< 0 - pure Inertial mode + ///< bit0(1) - GPS assist + ///< bit1(2) - baro assist + ///< bit2(4) - radar assist + ins->BIT = 0; ///< health status 0-health; otherwise-unhealth. + + + ErrorCode[0] = 0; +#endif + } + break; + default: + break; + } +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */ +} + + diff --git a/EF3Lite/hal_led_set_wrapper.c b/EF3Lite/hal_led_set_wrapper.c new file mode 100644 index 0000000..96ed669 --- /dev/null +++ b/EF3Lite/hal_led_set_wrapper.c @@ -0,0 +1,91 @@ + +/* + * Include Files + * + */ +#if defined(MATLAB_MEX_FILE) +#include "tmwtypes.h" +#include "simstruc_types.h" +#else +#include "rtwtypes.h" +#endif + +#include "hal_api.h" + + +/* %%%-SFUNWIZ_wrapper_includes_Changes_BEGIN --- EDIT HERE TO _END */ +#ifdef HAL_IMPL +//#include "param_mgr.h" +extern void DrvNuaaHalLedConfigSet(int TailRed,int TailGreen ,int TailBlue); +#endif +#include +/* %%%-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 */ +int is_led_init[1] = 0; + +void led_set_init(uint8_t id) +{ + switch (id) + { + case 0u: + if (!is_led_init[0]) + { +#ifdef HAL_IMPL + //TODO + is_led_init[0] = 1; +#endif + } + break; + } +} +/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */ + +/* + * Start function + * + */ +void hal_led_set_Start_wrapper(const uint8_T *id, const int_T p_width0) +{ +/* %%%-SFUNWIZ_wrapper_Start_Changes_BEGIN --- EDIT HERE TO _END */ +led_set_init(id[0]); +/* %%%-SFUNWIZ_wrapper_Start_Changes_END --- EDIT HERE TO _BEGIN */ +} +/* + * Output function + * + */ +void hal_led_set_Outputs_wrapper(const HAL_led_color_t *color, + int32_T *ErrorCode, + const uint8_T *id, const int_T p_width0) +{ +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */ +/* + * set LED group *id* with *color* + * + * ErrorCode - return zero on success, otherwise nonzero on failures. + */ + ErrorCode[0] = -1; + switch (id[0]) + { + case 0u: + if (is_led_init[0]) + { +#ifdef HAL_IMPL + // TODO set led color + DrvNuaaHalLedConfigSet(color->r, color->g, color->b); + + ErrorCode[0] = 0; +#endif + } + } +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */ +} + + diff --git a/EF3Lite/hal_nvram_cancel_wrapper.c b/EF3Lite/hal_nvram_cancel_wrapper.c new file mode 100644 index 0000000..7163e9b --- /dev/null +++ b/EF3Lite/hal_nvram_cancel_wrapper.c @@ -0,0 +1,91 @@ + +/* + * 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 "hal_nvram_read.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 */ + +/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */ + +/* + * Start function + * + */ +void hal_nvram_cancel_Start_wrapper(const uint8_T *nvram_id, const int_T p_width0) +{ +/* %%%-SFUNWIZ_wrapper_Start_Changes_BEGIN --- EDIT HERE TO _END */ +#ifdef HAL_IMPL + initialize_nvram_device(nvram_id[0]); +#endif +/* %%%-SFUNWIZ_wrapper_Start_Changes_END --- EDIT HERE TO _BEGIN */ +} +/* + * Output function + * + */ +void hal_nvram_cancel_Outputs_wrapper(const uint32_T *address, + int32_T *ErrorCode, + const uint8_T *nvram_id, const int_T p_width0) +{ +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */ +#ifdef HAL_IMPL +/* **************************************** + * Cancel to read/write NAVRAM device + * this call should return immediately, so it's better to state the + * backgournd task to do the real work. + * + * inputs: + * address - Starting address to be write + * + * parameter: + * nvram_id - NV-RAM device/proxy ID + * + * outputs: + * ErrorCode - return 0 when success cancelling, otherwise return -1 + */ + ErrorCode[0] = -1; + switch (nvram_id[0]) + { + case 0: + if (is_nvram0_init) + { + //TODO + //ErrorCode[0] = 0; + } + break; + case 1: + if (is_nvram1_init) + { + //TODO + //ErrorCode[0] = 0; + } + break; + } +#else +ErrorCode[0] = 0; +#endif +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */ +} + + diff --git a/EF3Lite/hal_nvram_read_wrapper.c b/EF3Lite/hal_nvram_read_wrapper.c new file mode 100644 index 0000000..0bfc908 --- /dev/null +++ b/EF3Lite/hal_nvram_read_wrapper.c @@ -0,0 +1,126 @@ + +/* + * 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 "hal_nvram_read.h" // for parameter registration +#include "param_mgr.h" // for parameter registration + +#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 */ +#ifdef HAL_IMPL +int is_nvram0_init = 0; +int is_nvram1_init = 0; + +void initialize_nvram_device(uint8_t nvram_id) +{ +if (nvram_id == 0u && !is_nvram0_init) +{ + /* + * initialize nvram device 0 here + */ + is_nvram0_init = 1; +} +else if (nvram_id == 1u && !is_nvram1_init) +{ + /* + * initialize nvram device 1 here + */ + //is_nvram1_init = 1; +} + +} +#endif +/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */ + +/* + * Start function + * + */ +void hal_nvram_read_Start_wrapper(const uint8_T *nvram_id, const int_T p_width0) +{ +/* %%%-SFUNWIZ_wrapper_Start_Changes_BEGIN --- EDIT HERE TO _END */ +#ifdef HAL_IMPL + initialize_nvram_device(nvram_id[0]); +#endif +/* %%%-SFUNWIZ_wrapper_Start_Changes_END --- EDIT HERE TO _BEGIN */ +} +/* + * Output function + * + */ +void hal_nvram_read_Outputs_wrapper(const uint32_T *address, + const uint16_T *read_len, + uint8_T *buffer, + int32_T *ErrorCode, + const uint8_T *nvram_id, const int_T p_width0, + const int_T y_width) +{ +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */ +#ifdef HAL_IMPL +/* **************************************** + * read from NAVRAM device + * this call should return immediately, so it's better to state the + * backgournd task to do the real work. + * + * inputs: + * address - Starting address to be read + * read_len - maxium bytes to be read + * + * outputs: + * buffer - read data to buffer + * ErrorCode - return 0 when read complete, otherwise + * return remaining length when readling uncompletly, + * return -1 on genral failures. + * return -2 on busy(ocuppied). + * return -3 on cancelled. + * + * parameter: + * nvram_id - NV-RAM device/proxy ID + * + * constant: + * y_width - the size of buffer, do not write overflow. + */ + ErrorCode[0] = -1; + switch (nvram_id[0]) + { + case 0: + if (is_nvram0_init) + { + //TODO + //ErrorCode[0] = 0; + } + break; + case 1: + if (is_nvram1_init) + { + //TODO + //ErrorCode[0] = 0; + } + break; + } +#else +ErrorCode[0] = 0; +#endif +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */ +} + + diff --git a/EF3Lite/hal_nvram_write_wrapper.c b/EF3Lite/hal_nvram_write_wrapper.c new file mode 100644 index 0000000..993e03e --- /dev/null +++ b/EF3Lite/hal_nvram_write_wrapper.c @@ -0,0 +1,104 @@ + +/* + * 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 "hal_nvram_read.h" +#include "DrvComSlaver.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_nvram_write_Start_wrapper(const uint8_T *nvram_id, const int_T p_width0) +{ +/* %%%-SFUNWIZ_wrapper_Start_Changes_BEGIN --- EDIT HERE TO _END */ +#ifdef HAL_IMPL + initialize_nvram_device(nvram_id[0]); +#endif +/* %%%-SFUNWIZ_wrapper_Start_Changes_END --- EDIT HERE TO _BEGIN */ +} +/* + * Output function + * + */ +void hal_nvram_write_Outputs_wrapper(const uint8_T *buffer, + const uint32_T *address, + const uint16_T *write_len, + int32_T *ErrorCode, + const uint8_T *nvram_id, const int_T p_width0, + const int_T u_width) +{ +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */ +#ifdef HAL_IMPL +/* **************************************** + * write to NAVRAM device + * this call should return immediately, so it's better to state the + * backgournd task to do the real work. + * + * inputs: + * buffer - write data to buffer + * address - Starting address to be write + * read_len - maxium bytes to be write + * + * outputs: + * ErrorCode - return 0 when write complete, otherwise + * return remaining length when writting uncompletly, + * return -1 on genral failures. + * return -2 on busy(ocuppied). + * return -3 on cancelled. + * + * parameter: + * nvram_id - NV-RAM device/proxy ID + * + * constant: + * u_width - the size of buffer, do not write overflow. + */ + ErrorCode[0] = -1; + switch (nvram_id[0]) + { + case 0: + if (is_nvram0_init) + { + //TODO + ErrorCode[0] = 0; + NuaaHalSendToSlaver(SPECIAL_TRACK, buffer, u_width); + } + break; + case 1: + if (is_nvram1_init) + { + //TODO + //ErrorCode[0] = 0; + } + break; + } +#else +ErrorCode[0] = 0; +#endif +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */ +} + + diff --git a/EF3Lite/hal_pressure_wrapper.c b/EF3Lite/hal_pressure_wrapper.c new file mode 100644 index 0000000..38392f3 --- /dev/null +++ b/EF3Lite/hal_pressure_wrapper.c @@ -0,0 +1,126 @@ + +/* + * Include Files + * + */ +#if defined(MATLAB_MEX_FILE) +#include "tmwtypes.h" +#include "simstruc_types.h" +#else +#include "rtwtypes.h" +#endif + +#include "hal_api.h" + + +/* %%%-SFUNWIZ_wrapper_includes_Changes_BEGIN --- EDIT HERE TO _END */ +#ifdef HAL_IMPL +/* TODO include files */ +#include "AppAirSpeed.h" +#endif +#include +/* %%%-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 pres_inited[4]; + +void initialize_pressure(uint8_t id) +{ + switch (id) + { + case 0: + if (!pres_inited[0]) + { +#ifdef HAL_IMPL + // TODO initialize pressure No.0 + pres_inited[0] = 1; +#endif + } + break; + + case 1: + if (!pres_inited[1]) + { +#ifdef HAL_IMPL + // TODO initialize pressure No.0 + pres_inited[1] = 1; +#endif + } + break; + + case 2: + if (!pres_inited[2]) + { +#ifdef HAL_IMPL + // TODO initialize pressure No.0 + pres_inited[2] = 1; +#endif + } + break; + default: + break; + } +} +/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */ + +/* + * Start function + * + */ +void hal_pressure_Start_wrapper(const uint8_T *id, const int_T p_width0) +{ +/* %%%-SFUNWIZ_wrapper_Start_Changes_BEGIN --- EDIT HERE TO _END */ +initialize_pressure(id[0]); +/* %%%-SFUNWIZ_wrapper_Start_Changes_END --- EDIT HERE TO _BEGIN */ +} +/* + * Output function + * + */ +void hal_pressure_Outputs_wrapper(HAL_pressure_SI_t *pres, + int32_T *ErrorCode, + const uint8_T *id, const int_T p_width0) +{ +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */ +ErrorCode[0] = -1; + switch (id[0]) + { + case 0: + if (pres_inited[0]) + { +#ifdef HAL_IMPL + // TODO read pressure + AppQbarGetRawData(id[0], &pres->pressure, &pres->seq); + + ErrorCode[0] = 0; +#endif + } + break; + + case 1: + case 2: + case 3: + if (pres_inited[id[0]]) + { +#ifdef HAL_IMPL + // TODO read pressure + AppBaroGetRawData(id[0], &pres->pressure, &pres->temperature, &pres->seq); + + + ErrorCode[0] = 0; +#endif + } + break; + + default: + break; + } +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */ +} + + diff --git a/EF3Lite/hal_pwm_in_wrapper.c b/EF3Lite/hal_pwm_in_wrapper.c new file mode 100644 index 0000000..044a1f7 --- /dev/null +++ b/EF3Lite/hal_pwm_in_wrapper.c @@ -0,0 +1,77 @@ + +/* + * 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" +#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_pwm_in_init = 0; + +void pwm_in_init() +{ + if (!is_pwm_in_init) + { +#ifdef HAL_IMPL + //TODO + is_pwm_in_init = 1; +#endif + } +} +/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */ + +/* + * Start function + * + */ +void hal_pwm_in_Start_wrapper(void) +{ +/* %%%-SFUNWIZ_wrapper_Start_Changes_BEGIN --- EDIT HERE TO _END */ +pwm_in_init(); +/* %%%-SFUNWIZ_wrapper_Start_Changes_END --- EDIT HERE TO _BEGIN */ +} +/* + * Output function + * + */ +void hal_pwm_in_Outputs_wrapper(const uint16_T *start_idx, + uint16_T *pwm, + int32_T *ErrorCode, + const int_T y_width) +{ +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */ +ErrorCode[0] = -1; + if (is_pwm_in_init) + { +#ifdef HAL_IMPL + /* + * input *pwm* from pwm devices from *start_idx* to *start_idx*+y_width-1. + * + * ErrorCode - return zero on success, otherwise nonzero on failures. + */ + // TODO set pwm outputs + ErrorCode[0] = 0; +#endif + } +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */ +} + + diff --git a/EF3Lite/hal_pwm_out_wrapper.c b/EF3Lite/hal_pwm_out_wrapper.c new file mode 100644 index 0000000..f359b4d --- /dev/null +++ b/EF3Lite/hal_pwm_out_wrapper.c @@ -0,0 +1,112 @@ + +/* + * 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 "DrvESC.h" +#endif +#include +/* %%%-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 */ +#ifdef HAL_IMPL +void get_pwm0peroid(param_value_ptr_t p) +{ + //TODO + p.I[0] = 400u; +} + +void set_pwm0peroid(param_value_ptr_t p) +{ + uint32_t peroid_req; + peroid_req = p.I[0]; + //TODO +} +#endif + +int is_pwm_out_init = 0; + +void pwm_out_init() +{ + if (!is_pwm_out_init) + { +#ifdef HAL_IMPL + //TODO + param_prop p; + strncpy(p.name, "pwm_peroid_g0", 16); + p.val_ptr.s = NULL; + p.getter_ptr = &get_pwm0peroid; + p.setter_ptr = &set_pwm0peroid; + p.typ = PARAM_TYPE_UINT32; + param_mgr_regist(&p); + 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, othedrwise nonzero on failures. + */ + // TODO set pwm outputs + if(start_idx[0]+u_width-1 > 9) + ErrorCode[0] = 1; + else + { + for(uint8_T i = start_idx[0]; i < start_idx[0]+u_width; i++) + { + AppPwmSetValue(i, pwm[i]); + } + + ErrorCode[0] = 0; + } + +#endif + } +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */ +} + + diff --git a/EF3Lite/hal_rec_wrapper.c b/EF3Lite/hal_rec_wrapper.c new file mode 100644 index 0000000..9f8caee --- /dev/null +++ b/EF3Lite/hal_rec_wrapper.c @@ -0,0 +1,49 @@ + +/* + * 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 */ + +/* %%%-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 */ + +/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */ + +/* + * Output function + * + */ +void hal_rec_Outputs_wrapper(const uint8_T *id, + uint8_T *pkg, + uint16_T *len, + const int_T y_width) +{ +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */ +len[0] = 0; +switch (id[0]) +{ + case 1: + pkg[0] = 0xEB; + pkg[1] = 0x90; + break; +} +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */ +} + + diff --git a/EF3Lite/hal_sbus_in_wrapper.c b/EF3Lite/hal_sbus_in_wrapper.c new file mode 100644 index 0000000..daf88e3 --- /dev/null +++ b/EF3Lite/hal_sbus_in_wrapper.c @@ -0,0 +1,99 @@ + +/* + * Include Files + * + */ +#if defined(MATLAB_MEX_FILE) +#include "tmwtypes.h" +#include "simstruc_types.h" +#else +#include "rtwtypes.h" +#endif + +#include "hal_api.h" + +/* %%%-SFUNWIZ_wrapper_includes_Changes_BEGIN --- EDIT HERE TO _END */ +#ifdef HAL_IMPL +//#include "param_mgr.h" +#include "DrvSbus.h" +#endif +#include +/* %%%-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_sbus_in_init[1]; + +void sbus_input_init(uint8_t id) +{ + switch (id) + { + case 0: + if (!is_sbus_in_init[0]) + { +#ifdef HAL_IMPL + //TODO config channels, update rate, etc. and bind properties + is_sbus_in_init[0] = 1; +#endif + } + } +} +/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */ + +/* + * Start function + * + */ +void hal_sbus_in_Start_wrapper(const uint8_T *id, const int_T p_width0) +{ + /* %%%-SFUNWIZ_wrapper_Start_Changes_BEGIN --- EDIT HERE TO _END */ + sbus_input_init(id[0]); + /* %%%-SFUNWIZ_wrapper_Start_Changes_END --- EDIT HERE TO _BEGIN */ +} +/* + * Output function + * + */ +void hal_sbus_in_Outputs_wrapper(HAL_sbus_in_t *sbus, + int32_T *ErrorCode, + const uint8_T *id, const int_T p_width0) +{ + /* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */ + ErrorCode[0] = -1; + /* + * input *AI* from ADC channels from *start_idx* to *start_idx*+y_width-1. + * + * ErrorCode - return zero on success, otherwise nonzero on failures. + */ + switch (id[0]) + { + case 0u: + if (is_sbus_in_init[0]) + { +#ifdef HAL_IMPL + // TODO set sbus outputs + if(g_Hal_RCin_channels.valid & 0x01) + { + for(uint8_T i = 0; i < 19; i++) //for(uint8_T i = start_idx[0]; i < start_idx[0]+y_width; i++) + { + sbus->channels[i] = g_Hal_RCin_channels.channels[i]; + } + sbus->seq = g_Hal_RCin_channels.seq; + sbus->valid = 1; + ErrorCode[0] = 0; + } + else + { + ErrorCode[0] = 1; + sbus->valid = 0; + } +#endif + } + break; + } + /* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */ +} diff --git a/EF3Lite/hal_sen_read_wrapper.c b/EF3Lite/hal_sen_read_wrapper.c new file mode 100644 index 0000000..46593b9 --- /dev/null +++ b/EF3Lite/hal_sen_read_wrapper.c @@ -0,0 +1,275 @@ + +/* + * 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" +#endif +#include +#include +/* %%%-SFUNWIZ_wrapper_includes_Changes_END --- EDIT HERE TO _BEGIN */ + +/* + * Create external references here. + * + */ +/* %%%-SFUNWIZ_wrapper_externs_Changes_BEGIN --- EDIT HERE TO _END */ +typedef enum PROP_TYPE +{ + PROP_ARRAY_UINT8 = 1, /* 8-bit unsigned integer | */ + PROP_ARRAY_INT8 = 2, /* 8-bit signed integer | */ + PROP_ARRAY_UINT16 = 3, /* 16-bit unsigned integer | */ + PROP_ARRAY_INT16 = 4, /* 16-bit signed integer | */ + PROP_ARRAY_UINT32 = 5, /* 32-bit unsigned integer | */ + PROP_ARRAY_INT32 = 6, /* 32-bit signed integer | */ + PROP_ARRAY_REAL32 = 7, /* 32-bit floating-point | */ + PROP_FUNC_UINT8 = 8, /* 8-bit unsigned integer | */ + PROP_FUNC_INT8 = 9, /* 8-bit signed integer | */ + PROP_FUNC_UINT16 = 10, /* 16-bit unsigned integer | */ + PROP_FUNC_INT16 = 11, /* 16-bit signed integer | */ + PROP_FUNC_UINT32 = 12, /* 32-bit unsigned integer | */ + PROP_FUNC_INT32 = 13, /* 32-bit signed integer | */ + PROP_FUNC_REAL32 = 14, /* 32-bit floating-point | */ +} PROP_TYPE; + +typedef int8_t (*get_prop_b_func_ptr)(int index, void *paramter); +typedef uint8_t (*get_prop_B_func_ptr)(int index, void *paramter); +typedef int16_t (*get_prop_h_func_ptr)(int index, void *paramter); +typedef uint16_t (*get_prop_H_func_ptr)(int index, void *paramter); +typedef int32_t (*get_prop_i_func_ptr)(int index, void *paramter); +typedef uint32_t (*get_prop_I_func_ptr)(int index, void *paramter); +typedef float (*get_prop_f_func_ptr)(int index, void *paramter); + +float RPM0[4]; + +float RPM1(int index, void *paramter) +{ + (void *)paramter; + + return RPM0[index]; +} +/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */ + +/* + * Start function + * + */ +void hal_sen_read_Start_wrapper(void **pW, + const uint8_T *name, const int_T p_width0) +{ +/* %%%-SFUNWIZ_wrapper_Start_Changes_BEGIN --- EDIT HERE TO _END */ +/* initialize code to bind property; */ + int *valid = (int *)&pW[0]; /* 0-invalid; 1-valid; */ + PROP_TYPE *type = (PROP_TYPE *)&pW[1]; + int *len = (int *)&pW[2]; /* parameter length; */ + void **val_ptr = &pW[3]; /* pointer to value array */ + void **parameter = &pW[4]; /* parameter for function */ + + /* set default pW values */ + *valid = 0; + *type = 0; + *val_ptr = NULL; + *parameter = NULL; + *len = 0; + if (strncmp(name, "RPM0", p_width0)) + { + *valid = 1; + *type = PROP_ARRAY_REAL32; + *len = 4; + *val_ptr = &RPM0; + } + else if (strncmp(name, "RPM1", p_width0)) + { + *valid = 1; + *type = PROP_FUNC_REAL32; + *len = 4; + *val_ptr = &RPM1; + } +/* %%%-SFUNWIZ_wrapper_Start_Changes_END --- EDIT HERE TO _BEGIN */ +} +/* + * Output function + * + */ +void hal_sen_read_Outputs_wrapper(real32_T *value, + int32_T *ErrorCode, + void **pW, + const uint8_T *name, const int_T p_width0, + const int_T y_width) +{ +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */ +/* get binded property value; */ + ErrorCode[0] = -1; + + int *valid = (int *)&pW[0]; + if (*valid) + { + int *len = (int *)&pW[2]; + if (y_width > *len) + { + ErrorCode[0] = -2; + } + else + { + int i; + PROP_TYPE *type = (PROP_TYPE *)&pW[1]; + switch (*type) + { + case PROP_ARRAY_UINT8: + { + uint8_t *val = *(uint8_t **)&pW[3]; + for (i = 0; i < y_width; ++i) + { + value[i] = (float)val[i]; + } + ErrorCode[0] = 0; + } + break; + case PROP_ARRAY_INT8: + { + int8_t *val = *(int8_t **)&pW[3]; + for (i = 0; i < y_width; ++i) + { + value[i] = (float)val[i]; + } + ErrorCode[0] = 0; + } + break; + case PROP_ARRAY_UINT16: + { + uint16_t *val = *(uint16_t **)&pW[3]; + for (i = 0; i < y_width; ++i) + { + value[i] = (float)val[i]; + } + ErrorCode[0] = 0; + } + break; + case PROP_ARRAY_INT16: + { + int16_t *val = *(int16_t **)&pW[3]; + for (i = 0; i < y_width; ++i) + { + value[i] = (float)val[i]; + } + ErrorCode[0] = 0; + } + break; + case PROP_ARRAY_UINT32: + { + uint32_t *val = *(uint32_t **)&pW[3]; + for (i = 0; i < y_width; ++i) + { + value[i] = (float)val[i]; + } + ErrorCode[0] = 0; + } + break; + case PROP_ARRAY_INT32: + { + int32_t *val = *(int32_t **)&pW[3]; + for (i = 0; i < y_width; ++i) + { + value[i] = (float)val[i]; + } + ErrorCode[0] = 0; + } + break; + case PROP_ARRAY_REAL32: + { + float *val = *(float **)&pW[3]; + for (i = 0; i < y_width; ++i) + { + value[i] = val[i]; + } + ErrorCode[0] = 0; + } + break; + case PROP_FUNC_UINT8: + { + get_prop_B_func_ptr func = *(get_prop_B_func_ptr *)&pW[3]; + for (i = 0; i < y_width; ++i) + { + value[i] = (float)(*func)(i, pW[4]); + } + ErrorCode[0] = 0; + } + break; + case PROP_FUNC_INT8: + { + get_prop_b_func_ptr func = *(get_prop_b_func_ptr *)&pW[3]; + for (i = 0; i < y_width; ++i) + { + value[i] = (float)(*func)(i, pW[4]); + } + ErrorCode[0] = 0; + } + break; + case PROP_FUNC_UINT16: + { + get_prop_H_func_ptr func = *(get_prop_H_func_ptr *)&pW[3]; + for (i = 0; i < y_width; ++i) + { + value[i] = (float)(*func)(i, pW[4]); + } + ErrorCode[0] = 0; + } + break; + case PROP_FUNC_INT16: + { + get_prop_h_func_ptr func = *(get_prop_h_func_ptr *)&pW[3]; + for (i = 0; i < y_width; ++i) + { + value[i] = (float)(*func)(i, pW[4]); + } + ErrorCode[0] = 0; + } + break; + case PROP_FUNC_UINT32: + { + get_prop_I_func_ptr func = *(get_prop_I_func_ptr *)&pW[3]; + for (i = 0; i < y_width; ++i) + { + value[i] = (float)(*func)(i, pW[4]); + } + ErrorCode[0] = 0; + } + break; + case PROP_FUNC_INT32: + { + get_prop_i_func_ptr func = *(get_prop_i_func_ptr *)&pW[3]; + for (i = 0; i < y_width; ++i) + { + value[i] = (float)(*func)(i, pW[4]); + } + ErrorCode[0] = 0; + } + break; + case PROP_FUNC_REAL32: + { + get_prop_f_func_ptr func = *(get_prop_f_func_ptr *)&pW[3]; + for (i = 0; i < y_width; ++i) + { + value[i] = (*func)(i, pW[4]); + } + ErrorCode[0] = 0; + } + break; + } + } + } +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */ +} + + diff --git a/EF3Lite/hal_uart_in_wrapper.c b/EF3Lite/hal_uart_in_wrapper.c new file mode 100644 index 0000000..cfe9749 --- /dev/null +++ b/EF3Lite/hal_uart_in_wrapper.c @@ -0,0 +1,99 @@ + +/* + * 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 "hal_uart_init.h" +#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: + if (is_uart0_init == 2) + { + // TODO read all data from fifo + Data_len[0] = UART_RX_FIFO_read(&rs232_rx1, Data, y_width); + + ErrorCode[0] = 0; + } + break; + case 1: + if (is_uart1_init == 2) + { + // TODO read all data from fifo + Data_len[0] = UART_RX_FIFO_read(&rs422_rx2, 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/EF3Lite/hal_uart_init_wrapper.c b/EF3Lite/hal_uart_init_wrapper.c new file mode 100644 index 0000000..6422227 --- /dev/null +++ b/EF3Lite/hal_uart_init_wrapper.c @@ -0,0 +1,375 @@ + +/* + * 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 "hal_uart_init.h" +#include "param_mgr.h" // for parameter registration +#include + +/** LQH add */ +#include "uart_fifos.h" +#include "usart.h" +extern UART_HandleTypeDef huart5; +extern UART_HandleTypeDef huart6; + +#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 */ +#ifdef HAL_IMPL + +void get_uart0_baud(param_value_ptr_t p) +{ + //TODO + p.I[0] =huart6.Init.BaudRate; +} + +void set_uart0_baud(param_value_ptr_t p) +{ + uint32_t buad_req; + buad_req = p.I[0]; + + uint32_t buad_backup; + buad_backup = huart6.Init.BaudRate; + huart6.Init.BaudRate = buad_req; + if (HAL_UART_Init(&huart6) != HAL_OK) + { + huart6.Init.BaudRate = buad_backup; + Error_Handler(); + } + //TODO +} + +void get_uart0_stopbits(param_value_ptr_t p) +{ + //TODO + if(huart6.Init.StopBits == UART_STOPBITS_1) + p.B[0] =1u; + else if(huart6.Init.StopBits == UART_STOPBITS_2) + p.B[0] =2u; +} + +void set_uart0_stopbits(param_value_ptr_t p) +{ + uint8_t stopbits_req; + stopbits_req = p.B[0]; + + uint32_t stopbits_backup; + stopbits_backup = huart6.Init.StopBits; + + if(stopbits_req == 1) + huart6.Init.StopBits = UART_STOPBITS_1; + else if(stopbits_req == 2) + huart6.Init.StopBits = UART_STOPBITS_2; + else + huart6.Init.StopBits = UART_STOPBITS_1; + + if (HAL_UART_Init(&huart6) != HAL_OK) + { + huart6.Init.StopBits = stopbits_backup; + Error_Handler(); + } + //TODO +} + +void get_uart0_wordlen(param_value_ptr_t p) +{ + //TODO + if(huart6.Init.WordLength == UART_WORDLENGTH_7B) + p.B[0] =7u; + else if(huart6.Init.WordLength == UART_WORDLENGTH_8B) + p.B[0] =8u; + else if(huart6.Init.WordLength == UART_WORDLENGTH_9B) + p.B[0] =9u; +} + +void set_uart0_wordlen(param_value_ptr_t p) +{ + uint8_t wordlen_req; + wordlen_req = p.B[0]; + + uint32_t wordlen_backup; + wordlen_backup = huart6.Init.WordLength; + + if(wordlen_req == 7) + huart6.Init.WordLength = UART_WORDLENGTH_7B; + else if(wordlen_req == 8) + huart6.Init.WordLength = UART_WORDLENGTH_8B; + else if(wordlen_req == 9) + huart6.Init.WordLength = UART_WORDLENGTH_9B; + else + huart6.Init.WordLength = UART_WORDLENGTH_8B; + + if (HAL_UART_Init(&huart6) != HAL_OK) + { + huart6.Init.WordLength = wordlen_backup; + Error_Handler(); + } + //TODO +} + +void get_uart0_parity(param_value_ptr_t p) +{ + //TODO + if(huart6.Init.Parity == UART_PARITY_NONE) + p.B[0] =0u; + else if(huart6.Init.Parity == UART_PARITY_ODD) + p.B[0] =1u; + else if(huart6.Init.Parity == UART_PARITY_EVEN) + p.B[0] =2u; +} + +void set_uart0_parity(param_value_ptr_t p) +{ + uint8_t parity_req; + parity_req = p.B[0]; + + uint32_t parity_backup; + parity_backup = huart6.Init.Parity; + + if(parity_req == 0) + huart6.Init.Parity = UART_PARITY_NONE; + else if(parity_req == 1) + huart6.Init.Parity = UART_PARITY_ODD; + else if(parity_req == 2) + huart6.Init.Parity = UART_PARITY_EVEN; + else + huart6.Init.Parity = UART_PARITY_NONE; + + if (HAL_UART_Init(&huart6) != HAL_OK) + { + huart6.Init.Parity = parity_backup; + Error_Handler(); + } + //TODO +} + +int is_uart0_init = 0; +int is_uart1_init = 0; + +void initialize_uart_device(uint8_t nvram_id) +{ +if (nvram_id == 0u && is_uart0_init == 0) +{ + /* + * initialize uart device 0 here + */ + + // bind property to config functions + param_prop p; + strncpy(p.name, "uart0_baud", 16); + p.val_ptr.s = NULL; + p.getter_ptr = &get_uart0_baud; + p.setter_ptr = &set_uart0_baud; + p.typ = PARAM_TYPE_UINT32; + param_mgr_regist(&p); + + strncpy(p.name, "uart0_stopbits", 16); + p.getter_ptr = &get_uart0_stopbits; + p.setter_ptr = &set_uart0_stopbits; + p.typ = PARAM_TYPE_UINT8; + param_mgr_regist(&p); + + strncpy(p.name, "uart0_wordlen", 16); + p.getter_ptr = &get_uart0_wordlen; + p.setter_ptr = &set_uart0_wordlen; + p.typ = PARAM_TYPE_UINT8; + param_mgr_regist(&p); + + strncpy(p.name, "uart0_parity", 16); + p.getter_ptr = &get_uart0_parity; + p.setter_ptr = &set_uart0_parity; + p.typ = PARAM_TYPE_UINT8; + param_mgr_regist(&p); + + is_uart0_init = 1; // initialized +} +else if (nvram_id == 1u && is_uart1_init == 0) +{ + /* + * initialize uart device 1 here + */ + is_uart1_init = 0; //TODO not initialized, change to 1 when done +} + +} +#endif +/* %%%-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 */ +#ifdef HAL_IMPL + initialize_uart_device(uart_id[0]); +#endif +/* %%%-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: + if (is_uart0_init == 1) // init + { + huart6.Instance = USART6; + huart6.Init.BaudRate = baudrate[0]; + if(wordlen[0] == 7) + huart6.Init.WordLength = UART_WORDLENGTH_7B; + else if(wordlen[0] == 8) + huart6.Init.WordLength = UART_WORDLENGTH_8B; + else if(wordlen[0] == 9) + huart6.Init.WordLength = UART_WORDLENGTH_9B; + else + huart6.Init.WordLength = UART_WORDLENGTH_8B; + + if(stopbits[0] == 1) + huart6.Init.StopBits = UART_STOPBITS_1; + else if(stopbits[0] == 2) + huart6.Init.StopBits = UART_STOPBITS_2; + else + huart6.Init.StopBits = UART_STOPBITS_1; + + if(parity[0] == 0) + huart6.Init.Parity = UART_PARITY_NONE; + else if(parity[0] == 1) + huart6.Init.Parity = UART_PARITY_ODD; + else if(parity[0] == 2) + huart6.Init.Parity = UART_PARITY_EVEN; + else + huart6.Init.Parity = UART_PARITY_NONE; + + if (HAL_UART_Init(&huart6) != HAL_OK) + { + Error_Handler(); + } + + //TODO config uart0 fifo + static uint8_T uart0_fifo_set_flag = 1; //保护fifo只注册一次 + if(uart0_fifo_set_flag) + { + uart0_fifo_set_flag = 0; + UART_RX_FIFO_open(&rs232_rx1,&huart6,buff_rx[0],UART_FIFO_DMA); + UART_TX_FIFO_open(&rs232_tx1,&huart6,buff_tx[0],UART_FIFO_DMA); + } + + is_uart0_init = 2; // init done + ErrCode[0] = 0; + } + break; + case 1: + if (is_uart1_init == 1) + { + huart5.Instance = UART5; + huart5.Init.BaudRate = baudrate[0]; + if(wordlen[0] == 7) + huart5.Init.WordLength = UART_WORDLENGTH_7B; + else if(wordlen[0] == 8) + huart5.Init.WordLength = UART_WORDLENGTH_8B; + else if(wordlen[0] == 9) + huart5.Init.WordLength = UART_WORDLENGTH_9B; + else + huart5.Init.WordLength = UART_WORDLENGTH_8B; + + if(stopbits[0] == 1) + huart5.Init.StopBits = UART_STOPBITS_1; + else if(stopbits[0] == 2) + huart5.Init.StopBits = UART_STOPBITS_2; + else + huart5.Init.StopBits = UART_STOPBITS_1; + + if(parity[0] == 0) + huart5.Init.Parity = UART_PARITY_NONE; + else if(parity[0] == 1) + huart5.Init.Parity = UART_PARITY_ODD; + else if(parity[0] == 2) + huart5.Init.Parity = UART_PARITY_EVEN; + else + huart5.Init.Parity = UART_PARITY_NONE; + + if (HAL_UART_Init(&huart5) != HAL_OK) + { + Error_Handler(); + } + //TODO config uart1 fifo + static uint8_T uart1_fifo_set_flag = 1; + if(uart1_fifo_set_flag) + { + uart1_fifo_set_flag = 0; + UART_RX_FIFO_open(&rs422_rx2,&huart5,buff_rx[0],UART_FIFO_DMA); + UART_TX_FIFO_open(&rs422_tx2,&huart5,buff_tx[0],UART_FIFO_IT); + } + + is_uart1_init = 2; // init done + ErrCode[0] = 0; + } + break; + case 2: + break; + case 3: + break; + } +#else +/* dummy function for generate mex file for sim*/ +ErrCode[0] = 0; +#endif +/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */ +} + + diff --git a/EF3Lite/hal_uart_out_wrapper.c b/EF3Lite/hal_uart_out_wrapper.c new file mode 100644 index 0000000..6378762 --- /dev/null +++ b/EF3Lite/hal_uart_out_wrapper.c @@ -0,0 +1,98 @@ + +/* + * 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 "hal_uart_init.h" +#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(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; + switch (uart_id[0]) + { + case 0: + if (is_uart0_init == 2) + { + // TODO write all data to fifo + UART_TX_FIFO_write(&rs232_tx1, buff, len[0]); + ErrorCode[0] = 0; + } + break; + case 1: + if (is_uart1_init == 2) + { + // TODO write all data to fifo + UART_TX_FIFO_write(&rs422_tx2, buff, len[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 */ +} + +