📄 peripheral_test_timer.c
字号:
#include "peripheral_test.h"
#include "excalibur.h"
// Prototypes
void DoEnableTimerInterrupt(void);
void DoDisableTimerInterrupt(void);
// Meat
void DoTimerMenu(void)
{
np_timer *timer = na_timer1;
char c;
long timerPeriod = 70000000;
timer->np_timerperiodh = timerPeriod >> 16;
timer->np_timerperiodl = timerPeriod & 0xffff;
menu:
MenuBegin("TIMER MENU");
MenuEntry('a',"Show Timer State");
MenuEntry('b',"Start Timer");
MenuEntry('c',"Stop Timer");
MenuEntry('d',"Set Timer Continuous");
MenuEntry('e',"Clear Timer Continuous");
MenuEntry('f',"Enable Timer Interrupt");
MenuEntry('g',"Disable Timer Interrupt");
c = MenuEnd('a','g');
menuSwitch:
switch(c)
{
case 'a':
printf("<space> to show timer, <Esc> to end\n");
while(1)
{
long timerVal;
long timerPeriod;
timer->np_timersnapl = 0; // snapshot
timerVal = (timer->np_timersnapl & 0x0ffff)
+ ((long)timer->np_timersnaph << 16);
timerPeriod = (timer->np_timerperiodl & 0x0ffff)
+ ((long)timer->np_timerperiodh << 16);
printf("Timer State Time=%8ld, Period = %8ld, Status=%d, Control=%d\n",
timerVal,timerPeriod,
timer->np_timerstatus,
timer->np_timercontrol);
while((c = rGetChar()) < 0)
;
if(c == 27) goto menu;
if(c != ' ') goto menuSwitch;
}
case 'b':
timer->np_timercontrol = (timer->np_timercontrol & 3)
+ np_timercontrol_start_mask;
break;
case 'c':
timer->np_timercontrol = (timer->np_timercontrol & 3)
+ np_timercontrol_stop_mask;
break;
case 'd':
timer->np_timercontrol = timer->np_timercontrol
| np_timercontrol_cont_mask;
break;
case 'e':
timer->np_timercontrol = timer->np_timercontrol
& ~np_timercontrol_cont_mask;
break;
MenuCase('f',DoEnableTimerInterrupt);
MenuCase('g',DoDisableTimerInterrupt);
}
if(c != 'q')
goto menu;
}
typedef struct
{
long interruptCount; // increment with each interrupt
np_timer *timer;
} TimerISRContext;
static TimerISRContext gC = {0,0};
void MyTimerISR(int context)
{
TimerISRContext *c;
c = (TimerISRContext *)context;
c->interruptCount++;
printf("(timer #%d!)",c->interruptCount);
c->timer->np_timerstatus = 0; // write anything to clear the IRQ
}
// Turn on interrupts: enable interrupt bit, and
// install a user ISR
void DoEnableTimerInterrupt(void)
{
gC.timer = na_timer1;
nr_installuserisr(na_timer1_irq,MyTimerISR,(long)&gC);
gC.timer->np_timercontrol = gC.timer->np_timercontrol | np_timercontrol_ito_mask;
printf("\n\nTimer interrupt enabled.\n\n");
}
void DoDisableTimerInterrupt(void)
{
gC.timer = na_timer1;
nr_installuserisr(na_timer1_irq,0,0);
gC.timer->np_timercontrol = gC.timer->np_timercontrol & ~np_timercontrol_ito_mask;
printf("\n\nTimer interrupt disabled.\n\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -