usart_enhanced.c File Reference

library for enhanced USART communication (code) More...

Go to the source code of this file.

## Macros

#define | USART_PERIPHERALS_NB 3
| number of available USART peripherals

## Functions

static uint8_t | usart_enhanced_id (uint32_t usart)
| get index of corresponding enhanced USART configurations More...
bool | usart_enhanced_config (uint32_t usart, uint8_t databits, enum usart_enhanced_parity_t parity)
| configure enhanced USART More...
void | usart_enhanced_send (uint32_t usart, uint8_t data)
| send data over the enhanced USART using the configuration More...
uint8_t | usart_enhanced_recv (uint32_t usart)
| receive data over the enhanced USART using the configuration More...
bool | usart_enhanced_parity_error (uint32_t usart)
| get the parity status of the received data More...

## Variables

static uint8_t | usart_enhanced_databits [USART_PERIPHERALS_NB]
| configured enhanced USART word size
static enum usart_enhanced_parity_t | usart_enhanced_parity [USART_PERIPHERALS_NB]
| configured enhanced USART parity
static bool | usart_enhanced_parity_errors [USART_PERIPHERALS_NB]
| last enhanced USART parity error status

const bool

usart_enhanced_even_parity_lut [256] = { true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, }

| know if there is an even number of 1's in a integer More...

## Detailed Description

library for enhanced USART communication (code)

Author
  King Kévin kingk.nosp@m.evin.nosp@m.@cuvo.nosp@m.odoo.nosp@m..info

Date
  2018

the USART peripherals only support 8 or 9-bit word and even or odd parity (included in the data bits). The library adds support for 5 to 8-bit words, none/even/odd/mark/space parity (on top of the data bits)

Note
  since parity is handled in software, the parity error (PE) flag is unused and should be replaced by the value return by usart_enhanced_parity_error

Remarks
  9-bit raw communication is not supported since this is not common and can be done without this library

Definition in file usart_enhanced.c.

## Function Documentation

## usart_enhanced_config()

bool usart_enhanced_config | ( | uint32_t | usart,
|  | uint8_t | databits,
|  | enum usart_enhanced_parity_t | parity
| ) |  |

configure enhanced USART

Parameters

  [in] | usart | USART peripheral base address
  [in] | databits | word size in bits (5 to 8)
  [in] | parity | additional parity bit

Returns
  if the input settings are valid and the configuration is successful

Definition at line 68 of file usart_enhanced.c.

## usart_enhanced_id()

static uint8_t usart_enhanced_id | ( | uint32_t | usart | ) |

static

get index of corresponding enhanced USART configurations

Parameters

  [in] | usart | USART peripheral base address

Returns
  index used for the individual USART configurations

Note
  the returned value is valid only is less than USART_PERIPHERALS_NB

Definition at line 48 of file usart_enhanced.c.

## usart_enhanced_parity_error()

bool usart_enhanced_parity_error | ( | uint32_t | usart | ) |

get the parity status of the received data

Parameters

  [in] | usart | USART peripheral base address

Returns
  if there is a parity error

Note
  the check only applies to the last data retrieved using usart_enhanced_recv

Definition at line 172 of file usart_enhanced.c.

## usart_enhanced_recv()

uint8_t usart_enhanced_recv | ( | uint32_t | usart | ) |

receive data over the enhanced USART using the configuration

Parameters

  [in] | usart | USART peripheral base address

Returns
  data received

Note
  uses usart_recv

Definition at line 131 of file usart_enhanced.c.

## usart_enhanced_send()

void usart_enhanced_send | ( | uint32_t | usart,
|  | uint8_t | data
| ) |  |

send data over the enhanced USART using the configuration

Parameters

  [in] | usart | USART peripheral base address
  [in] | data | data to be sent

Note
  uses usart_send

Definition at line 96 of file usart_enhanced.c.

## Variable Documentation

## usart_enhanced_even_parity_lut

const bool usart_enhanced_even_parity_lut[256] = { true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, }

know if there is an even number of 1's in a integer

Note
  this look up table is only useful for up to 8-bit words, else use __builtin_parity

Remarks
  a look-up is a lot faster than making the calculation and doesn't use a lot of (flash) memory

Definition at line 41 of file usart_enhanced.c.