-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathstm32f10x_it.c
120 lines (97 loc) · 2.89 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
113
114
115
116
117
/**
******************************************************************************
* @file GPIO/IOToggle/stm32f10x_it.c
* @author MCD Application Team
* @version V3.5.0
* @date 08-April-2011
* @brief Main Interrupt Service Routines.
* This file provides template for all exceptions handler and peripherals
* interrupt service routine.
******************************************************************************
* @attention
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
******************************************************************************
*/
#include <string.h>
#include "stm32f10x_it.h"
#include "dmx512_rec.h"
#include "serial_tracer.h"
static volatile int dmx_error = 1;
static volatile int byte_count = 0;
static volatile int start_flag = 0;
static enum packet_type packet_type;
void TIM1_CC_IRQHandler(void)
{
uint32_t break_time, mab_time;
TIM_ClearITPendingBit(TIM1, TIM_IT_CC1);
break_time = TIM_GetCapture2(TIM1);
mab_time = TIM_GetCapture1(TIM1) - break_time;
/* use some tolerance for times */
if (break_time > 80 && break_time < 10e3 && mab_time > 8) {
start_flag = 1;
TIM_ITConfig(TIM1, TIM_IT_CC1, DISABLE);
}
}
void USART2_IRQHandler(void)
{
uint8_t rx_byte;
int16_t fe_flag;
int start_addr = dmx512_get_start_addr();
USART_ClearITPendingBit(USART2, USART_IT_RXNE);
fe_flag = USART_GetFlagStatus(USART2, USART_FLAG_FE);
rx_byte = USART_ReceiveData(USART2); /* also clears FE flag */
if (fe_flag) {
TIM_ITConfig(TIM1, TIM_IT_CC1, ENABLE);
return;
}
if (start_flag) {
dmx512_new_data(packet_type, byte_count - 1);
dmx_error = 0;
byte_count = 0;
start_flag = 0;
/* first byte determines packet type */
switch (rx_byte) {
case 0x0:
packet_type = DATA_PACKET;
break;
case 0x17:
packet_type = TEST_PACKET;
break;
default:
dmx512_clear_input();
dmx_error = 1;
TIM_ITConfig(TIM1, TIM_IT_CC1, ENABLE);
return;
}
}
if (byte_count >= start_addr && byte_count < start_addr + NUMBER_OUTPUTS)
dmx512_set_input(byte_count - start_addr, rx_byte);
byte_count++;
}
/**
* @brief This function handles Hard Fault exception.
* @param None
* @retval None
*/
void HardFault_Handler(void)
{
/* Go to infinite loop when Hard Fault exception occurs */
tracer_puts("hardfault\n\r");
while (1) {}
}
/**
* @brief This function handles SysTick Handler.
* @param None
* @retval None
*/
void SysTick_Handler(void)
{
}