Choco OS  V.0.16.9.0
Join to the chocolate world
oc_pins.h
Go to the documentation of this file.
1 
38 #ifndef SYSTEM_PORTABLE_INC_OC_PINS_H_
39 #define SYSTEM_PORTABLE_INC_OC_PINS_H_
40 
41 #include <oc_1word.h>
42 #include <oc_pins_defs.h>
43 #include <oc_channels.h>
44 #include <oc_ba.h>
45 #include <oc_bits.h>
46 #include <oc_pinsmap.h>
47 #include <oc_array.h>
48 
49 #if !oC_Channel_IsModuleDefined(GPIO)
50 #error GPIO module is not defined
51 #else
52 
58 #define _________________________________________MACROS_SECTION_____________________________________________________________________________
59 
62 //==========================================================================================================================================
74 //==========================================================================================================================================
75 #define oC_ModulePin_IsModuleDefined(MODULE_NAME) defined(oC_MODULE_PINS_##MODULE_NAME)
76 //==========================================================================================================================================
88 //==========================================================================================================================================
89 #define oC_ModulePinFunctions_IsModuleDefined(MODULE_NAME) defined(oC_MODULE_PIN_FUNCTIONS_##MODULE_NAME)
90 
91 //==========================================================================================================================================
105 //==========================================================================================================================================
106 #define oC_Pin_(PIN_NAME,...) oC_1WORD_FROM_2(oC_Pin_ , PIN_NAME)
107 
108 //==========================================================================================================================================
113 //==========================================================================================================================================
114 #define oC_PinIndex_(PIN_NAME,...) oC_1WORD_FROM_2(oC_PinIndex_ , PIN_NAME)
115 
116 //==========================================================================================================================================
121 //==========================================================================================================================================
122 #define oC_ModulePinIndex_(CHANNEL_NAME,PIN_FUNCTION,PIN_NAME,DIGITAL_VALUE) oC_1WORD_FROM_8( oC_ModulePinIndex_ , CHANNEL_NAME , _ , PIN_FUNCTION , _ , PIN_NAME , _ , DIGITAL_VALUE )
123 
124 //==========================================================================================================================================
129 //==========================================================================================================================================
130 #define oC_PinFunctionIndex_(PIN_FUNCTION) oC_1WORD_FROM_2(oC_PinFunctionIndex_ , PIN_FUNCTION)
131 //==========================================================================================================================================
138 //==========================================================================================================================================
139 #define oC_ModulePinFunction_(MODULE_NAME,PIN_FUNCTION) oC_1WORD_FROM_4(oC_,MODULE_NAME,_PinFunction_ , PIN_FUNCTION )
140 //==========================================================================================================================================
149 //==========================================================================================================================================
150 #define oC_ModulePin_(MODULE_NAME,CHANNEL_NAME,PIN_FUNCTION,PIN_NAME,DIGITAL_VALUE) oC_1WORD_FROM_8(oC_ , MODULE_NAME, _Pin_ , CHANNEL_NAME , PIN_FUNCTION,PIN_NAME,_,DIGITAL_VALUE)
151 //==========================================================================================================================================
161 //==========================================================================================================================================
162 #define oC_ModulePinType_(MODULE_NAME) oC_1WORD_FROM_3(oC_,MODULE_NAME,_Pin_t)
163 
164 //==========================================================================================================================================
175 //==========================================================================================================================================
176 #define oC_PinsInPortMask ( (1<<(oC_PORT_WIDTH)) - 1 )
177 //==========================================================================================================================================
184 //==========================================================================================================================================
185 #define oC_PinFunctionMask ( (1<<(oC_MODULE_PIN_FUNCTION_WIDTH)) - 1 )
186 
187 //==========================================================================================================================================
194 //==========================================================================================================================================
195 #define oC_PinAlternateNumberMask ( (1<<(oC_ALTERNATE_NUMBER_FIELD_WIDTH)) - 1 )
196 
197 //==========================================================================================================================================
202 //==========================================================================================================================================
203 #define oC_Pin_PinsInPortMaskWidth (oC_PORT_WIDTH)
204 //==========================================================================================================================================
209 //==========================================================================================================================================
210 #define oC_Pin_ChannelMaskWidth (oC_CHANNEL_MASK_WIDTH)
211 //==========================================================================================================================================
216 //==========================================================================================================================================
217 #define oC_Pin_MaskWidth ((oC_Pin_PinsInPortMaskWidth) + (oC_Pin_ChannelMaskWidth))
218 
219 //==========================================================================================================================================
224 //==========================================================================================================================================
225 #define oC_Pin_PinsInPortMaskStartBit (0)
226 //==========================================================================================================================================
231 //==========================================================================================================================================
232 #define oC_Pin_ChannelMaskStartBit ((oC_Pin_PinsInPortMaskWidth) + (oC_Pin_PinsInPortMaskStartBit))
233 //==========================================================================================================================================
238 //==========================================================================================================================================
239 #define oC_Pin_PinsInPortMask ((oC_PinsInPortMask) << (oC_Pin_PinsInPortMaskStartBit))
240 //==========================================================================================================================================
245 //==========================================================================================================================================
246 #define oC_Pin_ChannelMask ((oC_ChannelMask) << (oC_Pin_ChannelMaskStartBit) )
247 //==========================================================================================================================================
252 //==========================================================================================================================================
253 #define oC_Pin_Mask ( (1<<(oC_Pin_MaskWidth)) - 1 )
254 //==========================================================================================================================================
263 //==========================================================================================================================================
264 #define oC_Make_PinFunctionsForModule(MODULE_NAME) oC_MODULE_PIN_FUNCTIONS_(MODULE_NAME)(MAKE_PIN_FUNCTION)
265 //==========================================================================================================================================
272 //==========================================================================================================================================
273 #define oC_Make_PinFunctionForModule(PIN_FUNCTION,...) oC_ModulePinFunction_(MODULE_NAME,PIN_FUNCTION) = oC_PinFunctionIndex_(PIN_FUNCTION) ,
274 //==========================================================================================================================================
281 //==========================================================================================================================================
282 #define oC_Make_ModulePinForModule( PIN_NAME , CHANNEL_NAME , PIN_FUNCTION , ALTERNATE_FUNCTION , ... ) \
283  oC_ModulePin_(MODULE_NAME,CHANNEL_NAME,PIN_FUNCTION,PIN_NAME,ALTERNATE_FUNCTION) = oC_ModulePinIndex_(CHANNEL_NAME,PIN_FUNCTION,PIN_NAME,ALTERNATE_FUNCTION),
284 
285 //==========================================================================================================================================
297 //==========================================================================================================================================
298 #define oC_Pin_GetPinsInPort(Pin) ( ((Pin) & (oC_Pin_PinsInPortMask)) >> oC_Pin_PinsInPortMaskStartBit )
299 //==========================================================================================================================================
311 //==========================================================================================================================================
312 #define oC_Pin_GetChannel(Pin) ( ((Pin) & (oC_Pin_ChannelMask)) >> oC_Pin_ChannelMaskStartBit )
313 
314 //==========================================================================================================================================
323 //==========================================================================================================================================
324 #define oC_Pin_GetPort(Pin) oC_Pin_GetChannel(Pin)
325 
326 //==========================================================================================================================================
338 //==========================================================================================================================================
339 #define oC_Pin_Make(Port,PinsInPort) \
340  oC_Bits_ValueWithMask( PinsInPort , oC_Pin_PinsInPortMaskStartBit, oC_Pin_PinsInPortMask) | \
341  oC_Bits_ValueWithMask( Port , oC_Pin_ChannelMaskStartBit, oC_Pin_ChannelMask) \
342 
343 
344 //==========================================================================================================================================
358 //==========================================================================================================================================
359 #define oC_Pins_ToSinglePin(Pins,PinIndex) ( ((Pins) & ((1<<PinIndex)<<oC_Pin_PinsInPortMaskStartBit)) | ((Pins) & oC_Pin_ChannelMask) )
360 
361 //==========================================================================================================================================
368 //==========================================================================================================================================
369 #define oC_ModulePin_GetData(ModulePin) (&oC_ModulePinsData[ModulePin])
370 //==========================================================================================================================================
381 //==========================================================================================================================================
382 #define oC_ModulePin_GetPin(ModulePin) oC_ModulePin_GetData(ModulePin)->Pin
383 //==========================================================================================================================================
396 //==========================================================================================================================================
397 #define oC_ModulePin_GetPinFunction(ModulePin) oC_ModulePin_GetData(ModulePin)->PinFunction
398 //==========================================================================================================================================
410 //==========================================================================================================================================
411 #define oC_ModulePin_GetChannel(ModulePin) oC_ModulePin_GetData(ModulePin)->Channel
412 
413 //==========================================================================================================================================
423 //==========================================================================================================================================
424 #define oC_ModulePin_GetAlternateNumber(ModulePin) oC_ModulePin_GetData(ModulePin)->AlternateNumber
425 
426 //==========================================================================================================================================
438 //==========================================================================================================================================
439 #define oC_ModulePinFunction_DefineType \
440  typedef enum \
441  { \
442  oC_MODULE_PIN_FUNCTIONS_(MODULE_NAME)(oC_Make_PinFunctionForModule) \
443  oC_Make_PinFunctionForModule(NumberOfElements)\
444  } oC_ModulePinFunction_(MODULE_NAME,t)
445 
446 //==========================================================================================================================================
462 //==========================================================================================================================================
463 #define oC_ModulePin_DefineType \
464  typedef enum \
465  { \
466  oC_MODULE_PINS_(MODULE_NAME)(oC_Make_ModulePinForModule) \
467  } oC_ModulePinType_(MODULE_NAME)
468 
469 //==========================================================================================================================================
484 //==========================================================================================================================================
485 #define oC_Pin_ForeachDefined(PinVariableName) oC_ARRAY_FOREACH_IN_ARRAY(oC_DefinedPins , PinVariableName)
486 
487 //==========================================================================================================================================
504 //==========================================================================================================================================
505 #define oC_ModulePin_ForeachDefined(PinVariableName) oC_ARRAY_FOREACH_IN_ARRAY(oC_ModulePinsData , PinVariableName)
506 
507 #undef _________________________________________MACROS_SECTION_____________________________________________________________________________
508 
515 #define _________________________________________TYPES_SECTION______________________________________________________________________________
516 
519 //==========================================================================================================================================
530 //==========================================================================================================================================
531 typedef enum
532 {
533  oC_Pin_NotUsed = 0 ,
534 #define MAKE_CFG_PIN(USER_PIN_NAME , PIN_NAME) oC_Pin_(USER_PIN_NAME) = oC_Pin_(PIN_NAME) ,
535 #define MAKE_PIN(BASE_ADDRESS_NAME , PIN_NAME , BIT_INDEX , PIN_NUMBER) \
536  oC_Pin_(PIN_NAME) = oC_Pin_Make(oC_Channel_(BASE_ADDRESS_NAME) , 1 << BIT_INDEX) ,
537 
538  oC_PINS_LIST(MAKE_PIN)
539  oC_CFG_PINS(MAKE_CFG_PIN)
540 #undef MAKE_PIN
541 #undef MAKE_CFG_PIN
542 } oC_Pin_t;
543 
544 //==========================================================================================================================================
549 //==========================================================================================================================================
550 typedef enum
551 {
552 #define MAKE_PIN(BASE_ADDRESS_NAME , PIN_NAME , BIT_INDEX , PIN_NUMBER) \
553  oC_PinIndex_(PIN_NAME) ,
554  oC_PINS_LIST(MAKE_PIN)
555  oC_PinIndex_NumberOfElements
556 #undef MAKE_PIN
557 } oC_PinIndex_t;
558 
559 //==========================================================================================================================================
564 //==========================================================================================================================================
565 typedef enum
566 {
567 #define MAKE_MODULE_PIN( PIN_NAME , CHANNEL_NAME , PIN_FUNCTION , ALTERNATE_FUNCTION ) \
568  oC_ModulePinIndex_(CHANNEL_NAME,PIN_FUNCTION,PIN_NAME,ALTERNATE_FUNCTION) ,
569 #define MAKE_MODULE(MODULE_NAME) oC_MODULE_PINS_(MODULE_NAME)(MAKE_MODULE_PIN)
570  oC_MODULES_PINS_LIST(MAKE_MODULE)
571 #undef MAKE_MODULE
572 #undef MAKE_MODULE_PIN
573  oC_ModulePinIndex_NumberOfElements
574 } oC_ModulePinIndex_t;
575 
576 //==========================================================================================================================================
581 //==========================================================================================================================================
582 typedef enum
583 {
584 #define MAKE_MODULE_PIN_FUNCTION( PIN_FUNCTION ) \
585  oC_PinFunctionIndex_(PIN_FUNCTION) ,
586 #define MAKE_MODULE(MODULE_NAME) oC_MODULE_PIN_FUNCTIONS_(MODULE_NAME)(MAKE_MODULE_PIN_FUNCTION)
587  oC_MODULES_PINS_LIST(MAKE_MODULE)
588 #undef MAKE_MODULE
589 #undef MAKE_MODULE_PIN_FUNCTION
590  oC_PinFunctionIndex_NumberOfElements
591 } oC_PinFunctionIndex_t;
592 
593 //==========================================================================================================================================
601 //==========================================================================================================================================
602 typedef oC_Pin_t oC_Pins_t;
603 
604 //==========================================================================================================================================
610 //==========================================================================================================================================
611 typedef oC_Channel_t oC_Port_t;
612 
613 //==========================================================================================================================================
621 //==========================================================================================================================================
622 typedef oC_ChannelIndex_t oC_PortIndex_t;
623 
624 #if oC_PORT_WIDTH <= 8
625 //==========================================================================================================================================
637 //==========================================================================================================================================
638 typedef uint8_t oC_PinsInPort_t;
639 #elif oC_PORT_WIDTH <= 16
640 //==========================================================================================================================================
652 //==========================================================================================================================================
653 typedef uint16_t oC_PinsInPort_t;
654 #elif oC_PORT_WIDTH <= 32
655 //==========================================================================================================================================
667 //==========================================================================================================================================
668 typedef uint32_t oC_PinsInPort_t;
669 #elif oC_PORT_WIDTH <= 64
670 //==========================================================================================================================================
682 //==========================================================================================================================================
683 typedef uint64_t oC_PinsInPort_t;
684 #else
685 # error oC_PORT_WIDTH is too big! (max 64)
686 #endif
687 
688 #if oC_ALTERNATE_NUMBER_FIELD_WIDTH <= 8
689 //==========================================================================================================================================
697 //==========================================================================================================================================
698 typedef uint8_t oC_PinAlternateNumber_t;
699 #elif oC_ALTERNATE_NUMBER_FIELD_WIDTH <= 16
700 //==========================================================================================================================================
708 //==========================================================================================================================================
709 typedef uint16_t oC_PinAlternateNumber_t;
710 #elif oC_ALTERNATE_NUMBER_FIELD_WIDTH <= 32
711 //==========================================================================================================================================
719 //==========================================================================================================================================
720 typedef uint32_t oC_PinAlternateNumber_t;
721 #elif oC_ALTERNATE_NUMBER_FIELD_WIDTH <= 64
722 //==========================================================================================================================================
730 //==========================================================================================================================================
731 typedef uint64_t oC_PinAlternateNumber_t;
732 #else
733 # error oC_ALTERNATE_NUMBER_FIELD_WIDTH is too big! (max 64)
734 #endif
735 
736 #if oC_MODULE_PIN_FUNCTION_WIDTH <= 8
737 //==========================================================================================================================================
742 //==========================================================================================================================================
743 typedef uint8_t oC_PinFunction_t;
744 #elif oC_MODULE_PIN_FUNCTION_WIDTH <= 16
745 //==========================================================================================================================================
750 //==========================================================================================================================================
751 typedef uint16_t oC_PinFunction_t;
752 #elif oC_MODULE_PIN_FUNCTION_WIDTH <= 32
753 //==========================================================================================================================================
758 //==========================================================================================================================================
759 typedef uint32_t oC_PinFunction_t;
760 #elif oC_MODULE_PIN_FUNCTION_WIDTH <= 64
761 //==========================================================================================================================================
766 //==========================================================================================================================================
767 typedef uint64_t oC_PinFunction_t;
768 #else
769 # error oC_MODULE_PIN_FUNCTION_WIDTH is too big! (max 64)
770 #endif
771 
772 //==========================================================================================================================================
781 //==========================================================================================================================================
782 typedef oC_PinsInPort_t oC_PinsMask_t;
783 
784 //==========================================================================================================================================
789 //==========================================================================================================================================
790 typedef struct
791 {
792  oC_Pin_t Pin;
793  const char * Name;
794 } oC_DefinedPinData_t;
795 
796 //==========================================================================================================================================
801 //==========================================================================================================================================
802 typedef struct
803 {
804  oC_Pin_t Pin;
805  oC_PinAlternateNumber_t AlternateNumber;
806  oC_Channel_t Channel;
807  oC_PinFunction_t PinFunction;
808  oC_ModulePinIndex_t ModulePinIndex;
809 } oC_ModulePinData_t;
810 
811 #undef _________________________________________TYPES_SECTION______________________________________________________________________________
812 
819 #define _________________________________________VARIABLES_SECTION__________________________________________________________________________
820 
821 //==========================================================================================================================================
828 //==========================================================================================================================================
829 extern const oC_DefinedPinData_t oC_DefinedPins[oC_PinIndex_NumberOfElements];
830 
831 //==========================================================================================================================================
838 //==========================================================================================================================================
839 extern const oC_ModulePinData_t oC_ModulePinsData[oC_ModulePinIndex_NumberOfElements];
840 
841 #undef _________________________________________VARIABLES_SECTION__________________________________________________________________________
842 
843 
844 #endif /* SYSTEM_PORTABLE_INC_OC_PINS_H_ */
845 #endif
Contains macros for creating one word from more words in macros.
oC_Channel_t
stores machine channel
Definition: oc_channels.h:573
The file with functions for the bits operation.
Static array definitions.
The file with interface for Channel module.
Interface for Machine Base Addresses (BA) module.