44 #include "em_device.h" 48 #include "em_leuart.h" 62 #define DBPRINT_TIMEOUT 0 65 #define TIMEOUT_SYNC 80 66 #define TIMEOUT_DMA 50000 67 #define TIMEOUT_SENDCMD 40000 68 #define TIMEOUT_WAITRESPONSE 2000000 71 #define DMA_CHANNEL_TX 0 72 #define DMA_CHANNEL_RX 1 73 #define DMA_CHANNELS 2 132 DMA_Init_TypeDef dmaInit;
133 DMA_CfgChannel_TypeDef rxChnlCfg;
134 DMA_CfgChannel_TypeDef txChnlCfg;
135 DMA_CfgDescr_TypeDef rxDescrCfg;
136 DMA_CfgDescr_TypeDef txDescrCfg;
140 dmaInit.controlBlock = dmaControlBlock;
150 rxChnlCfg.highPri =
false;
151 rxChnlCfg.enableInt =
true;
153 rxChnlCfg.select = DMAREQ_LEUART0_RXDATAV;
160 rxDescrCfg.dstInc = dmaDataIncNone;
162 rxDescrCfg.srcInc = dmaDataIncNone;
163 rxDescrCfg.size = dmaDataSize1;
165 rxDescrCfg.arbRate = dmaArbitrate1;
166 rxDescrCfg.hprot = 0;
178 txChnlCfg.highPri =
false;
179 txChnlCfg.enableInt =
true;
181 txChnlCfg.select = DMAREQ_LEUART0_TXBL;
188 txDescrCfg.dstInc = dmaDataIncNone;
190 txDescrCfg.srcInc = dmaDataInc1;
191 txDescrCfg.size = dmaDataSize1;
193 txDescrCfg.arbRate = dmaArbitrate1;
194 txDescrCfg.hprot = 0;
202 uint32_t counter = 0;
211 #if DEBUG_DBPRINT == 1 212 dbcrit(
"Waiting time for sync reached! (sendLeuartData)");
217 #if DBPRINT_TIMEOUT == 1 221 #if DEBUG_DBPRINT == 1 222 dbwarnInt(
"sendLeuartData SYNC (", counter,
")");
233 (
unsigned int)(bufferLength - 1));
245 #if DEBUG_DBPRINT == 1 246 dbcrit(
"Waiting time for DMA channel enable reached! (sendLeuartData)");
251 #if DBPRINT_TIMEOUT == 1 255 #if DEBUG_DBPRINT == 1 256 dbwarnInt(
"sendLeuartData DMA (", counter,
")");
267 CMU_ClockEnable(cmuClock_HFPER,
true);
269 CMU_ClockEnable(cmuClock_GPIO,
true);
274 LEUART_Init_TypeDef
init = LEUART_INIT_DEFAULT;
275 init.baudrate = 4800;
278 CMU_ClockEnable(cmuClock_CORELE,
true);
281 CMU_ClockSelectSet(cmuClock_LFB, cmuSelect_LFXO);
282 CMU_ClockEnable(cmuClock_LEUART0,
true);
285 CMU_ClockDivSet(cmuClock_LEUART0, cmuClkDiv_1);
288 init.enable = leuartDisable;
300 NVIC_ClearPendingIRQ(LEUART0_IRQn);
361 uint32_t counter = 0;
373 #if DEBUG_DBPRINT == 1 374 dbcrit(
"Waiting time for response reached! (Leuart_SendData)");
382 #if DEBUG_DBPRINT == 1 383 dbwarnInt(
"Leuart_SendData (", counter,
")");
395 uint32_t counter = 0;
407 #if DEBUG_DBPRINT == 1 408 dbcrit(
"Waiting time for response reached! (Leuart_SendCommand)");
415 #if DBPRINT_TIMEOUT == 1 419 #if DEBUG_DBPRINT == 1 420 dbwarnInt(
"Leuart_SendCommand (", counter,
")");
433 uint32_t counter = 0;
450 #if DEBUG_DBPRINT == 1 451 dbcrit(
"Waiting time for response reached! (Leuart_WaitForResponse)");
458 #if DBPRINT_TIMEOUT == 1 462 #if DEBUG_DBPRINT == 1 463 dbwarnInt(
"Leuart_WaitForResponse (", counter,
")");
enum leuart_statuses Leuart_Status_t
void Leuart_SendData(char *buffer, uint8_t bufferLength)
Leuart_Status_t Leuart_SendCommand(char *cb, uint8_t cbl, volatile bool *wakeUp)
Leuart_Status_t Leuart_WaitForResponse()
void dbwarnInt(char *message1, int32_t value, char *message2)
Print a warning value surrounded by two strings (char array) to USARTx.
void Leuart_BreakCondition(void)
#define TIMEOUT_WAITRESPONSE
static bool Leuart_ResponseAvailable(void)
static void sendLeuartData(char *buffer, uint8_t bufferLength)
static void setupLeuart(void)
void error(uint8_t number)
Error method.
The pin definitions for the regular and custom Happy Gecko board.
static void basicTxComplete(unsigned int channel, bool primary, void *user)
Enable or disable printing to UART with dbprint.
void delay(uint32_t msDelay)
Wait for a certain amount of milliseconds in EM2/3.
#define RECEIVE_BUFFER_SIZE
void Leuart_ClearBuffers(void)
static DMA_CB_TypeDef dmaCallBack[2]
volatile bool receiveComplete
void Leuart_ReadResponse(char *buffer, uint8_t bufferLength)
void dbcrit(char *message)
Print a critical error string (char array) in red to USARTx and go to the next line.
static void basicRxComplete(unsigned int channel, bool primary, void *user)
volatile uint8_t bufferPointer