?? usbci.c
字號:
/****************************************Copyright (c)**************************************************
** Guangzou ZLG-MCU Development Co.,LTD.
** graduate school
** http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name: USBCI.c
** Last modified Date: 2007-07-09
** Last Version: V1.0
** Descriptions: LPC23xx USB 接口命令層
** LPC23xx USB Interface command layer
**------------------------------------------------------------------------------------------------------
** Created by: 鄭明遠 MingYuan Zheng
** Created date: 2007-07-09
** Version: V1.0
** Descriptions: 初始版本 The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
********************************************************************************************************/
#include "config.h"
#include "USBConfig.h"
#include "USBCI.h"
/********************************************************
操作USB設備寄存器 operate USB device register
*********************************************************/
/***************************************************************************************************************
** 函數名稱 : USB_ConfigEndpoint() Name : USB_ConfigEndpoint()
** 功能描述 : 配置 USB 設備端點 Function : Configurate the endpoint of the USB
** 輸 入 : INT8U endp : 物理端點號 Input : INT8U endp: the physical endpoint number
INT8U packetsize: 該端點的最大包大小 INT8U packetsize: the max packet size of the endpoint INT8U packetsize: the max packet size of the endpoint
** 輸 出 : 無 Output : NULL
****************************************************************************************************************/
void USB_ConfigMaxPaketSize(INT8U endp, INT32U packetsize)
{
/* or with the existing value of the register */
USBReEp |= (INT32U)(0x01 << endp); /* 與原來存在的寄存器值做或操作 */
/* load endpoint index Reg with physical endpoint no. */
USBEpInd = (INT32U)endp; /* 選擇端點 */
/* load the max packet size Register */
USBMaxPSize = (INT32U)packetsize; /* 寫入端點最大包長度值 */
/* check whether the EP_RLSED bit is set */
while((USBDevIntSt & EP_RLZEDINT) == 0); /* 等待處理完成 */
/* clear the EP_RLZED bit */
USBDevIntClr = EP_RLZEDINT; /* 清除中斷標志位 */
}
/*********************************************************
協議引擎命令 Protocol Engine Command
**********************************************************/
/***************************************************************************************************************
** 函數名稱 : USB_GetData() Name : USB_GetData()
** 功能描述 : 從USB命令數據寄存器中讀取數據 Function : Read data from USB Command Data Register
** 輸 入 : INT32U cmd : 命令 Input : INT32U cmd: command word
** 輸 出 : 讀到的一個字節 Output : the read byte
****************************************************************************************************************/
INT8U USB_GetData(INT32U cmd)
{
/* command */
USBCmdCode = cmd; /* 寫入命令字 */
/* wait for CDFULL = 1 */
while((USBDevIntSt & CDFULL) == 0); /* 等待USBDevIntSt寄存器的CDFULL位置1*/
/* clear the CDFULL bit */
USBDevIntClr = CDFULL; /* 清除CDFULL位 */
/* get the received data */
return USBCmdData; /* 讀取數據 */
}
/***************************************************************************************************************
** 函數名稱 : USB_SendCmd() Name : USB_SendCmd()
** 功能描述 : 向USB命令代碼寄存器寫入命令 Function : write a command to Command Code Register
** 輸 入 : INT32U cmd : 命令 Input : INT32U cmd : command
INT32U data: 數據 INT32U data: data
** 輸 出 : 無 Output : NULL
****************************************************************************************************************/
void USB_SendCmd(INT32U cmd, INT32U data)
{
/* command */
USBCmdCode = cmd; /* 寫入命令字 */
/* wait for CCEMPTY = 1 */
while((USBDevIntSt & CCEMPTY) == 0); /* 等待 USBDevIntSt 寄存器的 CCEMPTY 位置1 */
/* clear the CCEMPTY bit */
USBDevIntClr = CCEMPTY; /* 清除 CCEMPTY 位*/
if (data != 0) /* 如果還有數據階段 */
{
/* command */
USBCmdCode = data; /* 將數據編碼寫入命令代碼寄存器 */
/* wait for CCEMPTY = 1 */
while((USBDevIntSt & CCEMPTY) == 0); /* 等待 USBDevIntSt 寄存器的 CCEMPTY 位置1 */
/* clear the CCEMPTY bit */
USBDevIntClr = CCEMPTY; /* 清除 CCEMPTY 位*/
}
}
/****************************************************************
LPC23xx USB控制器相關命令 Related Command of LPC23xx USB
*****************************************************************/
/***************************************************************************************************************
** 函數名稱 : USB_ReadTestRegister() Name : USB_ReadTestRegister()
** 功能描述 : 讀測試寄存器 Function : Read the Test Register of USB
** 輸 入 : 無 Input : NULL
** 輸 出 : 測試寄存器的值 Output : the value of the Test Register
****************************************************************************************************************/
INT16U USB_ReadTestRegister(void)
{
INT16U temp;
USB_SendCmd(USBCMD_RDTEST_REG, 0);
temp = USB_GetData(USBDAT_RDTEST_REG); /* read LSB byte */
temp += (INT16U)USB_GetData(USBDAT_RDTEST_REG) << 8; /* read MSB byte */
return temp;
}
/***************************************************************************************************************
** 函數名稱 : USB_SetAddressEnable() Name : USB_SetAddressEnable()
** 功能描述 : 設置 USB 設備地址 Function : set the USB device address
** 輸 入 : INT8U bAddress: 主機分配的地址值 Input : INT8U bAddress: the address value
INT8U bEnable: 1 - 使能USB設備 INT8U bEnable: 1: enable the USB device
0 - 禁止USB設備 0: disable the device
** 輸 出 : 無 Output : NULL
****************************************************************************************************************/
void USB_SetAddressEnable(INT8U bAddress, INT8U bEnable)
{
if (bEnable)
bAddress |= 0x80;
USB_SendCmd(USBCMD_SET_ADDRESS, ((INT32U)(bAddress << 16)) | USBDAT_SET_ADDRESS);
}
/***************************************************************************************************************
** 函數名稱 : USB_SetEndpointEnable() Name : USB_SetEndpointEnable()
** 功能描述 : 設置 USB 設備 Function : Configure USB Device
** 輸 入 : INT8U bEnble: 1 - 器件已配置 Input : INT8U bEnble: 1 - have finished configuring
0 - 器件未配置 0 - have not configured
** 輸 出 : 無 Output : NULL
****************************************************************************************************************/
void USB_SetEndpointEnable(INT8U bEnble)
{
USB_SendCmd(USBCMD_CONFIG_DEV, ((INT32U)(bEnble << 16)) | USBDAT_CONFIG_DEV);
}
/***************************************************************************************************************
** 函數名稱 : USB_SetMode() Name : USB_SetMode()
** 功能描述 : 設置模式 Function : Set Mode
** 輸 入 : INT8U value: 模式值 Input : INT8U value: the mode value
** 輸 出 : 無 Output : NULL
****************************************************************************************************************/
void USB_SetMode(INT8U value)
{
USB_SendCmd(USBCMD_SET_MODE, ((INT32U)(value << 16)) | USBDAT_SET_MODE);
}
/***************************************************************************************************************
** 函數名稱 : USB_SetDevStatus() Name : USB_SetDevStatus()
** 功能描述 : 設置設備狀態 Function : Set Device Status
** 輸 入 : INT8U value: 狀態值 Input : INT8U value: the Device Status
** 輸 出 : 無 Output : NULL
****************************************************************************************************************/
void USB_SetDevStatus(INT8U value)
{
USB_SendCmd(USBCMD_SET_DEVSTATUS, ((INT32U)(value << 16)) | USBDAT_SET_DEVSTATUS);
}
/***************************************************************************************************************
** 函數名稱 : USB_GetDevStatus() Name : USB_GetDevStatus()
** 功能描述 : 獲取設備狀態 Function : Get Device Status
** 輸 入 : NULL Input : NULL
** 輸 出 : USB 設備狀態字節 Output : the USB device status byte
****************************************************************************************************************/
INT8U USB_GetDevStatus(void)
{
USB_SendCmd(USBCMD_GET_DEVSTATUS, 0);
return USB_GetData(USBDAT_GET_DEVSTATUS);
}
/***************************************************************************************************************
** 函數名稱 : USB_SelectEndpoint() Name : USB_SelectEndpoint()
** 功能描述 : 選擇端點,并獲取端點信息 Function : select the endpoint, and get the endpoint information
** 輸 入 : INT8U endp: 物理端點號 Input : INT8U endp: the physical endpoint number
** 輸 出 : 對應端點的信息 Output : the endpoint information
****************************************************************************************************************/
INT8U USB_SelectEndpoint(INT8U endp)
{
INT32U tmp = (INT32U)(endp << 16);
USB_SendCmd(tmp | USBCMD_SEL_ENDP, 0);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -