📄 isr.c
字号:
// print INTMODE register Print("\nINTMODE [0x%08x] = 0x%08x", &INTMODE, INTMODE); for(bn = 0; bn < MAXHNDLRS; ++bn) { char * mstr; // mode string if(bn != INTBITS[bn].bit) { // incorrect INTBITS table return(0); } Print("\n"); mstr = (INTMODE & (1 << bn)) ? "1(FIQ)" : "0(IRQ)"; PrintINTBIT(bn, 0, 0, mstr); // print bit name and string value }// return(1);}////////////////////////////////////////////////////////////////////////////////// print INTPEND register //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////static int PrintINTPEND(void){ int bn;// print register value Print("\nINTPEND [0x%08x] = 0x%08x", &INTPEND, INTPEND); for(bn = 0; bn < MAXHNDLRS; ++bn) { int val; // bit value if(bn != INTBITS[bn].bit) { // incorrect INTBITS return(0); // table } Print("\n"); val = (INTPEND >> bn) & 1; // read bit PrintINTBIT(bn, 0, val, 0); // print decimal value }// return(1);}////////////////////////////////////////////////////////////////////////////////// print INTMASK register //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////static int PrintINTMASK(void){ U32 val; // bit value int bn; // bit number // print INTMASK register address, value Print("\nINTMASK [0x%08x] = 0x%08x", &INTMASK, INTMASK);// Print("\n"); val = (INTMASK >> nGLOBAL_INT) & 1; PrintINTBIT(0, "[21] Global int mask bit", val, 0); // for(bn = 0; bn < MAXHNDLRS; ++bn) { if(INTBITS[bn].bit != bn) { // incorrect INTBITS return(0); // table } // Print("\n"); val = (INTMASK >> bn) & 1; // bit value PrintINTBIT(bn, 0, val, 0); // print bit name and digital value }// return(1);}////////////////////////////////////////////////////////////////////////////////// view interrupt config ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////void ViewIntConfig(void){ while(1) { U8 ch; Print("\nInterrupt Status configurations."); Print("\n[F] INTMODE [0x%08x] = 0x%08x", &INTMODE, INTMODE); Print("\n[P] INTPEND [0x%08x] = 0x%08x", &INTPEND, INTPEND); Print("\n[M] INTMASK [0x%08x] = 0x%08x", &INTMASK, INTMASK); Print("\n INTPRI0 [0x%08x] = 0x%08x", &INTPRI0, INTPRI0); Print("\n INTPRI1 [0x%08x] = 0x%08x", &INTPRI1, INTPRI1); Print("\n INTPRI2 [0x%08x] = 0x%08x", &INTPRI2, INTPRI2); Print("\n INTPRI3 [0x%08x] = 0x%08x", &INTPRI3, INTPRI3); Print("\n INTPRI4 [0x%08x] = 0x%08x", &INTPRI4, INTPRI4); Print("\n INTPRI5 [0x%08x] = 0x%08x", &INTPRI5, INTPRI5); Print("\n INTOFFSET[0x%08x] = 0x%08x", &INTOFFSET,INTOFFSET); Print("\n[Q] Quit"); Print("\n Select Item "); ch = get_upper(); if(ch == 'Q') { return; } // switch(ch) { case 'F' : PrintINTMODE(); break; case 'P' : PrintINTPEND(); break; case 'M' : PrintINTMASK(); break; default : break; }// Print("\nPress any key to continue."); ch = get_byte(); if(ch == 'Q' || ch == 'q') { return; } }}#ifdef ISR_DEBUG /* Clear Interrupt statistics */void ClearIntStat(void){ int in; ISR_UndefCount = 0; // count of ISR_UndefHandler calling ISR_PrefetchCount= 0; // count of ISR_PrefetchHandler calling ISR_AbortCount = 0; // count of ISR_AbortHandler calling ISR_SwiCount = 0; // count of ISR_SwiHandler calling ISR_IrqCount = 0; // count of ISR_IrqHandler calling ISR_FiqCount = 0; // count of ISR_FiqHandler calling for(in = 0; in < MAXHNDLRS; ++in) { InterruptCount[in] = 0; // clear int count }}/* View Interrupt statistics */void ViewIntStat(void){ int bn; // int num // print ISR_ count Print("\n"); PrintINTBIT(0, "Undef" , ISR_UndefCount, 0); PrintINTBIT(0, "Prefetch", ISR_PrefetchCount,0); Print("\n"); PrintINTBIT(0, "Abort" , ISR_AbortCount, 0); PrintINTBIT(0, "Swi" , ISR_SwiCount, 0); Print("\n"); PrintINTBIT(0, "Irq" , ISR_IrqCount, 0); PrintINTBIT(0, "Fiq" , ISR_FiqCount, 0); for(bn = 0; bn < MAXHNDLRS; ++bn) { if((bn & 1) == 0) { Print("\n"); } PrintINTBIT(bn,0, InterruptCount[bn], 0); }} #endif /* ================================================= * Set interrupt priority function * ================================================= */void SetPriority(void){ U8 preg[24]; // content of INTPRI0-5 regs U32 *intpri; // pointer to preg U8 pri[MAXHNDLRS]; // int priority,index-int number (nIIC_INT) U8 read; // read regs flag U8 write; // write regs flag int pn; // priority number int bn; // bit number int rn; // register number U8 it; // selected pointer intpri = (U32 * ) preg;// read = 1; // read register, fill pri[] write = 0; while(1) { if(write == 1) {// write command /////////////////////////////////////////////////////////////// write = 0; // clear write cmd INTMASK = 0x3fffff; // disable all int INTPEND = 0x1fffff; // clear all pending for(pn = 0; pn < 24; ++pn) { // clear content of preg[pn] = 0xFF; // INTPRI regs } for(bn = 0; bn < MAXHNDLRS; ++bn) { pn = pri[bn]; // read int pri if(pn >= 0 && pn < MAXHNDLRS) { // write index (bn) to preg[pn] = bn; // corresponding regs } }// write preg to INTPRI0 - INTPRI5 INTPRI0 = *(intpri + 0); INTPRI1 = *(intpri + 1); INTPRI2 = *(intpri + 2); INTPRI3 = *(intpri + 3); INTPRI4 = *(intpri + 4); INTPRI5 = *(intpri + 5);// set read command flag read = 1; } if(read == 1) {// read registers command read = 0;// read regs INTPRI0 - INTPRI5 to preg *(intpri + 0) = INTPRI0; *(intpri + 1) = INTPRI1; *(intpri + 2) = INTPRI2; *(intpri + 3) = INTPRI3; *(intpri + 4) = INTPRI4; *(intpri + 5) = INTPRI5; for(bn = 0; bn < MAXHNDLRS; ++bn) { // clear int priority pri[bn] = 0xFF; // } for(pn = 0; pn < MAXHNDLRS; ++pn) { // pn = int priority bn = preg[pn]; // bn = int index if(bn >= 0 && bn < MAXHNDLRS) { pri[bn] = pn; } } }// print content of INTPRI0 - INTPRI5 Print("\n"); for(rn = 0; rn < 6; ++rn) { Print("%8x ", *(intpri + rn)); }// print title Print("\n"); PrintINTBIT(0, "Int source", 0, "PRI"); PrintINTBIT(0, "Int source", 0, "PRI"); // print Int names and priority for(bn = 0; bn < MAXHNDLRS; ++bn) // bn = int number { if(bn != INTBITS[bn].bit) { // incorrect INTBITS table return; } if((bn & 1) == 0) { // Print("\n"); }// print standard bit name and priority PrintINTBIT(bn, 0, pri[bn], 0); }// print menu Print("\n[C] Change Int Priority"); Print("\n[R] Read priority from regs INTPRI0-6"); Print("\n[W] Write priority to regs INTPRI0-6"); Print("\n[Q] Quit"); Print("\n Select Item"); it = get_upper(); // read selected item from console if(it == 'Q') { return; } if(it == 'R') { // set read command flag read = 1; } else if(it == 'W') { // set write command flag write = 1; } else if(it == 'C') {// change Int priority int num;// Print("\nInput Int source (0-%d) ", MAXHNDLRS-1); bn = get_number(10, 2); for(num = 0; num < MAXHNDLRS; ++num) { if(bn == INTBITS[num].bit) { break; } } if(num >= MAXHNDLRS) { Print("\nIncorrect Int source %d", bn); continue; } Print("\nSelected %s", INTBITS[num].name); // Print("\nInput Int priority (0-%d) ", MAXHNDLRS-1); pn = get_number(10, 2); if(pn < 0 || pn >= MAXHNDLRS) { Print("\nIncorrect Int priority %d", pn); continue; }// pri[bn] = pn; // save int priority preg[pn] = bn; // wrete to content of INTPRI0-5 regs } }}// set INTMODE register void SetIntMode(void){ U32 intmode; // intmode = INTMODE; // read INTMODE content while(1) { int bn; // bit number U8 it; // selected item // INTMODE register for(bn = 0; bn < MAXHNDLRS; ++bn) { char * mstr; if((bn & 1) == 0) { Print("\n"); } if(bn != INTBITS[bn].bit) { return; } mstr = ((intmode >> bn) & 1) ? "1(Fiq)" : "0(Irq)"; PrintINTBIT(bn, 0, 0, mstr); }// print change menu Print("\n[C] Change Int Mode"); Print("\n[Q] Quit"); Print("\n Select Item"); it = get_upper(); if(it == 'Q') { return; } // if(it == 'C') {// change int mode Print("\nInput Int source (0-%d)", MAXHNDLRS-1); bn = get_number(10, 2); // read bit number if(bn < 0 || bn > 20) { // continue; } intmode ^= (1 << bn); // toggle int mode bit INTMODE = intmode; // write INTMODE register } } }void IntTest(void){ U8 it; while(1) { Print("\n\nINTERRUPT TEST"); Print("\n[V] View the interrupt configuration.");#ifdef ISR_DEBUG Print("\n[S] View Interrupt statistics."); Print("\n[C] Clear Interrupt statistics.");#endif // Print("\n[P] Set Interrupt Priority."); Print("\n[M] Set Interrupt Mode."); Print("\n[Q] Type Q for exit interrupt test."); Print("\nSelect Test Item: "); it = get_upper(); switch(it) { case 'V' : ViewIntConfig(); break; /* show timer0/timer1 configuration */#ifdef ISR_DEBUG case 'S' : ViewIntStat(); break; /* View Interrupt statistics */ case 'C' : ClearIntStat(); break; /* Clear Interrupt statistics */#endif // ISR_DEBUG case 'P' : SetPriority(); break; /* Set Interrupt priority */ case 'M' : SetIntMode(); break; /* Set Int Mode */ case 'Q' : return; default : break; } Print("\nPress any key to continue."); it = get_upper(); if(it == 'Q') { break; } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -