-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuart.h
65 lines (49 loc) · 1.69 KB
/
uart.h
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
#ifndef UART_H_
#define UART_H_
#ifndef ADI_UART_H
#include <drivers/uart/adi_uart.h>
#endif
#ifndef _STDLIB_H_
#include <stdlib.h>
#endif
#ifndef ADI_PWR_H
#include <drivers/pwr/adi_pwr.h>
#endif
#define RX_BUFFER_SIZE 256
//uart control variables
extern uint8_t uartMemory[ADI_UART_BIDIR_MEMORY_SIZE];
extern uint32_t uart_hErrors;
extern ADI_UART_HANDLE uartDevice;
extern uint8_t rx_buffer[RX_BUFFER_SIZE];
extern uint8_t rx_buffer_b;
extern uint8_t rx_buffer_e;
extern uint8_t rx_buffer_overflow;
extern uint8_t rx_buffer_size;
void uartCallback(void* pAppHandle, uint32_t nEvent, void* pArg);
//setups UART driver
//baudrate: baudrate
ADI_UART_RESULT uartSetup(uint32_t baudrate);
//returns number of bytes received available in buffer
uint32_t uart_available();
//returns one byte from buffer as a pointer
uint8_t uartRead();
//reads len bytes from buffer. Returns 0 in case of success and 1 otherwise
//buf: pointer where the bytes are going to be copied to.
//len: number of bytes to be read
int uartReadBuffer(uint8_t* buf, uint32_t len);
//writes one byte (blocking)
//byte: data to be written
ADI_UART_RESULT uartWrite(uint8_t byte);
//writes len bytes (blocking)
//buffer: pointer with data to be written
//len: number of bytes to be written
ADI_UART_RESULT uartWriteBuffer(uint8_t* buffer, uint32_t len);
//writes one byte (non-blocking)
//byte: data to be written
ADI_UART_RESULT async_uartWrite(uint8_t byte);
//writes len bytes (non-blocking)
//buffer: pointer with data to be written
//len: number of bytes to be written
ADI_UART_RESULT async_uartWriteBuffer(uint8_t* buffer, uint32_t len);
void uartFlush();
#endif /* UART_H_ */