-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathInterrupt.c
685 lines (555 loc) · 25.2 KB
/
Interrupt.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
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
/********************* (C) COPYRIGHT 2010 e-Design Co.,Ltd. ********************
File Name : Interrupt.c
Version : DS203_APP Ver 2.3x Author : bure
*******************************************************************************/
#include "Interrupt.h"
#include "Function.h"
#include "Menu.h"
#include "BIOS.h"
#include "Process.h"
vu8 Cursor_Cnt, Key_Wait_Cnt, Key_Repeat_Cnt, Key_Buffer, Cnt_20mS, Key_Mid_Speed=0; // , IntCount, ModInit=0;
vu16 Cnt_mS;
vu8 Twink, Blink,ClearStatus=0;
u8 Volume=20, Light, LoBeepLevel=0;
vu16 Delay_Cnt, Beep_mS, Key_Status_Last, Sec_Cnt, PD_Cnt, NotificationTimer=0,DelayLoopBreak=0,SpecFrameCount,
PersHoldTimer, SecondsTick, ConfNameTimer, CursorDisplayTimer, AutoSetTimer;
vu8 Tim2Factor=1;
u16 ToneBurstCounter=0;
vu8 BurstLimit=0;
u8 SweepResetFlag;
vs16 NoiseIP[100];
vs16 FilterOut;
vu32 LimitTransfer;
vu8 FineAdjust=2;
u8 FineAdjustLimit=4;
vu16 FineAdjustFactor[17]={10000,5000,2000,1000,500,200,100,50,20,10,5,2,1,1,1,1,1};
vu32 Wait_Cnt;
void NMIException(void)
{}
void HardFaultException(void)
{
while (1) {}
}
void MemManageException(void)
{
while (1) {}
}
void BusFaultException(void)
{
while (1) {}
}
void UsageFaultException(void)
{
while (1) {}
}
void DebugMonitor(void)
{}
void SVCHandler(void)
{}
void PendSVC(void)
{}
void SysTickHandler(void)
{}
void WWDG_IRQHandler(void)
{}
void PVD_IRQHandler(void)
{}
void TAMPER_IRQHandler(void)
{}
void RTC_IRQHandler(void)
{}
void FLASH_IRQHandler(void)
{}
void RCC_IRQHandler(void)
{}
void EXTI0_IRQHandler(void)
{}
void EXTI1_IRQHandler(void)
{}
void EXTI2_IRQHandler(void)
{}
void EXTI3_IRQHandler(void)
{}
void EXTI4_IRQHandler(void)
{}
void DMA1_Channel1_IRQHandler(void)
{}
void DMA1_Channel2_IRQHandler(void)
{}
void DMA1_Channel3_IRQHandler(void)
{}
void DMA1_Channel4_IRQHandler(void)
{}
void DMA1_Channel5_IRQHandler(void)
{}
void DMA1_Channel6_IRQHandler(void)
{}
void DMA1_Channel7_IRQHandler(void)
{}
void ADC1_2_IRQHandler(void)
{}
void USB_HP_CAN_TX_IRQHandler(void)
{
__CTR_HP();
}
void USB_LP_CAN_RX0_IRQHandler(void)
{
__USB_Istr();
}
void CAN_RX1_IRQHandler(void)
{}
void CAN_SCE_IRQHandler(void)
{}
void EXTI9_5_IRQHandler(void)
{}
void TIM1_BRK_IRQHandler(void)
{}
void TIM1_UP_IRQHandler(void)
{}
void TIM1_TRG_COM_IRQHandler(void)
{}
void TIM1_CC_IRQHandler(void)
{}
void TIM2_IRQHandler(void)
{
u16 i;
u32 Limit=0;
u32 Reset;
Reset=LimitTransfer;
if((_Kind==5)&&(_Frqn>15))DAC->DHR12R1=(u32)RandomGen(); // take over seeding from int4 above 100khz limit
//==============================================SWEEP MODE===============================================
if(_Kind<5){
if((Sweep==1)&&((Cnt_mS%SweepMod)==0)){ //SWEEP MODE
//------------------------------------------RESET SWEEP TO START-----------------------------------------
if(GenFreqShift<=-100){ // >>> NEED TO TEST UPDATE EVENT FLAG AT INIT
if(_Frqn<=SweepIndex){ //LOW FREQS AND FAST SWEEP RATES (just to keep program going, not normally used...)
if(SweepResetFlag==0){
if(_Kind == PWM){
TIM4->SR &= 0xFFFE; //update event bit reset
}else {
DMA2->IFCR |= 0x2000; //reset finish bit
}
SweepResetFlag=1;
goto BypassFunction;
}else{
if(_Kind == PWM){
if((TIM4->SR&1)==0)goto BypassFunction;
}else {
if((DMA2->ISR & 0x2000)==0)goto BypassFunction;
}
SweepResetFlag=0;
GenFreqShift=100; //reset and use as counter to generate space
ClearStatus=1; //starts space between sweeps
if(_Kind == PWM){
for(i=0;i<720;i++)ATT_DATA[i]=2048; //clear ATT_DATA to create space
__Set(ANALOG_ARR, A_Tab[9]); //shuts off PWM, turns on Analog
}else{
for(i=0;i<720;i++)ATT_DATA[i]=2048; //clear ATT_DATA to create space
OutputAdjust();
}
} //if sweepresetflag
}else{ //HIGH FREQS AND LOW SWEEP RATES, (if GenFreqShift<=-100)
//END OF SWEEP: SHUT OFF WAVE AND START SPACE
GenFreqShift=100; //reset and use as counter to generate space
ClearStatus=1; //starts space between sweeps
Limit=0;
if(_Kind == PWM){
if(_Frqn<15){
TIM4->SR &= 0xFFFD; //capture compare event bit reset
while(Limit++<Reset){
if(TIM4->SR&2){ //wait for capture compare event
TIM4->CCMR1=0x005C; //force output high
break;
}
}
TIM4->SR &= 0xFFFE; //update event bit reset
Limit=0; while(Limit++<Reset){if(TIM4->SR&1)break;} //wait for wave (forced high) to finish
TIM4->CCMR1=0x0078; //restore capture compare output
}else if(_Frqn<17){
while(Limit++<7){} //delay, attempt to catch wave when high
}
GPIOB->CRL = 0x34BBB438; // puts PWM port(TIM4/PB6) in input, floating mode + configures other bits
TIM4->CR1 = 0x0080; // SQR_OUT = Disable. Stops counter 0x80=auto reload preload enable
// PA4 and PB6 hard wired together as common output
GPIOA->CRL = 0x111011BB; // puts analog (DAC port PA4) in input, analog mode + configures other bits
DAC->CR = 0x0003; // DAC= Enable without output buffer (connects DAC to port PA4, also PB6 through external connection)
TIM7->CR1 = 0x0085; // DAC_CLK = Enable (update on overflow only)
TIM4->EGR=0x0001; // generate update event for full reset in case counter stopped before reset
}else {
if((_Frqn==15)&&(_Kind<2)&&(SweepIndex==8))for(i=0;i<(M_Factor*48);i++)Waste++; //100Khz delay for sine/triangle
DMA2->IFCR |= 0x2000; //reset finish bit
while((DMA2->ISR & 0x2000)==0){if(Limit++>Reset)break;} //wait for waveform to finish
DMA2->IFCR|=0x00002000; //clear transfer complete int flag
for(i=0;i<720;i++)ATT_DATA[i]=2048; //clear ATT_DATA to create space
OutputAdjust();
}
} //if(_Frqn<=SweepIndex), else
//------------------------------------------SWEEP/SPACE COUNT DOWN-----------------------------------------
}else{ //if(GenFreqShift<=-100)
GenFreqShift-=SweepStep; //sweep or use to create space
if((ClearStatus)&&(GenFreqShift<40)){ //end space space=100-xx mS
GenFreqShift=100; //reset after space
if(_Kind == PWM){ //START OF NEW SWEEP
TIM4->CNT=TIM4->ARR; //load counter to auto reload value for quick reset
TIM4->CCER=0x0001; //turn PWM back on if turned off
TIM4->PSC = D_Tab[_Frqn].PSC;
GPIOA->CRL |= 0x40000; // DAC_OUT = Disable (puts analog port(PA4)in input, floating mode)
TIM7->CR1 = 0x0084; // DAC clock disable
DAC->CR = 0; // DAC = Disable
EnablePWM=1;
}else{
DMA2_Channel4->CCR &= ~DMA_CCR1_EN;
WaveGen(); //reload ATT_DATA
ResetDMA2_Ch4Params(720/ScaleIndex[_Frqn]);
}
ClearStatus=0;
}
}
if(ClearStatus==0) OutputAdjust();
//==============================================BURST MODE===============================================
}else if((Sweep>1)&&((Cnt_mS%SweepMod)==0)){
//------------------------------------------RESET BURST TO START-----------------------------------------
if((ClearStatus==0)&&(ToneBurstCounter>=BurstLimit)){ //burst limit = xx to 200
if(_Frqn<=SweepIndex){ //FOR LOW FREQS AND HIGH SWEEP SPEEDS
if(SweepResetFlag==0){
if(_Kind == PWM){
TIM4->SR &= 0xFFFE; //update event bit reset
}else {
DMA2->IFCR |= 0x2000; //reset finish bit
}
SweepResetFlag=1;
goto BypassFunction;
}else{
if(_Kind == PWM){
if((TIM4->SR&1)==0)goto BypassFunction; //this section to provide program flow only, not likely to be
}else { //using burst freq lower than burst rate
if((DMA2->ISR & 0x2000)==0)goto BypassFunction;
}
SweepResetFlag=0;
ToneBurstCounter=0;
ClearStatus=1; //starts space between sweep
if(_Kind == PWM){
TIM4->CCER=0x0000; //shut off PWM
}else{
for(i=0;i<720;i++)ATT_DATA[i]=2048; //clear ATT_DATA to create space
}
OutputAdjust(); //reset for beginning of new burst
} //if sweepresetflag
}else{ //HIGH FREQS AND LOW SWEEP SPEEDS
//END BURST, START SPACE
ToneBurstCounter=0;
ClearStatus=1; //starts space between sweeps
Limit=0;
if(((SweepIndex<2)&&(_Frqn>5))||(_Frqn>13))for(i=0;i<(FineAdjust*FineAdjustFactor[_Frqn-6]);i++)Waste++;
if(_Kind == PWM){ //SHUT OFF PWM
TIM4->SR &= 0xFFFE; //update event bit reset
while((TIM4->SR&1)==0){if(Limit++>Reset)break;} //wait for timer to reset signaling end of waveform
TIM4->CCER=0x0000; //shut off PWM
}else { //SHUT OFF ANALOG WAVES
DMA2->IFCR |= 0x2000; //reset finish bit
while((DMA2->ISR & 0x2000)==0){if(Limit++>Reset)break;} //wait for waveform to finish
for(i=0;i<720;i++)ATT_DATA[i]=2048; //clear ATT_DATA to create space
}
OutputAdjust(); //reset for beginning of new burst
} //if(_Frqn<=SweepIndex)
//------------------------------------------BURST/SPACE COUNTDOWN-----------------------------------------
}else{ //((ClearStatus==0)&&(ToneBurstCounter>BurstLimit))
ToneBurstCounter+=SweepStep; //sweep or use to create space
if((ClearStatus)&&(ToneBurstCounter>((200-BurstLimit)+60))){ //END SPACE, START NEW BURST
ToneBurstCounter=0; //reset after space
if(SweepIndex<2)Cnt_mS=19; //ModInit=1;else ModInit=0; //special case for sweepmod>1
if(_Kind == PWM){
TIM4->CNT=0x0000; //reset counter
TIM4->CCER=0x0001; //TURN PWM BACK ON
}else{ //TURN ANALOG WAVES BACK ON
DMA2_Channel4->CCR &= ~DMA_CCR1_EN;
WaveGen(); //reload ATT_DATA
ResetDMA2_Ch4Params(720/ScaleIndex[_Frqn]);
}
ClearStatus=0;
}
}
if(ClearStatus==0)OutputAdjust();
} //if sweep>1
}
//===================================================END====================================================
BypassFunction:
TIM2->SR=0;
}
void TIM3_IRQHandler(void)
{
u8 KeyCode;
SpecFrameCount++;
__Set(KEY_IF_RST, 0); //Clear TIM3 interrupt flag
if(Cnt_mS > 0) Cnt_mS--;
else {
//Cnt_mS=20; //use with 1mS IRQ timing
if((SweepIndex<2)&&(Sweep>1)&&(_Kind<5))
Cnt_mS=19; else Cnt_mS=20; //resetting to 19 provides correct 20mS timing since it includes 0 (necessary for SweepIndex 0 and 1)
//reset to 20 since other parts of program already compensate for this
if(Wait_Cnt >0) Wait_Cnt--; //for Synchro
if(Delay_Cnt >20) Delay_Cnt -= 20;
else Delay_Cnt = 0;
if(Beep_mS >=20) Beep_mS -= 20;
else __Set(BEEP_VOLUME, 0); // Beep off
if(Cnt_20mS < 50) Cnt_20mS++; //here again, this goes from 0 to 50, providing 1.02 seconds timing but is not a big issue here
else { // Do it pre sec.
Cnt_20mS = 0;
__Set(BETTERY_DT, 1); //Battery Detect
Sec_Cnt++;
if(PD_Cnt > 0) PD_Cnt--;
}
Cursor_Cnt++;
if (NotificationTimer==80)Cursor_Cnt=0; //synchronize blinker with message
if(Cursor_Cnt >= 15) { //12*20mS=240mS 15=300ms
Cursor_Cnt=0;
Twink=!Twink;
Blink = BLINK;
}
if(SecondsTick>0)SecondsTick--; //int based timers
if(DelayLoopBreak>0)DelayLoopBreak--;
if(NotificationTimer>0)NotificationTimer--;
if(PersHoldTimer>0)PersHoldTimer--;
if(ConfNameTimer>0)ConfNameTimer--;
if(CursorDisplayTimer>0)CursorDisplayTimer--;
if(AutoSetTimer>0)AutoSetTimer--;
if(Key_Mid_Speed) Key_Mid_Speed--;
if(Key_Wait_Cnt) Key_Wait_Cnt--;
if(Key_Repeat_Cnt) Key_Repeat_Cnt--;
KeyCode=Read_Keys();
if(KeyCode !=0) {
Key_Buffer = KeyCode;
if(SetLowVolume){
__Set(BEEP_VOLUME,((9-LoBeepLevel)*5*(Title[VOLUME][CLASS].Value-1))/9); // Fast key repeat volume
}else{
__Set(BEEP_VOLUME, 5*(Title[VOLUME][CLASS].Value-1)); // Volume
}
Beep_mS = 60;
}
}
}
void TIM4_IRQHandler(void){ //noise filter
u16 i;
static s32 tmp;
static u8 index;
static u8 SeedIndex=0;
if(_Kind==5){
if(InitiateNoise){
DAC->DHR12R2=(u32)RandomGen();
tmp=0;
index=0;
InitiateNoise=0;
FilterOut=0x0800;
for(i=0;i<100;i++)NoiseIP[i]=0;
tmp=0;
}else{
if(_Frqn<8){
DAC->DHR12R1=(u32)FilterOut;
NoiseIP[index]=((u32)DAC->DOR2&0x0FFF)-0x0800;
tmp+=NoiseIP[index];
if(index<99)tmp-=NoiseIP[index+1];
else {tmp-=NoiseIP[0]; DAC->DHR12R2=(u32)RandomGen();} //seed for DAC2 from seed generator mod 100
if(_Frqn<3)FilterOut=(tmp/25)+0x0800; //normalize output
else if(_Frqn<6)FilterOut=(tmp/27)+0x0800;
else FilterOut=(tmp/30)+0x0800;
if(++index>99)index=0;
}else if(_Frqn<14){
DAC->DHR12R1=(u32)FilterOut;
NoiseIP[index]=((u32)DAC->DOR2&0x0FFF)-0x0800;
tmp+=NoiseIP[index];
if(index<9)tmp-=NoiseIP[index+1];
else tmp-=NoiseIP[0];
if(++SeedIndex>17){DAC->DHR12R2=(u32)RandomGen();SeedIndex=0;} //seed for DAC2 from seed generator mod 17
if(_Frqn<12)FilterOut=(tmp/10)+0x0800;
else FilterOut=(tmp/8)+0x0800;
if(++index>9)index=0;
}else if(++SeedIndex>(17)){DAC->DHR12R1=(u32)RandomGen();SeedIndex=0;}
}
if(FilterOut<0)FilterOut=0;else if(FilterOut>0x0FFF)FilterOut=0x0FFF; //provide proper clipping limits
}
TIM4->SR=0;
}
void I2C1_EV_IRQHandler(void)
{}
void I2C1_ER_IRQHandler(void)
{}
void I2C2_EV_IRQHandler(void)
{}
void I2C2_ER_IRQHandler(void)
{}
void SPI1_IRQHandler(void)
{}
void SPI2_IRQHandler(void)
{}
void USART1_IRQHandler(void)
{}
void USART2_IRQHandler(void)
{}
void USART3_IRQHandler(void)
{}
void EXTI15_10_IRQHandler(void)
{}
void RTCAlarm_IRQHandler(void)
{}
void USBWakeUp_IRQHandler(void)
{}
/*******************************************************************************
* Function Name : TIM8_BRK_IRQHandler
* Description : This function handles TIM8 Break interrupt request.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void TIM8_BRK_IRQHandler(void)
{}
/*******************************************************************************
* Function Name : TIM8_UP_IRQHandler
* Description : This function handles TIM8 overflow and update interrupt
* request.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void TIM8_UP_IRQHandler(void)
{}
/*******************************************************************************
* Function Name : TIM8_TRG_COM_IRQHandler
* Description : This function handles TIM8 Trigger and commutation interrupts
* requests.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void TIM8_TRG_COM_IRQHandler(void)
{}
/*******************************************************************************
* Function Name : TIM8_CC_IRQHandler
* Description : This function handles TIM8 capture compare interrupt request.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void TIM8_CC_IRQHandler(void)
{}
/*******************************************************************************
* Function Name : ADC3_IRQHandler
* Description : This function handles ADC3 global interrupt request.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void ADC3_IRQHandler(void)
{}
/*******************************************************************************
* Function Name : FSMC_IRQHandler
* Description : This function handles FSMC global interrupt request.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void FSMC_IRQHandler(void)
{}
/*******************************************************************************
* Function Name : SDIO_IRQHandler
* Description : This function handles SDIO global interrupt request.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void SDIO_IRQHandler(void)
{
/* Process All SDIO Interrupt Sources */
// SD_ProcessIRQSrc();
}
/*******************************************************************************
* Function Name : TIM5_IRQHandler
* Description : This function handles TIM5 global interrupt request.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void TIM5_IRQHandler(void)
{}
/*******************************************************************************
* Function Name : SPI3_IRQHandler
* Description : This function handles SPI3 global interrupt request.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void SPI3_IRQHandler(void)
{}
/*******************************************************************************
* Function Name : UART4_IRQHandler
* Description : This function handles UART4 global interrupt request.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void UART4_IRQHandler(void)
{}
/*******************************************************************************
* Function Name : UART5_IRQHandler
* Description : This function handles UART5 global interrupt request.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void UART5_IRQHandler(void)
{}
/*******************************************************************************
* Function Name : TIM6_IRQHandler
* Description : This function handles TIM6 global interrupt request.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void TIM6_IRQHandler(void)
{}
/*******************************************************************************
* Function Name : TIM7_IRQHandler
* Description : This function handles TIM7 global interrupt request.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void TIM7_IRQHandler(void)
{}
/*******************************************************************************
* Function Name : DMA2_Channel1_IRQHandler
* Description : This function handles DMA2 Channel 1 interrupt request.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void DMA2_Channel1_IRQHandler(void)
{}
/*******************************************************************************
* Function Name : DMA2_Channel2_IRQHandler
* Description : This function handles DMA2 Channel 2 interrupt request.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void DMA2_Channel2_IRQHandler(void)
{}
/*******************************************************************************
* Function Name : DMA2_Channel3_IRQHandler
* Description : This function handles DMA2 Channel 3 interrupt request.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void DMA2_Channel3_IRQHandler(void)
{}
/*******************************************************************************
* Function Name : DMA2_Channel4_5_IRQHandler
* Description : This function handles DMA2 Channel 4 and DMA2 Channel 5
* interrupt request.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void DMA2_Channel4_5_IRQHandler(void)
{}
/********************************* END OF FILE ********************************/