1 |
/*****************************************************************************
|
2 |
*
|
3 |
* initialize uart-system
|
4 |
*
|
5 |
* parameter:
|
6 |
* UART_com_t *UART_com : pointer to an user-created UART_com_t structure
|
7 |
*
|
8 |
* UART_HandleTypeDef *huart : HAL-handle to the used UART
|
9 |
*
|
10 |
* const char uart_name[] : pointer to a human readable name of this uart
|
11 |
*
|
12 |
*****************************************************************************/
|
13 |
|
14 |
void uart_init(UART_com_t *UART_com, UART_HandleTypeDef *huart, const char uart_name[]);
|
15 |
|
16 |
/*****************************************************************************
|
17 |
*
|
18 |
* switch to raw-mode
|
19 |
*
|
20 |
* parameter:
|
21 |
* UART_com_t *UART_com : pointer to an user-created UART_com_t structure
|
22 |
*
|
23 |
* every single received byte is returned by uart_receive()
|
24 |
*
|
25 |
* this mode is the default after initialisation
|
26 |
*
|
27 |
*****************************************************************************/
|
28 |
|
29 |
void uart_set_rawmode(UART_com_t *UART_com);
|
30 |
|
31 |
/*****************************************************************************
|
32 |
*
|
33 |
* switch to string-mode
|
34 |
*
|
35 |
* parameter:
|
36 |
* UART_com_t *UART_com : pointer to an user-created UART_com_t structure
|
37 |
*
|
38 |
* char *stringbuf : a pointer to an buffer used for internaly construct the received string
|
39 |
* size_t bufsize : size of this buffer which is also the max. string-length
|
40 |
*
|
41 |
* char termchar : a character (usualy <CR>) that is interpreted as an end of line
|
42 |
*
|
43 |
* bool echo : when true, every char is echoed on output. usable for manual input.
|
44 |
* in case of echo = true, <BS> may be used, to edit the input line
|
45 |
*
|
46 |
*****************************************************************************/
|
47 |
|
48 |
void uart_set_stringmode(UART_com_t *UART_com, char *stringbuf, size_t bufsize,
|
49 |
char termchar, bool echo);
|
50 |
|
51 |
/*****************************************************************************
|
52 |
*
|
53 |
* receive data from uart
|
54 |
*
|
55 |
* parameter:
|
56 |
* UART_com_t *UART_com : pointer to an user-created UART_com_t structure
|
57 |
*
|
58 |
* uint8_t *result : a pointer to a buffer where the received data is copied to
|
59 |
*
|
60 |
* in rawmode this is a single byte
|
61 |
*
|
62 |
* in stringmode, the buffersize has to be equal or bigger than the buffer-size
|
63 |
* set in uart_set_stringmode()
|
64 |
*
|
65 |
* return:
|
66 |
* in non-rtos-mode it returns true if data has been received and copied
|
67 |
* false is returned if no data is available
|
68 |
*
|
69 |
* in rtos-mode the control is passed to the rtos, and the function
|
70 |
* returns true as soon as data is available and copied to the result-buffer
|
71 |
*
|
72 |
*****************************************************************************/
|
73 |
|
74 |
bool uart_receive(UART_com_t *uart, uint8_t *result);
|
75 |
|
76 |
/*****************************************************************************
|
77 |
*
|
78 |
* transmit single byte
|
79 |
*
|
80 |
* parameter:
|
81 |
* UART_com_t *UART_com : pointer to an user-created UART_com_t structure
|
82 |
*
|
83 |
* uint8_t byte : the byte to be tranmitted
|
84 |
*
|
85 |
*****************************************************************************/
|
86 |
|
87 |
void uart_put_byte(UART_com_t *Serial_COM, uint8_t byte);
|
88 |
|
89 |
/*****************************************************************************
|
90 |
*
|
91 |
* transmit array of data
|
92 |
*
|
93 |
* parameter:
|
94 |
* UART_com_t *UART_com : pointer to an user-created UART_com_t structure
|
95 |
*
|
96 |
* uint8_t *data : pointer to an array of bytes to be tranmitted
|
97 |
*
|
98 |
* size_t cnt : number of bytes to transmit
|
99 |
*
|
100 |
*****************************************************************************/
|
101 |
|
102 |
void uart_put_data(UART_com_t *Serial_COM, uint8_t *data, size_t cnt);
|
103 |
|
104 |
/*****************************************************************************
|
105 |
*
|
106 |
* transmit a single char
|
107 |
*
|
108 |
* parameter:
|
109 |
* UART_com_t *UART_com : pointer to an user-created UART_com_t structure
|
110 |
*
|
111 |
* char c : the char to be tranmitted
|
112 |
*
|
113 |
*****************************************************************************/
|
114 |
|
115 |
void uart_putc(UART_com_t *Serial_COM, char c);
|
116 |
|
117 |
/*****************************************************************************
|
118 |
*
|
119 |
* transmit a null-terminated string
|
120 |
*
|
121 |
* parameter:
|
122 |
* UART_com_t *UART_com : pointer to an user-created UART_com_t structure
|
123 |
*
|
124 |
* char *s : a pointer to the string to transmit
|
125 |
*
|
126 |
*****************************************************************************/
|
127 |
|
128 |
void uart_puts(UART_com_t *Serial_COM, char *s);
|