Hardware Abstraction Layer for FreeRTOS
uart_prv.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Author: Andreas Werner <kernel@andy89.org>
4  * Date: 2016
5  */
6 #ifndef UART_PRV_
7 #define UART_PRV_
8 #ifndef UART_PRV
9 # error "Never include this file out of a UART driver"
10 #endif
11 #include <FreeRTOS.h>
12 #include <semphr.h>
13 #include <stdint.h>
14 #include <stdbool.h>
15 #include <hal.h>
16 #define UART_ALREDY_INITED 1
17 int32_t uart_generic_init(struct uart *uart);
18 #ifdef CONFIG_UART_THREAD_SAVE
19 # define uart_lock(u, w, e) HAL_LOCK(u, w, e)
20 # define uart_unlock(u, e) HAL_UNLOCK(u, e)
21 #else
22 # define uart_lock(u, w, e)
23 # define uart_unlock(u, e)
24 #endif
25 
26 #define UART_ADDDEV(ns, p) HAL_ADDDEV(uart, ns, p)
28 #define UART_GET_DEV(index) HAL_GET_DEV(uart, index)
29 #ifndef CONFIG_UART_MULTI
30 # define UART_OPS(ns)
31 # define UART_INIT_DEV(ns)
32 # define UART_INIT(ns, port, baudrate) struct uart *uart_init(uint8_t port, uint32_t baudrate)
33 # define UART_DEINIT(ns, u) int32_t uart_deinit(struct uart *u)
34 # define UART_GETC(ns, u, waittime) char uart_getc(struct uart *u, TickType_t waittime)
35 # define UART_PUTC(ns, u, c, waittime) int32_t uart_putc(struct uart *u, char c, TickType_t waittime)
36 # define UART_READ(ns, u, data, length, waittime) int32_t uart_read(struct uart *u, uint8_t *data, size_t length, TickType_t waittime)
37 # define UART_WRITE(ns, u, data, length, waittime) int32_t uart_write(struct uart *u, uint8_t *data, size_t length, TickType_t waittime)
38 # define UART_PUTS(ns, u, s, waitime) int32_t uart_puts(struct uart *u, char *s, TickType_t waittime)
39 # define UART_GETC_ISR(ns, u) char uart_getcISR(struct uart *u)
40 # define UART_PUTC_ISR(ns, u, c) int32_t uart_putcISR(struct uart *u, char c)
41 # define UART_READ_ISR(ns, u, data, length) int32_t uart_readISR(struct uart *u, uint8_t *data, size_t length)
42 # define UART_WRITE_ISR(ns, u, data, length) int32_t uart_writeISR(struct uart *u, uint8_t *data, size_t length)
43 # define UART_PUTS_ISR(ns, u, s) int32_t uart_putsISR(struct uart *u, char *s)
44 #else
45 
46 # ifndef CONFIG_UART_GENERIC_BYTE
47 # define UART_READ_WRITE_OPS(ns) .uart_read = &ns##_uart_read, \
48  .uart_write = &ns##_uart_write, \
49  .uart_readISR = &ns##_uart_readISR, \
50  .uart_writeISR = &ns##_uart_writeISR,
51 # else
52 # define UART_READ_WRITE_OPS(ns)
53 # endif
54 
55 # ifndef CONFIG_UART_GENERIC_STRING
56 # define UART_STRING_OPS(ns) .uart_puts = &ns##_uart_puts, \
57  .uart_putsISR = &ns##_uart_putsISR,
58 # else
59 # define UART_STRING_OPS(ns)
60 #endif
61 
62 
63 # define UART_OPS(ns) const struct uart_ops ns##_uart_ops = { \
64  .uart_init = &ns##_uart_init, \
65  .uart_deinit = &ns##_uart_deinit, \
66  .uart_getc = &ns##_uart_getc, \
67  .uart_putc = &ns##_uart_putc, \
68  .uart_getcISR = &ns##_uart_getcISR, \
69  .uart_putcISR = &ns##_uart_putcISR, \
70  UART_READ_WRITE_OPS(ns) \
71  UART_STRING_OPS(ns) \
72 }
73 
74 # define UART_INIT_DEV(ns) .gen.ops = &ns##_uart_ops,
75 
76 # define UART_INIT(ns, port, baudrate) static struct uart *ns##_uart_init(uint8_t port, uint32_t baudrate)
77 # define UART_DEINIT(ns, u) static int32_t ns##_uart_deinit(struct uart *u)
78 # define UART_GETC(ns, u, waittime) static char ns##_uart_getc(struct uart *u, TickType_t waittime)
79 # define UART_PUTC(ns, u, c, waittime) static int32_t ns##_uart_putc(struct uart *u, char c, TickType_t waittime)
80 # define UART_READ(ns, u, data, length, waittime) static int32_t ns##_uart_read(struct uart *u, uint8_t *data, size_t length, TickType_t waittime)
81 # define UART_WRITE(ns, u, data, length, waittime) static int32_t ns##_uart_write(struct uart *u, uint8_t *data, size_t length, TickType_t waittime)
82 # define UART_PUTS(ns, u, s, waitime) static int32_t ns##_uart_puts(struct uart *u, char *s, TickType_t waittime)
83 # define UART_GETC_ISR(ns, u) static char ns##_uart_getcISR(struct uart *u)
84 # define UART_PUTC_ISR(ns, u, c) static int32_t ns##_uart_putcISR(struct uart *u, char c)
85 # define UART_READ_ISR(ns, u, data, length) static int32_t ns##_uart_readISR(struct uart *u, uint8_t *data, size_t length)
86 # define UART_WRITE_ISR(ns, u, data, length) static int32_t ns##_uart_writeISR(struct uart *u, uint8_t *data, size_t length)
87 # define UART_PUTS_ISR(ns, u, s) static int32_t ns##_uart_putsISR(struct uart *u, char *s)
88 #endif
89 #endif
hal.h
HAL_DEFINE_GLOBAL_ARRAY
HAL_DEFINE_GLOBAL_ARRAY(uart)
uart
Definition: remoteproc_trace.h:4
uart_generic_init
int32_t uart_generic_init(struct uart *uart)