|
发表于 2010-1-29 17:25:56
|
显示全部楼层
#include <dos.h>
#include <stdio.h>
#include <conio.h>
#include <process.h>
#include <stdlib.h>
#include "pci.h"
#define BASE 0x378
#define DATA BASE+0x00
#define STATUS BASE+0x01
#define CONTROL BASE+0x02
#define ECR BASE+0X402
#define IRQ 7
#define PIC1 0x20
#define PIC2 0xA0
#ifdef __cplusplus
#define __CPPARGS ...
#else
#define __CPPARGS
#endif
int interflag; /* Interrupt Flag */
int picaddr; /* Programmable Interrupt Controller (PIC) Base Address */
void interrupt (*oldhandler)(__CPPARGS);
void interrupt parisr(__CPPARGS) /* Interrupt Service Routine (ISR) */
{
interflag = 1;
outportb(picaddr,0x20); /* End of Interrupt (EOI) */
}
int main()
{
unsigned int init_con_status,init_ECR,Before_Status,Current_Status;
unsigned char Bus,Dev,Fun;
unsigned long int Data;
int passflag;
int intno; /* Interrupt Vector Number */
int picmask; /* PIC's Mask */
passflag=0;
clrscr();
printf(" Build Date:2010-01-14\n");
printf(" Prnloop utility for SEGA02 developed by Advantech AKMU MTD\n");
printf("===============================================================================\n");
//enable parallel function in south bridge
Bus = 0;
Dev = 31;
Fun = 0;
Data=Read_PCI_REG(Bus, Dev, Fun, 0x80);
Write_PCI_REG(Bus,Dev,Fun,0x80,Data|0x00040000); //Enable Parallel Port,LPT_LPT_EN
init_con_status=inportb(CONTROL);
init_ECR=inportb(ECR);
//check Pin 1 and 2-9,10
//check high->low
outportb(ECR,inportb(ECR)|0x30); //select PS/2 mode
outportb(CONTROL,inportb(CONTROL)|0x21);
if (inportb(DATA)==0x00)
printf("Data signal data 0-7 high->low pass\n");
else
{
printf("Data signal data 0-7 high->low fail\n");
passflag=1;
}
if (((inportb(STATUS)&0x40)/0x40)==0)
printf("Status signal nACK high->low pass\n");
else
{
printf("Status signal nACK high->low fail\n");
passflag=1;
}
outportb(CONTROL,init_con_status|0x20);
if (inportb(DATA)==0xFF)
printf("Data signal data 0-7 low->high pass\n");
else
{
printf("Data signal data 0-7 low->high fail\n");
passflag=1;
}
if (((inportb(STATUS)&0x40)/0x40)==1)
printf("Status signal nACK low->high pass\n");
else
{
printf("Status signal nACK low->high fail\n");
passflag=1;
}
//check Pin 16&pin11
//check high->low
Before_Status=inportb(STATUS);
outportb(CONTROL,init_con_status&0xFB);
Current_Status=inportb(STATUS);
#ifdef DEBUG
printf("Before status port value=%2X,Current status port value=%2X",Before_Status,Current_Status);
#endif
if ((Before_Status^(Current_Status))==0x80)
printf("Control signal nINIT and status signal BUSY high->low pass\n");
else
{
printf("Control signal nINIT and status signal BUSY high->low fail\n");
passflag=1;
}
//check low->high
Before_Status=inportb(STATUS);
outportb(CONTROL,init_con_status|0x04);
Current_Status=inportb(STATUS);
#ifdef DEBUG
printf("Before status port value=%2X,Current status port value=%2X",Before_Status,Current_Status);
#endif
if ((Before_Status^(Current_Status))==0x80)
printf("Control signal nINIT and status signal BUSY low->high pass\n");
else
{
printf("Control signal nINIT and status signal BUSY low->high fail\n");
passflag=1;
}
//IRQ TEST
/* Calculate Interrupt Vector, PIC Addr & Mask. */
if (IRQ >= 2 && IRQ <=7 ) {
intno = IRQ + 0x08;
picaddr = PIC1;
picmask = 1;
picmask = picmask << IRQ;
}
if (IRQ >= 8 && IRQ <= 15) {
intno = IRQ + 0x68;
picaddr = PIC2;
picmask = 1;
picmask = picmask << (IRQ-8);
}
if (IRQ < 2 || IRQ > 15)
{
printf("IRQ Out of Range\n");
exit(1);
}
outportb(CONTROL, inportb(CONTROL) & 0xDF); /* Make sure port is in Forward Direction */
outportb(DATA,0xFF);
oldhandler = getvect(intno); /* Save Old Interrupt Vector */
setvect(intno, parisr); /* Set New Interrupt Vector Entry */
outportb(picaddr+1,inportb(picaddr+1) & (0xFF - picmask)); /* Un-Mask Pic */
outportb(CONTROL, inportb(CONTROL) | 0x10); /* Enable Parallel Port IRQ's */
printf("Parallel Port Interrupt Polarity Tester\n");
printf("IRQ %d : INTNO %02X : PIC Addr 0x%X : Mask 0x%02X\n",IRQ,intno,picaddr,picmask);
interflag = 0; /* Reset Interrupt Flag */
delay(10);
outportb(DATA,0x00); /* High to Low Transition */
delay(10); /* Wait */
if (interflag == 1) printf("Interrupts Occur on High to Low Transition of ACK.\n");
else
{
outportb(DATA,0xFF); /* Low to High Transition */
delay(10); /* wait */
if (interflag == 1) printf("Interrupts Occur on Low to High Transition of ACK.\n");
else
{
printf("No Interrupt Activity Occurred. \nCheck IRQ Number, Port Address and Wiring.");
passflag=1;
}
}
outportb(CONTROL, inportb(CONTROL) & 0xEF); /* Disable Parallel Port IRQ's */
outportb(picaddr+1,inportb(picaddr+1) | picmask); /* Mask Pic */
setvect(intno, oldhandler); /* Restore old Interrupt Vector Before Exit */
//end of IRQ Test
outportb(CONTROL,init_con_status);
outportb(ECR,init_ECR);
gotoxy(35,19);
if (passflag==0)
{
textcolor(GREEN);
cprintf(" PASS\n");
}
else
{
textcolor(RED);
cprintf(" FAIL\n");
}
gotoxy(35,20);
cprintf("Return Code is %d",passflag);
return passflag;
} |
|