?? 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: LPC23xx USB 應用層
** LPC23xx 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 + -