Choco OS  V.0.16.9.0
Join to the chocolate world
oc_gpio_lld.c
1 
27 #include <oc_gpio_lld.h>
28 #include <oc_mem_lld.h>
29 #include <oc_bits.h>
30 #include <oc_lld.h>
31 #include <oc_module.h>
32 #include <oc_mcs.h>
33 #include <oc_lsf.h>
34 #include <oc_interrupts.h>
35 #include <oc_channels.h>
36 
42 #define _________________________________________LOCAL_MACROS_SECTION_______________________________________________________________________
43 
44 #define PORT(Pins) oC_Pin_GetPort(Pins)
45 #define PORT_INDEX(Pins) oC_Channel_ToIndex(GPIO , PORT(Pins))
46 #define PINS(Pins) oC_Pin_GetPinsInPort(Pins)
47 #define IsPoweredOn(Pins) oC_Machine_IsChannelPoweredOn(PORT(Pins))
48 #define GPIODATA(Pins) oC_Machine_Register(PORT(Pins),GPIODATA)
49 #define GPIOCR(Pins) oC_Machine_Register(PORT(Pins),GPIOCR)
50 #define GPIODEN(Pins) oC_Machine_Register(PORT(Pins),GPIODEN)
51 #define GPIODR2R(Pins) oC_Machine_Register(PORT(Pins),GPIODR2R)
52 #define GPIODR4R(Pins) oC_Machine_Register(PORT(Pins),GPIODR4R)
53 #define GPIODR8R(Pins) oC_Machine_Register(PORT(Pins),GPIODR8R)
54 #define GPIODIR(Pins) oC_Machine_Register(PORT(Pins),GPIODIR)
55 #define GPIOAFSEL(Pins) oC_Machine_Register(PORT(Pins),GPIOAFSEL)
56 #define GPIOPUR(Pins) oC_Machine_Register(PORT(Pins),GPIOPUR)
57 #define GPIOPDR(Pins) oC_Machine_Register(PORT(Pins),GPIOPDR)
58 #define GPIOPCTL(Pins) oC_Machine_Register(PORT(Pins),GPIOPCTL)
59 #define GPIOODR(Pins) oC_Machine_Register(PORT(Pins),GPIOODR)
60 #define GPIOIM(Pins) oC_Machine_Register(PORT(Pins),GPIOIM)
61 #define GPIOIS(Pins) oC_Machine_Register(PORT(Pins),GPIOIS)
62 #define GPIOIBE(Pins) oC_Machine_Register(PORT(Pins),GPIOIBE)
63 #define GPIOIEV(Pins) oC_Machine_Register(PORT(Pins),GPIOIEV)
64 #define IsRam(Address) oC_LSF_IsRamAddress(Address)
65 #define IsRom(Address) oC_LSF_IsRomAddress(Address)
66 
67 #undef _________________________________________LOCAL_MACROS_SECTION_______________________________________________________________________
68 
74 #define _________________________________________MAIN_DRIVER_CONNECTIONS_SECTION____________________________________________________________
75 
76 oC_LLD_ConnectToMainDriver(GPIO,IsPortCorrect);
77 oC_LLD_ConnectToMainDriver(GPIO,IsPortIndexCorrect);
78 oC_LLD_ConnectToMainDriver(GPIO,GetPinsMaskOfPins);
79 oC_LLD_ConnectToMainDriver(GPIO,GetPortOfPins);
80 oC_LLD_ConnectToMainDriver(GPIO,PortToPortIndex);
81 oC_LLD_ConnectToMainDriver(GPIO,PortIndexToPort);
82 oC_LLD_ConnectToMainDriver(GPIO,IsPinDefined);
83 oC_LLD_ConnectToMainDriver(GPIO,ArePinsDefined);
84 oC_LLD_ConnectToMainDriver(GPIO,ArePinsCorrect);
85 oC_LLD_ConnectToMainDriver(GPIO,IsSinglePin);
86 oC_LLD_ConnectToMainDriver(GPIO,GetPinsFor);
87 oC_LLD_ConnectToMainDriver(GPIO,GetPortName);
88 oC_LLD_ConnectToMainDriver(GPIO,GetPinName);
89 oC_LLD_ConnectToMainDriver(GPIO,SetPower);
90 oC_LLD_ConnectToMainDriver(GPIO,ReadPower);
91 oC_LLD_ConnectToMainDriver(GPIO,CheckIsPinUsed);
92 oC_LLD_ConnectToMainDriver(GPIO,ArePinsUnused);
93 oC_LLD_ConnectToMainDriver(GPIO,WriteData);
94 oC_LLD_ConnectToMainDriver(GPIO,ReadData);
95 oC_LLD_ConnectToMainDriver(GPIO,ReadDataReference);
96 oC_LLD_ConnectToMainDriver(GPIO,GetHighStatePins);
97 oC_LLD_ConnectToMainDriver(GPIO,GetLowStatePins);
98 oC_LLD_ConnectToMainDriver(GPIO,IsPinsState);
99 oC_LLD_ConnectToMainDriver(GPIO,SetPinsState);
100 oC_LLD_ConnectToMainDriver(GPIO,TogglePinsState);
101 oC_LLD_ConnectToMainDriver(GPIO,GetPinName);
102 
103 #undef _________________________________________MAIN_DRIVER_CONNECTIONS_SECTION____________________________________________________________
104 
110 #define _________________________________________LOCAL_VARIABLES_SECTION____________________________________________________________________
111 
112 static oC_PinsMask_t UsedPinsArray[oC_ModuleChannel_NumberOfElements(GPIO)];
113 static oC_GPIO_LLD_Interrupt_t InterruptHandler = NULL;
114 
115 #undef _________________________________________LOCAL_VARIABLES_SECTION____________________________________________________________________
116 
117 
123 #define _________________________________________INTERFACE_FUNCTIONS_SECTION_______________________________________________________________
124 
125 //==========================================================================================================================================
130 //==========================================================================================================================================
131 oC_ErrorCode_t oC_GPIO_LLD_TurnOnDriver( void )
132 {
133  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
134 
136 
137  if(oC_Module_TurnOffVerification(&errorCode , oC_Module_GPIO_LLD))
138  {
139  oC_Module_TurnOn(oC_Module_GPIO_LLD);
140 
141  oC_GPIO_LLD_ForEachPort(port)
142  {
143  UsedPinsArray[oC_Channel_ToIndex(GPIO,port)] = 0;
144  }
145 
147  errorCode = oC_ErrorCode_None;
148  }
149 
151 
152  return errorCode;
153 }
154 
155 //==========================================================================================================================================
160 //==========================================================================================================================================
161 oC_ErrorCode_t oC_GPIO_LLD_TurnOffDriver( void )
162 {
163  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
164 
166 
167  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO_LLD))
168  {
169  oC_Module_TurnOff(oC_Module_GPIO_LLD);
170 
172  errorCode = oC_ErrorCode_None;
173  }
174 
176 
177  return errorCode;
178 }
179 
180 //==========================================================================================================================================
185 //==========================================================================================================================================
186 bool oC_GPIO_LLD_IsPortCorrect( oC_Port_t Port )
187 {
188  return oC_Channel_IsCorrect(GPIO , Port);
189 }
190 
191 //==========================================================================================================================================
196 //==========================================================================================================================================
197 bool oC_GPIO_LLD_IsPortIndexCorrect( oC_PortIndex_t PortIndex )
198 {
199  return PortIndex < oC_ModuleChannel_NumberOfElements(GPIO);
200 }
201 
202 //==========================================================================================================================================
207 //==========================================================================================================================================
208 oC_PinsMask_t oC_GPIO_LLD_GetPinsMaskOfPins( oC_Pins_t Pins )
209 {
210  return PINS(Pins);
211 }
212 
213 //==========================================================================================================================================
218 //==========================================================================================================================================
219 oC_Port_t oC_GPIO_LLD_GetPortOfPins( oC_Pins_t Pins )
220 {
221  return PORT(Pins);
222 }
223 
224 //==========================================================================================================================================
229 //==========================================================================================================================================
230 oC_PortIndex_t oC_GPIO_LLD_PortToPortIndex( oC_Port_t Port )
231 {
232  return oC_Channel_ToIndex(GPIO,Port);
233 }
234 
235 //==========================================================================================================================================
240 //==========================================================================================================================================
241 oC_Port_t oC_GPIO_LLD_PortIndexToPort( oC_PortIndex_t PortIndex )
242 {
243  return oC_Channel_FromIndex(GPIO,PortIndex);
244 }
245 
246 //==========================================================================================================================================
251 //==========================================================================================================================================
252 bool oC_GPIO_LLD_IsPinDefined( oC_Pins_t Pin )
253 {
254  bool defined = false;
255 
256  oC_Pin_ForeachDefined(pin)
257  {
258  if(pin->Pin == Pin)
259  {
260  defined = true;
261  break;
262  }
263  }
264 
265  return defined;
266 }
267 
268 //==========================================================================================================================================
273 //==========================================================================================================================================
274 bool oC_GPIO_LLD_ArePinsDefined( oC_Pins_t Pins )
275 {
276  bool allDefined = false;
277  oC_Port_t port = PORT(Pins);
278  oC_PinsInPort_t pins = PINS(Pins);
279 
280  if(oC_Channel_IsCorrect(GPIO,port))
281  {
282  allDefined = true;
283 
284  for(uint8_t bitIndex = 0; bitIndex < oC_PORT_WIDTH && allDefined; bitIndex++ )
285  {
286  if(pins & (1<<bitIndex))
287  {
288  allDefined = oC_GPIO_LLD_IsPinDefined(oC_Pins_ToSinglePin(Pins,bitIndex));
289  }
290  }
291  }
292 
293  return allDefined;
294 }
295 
296 //==========================================================================================================================================
301 //==========================================================================================================================================
302 bool oC_GPIO_LLD_ArePinsCorrect( oC_Pins_t Pins )
303 {
304  return oC_Channel_IsCorrect(GPIO,PORT(Pins));
305 }
306 
307 //==========================================================================================================================================
312 //==========================================================================================================================================
313 bool oC_GPIO_LLD_IsSinglePin( oC_Pins_t Pins )
314 {
315  bool isSinglePin = false;
316  oC_PinsInPort_t pins = PINS(Pins);
317 
318  for(uint8_t bitIndex = 0; bitIndex < oC_PORT_WIDTH ; bitIndex++)
319  {
320  if(pins & (1<<bitIndex))
321  {
322  isSinglePin = oC_Pins_ToSinglePin(Pins,bitIndex) == Pins;
323  break;
324  }
325  }
326 
327  return isSinglePin;
328 }
329 
330 //==========================================================================================================================================
335 //==========================================================================================================================================
336 oC_Pins_t oC_GPIO_LLD_GetPinsFor( oC_Port_t Port , oC_PinsMask_t Pins )
337 {
338  return oC_Pin_Make(Port,Pins);
339 }
340 
341 //==========================================================================================================================================
346 //==========================================================================================================================================
347 const char * oC_GPIO_LLD_GetPortName( oC_Port_t Port )
348 {
349  return oC_Channel_GetName(Port);
350 }
351 
352 //==========================================================================================================================================
357 //==========================================================================================================================================
358 const char * oC_GPIO_LLD_GetPinName( oC_Pins_t Pin )
359 {
360  const char * name = "<INCORRECT_PIN>";
361  oC_Port_t port = PORT(Pin);
362 
363  if(oC_Channel_IsCorrect(GPIO,port))
364  {
365  name = "<UNDEFINED_PIN>";
366 
367  oC_Pin_ForeachDefined(pinData)
368  {
369  if(pinData->Pin == Pin)
370  {
371  name = pinData->Name;
372  break;
373  }
374  }
375  }
376 
377  return name;
378 }
379 
380 //==========================================================================================================================================
385 //==========================================================================================================================================
386 oC_ErrorCode_t oC_GPIO_LLD_SetDriverInterruptHandler( oC_GPIO_LLD_Interrupt_t Handler )
387 {
388  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
389 
390  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO_LLD))
391  {
392  if(
393  ErrorCondition( IsRam(Handler) || IsRom(Handler), oC_ErrorCode_WrongEventHandlerAddress) &&
394  ErrorCondition( InterruptHandler == NULL, oC_ErrorCode_InterruptHandlerAlreadySet)
395  )
396  {
397  InterruptHandler = Handler;
398  errorCode = oC_ErrorCode_None;
399  }
400  }
401 
402  return errorCode;
403 }
404 
405 //==========================================================================================================================================
410 //==========================================================================================================================================
411 oC_ErrorCode_t oC_GPIO_LLD_BeginConfiguration( oC_Pins_t Pins )
412 {
413  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
414 
415  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO_LLD))
416  {
417  if(
418  ErrorCondition( oC_GPIO_LLD_ArePinsCorrect(Pins) , oC_ErrorCode_WrongChannel) &&
419  ErrorCondition( PINS(Pins) != 0 , oC_ErrorCode_PinNotDefined) &&
420  ErrorCondition( oC_Machine_SetPowerStateForChannel(PORT(Pins),oC_Power_On) , oC_ErrorCode_CannotEnableChannel)
421  )
422  {
423  oC_Machine_RegisterIndirectDynamic(oC_BaseAddress_SystemControl , oC_RegisterOffset_GPIOHBCTL)|=1<<(PORT(Pins)-1);
424  errorCode = oC_ErrorCode_None;
425  }
426  }
427 
428  return errorCode;
429 }
430 
431 //==========================================================================================================================================
436 //==========================================================================================================================================
437 oC_ErrorCode_t oC_GPIO_LLD_FinishConfiguration( oC_Pins_t Pins )
438 {
439  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
440 
441  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO_LLD))
442  {
443  if(
444  ErrorCondition( oC_GPIO_LLD_ArePinsCorrect(Pins), oC_ErrorCode_WrongChannel) &&
445  ErrorCondition( PINS(Pins) != 0, oC_ErrorCode_PinNotDefined)
446  )
447  {
448  errorCode = oC_ErrorCode_None;
449  }
450  }
451 
452  return errorCode;
453 }
454 
455 //==========================================================================================================================================
460 //==========================================================================================================================================
461 oC_ErrorCode_t oC_GPIO_LLD_SetPower( oC_Pins_t Pins , oC_Power_t Power )
462 {
463  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
464 
465  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO_LLD))
466  {
467  if(
468  ErrorCondition( oC_GPIO_LLD_ArePinsCorrect(Pins), oC_ErrorCode_WrongChannel) &&
469  ErrorCondition( PINS(Pins) != 0, oC_ErrorCode_PinNotDefined) &&
470  ErrorCondition( Power == oC_Power_On || Power == oC_Power_Off, oC_ErrorCode_PowerStateNotCorrect)
471  )
472  {
473  if(oC_Machine_SetPowerStateForChannel(PORT(Pins) , Power ))
474  {
475  errorCode = oC_ErrorCode_None;
476  }
477  else
478  {
479  errorCode = oC_ErrorCode_CannotEnableChannel;
480  }
481  }
482  }
483 
484  return errorCode;
485 }
486 
487 //==========================================================================================================================================
492 //==========================================================================================================================================
493 oC_ErrorCode_t oC_GPIO_LLD_ReadPower( oC_Pins_t Pins , oC_Power_t * outPower )
494 {
495  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
496 
497  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO_LLD))
498  {
499  if(
500  ErrorCondition( oC_GPIO_LLD_ArePinsCorrect(Pins), oC_ErrorCode_WrongChannel) &&
501  ErrorCondition( PINS(Pins) != 0, oC_ErrorCode_PinNotDefined) &&
502  ErrorCondition( IsRam(outPower), oC_ErrorCode_OutputAddressNotInRAM)
503  )
504  {
505  oC_Power_t powerState = oC_Machine_GetPowerStateForChannel(PORT(Pins));
506 
507  if (powerState == oC_Power_NotHandled)
508  {
509  *outPower = oC_Power_On;
510  errorCode = oC_ErrorCode_None;
511  }
512  else if (powerState == oC_Power_On || powerState == oC_Power_Off)
513  {
514  *outPower = powerState;
515  errorCode = oC_ErrorCode_None;
516  }
517  else
518  {
519  errorCode = oC_ErrorCode_MachineCanBeDamaged;
520  }
521  }
522  }
523 
524  return errorCode;
525 }
526 
527 //==========================================================================================================================================
532 //==========================================================================================================================================
533 bool oC_GPIO_LLD_IsPinProtected( oC_Pins_t Pins )
534 {
535  bool pinProtected = false;
536 
537  if(oC_Module_IsTurnedOn(oC_Module_GPIO_LLD) && IsPoweredOn(Pins))
538  {
539  pinProtected = (~GPIOCR(Pins)->Value) & PINS(Pins);;
540  }
541 
542  return pinProtected;
543 }
544 
545 //==========================================================================================================================================
550 //==========================================================================================================================================
551 oC_ErrorCode_t oC_GPIO_LLD_UnlockProtection( oC_Pins_t Pins , oC_GPIO_LLD_Protection_t Protection )
552 {
553  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
554 
555  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO_LLD))
556  {
557  if(
558  ErrorCondition( oC_GPIO_LLD_ArePinsCorrect(Pins), oC_ErrorCode_WrongChannel) &&
559  ErrorCondition( PINS(Pins) != 0, oC_ErrorCode_PinNotDefined) &&
560  ErrorCondition( IsPoweredOn(Pins), oC_ErrorCode_ChannelNotPoweredOn) &&
561  ErrorCondition( Protection == oC_GPIO_LLD_Protection_UnlockProtectedPins, oC_ErrorCode_PinNeedUnlock)
562  )
563  {
565  oC_Machine_WriteRegister(PORT(Pins) , GPIOLOCK , oC_MACHINE_GPIO_LOCK_KEY);
566 
567  GPIOCR(Pins)->Value |= PINS(Pins);
568  GPIODEN(Pins)->Value |= PINS(Pins);
569 
570  oC_Machine_WriteRegister(PORT(Pins) , GPIOLOCK , 0);
571 
572  errorCode = oC_ErrorCode_None;
573 
575  }
576  }
577 
578  return errorCode;
579 }
580 
581 //==========================================================================================================================================
586 //==========================================================================================================================================
587 oC_ErrorCode_t oC_GPIO_LLD_LockProtection( oC_Pins_t Pins )
588 {
589  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
590 
591  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO_LLD))
592  {
593  if(
594  ErrorCondition( oC_GPIO_LLD_ArePinsCorrect(Pins), oC_ErrorCode_WrongChannel) &&
595  ErrorCondition( PINS(Pins) != 0, oC_ErrorCode_PinNotDefined) &&
596  ErrorCondition( IsPoweredOn(Pins), oC_ErrorCode_ChannelNotPoweredOn)
597  )
598  {
600 
601  oC_Machine_WriteRegister(PORT(Pins) , GPIOLOCK , oC_MACHINE_GPIO_LOCK_KEY);
602 
603  GPIOCR(Pins)->Value &= ~PINS(Pins);
604  GPIODEN(Pins)->Value &= ~PINS(Pins);
605 
606  oC_Machine_WriteRegister(PORT(Pins) , GPIOLOCK , 0);
607 
608  errorCode = oC_ErrorCode_None;
609 
611  }
612  }
613 
614  return errorCode;
615 }
616 
617 //==========================================================================================================================================
622 //==========================================================================================================================================
623 oC_ErrorCode_t oC_GPIO_LLD_CheckIsPinUnlocked( oC_Pins_t Pins , bool * outPinUnlocked )
624 {
625  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
626 
627  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO_LLD))
628  {
629  if(
630  ErrorCondition( oC_GPIO_LLD_ArePinsCorrect(Pins), oC_ErrorCode_WrongChannel) &&
631  ErrorCondition( PINS(Pins) != 0, oC_ErrorCode_PinNotDefined) &&
632  ErrorCondition( IsPoweredOn(Pins), oC_ErrorCode_ChannelNotPoweredOn) &&
633  ErrorCondition( IsRam(outPinUnlocked), oC_ErrorCode_OutputAddressNotInRAM)
634  )
635  {
637 
638  oC_Machine_WriteRegister(PORT(Pins) , GPIOLOCK , oC_MACHINE_GPIO_LOCK_KEY);
639 
640  *outPinUnlocked = (GPIOCR(Pins)->Value & PINS(Pins)) == PINS(Pins);
641 
642  oC_Machine_WriteRegister(PORT(Pins) , GPIOLOCK , 0);
643 
644  errorCode = oC_ErrorCode_None;
645 
647  }
648 }
649 
650 return errorCode;
651 }
652 
653 //==========================================================================================================================================
658 //==========================================================================================================================================
659 oC_ErrorCode_t oC_GPIO_LLD_SetSpeed( oC_Pins_t Pins , oC_GPIO_LLD_Speed_t Speed )
660 {
661  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
662 
663  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO_LLD))
664  {
665  if(
666  ErrorCondition( oC_GPIO_LLD_ArePinsCorrect(Pins), oC_ErrorCode_WrongChannel ) &&
667  ErrorCondition( PINS(Pins) != 0, oC_ErrorCode_PinNotDefined ) &&
668  ErrorCondition( IsPoweredOn(Pins), oC_ErrorCode_ChannelNotPoweredOn ) &&
669  ErrorCondition( Speed == oC_GPIO_LLD_Speed_Default, oC_ErrorCode_NotSupportedOnTargetMachine)
670  )
671  {
672  errorCode = oC_ErrorCode_None;
673  }
674  }
675 
676  return errorCode;
677 }
678 
679 //==========================================================================================================================================
684 //==========================================================================================================================================
685 oC_ErrorCode_t oC_GPIO_LLD_ReadSpeed( oC_Pins_t Pins , oC_GPIO_LLD_Speed_t * outSpeed )
686 {
687  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
688 
689  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO_LLD))
690  {
691  if(
692  ErrorCondition( oC_GPIO_LLD_ArePinsCorrect(Pins), oC_ErrorCode_WrongChannel) &&
693  ErrorCondition( PINS(Pins) != 0, oC_ErrorCode_PinNotDefined) &&
694  ErrorCondition( IsPoweredOn(Pins), oC_ErrorCode_ChannelNotPoweredOn) &&
695  ErrorCondition( IsRam(outSpeed), oC_ErrorCode_OutputAddressNotInRAM)
696  )
697  {
698  *outSpeed = oC_GPIO_LLD_Speed_Maximum;
699  errorCode = oC_ErrorCode_None;
700  }
701 
702  }
703 
704  return errorCode;
705 }
706 
707 //==========================================================================================================================================
712 //==========================================================================================================================================
713 oC_ErrorCode_t oC_GPIO_LLD_SetCurrent( oC_Pins_t Pins , oC_GPIO_LLD_Current_t Current )
714 {
715  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
716 
717  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO_LLD))
718  {
719  if(
720  ErrorCondition( oC_GPIO_LLD_ArePinsCorrect(Pins), oC_ErrorCode_WrongChannel) &&
721  ErrorCondition( PINS(Pins) != 0, oC_ErrorCode_PinNotDefined) &&
722  ErrorCondition( IsPoweredOn(Pins), oC_ErrorCode_ChannelNotPoweredOn)
723  )
724  {
725  errorCode = oC_ErrorCode_None;
726 
727  switch(Current)
728  {
729  case oC_GPIO_LLD_Current_Default:
730  case oC_GPIO_LLD_Current_Minimum:
731  GPIODR2R(Pins)->Value |= PINS(Pins);
732  break;
733  case oC_GPIO_LLD_Current_Medium:
734  GPIODR4R(Pins)->Value |= PINS(Pins);
735  break;
736  case oC_GPIO_LLD_Current_Maximum:
737  GPIODR8R(Pins)->Value |= PINS(Pins);
738  break;
739  default:
740  errorCode = oC_ErrorCode_GPIOCurrentNotCorrect;
741  break;
742  }
743  }
744  }
745 
746  return errorCode;
747 }
748 
749 //==========================================================================================================================================
754 //==========================================================================================================================================
755 oC_ErrorCode_t oC_GPIO_LLD_ReadCurrent( oC_Pins_t Pins , oC_GPIO_LLD_Current_t * outCurrent )
756 {
757  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
758 
759  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO_LLD))
760  {
761  if(
762  ErrorCondition( oC_GPIO_LLD_ArePinsCorrect(Pins), oC_ErrorCode_WrongChannel) &&
763  ErrorCondition( PINS(Pins) != 0, oC_ErrorCode_PinNotDefined) &&
764  ErrorCondition( IsPoweredOn(Pins), oC_ErrorCode_ChannelNotPoweredOn) &&
765  ErrorCondition( IsRam(outCurrent), oC_ErrorCode_OutputAddressNotInRAM)
766  )
767  {
768  errorCode = oC_ErrorCode_None;
769 
770  if(GPIODR2R(Pins)->Value & PINS(Pins))
771  {
772  *outCurrent = oC_GPIO_LLD_Current_Minimum;
773  }
774  else if(GPIODR4R(Pins)->Value & PINS(Pins))
775  {
776  *outCurrent = oC_GPIO_LLD_Current_Medium;
777  }
778  else if(GPIODR4R(Pins)->Value & PINS(Pins))
779  {
780  *outCurrent = oC_GPIO_LLD_Current_Maximum;
781  }
782  else
783  {
784  errorCode = oC_ErrorCode_MachineCanBeDamaged;
785  }
786  }
787  }
788 
789  return errorCode;
790 }
791 
792 //==========================================================================================================================================
797 //==========================================================================================================================================
798 oC_ErrorCode_t oC_GPIO_LLD_SetMode( oC_Pins_t Pins , oC_GPIO_LLD_Mode_t Mode )
799 {
800  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
801 
802  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO_LLD))
803  {
804  if(
805  ErrorCondition( oC_GPIO_LLD_ArePinsCorrect(Pins), oC_ErrorCode_WrongChannel) &&
806  ErrorCondition( PINS(Pins) != 0, oC_ErrorCode_PinNotDefined) &&
807  ErrorCondition( IsPoweredOn(Pins), oC_ErrorCode_ChannelNotPoweredOn)
808  )
809  {
811  errorCode = oC_ErrorCode_None;
812 
813  switch(Mode)
814  {
815  case oC_GPIO_LLD_Mode_Output:
816  oC_Bits_SetBitsU32( (oC_uint32_t*)&GPIODIR(Pins)->Value , PINS(Pins));
817  oC_Bits_ClearBitsU32( (oC_uint32_t*)&GPIOAFSEL(Pins)->Value , PINS(Pins));
818  oC_Bits_SetBitsU32( (oC_uint32_t*)&GPIODEN(Pins)->Value , PINS(Pins));
819  break;
820  case oC_GPIO_LLD_Mode_Default:
821  case oC_GPIO_LLD_Mode_Input:
822  oC_Bits_ClearBitsU32( (oC_uint32_t*)&GPIODIR(Pins)->Value , PINS(Pins));
823  oC_Bits_ClearBitsU32( (oC_uint32_t*)&GPIOAFSEL(Pins)->Value , PINS(Pins));
824  oC_Bits_SetBitsU32( (oC_uint32_t*)&GPIODEN(Pins)->Value , PINS(Pins));
825  break;
826  case oC_GPIO_LLD_Mode_Alternate:
827  oC_Bits_SetBitsU32( (oC_uint32_t*)&GPIOAFSEL(Pins)->Value , PINS(Pins) );
828  oC_Bits_SetBitsU32( (oC_uint32_t*)&GPIODEN(Pins)->Value , PINS(Pins) );
829  break;
830  default:
831  errorCode = oC_ErrorCode_GPIOModeNotCorrect;
832  break;
833  }
834 
836  }
837  }
838 
839  return errorCode;
840 }
841 
842 //==========================================================================================================================================
847 //==========================================================================================================================================
848 oC_ErrorCode_t oC_GPIO_LLD_ReadMode( oC_Pins_t Pins , oC_GPIO_LLD_Mode_t * outMode )
849 {
850  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
851 
852  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO_LLD))
853  {
854  if(
855  ErrorCondition( oC_GPIO_LLD_ArePinsCorrect(Pins), oC_ErrorCode_WrongChannel) &&
856  ErrorCondition( PINS(Pins) != 0, oC_ErrorCode_PinNotDefined) &&
857  ErrorCondition( IsPoweredOn(Pins), oC_ErrorCode_ChannelNotPoweredOn) &&
858  ErrorCondition( IsRam(outMode), oC_ErrorCode_OutputAddressNotInRAM)
859  )
860  {
862  errorCode = oC_ErrorCode_None;
863 
864  if(
865  oC_Bits_IsAtLeastOneBitSetU32( GPIODIR(Pins)->Value , PINS(Pins)) &&
866  oC_Bits_IsAtLeastOneBitClearU32( GPIOAFSEL(Pins)->Value , PINS(Pins))
867  )
868  {
869  *outMode = oC_GPIO_LLD_Mode_Output;
870  }
871  else if(
872  oC_Bits_IsAtLeastOneBitClearU32( GPIODIR(Pins)->Value , PINS(Pins)) &&
873  oC_Bits_IsAtLeastOneBitClearU32( GPIOAFSEL(Pins)->Value , PINS(Pins))
874  )
875  {
876  *outMode = oC_GPIO_LLD_Mode_Input;
877  }
878  else if(
879  oC_Bits_IsAtLeastOneBitSetU32( GPIODEN(Pins)->Value , PINS(Pins)) &&
880  oC_Bits_IsAtLeastOneBitSetU32( GPIOAFSEL(Pins)->Value , PINS(Pins))
881  )
882  {
883  *outMode = oC_GPIO_LLD_Mode_Alternate;
884  }
885  else
886  {
887  errorCode = oC_ErrorCode_MachineCanBeDamaged;
888  }
889 
891  }
892  }
893 
894  return errorCode;
895 }
896 
897 //==========================================================================================================================================
902 //==========================================================================================================================================
903 oC_ErrorCode_t oC_GPIO_LLD_SetPull( oC_Pins_t Pins , oC_GPIO_LLD_Pull_t Pull )
904 {
905  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
906 
907  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO_LLD))
908  {
909  if(
910  ErrorCondition( oC_GPIO_LLD_ArePinsCorrect(Pins), oC_ErrorCode_WrongChannel) &&
911  ErrorCondition( PINS(Pins) != 0, oC_ErrorCode_PinNotDefined) &&
912  ErrorCondition( IsPoweredOn(Pins), oC_ErrorCode_ChannelNotPoweredOn)
913  )
914  {
916  errorCode = oC_ErrorCode_None;
917 
918  switch(Pull)
919  {
920  case oC_GPIO_LLD_Pull_Default:
921  oC_Bits_ClearBitsU32( (oC_uint32_t*)&GPIOAFSEL(Pins)->Value , PINS(Pins));
922  oC_Bits_ClearBitsU32( (oC_uint32_t*)&GPIODEN(Pins)->Value , PINS(Pins));
923  oC_Bits_ClearBitsU32( (oC_uint32_t*)&GPIOPDR(Pins)->Value , PINS(Pins));
924  oC_Bits_ClearBitsU32( (oC_uint32_t*)&GPIOPUR(Pins)->Value , PINS(Pins));
925  break;
926  case oC_GPIO_LLD_Pull_Up:
927  oC_Bits_SetBitsU32( (oC_uint32_t*)&GPIOPUR(Pins)->Value , PINS(Pins));
928  break;
929  case oC_GPIO_LLD_Pull_Down:
930  oC_Bits_SetBitsU32( (oC_uint32_t*)&GPIOPDR(Pins)->Value , PINS(Pins));
931  break;
932  default:
933  errorCode = oC_ErrorCode_PullNotCorrect;
934  break;
935  }
936 
938 
939  }
940  }
941 
942  return errorCode;
943 }
944 
945 //==========================================================================================================================================
950 //==========================================================================================================================================
951 oC_ErrorCode_t oC_GPIO_LLD_ReadPull( oC_Pins_t Pins , oC_GPIO_LLD_Pull_t * outPull )
952 {
953  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
954 
955  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO_LLD))
956  {
957  if(
958  ErrorCondition( oC_GPIO_LLD_ArePinsCorrect(Pins), oC_ErrorCode_WrongChannel) &&
959  ErrorCondition( PINS(Pins) != 0, oC_ErrorCode_PinNotDefined) &&
960  ErrorCondition( IsPoweredOn(Pins), oC_ErrorCode_ChannelNotPoweredOn) &&
961  ErrorCondition( IsRam(outPull), oC_ErrorCode_OutputAddressNotInRAM)
962  )
963  {
965 
966  errorCode = oC_ErrorCode_None;
967 
968  if(
969  oC_Bits_IsAtLeastOneBitSetU32( GPIOPUR(Pins)->Value , PINS(Pins))
970  )
971  {
972  *outPull = oC_GPIO_LLD_Pull_Up;
973  }
974  else if(
975  oC_Bits_IsAtLeastOneBitSetU32( GPIOPDR(Pins)->Value , PINS(Pins))
976  )
977  {
978  *outPull = oC_GPIO_LLD_Pull_Down;
979  }
980  else
981  {
982  errorCode = oC_ErrorCode_MachineCanBeDamaged;
983  }
984 
986  }
987  }
988 
989  return errorCode;
990 }
991 
992 //==========================================================================================================================================
997 //==========================================================================================================================================
998 oC_ErrorCode_t oC_GPIO_LLD_SetOutputCircuit( oC_Pins_t Pins , oC_GPIO_LLD_OutputCircuit_t OutputCircuit )
999 {
1000  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1001 
1002  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO_LLD))
1003  {
1004  if(
1005  ErrorCondition( oC_GPIO_LLD_ArePinsCorrect(Pins), oC_ErrorCode_WrongChannel) &&
1006  ErrorCondition( PINS(Pins) != 0, oC_ErrorCode_PinNotDefined) &&
1007  ErrorCondition( IsPoweredOn(Pins), oC_ErrorCode_ChannelNotPoweredOn)
1008  )
1009  {
1011  errorCode = oC_ErrorCode_None;
1012 
1013  switch(OutputCircuit)
1014  {
1015  case oC_GPIO_LLD_OutputCircuit_Default:
1016  case oC_GPIO_LLD_OutputCircuit_PushPull:
1017  oC_Bits_ClearBitsU32( (oC_uint32_t*)&GPIOODR(Pins)->Value , PINS(Pins));
1018  break;
1019  case oC_GPIO_LLD_OutputCircuit_OpenDrain:
1020  oC_Bits_SetBitsU32( (oC_uint32_t*)&GPIOODR(Pins)->Value , PINS(Pins));
1021  break;
1022  default:
1023  errorCode = oC_ErrorCode_OutputCircuitNotCorrect;
1024  break;
1025  }
1027  }
1028  }
1029 
1030  return errorCode;
1031 }
1032 
1033 //==========================================================================================================================================
1038 //==========================================================================================================================================
1039 oC_ErrorCode_t oC_GPIO_LLD_ReadOutputCircuit( oC_Pins_t Pins , oC_GPIO_LLD_OutputCircuit_t * outOutputCircuit )
1040 {
1041  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1042 
1043  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO_LLD))
1044  {
1045  if(
1046  ErrorCondition( oC_GPIO_LLD_ArePinsCorrect(Pins), oC_ErrorCode_WrongChannel) &&
1047  ErrorCondition( PINS(Pins) != 0, oC_ErrorCode_PinNotDefined) &&
1048  ErrorCondition( IsPoweredOn(Pins), oC_ErrorCode_ChannelNotPoweredOn) &&
1049  ErrorCondition( IsRam(outOutputCircuit), oC_ErrorCode_OutputAddressNotInRAM)
1050  )
1051  {
1053  errorCode = oC_ErrorCode_None;
1054 
1055  if(
1056  oC_Bits_IsAtLeastOneBitClearU32( GPIOODR(Pins)->Value , PINS(Pins))
1057  )
1058  {
1059  *outOutputCircuit = oC_GPIO_LLD_OutputCircuit_PushPull;
1060  }
1061  else if(
1062  oC_Bits_IsAtLeastOneBitSetU32( GPIOODR(Pins)->Value , PINS(Pins))
1063  )
1064  {
1065  *outOutputCircuit = oC_GPIO_LLD_OutputCircuit_OpenDrain;
1066  }
1067  else
1068  {
1069  errorCode = oC_ErrorCode_MachineCanBeDamaged;
1070  }
1072  }
1073  }
1074 
1075  return errorCode;
1076 }
1077 
1078 //==========================================================================================================================================
1083 //==========================================================================================================================================
1084 oC_ErrorCode_t oC_GPIO_LLD_SetInterruptTrigger( oC_Pins_t Pins , oC_GPIO_LLD_IntTrigger_t InterruptTrigger )
1085 {
1086  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1087 
1088  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO_LLD))
1089  {
1090  if(
1091  ErrorCondition( oC_GPIO_LLD_ArePinsCorrect(Pins), oC_ErrorCode_WrongChannel) &&
1092  ErrorCondition( PINS(Pins) != 0, oC_ErrorCode_PinNotDefined) &&
1093  ErrorCondition( IsPoweredOn(Pins), oC_ErrorCode_ChannelNotPoweredOn) &&
1094  ErrorCondition( InterruptTrigger == oC_GPIO_LLD_IntTrigger_Off, oC_ErrorCode_NotSupportedOnTargetMachine)
1095  )
1096  {
1098  errorCode = oC_ErrorCode_None;
1099 
1100  switch(InterruptTrigger)
1101  {
1102  case oC_GPIO_LLD_IntTrigger_Off:
1103  oC_Bits_ClearBitsU32( (oC_uint32_t*)&GPIOIM(Pins)->Value , PINS(Pins));
1104  break;
1105  case oC_GPIO_LLD_IntTrigger_BothEdges:
1106  oC_Channel_EnableInterrupt(PORT(Pins) , PeripheralInterrupt);
1107  oC_Bits_SetBitsU32( (oC_uint32_t*)&GPIOIM(Pins)->Value , PINS(Pins));
1108 
1109  oC_Bits_ClearBitsU32( (oC_uint32_t*)&GPIOIS(Pins)->Value , PINS(Pins));
1110  oC_Bits_SetBitsU32( (oC_uint32_t*)&GPIOIBE(Pins)->Value , PINS(Pins));
1111 
1112  break;
1113 
1114  case oC_GPIO_LLD_IntTrigger_BothLevels:
1115  oC_Channel_EnableInterrupt(PORT(Pins) , PeripheralInterrupt);
1116  oC_Bits_SetBitsU32( (oC_uint32_t*)&GPIOIM(Pins)->Value , PINS(Pins));
1117 
1118  oC_Bits_SetBitsU32( (oC_uint32_t*)&GPIOIS(Pins)->Value , PINS(Pins));
1119  oC_Bits_SetBitsU32( (oC_uint32_t*)&GPIOIBE(Pins)->Value , PINS(Pins));
1120 
1121  break;
1122  case oC_GPIO_LLD_IntTrigger_FallingEdge:
1123  oC_Channel_EnableInterrupt(PORT(Pins) , PeripheralInterrupt);
1124  oC_Bits_SetBitsU32( (oC_uint32_t*)&GPIOIM(Pins)->Value , PINS(Pins));
1125 
1126  oC_Bits_ClearBitsU32( (oC_uint32_t*)&GPIOIS(Pins)->Value , PINS(Pins));
1127  oC_Bits_ClearBitsU32( (oC_uint32_t*)&GPIOIBE(Pins)->Value , PINS(Pins));
1128  oC_Bits_ClearBitsU32( (oC_uint32_t*)&GPIOIEV(Pins)->Value , PINS(Pins));
1129 
1130  break;
1131 
1132  case oC_GPIO_LLD_IntTrigger_RisingEdge:
1133  oC_Channel_EnableInterrupt(PORT(Pins) , PeripheralInterrupt);
1134  oC_Bits_SetBitsU32( (oC_uint32_t*)&GPIOIM(Pins)->Value , PINS(Pins));
1135 
1136  oC_Bits_ClearBitsU32( (oC_uint32_t*)&GPIOIS(Pins)->Value , PINS(Pins));
1137  oC_Bits_ClearBitsU32( (oC_uint32_t*)&GPIOIBE(Pins)->Value , PINS(Pins));
1138  oC_Bits_SetBitsU32( (oC_uint32_t*)&GPIOIEV(Pins)->Value , PINS(Pins));
1139 
1140  break;
1141  case oC_GPIO_LLD_IntTrigger_HighLevel:
1142  oC_Channel_EnableInterrupt(PORT(Pins) , PeripheralInterrupt);
1143  oC_Bits_SetBitsU32( (oC_uint32_t*)&GPIOIM(Pins)->Value , PINS(Pins));
1144 
1145  oC_Bits_SetBitsU32( (oC_uint32_t*)&GPIOIS(Pins)->Value , PINS(Pins));
1146  oC_Bits_ClearBitsU32( (oC_uint32_t*)&GPIOIBE(Pins)->Value , PINS(Pins));
1147  oC_Bits_SetBitsU32( (oC_uint32_t*)&GPIOIEV(Pins)->Value , PINS(Pins));
1148 
1149  break;
1150  case oC_GPIO_LLD_IntTrigger_LowLevel:
1151  oC_Channel_EnableInterrupt(PORT(Pins) , PeripheralInterrupt);
1152  oC_Bits_SetBitsU32( (oC_uint32_t*)&GPIOIM(Pins)->Value , PINS(Pins));
1153 
1154  oC_Bits_SetBitsU32( (oC_uint32_t*)&GPIOIS(Pins)->Value , PINS(Pins));
1155  oC_Bits_ClearBitsU32( (oC_uint32_t*)&GPIOIBE(Pins)->Value , PINS(Pins));
1156  oC_Bits_ClearBitsU32( (oC_uint32_t*)&GPIOIEV(Pins)->Value , PINS(Pins));
1157 
1158  break;
1159  default:
1160  errorCode = oC_ErrorCode_GPIOIntTriggerNotCorrect;
1161  break;
1162  }
1164  }
1165  }
1166 
1167  return errorCode;
1168 }
1169 
1170 //==========================================================================================================================================
1175 //==========================================================================================================================================
1176 oC_ErrorCode_t oC_GPIO_LLD_ReadInterruptTrigger( oC_Pins_t Pins , oC_GPIO_LLD_IntTrigger_t * outInterruptTrigger )
1177 {
1178  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1179 
1180  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO_LLD))
1181  {
1183  if(
1184  ErrorCondition( oC_GPIO_LLD_ArePinsCorrect(Pins), oC_ErrorCode_WrongChannel) &&
1185  ErrorCondition( PINS(Pins) != 0, oC_ErrorCode_PinNotDefined) &&
1186  ErrorCondition( IsPoweredOn(Pins), oC_ErrorCode_ChannelNotPoweredOn) &&
1187  ErrorCondition( IsRam(outInterruptTrigger), oC_ErrorCode_OutputAddressNotInRAM)
1188  )
1189  {
1190  errorCode = oC_ErrorCode_None;
1191  if(
1192  oC_Bits_IsAtLeastOneBitClearU32( GPIOIM(Pins)->Value , PINS(Pins)) ||
1193  (oC_Channel_IsInterruptEnabled( PORT(Pins) , PeripheralInterrupt ) == false)
1194  )
1195  {
1196  *outInterruptTrigger = oC_GPIO_LLD_IntTrigger_Off;
1197  }
1198  else if(
1199  oC_Bits_IsAtLeastOneBitClearU32( GPIOIS(Pins)->Value , PINS(Pins)) &&
1200  oC_Bits_IsAtLeastOneBitSetU32( GPIOIBE(Pins)->Value , PINS(Pins))
1201  )
1202  {
1203  *outInterruptTrigger = oC_GPIO_LLD_IntTrigger_BothEdges;
1204  }
1205  else if(
1206  oC_Bits_IsAtLeastOneBitSetU32( GPIOIS(Pins)->Value , PINS(Pins)) &&
1207  oC_Bits_IsAtLeastOneBitSetU32( GPIOIBE(Pins)->Value , PINS(Pins))
1208  )
1209  {
1210  *outInterruptTrigger = oC_GPIO_LLD_IntTrigger_BothLevels;
1211  }
1212  else if(
1213  oC_Bits_IsAtLeastOneBitClearU32( GPIOIS(Pins)->Value , PINS(Pins)) &&
1214  oC_Bits_IsAtLeastOneBitClearU32( GPIOIBE(Pins)->Value , PINS(Pins)) &&
1215  oC_Bits_IsAtLeastOneBitClearU32( GPIOIEV(Pins)->Value , PINS(Pins))
1216  )
1217  {
1218  *outInterruptTrigger = oC_GPIO_LLD_IntTrigger_FallingEdge;
1219  }
1220  else if(
1221  oC_Bits_IsAtLeastOneBitClearU32( GPIOIS(Pins)->Value , PINS(Pins)) &&
1222  oC_Bits_IsAtLeastOneBitClearU32( GPIOIBE(Pins)->Value , PINS(Pins)) &&
1223  oC_Bits_IsAtLeastOneBitSetU32( GPIOIEV(Pins)->Value , PINS(Pins))
1224  )
1225  {
1226  *outInterruptTrigger = oC_GPIO_LLD_IntTrigger_RisingEdge;
1227  }
1228  else if(
1229  oC_Bits_IsAtLeastOneBitSetU32( GPIOIS(Pins)->Value , PINS(Pins)) &&
1230  oC_Bits_IsAtLeastOneBitClearU32( GPIOIBE(Pins)->Value , PINS(Pins)) &&
1231  oC_Bits_IsAtLeastOneBitSetU32( GPIOIEV(Pins)->Value , PINS(Pins))
1232  )
1233  {
1234  *outInterruptTrigger = oC_GPIO_LLD_IntTrigger_HighLevel;
1235  }
1236  else if(
1237  oC_Bits_IsAtLeastOneBitSetU32( GPIOIS(Pins)->Value , PINS(Pins)) &&
1238  oC_Bits_IsAtLeastOneBitClearU32( GPIOIBE(Pins)->Value , PINS(Pins)) &&
1239  oC_Bits_IsAtLeastOneBitClearU32( GPIOIEV(Pins)->Value , PINS(Pins))
1240  )
1241  {
1242  *outInterruptTrigger = oC_GPIO_LLD_IntTrigger_LowLevel;
1243  }
1244  else
1245  {
1246  errorCode = oC_ErrorCode_MachineCanBeDamaged;
1247  }
1249  }
1250  }
1251 
1252  return errorCode;
1253 }
1254 
1255 //==========================================================================================================================================
1260 //==========================================================================================================================================
1261 oC_ErrorCode_t oC_GPIO_LLD_SetPinsUsed( oC_Pins_t Pins )
1262 {
1263  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1264 
1265  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO_LLD))
1266  {
1268  if(
1269  ErrorCondition( oC_GPIO_LLD_ArePinsCorrect(Pins), oC_ErrorCode_WrongChannel) &&
1270  ErrorCondition( PINS(Pins) != 0, oC_ErrorCode_PinNotDefined)
1271  )
1272  {
1273  oC_Bits_SetBitsU8(&UsedPinsArray[PORT_INDEX(Pins)] , PINS(Pins));
1274  errorCode = oC_ErrorCode_None;
1275  }
1277  }
1278 
1279  return errorCode;
1280 }
1281 
1282 //==========================================================================================================================================
1287 //==========================================================================================================================================
1288 oC_ErrorCode_t oC_GPIO_LLD_SetPinsUnused( oC_Pins_t Pins )
1289 {
1290  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1291 
1292  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO_LLD))
1293  {
1295  if(
1296  ErrorCondition( oC_GPIO_LLD_ArePinsCorrect(Pins), oC_ErrorCode_WrongChannel) &&
1297  ErrorCondition( PINS(Pins) != 0, oC_ErrorCode_PinNotDefined)
1298  )
1299  {
1300  oC_Bits_ClearBitsU8(&UsedPinsArray[PORT_INDEX(Pins)] , PINS(Pins));
1301  errorCode = oC_ErrorCode_None;
1302  }
1304  }
1305 
1306  return errorCode;
1307 }
1308 
1309 //==========================================================================================================================================
1314 //==========================================================================================================================================
1315 oC_ErrorCode_t oC_GPIO_LLD_CheckIsPinUsed( oC_Pins_t Pins , bool * outPinUsed )
1316 {
1317  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1318 
1319  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO_LLD))
1320  {
1322  if(
1323  ErrorCondition( oC_GPIO_LLD_ArePinsCorrect(Pins), oC_ErrorCode_WrongChannel) &&
1324  ErrorCondition( PINS(Pins) != 0, oC_ErrorCode_PinNotDefined) &&
1325  ErrorCondition( oC_GPIO_LLD_IsSinglePin(Pins), oC_ErrorCode_NotSinglePin) &&
1326  ErrorCondition( IsRam(outPinUsed), oC_ErrorCode_OutputAddressNotInRAM)
1327 
1328  )
1329  {
1330  *outPinUsed = oC_Bits_AreBitsSetU32(UsedPinsArray[PORT_INDEX(Pins)] , PINS(Pins));
1331  errorCode = oC_ErrorCode_None;
1332  }
1334  }
1335 
1336  return errorCode;
1337 }
1338 
1339 //==========================================================================================================================================
1344 //==========================================================================================================================================
1345 oC_ErrorCode_t oC_GPIO_LLD_ArePinsUnused( oC_Pins_t Pins , bool * outPinsUnused )
1346 {
1347  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1348 
1349  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO_LLD))
1350  {
1352  if(
1353  ErrorCondition( oC_GPIO_LLD_ArePinsCorrect(Pins), oC_ErrorCode_WrongChannel) &&
1354  ErrorCondition( PINS(Pins) != 0, oC_ErrorCode_PinNotDefined) &&
1355  ErrorCondition( IsRam(outPinsUnused), oC_ErrorCode_OutputAddressNotInRAM)
1356  )
1357  {
1358  *outPinsUnused = oC_Bits_AreBitsClearU32(UsedPinsArray[PORT_INDEX(Pins)] , PINS(Pins));
1359  errorCode = oC_ErrorCode_None;
1360  }
1362  }
1363 
1364  return errorCode;
1365 }
1366 
1367 //=========================================================================================================================================
1372 //==========================================================================================================================================
1373 oC_ErrorCode_t oC_GPIO_LLD_WriteData( oC_Pins_t Pins , oC_PinsMask_t Data )
1374 {
1375  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1376 
1377  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO_LLD))
1378  {
1380  if(
1381  ErrorCondition( oC_GPIO_LLD_ArePinsCorrect(Pins), oC_ErrorCode_WrongChannel) &&
1382  ErrorCondition( IsPoweredOn(Pins), oC_ErrorCode_ChannelNotPoweredOn) &&
1383  ErrorCondition( PINS(Pins) != 0, oC_ErrorCode_PinNotDefined)
1384  )
1385  {
1386  GPIODATA(Pins)->Value &= ~PINS(Pins);
1387  GPIODATA(Pins)->Value |= Data & PINS(Pins);
1388  errorCode = oC_ErrorCode_None;
1389  }
1391  }
1392 
1393  return errorCode;
1394 }
1395 
1396 //==========================================================================================================================================
1401 //==========================================================================================================================================
1402 oC_ErrorCode_t oC_GPIO_LLD_ReadData( oC_Pins_t Pins , oC_PinsMask_t * outData )
1403 {
1404  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1405 
1406  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO_LLD))
1407  {
1409  if(
1410  ErrorCondition( oC_GPIO_LLD_ArePinsCorrect(Pins), oC_ErrorCode_WrongChannel) &&
1411  ErrorCondition( IsPoweredOn(Pins), oC_ErrorCode_ChannelNotPoweredOn) &&
1412  ErrorCondition( PINS(Pins) != 0, oC_ErrorCode_PinNotDefined) &&
1413  ErrorCondition( IsRam(outData), oC_ErrorCode_OutputAddressNotInRAM)
1414  )
1415  {
1416  *outData = GPIODATA(Pins)->Value & PINS(Pins);
1417  errorCode = oC_ErrorCode_None;
1418  }
1420  }
1421 
1422  return errorCode;
1423 }
1424 
1425 //==========================================================================================================================================
1430 //==========================================================================================================================================
1431 oC_ErrorCode_t oC_GPIO_LLD_ReadDataReference( oC_Pins_t Pins , oC_UInt_t ** outDataReference )
1432 {
1433  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1434 
1435  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO_LLD))
1436  {
1438  if(
1439  ErrorCondition( oC_GPIO_LLD_ArePinsCorrect(Pins), oC_ErrorCode_WrongChannel) &&
1440  ErrorCondition( IsPoweredOn(Pins), oC_ErrorCode_ChannelNotPoweredOn) &&
1441  ErrorCondition( PINS(Pins) != 0, oC_ErrorCode_PinNotDefined) &&
1442  ErrorCondition( IsRam(outDataReference), oC_ErrorCode_OutputAddressNotInRAM)
1443  )
1444  {
1445  *outDataReference = (oC_UInt_t*)&GPIODATA(Pins)->Value;
1446  errorCode = oC_ErrorCode_None;
1447  }
1449  }
1450 
1451  return errorCode;
1452 }
1453 
1454 //==========================================================================================================================================
1459 //==========================================================================================================================================
1460 oC_Pins_t oC_GPIO_LLD_GetHighStatePins( oC_Pins_t Pins )
1461 {
1462  return oC_GPIO_LLD_GetPinsFor(PORT(Pins) , (oC_PinsMask_t)(GPIODATA(Pins)->Value & Pins));
1463 }
1464 
1465 //==========================================================================================================================================
1470 //==========================================================================================================================================
1471 oC_Pins_t oC_GPIO_LLD_GetLowStatePins( oC_Pins_t Pins )
1472 {
1473  return oC_GPIO_LLD_GetPinsFor(PORT(Pins) , (oC_PinsMask_t)(~GPIODATA(Pins)->Value) & Pins);
1474 }
1475 
1476 //==========================================================================================================================================
1481 //==========================================================================================================================================
1482 bool oC_GPIO_LLD_IsPinsState( oC_Pins_t Pins , oC_GPIO_LLD_PinsState_t ExpectedPinsState )
1483 {
1484  return (GPIODATA(Pins)->Value & PINS(Pins)) == (ExpectedPinsState & PINS(Pins));
1485 }
1486 
1487 //==========================================================================================================================================
1492 //==========================================================================================================================================
1493 void oC_GPIO_LLD_SetPinsState( oC_Pins_t Pins , oC_GPIO_LLD_PinsState_t PinsState )
1494 {
1495  GPIODATA(Pins)->Value = (GPIODATA(Pins)->Value & (~PINS(Pins))) | (PinsState & PINS(Pins) );
1496 }
1497 
1498 //==========================================================================================================================================
1503 //==========================================================================================================================================
1504 void oC_GPIO_LLD_TogglePinsState( oC_Pins_t Pins )
1505 {
1506  GPIODATA(Pins)->Value ^= PINS(Pins);
1507 }
1508 
1509 
1510 #undef _________________________________________INTERFACE_FUNCTIONS_SECTION_______________________________________________________________
1511 
1517 #define _________________________________________MSLLD_INTERFACE_FUNCTIONS_SECTION__________________________________________________________
1518 
1519 //==========================================================================================================================================
1524 //==========================================================================================================================================
1525 oC_ErrorCode_t oC_GPIO_MSLLD_SetAlternateNumber( oC_Pin_t Pin , oC_PinAlternateNumber_t Function )
1526 {
1527  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1528 
1529  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO_LLD))
1530  {
1531  if(
1532  ErrorCondition(oC_GPIO_LLD_IsSinglePin(Pin) , oC_ErrorCode_NotSinglePin) &&
1533  ErrorCondition(oC_GPIO_LLD_IsPinDefined(Pin) , oC_ErrorCode_PinNotDefined) &&
1534  ErrorCondition( IsPoweredOn(Pin), oC_ErrorCode_ChannelNotPoweredOn) &&
1535  ErrorCondition(Function <= oC_PinAlternateNumberMask , oC_ErrorCode_ValueTooBig)
1536  )
1537 
1538  {
1539  oC_PinsMask_t pinIndex = oC_Bits_GetBitNumberU32(PINS(Pin));
1540 
1542 
1543  oC_Bits_SetValueU32((oC_uint32_t*)&GPIOPCTL(Pin)->Value , Function , (pinIndex*4) , ((pinIndex+1)*4) - 1);
1544 
1546 
1547  errorCode = oC_ErrorCode_None;
1548  }
1549  }
1550 
1551 
1552  return errorCode;
1553 }
1554 
1555 //==========================================================================================================================================
1560 //==========================================================================================================================================
1561 oC_ErrorCode_t oC_GPIO_MSLLD_ConnectPin( oC_Pin_t Pin , oC_PinAlternateNumber_t Function )
1562 {
1563  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1564 
1565  if(oC_Module_TurnOnVerification(&errorCode , oC_Module_GPIO_LLD))
1566  {
1568  if(
1569  ErrorCondition(oC_GPIO_LLD_IsSinglePin(Pin) , oC_ErrorCode_NotSinglePin) &&
1570  ErrorCondition(oC_GPIO_LLD_IsPinDefined(Pin) , oC_ErrorCode_PinNotDefined) &&
1571  ErrorCondition(Function <= oC_PinAlternateNumberMask , oC_ErrorCode_ValueTooBig)
1572  )
1573  {
1574 
1575  if(
1576  oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_BeginConfiguration(Pin)) &&
1577  oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_SetMode(Pin , oC_GPIO_LLD_Mode_Alternate)) &&
1578  oC_AssignErrorCode(&errorCode , oC_GPIO_MSLLD_SetAlternateNumber(Pin , Function)) &&
1579  oC_AssignErrorCode(&errorCode , oC_GPIO_LLD_FinishConfiguration(Pin))
1580  )
1581  {
1582  errorCode = oC_ErrorCode_None;
1583  }
1584 
1585  }
1587  }
1588 
1589  return errorCode;
1590 }
1591 
1592 #undef _________________________________________MSLLD_INTERFACE_FUNCTIONS_SECTION__________________________________________________________
1593 
1594 
1600 #define _________________________________________INTERRUPTS_SECTION________________________________________________________________________
1601 
1602 
1603 //oC_Machine_DefineInterruptHandlersForChannels;
1604 #define MODULE_NAME GPIO
1605 #define INTERRUPT_TYPE_NAME PeripheralInterrupt
1606 
1607 //==========================================================================================================================================
1611 //==========================================================================================================================================
1613 {
1614  if(InterruptHandler)
1615  {
1616  oC_Pins_t pins = oC_GPIO_LLD_GetPinsFor(
1617  Channel ,
1618  oC_Machine_Register(Channel , GPIORIS)->Value
1619  );
1620  InterruptHandler(pins);
1621  }
1622 }
1623 #undef INTERRUPT_TYPE_NAME
1624 
1625 
1626 #undef _________________________________________INTERRUPTS_SECTION________________________________________________________________________
1627 
Something is powered on.
Definition: oc_stdtypes.h:252
The file with interface for LLD layer.
static bool oC_Bits_AreBitsSetU32(uint32_t BitMask, uint32_t BitsToCheck)
checks if all bits in field are set
Definition: oc_bits.h:884
Something power is not handled.
Definition: oc_stdtypes.h:253
uint32_t oC_uint32_t
type for 32 bit unsigned integer
Definition: oc_stdtypes.h:56
static bool oC_Bits_IsAtLeastOneBitClearU32(uint32_t BitMask, uint32_t BitsToCheck)
checks if at least one of bits in field is set
Definition: oc_bits.h:1088
static uint32_t oC_Bits_SetValueU32(uint32_t *outVariable, uint32_t Value, uint8_t StartBitNr, uint8_t EndBitNr)
Definition: oc_bits.h:308
static uint8_t oC_Bits_SetBitsU8(uint8_t *outVariable, uint8_t Mask)
Definition: oc_bits.h:120
The file with interface for LSF module.
#define oC_Channel_GetName(Channel)
returns name of channel
Definition: oc_channels.h:391
The file with LLD interface for the MEM driver.
The file with LLD interface for the GPIO driver.
#define oC_Machine_WriteRegister(Channel, REGISTER_NAME, Value)
redefinition of oC_Machine_WriteRegisterDirectStaticOffset
Definition: oc_machine.h:200
static bool oC_Bits_IsAtLeastOneBitSetU32(uint32_t BitMask, uint32_t BitsToCheck)
checks if at least one of bits in field is set
Definition: oc_bits.h:1020
static uint32_t oC_Bits_SetBitsU32(uint32_t *outVariable, uint32_t Mask)
Definition: oc_bits.h:154
#define oC_Machine_RegisterIndirectDynamic(BaseAddress, RegisterOffset)
allows for accessing registers in dynamic mode
Definition: oc_machine.h:91
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
Something is powered off.
Definition: oc_stdtypes.h:251
static oC_ErrorCode_t ReadData(oC_FMC_Context_t Context, char *outData)
Reads one byte from the configured buffer.
Definition: oc_fmc.c:624
static int8_t oC_Bits_GetBitNumberU32(uint32_t BitMask)
Definition: oc_bits.h:585
#define oC_Channel_IsCorrect(MODULE_NAME, Channel)
checks if channel is correct
Definition: oc_channels.h:283
static bool oC_Bits_AreBitsClearU32(uint32_t BitMask, uint32_t BitsToCheck)
checks if all bits in field are clear
Definition: oc_bits.h:952
#define oC_Channel_FromIndex(MODULE_NAME, ChannelIndex)
returns channel according to index in module
Definition: oc_channels.h:313
#define oC_ModuleChannel_NumberOfElements(MODULE_NAME)
Number of elements in module channel.
Definition: oc_channels.h:465
static void oC_Module_TurnOn(oC_Module_t Module)
sets module as turned on
Definition: oc_module.h:170
Contains machine core specific functions.
The file with functions for the bits operation.
static void oC_MCS_EnterCriticalSection(void)
Enters to critical section.
Definition: oc_mcs.h:755
static uint32_t oC_Bits_ClearBitsU32(uint32_t *outVariable, uint32_t Mask)
Definition: oc_bits.h:222
The file with interface interrupt module.
static oC_Power_t oC_Machine_GetPowerStateForChannel(oC_Channel_t Channel)
returns power state for channel
Definition: oc_machine.h:550
static oC_ErrorCode_t WriteData(oC_FMC_Context_t Context, char Data)
Writes one byte to the configured buffer.
Definition: oc_fmc.c:646
static bool oC_Module_TurnOffVerification(oC_ErrorCode_t *outErrorCode, oC_Module_t Module)
verify if module is turned off
Definition: oc_module.h:155
static bool oC_MCS_ExitCriticalSection(void)
Exits from critical section.
Definition: oc_mcs.h:784
static bool oC_Module_TurnOnVerification(oC_ErrorCode_t *outErrorCode, oC_Module_t Module)
verify if module is turned on
Definition: oc_module.h:138
#define oC_Channel_ToIndex(MODULE_NAME, Channel)
returns index in module according to channel
Definition: oc_channels.h:298
static void InterruptHandler(oC_ETH_LLD_InterruptSource_t Source)
handler for interrupts
Definition: oc_eth.c:1124
#define oC_Machine_Register(Channel, REGISTER_NAME)
allows for accessing registers using channel and offset name
Definition: oc_machine.h:132
#define oC_Channel_InterruptHandler(ChannelVariableName)
creates common interrupt handler for channel
Definition: oc_channels.h:514
static bool oC_Machine_SetPowerStateForChannel(oC_Channel_t Channel, oC_Power_t Power)
configures power state for machine channel
Definition: oc_machine.h:593
The file with interface for Channel module.
oC_Power_t
stores registers power state
Definition: oc_stdtypes.h:249
static uint8_t oC_Bits_ClearBitsU8(uint8_t *outVariable, uint8_t Mask)
Definition: oc_bits.h:188
#define NULL
pointer to a zero
Definition: oc_null.h:37
static void oC_Module_TurnOff(oC_Module_t Module)
sets module as turned off
Definition: oc_module.h:185