📄 dc_chap9.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 "ui.h"
#include "beep.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 "_otg/otg_demo.h"
struct {
unsigned char xfer_direction;
unsigned char type;
unsigned char recipient;
} bmRequestType;
unsigned char bRequest;
unsigned short wValue, wIndex, wLength;
unsigned short dc_config_value, dc_alt_setting_value;
STRING_DESCRIPTOR *string_dscrptr_manufacturer_ptr;
STRING_DESCRIPTOR *string_dscrptr_product_ptr;
STRING_DESCRIPTOR *string_dscrptr_serialnumber_ptr;
void ( *Standard_request[] )();
void ( *Class_request[] )();
void ( *Vendor_request[] )();
void Get_Status();
void Clear_Feature();
void Reserved();
void Set_Feature();
void Set_Address();
void Get_Descriptor();
void Set_Descriptor();
void Get_Configuration();
void Set_Configuration();
void Get_Interface();
void Set_Interface();
void Synch_Frame();
//void Vendor_request3( void );
unsigned long test=0;
unsigned short wCount;
unsigned short *pControlData;
void dc_control_handler()
{
int i;
if ( ctrl.setup )
{
hwacces_isr_hw_disable();
disable_INT();
bmRequestType.xfer_direction= (unsigned char)((setup_buf[0] & XFER_DIRECTION) >>7);
bmRequestType.type= (unsigned char)((setup_buf[0] & TYPE) >>5);
bmRequestType.recipient= (unsigned char)(setup_buf[0] & RECIPIENT);
bRequest= (unsigned char)(setup_buf[0]>>8);
wValue= setup_buf[1];
wIndex= setup_buf[2];
wLength= setup_buf[3];
wCount=0;
// for ( i=0; i<3; Dc_printf( WHITE, CONTINUE, "%04X ", change_endian( setup_buf[i++] ) ) );
// Dc_printf( WHITE, CONTINUE, "\r\n" );
if ( bmRequestType.type == 3 || bmRequestType.recipient >= 4 ) // Is received class Type or Recipient "Reserved"?
{
ctrl.setup=0;
Stall_handshake();
return;
}
if ( bmRequestType.xfer_direction ) // Device to Host
ctrl.read=1;
else
if ( wLength ) // Setup followed by Data?
ctrl.write=1;
if ( bmRequestType.type == 0 ) // standard request
( *Standard_request[ bRequest ] )();
if ( bmRequestType.type == 1 ) // class request
( *Class_request[ bRequest ] )();
if ( bmRequestType.type == 2 ) // vendor request
( *Vendor_request[ bRequest ] )();
ctrl.setup=0;
enable_INT();
hwacces_isr_hw_enable();
}
if ( vendor_specific.wait )
{
hwacces_isr_hw_disable();
disable_INT();
if ( vendor_specific.data )
{
io_req_data_stage();
}
enable_INT();
hwacces_isr_hw_enable();
}
}
void ( *Standard_request[] )()
={
Get_Status,
Clear_Feature,
Reserved,
Set_Feature,
Reserved,
Set_Address,
Get_Descriptor,
Set_Descriptor,
Get_Configuration,
Set_Configuration,
Get_Interface,
Set_Interface,
Synch_Frame
};
void ( *Class_request[] )()
={
Reserved
};
void ( *Vendor_request[] )()
={
Reserved,
Reserved,
Reserved,
Vendor_request3,
Reserved,
Reserved,
Reserved,
Reserved,
Reserved,
Reserved,
Reserved,
Reserved,
io_request,
Reserved,
Reserved,
Reserved
};
/*
char g_s[ 64 ];
unsigned short g_length;
void Vendor_request3( void )
{
if ( ( wValue >> 8 ) == OTG_DEMO_GET_A_STRING ) // Get Hello ?
{
OTG_demo_peripheral_side_7( g_s, &g_length, wValue & 0xF );
start_transmit( (unsigned short *)g_s, g_length );
Dc_printf( WHITE, CONTINUE, "Hello message returned. by request from remote\r\n" );
}
else if ( ( wValue >> 8 ) == OTG_DEMO_CTRL_AUDIO ) // Get list item ?
{
unsigned char start = 0;
start = OTG_demo_peripheral_side_9_0( g_s, &g_length, wValue );
start_transmit( (unsigned short *)g_s, g_length );
if ( start )
OTG_demo_peripheral_side_9_11( wValue );
}
else if ( ( wValue >> 8 ) == OTG_DEMO_CLOCK_SYNC ) // Clock sync
{
OTG_demo_peripheral_side_1( g_s, &g_length );
start_transmit( (unsigned short *)g_s, g_length );
Dc_printf( WHITE, CONTINUE, "Sending time info 0x%08lX 0x%08lX l=%u\r\n", *((unsigned long *)g_s), *((unsigned long *)(g_s + 4)), g_length );
}
else if ( ( wValue >> 8 ) == OTG_DEMO_BAR_DISPLAY ) // Dummy data transfer ?
{
OTG_demo_peripheral_side_8( wValue & 0xFF );
start_transmit( (unsigned short *)g_s, 64 );
Dc_printf( WHITE, CONTINUE, "Dummy data transfer (%02d - %d)\r", wValue & 0x7F, wValue >> 7 );
if ( (wValue & 0xFF) == 69 )
Dc_printf( WHITE, CONTINUE, "\r\n" );
}
else if ( ( wValue >> 8 ) == OTG_DEMO_APP_UPDATE ) // Dummy data transfer ?
{
OTG_demo_peripheral_side_0( g_s, &g_length, wValue & 0xFF );
start_transmit( (unsigned short *)g_s, g_length );
Dc_printf( WHITE, CONTINUE, "file data transfer %d\r", wValue & 0xFF );
}
else if ( ( wValue >> 8 ) == OTG_DEMO_REMOTE_AUDIO ) // data transfer through EP1?
{
OTG_demo_peripheral_side_2( g_s, &g_length, wValue & 0xFF );
if ( ctrl.read==1 )
start_transmit( (unsigned short *)g_s, g_length );
else
{
vendor_specific.data = 0;
vendor_specific.wait = 0;
zero_packet();
}
Dc_printf( WHITE, CONTINUE, "remote command : 0x%02X\r\n", wValue & 0xFF );
}
else if ( ( wValue >> 8 ) == OTG_DEMO_REMOTE_BEEP ) // Get Hello ?
{
OTG_demo_peripheral_side_3( g_s, &g_length, wValue & 0xF );
start_transmit( (unsigned short *)g_s, g_length );
Dc_printf( WHITE, CONTINUE, "Hello message returned. by request from remote\r\n" );
}
else // Unsupported Descriptor?
{
Stall_handshake();
ctrl.read=0;
}
}
*/
/* Standard Request */
void Get_Status()
{
unsigned short status;
if ( bmRequestType.recipient == 0 ) // Device
{
status = 0x0003; // remote-wakeup, self-powered
start_transmit( &status, 2 );
}
if ( bmRequestType.recipient == 1 ) // Interface
{
status = 0x0000;
start_transmit( &status, 2 );
}
if ( bmRequestType.recipient == 2 ) // Endpoint
{
status = Comm_r16( Chk_Ep_Status + ( (unsigned char)wIndex & 0x00F) ) & 0x0080;
status >>= 7;
start_transmit( &status, 2 );
}
}
void Clear_Feature()
{
if ( bmRequestType.recipient == 0 ) // Device
{
if ( wValue == DEVICE_REMOTE_WAKEUP )
{
//???????
zero_packet();
//Stall_handshake();
}
else Stall_handshake();
}
if ( bmRequestType.recipient == 1 ) // Interface
{
Stall_handshake();
}
if ( bmRequestType.recipient == 2 ) // Endpoint
{
if ( wValue == ENDPOINT_STALL )
{
Comm(Unstall_Ep + ( (unsigned char)wIndex & 0x7F ) ); // endpoint stall
zero_packet(); // end of status stage
}
else Stall_handshake();
}
}
void Reserved()
{
Stall_handshake();
}
void Set_Feature()
{
Dc_printf( WHITE, CONTINUE, "Set_Feature()\r\n" );
if ( bmRequestType.recipient == 0 ) // Device
{
if ( wValue == DEVICE_REMOTE_WAKEUP )
{
//???????
zero_packet();
//Stall_handshake();
}
else if ( wValue == 3 )
{
OTG_host_enable_command_from_A_device( wValue );
zero_packet();
}
else if ( wValue == 4 )
{
OTG_host_enable_command_from_A_device( wValue );
zero_packet();
}
else if ( wValue == 5 )
{
OTG_host_enable_command_from_A_device( wValue );
zero_packet();
}
else Stall_handshake();
}
if ( bmRequestType.recipient == 1 ) // Interface
{
Stall_handshake();
}
if ( bmRequestType.recipient == 2 ) // Endpoint
{
if ( wValue == ENDPOINT_STALL )
{
Comm(Stall_Ep + ( (unsigned char)wIndex & 0x7F ) ); // endpoint stall
zero_packet(); // end of status stage
}
else Stall_handshake();
}
}
void Set_Address()
{
Comm_w16( W_Device_Address, ( 0x80 | (unsigned char) wValue ) );
zero_packet(); // end of status stage
Dc_printf( WHITE, CONTINUE, "Set Address (New Address %d)\r\n", (unsigned char) wValue );
}
void Get_Descriptor()
{
if ( ( wValue >> 8 ) == DEVICE ) // Get Device Descriptor?
{
start_transmit( (unsigned short *)&device_dscrptr, (unsigned short)sizeof ( DEVICE_DESCRIPTOR ) );
Dc_printf( WHITE, CONTINUE, "Get Descriptor (Device)\r\n" );
}
else if ( ( wValue >> 8 ) == CONFIGURATION ) // Get Configuration Descriptor?
{
start_transmit( (unsigned short *)&configuration_dscrptr_table, (unsigned short)sizeof ( CONFIG_DESCRIPTOR_TABLE ) );
Dc_printf( WHITE, CONTINUE, "Get Descriptor (Configuration)\r\n" );
}
else if ( ( wValue >> 8 ) == OTG )
{
start_transmit( (unsigned short *)&otg_dscrptr, (unsigned short)sizeof (OTG_DESCRIPTOR ) );
Dc_printf( WHITE, CONTINUE, "Get Descriptor (On-The-Go)\r\n" );
}
else if ( ( wValue >> 8 ) == STRING ) // Get String Descriptor?
{
switch ( wValue & 0x00FF )
{
case 0:
{
start_transmit( (unsigned short *)&string_langid, (unsigned short)sizeof ( STRING_LANGID) );
Dc_printf( WHITE, CONTINUE, "Get Descriptor (String 0)\r\n" );
break;
}
#if 0
case 1:
{
start_transmit( (unsigned short *)&string_dscrptr_manufacturer, (unsigned short)sizeof ( STRING_DESCRIPTOR) );
Dc_printf( WHITE, CONTINUE, "Get Descriptor (String 1)\r\n" );
break;
}
case 2:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -