31 #include <oc_gpio_mslld.h> 32 #include <oc_machine_defs.h> 44 #define _________________________________________MACROS_SECTION_____________________________________________________________________________ 46 #define ControlTableEntry(ChannelIndex) ((ControlTableEntry_t*)ControlTable)[ChannelIndex] 47 #define AlternateControlTableEntry(ChannelIndex) ((ControlTableEntry_t*)ControlTable)[oC_DMA_LLD_ChannelIndex_NumberOfElements + ChannelIndex] 49 #define DMACFG(Channel) oC_Machine_Register(Channel,DMACFG) 50 #define DMACHMAP0(Channel) oC_Machine_Register(Channel,DMACHMAP0) 51 #define DMACHMAP1(Channel) oC_Machine_Register(Channel,DMACHMAP1) 52 #define DMACHMAP2(Channel) oC_Machine_Register(Channel,DMACHMAP2) 53 #define DMACHMAP3(Channel) oC_Machine_Register(Channel,DMACHMAP3) 55 #define DMASWREQ(Channel) oC_Machine_Register(Channel,DMASWREQ) 56 #define DMAENACLR(Channel) oC_Machine_Register(Channel,DMAENACLR) 57 #define DMAENASET(Channel) oC_Machine_Register(Channel,DMAENASET) 58 #define DMAPRIOSET(Channel) oC_Machine_Register(Channel,DMAPRIOSET) 59 #define DMAPRIOCLR(Channel) oC_Machine_Register(Channel,DMAPRIOCLR) 60 #define DMAALTCLR(Channel) oC_Machine_Register(Channel,DMAALTCLR) 61 #define DMAUSEBURSTCLR(Channel) oC_Machine_Register(Channel,DMAUSEBURSTCLR) 62 #define DMAREQMASKCLR(Channel) oC_Machine_Register(Channel,DMAREQMASKCLR) 63 #define DMACHIS(Channel) oC_Machine_Register(Channel,DMACHIS) 68 #define IsEventHandlerCorrect(Pointer) (oC_MEM_LLD_IsFlashAddress(Pointer) || oC_MEM_LLD_IsRamAddress(Pointer) || (Pointer == NULL) ) 70 #undef _________________________________________MACROS_SECTION_____________________________________________________________________________ 78 #define _________________________________________LOCAL_TYPES_SECTION________________________________________________________________________ 87 TransferMode_Stop = 0x0 ,
88 TransferMode_Basic = 0x1 ,
89 TransferMode_AutoRequest = 0x2 ,
90 TransferMode_PingPong = 0x3 ,
91 TransferMode_MemoryScatterGather = 0x4 ,
92 TransferMode_AlternateMemoryScatterGather = 0x5 ,
93 TransferMode_PeripheralScatterGather = 0x6 ,
94 TransferMode_AlternatePeripheralScatterGather = 0x7
105 DataSize_HalfWord = 1 ,
116 IncrementSize_Byte = 0 ,
117 IncrementSize_HalfWord = 1 ,
118 IncrementSize_Word = 2 ,
119 IncrementSize_NoIcrement = 3
129 ArbitrationSize_1Transfer = 0x0 ,
130 ArbitrationSize_2Transfers = 0x1 ,
131 ArbitrationSize_4Transfers = 0x2 ,
132 ArbitrationSize_8Transfers = 0x3 ,
133 ArbitrationSize_16Transfers = 0x4 ,
134 ArbitrationSize_32Transfers = 0x5 ,
135 ArbitrationSize_64Transfers = 0x6 ,
136 ArbitrationSize_128Transfers = 0x7 ,
137 ArbitrationSize_256Transfers = 0x8 ,
138 ArbitrationSize_512Transfers = 0x9 ,
139 ArbitrationSize_1024Transfers = 0xA ,
149 NextUseBurst_DontUse ,
164 oC_UInt_t XFERMODE:3;
165 oC_UInt_t NXTUSEBURST:1;
166 oC_UInt_t XFERSIZE:10;
168 oC_UInt_t __reserved_18_23:6;
179 void * SourceEndPointer;
180 void * DestinationEndPointer;
185 #undef _________________________________________LOCAL_TYPES_SECTION________________________________________________________________________ 192 #define _________________________________________LOCAL_PROTOTYPES_SECTION___________________________________________________________________ 194 static void ConfigureControlWord(
196 TransferMode_t TransferMode ,
197 IncrementSize_t DestinationIncrement ,
198 DataSize_t DestinationSize ,
199 IncrementSize_t SourceIncrement ,
200 DataSize_t SourceSize ,
201 ArbitrationSize_t ArbitrationSize ,
203 NextUseBurst_t NextUseBurst
206 static inline bool IsNumberOfTransfersCorrect( oC_UInt_t NumberOfTransfers );
210 #undef _________________________________________LOCAL_PROTOTYPES_SECTION___________________________________________________________________ 218 #define _________________________________________CONSTANT_SECTION___________________________________________________________________________ 221 #undef _________________________________________CONSTANT_SECTION___________________________________________________________________________ 229 #define _________________________________________LOCAL_VARIABLES_SECTION___________________________________________________________________ 234 static oC_UInt_t ControlTable[1024] __attribute__ ((aligned(1024)));
236 #undef _________________________________________LOCAL_VARIABLES_SECTION___________________________________________________________________ 243 #define _________________________________________INTERFACE_SECTION__________________________________________________________________________ 251 oC_ErrorCode_t oC_DMA_LLD_TurnOnDriver(
void )
253 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
256 oC_AssignErrorCodeIfFalse(&errorCode , !
ModuleEnabledFlag , oC_ErrorCode_ModuleIsTurnedOn ) &&
257 oC_AssignErrorCodeIfFalse(&errorCode , oC_Channel_EnableInterrupt( oC_DMA_Channel_uDMA0 , Software), oC_ErrorCode_CannotEnableInterrupt)
260 oC_DMA_LLD_ForeachChannel(Channel)
262 oC_DMA_LLD_RestoreDefaultStateOnChannel(Channel);
266 errorCode = oC_ErrorCode_None;
278 oC_ErrorCode_t oC_DMA_LLD_TurnOffDriver(
void )
280 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
283 oC_AssignErrorCodeIfFalse(&errorCode ,
ModuleEnabledFlag , oC_ErrorCode_ModuleNotStartedYet )
289 oC_DMA_LLD_ForeachChannel(Channel)
292 ChannelUsedArray[channelIndex] =
true;
296 DMACFG(oC_DMA_Channel_uDMA0)->MASTEN = 0;
298 oC_Channel_DisableInterrupt( oC_DMA_Channel_uDMA0 , Software );
300 errorCode = oC_ErrorCode_None;
312 bool oC_DMA_LLD_IsChannelAvailable( oC_DMA_Channel_t Channel )
323 void oC_DMA_LLD_RestoreDefaultStateOnChannel( oC_DMA_Channel_t Channel )
332 ControlTableEntry(channelIndex).ControlWord.Data = 0;
349 bool registerMapSupported =
false;
359 registerMapSupported =
true;
360 oC_ARRAY_FOREACH_BREAK(DmaChannelAssignmentsArray);
364 return registerMapSupported;
373 bool oC_DMA_LLD_IsSoftwareTradeSupportedOnDmaChannel( oC_DMA_Channel_t DmaChannel )
375 bool softwareTradeSupported =
false;
384 softwareTradeSupported =
true;
385 oC_ARRAY_FOREACH_BREAK(DmaChannelAssignmentsArray);
389 return softwareTradeSupported;
398 bool oC_DMA_LLD_DoesDmaHasAccessToAddress( oC_DMA_Channel_t Channel ,
const void * Address )
409 oC_ErrorCode_t oC_DMA_LLD_ConfigureSoftwareTrade( oC_DMA_Channel_t Channel ,
const oC_DMA_LLD_SoftwareTradeConfig_t * Config )
411 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
416 oC_AssignErrorCodeIfFalse(&errorCode ,
ModuleEnabledFlag , oC_ErrorCode_ModuleNotStartedYet) &&
417 oC_AssignErrorCodeIfFalse(&errorCode ,
oC_Channel_IsCorrect(DMA,Channel), oC_ErrorCode_WrongChannel ) &&
418 oC_AssignErrorCodeIfFalse(&errorCode , ChannelUsedArray[channelIndex] ==
false, oC_ErrorCode_ChannelIsUsed ) &&
419 oC_AssignErrorCodeIfFalse(&errorCode , dmaChannelAssignment != 0, oC_ErrorCode_DMASoftwareTransferNotPossibleOnThisChannel) &&
421 oC_AssignErrorCodeIfFalse(&errorCode , IsEventHandlerCorrect(Config->TransferCompleteEventHandler) , oC_ErrorCode_WrongEventHandlerAddress ) &&
422 oC_AssignErrorCodeIfFalse(&errorCode , oC_DMA_LLD_DoesDmaHasAccessToAddress(Channel,Config->Source) , oC_ErrorCode_DMAAddressNotHandledByDma ) &&
423 oC_AssignErrorCodeIfFalse(&errorCode , oC_DMA_LLD_DoesDmaHasAccessToAddress(Channel,Config->Destination) , oC_ErrorCode_DMAAddressNotHandledByDma ) &&
424 oC_AssignErrorCodeIfFalse(&errorCode , Config->ElementSize <= oC_DMA_LLD_ElementSize_Word , oC_ErrorCode_DMAElementSizeNotCorrect) &&
425 oC_AssignErrorCodeIfFalse(&errorCode , IsNumberOfTransfersCorrect(Config->BufferSize/(1<<Config->ElementSize)), oC_ErrorCode_SizeNotCorrect) &&
426 oC_AssignErrorCodeIfFalse(&errorCode , oC_DMA_LLD_IsSoftwareTradeSupportedOnDmaChannel(Channel) , oC_ErrorCode_DMASoftwareTransferNotPossibleOnThisChannel) &&
430 oC_UInt_t numberOfTransfers = Config->BufferSize/(1<<Config->ElementSize);
431 IncrementSize_t incrementSize = (numberOfTransfers > 1) ? Config->ElementSize : IncrementSize_NoIcrement;
433 ChannelUsedArray[channelIndex] =
true;
435 DMACFG(Channel)->MASTEN = 1;
438 if(Config->Priority == oC_DMA_LLD_Priority_High)
451 ControlTableEntry(channelIndex).SourceEndPointer = (
void*)((oC_UInt_t)Config->Source + Config->BufferSize - (1<<Config->ElementSize));
452 ControlTableEntry(channelIndex).DestinationEndPointer = (
void*)((oC_UInt_t)Config->Destination + Config->BufferSize - (1<<Config->ElementSize));
454 ConfigureControlWord(&ControlTableEntry(channelIndex),
455 TransferMode_AutoRequest ,
457 Config->ElementSize ,
459 Config->ElementSize ,
460 ArbitrationSize_1Transfer ,
465 EventHandlersArray[channelIndex] = Config->TransferCompleteEventHandler;
471 DMACHMAP = (uint32_t*)&DMACHMAP0(Channel)->Value;
473 else if(channelIndex < 16)
475 DMACHMAP = (uint32_t*)&DMACHMAP1(Channel)->Value;
477 else if(channelIndex < 24)
479 DMACHMAP = (uint32_t*)&DMACHMAP2(Channel)->Value;
483 DMACHMAP = (uint32_t*)&DMACHMAP3(Channel)->Value;
490 (channelIndex+1) * 4 - 1);
496 errorCode = oC_ErrorCode_None;
508 oC_ErrorCode_t oC_DMA_LLD_ConfigurePeripheralTrade( oC_DMA_Channel_t Channel ,
const oC_DMA_LLD_PeripheralTradeConfig_t * Config )
510 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
515 oC_AssignErrorCodeIfFalse(&errorCode ,
ModuleEnabledFlag , oC_ErrorCode_ModuleNotStartedYet) &&
516 oC_AssignErrorCodeIfFalse(&errorCode ,
oC_Channel_IsCorrect(DMA,Channel) , oC_ErrorCode_WrongChannel ) &&
517 oC_AssignErrorCodeIfFalse(&errorCode , ChannelUsedArray[channelIndex] ==
false, oC_ErrorCode_ChannelIsUsed ) &&
519 oC_AssignErrorCodeIfFalse(&errorCode , dmaChannelAssignment != 0, oC_ErrorCode_DMAPeripheralTransferNotPossibleOnThisChannel) &&
520 oC_AssignErrorCodeIfFalse(&errorCode , IsEventHandlerCorrect(Config->TransferCompleteEventHandler) , oC_ErrorCode_WrongEventHandlerAddress ) &&
521 oC_AssignErrorCodeIfFalse(&errorCode , oC_DMA_LLD_DoesDmaHasAccessToAddress(Channel,Config->Buffer) , oC_ErrorCode_DMAAddressNotHandledByDma ) &&
522 oC_AssignErrorCodeIfFalse(&errorCode , Config->ElementSize <= oC_DMA_LLD_ElementSize_Word , oC_ErrorCode_DMAElementSizeNotCorrect) &&
523 oC_AssignErrorCodeIfFalse(&errorCode , Config->TransmitDirection <= oC_DMA_LLD_Direction_Receive , oC_ErrorCode_DMATransmitDirectionNotCorrect) &&
524 oC_AssignErrorCodeIfFalse(&errorCode , IsNumberOfTransfersCorrect(Config->BufferSize/(1<<Config->ElementSize)), oC_ErrorCode_DMABufferSizeMustBePowerOf2) &&
525 oC_AssignErrorCodeIfFalse(&errorCode , oC_DMA_LLD_IsSoftwareTradeSupportedOnDmaChannel(Channel) , oC_ErrorCode_DMASoftwareTransferNotPossibleOnThisChannel) &&
529 oC_UInt_t numberOfTransfers = Config->BufferSize/(1<<Config->ElementSize);
530 IncrementSize_t sourceIncrementSize = (numberOfTransfers > 1) ? Config->ElementSize : IncrementSize_NoIcrement;
531 IncrementSize_t destinationIncrementSize= (numberOfTransfers > 1) ? Config->ElementSize : IncrementSize_NoIcrement;
533 ChannelUsedArray[channelIndex] =
true;
535 DMACFG(Channel)->MASTEN = 1;
538 if(Config->Priority == oC_DMA_LLD_Priority_High)
551 if(Config->TransmitDirection == oC_DMA_LLD_Direction_Transmit)
553 ControlTableEntry(channelIndex).SourceEndPointer = (
void*)((oC_UInt_t)Config->Buffer + Config->BufferSize - (1<<Config->ElementSize));
554 ControlTableEntry(channelIndex).DestinationEndPointer = Config->PeripheralData;
555 destinationIncrementSize = IncrementSize_NoIcrement;
559 ControlTableEntry(channelIndex).SourceEndPointer = Config->PeripheralData;
560 ControlTableEntry(channelIndex).DestinationEndPointer = (
void*)((oC_UInt_t)Config->Buffer + Config->BufferSize - (1<<Config->ElementSize));
561 sourceIncrementSize = IncrementSize_NoIcrement;
565 ConfigureControlWord(&ControlTableEntry(channelIndex),
567 destinationIncrementSize,
568 Config->ElementSize ,
569 sourceIncrementSize ,
570 Config->ElementSize ,
571 ArbitrationSize_1Transfer ,
576 EventHandlersArray[channelIndex] = Config->TransferCompleteEventHandler;
582 DMACHMAP = (uint32_t*)&DMACHMAP0(Channel)->Value;
584 else if(channelIndex < 16)
586 DMACHMAP = (uint32_t*)&DMACHMAP1(Channel)->Value;
588 else if(channelIndex < 24)
590 DMACHMAP = (uint32_t*)&DMACHMAP2(Channel)->Value;
594 DMACHMAP = (uint32_t*)&DMACHMAP3(Channel)->Value;
601 (channelIndex+1) * 4 - 1);
607 errorCode = oC_ErrorCode_None;
619 bool oC_DMA_LLD_IsTransferCompleteOnChannel( oC_DMA_Channel_t Channel )
632 oC_ErrorCode_t oC_DMA_LLD_ReadChannelUsedReference( oC_DMA_Channel_t Channel ,
bool ** outChannelUsedFlag )
634 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
637 oC_AssignErrorCodeIfFalse(&errorCode ,
ModuleEnabledFlag , oC_ErrorCode_ModuleNotStartedYet) &&
638 oC_AssignErrorCodeIfFalse(&errorCode ,
oC_Channel_IsCorrect(DMA,Channel), oC_ErrorCode_WrongChannel ) &&
639 oC_AssignErrorCodeIfFalse(&errorCode ,
oC_MEM_LLD_IsRamAddress(outChannelUsedFlag), oC_ErrorCode_OutputAddressNotInRAM )
644 *outChannelUsedFlag = &ChannelUsedArray[channelIndex];
646 errorCode = oC_ErrorCode_None;
660 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
663 oC_AssignErrorCodeIfFalse(&errorCode ,
ModuleEnabledFlag , oC_ErrorCode_ModuleNotStartedYet)
666 errorCode = oC_ErrorCode_NoChannelAvailable;
676 errorCode = oC_ErrorCode_None;
685 #undef _________________________________________INTERFACE_SECTION__________________________________________________________________________ 693 #define _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________ 700 static void ConfigureControlWord(
702 TransferMode_t TransferMode ,
703 IncrementSize_t DestinationIncrement ,
704 DataSize_t DestinationSize ,
705 IncrementSize_t SourceIncrement ,
706 DataSize_t SourceSize ,
707 ArbitrationSize_t ArbitrationSize ,
709 NextUseBurst_t NextUseBurst
712 Entry->ControlWord.XFERMODE = TransferMode;
713 Entry->ControlWord.NXTUSEBURST = NextUseBurst;
714 Entry->ControlWord.XFERSIZE = TransferSize - 1;
715 Entry->ControlWord.ARBSIZE = ArbitrationSize;
716 Entry->ControlWord.SRCSIZE = SourceSize;
717 Entry->ControlWord.SRCINC = SourceIncrement;
718 Entry->ControlWord.DSTSIZE = DestinationSize;
719 Entry->ControlWord.DSTINC = DestinationIncrement;
727 static inline bool IsNumberOfTransfersCorrect( oC_UInt_t NumberOfTransfers )
729 return (NumberOfTransfers > 0) && (NumberOfTransfers <= 1024);
748 channelAssignment = *DmaChannelAssignment;
749 oC_ARRAY_FOREACH_BREAK(DmaChannelAssignmentsArray);
753 return channelAssignment;
773 channelAssignment = *DmaChannelAssignment;
774 oC_ARRAY_FOREACH_BREAK(DmaChannelAssignmentsArray);
778 return channelAssignment;
781 #undef _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________ 788 #define _________________________________________LOCAL_INTERRUPTS_SECTION___________________________________________________________________ 806 oC_Bits_SetBitU32( (uint32_t*) &DMACHIS(oC_DMA_Channel_uDMA0)->Value, channelIndex );
809 if(EventHandlersArray[channelIndex])
811 EventHandlersArray[channelIndex](channel);
813 oC_DMA_LLD_RestoreDefaultStateOnChannel(channel);
818 #undef _________________________________________LOCAL_INTERRUPTS_SECTION___________________________________________________________________ #define oC_InterruptHandler(BASE_NAME, TYPE_NAME)
Define handler for interrupt.
oC_Machine_DmaSignalType_t
type with DMA signal types
static bool ModuleEnabledFlag
#define oC_Machine_DmaChannelAssignment_GetChannel(Assignment)
returns channel from oC_Machine_DmaChannelAssignment_t type
#define oC_Machine_DmaChannelAssignment_GetDmaSignalType(Assignment)
returns DMA signal type from oC_Machine_DmaChannelAssignment_t type
static uint32_t oC_Bits_SetValueU32(uint32_t *outVariable, uint32_t Value, uint8_t StartBitNr, uint8_t EndBitNr)
#define oC_Machine_ReadRegister(Channel, REGISTER_NAME)
redefinition of oC_Machine_ReadRegisterDirectStaticOffset
bool oC_MEM_LLD_IsFlashAddress(const void *Address)
checks if the pointer is in flash section
The file with LLD interface for the MEM driver.
#define oC_Machine_WriteRegister(Channel, REGISTER_NAME, Value)
redefinition of oC_Machine_WriteRegisterDirectStaticOffset
#define oC_Machine_DmaChannelAssignment_GetDmaChannel(Assignment)
returns DMA channel from oC_Machine_DmaChannelAssignment_t type
oC_Machine_DmaChannelAssignment_t
type for storing assignment of DMA channels
uint16_t oC_uint16_t
type for 16 bit unsigned integer
Something is powered off.
The file with LLD interface for the CLOCK driver.
oC_Channel_t
stores machine channel
static int8_t oC_Bits_GetBitNumberU32(uint32_t BitMask)
#define oC_Channel_IsCorrect(MODULE_NAME, Channel)
checks if channel is correct
#define oC_ModuleChannel_NumberOfElements(MODULE_NAME)
Number of elements in module channel.
The file with functions for the bits operation.
#define oC_Machine_DmaChannelAssignment_GetDmaEncodingValue(Assignment)
returns DMA encoding value from oC_Machine_DmaChannelAssignment_t type
Static array definitions.
The file with interface for the machine module.
#define oC_Channel_ToIndex(MODULE_NAME, Channel)
returns index in module according to channel
static uint32_t oC_Bits_SetBitU32(uint32_t *outVariable, uint8_t BitIndex)
sets bit in the variable
The file with LLD interface for the DMA driver.
static bool oC_Machine_SetPowerStateForChannel(oC_Channel_t Channel, oC_Power_t Power)
configures power state for machine channel
bool oC_MEM_LLD_IsRamAddress(const void *Address)
checks if the pointer is in ram section
#define NULL
pointer to a zero
const oC_Machine_DmaChannelAssignment_t oC_DmaChannelAssignments[oC_Machine_DmaChannelAssignmentIndex_NumberOfElements]
array with DMA channel assignments
static uint32_t oC_Bits_ClearBitU32(uint32_t *outVariable, uint8_t BitIndex)
clear selected bit