📄 init.c
字号:
/*
** Kenobi2 version 1.3
**
** ** This code has been made to check/learn the 1161 functionalities **
** ** Release 25-Feb-2002 **
**
** OKANO, Akifumi / Jason Ong
**
** Computing Segment, Semisonductors Div, Philips Japan Ltd.
** akifumi.okano@philips.com
** +81-3-3740-4668
*/
#include <stdio.h>
#include <dos.h>
#include <conio.h>
#include "hc_comm.h"
#include "hw_acces.h"
#include "init.h"
#include "ui.h"
#include "isr.h"
#include "isr_as.h"
#include "data_tr.h"
#include "general.h"
#include "pci.h"
/*
** register init values
*/
#define InitVal_HcInterruptDisable 0xFFFFFFFF
#define InitVal_HcInterruptEnable 0x80000060
#define InitVal_HcHcInterruptStatus 0xFFFFFFFF
#define InitVal_HcHardwareConfiguration 0x14AC
#define InitVal_HcFmInterval 0x20002EDF
#define InitVal_HcRhDescriptorA 0x20000202
#define InitVal_HcRhDescriptorB 0x00000001
#define InitVal_HcRhStatus 0x00080001
//#define InitVal_HcRhPortStatus1 0x00000018
//#define InitVal_HcRhPortStatus2 0x00000018
#define InitVal_HcRhPortStatus1 0x00000008
#define InitVal_HcRhPortStatus2 0x00000008
#define InitVal_HcControl 0x00000600 /* into USB RESET state */
#define InitVal_HcuPInterruptEnable 0x0017
#define InitVal_HcITLBufferLength 0x0400
#define InitVal_HcATLBufferLength 0x0800
unsigned char g_host_IRQ_num;
isrPtr old_vector;
void software_reset( void );
int check1161_connected( void );
void set_register_values( void );
void set_1161_interrupt_start( void );
void quit( void );
void initialize( void )
{
unsigned char is_PCI;
if ( 0 != (is_PCI = find_PCI_dev( 0x00068000, (ULONG *)(&g_ISA_base_address), (ULONG *)(&g_host_IRQ_num) )) )
{
g_1161_command_address = g_ISA_base_address + 2;
g_1161_data_address = g_ISA_base_address;
outportb( g_ISA_base_address + 0x468, 0x00 );
outportb( g_ISA_base_address + 0x469, 0x09 );
outportb( g_ISA_base_address + 0x46A, 0x00 );
outportb( g_ISA_base_address + 0x46B, 0x00 );
}
device_list_linitialize();
software_reset();
if ( check1161_connected() )
{
mprintf( LIGHTGRAY, ABORT, "1161 is not present!\r\n" );
}
set_register_values();
mprintf( LIGHTGRAY, CONTINUE, "Hc ISA base address = 0x%04X (on %s)\r\n", get_ISA_base_address(), is_PCI ? "PCI" : "ISA" );
mprintf( LIGHTGRAY, CONTINUE, "Hc IRQ = %d\r\n", g_host_IRQ_num );
old_vector = install_isr( g_host_IRQ_num, isr_USB_Hc );
set_1161_interrupt_start();
mprintf( RED, CONTINUE, "operation started...\r\n" );
rh_event_handler();
}
void software_reset( void )
{
write_register16( Com16_HcSoftwareReset, 0xF6 );
}
int check1161_connected( void )
{
int tmp;
/*
** check ChipID. ChipID value should be 0x6110
*/
tmp = read_register16( Com16_HcChipID );
mprintf( LIGHTGRAY, CONTINUE, " >>> ChipID = 0x%04X : ", tmp );
if ( (tmp & 0xFF00) == 0x6100 )
{
if ( (tmp & 0x00FF) == 0x10 )
mprintf( LIGHTCYAN, CONTINUE, "ISP1161 ES1" );
else if ( (tmp & 0x00FF) == 0x20 )
mprintf( LIGHTCYAN, CONTINUE, "ISP1161 ES2" );
else if ( (tmp & 0x00FF) == 0x21 )
mprintf( LIGHTCYAN, CONTINUE, "ISP1161 ES3" );
else if ( (tmp & 0x00FF) == 0x22 )
mprintf( LIGHTCYAN, CONTINUE, "ISP1161A ES4" );
else
mprintf( LIGHTCYAN, CONTINUE, "ISP1161 unknown version" );
}
else
{
mprintf( LIGHTCYAN, CONTINUE, " This may not ISP1161." );
return ( 1 );
}
mprintf( LIGHTGRAY , CONTINUE, " <<<\r\n\r\n" );
#if 1
/*
** write-read test using scratch register
*/
tmp = 0x55AA; /* pattern of "0101 1010" */
write_register16( Com16_HcScratch, tmp );
#if 0
mprintf( LIGHTCYAN, CONTINUE, " t Com16_HcScratch = 0x%04X\r\n", tmp );
mprintf( LIGHTCYAN, CONTINUE, " r Com16_HcScratch = 0x%04X\r\n", read_register16( Com16_HcScratch ) );
mprintf( LIGHTCYAN, CONTINUE, " r Com16_HcScratch = 0x%04X\r\n", read_register16( Com16_HcScratch ) );
mprintf( LIGHTCYAN, CONTINUE, " r Com16_HcScratch = 0x%04X\r\n", read_register16( Com16_HcScratch ) );
mprintf( LIGHTCYAN, CONTINUE, " r Com16_HcScratch = 0x%04X\r\n", read_register16( Com16_HcScratch ) );
mprintf( LIGHTCYAN, CONTINUE, " r Com16_HcChipID = 0x%04X\r\n", read_register16( Com16_HcChipID ) );
mprintf( LIGHTCYAN, CONTINUE, " r Com16_HcChipID = 0x%04X\r\n", read_register16( Com16_HcChipID ) );
mprintf( LIGHTCYAN, CONTINUE, " r Com16_HcChipID = 0x%04X\r\n", read_register16( Com16_HcChipID ) );
mprintf( LIGHTCYAN, CONTINUE, " r Com16_HcChipID = 0x%04X\r\n", read_register16( Com16_HcChipID ) );
mprintf( LIGHTCYAN, CONTINUE, " r Com16_HcChipID = 0x%04X\r\n", read_register16( Com16_HcChipID ) );
#endif
if ( tmp != read_register16( Com16_HcScratch ) )
{
mprintf( LIGHTCYAN, CONTINUE, " Com16_HcScratch = 0x%04X\r\n", read_register16( Com16_HcScratch ) );
return ( 2 );
}
tmp = ~tmp; /* check again with inverted pattern */
write_register16( Com16_HcScratch, tmp );
if ( tmp != read_register16( Com16_HcScratch ) )
{
mprintf( LIGHTCYAN, CONTINUE, " Com16_HcScratch = 0x%04X\r\n", read_register16( Com16_HcScratch ) );
return ( 3 );
}
#endif
#if 0
{
unsigned short i;
for ( i=0; i<16; i++ )
{
mprintf( LIGHTCYAN, CONTINUE, "hit kb, now %d\r\n", i );
while ( !kbhit() )
{
write_register16( Com16_HcScratch, 1 << i );
}
getch();
}
}
#endif
/*
** chip exists!
*/
return ( 0 );
}
void set_register_values( void )
{
/*
* disable and clear host controller interrupts
*/
write_register32( Com32_HcInterruptDisable, InitVal_HcInterruptDisable );
write_register32( Com32_HcInterruptStatus, InitVal_HcHcInterruptStatus );
/*
* set hardware configurations
*/
write_register16( Com16_HcITLBufferLength, InitVal_HcITLBufferLength );
write_register16( Com16_HcATLBufferLength, InitVal_HcATLBufferLength );
write_register32( Com32_HcFmInterval, InitVal_HcFmInterval );
write_register16( Com16_HcHardwareConfiguration, InitVal_HcHardwareConfiguration );
/*
* resetting host controller : set a bit and wait until done
*/
// write_register32( Com32_HcCommandStatus, read_register32( Com32_HcCommandStatus ) | 0x1 );
//
// while ( read_register32( Com32_HcCommandStatus ) & 0x1 )
// ;
/*
* put host controller into USB_RESET state
*/
write_register32( Com32_HcControl, InitVal_HcControl );
/*
* enable interrupt
*/
write_register16( Com16_HcuPInterruptEnable, InitVal_HcuPInterruptEnable );
write_register32( Com32_HcInterruptEnable, InitVal_HcInterruptEnable );
/*
* enter to USB_OPERATIONAL state
*/
write_register32( Com32_HcControl, InitVal_HcControl | 0x680 );
/*
* set root hub registers
*/
write_register32( Com32_HcRhDescriptorA, InitVal_HcRhDescriptorA );
write_register32( Com32_HcRhDescriptorB, InitVal_HcRhDescriptorB );
write_register32( Com32_HcRhStatus, InitVal_HcRhStatus );
write_register32( Com32_HcRhPortStatus1, InitVal_HcRhPortStatus1 );
write_register32( Com32_HcRhPortStatus2, InitVal_HcRhPortStatus2 );
}
void set_1161_interrupt_start( void )
{
hardware_configuration_setting = read_register16( Com16_HcHardwareConfiguration );
write_register32( Com32_HcInterruptEnable, InitVal_HcInterruptEnable );
write_register16( Com16_HcuPInterruptEnable, InitVal_HcuPInterruptEnable );
write_register16( Com16_HcHardwareConfiguration, ( hardware_configuration_setting | 0x0001 ) );
g_isr_flag = 0x0000;
}
void quit( void )
{
restore_isr( g_host_IRQ_num, (void interrupt (*)())old_vector );
mprintf( LIGHTGRAY, CONTINUE, "\r\n\r\nKenobi2\r\n" );
mprintf( LIGHTGRAY, CONTINUE, "\r\n" );
mprintf( LIGHTGRAY, CONTINUE, "\r\n" );
mprintf( LIGHTCYAN, CONTINUE, " ..........bye!" );
mprintf( LIGHTGRAY, CONTINUE, "\r\n" );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -