iLLD_TC27xC  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_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 "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_COUNT; 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, 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  index = IfxStm_getIndex(stm);
87 
88  if ((config->triggerInterruptEnabled > 0) && (index >= 0))
89  { /* configure interrupt */
90  volatile Ifx_SRC_SRCR *srcr;
91 
93  {
94  srcr = &(MODULE_SRC.STM.STM[index].SR0);
95  }
96  else
97  {
98  srcr = &(MODULE_SRC.STM.STM[index].SR1);
99  }
100 
101  IfxSrc_init(srcr, config->servProvider, config->triggerInterruptEnabled);
102  IfxSrc_enable(srcr);
103  }
104 
105  /*Configure the comparator ticks */
106  stm->CMP[config->comparator].U = IfxStm_getOffsetTimer(stm, (uint8)config->compareOffset) + config->ticks;
107 
108  if (config->comparator == 0)
109  {
110  comcon.B.MSIZE0 = config->compareSize;
111  comcon.B.MSTART0 = config->compareOffset;
112  icr.B.CMP0OS = config->comparatorInterrupt;
113  icr.B.CMP0EN = config->triggerInterruptEnabled ? 1 : 0;
114  result = TRUE;
115  }
116  else if (config->comparator == 1)
117  {
118  comcon.B.MSIZE1 = config->compareSize;
119  comcon.B.MSTART1 = config->compareOffset;
120  icr.B.CMP1OS = config->comparatorInterrupt;
121  icr.B.CMP1EN = config->triggerInterruptEnabled ? 1 : 0;
122  result = TRUE;
123  }
124  else
125  {
126  /*Invalid value */
127  result = FALSE;
128  }
129 
130  stm->ICR = icr;
131  stm->CMCON = comcon;
132 
133  return result;
134 }
135 
136 
138 {
142  config->triggerInterruptEnabled = FALSE;
143  config->comparatorInterrupt = IfxStm_ComparatorInterrupt_ir0; /*User must select the interrupt output */
144  config->ticks = 0xFFFFFFFF;
145  /* TODO add interrupt configuration */
146 }