User manual

LPCXpresso Experiment Kit - User’s Guide
Page 111
Copyright 2013 © Embedded Artists AB
Place the UART related code in file uart.c, and place the function prototype declarations in file
uart.h. Do not forget to remove the retarget.c file and change back C runtime library to
Redlib (semihost).
The code is quite complex and builds on two circular buffers. The receive and transmit buffers can
have different sizes, but they must be a power of two. The reason for this is the special mask
operations (bitwise-AND with size minus 1). Characters to be transmitted should be placed in a circular
buffer. If transmission is not active, start transmission again with the first character in the buffer. As
soon as a character has been transmitted the interrupt handler checks if there are more characters to
be transmitted in the buffer. If no more, disable the transmission interrupt.
Extend the code above to also implement a uint8_t UARTGetCharBlock(void) function
that blocks until a char has been received and returns the received character. Let the new function
make use of the UARTGetChar() function.
Also update the UARTSendString() and UARTSendBuffer() functions from Lab14a. The
suggested function prototypes are as below. These functions are needed on future experiments (with
RF modules).
/*****************************************************************************
** Function name: UARTSendString
**
** Descriptions: Send a null-terminated string to UART 0 port
**
** parameters: byte to send and if call should wait for transfer to complete
** Returned value: None
**
*****************************************************************************/
void UARTSendString(uint8_t *pStr, uint8_t blocking);
/*****************************************************************************
** Function name: UARTSendBuffer
**
** Descriptions: Send a number of bytes/chars of data to UART 0 port
**
** parameters: data to send, number of bytes and if call is blocking
** Returned value: None
**
*****************************************************************************/
void UARTSendBuffer(uint8_t *pBuf, uint16_t length, uint8_t blocking);
Create an application that demonstrates receive and transmit circular buffers. The receive overflow
problem in the previous experiment can for example be handled to some extent if the buffers are large
enough.