📄 dc_main.c
字号:
/*
** WASABI-Hot! version 1.2c (DeviceController sub-unit)
**
**
** -- copyright (c) 2001-2004 by Philips Japan, Ltd. -- All rights reserved --
**
**
** ** This code has been made to check/learn **
** ** the ISP1362/ISP1363 functionalities **
** ** Release 06-Aug-2004 **
**
** HIGASHIYAMA, Ken
**
** Application Laboratory, Mobile and Connectivity
** Semiconductors Div, Philips Japan Ltd.
** ken.higashiyama@philips.com
** +81-3-3740-5136
**
**
*/
#include <stdio.h>
#include <dos.h>
#include <conio.h>
#include "general.h"
#include "_hc_hw/hw_acces.h"
#include "_otg/otg.h"
#include "_dc/dc_main.h"
#include "_dc/dc_hal.h"
#include "_dc/dc_comm.h"
#include "_dc/dc_isr.h"
#include "_dc/dc_flags.h"
#include "_dc/dc_chap9.h"
#include "_dc/dc_spcfc.h"
#include "ui.h"
#ifdef DC_ONLY
void main()
{
int i, in_loop=1;
dc_init_isr();
dc_init_hw();
while ( in_loop )
{
dc_control_handler();
dc_bus_event_eval();
/* for ( i=0; i<4; i++)
printf ("%04X ", setup_buf [i]);
printf ("\n");
*/
if ( kbhit() )
{
switch ( getch() )
{
case 's':
Comm_w16(W_Mode_Register, (Mode_Value | GOSUSP) );
Comm_w16(W_Mode_Register, Mode_Value );
break;
case 'd':
// printf( "Interrupt Register = %08X\n", Comm_r32(R_Interrupt_Reg));
break;
case 'r':
Dc_printf( WHITE, CONTINUE, "Remote Wakeup in process!!\n");
Comm_w16( Unlock_Device, 0xAA37); // Unlock suspend --> resume
break;
case 'q':
case 0x1b:
in_loop=0;
break;
}
}
}
}
#endif // DC_ONLY
void dc_start_hw( void )
{
Comm_w32(W_Int_Enable, Int_Enable_Value);
Comm_r32(R_Interrupt_Reg);
Comm_w16(W_Mode_Register, Comm_r16(R_Mode_Register) | 0x08);
Dc_printf( WHITE, CONTINUE, "Device Controller Initialized\r\n" );
// mprintf( LIGHTGRAY, CONTINUE, "DC operation started...\r\n" );
}
void dc_init_hw( void )
{
string_descriptor_init();
OTG_Dc_bus_reset();
Comm_w16( Unlock_Device, 0xAA37);
Comm(Reset_Device);
Comm_w16(W_Device_Address, 0x80);
if ( gp_is_PCI )
Comm_w16(W_Hw_Config, Hw_Cfg_Value & ~0x1 );
else
Comm_w16(W_Hw_Config, Hw_Cfg_Value );
Comm_w16(W_Mode_Register, 0x80);
}
extern unsigned long gp_sof_counter;
void dc_bus_event_eval( void )
{
disable_INT();
disable_Dc();
if (intr_1.busreset)
{
Dc_printf( WHITE, CONTINUE, "Bus Reset!!\r\n");
intr_1.busreset=0;
OTG_Dc_bus_reset();
}
else if (intr_1.suspend)
{
Dc_printf( WHITE, CONTINUE, "Suspend!!\r\n" );
intr_1.suspend=0;
OTG_Dc_bus_suspend();
}
else if (intr_1.resume)
{
Dc_printf( WHITE, CONTINUE, "Resume!!\r\n" );
intr_1.resume=0;
OTG_Dc_bus_resume();
}
enable_INT();
}
unsigned char g_dc_suspend_state = False;
unsigned char g_dc_interrupt_enable;
void dc_set_dc_suspend( void )
{
if ( g_dc_suspend_state )
return;
g_dc_interrupt_enable = Comm_r32( R_Int_Enable ); // Save previous interrupt enable bits
Comm_w32( W_Int_Enable, 0 ); // Mask all interrupt
Comm_r32( R_Interrupt_Reg ); // Clear interrupt
Comm_w16(W_Mode_Register, (Mode_Value | GOSUSP) ); // Get into suspend
Comm_w16(W_Mode_Register, Mode_Value ); // Get into suspend
g_dc_suspend_state = True;
}
void dc_set_dc_wakeup( void )
{
Comm_r16( R_Chip_Id ); // Assert ChipSelect line to wake-up
wait_ms( 1 ); // Wait for PLL lock
Comm_w16( Unlock_Device, 0xAA37); // Unlock device
mprintf( LIGHTRED, CONTINUE, "R_Chip_Id = 0x%04X\r\n", Comm_r16( R_Chip_Id ) );
Comm_r32(R_Interrupt_Reg); // Clear interrupts
Comm_w32( W_Int_Enable, g_dc_interrupt_enable ); // Restore interrupt enable
g_dc_suspend_state = False;
}
unsigned char dc_dc_in_suspend( void )
{
return ( g_dc_suspend_state );
}
void dc_periodic_monitor( void )
{
dc_control_handler();
dc_bus_event_eval();
}
void dc_test( void )
{
mprintf( LIGHTRED, CONTINUE, "\r\nR_Chip_Id=0x%02X 0x%04X\r\n", (unsigned char)R_Chip_Id, Comm_r16( R_Chip_Id ) );
}
void DC_initialize( void )
{
dc_init_hw(); // DC
dc_init_isr(); // DC
dc_start_hw();
gene_install_asynchronous_periodic_process( 2, dc_periodic_monitor );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -