?? x1.c
字號:
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <string.h>
#include <bios.h>
#include <mem.h>
#include <graphics.h>
#include <stdlib.h>
#include <io.h>
#include <fcntl.h>
#include "isp1362.h"
#include "isa290.h"
#include "reg.h"
#include "cheeyu.h"
#define version 1.18
// 1.18 Release Version
#define TRUE 1
#define FALSE 0
unsigned int temp;
unsigned int hc_data;
unsigned int hc_com;
unsigned int dc_data;
unsigned int dc_com;
unsigned int g_ISA_base_address;
unsigned int g_1161_command_address;
unsigned int g_1161_data_address;
unsigned char g_host_IRQ_num;
unsigned char g_is_PCI;
#ifdef __cplusplus
#define __CPPARGS ...
#else
#define __CPPARGS
#endif
#define PIC1_base 0x20 // Master Interrupt Controller
#define PIC1_mask 0x21
#define PIC2_base 0xA0 // Slave Interrupt Controller
#define PIC2_mask 0xA1
#define EOI 0x20 // Non-specific End Of Interrupt
void open_interrupt(void);
void close_interrupt(void);
void end_interrupt(void);
void interrupt far intserv(__CPPARGS);
void interrupt far(*oldfunc)(__CPPARGS);
int get_int_num( int irq_num );
void get_PIC_masks( int *m_lower , int *m_higher, int irq_num );
int x=0;
int global_upint=0;
long global_intstatus=0;
int int_q=0;
void interrupt far intserv(__CPPARGS)
{
disable();
end_interrupt();
x++;
if(int_q==0)
{
global_upint=r16(HcUpInt);
global_intstatus=r32(HcIntStatus);
int_q++;
}
w16(HcUpInt, 0xFFFF);
w32(HcIntStatus, 0xFFFFFFFF);
w16(HcUpInt, 0xFFFF);
w32(HcIntStatus, 0xFFFFFFFF);
enable();
}
int get_int_num( int irq_num )
{
#define LowerINTOffset 0x08
#define HigherINTOffset 0x68
return ( ( irq_num < 8 ) ? irq_num + LowerINTOffset : irq_num + HigherINTOffset );
}
void get_PIC_masks( int *m_lower , int *m_higher, int irq_num )
{
if ( irq_num < 8 )
{
*m_lower = 0x01 << irq_num;
*m_higher = 0x00;
}
else
{
*m_lower = 0x04; /* for cascaded IRQ(IRQ2) */
*m_higher = 0x01 << (irq_num - 8);
}
}
void open_interrupt(void)
{
unsigned int temp;
int mask1, mask2;
int int_num, irq_num;
int PIC_mask1, PIC_mask2;
disable(); // Disable all ints
outportb(PIC2_base,EOI); // Reset PIC2
outportb(PIC1_base,EOI); // Reset PIC1
irq_num = g_host_IRQ_num;
int_num = get_int_num( irq_num );
get_PIC_masks( &PIC_mask1, &PIC_mask2, irq_num );
oldfunc=getvect(int_num); // Save old interrupt vector
setvect(int_num, intserv); // intserv is new ISR
mask1=inportb(PIC1_mask);
outportb(PIC1_mask, mask1&~PIC_mask1); // Clear bit 2(IRQ2) - Enable Master IRQ2
mask2= inportb(PIC2_mask);
outportb(PIC2_mask, mask2&~PIC_mask2); // Clear bit 2(IRQ10) (Enable IRQ10)
end_interrupt();
enable();
}
void close_interrupt()
{
int mask, irq_num, int_num;
int PIC_mask1, PIC_mask2;
disable();
irq_num = g_host_IRQ_num;
int_num = get_int_num( irq_num );
get_PIC_masks( &PIC_mask1, &PIC_mask2, irq_num );
setvect(int_num, oldfunc); // Set back to old vector address
outportb( 0x21, inportb( 0x21 ) | PIC_mask1 );
outportb( 0xA1, inportb( 0xA1 ) | PIC_mask2 );
enable();
}
void end_interrupt(void)
{
outportb(PIC2_base,EOI); // Send EOI to PIC2
outportb(PIC1_base,EOI); // Send EOI to PIC1
}
void decode_dev(unsigned int *reply,char mode,char startx)
{
int starty;
starty=5;
if(mode==1)
{
gotoxy(startx,starty + 1);
printf("DescriptorType :0x%8X " ,(reply[0]&0xFF00)>>8);
gotoxy(startx,starty + 2);
printf("DescriptorSize : %8d " ,reply[0]&0x00FF);
gotoxy(startx,starty + 3);
printf("USB DeviceType : %2X.%2X ",(reply[1]&0xFF00)>>8,reply[1]&0x00FF);
gotoxy(startx,starty + 4);
printf("Class :0x%8X " ,reply[2]&0x00FF);
gotoxy(startx,starty + 5);
printf("SubClass :0x%8X " ,(reply[2]&0xFF00)>>8);
gotoxy(startx,starty + 6);
printf("bDeviceProtocol:0x%8X " ,reply[3]&0x00FF);
gotoxy(startx,starty + 7);
printf("bMaxPacSize 0 :0x%8X " ,(reply[3]&0xFF00)>>8);
gotoxy(startx,starty + 8);
printf("VendorID :0x%8X " ,reply[4]);
gotoxy(startx,starty + 9);
printf("ProductID :0x%8X " ,reply[5]);
gotoxy(startx,starty +10);
printf("BCD Device :0x%8X " ,reply[6]);
gotoxy(startx,starty +11);
printf("iManufacturer :0x%8X " ,(reply[7]&0x00FF) );
gotoxy(startx,starty +12);
printf("iProduct :0x%8X " ,(reply[7]&0xFF00)>>8);
gotoxy(startx,starty +13);
printf("SerialNumber :0x%8X " ,(reply[8]&0x00FF));
gotoxy(startx,starty +14);
printf("No of Config :0x%8X " ,(reply[8]&0xFF00)>>8);
}
}
void enu(void)
{
unsigned int cbuf[128];
unsigned int rbuf[128];
unsigned char udn[64];
//atl parameters
unsigned long atl_skip=0xFFFFFFFE;
unsigned long atl_last=0x00000001;
unsigned int atl_blk_size=64;
unsigned int atl_cnt=1;
unsigned int atl_timeout=200;
unsigned int mycode;
unsigned int cnt,name_length;
unsigned int iManufacturer,iProduct;
unsigned long rhp1,rhp2;
unsigned int user_in=0;
clrscr();
set_operational();
enable_port();
delay(300);
reset_usb();
erase_all();
set_operational();
enable_port();
delay(300);
w16(HcBufStatus,0x00);
//Setup ATL Parameters
w32(HcATLSkip,atl_skip);
w32(HcATLLast,atl_last);
w16(HcATLBlkSize,atl_blk_size);
w16(HcATLThrsCnt,atl_cnt);
w16(HcATLTimeOut,atl_timeout);
w16(HcUpIntEnable,0x100);
mycode=assign_address(1,2,0);
if((mycode&(0xF0F0))!=0)
{
printf("\nError in assigning address to USB devices, MyCode:%04X",mycode);
getch();
clrscr();
return 0;
}
mycode=get_control(rbuf,1,'D',0,1);
gotoxy(1,2);
printf("GetDesc 1:%4X",mycode);
if(mycode==0x0300)
{
decode_dev(rbuf,1,1);
iManufacturer = rbuf[7]&0xFF;
iProduct = (rbuf[7]&0xFF00)>>8;
addr_info(1,'W','O',iManufacturer);
addr_info(1,'W','P',iProduct);
}
mycode=get_control(rbuf,2,'D',0,2);
gotoxy(41,2);
printf("GetDesc 2:%4X",mycode);
if(mycode==0x0300)
{
decode_dev(rbuf,1,41);
iManufacturer = rbuf[7]&0xFF;
iProduct = (rbuf[7]&0xFF00)>>8;
addr_info(2,'W','O',iManufacturer);
addr_info(2,'W','P',iProduct);
}
mycode=get_control(rbuf,1,'S',addr_info(1,'R','O',0),1);
if(mycode==0x0300)
{
convert_string(udn,rbuf);
gotoxy(1,3);
printf("Manufr : %s ",udn);
}
mycode=get_control(rbuf,1,'S',addr_info(1,'R','P',0),1);
if(mycode==0x0300)
{
convert_string(udn,rbuf);
gotoxy(1,4);
printf("Product : %s ",udn);
}
mycode=get_control(rbuf,2,'S',addr_info(2,'R','O',0),2);
if(mycode==0x0300)
{
convert_string(udn,rbuf);
gotoxy(41,3);
printf("Manufr : %s ",udn);
}
mycode=get_control(rbuf,2,'S',addr_info(2,'R','P',0),2);
if(mycode==0x0300)
{
convert_string(udn,rbuf);
gotoxy(41,4);
printf("Product T: %s ",udn);
}
gotoxy(1,20);
addr_info(0,'D',0,0);
do
{
gotoxy(1,25);
printf("Frame Number = %8lX Press '1' to go back to main menu",r32(HcFmNo));
user_in=read_key(0);
}
while(user_in!='1');
}
void bmat(void)
{
int user_in;
int basey=370;
int line_space=10;
gui();
clrscr();
cleardevice();
mem_init_mem();
mem_map();
do
{
e_box(320,418,638,110);
outtextxy(10,basey ,"Press 1 to reset memory using ABSOLUTE address");
outtextxy(10,basey+line_space ,"Press 2 to run TortureTest on 1362");
outtextxy(10,basey+(line_space*3),"Press 4 to display memory content details");
outtextxy(10,basey+(line_space*4),"Press 5 to write sequential values");
outtextxy(10,basey+(line_space*5),"Press 6 to perform randomised Write/Read");
outtextxy(10,basey+(line_space*6),"Press 7 to refresh memory snapshot");
outtextxy(10,basey+(line_space*7),"");
outtextxy(10,basey+(line_space*9),"Press 9 to exit submenu");
do
{
delay(1);
user_in=read_key(0);
}
while(user_in==0);
switch(user_in)
{
case '1': erase_all(); mem_map(); break;
case '2': torture_test(); break;
case '4': see_buf(); break;
case '5': set_all(); mem_map(); break;
case '6': r_test(); break;
case '7': mem_map(); break;
case '8': break;
case '9': break;
}
}
while(user_in!='9');
close_gui();
}
void chip_reset(void)
{
w16(HcReset,0x00F6);
}
void suspend(void)
{
unsigned int mode;
unsigned int otgcontrol;
unsigned int user_in;
clrscr();
gotoxy(35,12);
printf("\nSuspend");
if (g_is_PCI == FALSE) w16(HcHWCfg , 0x002D );
else w16(HcHWCfg , 0x0029 );
w32(HcFmItv , 0x25002EDF);
w32(HcControl , 0x00000680);
w32(HcControl , 0x000006C0);
do
{
delay(10);
gotoxy(1,1);
printf("HcIntStatus = %8lX",r32(HcIntStatus) );
delay(2);
gotoxy(1,1);
printf("HcIntStatus = %8lX",r32(HcIntStatus) );
user_in=read_key(0);
}
while(user_in!='1');
getch();
}
void main(void)
{
unsigned int cnt;
unsigned int user_in;
unsigned int chip_id;
unsigned int hw_cfg;
unsigned int temp;
clrscr();
if ( 0 != (findPCIdev(0x00068000, &g_ISA_base_address, &g_host_IRQ_num))) //jason add PnP
{
g_is_PCI = TRUE;
hc_data = g_ISA_base_address;
hc_com = g_ISA_base_address + 2;
dc_data = g_ISA_base_address + 4;
dc_com = g_ISA_base_address + 6;
set_pci_bridge();
}
else
{
g_is_PCI = FALSE;
hc_data=0x290;
hc_com=0x292;
dc_data=0x294;
dc_com=0x296;
g_ISA_base_address=hc_data;
g_host_IRQ_num=0xa;
}
delay(100);
w16(HcATLLen,0x100);
w16(HcPTLLen,0x1840);
w16(HcINTLen,0x100);
_setcursortype(_NOCURSOR);
do
{
clrscr();
printf("\nISP1362 %s HOST Controller - X2 Release Version %.2f",g_is_PCI ? "PCI" : "ISA",version);
printf("\n=====================================================");
printf("\n0 Chip Reset");
printf("\n2 Port Monitor");
printf("\n3 Enumeration");
printf("\n4 Read HC Registers");
printf("\n5 Mouse");
printf("\n6 Register Read/Write Test");
printf("\n7 BMAT Bitmapped Memory Analysis Tool");
printf("\n\n9 Exit");
chip_reset();
printf("\n\n HcChipID : 0x%4X",r16(HcChipID));
printf("\n\n HC base address: 0x%4X",g_ISA_base_address);
printf("\n HC IRQ used: 0x%X",g_host_IRQ_num);
user_in=read_key(1);
if(user_in=='0') {chip_reset();}
if(user_in=='2') {port_monitor();}
if(user_in=='3') {enu();}
if(user_in=='4') {load_def(); gui(); read_registers(); close_gui();}
if(user_in=='5') {mouse();}
if(user_in=='6') {load_def(); gui(); wr_reg(); close_gui();}
if(user_in=='7') {bmat();}
}
while(user_in!='9');
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -