From 0f6c308570e896309bff79dc01ceb04545d3189c Mon Sep 17 00:00:00 2001 From: Roy_01 Date: Thu, 16 Jan 2025 17:47:30 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=BF=AB=E9=80=9Fdemo=E4=BD=BF=E7=94=A8,?= =?UTF-8?q?=20=E6=9C=AA=E4=BE=86=E4=B8=8D=E5=86=8D=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E9=80=99=E5=80=8B=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pel.c | 73 ++++++++++++++++++++++++++++++++++++++---------------- pel.h | 1 - pel20_io.c | 6 +++++ 3 files changed, 58 insertions(+), 22 deletions(-) diff --git a/pel.c b/pel.c index 4bf5237..6913e94 100644 --- a/pel.c +++ b/pel.c @@ -227,22 +227,6 @@ static void _sample_measure_out_is_high(void) nrf_gpio_pin_toggle(ANODE_PIN); } -void pel_relays_set(uint32_t measure_out) -{ - if (measure_out) - { - nrf_gpio_pin_set(RELAY1_PIN); - nrf_gpio_pin_clear(RELAY2_PIN); - } - else - { - nrf_gpio_pin_clear(RELAY1_PIN); - nrf_gpio_pin_set(RELAY2_PIN); - } - /* delay 30ms */ - vTaskDelay(pdMS_TO_TICKS(30)); -} - pel_output_t pel_smaple_and_convt_all(uint32_t measure_out, uint32_t load_mask) { uint32_t ch_list[] = { @@ -333,9 +317,7 @@ void test_gpio_task(void *pArg) ANODE_PIN, CATHODE_PIN, SAMPLE_R_PIN, - SAMPLE_V_PIN, - RELAY1_PIN, - RELAY2_PIN + SAMPLE_V_PIN }; for (;;) @@ -375,14 +357,19 @@ static void decode_and_set_resistor_pattern(uint8_t *param) { uint16_t pattern_id = u8_to_u16(param[0], param[1]); + nrf_gpio_pin_set(RELAY1_PIN); set_pattern_resistor(pattern_id); + nrf_gpio_pin_clear(RELAY1_PIN); } static void decode_and_set_manual_resistor(uint8_t *param) { uint16_t manual_val = u8_to_u16(param[0], param[1]); + + nrf_gpio_pin_set(RELAY1_PIN); set_manual_resistor(manual_val); + nrf_gpio_pin_clear(RELAY1_PIN); } static void dev_mode_input_resistor(uint8_t *ins) @@ -697,7 +684,9 @@ static ret_code_t _send_event_char_notify_start_packet(void *p_buf, uint16_t p_b for (uint32_t i = 0; i < loops; 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 *)p_buf, p_buf_size); + nrf_gpio_pin_clear(TP2_PIN); if (ret != NRF_SUCCESS) { @@ -954,8 +943,9 @@ static void send_resis_and_sample_and_hold_data(void *p_arg) } 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, sizeof(packet_buf)); - + nrf_gpio_pin_clear(TP2_PIN); NRF_LOG_INFO("sizeof(packet_buf) %d", sizeof(packet_buf)); { @@ -1023,7 +1013,40 @@ void stop_sample_and_hold_pulse_task(void) event_char_notify_running = false; } -static void dev_mode_sample_and_hold_pulse_task(uint8_t *ins) +void dev_mode_sample_and_hold_pulse_task(uint8_t *ins); +void run_sample_and_hold_pulse_scanner_task(uint8_t *param) +{ + uint8_t start_ins[] = { 0x34, 0x00, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x0A}; + uint8_t stop_ins[] = { 0x34, 0x00, 0xFF, 0x01, 0x01}; + uint8_t set_resistor_ins[] = { 0x34, 0x00, 0xFF, 0x00, 0x01, 0x00, 0x00}; + uint16_t resistor_max = u8_to_u16(param[0], param[1]); + uint16_t resistor_min = u8_to_u16(param[2], param[3]); + uint16_t resistor_value = resistor_max; + + /*start*/ + set_resistor_ins[6] = resistor_value; + dev_mode_input_resistor(set_resistor_ins); + dev_mode_sample_and_hold_pulse_task(start_ins); + vTaskDelay(pdMS_TO_TICKS(100)); + + + /*change resistor*/ + while (resistor_value > resistor_min) + { + resistor_value--; + set_resistor_ins[6] = resistor_value; + dev_mode_sample_and_hold_pulse_task(stop_ins); + vTaskDelay(pdMS_TO_TICKS(10)); + dev_mode_input_resistor(set_resistor_ins); + dev_mode_sample_and_hold_pulse_task(start_ins); + vTaskDelay(pdMS_TO_TICKS(90)); + } + + /*stop*/ + dev_mode_sample_and_hold_pulse_task(stop_ins); +} + +void dev_mode_sample_and_hold_pulse_task(uint8_t *ins) { NRF_LOG_INFO("[DEV MODE] %s", __FUNCTION__); @@ -1048,6 +1071,10 @@ static void dev_mode_sample_and_hold_pulse_task(uint8_t *ins) stop_sample_and_hold_pulse_task(); break; + case 0x02: + run_sample_and_hold_pulse_scanner_task(p_ins->param); + break; + default: break; } @@ -1103,6 +1130,10 @@ const elite_instance_t *pel_init(void) { NRF_LOG_INFO("[Board] %s", BOARD_IOPx ? "IOPH" : "IOPL"); + uint8_t scan_ins[] = { 0x30, 0x00, 0xFF, 0x01, 0x02, 0x00, 0x2B, 0x00, 0x01}; + dev_mode_sample_and_hold_pulse_task(scan_ins); + + return &pel_elite_instance; } diff --git a/pel.h b/pel.h index 3324e89..f819837 100644 --- a/pel.h +++ b/pel.h @@ -31,7 +31,6 @@ typedef struct int32_t output_ve; } pel_output_t; -void pel_relays_set(uint32_t measure_out); pel_output_t pel_smaple_and_convt_all(uint32_t measure_out, uint32_t load_mask); const elite_instance_t *pel_init(void); diff --git a/pel20_io.c b/pel20_io.c index 1ba6f7f..34e464f 100644 --- a/pel20_io.c +++ b/pel20_io.c @@ -101,6 +101,8 @@ void set_anode_cathode_to_default(void) nrf_gpio_pin_clear(SAMPLE_R_PIN); nrf_gpio_pin_clear(SAMPLE_V_PIN); nrf_gpio_pin_clear(TP1_PIN); + nrf_gpio_pin_clear(TP2_PIN); + nrf_gpio_pin_clear(RELAY1_PIN); } else if (BOARD_IOPx == BOARD_IOPH) { @@ -109,6 +111,8 @@ void set_anode_cathode_to_default(void) nrf_gpio_pin_clear(SAMPLE_R_PIN); nrf_gpio_pin_clear(SAMPLE_V_PIN); nrf_gpio_pin_clear(TP1_PIN); + nrf_gpio_pin_clear(TP2_PIN); + nrf_gpio_pin_clear(RELAY1_PIN); } } @@ -372,6 +376,8 @@ void pel20_io_init(void) nrf_gpio_cfg_output(SAMPLE_R_PIN); nrf_gpio_cfg_output(SAMPLE_V_PIN); nrf_gpio_cfg_output(TP1_PIN); + nrf_gpio_cfg_output(TP2_PIN); + nrf_gpio_cfg_output(RELAY1_PIN); // Config spi module From bcf9bf46e2366cb5c0ab36f8420715d4f66289a7 Mon Sep 17 00:00:00 2001 From: Roy_01 Date: Wed, 22 Jan 2025 13:15:28 +0800 Subject: [PATCH 2/4] =?UTF-8?q?demo:=20=E5=BF=AB=E9=80=9Fdemo=E7=89=88?= =?UTF-8?q?=E6=9C=AC=20[IOPH]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pel.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/pel.c b/pel.c index 6913e94..3167dd2 100644 --- a/pel.c +++ b/pel.c @@ -276,9 +276,9 @@ pel_output_t pel_smaple_and_convt_all(uint32_t measure_out, uint32_t load_mask) #define VERSION_DATE_YEAR 25 #define VERSION_DATE_MONTH 1 -#define VERSION_DATE_DAY 6 -#define VERSION_DATE_HOUR 15 -#define VERSION_DATE_MINUTE 47 +#define VERSION_DATE_DAY 22 +#define VERSION_DATE_HOUR 13 +#define VERSION_DATE_MINUTE 15 static void cis_version(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); @@ -366,7 +366,6 @@ static void decode_and_set_manual_resistor(uint8_t *param) { uint16_t manual_val = u8_to_u16(param[0], param[1]); - nrf_gpio_pin_set(RELAY1_PIN); set_manual_resistor(manual_val); nrf_gpio_pin_clear(RELAY1_PIN); @@ -1016,12 +1015,12 @@ void stop_sample_and_hold_pulse_task(void) void dev_mode_sample_and_hold_pulse_task(uint8_t *ins); void run_sample_and_hold_pulse_scanner_task(uint8_t *param) { - uint8_t start_ins[] = { 0x34, 0x00, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x0A}; - uint8_t stop_ins[] = { 0x34, 0x00, 0xFF, 0x01, 0x01}; - uint8_t set_resistor_ins[] = { 0x34, 0x00, 0xFF, 0x00, 0x01, 0x00, 0x00}; - uint16_t resistor_max = u8_to_u16(param[0], param[1]); - uint16_t resistor_min = u8_to_u16(param[2], param[3]); - uint16_t resistor_value = resistor_max; + uint8_t start_ins[] = { 0x34, 0x00, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x0A }; + uint8_t stop_ins[] = { 0x34, 0x00, 0xFF, 0x01, 0x01 }; + uint8_t set_resistor_ins[] = { 0x34, 0x00, 0xFF, 0x00, 0x01, 0x00, 0x00 }; + uint16_t resistor_max = u8_to_u16(param[0], param[1]); + uint16_t resistor_min = u8_to_u16(param[2], param[3]); + uint16_t resistor_value = resistor_max; /*start*/ set_resistor_ins[6] = resistor_value; @@ -1029,7 +1028,6 @@ void run_sample_and_hold_pulse_scanner_task(uint8_t *param) dev_mode_sample_and_hold_pulse_task(start_ins); vTaskDelay(pdMS_TO_TICKS(100)); - /*change resistor*/ while (resistor_value > resistor_min) { @@ -1130,9 +1128,8 @@ const elite_instance_t *pel_init(void) { NRF_LOG_INFO("[Board] %s", BOARD_IOPx ? "IOPH" : "IOPL"); - uint8_t scan_ins[] = { 0x30, 0x00, 0xFF, 0x01, 0x02, 0x00, 0x2B, 0x00, 0x01}; - dev_mode_sample_and_hold_pulse_task(scan_ins); - + // uint8_t scan_ins[] = { 0x30, 0x00, 0xFF, 0x01, 0x02, 0x00, 0x2B, 0x00, 0x01}; + // dev_mode_sample_and_hold_pulse_task(scan_ins); return &pel_elite_instance; } From 203a0c0c87f33f77734adee01fb74c8fa97b5391 Mon Sep 17 00:00:00 2001 From: Roy_01 Date: Thu, 23 Jan 2025 16:28:16 +0800 Subject: [PATCH 3/4] fix: fix warning --- pel.c | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/pel.c b/pel.c index 3167dd2..22bc7db 100644 --- a/pel.c +++ b/pel.c @@ -276,9 +276,9 @@ pel_output_t pel_smaple_and_convt_all(uint32_t measure_out, uint32_t load_mask) #define VERSION_DATE_YEAR 25 #define VERSION_DATE_MONTH 1 -#define VERSION_DATE_DAY 22 -#define VERSION_DATE_HOUR 13 -#define VERSION_DATE_MINUTE 15 +#define VERSION_DATE_DAY 23 +#define VERSION_DATE_HOUR 16 +#define VERSION_DATE_MINUTE 28 static void cis_version(uint8_t *ins, uint16_t size) { NRF_LOG_INFO("%s", __FUNCTION__); @@ -438,26 +438,26 @@ static void data_char_update_once(void) { char str[128]; - snprintf(str, sizeof(str), "val_1: 0x%08X, %d", data.val_1, data.val_1); + snprintf(str, sizeof(str), "val_1: 0x%08lX, %ld", data.val_1, data.val_1); NRF_LOG_INFO("%s", str); - snprintf(str, sizeof(str), "val_2: 0x%08X, %d", data.val_2, data.val_2); + snprintf(str, sizeof(str), "val_2: 0x%08lX, %ld", data.val_2, data.val_2); NRF_LOG_INFO("%s", str); - snprintf(str, sizeof(str), "val_3: 0x%08X, %d", data.val_3, data.val_3); + snprintf(str, sizeof(str), "val_3: 0x%08lX, %ld", data.val_3, data.val_3); NRF_LOG_INFO("%s", str); - snprintf(str, sizeof(str), "val_4: 0x%08X, %d", data.val_4, data.val_4); + snprintf(str, sizeof(str), "val_4: 0x%08lX, %ld", data.val_4, data.val_4); NRF_LOG_INFO("%s", str); - snprintf(str, sizeof(str), "val_5: 0x%08X, %d", data.val_5, data.val_5); + snprintf(str, sizeof(str), "val_5: 0x%08lX, %ld", data.val_5, data.val_5); NRF_LOG_INFO("%s", str); - snprintf(str, sizeof(str), "val_6_f: %.7f", data.val_6_f, data.val_6_f); + snprintf(str, sizeof(str), "val_6_f: %.7f", data.val_6_f); NRF_LOG_INFO("%s", str); - snprintf(str, sizeof(str), "val_7_f: %.7f", data.val_7_f, data.val_7_f); + snprintf(str, sizeof(str), "val_7_f: %.7f", data.val_7_f); NRF_LOG_INFO("%s", str); - snprintf(str, sizeof(str), "val_8_f: %.7f", data.val_8_f, data.val_8_f); + snprintf(str, sizeof(str), "val_8_f: %.7f", data.val_8_f); NRF_LOG_INFO("%s", str); - snprintf(str, sizeof(str), "val_9_f: %.7f", data.val_9_f, data.val_9_f); + snprintf(str, sizeof(str), "val_9_f: %.7f", data.val_9_f); NRF_LOG_INFO("%s", str); - snprintf(str, sizeof(str), "val_10_f: %.7f", data.val_10_f, data.val_10_f); + snprintf(str, sizeof(str), "val_10_f: %.7f", data.val_10_f); NRF_LOG_INFO("%s", str); } @@ -569,7 +569,7 @@ static void start_data_char_notify_task(void *p_arg) { char str[128]; - snprintf(str, sizeof(str), "{%d, %d, %d, %d, %d, %d, %d, %d, %.7f, %.7f, %.7f, %.7f, %.7f, %d, 0x%08X}", 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_6_f, packet_buf.val_7_f, packet_buf.val_8_f, packet_buf.val_9_f, packet_buf.val_10_f, packet_buf.pattern_id, packet_buf.pattern); + 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_6_f, packet_buf.val_7_f, packet_buf.val_8_f, packet_buf.val_9_f, packet_buf.val_10_f, packet_buf.pattern_id, packet_buf.pattern); NRF_LOG_INFO("%s", str); } @@ -639,26 +639,26 @@ static void event_char_update_once(void) { char str[128]; - snprintf(str, sizeof(str), "val_1: 0x%08X, %d", data.val_1, data.val_1); + snprintf(str, sizeof(str), "val_1: 0x%08lX, %ld", data.val_1, data.val_1); NRF_LOG_INFO("%s", str); - snprintf(str, sizeof(str), "val_2: 0x%08X, %d", data.val_2, data.val_2); + snprintf(str, sizeof(str), "val_2: 0x%08lX, %ld", data.val_2, data.val_2); NRF_LOG_INFO("%s", str); - snprintf(str, sizeof(str), "val_3: 0x%08X, %d", data.val_3, data.val_3); + snprintf(str, sizeof(str), "val_3: 0x%08lX, %ld", data.val_3, data.val_3); NRF_LOG_INFO("%s", str); - snprintf(str, sizeof(str), "val_4: 0x%08X, %d", data.val_4, data.val_4); + snprintf(str, sizeof(str), "val_4: 0x%08lX, %ld", data.val_4, data.val_4); NRF_LOG_INFO("%s", str); - snprintf(str, sizeof(str), "val_5: 0x%08X, %d", data.val_5, data.val_5); + snprintf(str, sizeof(str), "val_5: 0x%08lX, %ld", data.val_5, data.val_5); NRF_LOG_INFO("%s", str); - snprintf(str, sizeof(str), "val_6_f: %.7f", data.val_6_f, data.val_6_f); + snprintf(str, sizeof(str), "val_6_f: %.7f", data.val_6_f); NRF_LOG_INFO("%s", str); - snprintf(str, sizeof(str), "val_7_f: %.7f", data.val_7_f, data.val_7_f); + snprintf(str, sizeof(str), "val_7_f: %.7f", data.val_7_f); NRF_LOG_INFO("%s", str); - snprintf(str, sizeof(str), "val_8_f: %.7f", data.val_8_f, data.val_8_f); + snprintf(str, sizeof(str), "val_8_f: %.7f", data.val_8_f); NRF_LOG_INFO("%s", str); - snprintf(str, sizeof(str), "val_9_f: %.7f", data.val_9_f, data.val_9_f); + snprintf(str, sizeof(str), "val_9_f: %.7f", data.val_9_f); NRF_LOG_INFO("%s", str); - snprintf(str, sizeof(str), "val_10_f: %.7f", data.val_10_f, data.val_10_f); + snprintf(str, sizeof(str), "val_10_f: %.7f", data.val_10_f); NRF_LOG_INFO("%s", str); } @@ -772,7 +772,7 @@ static void start_event_char_notify_task(void *p_arg) { char str[128]; - snprintf(str, sizeof(str), "{%d, %d, %d, %d, %d, %d, %d, %d, %.7f, %.7f, %.7f, %.7f, %.7f, %d, 0x%08X}", 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_6_f, packet_buf.val_7_f, packet_buf.val_8_f, packet_buf.val_9_f, packet_buf.val_10_f, packet_buf.pattern_id, packet_buf.pattern); + 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_6_f, packet_buf.val_7_f, packet_buf.val_8_f, packet_buf.val_9_f, packet_buf.val_10_f, packet_buf.pattern_id, packet_buf.pattern); NRF_LOG_INFO("%s", str); } @@ -949,7 +949,7 @@ static void send_resis_and_sample_and_hold_data(void *p_arg) { char str[128]; - snprintf(str, sizeof(str), "{%d, %d, %d, %d, %d, %d, %d, %d, %.7f, %.7f, %.7f, %.7f, %.7f, %d, 0x%08X}", 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), "{%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); } From fc6f7831457d61d013a3c3b23227092a35ea0e3a Mon Sep 17 00:00:00 2001 From: chain40 Date: Tue, 4 Feb 2025 23:38:04 +0800 Subject: [PATCH 4/4] =?UTF-8?q?fix:=20=E4=BD=BF=E7=94=A8=20SAADC=20?= =?UTF-8?q?=E4=B8=AD=E6=96=B7,=20=E4=BF=AE=E6=AD=A3=20pulse=20=E6=B2=92?= =?UTF-8?q?=E7=B5=90=E6=9D=9F=E5=B0=B1=E8=A2=AB=E5=81=9C=E6=AD=A2=E9=80=A0?= =?UTF-8?q?=E6=88=90=E7=9A=84=E6=B3=A2=E5=9E=8B=E7=95=B0=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 當 SAADC EVENTS_STARTED 觸發中斷時代表 pulse 已輸出完成並開始 ADC 轉換 2. 當 SAADC EVENTS_RESULTDONE 觸發中斷時代表 ADC 已轉換完成並寫入ram, 同時進入 pulse idle 的狀態. --- pel.c | 2 +- pel20_io.c | 46 +++++++++++++++++++++++++++++----------------- pel20_io.h | 1 + 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/pel.c b/pel.c index 22bc7db..931e30e 100644 --- a/pel.c +++ b/pel.c @@ -1037,7 +1037,7 @@ void run_sample_and_hold_pulse_scanner_task(uint8_t *param) vTaskDelay(pdMS_TO_TICKS(10)); dev_mode_input_resistor(set_resistor_ins); dev_mode_sample_and_hold_pulse_task(start_ins); - vTaskDelay(pdMS_TO_TICKS(90)); + vTaskDelay(pdMS_TO_TICKS(40)); } /*stop*/ diff --git a/pel20_io.c b/pel20_io.c index 34e464f..fb6030b 100644 --- a/pel20_io.c +++ b/pel20_io.c @@ -158,6 +158,7 @@ static void pel_saadc_init(pel_adc_t *p_adc) } } /* enable ssadc */ + NRF_SAADC->INTENSET = NRF_SAADC_INT_STARTED | NRF_SAADC_INT_RESULTDONE; NRF_SAADC->ENABLE = 1; NRF_SAADC->RESULT.PTR = (uint32_t)p_adc->results; NRF_SAADC->RESULT.MAXCNT = COUNTOF(p_adc->results); @@ -168,31 +169,34 @@ void TIMER3_IRQHandler(void) if (pel_hw.pulse_tmr->EVENTS_COMPARE[0]) { pel_hw.pulse_tmr->EVENTS_COMPARE[0] = 0; + + pel_hw.pulse_is_running = 1; + if (pel_hw.pulse_cnt) { pel_hw.pulse_cnt--; } } - else if (pel_hw.pulse_tmr->EVENTS_COMPARE[5]) +} + +void SAADC_IRQHandler(void) +{ + if (NRF_SAADC->EVENTS_STARTED) { - pel_hw.pulse_tmr->EVENTS_COMPARE[5] = 0; - if (pel_hw.pulse_cnt) + NRF_SAADC->EVENTS_STARTED = 0; + if (pel_hw.pulse_cnt == 0) { - NRF_SAADC->RESULT.PTR = (uint32_t)pel_hw.adc.results; - NRF_SAADC->RESULT.MAXCNT = COUNTOF(pel_hw.adc.results); - } - else - { - // disable gpio task - for (int i = 0; i < 5; i++) - { - nrf_gpiote_task_disable(i); - } - - set_anode_cathode_to_default(); - pel_hw.pulse_tmr->TASKS_STOP = 1; } + return; + } + + if (NRF_SAADC->EVENTS_RESULTDONE) + { + NRF_SAADC->EVENTS_RESULTDONE = 0; + NRF_SAADC->RESULT.PTR = (uint32_t)pel_hw.adc.results; + NRF_SAADC->RESULT.MAXCNT = COUNTOF(pel_hw.adc.results); + pel_hw.pulse_is_running = 0; } } @@ -203,6 +207,9 @@ void pel_pulse_gen_init(pel_config_t cfg) sd_nvic_DisableIRQ(pel_hw.pulse_irq_n); sd_nvic_ClearPendingIRQ(pel_hw.pulse_irq_n); + sd_nvic_DisableIRQ(SAADC_IRQn); + sd_nvic_ClearPendingIRQ(SAADC_IRQn); + pel_hw.pulse_cnt = cfg.pulse_cnt; pel_hw.adc.gain = cfg.gain; pel_hw.adc.smaple_time = cfg.smaple_time; @@ -290,7 +297,10 @@ void pel_pulse_gen_init(pel_config_t cfg) pel_hw.pulse_tmr->CC[4] = pel_hw.pulse_tmr->CC[3] + cfg.point_us[4] * 16 + cfg.adc_timing_shift; pel_hw.pulse_tmr->CC[5] = pel_hw.pulse_tmr->CC[4] + cfg.point_us[0] * 16; pel_hw.pulse_tmr->SHORTS = NRF_TIMER_SHORT_COMPARE5_CLEAR_MASK; - pel_hw.pulse_tmr->INTENSET = NRF_TIMER_INT_COMPARE0_MASK | NRF_TIMER_INT_COMPARE5_MASK; + pel_hw.pulse_tmr->INTENSET = NRF_TIMER_INT_COMPARE0_MASK; + + sd_nvic_SetPriority(SAADC_IRQn, _PRIO_APP_HIGH); + sd_nvic_EnableIRQ(SAADC_IRQn); sd_nvic_SetPriority(pel_hw.pulse_irq_n, _PRIO_APP_HIGH); sd_nvic_EnableIRQ(pel_hw.pulse_irq_n); @@ -304,6 +314,8 @@ void pel_pulse_gen_start(void) void pel_pulse_gen_stop(void) { pel_hw.pulse_cnt = 0; + do { + } while (pel_hw.pulse_is_running == 1); } #if (DEF_ELITE_DEMO_W_SOFTDEVICE == 1) || (DEF_ELITE_DEMO_WO_SOFTDEVICE == 1) diff --git a/pel20_io.h b/pel20_io.h index d926292..9d3d9e6 100644 --- a/pel20_io.h +++ b/pel20_io.h @@ -92,6 +92,7 @@ extern "C" NRF_TIMER_Type *pulse_tmr; uint32_t pulse_irq_n; uint32_t pulse_cnt; + uint32_t pulse_is_running; pel_adc_t adc; } pel_hw_t;