Choco OS  V.0.16.9.0
Join to the chocolate world
oc_gpio.c
Go to the documentation of this file.
1 
27 #include <oc_gpio.h>
28 #include <oc_gpio_lld.h>
29 #include <oc_compiler.h>
30 #include <oc_module.h>
31 #include <oc_intman.h>
32 #include <oc_null.h>
33 #include <string.h>
34 #include <oc_event.h>
35 
41 #define _________________________________________DRIVER_DEFINITIONS_SECTION_________________________________________________________________
42 
43 #define DRIVER_SOURCE
44 
45 /* Driver basic definitions */
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
51 
52 /* Driver interface definitions */
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
59 
60 #undef _________________________________________DRIVER_DEFINITIONS_SECTION_________________________________________________________________
61 
62 /* This header must be always at the end of include list */
63 #include <oc_driver.h>
64 
70 #define _________________________________________VARIABLES_SECTION__________________________________________________________________________
71 
72 static oC_Event_t InterruptEvent = NULL;
73 static const oC_Allocator_t Allocator = {
74  .Name = "gpio"
75 };
76 
77 #undef _________________________________________VARIABLES_SECTION__________________________________________________________________________
78 
84 #define _________________________________________LOCAL_PROTOTYPES_SECTION___________________________________________________________________
85 
86 static void InterruptHandler( oC_Pins_t Pins );
87 
88 #undef _________________________________________LOCAL_PROTOTYPES_SECTION___________________________________________________________________
89 
90 
96 #define _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________
97 
98 //==========================================================================================================================================
107 //==========================================================================================================================================
108 oC_ErrorCode_t oC_GPIO_TurnOn( void )
109 {
110  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
111 
112  oC_IntMan_EnterCriticalSection();
113 
114  if(oC_Module_TurnOffVerification(&errorCode , oC_Module_GPIO))
115  {
116  errorCode = oC_GPIO_LLD_TurnOnDriver();
117 
118  if(errorCode == oC_ErrorCode_ModuleIsTurnedOn)
119  {
120  errorCode = oC_ErrorCode_None;
121  }
122 
123  if(!oC_ErrorOccur(errorCode))
124  {
125  InterruptEvent = oC_Event_New(oC_Event_State_Inactive , &Allocator , AllocationFlags_CanWait1Second);
126 
127  if(
128  ErrorCondition( oC_Event_IsCorrect(InterruptEvent) , oC_ErrorCode_AllocationError) &&
129  oC_AssignErrorCode( &errorCode , oC_GPIO_LLD_SetDriverInterruptHandler(InterruptHandler))
130  )
131  {
132  oC_Module_TurnOn(oC_Module_GPIO);
133  errorCode = oC_ErrorCode_None;
134  }
135  }
136 
137  }
138 
139  oC_IntMan_ExitCriticalSection();
140 
141  return errorCode;
142 }
143 
144 //==========================================================================================================================================
153 //==========================================================================================================================================
154 oC_ErrorCode_t oC_GPIO_TurnOff( void )
155 {
156  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
157 
158  oC_IntMan_ExitCriticalSection();
159 
160  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO))
161  {
162  /* This must be at the start of the function */
163  oC_Module_TurnOff(oC_Module_GPIO);
164 
165  errorCode = oC_GPIO_LLD_TurnOffDriver();
166 
167  if(errorCode == oC_ErrorCode_ModuleNotStartedYet)
168  {
169  errorCode = oC_ErrorCode_None;
170  }
171 
172  if(!oC_Event_Delete(&InterruptEvent,AllocationFlags_CanWaitForever))
173  {
174  errorCode = oC_ErrorCode_CannotDeleteObject;
175  }
176  }
177 
178  oC_IntMan_ExitCriticalSection();
179 
180  return errorCode;
181 }
182 
183 //==========================================================================================================================================
189 //==========================================================================================================================================
190 bool oC_GPIO_IsTurnedOn( void )
191 {
192  return oC_Module_IsTurnedOn(oC_Module_GPIO);
193 }
194 
195 //==========================================================================================================================================
206 //==========================================================================================================================================
207 oC_ErrorCode_t oC_GPIO_Configure( const oC_GPIO_Config_t * Config , oC_GPIO_Context_t * outContext )
208 {
209  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
210 
211  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO))
212  {
213  if(
214  oC_AssignErrorCodeIfFalse(&errorCode , isaddresscorrect(Config) , oC_ErrorCode_WrongConfigAddress) &&
215  oC_AssignErrorCodeIfFalse(&errorCode , isram(outContext) , oC_ErrorCode_OutputAddressNotInRAM)
216  )
217  {
218  oC_Pins_t pins = Config->Pins;
219  bool unlocked = false;
220  bool used = false;
221  oC_Pins_t * pinsReference = ksmartalloc(sizeof(oC_Pins_t),&Allocator,AllocationFlags_CanWait1Second);
222 
223 
224  oC_IntMan_EnterCriticalSection();
225  if(
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))
239  )
240  {
241  *pinsReference = pins;
242  *outContext = pinsReference;
243  errorCode = oC_ErrorCode_None;
244  }
245  else
246  {
247  if(used)
248  {
249  oC_ErrorCode_t tempErrorCode = oC_GPIO_LLD_SetPinsUnused(pins);
250 
251  if(oC_ErrorOccur(tempErrorCode))
252  {
253  oC_SaveError("GPIO-Cfg/Setting pins unused" , tempErrorCode);
254  }
255  }
256  if(pinsReference)
257  {
258  if(ksmartfree(pinsReference,sizeof(oC_Pins_t),AllocationFlags_CanWaitForever)==false)
259  {
260  oC_SaveError("GPIO-Cfg/release context" , oC_ErrorCode_ReleaseError);
261  }
262  }
263  }
264  oC_IntMan_ExitCriticalSection();
265  }
266  }
267 
268  return errorCode;
269 }
270 
271 //==========================================================================================================================================
280 //==========================================================================================================================================
281 oC_ErrorCode_t oC_GPIO_Unconfigure( const oC_GPIO_Config_t * Config , oC_GPIO_Context_t * outContext )
282 {
283  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
284 
285  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO))
286  {
287  if(
288  oC_AssignErrorCodeIfFalse(&errorCode , isaddresscorrect(Config) , oC_ErrorCode_WrongConfigAddress) &&
289  oC_AssignErrorCodeIfFalse(&errorCode , isram(outContext) , oC_ErrorCode_OutputAddressNotInRAM)
290  )
291  {
292  errorCode = oC_GPIO_LLD_SetPinsUnused(Config->Pins);
293 
294  if(ksmartfree(*outContext,sizeof(oC_Pins_t),AllocationFlags_CanWaitForever)==false)
295  {
296  errorCode = oC_ErrorCode_ReleaseError;
297  }
298  }
299  }
300 
301  return errorCode;
302 }
303 
304 //==========================================================================================================================================
305 //==========================================================================================================================================
306 oC_ErrorCode_t oC_GPIO_Ioctl( oC_GPIO_Context_t Context , oC_Ioctl_Command_t Command , void * Data )
307 {
308  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
309 
310  if(
311  oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO) &&
312  oC_AssignErrorCodeIfFalse(&errorCode , isaddresscorrect(Context) , oC_ErrorCode_WrongAddress)
313  )
314  {
315  switch(Command)
316  {
317  //==============================================================================================================================
318  /*
319  * Toggle pins command
320  */
321  //==============================================================================================================================
323  oC_GPIO_LLD_TogglePinsState(*Context);
324  errorCode = oC_ErrorCode_None;
325  break;
326  //==============================================================================================================================
327  /*
328  * Set pins state command
329  */
330  //==============================================================================================================================
332  if(oC_AssignErrorCodeIfFalse(&errorCode,isaddresscorrect(Data),oC_ErrorCode_WrongAddress))
333  {
334  oC_GPIO_LLD_SetPinsState(*Context , gen_point_value(oC_GPIO_LLD_PinsState_t,Data));
335  errorCode = oC_ErrorCode_None;
336  }
337  break;
338  //==============================================================================================================================
339  /*
340  * Get high pins state command
341  */
342  //==============================================================================================================================
344  if(
345  oC_AssignErrorCodeIfFalse(&errorCode,isram(Data),oC_ErrorCode_OutputAddressNotInRAM) &&
346  oC_AssignErrorCodeIfFalse(&errorCode,oC_GPIO_LLD_ArePinsCorrect(*Context),oC_ErrorCode_GPIOPinIncorrect)
347  )
348  {
349  gen_point_value(oC_GPIO_LLD_PinsState_t,Data) = oC_GPIO_LLD_GetHighStatePins(*Context);
350  errorCode = oC_ErrorCode_None;
351  }
352  break;
353  //==============================================================================================================================
354  /*
355  * Get low pins state command
356  */
357  //==============================================================================================================================
359  if(
360  oC_AssignErrorCodeIfFalse(&errorCode,isram(Data),oC_ErrorCode_OutputAddressNotInRAM) &&
361  oC_AssignErrorCodeIfFalse(&errorCode,oC_GPIO_LLD_ArePinsCorrect(*Context),oC_ErrorCode_GPIOPinIncorrect)
362  )
363  {
364  gen_point_value(oC_GPIO_LLD_PinsState_t,Data) = oC_GPIO_LLD_GetHighStatePins(*Context);
365  errorCode = oC_ErrorCode_None;
366  }
367  break;
368  //==============================================================================================================================
369  /*
370  * Not handled commands
371  */
372  //==============================================================================================================================
373  default:
374  errorCode = oC_ErrorCode_CommandNotHandled;
375  break;
376  }
377  }
378 
379  return errorCode;
380 }
381 
382 //==========================================================================================================================================
383 //==========================================================================================================================================
384 oC_ErrorCode_t oC_GPIO_QuickOutput( oC_Pins_t Pins )
385 {
386  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
387 
388  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO))
389  {
390  bool unlocked = false;
391  bool used = false;
392 
393  oC_IntMan_EnterCriticalSection();
394  if(
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 ) &&
400  oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_SetMode(Pins,oC_GPIO_Mode_Output) ) &&
401  oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_SetOutputCircuit(Pins,oC_GPIO_OutputCircuit_PushPull) ) &&
402  oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_FinishConfiguration(Pins))
403  )
404  {
405  errorCode = oC_ErrorCode_None;
406  }
407  oC_IntMan_ExitCriticalSection();
408  }
409 
410  return errorCode;
411 }
412 
413 //==========================================================================================================================================
414 //==========================================================================================================================================
415 oC_ErrorCode_t oC_GPIO_QuickInput( oC_Pins_t Pins , oC_GPIO_Pull_t Pull )
416 {
417  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
418 
419  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO))
420  {
421  bool unlocked = false;
422  bool used = false;
423 
424  oC_IntMan_EnterCriticalSection();
425  if(
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)) &&
431  oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_SetMode(Pins,oC_GPIO_Mode_Input) ) &&
432  oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_SetPull(Pins,Pull) ) &&
433  oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_FinishConfiguration(Pins))
434  )
435  {
436  errorCode = oC_ErrorCode_None;
437  }
438  oC_IntMan_ExitCriticalSection();
439  }
440 
441  return errorCode;
442 }
443 
444 //==========================================================================================================================================
445 //==========================================================================================================================================
446 oC_ErrorCode_t oC_GPIO_QuickUnconfigure( oC_Pins_t Pins )
447 {
448  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
449 
450  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO))
451  {
452  errorCode = oC_GPIO_LLD_SetPinsUnused(Pins);
453  }
454 
455  return errorCode;
456 }
457 
458 //==========================================================================================================================================
473 //==========================================================================================================================================
474 oC_ErrorCode_t oC_GPIO_SetSpeed( oC_Pins_t Pins , oC_GPIO_Speed_t Speed )
475 {
476  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
477 
478  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO))
479  {
480  oC_IntMan_EnterCriticalSection();
481  if(
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))
485  )
486  {
487  errorCode = oC_ErrorCode_None;
488  }
489  oC_IntMan_ExitCriticalSection();
490  }
491 
492  return errorCode;
493 }
494 //==========================================================================================================================================
509 //==========================================================================================================================================
510 oC_ErrorCode_t oC_GPIO_ReadSpeed( oC_Pins_t Pins , oC_GPIO_Speed_t * outSpeed )
511 {
512  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
513 
514  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO))
515  {
516  oC_IntMan_EnterCriticalSection();
517 
518  if(oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_ReadSpeed(Pins,(oC_GPIO_LLD_Speed_t*)outSpeed)))
519  {
520  errorCode = oC_ErrorCode_None;
521  }
522 
523  oC_IntMan_ExitCriticalSection();
524  }
525 
526  return errorCode;
527 }
528 
529 //==========================================================================================================================================
544 //==========================================================================================================================================
545 oC_ErrorCode_t oC_GPIO_SetCurrent( oC_Pins_t Pins , oC_GPIO_Current_t Current )
546 {
547  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
548 
549  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO))
550  {
551  oC_IntMan_EnterCriticalSection();
552  if(
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))
556  )
557  {
558  errorCode = oC_ErrorCode_None;
559  }
560  oC_IntMan_ExitCriticalSection();
561  }
562 
563  return errorCode;
564 }
565 
566 //==========================================================================================================================================
581 //==========================================================================================================================================
582 oC_ErrorCode_t oC_GPIO_ReadCurrent( oC_Pins_t Pins , oC_GPIO_Current_t * outCurrent )
583 {
584  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
585 
586  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO))
587  {
588  oC_IntMan_EnterCriticalSection();
589 
590  if(oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_ReadCurrent(Pins,(oC_GPIO_LLD_Current_t*)outCurrent)))
591  {
592  errorCode = oC_ErrorCode_None;
593  }
594 
595  oC_IntMan_ExitCriticalSection();
596  }
597 
598  return errorCode;
599 }
600 //==========================================================================================================================================
614 //==========================================================================================================================================
615 oC_ErrorCode_t oC_GPIO_SetMode( oC_Pins_t Pins , oC_GPIO_Mode_t Mode )
616 {
617  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
618 
619  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO))
620  {
621  oC_IntMan_EnterCriticalSection();
622  if(
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))
626  )
627  {
628  errorCode = oC_ErrorCode_None;
629  }
630  oC_IntMan_ExitCriticalSection();
631  }
632 
633  return errorCode;
634 }
635 //==========================================================================================================================================
649 //==========================================================================================================================================
650 oC_ErrorCode_t oC_GPIO_ReadMode( oC_Pins_t Pins , oC_GPIO_Mode_t * outMode )
651 {
652  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
653 
654  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO))
655  {
656  oC_IntMan_EnterCriticalSection();
657 
658  if(oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_ReadMode(Pins,(oC_GPIO_LLD_Mode_t*)outMode)))
659  {
660  errorCode = oC_ErrorCode_None;
661  }
662 
663  oC_IntMan_ExitCriticalSection();
664  }
665 
666  return errorCode;
667 }
668 //==========================================================================================================================================
682 //==========================================================================================================================================
683 oC_ErrorCode_t oC_GPIO_SetPull( oC_Pins_t Pins , oC_GPIO_Pull_t Pull )
684 {
685  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
686 
687  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO))
688  {
689  oC_IntMan_EnterCriticalSection();
690  if(
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))
694  )
695  {
696  errorCode = oC_ErrorCode_None;
697  }
698  oC_IntMan_ExitCriticalSection();
699  }
700 
701  return errorCode;
702 }
703 //==========================================================================================================================================
717 //==========================================================================================================================================
718 oC_ErrorCode_t oC_GPIO_ReadPull( oC_Pins_t Pins , oC_GPIO_Pull_t * outPull )
719 {
720  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
721 
722  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO))
723  {
724  oC_IntMan_EnterCriticalSection();
725 
726  if(oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_ReadPull(Pins,(oC_GPIO_LLD_Pull_t*)outPull)))
727  {
728  errorCode = oC_ErrorCode_None;
729  }
730 
731  oC_IntMan_ExitCriticalSection();
732  }
733 
734  return errorCode;
735 }
736 //==========================================================================================================================================
751 //==========================================================================================================================================
752 oC_ErrorCode_t oC_GPIO_SetOutputCircuit( oC_Pins_t Pins , oC_GPIO_OutputCircuit_t OutputCircuit )
753 {
754  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
755 
756  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO))
757  {
758  oC_IntMan_EnterCriticalSection();
759  if(
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))
763  )
764  {
765  errorCode = oC_ErrorCode_None;
766  }
767  oC_IntMan_ExitCriticalSection();
768  }
769 
770  return errorCode;
771 }
772 //==========================================================================================================================================
787 //==========================================================================================================================================
788 oC_ErrorCode_t oC_GPIO_ReadOutputCircuit( oC_Pins_t Pins , oC_GPIO_OutputCircuit_t * outOutputCircuit )
789 {
790  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
791 
792  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO))
793  {
794  oC_IntMan_EnterCriticalSection();
795 
796  if(oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_ReadOutputCircuit(Pins,(oC_GPIO_LLD_OutputCircuit_t*)outOutputCircuit)))
797  {
798  errorCode = oC_ErrorCode_None;
799  }
800 
801  oC_IntMan_ExitCriticalSection();
802  }
803 
804  return errorCode;
805 }
806 //==========================================================================================================================================
821 //==========================================================================================================================================
822 oC_ErrorCode_t oC_GPIO_SetInterruptTrigger( oC_Pins_t Pins , oC_GPIO_IntTrigger_t InterruptTrigger )
823 {
824  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
825 
826  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO))
827  {
828  oC_IntMan_EnterCriticalSection();
829  if(
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))
833  )
834  {
835  errorCode = oC_ErrorCode_None;
836  }
837  oC_IntMan_ExitCriticalSection();
838  }
839 
840  return errorCode;
841 }
842 //==========================================================================================================================================
857 //==========================================================================================================================================
858 oC_ErrorCode_t oC_GPIO_ReadInterruptTrigger( oC_Pins_t Pins , oC_GPIO_IntTrigger_t * outInterruptTrigger )
859 {
860  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
861 
862  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO))
863  {
864  oC_IntMan_EnterCriticalSection();
865 
866  if(oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_ReadInterruptTrigger(Pins,(oC_GPIO_LLD_IntTrigger_t*)outInterruptTrigger)))
867  {
868  errorCode = oC_ErrorCode_None;
869  }
870 
871  oC_IntMan_ExitCriticalSection();
872  }
873 
874  return errorCode;
875 }
876 
877 
878 const char * oC_GPIO_GetCurrentNameFromEnum(oC_GPIO_Current_t Current)
879 {
880  char * name = malloc(sizeof(name) , 10);
881 
882  switch(Current)
883  {
885  name = "Default";
886  break;
888  name = "Minimum";
889  break;
891  name = "Medium";
892  break;
894  name = "Maximum";
895  break;
896  default:
897  name = "Unknown";
898  break;
899  }
900  free(&name, AllocationFlags_Default);
901  return name;
902 }
903 const char * oC_GPIO_GetModeNameFromEnum(oC_GPIO_Mode_t Mode)
904 {
905  char * name = malloc(sizeof(name) , 10);
906 
907  switch(Mode)
908  {
910  name = "Default";
911  break;
912  case oC_GPIO_Mode_Input:
913  name = "Input";
914  break;
915  case oC_GPIO_Mode_Output:
916  name = "Output";
917  break;
919  name = "Alternate";
920  break;
921  default:
922  name = "Unknown";
923  break;
924  }
925  free(&name, AllocationFlags_Default);
926  return name;
927 }
928 const char * oC_GPIO_GetOutputCircuitNameFromEnum(oC_GPIO_OutputCircuit_t OutputCircuit)
929 {
930  char * name = malloc(sizeof(name) , 10);
931 
932  switch(OutputCircuit)
933  {
934  case oC_GPIO_OutputCircuit_Default:
935  name = "Default";
936  break;
938  name = "OpenDrain";
939  break;
941  name = "PushPull";
942  break;
943  default:
944  name = "Unknown";
945  break;
946  }
947 
948  free(&name, AllocationFlags_Default);
949  return name;
950 }
951 
952 const char * oC_GPIO_GetPullNameFromEnum(oC_GPIO_Pull_t Pull)
953 {
954  char * name = malloc(sizeof(name) , 10);
955 
956  switch(Pull)
957  {
959  name = "Default";
960  break;
961  case oC_GPIO_Pull_Down:
962  name = "Down";
963  break;
964  case oC_GPIO_Pull_Up:
965  name = "Up";
966  break;
967  default:
968  name = "Unknown";
969  break;
970  }
971 
972  free(&name, AllocationFlags_Default);
973  return name;
974 }
975 
976 const char * oC_GPIO_GetSpeedNameFromEnum(oC_GPIO_Speed_t Speed)
977 {
978  char * name = malloc(sizeof(name) , 10);
979 
980  switch(Speed)
981  {
983  name = "Default";
984  break;
986  name = "Maximum";
987  break;
989  name = "Minimum";
990  break;
992  name = "Medium";
993  break;
994  default:
995  name = "Unknown";
996  break;
997  }
998 
999  free(&name, AllocationFlags_Default);
1000  return name;
1001 }
1002 
1003 const char * oC_GPIO_GetIntTriggerNameFromEnum(oC_GPIO_IntTrigger_t IntTrigger)
1004 {
1005  char * name = malloc(sizeof(name) , 6);
1006 
1007  switch(IntTrigger)
1008  {
1009  default:
1010  case oC_GPIO_IntTrigger_Off :
1011  name = "Off";
1012  break;
1014  name = "RisingEdge";
1015  break;
1017  name = "FallingEdge";
1018  break;
1020  name = "BothLevels";
1021  break;
1023  name = "HighLevel";
1024  break;
1026  name = "LowLevel";
1027  break;
1029  name = "BothLevels";
1030  break;
1031  name = "Unknown";
1032  break;
1033  }
1034 
1035  free(&name, AllocationFlags_Default);
1036  return name;
1037 }
1038 
1039 //==========================================================================================================================================
1064 //==========================================================================================================================================
1065 oC_ErrorCode_t oC_GPIO_FindPinByName( const char * Name , oC_Pin_t * outPin )
1066 {
1067  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1068 
1069  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO))
1070  {
1071  if(
1072  ErrorCondition(isram(outPin) , oC_ErrorCode_OutputAddressNotInRAM) &&
1073  ErrorCondition(isaddresscorrect(Name) , oC_ErrorCode_WrongAddress)
1074  )
1075  {
1076  errorCode = oC_ErrorCode_PinNotDefined;
1077 
1078  oC_Pin_ForeachDefined(pin)
1079  {
1080  if(strcmp(pin->Name,Name) == 0)
1081  {
1082  *outPin = pin->Pin;
1083  errorCode = oC_ErrorCode_None;
1084  }
1085  }
1086  }
1087  }
1088 
1089  return errorCode;
1090 }
1091 
1092 //==========================================================================================================================================
1096 //==========================================================================================================================================
1097 oC_ErrorCode_t oC_GPIO_WaitForPins( oC_Pins_t Pins , oC_Time_t Timeout )
1098 {
1099  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1100 
1101  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO))
1102  {
1103  if(oC_Event_WaitForState(InterruptEvent , Pins , oC_GPIO_LLD_GetImportantBitsMaskForPins(Pins) , Timeout))
1104  {
1105  oC_Event_ClearStateBits(InterruptEvent , oC_GPIO_LLD_GetPinsMaskOfPins(Pins));
1106  errorCode = oC_ErrorCode_None;
1107  }
1108  else
1109  {
1110  errorCode = oC_ErrorCode_TimeoutError;
1111  }
1112  }
1113 
1114  return errorCode;
1115 }
1116 
1117 #undef _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________
1118 
1124 #define _________________________________________INTERRUPTS_SECTION_________________________________________________________________________
1125 
1126 //==========================================================================================================================================
1127 //==========================================================================================================================================
1128 static void InterruptHandler( oC_Pins_t Pins )
1129 {
1130  oC_Event_SetState(InterruptEvent,Pins);
1131 }
1132 
1133 #undef _________________________________________INTERRUPTS_SECTION_________________________________________________________________________
1134 
reads pins in high state
Definition: oc_gpio.h:176
oC_GPIO_Mode_t
select In/Out mode
Definition: oc_gpio.h:97
Toggles pins state.
Definition: oc_gpio.h:174
bool oC_Event_WaitForState(oC_Event_t Event, oC_Event_State_t State, oC_Event_StateMask_t StateMask, oC_Time_t Timeout)
Definition: oc_event.c:245
oC_GPIO_Speed_t Speed
Definition: oc_gpio.h:194
oC_Pins_t Pins
Definition: oc_gpio.h:192
oC_ErrorCode_t oC_GPIO_SetInterruptTrigger(oC_Pins_t Pins, oC_GPIO_IntTrigger_t InterruptTrigger)
configures interrupt for pin(s)
Definition: oc_gpio.c:822
oC_GPIO_Pull_t Pull
Definition: oc_gpio.h:197
const char * Name
Definition: oc_stdlib.h:161
oC_ErrorCode_t oC_GPIO_ReadCurrent(oC_Pins_t Pins, oC_GPIO_Current_t *outCurrent)
reads configured current
Definition: oc_gpio.c:582
oC_Pins_t * oC_GPIO_Context_t
The GPIO context structure.
Definition: oc_gpio.h:212
The file with interface for the GPIO driver.
identifier for allocations
Definition: oc_stdlib.h:159
oC_ErrorCode_t oC_GPIO_SetMode(oC_Pins_t Pins, oC_GPIO_Mode_t Mode)
configures mode of pin(s)
Definition: oc_gpio.c:615
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)
Definition: oc_gpio.c:474
oC_ErrorCode_t oC_GPIO_SetOutputCircuit(oC_Pins_t Pins, oC_GPIO_OutputCircuit_t OutputCircuit)
configures output circuit
Definition: oc_gpio.c:752
oC_ErrorCode_t oC_GPIO_ReadSpeed(oC_Pins_t Pins, oC_GPIO_Speed_t *outSpeed)
reads configured speed
Definition: oc_gpio.c:510
oC_ErrorCode_t oC_GPIO_Unconfigure(const oC_GPIO_Config_t *Config, oC_GPIO_Context_t *outContext)
Restores default state on pins.
Definition: oc_gpio.c:281
oC_ErrorCode_t oC_GPIO_TurnOff(void)
Turns off the GPIO driver.
Definition: oc_gpio.c:154
The file with LLD interface for the GPIO driver.
GPIO driver configuration structure.
Definition: oc_gpio.h:190
oC_ErrorCode_t oC_GPIO_ReadOutputCircuit(oC_Pins_t Pins, oC_GPIO_OutputCircuit_t *outOutputCircuit)
reads output circuit configuration
Definition: oc_gpio.c:788
oC_GPIO_Current_t Current
Definition: oc_gpio.h:195
oC_ErrorCode_t oC_GPIO_SetCurrent(oC_Pins_t Pins, oC_GPIO_Current_t Current)
configures current of pin(s)
Definition: oc_gpio.c:545
oC_ErrorCode_t oC_GPIO_ReadMode(oC_Pins_t Pins, oC_GPIO_Mode_t *outMode)
reads mode configuration
Definition: oc_gpio.c:650
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
Definition: oc_module.h:121
reads pins in low state
Definition: oc_gpio.h:177
The file with interface for event module.
oC_GPIO_Speed_t
speed of pins
Definition: oc_gpio.h:66
oC_GPIO_IntTrigger_t
interrupt trigger source
Definition: oc_gpio.h:141
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
Definition: oc_gpio.c:1097
oC_GPIO_Mode_t Mode
Definition: oc_gpio.h:196
oC_ErrorCode_t oC_GPIO_Configure(const oC_GPIO_Config_t *Config, oC_GPIO_Context_t *outContext)
configures GPIO pins to work
Definition: oc_gpio.c:207
oC_ErrorCode_t oC_GPIO_FindPinByName(const char *Name, oC_Pin_t *outPin)
searching pin by its name
Definition: oc_gpio.c:1065
static void oC_Module_TurnOn(oC_Module_t Module)
sets module as turned on
Definition: oc_module.h:170
oC_GPIO_OutputCircuit_t OutputCircuit
Definition: oc_gpio.h:198
oC_ErrorCode_t oC_GPIO_TurnOn(void)
turns on the module
Definition: oc_gpio.c:108
oC_GPIO_Current_t
output current
Definition: oc_gpio.h:82
static bool oC_Module_TurnOffVerification(oC_ErrorCode_t *outErrorCode, oC_Module_t Module)
verify if module is turned off
Definition: oc_module.h:155
oC_ErrorCode_t oC_GPIO_ReadInterruptTrigger(oC_Pins_t Pins, oC_GPIO_IntTrigger_t *outInterruptTrigger)
reads interrupt trigger
Definition: oc_gpio.c:858
oC_GPIO_Protection_t Protection
Definition: oc_gpio.h:193
Definition of the null pointer.
static bool oC_Module_TurnOnVerification(oC_ErrorCode_t *outErrorCode, oC_Module_t Module)
verify if module is turned on
Definition: oc_module.h:138
oC_ErrorCode_t oC_GPIO_SetPull(oC_Pins_t Pins, oC_GPIO_Pull_t Pull)
configures pull for pin(s)
Definition: oc_gpio.c:683
static void InterruptHandler(oC_ETH_LLD_InterruptSource_t Source)
handler for interrupts
Definition: oc_eth.c:1124
oC_GPIO_OutputCircuit_t
output circuit - open drain/push pull
Definition: oc_gpio.h:126
oC_GPIO_Pull_t
pull-up/pull-down in input mode
Definition: oc_gpio.h:112
oC_ErrorCode_t oC_GPIO_ReadPull(oC_Pins_t Pins, oC_GPIO_Pull_t *outPull)
reads pull configuration
Definition: oc_gpio.c:718
bool oC_GPIO_IsTurnedOn(void)
checks if the driver is turned on
Definition: oc_gpio.c:190
#define NULL
pointer to a zero
Definition: oc_null.h:37
oC_GPIO_IntTrigger_t InterruptTrigger
Definition: oc_gpio.h:199
static void oC_Module_TurnOff(oC_Module_t Module)
sets module as turned off
Definition: oc_module.h:185