iLLD_TC29x  1.0
IfxStm.c
Go to the documentation of this file.
1 /**
2  * \file IfxStm.c
3  * \brief STM basic functionality
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 "IfxStm.h"
30 
31 /******************************************************************************/
32 /*-------------------------Function Implementations---------------------------*/
33 /******************************************************************************/
34 
35 void IfxStm_clearCompareFlag(Ifx_STM *stm, IfxStm_Comparator comparator)
36 {
37  if (comparator == IfxStm_Comparator_0)
38  {
39  stm->ISCR.B.CMP0IRR = 1U;
40  }
41  else if (comparator == IfxStm_Comparator_1)
42  {
43  stm->ISCR.B.CMP1IRR = 1U;
44  }
45 }
46 
47 
48 void IfxStm_enableOcdsSuspend(Ifx_STM *stm)
49 {
50  Ifx_STM_OCS ocs = stm->OCS;
51 
52  ocs.B.SUS_P = 1;
53  ocs.B.SUS = 2;
54  stm->OCS = ocs;
55  stm->OCS.B.SUS_P = 0;
56 }
57 
58 
60 {
61  uint32 index;
62  IfxStm_ResourceStm result;
63 
64  result = IfxStm_ResourceStm_none;
65 
66  for (index = 0; index < IFXSTM_NUM_MODULES; index++)
67  {
68  if (IfxStm_cfg_indexMap[index].module == stm)
69  {
70  result = IfxStm_cfg_indexMap[index].index;
71  break;
72  }
73  }
74 
75  return result;
76 }
77 
78 
79 boolean IfxStm_initCompare(Ifx_STM *stm, const IfxStm_CompareConfig *config)
80 {
81  sint32 index;
82  boolean result;
83  Ifx_STM_CMCON comcon = stm->CMCON;
84  Ifx_STM_ICR icr = stm->ICR;
85 
86  if (config->comparator == 0)
87  {
88  comcon.B.MSIZE0 = config->compareSize;
89  comcon.B.MSTART0 = config->compareOffset;
90  icr.B.CMP0OS = config->comparatorInterrupt;
91  result = TRUE;
92  }
93  else if (config->comparator == 1)
94  {
95  comcon.B.MSIZE1 = config->compareSize;
96  comcon.B.MSTART1 = config->compareOffset;
97  icr.B.CMP1OS = config->comparatorInterrupt;
98  result = TRUE;
99  }
100  else
101  {
102  /*Invalid value */
103  result = FALSE;
104  }
105 
106  stm->ICR.U = icr.U;
107  stm->CMCON.U = comcon.U;
108 
109  /* configure interrupt */
110  index = IfxStm_getIndex(stm);
111 
112  if (config->triggerPriority > 0)
113  {
114  volatile Ifx_SRC_SRCR *srcr;
115 
117  {
118  srcr = &(MODULE_SRC.STM.STM[index].SR0);
119  }
120  else
121  {
122  srcr = &(MODULE_SRC.STM.STM[index].SR1);
123  }
124 
125  IfxSrc_init(srcr, config->typeOfService, config->triggerPriority);
126  IfxSrc_enable(srcr);
127  }
128 
129  /*Configure the comparator ticks to current value to avoid any wrong triggering*/
130  stm->CMP[config->comparator].U = IfxStm_getOffsetTimer(stm, (uint8)config->compareOffset);
131 
132  /* clear the interrupt flag of the selected comparator before enabling the interrupt */
133  /* this is to avaoid the unneccesary interrupt for the compare match of reset values of the registers */
134  IfxStm_clearCompareFlag(stm, config->comparator);
135  /* enable the interrupt for the selected comparator */
137 
138  /*Configure the comparator ticks */
139  stm->CMP[config->comparator].U = IfxStm_getOffsetTimer(stm, (uint8)config->compareOffset) + config->ticks;
140 
141  return result;
142 }
143 
144 
146 {
150  config->comparatorInterrupt = IfxStm_ComparatorInterrupt_ir0; /*User must select the interrupt output */
151  config->ticks = 0xFFFFFFFF;
152  config->triggerPriority = 0;
153  /* TODO add interrupt configuration */
154 }
155 
156 
157 void IfxStm_resetModule(Ifx_STM *stm)
158 {
160 
162  stm->KRST0.B.RST = 1; /* Only if both Kernel reset bits are set a reset is executed */
163  stm->KRST1.B.RST = 1;
164  IfxScuWdt_setCpuEndinit(passwd);
165 
166  while (0 == stm->KRST0.B.RSTSTAT) /* Wait until reset is executed */
167 
168  {}
169 
171  stm->KRSTCLR.B.CLR = 1; /* Clear Kernel reset status bit */
172 
173  IfxScuWdt_setCpuEndinit(passwd);
174 }
175 
176 
178 {
179  if (comparator == IfxStm_Comparator_0)
180  {
181  stm->ICR.B.CMP0EN = 1U;
182  }
183  else if (comparator == IfxStm_Comparator_1)
184  {
185  stm->ICR.B.CMP1EN = 1U;
186  }
187 }