41 #define _________________________________________DRIVER_DEFINITIONS_SECTION_________________________________________________________________ 46 #define DRIVER_NAME GPIO 47 #define DRIVER_FILE_NAME "gpio" 48 #define DRIVER_VERSION oC_Driver_MakeVersion(1,0,0) 49 #define REQUIRED_DRIVERS 50 #define REQUIRED_BOOT_LEVEL oC_Boot_Level_RequireMemoryManager | oC_Boot_Level_RequireDriversManager 53 #define DRIVER_CONFIGURE oC_GPIO_Configure 54 #define DRIVER_UNCONFIGURE oC_GPIO_Unconfigure 55 #define DRIVER_TURN_ON oC_GPIO_TurnOn 56 #define DRIVER_TURN_OFF oC_GPIO_TurnOff 57 #define IS_TURNED_ON oC_GPIO_IsTurnedOn 58 #define HANDLE_IOCTL oC_GPIO_Ioctl 60 #undef _________________________________________DRIVER_DEFINITIONS_SECTION_________________________________________________________________ 70 #define _________________________________________VARIABLES_SECTION__________________________________________________________________________ 77 #undef _________________________________________VARIABLES_SECTION__________________________________________________________________________ 84 #define _________________________________________LOCAL_PROTOTYPES_SECTION___________________________________________________________________ 88 #undef _________________________________________LOCAL_PROTOTYPES_SECTION___________________________________________________________________ 96 #define _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________ 110 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
112 oC_IntMan_EnterCriticalSection();
116 errorCode = oC_GPIO_LLD_TurnOnDriver();
118 if(errorCode == oC_ErrorCode_ModuleIsTurnedOn)
120 errorCode = oC_ErrorCode_None;
123 if(!oC_ErrorOccur(errorCode))
125 InterruptEvent = oC_Event_New(oC_Event_State_Inactive , &Allocator , AllocationFlags_CanWait1Second);
128 ErrorCondition( oC_Event_IsCorrect(InterruptEvent) , oC_ErrorCode_AllocationError) &&
129 oC_AssignErrorCode( &errorCode , oC_GPIO_LLD_SetDriverInterruptHandler(
InterruptHandler))
133 errorCode = oC_ErrorCode_None;
139 oC_IntMan_ExitCriticalSection();
156 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
158 oC_IntMan_ExitCriticalSection();
165 errorCode = oC_GPIO_LLD_TurnOffDriver();
167 if(errorCode == oC_ErrorCode_ModuleNotStartedYet)
169 errorCode = oC_ErrorCode_None;
172 if(!oC_Event_Delete(&InterruptEvent,AllocationFlags_CanWaitForever))
174 errorCode = oC_ErrorCode_CannotDeleteObject;
178 oC_IntMan_ExitCriticalSection();
209 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
214 oC_AssignErrorCodeIfFalse(&errorCode , isaddresscorrect(Config) , oC_ErrorCode_WrongConfigAddress) &&
215 oC_AssignErrorCodeIfFalse(&errorCode , isram(outContext) , oC_ErrorCode_OutputAddressNotInRAM)
218 oC_Pins_t pins = Config->
Pins;
219 bool unlocked =
false;
221 oC_Pins_t * pinsReference = ksmartalloc(
sizeof(oC_Pins_t),&Allocator,AllocationFlags_CanWait1Second);
224 oC_IntMan_EnterCriticalSection();
226 oC_AssignErrorCodeIfFalse(&errorCode , isram(pinsReference) , oC_ErrorCode_AllocationError ) &&
227 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_BeginConfiguration( pins)) &&
228 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_CheckIsPinUnlocked(pins,&unlocked) ) &&
229 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_CheckIsPinUsed(pins,&used) ) &&
230 oC_AssignErrorCodeIfFalse(&errorCode , used ==
false , oC_ErrorCode_PinIsUsed ) &&
231 (unlocked ==
true || oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_UnlockProtection(pins,Config->
Protection) )) &&
232 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_SetSpeed(pins,Config->
Speed) ) &&
233 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_SetCurrent(pins,Config->
Current) ) &&
234 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_SetMode(pins,Config->
Mode) ) &&
235 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_SetPull(pins,Config->
Pull) ) &&
236 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_SetOutputCircuit(pins,Config->
OutputCircuit) ) &&
237 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_SetInterruptTrigger(pins,Config->
InterruptTrigger) ) &&
238 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_FinishConfiguration(pins))
241 *pinsReference = pins;
242 *outContext = pinsReference;
243 errorCode = oC_ErrorCode_None;
249 oC_ErrorCode_t tempErrorCode = oC_GPIO_LLD_SetPinsUnused(pins);
251 if(oC_ErrorOccur(tempErrorCode))
253 oC_SaveError(
"GPIO-Cfg/Setting pins unused" , tempErrorCode);
258 if(ksmartfree(pinsReference,
sizeof(oC_Pins_t),AllocationFlags_CanWaitForever)==
false)
260 oC_SaveError(
"GPIO-Cfg/release context" , oC_ErrorCode_ReleaseError);
264 oC_IntMan_ExitCriticalSection();
283 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
288 oC_AssignErrorCodeIfFalse(&errorCode , isaddresscorrect(Config) , oC_ErrorCode_WrongConfigAddress) &&
289 oC_AssignErrorCodeIfFalse(&errorCode , isram(outContext) , oC_ErrorCode_OutputAddressNotInRAM)
292 errorCode = oC_GPIO_LLD_SetPinsUnused(Config->
Pins);
294 if(ksmartfree(*outContext,
sizeof(oC_Pins_t),AllocationFlags_CanWaitForever)==
false)
296 errorCode = oC_ErrorCode_ReleaseError;
306 oC_ErrorCode_t oC_GPIO_Ioctl(
oC_GPIO_Context_t Context , oC_Ioctl_Command_t Command ,
void * Data )
308 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
312 oC_AssignErrorCodeIfFalse(&errorCode , isaddresscorrect(Context) , oC_ErrorCode_WrongAddress)
323 oC_GPIO_LLD_TogglePinsState(*Context);
324 errorCode = oC_ErrorCode_None;
332 if(oC_AssignErrorCodeIfFalse(&errorCode,isaddresscorrect(Data),oC_ErrorCode_WrongAddress))
334 oC_GPIO_LLD_SetPinsState(*Context , gen_point_value(oC_GPIO_LLD_PinsState_t,Data));
335 errorCode = oC_ErrorCode_None;
345 oC_AssignErrorCodeIfFalse(&errorCode,isram(Data),oC_ErrorCode_OutputAddressNotInRAM) &&
346 oC_AssignErrorCodeIfFalse(&errorCode,oC_GPIO_LLD_ArePinsCorrect(*Context),oC_ErrorCode_GPIOPinIncorrect)
349 gen_point_value(oC_GPIO_LLD_PinsState_t,Data) = oC_GPIO_LLD_GetHighStatePins(*Context);
350 errorCode = oC_ErrorCode_None;
360 oC_AssignErrorCodeIfFalse(&errorCode,isram(Data),oC_ErrorCode_OutputAddressNotInRAM) &&
361 oC_AssignErrorCodeIfFalse(&errorCode,oC_GPIO_LLD_ArePinsCorrect(*Context),oC_ErrorCode_GPIOPinIncorrect)
364 gen_point_value(oC_GPIO_LLD_PinsState_t,Data) = oC_GPIO_LLD_GetHighStatePins(*Context);
365 errorCode = oC_ErrorCode_None;
374 errorCode = oC_ErrorCode_CommandNotHandled;
384 oC_ErrorCode_t oC_GPIO_QuickOutput( oC_Pins_t Pins )
386 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
390 bool unlocked =
false;
393 oC_IntMan_EnterCriticalSection();
395 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_BeginConfiguration( Pins)) &&
396 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_CheckIsPinUnlocked(Pins,&unlocked) ) &&
397 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_CheckIsPinUsed(Pins,&used) ) &&
398 oC_AssignErrorCodeIfFalse(&errorCode , used ==
false , oC_ErrorCode_PinIsUsed ) &&
399 oC_AssignErrorCodeIfFalse(&errorCode , unlocked , oC_ErrorCode_GPIOPinNeedUnlock ) &&
402 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_FinishConfiguration(Pins))
405 errorCode = oC_ErrorCode_None;
407 oC_IntMan_ExitCriticalSection();
415 oC_ErrorCode_t oC_GPIO_QuickInput( oC_Pins_t Pins ,
oC_GPIO_Pull_t Pull )
417 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
421 bool unlocked =
false;
424 oC_IntMan_EnterCriticalSection();
426 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_CheckIsPinUnlocked(Pins,&unlocked) ) &&
427 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_CheckIsPinUsed(Pins,&used) ) &&
428 oC_AssignErrorCodeIfFalse(&errorCode , used ==
false , oC_ErrorCode_PinIsUsed ) &&
429 oC_AssignErrorCodeIfFalse(&errorCode , unlocked , oC_ErrorCode_GPIOPinNeedUnlock ) &&
430 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_BeginConfiguration( Pins)) &&
432 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_SetPull(Pins,Pull) ) &&
433 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_FinishConfiguration(Pins))
436 errorCode = oC_ErrorCode_None;
438 oC_IntMan_ExitCriticalSection();
446 oC_ErrorCode_t oC_GPIO_QuickUnconfigure( oC_Pins_t Pins )
448 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
452 errorCode = oC_GPIO_LLD_SetPinsUnused(Pins);
476 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
480 oC_IntMan_EnterCriticalSection();
482 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_BeginConfiguration(Pins)) &&
483 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_SetSpeed(Pins,Speed)) &&
484 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_FinishConfiguration(Pins))
487 errorCode = oC_ErrorCode_None;
489 oC_IntMan_ExitCriticalSection();
512 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
516 oC_IntMan_EnterCriticalSection();
518 if(oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_ReadSpeed(Pins,(oC_GPIO_LLD_Speed_t*)outSpeed)))
520 errorCode = oC_ErrorCode_None;
523 oC_IntMan_ExitCriticalSection();
547 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
551 oC_IntMan_EnterCriticalSection();
553 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_BeginConfiguration(Pins)) &&
554 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_SetCurrent(Pins,Current)) &&
555 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_FinishConfiguration(Pins))
558 errorCode = oC_ErrorCode_None;
560 oC_IntMan_ExitCriticalSection();
584 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
588 oC_IntMan_EnterCriticalSection();
590 if(oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_ReadCurrent(Pins,(oC_GPIO_LLD_Current_t*)outCurrent)))
592 errorCode = oC_ErrorCode_None;
595 oC_IntMan_ExitCriticalSection();
617 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
621 oC_IntMan_EnterCriticalSection();
623 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_BeginConfiguration(Pins)) &&
624 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_SetMode(Pins,Mode)) &&
625 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_FinishConfiguration(Pins))
628 errorCode = oC_ErrorCode_None;
630 oC_IntMan_ExitCriticalSection();
652 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
656 oC_IntMan_EnterCriticalSection();
658 if(oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_ReadMode(Pins,(oC_GPIO_LLD_Mode_t*)outMode)))
660 errorCode = oC_ErrorCode_None;
663 oC_IntMan_ExitCriticalSection();
685 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
689 oC_IntMan_EnterCriticalSection();
691 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_BeginConfiguration(Pins)) &&
692 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_SetPull(Pins,Pull)) &&
693 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_FinishConfiguration(Pins))
696 errorCode = oC_ErrorCode_None;
698 oC_IntMan_ExitCriticalSection();
720 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
724 oC_IntMan_EnterCriticalSection();
726 if(oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_ReadPull(Pins,(oC_GPIO_LLD_Pull_t*)outPull)))
728 errorCode = oC_ErrorCode_None;
731 oC_IntMan_ExitCriticalSection();
754 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
758 oC_IntMan_EnterCriticalSection();
760 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_BeginConfiguration(Pins)) &&
761 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_SetOutputCircuit(Pins,OutputCircuit)) &&
762 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_FinishConfiguration(Pins))
765 errorCode = oC_ErrorCode_None;
767 oC_IntMan_ExitCriticalSection();
790 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
794 oC_IntMan_EnterCriticalSection();
796 if(oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_ReadOutputCircuit(Pins,(oC_GPIO_LLD_OutputCircuit_t*)outOutputCircuit)))
798 errorCode = oC_ErrorCode_None;
801 oC_IntMan_ExitCriticalSection();
824 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
828 oC_IntMan_EnterCriticalSection();
830 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_BeginConfiguration(Pins)) &&
831 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_SetInterruptTrigger(Pins,InterruptTrigger)) &&
832 oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_FinishConfiguration(Pins))
835 errorCode = oC_ErrorCode_None;
837 oC_IntMan_ExitCriticalSection();
860 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
864 oC_IntMan_EnterCriticalSection();
866 if(oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_ReadInterruptTrigger(Pins,(oC_GPIO_LLD_IntTrigger_t*)outInterruptTrigger)))
868 errorCode = oC_ErrorCode_None;
871 oC_IntMan_ExitCriticalSection();
880 char * name = malloc(
sizeof(name) , 10);
900 free(&name, AllocationFlags_Default);
905 char * name = malloc(
sizeof(name) , 10);
925 free(&name, AllocationFlags_Default);
930 char * name = malloc(
sizeof(name) , 10);
932 switch(OutputCircuit)
934 case oC_GPIO_OutputCircuit_Default:
948 free(&name, AllocationFlags_Default);
954 char * name = malloc(
sizeof(name) , 10);
972 free(&name, AllocationFlags_Default);
978 char * name = malloc(
sizeof(name) , 10);
999 free(&name, AllocationFlags_Default);
1005 char * name = malloc(
sizeof(name) , 6);
1014 name =
"RisingEdge";
1017 name =
"FallingEdge";
1020 name =
"BothLevels";
1029 name =
"BothLevels";
1035 free(&name, AllocationFlags_Default);
1067 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1072 ErrorCondition(isram(outPin) , oC_ErrorCode_OutputAddressNotInRAM) &&
1073 ErrorCondition(isaddresscorrect(Name) , oC_ErrorCode_WrongAddress)
1076 errorCode = oC_ErrorCode_PinNotDefined;
1078 oC_Pin_ForeachDefined(pin)
1080 if(strcmp(pin->Name,Name) == 0)
1083 errorCode = oC_ErrorCode_None;
1099 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1103 if(
oC_Event_WaitForState(InterruptEvent , Pins , oC_GPIO_LLD_GetImportantBitsMaskForPins(Pins) , Timeout))
1105 oC_Event_ClearStateBits(InterruptEvent , oC_GPIO_LLD_GetPinsMaskOfPins(Pins));
1106 errorCode = oC_ErrorCode_None;
1110 errorCode = oC_ErrorCode_TimeoutError;
1117 #undef _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________ 1124 #define _________________________________________INTERRUPTS_SECTION_________________________________________________________________________ 1130 oC_Event_SetState(InterruptEvent,Pins);
1133 #undef _________________________________________INTERRUPTS_SECTION_________________________________________________________________________
oC_GPIO_Mode_t
select In/Out mode
bool oC_Event_WaitForState(oC_Event_t Event, oC_Event_State_t State, oC_Event_StateMask_t StateMask, oC_Time_t Timeout)
oC_ErrorCode_t oC_GPIO_SetInterruptTrigger(oC_Pins_t Pins, oC_GPIO_IntTrigger_t InterruptTrigger)
configures interrupt for pin(s)
oC_ErrorCode_t oC_GPIO_ReadCurrent(oC_Pins_t Pins, oC_GPIO_Current_t *outCurrent)
reads configured current
oC_Pins_t * oC_GPIO_Context_t
The GPIO context structure.
The file with interface for the GPIO driver.
identifier for allocations
oC_ErrorCode_t oC_GPIO_SetMode(oC_Pins_t Pins, oC_GPIO_Mode_t Mode)
configures mode of pin(s)
The file contains definitions for the compiler, that helps to manage errors, etc. ...
oC_ErrorCode_t oC_GPIO_SetSpeed(oC_Pins_t Pins, oC_GPIO_Speed_t Speed)
configures speed of pin(s)
oC_ErrorCode_t oC_GPIO_SetOutputCircuit(oC_Pins_t Pins, oC_GPIO_OutputCircuit_t OutputCircuit)
configures output circuit
oC_ErrorCode_t oC_GPIO_ReadSpeed(oC_Pins_t Pins, oC_GPIO_Speed_t *outSpeed)
reads configured speed
oC_ErrorCode_t oC_GPIO_Unconfigure(const oC_GPIO_Config_t *Config, oC_GPIO_Context_t *outContext)
Restores default state on pins.
oC_ErrorCode_t oC_GPIO_TurnOff(void)
Turns off the GPIO driver.
The file with LLD interface for the GPIO driver.
GPIO driver configuration structure.
oC_ErrorCode_t oC_GPIO_ReadOutputCircuit(oC_Pins_t Pins, oC_GPIO_OutputCircuit_t *outOutputCircuit)
reads output circuit configuration
oC_GPIO_Current_t Current
oC_ErrorCode_t oC_GPIO_SetCurrent(oC_Pins_t Pins, oC_GPIO_Current_t Current)
configures current of pin(s)
oC_ErrorCode_t oC_GPIO_ReadMode(oC_Pins_t Pins, oC_GPIO_Mode_t *outMode)
reads mode configuration
The file with interface for driver creating.
The file with interface for the module library.
static bool oC_Module_IsTurnedOn(oC_Module_t Module)
checks if the module is turned on
The file with interface for event module.
oC_GPIO_Speed_t
speed of pins
oC_GPIO_IntTrigger_t
interrupt trigger source
The file with interface for interrupt manager.
oC_ErrorCode_t oC_GPIO_WaitForPins(oC_Pins_t Pins, oC_Time_t Timeout)
waits for interrupt in the pins
oC_ErrorCode_t oC_GPIO_Configure(const oC_GPIO_Config_t *Config, oC_GPIO_Context_t *outContext)
configures GPIO pins to work
oC_ErrorCode_t oC_GPIO_FindPinByName(const char *Name, oC_Pin_t *outPin)
searching pin by its name
static void oC_Module_TurnOn(oC_Module_t Module)
sets module as turned on
oC_GPIO_OutputCircuit_t OutputCircuit
oC_ErrorCode_t oC_GPIO_TurnOn(void)
turns on the module
oC_GPIO_Current_t
output current
static bool oC_Module_TurnOffVerification(oC_ErrorCode_t *outErrorCode, oC_Module_t Module)
verify if module is turned off
oC_ErrorCode_t oC_GPIO_ReadInterruptTrigger(oC_Pins_t Pins, oC_GPIO_IntTrigger_t *outInterruptTrigger)
reads interrupt trigger
oC_GPIO_Protection_t Protection
Definition of the null pointer.
static bool oC_Module_TurnOnVerification(oC_ErrorCode_t *outErrorCode, oC_Module_t Module)
verify if module is turned on
oC_ErrorCode_t oC_GPIO_SetPull(oC_Pins_t Pins, oC_GPIO_Pull_t Pull)
configures pull for pin(s)
static void InterruptHandler(oC_ETH_LLD_InterruptSource_t Source)
handler for interrupts
oC_GPIO_OutputCircuit_t
output circuit - open drain/push pull
oC_GPIO_Pull_t
pull-up/pull-down in input mode
oC_ErrorCode_t oC_GPIO_ReadPull(oC_Pins_t Pins, oC_GPIO_Pull_t *outPull)
reads pull configuration
bool oC_GPIO_IsTurnedOn(void)
checks if the driver is turned on
#define NULL
pointer to a zero
oC_GPIO_IntTrigger_t InterruptTrigger
static void oC_Module_TurnOff(oC_Module_t Module)
sets module as turned off