📄 iop.c
字号:
{ iopcon |= IOPCON_xIRQ0_FILTER_ON; // Filtering On } else if(ch == 'Q') { return; } //////////////////////////////////////////////////////////////////////////////// Print("\nActive Hight [Y/N/Q]"); ch = get_upper(); if(ch == 'Y') { iopcon |= IOPCON_xIRQ0_ACT_HIGH; // Filtering On } else if(ch == 'Q') { return; } iopcon |= IOPCON_xIRQ0_EN; // enable xIRQ // set IPCON /////////////////////////////////////////////////////////////////// IOPCON = (IOPCON & ~(0x1F << (channel * 5))) | // clear xIRQ channel bits (iopcon << (channel * 5)); // set xIRQ channel bits// Enable External Interrupt /////////////////////////////////////////////////// switch(channel) { case 0: Enable_Int(nEXT0_INT); break; // xIRQ0 case 1: Enable_Int(nEXT1_INT); break; // xIRQ1 case 2: Enable_Int(nEXT2_INT); break; // xIRQ2 case 3: Enable_Int(nEXT3_INT); break; // xIRQ3 }// Print("\nTo set IOPDATA press [D]"); // message to set IOPDATA Print("\nTo break test press [Q]"); // message to break test ExtIntFlag = 0; // clear external interrupt done flag ExtIntCnt = 0; // clear external interrupts count // enable globbal interrupt //////////////////////////////////////////////////// Enable_Int(nGLOBAL_INT); while(1) { if(kbd_hit()) { ch = get_byte(); if(ch == 'Q' || ch == 'q') {// break from test ///////////////////////////////////////////////////////////// break; } if(ch == 'D' || ch == 'd') {// set IOPDATA ///////////////////////////////////////////////////////////////// Print("\nSet IOPDATA register [5 hexdigit] 0x"); iopdata = get_number(16,5); // Print("\nIOPDATA 0x%08x", iopdata); IOPDATA = iopdata; // set IOPDATA } } } // disable interrupts ////////////////////////////////////////////////////////// switch(channel) { case 0: Disable_Int(nEXT0_INT); break; case 1: Disable_Int(nEXT1_INT); break; case 2: Disable_Int(nEXT2_INT); break; case 3: Disable_Int(nEXT3_INT); break; } Disable_Int(nGLOBAL_INT); // disable global interrupt // if(ExtIntFlag == 0) { Print("\nNo external interrupts detected\n"); } else { Print("\nDetected %d external interrupts\n", ExtIntCnt); }// ExtIntFlag = 0; ExtIntCnt = 0; IOPMOD = iopmod; // restore IOPMOD content, P17 output }////////////////////////////////////////////////////////////////////////////////// configure IOPMOD, IOPCON ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////void SetupIoport(void){ U32 iopcon; // IOPCON content U32 iopmod; // IOPMOD content int shift; // shift for xINT, DREQ, DACK conf int irq; // xIRQ number int dreq; // DREQ, DACK number int port; // port number int it; // selected item// for(irq = 0, shift = 0; irq < 4; ++irq, shift += 5) { iopcon = 0; Print("\nxIRQ%d configuration", irq);// xIRQ name// detection /////////////////////////////////////////////////////////////////// while(1) { Print("\n[0] Level detection."); Print("\n[1] Rising edge detection."); Print("\n[2] Failing edge detection."); Print("\n[3] Both edge detection."); Print("\n[Q] Quit from test."); Print("\nSelect Item"); it = get_upper(); if(it == 'Q') { // exit from test return; } if(it == '0') {// level detection ///////////////////////////////////////////////////////////// iopcon |= (IOPCON_xIRQ0_LEVEL << shift); break; // } else if(it == '1') {// Rising edge detection /////////////////////////////////////////////////////// iopcon |= (IOPCON_xIRQ0_EDGE_RISE << shift); break; // } else if(it == '2') {// Failing edge detection ////////////////////////////////////////////////////// iopcon |= (IOPCON_xIRQ0_EDGE_FALL << shift); break; // } else if(it == '3') {// Both edge detection ///////////////////////////////////////////////////////// iopcon |= (IOPCON_xIRQ0_EDGE_BOTH << shift); break; // } }// filtering /////////////////////////////////////////////////////////////////// Print("\nFiltering on [Y/N/Q]"); it = get_upper(); if(it == 'Y') { iopcon |= (IOPCON_xIRQ0_FILTER_ON << shift); } else if(it == 'Q') { return; } // active hight //////////////////////////////////////////////////////////////// Print("\nActive Hight [Y/N/Q]"); it = get_upper(); if(it == 'Y') { iopcon |= (IOPCON_xIRQ0_ACT_HIGH << shift); } else if(it == 'Q') { return; } // enable ////////////////////////////////////////////////////////////////////// Print("\nEnable xIRQ%d [Y/N/Q]", irq); it = get_upper(); if(it == 'Y') { iopcon |= (IOPCON_xIRQ0_EN << shift); } else if(it == 'Q') { return; } IOPCON &= ~(IOPCON_xIRQ0 << shift); // clear xIRQ<irq> bits IOPCON |= iopcon; // write xIRQ<irq> bits }////////////////////////////////////////////////////////////////////////////////// Configure DREQ0, DREQ1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// for(dreq = 0, shift = 0; dreq < 2; ++dreq, shift += 3) { iopcon = 0; Print("\nDREQ%d Configuratuion", dreq); // DREQ name // Active Hight //////////////////////////////////////////////////////////////// Print("\nDREQ%d Active Hight [Y/N/Q]", dreq); it = get_upper(); if(it == 'Y') { iopcon |= (IOPCON_DREQ0_HIGHT << shift); } else if(it == 'Q') { return; } // Filtering on //////////////////////////////////////////////////////////////// Print("\nDREQ%d Filtering on [Y/N/Q]", dreq); it = get_upper(); if(it == 'Y') { iopcon |= (IOPCON_DREQ0_FILTER_ON << shift); } else if(it == 'Q') { return; } // enable/disable ////////////////////////////////////////////////////////////// Print("\nDREQ%d Enable [Y/N]", dreq); it = get_upper(); if(it == 'Y') { iopcon |= (IOPCON_DREQ0_EN << shift); } else if(it == 'Q') { return; } IOPCON &= ~(IOPCON_DREQ0 << shift); // clear DREQ<dreq> bits IOPCON |= iopcon; // write DREQ<dreq> bits }////////////////////////////////////////////////////////////////////////////////// configure DACK0,DACK1 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// for(dreq = 0, shift = 0; dreq < 2; ++dreq, shift += 2) { iopcon = 0; Print("\nDACK%d Configuratuion", dreq);// Active Hight //////////////////////////////////////////////////////////////// Print("\nDACK%d Active Hight [Y/N]", dreq); it = get_upper(); if(it == 'Y') { iopcon |= (IOPCON_DACK0_HIGHT << shift); }// enable ////////////////////////////////////////////////////////////////////// Print("\nDACK%d Enable [Y/N]", dreq); it = get_upper(); if(it == 'Y') { iopcon |= (IOPCON_DACK0_EN << shift); }// IOPCON &= ~(IOPCON_DACK0 << shift); // clear DACK<dreq> bits IOPCON |= iopcon; // write DACK<dreq> bits }////////////////////////////////////////////////////////////////////////////////// Configure I/O Port MODe register //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// iopmod = IOPMOD;// P0 - P7 ///////////////////////////////////////////////////////////////////// for(port = 0; port < 8; ++port) { Print("\nP%d output [Y/N]", port); it = get_upper(); if(it == 'Y') {// output ////////////////////////////////////////////////////////////////////// iopmod |= (1 << port); } else if(it == 'N') {// input /////////////////////////////////////////////////////////////////////// iopmod &=~(1 << port); } else {// save PORT direction ///////////////////////////////////////////////////////// } }// configure P8-P17 //////////////////////////////////////////////////////////// for(port = 8; port < 17; ++port) { char * pnam[10] = // ports names { "P8 (xIRQ0)", "P9 (xIRQ1)", "P10 (xIRQ2)", "P11 (xIRQ3)", "P12 (DREQ0)", "P13 (DREQ1)", "P14 (DACK0)", "P15 (DACK1)", "P16 (TOEN0)", "P17 (TOEN1)" };// Print("\n%s output [Y/N]", pnam[port-8]); it = get_upper(); if(it == 'Y') { iopmod |= (1 << port); } else if(it == 'N') { iopmod &=~(1 << port); } } // IOPMOD = iopmod; // set IOPMOD register }////////////////////////////////////////////////////////////////////////////////// I/O Function Test ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////void IopTest(void){// Setup interrupt vector ////////////////////////////////////////////////////// SysSetInterrupt(nEXT0_INT, ext0isr); // ISR for External Interrupt 0 SysSetInterrupt(nEXT1_INT, ext1isr); // ISR for External Interrupt 1 SysSetInterrupt(nEXT2_INT, ext2isr); // ISR for External Interrupt 2 SysSetInterrupt(nEXT3_INT, ext3isr); // ISR for External Interrupt 3 Enable_Int(nGLOBAL_INT); // enable global interrupt mask while(1) { U8 it; Print("\n\n"); Print("\n[0] External Interrupt req 0 test.");// xIRQ0 test Print("\n[1] External Interrupt req 1 test.");// xIRQ1 test Print("\n[2] External Interrupt req 2 test.");// xIRQ2 test Print("\n[3] External Interrupt req 3 test.");// xIRQ3 test Print("\n[E] External Interrupt enable."); // enable ext int 0,1,2,3 Print("\n[D] External Interrupt disable."); // disable ext int 0,1,2,3 Print("\n[W] IOPDATA read/write."); // read IOPDATA Print("\n[S] Set port Mode & IOPCON."); Print("\n[M] IOPMOD Port Mode Register."); Print("\n[C] IOPCON Port Control Register.");#ifdef _S3C4530_ if(is_s3c4530(syscfg_pd_id)) { Print("\n[O] IOPCON1 Port Control Register 1."); }#endif /* _S3C4530_ */ Print("\n[Q] Quit - Return main menu."); Print("\nSelect test item"); it = get_upper(); if(it == 'Q') { // 'Q' or 'q' break; // break from test } switch(it) { case '0': ExtIntReq(0); break; // Test External Interrupt 0 case '1': ExtIntReq(1); break; // Test External Interrupt 1 case '2': ExtIntReq(2); break; // Test External Interrupt 2 case '3': ExtIntReq(3); break; // Test External Interrupt 3 case 'E': ExtIntAllEnable(); break; // Enable All External Interrupts case 'D': ExtIntAllDisable(); break; // Disable All External Interrupts case 'W': IoPortRw(); break; // I/O Port Read/Write case 'S': SetupIoport(); break; // Setup I/O registers case 'M' :// IOPMOD Port Mode Register /////////////////////////////////////////////////// PrintIOPMOD(); // Print IOPMOD register break; case 'C' : // IOPCON Port Control Register //////////////////////////////////////////////// PrintIOPCON(); // print IOPCON register break; case 'O' : // print IOPCON1 regiter PrintIOPCON1(); break; default : break; } Print("\nPress any key to continue."); it = get_byte(); if(it == 'Q' || it == 'q') { break; } } Disable_Int(nGLOBAL_INT); // disable global interrupt mask}////////////////////////////////////////////////////////////////////////////////// IOPORT EXTERNAL INTERRUPT FUNCTIONS /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////void ext0isr(void){ ExtIntCnt++; // external int count ExtIntFlag = 1;}void ext1isr(void){ ExtIntCnt++; ExtIntFlag = 1;}void ext2isr(void){ ExtIntCnt++; ExtIntFlag = 1;}void ext3isr(void){ ExtIntCnt++; ExtIntFlag = 1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -