?? chap_9.c
字號:
/****************************************Copyright (c)**************************************************
** Guangzhou ZLG-MCU Development Co.,LTD.
** graduate school
** http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name: Chap_9.c
** Last modified Date: 2004-12-10
** Last Version: V1.0
** Descriptions: USB驅動程序軟件包: ISP1181B(D13) 設備端驅動程序 協議層
** Soft Packet of USB Driver: the Driver of Device of ISP1181B(D13)
** Protocol layer
**------------------------------------------------------------------------------------------------------
** Created by:
** Created date:
** Version:
** Descriptions:
**
**------------------------------------------------------------------------------------------------------
** Modified by: Ming Yuan Zheng
** Modified date: 2004-12-10
** Version: V1.0
** Descriptions: The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
********************************************************************************************************/
#include "config.h"
#include "D13Config.h"
#include "D13CI.h"
#include "Chap_9.h"
#include "Descriptor.h"
//定義控制傳輸結構變量 define structure variable of control transfer
CONTROL_XFER ControlData;
//定義USB事件標志變量 define the flag varialbe of USB events
EPPFLAGS bEPPflags;
extern OS_EVENT *pSetup_Event;
//***********************************************************************************************
//USB標準設備請求入口地址指針表 the address pointer table of the normal device request of USB
//***********************************************************************************************
void (*StandardDeviceRequest[])(void) =
{
get_status,
clear_feature,
reserved,
set_feature,
reserved,
set_address,
get_descriptor,
reserved,
get_configuration,
set_configuration,
get_interface,
set_interface,
reserved,
reserved,
reserved,
reserved
};
//*************************************************************************
// USB 協議層函數 the protocol function of USB
//*************************************************************************
/*************************************************************************************************************************
** 函數名稱: stall_ep0() Name: stall_ep0()
** 功能描述: 使控制端點處于停止狀態 Function: stall control endpoints ep0
** 輸 入: 無 Input: NULL
** 輸 出: 無 Output: NULL
*************************************************************************************************************************/
void stall_ep0(void)
{
D13_SetEndpointStatus(EPINDEX4EP0_CONTROL_OUT,D13REG_EPSTS_STALL); //停止控制端點OUT stall control OUT
D13_SetEndpointStatus(EPINDEX4EP0_CONTROL_IN,D13REG_EPSTS_STALL); //停止控制端點IN stall control IN
}
/************************************************************************************************************************
** 函數名稱: reserved() Name: reserved()
** 功能描述: 保留子程序 Function: reserved rountine
** 輸 入: 無 Input: NULL
** 輸 出: 無 Output: NULL
*************************************************************************************************************************/
void reserved(void)
{
stall_ep0(); //禁止端點0 stall endpoint 0
}
/************************************************************************************************************************
** 函數名稱: init_unconfig() Name: init_unconfig()
** 功能描述: 對ISP1181B無作用 Function: it is not effective for ISP1181B
** 輸 入: 無 Input: NULL
** 輸 出: 無 Output: NULL
*************************************************************************************************************************/
void init_unconfig(void)
{
}
/************************************************************************************************************************
** 函數名稱: init_config() Name: init_config()
** 功能描述: 對ISP1181B無作用 Function: it is not effective for ISP1181B
** 輸 入: 無 Input: NULL
** 輸 出: 無 Output: NULL
*************************************************************************************************************************/
void init_config(void)
{
}
/************************************************************************************************************************
** 函數名稱: single_transmit() Name: single_transmit()
** 功能描述: 通過IN端點發送數據(DATA 類型) Function: send data(type DATA) via CONTROL_IN
** 輸 入: INT8U * buf: 發送數據指針 Input: INT8U * buf: send buffer
INT8U len: 發送數據長度 INT8U len: send length
** 輸 出: 無 Output: NULL
*************************************************************************************************************************/
void single_transmit(INT8U * buf, INT8U len)
{
if( len <= EP0_PACKET_SIZE) { //通過控制輸入端點發送數據
D13_WriteEndpoint(1, len, buf); //send data via CONTROL_IN
}
}
/***********************************************************************************************************************
** 函數名稱: code_transmit() Name: code_transmit()
** 功能描述: 通過OUT端點發送數據(CODE類型) Function: send data(type CODE) via CONTROL_IN
** 輸 入: INT8U *pRomData: 發送數據指針 Input: INT8U *pRomData: send buffer
INT8U len: 發送數據長度 INT8U len: send length
** 輸 出: 無 Output: NULL
************************************************************************************************************************/
void code_transmit(INT8U * pRomData, INT16U len)
{
ControlData.wCount = 0;
if(ControlData.wLength > len)
ControlData.wLength = len; //傳輸數據總字節數不得超過len
//the number of bytes that will be sent is not
//beyond len
ControlData.pData = pRomData;
if( ControlData.wLength >= EP0_PACKET_SIZE) { //發送端點0最大信息包大小個字節
D13_WriteEndpoint(1, EP0_PACKET_SIZE, ControlData.pData); //transmit the number of bytes of EP0_PACKET_SIZE
ControlData.wCount += EP0_PACKET_SIZE;
bEPPflags.bits.control_state = USB_TRANSMIT; //標志數據發送狀態
//mark the status that data be transmitted
}
else {
D13_WriteEndpoint(1, ControlData.wLength, pRomData); //發送需要傳輸的字節數
ControlData.wCount += ControlData.wLength; //transmit the numbers of bytes of ControlData.wLength
bEPPflags.bits.control_state = USB_IDLE; //標志空閑狀態
//mark the idle status
}
}
//*******************************************************************************
// USB 標準設備請求服務程序 the normal device request program of USB
//*******************************************************************************
/*************************************************************************************************************************
** 函數名稱: get_status() Name: get_status()
** 功能描述: 主機要求獲取狀態,設備返回16位 Function: the host request the status,the device return
的狀態描述給主機 the status descriptor to host
** 輸 入: 無 Input: NULL
** 輸 出: 無 Output: NULL
*************************************************************************************************************************/
void get_status(void)
{
INT8 endp;
INT8U txdat[2], c;
INT8U bRecipient = ControlData.DeviceRequest.bmRequestType & USB_RECIPIENT;
//取得設備請求類型 get the request type of device
if (bRecipient == USB_RECIPIENT_DEVICE) { //對設備請求 request of deviece
if(bEPPflags.bits.remote_wakeup == 1)
txdat[0] = 3; //支持遠程喚醒和自供電 support remove wakeup and power itself
else
txdat[0] = 1; //不支持遠程喚醒和自供電 not support remove wakeup and power itself
txdat[1]=0; //高8位為0 the upper byte is zero
single_transmit(txdat, 2); //發送16位的狀態到主機 transmit 16-bit to USB host
} else if (bRecipient == USB_RECIPIENT_INTERFACE) { //對接口請求 request of interface
txdat[0]=0;
txdat[1]=0;
single_transmit(txdat, 2);
} else if (bRecipient == USB_RECIPIENT_ENDPOINT) { //對端點請求 request of endpoint
endp = (INT8U)(ControlData.DeviceRequest.wIndex & MAX_ENDPOINTS);
if ((ControlData.DeviceRequest.wIndex & (INT8U)USB_ENDPOINT_DIRECTION_MASK) == 0){
if (endp == 0)
endp = -1; //被請求的端點為控制OUT the requested endpoint is control OUT
}
c = D13_GetEndpointStatusWOInteruptClear(endp + 1); //讀取輸出端點狀態 read the status of output endpoint
if(c & D13REG_EPSTS_STALL)
txdat[0] = 1; //端點禁止 disable endpoint
else
txdat[0] = 0; //端點有效 enable endpoint
txdat[1] = 0;
single_transmit(txdat, 2);
} else
stall_ep0(); //非標準請求,發STALL the unknown request,transmit stall
}
/***********************************************************************************************************************
** 函數名稱: clear_feature() Name: clear_feature()
** 功能描述: 清除特性 Function: clear feature
** 輸 入: 無 Input: NULL
** 輸 出: 無 Output: NULL
************************************************************************************************************************/
void clear_feature(void)
{
INT8 endp;
INT8U bRecipient = ControlData.DeviceRequest.bmRequestType & USB_RECIPIENT;
//讀取請求類型 get the request type
if (bRecipient == USB_RECIPIENT_DEVICE //對設備請求 the request of device
&& ControlData.DeviceRequest.wValue == USB_FEATURE_REMOTE_WAKEUP) {
bEPPflags.bits.remote_wakeup = 0; //清0遠程喚醒標志 clear the flag of remove wakeup
single_transmit(0, 0); //發回一個空的數據表示執行完畢
} //indicate that transmit end by transmitting a empty packet
else if (bRecipient == USB_RECIPIENT_ENDPOINT //對端點請求 the request of enpoint
&& ControlData.DeviceRequest.wValue == USB_FEATURE_ENDPOINT_STALL) {
//清除端點禁止特性,恢復其使用
endp = (INT8U)(ControlData.DeviceRequest.wIndex & MAX_ENDPOINTS);
if ((ControlData.DeviceRequest.wIndex & (INT8U)USB_ENDPOINT_DIRECTION_MASK) == 0){
if (endp == 0)
endp = -1; //被請求的端點為控制OUT the requested endpoint is control OUT
}
D13_SetEndpointStatus(endp + 1, 0); //解禁端點 unstall OUT endpoint
single_transmit(0, 0); //發回一個空的數據表示執行完畢
} else //indicate that transmit end by transmitting a empty packet
stall_ep0(); //非標準請求,發STALL
//the unknown request,transmit stall
}
/**********************************************************************************************************************
** 函數名稱: set_feature() Name: set_feature()
** 功能描述: 設置特性 Function: set feature
** 輸 入: 無 Input: NULL
** 輸 出: 無 Output: NULL
***********************************************************************************************************************/
void set_feature(void)
{
INT8 endp;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -