28 #ifndef INC_OC_DRIVER_H_ 29 #define INC_OC_DRIVER_H_ 33 #include <oc_errors.h> 39 #include <oc_stdlib.h> 55 #define _________________________________________MACROS_SECTION_____________________________________________________________________________ 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 63 #define oC_DRIVER_GET_ARCHITECTURE_FROM_VERSION(VERSION) ((VERSION >> 24) & 0xFF) 65 #define oC_Driver_MakeVersion(MAJOR,MINOR,PATCH) ( (PATCH<<0) | (MINOR<<8) | (MAJOR<<16) | (oC_DRIVER_ARCHITECTURE_VERSION<<24) ) 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) 70 #define oC_Driver_IsDriverType(TYPE) ( (DRIVER_TYPE) == (TYPE) ) 72 #define STANDARD_DRIVER 1 73 #define COMMUNICATION_DRIVER 2 74 #define GRAPHICS_DRIVER 3 75 #define NETWORK_DRIVER 4 77 #undef _________________________________________MACROS_SECTION_____________________________________________________________________________ 85 #define _________________________________________TYPES_SECTION_____________________________________________________________________________ 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 );
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,
116 typedef struct _oC_Driver_Registration_t
119 oC_MemorySize_t ConfigurationSize;
120 const struct _oC_Driver_Registration_t *
const * RequiredList;
121 uint16_t RequiredCount;
122 oC_Boot_Level_t RequiredBootLevel;
124 oC_Driver_Type_t Type;
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;
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;
145 typedef const oC_Driver_Registration_t * oC_Driver_t;
146 typedef const struct _oC_Driver_Registration_t *
const * oC_Driver_RequiredList_t;
148 #undef _________________________________________TYPES_SECTION_____________________________________________________________________________ 156 #define _________________________________________MACROS_SECTION_____________________________________________________________________________ 160 #define oC_Driver_BeginRequireList static const oC_Driver_Registration_t * const __RequiredList[] = { 162 #define oC_Driver_EndRequireList } 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 , \ 193 #define oC_Driver_DeclareDriver extern const oC_Driver_Registration_t DRIVER_NAME 194 #undef _________________________________________MACROS_SECTION_____________________________________________________________________________ 202 #define _________________________________________FUNCTIONS_SECTION__________________________________________________________________________ 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 );
228 #undef _________________________________________FUNCTIONS_SECTION__________________________________________________________________________ 233 #if defined(DRIVER_HEADER) || defined(DRIVER_SOURCE) 235 #error DRIVER_NAME is not defined! You must define it first 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;
242 #elif defined(DRIVER_SOURCE) 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) 257 #define DRIVER_TYPE oC_Driver_Type_Standard 261 #ifndef DRIVER_CONFIGURE 262 #error DRIVER_CONFIGURE is not defined! Each driver has to have defined configure function! 263 #define DRIVER_CONFIGURE NULL 265 #ifndef DRIVER_UNCONFIGURE 266 #error DRIVER_UNCONFIGURE is not defined! Each driver has to have defined unconfigure function! 267 #define DRIVER_UNCONFIGURE NULL 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! 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! 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) 288 # define READ_FROM_DRIVER NULL 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) 297 # define WRITE_TO_DRIVER NULL 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! 306 # define READ_COLOR_MAP NULL 309 #ifndef SET_RESOLUTION 310 # if oC_Driver_IsDriverType(GRAPHICS_DRIVER) 311 # error SET_RESOLUTION function required for graphics drivers is not defined! 313 # define SET_RESOLUTION NULL 316 #ifndef READ_RESOLUTION 317 # if oC_Driver_IsDriverType(GRAPHICS_DRIVER) 318 # error READ_RESOLUTION function required for graphics drivers is not defined! 320 # define READ_RESOLUTION NULL 324 #define HANDLE_IOCTL NULL 329 #define IS_TURNED_ON NULL 335 # if oC_Driver_IsDriverType(NETWORK_DRIVER) 336 # error SEND_FRAME function required for network drivers is not defined! 338 # define SEND_FRAME NULL 341 #ifndef RECEIVE_FRAME 342 # if oC_Driver_IsDriverType(NETWORK_DRIVER) 343 # error RECEIVE_FRAME function required for network drivers is not defined! 345 # define RECEIVE_FRAME NULL 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! 352 # define READ_NET_INFO NULL 355 #ifndef SET_WAKE_ON_LAN_EVENT 356 #define SET_WAKE_ON_LAN_EVENT NULL 364 #define SET_LOOPBACK NULL 367 #ifndef PERFORM_DIAGNOSTIC 368 # if oC_Driver_IsDriverType(NETWORK_DRIVER) 369 # error PERFORM_DIAGNOSTIC function required for network drivers is not defined! 371 # define PERFORM_DIAGNOSTIC NULL 374 oC_Driver_BeginRequireList
376 oC_Driver_EndRequireList;
377 oC_Driver_DefineDriver;
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 390 #undef DRIVER_CONFIGURE 391 #undef READ_COLOR_MAP 392 #undef SET_RESOLUTION 393 #undef READ_RESOLUTION 396 #undef SET_WAKE_ON_LAN_EVENT 399 #undef PERFORM_DIAGNOSTIC Contains macros for creating one word from more words in macros.
The file with interface for the GPIO driver.
static oC_ErrorCode_t Configure(VirtualDriverConfig_t *Config, ConnectionContext_t *outContext)
configures TELNET connection to work
The file with version handling.
stores network interface informations
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
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
stores informations about the frame to send
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
Static array definitions.
static oC_ErrorCode_t Unconfigure(void *Dummy, ConnectionContext_t *Context)
unconfigures virtual telnet driver
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
oC_Net_Layer_t
stores layer of the OSI model