Choco OS  V.0.16.9.0
Join to the chocolate world
Channels Module

Module for managing machine module channels. More...

Data Structures

struct  oC_ChannelData_t
 stores data for channel More...
 

Macros

#define oC_ChannelMask
 mask for channel type width More...
 
#define oC_Channel_(CHANNEL_NAME, ...)
 returns channel for oC_Channel_t type
 
#define oC_ChannelModule_(CHANNEL_NAME, ...)
 returns module index of channel with the given name
 
#define oC_ChannelStartIndex_(MODULE_NAME, ...)
 returns start channel index for module More...
 
#define oC_ChannelEndIndex_(MODULE_NAME, ...)
 returns end channel index for module More...
 
#define oC_ModuleChannel_(MODULE_NAME, CHANNEL_NAME, ...)
 returns channel of module More...
 
#define oC_Channel_InterruptHandlerName(INTERRUPT_TYPE_NAME)
 returns name of interrupt handler More...
 
#define oC_Channel_InterruptHandlerPrototype(INTERRUPT_TYPE_NAME, ChannelVariableName)
 Prototype for channels interrupt. More...
 
#define oC_Make_ModuleWithChannels(MODULE_NAME)
 makes module with channels. Not for user usage.
 
#define oC_Make_ChannelForModule(CHANNEL_NAME, ...)
 makes module with channels. Not for user usage.
 
#define oC_Make_InterruptHandlerForChannel(CHANNEL_NAME, BASE_NAME, ...)
 makes handler of interrupt for channel. Not for user usage.
 
#define oC_ChannelData_(CHANNEL_NAME)
 returns pointer to channel's data More...
 
#define oC_Channel_IsModuleDefined(MODULE_NAME)
 macro for checking if module is defined More...
 
#define oC_Channel_GetData(Channel)
 returns data of channel More...
 
#define oC_Channel_IsCorrect(MODULE_NAME, Channel)
 checks if channel is correct More...
 
#define oC_Channel_ToIndex(MODULE_NAME, Channel)
 returns index in module according to channel More...
 
#define oC_Channel_FromIndex(MODULE_NAME, ChannelIndex)
 returns channel according to index in module More...
 
#define oC_Channel_GetBaseAddress(Channel)
 returns base address assigned to the channel More...
 
#define oC_Channel_GetPowerBaseAddress(Channel)
 returns base address of power register More...
 
#define oC_Channel_GetPowerOffset(Channel)
 returns offset of power register More...
 
#define oC_Channel_GetPowerBitIndex(Channel)
 returns index of bit for power register More...
 
#define oC_Channel_GetRegisterMap(Channel)
 returns index of register map More...
 
#define oC_Channel_GetName(Channel)
 returns name of channel More...
 
#define oC_Channel_Register(Channel, REGISTER_NAME)
 checks if base address of power register exist More...
 
#define oC_ModuleChannel_NumberOfElements(MODULE_NAME)
 Number of elements in module channel. More...
 
#define oC_Channel_Foreach(MODULE_NAME, Channel)
 loop for each module channel More...
 
#define oC_Channel_InterruptHandler(ChannelVariableName)
 creates common interrupt handler for channel More...
 
#define oC_ModuleChannel_DefineType
 defines module channel type More...
 

Typedefs

typedef oC_Channel_t oC_ChannelIndex_t
 stores index of channel More...
 
typedef void(* oC_ChannelInterruptHandler_t) (oC_Channel_t Channel)
 stores pointer of channel interrupt function More...
 

Enumerations

Variables

const oC_ChannelData_t oC_ChannelsData []
 stores data of channels More...
 

Detailed Description

The module contains interface for managing machine module channels, for example SPI, UART, TIMER and more...

Macro Definition Documentation

#define oC_Channel_Foreach (   MODULE_NAME,
  Channel 
)

Creates a loop for each channel in the module.

Parameters
MODULE_NAMEname of module from the oc_channels_defs.h file
ChannelA channel variable name
oC_Channel_Foreach(SPI,channel)
{
oC_Channel_Register(SPI,SPIDR)->Value = 0xBABA;
}

Definition at line 485 of file oc_channels.h.

#define oC_Channel_FromIndex (   MODULE_NAME,
  ChannelIndex 
)

The macro returns channel from the index in the given module. Example of usage:

oC_ChannelIndex_t channelIndex = 0;
oC_Channel_t channel = oC_Channel_FromIndex(SPI,channelIndex);
printf("SPI channel with index 0 is named %s\n\r" , oC_Channel_GetName(channel));

Definition at line 313 of file oc_channels.h.

#define oC_Channel_GetBaseAddress (   Channel)

The macro returns base address of channel.

oC_Channel_t channel = oC_Channel_SPI0;

Definition at line 327 of file oc_channels.h.

#define oC_Channel_GetData (   Channel)

The macro is to get channel's data. The parameter, that is given to it should be variable (channel index). If you want to get data of channel according to the name, you should use oC_ChannelData_.

Parameters
ChannelVariable with channel index

Example of usage:

oC_Channel_t channel = oC_Channel_SPI0;
printf("Found %s channel\n\r" , oC_Channel_GetData(channel)->ChannelName);
See also
oC_ChannelData_

Definition at line 266 of file oc_channels.h.

#define oC_Channel_GetName (   Channel)

The macro returns printable name of the channel.

Example of usage:

oC_Channel_t channel = oC_Channel_SPI0;
const char * name = oC_Channel_GetName(channel);
printf("Found channel named %s\n\r" , name);

Definition at line 391 of file oc_channels.h.

#define oC_Channel_GetPowerBaseAddress (   Channel)

The macro returns base address of power register.

oC_Channel_t channel = oC_Channel_SPI0;
See also
oC_PowerBaseAddress_

Definition at line 344 of file oc_channels.h.

#define oC_Channel_GetPowerBitIndex (   Channel)

The macro returns index of bit in power register, that should be set to enable power for the register map that is assigned with the channel.

Definition at line 365 of file oc_channels.h.

#define oC_Channel_GetPowerOffset (   Channel)

The macro returns offset of power register.

See also
oC_PowerOffset_

Definition at line 355 of file oc_channels.h.

#define oC_Channel_GetRegisterMap (   Channel)

The macro returns index of register map connected to the channel.

Definition at line 374 of file oc_channels.h.

#define oC_Channel_InterruptHandler (   ChannelVariableName)

The macro creates interrupt handler for channel (common for each module channels). It require 2 additional definitions before usage: MODULE_NAME with name of the module from oc_channels_defs.h file and INTERRUPT_TYPE_NAME from the oc_interrupts_defs.h file.

The function, that is created by the macro is local (static).

Parameters
ChannelVariableNameName of the variable, that stores channel

Example of usage:

#define MODULE_NAME SPI
#define INTERRUPT_TYPE_NAME PeripheralInterrupt
{
printf("An interrupt occurs for the %s channel of SPI\n\r" , oC_Channel_GetName(Channel));
}
#undef MODULE_NAME
#undef INTERRUPT_TYPE_NAME

Definition at line 514 of file oc_channels.h.

#define oC_Channel_InterruptHandlerName (   INTERRUPT_TYPE_NAME)

The macro returns name of channel interrupt handler name.

Parameters
INTERRUPT_TYPE_NAMEName of the type from oc_interrupts_defs.h file

Example of usage:

// Define a prototype for local channel interrupt
oC_Channel_InterruptHandlerPrototype(PeripheralInterrupt,Channel);
// Saving pointer to the channel interrupt
oC_ChannelInterruptHandler_t channelInterruptHandler = oC_Channel_InterruptHandlerName(PeripheralInterrupt);
// Simulating interrupt
channelInterruptHandler(oC_Channel_SPI0);

Definition at line 161 of file oc_channels.h.

#define oC_Channel_InterruptHandlerPrototype (   INTERRUPT_TYPE_NAME,
  ChannelVariableName 
)

This is a macro for definition of channels interrupt handler prototype.

Parameters
INTERRUPT_TYPE_NAMEName of the type from oc_interrupts_defs.h file
ChannelVariableNameName of variable, that will store channel

Example of usage:

// Define a prototype for local channel interrupt
oC_Channel_InterruptHandlerPrototype(PeripheralInterrupt,Channel);
// Saving pointer to the channel interrupt
oC_ChannelInterruptHandler_t channelInterruptHandler = oC_Channel_InterruptHandlerName(PeripheralInterrupt);
// Simulating interrupt
channelInterruptHandler(oC_Channel_SPI0);

Definition at line 185 of file oc_channels.h.

#define oC_Channel_IsCorrect (   MODULE_NAME,
  Channel 
)

The macro is for checking if the given channel is correct for the given module.

oC_Channel_t channel = oC_Channel_SPI0;
if(oC_Channel_IsCorrect(SPI,channel))
{
printf("Channel %s is correct!\n\r" , oC_Channel_GetName(channel));
}

Definition at line 283 of file oc_channels.h.

#define oC_Channel_IsModuleDefined (   MODULE_NAME)

The macro checks if the module with the given name is defined. It can be used only in hash conditions. Example of usage:

#if !oC_Channel_IsModuleDefined(GPIO)
# error Module GPIO is not defined!
#endif

Definition at line 244 of file oc_channels.h.

#define oC_Channel_Register (   Channel,
  REGISTER_NAME 
)

The macro returns true if base address of the power register is configured for the given channel.

if(!oC_Channel_PowerBaseAddressExist(channel))
{
printf("Power base address is not set for the given channel. Enabling is not possible\n\r");
}
/
//==========================================================================================================================================
#define oC_Channel_PowerBaseAddressExist(Channel) (oC_PowerBaseAddress_Exist( oC_Channel_GetPowerBaseAddress(Channel) ) )
//==========================================================================================================================================
//==========================================================================================================================================
#define oC_Channel_PowerOffsetExist(Channel) (oC_PowerOffset_Exist( oC_Channel_GetPowerOffset(Channel) ) )
//==========================================================================================================================================
//==========================================================================================================================================
#define oC_Channel_PowerBitIndexExist(Channel) (oC_PowerBit_Exist( oC_Channel_GetPowerBitIndex(Channel) ) )
//==========================================================================================================================================

Definition at line 455 of file oc_channels.h.

#define oC_Channel_ToIndex (   MODULE_NAME,
  Channel 
)

The macro returns index of channel in the given module. Example of usage:

oC_Channel_t channel = oC_Channel_SPI0;
oC_ChannelIndex_t channelIndex = oC_Channel_ToIndex(SPI,channel);
printf("Channel %s is %d in the module SPI\n\r" , oC_Channel_GetName(channel) , channelIndex);
See also
oC_Channel_FromIndex

Definition at line 298 of file oc_channels.h.

#define oC_ChannelData_ (   CHANNEL_NAME)

The macro returns pointer to data from the oC_ChannelsData array for the given channel.

Parameters
CHANNEL_NAMEName of the channel from oc_channels_defs.h file

Example of usage:

printf("Found channel %s\n\r" , oC_ChannelData_(SPI0)->ChannelName);

Definition at line 229 of file oc_channels.h.

#define oC_ChannelEndIndex_ (   MODULE_NAME,
  ... 
)

This macro returns end index of channels for the given module. Channels are defined in the oC_Channel_t type. Each channel has it's own unique number (index) in the global array named oC_ChannelsData. Thanks to the index, it is possible to read data of the channel, such as register map, base address, power register data, etc.

Parameters
MODULE_NAMEName of module of channels

Example of usage:

while(channel < oC_ChannelEndIndex_(SPI))
{
printf("Found SPI channel %d\n\r" , channel);
}
See also
oC_ChannelStartIndex_ , oC_ModuleChannel_ , oC_Channel_Foreach

Definition at line 125 of file oc_channels.h.

#define oC_ChannelMask

This definition keep mask for the oC_Channel_t type. It has all bits taken by this type set. It is created using #oC_CHANNEL_MASK_WIDTH from the oc_channels_defs.h file.

Definition at line 62 of file oc_channels.h.

#define oC_ChannelStartIndex_ (   MODULE_NAME,
  ... 
)

This macro returns start index of channels for the given module. Channels are defined in the oC_Channel_t type. Each channel has it's own unique number (index) in the global array named oC_ChannelsData. Thanks to the index, it is possible to read data of the channel, such as register map, base address, power register data, etc.

Example of usage:

while(channel < oC_ChannelEndIndex_(SPI))
{
printf("Found SPI channel %d\n\r" , channel);
}
See also
oC_ChannelEndIndex_ , oC_ModuleChannel_ , oC_Channel_Foreach

Definition at line 100 of file oc_channels.h.

#define oC_ModuleChannel_ (   MODULE_NAME,
  CHANNEL_NAME,
  ... 
)

This macro returns channel of the module channel type. A module channels should be defined first by using oC_ModuleChannel_DefineType macro.

Parameters
MODULE_NAMEName of module of channels
CHANNEL_NAMEName of a channel from oc_channels_defs.h file

Definition at line 137 of file oc_channels.h.

#define oC_ModuleChannel_DefineType

The macro is for definition of channel type for the module. Require MODULE_NAME definition

Example of usage:

#define MODULE_NAME SPI
#undef MODULE_NAME
void main(void)
{
oC_SPI_Channel_t channel = oC_SPI_Channel_SPI0;
}

Definition at line 541 of file oc_channels.h.

#define oC_ModuleChannel_NumberOfElements (   MODULE_NAME)

Definition with number of channels in module channel type.

Definition at line 465 of file oc_channels.h.

Typedef Documentation

The type is for storing index of a channel in a module. For example, for the SPI1 channel, the channel index will be 1, and for UART1 it will be also 1.

Definition at line 597 of file oc_channels.h.

typedef void(* oC_ChannelInterruptHandler_t) (oC_Channel_t Channel)

The type is for storing special interrupt handler - common for each channel of a module. A parameter #Channel point to the channel, that cause the interrupt.

Parameters
ChannelInterrupt source
See also
oC_Channel_InterruptHandler

Definition at line 644 of file oc_channels.h.

Enumeration Type Documentation

The type is for storing machine channels. This type is generated from definitions in the oc_channels_defs.h file. The channel is an ID in global array with assigned base address and register map. This type is generic for all machine modules (UART,SPI,I2C,GPIO,etc) and each channel in this enum is different.

Definition at line 573 of file oc_channels.h.

Variable Documentation

const oC_ChannelData_t oC_ChannelsData[]

This is a global array, that stores data for each channel. Channels are indexes in the array.

See also
oC_ChannelData_t

Definition at line 33 of file oc_channels.c.