Embedded System Design 2 - Project
leuart.h File Reference

Go to the source code of this file.

Macros

#define RECEIVE_BUFFER_SIZE   50
 
#define COMMAND_BUFFER_SIZE   50
 

Typedefs

typedef enum leuart_statuses Leuart_Status_t
 

Enumerations

enum  leuart_statuses { TX_TIMEOUT, RX_TIMEOUT, DATA_SENT, DATA_RECEIVED }
 

Functions

void Leuart_Init (void)
 
void Leuart_Reinit (void)
 
void Leuart_ClearBuffers (void)
 
void Leuart_BreakCondition (void)
 
void Leuart_SendData (char *buffer, uint8_t bufferLength)
 
void Leuart_ReadResponse (char *buffer, uint8_t bufferLength)
 
Leuart_Status_t Leuart_SendCommand (char *cb, uint8_t cbl, volatile bool *wakeUp)
 
Leuart_Status_t Leuart_WaitForResponse ()
 

Macro Definition Documentation

◆ COMMAND_BUFFER_SIZE

#define COMMAND_BUFFER_SIZE   50

Definition at line 24 of file leuart.h.

◆ RECEIVE_BUFFER_SIZE

#define RECEIVE_BUFFER_SIZE   50

Definition at line 23 of file leuart.h.

Typedef Documentation

◆ Leuart_Status_t

Enumeration Type Documentation

◆ leuart_statuses

Enumerator
TX_TIMEOUT 
RX_TIMEOUT 
DATA_SENT 
DATA_RECEIVED 

Definition at line 26 of file leuart.h.

26  {
27  TX_TIMEOUT,
28  RX_TIMEOUT,
29  DATA_SENT,
enum leuart_statuses Leuart_Status_t

Function Documentation

◆ Leuart_BreakCondition()

void Leuart_BreakCondition ( void  )

Definition at line 342 of file leuart.c.

343 {
344  GPIO_PinModeSet(RN2483_TX_PORT, RN2483_TX_PIN, gpioModePushPull, 1);
345  delay(40);
346  GPIO_PinModeSet(RN2483_TX_PORT, RN2483_TX_PIN, gpioModePushPull, 0);
347  delay(20);
348  GPIO_PinOutSet(RN2483_TX_PORT, RN2483_TX_PIN);
349 }
#define RN2483_TX_PIN
Definition: pin_mapping.h:118
#define RN2483_TX_PORT
Definition: pin_mapping.h:117
void delay(uint32_t msDelay)
Wait for a certain amount of milliseconds in EM2/3.
Definition: delay.c:124

◆ Leuart_ClearBuffers()

void Leuart_ClearBuffers ( void  )

Definition at line 83 of file leuart.c.

84 {
85  memset(receiveBuffer, '\0', RECEIVE_BUFFER_SIZE);
86  receiveComplete = false;
87 }
#define RECEIVE_BUFFER_SIZE
Definition: leuart.h:23
volatile bool receiveComplete
Definition: leuart.c:80
char receiveBuffer[50]
Definition: leuart.c:78

◆ Leuart_Init()

void Leuart_Init ( void  )

Definition at line 306 of file leuart.c.

307 {
308  // TODO: Lines below might fix some sleep functionality...
309  //CMU_ClockEnable(cmuClock_CORELE, true);
310  //CMU_ClockEnable(cmuClock_DMA, true);
311  //CMU_ClockEnable(cmuClock_LEUART0, true);
312 
313  setupDma();
315  setupLeuart();
316 
317  /* Auto baud setting */
318  char b[] = "U";
319  sendLeuartData(b, 1);
320  delay(500);
321 }
void Leuart_BreakCondition(void)
Definition: leuart.c:342
static void sendLeuartData(char *buffer, uint8_t bufferLength)
Definition: leuart.c:199
static void setupLeuart(void)
Definition: leuart.c:264
void setupDma(void)
Definition: leuart.c:130
void delay(uint32_t msDelay)
Wait for a certain amount of milliseconds in EM2/3.
Definition: delay.c:124

◆ Leuart_ReadResponse()

void Leuart_ReadResponse ( char *  buffer,
uint8_t  bufferLength 
)

Definition at line 351 of file leuart.c.

352 {
353  sprintf(buffer, "%s", receiveBuffer);
354  receiveComplete = false;
355  bufferPointer = 0;
356 }
volatile bool receiveComplete
Definition: leuart.c:80
char receiveBuffer[50]
Definition: leuart.c:78
volatile uint8_t bufferPointer
Definition: leuart.c:79

◆ Leuart_Reinit()

void Leuart_Reinit ( void  )

Definition at line 323 of file leuart.c.

324 {
325  // TODO: Lines below might fix some sleep functionality...
326  //CMU_ClockEnable(cmuClock_CORELE, true);
327  //CMU_ClockEnable(cmuClock_DMA, true);
328  //CMU_ClockEnable(cmuClock_LEUART0, true);
329 
330  LEUART_Reset(RN2483_UART);
332  setupLeuart();
333 
334  /* Auto baud setting */
335  char b[] = "U";
336  sendLeuartData(b, 1);
338  delay(20);
340 }
Leuart_Status_t Leuart_WaitForResponse()
Definition: leuart.c:430
#define RN2483_UART
Definition: pin_mapping.h:115
void Leuart_BreakCondition(void)
Definition: leuart.c:342
static void sendLeuartData(char *buffer, uint8_t bufferLength)
Definition: leuart.c:199
static void setupLeuart(void)
Definition: leuart.c:264
void delay(uint32_t msDelay)
Wait for a certain amount of milliseconds in EM2/3.
Definition: delay.c:124

◆ Leuart_SendCommand()

Leuart_Status_t Leuart_SendCommand ( char *  cb,
uint8_t  cbl,
volatile bool *  wakeUp 
)

Send a command string over the LEUART. "wakeUp" IS NOT USED

Definition at line 392 of file leuart.c.

393 {
394  /* Timeout counter */
395  uint32_t counter = 0;
396 
397  /* Send data over LEUART */
398  sendLeuartData(cb, cbl);
399 
400  /* Wait for response */
401  while ((counter < TIMEOUT_SENDCMD) && !Leuart_ResponseAvailable()) counter++;
402 
403  /* Exit the function if the maximum waiting time was reached */
404  if (counter == TIMEOUT_SENDCMD)
405  {
406 
407 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
408  dbcrit("Waiting time for response reached! (Leuart_SendCommand)");
409 #endif /* DEBUG_DBPRINT */
410 
411  error(54);
412 
413  return (TX_TIMEOUT);
414  }
415 #if DBPRINT_TIMEOUT == 1 /* DBPRINT_TIMEOUT */
416  else
417  {
418 
419 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
420  dbwarnInt("Leuart_SendCommand (", counter, ")");
421 #endif /* DEBUG_DBPRINT */
422 
423  }
424 #endif /* DBPRINT_TIMEOUT */
425 
426  return (DATA_SENT);
427 }
void dbwarnInt(char *message1, int32_t value, char *message2)
Print a warning value surrounded by two strings (char array) to USARTx.
Definition: dbprint.c:598
static bool Leuart_ResponseAvailable(void)
Definition: leuart.c:126
static void sendLeuartData(char *buffer, uint8_t bufferLength)
Definition: leuart.c:199
void error(uint8_t number)
Error method.
Definition: util.c:131
#define TIMEOUT_SENDCMD
Definition: leuart.c:67
void dbcrit(char *message)
Print a critical error string (char array) in red to USARTx and go to the next line.
Definition: dbprint.c:539

◆ Leuart_SendData()

void Leuart_SendData ( char *  buffer,
uint8_t  bufferLength 
)

Definition at line 358 of file leuart.c.

359 {
360  /* Timeout counter */
361  uint32_t counter = 0;
362 
363  /* Send data over LEUART */
364  sendLeuartData(buffer, bufferLength);
365 
366  /* Wait for response */
367  while ((counter < TIMEOUT_WAITRESPONSE) && !Leuart_ResponseAvailable()) counter++;
368 
369  /* Exit the function if the maximum waiting time was reached */
370  if (counter == TIMEOUT_WAITRESPONSE)
371  {
372 
373 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
374  dbcrit("Waiting time for response reached! (Leuart_SendData)");
375 #endif /* DEBUG_DBPRINT */
376 
377  error(53);
378  }
379  else
380  {
381 
382 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
383  dbwarnInt("Leuart_SendData (", counter, ")");
384 #endif /* DEBUG_DBPRINT */
385 
386  }
387 
388  receiveComplete = true;
389 }
void dbwarnInt(char *message1, int32_t value, char *message2)
Print a warning value surrounded by two strings (char array) to USARTx.
Definition: dbprint.c:598
#define TIMEOUT_WAITRESPONSE
Definition: leuart.c:68
static bool Leuart_ResponseAvailable(void)
Definition: leuart.c:126
static void sendLeuartData(char *buffer, uint8_t bufferLength)
Definition: leuart.c:199
void error(uint8_t number)
Error method.
Definition: util.c:131
volatile bool receiveComplete
Definition: leuart.c:80
void dbcrit(char *message)
Print a critical error string (char array) in red to USARTx and go to the next line.
Definition: dbprint.c:539

◆ Leuart_WaitForResponse()

Leuart_Status_t Leuart_WaitForResponse ( )

Definition at line 430 of file leuart.c.

431 {
432  /* Timeout counter */
433  uint32_t counter = 0;
434 
435  /* Activate DMA */
436  DMA_ActivateBasic( DMA_CHANNEL_RX,
437  true,
438  false,
439  (void *)&receiveBuffer[0],
440  (void *)&RN2483_UART->RXDATA,
441  0);
442 
443  /* Wait for response */
444  while ((counter < TIMEOUT_WAITRESPONSE) && !Leuart_ResponseAvailable()) counter++;
445 
446  /* Exit the function if the maximum waiting time was reached */
447  if (counter == TIMEOUT_WAITRESPONSE)
448  {
449 
450 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
451  dbcrit("Waiting time for response reached! (Leuart_WaitForResponse)");
452 #endif /* DEBUG_DBPRINT */
453 
454  error(55);
455 
456  return (RX_TIMEOUT);
457  }
458 #if DBPRINT_TIMEOUT == 1 /* DBPRINT_TIMEOUT */
459  else
460  {
461 
462 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
463  dbwarnInt("Leuart_WaitForResponse (", counter, ")");
464 #endif /* DEBUG_DBPRINT */
465 
466  }
467 #endif /* DBPRINT_TIMEOUT */
468 
469  return (DATA_RECEIVED);
470 }
#define RN2483_UART
Definition: pin_mapping.h:115
void dbwarnInt(char *message1, int32_t value, char *message2)
Print a warning value surrounded by two strings (char array) to USARTx.
Definition: dbprint.c:598
#define TIMEOUT_WAITRESPONSE
Definition: leuart.c:68
#define DMA_CHANNEL_RX
Definition: leuart.c:72
static bool Leuart_ResponseAvailable(void)
Definition: leuart.c:126
void error(uint8_t number)
Error method.
Definition: util.c:131
void dbcrit(char *message)
Print a critical error string (char array) in red to USARTx and go to the next line.
Definition: dbprint.c:539
char receiveBuffer[50]
Definition: leuart.c:78