Choco OS  V.0.16.9.0
Join to the chocolate world
oc_driver.h
Go to the documentation of this file.
1 
28 #ifndef INC_OC_DRIVER_H_
29 #define INC_OC_DRIVER_H_
30 
31 #include <oc_array.h>
32 #include <oc_version.h>
33 #include <oc_errors.h>
34 #include <oc_null.h>
35 #include <oc_ioctl.h>
36 #include <stdint.h>
37 #include <stdbool.h>
38 #include <oc_list.h>
39 #include <oc_stdlib.h>
40 #include <oc_boot.h>
41 #include <oc_compiler.h>
42 #include <oc_1word.h>
43 #include <oc_pixel.h>
44 #include <oc_colormap.h>
45 #include <oc_memory.h>
46 #include <oc_net.h>
47 #include <oc_diag.h>
48 #include <oc_event.h>
49 
55 #define _________________________________________MACROS_SECTION_____________________________________________________________________________
56 
59 #define oC_DRIVER_ARCHITECTURE_VERSION_01 0xF1
60 #define oC_DRIVER_ARCHITECTURE_VERSION_02 0xF2
61 #define oC_DRIVER_ARCHITECTURE_VERSION oC_DRIVER_ARCHITECTURE_VERSION_02
62 
63 #define oC_DRIVER_GET_ARCHITECTURE_FROM_VERSION(VERSION) ((VERSION >> 24) & 0xFF)
64 
65 #define oC_Driver_MakeVersion(MAJOR,MINOR,PATCH) ( (PATCH<<0) | (MINOR<<8) | (MAJOR<<16) | (oC_DRIVER_ARCHITECTURE_VERSION<<24) )
66 
67 #define oC_Driver_IsVersionCorrect(VERSION) (oC_DRIVER_GET_ARCHITECTURE_FROM_VERSION(VERSION) == oC_DRIVER_ARCHITECTURE_VERSION)
68 #define oC_DRIVER_CONFIG_TYPE_NAME(DRIVER_NAME) oC_1WORD_FROM_3(oC_,DRIVER_NAME,_Config_t)
69 
70 #define oC_Driver_IsDriverType(TYPE) ( (DRIVER_TYPE) == (TYPE) )
71 
72 #define STANDARD_DRIVER 1
73 #define COMMUNICATION_DRIVER 2
74 #define GRAPHICS_DRIVER 3
75 #define NETWORK_DRIVER 4
76 
77 #undef _________________________________________MACROS_SECTION_____________________________________________________________________________
78 
85 #define _________________________________________TYPES_SECTION_____________________________________________________________________________
86 
89 typedef oC_ErrorCode_t (*oC_Driver_ConfigureFunction_t) ( const void * Config , void ** outContext );
90 typedef oC_ErrorCode_t (*oC_Driver_UnconfigureFunction_t) ( const void * Config , void ** outContext );
91 typedef oC_ErrorCode_t (*oC_Driver_ReadFunction_t) ( void * Context , char * Buffer , uint32_t * Size , oC_Time_t Timeout );
92 typedef oC_ErrorCode_t (*oC_Driver_WriteFunction_t) ( void * Context , const char * Buffer , uint32_t * Size , oC_Time_t Timeout );
93 typedef oC_ErrorCode_t (*oC_Driver_HandleIoctlFunction_t) ( void * Context , oC_Ioctl_Command_t Command , void * Data );
94 typedef oC_ErrorCode_t (*oC_Driver_ReadColorMapFunction_t) ( void * Context , oC_ColorMap_t ** outColorMap );
95 typedef oC_ErrorCode_t (*oC_Driver_SetResolutionFunction_t) ( void * Context , oC_Pixel_ResolutionUInt_t Width , oC_Pixel_ResolutionUInt_t Height );
96 typedef oC_ErrorCode_t (*oC_Driver_ReadResolutionFunction_t) ( void * Context , oC_Pixel_ResolutionUInt_t * outWidth , oC_Pixel_ResolutionUInt_t * outHeight );
97 typedef oC_ErrorCode_t (*oC_Driver_TurnFunction_t) ( void );
98 typedef bool (*oC_Driver_IsTurnedOnFunction_t) ( void );
99 typedef oC_ErrorCode_t (*oC_Driver_SendFrame_t ) ( void * Context , const oC_Net_Frame_t * Frame , oC_Time_t Timeout );
100 typedef oC_ErrorCode_t (*oC_Driver_ReceiveFrame_t ) ( void * Context , oC_Net_Frame_t * outFrame , oC_Time_t Timeout );
101 typedef oC_ErrorCode_t (*oC_Driver_SetWakeOnLanEvent_t ) ( void * Context , oC_Event_t WolEvent );
102 typedef oC_ErrorCode_t (*oC_Driver_Flush_t ) ( void * Context );
103 typedef oC_ErrorCode_t (*oC_Driver_SetLoopback_t ) ( void * Context , oC_Net_Layer_t Layer , bool Enabled );
104 typedef oC_ErrorCode_t (*oC_Driver_PerformDiagnostics_t) ( void * Context , oC_Diag_t * outDiags , uint32_t * NumberOfDiags );
105 typedef oC_ErrorCode_t (*oC_Driver_ReadNetInfo_t) ( void * Context , oC_Net_Info_t * outInfo );
106 
107 typedef enum
108 {
109  oC_Driver_Type_Incorrect = 0 ,
110  oC_Driver_Type_Standard = STANDARD_DRIVER,
111  oC_Driver_Type_Communication = COMMUNICATION_DRIVER,
112  oC_Driver_Type_Graphics = GRAPHICS_DRIVER,
113  oC_Driver_Type_Network = NETWORK_DRIVER,
114 } oC_Driver_Type_t;
115 
116 typedef struct _oC_Driver_Registration_t
117 {
118  char * FileName;
119  oC_MemorySize_t ConfigurationSize;
120  const struct _oC_Driver_Registration_t * const * RequiredList;
121  uint16_t RequiredCount;
122  oC_Boot_Level_t RequiredBootLevel;
123  uint32_t Version;
124  oC_Driver_Type_t Type;
125  oC_Driver_ConfigureFunction_t Configure;
126  oC_Driver_UnconfigureFunction_t Unconfigure;
127  oC_Driver_TurnFunction_t TurnOn;
128  oC_Driver_TurnFunction_t TurnOff;
129  oC_Driver_IsTurnedOnFunction_t IsTurnedOn;
130  oC_Driver_ReadFunction_t Read;
131  oC_Driver_WriteFunction_t Write;
132  oC_Driver_HandleIoctlFunction_t HandleIoctl;
133  oC_Driver_ReadColorMapFunction_t ReadColorMap;
134  oC_Driver_SetResolutionFunction_t SetResolution;
135  oC_Driver_ReadResolutionFunction_t ReadResolution;
136  oC_Driver_SendFrame_t SendFrame;
137  oC_Driver_ReceiveFrame_t ReceiveFrame;
138  oC_Driver_SetWakeOnLanEvent_t SetWakeOnLanEvent;
139  oC_Driver_Flush_t Flush;
140  oC_Driver_SetLoopback_t SetLoopback;
141  oC_Driver_PerformDiagnostics_t PerformDiagnostics;
142  oC_Driver_ReadNetInfo_t ReadNetInfo;
143 } oC_Driver_Registration_t;
144 
145 typedef const oC_Driver_Registration_t * oC_Driver_t;
146 typedef const struct _oC_Driver_Registration_t * const * oC_Driver_RequiredList_t;
147 
148 #undef _________________________________________TYPES_SECTION_____________________________________________________________________________
149 
156 #define _________________________________________MACROS_SECTION_____________________________________________________________________________
157 
160 #define oC_Driver_BeginRequireList static const oC_Driver_Registration_t * const __RequiredList[] = {
161 
162 #define oC_Driver_EndRequireList }
163 
164 #define oC_Driver_DefineDriver const oC_Driver_Registration_t DRIVER_NAME = {\
165  .FileName = DRIVER_FILE_NAME, \
166  .ConfigurationSize = sizeof(oC_DRIVER_CONFIG_TYPE_NAME(DRIVER_NAME)),\
167  .RequiredList = __RequiredList, \
168  .RequiredCount = oC_ARRAY_SIZE(__RequiredList), \
169  .RequiredBootLevel = REQUIRED_BOOT_LEVEL, \
170  .Version = DRIVER_VERSION ,\
171  .TurnOn = (oC_Driver_TurnFunction_t)DRIVER_TURN_ON ,\
172  .TurnOff = (oC_Driver_TurnFunction_t)DRIVER_TURN_OFF ,\
173  .IsTurnedOn = (oC_Driver_IsTurnedOnFunction_t)IS_TURNED_ON, \
174  .Read = (oC_Driver_ReadFunction_t)READ_FROM_DRIVER ,\
175  .Write = (oC_Driver_WriteFunction_t)WRITE_TO_DRIVER ,\
176  .HandleIoctl = (oC_Driver_HandleIoctlFunction_t)HANDLE_IOCTL ,\
177  .Configure = (oC_Driver_ConfigureFunction_t)DRIVER_CONFIGURE ,\
178  .Unconfigure = (oC_Driver_UnconfigureFunction_t)DRIVER_UNCONFIGURE ,\
179  .ReadColorMap = (oC_Driver_ReadColorMapFunction_t)READ_COLOR_MAP, \
180  .SetResolution = (oC_Driver_SetResolutionFunction_t)SET_RESOLUTION, \
181  .ReadResolution = (oC_Driver_ReadResolutionFunction_t)READ_RESOLUTION , \
182  .SendFrame = (oC_Driver_SendFrame_t ) SEND_FRAME ,\
183  .ReceiveFrame = (oC_Driver_ReceiveFrame_t ) RECEIVE_FRAME ,\
184  .SetWakeOnLanEvent = (oC_Driver_SetWakeOnLanEvent_t ) SET_WAKE_ON_LAN_EVENT ,\
185  .Flush = (oC_Driver_Flush_t ) FLUSH ,\
186  .SetLoopback = (oC_Driver_SetLoopback_t ) SET_LOOPBACK ,\
187  .PerformDiagnostics= (oC_Driver_PerformDiagnostics_t ) PERFORM_DIAGNOSTIC ,\
188  .ReadNetInfo = (oC_Driver_ReadNetInfo_t ) READ_NET_INFO, \
189  .Type = DRIVER_TYPE , \
190  }
191 
192 
193 #define oC_Driver_DeclareDriver extern const oC_Driver_Registration_t DRIVER_NAME
194 #undef _________________________________________MACROS_SECTION_____________________________________________________________________________
195 
202 #define _________________________________________FUNCTIONS_SECTION__________________________________________________________________________
203 
206 extern bool oC_Driver_IsDriverRequiredBy( oC_Driver_t Driver , oC_Driver_t RequiredDriver );
207 extern oC_Driver_Type_t oC_Driver_GetDriverType ( oC_Driver_t Driver );
208 extern bool oC_Driver_ReadRequiredList ( oC_Driver_t Driver , oC_Driver_RequiredList_t * outRequiredList , uint16_t * outRequiredListCount );
209 extern oC_ErrorCode_t oC_Driver_TurnOn ( oC_Driver_t Driver );
210 extern oC_ErrorCode_t oC_Driver_TurnOff ( oC_Driver_t Driver );
211 extern bool oC_Driver_IsTurnedOn ( oC_Driver_t Driver );
212 extern oC_ErrorCode_t oC_Driver_Configure ( oC_Driver_t Driver , const void * Config , void ** outContext );
213 extern oC_ErrorCode_t oC_Driver_Unconfigure ( oC_Driver_t Driver , const void * Config , void ** outContext );
214 extern oC_ErrorCode_t oC_Driver_Read ( oC_Driver_t Driver , void * Context , char * outBuffer , uint32_t * Size , oC_Time_t Timeout );
215 extern oC_ErrorCode_t oC_Driver_Write ( oC_Driver_t Driver , void * Context , const char * Buffer , uint32_t * Size , oC_Time_t Timeout );
216 extern oC_ErrorCode_t oC_Driver_HandleIoctl ( oC_Driver_t Driver , void * Context , oC_Ioctl_Command_t Command , void * Data );
217 extern oC_ErrorCode_t oC_Driver_ReadColorMap ( oC_Driver_t Driver , void * Context , oC_ColorMap_t ** outColorMap );
218 extern oC_ErrorCode_t oC_Driver_SetResolution ( oC_Driver_t Driver , void * Context , oC_Pixel_ResolutionUInt_t Width , oC_Pixel_ResolutionUInt_t Height );
219 extern oC_ErrorCode_t oC_Driver_ReadResolution ( oC_Driver_t Driver , void * Context , oC_Pixel_ResolutionUInt_t * outWidth , oC_Pixel_ResolutionUInt_t * outHeight );
220 extern oC_ErrorCode_t oC_Driver_SendFrame ( oC_Driver_t Driver , void * Context , const oC_Net_Frame_t * Frame , oC_Time_t Timeout );
221 extern oC_ErrorCode_t oC_Driver_ReceiveFrame ( oC_Driver_t Driver , void * Context , oC_Net_Frame_t * outFrame , oC_Time_t Timeout );
222 extern oC_ErrorCode_t oC_Driver_SetWakeOnLanEvent ( oC_Driver_t Driver , void * Context , oC_Event_t WolEvent );
223 extern oC_ErrorCode_t oC_Driver_Flush ( oC_Driver_t Driver , void * Context );
224 extern oC_ErrorCode_t oC_Driver_SetLoopback ( oC_Driver_t Driver , void * Context , oC_Net_Layer_t Layer , bool Enabled );
225 extern oC_ErrorCode_t oC_Driver_PerformDiagnostics( oC_Driver_t Driver , void * Context , oC_Diag_t * outDiags , uint32_t * NumberOfDiags );
226 extern oC_ErrorCode_t oC_Driver_ReadNetInfo ( oC_Driver_t Driver , void * Context , oC_Net_Info_t * outInfo );
227 
228 #undef _________________________________________FUNCTIONS_SECTION__________________________________________________________________________
229 
231 #endif /* INC_OC_DRIVER_H_ */
232 
233 #if defined(DRIVER_HEADER) || defined(DRIVER_SOURCE)
234 #ifndef DRIVER_NAME
235 #error DRIVER_NAME is not defined! You must define it first
236 #endif
237 #if defined(DRIVER_HEADER) && defined(DRIVER_SOURCE)
238 #error DRIVER_HEADER and DRIVER_SOURCE are both defined. You must define only one of them at once. Use #undef DRIVER_HEADER before second include of the oc_driver.h file.
239 #elif defined(DRIVER_HEADER)
240 oC_Driver_DeclareDriver;
241 #undef DRIVER_HEADER
242 #elif defined(DRIVER_SOURCE)
243 
244 #if !defined(DRIVER_VERSION)
245 #error DRIVER_VERSION is not defined! Define it using oC_Driver_MakeVersion definition
246 #elif !oC_Driver_IsVersionCorrect(DRIVER_VERSION)
247 #error DRIVER_VERSION is not correctly defined! You must use oC_Driver_MakeVersion macro to define the driver version
248 #elif !defined(REQUIRED_DRIVERS)
249 #error REQUIRED_DRIVERS is not defined! Define it as list of drivers, that is required by this driver separated by comma. If the driver does not require anything, just define it as empty
250 #elif !defined(DRIVER_FILE_NAME)
251 #error DRIVER_FILE_NAME is not define! Define it as string with name of the file that will be created for this driver. Note, that it is not a path!
252 #elif !defined(REQUIRED_BOOT_LEVEL)
253 #error REQUIRED_BOOT_LEVEL is not defined! Define it as a oC_Boot_Level_t type value (for example as oC_Boot_Level_0)
254 #else
255 
256 #ifndef DRIVER_TYPE
257 #define DRIVER_TYPE oC_Driver_Type_Standard
258 #endif
259 
260 /* Checking driver interface */
261 #ifndef DRIVER_CONFIGURE
262 #error DRIVER_CONFIGURE is not defined! Each driver has to have defined configure function!
263 #define DRIVER_CONFIGURE NULL
264 #endif
265 #ifndef DRIVER_UNCONFIGURE
266 #error DRIVER_UNCONFIGURE is not defined! Each driver has to have defined unconfigure function!
267 #define DRIVER_UNCONFIGURE NULL
268 #endif
269 #ifndef DRIVER_TURN_ON
270 #define DRIVER_TURN_ON NULL
271 #elif !defined(IS_TURNED_ON)
272 #error IS_TURNED_ON is not defined! When the DRIVER_TURN_ON function is set, it is required to define also IS_TURNED_ON function!
273 #else
274 //oC_Driver_TurnFunction_t DRIVER_TURN_ON;
275 #endif
276 #ifndef DRIVER_TURN_OFF
277 #define DRIVER_TURN_OFF NULL
278 #elif !defined(IS_TURNED_ON)
279 #error IS_TURNED_ON is not defined! When the DRIVER_TURN_OFF function is set, it is required to define also IS_TURNED_ON function!
280 #else
281 //oC_Driver_TurnFunction_t DRIVER_TURN_OFF;
282 #endif
283 #ifndef READ_FROM_DRIVER
284 # if oC_Driver_IsDriverType(COMMUNICATION_DRIVER)
285 # error READ_FROM_DRIVER function is not defined (required for communication drivers)
286 # endif
287 
288 # define READ_FROM_DRIVER NULL
289 #else
290 //oC_Driver_ReadFunction_t READ_FROM_DRIVER;
291 #endif
292 #ifndef WRITE_TO_DRIVER
293 # if oC_Driver_IsDriverType(COMMUNICATION_DRIVER)
294 # error WRITE_TO_DRIVER function is not defined (required for communication drivers)
295 # endif
296 
297 # define WRITE_TO_DRIVER NULL
298 #else
299 //oC_Driver_WriteFunction_t WRITE_TO_DRIVER;
300 #endif
301 
302 #ifndef READ_COLOR_MAP
303 # if oC_Driver_IsDriverType(GRAPHICS_DRIVER)
304 # error READ_COLOR_MAP function required for graphics drivers is not defined!
305 # endif
306 # define READ_COLOR_MAP NULL
307 #endif
308 
309 #ifndef SET_RESOLUTION
310 # if oC_Driver_IsDriverType(GRAPHICS_DRIVER)
311 # error SET_RESOLUTION function required for graphics drivers is not defined!
312 # endif
313 # define SET_RESOLUTION NULL
314 #endif
315 
316 #ifndef READ_RESOLUTION
317 # if oC_Driver_IsDriverType(GRAPHICS_DRIVER)
318 # error READ_RESOLUTION function required for graphics drivers is not defined!
319 # endif
320 # define READ_RESOLUTION NULL
321 #endif
322 
323 #ifndef HANDLE_IOCTL
324 #define HANDLE_IOCTL NULL
325 #else
326 //oC_Driver_HandleIoctlFunction_t HANDLE_IOCTL;
327 #endif
328 #ifndef IS_TURNED_ON
329 #define IS_TURNED_ON NULL
330 #else
331 //oC_Driver_IsTurnedOnFunction_t IS_TURNED_ON;
332 #endif
333 
334 #ifndef SEND_FRAME
335 # if oC_Driver_IsDriverType(NETWORK_DRIVER)
336 # error SEND_FRAME function required for network drivers is not defined!
337 # endif
338 # define SEND_FRAME NULL
339 #endif
340 
341 #ifndef RECEIVE_FRAME
342 # if oC_Driver_IsDriverType(NETWORK_DRIVER)
343 # error RECEIVE_FRAME function required for network drivers is not defined!
344 # endif
345 # define RECEIVE_FRAME NULL
346 #endif
347 
348 #ifndef READ_NET_INFO
349 # if oC_Driver_IsDriverType(NETWORK_DRIVER)
350 # error READ_NET_INFO function required for network drivers is not defined!
351 # endif
352 # define READ_NET_INFO NULL
353 #endif
354 
355 #ifndef SET_WAKE_ON_LAN_EVENT
356 #define SET_WAKE_ON_LAN_EVENT NULL
357 #endif
358 
359 #ifndef FLUSH
360 #define FLUSH NULL
361 #endif
362 
363 #ifndef SET_LOOPBACK
364 #define SET_LOOPBACK NULL
365 #endif
366 
367 #ifndef PERFORM_DIAGNOSTIC
368 # if oC_Driver_IsDriverType(NETWORK_DRIVER)
369 # error PERFORM_DIAGNOSTIC function required for network drivers is not defined!
370 # endif
371 # define PERFORM_DIAGNOSTIC NULL
372 #endif
373 
374 oC_Driver_BeginRequireList
375 REQUIRED_DRIVERS
376 oC_Driver_EndRequireList;
377 oC_Driver_DefineDriver;
378 #endif
379 #undef DRIVER_SOURCE
380 #undef DRIVER_VERSION
381 #undef REQUIRED_DRIVERS
382 #undef DRIVER_FILE_NAME
383 #undef DRIVER_TURN_ON
384 #undef DRIVER_TURN_OFF
385 #undef READ_FROM_DRIVER
386 #undef WRITE_TO_DRIVER
387 #undef HANDLE_IOCTL
388 #undef READ_CONTEXT
389 #undef IS_TURNED_ON
390 #undef DRIVER_CONFIGURE
391 #undef READ_COLOR_MAP
392 #undef SET_RESOLUTION
393 #undef READ_RESOLUTION
394 #undef SEND_FRAME
395 #undef RECEIVE_FRAME
396 #undef SET_WAKE_ON_LAN_EVENT
397 #undef FLUSH
398 #undef SET_LOOPBACK
399 #undef PERFORM_DIAGNOSTIC
400 #undef DRIVER_TYPE
401 #endif
402 #undef DRIVER_NAME
403 #endif
Contains macros for creating one word from more words in macros.
FILE_DESCRIPTION
The file with interface for the GPIO driver.
static oC_ErrorCode_t Configure(VirtualDriverConfig_t *Config, ConnectionContext_t *outContext)
configures TELNET connection to work
Definition: oc_telnet.c:630
The file with version handling.
stores network interface informations
Definition: oc_net.h:508
The file contains definitions for the compiler, that helps to manage errors, etc. ...
The file with interface for bootloader.
The file with interface for event module.
The file with list library.
static oC_ErrorCode_t SendFrame(oC_ETH_Context_t Context, const oC_Net_MacAddress_t Source, const oC_Net_MacAddress_t Destination, const void *Data, uint16_t Size, oC_ETH_LLD_FrameSegment_t FrameSegment, oC_Net_FrameType_t FrameType, oC_Time_t Timeout)
sends frame
Definition: oc_eth.c:968
The file with interface for the GPIO driver.
static oC_ErrorCode_t Write(ConnectionContext_t Context, const char *Buffer, uint32_t *Size, oC_Time_t Timeout)
function called when process want to write data on STDOUT stream
Definition: oc_telnet.c:694
stores informations about the frame to send
Definition: oc_net.h:314
The file with interface for IOCTL.
static oC_ErrorCode_t Read(ConnectionContext_t Context, char *outBuffer, uint32_t *Size, oC_Time_t Timeout)
function called when process want to read data from STDIN stream
Definition: oc_telnet.c:749
Static array definitions.
static oC_ErrorCode_t Unconfigure(void *Dummy, ConnectionContext_t *Context)
unconfigures virtual telnet driver
Definition: oc_telnet.c:671
Definition of the null pointer.
File with interface for the NET module.
static oC_ErrorCode_t ReceiveFrame(oC_ETH_Context_t Context, oC_Net_MacAddress_t outSource, oC_Net_MacAddress_t outDestination, void *Data, uint16_t *Size, oC_ETH_LLD_FrameSegment_t *outFrameSegment, oC_Net_FrameType_t *outFrameType, oC_Time_t Timeout)
receives frame
Definition: oc_eth.c:1002
oC_Net_Layer_t
stores layer of the OSI model
Definition: oc_net.h:333