Prusa MINI Firmware overview
uartrxbuff.h File Reference
#include <inttypes.h>
#include "stm32f4xx_hal.h"

Go to the source code of this file.

Classes

struct  _uartrxbuff_t
 

Macros

#define UARTRXBUFF_FLG_HALF   0x01
 
#define UARTRXBUFF_FLG_CPLT   0x02
 
#define UARTRXBUFF_FLG_FULL   0x04
 
#define UARTRXBUFF_FLG_OVER   0x08
 

Typedefs

typedef struct _uartrxbuff_t uartrxbuff_t
 

Functions

void uartrxbuff_init (uartrxbuff_t *prxbuff, UART_HandleTypeDef *phuart, DMA_HandleTypeDef *phdma, uint8_t size, uint8_t *pdata)
 
void uartrxbuff_open (uartrxbuff_t *prxbuff)
 
void uartrxbuff_close (uartrxbuff_t *prxbuff)
 
void uartrxbuff_reset (uartrxbuff_t *prxbuff)
 
int uartrxbuff_getchar (uartrxbuff_t *prxbuff)
 
void uartrxbuff_rxhalf_cb (uartrxbuff_t *prxbuff)
 
void uartrxbuff_rxcplt_cb (uartrxbuff_t *prxbuff)
 

Macro Definition Documentation

◆ UARTRXBUFF_FLG_HALF

#define UARTRXBUFF_FLG_HALF   0x01

◆ UARTRXBUFF_FLG_CPLT

#define UARTRXBUFF_FLG_CPLT   0x02

◆ UARTRXBUFF_FLG_FULL

#define UARTRXBUFF_FLG_FULL   0x04

◆ UARTRXBUFF_FLG_OVER

#define UARTRXBUFF_FLG_OVER   0x08

Typedef Documentation

◆ uartrxbuff_t

typedef struct _uartrxbuff_t uartrxbuff_t

Function Documentation

◆ uartrxbuff_init()

void uartrxbuff_init ( uartrxbuff_t prxbuff,
UART_HandleTypeDef phuart,
DMA_HandleTypeDef phdma,
uint8_t  size,
uint8_t pdata 
)
15  {
16  prxbuff->phuart = phuart;
17  prxbuff->phdma = phdma;
18  prxbuff->flags = 0;
19  prxbuff->index = 0;
20  prxbuff->size = size;
21  prxbuff->pdata = pdata;
22 }
Here is the caller graph for this function:

◆ uartrxbuff_open()

void uartrxbuff_open ( uartrxbuff_t prxbuff)
24  {
25  HAL_UART_Receive_DMA(prxbuff->phuart, prxbuff->pdata, prxbuff->size);
26  uartrxbuff_reset(prxbuff);
27 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ uartrxbuff_close()

void uartrxbuff_close ( uartrxbuff_t prxbuff)
29  {
30  HAL_UART_AbortReceive(prxbuff->phuart);
31 }
Here is the call graph for this function:

◆ uartrxbuff_reset()

void uartrxbuff_reset ( uartrxbuff_t prxbuff)
33  {
34  prxbuff->flags = 0;
35  prxbuff->index = prxbuff->size - prxbuff->phdma->Instance->NDTR;
36 }
Here is the caller graph for this function:

◆ uartrxbuff_getchar()

int uartrxbuff_getchar ( uartrxbuff_t prxbuff)
38  {
39  int ch = -1;
40  uint32_t ndtr = prxbuff->phdma->Instance->NDTR;
41  uint8_t cnt = prxbuff->size - ndtr;
42  if (prxbuff->index < (prxbuff->size / 2)) {
43  if ((prxbuff->flags & UARTRXBUFF_FLG_HALF) || (prxbuff->index < cnt)) {
44  ch = prxbuff->pdata[prxbuff->index++];
45  if (prxbuff->index == (prxbuff->size / 2))
46  prxbuff->flags &= ~UARTRXBUFF_FLG_HALF;
47  }
48  } else {
49  if ((prxbuff->flags & UARTRXBUFF_FLG_CPLT) || (prxbuff->index < cnt)) {
50  ch = prxbuff->pdata[prxbuff->index++];
51  if (prxbuff->index >= prxbuff->size) {
52  prxbuff->index = 0;
53  prxbuff->flags &= ~UARTRXBUFF_FLG_CPLT;
54  }
55  }
56  }
57  //TODO: check overflow
58  return ch;
59 }
Here is the caller graph for this function:

◆ uartrxbuff_rxhalf_cb()

void uartrxbuff_rxhalf_cb ( uartrxbuff_t prxbuff)
61  {
62  if (prxbuff->flags & UARTRXBUFF_FLG_HALF)
63  uartrxbuff_rx_overflow(prxbuff);
64  else {
65  prxbuff->flags |= UARTRXBUFF_FLG_HALF;
66  if ((prxbuff->flags & UARTRXBUFF_FLG_CPLT) && (prxbuff->index == (prxbuff->size / 2)))
67  uartrxbuff_rx_full(prxbuff);
68  }
69 }
Here is the call graph for this function:

◆ uartrxbuff_rxcplt_cb()

void uartrxbuff_rxcplt_cb ( uartrxbuff_t prxbuff)
71  {
72  if (prxbuff->flags & UARTRXBUFF_FLG_CPLT)
73  uartrxbuff_rx_overflow(prxbuff);
74  else {
75  prxbuff->flags |= UARTRXBUFF_FLG_CPLT;
76  if ((prxbuff->flags & UARTRXBUFF_FLG_HALF) && (prxbuff->index == 0))
77  uartrxbuff_rx_full(prxbuff);
78  }
79 }
Here is the call graph for this function:
Here is the caller graph for this function:
UARTRXBUFF_FLG_HALF
#define UARTRXBUFF_FLG_HALF
Definition: uartrxbuff.h:8
__DMA_HandleTypeDef::Instance
DMA_Stream_TypeDef * Instance
Definition: stm32f4xx_hal_dma.h:157
HAL_UART_Receive_DMA
HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
_uartrxbuff_t::index
uint8_t index
Definition: uartrxbuff.h:20
uartrxbuff_reset
void uartrxbuff_reset(uartrxbuff_t *prxbuff)
Definition: uartrxbuff.c:33
UARTRXBUFF_FLG_CPLT
#define UARTRXBUFF_FLG_CPLT
Definition: uartrxbuff.h:9
_uartrxbuff_t::pdata
uint8_t * pdata
Definition: uartrxbuff.h:22
uartrxbuff_rx_full
void uartrxbuff_rx_full(uartrxbuff_t *prxbuff)
Definition: uartrxbuff.c:5
_uartrxbuff_t::phuart
UART_HandleTypeDef * phuart
Definition: uartrxbuff.h:17
_uartrxbuff_t::flags
uint8_t flags
Definition: uartrxbuff.h:19
HAL_UART_AbortReceive
HAL_StatusTypeDef HAL_UART_AbortReceive(UART_HandleTypeDef *huart)
uint8_t
const uint8_t[]
Definition: 404_html.c:3
uartrxbuff_rx_overflow
void uartrxbuff_rx_overflow(uartrxbuff_t *prxbuff)
Definition: uartrxbuff.c:10
_uartrxbuff_t::size
uint8_t size
Definition: uartrxbuff.h:21
_uartrxbuff_t::phdma
DMA_HandleTypeDef * phdma
Definition: uartrxbuff.h:18
size
static png_bytep size_t size
Definition: pngwrite.c:2170