-
Notifications
You must be signed in to change notification settings - Fork 0
/
Device_UART.c
150 lines (120 loc) · 3.09 KB
/
Device_UART.c
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
* Device_UART.c
*
* Created on: 17 de set de 2020
* Author: gustavo
*/
#include <stdint.h>
#include <stdbool.h>
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"
#include "device.h"
// Declares a queue structure for the UART
QueueHandle_t qUART[3];
#if UART_STRING == UART_QUEUE
QueueHandle_t qUART_Tx[3];
#endif
// Declares a semaphore structure for the UART
SemaphoreHandle_t sUART[3];
// Declares a mutex structure for the UART
SemaphoreHandle_t mutexTx[3];
void Init_UART0(void *parameters)
{
uart_config_t *uart_conf = (uart_config_t *)parameters;
}
void Init_UART1(void *parameters)
{
}
void Init_UART2(void *parameters)
{
}
//*****************************************************************************
//
// The UART interrupt handler.
//
//*****************************************************************************
void UARTIntHandler(void){
}
size_t UART_Write(OS_Device_Control_t *dev, char *string, size_t size ){
char data;
size_t nbytes = 0;
return nbytes;
}
size_t UART_Read(OS_Device_Control_t *dev, char *string, size_t size ){
size_t nbytes = 0;
failed_rx:
return nbytes;
}
size_t UART_Set(OS_Device_Control_t *dev, uint32_t request, uint32_t value){
uart_config_t *uart_conf = (uart_config_t *)dev->device->DriverData;
switch(request){
case UART_BAUDRATE:
break;
case UART_PARITY:
break;
case UART_STOP_BITS:
break;
case UART_QUEUE_SIZE:
break;
case UART_TIMEOUT:
uart_conf->timeout = value;
break;
default:
break;
}
return 0;
}
size_t UART_Get(OS_Device_Control_t *dev, uint32_t request){
uint32_t ret;
uart_config_t *uart_conf = (uart_config_t *)dev->device->DriverData;
switch(request){
case UART_BAUDRATE:
ret = uart_conf->baudrate;
break;
case UART_PARITY:
ret = uart_conf->parity;
break;
case UART_STOP_BITS:
ret = uart_conf->stop_bits;
break;
case UART_QUEUE_SIZE:
ret = uart_conf->queue_size;
break;
case UART_TIMEOUT:
ret = uart_conf->timeout;
break;
default:
ret = 0;
break;
}
return ret;
}
const device_api_t UART_api ={
.read = (Device_Control_read_t)UART_Read,
.write = (Device_Control_write_t)UART_Write,
.set = (Device_Control_set_t)UART_Set,
.get = (Device_Control_get_t)UART_Get
};
void OSOpenUART(OS_Device_Control_t *dev, void *parameters){
switch(dev->device_number){
case 0:
Init_UART0(parameters);
dev->device->base_address = UART0_BASE;
break;
#if 0
case 1:
Init_UART1(parameters);
dev->device->base_address = UART1_BASE;
break;
case 2:
Init_UART2(parameters);
dev->device->base_address = UART2_BASE;
break;
#endif
default:
break;
}
dev->api = &UART_api;
}