Choco OS  V.0.16.9.0
Join to the chocolate world
oc_channels.h
Go to the documentation of this file.
1 
34 #ifndef SYSTEM_PORTABLE_INC_OC_CHANNELS_H_
35 #define SYSTEM_PORTABLE_INC_OC_CHANNELS_H_
36 
37 #include <oc_1word.h>
38 #include <oc_channels_defs.h>
39 #include <oc_ba.h>
40 #include <oc_rmaps.h>
41 #include <oc_registers.h>
42 #include <oc_interrupts.h>
43 
49 #define _________________________________________MACROS_SECTION_____________________________________________________________________________
50 
53 //==========================================================================================================================================
61 //==========================================================================================================================================
62 #define oC_ChannelMask ( (1<<(oC_CHANNEL_MASK_WIDTH)) - 1 )
63 
64 //==========================================================================================================================================
69 //==========================================================================================================================================
70 #define oC_Channel_(CHANNEL_NAME,...) oC_1WORD_FROM_2(oC_Channel_ , CHANNEL_NAME)
71 //==========================================================================================================================================
76 //==========================================================================================================================================
77 #define oC_ChannelModule_(CHANNEL_NAME,...) oC_1WORD_FROM_2(oC_ChannelModule_ , CHANNEL_NAME)
78 //==========================================================================================================================================
99 //==========================================================================================================================================
100 #define oC_ChannelStartIndex_(MODULE_NAME,...) oC_1WORD_FROM_3(oC_Channel_ , MODULE_NAME , _StartIndex )
101 //==========================================================================================================================================
124 //==========================================================================================================================================
125 #define oC_ChannelEndIndex_(MODULE_NAME,...) oC_1WORD_FROM_3(oC_Channel_ , MODULE_NAME , _EndIndex )
126 //==========================================================================================================================================
136 //==========================================================================================================================================
137 #define oC_ModuleChannel_(MODULE_NAME,CHANNEL_NAME,...) oC_1WORD_FROM_4(oC_ , MODULE_NAME , _Channel_ , CHANNEL_NAME )
138 
139 //==========================================================================================================================================
160 //==========================================================================================================================================
161 #define oC_Channel_InterruptHandlerName(INTERRUPT_TYPE_NAME) oC_1WORD_FROM_2( INTERRUPT_TYPE_NAME , ChannelHandler )
162 //==========================================================================================================================================
184 //==========================================================================================================================================
185 #define oC_Channel_InterruptHandlerPrototype(INTERRUPT_TYPE_NAME,ChannelVariableName) static void oC_Channel_InterruptHandlerName(INTERRUPT_TYPE_NAME) ( oC_Channel_t ChannelVariableName )
186 
187 //==========================================================================================================================================
192 //==========================================================================================================================================
193 #define oC_Make_ModuleWithChannels(MODULE_NAME) oC_MODULE_CHANNELS_(MODULE_NAME)(MAKE_CHANNEL)
194 //==========================================================================================================================================
199 //==========================================================================================================================================
200 #define oC_Make_ChannelForModule(CHANNEL_NAME,...) oC_ModuleChannel_(MODULE_NAME,CHANNEL_NAME) = oC_Channel_(CHANNEL_NAME) ,
201 
202 //==========================================================================================================================================
207 //==========================================================================================================================================
208 #define oC_Make_InterruptHandlerForChannel(CHANNEL_NAME,BASE_NAME,...) \
209  oC_InterruptHandler(BASE_NAME,INTERRUPT_TYPE_NAME) \
210  { \
211  oC_Channel_InterruptHandlerName(INTERRUPT_TYPE_NAME)(oC_Channel_(CHANNEL_NAME));\
212  } \
213 
214 //==========================================================================================================================================
228 //==========================================================================================================================================
229 #define oC_ChannelData_(CHANNEL_NAME) (&oC_ChannelsData[oC_Channel_(CHANNEL_NAME)])
230 
231 //==========================================================================================================================================
243 //==========================================================================================================================================
244 #define oC_Channel_IsModuleDefined(MODULE_NAME) (defined(oC_MODULE_CHANNELS_##MODULE_NAME))
245 
246 //==========================================================================================================================================
265 //==========================================================================================================================================
266 #define oC_Channel_GetData(Channel) (&oC_ChannelsData[Channel])
267 //==========================================================================================================================================
282 //==========================================================================================================================================
283 #define oC_Channel_IsCorrect(MODULE_NAME,Channel) ((((oC_Channel_t)(Channel)) > oC_ChannelStartIndex_(MODULE_NAME)) && (((oC_Channel_t)(Channel)) < oC_ChannelEndIndex_(MODULE_NAME)))
284 //==========================================================================================================================================
297 //==========================================================================================================================================
298 #define oC_Channel_ToIndex(MODULE_NAME,Channel) (Channel - oC_ChannelStartIndex_(MODULE_NAME) - 1)
299 //==========================================================================================================================================
312 //==========================================================================================================================================
313 #define oC_Channel_FromIndex(MODULE_NAME,ChannelIndex) (ChannelIndex + oC_ChannelStartIndex_(MODULE_NAME) + 1)
314 //==========================================================================================================================================
326 //==========================================================================================================================================
327 #define oC_Channel_GetBaseAddress(Channel) oC_Channel_GetData(Channel)->BaseAddress
328 //==========================================================================================================================================
343 //==========================================================================================================================================
344 #define oC_Channel_GetPowerBaseAddress(Channel) oC_Channel_GetData(Channel)->PowerBaseAddress
345 //==========================================================================================================================================
354 //==========================================================================================================================================
355 #define oC_Channel_GetPowerOffset(Channel) oC_Channel_GetData(Channel)->PowerOffset
356 //=========================================================================================================================================
364 //==========================================================================================================================================
365 #define oC_Channel_GetPowerBitIndex(Channel) oC_Channel_GetData(Channel)->PowerBitIndex
366 //==========================================================================================================================================
373 //==========================================================================================================================================
374 #define oC_Channel_GetRegisterMap(Channel) oC_Channel_GetData(Channel)->RegisterMap
375 //==========================================================================================================================================
390 //==========================================================================================================================================
391 #define oC_Channel_GetName(Channel) oC_Channel_GetData(Channel)->ChannelName
392 
393 //==========================================================================================================================================
406 //==========================================================================================================================================
407 #define oC_Channel_PowerBaseAddressExist(Channel) (oC_PowerBaseAddress_Exist( oC_Channel_GetPowerBaseAddress(Channel) ) )
408 //==========================================================================================================================================
421 //==========================================================================================================================================
422 #define oC_Channel_PowerOffsetExist(Channel) (oC_PowerOffset_Exist( oC_Channel_GetPowerOffset(Channel) ) )
423 //==========================================================================================================================================
436 //==========================================================================================================================================
437 #define oC_Channel_PowerBitIndexExist(Channel) (oC_PowerBit_Exist( oC_Channel_GetPowerBitIndex(Channel) ) )
438 
439 //==========================================================================================================================================
454 //==========================================================================================================================================
455 #define oC_Channel_Register(Channel,REGISTER_NAME) oC_RegisterByBaseAddress( oC_Channel_GetBaseAddress(Channel) , REGISTER_NAME )
456 
457 //==========================================================================================================================================
464 //==========================================================================================================================================
465 #define oC_ModuleChannel_NumberOfElements(MODULE_NAME) (oC_ChannelEndIndex_(MODULE_NAME) - oC_ChannelStartIndex_(MODULE_NAME) - 1)
466 
467 //==========================================================================================================================================
484 //==========================================================================================================================================
485 #define oC_Channel_Foreach(MODULE_NAME,Channel) for(oC_Channel_t Channel = oC_ChannelStartIndex_(MODULE_NAME) + 1 ; Channel < oC_ChannelEndIndex_(MODULE_NAME) ; Channel++)
486 
487 //==========================================================================================================================================
513 //==========================================================================================================================================
514 #define oC_Channel_InterruptHandler(ChannelVariableName) \
515  oC_Channel_InterruptHandlerPrototype(INTERRUPT_TYPE_NAME,ChannelVariableName);\
516  oC_MODULE_CHANNELS_(MODULE_NAME)(oC_Make_InterruptHandlerForChannel)\
517  oC_Channel_InterruptHandlerPrototype(INTERRUPT_TYPE_NAME,ChannelVariableName)
518 
519 //==========================================================================================================================================
540 //==========================================================================================================================================
541 #define oC_ModuleChannel_DefineType \
542  typedef enum {\
543  oC_MODULE_CHANNELS_(MODULE_NAME)(oC_Make_ChannelForModule) \
544  } oC_ModuleChannel_(MODULE_NAME,t)
545 
546 #define oC_Channel_SetInterruptPriority( Channel , INTERRUPT_TYPE , InterruptPriority ) oC_Channel_SetInterruptPriorityFunction( Channel , oC_InterruptType_(INTERRUPT_TYPE) , InterruptPriority )
547 #define oC_Channel_EnableInterrupt( Channel , INTERRUPT_TYPE ) oC_Channel_EnableInterruptFunction( Channel , oC_InterruptType_(INTERRUPT_TYPE) )
548 #define oC_Channel_DisableInterrupt( Channel , INTERRUPT_TYPE ) oC_Channel_DisableInterruptFunction( Channel , oC_InterruptType_(INTERRUPT_TYPE) )
549 #define oC_Channel_IsInterruptEnabled( Channel , INTERRUPT_TYPE ) oC_Channel_IsInterruptEnabledFunction( Channel , oC_InterruptType_(INTERRUPT_TYPE) )
550 
551 #undef _________________________________________MACROS_SECTION_____________________________________________________________________________
552 
559 #define _________________________________________TYPES_SECTION______________________________________________________________________________
560 
563 //==========================================================================================================================================
572 //==========================================================================================================================================
573 typedef enum
574 {
575 #define MAKE_MODULE(MODULE_NAME) \
576  oC_ChannelStartIndex_(MODULE_NAME), \
577  oC_MODULE_CHANNELS_(MODULE_NAME)(MAKE_CHANNEL) \
578  oC_ChannelEndIndex_(MODULE_NAME),
579 #define MAKE_CHANNEL(CHANNEL_NAME,BASE_ADDRESS_NAME,REGISTER_MAP_NAME,...) oC_Channel_(CHANNEL_NAME) ,
580  oC_MODULES_LIST(MAKE_MODULE)
581  oC_Channel_MaximumChannelNumber ,
582  oC_Channel_System = oC_Channel_MaximumChannelNumber,
583  oC_Channel_Software = oC_Channel_MaximumChannelNumber
584 #undef MAKE_CHANNEL
585 #undef MAKE_MODULE
586 } oC_Channel_t;
587 
588 //==========================================================================================================================================
596 //==========================================================================================================================================
598 
599 #if oC_Channel_MaximumChannelNumber > oC_ChannelMask
600 # error Channel mask width is too small!
601 #endif
602 
603 //==========================================================================================================================================
609 //==========================================================================================================================================
610 typedef struct
611 {
617  const char * ChannelName;
619 
620 //==========================================================================================================================================
624 //==========================================================================================================================================
625 typedef enum
626 {
627 #define MAKE_MODULE(MODULE_NAME) oC_ChannelModule_(MODULE_NAME) ,
628  oC_MODULES_LIST(MAKE_MODULE)
629 #undef MAKE_MODULE
631 
632 //==========================================================================================================================================
643 //==========================================================================================================================================
644 typedef void (*oC_ChannelInterruptHandler_t)( oC_Channel_t Channel );
645 
646 #undef _________________________________________TYPES_SECTION______________________________________________________________________________
647 
654 #define _________________________________________PROTOTYPES_SECTION_________________________________________________________________________
655 
657 extern bool oC_Channel_EnableInterruptFunction( oC_Channel_t Channel , oC_InterruptType_t InterruptType );
658 extern bool oC_Channel_DisableInterruptFunction( oC_Channel_t Channel , oC_InterruptType_t InterruptType );
659 extern bool oC_Channel_IsInterruptEnabledFunction( oC_Channel_t Channel , oC_InterruptType_t InterruptType );
660 
661 #undef _________________________________________PROTOTYPES_SECTION_________________________________________________________________________
662 
663 
669 #define _________________________________________VARIABLES_SECTION__________________________________________________________________________
670 
673 //==========================================================================================================================================
682 //==========================================================================================================================================
683 extern const oC_ChannelData_t oC_ChannelsData[];
684 
685 #undef _________________________________________VARIABLES_SECTION__________________________________________________________________________
686 
688 #endif /* SYSTEM_PORTABLE_INC_OC_CHANNELS_H_ */
The file with interface for registers module.
Contains macros for creating one word from more words in macros.
oC_RegisterMap_t RegisterMap
Index of register map.
Definition: oc_channels.h:616
bool oC_Channel_DisableInterruptFunction(oC_Channel_t Channel, oC_InterruptType_t InterruptType)
disables interrupt according to channel and type
Definition: oc_channels.c:120
void(* oC_ChannelInterruptHandler_t)(oC_Channel_t Channel)
stores pointer of channel interrupt function
Definition: oc_channels.h:644
oC_BaseAddress_t BaseAddress
Start address in memory.
Definition: oc_channels.h:612
const oC_ChannelData_t oC_ChannelsData[]
stores data of channels
Definition: oc_channels.c:33
oC_PowerBit_t
stores number of bit in the Power Register
Definition: oc_ba.h:235
const char * ChannelName
Name of the given register map.
Definition: oc_channels.h:617
oC_InterruptPriotity_t
stores priority of interrupts
Definition: oc_mcs.h:174
stores data for channel
Definition: oc_channels.h:610
oC_ChannelModule_t
stores index of channel module (UART,SPI,etc)
Definition: oc_channels.h:625
oC_PowerOffset_t
stores offset of the Power Register
Definition: oc_ba.h:219
oC_PowerOffset_t PowerOffset
Power register offset.
Definition: oc_channels.h:614
oC_Channel_t
stores machine channel
Definition: oc_channels.h:573
The file with interface for register maps module.
oC_InterruptType_t
Stores interrupt type.
bool oC_Channel_SetInterruptPriorityFunction(oC_Channel_t Channel, oC_InterruptType_t InterruptType, oC_InterruptPriotity_t Priority)
set interrupt priority according to channel and type
Definition: oc_channels.c:67
oC_RegisterMap_t
Type for storing register map ID.
Definition: oc_rmaps.h:167
oC_PowerBaseAddress_t PowerBaseAddress
Power register base address.
Definition: oc_channels.h:613
The file with interface interrupt module.
oC_PowerBaseAddress_t
stores base address of the Power Register
Definition: oc_ba.h:203
bool oC_Channel_IsInterruptEnabledFunction(oC_Channel_t Channel, oC_InterruptType_t InterruptType)
checks if interrupt is enabled according to channel and type
Definition: oc_channels.c:147
oC_PowerBit_t PowerBitIndex
Bit in power register for enabling power for the channel.
Definition: oc_channels.h:615
bool oC_Channel_EnableInterruptFunction(oC_Channel_t Channel, oC_InterruptType_t InterruptType)
enables interrupt according to channel and type
Definition: oc_channels.c:93
oC_Channel_t oC_ChannelIndex_t
stores index of channel
Definition: oc_channels.h:597
Interface for Machine Base Addresses (BA) module.
oC_BaseAddress_t
type for storing base address
Definition: oc_ba.h:185