Infineon
Infineon
⚙️ Infineon MCU Programming
📌 Internal Timer Interrupt
1
2
3
State 0 : 빨강 LED on (3초)
State 1 : 파랑 LED on (3초)
State 2 : 파랑 LED 0.5초 간격 점멸
코드 보기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include "Ifx_Types.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"
#include "IfxPort.h"
#include "IfxPort_PinMap.h"
#include "IfxStm.h"
#include "IfxCpu_Irq.h"
enum ledState{
STATE0 = 0,
STATE1 = 1,
STATE2 = 2,
};
int state_val=0;
int blue_toggle=1;
int blink_cnt=0;
#define HIGH 1
#define LOW 0
#define Seconds 3
typedef struct
{
Ifx_STM *stmSfr; /**< \brief Pointer to Stm register base */
IfxStm_CompareConfig stmConfig; /**< \brief Stm Configuration structure */
volatile uint8 LedBlink; /**< \brief LED state variable */
volatile uint32 counter; /**< \brief interrupt counter */
} App_Stm;
App_Stm g_Stm; /**< \brief Stm global data */
IfxCpu_syncEvent g_cpuSyncEvent = 0;
void IfxStmDemo_init(void);
void IfxStmDemo2_init(void);
int core0_main(void) {
IfxCpu_enableInterrupts();
/* !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!
* Enable the watchdogs and service them periodically if it is required
*/
IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword());
/* Wait for CPU sync event */
IfxCpu_emitEvent(&g_cpuSyncEvent);
IfxCpu_waitEvent(&g_cpuSyncEvent, 1);
IfxStmDemo_init();
/*P10_2 Digital Output*/
IfxPort_setPinModeOutput(IfxPort_P10_2.port, IfxPort_P10_2.pinIndex, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
IfxPort_setPinLow(IfxPort_P10_2.port, IfxPort_P10_2.pinIndex);
/*P10_1 Digital Output*/
IfxPort_setPinModeOutput(IfxPort_P10_1.port, IfxPort_P10_1.pinIndex, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
IfxPort_setPinLow(IfxPort_P10_1.port, IfxPort_P10_1.pinIndex);
while(1)
{
}
return (1);
}
IFX_INTERRUPT(STM_Int0Handler, 0, 100);
void STM_Int0Handler(void)
{
IfxStm_clearCompareFlag(g_Stm.stmSfr, g_Stm.stmConfig.comparator);
switch(state_val){
case STATE0:
IfxStm_increaseCompare(g_Stm.stmSfr, g_Stm.stmConfig.comparator, 100000000u * Seconds);
state_val += 1;
IfxPort_setPinHigh(IfxPort_P10_1.port, IfxPort_P10_1.pinIndex); //red on
IfxPort_setPinLow(IfxPort_P10_2.port, IfxPort_P10_2.pinIndex); //blue off
break;
case STATE1:
IfxStm_increaseCompare(g_Stm.stmSfr, g_Stm.stmConfig.comparator, 100000000u * Seconds);
state_val += 1;
IfxPort_setPinLow(IfxPort_P10_1.port, IfxPort_P10_1.pinIndex); //red of
IfxPort_setPinHigh(IfxPort_P10_2.port, IfxPort_P10_2.pinIndex); //blue on
break;
case STATE2:
IfxStm_increaseCompare(g_Stm.stmSfr, g_Stm.stmConfig.comparator, 50000000u); //cmp reg 원하는 시간으로 다시 실행
if(blink_cnt++ < Seconds * 2){
if(blue_toggle){
IfxPort_setPinLow(IfxPort_P10_2.port, IfxPort_P10_2.pinIndex); //blue on
blue_toggle= 0;
}
else {
IfxPort_setPinHigh(IfxPort_P10_2.port, IfxPort_P10_2.pinIndex); //blue on
blue_toggle= 1;
}
}
else if(blink_cnt >= Seconds * 2) {
state_val = 0; //State 이동
blink_cnt=0; //깜빡이 cnt 초기화
}
break;
default:
break;
}
IfxCpu_enableInterrupts();
}
void IfxStmDemo_init(void)
{
/* disable interrupts */
boolean interruptState = IfxCpu_disableInterrupts();
IfxStm_enableOcdsSuspend(&MODULE_STM0);
g_Stm.stmSfr = &MODULE_STM0;
IfxStm_initCompareConfig(&g_Stm.stmConfig);
g_Stm.stmConfig.triggerPriority = 100u;
g_Stm.stmConfig.typeOfService = IfxSrc_Tos_cpu0;
g_Stm.stmConfig.ticks = 100000000 * Seconds;
IfxStm_initCompare(g_Stm.stmSfr, &g_Stm.stmConfig);
/* enable interrupts again */
IfxCpu_restoreInterrupts(interruptState);
}
###