BRTOS  1.90
Brazilian Real-Time Operating System
 All Data Structures Files Functions Variables Macros
device.h
1 /*
2  * device.h
3  *
4  * Created on: 20 de jul de 2016
5  * Author: gustavo
6  */
7 
8 #ifndef BRTOS_DEVICE_H_
9 #define BRTOS_DEVICE_H_
10 
11 /* Standard includes. */
12 #include <stdint.h>
13 #include <stddef.h>
14 
15 #include "BRTOS.h"
16 #include "OSDevConfig.h"
17 
24 typedef struct BRTOS_Device_{
25  char *name;
26  Device_Types_t device_type;
27  unsigned long base_address;
28  void *DriverData;
30 
31 /* Device handles are void * for data hiding purposes. */
32 typedef const void *Device_Descriptor_t;
33 
34 /* Types that define read(), write(), set() and get() functions. */
35 typedef size_t (*Device_Control_write_t)(Device_Descriptor_t const device, const void *pvBuffer, const size_t xBytes );
36 typedef size_t (*Device_Control_read_t)(Device_Descriptor_t const device, void *pvBuffer, const size_t xBytes );
37 typedef size_t (*Device_Control_set_t)(Device_Descriptor_t const device, uint32_t ulRequest, uint32_t value );
38 typedef size_t (*Device_Control_get_t)(Device_Descriptor_t const device, uint32_t ulRequest);
39 
40 
41 typedef struct device_api_t_{
42  Device_Control_write_t write;
43  Device_Control_read_t read;
44  Device_Control_set_t set;
45  Device_Control_get_t get;
46 }device_api_t;
54 typedef struct BRTOS_Device_Control_t_{
55  OS_Device_t *device;
56  int8_t device_number; // Quando houver mais de uma uart por exemplo
57  const device_api_t *api;
59 
60 
61 typedef void (*OSOpenFunc)(OS_Device_Control_t *dev, void *parameters);
62 
63 typedef struct
64 {
65  int type;
66  void *func;
67 }driver_installer_t;
68 
69 #if 0
70 #ifndef OS_UART_DEVICE
71 #define OSOpenUART(x,y)
72 #else
73 void OSOpenUART(OS_Device_Control_t *dev, void *parameters);
74 #endif
75 
76 #ifndef OS_SPI_DEVICE
77 #define OSOpenSPI(x,y)
78 #else
79 void OSOpenSPI(OS_Device_Control_t *dev, void *parameters);
80 #endif
81 
82 #ifndef OS_I2C_DEVICE
83 #define OSOpenI2C(x,y)
84 #else
85 void OSOpenI2C(OS_Device_Control_t *dev, void *parameters);
86 #endif
87 
88 #ifndef OS_GPIO_DEVICE
89 #define OSOpenGPIO(x,y)
90 #else
91 void OSOpenGPIO(OS_Device_Control_t *dev, void *parameters);
92 #endif
93 #endif
94 
95 
96 OS_Device_Control_t *OSDevOpen(char *name, void *option);
97 size_t OSDevWrite(OS_Device_Control_t *dev, const void *string, const size_t bytes);
98 size_t OSDevRead(OS_Device_Control_t *dev, void *string, const size_t bytes);
99 size_t OSDevSet(OS_Device_Control_t *dev, uint32_t request, uint32_t value );
100 size_t OSDevGet(OS_Device_Control_t *dev, uint32_t request);
101 
102 #define OSGPIOWrite(x,y,z) OSDevWrite(x, (const void *)(y), z)
103 #define OSGPIORead(x,y) OSDevRead(x, y, 0)
104 
105 // UART types
106 #define INF_TIMEOUT 0
107 #ifndef NO_TIMEOUT
108 #define NO_TIMEOUT (ostick_t)(MAX_TIMER - 1)
109 #endif
110 
111 typedef enum{
112  CTRL_ACQUIRE_READ_MUTEX = 10,
113  CTRL_ACQUIRE_WRITE_MUTEX,
114  CTRL_RELEASE_WRITE_MUTEX,
115  CTRL_RELEASE_READ_MUTEX
116 }ctrl_t;
117 
118 typedef enum{
119  UART_PAR_NONE,
120  UART_PAR_ODD,
121  UART_PAR_EVEN
122 }uart_par_t;
123 
124 typedef enum{
125  UART_STOP_ONE = 1,
126  UART_STOP_TWO,
127 }uart_stop_t;
128 
129 typedef enum{
130  UART_POLLING,
131  UART_IRQ,
132 }uart_irq_t;
133 
134 typedef enum{
135  UART_BAUDRATE,
136  UART_PARITY,
137  UART_STOP_BITS,
138  UART_QUEUE_SIZE,
139  UART_TIMEOUT
140 }uart_request_t;
141 
142 typedef struct uart_config_t_{
143  int baudrate;
144  uart_par_t parity;
145  uart_stop_t stop_bits;
146  uart_irq_t polling_irq;
147  int queue_size;
148  ostick_t timeout;
149  bool read_mutex;
150  bool write_mutex;
151 }uart_config_t;
152 
153 
154 // GPIO types
155 typedef enum{
156  GPIO_DIR_IN,
157  GPIO_DIR_OUT
158 }gpio_dir_t;
159 
160 #define GPIO_PIN_0 0x00000001
161 #define GPIO_PIN_1 0x00000002
162 #define GPIO_PIN_2 0x00000004
163 #define GPIO_PIN_3 0x00000008
164 #define GPIO_PIN_4 0x00000010
165 #define GPIO_PIN_5 0x00000020
166 #define GPIO_PIN_6 0x00000040
167 #define GPIO_PIN_7 0x00000080
168 #define GPIO_PIN_8 0x00000100
169 #define GPIO_PIN_9 0x00000200
170 #define GPIO_PIN_10 0x00000400
171 #define GPIO_PIN_11 0x00000800
172 #define GPIO_PIN_12 0x00001000
173 #define GPIO_PIN_13 0x00002000
174 #define GPIO_PIN_14 0x00004000
175 #define GPIO_PIN_15 0x00008000
176 #define GPIO_PIN_16 0x00010000
177 #define GPIO_PIN_17 0x00020000
178 #define GPIO_PIN_18 0x00040000
179 #define GPIO_PIN_19 0x00080000
180 #define GPIO_PIN_20 0x00100000
181 #define GPIO_PIN_21 0x00200000
182 #define GPIO_PIN_22 0x00400000
183 #define GPIO_PIN_23 0x00800000
184 #define GPIO_PIN_24 0x01000000
185 #define GPIO_PIN_25 0x02000000
186 #define GPIO_PIN_26 0x04000000
187 #define GPIO_PIN_27 0x08000000
188 #define GPIO_PIN_28 0x10000000
189 #define GPIO_PIN_29 0x20000000
190 #define GPIO_PIN_30 0x40000000
191 #define GPIO_PIN_31 0x80000000
192 
193 
194 typedef struct gpio_config_t_{
195  unsigned long used_pins_in;
196  unsigned long used_pins_out;
197  unsigned long pull;
198  unsigned long irq_pins;
199 }gpio_config_t;
200 
201 typedef struct mux_gpio_config_t_{
202  unsigned long base;
203  unsigned long pin;
204  unsigned long pin_number;
205 }mux_gpio_config_t;
206 
207 //
209 //
210 #ifndef PWM_MODE_EDGE_ALIGNED1
211 #define PWM_MODE_EDGE_ALIGNED1 0x00000000
212 #endif
213 
214 //
216 //
217 #ifndef PWM_MODE_EDGE_ALIGNED2
218 #define PWM_MODE_EDGE_ALIGNED2 0x00000001
219 #endif
220 
221 //
223 //
224 #ifndef PWM_MODE_CENTER_ALIGNED1
225 #define PWM_MODE_CENTER_ALIGNED1 0x00000002
226 #endif
227 
228 //
230 //
231 #ifndef PWM_MODE_CENTER_ALIGNED2
232 #define PWM_MODE_CENTER_ALIGNED2 0x00000003
233 #endif
234 
235 typedef struct pwm_config_t_{
236  int *channel_list;
237  int frequency;
238  int mode;
239  int *init_duty;
240 }pwm_config_t;
241 
242 #endif /* BRTOS_DEVICE_H_ */
Static device information (In ROM) Per driver instance.
Definition: device.h:24
BRTOS kernel main defines, functions prototypes and structs declaration.
Runtime device structure (In memory) Per driver instance.
Definition: device.h:54