Руслан Урядинский / libuavcan

Dependents:   UAVCAN UAVCAN_Subscriber

Embed: (wiki syntax)

« Back to documentation index

CHIP: LPC11xx UART driver

CHIP: LPC11xx UART driver

Data Structures

struct  LPC_USART_T
 USART register block structure. More...

Functions

STATIC INLINE void Chip_UART_TXEnable (LPC_USART_T *pUART)
 Enable transmission on UART TxD pin.
STATIC INLINE void Chip_UART_TXDisable (LPC_USART_T *pUART)
 Disable transmission on UART TxD pin.
STATIC INLINE void Chip_UART_SendByte (LPC_USART_T *pUART, uint8_t data)
 Transmit a single data byte through the UART peripheral.
STATIC INLINE uint8_t Chip_UART_ReadByte (LPC_USART_T *pUART)
 Read a single byte data from the UART peripheral.
STATIC INLINE void Chip_UART_IntEnable (LPC_USART_T *pUART, uint32_t intMask)
 Enable UART interrupts.
STATIC INLINE void Chip_UART_IntDisable (LPC_USART_T *pUART, uint32_t intMask)
 Disable UART interrupts.
STATIC INLINE uint32_t Chip_UART_GetIntsEnabled (LPC_USART_T *pUART)
 Returns UART interrupts that are enabled.
STATIC INLINE uint32_t Chip_UART_ReadIntIDReg (LPC_USART_T *pUART)
 Read the Interrupt Identification Register (IIR)
STATIC INLINE void Chip_UART_SetupFIFOS (LPC_USART_T *pUART, uint32_t fcr)
 Setup the UART FIFOs.
STATIC INLINE void Chip_UART_ConfigData (LPC_USART_T *pUART, uint32_t config)
 Configure data width, parity and stop bits.
STATIC INLINE void Chip_UART_EnableDivisorAccess (LPC_USART_T *pUART)
 Enable access to Divisor Latches.
STATIC INLINE void Chip_UART_DisableDivisorAccess (LPC_USART_T *pUART)
 Disable access to Divisor Latches.
STATIC INLINE void Chip_UART_SetDivisorLatches (LPC_USART_T *pUART, uint8_t dll, uint8_t dlm)
 Set LSB and MSB divisor latch registers.
STATIC INLINE uint32_t Chip_UART_ReadModemControl (LPC_USART_T *pUART)
 Return modem control register/status.
STATIC INLINE void Chip_UART_SetModemControl (LPC_USART_T *pUART, uint32_t mcr)
 Set modem control register/status.
STATIC INLINE void Chip_UART_ClearModemControl (LPC_USART_T *pUART, uint32_t mcr)
 Clear modem control register/status.
STATIC INLINE uint32_t Chip_UART_ReadLineStatus (LPC_USART_T *pUART)
 Return Line Status register/status (LSR)
STATIC INLINE uint32_t Chip_UART_ReadModemStatus (LPC_USART_T *pUART)
 Return Modem Status register/status (MSR)
STATIC INLINE void Chip_UART_SetScratch (LPC_USART_T *pUART, uint8_t data)
 Write a byte to the scratchpad register.
STATIC INLINE uint8_t Chip_UART_ReadScratch (LPC_USART_T *pUART)
 Returns current byte value in the scratchpad register.
STATIC INLINE void Chip_UART_SetAutoBaudReg (LPC_USART_T *pUART, uint32_t acr)
 Set autobaud register options.
STATIC INLINE void Chip_UART_ClearAutoBaudReg (LPC_USART_T *pUART, uint32_t acr)
 Clear autobaud register options.
STATIC INLINE void Chip_UART_SetRS485Flags (LPC_USART_T *pUART, uint32_t ctrl)
 Set RS485 control register options.
STATIC INLINE void Chip_UART_ClearRS485Flags (LPC_USART_T *pUART, uint32_t ctrl)
 Clear RS485 control register options.
STATIC INLINE void Chip_UART_SetRS485Addr (LPC_USART_T *pUART, uint8_t addr)
 Set RS485 address match value.
STATIC INLINE uint8_t Chip_UART_GetRS485Addr (LPC_USART_T *pUART)
 Read RS485 address match value.
STATIC INLINE void Chip_UART_SetRS485Delay (LPC_USART_T *pUART, uint8_t dly)
 Set RS485 direction control (RTS or DTR) delay value.
STATIC INLINE uint8_t Chip_UART_GetRS485Delay (LPC_USART_T *pUART)
 Read RS485 direction control (RTS or DTR) delay value.
void Chip_UART_Init (LPC_USART_T *pUART)
 Initializes the pUART peripheral.
void Chip_UART_DeInit (LPC_USART_T *pUART)
 De-initializes the pUART peripheral.
int Chip_UART_Send (LPC_USART_T *pUART, const void *data, int numBytes)
 Transmit a byte array through the UART peripheral (non-blocking)
int Chip_UART_Read (LPC_USART_T *pUART, void *data, int numBytes)
 Read data through the UART peripheral (non-blocking)
uint32_t Chip_UART_SetBaud (LPC_USART_T *pUART, uint32_t baudrate)
 Sets best dividers to get a target bit rate (without fractional divider)
uint32_t Chip_UART_SetBaudFDR (LPC_USART_T *pUART, uint32_t baudrate)
 Sets best dividers to get a target bit rate (with fractional divider)
int Chip_UART_SendBlocking (LPC_USART_T *pUART, const void *data, int numBytes)
 Transmit a byte array through the UART peripheral (blocking)
int Chip_UART_ReadBlocking (LPC_USART_T *pUART, void *data, int numBytes)
 Read data through the UART peripheral (blocking)
void Chip_UART_RXIntHandlerRB (LPC_USART_T *pUART, RINGBUFF_T *pRB)
 UART receive-only interrupt handler for ring buffers.
void Chip_UART_TXIntHandlerRB (LPC_USART_T *pUART, RINGBUFF_T *pRB)
 UART transmit-only interrupt handler for ring buffers.
uint32_t Chip_UART_SendRB (LPC_USART_T *pUART, RINGBUFF_T *pRB, const void *data, int bytes)
 Populate a transmit ring buffer and start UART transmit.
int Chip_UART_ReadRB (LPC_USART_T *pUART, RINGBUFF_T *pRB, void *data, int bytes)
 Copy data from a receive ring buffer.
void Chip_UART_IRQRBHandler (LPC_USART_T *pUART, RINGBUFF_T *pRXRB, RINGBUFF_T *pTXRB)
 UART receive/transmit interrupt handler for ring buffers.

Function Documentation

STATIC INLINE void Chip_UART_ClearAutoBaudReg ( LPC_USART_T pUART,
uint32_t  acr 
)

Clear autobaud register options.

Parameters:
pUART: Pointer to selected UART peripheral
acr: Or'ed values to clear for ACR register
Returns:
Nothing
Note:
Use an Or'ed value of UART_ACR_* definitions with this call to clear specific options.

Definition at line 564 of file uart_11xx.h.

STATIC INLINE void Chip_UART_ClearModemControl ( LPC_USART_T pUART,
uint32_t  mcr 
)

Clear modem control register/status.

Parameters:
pUART: Pointer to selected UART peripheral
mcr: Modem control register flags to clear
Returns:
Nothing
Note:
Use an Or'ed value of UART_MCR_* definitions with this call to clear specific options.

Definition at line 493 of file uart_11xx.h.

STATIC INLINE void Chip_UART_ClearRS485Flags ( LPC_USART_T pUART,
uint32_t  ctrl 
)

Clear RS485 control register options.

Parameters:
pUART: Pointer to selected UART peripheral
ctrl: Or'ed values to clear for RS485 control register
Returns:
Nothing
Note:
Use an Or'ed value of UART_RS485CTRL_* definitions with this call to clear specific options.

Definition at line 590 of file uart_11xx.h.

STATIC INLINE void Chip_UART_ConfigData ( LPC_USART_T pUART,
uint32_t  config 
)

Configure data width, parity and stop bits.

Parameters:
pUART: Pointer to selected pUART peripheral
config: UART configuration, OR'ed values of UART_LCR_* defines
Returns:
Nothing
Note:
Select OR'ed config options for the UART from the UART_LCR_* definitions. For example, a configuration of 8 data bits, 1 stop bit, and even (enabled) parity would be (UART_LCR_WLEN8 | UART_LCR_SBS_1BIT | UART_LCR_PARITY_EN | UART_LCR_PARITY_EVEN)

Definition at line 419 of file uart_11xx.h.

void Chip_UART_DeInit ( LPC_USART_T pUART )

De-initializes the pUART peripheral.

Parameters:
pUART: Pointer to selected pUART peripheral
Returns:
Nothing

Definition at line 74 of file uart_11xx.c.

STATIC INLINE void Chip_UART_DisableDivisorAccess ( LPC_USART_T pUART )

Disable access to Divisor Latches.

Parameters:
pUART: Pointer to selected UART peripheral
Returns:
Nothing

Definition at line 439 of file uart_11xx.h.

STATIC INLINE void Chip_UART_EnableDivisorAccess ( LPC_USART_T pUART )

Enable access to Divisor Latches.

Parameters:
pUART: Pointer to selected UART peripheral
Returns:
Nothing

Definition at line 429 of file uart_11xx.h.

STATIC INLINE uint32_t Chip_UART_GetIntsEnabled ( LPC_USART_T pUART )

Returns UART interrupts that are enabled.

Parameters:
pUART: Pointer to selected UART peripheral
Returns:
Returns the enabled UART interrupts
Note:
Use an OR'ed value of UART_IER_* definitions with this function to determine which interrupts are enabled. You can check for multiple enabled bits if needed.

Definition at line 379 of file uart_11xx.h.

STATIC INLINE uint8_t Chip_UART_GetRS485Addr ( LPC_USART_T pUART )

Read RS485 address match value.

Parameters:
pUART: Pointer to selected UART peripheral
Returns:
Address match value for RS-485/EIA-485 mode

Definition at line 611 of file uart_11xx.h.

STATIC INLINE uint8_t Chip_UART_GetRS485Delay ( LPC_USART_T pUART )

Read RS485 direction control (RTS or DTR) delay value.

Parameters:
pUART: Pointer to selected UART peripheral
Returns:
direction control (RTS or DTR) delay value
Note:
This delay time is in periods of the baud clock. Any delay time from 0 to 255 bit times may be programmed.

Definition at line 636 of file uart_11xx.h.

void Chip_UART_Init ( LPC_USART_T pUART )

Initializes the pUART peripheral.

Parameters:
pUART: Pointer to selected pUART peripheral
Returns:
Nothing

Definition at line 58 of file uart_11xx.c.

STATIC INLINE void Chip_UART_IntDisable ( LPC_USART_T pUART,
uint32_t  intMask 
)

Disable UART interrupts.

Parameters:
pUART: Pointer to selected UART peripheral
intMask: OR'ed Interrupts to disable in the Interrupt Enable Register (IER)
Returns:
Nothing
Note:
Use an OR'ed value of UART_IER_* definitions with this function to disable specific UART interrupts. The Divisor Latch Access Bit (DLAB) in LCR must be cleared in order to access the IER register. This function doesn't alter the DLAB state

Definition at line 366 of file uart_11xx.h.

STATIC INLINE void Chip_UART_IntEnable ( LPC_USART_T pUART,
uint32_t  intMask 
)

Enable UART interrupts.

Parameters:
pUART: Pointer to selected UART peripheral
intMask: OR'ed Interrupts to enable in the Interrupt Enable Register (IER)
Returns:
Nothing
Note:
Use an OR'ed value of UART_IER_* definitions with this function to enable specific UART interrupts. The Divisor Latch Access Bit (DLAB) in LCR must be cleared in order to access the IER register. This function doesn't alter the DLAB state

Definition at line 351 of file uart_11xx.h.

void Chip_UART_IRQRBHandler ( LPC_USART_T pUART,
RINGBUFF_T pRXRB,
RINGBUFF_T pTXRB 
)

UART receive/transmit interrupt handler for ring buffers.

Parameters:
pUART: Pointer to selected UART peripheral
pRXRB: Pointer to transmit ring buffer
pTXRB: Pointer to receive ring buffer
Returns:
Nothing
Note:
This provides a basic implementation of the UART IRQ handler for support of a ring buffer implementation for transmit and receive.

Definition at line 220 of file uart_11xx.c.

int Chip_UART_Read ( LPC_USART_T pUART,
void *  data,
int  numBytes 
)

Read data through the UART peripheral (non-blocking)

Parameters:
pUART: Pointer to selected UART peripheral
data: Pointer to bytes array to fill
numBytes: Size of the passed data array
Returns:
The actual number of bytes read
Note:
This function reads data from the receive FIFO until either all the data has been read or the passed buffer is completely full. This function will not block. This function ignores errors.

Definition at line 113 of file uart_11xx.c.

int Chip_UART_ReadBlocking ( LPC_USART_T pUART,
void *  data,
int  numBytes 
)

Read data through the UART peripheral (blocking)

Parameters:
pUART: Pointer to selected UART peripheral
data: Pointer to data array to fill
numBytes: Size of the passed data array
Returns:
The size of the dat array
Note:
This function reads data from the receive FIFO until the passed buffer is completely full. The function will block until full. This function ignores errors.

Definition at line 130 of file uart_11xx.c.

STATIC INLINE uint8_t Chip_UART_ReadByte ( LPC_USART_T pUART )

Read a single byte data from the UART peripheral.

Parameters:
pUART: Pointer to selected UART peripheral
Returns:
A single byte of data read
Note:
This function reads a byte from the UART receive FIFO or receive hold register regard regardless of UART state. The FIFO status should be read first prior to using this function

Definition at line 336 of file uart_11xx.h.

STATIC INLINE uint32_t Chip_UART_ReadIntIDReg ( LPC_USART_T pUART )

Read the Interrupt Identification Register (IIR)

Parameters:
pUART: Pointer to selected UART peripheral
Returns:
Current pending interrupt status per the IIR register

Definition at line 389 of file uart_11xx.h.

STATIC INLINE uint32_t Chip_UART_ReadLineStatus ( LPC_USART_T pUART )

Return Line Status register/status (LSR)

Parameters:
pUART: Pointer to selected UART peripheral
Returns:
Line Status register (status)
Note:
Mask bits of the returned status value with UART_LSR_* definitions for specific statuses.

Definition at line 505 of file uart_11xx.h.

STATIC INLINE uint32_t Chip_UART_ReadModemControl ( LPC_USART_T pUART )

Return modem control register/status.

Parameters:
pUART: Pointer to selected UART peripheral
Returns:
Modem control register (status)
Note:
Mask bits of the returned status value with UART_MCR_* definitions for specific statuses.

Definition at line 467 of file uart_11xx.h.

STATIC INLINE uint32_t Chip_UART_ReadModemStatus ( LPC_USART_T pUART )

Return Modem Status register/status (MSR)

Parameters:
pUART: Pointer to selected UART peripheral
Returns:
Modem Status register (status)
Note:
Mask bits of the returned status value with UART_MSR_* definitions for specific statuses.

Definition at line 517 of file uart_11xx.h.

int Chip_UART_ReadRB ( LPC_USART_T pUART,
RINGBUFF_T pRB,
void *  data,
int  bytes 
)

Copy data from a receive ring buffer.

Parameters:
pUART: Pointer to selected UART peripheral
pRB: Pointer to ring buffer structure to use
data: Pointer to buffer to fill from ring buffer
bytes: Size of the passed buffer in bytes
Returns:
The number of bytes placed into the ring buffer
Note:
Will move the data from the RX ring buffer up to the the maximum passed buffer size. Returns 0 if there is no data in the ring buffer.

Definition at line 212 of file uart_11xx.c.

STATIC INLINE uint8_t Chip_UART_ReadScratch ( LPC_USART_T pUART )

Returns current byte value in the scratchpad register.

Parameters:
pUART: Pointer to selected UART peripheral
Returns:
Byte value read from scratchpad register

Definition at line 538 of file uart_11xx.h.

void Chip_UART_RXIntHandlerRB ( LPC_USART_T pUART,
RINGBUFF_T pRB 
)

UART receive-only interrupt handler for ring buffers.

Parameters:
pUART: Pointer to selected UART peripheral
pRB: Pointer to ring buffer structure to use
Returns:
Nothing
Note:
If ring buffer support is desired for the receive side of data transfer, the UART interrupt should call this function for a receive based interrupt status.

Definition at line 168 of file uart_11xx.c.

int Chip_UART_Send ( LPC_USART_T pUART,
const void *  data,
int  numBytes 
)

Transmit a byte array through the UART peripheral (non-blocking)

Parameters:
pUART: Pointer to selected UART peripheral
data: Pointer to bytes to transmit
numBytes: Number of bytes to transmit
Returns:
The actual number of bytes placed into the FIFO
Note:
This function places data into the transmit FIFO until either all the data is in the FIFO or the FIFO is full. This function will not block in the FIFO is full. The actual number of bytes placed into the FIFO is returned. This function ignores errors.

Definition at line 80 of file uart_11xx.c.

int Chip_UART_SendBlocking ( LPC_USART_T pUART,
const void *  data,
int  numBytes 
)

Transmit a byte array through the UART peripheral (blocking)

Parameters:
pUART: Pointer to selected UART peripheral
data: Pointer to data to transmit
numBytes: Number of bytes to transmit
Returns:
The number of bytes transmitted
Note:
This function will send or place all bytes into the transmit FIFO. This function will block until the last bytes are in the FIFO.

Definition at line 97 of file uart_11xx.c.

STATIC INLINE void Chip_UART_SendByte ( LPC_USART_T pUART,
uint8_t  data 
)

Transmit a single data byte through the UART peripheral.

Parameters:
pUART: Pointer to selected UART peripheral
data: Byte to transmit
Returns:
Nothing
Note:
This function attempts to place a byte into the UART transmit FIFO or transmit hold register regard regardless of UART state

Definition at line 323 of file uart_11xx.h.

uint32_t Chip_UART_SendRB ( LPC_USART_T pUART,
RINGBUFF_T pRB,
const void *  data,
int  bytes 
)

Populate a transmit ring buffer and start UART transmit.

Parameters:
pUART: Pointer to selected UART peripheral
pRB: Pointer to ring buffer structure to use
data: Pointer to buffer to move to ring buffer
bytes: Number of bytes to move
Returns:
The number of bytes placed into the ring buffer
Note:
Will move the data into the TX ring buffer and start the transfer. If the number of bytes returned is less than the number of bytes to send, the ring buffer is considered full.

Definition at line 190 of file uart_11xx.c.

STATIC INLINE void Chip_UART_SetAutoBaudReg ( LPC_USART_T pUART,
uint32_t  acr 
)

Set autobaud register options.

Parameters:
pUART: Pointer to selected UART peripheral
acr: Or'ed values to set for ACR register
Returns:
Nothing
Note:
Use an Or'ed value of UART_ACR_* definitions with this call to set specific options.

Definition at line 551 of file uart_11xx.h.

uint32_t Chip_UART_SetBaud ( LPC_USART_T pUART,
uint32_t  baudrate 
)

Sets best dividers to get a target bit rate (without fractional divider)

Parameters:
pUART: Pointer to selected UART peripheral
baudrate: Target baud rate (baud rate = bit rate)
Returns:
The actual baud rate, or 0 if no rate can be found

Definition at line 146 of file uart_11xx.c.

uint32_t Chip_UART_SetBaudFDR ( LPC_USART_T pUART,
uint32_t  baudrate 
)

Sets best dividers to get a target bit rate (with fractional divider)

Parameters:
pUART: Pointer to selected UART peripheral
baudrate: Target baud rate (baud rate = bit rate)
Returns:
The actual baud rate, or 0 if no rate can be found

Definition at line 237 of file uart_11xx.c.

STATIC INLINE void Chip_UART_SetDivisorLatches ( LPC_USART_T pUART,
uint8_t  dll,
uint8_t  dlm 
)

Set LSB and MSB divisor latch registers.

Parameters:
pUART: Pointer to selected UART peripheral
dll: Divisor Latch LSB value
dlm: Divisor Latch MSB value
Returns:
Nothing
Note:
The Divisor Latch Access Bit (DLAB) in LCR must be set in order to access the USART Divisor Latches. This function doesn't alter the DLAB state.

Definition at line 454 of file uart_11xx.h.

STATIC INLINE void Chip_UART_SetModemControl ( LPC_USART_T pUART,
uint32_t  mcr 
)

Set modem control register/status.

Parameters:
pUART: Pointer to selected UART peripheral
mcr: Modem control register flags to set
Returns:
Nothing
Note:
Use an Or'ed value of UART_MCR_* definitions with this call to set specific options.

Definition at line 480 of file uart_11xx.h.

STATIC INLINE void Chip_UART_SetRS485Addr ( LPC_USART_T pUART,
uint8_t  addr 
)

Set RS485 address match value.

Parameters:
pUART: Pointer to selected UART peripheral
addr: Address match value for RS-485/EIA-485 mode
Returns:
Nothing

Definition at line 601 of file uart_11xx.h.

STATIC INLINE void Chip_UART_SetRS485Delay ( LPC_USART_T pUART,
uint8_t  dly 
)

Set RS485 direction control (RTS or DTR) delay value.

Parameters:
pUART: Pointer to selected UART peripheral
dly: direction control (RTS or DTR) delay value
Returns:
Nothing
Note:
This delay time is in periods of the baud clock. Any delay time from 0 to 255 bit times may be programmed.

Definition at line 624 of file uart_11xx.h.

STATIC INLINE void Chip_UART_SetRS485Flags ( LPC_USART_T pUART,
uint32_t  ctrl 
)

Set RS485 control register options.

Parameters:
pUART: Pointer to selected UART peripheral
ctrl: Or'ed values to set for RS485 control register
Returns:
Nothing
Note:
Use an Or'ed value of UART_RS485CTRL_* definitions with this call to set specific options.

Definition at line 577 of file uart_11xx.h.

STATIC INLINE void Chip_UART_SetScratch ( LPC_USART_T pUART,
uint8_t  data 
)

Write a byte to the scratchpad register.

Parameters:
pUART: Pointer to selected UART peripheral
data: Byte value to write
Returns:
Nothing

Definition at line 528 of file uart_11xx.h.

STATIC INLINE void Chip_UART_SetupFIFOS ( LPC_USART_T pUART,
uint32_t  fcr 
)

Setup the UART FIFOs.

Parameters:
pUART: Pointer to selected UART peripheral
fcr: FIFO control register setup OR'ed flags
Returns:
Nothing
Note:
Use OR'ed value of UART_FCR_* definitions with this function to select specific options. For example, to enable the FIFOs with a RX trip level of 8 characters, use something like (UART_FCR_FIFO_EN | UART_FCR_TRG_LEV2)

Definition at line 404 of file uart_11xx.h.

STATIC INLINE void Chip_UART_TXDisable ( LPC_USART_T pUART )

Disable transmission on UART TxD pin.

Parameters:
pUART: Pointer to selected pUART peripheral
Returns:
Nothing

Definition at line 310 of file uart_11xx.h.

STATIC INLINE void Chip_UART_TXEnable ( LPC_USART_T pUART )

Enable transmission on UART TxD pin.

Parameters:
pUART: Pointer to selected pUART peripheral
Returns:
Nothing

Definition at line 300 of file uart_11xx.h.

void Chip_UART_TXIntHandlerRB ( LPC_USART_T pUART,
RINGBUFF_T pRB 
)

UART transmit-only interrupt handler for ring buffers.

Parameters:
pUART: Pointer to selected UART peripheral
pRB: Pointer to ring buffer structure to use
Returns:
Nothing
Note:
If ring buffer support is desired for the transmit side of data transfer, the UART interrupt should call this function for a transmit based interrupt status.

Definition at line 178 of file uart_11xx.c.