From dc12bfd19aecb8fcf9b18bd646f3b17ba8163b82 Mon Sep 17 00:00:00 2001 From: worker2345234 Date: Mon, 4 Dec 2017 10:23:49 +0100 Subject: [PATCH 1/5] speedup for CAN-RX task --- components/can/CAN.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/components/can/CAN.c b/components/can/CAN.c index ffd55bf..24b93a3 100644 --- a/components/can/CAN.c +++ b/components/can/CAN.c @@ -48,6 +48,7 @@ static void CAN_isr(void *arg_p); static void CAN_isr(void *arg_p){ +bool fYieldRequiered = false; //Interrupt flag buffer __CAN_IRQ_t interrupt; @@ -61,7 +62,7 @@ static void CAN_isr(void *arg_p){ // Handle RX frame available interrupt if ((interrupt & __CAN_IRQ_RX) != 0) - CAN_read_frame(); + fYieldRequired = CAN_read_frame(); // Handle error interrupts. if ((interrupt & (__CAN_IRQ_ERR //0x4 @@ -73,9 +74,11 @@ static void CAN_isr(void *arg_p){ )) != 0) { /*handler*/ } + if (fYieldRequired == pdTRUE) + portYIELD_FROM_ISR(); } -static void CAN_read_frame(){ +static bool CAN_read_frame(){ //byte iterator uint8_t __byte_i; @@ -87,7 +90,7 @@ static void CAN_read_frame(){ if (CAN_cfg.rx_queue == NULL){ // Let the hardware know the frame has been read. MODULE_CAN->CMR.B.RRB=1; - return; + return false; } //get FIR @@ -118,10 +121,12 @@ static void CAN_read_frame(){ } //send frame to input queue - xQueueSendFromISR(CAN_cfg.rx_queue,&__frame,0); + bool fYieldRequired = xQueueSendFromISR(CAN_cfg.rx_queue,&__frame,0); //Let the hardware know the frame has been read. MODULE_CAN->CMR.B.RRB=1; + + return fYieldRequired; } int CAN_write_frame(const CAN_frame_t* p_frame){ From 09380774d329f624b84fd72db75e65f9b132a10d Mon Sep 17 00:00:00 2001 From: worker2345234 Date: Fri, 8 Dec 2017 13:15:43 +0100 Subject: [PATCH 2/5] use pxHigherPriorityTaskWoken of xQueueSendFromISR instead of the return value https://www.freertos.org/a00119.html --- components/can/CAN.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/components/can/CAN.c b/components/can/CAN.c index 24b93a3..3ef88ce 100644 --- a/components/can/CAN.c +++ b/components/can/CAN.c @@ -48,7 +48,7 @@ static void CAN_isr(void *arg_p); static void CAN_isr(void *arg_p){ -bool fYieldRequiered = false; +BaseType_t fYieldRequired = false; //Interrupt flag buffer __CAN_IRQ_t interrupt; @@ -67,7 +67,7 @@ bool fYieldRequiered = false; // Handle error interrupts. if ((interrupt & (__CAN_IRQ_ERR //0x4 | __CAN_IRQ_DATA_OVERRUN //0x8 - | __CAN_IRQ_WAKEUP //0x10 +; | __CAN_IRQ_WAKEUP //0x10 | __CAN_IRQ_ERR_PASSIVE //0x20 | __CAN_IRQ_ARB_LOST //0x40 | __CAN_IRQ_BUS_ERR //0x80 @@ -82,6 +82,7 @@ static bool CAN_read_frame(){ //byte iterator uint8_t __byte_i; + bool fYieldRequired; //frame read buffer CAN_frame_t __frame; @@ -121,7 +122,7 @@ static bool CAN_read_frame(){ } //send frame to input queue - bool fYieldRequired = xQueueSendFromISR(CAN_cfg.rx_queue,&__frame,0); + xQueueSendFromISR(CAN_cfg.rx_queue,&__frame, &fYieldRequired); //Let the hardware know the frame has been read. MODULE_CAN->CMR.B.RRB=1; From a0dd9fb2d388dafab08b50d98f46433d0abae2b4 Mon Sep 17 00:00:00 2001 From: worker2345234 Date: Fri, 8 Dec 2017 13:24:28 +0100 Subject: [PATCH 3/5] compiles now.. --- components/can/CAN.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/components/can/CAN.c b/components/can/CAN.c index 3ef88ce..1074c19 100644 --- a/components/can/CAN.c +++ b/components/can/CAN.c @@ -42,13 +42,13 @@ #include "CAN_config.h" -static void CAN_read_frame(); +static BaseType_t CAN_read_frame(); static void CAN_isr(void *arg_p); static void CAN_isr(void *arg_p){ -BaseType_t fYieldRequired = false; +BaseType_t fYieldRequired = pdFALSE; //Interrupt flag buffer __CAN_IRQ_t interrupt; @@ -67,7 +67,7 @@ BaseType_t fYieldRequired = false; // Handle error interrupts. if ((interrupt & (__CAN_IRQ_ERR //0x4 | __CAN_IRQ_DATA_OVERRUN //0x8 -; | __CAN_IRQ_WAKEUP //0x10 + | __CAN_IRQ_WAKEUP //0x10 | __CAN_IRQ_ERR_PASSIVE //0x20 | __CAN_IRQ_ARB_LOST //0x40 | __CAN_IRQ_BUS_ERR //0x80 @@ -78,11 +78,11 @@ BaseType_t fYieldRequired = false; portYIELD_FROM_ISR(); } -static bool CAN_read_frame(){ +static BaseType_t CAN_read_frame(){ //byte iterator uint8_t __byte_i; - bool fYieldRequired; + BaseType_t fYieldRequired; //frame read buffer CAN_frame_t __frame; From da4563a280c64b35988bc15c39381c79a979b8c7 Mon Sep 17 00:00:00 2001 From: worker2345234 Date: Mon, 11 Dec 2017 09:56:39 +0100 Subject: [PATCH 4/5] better code --- components/can/CAN.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/components/can/CAN.c b/components/can/CAN.c index 1074c19..2c9b012 100644 --- a/components/can/CAN.c +++ b/components/can/CAN.c @@ -42,7 +42,7 @@ #include "CAN_config.h" -static BaseType_t CAN_read_frame(); +static void CAN_read_frame(BaseType_t* pfYieldRequired); static void CAN_isr(void *arg_p); @@ -62,7 +62,7 @@ BaseType_t fYieldRequired = pdFALSE; // Handle RX frame available interrupt if ((interrupt & __CAN_IRQ_RX) != 0) - fYieldRequired = CAN_read_frame(); + CAN_read_frame(&fYieldRequired); // Handle error interrupts. if ((interrupt & (__CAN_IRQ_ERR //0x4 @@ -78,11 +78,10 @@ BaseType_t fYieldRequired = pdFALSE; portYIELD_FROM_ISR(); } -static BaseType_t CAN_read_frame(){ +static void CAN_read_frame(BaseType_t* pfYieldRequired){ //byte iterator uint8_t __byte_i; - BaseType_t fYieldRequired; //frame read buffer CAN_frame_t __frame; @@ -122,12 +121,10 @@ static BaseType_t CAN_read_frame(){ } //send frame to input queue - xQueueSendFromISR(CAN_cfg.rx_queue,&__frame, &fYieldRequired); + xQueueSendFromISR(CAN_cfg.rx_queue,&__frame, pfYieldRequired); //Let the hardware know the frame has been read. MODULE_CAN->CMR.B.RRB=1; - - return fYieldRequired; } int CAN_write_frame(const CAN_frame_t* p_frame){ From 0bf3163d4d15c43f4be9a010a059dde1b0d0fcc2 Mon Sep 17 00:00:00 2001 From: worker2345234 Date: Mon, 11 Dec 2017 11:06:11 +0100 Subject: [PATCH 5/5] this commit shows why I prefer to use return values instead of args by reference (the compiler ensures all code pathes return a result) --- components/can/CAN.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/can/CAN.c b/components/can/CAN.c index 2c9b012..31e30fa 100644 --- a/components/can/CAN.c +++ b/components/can/CAN.c @@ -90,7 +90,8 @@ static void CAN_read_frame(BaseType_t* pfYieldRequired){ if (CAN_cfg.rx_queue == NULL){ // Let the hardware know the frame has been read. MODULE_CAN->CMR.B.RRB=1; - return false; + *pfYieldRequired = pdFALSE; + return; } //get FIR