-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstm32f4xx_it.c
445 lines (396 loc) · 11.3 KB
/
stm32f4xx_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
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
/********************************************************************************
* @file Project/STM32F4xx_StdPeriph_Templates/stm32f4xx_it.c
* @author MCD Application Team
* @version V1.7.0
* @date 22-April-2016
* @brief Main Interrupt Service Routines.
* This file provides template for all exceptions handler and
* peripherals interrupt service routine.
******************************************************************************
* @attention
*
* <h2><center>© COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx_it.h"
#include "main.h"
#include "HardwareSerial.h"
#include "Encoder.h"
#include "stdlib.h"
#include "IMU.h"
#include "Speed.h"
#include "output.h"
#include "headfile.h"
#include "Odometer.h"
extern volatile uint32_t _millis;
extern ring_buffer rx_buffer;
extern ring_buffer tx_buffer;
extern ring_buffer rx_buffer2;
extern ring_buffer tx_buffer2;
extern ring_buffer rx_buffer3;
extern ring_buffer tx_buffer3;
extern ring_buffer rx_buffer4;
extern ring_buffer tx_buffer4;
extern ring_buffer rx_buffer5;
extern ring_buffer tx_buffer5;
extern ring_buffer rx_buffer6;
extern ring_buffer tx_buffer6;
uint16_t capture = 0;
extern __IO uint16_t CCR1_Val;
extern __IO uint16_t CCR2_Val;
extern __IO uint16_t CCR3_Val;
extern __IO uint16_t CCR4_Val;
extern __IO uint16_t TIM9_CCR1_Val;
extern __IO uint16_t TIM9_CCR2_Val;
extern uint32_t EncodeSpeedL;
extern uint32_t EncodeSpeedR;
extern uint32_t EncodeSpeedM;
/** @addtogroup Template_Project
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/******************************************************************************/
/* Cortex-M4 Processor Exceptions Handlers */
/******************************************************************************/
/**
* @brief This function handles NMI exception.
* @param None
* @retval None
*/
void NMI_Handler(void)
{
}
/**
* @brief This function handles Hard Fault exception.
* @param None
* @retval None
*/
void HardFault_Handler(void)
{
/* Go to infinite loop when Hard Fault exception occurs */
while (1)
{
}
}
/**
* @brief This function handles Memory Manage exception.
* @param None
* @retval None
*/
void MemManage_Handler(void)
{
/* Go to infinite loop when Memory Manage exception occurs */
while (1)
{
}
}
/**
* @brief This function handles Bus Fault exception.
* @param None
* @retval None
*/
void BusFault_Handler(void)
{
/* Go to infinite loop when Bus Fault exception occurs */
while (1)
{
}
}
/**
* @brief This function handles Usage Fault exception.
* @param None
* @retval None
*/
void UsageFault_Handler(void)
{
/* Go to infinite loop when Usage Fault exception occurs */
while (1)
{
}
}
/**
* @brief This function handles SVCall exception.
* @param None
* @retval None
*/
void SVC_Handler(void)
{
}
/**
* @brief This function handles Debug Monitor exception.
* @param None
* @retval None
*/
void DebugMon_Handler(void)
{
}
/**
* @brief This function handles PendSVC exception.
* @param None
* @retval None
*/
void PendSV_Handler(void)
{
}
/**
* @brief This function handles SysTick Handler.
* @param None
* @retval None
*/
void SysTick_Handler(void)
{
_millis++;
}
void TIM1_CC_IRQHandler(void)
{
if (TIM_GetITStatus(TIM1, TIM_IT_CC1) != RESET)
{
TIM_ClearITPendingBit(TIM1, TIM_IT_CC1);
IMU_Yaw();
imu_check(20);
Odometer_Velocity(&Robot.odomter);
static uint16_t i=0;
static uint8_t time_i=0;
if(time_i%2==0)
{
i++;
if(i>500)
{
time_i++;
}
}
else
{
i--;
if(i==0)
time_i++;
}
if(time_i>10)
{
i=0;
}
Speed_out(-i,i);
// Right+=((float)(Right_pulse)/6000);
// Left+=((float)(Left_pulse)/6000);
if(send_flag==1)
{
int16_t a[17]={0};
a[0]=(int16_t)(Robot.odomter.Angle_Velocity*10);
a[1]=(int16_t)(Robot.imu.Angle_Velocity*10);
a[2]=(int16_t)(Robot.odomter.Left_pulse.Revs);
a[3]=(int16_t)(Robot.odomter.Right_pulse.Revs);
a[4]=i;
Oscillograph_out(a,5);
}
/**********************************/
capture = TIM_GetCapture1(TIM1);
TIM_SetCompare1(TIM1, capture + CCR1_Val);
}
}
void TIM2_IRQHandler(void)
{
if (TIM_GetITStatus(TIM2, TIM_IT_CC1) != RESET)
{
TIM_ClearITPendingBit(TIM2, TIM_IT_CC1);
capture = TIM_GetCapture1(TIM2);
TIM_SetCompare1(TIM2, capture + CCR1_Val);
}
}
/**
* @brief This function handles TIM9 global interrupt request.
* @param None
* @retval None
*/
/**
* @brief This function handles USART1 global interrupt request.
* @param None
* @retval None
*/
void USART1_IRQHandler(void)
{
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
{
unsigned char c = USART_ReceiveData(USART1);
store_char(c, &rx_buffer);
}
if(USART_GetITStatus(USART1, USART_IT_TXE) != RESET)
{
if (tx_buffer.head == tx_buffer.tail) {
// Buffer empty, so disable interrupts
USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
}
else {
// There is more data in the output buffer. Send the next byte
unsigned char c = tx_buffer.buffer[tx_buffer.tail];
tx_buffer.tail = (tx_buffer.tail + 1) % SERIAL_BUFFER_SIZE;
USART_SendData(USART1, c);
}
}
}
/**
* @brief This function handles USART2 global interrupt request.
* @param None
* @retval None
*/
void USART2_IRQHandler(void)
{
if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)
{
unsigned char c = USART_ReceiveData(USART2);
store_char(c, &rx_buffer2);
}
if(USART_GetITStatus(USART2, USART_IT_TXE) != RESET)
{
if (tx_buffer2.head == tx_buffer2.tail) {
// Buffer empty, so disable interrupts
USART_ITConfig(USART2, USART_IT_TXE, DISABLE);
}
else {
// There is more data in the output buffer. Send the next byte
unsigned char c = tx_buffer2.buffer[tx_buffer2.tail];
tx_buffer2.tail = (tx_buffer2.tail + 1) % SERIAL_BUFFER_SIZE;
USART_SendData(USART2, c);
}
}
}
/**
* @brief This function handles USART3 global interrupt request.
* @param None
* @retval None
*/
void USART3_IRQHandler(void)
{
if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)
{
unsigned char c = USART_ReceiveData(USART3);
store_char(c, &rx_buffer3);
}
if(USART_GetITStatus(USART3, USART_IT_TXE) != RESET)
{
if (tx_buffer3.head == tx_buffer3.tail) {
// Buffer empty, so disable interrupts
USART_ITConfig(USART3, USART_IT_TXE, DISABLE);
}
else {
// There is more data in the output buffer. Send the next byte
unsigned char c = tx_buffer3.buffer[tx_buffer3.tail];
tx_buffer3.tail = (tx_buffer3.tail + 1) % SERIAL_BUFFER_SIZE;
USART_SendData(USART3, c);
}
}
}
/**
* @brief This function handles UART4 global interrupt request.
* @param None
* @retval None
*/
void UART4_IRQHandler(void)
{
if(USART_GetITStatus(UART4, USART_IT_RXNE) != RESET)
{
unsigned char c = USART_ReceiveData(UART4);
store_char(c, &rx_buffer4);
}
if(USART_GetITStatus(UART4, USART_IT_TXE) != RESET)
{
if (tx_buffer4.head == tx_buffer4.tail) {
// Buffer empty, so disable interrupts
USART_ITConfig(UART4, USART_IT_TXE, DISABLE);
}
else {
// There is more data in the output buffer. Send the next byte
unsigned char c = tx_buffer4.buffer[tx_buffer4.tail];
tx_buffer4.tail = (tx_buffer4.tail + 1) % SERIAL_BUFFER_SIZE;
USART_SendData(UART4, c);
}
}
}
/**
* @brief This function handles UART5 global interrupt request.
* @param None
* @retval None
*/
void UART5_IRQHandler(void)
{
if(USART_GetITStatus(UART5, USART_IT_RXNE) != RESET)
{
unsigned char c = USART_ReceiveData(UART5);
store_char(c, &rx_buffer5);
}
if(USART_GetITStatus(UART5, USART_IT_TXE) != RESET)
{
if (tx_buffer5.head == tx_buffer5.tail) {
// Buffer empty, so disable interrupts
USART_ITConfig(UART5, USART_IT_TXE, DISABLE);
}
else {
// There is more data in the output buffer. Send the next byte
unsigned char c = tx_buffer5.buffer[tx_buffer5.tail];
tx_buffer5.tail = (tx_buffer5.tail + 1) % SERIAL_BUFFER_SIZE;
USART_SendData(UART5, c);
}
}
}
/**
* @brief This function handles USART6 global interrupt request.
* @param None
* @retval None
*/
void USART6_IRQHandler(void)
{
if(USART_GetITStatus(USART6, USART_IT_RXNE) != RESET)
{
unsigned char c = USART_ReceiveData(USART6);
store_char(c, &rx_buffer6);
}
if(USART_GetITStatus(USART6, USART_IT_TXE) != RESET)
{
if (tx_buffer6.head == tx_buffer6.tail) {
// Buffer empty, so disable interrupts
USART_ITConfig(USART6, USART_IT_TXE, DISABLE);
}
else {
// There is more data in the output buffer. Send the next byte
unsigned char c = tx_buffer6.buffer[tx_buffer6.tail];
tx_buffer6.tail = (tx_buffer6.tail + 1) % SERIAL_BUFFER_SIZE;
USART_SendData(USART6, c);
}
}
}
/******************************************************************************/
/* STM32F4xx Peripherals Interrupt Handlers */
/* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */
/* available peripheral interrupt handler's name please refer to the startup */
/* file (startup_stm32f4xx.s). */
/******************************************************************************/
/**
* @brief This function handles PPP interrupt request.
* @param None
* @retval None
*/
/*void PPP_IRQHandler(void)
{
}*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/