uart.h
Go to the documentation of this file.
1 /*
2  * KubOS HAL
3  * Copyright (C) 2016 Kubos Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
27 #if (defined YOTTA_CFG_HARDWARE_UART) && (YOTTA_CFG_HARDWARE_UART_COUNT > 0)
28 #ifndef K_UART_H
29 #define K_UART_H
30 
31 #include <csp/arch/csp_queue.h>
32 #include <stdint.h>
33 
34 #include "pins.h"
35 
48 #ifndef K_NUM_UARTS
49 #define K_NUM_UARTS YOTTA_CFG_HARDWARE_UART_COUNT
50 #endif
51 
64 #ifndef K_UART_CONSOLE
65 #define K_UART_CONSOLE YOTTA_CFG_HARDWARE_CONSOLE_UART
66 #endif
67 
80 #ifndef K_UART_CONSOLE_BAUDRATE
81 #define K_UART_CONSOLE_BAUDRATE YOTTA_CFG_HARDWARE_CONSOLE_BAUDRATE
82 #endif
83 
87 typedef enum {
88  // @warning - need to add K_UART_NO_BUS
89 #ifdef YOTTA_CFG_HARDWARE_UART_UART1
90  K_UART1 = 0,
91 #endif
92 #ifdef YOTTA_CFG_HARDWARE_UART_UART2
94 #endif
95 #ifdef YOTTA_CFG_HARDWARE_UART_UART3
97 #endif
98 #ifdef YOTTA_CFG_HARDWARE_UART_UART4
100 #endif
101 #ifdef YOTTA_CFG_HARDWARE_UART_UART5
103 #endif
104 #ifdef YOTTA_CFG_HARDWARE_UART_UART6
106 #endif
107 } KUARTNum;
108 
113 typedef enum {
117 } KWordLen;
118 
122 typedef enum {
125 } KStopBits;
126 
130 typedef enum {
134 } KParity;
135 
139 typedef enum {
144 } KUARTStatus;
145 
149 typedef struct {
153  const char *dev_path;
162  uint32_t baud_rate;
181  uint8_t rx_queue_len;
185  uint8_t tx_queue_len;
186 } KUARTConf;
187 
191 typedef struct {
192  int dev;
194  csp_queue_handle_t rx_queue;
195  csp_queue_handle_t tx_queue;
196 } KUART;
197 
203 
211 
212 
217 void k_uart_terminate(KUARTNum uart);
218 
222 void k_uart_console_init(void);
223 
234 int k_uart_read(KUARTNum uart, char *ptr, int len);
235 
246 int k_uart_write(KUARTNum uart, char *ptr, int len);
247 
255 
263 KUARTStatus k_uart_write_immediate_str(KUARTNum uart, uint8_t * ptr, uint8_t len);
264 
270 int k_uart_rx_queue_len(KUARTNum uart);
271 
278 void k_uart_rx_queue_push(KUARTNum uart, char c, void *task_woken);
279 
285 int k_uart_rx_pin(KUARTNum uart);
286 
292 int k_uart_tx_pin(KUARTNum uart);
293 
294 // private APIs
301 
308 
310 
316 #endif // #ifndef K_UART_H
317 #endif // #ifdef YOTTA_CFG_HARDWARE_UART && YOTTA_CFG_HARDE_UART_COUNT > 0
318 /* @} */
KStopBits
Number of stop bits.
Definition: uart.h:122
int dev
Definition: uart.h:192
KUART * kprv_uart_get(KUARTNum uart)
Returns uart data structure for specified interface.
KStopBits stop_bits
The number of stop bits at the end of each transmit/receive of the uart bus.
Definition: uart.h:172
Definition: uart.h:114
void kprv_uart_enable_tx_int(KUARTNum uart)
Enables uart transmit interrupt.
KParity
Parity setting.
Definition: uart.h:130
Uart configuration structure.
Definition: uart.h:149
Definition: uart.h:96
csp_queue_handle_t tx_queue
Definition: uart.h:195
Definition: uart.h:141
Definition: uart.h:140
int k_uart_write(KUARTNum uart, char *ptr, int len)
Interrupt driven function for writing data to a uart interface.
Definition: uart.h:116
void k_uart_console_init(void)
Setup and enable console uart interface.
KUARTStatus k_uart_write_immediate(KUARTNum uart, char c)
Write data directly to a uart interface.
Definition: uart.h:93
Definition: uart.h:99
Definition: uart.h:143
Definition: uart.h:90
Definition: uart.h:123
Definition: uart.h:132
KUARTNum
Available uart interfaces.
Definition: uart.h:87
Definition: uart.h:131
KUARTConf conf
Definition: uart.h:193
void k_uart_terminate(KUARTNum uart)
Terminates uart interface.
Definition: uart.h:105
uint8_t tx_queue_len
The size of the queue for outgoing messages.
Definition: uart.h:185
Definition: uart.h:142
KUARTStatus kprv_uart_dev_init(KUARTNum uart)
Performs low level uart hardware initialization.
KUARTStatus
Uart status values.
Definition: uart.h:139
Definition: uart.h:115
void kprv_uart_dev_terminate(KUARTNum uart)
KWordLen
Word length.
Definition: uart.h:113
Definition: uart.h:102
Definition: uart.h:133
Definition: uart.h:124
uint8_t rx_queue_len
The size of the queue for incoming messages.
Definition: uart.h:181
int k_uart_read(KUARTNum uart, char *ptr, int len)
Interrupt driven function for reading data from a uart interface.
int k_uart_rx_queue_len(KUARTNum uart)
Returns the number of characters currently in the uart rx queue.
int k_uart_rx_pin(KUARTNum uart)
Returns rx pin for specified uart interface.
KUARTStatus k_uart_write_immediate_str(KUARTNum uart, uint8_t *ptr, uint8_t len)
Write data directly to a uart interface.
KParity parity
The presence and state of the parity bit in each transmit/receive of the uart bus.
Definition: uart.h:177
uint32_t baud_rate
The buad rate of the uart bus.
Definition: uart.h:162
KWordLen word_len
The number of data bits in each transmit/receive of the uart bus.
Definition: uart.h:167
KUARTConf k_uart_conf_defaults(void)
Generate KUARTConf with default uart values.
csp_queue_handle_t rx_queue
Definition: uart.h:194
const char * dev_path
The path of the uart bus.
Definition: uart.h:153
Uart interface data structure.
Definition: uart.h:191
void k_uart_rx_queue_push(KUARTNum uart, char c, void *task_woken)
Pushes a character into the uart rx queue.
KUARTStatus k_uart_init(KUARTNum uart, KUARTConf *conf)
Setup and enable uart interface.
int k_uart_tx_pin(KUARTNum uart)
Returns tx pin for specified uart interface.