-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstm32f10x_it.c
113 lines (94 loc) · 2.81 KB
/
stm32f10x_it.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
#include <stm32f10x_it.h>
extern time_t _current_raw_time;
extern struct tm* _current_time;
extern bool _time_set;
extern void incoming_packet_handler(char* string, uint8_t size);
void SysTick_Handler(void) {
if (function_timeout == 20 && !settings.poweroff) {
// Turn off display
hd44780_backlight(false);
// Print current time
update_time();
}
// Saturated add to avoid overflow
function_timeout = sadd8(function_timeout, 1);
}
void TIM2_IRQHandler()
{
if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
{
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
// Timeout or IR communication
ir_nec_reset_transmission();
}
}
// Handle software interrupt (after decoding command from IR, execute function)
void EXTI1_IRQHandler(void)
{
if (EXTI_GetITStatus(EXTI_Line1) != RESET) {
u8 data = ir_nec_get_last_command();
remote_function(data);
EXTI_ClearITPendingBit(EXTI_Line1);
}
}
// Handle data from IR sensor
void EXTI15_10_IRQHandler(void)
{
static unsigned int counter;
if (EXTI_GetITStatus(EXTI_Line10) != RESET) {
// Restart Timer
counter = TIM_GetCounter(TIM2);
TIM_SetCounter(TIM2, 0);
ir_nec_state_machine(counter);
EXTI_ClearITPendingBit(EXTI_Line10);
}
}
// Handle USART interrupt (data from WiFi module)
void USART1_IRQHandler(void)
{
static uint8_t index = 0;
static char buffer[80];
if (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) {
char c = USART_ReceiveData(USART1);
buffer[index] = c;
index = (index + 1) % sizeof(buffer);
if (c == '\n') {
// if line has more than 2 chars (i.e. \r\n sequence) strip them
// and send to esp8266 library
if (index > 2)
esp8266_new_line(strndup(buffer, index - 2));
buffer[index] = 0;
index = 0;
}
}
}
// Handle RTC interrupts (ticks and alarms)
void RTC_IRQHandler(void)
{
static uint8_t ticks_without_clock = 0;
// Tick every second
if(RTC_GetITStatus(RTC_IT_SEC) != RESET)
{
if (_time_set) {
ticks_without_clock = 0;
_current_raw_time = RTC_GetCounter();
_current_time = gmtime(&_current_raw_time);
if (_current_time->tm_sec == 0) {
// Update time every minute
update_time();
}
if (_current_time->tm_hour == 0) {
// Schedule time sync every hour
_time_set = 0;
}
} else {
// Clock not configured
ticks_without_clock++;
}
LED_toggle(2);
// Clear Interrupt Bit
RTC_ClearITPendingBit(RTC_IT_SEC);
// Wait for RTC Write Operations
RTC_WaitForLastTask();
}
}