📄 iop.c
字号:
//#include <stdio.h>
#include "snds.h"
//#include "uart.h"
//#include "isr.h"
//#include "pollio.h"
#include "iop.h"
//#include "timer.h"
//#include "system.h"
#include "sysconf.h"
#define MON_TIME_DELAY 1000000
volatile unsigned int ExtIntFlag = 0;
volatile unsigned int ExtIntCnt = 0;
extern volatile unsigned int clk_tick; //defined at timer.c
void ExtIntEnable(int channel)
{
switch(channel) {
case 0: Enable_Int(nEXT0_INT); break;
case 1: Enable_Int(nEXT1_INT); break;
case 2: Enable_Int(nEXT2_INT); break;
case 3: Enable_Int(nEXT3_INT);
}
}
void ExtIntDisable(int channel)
{
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);
}
}
void ExtIntAllEnable(void)
{
Enable_Int(nEXT0_INT);
Enable_Int(nEXT1_INT);
Enable_Int(nEXT2_INT);
Enable_Int(nEXT3_INT);
}
void ExtIntAllDisable(void)
{
Disable_Int(nEXT0_INT);
Disable_Int(nEXT1_INT);
Disable_Int(nEXT2_INT);
Disable_Int(nEXT3_INT);
}
/*
// I/O Function Test
void ioptest(void)
{
char items;
// -------------------------
// Setup interrupt vector
// -------------------------
SysSetInterrupt(nEXT0_INT, ext0isr);
SysSetInterrupt(nEXT1_INT, ext1isr);
SysSetInterrupt(nEXT2_INT, ext2isr);
SysSetInterrupt(nEXT3_INT, ext3isr);
Enable_Int(nGLOBAL_INT); //enable global interrupt mask
// -------------------------
// --- use for debugging ---
// -------------------------
IOPMOD |= 0x1F; // Use output port for LED display
IOPDATA = ~0xd; // In iop test mode
do {
PortTestItems(); // Main memu for ioport test
do {
Print("\rSelect Number?_");
items = get_byte();
}while(is_space(items));
if(is_xdigit(to_upper(items))) {
switch(to_upper(items)) {
case '1': SetupIoport(); break;
case '2': ExtIntReq(0); break;
case '3': ExtIntReq(1); break;
case '4': ExtIntReq(2); break;
case '5': ExtIntReq(3); break;
case '6': ExtIntAllEnable(); break;
case '7': ExtIntAllDisable(); break;
case '8': IoPortRw(); break;
case '9': IopStatus(); break;
case 'A': SetPriority(); break;
case 'B': SetIntMode(); break;
case 'C': ExtIntStress(3); break;
default : break;
}
}
Print("\rPress any key to continue.\r");
while(!is_space(get_byte()));
} while((items!='q')&&(items!='Q'));
Disable_Int(nGLOBAL_INT); //disable global interrupt mask
}
// *******************************************************************
// * IOPORT TEST TOP MEMU SELECT FUNCTION
// *******************************************************************
void PortTestItems(void)
{
Print("\n\n");
Print("+---------------------------------------------------+\r") ;
Print("| KS32C50100 INPUT & OUTPUT TEST ITEMS |\r") ;
Print("+---------------------------------------------------+\r") ;
Print("| 1. Set port Mode & IOPCON |\r") ;
Print("| 2. External Interrupt request0 test |\r") ;
Print("| 3. External Interrupt request1 test |\r") ;
Print("| 4. External Interrupt request2 test |\r") ;
Print("| 5. External Interrupt request3 test |\r") ;
Print("| 6. External Interrupt enable |\r") ;
Print("| 7. External Interrupt disable |\r") ;
Print("| 8. IOPDATA read/write |\r") ;
Print("| 9. I/O port status. |\r") ;
Print("| A. Set Interrupt Priority. |\r") ;
Print("| B. Set Interrupt Mode. |\r") ;
Print("| C. External interrupt Stress test |\r") ;
Print("| Q.QUIT - Return main menu. |\r") ;
Print("+---------------------------------------------------+\r") ;
}
void IopStatus(void)
{
U32 rIOPMOD;
U32 rIOPCON;
int i;
int j;
rIOPMOD = IOPMOD;
rIOPCON = IOPCON;
Print("\r\r<<< I/O PORT STATUS >>>");
Print("\r============================");
// Check PORT0~PORT7 MODE
for(i=0; i< nPORT8 ;i++) {
if((rIOPMOD>>i)&1) Print("\r>PORT%d is output.",i);
else Print("\r>PORT%d is input.",i);
}
// CHECK PORT8~PORT11 MODE
for(i=nPORT8,j=0; i<nPORT12;i++,j+=5) {
if((rIOPCON>>j)&xIRQ0_ON) {
Print("\r>PORT%d is external interrup Request%d input.",i,i-nPORT8);
if(((rIOPCON>>j)&xIRQ0_CON)>>3) Print("\r -Active high,");
else Print("\r -Active low,");
if(((rIOPCON>>j)&xIRQ0_CON)>>2) Print("\r Filtering ON,");
else Print("\r Filtering OFF,");
switch((rIOPCON>>j)&0x3) {
case 0x0 : Print("\r Level Detection.\r");
break;
case 0x1 : Print("\r Rising edge Detection.\r");
break;
case 0x2 : Print("\r Falling edge Detection.");
break;
case 0x3 : Print("\r Both edge Detection.");
}
}
else if((rIOPMOD>>i)&1) Print("\r>PORT%d is output.",i);
else Print("\r>PORT%d is input.",i);
}
// CHECK PORT12 MODE
if(rIOPCON&DREQ0_ON) {
Print("\r>PORT12 is external DMA request0 input.");
switch((rIOPCON&DREQ0_CON)>>20) {
case 0x0 : Print("\r - Filtering OFF, Active low.");
break;
case 0x1 : Print("\r - Filtering OFF, Active high.");
break;
case 0x2 : Print("\r - Filtering ON, Active low.");
break;
case 0x3 : Print("\r - Filtering ON, Active high.");
}
}
else if((rIOPMOD>>nPORT12)&1) Print("\r>PORT12 is output.");
else Print("\r>PORT12 is input.");
// CHECK PORT13 MODE
if(rIOPCON&DREQ1_ON) {
Print("\r>PORT13 is external DMA request0 input.");
switch((rIOPCON&DREQ1_CON)>>23) {
case 0x0 : Print("\r - Filtering OFF, Active low.");
break;
case 0x1 : Print("\r - Filtering OFF, Active high.");
break;
case 0x2 : Print("\r - Filtering ON, Active low.");
break;
case 0x3 : Print("\r - Filtering ON, Active high.");
}
}
else if((rIOPMOD>>nPORT13)&1) Print("\r>PORT13 is output.");
else Print("\r>PORT13 is input.");
// CHECK PORT14 MODE
if(rIOPCON&DACK0_ON) {
Print("\r>PORT14 is external DMA ACK0 input.");
if((rIOPCON&DACK0_CON)>>26) Print("\r - Active High.");
else Print("\r - Active Low.");
}
else if((rIOPMOD>>nPORT14)&1) Print("\r>PORT14 is output.");
else Print("\r>PORT14 is input.");
// CHECK PORT15 MODE
if(rIOPCON&DACK1_ON) {
Print("\r>PORT15 is external DMA ACK0 input.");
if((rIOPCON&DACK1_CON)>>28) Print("\r - Active High.");
else Print("\r - Active Low.");
}
else if((rIOPMOD>>nPORT15)&1) Print("\r>PORT15 is output.");
else Print("\r>PORT15 is input.");
// CHECK PORT16 MODE
if(rIOPCON&TOEN0_ON) Print("\r>PORT16 is timer0 output.");
else if((rIOPMOD>>nPORT16)&1) Print("\r>PORT16 is output.");
else Print("\r>PORT16 is input.");
// CHECK PORT17 MODE
if(rIOPCON&TOEN1_ON) Print("\r>PORT17 is timer1 output.");
else if((rIOPMOD>>nPORT17)&1) Print("\r>PORT17 is output.");
else Print("\r>PORT17 is input.");
Print("\r================================\r\r");
}
// *******************************************************************
// * IOPORT MODE TEST FUNCTIONS
// *******************************************************************
void SetupIoport(void)
{
U32 rIOPCON;
Print("\r> Set IOPMOD register[5 hexdigit]_");
IOPMOD = gethex2dec(5); get_byte();
Print("\r - IOPMOD input is 0x%08x\r",IOPMOD);
Print("\r>Set IOPCON.xIRQ0[2hexdigit]_");
rIOPCON = gethex2dec(2); get_byte();
IOPCON = rIOPCON & (xIRQ0_CON|xIRQ0_ON);
Print("\r>Set IOPCON.xIRQ1[2hexdigit]_");
rIOPCON = gethex2dec(2); get_byte();
IOPCON |= (rIOPCON<<5)&(xIRQ1_CON|xIRQ1_ON);
Print("\r>Set IOPCON.xIRQ2[2hexdigit]_");
rIOPCON = gethex2dec(2); get_byte();
IOPCON |= (rIOPCON<<10)&(xIRQ2_CON|xIRQ2_ON);
Print("\r>Set IOPCON.xIRQ3[2hexdigit]_");
rIOPCON = gethex2dec(2); get_byte();
IOPCON |= (rIOPCON<<15)&(xIRQ3_CON|xIRQ3_ON);
Print("\r>Set IOPCON.DREQ0[1 hexdigit]_");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -