diff --git a/pel.c b/pel.c index e4de549..3c3307a 100644 --- a/pel.c +++ b/pel.c @@ -86,12 +86,6 @@ static void set_resistor_load_bits(uint32_t mask) load_config.resistor.pattern_index = 0; load_config.resistor.resistor_mask = mask; load_config.resistor.resistor_conductance = _load_set(load_config.resistor.resistor_mask); - - { - char str[128]; - snprintf(str, sizeof(str), "pattern_index[%d] = resistor_mask:0x%08X, resistor_conductance = %.7f", load_config.resistor.pattern_index, load_config.resistor.resistor_mask, load_config.resistor.resistor_conductance); - NRF_LOG_INFO("%s", str); - } } static void set_resistor_load_pattern(uint32_t index) @@ -150,12 +144,6 @@ static void set_resistor_load_pattern(uint32_t index) load_config.resistor.pattern_index = index; load_config.resistor.resistor_mask = pattern_tab[i].resistor_mask; load_config.resistor.resistor_conductance = _load_set(load_config.resistor.resistor_mask); - - { - char str[128]; - snprintf(str, sizeof(str), "pattern_index[%d] = resistor_mask:0x%08X, resistor_conductance = %.7f", load_config.resistor.pattern_index, load_config.resistor.resistor_mask, load_config.resistor.resistor_conductance); - NRF_LOG_INFO("%s", str); - } break; } } @@ -228,26 +216,25 @@ static void cis_version(uint8_t *ins, uint16_t size) le_data_update((void *)cis_ver, sizeof(cis_ver)); } -static void send_start_package(pel20_notify_packet1_t *packet_buf, uint32_t packet_len) +static void send_start_package(void *packet_buf, uint32_t packet_len) { + NRF_LOG_INFO(__FUNCTION__); + for (uint32_t i = 0; i < 4; i++) { ret_code_t le_event_notify(uint8_t * p_value, uint16_t len); nrf_gpio_pin_set(TP2_PIN); - ret_code_t ret = le_event_notify((void *)packet_buf, packet_len); + ret_code_t ret = le_event_notify(packet_buf, packet_len); nrf_gpio_pin_clear(TP2_PIN); vTaskDelay(pdMS_TO_TICKS(10)); - { - char str[128]; - snprintf(str, sizeof(str), "{%d, %lu, %d, %lu, %lu, %lu, %lu, %lu, %.7f, %.7f, %.7f, %.7f, %.7f, %d, 0x%08lX}", packet_buf->mem_board_id, packet_buf->notify_time, packet_buf->packet_seq, packet_buf->val_1, packet_buf->val_2, packet_buf->val_3, packet_buf->val_4, packet_buf->val_5, packet_buf->val_1_f, packet_buf->val_2_f, packet_buf->val_3_f, packet_buf->val_4_f, packet_buf->val_5_f, packet_buf->pattern_id, packet_buf->pattern); - NRF_LOG_INFO("%s", str); - } + NRF_LOG_HEXDUMP_INFO(packet_buf, packet_len); + NRF_LOG_INFO("\n"); } } -static void pel_scan_mode_notify(pel20_notify_packet1_t *packet_buf, uint32_t packet_len) +static void pel_scan_mode_notify(scan_mode_notify_packet_t *packet_buf, uint32_t packet_len) { int32_t adc_raw[COUNTOF(pel_hw.adc.results)] = { 0 }; @@ -259,25 +246,22 @@ static void pel_scan_mode_notify(pel20_notify_packet1_t *packet_buf, uint32_t pa adc_read_mutiple_channels_convert_milivolt(adc_raw, pel_hw.adc.results_f, COUNTOF(pel_hw.adc.channels)); packet_buf->mem_board_id = global_memoryboard_id; - packet_buf->notify_time = xTaskGetTickCount(); packet_buf->packet_seq++; - packet_buf->val_1 = pel_hw.adc.results[0]; - packet_buf->val_2 = pel_hw.adc.results[1]; - packet_buf->val_3 = pel_hw.adc.results[2]; - packet_buf->val_4 = pel_hw.adc.results[3]; - packet_buf->val_5 = pel_hw.adc.results[4]; - packet_buf->val_1_f = 0; - packet_buf->val_2_f = load_config.resistor.resistor_conductance; - packet_buf->val_3_f = pel_hw.adc.results_f[2] * 10 / 1000; // OUT[V] - packet_buf->val_4_f = pel_hw.adc.results_f[3] * 10 / 1000; // VCC[V] - packet_buf->val_5_f = pel_hw.adc.results_f[4] * 10 / 1000; // VEE[V] - packet_buf->pattern_id = load_config.resistor.pattern_index; - packet_buf->pattern = load_config.resistor.resistor_mask; - ret_code_t ret = le_event_async_notify((void *)packet_buf, packet_len, pdMS_TO_TICKS(5)); + packet_buf->notify_time = xTaskGetTickCount(); + packet_buf->output_vo_raw = pel_hw.adc.results[2]; + packet_buf->output_vc_raw = pel_hw.adc.results[3]; + packet_buf->output_ve_raw = pel_hw.adc.results[4]; + packet_buf->hold_OUT_v = pel_hw.adc.results_f[2] * 10 / 1000; + packet_buf->hold_VCC_v = pel_hw.adc.results_f[3] * 10 / 1000; + packet_buf->hold_VEE_v = pel_hw.adc.results_f[4] * 10 / 1000; + packet_buf->resis_pattern_id = load_config.resistor.pattern_index; + packet_buf->resis_bitsmask = load_config.resistor.resistor_mask; + packet_buf->resis_g_value = load_config.resistor.resistor_conductance; + ret_code_t ret = le_event_async_notify((void *)packet_buf, packet_len, pdMS_TO_TICKS(5)); { char str[128]; - snprintf(str, sizeof(str), "{%d, %lu, %d, %lu, %lu, %lu, %lu, %lu, %.7f, %.7f, %.7f, %.7f, %.7f, %d, 0x%08lX}", packet_buf->mem_board_id, packet_buf->notify_time, packet_buf->packet_seq, packet_buf->val_1, packet_buf->val_2, packet_buf->val_3, packet_buf->val_4, packet_buf->val_5, packet_buf->val_1_f, packet_buf->val_2_f, packet_buf->val_3_f, packet_buf->val_4_f, packet_buf->val_5_f, packet_buf->pattern_id, packet_buf->pattern); + snprintf(str, sizeof(str), "{%3d, %3d, %10lu, %10lu, %10lu, %10lu, %2.7f, %2.7f, %2.7f, %5d, 0x%04X, %.7f, %d}", packet_buf->mem_board_id, packet_buf->packet_seq, packet_buf->notify_time, packet_buf->output_vo_raw, packet_buf->output_vc_raw, packet_buf->output_ve_raw, packet_buf->hold_OUT_v, packet_buf->hold_VCC_v, packet_buf->hold_VEE_v, packet_buf->resis_pattern_id, packet_buf->resis_bitsmask, packet_buf->resis_g_value, packet_buf->mode_complete); NRF_LOG_INFO("%s", str); } } @@ -466,7 +450,7 @@ static void pel_pulse_notify(void *p_arg) notify_setting_t *p_setting = p_arg; - static pel20_notify_packet1_t packet_buf = { 0 }; + static scan_mode_notify_packet_t packet_buf = { 0 }; xSemaphoreTake(adc_convt_cplt_sem, 0); @@ -566,7 +550,7 @@ static void manual_scan_mode(uint8_t *ins, uint16_t size) global_memoryboard_id = p_ins->id; static pel_scan_msg_t pel_scan_msg; - pel20_notify_packet1_t packet_buf = { 0 }; + scan_mode_notify_packet_t packet_buf = { 0 }; switch (p_ins->opcode) { @@ -582,7 +566,7 @@ static void manual_scan_mode(uint8_t *ins, uint16_t size) // manual_scan_mode start // 30 00 01 01 00 01 00 05 00 0A 00 03 (pattern_index) // 30 00 01 01 00 00 00 F0 00 0A 00 03 (resistor_mask) - send_start_package(&packet_buf, sizeof(packet_buf)); + send_start_package((void *)&packet_buf, sizeof(packet_buf)); pel_scan_msg.opcode = PEL_START; pel_scan_msg.resistor_setting.is_pattern = u8_to_u16(p_ins->param[0], p_ins->param[1]) & 0x01; pel_scan_msg.resistor_setting.value = u8_to_u16(p_ins->param[2], p_ins->param[3]); @@ -641,7 +625,7 @@ static void auto_scan_mode(uint8_t *ins, uint16_t size) global_memoryboard_id = p_ins->id; static pel_scan_msg_t pel_scan_msg; - pel20_notify_packet1_t packet_buf = { 0 }; + scan_mode_notify_packet_t packet_buf = { 0 }; switch (p_ins->opcode) { @@ -659,7 +643,7 @@ static void auto_scan_mode(uint8_t *ins, uint16_t size) uint16_t pattern_max = u8_to_u16(p_ins->param[0], p_ins->param[1]); uint16_t pattern_min = u8_to_u16(p_ins->param[2], p_ins->param[3]); - send_start_package(&packet_buf, sizeof(packet_buf)); + send_start_package((void *)&packet_buf, sizeof(packet_buf)); for (uint16_t i = pattern_max; i >= pattern_min; i--) { @@ -733,7 +717,7 @@ static void R_external_calibration_mode(uint8_t *ins, uint16_t size) global_memoryboard_id = p_ins->id; static pel_scan_msg_t pel_scan_msg; - pel20_notify_packet1_t packet_buf = { 0 }; + scan_mode_notify_packet_t packet_buf = { 0 }; switch (p_ins->opcode) { @@ -746,7 +730,7 @@ static void R_external_calibration_mode(uint8_t *ins, uint16_t size) case 0x01: { // R_external_calibration_mode start with drop n * 10ms // 30 00 03 01 00 0A 00 05 - send_start_package(&packet_buf, sizeof(packet_buf)); + send_start_package((void *)&packet_buf, sizeof(packet_buf)); for (uint16_t i = 0; i < COUNTOF(calibration_bits_pattern_tab); i++) { diff --git a/pel.h b/pel.h index 3edc50a..be71090 100644 --- a/pel.h +++ b/pel.h @@ -12,9 +12,9 @@ extern "C" #define VERSION_DATE_YEAR 25 #define VERSION_DATE_MONTH 3 -#define VERSION_DATE_DAY 13 -#define VERSION_DATE_HOUR 13 -#define VERSION_DATE_MINUTE 0 +#define VERSION_DATE_DAY 17 +#define VERSION_DATE_HOUR 16 +#define VERSION_DATE_MINUTE 36 #define PEL_0P5R_MASK (0x01 << 0) #define PEL_1P0R_MASK (0x01 << 1) @@ -29,33 +29,26 @@ extern "C" #define PEL_511R_MASK (0x01 << 10) #define PEL_1000R_MASK (0x01 << 11) - typedef struct - { - int32_t output_r1; - int32_t output_r2; - int32_t output_vo; - int32_t output_vc; - int32_t output_ve; - } pel_output_t; - typedef struct __PACKED { - uint8_t mem_board_id; + uint16_t mem_board_id : 8; + uint16_t packet_seq : 8; uint32_t notify_time; - uint8_t packet_seq; + int32_t output_vo_raw; + int32_t output_vc_raw; + int32_t output_ve_raw; + float hold_OUT_v; + float hold_VCC_v; + float hold_VEE_v; + uint16_t resis_pattern_id; + uint16_t resis_bitsmask; + float resis_g_value; + uint32_t mode_complete : 4; + uint32_t rsvd : 28; int32_t val_1; int32_t val_2; - int32_t val_3; - int32_t val_4; - int32_t val_5; - float val_1_f; - float val_2_f; - float val_3_f; - float val_4_f; - float val_5_f; - uint16_t pattern_id; - uint32_t pattern; - } pel20_notify_packet1_t; + int16_t val_3; + } scan_mode_notify_packet_t; const elite_instance_t *pel_init(void);