📄 iop.c
字号:
/*************************************************************************//* *//* FILE NAME VERSION *//* *//* iop.c KS32C5000, KS32C50100 : version 1.0 *//* *//* COMPONENT *//* *//* *//* DESCRIPTION *//* *//* *//* AUTHOR *//* *//* Young Sun KIM, Samsung Electronics, Inc. *//* *//* DATA STRUCTURES *//* *//* *//* FUNCTIONS *//* *//* I/O port input, output and share function test *//* *//* DEPENDENCIES *//* *//* *//* HISTORY *//* *//* NAME DATE REMARKS *//* *//* in4maker 12-18-1998 Created initial version 1.0 *//*************************************************************************//* *//* Modified by *//* Dmitriy Cherkashin *//* dch@ucrouter.ru *//* 2002 *//* */#include "ks32c50.h"#include "evm50100.h"volatile unsigned int ExtIntFlag = 0; /* external int flag */volatile unsigned int ExtIntCnt = 0; /* external int count */////////////////////////////////////////////////////////////////////////////////// IOPMOD Port Mode Register ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////static void PrintIOPMOD(void){ int cnt; int port; // port number // Print("\n\nIOPMOD Port Mode Register = 0x%08x", IOPMOD);// Check PORT0~PORT17 MODE /////////////////////////////////////////////////////#ifdef _S3C4530_ if(is_s3c4530(syscfg_pd_id)) { cnt = 26; } else { cnt = 18; } #else cnt = 18; #endif for(port = 0; port < cnt; ++port) { char * pname[] = { "P0 ........", // 0 "P1 ........", // 1 "P2 ........", // 2 "P3 ........", // 3 "P4 ........", // 4 "P5 ........", // 5 "P6 ........", // 6 "P7 ........", // 7 "P8 (xIRQ0)", // 8 "P9 (xIRQ1)", // 9 "P10 (xIRQ2)", // 10 "P11 (xIRQ3)", // 11 "P12 (DREQ0)", // 12 "P13 (DREQ1)", // 13 "P14 (DACK0)", // 14 "P15 (DACK1)", // 15 "P16 (TOEN0)", // 16 "P17 (TOEN1)" // 17#ifdef _S3C4530_ , "P18 ()", // 18 "P19 ()", // 19 "P20 ()", // 20 "P21 ()", // 21 "P22 ()", // 22 "P23 ()", // 23 "P24 ()", // 24 "P25 ()" // 25#endif /* _S3C4530_ */ }; Print("\n%s..........", pname[port]);// print port name if(IOPMOD & (1 << port)) { // Print("1(output)"); // output } else { Print("0(input)"); // input } }}////////////////////////////////////////////////////////////////////////////////// print IOPCON (control register) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////static void PrintIOPCON(void){ U32 iopcon; // IOPCON content int irq; // external irq number int dreq; // DREQ number int offset; // // Print("\n\nIOPCON Port Control Register = 0x%08x", IOPCON);// print title to xIRQ configuration table ///////////////////////////////////// Print ( "\n%10s%15s%15s%10s%10s", "", // xIRQ number "Detection", // detection "Filtering", // filtering "Active", // active "Enable" // enable ); for(irq = 0, offset = 0; irq < 4; ++irq, offset+= 5) { char * det; // Detection string char * filt; // filtering string char * act; // active string char * en; // enable string iopcon = (IOPCON >> offset); iopcon &= IOPCON_xIRQ0; // xIRQ0 mask// detection string //////////////////////////////////////////////////////////// switch(iopcon & 0x3) { case IOPCON_xIRQ0_LEVEL : det = "00(Level)"; break; case IOPCON_xIRQ0_EDGE_RISE : det = "01(Rising edge)"; break; case IOPCON_xIRQ0_EDGE_FALL : det = "10(Failing edge)"; break; case IOPCON_xIRQ0_EDGE_BOTH : det = "11(Both edge)"; break; default : det = ""; break; }// [2] Filtering string //////////////////////////////////////////////////////// filt = (iopcon & IOPCON_xIRQ0_FILTER_ON) ? "1(On)" : "0(Off)";// [3] Active string /////////////////////////////////////////////////////////// act = (iopcon & IOPCON_xIRQ0_ACT_HIGH ) ? "1(high)": "0(low)";// [4] xIRQ0 enable string ///////////////////////////////////////////////////// en = (iopcon & IOPCON_xIRQ0_EN) ? "1(enabled)" : "0(disabled)"; Print ( "\nxIRQ%d%5s%15s%15s%10s%10s", irq , // xIRQ number "" , // padding det , // detection string filt , // filterring string act , // active string en // enable string ); }////////////////////////////////////////////////////////////////////////////////// DREQ0/DREQ1 configuration /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Print ( "\n%10s%15s%15s%10s%10s", "", "", // detection "Filtering", // filtering "Active", // active "Enable" // enable ); for(dreq = 0; dreq <= 1; ++dreq) { U32 mask; // bit mask char * dact; // active string char * filt; // filterring string char * en; // enable string // active string /////////////////////////////////////////////////////////////// mask = dreq ? IOPCON_DREQ1_HIGHT : // DREQ1 active hight mask IOPCON_DREQ0_HIGHT; // DREQ0 active hight mask dact = (IOPCON & mask) ? "1(Hight)" : // active hight "0(Low)"; // active low// filterring string /////////////////////////////////////////////////////////// mask = dreq ? IOPCON_DREQ1_FILTER_ON : // DREQ1 filterring On mask IOPCON_DREQ0_FILTER_ON; // DREQ1 filterring On mask filt = (IOPCON & mask) ? "1(On)" : "0(Off)";// enable string /////////////////////////////////////////////////////////////// mask = dreq ? IOPCON_DREQ1_EN : // DREQ1 enable mask IOPCON_DREQ0_EN; // DREQ0 enable mask en = (IOPCON & mask) ? "1(enabled)" : "0(disabled)"; Print ( "\nDREQ%d%5s%15s%15s%10s%10s", dreq, // number "", // padding "", filt, // filterring string dact, // active string en // enable string ); }////////////////////////////////////////////////////////////////////////////////// DACK0/DACK1 configuration /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Print ( "\n%10s%15s%15s%10s%10s", "", "", // detection "", // filtering "Active", // active "Enable" // enable ); for(dreq = 0; dreq <= 1; ++dreq) { U32 mask; // char * dact; // active string char * en; // enable string mask = dreq ? IOPCON_DACK1_HIGHT : // DACK1 active hight mask IOPCON_DACK0_HIGHT; // DACK0 active low mask dact = (IOPCON & mask) ? "1(Hight)" : "0(Low)"; mask = dreq ? IOPCON_DACK1_EN : // DACK1 enable mask IOPCON_DACK0_EN; // DACK0 enable mask en = (IOPCON & mask) ? "1(enable)" : "0(disabled)"; Print ( "\nDACK%d%5s%15s%15s%10s%10s", dreq , "", "", // detection "", // filtering dact, // active en // enable ); } Print("\ntimeout0 for port 16 (TOEN0) .....................%s", (IOPCON & IOPCON_TOEN0_EN) ? "1(enabled)" : "0(disabled)" ); Print("\ntimeout1 for port 17 (TOEN1) .....................%s", (IOPCON & IOPCON_TOEN1_EN) ? "1(enabled)" : "0(disabled)" );}#ifdef _S3C4530_static void PrintIOPCON1(void){ U32 reg = IOPCON1; PrintSBIT(0,"2 UART DCD0 or port2", ®,IOPCON1_DCD0,"1(DCD0)","0(port2)" ); PrintSBIT(0,"3 UART CTS0 or port3", ®,IOPCON1_CTS0,"1(CTS0)","0(port3)" ); PrintSBIT(0,"4 UART RTS0 or port4", ®,IOPCON1_RTS0,"1(RTS0)","0(port4)" ); PrintSBIT(0,"5 UART DCD1 or port5", ®,IOPCON1_DCD1,"1(DCD1)","0(port5)" ); PrintSBIT(0,"6 UART CTS1 or port6", ®,IOPCON1_CTS1,"1(CTS1)","0(port6)" ); PrintSBIT(0,"7 UART RTS1 or port7", ®,IOPCON1_RTS1,"1(RTS1)","0(port7)" ); PrintSBIT(0,"18 port18 or UART RxD0", ®,IOPCON1_RXD0,"1(RXD0)","0(port18)"); PrintSBIT(0,"19 port19 or UART DSR0", ®,IOPCON1_DSR0,"1(DSR0)","0(port19)"); PrintSBIT(0,"20 port20 or UART TxD0", ®,IOPCON1_TXD0,"1(TXD0)","0(port20)"); PrintSBIT(0,"21 port21 or UART DTR0", ®,IOPCON1_DTR0,"1(DTR0)","0(port21)"); PrintSBIT(0,"22 port22 or UART RxD1", ®,IOPCON1_RXD1,"1(RXD1)","0(port22)"); PrintSBIT(0,"23 port23 or UART DSR1", ®,IOPCON1_DSR1,"1(DSR1)","0(port23)"); PrintSBIT(0,"24 port24 or UART TxD1", ®,IOPCON1_TXD1,"1(TXD1)","0(port24)"); PrintSBIT(0,"25 port25 or UART DTR1", ®,IOPCON1_DTR1,"1(DTR1)","0(port25)");}#endif // _S3C4530_////////////////////////////////////////////////////////////////////////////////// read/write IOPDATA register /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////void IoPortRw(void){ char ch; U32 rIOPDATA; Print("\nType Esc to exit."); while(1) { Print("\nRead or Write I/O Port data [R/W/Q]"); ch = get_upper(); if(ch == 'Q' || ch == KEY_ESC) { return; } if(ch == 'W') { Print("\nWrite data to IOPDATA [5 hexdigit] 0x"); rIOPDATA = get_number(16,5); IOPDATA = rIOPDATA; Print("\nIOPDATA is writen 0x%08x",rIOPDATA); } else if(ch == 'R') { Print("\nIOPDATA is readed 0x%08x",IOPDATA); } }}////////////////////////////////////////////////////////////////////////////////// Enable External Interrupt 0,1,2,3 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////void ExtIntAllEnable(void){ Enable_Int(nEXT0_INT); // Enable External Interrupt 0 Enable_Int(nEXT1_INT); // Enable External Interrupt 1 Enable_Int(nEXT2_INT); // Enable External Interrupt 2 Enable_Int(nEXT3_INT); // Enable External Interrupt 3}////////////////////////////////////////////////////////////////////////////////// Disable External Interrupt 0,1,2,3 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////void ExtIntAllDisable(void){ Disable_Int(nEXT0_INT); // Disbale External Interrupt 0 Disable_Int(nEXT1_INT); // Disable External Interrupt 1 Disable_Int(nEXT2_INT); // Disbale External Interrupt 2 Disable_Int(nEXT3_INT); // Disable External Interrupt 3}////////////////////////////////////////////////////////////////////////////////// external interrupt test /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////void ExtIntReq(int channel){ U32 iopmod; // saved content of IOPMOD U32 iopdata; // IOPDATA content U32 iopcon; // IOPCON content U8 ch; // character readed from console // set all output, P17 reset pin as input ////////////////////////////////////// Print("\nIOPMOD set to 0x%08x", 0x1ffff); iopmod = IOPMOD; // save IOPMOD content IOPMOD = 0x1ffff; // // start setup IOPDATA ///////////////////////////////////////////////////////// Print("\nSet IOPDATA register [5 hexdigit] 0x"); iopdata = get_number(16,5); // Print("\nIOPDATA 0x%08x", iopdata); IOPDATA = iopdata; // set IOPDATA////////////////////////////////////////////////////////////////////////////////// configure iopcon //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// iopcon = 0;////////////////////////////////////////////////////////////////////////////////// detection /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// while(1) { Print("\nxIRQ%d detection", channel); 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."); Print("\nSelect Item"); ch = get_upper(); if(ch == '0') { // Level detection ///////////////////////////////////////////////////////////// iopcon |= IOPCON_xIRQ0_LEVEL; break; } else if(ch == '1') { // Rising edge detection /////////////////////////////////////////////////////// iopcon |= IOPCON_xIRQ0_EDGE_RISE; break; } else if(ch == '2') {// Falling adge detection ////////////////////////////////////////////////////// iopcon |= IOPCON_xIRQ0_EDGE_FALL; break; } else if(ch == '3') { // Both edge detection ///////////////////////////////////////////////////////// iopcon |= IOPCON_xIRQ0_EDGE_BOTH; break; } else if(ch == 'Q') { return; } } // Filtering /////////////////////////////////////////////////////////////////// Print("\nFiltering on [Y/N/Q]"); ch = get_upper(); if(ch == 'Y')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -