iLLD_TC27xC  1.0
IfxGtm_Trig.c
Go to the documentation of this file.
1 /**
2  * \file IfxGtm_Trig.c
3  * \brief GTM TRIG details
4  *
5  * \version iLLD_0_1_0_10
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 "IfxGtm_Trig.h"
30 #include "_Utilities/Ifx_Assert.h"
32 
33 /******************************************************************************/
34 /*-----------------------------Data Structures--------------------------------*/
35 /******************************************************************************/
36 
37 /** \addtogroup IfxLld_Gtm_Trig_Data_Structures
38  * \{ */
39 typedef struct
40 {
41  sint8 config; /**< \brief Value for SEL0/1. config=0xFF means "not available" */
43 
44 /** \} */
45 
46 /** \addtogroup IfxLld_Gtm_Trig_Data_Structures
47  * \{ */
48 typedef struct
49 {
52 
53 /** \} */
54 
55 /** \addtogroup IfxLld_Gtm_Trig_Data_Structures
56  * \{ */
57 typedef struct
58 {
61 
62 /** \} */
63 
64 /** \addtogroup IfxLld_Gtm_Trig_Data_Structures
65  * \{ */
66 typedef struct
67 {
70 
71 /** \} */
72 
73 /******************************************************************************/
74 /*------------------------Private Variables/Constants-------------------------*/
75 /******************************************************************************/
76 
77 static const IfxGtm_Trig_AdcTrig_Table IfxGtm_Trig_AdcTrig_tableAdc0_1_2 = {
78  .trigger = {
79  {.source = { //IfxGtm_AdcTrig_0
80  //{.channel = { {Channel_4 }, {Channel_5 }, {Channel_6 }, {Channel_7 }, {Channel_13 }, {Channel_14 }, {Channel_15 }}},
81  {.channel = { {.config = 0x05}, {.config = 0x06}, {.config = 0x07}, {.config = 0x08}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom0
82  {.channel = { {.config = 0x09}, {.config = 0x0A}, {.config = 0x0B}, {.config = 0x0C}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom1
83  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom2
84  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom3
85 
86  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom4
87  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0x01}, {.config = 0x02}, {.config = 0x03}, {.config = 0x04}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_tom0
88  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_tom1
89  }},
90  {.source = { //IfxGtm_AdcTrig_1
91  //{.channel = { {Channel_4 }, {Channel_5 }, {Channel_6 }, {Channel_7 }, {Channel_13 }, {Channel_14 }, {Channel_15 }}},
92  {.channel = { {.config = 0x0B}, {.config = 0x0C}, {.config = 0x0D}, {.config = 0x0E}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom0
93  {.channel = { {.config = 0x05}, {.config = 0x06}, {.config = 0x07}, {.config = 0x08}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom1
94  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom2
95  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom3
96 
97  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom4
98  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0x09}, {.config = 0x0A}}}, //IfxGtm_AdcTrigSource_tom0
99  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0x01}, {.config = 0x02}, {.config = 0x03}, {.config = 0x04}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_tom1
100  }}
101  }
102 };
103 
104 static const IfxGtm_Trig_AdcTrig_Table IfxGtm_Trig_AdcTrig_tableAdc3_4 = {
105  .trigger = {
106  {.source = { //IfxGtm_AdcTrig_0
107  // IfxGtm_AdcTrig
108  //{.channel = { {Channel_4 }, {Channel_5 }, {Channel_6 }, {Channel_7 }, {Channel_13 }, {Channel_14 }, {Channel_15 }}},
109  {.channel = { {.config = 0x05}, {.config = 0x06}, {.config = 0x07}, {.config = 0x08}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom0
110  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom1
111  {.channel = { {.config = 0x0B}, {.config = 0x0C}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom2
112  {.channel = { {.config = 0x0D}, {.config = 0x0E}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom3
113 
114  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom4
115  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0x01}, {.config = 0x02}, {.config = 0x03}, {.config = 0x04}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_tom0
116  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0x09}, {.config = 0x0A}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_tom1
117  }},
118  {.source = { //IfxGtm_AdcTrig_1
119  //{.channel = { {Channel_4 }, {Channel_5 }, {Channel_6 }, {Channel_7 }, {Channel_13 }, {Channel_14 }, {Channel_15 }}},
120  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom0
121  {.channel = { {.config = 0x05}, {.config = 0x06}, {.config = 0x07}, {.config = 0x08}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom1
122  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0x0B}, {.config = 0x0C}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom2
123  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0x0D}, {.config = 0x0E}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom3
124 
125  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom4
126  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_tom0
127  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0x01}, {.config = 0x02}, {.config = 0x03}, {.config = 0x04}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_tom1
128  }}
129  }
130 };
131 
132 static const IfxGtm_Trig_AdcTrig_Table IfxGtm_Trig_AdcTrig_tableAdc5_6_7 = {
133  .trigger = {
134  {.source = { //IfxGtm_AdcTrig_0
135  // IfxGtm_AdcTrig
136  //{.channel = { {Channel_4 }, {Channel_5 }, {Channel_6 }, {Channel_7 }, {Channel_13 }, {Channel_14 }, {Channel_15 }}},
137  {.channel = { {.config = 0x05}, {.config = 0x06}, {.config = 0x07 }, {.config = 0x08 }, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom0
138  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF }, {.config = 0xFF }, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom1
139  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF }, {.config = 0xFF }, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom2
140  {.channel = { {.config = 0x0D}, {.config = 0x0E}, {.config = 0xFF }, {.config = 0xFF }, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom3
141  {.channel = { {.config = 0x0B}, {.config = 0x0C}, {.config = 0xFF }, {.config = 0xFF }, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom4
142 
143  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0x01 /*0x09 */}, {.config = 0x02 /*0x0A */}, {.config = 0x03}, {.config = 0x04}, {.config = 0x0F}}}, //IfxGtm_AdcTrigSource_tom0
144  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF }, {.config = 0xFF }, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_tom1
145  }},
146  {.source = { //IfxGtm_AdcTrig_1
147  //{.channel = { {Channel_4 }, {Channel_5 }, {Channel_6 }, {Channel_7 }, {Channel_13 }, {Channel_14 }, {Channel_15 }}},
148  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF }, {.config = 0xFF }, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom0
149  {.channel = { {.config = 0x05}, {.config = 0x06}, {.config = 0x07 }, {.config = 0x08 }, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom1
150  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF }, {.config = 0xFF }, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom2
151  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0x0D }, {.config = 0x0E }, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom3
152  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0x0B }, {.config = 0x0C }, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom4
153 
154  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF }, {.config = 0xFF }, {.config = 0xFF}, {.config = 0x09}, {.config = 0x0A}}}, //IfxGtm_AdcTrigSource_tom0
155  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0x01 }, {.config = 0x02 }, {.config = 0x03}, {.config = 0x04}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_tom1
156  }}
157  }
158 };
159 
160 static const IfxGtm_Trig_AdcTrig_Table IfxGtm_Trig_AdcTrig_tableAdc8 = {
161  .trigger = {
162  {.source = { //IfxGtm_AdcTrig_0
163  // IfxGtm_AdcTrig
164  //{.channel = {{Channel_4 }, {Channel_5 }, {Channel_6 }, {Channel_7 }, {Channel_13 }, {Channel_14 }, {Channel_15 }}},
165  {.channel = { {.config = 0x05}, {.config = 0x06}, {.config = 0x07 }, {.config = 0xFF }, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom0
166  {.channel = { {.config = 0x0B}, {.config = 0x0C}, {.config = 0xFF }, {.config = 0xFF }, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom1
167  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF }, {.config = 0xFF }, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom2
168  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF }, {.config = 0xFF }, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom3
169  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF }, {.config = 0xFF }, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom4
170  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0x01 /*0x09 */}, {.config = 0x02 /*0x0A */}, {.config = 0x03}, {.config = 0x04}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_tom0
171  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF }, {.config = 0xFF }, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_tom1
172  }},
173  {.source = { //IfxGtm_AdcTrig_1
174  //{.channel = {{Channel_4 }, {Channel_5 }, {Channel_6 }, {Channel_7 }, {Channel_13 }, {Channel_14 }, {Channel_15 }}},
175  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF }, {.config = 0xFF }, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom0
176  {.channel = { {.config = 0x05}, {.config = 0x06}, {.config = 0x07 /*0x0B */}, {.config = 0x08 /*0x0C */}, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom1
177  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF }, {.config = 0xFF }, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom2
178  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF }, {.config = 0xFF }, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom3
179  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF }, {.config = 0xFF }, {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_atom4
180  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0xFF }, {.config = 0xFF }, {.config = 0xFf}, {.config = 0x09}, {.config = 0x0A}}}, //IfxGtm_AdcTrigSource_tom0
181  {.channel = { {.config = 0xFF}, {.config = 0xFF}, {.config = 0x01 }, {.config = 0x02 }, {.config = 0x03}, {.config = 0x04}, {.config = 0xFF}}}, //IfxGtm_AdcTrigSource_tom1
182  }}
183  }
184 };
185 
186 /******************************************************************************/
187 /*-------------------------Function Implementations---------------------------*/
188 /******************************************************************************/
189 
190 boolean IfxGtm_Trig_fromDsadc(Ifx_GTM *gtm, uint32 dsadcChannel, IfxGtm_Tim tim, IfxGtm_Tim_Ch timChannel)
191 {
192  boolean result = __checkrange(dsadcChannel, 0, 5);
193 
194  result &= __checkrange(timChannel, IfxGtm_Tim_Ch_0, IfxGtm_Tim_Ch_5);
195 
196  if (result != FALSE)
197  {
198  uint32 mask = 0xFU << (timChannel * 4);
199  __ldmst_c(&(gtm->INOUTSEL.DSADC.INSEL[tim].U), mask, dsadcChannel << (timChannel * 4));
200  }
201 
202  return result;
203 }
204 
205 
206 void IfxGtm_Trig_toDsadc(Ifx_GTM *gtm, uint32 dsadcChannel, IfxGtm_Trig_DsadcTrig dsadcTrig, IfxGtm_Trig_DsadcTrigSource sel)
207 {
208  uint32 mask = 0xFU << (dsadcChannel * 4);
209 
210  switch (dsadcTrig)
211  {
213  __ldmst_c(&(gtm->INOUTSEL.DSADC.OUTSEL00.U), mask, sel << (dsadcChannel * 4));
214  break;
216  __ldmst_c(&(gtm->INOUTSEL.DSADC.OUTSEL10.U), mask, sel << (dsadcChannel * 4));
217  break;
218  }
219 }
220 
221 
223 {
225  uint8 config;
226 
227  boolean result;
228 
229  switch (adcGroup)
230  {
234  table = &IfxGtm_Trig_AdcTrig_tableAdc0_1_2;
235  break;
238  table = &IfxGtm_Trig_AdcTrig_tableAdc3_4;
239  break;
243  table = &IfxGtm_Trig_AdcTrig_tableAdc5_6_7;
244  break;
246  table = &IfxGtm_Trig_AdcTrig_tableAdc8;
247  break;
248  }
249 
250  if (table != NULL_PTR)
251  {
252  config = table->trigger[adcTrig].source[source].channel[channel].config;
253  result = config != 0xFF;
254  uint32 mask = 0xFU << (adcGroup * 4);
255 
256  if (adcGroup < IfxGtm_Trig_AdcGroup_8)
257  {
258  switch (adcTrig)
259  {
261  __ldmst_c(&(gtm->ADCTRIG0OUT0.U), mask, config << (adcGroup * 4));
262  break;
264  __ldmst_c(&(gtm->ADCTRIG1OUT0.U), mask, config << (adcGroup * 4));
265  break;
266  default:
267  result = FALSE;
268  break;
269  }
270  }
271  else if (adcGroup >= IfxGtm_Trig_AdcGroup_8)
272  {
273  switch (adcTrig)
274  {
276  __ldmst_c(&(gtm->ADCTRIG0OUT1.U), mask, config << (adcGroup * 4));
277  break;
279  __ldmst_c(&(gtm->ADCTRIG1OUT1.U), mask, config << (adcGroup * 4));
280  break;
281  default:
282  result = FALSE;
283  break;
284  }
285  }
286  else
287  {
288  result = FALSE;
289  }
290  }
291  else
292  {
293  result = FALSE;
294  }
295 
297 
298  return result;
299 }