snickerdoodle Platform Controller
firmware for STM32F0 platform controller
UART

UART configuration and control. More...

Modules

 UART Definitions
 
 UART Exported Variables
 
 UART Functions
 
 UART Private Variables
 
 UART Types
 

Functions

static enum sd_uart_err sd_uart_dev_init (struct sd_uart_dev *dev, UART_HandleTypeDef *huart)
 UART Device Initialization Initialize UART device structure. More...
 
static enum sd_uart_err sd_uart_rx_isr (struct sd_uart_dev *dev)
 Receive Interrupt Routine. More...
 
static void sd_uart_err_cb (struct sd_uart_dev *dev)
 Handle UART errors. More...
 

Detailed Description

UART configuration and control.

Function Documentation

◆ sd_uart_dev_init()

enum sd_uart_err sd_uart_dev_init ( struct sd_uart_dev dev,
UART_HandleTypeDef *  huart 
)
static

#include <Src/sd_uart.c>

UART Device Initialization Initialize UART device structure.

Parameters
uart_devDevice structure to initialize
Return values
SD_UART_SUCCESSon success, error state otherwise
291 {
292  if (huart == NULL)
293  return SD_UART_ERROR;
294 
295  /* Reset the UART device structure */
296  memset(dev, 0, sizeof(struct sd_uart_dev));
297 
298  dev->uart = huart; /* Set the UART handle pointer */
299 
300 
301  return SD_UART_SUCCESS;
302 }
UART_HandleTypeDef * uart
Definition: sd_uart.h:140
UART device structure.
Definition: sd_uart.h:139
Definition: sd_uart.h:117
Definition: sd_uart.h:121

◆ sd_uart_err_cb()

static void sd_uart_err_cb ( struct sd_uart_dev dev)
inlinestatic

#include <Src/sd_uart.c>

Handle UART errors.

Parameters
huartUART handle with error triggered error interrupt
Return values
none
455 {
456  /* Handle errors */
457 }

◆ sd_uart_rx_isr()

enum sd_uart_err sd_uart_rx_isr ( struct sd_uart_dev dev)
inlinestatic

#include <Src/sd_uart.c>

Receive Interrupt Routine.

Note
This function is called from within the interrupt handler when the the RXNE interrupt is enabled and set.
Parameters
devThe UART peripheral that triggered interrupt
Return values
SD_UART_SUCCESSon success, error status otherwise

Put the character in the current buffer

405 {
406  struct sd_cbuf *rx_buff = dev->rx_buff;
407  UART_HandleTypeDef *huart = dev->uart;
408  uint16_t mask = huart->Mask;
409 
411  rx_buff->buff[rx_buff->in++] = (uint8_t)(huart->Instance->RDR & (uint8_t)mask);
412 
413  /* Wrap buffer if at the end */
414  if (rx_buff->in >= rx_buff->size)
415  rx_buff->in = 0;
416 
417  if (++rx_buff->len >= rx_buff->size) {
418  rx_buff->state = SD_BUFF_OVERFLOW;
419  return SD_UART_ERROR;
420  }
421 
422  return SD_UART_SUCCESS;
423 }
uint32_t size
Definition: sd_buffer.h:107
struct sd_cbuf * rx_buff
Definition: sd_uart.h:142
uint8_t * buff
Definition: sd_buffer.h:103
uint32_t in
Definition: sd_buffer.h:104
enum sd_buff_state state
Definition: sd_buffer.h:108
Character buffer structure.
Definition: sd_buffer.h:102
UART_HandleTypeDef * uart
Definition: sd_uart.h:140
Definition: sd_uart.h:117
Definition: sd_uart.h:121
Definition: sd_buffer.h:82
uint32_t len
Definition: sd_buffer.h:106