# MIOS32_UART

## Defines
#define | UART_PERIPHERAL_FRQ (MIOS32_SYS_CPU_FREQUENCY/4)
#define | MIOS32_UART0_TX_INIT { MIOS32_SYS_LPC_PINSEL(2, 0, 2); MIOS32_SYS_LPC_PINMODE(2, 0, 2); MIOS32_SYS_LPC_PINMODE_OD(2, 0, 1); }
#define | MIOS32_UART0_RX_INIT { MIOS32_SYS_LPC_PINSEL(2, 1, 2); MIOS32_SYS_LPC_PINMODE(2, 1, 0); }
#define | MIOS32_UART0 LPC_UART1
#define | MIOS32_UART0_IRQ_CHANNEL UART1_IRQn
#define | MIOS32_UART0_IRQHANDLER_FUNC void UART1_IRQHandler(void)
#define | MIOS32_UART1_TX_INIT { MIOS32_SYS_LPC_PINSEL(0, 0, 2); MIOS32_SYS_LPC_PINMODE(0, 0, 2); MIOS32_SYS_LPC_PINMODE_OD(0, 0, 1); }
#define | MIOS32_UART1_RX_INIT { MIOS32_SYS_LPC_PINSEL(0, 1, 2); MIOS32_SYS_LPC_PINMODE(0, 1, 0); }
#define | MIOS32_UART1 LPC_UART3
#define | MIOS32_UART1_IRQ_CHANNEL UART3_IRQn
#define | MIOS32_UART1_IRQHANDLER_FUNC void UART3_IRQHandler(void)
#define | MIOS32_UART2_TX_INIT { MIOS32_SYS_LPC_PINSEL(0, 2, 1); MIOS32_SYS_LPC_PINMODE(0, 2, 2); MIOS32_SYS_LPC_PINMODE_OD(0, 2, 1); }
#define | MIOS32_UART2_RX_INIT { MIOS32_SYS_LPC_PINSEL(0, 3, 1); MIOS32_SYS_LPC_PINMODE(0, 3, 0); }
#define | MIOS32_UART2 LPC_UART0
#define | MIOS32_UART2_IRQ_CHANNEL UART0_IRQn
#define | MIOS32_UART2_IRQHANDLER_FUNC void UART0_IRQHandler(void)
#define | MIOS32_UART3_TX_INIT { MIOS32_SYS_LPC_PINSEL(0, 10, 1); MIOS32_SYS_LPC_PINMODE(0, 10, 2); MIOS32_SYS_LPC_PINMODE_OD(0, 10, 1); }
#define | MIOS32_UART3_RX_INIT { MIOS32_SYS_LPC_PINSEL(0, 11, 1); MIOS32_SYS_LPC_PINMODE(0, 11, 0); }
#define | MIOS32_UART3 LPC_UART2
#define | MIOS32_UART3_IRQ_CHANNEL UART2_IRQn
#define | MIOS32_UART3_IRQHANDLER_FUNC void UART2_IRQHandler(void)
#define | LSR_RDR 0x01
#define | LSR_OE 0x02
#define | LSR_PE 0x04
#define | LSR_FE 0x08
#define | LSR_BI 0x10
#define | LSR_THRE 0x20
#define | LSR_TEMT 0x40
#define | LSR_RXFE 0x80
#define | NUM_SUPPORTED_UARTS 3
#define | MIOS32_UART0_TX_PORT GPIOA
#define | MIOS32_UART0_TX_PIN GPIO_Pin_9
#define | MIOS32_UART0_RX_PORT GPIOA
#define | MIOS32_UART0_RX_PIN GPIO_Pin_10
#define | MIOS32_UART0 USART1
#define | MIOS32_UART0_IRQ_CHANNEL USART1_IRQn
#define | MIOS32_UART0_IRQHANDLER_FUNC void USART1_IRQHandler(void)
#define | MIOS32_UART0_REMAP_FUNC {}
#define | MIOS32_UART1_TX_PORT GPIOC
#define | MIOS32_UART1_TX_PIN GPIO_Pin_10
#define | MIOS32_UART1_RX_PORT GPIOC
#define | MIOS32_UART1_RX_PIN GPIO_Pin_11
#define | MIOS32_UART1 USART3
#define | MIOS32_UART1_IRQ_CHANNEL USART3_IRQn
#define | MIOS32_UART1_IRQHANDLER_FUNC void USART3_IRQHandler(void)
#define | MIOS32_UART1_REMAP_FUNC { GPIO_PinRemapConfig(GPIO_PartialRemap_USART3, ENABLE); }
#define | MIOS32_UART2_TX_PORT GPIOA
#define | MIOS32_UART2_TX_PIN GPIO_Pin_2
#define | MIOS32_UART2_RX_PORT GPIOA
#define | MIOS32_UART2_RX_PIN GPIO_Pin_3
#define | MIOS32_UART2 USART2
#define | MIOS32_UART2_IRQ_CHANNEL USART2_IRQn
#define | MIOS32_UART2_IRQHANDLER_FUNC void USART2_IRQHandler(void)
#define | MIOS32_UART2_REMAP_FUNC {}
#define | NUM_SUPPORTED_UARTS MIOS32_UART_NUM
#define | MIOS32_UART0_TX_PORT GPIOA
#define | MIOS32_UART0_TX_PIN GPIO_Pin_2
#define | MIOS32_UART0_RX_PORT GPIOA
#define | MIOS32_UART0_RX_PIN GPIO_Pin_3
#define | MIOS32_UART0 USART2
#define | MIOS32_UART0_IRQ_CHANNEL USART2_IRQn
#define | MIOS32_UART0_IRQHANDLER_FUNC void USART2_IRQHandler(void)
#define | MIOS32_UART0_REMAP_FUNC { GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2); GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_USART2); }
#define | MIOS32_UART1_TX_PORT GPIOD
#define | MIOS32_UART1_TX_PIN GPIO_Pin_8
#define | MIOS32_UART1_RX_PORT GPIOD
#define | MIOS32_UART1_RX_PIN GPIO_Pin_9
#define | MIOS32_UART1 USART3
#define | MIOS32_UART1_IRQ_CHANNEL USART3_IRQn
#define | MIOS32_UART1_IRQHANDLER_FUNC void USART3_IRQHandler(void)
#define | MIOS32_UART1_REMAP_FUNC { GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_USART3); GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_USART3); }
#define | MIOS32_UART2_TX_PORT GPIOC
#define | MIOS32_UART2_TX_PIN GPIO_Pin_6
#define | MIOS32_UART2_RX_PORT GPIOB
#define | MIOS32_UART2_RX_PIN GPIO_Pin_7
#define | MIOS32_UART2_TX USART6
#define | MIOS32_UART2_RX USART1
#define | MIOS32_UART2_TX_IRQ_CHANNEL USART6_IRQn
#define | MIOS32_UART2_RX_IRQ_CHANNEL USART1_IRQn
#define | MIOS32_UART2_TX_IRQHANDLER_FUNC void USART6_IRQHandler(void)
#define | MIOS32_UART2_RX_IRQHANDLER_FUNC void USART1_IRQHandler(void)
#define | MIOS32_UART2_REMAP_FUNC { GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_USART6); GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_USART1); }
#define | MIOS32_UART3_TX_PORT GPIOC
#define | MIOS32_UART3_TX_PIN GPIO_Pin_12
#define | MIOS32_UART3_RX_PORT GPIOD
#define | MIOS32_UART3_RX_PIN GPIO_Pin_2
#define | MIOS32_UART3 UART5
#define | MIOS32_UART3_IRQ_CHANNEL UART5_IRQn
#define | MIOS32_UART3_IRQHANDLER_FUNC void UART5_IRQHandler(void)
#define | MIOS32_UART3_REMAP_FUNC { GPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_UART5); GPIO_PinAFConfig(GPIOD, GPIO_PinSource2, GPIO_AF_UART5); }
## Functions
s32 | MIOS32_UART_BaudrateSet (u8 uart, u32 baudrate)
u32 | MIOS32_UART_BaudrateGet (u8 uart)
s32 | MIOS32_UART_RxBufferFree (u8 uart)
s32 | MIOS32_UART_RxBufferUsed (u8 uart)
s32 | MIOS32_UART_RxBufferGet (u8 uart)
s32 | MIOS32_UART_RxBufferPeek (u8 uart)
s32 | MIOS32_UART_RxBufferPut (u8 uart, u8 b)
s32 | MIOS32_UART_TxBufferFree (u8 uart)
s32 | MIOS32_UART_TxBufferUsed (u8 uart)
s32 | MIOS32_UART_TxBufferGet (u8 uart)
s32 | MIOS32_UART_TxBufferPutMore_NonBlocking (u8 uart, u8 *buffer, u16 len)
s32 | MIOS32_UART_TxBufferPutMore (u8 uart, u8 *buffer, u16 len)
s32 | MIOS32_UART_TxBufferPut_NonBlocking (u8 uart, u8 b)
s32 | MIOS32_UART_TxBufferPut (u8 uart, u8 b)
s32 | MIOS32_UART_Init (u32 mode)

## Detailed Description

U(S)ART functions for MIOS32

Applications shouldn't call these functions directly, instead please use MIOS32_COM or MIOS32_MIDI layer functions

## Define Documentation

#define LSR_BI 0x10

#define LSR_FE 0x08

#define LSR_OE 0x02

#define LSR_PE 0x04

#define LSR_RDR 0x01

#define LSR_RXFE 0x80

#define LSR_TEMT 0x40

#define LSR_THRE 0x20

#define MIOS32_UART0 USART2

#define MIOS32_UART0 USART1

#define MIOS32_UART0 LPC_UART1

#define MIOS32_UART0_IRQ_CHANNEL USART2_IRQn

#define MIOS32_UART0_IRQ_CHANNEL USART1_IRQn

#define MIOS32_UART0_IRQ_CHANNEL UART1_IRQn

#define MIOS32_UART0_IRQHANDLER_FUNC void USART2_IRQHandler(void)

#define MIOS32_UART0_IRQHANDLER_FUNC void USART1_IRQHandler(void)

#define MIOS32_UART0_IRQHANDLER_FUNC void UART1_IRQHandler(void)

#define MIOS32_UART0_REMAP_FUNC { GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2); GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_USART2); }

#define MIOS32_UART0_REMAP_FUNC {}

#define MIOS32_UART0_RX_INIT { MIOS32_SYS_LPC_PINSEL(2, 1, 2); MIOS32_SYS_LPC_PINMODE(2, 1, 0); }

#define MIOS32_UART0_RX_PIN GPIO_Pin_3

#define MIOS32_UART0_RX_PIN GPIO_Pin_10

#define MIOS32_UART0_RX_PORT GPIOA

#define MIOS32_UART0_TX_INIT { MIOS32_SYS_LPC_PINSEL(2, 0, 2); MIOS32_SYS_LPC_PINMODE(2, 0, 2); MIOS32_SYS_LPC_PINMODE_OD(2, 0, 1); }

#define MIOS32_UART0_TX_PIN GPIO_Pin_2

#define MIOS32_UART0_TX_PIN GPIO_Pin_9

#define MIOS32_UART0_TX_PORT GPIOA

#define MIOS32_UART1 USART3

#define MIOS32_UART1 LPC_UART3

#define MIOS32_UART1_IRQ_CHANNEL USART3_IRQn

#define MIOS32_UART1_IRQ_CHANNEL UART3_IRQn

#define MIOS32_UART1_IRQHANDLER_FUNC void USART3_IRQHandler(void)

#define MIOS32_UART1_IRQHANDLER_FUNC void UART3_IRQHandler(void)

#define MIOS32_UART1_REMAP_FUNC { GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_USART3); GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_USART3); }

#define MIOS32_UART1_REMAP_FUNC { GPIO_PinRemapConfig(GPIO_PartialRemap_USART3, ENABLE); }

#define MIOS32_UART1_RX_INIT { MIOS32_SYS_LPC_PINSEL(0, 1, 2); MIOS32_SYS_LPC_PINMODE(0, 1, 0); }

#define MIOS32_UART1_RX_PIN GPIO_Pin_9

#define MIOS32_UART1_RX_PIN GPIO_Pin_11

#define MIOS32_UART1_RX_PORT GPIOD

#define MIOS32_UART1_RX_PORT GPIOC

#define MIOS32_UART1_TX_INIT { MIOS32_SYS_LPC_PINSEL(0, 0, 2); MIOS32_SYS_LPC_PINMODE(0, 0, 2); MIOS32_SYS_LPC_PINMODE_OD(0, 0, 1); }

#define MIOS32_UART1_TX_PIN GPIO_Pin_8

#define MIOS32_UART1_TX_PIN GPIO_Pin_10

#define MIOS32_UART1_TX_PORT GPIOD

#define MIOS32_UART1_TX_PORT GPIOC

#define MIOS32_UART2 USART2

#define MIOS32_UART2 LPC_UART0

#define MIOS32_UART2_IRQ_CHANNEL USART2_IRQn

#define MIOS32_UART2_IRQ_CHANNEL UART0_IRQn

#define MIOS32_UART2_IRQHANDLER_FUNC void USART2_IRQHandler(void)

#define MIOS32_UART2_IRQHANDLER_FUNC void UART0_IRQHandler(void)

#define MIOS32_UART2_REMAP_FUNC { GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_USART6); GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_USART1); }

#define MIOS32_UART2_REMAP_FUNC {}

#define MIOS32_UART2_RX USART1

#define MIOS32_UART2_RX_INIT { MIOS32_SYS_LPC_PINSEL(0, 3, 1); MIOS32_SYS_LPC_PINMODE(0, 3, 0); }

#define MIOS32_UART2_RX_IRQ_CHANNEL USART1_IRQn

#define MIOS32_UART2_RX_IRQHANDLER_FUNC void USART1_IRQHandler(void)

#define MIOS32_UART2_RX_PIN GPIO_Pin_7

#define MIOS32_UART2_RX_PIN GPIO_Pin_3

#define MIOS32_UART2_RX_PORT GPIOB

#define MIOS32_UART2_RX_PORT GPIOA

#define MIOS32_UART2_TX USART6

#define MIOS32_UART2_TX_INIT { MIOS32_SYS_LPC_PINSEL(0, 2, 1); MIOS32_SYS_LPC_PINMODE(0, 2, 2); MIOS32_SYS_LPC_PINMODE_OD(0, 2, 1); }

#define MIOS32_UART2_TX_IRQ_CHANNEL USART6_IRQn

#define MIOS32_UART2_TX_IRQHANDLER_FUNC void USART6_IRQHandler(void)

#define MIOS32_UART2_TX_PIN GPIO_Pin_6

#define MIOS32_UART2_TX_PIN GPIO_Pin_2

#define MIOS32_UART2_TX_PORT GPIOC

#define MIOS32_UART2_TX_PORT GPIOA

#define MIOS32_UART3 UART5

#define MIOS32_UART3 LPC_UART2

#define MIOS32_UART3_IRQ_CHANNEL UART5_IRQn

#define MIOS32_UART3_IRQ_CHANNEL UART2_IRQn

#define MIOS32_UART3_IRQHANDLER_FUNC void UART5_IRQHandler(void)

#define MIOS32_UART3_IRQHANDLER_FUNC void UART2_IRQHandler(void)

#define MIOS32_UART3_REMAP_FUNC { GPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_UART5); GPIO_PinAFConfig(GPIOD, GPIO_PinSource2, GPIO_AF_UART5); }

#define MIOS32_UART3_RX_INIT { MIOS32_SYS_LPC_PINSEL(0, 11, 1); MIOS32_SYS_LPC_PINMODE(0, 11, 0); }

#define MIOS32_UART3_RX_PIN GPIO_Pin_2

#define MIOS32_UART3_RX_PORT GPIOD

#define MIOS32_UART3_TX_INIT { MIOS32_SYS_LPC_PINSEL(0, 10, 1); MIOS32_SYS_LPC_PINMODE(0, 10, 2); MIOS32_SYS_LPC_PINMODE_OD(0, 10, 1); }

#define MIOS32_UART3_TX_PIN GPIO_Pin_12

#define MIOS32_UART3_TX_PORT GPIOC

#define NUM_SUPPORTED_UARTS MIOS32_UART_NUM

#define NUM_SUPPORTED_UARTS 3

#define UART_PERIPHERAL_FRQ (MIOS32_SYS_CPU_FREQUENCY/4)

## Function Documentation

u32 MIOS32_UART_BaudrateGet | ( | u8 | uart | ) |

returns the current baudrate of a UART port

Parameters:

  `[in]` | uart | UART number (0..2)

Returns:
  0: uart not available
  all other values: the current baudrate

s32 MIOS32_UART_BaudrateSet | ( | u8 | uart,
|  | u32 | baudrate |
| ) |  |  |

sets the baudrate of a UART port

Parameters:

  `[in]` | uart | UART number (0..2)
  `[in]` | baudrate | the baudrate

Returns:
  0: baudrate has been changed
  -1: uart not available
  -2: function not prepared for this UART

s32 MIOS32_UART_Init | ( | u32 | mode | ) |

Initializes UART interfaces

Parameters:

  `[in]` | mode | currently only mode 0 supported

Returns:
  < 0 if initialisation failed

Note:
  Applications shouldn't call this function directly, instead please use MIOS32_COM or MIOS32_MIDI layer functions

Here is the call graph for this function:

s32 MIOS32_UART_RxBufferFree | ( | u8 | uart | ) |

returns number of free bytes in receive buffer

Parameters:

  `[in]` | uart | UART number (0..2)

Returns:
  uart number of free bytes
  1: uart available
  0: uart not available

s32 MIOS32_UART_RxBufferGet | ( | u8 | uart | ) |

gets a byte from the receive buffer

Parameters:

  `[in]` | uart | UART number (0..2)

Returns:
  -1 if UART not available
  -2 if no new byte available
  >= 0: number of received bytes

Note:
  Applications shouldn't call these functions directly, instead please use MIOS32_COM or MIOS32_MIDI layer functions

Here is the call graph for this function:

s32 MIOS32_UART_RxBufferPeek | ( | u8 | uart | ) |

returns the next byte of the receive buffer without taking it

Parameters:

  `[in]` | uart | UART number (0..2)

Returns:
  -1 if UART not available
  -2 if no new byte available
  >= 0: number of received bytes

Note:
  Applications shouldn't call these functions directly, instead please use MIOS32_COM or MIOS32_MIDI layer functions

Here is the call graph for this function:

s32 MIOS32_UART_RxBufferPut | ( | u8 | uart,
|  | u8 | b |
| ) |  |  |

puts a byte onto the receive buffer

Parameters:

  `[in]` | uart | UART number (0..2)
  `[in]` | b | byte which should be put into Rx buffer

Returns:
  0 if no error
  -1 if UART not available
  -2 if buffer full (retry)

Note:
  Applications shouldn't call these functions directly, instead please use MIOS32_COM or MIOS32_MIDI layer functions

Here is the call graph for this function:

s32 MIOS32_UART_RxBufferUsed | ( | u8 | uart | ) |

returns number of used bytes in receive buffer

Parameters:

  `[in]` | uart | UART number (0..2)

Returns:
  > 0: number of used bytes
  0 if uart not available

Note:
  Applications shouldn't call these functions directly, instead please use MIOS32_COM or MIOS32_MIDI layer functions

s32 MIOS32_UART_TxBufferFree | ( | u8 | uart | ) |

returns number of free bytes in transmit buffer

Parameters:

  `[in]` | uart | UART number (0..2)

Returns:
  number of free bytes
  0 if uart not available

Note:
  Applications shouldn't call these functions directly, instead please use MIOS32_COM or MIOS32_MIDI layer functions

s32 MIOS32_UART_TxBufferGet | ( | u8 | uart | ) |

gets a byte from the transmit buffer

Parameters:

  `[in]` | uart | UART number (0..2)

Returns:
  -1 if UART not available
  -2 if no new byte available
  >= 0: transmitted byte

Note:
  Applications shouldn't call these functions directly, instead please use MIOS32_COM or MIOS32_MIDI layer functions

Here is the call graph for this function:

s32 MIOS32_UART_TxBufferPut | ( | u8 | uart,
|  | u8 | b |
| ) |  |  |

puts a byte onto the transmit buffer
(blocking function)

Parameters:

  `[in]` | uart | UART number (0..2)
  `[in]` | b | byte which should be put into Tx buffer

Returns:
  0 if no error
  -1 if UART not available
  -3 if UART not supported by MIOS32_UART_TxBufferPut Routine

Note:
  Applications shouldn't call these functions directly, instead please use MIOS32_COM or MIOS32_MIDI layer functions

Here is the call graph for this function:

s32 MIOS32_UART_TxBufferPut_NonBlocking | ( | u8 | uart,
|  | u8 | b |
| ) |  |  |

puts a byte onto the transmit buffer

Parameters:

  `[in]` | uart | UART number (0..2)
  `[in]` | b | byte which should be put into Tx buffer

Returns:
  0 if no error
  -1 if UART not available
  -2 if buffer full (retry)
  -3 if UART not supported by MIOS32_UART_TxBufferPut Routine

Note:
  Applications shouldn't call these functions directly, instead please use MIOS32_COM or MIOS32_MIDI layer functions

Here is the call graph for this function:

s32 MIOS32_UART_TxBufferPutMore | ( | u8 | uart,
|  | u8 * | buffer,
|  | u16 | len |
| ) |  |  |

puts more than one byte onto the transmit buffer (used for atomic sends)
(blocking function)

Parameters:

  `[in]` | uart | UART number (0..2)
  `[in]` | *buffer | pointer to buffer to be sent
  `[in]` | len | number of bytes to be sent

Returns:
  0 if no error
  -1 if UART not available
  -3 if UART not supported by MIOS32_UART_TxBufferPut Routine

Note:
  Applications shouldn't call these functions directly, instead please use MIOS32_COM or MIOS32_MIDI layer functions

Here is the call graph for this function:

s32 MIOS32_UART_TxBufferPutMore_NonBlocking | ( | u8 | uart,
|  | u8 * | buffer,
|  | u16 | len |
| ) |  |  |

puts more than one byte onto the transmit buffer (used for atomic sends)

Parameters:

  `[in]` | uart | UART number (0..2)
  `[in]` | *buffer | pointer to buffer to be sent
  `[in]` | len | number of bytes to be sent

Returns:
  0 if no error
  -1 if UART not available
  -2 if buffer full or cannot get all requested bytes (retry)
  -3 if UART not supported by MIOS32_UART_TxBufferPut Routine

Note:
  Applications shouldn't call these functions directly, instead please use MIOS32_COM or MIOS32_MIDI layer functions

Here is the call graph for this function:

s32 MIOS32_UART_TxBufferUsed | ( | u8 | uart | ) |

returns number of used bytes in transmit buffer

Parameters:

  `[in]` | uart | UART number (0..2)

Returns:
  number of used bytes
  0 if uart not available

Note:
  Applications shouldn't call these functions directly, instead please use MIOS32_COM or MIOS32_MIDI layer functions