iLLD_TC27xD  1.0
IfxDma_Dma.c
Go to the documentation of this file.
1 /**
2  * \file IfxDma_Dma.c
3  * \brief DMA DMA details
4  *
5  * \version iLLD_1_0_0_11_0
6  * \copyright Copyright (c) 2013 Infineon Technologies AG. All rights reserved.
7  *
8  *
9  * IMPORTANT NOTICE
10  *
11  *
12  * Infineon Technologies AG (Infineon) is supplying this file for use
13  * exclusively with Infineon's microcontroller products. This file can be freely
14  * distributed within development tools that are supporting such microcontroller
15  * products.
16  *
17  * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
18  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
19  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
20  * INFINEON SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
21  * OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
22  *
23  */
24 
25 /******************************************************************************/
26 /*----------------------------------Includes----------------------------------*/
27 /******************************************************************************/
28 
29 #include "IfxDma_Dma.h"
30 
31 /******************************************************************************/
32 /*-----------------------Private Function Prototypes--------------------------*/
33 /******************************************************************************/
34 
35 /** \brief local function to copy a transaction set into DMA channel SFRs or memory location (for linked lists)
36  * \param channel Specifies the pointer to DMA channel registers
37  * \param config pointer to the DMA default channel configuration structure
38  * \return None
39  */
40 static void IfxDma_Dma_configureTransactionSet(Ifx_DMA_CH *channel, const IfxDma_Dma_ChannelConfig *config);
41 
42 /******************************************************************************/
43 /*-------------------------Function Implementations---------------------------*/
44 /******************************************************************************/
45 
46 static void IfxDma_Dma_configureTransactionSet(Ifx_DMA_CH *channel, const IfxDma_Dma_ChannelConfig *config)
47 {
48  {
49  Ifx_DMA_CH_CHCFGR chcfgr;
50  chcfgr.U = 0;
51  chcfgr.B.TREL = config->transferCount;
52  chcfgr.B.BLKM = config->blockMode;
53  chcfgr.B.RROAT = config->requestMode;
54  chcfgr.B.CHMODE = config->operationMode;
55  chcfgr.B.CHDW = config->moveSize;
56  chcfgr.B.PRSEL = config->requestSource;
57  chcfgr.B.PATSEL = config->pattern;
58 
59  channel->CHCFGR.U = chcfgr.U;
60  }
61 
62  {
63  Ifx_DMA_CH_ADICR adicr;
64  adicr.U = 0;
65  adicr.B.SMF = config->sourceAddressIncrementStep;
66  adicr.B.INCS = config->sourceAddressIncrementDirection;
67  adicr.B.CBLS = config->sourceAddressCircularRange;
68  adicr.B.SCBE = config->sourceCircularBufferEnabled;
69  adicr.B.DMF = config->destinationAddressIncrementStep;
70  adicr.B.INCD = config->destinationAddressIncrementDirection;
71  adicr.B.CBLD = config->destinationAddressCircularRange;
72  adicr.B.DCBE = config->destinationCircularBufferEnabled;
73  adicr.B.SHCT = config->shadowControl;
74  adicr.B.STAMP = config->timestampEnabled;
75  adicr.B.WRPSE = config->wrapSourceInterruptEnabled;
76  adicr.B.WRPDE = config->wrapDestinationInterruptEnabled;
77  adicr.B.INTCT = (config->channelInterruptEnabled ? 2 : 0) | (config->channelInterruptControl ? 1 : 0);
78  adicr.B.IRDV = config->interruptRaiseThreshold;
79  adicr.B.ETRL = config->transactionRequestLostInterruptEnabled;
80  //enter also the circular buffer enable bits
81 
82  channel->ADICR.U = adicr.U;
83  }
84 
85  channel->SADR.U = config->sourceAddress;
86  channel->DADR.U = config->destinationAddress;
87  channel->SDCRCR.U = config->sourceDestinationAddressCrc;
88  channel->RDCRCR.U = config->readDataCrc;
89 
90  // write not allowed if SHCT=1 or SHCT=2
91  if ((config->shadowControl != IfxDma_ChannelShadow_none) &&
94  {
95  channel->SHADR.U = config->shadowAddress;
96  }
97 }
98 
99 
100 void IfxDma_Dma_createModuleHandle(IfxDma_Dma *dmaHandle, Ifx_DMA *dma)
101 {
102  dmaHandle->dma = dma;
103 }
104 
105 
107 {
108  //TODO
109 }
110 
111 
113 {
114  Ifx_DMA *dma = config->module->dma;
115 
116  channel->dma = dma;
117  channel->channelId = config->channelId;
118  channel->channel = &dma->CH[config->channelId];
119 
120  IfxDma_Dma_configureTransactionSet(channel->channel, config);
121 
122  {
123  Ifx_DMA_TSR tsr;
124  tsr.U = 0;
125 
126  if (config->hardwareRequestEnabled)
127  {
128  tsr.B.ECH = 1;
129  }
130  else
131  {
132  tsr.B.DCH = 1;
133  }
134 
135  dma->TSR[channel->channelId].U = tsr.U;
136  }
137 
138  if (config->channelInterruptPriority > 0)
139  {
140  volatile Ifx_SRC_SRCR *src = IfxDma_getSrcPointer(channel->dma, channel->channelId);
142  IfxSrc_enable(src);
143  }
144 }
145 
146 
148 {
149  const IfxDma_Dma_ChannelConfig defaultConfig = {
150  .module = NULL_PTR,
151  .channelId = IfxDma_ChannelId_0,
152  .sourceAddress = 0,
153  .destinationAddress = 0,
154  .shadowAddress = 0,
155  .readDataCrc = 0,
156  .sourceDestinationAddressCrc = 0,
157  .transferCount = 0,
158  .blockMode = IfxDma_ChannelMove_1,
160  .operationMode = IfxDma_ChannelOperationMode_single,
161  .moveSize = IfxDma_ChannelMoveSize_8bit,
164  .busPriority = IfxDma_ChannelBusPriority_medium,
165  .hardwareRequestEnabled = FALSE,
166  .sourceAddressIncrementStep = IfxDma_ChannelIncrementStep_1,
167  .sourceAddressIncrementDirection = IfxDma_ChannelIncrementDirection_positive,
168  .sourceAddressCircularRange = IfxDma_ChannelIncrementCircular_32768,
169  .destinationAddressIncrementStep = IfxDma_ChannelIncrementStep_1,
170  .destinationAddressIncrementDirection = IfxDma_ChannelIncrementDirection_positive,
171  .destinationAddressCircularRange = IfxDma_ChannelIncrementCircular_32768,
172  .shadowControl = IfxDma_ChannelShadow_none,
173  .sourceCircularBufferEnabled = FALSE,
174  .destinationCircularBufferEnabled = FALSE,
175  .timestampEnabled = FALSE,
176  .wrapSourceInterruptEnabled = FALSE,
177  .wrapDestinationInterruptEnabled = FALSE,
178  .channelInterruptEnabled = FALSE,
179  .channelInterruptControl = IfxDma_ChannelInterruptControl_thresholdLimitMatch,
180  .interruptRaiseThreshold = 0,
181  .transactionRequestLostInterruptEnabled = FALSE,
182  .channelInterruptPriority = 0,
183  .channelInterruptTypeOfService = IfxSrc_Tos_cpu0
184  };
185 
186  /* Default Configuration */
187  *config = defaultConfig;
188 
189  /* take over module pointer */
190  config->module = dma;
191 }
192 
193 
194 void IfxDma_Dma_initLinkedListEntry(void *ptrToAddress, const IfxDma_Dma_ChannelConfig *config)
195 {
196  IfxDma_Dma_configureTransactionSet((Ifx_DMA_CH *)ptrToAddress, config);
197 }
198 
199 
201 {
202  dma->dma = config->dma;
203 }
204 
205 
207 {
208  config->dma = dma;
209 }