From 5dbe2983aaaeed4047624fca21a9caa689e0ccd2 Mon Sep 17 00:00:00 2001 From: DrZlo13 Date: Tue, 9 Feb 2021 21:21:05 +1000 Subject: [PATCH] Fixed procedure for sending IrDA commands, disabled interrupts for better stability (#329) * Disable irq when send command --- applications/irda/irda.c | 2 -- applications/irda/irda_nec.c | 7 +++++++ applications/irda/irda_samsung.c | 7 +++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/applications/irda/irda.c b/applications/irda/irda.c index e386719c..e43112cd 100644 --- a/applications/irda/irda.c +++ b/applications/irda/irda.c @@ -139,7 +139,6 @@ void render_packet(Canvas* canvas, State* state) { void input_packet(AppEvent* event, State* state) { if(event->value.input.input == InputOk) { if(event->value.input.state) { - vTaskSuspendAll(); switch(state->packets[state->packet_id].protocol) { case IRDA_NEC: ir_nec_send( @@ -154,7 +153,6 @@ void input_packet(AppEvent* event, State* state) { default: break; } - xTaskResumeAll(); } } diff --git a/applications/irda/irda_nec.c b/applications/irda/irda_nec.c index 8c22cea5..11ea5f25 100644 --- a/applications/irda/irda_nec.c +++ b/applications/irda/irda_nec.c @@ -37,10 +37,17 @@ void ir_nec_send(uint16_t addr, uint8_t data) { // and I don’t know if this is my fault or a feature of the analyzer // TODO: check the dictionary and check with a known remote uint8_t nec_packet[4] = {~(uint8_t)addr, ~(uint8_t)(addr >> 8), ~(uint8_t)data, data}; + + osKernelLock(); + __disable_irq(); + ir_nec_preambula(); ir_nec_send_byte(nec_packet[0]); ir_nec_send_byte(nec_packet[1]); ir_nec_send_byte(nec_packet[2]); ir_nec_send_byte(nec_packet[3]); ir_nec_send_bit(1); + + __enable_irq(); + osKernelUnlock(); } \ No newline at end of file diff --git a/applications/irda/irda_samsung.c b/applications/irda/irda_samsung.c index e608a7da..603ad38d 100644 --- a/applications/irda/irda_samsung.c +++ b/applications/irda/irda_samsung.c @@ -29,10 +29,17 @@ void ir_samsung_send_byte(uint8_t data) { void ir_samsung_send(uint16_t addr, uint16_t data) { uint8_t samsung_packet[4] = { (uint8_t)addr, (uint8_t)(addr >> 8), (uint8_t)data, (uint8_t)(data >> 8)}; + + osKernelLock(); + __disable_irq(); + ir_samsung_preambula(); ir_samsung_send_byte(samsung_packet[0]); ir_samsung_send_byte(samsung_packet[1]); ir_samsung_send_byte(samsung_packet[2]); ir_samsung_send_byte(samsung_packet[3]); ir_samsung_send_bit(0); + + __enable_irq(); + osKernelUnlock(); } \ No newline at end of file