-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathmain.c
164 lines (130 loc) · 3.81 KB
/
main.c
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// See LICENSE for license details.
#include "nuclei_sdk_hal.h"
#include <stdio.h>
void user_key_exti_config();
void soc_timer_config();
/**
\brief main function
\param[in] none
\param[out] none
\retval none
*/
int main(void)
{
uint8_t timer_intlevel=1;
uint8_t exti_intlevel =2;
int32_t returnCode;
/* Board Config */
gd_rvstar_led_init(LED3);
gd_rvstar_led_init(LED1);
gd_rvstar_led_init(LED2);
gd_rvstar_key_init(WAKEUP_KEY_GPIO_PORT,KEY_MODE_EXTI);
/* Timer Config */
soc_timer_config();
/* EXIT config */
user_key_exti_config();
/* ECLIC config */
returnCode = ECLIC_Register_IRQ(EXTI0_IRQn, ECLIC_NON_VECTOR_INTERRUPT,
ECLIC_LEVEL_TRIGGER, exti_intlevel, 0, NULL);
returnCode = ECLIC_Register_IRQ(TIMER1_IRQn, ECLIC_NON_VECTOR_INTERRUPT,
ECLIC_LEVEL_TRIGGER, timer_intlevel, 0, NULL);
/* Enable interrupts in general */
__enable_irq();
/* Timer Start */
timer_enable(TIMER1);
/* RGB Control */
while(1)
{
/* set led to RED */
gd_rvstar_led_off(LED2);
gd_rvstar_led_off(LED1);
gd_rvstar_led_on(LED3);
}
return 0;
}
/**
\brief configure the TIMER peripheral
\param[in] none
\param[out] none
\retval none
*/
void soc_timer_config()
{
timer_parameter_struct timer_initpara;
/* ----------------------------------------------------------------------------
TIMER1 Configuration:
TIMER1CLK = SystemCoreClock/54000 = 2KHz.
TIMER1CAR = 20000
---------------------------------------------------------------------------- */
rcu_periph_clock_enable(RCU_TIMER1);
timer_deinit(TIMER1);
timer_update_source_config(TIMER1, TIMER_UPDATE_SRC_REGULAR);
/* initialize TIMER init parameter struct */
timer_struct_para_init(&timer_initpara);
/* TIMER1 configuration */
timer_initpara.prescaler = 53999;
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
timer_initpara.counterdirection = TIMER_COUNTER_UP;
timer_initpara.period = 20000;
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
timer_init(TIMER1, &timer_initpara);
timer_interrupt_enable(TIMER1, TIMER_INT_UP);
}
/**
\brief configure the EXTI peripheral for user key
\param[in] none
\param[out] none
\retval none
*/
void user_key_exti_config()
{
/* enable the AF clock */
rcu_periph_clock_enable(RCU_AF);
/* connect EXTI line to key GPIO pin */
gpio_exti_source_select(WAKEUP_KEY_EXTI_PORT_SOURCE, WAKEUP_KEY_EXTI_PIN_SOURCE);
/* configure key EXTI line */
exti_init(EXTI_0, EXTI_INTERRUPT, EXTI_TRIG_FALLING);
exti_interrupt_flag_clear(EXTI_0);
}
/**
\brief EXTI line0 interrupt service routine
\param[in] none
\param[out] none
\retval none
*/
void EXTI0_IRQHandler()
{
if (SET == exti_interrupt_flag_get(WAKEUP_KEY_PIN)){
if(RESET == gd_rvstar_key_state_get(KEY_WAKEUP)){
/* clear EXTI lines interrupt flag */
exti_interrupt_flag_clear(WAKEUP_KEY_PIN);
/* set led to BLUE */
gd_rvstar_led_off(LED3);
gd_rvstar_led_off(LED1);
gd_rvstar_led_on(LED2);
delay_1ms(1000);
}
}
}
/**
\brief TIMER1 interrupt service routine
\param[in] none
\param[out] none
\retval none
*/
void TIMER1_IRQHandler()
{
uint16_t cnt;
if(SET == timer_interrupt_flag_get(TIMER1, TIMER_INT_FLAG_UP)){
/* clear update interrupt bit */
timer_interrupt_flag_clear(TIMER1, TIMER_INT_FLAG_UP);
for(cnt = 0; cnt < 5; cnt++)
{
/* set led to GREEN */
gd_rvstar_led_off(LED3);
gd_rvstar_led_off(LED2);
gd_rvstar_led_on(LED1);
delay_1ms(1000);
}
}
}