diff --git a/include/ldma_handler.h b/include/ldma_handler.h new file mode 100644 index 0000000..4a1b541 --- /dev/null +++ b/include/ldma_handler.h @@ -0,0 +1,16 @@ +#ifndef LDMA_HANDLER_CONF +#define LDMA_HANDLER_CONF + +#include "cmsis_os2.h" + +typedef struct { + uint32_t channel; + osThreadId_t thrd; + uint32_t name; + uint32_t 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..a01b3bf --- /dev/null +++ b/silabs/ldma_handler.c @@ -0,0 +1,58 @@ + +#include "platform.h" +#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 volatile ldma_handler_conf_t m_head = {0xFF, NULL, 0, 0, NULL}; + + +void LDMA_IRQHandler (void) +{ + uint32_t pending = LDMA_IntGet(); + + while (pending & LDMA_IF_ERROR) + { + //err1("ldma if"); + } + + + + ldma_handler_conf_t* ptr = &m_head; + while(ptr != NULL) + { + 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) +{ + //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..7c2988a 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" @@ -60,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; @@ -68,13 +70,15 @@ 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 +/* void LDMA_IRQHandler (void) { uint32_t pending = LDMA_IntGet(); - + PLATFORM_LedsSet(PLATFORM_LedsGet()^1); while (pending & LDMA_IF_ERROR) { sys_panic("ldma if"); @@ -87,6 +91,7 @@ void LDMA_IRQHandler (void) osThreadFlagsSet(m_ldma_thread, LOGGER_THREAD_FLAG_LDMA_DONE); } } +*/ #endif//LOGGER_LDMA_DMADRV @@ -225,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 ) { + 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"); @@ -262,6 +269,14 @@ int logger_ldma_init () return 1; // should perhaps panic instead } #else + + + 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);