📄 u_request.c
字号:
/******************************************************************************
* File name : request.c
* Module name : USB request module
* Author : Hiromichi.Kondo
*----------------------------------------------------------------------------
* $Id: request.c,v 1.2 2003/04/16 10:18:10 9551619 Exp $
*****************************************************************************/
#include "u_value.h"
#include "u_ram_data.h"
#include "u_rom_data.h"
#include "u_regNikka.h"
#include "u_dev_fp.h"
#include "u_com_fp.h"
/*--- Function Prototype ---------------------------------------------------*/
int StandardRequest(void);
int ClassRequest(void);
int VendorRequest(void);
int GetStatus(void);
int ClearFeature(void);
int SetFeature(void);
int SetAddress(void);
int GetDescriptor(void);
int GetConfiguration(void);
int SetConfiguration(void);
int SetInterface(void);
int GetInterface(void);
int RequestError(void);
void SetAlternateInterface(BYTE alternate_valid);
int BulkOnlyMassStorageReset(void);
int GetMaxLUN(void);
int AcceptDeviceSpecificCmd(void);
int TestEP0Out(void);
int TestEP0In(void);
/*****************************************************************************
*
* :
*
* :
* :
* :
* :
*
*****************************************************************************/
int (*const standard_req_tbl[])(void) = {
GetStatus, /* 00h Get Status */
ClearFeature, /* 01h Clear Feature */
RequestError, /* 02h Reserved for future use */
SetFeature, /* 03h Set Feature */
RequestError, /* 04h Reserved for future use */
SetAddress, /* 05h Set Address */
GetDescriptor, /* 06h Get Descriptor */
RequestError, /* 07h Set Descriptor */
GetConfiguration, /* 08h Get Configuration */
SetConfiguration, /* 09h Set Configuration */
GetInterface, /* 0Ah Get Interface */
SetInterface, /* 0Bh Set Interface */
RequestError}; /* 0Ch Synch Frame */
int StandardRequest(void)
{
int ret;
if (rEP0SETUP_1 < 0x0D) {
ret = standard_req_tbl[rEP0SETUP_1]();
} else {
/* RequestError */
ret = RequestError();
}
return ret;
}
/*****************************************************************************
*
* :
*
* :
* :
* :
* :
*
*****************************************************************************/
int ClassRequest(void)
{
int ret;
switch(rEP0SETUP_1){
case ACCEPT_DEV_SPC_CMD:
ret = AcceptDeviceSpecificCmd();
break;
case B_ONLY_STORAGE_RST:
ret = BulkOnlyMassStorageReset();
break;
case GET_MAX_LUN:
ret = GetMaxLUN();
break;
default:
ret = REQUEST_ERROR;
break;
}
return ret;
}
/*****************************************************************************
*
* :
*
* :
* :
* :
* :
*
*****************************************************************************/
int VendorRequest(void)
{
int ret;
switch(rEP0SETUP_1){
case TEST_EP0_OUT:
ret = TestEP0Out();
break;
case TEST_EP0_IN:
ret = TestEP0In();
break;
default:
ret = REQUEST_ERROR;
}
return ret;
}
/*****************************************************************************
*
* : Get Stateus
* :
* :
* :
* : usb_state
* usb_wk_data[] USB
* usb_flag USB
* total_tran_cnt
* actual_tran_cnt
* tran_start_addr
*
*****************************************************************************/
int GetStatus(void)
{
int i, ret = REQUEST_ERROR;
if(usb_state != DEFAULT_STATE){ /* Default */
if((rEP0SETUP_0 & 0x80) == 0x80){ /* */
switch(rEP0SETUP_0 & 0x1F){
case RECIPIENT_DEVICE:
if(rEP0SETUP_3 || rEP0SETUP_2){ /* wValue */
break;
}
if(rEP0SETUP_5 || rEP0SETUP_4){ /* wIndex */
break;
}
if(rEP0SETUP_7 || rEP0SETUP_6 != 0x02){ /* wLength */
break;
}
/* */
usb_wk_data[0] = (usb_flag.EnbRemoteWakeup << 1) + 0x01;
/* Self Powerd(0x01) */
usb_wk_data[1] = 0x00;
total_tran_cnt = actual_tran_cnt = 0x02;
tran_start_addr = &usb_wk_data[0];
ret = REQUEST_OK;
break;
case RECIPIENT_INTERFACE:
if(usb_state == ADDRESS_STATE){
break;
}
if(rEP0SETUP_3 || rEP0SETUP_2){ /* wValue */
break;
}
if(rEP0SETUP_5 || rEP0SETUP_4){ /* wIndex */
break;
}
if(rEP0SETUP_7 || rEP0SETUP_6 != 0x02){ /* wLength */
break;
}
/* */
usb_wk_data[0] = usb_wk_data[1] = 0x00;
total_tran_cnt = actual_tran_cnt = 0x02;
tran_start_addr = &usb_wk_data[0];
ret = REQUEST_OK;
break;
case RECIPIENT_ENDPOINT:
if(rEP0SETUP_3 || rEP0SETUP_2){ /* wValue */
break;
}
if(rEP0SETUP_5){ /* wIndex.h */
break;
}
if(rEP0SETUP_7 || rEP0SETUP_6 != 0x02){ /* wLength */
break;
}
if(rEP0SETUP_4 == 0){
/* EndPoint 0 */
if(rEP0ControlIN_BP.ForceSTALL || rEP0ControlOUT_BP.ForceSTALL){
usb_wk_data[0] = 0x01;
}else{
usb_wk_data[0] = 0x00;
}
usb_wk_data[1] = 0x00;
total_tran_cnt = actual_tran_cnt = 0x02;
tran_start_addr = &usb_wk_data[0];
ret = REQUEST_OK;
}else{
if(usb_state == ADDRESS_STATE){
break;
}
for( i=0; i<NUM_ENDPOINT; i++ ){
if( rEP0SETUP_4 == ep_number[i] ){
if( i == 0 ){
/* EndPoint a */
if(rEPaControl_BP.ForceSTALL){
usb_wk_data[0] = 0x01;
}else{
usb_wk_data[0] = 0x00;
}
}else{
if( i == 1 ){
/* EndPoint b */
if(rEPbControl_BP.ForceSTALL){
usb_wk_data[0] = 0x01;
}else{
usb_wk_data[0] = 0x00;
}
}else{
if( i == 2 ){
/* EndPoint c */
if(rEPcControl_BP.ForceSTALL){
usb_wk_data[0] = 0x01;
}else{
usb_wk_data[0] = 0x00;
}
}
}
}
usb_wk_data[1] = 0x00;
total_tran_cnt = actual_tran_cnt = 0x02;
tran_start_addr = &usb_wk_data[0];
ret = REQUEST_OK;
}
}
}
}
}
}
return ret;
}
/*****************************************************************************
*
* : Clear Feature
* :
* :
* :
* : usb_state
* fs_config_desc[] FSConfiguration
* hs_config_desc[] HSConfiguration
* usb_flag USB
* protocol_phase
* bulk_in_state Bulk IN
* bulk_out_state Bulk OUT
* int_in_state Interrupt IN
*
*****************************************************************************/
int ClearFeature(void)
{
int i, ret = REQUEST_ERROR;
if(usb_state != DEFAULT_STATE){ /* */
if((rEP0SETUP_0 & 0x80) == 0x00){ /* */
switch(rEP0SETUP_0 & 0x1F){
case RECIPIENT_DEVICE:
if(rEP0SETUP_3){ /* wValue.h */
break;
}
if(rEP0SETUP_2 == DEVICE_REMOTE_WAKEUP){
if(rEP0SETUP_5 || rEP0SETUP_4){ /* wIndex */
break;
}
if(rEP0SETUP_7 || rEP0SETUP_6){ /* wLength */
break;
}
if((fs_config_desc.bmAttributes & REMOTEWAKEUP) == 0){
break;
}
usb_flag.EnbRemoteWakeup = 0; /* RemoteWakeup */
ret = REQUEST_OK;
}else{
if(rEP0SETUP_2 == TEST_MODE){
#ifndef TEST_MODE_ON
break;
#endif /* TEST_MODE_ON */
if(rEP0SETUP_5 || rEP0SETUP_4){ /* wIndex */
break;
}
if(rEP0SETUP_7 || rEP0SETUP_6){ /* wLength */
break;
}
/* TestMode */
ret = REQUEST_OK;
}else{
ret = REQUEST_ERROR;
}
}
break;
case RECIPIENT_ENDPOINT:
if(rEP0SETUP_3){ /* wValue.h */
break;
}
if(rEP0SETUP_2 != ENDPOINT_HALT){
break;
}
if(rEP0SETUP_5){ /* wIndex.h */
break;
}
if(rEP0SETUP_7 || rEP0SETUP_6){ /* wLength */
break;
}
if(rEP0SETUP_4 != 0){
/* EndPoint 0 */
if(usb_state == ADDRESS_STATE){
break;
}
for( i=0; i<NUM_ENDPOINT; i++ ){
if( rEP0SETUP_4 == ep_number[i] ){
if( i == 0 ){
/* EndPoint a */
rEPaControl_BP.ToggleClr = 1;
if(rEPaControl_BP.ForceSTALL){
rEPrFIFO_Clr_BP.EPaFIFO_Clr = 1;
if(protocol_phase != RESET_WAIT){
rEPaControl_BP.ForceSTALL = 0;
bulk_in_state = BULK_IN_IDLE;
if(protocol_phase == DATA_PHASE){
protocol_phase = STATUS_PHASE;
tran_flag.XferCmp = 1;
}
}
}
}else{
if( i == 1 ){
/* EndPoint b */
rEPbControl_BP.ToggleClr = 1;
if(rEPbControl_BP.ForceSTALL){
rEPrFIFO_Clr_BP.EPbFIFO_Clr = 1;
if(protocol_phase != RESET_WAIT){
rEPbControl_BP.ForceSTALL = 0;
bulk_out_state = BULK_OUT_IDLE;
if(protocol_phase == DATA_PHASE){
protocol_phase = STATUS_PHASE;
tran_flag.XferCmp = 1;
}
}
}
}else{
if( i == 2 ){
/* EndPoint c */
rEPcControl_BP.ToggleClr = 1;
if(rEPcControl_BP.ForceSTALL){
rEPrFIFO_Clr_BP.EPcFIFO_Clr = 1;
if(protocol_phase != RESET_WAIT){
rEPcControl_BP.ForceSTALL = 0;
int_in_state = INT_IN_IDLE;
}
}
}
}
}
usb_wk_data[1] = 0x00;
total_tran_cnt = actual_tran_cnt = 0x02;
tran_start_addr = &usb_wk_data[0];
ret = REQUEST_OK;
}
}
}
}
}
}
return ret;
}
/*****************************************************************************
*
* : Set Feature
* :
* :
* :
* : usb_state
* fs_config_desc[] FSConfiguration
* hs_config_desc[] HSConfiguration
* usb_flag USB
* test_packet[] TestModeTestPacket
* bulk_in_state Bulk IN
* bulk_out_state Bulk OUT
* int_in_state Interrupt IN
*
*****************************************************************************/
int SetFeature(void)
{
int i,ret = REQUEST_ERROR;
if((rEP0SETUP_0 & 0x80) == 0x00){ /* */
switch(rEP0SETUP_0 & 0x1F){
case RECIPIENT_DEVICE:
if(rEP0SETUP_3){ /* wValue */
break;
}
if(rEP0SETUP_2 == DEVICE_REMOTE_WAKEUP){
if(usb_state == DEFAULT_STATE){
break;
}
if(rEP0SETUP_5 || rEP0SETUP_4){ /* wIndex */
break;
}
if(rEP0SETUP_7 || rEP0SETUP_6){ /* wLength */
break;
}
if((fs_config_desc.bmAttributes & REMOTEWAKEUP) == 0){
break;
}
usb_flag.EnbRemoteWakeup = 1;
ret = REQUEST_OK;
}else{
if(rEP0SETUP_2 == TEST_MODE){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -