From aaaa331bcb7aa66162bde71eae5f94a8dc9ba3e7 Mon Sep 17 00:00:00 2001 From: Roy_01 Date: Fri, 24 May 2024 13:37:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=201.Measure=20OUT=3DL=E3=80=81Measure=20OU?= =?UTF-8?q?T=3DH=E6=98=AF=E4=B8=8D=E5=90=8Crelay,=20Anode,=20Cathode=20?= =?UTF-8?q?=E7=9A=84=E8=A8=8A=E8=99=9F=202.=E6=9B=B4=E6=94=B9dev=20mode?= =?UTF-8?q?=E6=8C=87=E4=BB=A4:=200x60:=20=E6=89=93pulse+=E8=A8=AD=E5=AE=9A?= =?UTF-8?q?=E9=98=BB=E5=80=BC+ADC=E8=AE=80ouput=5Fr1/r2/vo/vc/ve=200x61:?= =?UTF-8?q?=20=E6=8A=8Aouput=5Fr1/r2/vo/vc/ve=20=E5=82=B3=E7=B5=A6=20centr?= =?UTF-8?q?al=200xF0:=20pel=20io=20init=200xF1:=20start/stop=20testing=20o?= =?UTF-8?q?utput=20pin=20task?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pel.c | 143 ++++++++++++++++++++++++++++++++++++++-------------------- pel.h | 2 +- 2 files changed, 94 insertions(+), 51 deletions(-) diff --git a/pel.c b/pel.c index 5126ad2..53f6ddd 100644 --- a/pel.c +++ b/pel.c @@ -61,7 +61,7 @@ static float _load_set_by_ohms(float ohms) return ohms; } -static void _sample(void) +static void _sample_measure_out_is_low(void) { nrf_gpio_pin_set(ANODE_PIN); nrf_gpio_pin_clear(CATHODE_PIN); @@ -83,6 +83,28 @@ static void _sample(void) nrf_gpio_pin_toggle(SAMPLE_V_PIN); } +static void _sample_measure_out_is_high(void) +{ + nrf_gpio_pin_clear(ANODE_PIN); + nrf_gpio_pin_set(CATHODE_PIN); + nrf_gpio_pin_clear(SAMPLE_R_PIN); + nrf_gpio_pin_clear(SAMPLE_V_PIN); + nrf_delay_us(10); + + nrf_gpio_pin_toggle(ANODE_PIN); + nrf_gpio_pin_toggle(CATHODE_PIN); + nrf_delay_us(5); + + nrf_gpio_pin_toggle(SAMPLE_R_PIN); + nrf_gpio_pin_toggle(SAMPLE_V_PIN); + nrf_delay_us(5); + + nrf_gpio_pin_toggle(CATHODE_PIN); + nrf_gpio_pin_toggle(ANODE_PIN); + nrf_gpio_pin_toggle(SAMPLE_R_PIN); + nrf_gpio_pin_toggle(SAMPLE_V_PIN); +} + void pel_relays_set(uint32_t measure_out) { if (measure_out) @@ -99,7 +121,7 @@ void pel_relays_set(uint32_t measure_out) vTaskDelay(pdMS_TO_TICKS(30)); } -pel_output_t pel_smaple_and_convt_all(uint32_t load_mask) +pel_output_t pel_smaple_and_convt_all(uint32_t measure_out, uint32_t load_mask) { uint32_t ch_list[] = { OUTPUT_R1_CHANNEL, @@ -112,7 +134,14 @@ pel_output_t pel_smaple_and_convt_all(uint32_t load_mask) /* config E-load */ _load_set(load_mask); /* send a pulse to sample and then read ADC channels */ - adc_read_mutiple_channels_ex(ch_list, results, COUNTOF(ch_list), _sample); + if (measure_out) + { + adc_read_mutiple_channels_ex(ch_list, results, COUNTOF(ch_list), _sample_measure_out_is_high); + } + else + { + adc_read_mutiple_channels_ex(ch_list, results, COUNTOF(ch_list), _sample_measure_out_is_low); + } /* copy results */ output_data.output_r1 = results[0]; output_data.output_r2 = results[1]; @@ -227,66 +256,80 @@ static void dev_mode(uint8_t *ins, uint16_t size) return; } - struct - { - uint8_t status; - uint16_t mask; - } __PACKED *p_param = (void *)p_ins->param; - switch (p_ins->opcode) { - case 0x00: { + case 0x60: { + struct + { + uint8_t status; + uint16_t mask; + } __PACKED *p_param = (void *)p_ins->param; + pel_relays_set(p_param->status); - dev_mode_pel_output = pel_smaple_and_convt_all(p_param->mask); + dev_mode_pel_output = pel_smaple_and_convt_all(p_param->status, __REVSH(p_param->mask)); break; } - case 0x01: { - extern ret_code_t le_data_upadate(uint8_t * p_value, uint16_t len); - le_data_upadate((void *)&dev_mode_pel_output.output_r1, sizeof(dev_mode_pel_output.output_r1)); - break; - } - case 0x02: { - extern ret_code_t le_data_upadate(uint8_t * p_value, uint16_t len); - le_data_upadate((void *)&dev_mode_pel_output.output_r2, sizeof(dev_mode_pel_output.output_r2)); - break; - } - case 0x03: { - extern ret_code_t le_data_upadate(uint8_t * p_value, uint16_t len); - le_data_upadate((void *)&dev_mode_pel_output.output_vo, sizeof(dev_mode_pel_output.output_vo)); - break; - } - case 0x04: { - extern ret_code_t le_data_upadate(uint8_t * p_value, uint16_t len); - le_data_upadate((void *)&dev_mode_pel_output.output_vc, sizeof(dev_mode_pel_output.output_vc)); - break; - } - case 0x05: { - extern ret_code_t le_data_upadate(uint8_t * p_value, uint16_t len); - le_data_upadate((void *)&dev_mode_pel_output.output_ve, sizeof(dev_mode_pel_output.output_ve)); - break; - } - case 0x06: { - if (test_gpio_task_Handle == NULL) + case 0x61: { + struct { - NRF_LOG_INFO("[test] start test_gpio_task task"); - xTaskCreate(test_gpio_task, "test_gpio_task", 1024, NULL, 4, &test_gpio_task_Handle); + uint8_t channel; + } __PACKED *p_param = (void *)p_ins->param; + + if (p_param->channel == 0x01) { + extern ret_code_t le_data_upadate(uint8_t * p_value, uint16_t len); + le_data_upadate((void *)&dev_mode_pel_output.output_r1, sizeof(dev_mode_pel_output.output_r1)); + } + else if (p_param->channel == 0x02) { + extern ret_code_t le_data_upadate(uint8_t * p_value, uint16_t len); + le_data_upadate((void *)&dev_mode_pel_output.output_r2, sizeof(dev_mode_pel_output.output_r2)); + } + else if (p_param->channel == 0x03) { + extern ret_code_t le_data_upadate(uint8_t * p_value, uint16_t len); + le_data_upadate((void *)&dev_mode_pel_output.output_vo, sizeof(dev_mode_pel_output.output_vo)); + } + else if (p_param->channel == 0x04) { + extern ret_code_t le_data_upadate(uint8_t * p_value, uint16_t len); + le_data_upadate((void *)&dev_mode_pel_output.output_vc, sizeof(dev_mode_pel_output.output_vc)); + } + else if (p_param->channel == 0x05) { + extern ret_code_t le_data_upadate(uint8_t * p_value, uint16_t len); + le_data_upadate((void *)&dev_mode_pel_output.output_ve, sizeof(dev_mode_pel_output.output_ve)); } break; } - case 0x07: { - if (test_gpio_task_Handle != NULL) - { - NRF_LOG_INFO("[test] delete test_gpio_task task"); - vTaskDelete(test_gpio_task_Handle); - test_gpio_task_Handle = NULL; - } - break; - } - case 0x08: { + + case 0xF0: { pel10_io_init(); break; } + + case 0xF1: { + struct + { + uint8_t status; + } __PACKED *p_param = (void *)p_ins->param; + + if (p_param->status == 0x01) + { + if (test_gpio_task_Handle == NULL) + { + NRF_LOG_INFO("[test] start test_gpio_task task"); + xTaskCreate(test_gpio_task, "test_gpio_task", 1024, NULL, 4, &test_gpio_task_Handle); + } + } + else if (p_param->status == 0x00) + { + if (test_gpio_task_Handle != NULL) + { + NRF_LOG_INFO("[test] delete test_gpio_task task"); + vTaskDelete(test_gpio_task_Handle); + test_gpio_task_Handle = NULL; + } + } + break; + } + default: { break; } diff --git a/pel.h b/pel.h index 6750464..0dc4b2e 100644 --- a/pel.h +++ b/pel.h @@ -29,7 +29,7 @@ typedef struct } pel_output_t; void pel_relays_set(uint32_t measure_out); -pel_output_t pel_smaple_and_convt_all(uint32_t load_mask); +pel_output_t pel_smaple_and_convt_all(uint32_t measure_out, uint32_t load_mask); const elite_instance_t *pel_init(void); #endif // !__PEL_H__