⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ioport.c

📁 三星mcu S3C4510B评估板的原码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*************************************************************************/
/*                                                                       */
/* FILE NAME                                      VERSION                */
/*                                                                       */
/* source\ioport.c                                 1.0                   */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*     DIAGNOSTIC CODE for S3C4510B0                                     */
/*                                                                       */
/*                                                                       */
/* DATA STRUCTURES                                                       */
/*                                                                       */
/* FUNCTIONS : ioport initialization and test                            */
/*                                                                       */
/* DEPENDENCIES                                                          */
/*                                                                       */
/*                                                                       */
/* NAME:    Nicolas Park           					 */
/* The last Modification date:  18-April-2002                            */
/* REMARKS:  Created initial version 1.0                                 */
/*                                                                       */
/*                                Copyright (C) 2002 AIJISYSTEM CO.,LTD  */
/*************************************************************************/

#include <stdio.h>
#include "s3c4510b0.h"
#include "uart.h"
#include "isr.h"
#include "pollio.h"
#include "ioport.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 ioptest(void)
{
       char items;

	SysSetInterrupt(nEXT0_INT, ext0isr);
	SysSetInterrupt(nEXT1_INT, ext1isr);
	SysSetInterrupt(nEXT2_INT, ext2isr);
	SysSetInterrupt(nEXT3_INT, ext3isr);

        Enable_Int(nGLOBAL_INT); //enable global interrupt mask


	IOPMOD |= 0x1F;        // Use output port for LED display
        IOPDATA = ~0xd;        // In iop test mode


     do {
           PortTestItems(); // Main memu for ioport test

           do { 
                 Print("\n\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("\n\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("\n#####################################################\r") ;
        Print("\n#   NIBA_BABY S3C4530A0 INPUT & OUTPUT TEST ITEMS   #\r") ;
	Print("\n#####################################################\r") ;
	Print("\n# 1. Set port Mode & IOPCON                         #\r") ;
	Print("\n# 2. External Interrupt request0 test               #\r") ;
	Print("\n# 3. External Interrupt request1 test               #\r") ;
	Print("\n# 4. External Interrupt request2 test               #\r") ;
	Print("\n# 5. External Interrupt request3 test               #\r") ;
	Print("\n# 6. External Interrupt enable                      #\r") ;
	Print("\n# 7. External Interrupt disable                     #\r") ;
	Print("\n# 8. IOPDATA read/write                             #\r") ;
	Print("\n# 9. I/O port status.                               #\r") ;
	Print("\n# A. Set Interrupt Priority.                        #\r") ;
	Print("\n# B. Set Interrupt Mode.                            #\r") ;
	Print("\n# C. External interrupt Stress test                 #\r") ;
	Print("\n# Q.QUIT - Return main menu.                        #\r") ;
	Print("\n#####################################################\r") ;
}


void IopStatus(void)
{
    U32  rIOPMOD;
    U32  rIOPCON;
    int  i;
    int  j;

    rIOPMOD = IOPMOD;
    rIOPCON = IOPCON;

    Print("\n\r\r<<<  I/O PORT STATUS   >>>"); 
    Print("\n\r============================");

    /* Check PORT0~PORT7 MODE */
    for(i=0; i< nPORT8 ;i++) {
       if((rIOPMOD>>i)&1) Print("\n\r>PORT%d is  output.",i);
       else  Print("\n\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("\n\r>PORT%d is external interrup Request%d input.",i,i-nPORT8); 

              if(((rIOPCON>>j)&xIRQ0_CON)>>3) Print("\n\r  -Active high,");
              else Print("\n\r  -Active low,");

              if(((rIOPCON>>j)&xIRQ0_CON)>>2) Print("\n\r  Filtering ON,");
              else Print("\n\r  Filtering OFF,");


              switch((rIOPCON>>j)&0x3) {
                 case 0x0 : Print("\n\r  Level Detection.\r");
                                    break;
                 case 0x1 : Print("\n\r  Rising edge Detection.\r");
                                    break;
                 case 0x2 : Print("\n\r  Falling edge Detection.");
                                    break;
                 case 0x3 : Print("\n\r  Both edge Detection.");
              }
         }
         else  if((rIOPMOD>>i)&1) Print("\n\r>PORT%d is  output.",i); 
               else Print("\n\r>PORT%d is input.",i);
    }


    /* CHECK PORT12 MODE */
    if(rIOPCON&DREQ0_ON) {
        Print("\n\r>PORT12 is external DMA request0 input.");

        switch((rIOPCON&DREQ0_CON)>>20) {
           case 0x0 : Print("\n\r - Filtering OFF, Active low.");
                      break;
           case 0x1 : Print("\n\r - Filtering OFF, Active high.");
                      break;
           case 0x2 : Print("\n\r - Filtering ON, Active low.");
                      break;
           case 0x3 : Print("\n\r - Filtering ON, Active high.");
       }
    }
    else if((rIOPMOD>>nPORT12)&1) Print("\n\r>PORT12 is  output."); 
         else Print("\n\r>PORT12 is input.");

    /* CHECK PORT13 MODE */
    if(rIOPCON&DREQ1_ON) {
        Print("\n\r>PORT13 is external DMA request0 input.");

        switch((rIOPCON&DREQ1_CON)>>23) {
           case 0x0 : Print("\n\r - Filtering OFF, Active low.");
                      break;
           case 0x1 : Print("\n\r - Filtering OFF, Active high.");
                      break;
           case 0x2 : Print("\n\r - Filtering ON, Active low.");
                      break;
           case 0x3 : Print("\n\r - Filtering ON, Active high.");
        }
    }
    else if((rIOPMOD>>nPORT13)&1) Print("\n\r>PORT13 is  output."); 
         else Print("\n\r>PORT13 is input.");


    
    /* CHECK PORT14 MODE */
    if(rIOPCON&DACK0_ON) {
        Print("\n\r>PORT14 is external DMA ACK0 input."); 
        if((rIOPCON&DACK0_CON)>>26) Print("\n\r - Active High.");
        else Print("\n\r - Active Low.");
    }
    else if((rIOPMOD>>nPORT14)&1)  Print("\n\r>PORT14 is output.");  
         else Print("\n\r>PORT14 is input.");


    /* CHECK PORT15 MODE */
    if(rIOPCON&DACK1_ON) {
        Print("\n\r>PORT15 is external DMA ACK0 input."); 
        if((rIOPCON&DACK1_CON)>>28) Print("\n\r - Active High.");
        else Print("\n\r - Active Low.");
    }
    else if((rIOPMOD>>nPORT15)&1) Print("\n\r>PORT15 is output.");
         else Print("\n\r>PORT15 is input.");


    /* CHECK PORT16 MODE */
    if(rIOPCON&TOEN0_ON) Print("\n\r>PORT16 is timer0 output.");
    else if((rIOPMOD>>nPORT16)&1) Print("\n\r>PORT16 is output.");   
         else Print("\n\r>PORT16 is input.");
    


    /* CHECK PORT17 MODE */
    if(rIOPCON&TOEN1_ON) Print("\n\r>PORT17 is timer1 output.");
    else if((rIOPMOD>>nPORT17)&1) Print("\n\r>PORT17 is output.");  
         else Print("\n\r>PORT17 is input.");
    Print("\n\r================================\r\r");
}

/*******************************************************************
 *             IOPORT MODE TEST FUNCTIONS
 *******************************************************************/
void SetupIoport(void)
{
     U32 rIOPCON;

     Print("\n\r> Set IOPMOD register[5 hexdigit]_");
     IOPMOD = gethex2dec(5); get_byte();
     Print("\n\r  - IOPMOD input is 0x%08x\r",IOPMOD);

     Print("\n\r>Set IOPCON.xIRQ0[2hexdigit]_");
     rIOPCON = gethex2dec(2); get_byte();
     IOPCON = rIOPCON & (xIRQ0_CON|xIRQ0_ON);

     Print("\n\r>Set IOPCON.xIRQ1[2hexdigit]_");
     rIOPCON = gethex2dec(2); get_byte();
     IOPCON |= (rIOPCON<<5)&(xIRQ1_CON|xIRQ1_ON);

     Print("\n\r>Set IOPCON.xIRQ2[2hexdigit]_");
     rIOPCON = gethex2dec(2); get_byte();
     IOPCON |= (rIOPCON<<10)&(xIRQ2_CON|xIRQ2_ON);
     
     Print("\n\r>Set IOPCON.xIRQ3[2hexdigit]_");
     rIOPCON = gethex2dec(2); get_byte();
     IOPCON |= (rIOPCON<<15)&(xIRQ3_CON|xIRQ3_ON);

     Print("\n\r>Set IOPCON.DREQ0[1 hexdigit]_");
     rIOPCON = gethex2dec(1); get_byte();
     IOPCON |= (rIOPCON<<20)&(DREQ0_CON|DREQ0_ON);

     Print("\n\r>Set IOPCON.DREQ1[1 hexdigit]_");
     rIOPCON = gethex2dec(1); get_byte();
     IOPCON |= (rIOPCON<<20)&(DREQ1_CON|DREQ1_ON);

     Print("\n\r>Set IOPCON.DACK0[1 hexdigit]_");
     rIOPCON = gethex2dec(1); get_byte();
     IOPCON |= (rIOPCON<<26)&(DACK0_CON|DACK0_ON);

     Print("\n\r>Set IOPCON.DACK1[1 hexdigit]_");
     rIOPCON = gethex2dec(1); get_byte();
     IOPCON |= (rIOPCON<<26)&(DACK1_CON|DACK1_ON);
}


void IoPortRw(void)
{
     char ch;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -