📄 usbdriver.h
字号:
/****************************************Copyright (c)**************************************************
** Guangzou ZLG-MCU Development Co.,LTD.
** graduate school
** http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name: USBDriver.h
** Last modified Date: 2005-8-6
** Last Version: V1.0
** Descriptions: LPC214x USB 应用层
** LPC214x USB Application Layer
**------------------------------------------------------------------------------------------------------
** Created by: 郑明远 MingYuan Zheng
** Created date: 2005-8-6
** Version: V1.0
** Descriptions: 初始版本 The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
********************************************************************************************************/
#ifndef __USBDRIVER_H__
#define __USBDRIVER_H__
#include "Descriptor.h"
/**************** 定义 USB 收发错误码 ***************************/
#define USB_NO_ERR 0x00 //正确
#define USB_ERR_NO_CONFIG 0x01 //USB总线未配置完成错误
#define USB_ERR_BUFF_INVALID 0x02 //接收或发送缓冲区错误
#define USB_ERR_WR_TIMEOUT 0x03 //接收或发送超时错误
#define USB_ERR_READ_TESTREG 0x10 //读测试寄存器失败
#define USB_ERR_CREATE_SEM 0x11 //创建信号量失败
#define USB_ERR_ENDP_OCCUPY 0x12 //端点已被其它任务占用
/*************** 定义 USB 接收或发送控制块 **********************/
typedef struct tagUsb_Struct
{
OS_EVENT *Ep_Sem; /* 端点收/发信号量 */
INT8U bEpUsed; /* 端点正被其它任务使用 */
INT8U bTaskWaiting; /* 任务已进入等待接收状态 或 等待数据发送完成状态 */
INT8U bEpReady; /* OUT端点已收到数据 或IN端点中的数据已发送到USB主机 */
/* 下面的成员与DMA相关*/
#if DMA_ENGINE_EN
INT8U *buff; /* 用户接收/发送缓冲区 */
INT32U len; /* 接收/发送数据长度 */
INT32U cnt; /* 计数器 */
#endif
}CTRL_USB;
extern CTRL_USB Ctrl_Usb[NUM_ENDPOINTS];
/************ USB Event Flag Structure *********************/
typedef union _epp_flags
{
struct _flags
{
unsigned setup_packet : 1; //receive SETUP packet
unsigned remote_wakeup : 1; //remote wakeup
unsigned control_state : 2; //control endpoint status
//0: IDLE
//1: TRANSMIT
//2: RECEIVE
unsigned configuration : 1; //usb configured (0: no; 1: yes)
unsigned command : 1; //reserved
} bits;
INT16U value;
} EPPFLAGS;
extern EPPFLAGS bEPPflags;
/*************************************************************
*
* 下面为向用户开放的 API 函数
*
**************************************************************/
/***********************************************************************************************************************
** 函数名称 : USB_Initialize() Name : USB_Initialize()
** 功能描述 : 初始化 USB 设备控制器 Function : Initialize the USB device controller
** 输 入 : 无 Input : NULL
** 输 出 : 0: 初始化成功 >0: 初始化失败(错误码) Output : 0: Initialize sucessfully >0: Initialize fail(error code)
***********************************************************************************************************************/
extern INT8U USB_Initialize(void);
/*******************************************************************************************************************************
** 函数名称: INT8U ReadPort1() Name: INT8U ReadPort1()
** 功能描述: 从端口 1 接收len个字节 Function: receive len Bytes from Port1
** 输 入: INT32U len: 要接收的字节数 Input: INT32U len: numbers will be receive
(取值范围为0x00000001 ~ 0xFFFFFFFF) (range: 0x00000001 ~ 0xFFFFFFFF)
INT8U recbuff: 接收缓冲区指针 INT8U recbuff: receive buffer
INT16U timeout: 超时等待时间, 等于0表示无限等待 INT16U timeout: timeout of receiving,0 indicates limitless waiting
** 输 出: 0: 接收成功 > 0: 接收失败(错误码) Output: 0: sucessfully >0 fail (error code)
*******************************************************************************************************************************/
extern INT8U ReadPort1(INT32U len, INT8U *recbuff, INT16U timeout);
/*******************************************************************************************************************************
** 函数名称: INT8U ReadPort2() Name: INT8U ReadPort2()
** 功能描述: 从端口 2 接收len个字节 Function: receive len Bytes from Port2
** 输 入: INT32U len: 要接收的字节数 Input: INT32U len: numbers will be receive
(取值范围为0x00000001 ~ 0xFFFFFFFF) (range: 0x00000001 ~ 0xFFFFFFFF)
INT8U recbuff: 接收缓冲区指针 INT8U sendbuff: receive buffer
INT16U timeout: 超时等待时间, 等于0表示无限等待 INT16U timeout: timeout of receiving,0 indicates limitless waiting
** 输 出: 0: 接收成功 > 0: 接收失败(错误码) Output: 0: sucessfully >0 fail (error code)
*******************************************************************************************************************************/
extern INT8U ReadPort2(INT32U len, INT8U *recbuff, INT16U timeout);
/*******************************************************************************************************************************
** 函数名称: INT8U WritePort1() Name: INT8U WritePort1()
** 功能描述: 用端口 1 发送len个字节 Function: Send len Bytes via Port1
** 输 入: INT32U len: 发送的字节数 Input: INT32U len: numbers will be send
(取值范围为0x00000001 ~ 0xFFFFFFFF) (range: 0x00000001 ~ 0xFFFFFFFF)
INT8U sendbuff: 发送缓冲区指针 INT8U sendbuff: send buffer
INT16U timeout: 超时等待时间, 等于0表示无限等待 INT16U timeout: timeout of transmitting,0 indicates limitless waiting
** 输 出: 0: 发送成功 > 0: 发送失败(错误码) Output: 0: sucessfully >0 fail (error code)
*******************************************************************************************************************************/
extern INT8U WritePort1(INT32U len, INT8U *sendbuff, INT16U timeout);
/*******************************************************************************************************************************
** 函数名称: INT8U WritePort2() Name: INT8U WritePort2()
** 功能描述: 用端口 2 发送len个字节 Function: Send len Bytes via Port2
** 输 入: INT32U len: 发送的字节数 Input: INT32U len: numbers will be send
(取值范围为0x00000001 ~ 0xFFFFFFFF) (range: 0x00000001 ~ 0xFFFFFFFF)
INT8U sendbuff: 发送缓冲区指针 INT8U sendbuff: send buffer
INT16U timeout: 超时等待时间, 等于0表示无限等待 INT16U timeout: timeout of transmitting,0 indicates limitless waiting
** 输 出: 0: 发送成功 > 0: 发送失败(错误码) Output: 0: sucessfully >0 fail (error code)
*******************************************************************************************************************************/
extern INT8U WritePort2(INT32U len,INT8U *sendbuff,INT16U timeout);
/***************************************************************************************************************
** 函数名称 : Usb_Exception() Name : Usb_Exception()
** 功能描述 : USB 中断服务程序 Function : USB Interrupt Service Program
** 输 入 : 无 Input : NULL
** 输 出 : 无 Output : NULL
****************************************************************************************************************/
extern void Usb_Exception(void);
/***********************************************************************************************************************
** 函数名称: void TaskSetup(void *pdata) Name: void TaskSetup(void *pdata)
** 功能描述: 控制传输处理 Function: deal with control transfer
** 输 入: void *pdata 任务参数 Input: void *pdata: parameter of the task
** 输 出: 无 Output: NULL
** 注 意: 该任务的优先级应高于其它任务,才能在 Note: the prior of the task must be higher than other,so
任何情况下传输SETUP包 it will be sucessful when tranfering SETUP packet
************************************************************************************************************************/
extern void TaskSetup(void *pdata);
/*************** Setup包处理任务堆栈与事件 ****************************/
extern OS_STK TaskSetupStk[128];
extern OS_EVENT *pSetup_Event;
/**************** USBDriver.c内部使用函数 ************************/
extern void USB_ConfigEndpoint(void);
INT8U USB_RW_Param(CTRL_USB *pUsb, INT8U *pbuff);
void USB_RW_Result(INT8U endp, INT8U buffnums, CTRL_USB *pUsb, INT8U bread, INT8U berr);
INT8U USB_ReadPort(INT8U endp, INT32U eppsize, INT8U buffnums,
CTRL_USB *pUsb, INT32U len, INT8U *recbuff, INT16U timeout);
INT8U USB_WritePort(INT8U endp, INT32U eppsize, INT8U buffnums,
CTRL_USB *pUsb, INT8U *sendbuff, INT32U len, INT16U timeout);
void Usb_EpISR(INT8U endp);
extern INT8U USB_ReadPortDMA(INT8U endp, CTRL_USB *pUsb, INT32U len, INT8U *recbuff,
INT16U timeout);
extern INT8U USB_WritePortDMA(INT8U endp, CTRL_USB *pUsb, INT8U *sendbuff, INT32U len,
INT16U timeout);
void Usb_LPService(void);
void Usb_HPService(void);
void USB_BusReset(void);
void USB_SuspendChange(void);
void USB_ConnectChange(void);
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -