📄 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 + -