-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathUartRingbuffer.h
More file actions
65 lines (48 loc) · 1.77 KB
/
Copy pathUartRingbuffer.h
File metadata and controls
65 lines (48 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* UartRingbuffer.c
* Created on: 10-Jul-2019
* Author: Controllerstech
* Edited by embryonic.dk
*/
#ifndef UARTRINGBUFFER_H_
#define UARTRINGBUFFER_H_
#include "stm32f7xx_hal.h"
/* change the size of the buffer */
#define UART_BUFFER_SIZE 64
typedef struct
{
unsigned char buffer[UART_BUFFER_SIZE];
volatile unsigned int head;
volatile unsigned int tail;
} ring_buffer;
/* reads the data in the rx_buffer and increment the tail count in rx_buffer */
int Uart_read(void);
/* writes the data to the tx_buffer and increment the head count in tx_buffer */
void Uart_write(int c);
/* Writes a byte array to the tx_buffer*/
void Uart_sendArray (char arr[],int numBytes);
/* function to send the string to the uart */
void Uart_sendstring(const char *s);
/* Print a number with any base
* base can be 10, 8 etc*/
void Uart_printbase (long n, uint8_t base);
/* Initialize the ring buffer */
void Ringbuf_init(UART_HandleTypeDef handle);
/* checks if the data is available to read in the rx_buffer */
int IsDataAvailable(void);
/* get the position of the given string within the incoming data.
* It returns the position, where the string ends */
uint16_t get_pos (char *string);
//flush all available characters from the RX buffer
void flush(void);
/* the ISR for the uart. put it in the IRQ handler */
void Uart_isr (UART_HandleTypeDef *huart);
/* once you hit 'enter' (\r\n), it copies the entire string to the buffer*/
void Get_string (char *buffer);
/* keep waiting until the given string has arrived and stores the data in the buffertostore
* on success return 1
* or else returns 0
* @ usage : while (!(wait_until("\r\n", buffer)));
*/
int wait_until (char *string, char *buffertostore);
#endif /* UARTRINGBUFFER_H_ */