📄 iop.c
字号:
rIOPCON = gethex2dec(1); get_byte();
IOPCON |= (rIOPCON<<20)&(DREQ0_CON|DREQ0_ON);
Print("\r>Set IOPCON.DREQ1[1 hexdigit]_");
rIOPCON = gethex2dec(1); get_byte();
IOPCON |= (rIOPCON<<20)&(DREQ1_CON|DREQ1_ON);
Print("\r>Set IOPCON.DACK0[1 hexdigit]_");
rIOPCON = gethex2dec(1); get_byte();
IOPCON |= (rIOPCON<<26)&(DACK0_CON|DACK0_ON);
Print("\r>Set IOPCON.DACK1[1 hexdigit]_");
rIOPCON = gethex2dec(1); get_byte();
IOPCON |= (rIOPCON<<26)&(DACK1_CON|DACK1_ON);
}
void IoPortRw(void)
{
char ch;
U32 rIOPDATA;
Print("\r\r#@$ Type Esc to exit.#$@%*");
do {
do {
Print("\rRead or Write I/O Port data?[R/W]");
ch = get_byte(); ch = to_upper(ch);
} while(ch !='R' && ch !='W');
if(ch == 'W') {
Print("\r> Write data to IOPDATA register[5 hexdigit]_");
rIOPDATA = gethex2dec(5); get_byte();
IOPDATA = rIOPDATA;
Print("\rWrite IOPDATA is 0x%08x",IOPDATA);
}
else if(ch == 'R')
Print("\rRead IOPDATA is 0x%08x",IOPDATA);
ch = get_byte();
}while(ch != ESC);
}
void SetExtIntMode(int channel)
{
U32 rIOPCON;
switch(channel) {
case 0: Print("\rSet external interrupt Req0 mode.");
Print("\r> IOPCON[2hexdigit]_");
rIOPCON = gethex2dec(2); get_byte();
rIOPCON = rIOPCON & (xIRQ0_CON|xIRQ0_ON);
Print("\r - IOPCON input is 0x%08x",rIOPCON);
break;
case 1: Print("\rSet external interrupt Req1 mode.");
Print("\r> IOPCON[2hexdigit]_");
rIOPCON = gethex2dec(2); get_byte();
rIOPCON = (rIOPCON<<5)&(xIRQ1_CON|xIRQ1_ON);
Print("\r - IOPCON input is 0x%08x",rIOPCON);
break;
case 2: Print("\rSet external interrupt Req2 mode.");
Print("\r> IOPCON[2hexdigit]_");
rIOPCON = gethex2dec(2); get_byte();
rIOPCON = (rIOPCON<<10)&(xIRQ2_CON|xIRQ2_ON);
Print("\r - IOPCON input is 0x%08x",rIOPCON);
break;
case 3: Print("\rSet external interrupt Req3 mode.");
Print("\r> IOPCON[2hexdigit]_");
rIOPCON = gethex2dec(2); get_byte();
rIOPCON = (rIOPCON<<15)&(xIRQ3_CON|xIRQ3_ON);
Print("\r - IOPCON input is 0x%08x",rIOPCON);
}
IOPCON = rIOPCON;
}
// This is for the stress test fucntion on external interrupt
int keyscan()
{
U32 rIOPMOD; // All output mode
U32 rIOPDATA; // LED All OFF
U32 rIOPCON;
int KeyInValue ;
int i;
// Interrupt vector setup for key scan
SysSetInterrupt(nEXT0_INT, ext0isr);
SysSetInterrupt(nEXT1_INT, ext1isr);
SysSetInterrupt(nEXT2_INT, ext2isr);
SysSetInterrupt(nEXT3_INT, ext3isr);
ExtIntAllDisable();
// Save previous port configuration
rIOPMOD = IOPMOD;
rIOPCON = IOPCON;
// external interrupt mode & IO port mode setup
// Ext int enable,alctive low, filter on,level detection
IOPMOD = 0x3ffff; // All output mode
IOPDATA = 0xf0f; // Initialize to all high
IOPCON = xIRQ0(0x16)|xIRQ1(0x16)|xIRQ2(0x16)|xIRQ3(0x16);
ExtIntAllEnable();
for(i = 0; i < KEY_TIME_OUT ; i++)
{
if(ExtIntFlag)
{
ExtIntFlag = 0;
break;
}
}
ExtIntAllDisable();
if(i < KEY_TIME_OUT)
{
KeyInValue = ((IOPDATA & KEY_PAD)>>8);
}
else {
KeyInValue = INVALID_KEY; //No Valid key input
}
// Restore previous port configuration
IOPDATA = 0xff0; // Initialize to all high
IOPMOD = rIOPMOD;
IOPCON = rIOPCON;
return(KeyInValue);
}
// *******************************************************************
// * IOPORT EXTERNAL INTERRUPT FUNCTIONS
// *******************************************************************
*/
void ext0isr(void)
{
//Clear_PendingBit(nEXT0_INT);
//Print("\r> External interrupt 0 !!!\r");
//CLKCON = 0x0; //Recover the system clock to 33Mhz
ExtIntCnt++;
ExtIntFlag = 1;
//ExtIntDisable(0);
}
void ext1isr(void)
{
//Clear_PendingBit(nEXT1_INT);
//Print("\r> External interrupt 1 !!!\r");
//CLKCON = 0x0; //Recover the system clock to 33Mhz
ExtIntCnt++;
ExtIntFlag = 1;
//ExtIntDisable(1);
}
void ext2isr(void)
{
//Clear_PendingBit(nEXT2_INT);
//Print("\r> External interrupt 2 !!!\r");
//CLKCON = 0x0; //Recover the system clock to 33Mhz
ExtIntCnt++;
ExtIntFlag = 1;
//ExtIntDisable(2);
}
void ext3isr(void)
{
//Clear_PendingBit(nEXT3_INT);
//Print("\r> External interrupt 3 !!!\r");
//CLKCON = 0x0; //Recover the system clock to 33Mhz
ExtIntCnt++;
ExtIntFlag = 1;
//ExtIntDisable(3);
}
// *******************************************************************
// * EXTERNAL INTERRUPT REQUEST FUNCTION TEST
// *******************************************************************
/*
void ExtIntReq(int channel)
{
U32 rIOPMOD = 0x3ffff; //All output mode
U32 rIOPDATA;
char ch;
do {
ExtIntFlag = 0;
IOPMOD = rIOPMOD;
do {
Print("\r> Set IOPDATA register[5 hexdigit]_");
rIOPDATA = gethex2dec(5); get_byte();
Print("\r - IOPDATA input is 0x%08x",rIOPDATA);
IOPDATA = rIOPDATA;
SetExtIntMode(channel); //set IOPCON
ExtIntEnable(channel);
} while(!ExtIntFlag);
Print("\r\r$Continuing External Interrupt Test?[Y/N]_");
} while(((ch=get_byte()) != 'N')&& (ch != 'n'));
ExtIntDisable(channel);
}
// This is for the stress test fucntion on external interrupt
void ExtIntStress(int channel)
{
U32 rIOPMOD = 0x3ffff; // All output mode
U32 rIOPDATA = 0x1f; // LED All OFF
U32 rIOPCON;
U32 rMonitor = 0;
ExtIntFlag = 0;
SyscfgInit(CACHE_8K);
Print("\r\n<< External interrupt input stress test >>\r");
Print("\rSelected channel of External interrupt is %d.",channel);
//Print("\rExternal interrupt source is timer1 output.");
Print("\rExternal interrupt source is 1.544MHz OSC.");
Print("\rInterrupt modes are Filter on,Rising edge detect.");
Print("\r\r");
ExtIntDisable(channel);
// external interrupt mode & IO port mode setup
// Ext int enable,alctive low, filter on,rising edge
switch(channel) {
//case 0 : rIOPCON = (xIRQ0(0x15)|TOEN1_ON); break;
//case 1 : rIOPCON = (xIRQ1(0x17)|TOEN1_ON); break;
//case 2 : rIOPCON = (xIRQ2(0x17)|TOEN1_ON); break;
//case 3 : rIOPCON = (xIRQ3(0x17)|TOEN1_ON); break;
case 0 : rIOPCON = xIRQ0(0x15); break;
case 1 : rIOPCON = xIRQ1(0x15); break;
case 2 : rIOPCON = xIRQ2(0x15); break;
case 3 : rIOPCON = xIRQ3(0x15); break;
}
IOPMOD = rIOPMOD;
IOPDATA = rIOPDATA;
IOPCON = rIOPCON;
IopStatus();
// timer setup
tmReset(TIMER_DEV1);
tm_init(TIMER_DEV1,(ONE_SECOND/TICKS_PER_SECOND));
//tm_init(TIMER_DEV1,t_data_us(48)); //for 53byte/8M -> 48us
IntConfig(); // Interrupt status
ExtIntEnable(channel);
TimerStart(TIMER_DEV1);
while(1) {
while(!ExtIntFlag) ; //SysTime('0');
if(ExtIntCnt == MON_TIME_DELAY)
{
//Disable_Int(nGLOBAL_INT);
rMonitor++;
Print("\r\n[%d]External interrupt occurred %d times!!\r",rMonitor,ExtIntCnt);
PrtSysTime(TIMER_DEV1,"External INT event time"); Print("\r");
//if(ExtIntCnt != clk_tick) {
//Print("Lost the External interrupt %d times\r",
// ((U32)clk_tick)-ExtIntCnt);
//}
//clk_tick = 0;
ExtIntCnt = 0;
//Enable_Int(nGLOBAL_INT); //enable global interrupt mask
}
ExtIntFlag =0;
}
ExtIntDisable(channel);
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -