Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions include/ldma_handler.h
Original file line number Diff line number Diff line change
@@ -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
58 changes: 58 additions & 0 deletions silabs/ldma_handler.c
Original file line number Diff line number Diff line change
@@ -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};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use structre members names to initialize them e.g. const osThreadAttr_t app_thread_attr = { .name = "app" };



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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BARR - add space

{
if ( pending & (1 << ptr->channel) )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BARR - remove spaces if ((pending & (1 << ptr->channel)))

{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identation - open all files in editor and convert tabs to spaces and check after that the indentation is correct

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;
}
}
19 changes: 17 additions & 2 deletions silabs/logger_ldma.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "dmadrv.h"
#else
#include "em_ldma.h"
#include "ldma_handler.h"
#endif//LOGGER_LDMA_DMADRV

#include "sleep.h"
Expand Down Expand Up @@ -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;

Expand All @@ -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");
Expand All @@ -87,6 +91,7 @@ void LDMA_IRQHandler (void)
osThreadFlagsSet(m_ldma_thread, LOGGER_THREAD_FLAG_LDMA_DONE);
}
}
*/
#endif//LOGGER_LDMA_DMADRV


Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use constants instead of mystical numbers. e.g. #define DEFAULT_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);
Expand Down