From 41697a7320e83a18e20d533b951da55b014f30ce Mon Sep 17 00:00:00 2001 From: Lembitu Valdmets Date: Sat, 19 Feb 2022 10:41:36 +0200 Subject: [PATCH 1/4] [TS-861] Made universal interrupt handler for ldma, because there can only be 1. Modified logger-ldma to use universal handler. --- include/ldma_handler.h | 15 ++++++++++++ silabs/ldma_handler.c | 54 ++++++++++++++++++++++++++++++++++++++++++ silabs/logger_ldma.c | 9 +++++++ 3 files changed, 78 insertions(+) create mode 100644 include/ldma_handler.h create mode 100644 silabs/ldma_handler.c diff --git a/include/ldma_handler.h b/include/ldma_handler.h new file mode 100644 index 0000000..d950c96 --- /dev/null +++ b/include/ldma_handler.h @@ -0,0 +1,15 @@ +#ifndef LDMA_HANDLER_CONF +#define LDMA_HANDLER_CONF + +#include "cmsis_os2.h" + +typedef struct { + int channel; + osThreadId_t thrd; + int signal; + struct ldma_handler_conf_t* next; +} ldma_handler_conf_t; + +void append_to_ldma_stored_configuration(ldma_handler_conf_t * newconf); + +#endif //LDMA_HANDLER_CONF diff --git a/silabs/ldma_handler.c b/silabs/ldma_handler.c new file mode 100644 index 0000000..692c694 --- /dev/null +++ b/silabs/ldma_handler.c @@ -0,0 +1,54 @@ + +#include "em_device.h" +#include "em_gpio.h" +#include "em_cmu.h" +#include "ldma_handler.h" +#include "em_ldma.h" +#include "cmsis_os2.h" +#include "sys_panic.h" + +#define SIZE_OF_ARRAY(arr) (sizeof(arr))/sizeof(arr[0]) + +static ldma_handler_conf_t m_head; + +void LDMA_IRQHandler (void) +{ + uint32_t pending = LDMA_IntGet(); + + while (pending & LDMA_IF_ERROR) + { + //err1("ldma if"); + } + + LDMA_IntClear(pending); + + + for(ldma_handler_conf_t* ptr = &m_head; ptr->next != NULL ; ptr = ptr->next ) + { + if ( pending & (1<channel) ) + { + osThreadFlagsSet(ptr->thrd, ptr->signal); + } + } +} + +void append_to_ldma_stored_configuration(ldma_handler_conf_t * newconf) +{ + //append to configuration + ldma_handler_conf_t *ptr = &m_head; + if(!m_head.next) + { + // adding first config + ptr->next = newconf; + } + else + { + //looping to the end of list + while(ptr != NULL && ptr->next != NULL) + { + ptr = ptr->next; + } + //adding new element + ptr->next = newconf; + } +} diff --git a/silabs/logger_ldma.c b/silabs/logger_ldma.c index fcd6925..d0c4880 100644 --- a/silabs/logger_ldma.c +++ b/silabs/logger_ldma.c @@ -27,6 +27,7 @@ #include "dmadrv.h" #else #include "em_ldma.h" +#include "ldma_handler.h" #endif//LOGGER_LDMA_DMADRV #include "sleep.h" @@ -71,6 +72,7 @@ static bool dmadrv_callback (unsigned int channel, unsigned int sequenceNo, void return false; } #else +/* void LDMA_IRQHandler (void) { uint32_t pending = LDMA_IntGet(); @@ -87,6 +89,7 @@ void LDMA_IRQHandler (void) osThreadFlagsSet(m_ldma_thread, LOGGER_THREAD_FLAG_LDMA_DONE); } } +*/ #endif//LOGGER_LDMA_DMADRV @@ -262,6 +265,12 @@ int logger_ldma_init () return 1; // should perhaps panic instead } #else + + ldma_handler_conf_t ldma_conf; + ldma_conf.channel = LOGGER_LDMA_CHANNEL; + ldma_conf.signal = LOGGER_THREAD_FLAG_LDMA_DONE; + ldma_conf.thrd = m_ldma_thread; + LDMA_Init_t initLdma = LDMA_INIT_DEFAULT; initLdma.ldmaInitIrqPriority = LDMA_INTERRUPT_PRIORITY; LDMA_Init(&initLdma); From 10a7079db7d5bb6cc04a130ad956fb6ee55cc9f6 Mon Sep 17 00:00:00 2001 From: Lembitu Valdmets Date: Mon, 21 Feb 2022 16:23:48 +0200 Subject: [PATCH 2/4] This ldma-handler doesn't seem to work properly. Reduced issue to setting up false flags. --- include/ldma_handler.h | 1 + silabs/ldma_handler.c | 19 +++++++++++++------ silabs/logger_ldma.c | 18 ++++++++++++------ 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/include/ldma_handler.h b/include/ldma_handler.h index d950c96..e9371e0 100644 --- a/include/ldma_handler.h +++ b/include/ldma_handler.h @@ -6,6 +6,7 @@ typedef struct { int channel; osThreadId_t thrd; + int name; int signal; struct ldma_handler_conf_t* next; } ldma_handler_conf_t; diff --git a/silabs/ldma_handler.c b/silabs/ldma_handler.c index 692c694..25f982e 100644 --- a/silabs/ldma_handler.c +++ b/silabs/ldma_handler.c @@ -1,4 +1,5 @@ +#include "platform.h" #include "em_device.h" #include "em_gpio.h" #include "em_cmu.h" @@ -9,26 +10,32 @@ #define SIZE_OF_ARRAY(arr) (sizeof(arr))/sizeof(arr[0]) -static ldma_handler_conf_t m_head; +static volatile ldma_handler_conf_t m_head; void LDMA_IRQHandler (void) { uint32_t pending = LDMA_IntGet(); - - while (pending & LDMA_IF_ERROR) + PLATFORM_LedsSet(PLATFORM_LedsGet()^1); + uint32_t error = 0; + while (pending & LDMA_IF_ERROR) { //err1("ldma if"); } LDMA_IntClear(pending); - - for(ldma_handler_conf_t* ptr = &m_head; ptr->next != NULL ; ptr = ptr->next ) + ldma_handler_conf_t* ptr = &m_head; + while(ptr != NULL) { if ( pending & (1<channel) ) { - osThreadFlagsSet(ptr->thrd, ptr->signal); + if(ptr->name == 69) + { + error = osThreadFlagsSet(ptr->thrd, ptr->signal); + + } } + ptr = ptr->next; } } diff --git a/silabs/logger_ldma.c b/silabs/logger_ldma.c index d0c4880..618df46 100644 --- a/silabs/logger_ldma.c +++ b/silabs/logger_ldma.c @@ -61,6 +61,7 @@ static osThreadId_t m_ldma_thread; static osMutexId_t m_log_mutex; static bool m_ldma_idle; static bool m_uart_active; +static ldma_handler_conf_t m_ldma_handler_conf; static unsigned int m_dma_channel = LOGGER_LDMA_CHANNEL; @@ -69,6 +70,7 @@ static unsigned int m_dma_channel = LOGGER_LDMA_CHANNEL; static bool dmadrv_callback (unsigned int channel, unsigned int sequenceNo, void * data) { osThreadFlagsSet(m_ldma_thread, LOGGER_THREAD_FLAG_LDMA_DONE); + //PLATFORM_LedsSet(PLATFORM_LedsGet()^1); return false; } #else @@ -76,7 +78,7 @@ static bool dmadrv_callback (unsigned int channel, unsigned int sequenceNo, void void LDMA_IRQHandler (void) { uint32_t pending = LDMA_IntGet(); - + PLATFORM_LedsSet(PLATFORM_LedsGet()^1); while (pending & LDMA_IF_ERROR) { sys_panic("ldma if"); @@ -228,13 +230,15 @@ static void ldma_thread (void* argument) while (osOK != osMutexAcquire(m_log_mutex, osWaitForever)); - if (flags & LOGGER_THREAD_FLAG_LDMA_DONE) + if (flags & LOGGER_THREAD_FLAG_LDMA_DONE || flags & 16) { + busy = false; m_buf_full = false; m_buf_start = m_buf_pos; } + if ((m_buf_start >= LOGGER_LDMA_BUFFER_LENGTH)||(m_buf_end >= LOGGER_LDMA_BUFFER_LENGTH)) { sys_panic("ldma buf"); @@ -266,11 +270,13 @@ int logger_ldma_init () } #else - ldma_handler_conf_t ldma_conf; - ldma_conf.channel = LOGGER_LDMA_CHANNEL; - ldma_conf.signal = LOGGER_THREAD_FLAG_LDMA_DONE; - ldma_conf.thrd = m_ldma_thread; + m_ldma_handler_conf.channel = LOGGER_LDMA_CHANNEL; + m_ldma_handler_conf.signal = LOGGER_THREAD_FLAG_LDMA_DONE; + m_ldma_handler_conf.thrd = &m_ldma_thread; + m_ldma_handler_conf.name = 69; + m_ldma_handler_conf.next = NULL; + append_to_ldma_stored_configuration(&m_ldma_handler_conf); LDMA_Init_t initLdma = LDMA_INIT_DEFAULT; initLdma.ldmaInitIrqPriority = LDMA_INTERRUPT_PRIORITY; LDMA_Init(&initLdma); From 61b1d251ad07e794343f436b9fb58fd6442a75d9 Mon Sep 17 00:00:00 2001 From: Lembitu Valdmets Date: Tue, 22 Feb 2022 15:50:45 +0200 Subject: [PATCH 3/4] [TS-861] Reworked ldma-Handler a bit Seems that logger_ldma is expecting some other flag to function properly. Currently unable to fix logger_ldma myself (Lembitu). Went with easier approach letting logger_ldma to accept both flags. Currently seems to work. TODO: make actual fix --- silabs/ldma_handler.c | 9 ++------- silabs/logger_ldma.c | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/silabs/ldma_handler.c b/silabs/ldma_handler.c index 25f982e..0bdab15 100644 --- a/silabs/ldma_handler.c +++ b/silabs/ldma_handler.c @@ -15,8 +15,7 @@ static volatile ldma_handler_conf_t m_head; void LDMA_IRQHandler (void) { uint32_t pending = LDMA_IntGet(); - PLATFORM_LedsSet(PLATFORM_LedsGet()^1); - uint32_t error = 0; + while (pending & LDMA_IF_ERROR) { //err1("ldma if"); @@ -29,11 +28,7 @@ void LDMA_IRQHandler (void) { if ( pending & (1<channel) ) { - if(ptr->name == 69) - { - error = osThreadFlagsSet(ptr->thrd, ptr->signal); - - } + osThreadFlagsSet(ptr->thrd, ptr->signal); } ptr = ptr->next; } diff --git a/silabs/logger_ldma.c b/silabs/logger_ldma.c index 618df46..942b4f3 100644 --- a/silabs/logger_ldma.c +++ b/silabs/logger_ldma.c @@ -230,7 +230,7 @@ static void ldma_thread (void* argument) while (osOK != osMutexAcquire(m_log_mutex, osWaitForever)); - if (flags & LOGGER_THREAD_FLAG_LDMA_DONE || flags & 16) + if (flags & LOGGER_THREAD_FLAG_LDMA_DONE || flags & LOGGER_THREAD_FLAG_NEW_DATA) { busy = false; From d03c204abba59980ea8f5fab77a8dd2ac8d2d072 Mon Sep 17 00:00:00 2001 From: Lembitu Valdmets Date: Tue, 1 Mar 2022 09:54:17 +0200 Subject: [PATCH 4/4] [TS-861] fixed ldma_handler, now is able to set correct flag to threads needed. --- include/ldma_handler.h | 6 +++--- silabs/ldma_handler.c | 8 +++++--- silabs/logger_ldma.c | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/include/ldma_handler.h b/include/ldma_handler.h index e9371e0..4a1b541 100644 --- a/include/ldma_handler.h +++ b/include/ldma_handler.h @@ -4,10 +4,10 @@ #include "cmsis_os2.h" typedef struct { - int channel; + uint32_t channel; osThreadId_t thrd; - int name; - int signal; + uint32_t name; + uint32_t signal; struct ldma_handler_conf_t* next; } ldma_handler_conf_t; diff --git a/silabs/ldma_handler.c b/silabs/ldma_handler.c index 0bdab15..a01b3bf 100644 --- a/silabs/ldma_handler.c +++ b/silabs/ldma_handler.c @@ -10,7 +10,8 @@ #define SIZE_OF_ARRAY(arr) (sizeof(arr))/sizeof(arr[0]) -static volatile ldma_handler_conf_t m_head; +static volatile ldma_handler_conf_t m_head = {0xFF, NULL, 0, 0, NULL}; + void LDMA_IRQHandler (void) { @@ -21,17 +22,18 @@ void LDMA_IRQHandler (void) //err1("ldma if"); } - LDMA_IntClear(pending); + ldma_handler_conf_t* ptr = &m_head; while(ptr != NULL) { - if ( pending & (1<channel) ) + if ( pending & (1 << ptr->channel) ) { osThreadFlagsSet(ptr->thrd, ptr->signal); } ptr = ptr->next; } + LDMA_IntClear(pending); } void append_to_ldma_stored_configuration(ldma_handler_conf_t * newconf) diff --git a/silabs/logger_ldma.c b/silabs/logger_ldma.c index 942b4f3..7c2988a 100644 --- a/silabs/logger_ldma.c +++ b/silabs/logger_ldma.c @@ -230,7 +230,7 @@ static void ldma_thread (void* argument) while (osOK != osMutexAcquire(m_log_mutex, osWaitForever)); - if (flags & LOGGER_THREAD_FLAG_LDMA_DONE || flags & LOGGER_THREAD_FLAG_NEW_DATA) + if (flags & LOGGER_THREAD_FLAG_LDMA_DONE ) { busy = false; @@ -273,7 +273,7 @@ int logger_ldma_init () m_ldma_handler_conf.channel = LOGGER_LDMA_CHANNEL; m_ldma_handler_conf.signal = LOGGER_THREAD_FLAG_LDMA_DONE; - m_ldma_handler_conf.thrd = &m_ldma_thread; + m_ldma_handler_conf.thrd = m_ldma_thread; m_ldma_handler_conf.name = 69; m_ldma_handler_conf.next = NULL; append_to_ldma_stored_configuration(&m_ldma_handler_conf);