summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorHanhui <sylixos@gmail.com>2015-08-30 09:25:53 (GMT)
committer Hanhui <sylixos@gmail.com>2015-08-30 09:25:53 (GMT)
commit7f7535e1c73380480f3e74932b67bc953b12a82c (patch)
tree372dcb05b23c5dc90a1b15a5e43c2ed4a0d208ed
parent888ef69e9a5e0a567cdf1f5fb5c8817fecd04510 (diff)
parentcbcba97385654852b40610063eea8c5cf96f948b (diff)
downloadbspam335x-7f7535e1c73380480f3e74932b67bc953b12a82c.zip
bspam335x-7f7535e1c73380480f3e74932b67bc953b12a82c.tar.gz
bspam335x-7f7535e1c73380480f3e74932b67bc953b12a82c.tar.bz2
Merge branch 'master' of commit.git.sylixos.com:bspam335x
-rw-r--r--Makefile38
-rw-r--r--README.txt20
-rw-r--r--SylixOS/StarterWare/drivers/cppi41dma.c2044
-rw-r--r--SylixOS/StarterWare/drivers/usb.c3543
-rw-r--r--SylixOS/StarterWare/drivers/usbphyGS70.c109
-rw-r--r--SylixOS/StarterWare/usblib/device/usbdbulk.c1445
-rw-r--r--SylixOS/StarterWare/usblib/device/usbdcdc.c3020
-rw-r--r--SylixOS/StarterWare/usblib/device/usbdcdesc.c659
-rw-r--r--SylixOS/StarterWare/usblib/device/usbdcomp.c1196
-rw-r--r--SylixOS/StarterWare/usblib/device/usbdconfig.c673
-rw-r--r--SylixOS/StarterWare/usblib/device/usbdenum.c3113
-rw-r--r--SylixOS/StarterWare/usblib/device/usbdhandler.c210
-rw-r--r--SylixOS/StarterWare/usblib/device/usbdhid.c2665
-rw-r--r--SylixOS/StarterWare/usblib/device/usbdhidmouse.c845
-rw-r--r--SylixOS/StarterWare/usblib/device/usbdmsc.c2420
-rw-r--r--SylixOS/StarterWare/usblib/host/usbhhid.c677
-rw-r--r--SylixOS/StarterWare/usblib/host/usbhhidkeyboard.c730
-rw-r--r--SylixOS/StarterWare/usblib/host/usbhhidmouse.c419
-rw-r--r--SylixOS/StarterWare/usblib/host/usbhmsc.c678
-rw-r--r--SylixOS/StarterWare/usblib/host/usbhostenum.c4762
-rw-r--r--SylixOS/StarterWare/usblib/host/usbhscsi.c823
-rw-r--r--SylixOS/StarterWare/usblib/include/usb-ids.h61
-rw-r--r--SylixOS/StarterWare/usblib/include/usbcdc.h790
-rw-r--r--SylixOS/StarterWare/usblib/include/usbdbulk.h269
-rw-r--r--SylixOS/StarterWare/usblib/include/usbdcdc.h354
-rw-r--r--SylixOS/StarterWare/usblib/include/usbdcomp.h283
-rw-r--r--SylixOS/StarterWare/usblib/include/usbdevice.h143
-rw-r--r--SylixOS/StarterWare/usblib/include/usbdevicepriv.h67
-rw-r--r--SylixOS/StarterWare/usblib/include/usbdhid.h975
-rw-r--r--SylixOS/StarterWare/usblib/include/usbdhidmouse.h322
-rw-r--r--SylixOS/StarterWare/usblib/include/usbdmsc.h392
-rw-r--r--SylixOS/StarterWare/usblib/include/usbhhid.h203
-rw-r--r--SylixOS/StarterWare/usblib/include/usbhhidkeyboard.h78
-rw-r--r--SylixOS/StarterWare/usblib/include/usbhhidmouse.h70
-rw-r--r--SylixOS/StarterWare/usblib/include/usbhid.h661
-rw-r--r--SylixOS/StarterWare/usblib/include/usbhmsc.h147
-rw-r--r--SylixOS/StarterWare/usblib/include/usbhost.h580
-rw-r--r--SylixOS/StarterWare/usblib/include/usbhscsi.h111
-rw-r--r--SylixOS/StarterWare/usblib/include/usblib.h1903
-rw-r--r--SylixOS/StarterWare/usblib/include/usblibpriv.h136
-rw-r--r--SylixOS/StarterWare/usblib/include/usbmsc.h394
-rw-r--r--SylixOS/StarterWare/usblib/readme.txt21
-rw-r--r--SylixOS/StarterWare/usblib/usbbuffer.c1098
-rw-r--r--SylixOS/StarterWare/usblib/usbdata.c48
-rw-r--r--SylixOS/StarterWare/usblib/usbdesc.c479
-rw-r--r--SylixOS/StarterWare/usblib/usbkeyboardmap.c143
-rw-r--r--SylixOS/StarterWare/usblib/usbringbuf.c770
-rw-r--r--SylixOS/StarterWare/usblib/usbtick.c183
-rw-r--r--SylixOS/bsp/beaglebone/bspBeaglebone.c32
-rw-r--r--SylixOS/bsp/bspInit.c5
-rw-r--r--SylixOS/bsp/bspLib.c3
-rw-r--r--SylixOS/bsp/config.h1
-rw-r--r--SylixOS/bsp/forlinx/bspForlinx.c122
-rw-r--r--SylixOS/driver/dvfs/dvfs.c11
-rw-r--r--SylixOS/driver/i2c/am335x_i2c.c30
-rw-r--r--SylixOS/driver/netif/cpswif.c13
-rw-r--r--SylixOS/driver/tps65217/tps65217.c2
-rw-r--r--SylixOS/driver/usb/am335x_usb_hw_init.c (renamed from SylixOS/driver/usb/host/mouse/am335x_usb_mouse.h)47
-rw-r--r--SylixOS/driver/usb/am335x_usb_hw_init.h29
-rw-r--r--SylixOS/driver/usb/dev/bulk/am335x_usb_bulk.c338
-rw-r--r--SylixOS/driver/usb/dev/bulk/am335x_usb_bulk.h13
-rw-r--r--SylixOS/driver/usb/dev/bulk/usb_bulk_structs.c227
-rw-r--r--SylixOS/driver/usb/dev/bulk/usb_bulk_structs.h59
-rw-r--r--SylixOS/driver/usb/host/mouse/am335x_usb_mouse.c821
-rw-r--r--SylixOS/driver/usb/module/debug/usb.kobin0 -> 21886074 bytes
-rw-r--r--SylixOS/driver/usb/module/debug/usbdrv_am33xx.kobin0 -> 1052515 bytes
-rw-r--r--SylixOS/driver/usb/module/release/usb.kobin0 -> 3590668 bytes
-rw-r--r--SylixOS/driver/usb/module/release/usbdrv_am33xx.kobin0 -> 1052515 bytes
-rw-r--r--U-Boot.txt8
-rw-r--r--config.mk4
70 files changed, 251 insertions, 42284 deletions
diff --git a/Makefile b/Makefile
index 8f58f59..b77bb12 100644
--- a/Makefile
+++ b/Makefile
@@ -161,9 +161,7 @@ SylixOS/driver/memory/gpmc/gpmc.c \
SylixOS/driver/memory/gpmc/gpmc-nand.c \
SylixOS/driver/memory/nand/omap2.c \
SylixOS/driver/memory/am335x_nand.c \
-SylixOS/driver/usb/host/mouse/am335x_usb_mouse.c \
-SylixOS/driver/usb/dev/bulk/am335x_usb_bulk.c \
-SylixOS/driver/usb/dev/bulk/usb_bulk_structs.c \
+SylixOS/driver/usb/am335x_usb_hw_init.c \
SylixOS/driver/ft5x06/ft5x06.c \
SylixOS/driver/beep/beep.c \
SylixOS/driver/beep/beep_test.c \
@@ -174,7 +172,6 @@ SylixOS/driver/ds1337/ds1337_test.c
# StarterWare src(s) file
#*********************************************************************************************************
STARTERWARE_DRIVERS_SRCS = \
-SylixOS/StarterWare/drivers/cppi41dma.c \
SylixOS/StarterWare/drivers/cpsw.c \
SylixOS/StarterWare/drivers/dcan.c \
SylixOS/StarterWare/drivers/dmtimer.c \
@@ -195,8 +192,6 @@ SylixOS/StarterWare/drivers/raster.c \
SylixOS/StarterWare/drivers/rtc.c \
SylixOS/StarterWare/drivers/tsc_adc.c \
SylixOS/StarterWare/drivers/uart_irda_cir.c \
-SylixOS/StarterWare/drivers/usb.c \
-SylixOS/StarterWare/drivers/usbphyGS70.c \
SylixOS/StarterWare/drivers/watchdog.c
STARTERWARE_SYSTEM_CONFIG_SRCS = \
@@ -205,30 +200,6 @@ SylixOS/StarterWare/system_config/armv7a/am335x/clock.c \
SylixOS/StarterWare/system_config/armv7a/am335x/device.c \
SylixOS/StarterWare/system_config/armv7a/am335x/interrupt.c
-STARTERWARE_USBLIB_SRCS = \
-SylixOS/StarterWare/usblib/usbbuffer.c \
-SylixOS/StarterWare/usblib/usbdata.c \
-SylixOS/StarterWare/usblib/usbdesc.c \
-SylixOS/StarterWare/usblib/usbkeyboardmap.c \
-SylixOS/StarterWare/usblib/usbringbuf.c \
-SylixOS/StarterWare/usblib/usbtick.c \
-SylixOS/StarterWare/usblib/host/usbhhid.c \
-SylixOS/StarterWare/usblib/host/usbhhidkeyboard.c \
-SylixOS/StarterWare/usblib/host/usbhhidmouse.c \
-SylixOS/StarterWare/usblib/host/usbhmsc.c \
-SylixOS/StarterWare/usblib/host/usbhostenum.c \
-SylixOS/StarterWare/usblib/host/usbhscsi.c \
-SylixOS/StarterWare/usblib/device/usbdbulk.c \
-SylixOS/StarterWare/usblib/device/usbdcdc.c \
-SylixOS/StarterWare/usblib/device/usbdcdesc.c \
-SylixOS/StarterWare/usblib/device/usbdcomp.c \
-SylixOS/StarterWare/usblib/device/usbdconfig.c \
-SylixOS/StarterWare/usblib/device/usbdenum.c \
-SylixOS/StarterWare/usblib/device/usbdhandler.c \
-SylixOS/StarterWare/usblib/device/usbdhid.c \
-SylixOS/StarterWare/usblib/device/usbdhidmouse.c \
-SylixOS/StarterWare/usblib/device/usbdmsc.c
-
STARTERWARE_UTILS_SRCS = \
SylixOS/StarterWare/utils/delay.c \
SylixOS/StarterWare/utils/perf.c
@@ -238,7 +209,6 @@ SylixOS/StarterWare/platform/platform.c
STARTERWARE_SRCS += $(STARTERWARE_DRIVERS_SRCS)
STARTERWARE_SRCS += $(STARTERWARE_SYSTEM_CONFIG_SRCS)
-STARTERWARE_SRCS += $(STARTERWARE_USBLIB_SRCS)
STARTERWARE_SRCS += $(STARTERWARE_UTILS_SRCS)
STARTERWARE_SRCS += $(STARTERWARE_PLATFORM_SRCS)
@@ -273,9 +243,9 @@ DEPPATH = $(OUTPATH)/dep
#*********************************************************************************************************
# target
#*********************************************************************************************************
-O_IMG = $(OUTPATH)/bspam335x.elf
-O_BIN = $(OUTPATH)/bspam335x.bin
-O_SIZ = $(OUTPATH)/bspam335x.siz
+O_IMG = $(OUTPATH)/bsp$(PLATFORM).elf
+O_BIN = $(OUTPATH)/bsp$(PLATFORM).bin
+O_SIZ = $(OUTPATH)/bsp$(PLATFORM).siz
#*********************************************************************************************************
# bspam335x objects
diff --git a/README.txt b/README.txt
new file mode 100644
index 0000000..3de5d78
--- /dev/null
+++ b/README.txt
@@ -0,0 +1,20 @@
+
+bspam335x 是 SylixOS 支持 Ti AM335x 系列处理器的 BSP 包,
+
+目前该 BSP 支持飞凌嵌入式公司的 Ok335xS 和 OK335xD 及 BeagleBone 开发板,
+
+如果您需要移植该 BSP 到您的 AM335x 处理器工控板上,请联系我们的销售人员,我们将提供有偿定制服务。
+
+使用 RealCoder 或 Eclipse 打开 bspam335x 工程;
+
+如果您使用 Eclipse,需要修改 config.mk 文件,设置正确的 SylixOS Base 工程路径和工具链前缀及调试级别;
+
+如果您使用 RealCoder,则需要对工程进行通用设置,方法请参考 《RealCoder 使用手册》。
+
+根据您使用的开发板,需要修改 Makefile 的 PLATFORM 变量。
+
+下载、运行和烧写内核镜像的方法请参考 U-Boot.txt 文件,我们建议使用 U-Boot 作为 Bootloader。
+
+项目发布时,建议将 libsylixos 的 LW_CFG_SMP_EN 配置为 0,将 LW_CFG_MONITOR_EN 配置为 0,这样性能会更好。
+
+一些实时以太网应用为了获得更好的网络性能,建议将 LW_CFG_LWIP_MSG_SIZE 配置为 2048,将 LW_CFG_LWIP_NUM_PBUFS 配置为 1024。 \ No newline at end of file
diff --git a/SylixOS/StarterWare/drivers/cppi41dma.c b/SylixOS/StarterWare/drivers/cppi41dma.c
deleted file mode 100644
index c6c5716..0000000
--- a/SylixOS/StarterWare/drivers/cppi41dma.c
+++ /dev/null
@@ -1,2044 +0,0 @@
-/**
- * \file cppi41dma.c
- *
- * \brief This file contains the API definitions for initializing and
- * configuring CPPI DMA engine.
- */
-
-/*
-* Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
-*/
-/*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions
-* are met:
-*
-* Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-*
-* Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the
-* distribution.
-*
-* Neither the name of Texas Instruments Incorporated nor the names of
-* its contributors may be used to endorse or promote products derived
-* from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*
-*/
-
-/* HW Macros and Peripheral Defines */
-#ifdef SYLIXOS
-#include "stdio.h"
-#endif
-#include "hw_types.h"
-#include "hw_usb.h"
-#include "debug.h"
-#include "cppi41dma.h"
-/* Driver APIs */
-#include "usb.h"
-#ifdef _TMS320C6X
-#include "dspcache.h"
-#else
-#include "cache.h"
-#endif
-#include "uartStdio.h"
-#include "consoleUtils.h"
-/*****************************************************************************
-** STATIC FUNCTIONs
-******************************************************************************/
-
-static void Cppi41DmaModeSet(unsigned short usbDevInst, endpointInfo *epInfo);
-static void Cppi41DmaInitBdPool();
-static unsigned int Cppi41DmaReadCompletionQueue(unsigned short usbDevInst,
- unsigned int queueNum);
-
-static void Cppi41DmaConfigRxhostPacket(unsigned short usbDevInst, unsigned short chan,
- unsigned int rxSubmitqA, unsigned int rxSubmitqB);
-
-static void Cppi41DmaConfigRxCompletionQueue(unsigned short usbDevInst,
- unsigned short rxChan,unsigned int rxCompq);
-static void Cppi41DmaConfigTxCompletionQueue(unsigned short usbDevInst,
- unsigned short txChan,unsigned int txCompq);
-
-static void Cppi41DmaControlScheduler(unsigned short usbDevInst,
- unsigned short enableDisable,
- unsigned short numOfentries);
-
-static void Cppi41DmaProcessBD( unsigned short usbDevInst, hostPacketDesc *current_bd,
- unsigned short direction, unsigned char * buffadd,
- unsigned int length, unsigned int ulEndpoint);
-static void cppi41DmaInitBuffer();
-
-unsigned int (*Cppi41DmaPopQueue)(unsigned short, unsigned int) =
- Cppi41DmaReadCompletionQueue;
-
-static void Cppi41DmaPushToTearDownQ(unsigned short usbDevInst,
- unsigned int queueNum, cppi41TearDownDesc *curr_tdd);
-static unsigned int Cppi41DmaPopFromSubmitQ(unsigned short usbDevInst, unsigned int queueNum);
-
-
-static void Cppi41DmaConfigTDDescQueue(unsigned short usbDevInst,unsigned int tdDescq);
-
-void setTxTearDown(unsigned short usbDevInst, unsigned int indexEndPoint);
-void setRxTearDown(unsigned short usbDevInst, unsigned int indexEndPoint);
-
-unsigned int getQLength(unsigned short usbDevInst, unsigned int queueNum);
-
-static unsigned int Cppi41DmaRecoverBD( hostPacketDesc* completed_bd );
-// Debug Print
-
-void print_pend (void);
-
-/*****************************************************************************
-** VARIABLES AND BUFFERS
-******************************************************************************/
-
-/*Link RAM 0 area declaration */
-static unsigned int linking_ram0[LINK_RAM0_SIZE];
-
-/*Descriptor region 0 declaration */
-unsigned int region0DescriptorSpace[DESC0_REGION_SIZE];
-
-/*CPPI info structure */
-cppi41DmaInfo cppiInfo;
-
-/*Data Buffers for DMA data transfer */
-#if defined(__IAR_SYSTEMS_ICC__)
-#pragma data_alignment=(SOC_CACHELINE_SIZE_MAX)
-unsigned char dBuffer[CPDMA_NUMOF_BUFFERS][USB_PACKET_LENGTH];
-#elif defined __TMS470__ || defined _TMS320C6X
-#pragma DATA_ALIGN(dBuffer, SOC_CACHELINE_SIZE_MAX);
-unsigned char dBuffer[CPDMA_NUMOF_BUFFERS][USB_PACKET_LENGTH];
-#else
-unsigned char dBuffer[CPDMA_NUMOF_BUFFERS][USB_PACKET_LENGTH]__attribute__((aligned(SOC_CACHELINE_SIZE_MAX)));
-#endif
-
-/*Buffer management structre */
-typedef struct
-{
- unsigned int *dataBuffer;
- unsigned short usedFlag;
- unsigned short nBlocks;
-}dmaDataBuffer;
-
-#if defined(__IAR_SYSTEMS_ICC__)
-#pragma data_alignment=(SOC_CACHELINE_SIZE_MAX)
-dmaDataBuffer dmaBuffer[CPDMA_NUMOF_BUFFERS];
-#elif defined __TMS470__ || defined _TMS320C6X
-#pragma DATA_ALIGN(dmaBuffer, SOC_CACHELINE_SIZE_MAX);
-dmaDataBuffer dmaBuffer[CPDMA_NUMOF_BUFFERS];
-#else
-dmaDataBuffer dmaBuffer[CPDMA_NUMOF_BUFFERS]__attribute__((aligned(SOC_CACHELINE_SIZE_MAX)));
-#endif
-
-/* Converts from an endpoint specifier to the offset of the endpoint's
- * control/status registers. */
-#define EP_OFFSET(Endpoint) (Endpoint - 0x10)
-#define QUEUE_OFFSET(queue) (queue << 4)
-#define CHANNEL_OFFSET(chan) (chan << 5)
-
-/*****************************************************************************
-** FUNCTION DEFINITIONS
-******************************************************************************/
-
-/**
-* \brief This API initializes the DMA. This API should be called by the application
-* API . API populates cppi Info structure according to the information
-* passed from the application. This information is used by this API and all other
-* APIs. This API configures Channels queues and schedulers as per the
-* information passed from the application.
-*
-* \param usbDevIns :- This is the USB device instance
-*
-*\param epInfo:- End point info structure
-*
-*\param numOfEndPoimts:- Total Number of endpoints to be configured(RX+TX)
-*
-* \return None.
-*
-**/
-void Cppi41DmaInit(unsigned short usbDevInst, endpointInfo *epInfo,
- unsigned short numOfEndPoimts)
-{
- /* This function need to be changed for porting to different SoC ,
- * to initialise base addresses and other details. */
-
- unsigned int descAddress = 0;
- unsigned short i= 0;
-
- usbInstance *usbInstance;
-#if defined (am335x_15x15) || defined(am335x) || defined(c6a811x)
- unsigned short j = 0;
-#endif
-
- usbInstance = &(cppiInfo.usbInst[usbDevInst]);
-
- /*Populate the CPPI info structure */
- cppiInfo.head_bd = NULL;
- cppiInfo.tail_bd = NULL;
-
-#if defined (am335x_15x15) || defined(am335x) || defined(c6a811x)
- for(i =0; i < MAX_NUM_EP; i++)
- {
- /*TX Completion queues */
- cppiInfo.txCompletionq[i]= TX_COMPQ1 + i;
- /*RX Completion queues */
- cppiInfo.rxCompletionq[i]= RX_COMPQ1 + i;
-
- /*TX submit queues */
- for(j = 0; j < 2; j++)
- {
- cppiInfo.txSubmitq[i][j]=TX_SUBMITQ1 + (i *2) + j;
- }
- }
- for(i = MAX_NUM_EP; i < (MAX_NUM_EP*2); i++)
- {
- /*TX Completion queues */
- cppiInfo.txCompletionq[i]= TX_COMPQ16 + (i - MAX_NUM_EP);
- /*RX Completion queues */
- cppiInfo.rxCompletionq[i]= RX_COMPQ16 + (i - MAX_NUM_EP );
-
- /*TX submit queues */
- for(j = 0; j < 2; j++)
- {
- cppiInfo.txSubmitq[i][j]=TX_SUBMITQ1 + (i *2) + j;
- }
- }
- /*Teardown Q number 31 is used . This is a free descriptor Q which is unused*/
- cppiInfo.tearDownq = USB0_TEARDOWNQ1;
-
-#else
- /*TX Completion queues */
- cppiInfo.txCompletionq[0]= TX_COMPQ1;
- cppiInfo.txCompletionq[1]= TX_COMPQ2;
- cppiInfo.txCompletionq[2]= TX_COMPQ1;
- cppiInfo.txCompletionq[3]= TX_COMPQ2;
-
- /*RX Completion queues */
- cppiInfo.rxCompletionq[0]= RX_COMPQ1;
- cppiInfo.rxCompletionq[1]= RX_COMPQ2;
- cppiInfo.rxCompletionq[2]= RX_COMPQ1;
- cppiInfo.rxCompletionq[3]= RX_COMPQ2;
-
- /*TX submit queues */
- cppiInfo.txSubmitq[0][0]=TX_SUBMITQ1;
- cppiInfo.txSubmitq[0][1]=TX_SUBMITQ2;
- cppiInfo.txSubmitq[1][0]=TX_SUBMITQ3;
- cppiInfo.txSubmitq[1][1]=TX_SUBMITQ4;
- cppiInfo.txSubmitq[2][0]=TX_SUBMITQ5;
- cppiInfo.txSubmitq[2][1]=TX_SUBMITQ6;
- cppiInfo.txSubmitq[3][0]=TX_SUBMITQ7;
- cppiInfo.txSubmitq[3][1]=TX_SUBMITQ8;
-#endif
-
- /*USB base address and OTG basse adress for USB instance 0 */
- cppiInfo.usbInst[0].usbInstCoreBaseAddress = USB0_BASE;
- cppiInfo.usbInst[0].usbSubSysBaseAddress = USB_OTGBASE;
-
- cppiInfo.usbInst[0].usbInstBaseAddress = 0x47401000;
- cppiInfo.usbInst[0].usbInstPhyBaseAddress = 0x47401300;
-#if defined (am335x_15x15) || defined(am335x) || defined(c6a811x)
-
- cppiInfo.usbInst[1].usbSubSysBaseAddress = USB_OTGBASE;
- cppiInfo.usbInst[1].usbInstBaseAddress = 0x47401800;
- cppiInfo.usbInst[1].usbInstPhyBaseAddress = 0x47401B00;
- cppiInfo.usbInst[1].usbInstCoreBaseAddress = USB1_BASE;
-
-
-#endif
-
- /*This function initializes the buffer Management system */
- cppi41DmaInitBuffer();
-
- /* This loop populates the RX and TX queues(both submission and completion queues),
- * channels and dma mode for each end point */
- for(i= 0;i< numOfEndPoimts;i++)
- {
- if((epInfo + i)->direction == CPDMA_DIR_RX)
- {
- usbInstance->rxEndPoint[(epInfo + i)->endPoint].channel =
- ((epInfo + i)->endPoint - 1) + (usbDevInst * MAX_NUM_EP);
-
- usbInstance->rxEndPoint[(epInfo + i)->endPoint].complettionq =
- cppiInfo.rxCompletionq[((epInfo + i)->endPoint - 1) +
- (usbDevInst * MAX_NUM_EP)];
-
- usbInstance->rxEndPoint[(epInfo + i)->endPoint].submitq =
- ((epInfo + i)->endPoint - 1) +
- (usbDevInst * MAX_NUM_EP);
-
- usbInstance->rxEndPoint[(epInfo + i)->endPoint].tearDownq =
- USB0_TEARDOWNQ1;
-
- usbInstance->rxEndPoint[(epInfo + i)->endPoint].mode =
- (epInfo + i)->dmaMode;
- }
- else
- {
- usbInstance->txEndPoint[(epInfo + i)->endPoint].channel =
- ((epInfo + i)->endPoint - 1) +
- (usbDevInst * MAX_NUM_EP);
-
- usbInstance->txEndPoint[(epInfo + i)->endPoint].complettionq =
- cppiInfo.txCompletionq[((epInfo + i)->endPoint - 1) +
- (usbDevInst * MAX_NUM_EP)];
-
- usbInstance->txEndPoint[(epInfo + i)->endPoint].submitq =
- cppiInfo.txSubmitq[((epInfo + i)->endPoint - 1) +
- (usbDevInst * MAX_NUM_EP)][0];
- usbInstance->txEndPoint[(epInfo + i)->endPoint].tearDownq =
- USB0_TEARDOWNQ1;
-
- usbInstance->txEndPoint[(epInfo + i)->endPoint].mode =
- (epInfo + i)->dmaMode;
- }
- }
-
- /* Set mode for each end pont*/
- for(i = 0;i < numOfEndPoimts; i++)
- Cppi41DmaModeSet(usbDevInst, &epInfo[i]);
-
- /*Link Ram setup */
- HWREG(usbInstance->usbSubSysBaseAddress + CPDMA_LRAM_0_BASE) =
- (unsigned int)&linking_ram0[0];
- /*Indicates Number of BDs queued up and not the size of Link RAM*/
- HWREG(usbInstance->usbSubSysBaseAddress + CPDMA_LRAM_0_SIZE) = LINK_RAM0_SIZE;
- //sizeof(linking_ram0);
-
- HWREG(usbInstance->usbSubSysBaseAddress + CPDMA_LRAM_1_BASE) = 0x0;
-
-
- /*Queue region setup */
- /*The Descriptor region address is aligned for SOC_CACHELINE_SIZE_MAX Byte access */
- descAddress = (unsigned int)region0DescriptorSpace;
- /*Add SOC_CACHELINE_SIZE_MAX to the starting address */
- descAddress = descAddress + BYTE_ALIGNMENT;
- /*Align the strating adress */
- descAddress &= ~0x3F;
- cppiInfo.region0DescriptorAddress = (unsigned int *)descAddress;
-
- HWREG(usbInstance->usbSubSysBaseAddress + CPDMA_QUEUEMGR_REGION_0)=
- (unsigned int)cppiInfo.region0DescriptorAddress;
- /*queue manager cotrol setup */
- HWREG(usbInstance->usbSubSysBaseAddress + CPDMA_QUEUEMGR_REGION_0_CONTROL) =
- QUEUE_MGR_DESCSIZE | QUEUE_MGR_REGSIZE;
-
- /*initialize the BD pool */
- Cppi41DmaInitBdPool();
-
- /*configure the RX channel for each end point */
- for(i=0;i<numOfEndPoimts;i++)
- {
- if((epInfo + i)->direction == CPDMA_DIR_RX)
- Cppi41DmaConfigRxhostPacket(usbDevInst, usbInstance
- ->rxEndPoint[(epInfo + i)->endPoint].channel,
- usbInstance->rxEndPoint[(epInfo + i)->endPoint].submitq,
- usbInstance->rxEndPoint[(epInfo + i)->endPoint].submitq);
-
- }
-
- /*configure the RX and TX completion queues for each end point */
- for(i=0;i<numOfEndPoimts;i++)
- {
- if((epInfo + i)->direction == CPDMA_DIR_RX)
- {
- Cppi41DmaConfigRxCompletionQueue(usbDevInst, usbInstance
- ->rxEndPoint[(epInfo + i)->endPoint].channel, usbInstance
- ->rxEndPoint[(epInfo + i)->endPoint].complettionq);
- }
- else
- {
- Cppi41DmaConfigTxCompletionQueue(usbDevInst, usbInstance
- ->txEndPoint[(epInfo + i)->endPoint].channel, usbInstance
- ->txEndPoint[(epInfo + i)->endPoint].complettionq);
- }
- }
-
- /*configure the TD Free Decsriptor Queue Control */
- Cppi41DmaConfigTDDescQueue(usbDevInst, USB0_TEARDOWNQ1);
-
- /*Scheduler configuration */
- /*Set the order of each RX and TX chennel to Processed to scheduler table 0 */
- HWREG(usbInstance->usbSubSysBaseAddress + CPDMA_SCHED_TABLE_0) = SCHEDULE_TX_CHANNEL;
- HWREG(usbInstance->usbSubSysBaseAddress + CPDMA_SCHED_TABLE_1) = SCHEDULE_RX_CHANNEL;
-#if defined (am335x_15x15) || defined(am335x) || defined(c6a811x)
- HWREG(usbInstance->usbSubSysBaseAddress + CPDMA_SCHED_TABLE_2) = SCHEDULE_TX1_CHANNEL;
- HWREG(usbInstance->usbSubSysBaseAddress + CPDMA_SCHED_TABLE_3) = SCHEDULE_RX1_CHANNEL;
-#endif
-
- /*Specify the number of entries in the scheduler table 0 */
- HWREG(usbInstance->usbSubSysBaseAddress + CPDMA_SCHED_CONTROL_REG )=
- (ENABLE_CPPIDMA<< SCHEDULER_ENABLE_SHFT) |
- (NUM_OF_SCHEDULER_ENTRIES - 1);
-
-}
-
-/**
-* \brief This API sets the DMA mode for each channel
-*
-* \param dmaMde :- mode for rx and Tx.
-*
-*\param epInfo:- End point info structure
-*
-* \return None.
-*
-**/
-void Cppi41DmaModeSet(unsigned short usbDevInst, endpointInfo *epInfo)
-{
-
- usbInstance *usbInstance;
-
- usbInstance = &(cppiInfo.usbInst[usbDevInst]);
-
- /* Enable RNDIS from Global Level */
- if (epInfo->dmaMode == CPDMA_MODE_SET_RNDIS)
- {
- HWREG(usbInstance->usbInstBaseAddress + USB_0_CTRL)|=
- CPDMA_MODE_ENABLE_GLOBAL_RNDIS;
- }
-
- /* Disable RNDIS from Global Level */
- else
- {
- HWREG(usbInstance->usbInstBaseAddress + USB_0_CTRL)&=
- ~CPDMA_MODE_ENABLE_GLOBAL_RNDIS;
- }
- /*Set the mode for RX and TX channel */
- if(epInfo->direction == CPDMA_DIR_TX)
- {
- HWREG(usbInstance->usbInstBaseAddress + USB_0_TX_MODE)|=
- (epInfo->dmaMode << USB_TX_MODE_SHIFT(epInfo->endPoint));
- }
-
- else
- {
- HWREG(usbInstance->usbInstBaseAddress + USB_0_RX_MODE)|=
- (epInfo->dmaMode<< USB_RX_MODE_SHIFT(epInfo->endPoint));
- }
-
- /* For GRNDIS mode, set the maximum packet length */
- if (epInfo->dmaMode == CPDMA_MODE_SET_GRNDIS)
- {
- if(usbDevInst == 0)
- {
- HWREG(usbInstance->usbInstBaseAddress + USB_0_GEN_RNDIS_SIZE_EP1) =
- GRNDIS_MAX_PACKET_LENGTH;
- }
- else if(usbDevInst == 1)
- {
-#if defined (am335x_15x15) || defined(am335x) || defined(c6a811x)
- HWREG(usbInstance->usbInstBaseAddress + USB_1_GEN_RNDIS_SIZE_EP1) =
- GRNDIS_MAX_PACKET_LENGTH;
-#endif
- }
- }
-}
-
-
-/**
-* \brief This API enables the TX DMA for an endpoint. The API access the CSR
-* register of the particular endpoint to set appropriate bits. This API is
-* called by the stack to enable DMA when it is requied.
-*
-* \param usbDevInst:- USB device instance
-*
-* \param ulEndpoint:- Endpoint Number
-*
-* \return None.
-*
-**/
-void enableCoreTxDMA(unsigned short usbDevInst, unsigned int ulEndpoint)
-{
- unsigned int ulRegister;
- usbInstance *usbInstance;
- unsigned int timeout = 0xFFFF;
- usbInstance = &(cppiInfo.usbInst[usbDevInst]);
-
- /*Find out the TX CRS address */
- ulRegister = USB_O_TXCSRL1 + EP_OFFSET(ulEndpoint);
-
- /*Wait till completion of any previous transaction */
- do
- {
- --timeout;
- }
- while (((HWREGH(usbInstance->usbInstCoreBaseAddress + ulRegister) & 0x2) == 0x02)&&timeout);
-
- /* Clear Autoset */
- HWREGH(usbInstance->usbInstCoreBaseAddress + ulRegister)&= CPDMA_TX_CLR_AUTO_SET;
-
- /* Set DMAReqEnab & DMAReqMode */
- HWREGH(usbInstance->usbInstCoreBaseAddress + ulRegister)|=CPDMA_TX_SET_REQ_ENABLE;
-
-}
-
-
-/**
-* \brief This API enables the RX DMA for an endPoint.The API access the CSR
-* register of the particular endpoint to set appropriate bits. This API is
-* called by the stack to enable DMA when it is requied.
-*
-* \param usbDevInst:- USB device instance
-*
-* \param ulEndpoint:- Endpoint Number
-*
-* \return None.
-*
-**/
-void enableCoreRxDMA(unsigned short usbDevInst, unsigned int ulEndpoint)
-{
- unsigned int ulRegister;
- usbInstance *usbInstance;
-
- usbInstance = &(cppiInfo.usbInst[usbDevInst]);
-
- /*Find out the RX CSR address */
- ulRegister = USB_O_RXCSRL1 + EP_OFFSET(ulEndpoint);
-
- /*Find out the index to usb intance end point array */
- ulEndpoint = USB_EP_TO_INDEX(ulEndpoint);
-
- /*Enable the scheduler with number entries */
- Cppi41DmaControlScheduler(usbDevInst, ENABLE_CPPIDMA, NUM_OF_SCHEDULER_ENTRIES);
-
- /*Configure the completion queue */
- Cppi41DmaConfigRxCompletionQueue(usbDevInst, usbInstance->rxEndPoint[ulEndpoint].channel,
- usbInstance->rxEndPoint[ulEndpoint].complettionq);
-
- /* Clear AUTOCLEAR and DMAReqMode */
- HWREGH(usbInstance->usbInstCoreBaseAddress + ulRegister)&=CPDMA_RX_CLR_AUTO_CLEAR;
-
- /* Set DMAReqEnab */
- HWREGH(usbInstance->usbInstCoreBaseAddress + ulRegister)|=CPDMA_RX_SET_REQ_ENABLE;
-}
-
-/**
-* \brief This API disables the RX DMA for an endpoint. The API access the CSR
-* register of the particular endpoint to set appropriate bits. This API is
-* Called by the stack to disable DMA when it is required
-*
-* \param usbDevInst:- USB device instance
-*
-* \param ulEndpoint:- Endpoint Number
-*
-* \return None.
-*
-**/
-void disableCoreRxDMA(unsigned short usbDevInst, unsigned int ulEndpoint)
-{
- unsigned int ulRegister;
- usbInstance *usbInstance;
- unsigned int timeout = 0xFFFF;
- usbInstance = &(cppiInfo.usbInst[usbDevInst]);
-
- /*Find out the CSR offset */
- ulRegister = USB_O_RXCSRL1 + EP_OFFSET(ulEndpoint);
-
- /*wait till completion of any previos transaction */
- do
- {
- --timeout;
- }
- while (((HWREGH(usbInstance->usbInstCoreBaseAddress + ulRegister) & 0x1) == 0x01)&& timeout);
-
- /* Clear DMAReqEnab */
- HWREGH(usbInstance->usbInstCoreBaseAddress + ulRegister)&= CPDMA_RX_CLR_REQ_ENABLE;
-}
-
-/**
-* \brief This API enables the TX DMA for an endpont. The API access the CSR
-* register of the particular endpoint to set appropriate bits. This API is
-* Called by the stack to disable DMA when it is required
-*
-* \param usbDevInst:- USB device instance
-*
-* \param ulEndpoint:- Endpoint Number
-*
-* \return None.
-*
-**/
-void disableCoreTxDMA(unsigned short usbDevInst, unsigned int ulEndpoint)
-{
- unsigned int ulRegister;
- usbInstance *usbInstance;
- unsigned int timeout = 0xFFFF;
-
- usbInstance = &(cppiInfo.usbInst[usbDevInst]);
-
- ulRegister = USB_O_TXCSRL1 + EP_OFFSET(ulEndpoint);
- do
- {
- --timeout;
- }
- while (((HWREGH(usbInstance->usbInstCoreBaseAddress + ulRegister) & 0x2) == 0x02)&& timeout);
-
- /* Clear AUTOSET */
- HWREGH(usbInstance->usbInstCoreBaseAddress + ulRegister)&=CPDMA_TX_CLR_AUTO_SET;
-
- /* Clear DMAReqEnab & DMAReqMode */
- HWREGH(usbInstance->usbInstCoreBaseAddress + ulRegister)&=CPDMA_TX_CLR_REQ_ENABLE;
-}
-
-/**
-* \brief This API reads the complettion queue. This is called from the stack when a completion
-* interrupt comes. RX/TX completion queue number can be passed as an argument to
-* this function. The function returns completed BD address.
-*
-* \param usbDevInst:- USB device instance
-*
-* \param queueNum:- The completeion queue number
-*
-* \return None.
-*
-**/
-unsigned int Cppi41DmaReadCompletionQueue(unsigned short usbDevInst,
- unsigned int queueNum)
-{
- unsigned int descAddress;
- usbInstance *usbInstance;
-
- usbInstance = &(cppiInfo.usbInst[usbDevInst]);
-
- /*Read the completetion queue register */
- descAddress=(unsigned int)HWREG(usbInstance->usbSubSysBaseAddress +
- (CPDMA_QUEUE_REGISTER_D + QUEUE_OFFSET(queueNum)));
- /*Extract the BD address */
- descAddress&=0xFFFFFFE0;
- return(descAddress);
-}
-
-/**
-* \brief This API configures an RX channel submit queue
-*
-* \param usbDevInst:- The USB Device instance
-*
-* \param chan:- The channel Number
-*
-* \param rxSubmitqA:- The queue register A value
-*
-* \param rxSubmitqB:- The queue register B value
-*
-* \return None.
-*
-**/
-void Cppi41DmaConfigRxhostPacket(unsigned short usbDevInst, unsigned short chan,
- unsigned int rxSubmitqA, unsigned int rxSubmitqB)
-{
- usbInstance *usbInstance;
-
- usbInstance = &(cppiInfo.usbInst[usbDevInst]);
-
- HWREG(usbInstance->usbSubSysBaseAddress + (CPDMA_RX_CHANNEL_REG_A +
- CHANNEL_OFFSET(chan))) = (rxSubmitqA | rxSubmitqA << 16);
- HWREG(usbInstance->usbSubSysBaseAddress + (CPDMA_RX_CHANNEL_REG_B +
- CHANNEL_OFFSET(chan))) = (rxSubmitqB | rxSubmitqB << 16) ;
-}
-
-/**
-* \brief Configure the RX completion queues
-*
-* \param usbDevInst:- The USB Device instance
-*
-* \param rxChan:- The channel Number
-*
-* \param rxCompq:-RX Completion queue
-*
-* \return None.
-*
-**/
-void Cppi41DmaConfigRxCompletionQueue(unsigned short usbDevInst,
- unsigned short rxChan,unsigned int rxCompq)
-{
- usbInstance *usbInstance;
-
- usbInstance = &(cppiInfo.usbInst[usbDevInst]);
-
- HWREG(usbInstance->usbSubSysBaseAddress + (CPDMA_RX_CHANNEL_CONFIG_REG +
- CHANNEL_OFFSET(rxChan))) = CPDMA_RX_CHANNEL_ENABLE | rxCompq;
-
-}
-
-
-/**
-* \brief Configure the TX completion queues
-*
-* \param usbDevInst:- The USB Device instance
-*
-* \param txChan:- The channel Number
-*
-* \param txCompq:-RX Completion queue
-*
-* \return None.
-*
-**/
-void Cppi41DmaConfigTxCompletionQueue(unsigned short usbDevInst,
- unsigned short txChan, unsigned int txCompq)
-{
- usbInstance *usbInstance;
-
- usbInstance = &(cppiInfo.usbInst[usbDevInst]);
-
- HWREG(usbInstance->usbSubSysBaseAddress + (CPDMA_TX_CHANNEL_CONFIG_REG +
- CHANNEL_OFFSET(txChan))) = CPDMA_TX_CHANNEL_ENABLE | txCompq;
-}
-
-
-
-/**
-* \brief Initializes the BD pool
-*
-* \param
-*
-* \return None.
-*
-**/
-void Cppi41DmaInitBdPool()
-{
- hostPacketDesc *temp_bd = NULL;
- unsigned int i;
-
- temp_bd = (hostPacketDesc *)cppiInfo.region0DescriptorAddress;
- for(i=0;i<MAX_BD_NUM; i++, temp_bd++)
- {
- if(!cppiInfo.head_bd)
- {
- cppiInfo.head_bd = temp_bd;
- cppiInfo.tail_bd = temp_bd;
- temp_bd->nextHBDptr = NULL;
- }
- else
- {
- cppiInfo.tail_bd->nextHBDptr = temp_bd;
- cppiInfo.tail_bd = cppiInfo.tail_bd->nextHBDptr;
- temp_bd->nextHBDptr = NULL;
- }
- }
- temp_bd = NULL;
-}
-
-
-/**
-* \brief This API will get a free BD from the BD pool
-*
-* \param
-*
-* \return None.
-*
-**/
-hostPacketDesc * getFreeBd()
-{
- hostPacketDesc *free_bd;
-
- free_bd = NULL;
-
- if(cppiInfo.head_bd)
- {
- free_bd = cppiInfo.head_bd;
- cppiInfo.head_bd = cppiInfo.head_bd->nextHBDptr;
- free_bd->nextHBDptr = NULL;
- }
-
- return free_bd;
-}
-
-/**
-* \brief This API puts the free BD back to the BD pool
-*
-* \param
-*
-* \return None.
-*
-**/
-void putFreeBd(hostPacketDesc *free_bd)
-{
- if(cppiInfo.head_bd)
- {
- free_bd->nextHBDptr = cppiInfo.head_bd;
- cppiInfo.head_bd =free_bd;
- }
- else
- {
- cppiInfo.head_bd = free_bd;
- cppiInfo.head_bd->nextHBDptr = NULL;
- }
-}
-
-/**
-* \brief API to submit a BD to the queue
-*
-* \param usbDevInst:- The USB device instance
-*
-* \param queueNum:- The submit queue number
-*
-* \param curr_bd:- Address of BD to submit
-*
-* \return None.
-*
-**/
-void pushToSubmitQ(unsigned short usbDevInst,
- unsigned int queueNum, hostPacketDesc *curr_bd)
-{
-
- unsigned int submitqAdd;
- unsigned int curr_bdAdd;
- hostPacketDesc *bdAddr;
- usbInstance *usbInstance;
-
- usbInstance = &(cppiInfo.usbInst[usbDevInst]);
-
- /*get the BD address */
- curr_bdAdd = (unsigned int) curr_bd;
- /* Add the length to it */
- curr_bdAdd |= SIZE_OF_SINGLE_BD;
- bdAddr = (hostPacketDesc *)curr_bdAdd;
- /*Get the submit queue address */
- submitqAdd = usbInstance->usbSubSysBaseAddress + (CPDMA_QUEUE_REGISTER_D +
- QUEUE_OFFSET(queueNum));
- HWREG(submitqAdd) = (unsigned int) bdAddr;
-
-}
-
-/**
-* \brief This API gets a free BD , process it for TX transfer and submit it to the TX queue.
-* The API can take care of packetizing the data according to USB transfer size and
-* attach to the BDs. This API will work in both transparent mode and GRNDIS mode .
-*
-* \param lenght:- length of the data buffer
-*
-* \param buff :- Bata buffer
-*
-* \param endPoind :- The TX end point
-*
-* \return None.
-*
-**/
-#ifdef _TMS320C6X
-void doDmaTxTransfer(unsigned short usbDevInst, unsigned char *buff,
- unsigned int length, unsigned int endPoint)
-{
- hostPacketDesc *current_bd = NULL;
-
- unsigned int numOfBlocks =0;
- unsigned int residue;
- unsigned int i;
- usbInstance *usbInstance;
-
- usbInstance = &(cppiInfo.usbInst[usbDevInst]);
-
- endPoint = USB_EP_TO_INDEX(endPoint);
-
- /*This code segment will take care of the transparent mode transaction */
- if(CPDMA_MODE_SET_TRANSPARENT == usbInstance->txEndPoint[endPoint].mode)
- {
- /* If the data length is less than the USB packet size */
- if(length < USB_PACKET_LENGTH)
- {
- /*get a free db from the BD pool */
- current_bd = getFreeBd();
-
- /*Clean the cache so that buffer will have proper data */
- CacheWB((unsigned int)buff, length);
-
- /*This API will initialize the BD fields */
- Cppi41DmaProcessBD(usbDevInst, current_bd, CPDMA_DIR_TX, buff, length, endPoint);
-
- current_bd->packetId = EOP;
-
- /*Clean the cache so that bd will have proper data */
- CacheWB((unsigned int)current_bd,sizeof(hostPacketDesc));
-
- /*Submit the BD to the queue for transaction */
- pushToSubmitQ(usbDevInst, usbInstance->txEndPoint[endPoint]
- .submitq, current_bd);
- }
-
- /*If the length is more than packet size, then packetize it */
- else
- {
- numOfBlocks = length / USB_PACKET_LENGTH;
- residue = length - (numOfBlocks * USB_PACKET_LENGTH);
-
- for(i=0; i < numOfBlocks; i++)
- {
- /*get a free db from the BD pool */
- current_bd = getFreeBd();
-
- CacheWB((unsigned int)&buff[i*USB_PACKET_LENGTH],
- USB_PACKET_LENGTH);
-
- /*This API will initialize the BD fields */
- Cppi41DmaProcessBD(usbDevInst, current_bd, CPDMA_DIR_TX,
- &buff[i*USB_PACKET_LENGTH], USB_PACKET_LENGTH, endPoint);
-
- /*Set the packet id to identify the packet position */
- if(numOfBlocks == 1)
- current_bd->packetId = EOP;
- else if(i==0)
- current_bd->packetId = SOP;
- else if((numOfBlocks != 1) && (i < (numOfBlocks -1)))
- current_bd->packetId = MOP;
- else if(i == (numOfBlocks -1) && residue == 0)
- current_bd->packetId = EOP;
- else
- current_bd->packetId = MOP;
-
- CacheWB((unsigned int)current_bd,sizeof(hostPacketDesc));
-
- /*Submit the BD to the queue for transaction */
- pushToSubmitQ(usbDevInst, usbInstance->txEndPoint[endPoint]
- .submitq, current_bd);
- }
-
- /*If there are some remaining data then send it also */
- if(residue)
- {
- /*get a free db from the BD pool */
- current_bd = getFreeBd();
-
- CacheWB((unsigned int)&buff[i*USB_PACKET_LENGTH], residue);
-
- /*This API will initialize the BD fields */
- Cppi41DmaProcessBD(usbDevInst, current_bd, CPDMA_DIR_TX,
- &buff[i*USB_PACKET_LENGTH], residue, endPoint);
-
- current_bd->packetId = EOP;
-
- /*This API will initialize the BD fields */
- CacheWB((unsigned int)current_bd,sizeof(hostPacketDesc));
-
- /*Submit the BD to the queue for transaction */
- pushToSubmitQ(usbDevInst, usbInstance->txEndPoint[endPoint]
- .submitq, current_bd);
- }
-
- }
- }
-
- /*This segment of the code will take care of GRNIS mode of transaction */
- else if(usbInstance->txEndPoint[endPoint].mode == CPDMA_MODE_SET_GRNDIS)
- {
- /*get a free db from the BD pool */
- current_bd = getFreeBd();
-
- CacheWB((unsigned int)buff, length);
-
- /*This API will initialize the BD fields */
- Cppi41DmaProcessBD(usbDevInst, current_bd, CPDMA_DIR_TX, buff, length, endPoint);
-
- current_bd->packetId = EOP;
-
- CacheWB((unsigned int)current_bd,sizeof(hostPacketDesc));
-
- /*Submit the BD to the queue for transaction */
- pushToSubmitQ(usbDevInst, usbInstance->txEndPoint[endPoint]
- .submitq, current_bd);
- }
-
-}
-#else
-void doDmaTxTransfer(unsigned short usbDevInst, unsigned char *buff,
- unsigned int length, unsigned int endPoint)
-{
- hostPacketDesc *current_bd = NULL;
-
- unsigned int numOfBlocks =0;
- unsigned int residue;
- unsigned int i;
- usbInstance *usbInstance;
-
- usbInstance = &(cppiInfo.usbInst[usbDevInst]);
-
- endPoint = USB_EP_TO_INDEX(endPoint);
-
- /*This code segment will take care of the transparent mode transaction */
- if(CPDMA_MODE_SET_TRANSPARENT == usbInstance->txEndPoint[endPoint].mode)
- {
- /* If the data length is less than the USB packet size */
- if(length < USB_PACKET_LENGTH)
- {
- /*get a free db from the BD pool */
- current_bd = getFreeBd();
- ASSERT(current_bd != NULL);
- ASSERT(buff != NULL);
-
- /*Clean the cache so that buffer will have proper data */
- CacheDataCleanBuff((unsigned int)buff, length);
-
- /*This API will initialize the BD fields */
- Cppi41DmaProcessBD(usbDevInst, current_bd, CPDMA_DIR_TX, buff, length, endPoint);
-
- current_bd->packetId = EOP;
-
- /*Clean the cache so that bd will have proper data */
- CacheDataCleanBuff((unsigned int)current_bd,sizeof(hostPacketDesc));
-
- /*Submit the BD to the queue for transaction */
- pushToSubmitQ(usbDevInst, usbInstance->txEndPoint[endPoint]
- .submitq, current_bd);
- }
-
- /*If the length is more than packet size, then packetize it */
- else
- {
- numOfBlocks = length / USB_PACKET_LENGTH;
- residue = length - (numOfBlocks * USB_PACKET_LENGTH);
-
- for(i=0; i < numOfBlocks; i++)
- {
- /*get a free db from the BD pool */
- current_bd = getFreeBd();
- ASSERT(current_bd != NULL);
- ASSERT(buff != NULL);
-
- CacheDataCleanBuff((unsigned int)&buff[i*USB_PACKET_LENGTH],
- USB_PACKET_LENGTH);
-
- /*This API will initialize the BD fields */
- Cppi41DmaProcessBD(usbDevInst, current_bd, CPDMA_DIR_TX,
- &buff[i*USB_PACKET_LENGTH], USB_PACKET_LENGTH, endPoint);
-
- /*Set the packet id to identify the packet position */
- if(numOfBlocks == 1)
- current_bd->packetId = EOP;
- else if(i==0)
- current_bd->packetId = SOP;
- else if((numOfBlocks != 1) && (i < (numOfBlocks -1)))
- current_bd->packetId = MOP;
- else if(i == (numOfBlocks -1) && residue == 0)
- current_bd->packetId = EOP;
- else
- current_bd->packetId = MOP;
-
- CacheDataCleanBuff((unsigned int)current_bd,sizeof(hostPacketDesc));
-
- /*Submit the BD to the queue for transaction */
- pushToSubmitQ(usbDevInst, usbInstance->txEndPoint[endPoint]
- .submitq, current_bd);
- }
-
- /*If there are some remaining data then send it also */
- if(residue)
- {
- /*get a free db from the BD pool */
- current_bd = getFreeBd();
- ASSERT(current_bd != NULL);
-
- CacheDataCleanBuff((unsigned int)&buff[i*USB_PACKET_LENGTH], residue);
-
- /*This API will initialize the BD fields */
- Cppi41DmaProcessBD(usbDevInst, current_bd, CPDMA_DIR_TX,
- &buff[i*USB_PACKET_LENGTH], residue, endPoint);
-
- current_bd->packetId = EOP;
-
- /*This API will initialize the BD fields */
- CacheDataCleanBuff((unsigned int)current_bd,sizeof(hostPacketDesc));
-
- /*Submit the BD to the queue for transaction */
- pushToSubmitQ(usbDevInst, usbInstance->txEndPoint[endPoint]
- .submitq, current_bd);
- }
-
- }
- }
-
- /*This segment of the code will take care of GRNIS mode of transaction */
- else if(usbInstance->txEndPoint[endPoint].mode == CPDMA_MODE_SET_GRNDIS)
- {
- /*get a free db from the BD pool */
- current_bd = getFreeBd();
- ASSERT(current_bd != NULL);
-
- CacheDataCleanBuff((unsigned int)buff, length);
-
- /*This API will initialize the BD fields */
- Cppi41DmaProcessBD(usbDevInst, current_bd, CPDMA_DIR_TX, buff, length, endPoint);
-
- current_bd->packetId = EOP;
-
- CacheDataCleanBuff((unsigned int)current_bd,sizeof(hostPacketDesc));
-
- /*Submit the BD to the queue for transaction */
- pushToSubmitQ(usbDevInst, usbInstance->txEndPoint[endPoint]
- .submitq, current_bd);
- }
-
-}
-#endif
-
-/**
-* \brief This API gets a free BD , process it for RX transfer and submit it to the RX queue.
-* This API will work in both transparent mode and GRNDIS mode. . Max transfer size
-* of this rx transfer is max USB packet size
-*
-* \param lenght:- length of the data buffer
-*
-* \param buff :- Bata buffer
-*
-* \param endPoind :- The RX end point
-*
-* \return None.
-*
-**/
-#ifdef _TMS320C6X
-void doDmaRxTransfer(unsigned short usbDevInst, unsigned int length,
- unsigned char *buff, unsigned int endPoint)
-{
- hostPacketDesc *current_bd = NULL;
- usbInstance *usbInstance;
-
- usbInstance = &(cppiInfo.usbInst[usbDevInst]);
-
- current_bd = getFreeBd();
- endPoint = USB_EP_TO_INDEX(endPoint);
-
- /* Process the BD */
- Cppi41DmaProcessBD(usbDevInst, current_bd, CPDMA_DIR_RX, buff, length, endPoint);
-
- /* Clean the cache */
- CacheWB((unsigned int)current_bd,sizeof(hostPacketDesc));
-
- /*Submit the BD */
- pushToSubmitQ(usbDevInst, usbInstance->rxEndPoint[endPoint].submitq, current_bd);
-
-}
-#else
-void doDmaRxTransfer(unsigned short usbDevInst, unsigned int length,
- unsigned char *buff, unsigned int endPoint)
-{
- hostPacketDesc *current_bd = NULL;
- usbInstance *usbInstance;
-
- ASSERT(buff != NULL);
-
- usbInstance = &(cppiInfo.usbInst[usbDevInst]);
-
- current_bd = getFreeBd();
- ASSERT(current_bd != NULL);
-
- endPoint = USB_EP_TO_INDEX(endPoint);
-
- /* Process the BD */
- Cppi41DmaProcessBD(usbDevInst, current_bd, CPDMA_DIR_RX, buff, length, endPoint);
-
- /* Clean the cache */
- CacheDataCleanBuff((unsigned int)current_bd,sizeof(hostPacketDesc));
-
- /*Submit the BD */
- pushToSubmitQ(usbDevInst, usbInstance->rxEndPoint[endPoint].submitq, current_bd);
-
-}
-#endif
-/**
-* \brief This API reads the TX completion queue and puts the free bd to the BD pool.
-* Extracts the buffer address from the BD and frees it. This will return the
-* current DMA status on TX operation to the caller. his API will be called on
-* reception of a completion interrupt
-*
-* \param usbDevIns:- The USB device instacnce
-*
-* \param ulEndpoint :- Endpoint Number*
-*
-* \return None.
-*
-**/
-#ifdef _TMS320C6X
-unsigned int dmaTxCompletion(unsigned short usbDevInst, unsigned int ulEndpoint )
-{
-
- hostPacketDesc *completed_bd;
- unsigned int ulRegister;
- unsigned int state;
- unsigned int packetid;
- usbInstance *usbInstance;
- unsigned int timeout = 0xFFFF;
-
- usbInstance = &(cppiInfo.usbInst[usbDevInst]);
-
- ulRegister = USB_O_TXCSRL1 + EP_OFFSET( ulEndpoint);
-
- ulEndpoint = USB_EP_TO_INDEX(ulEndpoint);
-
-
- /*read the compltetion queue */
- completed_bd = (hostPacketDesc *)Cppi41DmaReadCompletionQueue(usbDevInst, usbInstance
- ->txEndPoint[ulEndpoint].complettionq);
- /*Get the packet ID to update the DMA status */
- packetid = completed_bd->packetId;
- if(packetid == EOP)
- state = DMA_TX_COMPLETED;
- else
- state = DMA_TX_IN_PROGRESS;
-
- /*wait till Tx completion */
- if(state == DMA_TX_COMPLETED)
- do{
- -- timeout;
- }while (((HWREGH(usbInstance->usbInstCoreBaseAddress + ulRegister) & 0x2) == 0x02)&& timeout );
-
- CacheInv((unsigned int)completed_bd->buffAdd, sizeof(completed_bd->buffAdd));
-
- cppiDmaFreenBuffer((unsigned int *)completed_bd->buffAdd);
-
- completed_bd->buffAdd = 0;
-
- /*put the free buffer */
- putFreeBd(completed_bd);
-
- return state;
-
-}
-#else
-unsigned int dmaTxCompletion(unsigned short usbDevInst, unsigned int ulEndpoint )
-{
-
- hostPacketDesc *completed_bd;
- unsigned int ulRegister;
- unsigned int state;
- unsigned int packetid;
- usbInstance *usbInstance;
- unsigned int timeout = 0xFFFF;
- usbInstance = &(cppiInfo.usbInst[usbDevInst]);
-
- ulRegister = USB_O_TXCSRL1 + EP_OFFSET( ulEndpoint);
-
- ulEndpoint = USB_EP_TO_INDEX(ulEndpoint);
-
-
- /*read the compltetion queue */
- completed_bd = (hostPacketDesc *)Cppi41DmaReadCompletionQueue(usbDevInst, usbInstance
- ->txEndPoint[ulEndpoint].complettionq);
- /*Get the packet ID to update the DMA status */
- packetid = completed_bd->packetId;
- if(packetid == EOP)
- state = DMA_TX_COMPLETED;
- else
- state = DMA_TX_IN_PROGRESS;
-
- /*wait till Tx completion */
- if(state == DMA_TX_COMPLETED)
- do{
- -- timeout;
- }while (((HWREGH(usbInstance->usbInstCoreBaseAddress + ulRegister) & 0x2) == 0x02)&& timeout );
-
- CacheDataInvalidateBuff((unsigned int)completed_bd->buffAdd, sizeof(completed_bd->buffAdd));
-
- cppiDmaFreenBuffer((unsigned int *)completed_bd->buffAdd);
-
- completed_bd->buffAdd = 0;
-
- /*put the free buffer */
- putFreeBd(completed_bd);
-
- return state;
-
-}
-#endif
-/**
-* \brief This API reads the RX completion queue and puts the free bd to the BD pool
-* Extracts the data buffer from the DB and pass it to the caller . Extracts the
-* data buffer from the DB and pass it to the caller . This API will be called on
-* reception of a completion interrupt
-*
-* \param usbDevInst:- The USB Intance Number
-*
-* \param ulEndpoin:- End point Number
-*
-* \return Free BD.
-*
-**/
-#ifdef _TMS320C6X
-unsigned int dmaRxCompletion(unsigned short usbDevInst, unsigned int ulEndpoint )
-{
- unsigned int bufferAdd;
- unsigned int length;
- usbInstance *usbInstance;
-
- hostPacketDesc *rx_bd =NULL;;
-
- usbInstance = &(cppiInfo.usbInst[usbDevInst]);
-
- ulEndpoint = USB_EP_TO_INDEX(ulEndpoint);
-
- /*read the compltetion queue */
- rx_bd = (hostPacketDesc *)Cppi41DmaReadCompletionQueue(usbDevInst, usbInstance
- ->rxEndPoint[ulEndpoint].complettionq);
- /*Fush the cache to update the BD */
- CacheInv((unsigned int)rx_bd, sizeof(hostPacketDesc));
-
- bufferAdd = rx_bd->buffAdd;
- length = rx_bd->buffLength;
-
- /*Flush the cache to update the buffer */
- CacheInv(bufferAdd, length);
-
- putFreeBd(rx_bd);
-
- return bufferAdd;
-}
-#else
-unsigned int dmaRxCompletion(unsigned short usbDevInst, unsigned int ulEndpoint )
-{
-
- unsigned int bufferAdd;
- usbInstance *usbInstance;
-
- hostPacketDesc *rx_bd =NULL;
-
- usbInstance = &(cppiInfo.usbInst[usbDevInst]);
-
- ulEndpoint = USB_EP_TO_INDEX(ulEndpoint);
-
- /*read the compltetion queue */
- rx_bd = (hostPacketDesc *)Cppi41DmaReadCompletionQueue(usbDevInst, usbInstance
- ->rxEndPoint[ulEndpoint].complettionq);
- bufferAdd = rx_bd->buffAdd;
- /*Flush the cache to update the buffer */
- CacheDataInvalidateBuff(rx_bd->buffAdd, rx_bd->buffLength);
-
- putFreeBd(rx_bd);
-
- return bufferAdd;
-}
-#endif
-
-/**
-* \brief This API gets the transfer completion interupt status. This API will be on
-* reception of a USB interrupt to check the cause of interrupt.
-*
-* \param usbDevInst:- The USB Intance Number
-*
-* \return None.
-*
-**/
-unsigned int CppiDmaGetPendStatus(unsigned short usbDevInst)
-{
-
-#if defined (am335x_15x15) || defined(am335x) || defined(c6a811x)
- unsigned int pendReg2 = 0;
- unsigned int pendReg3 = 0;
-#endif
-
- unsigned int pendReg0 = 0;
-
-#if defined (am335x_15x15) || defined(am335x) || defined(c6a811x)
- if(usbDevInst == 0)
- {
- pendReg2 = HWREG(USB_OTGBASE + CPDMA_PEND_2_REGISTER);
- pendReg3 = HWREG(USB_OTGBASE + CPDMA_PEND_3_REGISTER);
- }
- else if(usbDevInst == 1)
- {
- pendReg2 = HWREG(USB_OTGBASE + CPDMA_PEND_3_REGISTER);
- pendReg3 = HWREG(USB_OTGBASE + CPDMA_PEND_4_REGISTER);
- }
- pendReg2 = pendReg2 & CPDMA_TX_PENDING;
- pendReg3 = pendReg3 & CPDMA_RX_PENDING;
-
- pendReg0 = pendReg2 | pendReg3;
-
-#else
- /*Read the pend register */
- pendReg0 = HWREG(USB_OTGBASE + CPDMA_PEND_0_REGISTER);
-#endif
- return pendReg0;
-}
-
-/**
-* \brief This API configures the scheduler
-*
-* \param Configuration entries for the channels
-*
-* \return None.
-*
-**/
-void Cppi41DmaControlScheduler(unsigned short usbDevInst, unsigned short enableDisable,
- unsigned short numOfentries)
-{
- usbInstance *usbInstance;
-
- usbInstance = &(cppiInfo.usbInst[usbDevInst]);
-
- HWREG(usbInstance->usbSubSysBaseAddress + CPDMA_SCHED_CONTROL_REG ) =(enableDisable
- << SCHEDULER_ENABLE_SHFT) | (numOfentries - 1);
-
-}
-
-/**
-* \brief This API to Process the BD
-*
-* \param current_bd :- the current BD Address
-*
-* \param direction:- The Transfer Direction
-*
-* \param buffadd:- The buffer address
-*
-* \param length:- Length of the buffer
-*
-* \return None.
-*
-**/
-void Cppi41DmaProcessBD(unsigned short usbDevInst, hostPacketDesc *current_bd,
- unsigned short direction, unsigned char * buffadd,
- unsigned int length, unsigned int ulEndpoint)
-{
-
- usbInstance *usbInstance;
-
- usbInstance = &(cppiInfo.usbInst[usbDevInst]);
-
- /*These values are fixed for a PD */
- current_bd->hPDword0.hostPktType = CPDMA_BD_PACKET_TYPE;
- current_bd->hPDword0.protSize=0;
-
- /* For TX BD, need to mention the lenght, for RX CPU will fill the feild */
- if(direction == CPDMA_DIR_TX)
- current_bd->hPDword0.pktLength= length;
- else
- current_bd->hPDword0.pktLength= 0;
-
- /* These vlaues are always initialized to zero */
- current_bd->hPDword1.dstTag=0;
- current_bd->hPDword1.srcSubChNum=0;
- current_bd->hPDword1.srcChNum=0;
-
- /*The channel Number */
- if(direction == CPDMA_DIR_TX)
- current_bd->hPDword1.srcPrtNum = usbInstance->txEndPoint[ulEndpoint]
- .channel + 1; /*chan_num+1; */
- else
- current_bd->hPDword1.srcPrtNum = usbInstance->rxEndPoint[ulEndpoint]
- .channel + 1; /*chan_num+1; */
-
- /*Completion Queues */
- if(direction == CPDMA_DIR_TX)
- current_bd->hPDword2.pktRetQueue=usbInstance->txEndPoint[ulEndpoint]
- .complettionq; /*returnQueue; */
- else
- current_bd->hPDword2.pktRetQueue=usbInstance->rxEndPoint[ulEndpoint]
- .complettionq; /*returnQueue; */
-
- current_bd->hPDword2.pktRetQM=0;
- /*The BD is on chip */
- current_bd->hPDword2.onChip=1;
- current_bd->hPDword2.retPolicy=0;
- current_bd->hPDword2.protoSpecific=0;
- current_bd->hPDword2.rsv=0;
- /*USB type packet */
- current_bd->hPDword2.pktType=5;
- current_bd->hPDword2.pktErr=0;
- current_bd->buffLength=length;
- current_bd->buffAdd=(unsigned int)buffadd;
- current_bd->nextHBDptr=0;
- current_bd->gBuffLength=current_bd->buffLength;
- current_bd->gBuffLength |= (unsigned int)(1<<31);
- current_bd->gBuffAdd=current_bd->buffAdd;
- current_bd->endPoint = (unsigned short)ulEndpoint;
- if(direction == CPDMA_DIR_TX)
- current_bd->channel = usbInstance->txEndPoint[ulEndpoint].channel;
- else
- current_bd->channel = usbInstance->rxEndPoint[ulEndpoint].channel;
- current_bd->devInst = (unsigned char)usbDevInst;
-
-}
-
-
-/**
-* \brief This API initialize the bbuffer
-*
-* \param none
-*
-* \return None.
-*
-**/
-void cppi41DmaInitBuffer()
-{
- int i;
-
- for(i =0;i<CPDMA_NUMOF_BUFFERS;i++)
- {
- dmaBuffer[i].dataBuffer =(unsigned int *)&dBuffer[i][0];
- dmaBuffer[i].usedFlag = CPDMA_BUFFER_NOT_USED;
- dmaBuffer[i].nBlocks = 0;
- }
-}
-
-
-/**
-* \brief This API will allocate 1unit(512 bytes) of buffer. This API is called
-* just before the RX and TX transfer. The API returns a pointer to the
-* buffer allocated , which can used by the caller for data transfer.
-*
-* \param none
-*
-* \return None.
-*
-**/
-unsigned int * cppiDmaAllocBuffer()
-{
- int i;
-
- for(i =0;i<CPDMA_NUMOF_BUFFERS;i++)
- {
- if(dmaBuffer[i].usedFlag == CPDMA_BUFFER_NOT_USED)
- {
- dmaBuffer[i].usedFlag = CPDMA_BUFFER_USED;
- dmaBuffer[i].nBlocks = 1;
- return dmaBuffer[i].dataBuffer;
- }
- }
- return NULL;
-}
-
-
-/**
-* \brief This API will free 1 unit of buffer. Caller needs to pass the buffer
-* address to be freed. Once buffer is freed, the usage flag will set
-* as BUFFER _NOT_USED
-*
-* \param dataBuffer:- Buffer address
-*
-* \return None.
-*
-**/
-void cppiDmaFreeBuffer(unsigned int *dataBuffer)
-{
- int i;
-
- for(i=0;i<CPDMA_NUMOF_BUFFERS;i++)
- {
- if(dmaBuffer[i].dataBuffer == dataBuffer)
- {
- dmaBuffer[i].usedFlag = CPDMA_BUFFER_NOT_USED;
- dmaBuffer[i].nBlocks = 0;
- break;
- }
- }
-
-}
-
-/**
-* \brief This API will allocate N (N*512 bytes) number of buffers. This API is called
-* just before the RX and TX transfer. The API returns a pointer to the
-* buffer allocated , which can used by the caller for data transfer.
-*
-* \param numOfBlocks:- Number of buffers
-*
-* \return None.
-*
-**/
-unsigned int * cppiDmaAllocnBuffer(unsigned int numOfBlocks)
-{
- unsigned int nBlocks = numOfBlocks;
- unsigned int i,j;
-
-
-
- for(i =0;i<CPDMA_NUMOF_BUFFERS;i++)
- {
- if(dmaBuffer[i].usedFlag == CPDMA_BUFFER_NOT_USED)
- nBlocks--;
- else
- nBlocks = numOfBlocks;
-
- if(nBlocks == 0)
- break;
-
- }
-
-
- if(nBlocks == 0)
- {
- for(j = i; j>(i-numOfBlocks); j--)
- {
- dmaBuffer[j].usedFlag = CPDMA_BUFFER_USED;
- }
- dmaBuffer[j+1].nBlocks = numOfBlocks;
- return dmaBuffer[j+1].dataBuffer;
- }
- else
- return NULL;
-
-}
-
-
-/**
-* \brief This API will free N(N *512 Bytes) buffers. Caller needs to pass the buffer
-* address to be freed. Once buffer is freed, the usage flag will set
-* as BUFFER _NOT_USED.
-*
-* \param dataBuffer:- Buffer address
-*
-* \return None.
-*
-**/
-
-void cppiDmaFreenBuffer(unsigned int *dataBuffer)
-{
- int i,j;
- unsigned int nBlocks = 0;
-
- for(i=0;i<CPDMA_NUMOF_BUFFERS;i++)
- {
- if(dmaBuffer[i].dataBuffer == dataBuffer)
- {
- nBlocks= dmaBuffer[i].nBlocks;
- break;
- }
- }
-
- if(nBlocks)
- {
- for(j =i; j<(i+nBlocks); j++)
- {
- dmaBuffer[j].usedFlag = CPDMA_BUFFER_NOT_USED;
- dmaBuffer[i].nBlocks= 0;
- }
-
- }
-
-}
-
-/**
-* \brief This API will Handle the starvation Error. The API will enable the
-* scheduler which is disabled due to the starvation interrupt.
-* This will help the DMA to resume the operation after clearing the starvation
-* interrupt.
-*
-* \param dusbDevInst:- USB device instance.
-*
-* \return None.
-*
-**/
-
-void cppiDmaHandleError(unsigned int usbDevInst)
-{
- Cppi41DmaControlScheduler(usbDevInst, ENABLE_CPPIDMA, NUM_OF_SCHEDULER_ENTRIES);
-
-}
-
-/**
-+* \brief This API will teardown a receive DMA channel.
-+* /
-+* For Rx DMA channels,there's only a single completion queue for
-+* TD Desc and the Buff desc, hence we temporarily redirect the
-+* completed descriptors to our teardown completion queue.
-+*
-+* \param usbDevInst:- USB device instance
-+* \param ulEndpoint:- endpoint whose rx channel needs to be torn down.
-+*
-+* \return None.
-+*
-+**/
-
-int Cppi41DmaRxChTeardown(unsigned short usbDevInst, unsigned int ulEndpoint )
-{
- signed int TeardownStatus = 0x0;
- usbInstance *usbInstance = &(cppiInfo.usbInst[usbDevInst]);
- volatile int TimeOut = 0xffff;
- unsigned int ulEndPointIndex = USB_EP_TO_INDEX(ulEndpoint);
- unsigned short ulRxChan = usbInstance->rxEndPoint[ulEndPointIndex].channel;
- hostPacketDesc* completed_bd = NULL;
- hPDWord0* DescHeaderPtr = NULL;
- int GlobalConfigReg =
- HWREG(usbInstance->usbSubSysBaseAddress + (CPDMA_RX_CHANNEL_CONFIG_REG +
- CHANNEL_OFFSET(ulRxChan)));
-
- /* Set Completion Q related info - Default Q manager (0)and Default Completion Q
- Note that we have alerady done this for this endpoint ,but these fields
- are Write only! */
-
- GlobalConfigReg |=
- ((usbInstance->rxEndPoint[ulEndPointIndex].complettionq
- << DMA_CH_TX_DEFAULT_QNUM_SHIFT) & DMA_CH_TX_DEFAULT_QNUM_MASK);
-
- /* Initiate channel teardown in gloabal CPPI Regs TxGCRn or RxGCRn */
- /* Disable the DMA channel and set the tear down bit*/
-
- /* Note CPPI Specification 4.7 clearly states that "host should not clear
- the enable bit when issuing the teardown command. Doing so may prevent
- the teardown operation from completing since the channel will be removed
- from transmit scheduling operations." - But for us this is what works! */
-
- GlobalConfigReg &= ~DMA_CH_TX_ENABLE_MASK;
- GlobalConfigReg |= DMA_CH_TX_TEARDOWN_MASK;
-
- HWREG(usbInstance->usbSubSysBaseAddress + (CPDMA_RX_CHANNEL_CONFIG_REG +
- CHANNEL_OFFSET(ulRxChan))) = GlobalConfigReg;
-
- /* Now we wait for the Buffer descriptor and the Teardown Desc to appear
- in the completion Queue of the Rx endpoint */
- do
- {
- /* First the Rx BD would come to the completion Q then the TD desc */
- DescHeaderPtr =(hPDWord0*)Cppi41DmaPopFromSubmitQ( usbDevInst,
- usbInstance->rxEndPoint[ulEndPointIndex].complettionq);
- if (NULL == DescHeaderPtr)
- {
- --TimeOut;
-
- }
- else if ( CPDMA_TEARDOWN_DESC_TYPE == DescHeaderPtr->hostPktType )
- {
- /* tear down descriptor has been received
- this function returns the number of bytes recevied in the
- Rx BD*/
- if (0xFFFFFFFF == TeardownStatus )
- {
- TeardownStatus = 1;
- }
- break;
- }
- else if ( CPDMA_BD_PACKET_TYPE == DescHeaderPtr->hostPktType )
- {
- /* We have popped the completed packet - is this the same channel
- that we tore down ? */
- //->hPDword1.srcPrtNum = usbInstance->txEndPoint[ulEndpoint]
- //.channel + 1; /*chan_num+1; */
- completed_bd = (hostPacketDesc*)DescHeaderPtr;
- TeardownStatus = DescHeaderPtr->pktLength ;
- continue;
- }
- } while(--TimeOut);
-
- /* We have got TD in the completion Q */
- if (TimeOut)
- {
- /* Now we need to free the Rx BD - if not read the Submit Q */
- if ( !completed_bd )
- {
- completed_bd = (hostPacketDesc*)Cppi41DmaPopFromSubmitQ( usbDevInst,
- usbInstance->rxEndPoint[ulEndPointIndex].submitq);
- }
-
- /* Now reuse the BD and buffer that we got in the rx completion q*/
- if (NULL!= completed_bd)
- {
- Cppi41DmaRecoverBD( completed_bd );
- }
- }
- return (TeardownStatus);
-}
-
-
-/**
-+* \brief This API will teardown a Transmit DMA channel.
-+* /
-+* For
-+*
-+*
-+* \param usbDevInst:- USB device instance
-+* \param ulEndpoint:- endpoint whose rx channel needs to be torn down.
-+*
-+* \return Teardown status or number of bytes transmitted by the torn channel
-+*
-+**/
-
-int Cppi41DmaTxChTeardown(unsigned short usbDevInst, unsigned int ulEndpoint )
-{
- signed int TeardownStatus = 0xFFFFFFFF;
- usbInstance *usbInstance = &(cppiInfo.usbInst[usbDevInst]);
- volatile int TimeOut = 0xffff;
- unsigned int ulEndPointIndex = USB_EP_TO_INDEX(ulEndpoint);
- unsigned short ulTxChan = usbInstance->txEndPoint[ulEndPointIndex].channel;
-
- int GlobalConfigReg =
- HWREG(usbInstance->usbSubSysBaseAddress + (CPDMA_TX_CHANNEL_CONFIG_REG +
- CHANNEL_OFFSET(ulTxChan)));
- hostPacketDesc* completed_bd = NULL;
- hPDWord0* DescHeaderPtr = NULL;
- /* Set Completion Q related info - Default Q manager (0)and Default Completion Q
- Note that we have alerady done this for this endpoint ,but these fields
- are Write only! */
-
- GlobalConfigReg |=
- ((usbInstance->txEndPoint[ulEndPointIndex].complettionq
- << DMA_CH_TX_DEFAULT_QNUM_SHIFT) & DMA_CH_TX_DEFAULT_QNUM_MASK);
-
- /* Initiate channel teardown in gloabal CPPI Regs TxGCRn or RxGCRn */
- /* Disable the DMA channel and set the tear down bit*/
-
- /* Note CPPI Specification 4.7 clearly states "host should not clear
- the enable bit when issuing the teardown command. Doing so may prevent
- the teardown operation from completing since the channel will be removed
- from transmit scheduling operations." - But for us this is what works! */
-
- GlobalConfigReg &= ~DMA_CH_TX_ENABLE_MASK;
- GlobalConfigReg |= DMA_CH_TX_TEARDOWN_MASK;
-
- HWREG(usbInstance->usbSubSysBaseAddress + (CPDMA_TX_CHANNEL_CONFIG_REG +
- CHANNEL_OFFSET(ulTxChan))) = GlobalConfigReg;
-
- /* Now we wait for the Buffer descriptor and the Teardown Desc to appear
- in the completion Queue of the Rx endpoint */
- do
- {
- /* Set the Teardown mask in USBnTDOWN register */
- if ( 1 == usbDevInst)
- {
- USBDmaTxChTeardown ( USB1_BASE, ulEndpoint);
- }
- else
- {
- USBDmaTxChTeardown ( USB0_BASE, ulEndpoint);
- }
- /* First the Tx BD would come to the completion Q then the TD desc */
- DescHeaderPtr =(hPDWord0*)Cppi41DmaPopFromSubmitQ( usbDevInst,
- usbInstance->txEndPoint[ulEndPointIndex].complettionq);
-
- if (NULL == DescHeaderPtr)
- {
- --TimeOut;
- }
- else if ( CPDMA_TEARDOWN_DESC_TYPE == DescHeaderPtr->hostPktType )
- {
- /* tear down descriptor has been received
- this function returns the number of bytes recevied in the
- Rx BD*/
- if (0xFFFFFFFF == TeardownStatus )
- {
- TeardownStatus = 1;
- }
- break;
- }
- else if ( CPDMA_BD_PACKET_TYPE == DescHeaderPtr->hostPktType )
- {
- /* We have popped the completed packet - is this the same channel
- that we tore down ? */
- //->hPDword1.srcPrtNum = usbInstance->txEndPoint[ulEndpoint]
- //.channel + 1; /*chan_num+1; */
- TeardownStatus = DescHeaderPtr->pktLength ;
- continue;
- }
-
- } while(--TimeOut);
- /* We have got TD in the completion Q */
- if (TimeOut)
- {
- /* Now we need to free the Tx BD - if not read the Submit Q */
- if ( !completed_bd )
- {
- completed_bd = (hostPacketDesc*)Cppi41DmaPopFromSubmitQ( usbDevInst,
- usbInstance->txEndPoint[ulEndPointIndex].submitq);
- }
- /* Now reuse the BD and buffer that we got in the rx completion q*/
- if (NULL!= completed_bd)
- {
- Cppi41DmaRecoverBD( completed_bd );
- }
- }
- return (TeardownStatus);
-}
-
-/**
-* \brief Configures the TD Desc Queue Control
-*
-* \param usbDevInst:- The USB Device instance
-*
-* \param tdDescq:-TD Desc queue
-*
-* \return None.
-*
-**/
-void Cppi41DmaConfigTDDescQueue(unsigned short usbDevInst,
- unsigned int tdDescq)
-{
- usbInstance *usbInstance;
-
- usbInstance = &(cppiInfo.usbInst[usbDevInst]);
-
- HWREG(usbInstance->usbSubSysBaseAddress + CPDMA_TD_FD_QUEUE_CONTROL_REG) = tdDescq;
-}
-
-/**
-* \brief API to submit a TDD to the queue
-*
-* \param usbDevInst:- The USB device instance
-*
-* \param queueNum:- The submit queue number
-*
-* \param curr_bd:- Address of TD to submit
-*
-* \return None.
-*
-**/
-void Cppi41DmaPushToTearDownQ(unsigned short usbDevInst,
- unsigned int queueNum, cppi41TearDownDesc *curr_tdd)
-{
-
- unsigned int submitqAdd;
- usbInstance *usbInstance;
- unsigned int curr_tdAdd = 0;
- usbInstance = &(cppiInfo.usbInst[usbDevInst]);
-
- /*get the TD address */
- curr_tdAdd = (unsigned int) curr_tdd;
- /* Add the length to it */
- curr_tdAdd |= SIZE_OF_TEARDOWNDESC;
-
- submitqAdd = usbInstance->usbSubSysBaseAddress + (CPDMA_QUEUE_REGISTER_D +
- QUEUE_OFFSET(queueNum));
- /*submit the queue */
- HWREG(submitqAdd) = (unsigned int) curr_tdAdd ;
-
-}
-
-/**
-* \brief API to submit a BD to the queue
-*
-* \param usbDevInst:- The USB device instance
-*
-* \param queueNum:- The submit queue number
-*
-* \return BD in the submit Q.
-*
-**/
-unsigned int Cppi41DmaPopFromSubmitQ(unsigned short usbDevInst, unsigned int queueNum)
-{
- unsigned int descAddress;
- usbInstance *usbInstance;
-
- usbInstance = &(cppiInfo.usbInst[usbDevInst]);
-
- /*Read the completetion queue register */
- descAddress=(unsigned int)HWREG(usbInstance->usbSubSysBaseAddress +
- (CPDMA_QUEUE_REGISTER_D + QUEUE_OFFSET(queueNum)));
- /*Extract the BD address */
- descAddress&=0xFFFFFFE0;
- return(descAddress);
-}
-
-/**
-* \brief Initializes the TD pool
-*
-* \param
-*
-* \return None.
-*
-**/
-
-void Cppi41DmaInitTddPool(unsigned short usbDevInst )
-{
-
- /* Since we do not have a different region space get the TD
- from the BD pool*/
- cppi41TearDownDesc *temp_bd = (cppi41TearDownDesc *)getFreeBd();
- ASSERT(temp_bd != NULL);
-
- temp_bd->teardown_info = (unsigned int)
- (CPDMA_DESC_TYPE_TD<<CPDMA_DESC_TYPE_TD_SHIFT);
- Cppi41DmaPushToTearDownQ(usbDevInst, USB0_TEARDOWNQ1, temp_bd);
-
-}
-/**
-* \brief API to get the queue packet count
-*
-* \param usbDevInst:- The USB device instance
-*
-* \param queueNum:- The queue number
-*
-* \return Number of packets in submit Q.
-*
-**/
-unsigned int Cppi41DmaGetQLength(unsigned short usbDevInst, unsigned int queueNum)
-{
- unsigned int ulQLength;
- usbInstance *usbInstance;
-
- usbInstance = &(cppiInfo.usbInst[usbDevInst]);
-
- /*Read the completetion queue register */
- ulQLength=(unsigned int)(HWREG(usbInstance->usbSubSysBaseAddress +
- (CPDMA_QUEUE_STATUS_A+ QUEUE_OFFSET(queueNum)))
- &CPDMA_QUEUE_STATUS_A_COUNT_MASK);
- return(ulQLength);
-}
-
-/**
-* \brief API to Free the BDs once complete
-*
-* \param completed_bd:- pointer to completed BD
-*
-*
-*
-* \return state.
-*
-**/
-unsigned int Cppi41DmaRecoverBD( hostPacketDesc* completed_bd )
-{
- unsigned int state;
- unsigned int packetid;
-
- /*Get the packet ID to update the DMA status */
- packetid = completed_bd->packetId;
- /* state is just information for the caller and is curently unused*/
- if(packetid == EOP)
- state = DMA_TX_COMPLETED;
- else
- state = DMA_TX_IN_PROGRESS;
-
- CacheDataInvalidateBuff((unsigned int)completed_bd->buffAdd, sizeof(completed_bd->buffAdd));
-
- cppiDmaFreenBuffer((unsigned int *)completed_bd->buffAdd);
-
- completed_bd->buffAdd = 0;
-
- /*put the free buffer */
- putFreeBd(completed_bd);
-
- return (state);
-}
-
-/**
-* \brief Print Pend Registers - debug
-*
-* \param none
-*
-*
-*
-* \return none.
-*
-**/
-
-void print_pend ( )
-{
-
- unsigned int pend0 = 0;
- unsigned int pend1 = 0;
- unsigned int pend2 = 0;
- unsigned int pend3 = 0;
-
- pend0 = HWREG(USB_OTGBASE + CPDMA_PEND_0_REGISTER);
- pend1 = HWREG(USB_OTGBASE + CPDMA_PEND_1_REGISTER);
- pend2 = HWREG(USB_OTGBASE + CPDMA_PEND_2_REGISTER);
- pend3 = HWREG(USB_OTGBASE + CPDMA_PEND_3_REGISTER);
-
-#ifndef SYLIXOS
- ConsoleUtilsPrintf("\t\t%s: %s = %x\n\n", __FUNCTION__, " pend0 ", pend0);
- ConsoleUtilsPrintf("\t\t%s: %s = %x\n\n", __FUNCTION__, " pend1 ", pend1);
- ConsoleUtilsPrintf("\t\t%s: %s = %x\n\n", __FUNCTION__, " pend2 ", pend2);
- ConsoleUtilsPrintf("\t\t%s: %s = %x\n\n", __FUNCTION__, " pend3 ", pend3);
-#else
- /*
- * 避免实现 ConsoleUtilsPrintf 这个调试函数,直接使用 printf 函数替换
- */
- printf("\t\t%s: %s = %x\n\n", __FUNCTION__, " pend0 ", pend0);
- printf("\t\t%s: %s = %x\n\n", __FUNCTION__, " pend1 ", pend1);
- printf("\t\t%s: %s = %x\n\n", __FUNCTION__, " pend2 ", pend2);
- printf("\t\t%s: %s = %x\n\n", __FUNCTION__, " pend3 ", pend3);
-#endif
-}
-
diff --git a/SylixOS/StarterWare/drivers/usb.c b/SylixOS/StarterWare/drivers/usb.c
deleted file mode 100644
index 9202e1b..0000000
--- a/SylixOS/StarterWare/drivers/usb.c
+++ /dev/null
@@ -1,3543 +0,0 @@
-/**
- * \file usb.c
- *
- * \brief Driver for the USB Interface.
- */
-
-/*
-* Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
-*/
-/*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions
-* are met:
-*
-* Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-*
-* Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the
-* distribution.
-*
-* Neither the name of Texas Instruments Incorporated nor the names of
-* its contributors may be used to endorse or promote products derived
-* from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*
-*/
-
-/**
- * \addtogroup usb_api
- * @{
- */
-
-/* Debug Macros */
-#include "debug.h"
-
-/* HW Macros and Peripheral Defines */
-#include "hw_types.h"
-#include "hw_usb.h"
-// Must be added to PREDEFINES
-#define DMA_MODE 1
-
-#ifdef DMA_MODE
-#include "cppi41dma.h"
-#endif
-
-/* Driver APIs */
-#include "usb.h"
-#include "interrupt.h"
-#include "delay.h"
-
-/* Amount to shift the RX interrupt sources by in the flags used in the
- * interrupt calls. */
-#ifndef DEPRECATED
-#define USB_INT_RX_SHIFT 8
-#endif
-#define USB_INTEP_RX_SHIFT 16
-
-/* Amount to shift the status interrupt sources by in the flags used in the
- * interrupt calls. */
-#ifndef DEPRECATED
-#define USB_INT_STATUS_SHIFT 24
-#endif
-
-/* Amount to shift the RX endpoint status sources by in the flags used in the
- * calls. */
-#define USB_RX_EPSTATUS_SHIFT 16
-
-/* Converts from an endpoint specifier to the offset of the endpoint's
- * control/status registers. */
-#define EP_OFFSET(Endpoint) (Endpoint - 0x10)
-
-
-/**
- * Sets one of the indexed registers.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint is the endpoint index to target for this write.
- * \param ulIndexedReg is the indexed register to write to.
- * \param ucValue is the value to write to the register.
- *
- * This function is used to access the indexed registers for each endpoint.
- * The only registers that are indexed are the FIFO configuration registers
- * which are not used after configuration.
- *
- * \return None.
- */
-static void
-USBIndexWrite(unsigned int ulBase, unsigned int ulEndpoint,
- unsigned int ulIndexedReg, unsigned int ulValue,
- unsigned int ulSize)
-{
- unsigned int ulIndex;
-
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulEndpoint == 0) || (ulEndpoint == 1) || (ulEndpoint == 2) ||
- (ulEndpoint == 3));
- ASSERT((ulSize == 1) || (ulSize == 2));
-
- /* Save the old index in case it was in use. */
- ulIndex = HWREGB(ulBase + USB_O_EPIDX);
-
- /* Set the index. */
- HWREGB(ulBase + USB_O_EPIDX) = ulEndpoint;
-
- /* Determine the size of the register value. */
- if(ulSize == 1)
- {
- /* Set the value. */
- HWREGB(ulBase + ulIndexedReg) = ulValue;
- }
- else
- {
- /* Set the value. */
- HWREGH(ulBase + ulIndexedReg) = ulValue;
- }
-
- /* Restore the old index in case it was in use. */
- HWREGB(ulBase + USB_O_EPIDX) = ulIndex;
-}
-
-/**
- * Reads one of the indexed registers.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint is the endpoint index to target for this write.
- * \param ulIndexedReg is the indexed register to write to.
- *
- * This function is used interally to access the indexed registers for each
- * endpoint. The only registers that are indexed are the FIFO configuration
- * registers which are not used after configuration.
- *
- * \return The value in the register requested.
- */
-static unsigned int
-USBIndexRead(unsigned int ulBase, unsigned int ulEndpoint,
- unsigned int ulIndexedReg, unsigned int ulSize)
-{
- unsigned char ulIndex;
- unsigned char ulValue;
-
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulEndpoint == 0) || (ulEndpoint == 1) || (ulEndpoint == 2) ||
- (ulEndpoint == 3));
- ASSERT((ulSize == 1) || (ulSize == 2));
-
- /* Save the old index in case it was in use. */
- ulIndex = HWREGB(ulBase + USB_O_EPIDX);
-
- /* Set the index. */
- HWREGB(ulBase + USB_O_EPIDX) = ulEndpoint;
-
- /* Determine the size of the register value. */
- if(ulSize == 1)
- {
- /* Get the value. */
- ulValue = HWREGB(ulBase + ulIndexedReg);
- }
- else
- {
- /* Get the value. */
- ulValue = HWREGH(ulBase + ulIndexedReg);
- }
-
- /* Restore the old index in case it was in use. */
- HWREGB(ulBase + USB_O_EPIDX) = ulIndex;
-
- /* Return the register's value. */
- return(ulValue);
-}
-
-/**
- * Puts the USB bus in a suspended state.
- *
- * \param ulBase specifies the USB module base address.
- *
- * When used in host mode, this function will put the USB bus in the suspended
- * state.
- *
- * \note This function should only be called in host mode.
- *
- * \return None.
- */
-void
-USBHostSuspend(unsigned int ulBase)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
-
- /* Send the suspend signaling to the USB bus. */
- HWREGB(ulBase + USB_O_POWER) |= USB_POWER_SUSPEND;
-}
-
-/**
- * Handles the USB bus reset condition.
- *
- * \param ulBase specifies the USB module base address.
- * \param bStart specifies whether to start or stop signaling reset on the USB
- * bus.
- *
- * When this function is called with the \e bStart parameter set to \b true,
- * this function will cause the start of a reset condition on the USB bus.
- * The caller should then delay at least 20ms before calling this function
- * again with the \e bStart parameter set to \b false.
- *
- * \note This function should only be called in host mode.
- *
- * \return None.
- */
-void
-USBHostReset(unsigned int ulBase, tBoolean bStart)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
-
- /* Send a reset signal to the bus. */
- if(bStart)
- {
- HWREGB(ulBase + USB_O_POWER) |= USB_POWER_RESET;
- }
- else
- {
- HWREGB(ulBase + USB_O_POWER) &= ~USB_POWER_RESET;
- }
-}
-
-/**
- * Handles the USB bus resume condition.
- *
- * \param ulBase specifies the USB module base address.
- * \param bStart specifies if the USB controller is entering or leaving the
- * resume signaling state.
- *
- * When in device mode this function will bring the USB controller out of the
- * suspend state. This call should first be made with the \e bStart parameter
- * set to \b true to start resume signaling. The device application should
- * then delay at least 10ms but not more than 15ms before calling this
- * function with the \e bStart parameter set to \b false.
- *
- * When in host mode this function will signal devices to leave the suspend
- * state. This call should first be made with the \e bStart parameter set to
- * \b true to start resume signaling. The host application should then delay
- * at least 20ms before calling this function with the \e bStart parameter set
- * to \b false. This will cause the controller to complete the resume
- * signaling on the USB bus.
- *
- * \return None.
-*/
-void
-USBHostResume(unsigned int ulBase, tBoolean bStart)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
-
- /* Send a resume signal to the bus. */
- if(bStart)
- {
- HWREGB(ulBase + USB_O_POWER) |= USB_POWER_RESUME;
- }
- else
- {
- HWREGB(ulBase + USB_O_POWER) &= ~USB_POWER_RESUME;
- }
-}
-
-/**
- * Returns the current speed of the USB device connected.
- *
- * \param ulBase specifies the USB module base address.
- *
- * This function will return the current speed of the USB bus.
- *
- * \note This function should only be called in host mode.
- *
- * \return Returns either \b USB_LOW_SPEED, \b USB_FULL_SPEED, or
- * \b USB_UNDEF_SPEED.
- */
-unsigned int
-USBHostSpeedGet(unsigned int ulBase)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
-
- /* After Reset , Host negitiates the speed by Chirp logic and then sets this bit */
- if(HWREGB(ulBase + USB_O_POWER) & USB_POWER_HS_MODE)
- {
- return(USB_HIGH_SPEED);
- }
-
- /* If the Full Speed device bit is set, then this is a full speed device. */
- if(HWREGB(ulBase + USB_O_DEVCTL) & USB_DEVCTL_FSDEV)
- {
- return(USB_FULL_SPEED);
- }
-
- /* If the Low Speed device bit is set, then this is a low speed device. */
- if(HWREGB(ulBase + USB_O_DEVCTL) & USB_DEVCTL_LSDEV)
- {
- return(USB_LOW_SPEED);
- }
-
- /* The device speed is not known. */
- return(USB_UNDEF_SPEED);
-}
-
-/**
- * Returns the status of the USB interrupts.
- *
- * \param ulBase specifies the USB module base address.
- *
- * This function will read the source of the interrupt for the USB controller.
- * There are three groups of interrupt sources, IN Endpoints, OUT Endpoints,
- * and general status changes. This call will return the current status for
- * all of these interrupts. The bit values returned should be compared
- * against the \b USB_HOST_IN, \b USB_HOST_OUT, \b USB_HOST_EP0,
- * \b USB_DEV_IN, \b USB_DEV_OUT, and \b USB_DEV_EP0 values.
- *
- * \note This call will clear the source of all of the general status
- * interrupts.
- *
- * \note WARNING: This API cannot be used on endpoint numbers greater than
- * endpoint 3 so USBIntStatusControl() or USBIntStatusEndpoint() should be
- * used instead.
- *
- * \return Returns the status of the sources for the USB controller's
- * interrupt.
- */
-#ifndef DEPRECATED
-unsigned int
-USBIntStatus(unsigned int ulBase)
-{
- unsigned int ulStatus;
-
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
-
- /* Get the transmit interrupt status. */
- ulStatus = (HWREGB(ulBase + USB_O_TXIS));
-
- /* Get the receive interrupt status, these bits go into the second byte of
- * the returned value. */
- ulStatus |= (HWREGB(ulBase + USB_O_RXIS) << USB_INT_RX_SHIFT);
-
- /* Get the general interrupt status, these bits go into the upper 8 bits
- * of the returned value. */
- ulStatus |= (HWREGB(ulBase + USB_O_IS) << USB_INT_STATUS_SHIFT);
-
- /* Add the power fault status. */
- if(HWREG(ulBase + USB_O_EPCISC) & USB_EPCISC_PF)
- {
- /* Indicate a power fault was detected. */
- ulStatus |= USB_INT_POWER_FAULT;
-
- /* Clear the power fault interrupt. */
- HWREGB(ulBase + USB_O_EPCISC) |= USB_EPCISC_PF;
- }
-
- if(HWREG(ulBase + USB_O_IDVISC) & USB_IDVRIS_ID)
- {
- /* Indicate a id detection was detected. */
- ulStatus |= USB_INT_MODE_DETECT;
-
- /* Clear the id detection interrupt. */
- HWREG(ulBase + USB_O_IDVISC) |= USB_IDVRIS_ID;
- }
-
- /* Return the combined interrupt status. */
- return(ulStatus);
-}
-#endif
-
-/**
- * Disables the sources for USB interrupts.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulFlags specifies which interrupts to disable.
- *
- * This function will disable the USB controller from generating the
- * interrupts indicated by the \e ulFlags parameter. There are three groups
- * of interrupt sources, IN Endpoints, OUT Endpoints, and general status
- * changes, specified by \b USB_INT_HOST_IN, \b USB_INT_HOST_OUT,
- * \b USB_INT_DEV_IN, \b USB_INT_DEV_OUT, and \b USB_INT_STATUS. If
- * \b USB_INT_ALL is specified then all interrupts will be disabled.
- *
- * \note WARNING: This API cannot be used on endpoint numbers greater than
- * endpoint 3 so USBIntDisableControl() or USBIntDisableEndpoint() should be
- * used instead.
- *
- * \return None.
- */
-#ifndef DEPRECATED
-void
-USBIntDisable(unsigned int ulBase, unsigned int ulFlags)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulFlags & ~(USB_INT_ALL)) == 0);
-
- /* If any transmit interrupts were disabled then write the transmit
- * interrupt settings out to the hardware. */
- if(ulFlags & (USB_INT_HOST_OUT | USB_INT_DEV_IN | USB_INT_EP0))
- {
- HWREGH(ulBase + USB_O_TXIE) &=
- ~(ulFlags & (USB_INT_HOST_OUT | USB_INT_DEV_IN | USB_INT_EP0));
- }
-
- /* If any receive interrupts were disabled then write the receive interrupt
- * settings out to the hardware. */
- if(ulFlags & (USB_INT_HOST_IN | USB_INT_DEV_OUT))
- {
- HWREGH(ulBase + USB_O_RXIE) &=
- ~((ulFlags & (USB_INT_HOST_IN | USB_INT_DEV_OUT)) >>
- USB_INT_RX_SHIFT);
- }
-
- /* If any general interrupts were disabled then write the general interrupt
- * settings out to the hardware. */
- if(ulFlags & USB_INT_STATUS)
- {
- HWREGB(ulBase + USB_O_IE) &=
- ~((ulFlags & USB_INT_STATUS) >> USB_INT_STATUS_SHIFT);
- }
-
- /* Disable the power fault interrupt. */
- if(ulFlags & USB_INT_POWER_FAULT)
- {
- HWREG(ulBase + USB_O_EPCIM) = 0;
- }
-
- /* Disable the ID pin detect interrupt. */
- if(ulFlags & USB_INT_MODE_DETECT)
- {
- HWREG(ulBase + USB_O_IDVIM) = 0;
- }
-}
-#endif
-
-/**
- * Enables the sources for USB interrupts.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulFlags specifies which interrupts to enable.
- *
- * This function will enable the USB controller's ability to generate the
- * interrupts indicated by the \e ulFlags parameter. There are three
- * groups of interrupt sources, IN Endpoints, OUT Endpoints, and
- * general status changes, specified by \b USB_INT_HOST_IN,
- * \b USB_INT_HOST_OUT, \b USB_INT_DEV_IN, \b USB_INT_DEV_OUT, and
- * \b USB_STATUS. If \b USB_INT_ALL is specified then all interrupts will be
- * enabled.
- *
- * \note A call must be made to enable the interrupt in the main interrupt
- * controller to receive interrupts. The USBIntRegister() API performs this
- * controller level interrupt enable. However if static interrupt handlers
- * are used then then a call to IntEnable() must be made in order to allow any
- * USB interrupts to occur.
- *
- * \note WARNING: This API cannot be used on endpoint numbers greater than
- * endpoint 3 so USBIntEnableControl() or USBIntEnableEndpoint() should be
- * used instead.
- *
- * \return None.
- */
-#ifndef DEPRECATED
-void
-USBIntEnable(unsigned int ulBase, unsigned int ulFlags)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulFlags & (~USB_INT_ALL)) == 0);
-
- /* If any transmit interrupts were enabled then write the transmit
- * interrupt settings out to the hardware. */
- if(ulFlags & (USB_INT_HOST_OUT | USB_INT_DEV_IN | USB_INT_EP0))
- {
- HWREGH(ulBase + USB_O_TXIE) |=
- ulFlags & (USB_INT_HOST_OUT | USB_INT_DEV_IN | USB_INT_EP0);
- }
-
- /* If any receive interrupts were enabled then write the receive interrupt
- * settings out to the hardware. */
- if(ulFlags & (USB_INT_HOST_IN | USB_INT_DEV_OUT))
- {
- HWREGH(ulBase + USB_O_RXIE) |=
- ((ulFlags & (USB_INT_HOST_IN | USB_INT_DEV_OUT)) >>
- USB_INT_RX_SHIFT);
- }
-
- /* If any general interrupts were enabled then write the general interrupt
- * settings out to the hardware. */
- if(ulFlags & USB_INT_STATUS)
- {
- HWREGB(ulBase + USB_O_IE) |=
- (ulFlags & USB_INT_STATUS) >> USB_INT_STATUS_SHIFT;
- }
-
- /* Enable the power fault interrupt. */
- if(ulFlags & USB_INT_POWER_FAULT)
- {
- HWREG(ulBase + USB_O_EPCIM) = USB_EPCIM_PF;
- }
-
- /* Enable the ID pin detect interrupt. */
- if(ulFlags & USB_INT_MODE_DETECT)
- {
- HWREG(ulBase + USB_O_IDVIM) = USB_IDVIM_ID;
- }
-}
-#endif
-
-/**
- * Disable control interrupts on a given USB controller.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulFlags specifies which control interrupts to disable.
- *
- * This function will disable the control interrupts for the USB controller
- * specified by the \e ulBase parameter. The \e ulFlags parameter specifies
- * which control interrupts to disable. The flags passed in the \e ulFlags
- * parameters should be the definitions that start with \b USB_INTCTRL_* and
- * not any other \b USB_INT flags.
- *
- * \return None.
- */
-void
-USBIntDisableControl(unsigned int ulBase, unsigned int ulFlags)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulFlags & ~(USB_INTCTRL_ALL)) == 0);
-
- /* If any general interrupts were disabled then write the general interrupt
- * settings out to the hardware. */
- if(ulFlags & USB_INTCTRL_STATUS)
- {
- HWREGB(ulBase + USB_O_IE) &= ~(ulFlags & USB_INTCTRL_STATUS);
- }
-
- /* Disable the power fault interrupt. */
- if(ulFlags & USB_INTCTRL_POWER_FAULT)
- {
- HWREG(ulBase + USB_O_EPCIM) = 0;
- }
-
- /* Disable the ID pin detect interrupt. */
- if(ulFlags & USB_INTCTRL_MODE_DETECT)
- {
- HWREG(ulBase + USB_O_IDVIM) = 0;
- }
-}
-
-/**
- * Enable control interrupts on a given USB controller.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulFlags specifies which control interrupts to enable.
- *
- * This function will enable the control interrupts for the USB controller
- * specified by the \e ulBase parameter. The \e ulFlags parameter specifies
- * which control interrupts to enable. The flags passed in the \e ulFlags
- * parameters should be the definitions that start with \b USB_INTCTRL_* and
- * not any other \b USB_INT flags.
- *
- * \return None.
- */
-void
-USBIntEnableControl(unsigned int ulBase, unsigned int ulFlags)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulFlags & (~USB_INTCTRL_ALL)) == 0);
-
- /* If any general interrupts were enabled then write the general interrupt
- * settings out to the hardware. */
- if(ulFlags & USB_INTCTRL_STATUS)
- {
- HWREGB(ulBase + USB_O_IE) |= ulFlags;
- }
-
- /* Enable the power fault interrupt. */
- if(ulFlags & USB_INTCTRL_POWER_FAULT)
- {
- HWREG(ulBase + USB_O_EPCIM) = USB_EPCIM_PF;
- }
-
- /* Enable the ID pin detect interrupt. */
- if(ulFlags & USB_INTCTRL_MODE_DETECT)
- {
- HWREG(ulBase + USB_O_IDVIM) = USB_IDVIM_ID;
- }
-}
-
-/**
- * Returns the control interrupt status on a given USB controller.
- *
- * \param ulBase specifies the USB module base address.
- *
- * This function will read control interrupt status for a USB controller.
- * This call will return the current status for control interrupts only, the
- * endpoint interrupt status is retrieved by calling USBIntStatusEndpoint().
- * The bit values returned should be compared against the \b USB_INTCTRL_*
- * values.
- *
- * The following are the meanings of all \b USB_INCTRL_ flags and the modes
- * for which they are valid. These values apply to any calls to
- * USBIntStatusControl(), USBIntEnableControl(), and USBIntDisableConrol().
- * Some of these flags are only valid in the following modes as indicated in
- * the parenthesis: Host, Device, and OTG.
- *
- * - \b USB_INTCTRL_ALL - A full mask of all control interrupt sources.
- * - \b USB_INTCTRL_VBUS_ERR - A VBUS error has occurred (Host Only).
- * - \b USB_INTCTRL_SESSION - Session Start Detected on A-side of cable
- * (OTG Only).
- * - \b USB_INTCTRL_SESSION_END - Session End Detected (Device Only)
- * - \b USB_INTCTRL_DISCONNECT - Device Disconnect Detected (Host Only)
- * - \b USB_INTCTRL_CONNECT - Device Connect Detected (Host Only)
- * - \b USB_INTCTRL_SOF - Start of Frame Detected.
- * - \b USB_INTCTRL_BABBLE - USB controller detected a device signalling past
- * the end of a frame. (Host Only)
- * - \b USB_INTCTRL_RESET - Reset signalling detected by device. (Device Only)
- * - \b USB_INTCTRL_RESUME - Resume signalling detected.
- * - \b USB_INTCTRL_SUSPEND - Suspend signalling detected by device (Device
- * Only)
- * - \b USB_INTCTRL_MODE_DETECT - OTG cable mode detection has completed
- * (OTG Only)
- * - \b USB_INTCTRL_POWER_FAULT - Power Fault detected. (Host Only)
- *
- * \note This call will clear the source of all of the control status
- * interrupts.
- *
- * \return Returns the status of the control interrupts for a USB controller.
- */
-unsigned int
-USBIntStatusControl(unsigned int ulBase)
-{
- unsigned int ulStatus = 0;
-
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
-
- /* Get the general interrupt status, these bits go into the upper 8 bits
- * of the returned value. */
-
- /*ulStatus = HWREGB(USB_0_OTGBASE + USB_0_GENR_INTR); */
-
- /* Add the power fault status. */
- if(HWREG(ulBase + USB_O_EPCISC) & USB_EPCISC_PF)
- {
- /* Indicate a power fault was detected. */
- ulStatus |= USB_INTCTRL_POWER_FAULT;
-
- /* Clear the power fault interrupt. */
- HWREGB(ulBase + USB_O_EPCISC) |= USB_EPCISC_PF;
- }
-
- if(HWREG(ulBase + USB_O_IDVISC) & USB_IDVRIS_ID)
- {
- /* Indicate a id detection was detected. */
- ulStatus |= USB_INTCTRL_MODE_DETECT;
-
- /* Clear the id detection interrupt. */
- HWREG(ulBase + USB_O_IDVISC) |= USB_IDVRIS_ID;
- }
-
- /* Return the combined interrupt status. */
- return(ulStatus);
-}
-
-/**
- * Disable endpoint interrupts on a given USB controller.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulFlags specifies which endpoint interrupts to disable.
- *
- * This function will disable endpoint interrupts for the USB controller
- * specified by the \e ulBase parameter. The \e ulFlags parameter specifies
- * which endpoint interrupts to disable. The flags passed in the \e ulFlags
- * parameters should be the definitions that start with \b USB_INTEP_* and not
- * any other \b USB_INT flags.
- *
- * \return None.
- */
-void
-USBIntDisableEndpoint(unsigned int ulBase, unsigned int ulFlags)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
-
- /* If any transmit interrupts were disabled then write the transmit
- * interrupt settings out to the hardware. */
- HWREGH(ulBase + USB_O_TXIE) &=
- ~(ulFlags & (USB_INTEP_HOST_OUT | USB_INTEP_DEV_IN | USB_INTEP_0));
-
- /* If any receive interrupts were disabled then write the receive interrupt
- * settings out to the hardware. */
- HWREGH(ulBase + USB_O_RXIE) &=
- ~((ulFlags & (USB_INTEP_HOST_IN | USB_INTEP_DEV_OUT)) >>
- USB_INTEP_RX_SHIFT);
-}
-
-/**
- * Enable endpoint interrupts on a given USB controller.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulFlags specifies which endpoint interrupts to enable.
- *
- * This function will enable endpoint interrupts for the USB controller
- * specified by the \e ulBase parameter. The \e ulFlags parameter specifies
- * which endpoint interrupts to enable. The flags passed in the \e ulFlags
- * parameters should be the definitions that start with \b USB_INTEP_* and not
- * any other \b USB_INT flags.
- *
- * \return None.
- */
-void
-USBIntEnableEndpoint(unsigned int ulBase, unsigned int ulFlags)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
-
- /* Enable any transmit endpoint interrupts. */
- HWREGH(ulBase + USB_O_TXIE) |=
- ulFlags & (USB_INTEP_HOST_OUT | USB_INTEP_DEV_IN | USB_INTEP_0);
-
- /* Enable any receive endpoint interrupts. */
- HWREGH(ulBase + USB_O_RXIE) |=
- ((ulFlags & (USB_INTEP_HOST_IN | USB_INTEP_DEV_OUT)) >>
- USB_INTEP_RX_SHIFT);
-}
-
-/**
- * Returns the endpoint interrupt status on a given USB controller.
- *
- * \param ulBase specifies the USB module base address.
- *
- * This function will read endpoint interrupt status for a USB controller.
- * This call will return the current status for endpoint interrupts only, the
- * control interrupt status is retrieved by calling USBIntStatusControl().
- * The bit values returned should be compared against the \b USB_INTEP_*
- * values. These are grouped into classes for \b USB_INTEP_HOST_* and
- * \b USB_INTEP_DEV_* values to handle both host and device modes with all
- * endpoints.
- *
- * \note This call will clear the source of all of the endpoint interrupts.
- *
- * \return Returns the status of the endpoint interrupts for a USB controller.
- */
-unsigned int
-USBIntStatusEndpoint(unsigned int ulBase)
-{
- unsigned int ulStatus;
-
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
-
- /* Get the transmit interrupt status. */
- ulStatus = HWREGH(ulBase + USB_O_TXIS);
-
- ulStatus |= (HWREGH(ulBase + USB_O_RXIS) << USB_INTEP_RX_SHIFT);
- /* Return the combined interrupt status. */
- return(ulStatus);
-}
-
-#ifndef SYLIXOS
-/**
- * Registers an interrupt handler for the USB controller.
- *
- * \param ulBase specifies the USB module base address.
- * \param pfnHandler is a pointer to the function to be called when a USB
- * interrupt occurs.
- *
- * This sets the handler to be called when a USB interrupt occurs. This will
- * also enable the global USB interrupt in the interrupt controller. The
- * specific desired USB interrupts must be enabled via a separate call to
- * USBIntEnable(). It is the interrupt handler's responsibility to clear the
- * interrupt sources via a calls to USBIntStatusControl() and
- * USBIntStatusEndpoint().
- *
- * \sa IntRegister() for important information about registering interrupt
- * handlers.
- *
- * \return None.
- */
-void
-USBIntRegister(unsigned int ulBase, void(*pfnHandler)(void))
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
-
-#ifdef _TMS320C6X
-#if defined(c6a811x) || defined(c6741x)
- /* Apply interrupt mux. */
- USBIntMux();
-#endif
-
- /* Register the interrupt handler. */
- IntRegister(ulBase, pfnHandler);
-
- /* Enable the USB interrupt. */
- IntEnable(ulBase);
-#else
- /* Register the interrupt handler. */
- IntRegister(ulBase, pfnHandler);
-
- /* Enable the USB interrupt. */
- IntEnable(ulBase);
-#endif
-}
-
-/**
- * Unregisters an interrupt handler for the USB controller.
- *
- * \param ulBase specifies the USB module base address.
- *
- * This function unregister the interrupt handler. This function will also
- * disable the USB interrupt in the interrupt controller.
- *
- * \sa IntRegister() for important information about registering or
- * unregistering interrupt handlers.
- *
- * \return None.
- */
-void
-USBIntUnregister(unsigned int ulBase)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
-
- /*Disable the Interrupts */
-#ifdef _TMS320C6X
- IntDisable(ulBase);
-#else
- IntDisable();
-#endif
-}
-#endif
-
-/**
- * Returns the current status of an endpoint.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint is the endpoint to access.
- *
- * This function will return the status of a given endpoint. If any of these
- * status bits need to be cleared, then these these values must be cleared by
- * calling the USBDevEndpointStatusClear() or USBHostEndpointStatusClear()
- * functions.
- *
- * The following are the status flags for host mode:
- *
- * - \b USB_HOST_IN_PID_ERROR - PID error on the given endpoint.
- * - \b USB_HOST_IN_NOT_COMP - The device failed to respond to an IN request.
- * - \b USB_HOST_IN_STALL - A stall was received on an IN endpoint.
- * - \b USB_HOST_IN_DATA_ERROR - There was a CRC or bit-stuff error on an IN
- * endpoint in Isochronous mode.
- * - \b USB_HOST_IN_NAK_TO - NAKs received on this IN endpoint for more than
- * the specified timeout period.
- * - \b USB_HOST_IN_ERROR - Failed to communicate with a device using this IN
- * endpoint.
- * - \b USB_HOST_IN_FIFO_FULL - This IN endpoint's FIFO is full.
- * - \b USB_HOST_IN_PKTRDY - Data packet ready on this IN endpoint.
- * - \b USB_HOST_OUT_NAK_TO - NAKs received on this OUT endpoint for more than
- * the specified timeout period.
- * - \b USB_HOST_OUT_NOT_COMP - The device failed to respond to an OUT
- * request.
- * - \b USB_HOST_OUT_STALL - A stall was received on this OUT endpoint.
- * - \b USB_HOST_OUT_ERROR - Failed to communicate with a device using this
- * OUT endpoint.
- * - \b USB_HOST_OUT_FIFO_NE - This endpoint's OUT FIFO is not empty.
- * - \b USB_HOST_OUT_PKTPEND - The data transfer on this OUT endpoint has not
- * completed.
- * - \b USB_HOST_EP0_NAK_TO - NAKs received on endpoint zero for more than the
- * specified timeout period.
- * - \b USB_HOST_EP0_ERROR - The device failed to respond to a request on
- * endpoint zero.
- * - \b USB_HOST_EP0_IN_STALL - A stall was received on endpoint zero for an
- * IN transaction.
- * - \b USB_HOST_EP0_IN_PKTRDY - Data packet ready on endpoint zero for an IN
- * transaction.
- *
- * The following are the status flags for device mode:
- *
- * - \b USB_DEV_OUT_SENT_STALL - A stall was sent on this OUT endpoint.
- * - \b USB_DEV_OUT_DATA_ERROR - There was a CRC or bit-stuff error on an OUT
- * endpoint.
- * - \b USB_DEV_OUT_OVERRUN - An OUT packet was not loaded due to a full FIFO.
- * - \b USB_DEV_OUT_FIFO_FULL - The OUT endpoint's FIFO is full.
- * - \b USB_DEV_OUT_PKTRDY - There is a data packet ready in the OUT
- * endpoint's FIFO.
- * - \b USB_DEV_IN_NOT_COMP - A larger packet was split up, more data to come.
- * - \b USB_DEV_IN_SENT_STALL - A stall was sent on this IN endpoint.
- * - \b USB_DEV_IN_UNDERRUN - Data was requested on the IN endpoint and no
- * data was ready.
- * - \b USB_DEV_IN_FIFO_NE - The IN endpoint's FIFO is not empty.
- * - \b USB_DEV_IN_PKTPEND - The data transfer on this IN endpoint has not
- * completed.
- * - \b USB_DEV_EP0_SETUP_END - A control transaction ended before Data End
- * condition was sent.
- * - \b USB_DEV_EP0_SENT_STALL - A stall was sent on endpoint zero.
- * - \b USB_DEV_EP0_IN_PKTPEND - The data transfer on endpoint zero has not
- * completed.
- * - \b USB_DEV_EP0_OUT_PKTRDY - There is a data packet ready in endpoint
- * zero's OUT FIFO.
- *
- * \return The current status flags for the endpoint depending on mode.
- */
-unsigned int
-USBEndpointStatus(unsigned int ulBase, unsigned int ulEndpoint)
-{
- unsigned int ulStatus;
-
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
-
- /* Get the TX portion of the endpoint status. */
- ulStatus = HWREGH(ulBase + EP_OFFSET(ulEndpoint) + USB_O_TXCSRL1);
-
- /* Get the RX portion of the endpoint status. */
- ulStatus |= ((HWREGH(ulBase + EP_OFFSET(ulEndpoint) + USB_O_RXCSRL1)) <<
- USB_RX_EPSTATUS_SHIFT);
-
- /* Return the endpoint status. */
- return(ulStatus);
-}
-
-/**
- * Clears the status bits in this endpoint in host mode.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint is the endpoint to access.
- * \param ulFlags are the status bits that will be cleared.
- *
- * This function will clear the status of any bits that are passed in the
- * \e ulFlags parameter. The \e ulFlags parameter can take the value returned
- * from the USBEndpointStatus() call.
- *
- * \note This function should only be called in host mode.
- *
- * \return None.
- */
-void
-USBHostEndpointStatusClear(unsigned int ulBase, unsigned int ulEndpoint,
- unsigned int ulFlags)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
-
- /* Clear the specified flags for the endpoint. */
- if(ulEndpoint == USB_EP_0)
- {
- HWREGB(ulBase + USB_O_CSRL0) &= ~ulFlags;
- }
- else
- {
- HWREGB(ulBase + USB_O_TXCSRL1 + EP_OFFSET(ulEndpoint)) &= ~ulFlags;
- HWREGB(ulBase + USB_O_RXCSRL1 + EP_OFFSET(ulEndpoint)) &=
- ~(ulFlags >> USB_RX_EPSTATUS_SHIFT);
- }
-}
-
-/**
- * Clears the status bits in this endpoint in device mode.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint is the endpoint to access.
- * \param ulFlags are the status bits that will be cleared.
- *
- * This function will clear the status of any bits that are passed in the
- * \e ulFlags parameter. The \e ulFlags parameter can take the value returned
- * from the USBEndpointStatus() call.
- *
- * \note This function should only be called in device mode.
- *
- * \return None.
- */
-void
-USBDevEndpointStatusClear(unsigned int ulBase, unsigned int ulEndpoint,
- unsigned int ulFlags)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
-
- /* If this is endpoint 0 then the bits have different meaning and map into
- * the TX memory location. */
- if(ulEndpoint == USB_EP_0)
- {
- /* Set the Serviced RxPktRdy bit to clear the RxPktRdy. */
- if(ulFlags & USB_DEV_EP0_OUT_PKTRDY)
- {
- HWREGB(ulBase + USB_O_CSRL0) |= USB_CSRL0_RXRDYC;
- }
-
- /* Set the serviced Setup End bit to clear the SetupEnd status. */
- if(ulFlags & USB_DEV_EP0_SETUP_END)
- {
- HWREGB(ulBase + USB_O_CSRL0) |= USB_CSRL0_SETENDC;
- }
-
- /* Clear the Sent Stall status flag. */
- if(ulFlags & USB_DEV_EP0_SENT_STALL)
- {
- HWREGB(ulBase + USB_O_CSRL0) &= ~(USB_DEV_EP0_SENT_STALL);
- }
- }
- else
- {
- /* Clear out any TX flags that were passed in. Only
- * USB_DEV_TX_SENT_STALL and USB_DEV_TX_UNDERRUN should be cleared. */
- HWREGB(ulBase + USB_O_TXCSRL1 + EP_OFFSET(ulEndpoint)) &=
- ~(ulFlags & (USB_DEV_TX_SENT_STALL | USB_DEV_TX_UNDERRUN));
-
- /* Clear out valid RX flags that were passed in. Only
- * USB_DEV_RX_SENT_STALL, USB_DEV_RX_DATA_ERROR, and USB_DEV_RX_OVERRUN
- * should be cleared. */
- HWREGB(ulBase + USB_O_RXCSRL1 + EP_OFFSET(ulEndpoint)) &=
- ~((ulFlags & (USB_DEV_RX_SENT_STALL | USB_DEV_RX_DATA_ERROR |
- USB_DEV_RX_OVERRUN)) >> USB_RX_EPSTATUS_SHIFT);
- }
-}
-
-/**
- * Sets the value data toggle on an endpoint in host mode.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint specifies the endpoint to reset the data toggle.
- * \param bDataToggle specifies whether to set the state to DATA0 or DATA1.
- * \param ulFlags specifies whether to set the IN or OUT endpoint.
- *
- * This function is used to force the state of the data toggle in host mode.
- * If the value passed in the \e bDataToggle parameter is \b false, then the
- * data toggle will be set to the DATA0 state, and if it is \b true it will be
- * set to the DATA1 state. The \e ulFlags parameter can be \b USB_EP_HOST_IN
- * or \b USB_EP_HOST_OUT to access the desired portion of this endpoint. The
- * \e ulFlags parameter is ignored for endpoint zero.
- *
- * \note This function should only be called in host mode.
- *
- * \return None.
- */
-void
-USBHostEndpointDataToggle(unsigned int ulBase, unsigned int ulEndpoint,
- tBoolean bDataToggle, unsigned int ulFlags)
-{
- unsigned int ulDataToggle;
-
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
-
- /* The data toggle defaults to DATA0. */
- ulDataToggle = 0;
-
- /* See if the data toggle should be set to DATA1. */
- if(bDataToggle)
- {
- /* Select the data toggle bit based on the endpoint. */
- if(ulEndpoint == USB_EP_0)
- {
- ulDataToggle = USB_CSRH0_DT;
- }
- else if(ulFlags == USB_EP_HOST_IN)
- {
- ulDataToggle = USB_RXCSRH1_DT;
- }
- else
- {
- ulDataToggle = USB_TXCSRH1_DT;
- }
- }
-
- /* Set the data toggle based on the endpoint. */
- if(ulEndpoint == USB_EP_0)
- {
- /* Set the write enable and the bit value for endpoint zero. */
- HWREGB(ulBase + USB_O_CSRH0) =
- ((HWREGB(ulBase + USB_O_CSRH0) &
- ~(USB_CSRH0_DTWE | USB_CSRH0_DT)) |
- (ulDataToggle | USB_CSRH0_DTWE));
- }
- else if(ulFlags == USB_EP_HOST_IN)
- {
- /* Set the Write enable and the bit value for an IN endpoint. */
- HWREGB(ulBase + USB_O_RXCSRH1 + EP_OFFSET(ulEndpoint)) =
- ((HWREGB(ulBase + USB_O_RXCSRH1 + EP_OFFSET(ulEndpoint)) &
- ~(USB_RXCSRH1_DTWE | USB_RXCSRH1_DT)) |
- (ulDataToggle | USB_RXCSRH1_DTWE));
- }
- else
- {
- /* Set the Write enable and the bit value for an OUT endpoint. */
- HWREGB(ulBase + USB_O_TXCSRH1 + EP_OFFSET(ulEndpoint)) =
- ((HWREGB(ulBase + USB_O_TXCSRH1 + EP_OFFSET(ulEndpoint)) &
- ~(USB_TXCSRH1_DTWE | USB_TXCSRH1_DT)) |
- (ulDataToggle | USB_TXCSRH1_DTWE));
- }
-}
-
-/**
- * Sets the Data toggle on an endpoint to zero.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint specifies the endpoint to reset the data toggle.
- * \param ulFlags specifies whether to access the IN or OUT endpoint.
- *
- * This function will cause the controller to clear the data toggle for an
- * endpoint. This call is not valid for endpoint zero and can be made with
- * host or device controllers.
- *
- * The \e ulFlags parameter should be one of \b USB_EP_HOST_OUT,
- * \b USB_EP_HOST_IN, \b USB_EP_DEV_OUT, or \b USB_EP_DEV_IN.
- *
- * \return None.
- */
-void
-USBEndpointDataToggleClear(unsigned int ulBase, unsigned int ulEndpoint,
- unsigned int ulFlags)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulEndpoint == USB_EP_1) || (ulEndpoint == USB_EP_2) ||
- (ulEndpoint == USB_EP_3) || (ulEndpoint == USB_EP_4) ||
- (ulEndpoint == USB_EP_5) || (ulEndpoint == USB_EP_6) ||
- (ulEndpoint == USB_EP_7) || (ulEndpoint == USB_EP_8) ||
- (ulEndpoint == USB_EP_9) || (ulEndpoint == USB_EP_10) ||
- (ulEndpoint == USB_EP_11) || (ulEndpoint == USB_EP_12) ||
- (ulEndpoint == USB_EP_13) || (ulEndpoint == USB_EP_14) ||
- (ulEndpoint == USB_EP_15));
-
- /* See if the transmit or receive data toggle should be cleared. */
- if(ulFlags & (USB_EP_HOST_OUT | USB_EP_DEV_IN))
- {
- HWREGB(ulBase + USB_O_TXCSRL1 + EP_OFFSET(ulEndpoint)) |=
- USB_TXCSRL1_CLRDT;
- }
- else
- {
- HWREGB(ulBase + USB_O_RXCSRL1 + EP_OFFSET(ulEndpoint)) |=
- USB_RXCSRL1_CLRDT;
- }
-}
-
-/**
- * Stalls the specified endpoint in device mode.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint specifies the endpoint to stall.
- * \param ulFlags specifies whether to stall the IN or OUT endpoint.
- *
- * This function will cause to endpoint number passed in to go into a stall
- * condition. If the \e ulFlags parameter is \b USB_EP_DEV_IN then the stall
- * will be issued on the IN portion of this endpoint. If the \e ulFlags
- * parameter is \b USB_EP_DEV_OUT then the stall will be issued on the OUT
- * portion of this endpoint.
- *
- * \note This function should only be called in device mode.
- *
- * \return None.
- */
-void
-USBDevEndpointStall(unsigned int ulBase, unsigned int ulEndpoint,
- unsigned int ulFlags)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulFlags & ~(USB_EP_DEV_IN | USB_EP_DEV_OUT)) == 0)
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
-
- /* Determine how to stall this endpoint. */
- if(ulEndpoint == USB_EP_0)
- {
- /* Perform a stall on endpoint zero. */
- HWREGB(ulBase + USB_O_CSRL0) |=
- (USB_CSRL0_STALL | USB_CSRL0_RXRDYC);
- }
- else if(ulFlags == USB_EP_DEV_IN)
- {
- /* Perform a stall on an IN endpoint. */
- HWREGB(ulBase + USB_O_TXCSRL1 + EP_OFFSET(ulEndpoint)) |=
- USB_TXCSRL1_STALL;
- }
- else
- {
- /* Perform a stall on an OUT endpoint. */
- HWREGB(ulBase + USB_O_RXCSRL1 + EP_OFFSET(ulEndpoint)) |=
- USB_RXCSRL1_STALL;
- }
-}
-
-/**
- * Clears the stall condition on the specified endpoint in device mode.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint specifies which endpoint to remove the stall condition.
- * \param ulFlags specifies whether to remove the stall condition from the IN
- * or the OUT portion of this endpoint.
- *
- * This function will cause the endpoint number passed in to exit the stall
- * condition. If the \e ulFlags parameter is \b USB_EP_DEV_IN then the stall
- * will be cleared on the IN portion of this endpoint. If the \e ulFlags
- * parameter is \b USB_EP_DEV_OUT then the stall will be cleared on the OUT
- * portion of this endpoint.
- *
- * \note This function should only be called in device mode.
- *
- * \return None.
- */
-void
-USBDevEndpointStallClear(unsigned int ulBase, unsigned int ulEndpoint,
- unsigned int ulFlags)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
- ASSERT((ulFlags & ~(USB_EP_DEV_IN | USB_EP_DEV_OUT)) == 0)
-
- /* Determine how to clear the stall on this endpoint. */
- if(ulEndpoint == USB_EP_0)
- {
- /* Clear the stall on endpoint zero. */
- HWREGB(ulBase + USB_O_CSRL0) &= ~USB_CSRL0_STALLED;
- }
- else if(ulFlags == USB_EP_DEV_IN)
- {
- /* Clear the stall on an IN endpoint. */
- HWREGB(ulBase + USB_O_TXCSRL1 + EP_OFFSET(ulEndpoint)) &=
- ~(USB_TXCSRL1_STALL | USB_TXCSRL1_STALLED);
-
- /* Reset the data toggle. */
- HWREGB(ulBase + USB_O_TXCSRL1 + EP_OFFSET(ulEndpoint)) |=
- USB_TXCSRL1_CLRDT;
- }
- else
- {
- /* Clear the stall on an OUT endpoint. */
- HWREGB(ulBase + USB_O_RXCSRL1 + EP_OFFSET(ulEndpoint)) &=
- ~(USB_RXCSRL1_STALL | USB_RXCSRL1_STALLED);
-
- /* Reset the data toggle. */
- HWREGB(ulBase + USB_O_RXCSRL1 + EP_OFFSET(ulEndpoint)) |=
- USB_RXCSRL1_CLRDT;
- }
-}
-
-/**
- * Connects the USB controller to the bus in device mode.
- *
- * \param ulBase specifies the USB module base address.
- *
- * This function will cause the soft connect feature of the USB controller to
- * be enabled. Call USBDisconnect() to remove the USB device from the bus.
- *
- * \note This function should only be called in device mode.
- *
- * \return None.
- */
-void
-USBDevConnect(unsigned int ulBase)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
-
- /* Enable connection to the USB bus. */
- HWREGB(ulBase + USB_O_POWER) |= USB_POWER_SOFTCONN;
-}
-
-/**
- * Removes the USB controller from the bus in device mode.
- *
- * \param ulBase specifies the USB module base address.
- *
- * This function will cause the soft connect feature of the USB controller to
- * remove the device from the USB bus. A call to USBDevConnect() is needed to
- * reconnect to the bus.
- *
- * \note This function should only be called in device mode.
- *
- * \return None.
- */
-void
-USBDevDisconnect(unsigned int ulBase)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
-
- /* Disable connection to the USB bus. */
- HWREGB(ulBase + USB_O_POWER) &= (~USB_POWER_SOFTCONN);
-}
-
-/**
- * Sets the address in device mode.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulAddress is the address to use for a device.
- *
- * This function will set the device address on the USB bus. This address was
- * likely received via a SET ADDRESS command from the host controller.
- *
- * \note This function should only be called in device mode.
- *
- * \return None.
- */
-void
-USBDevAddrSet(unsigned int ulBase, unsigned int ulAddress)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
-
- /* Set the function address in the correct location. */
- HWREGB(ulBase + USB_O_FADDR) = (unsigned char)ulAddress;
-}
-
-/**
- * Returns the current device address in device mode.
- *
- * \param ulBase specifies the USB module base address.
- *
- * This function will return the current device address. This address was set
- * by a call to USBDevAddrSet().
- *
- * \note This function should only be called in device mode.
- *
- * \return The current device address.
- */
-unsigned int
-USBDevAddrGet(unsigned int ulBase)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
-
- /* Return the function address. */
- return(HWREGB(ulBase + USB_O_FADDR));
-}
-
-/**
- * Sets the base configuration for a host endpoint.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint is the endpoint to access.
- * \param ulMaxPayload is the maximum payload for this endpoint.
- * \param ulNAKPollInterval is the either the NAK timeout limit or the polling
- * interval depending on the type of endpoint.
- * \param ulTargetEndpoint is the endpoint that the host endpoint is
- * targeting.
- * \param ulFlags are used to configure other endpoint settings.
- *
- * This function will set the basic configuration for the transmit or receive
- * portion of an endpoint in host mode. The \e ulFlags parameter determines
- * some of the configuration while the other parameters provide the rest. The
- * \e ulFlags parameter determines whether this is an IN endpoint
- * (USB_EP_HOST_IN or USB_EP_DEV_IN) or an OUT endpoint (USB_EP_HOST_OUT or
- * USB_EP_DEV_OUT), whether this is a Full speed endpoint (USB_EP_SPEED_FULL)
- * or a Low speed endpoint (USB_EP_SPEED_LOW).
- *
- * The \b USB_EP_MODE_ flags control the type of the endpoint.
- * - \b USB_EP_MODE_CTRL is a control endpoint.
- * - \b USB_EP_MODE_ISOC is an isochronous endpoint.
- * - \b USB_EP_MODE_BULK is a bulk endpoint.
- * - \b USB_EP_MODE_INT is an interrupt endpoint.
- *
- * The \e ulNAKPollInterval parameter has different meanings based on the
- * \b USB_EP_MODE value and whether or not this call is being made for
- * endpoint zero or another endpoint. For endpoint zero or any Bulk
- * endpoints, this value always indicates the number of frames to allow a
- * device to NAK before considering it a timeout. If this endpoint is an
- * isochronous or interrupt endpoint, this value is the polling interval for
- * this endpoint.
- *
- * For interrupt endpoints the polling interval is simply the number of
- * frames between polling an interrupt endpoint. For isochronous endpoints
- * this value represents a polling interval of 2 ^ (\e ulNAKPollInterval - 1)
- * frames. When used as a NAK timeout, the \e ulNAKPollInterval value
- * specifies 2 ^ (\e ulNAKPollInterval - 1) frames before issuing a time out.
- * There are two special time out values that can be specified when setting
- * the \e ulNAKPollInterval value. The first is \b MAX_NAK_LIMIT which is the
- * maximum value that can be passed in this variable. The other is
- * \b DISABLE_NAK_LIMIT which indicates that there should be no limit on the
- * number of NAKs.
- *
- * The \b USB_EP_DMA_MODE_ flags enables the type of DMA used to access the
- * endpoint's data FIFOs. The choice of the DMA mode depends on how the DMA
- * controller is configured and how it is being used. See the ``Using USB
- * with the uDMA Controller'' section for more information on DMA
- * configuration.
- *
- * When configuring the OUT portion of an endpoint, the \b USB_EP_AUTO_SET bit
- * is specified to cause the transmission of data on the USB bus to start
- * as soon as the number of bytes specified by \e ulMaxPayload have been
- * written into the OUT FIFO for this endpoint.
- *
- * When configuring the IN portion of an endpoint, the \b USB_EP_AUTO_REQUEST
- * bit can be specified to trigger the request for more data once the FIFO has
- * been drained enough to fit \e ulMaxPayload bytes. The \b USB_EP_AUTO_CLEAR
- * bit can be used to clear the data packet ready flag automatically once the
- * data has been read from the FIFO. If this is not used, this flag must be
- * manually cleared via a call to USBDevEndpointStatusClear() or
- * USBHostEndpointStatusClear().
- *
- * \note This function should only be called in host mode.
- *
- * \return None.
- */
-void
-USBHostEndpointConfig(unsigned int ulBase, unsigned int ulEndpoint,
- unsigned int ulMaxPayload,
- unsigned int ulNAKPollInterval,
- unsigned int ulTargetEndpoint, unsigned int ulFlags)
-{
- unsigned int ulRegister;
-
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
- ASSERT(ulNAKPollInterval <= MAX_NAK_LIMIT);
-
- /* Endpoint zero is configured differently than the other endpoints, so see
- * if this is endpoint zero. */
- if(ulEndpoint == USB_EP_0)
- {
- /* Set the NAK timeout. */
- HWREGB(ulBase + USB_O_NAKLMT) = ulNAKPollInterval;
-
- /* Set the transfer type information. */
- if(ulFlags & USB_EP_SPEED_HIGH)
- {
- HWREGB(ulBase + EP_OFFSET(ulEndpoint) + USB_O_TYPE0) =
- USB_TYPE0_SPEED_HIGH;
- }
- else if(ulFlags & USB_EP_SPEED_FULL)
- {
- HWREGB(ulBase + EP_OFFSET(ulEndpoint) + USB_O_TYPE0) =
- USB_TYPE0_SPEED_FULL;
- }
- else
- {
- HWREGB(ulBase + EP_OFFSET(ulEndpoint) + USB_O_TYPE0) =
- USB_TYPE0_SPEED_LOW;
- }
- }
- else
- {
- /* Start with the target endpoint. */
- ulRegister = ulTargetEndpoint;
-
- /* Set the speed for the device using this endpoint. */
- if(ulFlags & USB_EP_SPEED_HIGH)
- {
- ulRegister |= USB_TXTYPE1_SPEED_HIGH;
- }
- else if(ulFlags & USB_EP_SPEED_FULL)
- {
- ulRegister |= USB_TXTYPE1_SPEED_FULL;
- }
- else
- {
- ulRegister |= USB_TXTYPE1_SPEED_LOW;
- }
-
- /* Set the protocol for the device using this endpoint. */
- switch(ulFlags & USB_EP_MODE_MASK)
- {
- /* The bulk protocol is being used. */
- case USB_EP_MODE_BULK:
- {
- ulRegister |= USB_TXTYPE1_PROTO_BULK;
- break;
- }
-
- /* The isochronous protocol is being used. */
- case USB_EP_MODE_ISOC:
- {
- ulRegister |= USB_TXTYPE1_PROTO_ISOC;
- break;
- }
-
- /* The interrupt protocol is being used. */
- case USB_EP_MODE_INT:
- {
- ulRegister |= USB_TXTYPE1_PROTO_INT;
- break;
- }
-
- /* The control protocol is being used. */
- case USB_EP_MODE_CTRL:
- {
- ulRegister |= USB_TXTYPE1_PROTO_CTRL;
- break;
- }
- }
-
- /* See if the transmit or receive endpoint is being configured. */
- if(ulFlags & USB_EP_HOST_OUT)
- {
- /* Set the transfer type information. */
- HWREGB(ulBase + EP_OFFSET(ulEndpoint) + USB_O_TXTYPE1) =
- ulRegister;
-
- /* Set the NAK timeout or polling interval. */
- HWREGB(ulBase + EP_OFFSET(ulEndpoint) + USB_O_TXINTERVAL1) =
- ulNAKPollInterval;
-
- /* Set the Maximum Payload per transaction. */
- HWREGH(ulBase + EP_OFFSET(ulEndpoint) + USB_O_TXMAXP1) =
- ulMaxPayload;
-
- /* Set the transmit control value to zero. */
- ulRegister = 0;
-
- /* Allow auto setting of TxPktRdy when max packet size has been
- * loaded into the FIFO. */
- if(ulFlags & USB_EP_AUTO_SET)
- {
- ulRegister |= USB_TXCSRH1_AUTOSET;
- }
-
- /* Configure the DMA Mode. */
- //if(ulFlags & USB_EP_DMA_MODE_1)
- if (1)
- {
- //ulRegister |= USB_TXCSRH1_DMAEN | USB_TXCSRH1_DMAMOD;
- ulRegister |= USB_TXCSRH1_DMAMOD;
- }
- else if(ulFlags & USB_EP_DMA_MODE_0)
- {
- ulRegister |= USB_TXCSRH1_DMAEN;
- }
-
- /* Write out the transmit control value. */
- HWREGB(ulBase + EP_OFFSET(ulEndpoint) + USB_O_TXCSRH1) =
- (unsigned char)ulRegister;
-
- }
- else
- {
- /* Set the transfer type information. */
- HWREGB(ulBase + EP_OFFSET(ulEndpoint) + USB_O_RXTYPE1) =
- ulRegister;
-
- /* Set the NAK timeout or polling interval. */
- HWREGB(ulBase + EP_OFFSET(ulEndpoint) + USB_O_RXINTERVAL1) =
- ulNAKPollInterval;
-
- /* Set the receive control value to zero. */
- ulRegister = 0;
-
- /* Allow auto clearing of RxPktRdy when packet of size max packet
- * has been unloaded from the FIFO. */
- if(ulFlags & USB_EP_AUTO_CLEAR)
- {
- ulRegister |= USB_RXCSRH1_AUTOCL;
- }
-
- /* Configure the DMA Mode. */
- if(ulFlags & USB_EP_DMA_MODE_1)
- {
- ulRegister |= USB_RXCSRH1_DMAEN | USB_RXCSRH1_DMAMOD;
- }
- else if(ulFlags & USB_EP_DMA_MODE_0)
- {
- ulRegister |= USB_RXCSRH1_DMAEN;
- }
-
- /* Write out the receive control value. */
- HWREGB(ulBase + EP_OFFSET(ulEndpoint) + USB_O_RXCSRH1) =
- (unsigned char)ulRegister;
-
- }
- }
-}
-
-/**
- * Sets the configuration for an endpoint.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint is the endpoint to access.
- * \param ulMaxPacketSize is the maximum packet size for this endpoint.
- * \param ulFlags are used to configure other endpoint settings.
- *
- * This function will set the basic configuration for an endpoint in device
- * mode. Endpoint zero does not have a dynamic configuration, so this
- * function should not be called for endpoint zero. The \e ulFlags parameter
- * determines some of the configuration while the other parameters provide the
- * rest.
- *
- * The \b USB_EP_MODE_ flags define what the type is for the given endpoint.
- *
- * - \b USB_EP_MODE_CTRL is a control endpoint.
- * - \b USB_EP_MODE_ISOC is an isochronous endpoint.
- * - \b USB_EP_MODE_BULK is a bulk endpoint.
- * - \b USB_EP_MODE_INT is an interrupt endpoint.
- *
- * The \b USB_EP_DMA_MODE_ flags determines the type of DMA access to the
- * endpoint data FIFOs. The choice of the DMA mode depends on how the DMA
- * controller is configured and how it is being used. See the ``Using USB
- * with the uDMA Controller'' section for more information on DMA
- * configuration.
- *
- * When configuring an IN endpoint, the \b USB_EP_AUTO_SET bit can be
- * specified to cause the automatic transmission of data on the USB bus as
- * soon as \e ulMaxPacketSize bytes of data are written into the FIFO for
- * this endpoint. This is commonly used with DMA as no interaction is
- * required to start the transmission of data.
- *
- * When configuring an OUT endpoint, the \b USB_EP_AUTO_REQUEST bit is
- * specified to trigger the request for more data once the FIFO has been
- * drained enough to receive \e ulMaxPacketSize more bytes of data. Also for
- * OUT endpoints, the \b USB_EP_AUTO_CLEAR bit can be used to clear the data
- * packet ready flag automatically once the data has been read from the FIFO.
- * If this is not used, this flag must be manually cleared via a call to
- * USBDevEndpointStatusClear(). Both of these settings can be used to remove
- * the need for extra calls when using the controller in DMA mode.
- *
- * \note This function should only be called in device mode.
- *
- * \return None.
- */
-void
-USBDevEndpointConfigSet(unsigned int ulBase, unsigned int ulEndpoint,
- unsigned int ulMaxPacketSize, unsigned int ulFlags)
-{
- unsigned int ulRegister;
-
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulEndpoint == USB_EP_1) || (ulEndpoint == USB_EP_2) ||
- (ulEndpoint == USB_EP_3) || (ulEndpoint == USB_EP_4) ||
- (ulEndpoint == USB_EP_5) || (ulEndpoint == USB_EP_6) ||
- (ulEndpoint == USB_EP_7) || (ulEndpoint == USB_EP_8) ||
- (ulEndpoint == USB_EP_9) || (ulEndpoint == USB_EP_10) ||
- (ulEndpoint == USB_EP_11) || (ulEndpoint == USB_EP_12) ||
- (ulEndpoint == USB_EP_13) || (ulEndpoint == USB_EP_14) ||
- (ulEndpoint == USB_EP_15));
-
- /* Determine if a transmit or receive endpoint is being configured. */
- if(ulFlags & USB_EP_DEV_IN)
- {
- /* Set the maximum packet size. */
- HWREGH((ulBase + EP_OFFSET(ulEndpoint) + USB_O_TXMAXP1)) =
- ulMaxPacketSize;
-
- /* The transmit control value is zero unless options are enabled. */
- ulRegister = 0;
-
- /* Allow auto setting of TxPktRdy when max packet size has been loaded */
- /* into the FIFO. */
- if(ulFlags & USB_EP_AUTO_SET)
- {
- ulRegister |= USB_TXCSRH1_AUTOSET;
- }
-
- /* Configure the DMA mode. */
- if(ulFlags & USB_EP_DMA_MODE_1)
- {
- ulRegister |= USB_TXCSRH1_DMAEN | USB_TXCSRH1_DMAMOD;
- }
- else if(ulFlags & USB_EP_DMA_MODE_0)
- {
- ulRegister |= USB_TXCSRH1_DMAEN;
- }
-
- /* Enable isochronous mode if requested. */
- if((ulFlags & USB_EP_MODE_MASK) == USB_EP_MODE_ISOC)
- {
- ulRegister |= USB_TXCSRH1_ISO;
- }
-
- /* Write the transmit control value. */
- HWREGB(ulBase + EP_OFFSET(ulEndpoint) + USB_O_TXCSRH1) =
- (unsigned char)ulRegister;
-
- /* Reset the Data toggle to zero. */
- HWREGB(ulBase + EP_OFFSET(ulEndpoint) + USB_O_TXCSRL1) =
- USB_TXCSRL1_CLRDT;
- }
- else
- {
- /* Set the MaxPacketSize. */
- HWREGH((ulBase + EP_OFFSET(ulEndpoint) + USB_O_RXMAXP1)) =
- ulMaxPacketSize;
-
- /* The receive control value is zero unless options are enabled. */
- ulRegister = 0;
-
- /* Allow auto clearing of RxPktRdy when packet of size max packet
- * has been unloaded from the FIFO. */
- if(ulFlags & USB_EP_AUTO_CLEAR)
- {
- ulRegister = USB_RXCSRH1_AUTOCL;
- }
-
- /* Configure the DMA mode. */
- if(ulFlags & USB_EP_DMA_MODE_1)
- {
- ulRegister |= USB_RXCSRH1_DMAEN | USB_RXCSRH1_DMAMOD;
- }
- else if(ulFlags & USB_EP_DMA_MODE_0)
- {
- ulRegister |= USB_RXCSRH1_DMAEN;
- }
-
- /* Enable isochronous mode if requested. */
- if((ulFlags & USB_EP_MODE_MASK) == USB_EP_MODE_ISOC)
- {
- ulRegister |= USB_RXCSRH1_ISO;
- }
-
- /* Write the receive control value. */
- HWREGB(ulBase + EP_OFFSET(ulEndpoint) + USB_O_RXCSRH1) =
- (unsigned char)ulRegister;
-
- /* Reset the Data toggle to zero. */
- HWREGB(ulBase + EP_OFFSET(ulEndpoint) + USB_O_RXCSRL1) =
- USB_RXCSRL1_CLRDT;
- }
-}
-
-/**
- * Gets the current configuration for an endpoint.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint is the endpoint to access.
- * \param pulMaxPacketSize is a pointer which will be written with the
- * maximum packet size for this endpoint.
- * \param pulFlags is a pointer which will be written with the current
- * endpoint settings. On entry to the function, this pointer must contain
- * either \b USB_EP_DEV_IN or \b USB_EP_DEV_OUT to indicate whether the IN or
- * OUT endpoint is to be queried.
- *
- * This function will return the basic configuration for an endpoint in device
- * mode. The values returned in \e *pulMaxPacketSize and \e *pulFlags are
- * equivalent to the \e ulMaxPacketSize and \e ulFlags previously passed to
- * USBDevEndpointConfigSet() for this endpoint.
- *
- * \note This function should only be called in device mode.
- *
- * \return None.
- */
-void
-USBDevEndpointConfigGet(unsigned int ulBase, unsigned int ulEndpoint,
- unsigned int *pulMaxPacketSize,
- unsigned int *pulFlags)
-{
- unsigned int ulRegister;
-
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT(pulMaxPacketSize && pulFlags);
- ASSERT((ulEndpoint == USB_EP_1) || (ulEndpoint == USB_EP_2) ||
- (ulEndpoint == USB_EP_3) || (ulEndpoint == USB_EP_4) ||
- (ulEndpoint == USB_EP_5) || (ulEndpoint == USB_EP_6) ||
- (ulEndpoint == USB_EP_7) || (ulEndpoint == USB_EP_8) ||
- (ulEndpoint == USB_EP_9) || (ulEndpoint == USB_EP_10) ||
- (ulEndpoint == USB_EP_11) || (ulEndpoint == USB_EP_12) ||
- (ulEndpoint == USB_EP_13) || (ulEndpoint == USB_EP_14) ||
- (ulEndpoint == USB_EP_15));
-
- /* Determine if a transmit or receive endpoint is being queried. */
- if(*pulFlags & USB_EP_DEV_IN)
- {
- /* Clear the flags other than the direction bit. */
- *pulFlags = USB_EP_DEV_IN;
-
- /* Get the maximum packet size. */
- *pulMaxPacketSize = (unsigned int)HWREGH(ulBase +
- EP_OFFSET(ulEndpoint) +
- USB_O_TXMAXP1);
-
- /* Get the current transmit control register value. */
- ulRegister = (unsigned int)HWREGB(ulBase + EP_OFFSET(ulEndpoint) +
- USB_O_TXCSRH1);
-
- /* Are we allowing auto setting of TxPktRdy when max packet size has
- * been loaded into the FIFO? */
- if(ulRegister & USB_TXCSRH1_AUTOSET)
- {
- *pulFlags |= USB_EP_AUTO_SET;
- }
-
- /* Get the DMA mode. */
- if(ulRegister & USB_TXCSRH1_DMAEN)
- {
- if(ulRegister & USB_TXCSRH1_DMAMOD)
- {
- *pulFlags |= USB_EP_DMA_MODE_1;
- }
- else
- {
- *pulFlags |= USB_EP_DMA_MODE_0;
- }
- }
-
- /* Are we in isochronous mode? */
- if(ulRegister & USB_TXCSRH1_ISO)
- {
- *pulFlags |= USB_EP_MODE_ISOC;
- }
- else
- {
- /* The hardware doesn't differentiate between bulk, interrupt
- * and control mode for the endpoint so we just set something
- * that isn't isochronous. This ensures that anyone modifying
- * the returned flags in preparation for a call to
- * USBDevEndpointConfigSet will not see an unexpected mode change.
- * If they decode the returned mode, however, they may be in for
- * a surprise. */
- *pulFlags |= USB_EP_MODE_BULK;
- }
- }
- else
- {
- /* Clear the flags other than the direction bit. */
- *pulFlags = USB_EP_DEV_OUT;
-
- /* Get the MaxPacketSize. */
- *pulMaxPacketSize = (unsigned int)HWREGH(ulBase +
- EP_OFFSET(ulEndpoint) +
- USB_O_RXMAXP1);
-
- /* Get the current receive control register value. */
- ulRegister = (unsigned int)HWREGB(ulBase + EP_OFFSET(ulEndpoint) +
- USB_O_RXCSRH1);
-
- /* Are we allowing auto clearing of RxPktRdy when packet of size max
- * packet has been unloaded from the FIFO? */
- if(ulRegister & USB_RXCSRH1_AUTOCL)
- {
- *pulFlags |= USB_EP_AUTO_CLEAR;
- }
-
- /* Get the DMA mode. */
- if(ulRegister & USB_RXCSRH1_DMAEN)
- {
- if(ulRegister & USB_RXCSRH1_DMAMOD)
- {
- *pulFlags |= USB_EP_DMA_MODE_1;
- }
- else
- {
- *pulFlags |= USB_EP_DMA_MODE_0;
- }
- }
-
- /* Are we in isochronous mode? */
- if(ulRegister & USB_RXCSRH1_ISO)
- {
- *pulFlags |= USB_EP_MODE_ISOC;
- }
- else
- {
- /* The hardware doesn't differentiate between bulk, interrupt
- * and control mode for the endpoint so we just set something
- * that isn't isochronous. This ensures that anyone modifying
- * the returned flags in preparation for a call to
- * USBDevEndpointConfigSet will not see an unexpected mode change.
- * If they decode the returned mode, however, they may be in for
- * a surprise. */
- *pulFlags |= USB_EP_MODE_BULK;
- }
- }
-}
-
-/**
- * Sets the FIFO configuration for an endpoint.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint is the endpoint to access.
- * \param ulFIFOAddress is the starting address for the FIFO.
- * \param ulFIFOSize is the size of the FIFO in bytes.
- * \param ulFlags specifies what information to set in the FIFO configuration.
- *
- * This function will set the starting FIFO RAM address and size of the FIFO
- * for a given endpoint. Endpoint zero does not have a dynamically
- * configurable FIFO so this function should not be called for endpoint zero.
- * The \e ulFIFOSize parameter should be one of the values in the
- * \b USB_FIFO_SZ_ values. If the endpoint is going to use double buffering
- * it should use the values with the \b _DB at the end of the value. For
- * example, use \b USB_FIFO_SZ_16_DB to configure an endpoint to have a 16
- * byte double buffered FIFO. If a double buffered FIFO is used, then the
- * actual size of the FIFO will be twice the size indicated by the
- * \e ulFIFOSize parameter. This means that the \b USB_FIFO_SZ_16_DB value
- * will use 32 bytes of the USB controller's FIFO memory.
- *
- * The \e ulFIFOAddress value should be a multiple of 8 bytes and directly
- * indicates the starting address in the USB controller's FIFO RAM. For
- * example, a value of 64 indicates that the FIFO should start 64 bytes into
- * the USB controller's FIFO memory. The \e ulFlags value specifies whether
- * the endpoint's OUT or IN FIFO should be configured. If in host mode, use
- * \b USB_EP_HOST_OUT or \b USB_EP_HOST_IN, and if in device mode use
- * \b USB_EP_DEV_OUT or \b USB_EP_DEV_IN.
- *
- * \return None.
- */
-void
-USBFIFOConfigSet(unsigned int ulBase, unsigned int ulEndpoint,
- unsigned int ulFIFOAddress, unsigned int ulFIFOSize,
- unsigned int ulFlags)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulEndpoint == USB_EP_1) || (ulEndpoint == USB_EP_2) ||
- (ulEndpoint == USB_EP_3) || (ulEndpoint == USB_EP_4) ||
- (ulEndpoint == USB_EP_5) || (ulEndpoint == USB_EP_6) ||
- (ulEndpoint == USB_EP_7) || (ulEndpoint == USB_EP_8) ||
- (ulEndpoint == USB_EP_9) || (ulEndpoint == USB_EP_10) ||
- (ulEndpoint == USB_EP_11) || (ulEndpoint == USB_EP_12) ||
- (ulEndpoint == USB_EP_13) || (ulEndpoint == USB_EP_14) ||
- (ulEndpoint == USB_EP_15));
-
- /* See if the transmit or receive FIFO is being configured. */
- if(ulFlags & (USB_EP_HOST_OUT | USB_EP_DEV_IN))
- {
- /* Set the transmit FIFO location and size for this endpoint. */
- USBIndexWrite(ulBase, ulEndpoint >> 4, USB_O_TXFIFOSZ, ulFIFOSize, 1);
- USBIndexWrite(ulBase, ulEndpoint >> 4, USB_O_TXFIFOADD,
- ulFIFOAddress >> 3, 2);
- }
- else
- {
- /* Set the receive FIFO location and size for this endpoint. */
- USBIndexWrite(ulBase, ulEndpoint >> 4, USB_O_RXFIFOSZ, ulFIFOSize, 1);
- USBIndexWrite(ulBase, ulEndpoint >> 4, USB_O_RXFIFOADD,
- ulFIFOAddress >> 3, 2);
- }
-}
-
-/**
- * Returns the FIFO configuration for an endpoint.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint is the endpoint to access.
- * \param pulFIFOAddress is the starting address for the FIFO.
- * \param pulFIFOSize is the size of the FIFO in bytes.
- * \param ulFlags specifies what information to retrieve from the FIFO
- * configuration.
- *
- * This function will return the starting address and size of the FIFO for a
- * given endpoint. Endpoint zero does not have a dynamically configurable
- * FIFO so this function should not be called for endpoint zero. The
- * \e ulFlags parameter specifies whether the endpoint's OUT or IN FIFO should
- * be read. If in host mode, the \e ulFlags parameter should be
- * \b USB_EP_HOST_OUT or \b USB_EP_HOST_IN, and if in device mode the
- * \e ulFlags parameter should be either \b USB_EP_DEV_OUT or
- * \b USB_EP_DEV_IN.
- *
- * \return None.
- */
-void
-USBFIFOConfigGet(unsigned int ulBase, unsigned int ulEndpoint,
- unsigned int *pulFIFOAddress, unsigned int *pulFIFOSize,
- unsigned int ulFlags)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulEndpoint == USB_EP_1) || (ulEndpoint == USB_EP_2) ||
- (ulEndpoint == USB_EP_3) || (ulEndpoint == USB_EP_4) ||
- (ulEndpoint == USB_EP_5) || (ulEndpoint == USB_EP_6) ||
- (ulEndpoint == USB_EP_7) || (ulEndpoint == USB_EP_8) ||
- (ulEndpoint == USB_EP_9) || (ulEndpoint == USB_EP_10) ||
- (ulEndpoint == USB_EP_11) || (ulEndpoint == USB_EP_12) ||
- (ulEndpoint == USB_EP_13) || (ulEndpoint == USB_EP_14) ||
- (ulEndpoint == USB_EP_15));
-
- /* See if the transmit or receive FIFO is being configured. */
- if(ulFlags & (USB_EP_HOST_OUT | USB_EP_DEV_IN))
- {
- /* Get the transmit FIFO location and size for this endpoint. */
- *pulFIFOAddress = (USBIndexRead(ulBase, ulEndpoint >> 4,
- (unsigned int)USB_O_TXFIFOADD,
- 2)) << 3;
- *pulFIFOSize = USBIndexRead(ulBase, ulEndpoint >> 4,
- (unsigned int)USB_O_TXFIFOSZ, 1);
-
- }
- else
- {
- /* Get the receive FIFO location and size for this endpoint. */
- *pulFIFOAddress = (USBIndexRead(ulBase, ulEndpoint >> 4,
- (unsigned int)USB_O_RXFIFOADD,
- 2)) << 3;
- *pulFIFOSize = USBIndexRead(ulBase, ulEndpoint >> 4,
- (unsigned int)USB_O_RXFIFOSZ, 1);
- }
-}
-
-/**
- * Enable DMA on a given endpoint.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint is the endpoint to access.
- * \param ulFlags specifies which direction and what mode to use when enabling
- * DMA.
- *
- * This function will enable DMA on a given endpoint and set the mode according
- * to the values in the \e ulFlags parameter. The \e ulFlags parameter should
- * have \b USB_EP_DEV_IN or \b USB_EP_DEV_OUT set.
- *
- * \return None.
- */
-void
-USBEndpointDMAEnable(unsigned int ulBase, unsigned int ulEndpoint,
- unsigned int ulFlags)
-{
- /* See if the transmit DMA is being enabled. */
- if(ulFlags & USB_EP_DEV_IN)
- {
- /* Enable DMA on the transmit end point. */
- HWREGB(ulBase + EP_OFFSET(ulEndpoint) + USB_O_TXCSRH1) |=
- USB_TXCSRH1_DMAEN;
- }
- else
- {
- /* Enable DMA on the receive end point. */
- HWREGB(ulBase + EP_OFFSET(ulEndpoint) + USB_O_RXCSRH1) |=
- USB_RXCSRH1_DMAEN;
- }
-}
-
-/**
- * Disable DMA on a given endpoint.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint is the endpoint to access.
- * \param ulFlags specifies which direction to disable.
- *
- * This function will disable DMA on a given end point to allow non-DMA
- * USB transactions to generate interrupts normally. The ulFlags should be
- * \b USB_EP_DEV_IN or \b USB_EP_DEV_OUT all other bits are ignored.
- *
- * \return None.
- */
-void
-USBEndpointDMADisable(unsigned int ulBase, unsigned int ulEndpoint,
- unsigned int ulFlags)
-{
- /* If this was a request to disable DMA on the IN portion of the end point */
- /* then handle it. */
- if(ulFlags & USB_EP_DEV_IN)
- {
- /* Just disable DMA leave the mode setting. */
- HWREGB(ulBase + EP_OFFSET(ulEndpoint) + USB_O_TXCSRH1) &=
- ~USB_TXCSRH1_DMAEN;
- }
- else
- {
- /* Just disable DMA leave the mode setting. */
- HWREGB(ulBase + EP_OFFSET(ulEndpoint) + USB_O_RXCSRH1) &=
- ~USB_RXCSRH1_DMAEN;
- }
-}
-
-/**
- * Determine the number of bytes of data available in a given endpoint's FIFO.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint is the endpoint to access.
- *
- * This function will return the number of bytes of data currently available
- * in the FIFO for the given receive (OUT) endpoint. It may be used prior to
- * calling USBEndpointDataGet() to determine the size of buffer required to
- * hold the newly-received packet.
- *
- * \return This call will return the number of bytes available in a given
- * endpoint FIFO.
- */
-unsigned int
-USBEndpointDataAvail(unsigned int ulBase, unsigned int ulEndpoint)
-{
- unsigned int ulRegister;
-
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
-
- /* Get the address of the receive status register to use, based on the
- * endpoint. */
- if(ulEndpoint == USB_EP_0)
- {
- ulRegister = USB_O_CSRL0;
- }
- else
- {
- ulRegister = USB_O_RXCSRL1 + EP_OFFSET(ulEndpoint);
- }
-
- /* Is there a packet ready in the FIFO? */
- if((HWREGH(ulBase + ulRegister) & USB_CSRL0_RXRDY) == 0)
- {
- return(0);
- }
-
- /* Return the byte count in the FIFO. */
- return(HWREGH(ulBase + USB_O_COUNT0 + ulEndpoint));
-}
-
-/**
- * Retrieves data from the given endpoint's FIFO.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint is the endpoint to access.
- * \param pucData is a pointer to the data area used to return the data from
- * the FIFO.
- * \param pulSize is initially the size of the buffer passed into this call
- * via the \e pucData parameter. It will be set to the amount of data
- * returned in the buffer.
- *
- * This function will return the data from the FIFO for the given endpoint.
- * The \e pulSize parameter should indicate the size of the buffer passed in
- * the \e pulData parameter. The data in the \e pulSize parameter will be
- * changed to match the amount of data returned in the \e pucData parameter.
- * If a zero byte packet was received this call will not return a error but
- * will instead just return a zero in the \e pulSize parameter. The only
- * error case occurs when there is no data packet available.
- *
- * \return This call will return 0, or -1 if no packet was received.
- */
-int
-USBEndpointDataGet(unsigned int ulBase, unsigned int ulEndpoint,
- unsigned char *pucData, unsigned int *pulSize)
-{
- unsigned int ulRegister, ulByteCount, ulFIFO;
-
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
-
- /* Get the address of the receive status register to use, based on the
- * endpoint. */
- if(ulEndpoint == USB_EP_0)
- {
- ulRegister = USB_O_CSRL0;
- }
- else
- {
- ulRegister = USB_O_RXCSRL1 + EP_OFFSET(ulEndpoint);
- }
-
- /* Don't allow reading of data if the RxPktRdy bit is not set. */
- if((HWREGH(ulBase + ulRegister) & USB_CSRL0_RXRDY) == 0)
- {
- /* Can't read the data because none is available. */
- *pulSize = 0;
-
- /* Return a failure since there is no data to read. */
- return(-1);
- }
-
- /* Get the byte count in the FIFO. */
- ulByteCount = HWREGH(ulBase + USB_O_COUNT0 + ulEndpoint);
-
- /* Determine how many bytes we will actually copy. */
- ulByteCount = (ulByteCount < *pulSize) ? ulByteCount : *pulSize;
-
- /* Return the number of bytes we are going to read. */
- *pulSize = ulByteCount;
-
- /* Calculate the FIFO address. */
- ulFIFO = ulBase + USB_O_FIFO0 + (ulEndpoint >> 2);
-
- /* Read the data out of the FIFO. */
- for(; ulByteCount > 0; ulByteCount--)
- {
- /* Read a byte at a time from the FIFO. */
- *pucData++ = HWREGB(ulFIFO);
- }
-
- /* Success. */
- return(0);
-}
-
-/**
- * Acknowledge that data was read from the given endpoint's FIFO in device
- * mode.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint is the endpoint to access.
- * \param bIsLastPacket indicates if this is the last packet.
- *
- * This function acknowledges that the data was read from the endpoint's FIFO.
- * The \e bIsLastPacket parameter is set to a \b true value if this is the
- * last in a series of data packets on endpoint zero. The \e bIsLastPacket
- * parameter is not used for endpoints other than endpoint zero. This call
- * can be used if processing is required between reading the data and
- * acknowledging that the data has been read.
- *
- * \note This function should only be called in device mode.
- *
- * \return None.
- */
-void
-USBDevEndpointDataAck(unsigned int ulBase, unsigned int ulEndpoint,
- tBoolean bIsLastPacket)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
-
- /* Determine which endpoint is being acked. */
- if(ulEndpoint == USB_EP_0)
- {
- /* Clear RxPktRdy, and optionally DataEnd, on endpoint zero. */
- HWREGB(ulBase + USB_O_CSRL0) =
- USB_CSRL0_RXRDYC | (bIsLastPacket ? USB_CSRL0_DATAEND : 0);
- }
- else
- {
- /* Clear RxPktRdy on all other endpoints. */
- HWREGB(ulBase + USB_O_RXCSRL1 + EP_OFFSET(ulEndpoint)) &=
- ~(USB_RXCSRL1_RXRDY);
- }
-}
-
-/**
- * Acknowledge that data was read from the given endpoint's FIFO in host
- * mode.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint is the endpoint to access.
- *
- * This function acknowledges that the data was read from the endpoint's FIFO.
- * This call is used if processing is required between reading the data and
- * acknowledging that the data has been read.
- *
- * \note This function should only be called in host mode.
- *
- * \return None.
- */
-void
-USBHostEndpointDataAck(unsigned int ulBase, unsigned int ulEndpoint)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
-
- /* Clear RxPktRdy. */
- if(ulEndpoint == USB_EP_0)
- {
- HWREGB(ulBase + USB_O_CSRL0) &= ~USB_CSRL0_RXRDY;
- }
- else
- {
- HWREGB(ulBase + USB_O_RXCSRL1 + EP_OFFSET(ulEndpoint)) &=
- ~(USB_RXCSRL1_RXRDY);
- }
-}
-
-/**
- * Puts data into the given endpoint's FIFO.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint is the endpoint to access.
- * \param pucData is a pointer to the data area used as the source for the
- * data to put into the FIFO.
- * \param ulSize is the amount of data to put into the FIFO.
- *
- * This function will put the data from the \e pucData parameter into the FIFO
- * for this endpoint. If a packet is already pending for transmission then
- * this call will not put any of the data into the FIFO and will return -1.
- * Care should be taken to not write more data than can fit into the FIFO
- * allocated by the call to USBFIFOConfig().
- *
- * \return This call will return 0 on success, or -1 to indicate that the FIFO
- * is in use and cannot be written.
- */
-int
-USBEndpointDataPut(unsigned int ulBase, unsigned int ulEndpoint,
- unsigned char *pucData, unsigned int ulSize)
-{
- unsigned int ulFIFO;
- unsigned char ucTxPktRdy;
-
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
-
- /* Get the bit position of TxPktRdy based on the endpoint. */
- if(ulEndpoint == USB_EP_0)
- {
- ucTxPktRdy = USB_CSRL0_TXRDY;
- }
- else
- {
- ucTxPktRdy = USB_TXCSRL1_TXRDY;
- }
-
- /* Don't allow transmit of data if the TxPktRdy bit is already set. */
- if(HWREGB(ulBase + USB_O_CSRL0 + ulEndpoint) & ucTxPktRdy)
- {
- return(-1);
- }
-
- /* Calculate the FIFO address. */
- ulFIFO = ulBase + USB_O_FIFO0 + (ulEndpoint >> 2);
-
- /* Write the data to the FIFO. */
- for(; ulSize > 0; ulSize--)
- {
- HWREGB(ulFIFO) = *pucData++;
- }
-
- /* Success. */
- return(0);
-}
-
-/**
- * Starts the transfer of data from an endpoint's FIFO.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint is the endpoint to access.
- * \param ulTransType is set to indicate what type of data is being sent.
- *
- * This function will start the transfer of data from the FIFO for a given
- * endpoint. This is necessary if the \b USB_EP_AUTO_SET bit was not enabled
- * for the endpoint. Setting the \e ulTransType parameter will allow the
- * appropriate signaling on the USB bus for the type of transaction being
- * requested. The \e ulTransType parameter should be one of the following:
- *
- * - USB_TRANS_OUT for OUT transaction on any endpoint in host mode.
- * - USB_TRANS_IN for IN transaction on any endpoint in device mode.
- * - USB_TRANS_IN_LAST for the last IN transactions on endpoint zero in a
- * sequence of IN transactions.
- * - USB_TRANS_SETUP for setup transactions on endpoint zero.
- * - USB_TRANS_STATUS for status results on endpoint zero.
- *
- * \return This call will return 0 on success, or -1 if a transmission is
- * already in progress.
- */
-int
-USBEndpointDataSend(unsigned int ulBase, unsigned int ulEndpoint,
- unsigned int ulTransType)
-{
- unsigned int ulTxPktRdy;
-
- /* CHeck the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
-
- /* Get the bit position of TxPktRdy based on the endpoint. */
- if(ulEndpoint == USB_EP_0)
- {
- ulTxPktRdy = ulTransType & 0xff;
- }
- else
- {
- ulTxPktRdy = (ulTransType >> 8) & 0xff;
- }
-
- /* Don't allow transmit of data if the TxPktRdy bit is already set. */
- if(HWREGB(ulBase + USB_O_CSRL0 + ulEndpoint) & USB_CSRL0_TXRDY)
- {
- return(-1);
- }
-
- /* Set TxPktRdy in order to send the data. */
- HWREGB(ulBase + USB_O_CSRL0 + ulEndpoint) = ulTxPktRdy;
-
- /* Success. */
- return(0);
-}
-
-/**
- * Forces a flush of an endpoint's FIFO.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint is the endpoint to access.
- * \param ulFlags specifies if the IN or OUT endpoint should be accessed.
- *
- * This function will force the controller to flush out the data in the FIFO.
- * The function can be called with either host or device controllers and
- * requires the \e ulFlags parameter be one of \b USB_EP_HOST_OUT,
- * \b USB_EP_HOST_IN, \b USB_EP_DEV_OUT, or \b USB_EP_DEV_IN.
- *
- * \return None.
- */
-void
-USBFIFOFlush(unsigned int ulBase, unsigned int ulEndpoint,
- unsigned int ulFlags)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
-
- /* Endpoint zero has a different register set for FIFO flushing. */
- if(ulEndpoint == USB_EP_0)
- {
- /* Nothing in the FIFO if neither of these bits are set. */
- if((HWREGB(ulBase + USB_O_CSRL0) &
- (USB_CSRL0_RXRDY | USB_CSRL0_TXRDY)) != 0)
- {
- /* Hit the Flush FIFO bit. */
- HWREGB(ulBase + USB_O_CSRH0) = USB_CSRH0_FLUSH;
- }
- }
- else
- {
- /* Only reset the IN or OUT FIFO. */
- if(ulFlags & (USB_EP_HOST_OUT | USB_EP_DEV_IN))
- {
- /* Make sure the FIFO is not empty. */
- if(HWREGB(ulBase + USB_O_TXCSRL1 + EP_OFFSET(ulEndpoint)) &
- USB_TXCSRL1_TXRDY)
- {
- /* Hit the Flush FIFO bit. */
- HWREGB(ulBase + USB_O_TXCSRL1 + EP_OFFSET(ulEndpoint)) |=
- USB_TXCSRL1_FLUSH;
- }
- }
- else
- {
- /* Make sure that the FIFO is not empty. */
- if(HWREGB(ulBase + USB_O_RXCSRL1 + EP_OFFSET(ulEndpoint)) &
- USB_RXCSRL1_RXRDY)
- {
- /* Hit the Flush FIFO bit. */
- HWREGB(ulBase + USB_O_RXCSRL1 + EP_OFFSET(ulEndpoint)) |=
- USB_RXCSRL1_FLUSH;
- }
- }
- }
-}
-
-/**
- * Schedules a request for an IN transaction on an endpoint in host mode.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint is the endpoint to access.
- *
- * This function will schedule a request for an IN transaction. When the USB
- * device being communicated with responds the data, the data can be retrieved
- * by calling USBEndpointDataGet() or via a DMA transfer.
- *
- * \note This function should only be called in host mode.
- *
- * \return None.
- */
-void
-USBHostRequestIN(unsigned int ulBase, unsigned int ulEndpoint)
-{
- unsigned int ulRegister;
-
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
-
- /* Endpoint zero uses a different offset than the other endpoints. */
- if(ulEndpoint == USB_EP_0)
- {
- ulRegister = USB_O_CSRL0;
- }
- else
- {
- ulRegister = USB_O_RXCSRL1 + EP_OFFSET(ulEndpoint);
- }
-
- /* Set the request for an IN transaction. */
- HWREGB(ulBase + ulRegister) = USB_RXCSRL1_REQPKT;
-}
-
-/**
- * Stop any request for an IN transaction on an endpoint in host mode.
- * This is used to stop further requests during teardown process.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint is the endpoint to access.
- *
- * This function will stop further requests for an IN transaction. When the USB
- * device being communicated with responds the data, the data can be retrieved
- * by calling USBEndpointDataGet() or via a DMA transfer.
- *
- * \note This function should only be called in host mode.
- *
- * \return None.
- */
-void
-USBHostRequestINClear(unsigned int ulBase, unsigned int ulEndpoint)
-{
- unsigned int ulRegister;
-
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
-
- /* Endpoint zero uses a different offset than the other endpoints. */
- if(ulEndpoint == USB_EP_0)
- {
- ulRegister = USB_O_CSRL0;
- }
- else
- {
- ulRegister = USB_O_RXCSRL1 + EP_OFFSET(ulEndpoint);
- }
-
- /* Clear the request for an IN transaction. */
- HWREGB(ulBase + ulRegister) &= ~USB_RXCSRL1_REQPKT;
-}
-
-/**
- * Autorequest for packet when FIFOs are empty.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint is the endpoint to access.
- *
- * This function will set autoreq bit, which when set, will autorequest
- * for packet when FIFOs are empty.
- *
- * \note This function should only be called in host mode.
- *
- * \return None.
- */
-void
-USBHostAutoReqSet(unsigned int ulBase, unsigned int ulEndpoint)
-{
- unsigned int ulRegister;
-
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
-
- /* Endpoint zero uses a different offset than the other endpoints. */
- if(ulEndpoint == USB_EP_0)
- {
- ulRegister = USB_O_CSRH0;
- }
- else
- {
- ulRegister = USB_O_RXCSRH1 + EP_OFFSET(ulEndpoint);
- }
-
- /* Clear the request for an IN transaction. */
- HWREGB(ulBase + ulRegister) |= USB_RXCSRH1_AUTORQ;
-}
-
-/**
- * Donot autorequest for packet when FIFOs are empty.
- * This is used to stop further requests during teardown process.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint is the endpoint to access.
- *
- * This function will clear autoreq bit, which when set, will autorequest
- * for packet when FIFOs are empty.
- *
- * \note This function should only be called in host mode.
- *
- * \return None.
- */
-void
-USBHostAutoReqClear(unsigned int ulBase, unsigned int ulEndpoint)
-{
- unsigned int ulRegister;
-
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
-
- /* Endpoint zero uses a different offset than the other endpoints. */
- if(ulEndpoint == USB_EP_0)
- {
- ulRegister = USB_O_CSRH0;
- }
- else
- {
- ulRegister = USB_O_RXCSRH1 + EP_OFFSET(ulEndpoint);
- }
-
- /* Clear the request for an IN transaction. */
- HWREGB(ulBase + ulRegister) &= ~USB_RXCSRH1_AUTORQ;
-}
-#ifdef DMA_MODE
-/**
- *
- * This is used to stop further requests during teardown process.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint is the endpoint to access.
- *
- * This function will clear autoreq bit, which when set, will autorequest
- * for packet when FIFOs are empty.
- *
- * \note This function can be called in host oe device mode.
- *
- * \return None.
- */
-void
-USBRxChAbort(unsigned int ulBase, unsigned int ulEndpoint)
-{
- unsigned int ulRegister;
- short rx_csr = 0x00;
-
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
-
- /* Disable REQPKT and DMAEN in RxCSR */
- ulRegister = USB_O_RXCSRL1 + EP_OFFSET(ulEndpoint);
- rx_csr = HWREGH(ulBase + ulRegister);
- if (1) // if host mode -
- {
- rx_csr &= (~MUSB_RXCSR_H_REQPKT);
- }
- rx_csr &= (~MUSB_RXCSR_DMAENAB);
- HWREGH(ulBase + ulRegister) = rx_csr;
- /* 250 microsecond delay needed - we dont have that granularity*/
- delay(1);
- /* Flush FIFO of the endpoint */
- rx_csr = HWREGH(ulBase + ulRegister);
-
- if (rx_csr & MUSB_RXCSR_RXPKTRDY)
- {
- rx_csr |= MUSB_RXCSR_FLUSHFIFO;
- }
-
- /* */
- rx_csr |= MUSB_RXCSR_H_WZC_BITS;
- /* Flush the FIFO twice - incase it is Double buffered*/
- HWREGH(ulBase + ulRegister) = rx_csr;
- HWREGH(ulBase + ulRegister) = rx_csr;
-
- if (ulBase == USB0_BASE)
- {
- ulBase = USB_0_OTGBASE;
- }
- else
- {
- ulBase = USB_1_OTGBASE;
- }
- /* Initiate CPPI RX FIFO teardown in USBnTDOWN - module register */
- HWREG(ulBase + USB_0_TEARDOWN) =
- USB_RX_TDOWN_MASK(USB_EP_TO_INDEX(ulEndpoint));
- /* CPPI 4.1 tear down actions - CPPI registers*/
-
-}
-
-/**
- *
- * This function is used to disable the DMA channel.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint is the endpoint to access.
- *
- *
- *
- *
- * \note This function can be called in host or device mode.
- *
- * \return None.
- */
-void
-USBDmaTxChDisable(unsigned int ulBase, unsigned int ulEndpoint)
-{
- unsigned int ulRegister;
- short tx_csr = 0x00;
-
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
-
- /* Disable DMAEN in TxCSR */
- ulRegister = USB_O_TXCSRL1 + EP_OFFSET(ulEndpoint);
- tx_csr = HWREGH(ulBase + ulRegister);
- tx_csr &= ~MUSB_TXCSR_DMAENAB;
- HWREGH(ulBase + ulRegister) = tx_csr;
-
-}
-
-/**
- *
- * This function is used to disable the DMA channel.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint is the endpoint to access.
- *
- *
- *
- *
- * \note This function can be called in host or device mode.
- *
- * \return None.
- */
-void
-USBDmaTxChTeardown(unsigned int ulBase, unsigned int ulEndpoint)
-{
-
- unsigned int ulRegister;
- short tx_csr = 0x00;
-
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
-
- ulRegister = USB_O_TXCSRL1 + EP_OFFSET(ulEndpoint);
- tx_csr = HWREGH(ulBase + ulRegister);
- tx_csr |= MUSB_TXCSR_FLUSHFIFO;
- HWREGH(ulBase + ulRegister) = tx_csr;
-
- if (ulBase == USB0_BASE)
- {
- ulBase = USB_0_OTGBASE;
- }
- else
- {
- ulBase = USB_1_OTGBASE;
- }
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
-
- /* Initiate CPPI Tx FIFO teardown in USBnTDOWN - module register */
- HWREG(ulBase + USB_0_TEARDOWN) =
- USB_TX_TDOWN_MASK( USB_EP_TO_INDEX(ulEndpoint));
-}
-
-/**
- *
- * This is used to stop further requests during teardown process.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint is the endpoint to access.
- *
- * This function will clear autoreq bit, which when set, will autorequest
- * for packet when FIFOs are empty.
- *
- * \note This function can be called in host or device mode.
- *
- * \return None.
- */
-void
-USBHostTxFifoFlush(unsigned int ulBase, unsigned int ulEndpoint)
-{
- unsigned int ulRegister;
- short tx_csr = 0x00;
-
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
-
- /* Initiate CPPI Tx FIFO teardown in USBnTDOWN - module register */
- if (ulBase == USB0_BASE)
- {
- HWREG(USB_0_OTGBASE + USB_0_TEARDOWN) |=
- USB_TX_TDOWN_MASK(USB_EP_TO_INDEX(ulEndpoint));
- }
- else
- {
- HWREG(USB_1_OTGBASE + USB_0_TEARDOWN) |=
- USB_TX_TDOWN_MASK(USB_EP_TO_INDEX(ulEndpoint));
- }
-
- /* Disable DMAEN in TxCSR */
- ulRegister = USB_O_TXCSRL1 + EP_OFFSET(ulEndpoint);
- tx_csr = HWREGH(ulBase + ulRegister);
-
- /* Flush FIFO of the endpoint */
- tx_csr = HWREGH(ulBase + ulRegister);
-
- if (tx_csr & MUSB_TXCSR_TXPKTRDY)
- {
- tx_csr |= MUSB_TXCSR_FLUSHFIFO;
- /* */
- tx_csr |= MUSB_TXCSR_H_WZC_BITS;
- /* Flush the FIFO twice - incase it is Double buffered*/
- HWREGH(ulBase + ulRegister) = tx_csr;
- HWREGH(ulBase + ulRegister) = tx_csr;
- }
-
-}
-
-#endif
-/**
- * Issues a request for a status IN transaction on endpoint zero.
- *
- * \param ulBase specifies the USB module base address.
- *
- * This function is used to cause a request for an status IN transaction from
- * a device on endpoint zero. This function can only be used with endpoint
- * zero as that is the only control endpoint that supports this ability. This
- * is used to complete the last phase of a control transaction to a device and
- * an interrupt will be signaled when the status packet has been received.
- *
- * \return None.
- */
-void
-USBHostRequestStatus(unsigned int ulBase)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
-
- /* Set the request for a status IN transaction. */
- HWREGB(ulBase + USB_O_CSRL0) = USB_CSRL0_REQPKT | USB_CSRL0_STATUS;
-}
-
-/**
- * Sets the functional address for the device that is connected to an
- * endpoint in host mode.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint is the endpoint to access.
- * \param ulAddr is the functional address for the controller to use for this
- * endpoint.
- * \param ulFlags determines if this is an IN or an OUT endpoint.
- *
- * This function will set the functional address for a device that is using
- * this endpoint for communication. This \e ulAddr parameter is the address
- * of the target device that this endpoint will be used to communicate with.
- * The \e ulFlags parameter indicates if the IN or OUT endpoint should be set.
- *
- * \note This function should only be called in host mode.
- *
- * \return None.
- */
-void
-USBHostAddrSet(unsigned int ulBase, unsigned int ulEndpoint,
- unsigned int ulAddr, unsigned int ulFlags)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
-
- /* See if the transmit or receive address should be set. */
- if(ulFlags & USB_EP_HOST_OUT)
- {
- /* Set the transmit address. */
- HWREGB(ulBase + USB_O_TXFUNCADDR0 + (ulEndpoint >> 1)) = ulAddr;
- }
- else
- {
- /* Set the receive address. */
- HWREGB(ulBase + USB_O_TXFUNCADDR0 + 4 + (ulEndpoint >> 1)) = ulAddr;
- }
-}
-
-/**
- * Gets the current functional device address for an endpoint.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint is the endpoint to access.
- * \param ulFlags determines if this is an IN or an OUT endpoint.
- *
- * This function returns the current functional address that an endpoint is
- * using to communicate with a device. The \e ulFlags parameter determines if
- * the IN or OUT endpoint's device address is returned.
- *
- * \note This function should only be called in host mode.
- *
- * \return Returns the current function address being used by an endpoint.
- */
-unsigned int
-USBHostAddrGet(unsigned int ulBase, unsigned int ulEndpoint,
- unsigned int ulFlags)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
-
- /* See if the transmit or receive address should be returned. */
- if(ulFlags & USB_EP_HOST_OUT)
- {
- /* Return this endpoint's transmit address. */
- return(HWREGB(ulBase + USB_O_TXFUNCADDR0 + (ulEndpoint >> 1)));
- }
- else
- {
- /* Return this endpoint's receive address. */
- return(HWREGB(ulBase + USB_O_TXFUNCADDR0 + 4 + (ulEndpoint >> 1)));
- }
-}
-
-/**
- * Set the hub address for the device that is connected to an endpoint.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint is the endpoint to access.
- * \param ulAddr is the hub address for the device using this endpoint.
- * \param ulFlags determines if this is an IN or an OUT endpoint.
- *
- * This function will set the hub address for a device that is using this
- * endpoint for communication. The \e ulFlags parameter determines if the
- * device address for the IN or the OUT endpoint is set by this call.
- *
- * \note This function should only be called in host mode.
- *
- * \return None.
- */
-void
-USBHostHubAddrSet(unsigned int ulBase, unsigned int ulEndpoint,
- unsigned int ulAddr, unsigned int ulFlags)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
-
- /* See if the hub transmit or receive address is being set. */
- if(ulFlags & USB_EP_HOST_OUT)
- {
- /* Set the hub transmit address for this endpoint. */
- HWREGB(ulBase + USB_O_TXHUBADDR0 + (ulEndpoint >> 1)) = ulAddr;
- }
- else
- {
- /* Set the hub receive address for this endpoint. */
- HWREGB(ulBase + USB_O_TXHUBADDR0 + 4 + (ulEndpoint >> 1)) = ulAddr;
- }
-}
-
-/**
- * Get the current device hub address for this endpoint.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint is the endpoint to access.
- * \param ulFlags determines if this is an IN or an OUT endpoint.
- *
- * This function will return the current hub address that an endpoint is using
- * to communicate with a device. The \e ulFlags parameter determines if the
- * device address for the IN or OUT endpoint is returned.
- *
- * \note This function should only be called in host mode.
- *
- * \return This function returns the current hub address being used by an
- * endpoint.
- */
-unsigned int
-USBHostHubAddrGet(unsigned int ulBase, unsigned int ulEndpoint,
- unsigned int ulFlags)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulEndpoint == USB_EP_0) || (ulEndpoint == USB_EP_1) ||
- (ulEndpoint == USB_EP_2) || (ulEndpoint == USB_EP_3) ||
- (ulEndpoint == USB_EP_4) || (ulEndpoint == USB_EP_5) ||
- (ulEndpoint == USB_EP_6) || (ulEndpoint == USB_EP_7) ||
- (ulEndpoint == USB_EP_8) || (ulEndpoint == USB_EP_9) ||
- (ulEndpoint == USB_EP_10) || (ulEndpoint == USB_EP_11) ||
- (ulEndpoint == USB_EP_12) || (ulEndpoint == USB_EP_13) ||
- (ulEndpoint == USB_EP_14) || (ulEndpoint == USB_EP_15));
-
- /* See if the hub transmit or receive address should be returned. */
- if(ulFlags & USB_EP_HOST_OUT)
- {
- /* Return the hub transmit address for this endpoint. */
- return(HWREGB(ulBase + USB_O_TXHUBADDR0 + (ulEndpoint >> 1)));
- }
- else
- {
- /* Return the hub receive address for this endpoint. */
- return(HWREGB(ulBase + USB_O_TXHUBADDR0 + 4 + (ulEndpoint >> 1)));
- }
-}
-
-/**
- * Sets the configuration for USB power fault.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulFlags specifies the configuration of the power fault.
- *
- * This function controls how the USB controller uses its external power
- * control pins(USBnPFTL and USBnEPEN). The flags specify the power
- * fault level sensitivity, the power fault action, and the power enable level
- * and source.
- *
- * One of the following can be selected as the power fault level
- * sensitivity:
- *
- * - \b USB_HOST_PWRFLT_LOW - An external power fault is indicated by the pin
- * being driven low.
- * - \b USB_HOST_PWRFLT_HIGH - An external power fault is indicated by the pin
- * being driven high.
- *
- * One of the following can be selected as the power fault action:
- *
- * - \b USB_HOST_PWRFLT_EP_NONE - No automatic action when power fault
- * detected.
- * - \b USB_HOST_PWRFLT_EP_TRI - Automatically Tri-state the USBnEPEN pin on a
- * power fault.
- * - \b USB_HOST_PWRFLT_EP_LOW - Automatically drive USBnEPEN pin low on a
- * power fault.
- * - \b USB_HOST_PWRFLT_EP_HIGH - Automatically drive USBnEPEN pin high on a
- * power fault.
- *
- * One of the following can be selected as the power enable level and source:
- *
- * - \b USB_HOST_PWREN_MAN_LOW - USBEPEN is driven low by the USB controller
- * when USBHostPwrEnable() is called.
- * - \b USB_HOST_PWREN_MAN_HIGH - USBEPEN is driven high by the USB controller
- * when USBHostPwrEnable() is called.
- * - \b USB_HOST_PWREN_AUTOLOW - USBEPEN is driven low by the USB controller
- * automatically if USBOTGSessionRequest() has
- * enabled a session.
- * - \b USB_HOST_PWREN_AUTOHIGH - USBEPEN is driven high by the USB controller
- * automatically if USBOTGSessionRequest() has
- * enabled a session.
- *
- * On devices that support the VBUS glitch filter, the
- * \b USB_HOST_PWREN_FILTER can be added to ignore small short drops in VBUS
- * level caused by high power consumption. This is mainly used to avoid
- * causing VBUS errors caused by devices with high in-rush current.
- *
- * \note The following values have been deprecated and should no longer be
- * used.
- * - \b USB_HOST_PWREN_LOW - Automatically drive USBnEPEN low when power is
- * enabled.
- * - \b USB_HOST_PWREN_HIGH - Automatically drive USBnEPEN high when power is
- * enabled.
- * - \b USB_HOST_PWREN_VBLOW - Automatically drive USBnEPEN low when power is
- * enabled.
- * - \b USB_HOST_PWREN_VBHIGH - Automatically drive USBnEPEN high when power is
- * enabled.
- *
- * \note This function should only be called on microcontrollers that support
- * host mode or OTG operation.
- *
- * \return None.
- */
-void
-USBHostPwrConfig(unsigned int ulBase, unsigned int ulFlags)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulFlags & ~(USB_EPC_PFLTACT_M | USB_EPC_PFLTAEN |
- USB_EPC_PFLTSEN_HIGH | USB_EPC_EPEN_M)) == 0);
-
- /* If requested, enable VBUS droop detection on parts that support this
- * feature. */
- HWREG(ulBase + USB_O_VDC) = ulFlags >> 16;
-
- /* Set the power fault configuration as specified. This will not change
- * whether fault detection is enabled or not. */
- HWREGH(ulBase + USB_O_EPC) =
- (ulFlags | (HWREGH(ulBase + USB_O_EPC) &
- ~(USB_EPC_PFLTACT_M | USB_EPC_PFLTAEN |
- USB_EPC_PFLTSEN_HIGH | USB_EPC_EPEN_M)));
-}
-
-/**
- * Enables power fault detection.
- *
- * \param ulBase specifies the USB module base address.
- *
- * This function enables power fault detection in the USB controller. If the
- * USBPFLT pin is not in use this function should not be used.
- *
- * \note This function should only be called in host mode.
- *
- * \return None.
- */
-void
-USBHostPwrFaultEnable(unsigned int ulBase)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
-
- /* Enable power fault input. */
- HWREGH(ulBase + USB_O_EPC) |= USB_EPC_PFLTEN;
-}
-
-/**
- * Disables power fault detection.
- *
- * \param ulBase specifies the USB module base address.
- *
- * This function disables power fault detection in the USB controller.
- *
- * \note This function should only be called in host mode.
- *
- * \return None.
- */
-void
-USBHostPwrFaultDisable(unsigned int ulBase)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
-
- /* Enable power fault input. */
- HWREGH(ulBase + USB_O_EPC) &= ~USB_EPC_PFLTEN;
-}
-
-/**
- * Enables the external power pin.
- *
- * \param ulBase specifies the USB module base address.
- *
- * This function enables the USBEPEN signal to enable an external power supply
- * in host mode operation.
- *
- * \note This function should only be called in host mode.
- *
- * \return None.
- */
-void
-USBHostPwrEnable(unsigned int ulBase)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
-
- /* Enable the external power suppply enable signal. */
- HWREGH(ulBase + USB_O_EPC) |= USB_EPC_EPENDE;
-}
-
-/**
- * Disables the external power pin.
- *
- * \param ulBase specifies the USB module base address.
- *
- * This function disables the USBEPEN signal to disable an external power
- * supply in host mode operation.
- *
- * \note This function should only be called in host mode.
- *
- * \return None.
- */
-void
-USBHostPwrDisable(unsigned int ulBase)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
-
- /* Disable the external power supply enable signal. */
- HWREGH(ulBase + USB_O_EPC) &= ~USB_EPC_EPENDE;
-}
-
-/**
- * Get the current frame number.
- *
- * \param ulBase specifies the USB module base address.
- *
- * This function returns the last frame number received.
- *
- * \return The last frame number received.
- */
-unsigned int
-USBFrameNumberGet(unsigned int ulBase)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
-
- /* Return the most recent frame number. */
- return(HWREGH(ulBase + USB_O_FRAME));
-}
-
-/**
- * Starts or ends a session.
- *
- * \param ulBase specifies the USB module base address.
- * \param bStart specifies if this call starts or ends a session.
- *
- * This function is used in OTG mode to start a session request or end a
- * session. If the \e bStart parameter is set to \b true, then this function
- * start a session and if it is \b false it will end a session.
- *
- * \return None.
- */
-void
-USBOTGSessionRequest(unsigned int ulBase, tBoolean bStart)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
-
- /* Start or end the session as directed. */
- if(bStart)
- {
- HWREGB(ulBase + USB_O_DEVCTL) |= USB_DEVCTL_SESSION;
- }
- else
- {
- HWREGB(ulBase + USB_O_DEVCTL) &= ~USB_DEVCTL_SESSION;
- }
-}
-
-/**
- * Returns the absolute FIFO address for a given endpoint.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint specifies which endpoint's FIFO address to return.
- *
- * This function returns the actual physical address of the FIFO. This is
- * needed when the USB is going to be used with the uDMA controller and the
- * source or destination address needs to be set to the physical FIFO address
- * for a given endpoint.
- *
- * \return None.
- */
-unsigned int
-USBFIFOAddrGet(unsigned int ulBase, unsigned int ulEndpoint)
-{
- /* Return the FIFO address for this endpoint. */
- return(ulBase + USB_O_FIFO0 + (ulEndpoint >> 2));
-}
-
-/**
- * Returns the current operating mode of the controller.
- *
- * \param ulBase specifies the USB module base address.
- *
- * This function returns the current operating mode on USB controllers with
- * OTG or Dual mode functionality.
- *
- * For OTG controllers:
- *
- * The function will return on of the following values on OTG controllers:
- * \b USB_OTG_MODE_ASIDE_HOST, \b USB_OTG_MODE_ASIDE_DEV,
- * \b USB_OTG_MODE_BSIDE_HOST, \b USB_OTG_MODE_BSIDE_DEV,
- * \b USB_OTG_MODE_NONE.
- *
- * \b USB_OTG_MODE_ASIDE_HOST indicates that the controller is in host mode
- * on the A-side of the cable.
- *
- * \b USB_OTG_MODE_ASIDE_DEV indicates that the controller is in device mode
- * on the A-side of the cable.
- *
- * \b USB_OTG_MODE_BSIDE_HOST indicates that the controller is in host mode
- * on the B-side of the cable.
- *
- * \b USB_OTG_MODE_BSIDE_DEV indicates that the controller is in device mode
- * on the B-side of the cable. If and OTG session request is started with no
- * cable in place this is the default mode for the controller.
- *
- * \b USB_OTG_MODE_NONE indicates that the controller is not attempting to
- * determine its role in the system.
- *
- * For Dual Mode controllers:
- *
- * The function will return on of the following values:
- * \b USB_DUAL_MODE_HOST, \b USB_DUAL_MODE_DEVICE, or
- * \b USB_DUAL_MODE_NONE.
- *
- * \b USB_DUAL_MODE_HOST indicates that the controller is acting as a host.
- *
- * \b USB_DUAL_MODE_DEVICE indicates that the controller acting as a device.
- *
- * \b USB_DUAL_MODE_NONE indicates that the controller is not active as
- * either a host or device.
- *
- * \return Returns \b USB_OTG_MODE_ASIDE_HOST, \b USB_OTG_MODE_ASIDE_DEV,
- * \b USB_OTG_MODE_BSIDE_HOST, \b USB_OTG_MODE_BSIDE_DEV,
- * \b USB_OTG_MODE_NONE, \b USB_DUAL_MODE_HOST, \b USB_DUAL_MODE_DEVICE, or
- * \b USB_DUAL_MODE_NONE.
- */
-unsigned int
-USBModeGet(unsigned int ulBase)
-{
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
-
- /* Checks the current mode in the USB_O_DEVCTL and returns the current
- * mode.
- * USB_OTG_MODE_ASIDE_HOST: USB_DEVCTL_HOST | USB_DEVCTL_SESSION
- * USB_OTG_MODE_ASIDE_DEV: USB_DEVCTL_SESSION
- * USB_OTG_MODE_BSIDE_HOST: USB_DEVCTL_DEV | USB_DEVCTL_SESSION |
- * USB_DEVCTL_HOST
- * USB_OTG_MODE_BSIDE_DEV: USB_DEVCTL_DEV | USB_DEVCTL_SESSION
- * USB_OTG_MODE_NONE: USB_DEVCTL_DEV */
- return(HWREGB(ulBase + USB_O_DEVCTL) &
- (USB_DEVCTL_DEV | USB_DEVCTL_HOST | USB_DEVCTL_SESSION |
- USB_DEVCTL_VBUS_M));
-}
-
-/**
- * Sets the DMA channel to use for a given endpoint.
- *
- * \param ulBase specifies the USB module base address.
- * \param ulEndpoint specifies which endpoint's FIFO address to return.
- * \param ulChannel specifies which DMA channel to use for which endpoint.
- *
- * This function is used to configure which DMA channel to use with a given
- * endpoint. Receive DMA channels can only be used with receive endpoints
- * and transmit DMA channels can only be used with transmit endpoints. This
- * allows the 3 receive and 3 transmit DMA channels to be mapped to any
- * endpoint other than 0. The values that should be passed into the \e
- * ulChannel value are the UDMA_CHANNEL_USBEP* values defined in udma.h.
- *
- * \note This function only has an effect on microcontrollers that have the
- * ability to change the DMA channel for an endpoint. Calling this function
- * on other devices will have no effect.
- *
- * \return None.
- */
-void
-USBEndpointDMAChannel(unsigned int ulBase, unsigned int ulEndpoint,
- unsigned int ulChannel)
-{
- unsigned int ulMask;
-
- /* Check the arguments. */
- ASSERT((ulBase == USB0_BASE)||(ulBase == USB1_BASE));
- ASSERT((ulEndpoint == USB_EP_1) || (ulEndpoint == USB_EP_2) ||
- (ulEndpoint == USB_EP_3) || (ulEndpoint == USB_EP_4) ||
- (ulEndpoint == USB_EP_5) || (ulEndpoint == USB_EP_6) ||
- (ulEndpoint == USB_EP_7) || (ulEndpoint == USB_EP_8) ||
- (ulEndpoint == USB_EP_9) || (ulEndpoint == USB_EP_10) ||
- (ulEndpoint == USB_EP_11) || (ulEndpoint == USB_EP_12) ||
- (ulEndpoint == USB_EP_13) || (ulEndpoint == USB_EP_14) ||
- (ulEndpoint == USB_EP_15));
- ASSERT(ulChannel <= UDMA_CHANNEL_USBEP3TX);
-
- /* The input select mask needs to be shifted into the correct position
- * based on the channel. */
- ulMask = 0xf << (ulChannel * 4);
-
- /* Clear out the current selection for the channel. */
- ulMask = HWREG(ulBase + USB_O_DMASEL) & (~ulMask);
-
- /* The input select is now shifted into the correct position based on the
- * channel. */
- ulMask |= (USB_EP_TO_INDEX(ulEndpoint)) << (ulChannel * 4);
-
- /* Write the value out to the register. */
- HWREG(ulBase + USB_O_DMASEL) = ulMask;
-}
-
-/**
- * Enables the USB interrupt at OTG level.
- *
- * \param None.
- *
- * \return None.
- */
-void USBEnableOtgIntr(unsigned int ulBase)
-{
- unsigned int reg;
-
- reg = HWREG(ulBase + USB_0_CTRL);
- reg &= 0xFFFFFFF7;
- HWREG(ulBase + USB_0_CTRL) = reg;
-
- /* This API enables the USB Interrupts through subsystem specific wrapper
- registers*/
- USBEnableInt(ulBase);
-}
-
-/**
- * Resets the USB Controller
- *
- * \param None.
- *
- * \return None.
- */
-void USBReset(unsigned int ulBase)
-{
- unsigned int reg;
-
- reg = HWREG(ulBase + USB_0_CTRL);
- reg |= 1;
-
- /* Set the Reset Bit */
- HWREG(ulBase + USB_0_CTRL) = reg;
-
- /* Wait till Reset bit is cleared */
- while(((HWREG(ulBase + USB_0_CTRL)) & 0x1 )== 1);
-
-}
-
-void USBClearOtgIntr(unsigned int ulBase)
-{
- USBClearInt(ulBase);
-}
-/* Close the Doxygen group. */
-/** @} */
diff --git a/SylixOS/StarterWare/drivers/usbphyGS70.c b/SylixOS/StarterWare/drivers/usbphyGS70.c
deleted file mode 100644
index 5c2b114..0000000
--- a/SylixOS/StarterWare/drivers/usbphyGS70.c
+++ /dev/null
@@ -1,109 +0,0 @@
-/**
- * \file UsbphyGS70.c
- *
- * \brief This file contains AM335x USB Phy related functions.
- *
-*/
-
-/*
-* Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
-*/
-/*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions
-* are met:
-*
-* Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-*
-* Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the
-* distribution.
-*
-* Neither the name of Texas Instruments Incorporated nor the names of
-* its contributors may be used to endorse or promote products derived
-* from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*
-*/
-
-#include "hw_types.h"
-#include "soc_AM335x.h"
-#include "hw_usbphyGS70.h"
-#include "usblib.h"
-#include "hw_usb.h"
-#include "debug.h"
-
-//*****************************************************************************
-//
-// USB instance Object
-//
-//*****************************************************************************
-extern tUSBInstanceObject g_USBInstance[];
-
-
-/**
- * \brief This function will switch on the USB Phy
- *
- *
- * \param None
- *
- * \return None
- *
- **/
-void UsbPhyOn(unsigned int ulIndex)
-{
- unsigned int usbphycfg = 0;
-#if defined (am335x_15x15) || defined(am335x) || defined(c6a811x)
- ASSERT((0==ulIndex)||(1==ulIndex));
-#else
- ASSERT(0==ulIndex);
-#endif /* defined (am335x_15x15) || ... */
-
-#ifdef USB_MODE_FULLSPEED
- if (0==ulIndex)
- HWREGB(USB0_BASE + USB_O_POWER) &= 0xdf;
-#if defined (am335x_15x15) || defined(am335x) || defined(c6a811x)
- else
- HWREGB(USB1_BASE + USB_O_POWER) &= 0xdf;
-#endif /* defined (am335x_15x15) || ... */
-#endif /* USB_MODE_HS_DISABLE */
-
- usbphycfg = HWREG(g_USBInstance[ulIndex].uiPHYConfigRegAddr);
- usbphycfg &= ~(USBPHY_CM_PWRDN | USBPHY_OTG_PWRDN);
- usbphycfg |= (USBPHY_OTGVDET_EN | USBPHY_OTGSESSEND_EN);
-
- HWREG(g_USBInstance[ulIndex].uiPHYConfigRegAddr) = usbphycfg;
-}
-
-
-/**
- * \brief This function will switch off the USB Phy
- *
- *
- * \param None
- *
- * \return None
- *
- **/
-void UsbPhyOff(unsigned int ulIndex)
-{
- unsigned int usbphycfg = 0;
-
- usbphycfg = HWREG(g_USBInstance[ulIndex].uiPHYConfigRegAddr);
- usbphycfg |= (USBPHY_CM_PWRDN | USBPHY_OTG_PWRDN);
- HWREG(g_USBInstance[ulIndex].uiPHYConfigRegAddr) = usbphycfg;
-}
-
diff --git a/SylixOS/StarterWare/usblib/device/usbdbulk.c b/SylixOS/StarterWare/usblib/device/usbdbulk.c
deleted file mode 100644
index 76e7f5e..0000000
--- a/SylixOS/StarterWare/usblib/device/usbdbulk.c
+++ /dev/null
@@ -1,1445 +0,0 @@
-//*****************************************************************************
-//
-// usbdbulk.c - USB bulk device class driver.
-//
-// Copyright (c) 2008-2010 Texas Instruments Incorporated. All rights reserved.
-// Software License Agreement
-//
-// Texas Instruments (TI) is supplying this software for use solely and
-// exclusively on TI's microcontroller products. The software is owned by
-// TI and/or its suppliers, and is protected under applicable copyright
-// laws. You may not combine this software with "viral" open-source
-// software in order to form a larger program.
-//
-// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
-// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
-// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
-// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
-// DAMAGES, FOR ANY REASON WHATSOEVER.
-//
-// This is part of revision 6288 of the Stellaris USB Library.
-//
-//*****************************************************************************
-
-#include "hw_usb.h"
-#include "hw_types.h"
-#include "debug.h"
-#include "interrupt.h"
-#include "usb.h"
-#include "usblib.h"
-#include "usbdevice.h"
-#include "usbdcomp.h"
-#include "usbdbulk.h"
-#include "usblibpriv.h"
-
-//*****************************************************************************
-//
-//! \addtogroup bulk_device_class_api
-//! @{
-//
-//*****************************************************************************
-
-//*****************************************************************************
-//
-// The subset of endpoint status flags that we consider to be reception
-// errors. These are passed to the client via USB_EVENT_ERROR if seen.
-//
-//*****************************************************************************
-#define USB_RX_ERROR_FLAGS (USBERR_DEV_RX_DATA_ERROR | \
- USBERR_DEV_RX_OVERRUN | \
- USBERR_DEV_RX_FIFO_FULL)
-
-//*****************************************************************************
-//
-// Flags that may appear in usDeferredOpFlags to indicate some operation that
-// has been requested but could not be processed at the time it was received.
-// Each deferred operation is defined as the bit number that should be set in
-// tBulkInstance->usDeferredOpFlags to indicate that the operation is pending.
-//
-//*****************************************************************************
-#define BULK_DO_PACKET_RX 5
-
-//*****************************************************************************
-//
-// Macros to convert between USB controller base address and an index. These
-// are currently trivial but are included to allow for the possibility of
-// supporting more than one controller in the future.
-//
-//*****************************************************************************
-#if (USB_NUM_INSTANCE == 2)
-#define USB_BASE_TO_INDEX(BaseAddr, index) do{ \
- if(USB0_BASE==BaseAddr) \
- index = 0; \
- else if(USB1_BASE==BaseAddr) \
- index = 1; \
- else \
- index = -1; \
- }while(0)
-
-#define USB_INDEX_TO_BASE(Index, BaseAddr) ( \
- if(0==Index) \
- BaseAddr = USB0_BASE; \
- else if(1==Index) \
- BaseAddr = USB1_BASE; \
- else \
- BaseAddr = -1; \
- )
-#else
-#define USB_BASE_TO_INDEX(BaseAddr, index) do{ \
- if(USB0_BASE==BaseAddr) \
- index = 0; \
- else \
- index = -1; \
- }while(0)
-
-#define USB_INDEX_TO_BASE(Index, BaseAddr) ( \
- if(0==Index) \
- BaseAddr = USB0_BASE; \
- else \
- BaseAddr = -1; \
- )
-#endif
-
-//*****************************************************************************
-//
-// Endpoints to use for each of the required endpoints in the driver.
-//
-//*****************************************************************************
-#define DATA_IN_ENDPOINT USB_EP_1
-#define DATA_OUT_ENDPOINT USB_EP_1
-
-//*****************************************************************************
-//
-// Maximum packet size for the bulk endpoints used for serial data
-// transmission and reception and the associated FIFO sizes to set aside
-// for each endpoint.
-//
-//*****************************************************************************
-#define DATA_IN_EP_FIFO_SIZE USB_FIFO_SZ_64
-#define DATA_OUT_EP_FIFO_SIZE USB_FIFO_SZ_64
-
-#define DATA_IN_EP_MAX_SIZE USB_FIFO_SZ_TO_BYTES(DATA_IN_EP_FIFO_SIZE)
-#define DATA_OUT_EP_MAX_SIZE USB_FIFO_SZ_TO_BYTES(DATA_IN_EP_FIFO_SIZE)
-
-//*****************************************************************************
-//
-// USB instance Object
-//
-//*****************************************************************************
-extern tUSBInstanceObject g_USBInstance[];
-
-//*****************************************************************************
-//
-// Device Descriptor. This is stored in RAM to allow several fields to be
-// changed at runtime based on the client's requirements.
-//
-//*****************************************************************************
-unsigned char g_pBulkDeviceDescriptor[] =
-{
- 18, // Size of this structure.
- USB_DTYPE_DEVICE, // Type of this structure.
- USBShort(0x110), // USB version 1.1 (if we say 2.0, hosts assume
- // high-speed - see USB 2.0 spec 9.2.6.6)
- USB_CLASS_VEND_SPECIFIC, // USB Device Class
- 0, // USB Device Sub-class
- 0, // USB Device protocol
- 64, // Maximum packet size for default pipe.
- USBShort(0), // Vendor ID (VID).
- USBShort(0), // Product ID (PID).
- USBShort(0x100), // Device Version BCD.
- 1, // Manufacturer string identifier.
- 2, // Product string identifier.
- 3, // Product serial number.
- 1 // Number of configurations.
-};
-
-//*****************************************************************************
-//
-// Bulk device configuration descriptor.
-//
-// It is vital that the configuration descriptor bConfigurationValue field
-// (byte 6) is 1 for the first configuration and increments by 1 for each
-// additional configuration defined here. This relationship is assumed in the
-// device stack for simplicity even though the USB 2.0 specification imposes
-// no such restriction on the bConfigurationValue values.
-//
-// Note that this structure is deliberately located in RAM since we need to
-// be able to patch some values in it based on client requirements.
-//
-//*****************************************************************************
-unsigned char g_pBulkDescriptor[] =
-{
- //
- // Configuration descriptor header.
- //
- 9, // Size of the configuration descriptor.
- USB_DTYPE_CONFIGURATION, // Type of this descriptor.
- USBShort(32), // The total size of this full structure.
- 1, // The number of interfaces in this
- // configuration.
- 1, // The unique value for this configuration.
- 5, // The string identifier that describes this
- // configuration.
- USB_CONF_ATTR_SELF_PWR, // Bus Powered, Self Powered, remote wake up.
- 250, // The maximum power in 2mA increments.
-};
-
-//*****************************************************************************
-//
-// The remainder of the configuration descriptor is stored in flash since we
-// don't need to modify anything in it at runtime.
-//
-//*****************************************************************************
-const unsigned char g_pBulkInterface[] =
-{
- //
- // Vendor-specific Interface Descriptor.
- //
- 9, // Size of the interface descriptor.
- USB_DTYPE_INTERFACE, // Type of this descriptor.
- 0, // The index for this interface.
- 0, // The alternate setting for this interface.
- 2, // The number of endpoints used by this
- // interface.
- USB_CLASS_VEND_SPECIFIC, // The interface class
- 0, // The interface sub-class.
- 0, // The interface protocol for the sub-class
- // specified above.
- 4, // The string index for this interface.
-
- //
- // Endpoint Descriptor
- //
- 7, // The size of the endpoint descriptor.
- USB_DTYPE_ENDPOINT, // Descriptor type is an endpoint.
- USB_EP_DESC_IN | USB_EP_TO_INDEX(DATA_IN_ENDPOINT),
- USB_EP_ATTR_BULK, // Endpoint is a bulk endpoint.
- USBShort(DATA_IN_EP_MAX_SIZE), // The maximum packet size.
- 0, // The polling interval for this endpoint.
-
- //
- // Endpoint Descriptor
- //
- 7, // The size of the endpoint descriptor.
- USB_DTYPE_ENDPOINT, // Descriptor type is an endpoint.
- USB_EP_DESC_OUT | USB_EP_TO_INDEX(DATA_OUT_ENDPOINT),
- USB_EP_ATTR_BULK, // Endpoint is a bulk endpoint.
- USBShort(DATA_OUT_EP_MAX_SIZE), // The maximum packet size.
- 0, // The polling interval for this endpoint.
-};
-
-//*****************************************************************************
-//
-// The serial config descriptor is defined as two sections, one containing
-// just the 9 byte USB configuration descriptor and the other containing
-// everything else that is sent to the host along with it.
-//
-//*****************************************************************************
-const tConfigSection g_sBulkConfigSection =
-{
- sizeof(g_pBulkDescriptor),
- g_pBulkDescriptor
-};
-
-const tConfigSection g_sBulkInterfaceSection =
-{
- sizeof(g_pBulkInterface),
- g_pBulkInterface
-};
-
-//*****************************************************************************
-//
-// This array lists all the sections that must be concatenated to make a
-// single, complete bulk device configuration descriptor.
-//
-//*****************************************************************************
-const tConfigSection *g_psBulkSections[] =
-{
- &g_sBulkConfigSection,
- &g_sBulkInterfaceSection
-};
-
-#define NUM_BULK_SECTIONS (sizeof(g_psBulkSections) / \
- sizeof(tConfigSection *))
-
-//*****************************************************************************
-//
-// The header for the single configuration we support. This is the root of
-// the data structure that defines all the bits and pieces that are pulled
-// together to generate the configuration descriptor.
-//
-//*****************************************************************************
-const tConfigHeader g_sBulkConfigHeader =
-{
- NUM_BULK_SECTIONS,
- g_psBulkSections
-};
-
-//*****************************************************************************
-//
-// Configuration Descriptor.
-//
-//*****************************************************************************
-const tConfigHeader * const g_pBulkConfigDescriptors[] =
-{
- &g_sBulkConfigHeader
-};
-
-//*****************************************************************************
-//
-// Forward references for device handler callbacks
-//
-//*****************************************************************************
-static void HandleConfigChange(void *pvInstance, unsigned int ulInfo,
- unsigned int ulIndex);
-static void HandleDisconnect(void *pvInstance);
-static void HandleEndpoints(void *pvInstance, unsigned int ulStatus,
- unsigned int ulIndex);
-static void HandleSuspend(void *pvInstance);
-static void HandleResume(void *pvInstance);
-static void HandleDevice(void *pvInstance, unsigned int ulRequest,
- void *pvRequestData);
-
-//*****************************************************************************
-//
-// The device information structure for the USB serial device.
-//
-//*****************************************************************************
-tDeviceInfo g_sBulkDeviceInfo =
-{
- //
- // Device event handler callbacks.
- //
- {
- 0, // GetDescriptor
- 0, // RequestHandler
- 0, // InterfaceChange
- HandleConfigChange, // ConfigChange
- 0, // DataReceived
- 0, // DataSentCallback
- 0, // ResetHandler
- HandleSuspend, // SuspendHandler
- HandleResume, // ResumeHandler
- HandleDisconnect, // DisconnectHandler
- HandleEndpoints, // EndpointHandler
- HandleDevice // Device handler.
- },
- g_pBulkDeviceDescriptor,
- g_pBulkConfigDescriptors,
- 0, // Will be completed during USBDBulkInit().
- 0, // Will be completed during USBDBulkInit().
- &g_sUSBDefaultFIFOConfig
-};
-
-//*****************************************************************************
-//
-// Set or clear deferred operation flags in an "atomic" manner.
-//
-// \param pusDeferredOp points to the flags variable which is to be modified.
-// \param usBit indicates which bit number is to be set or cleared.
-// \param bSet indicates the state that the flag must be set to. If \b true,
-// the flag is set, if \b false, the flag is cleared.
-//
-// This function safely sets or clears a bit in a flag variable. The operation
-// makes use of bitbanding to ensure that the operation is atomic (no read-
-// modify-write is required).
-//
-// \return None.
-//
-//*****************************************************************************
-static void
-SetDeferredOpFlag(volatile unsigned short *pusDeferredOp, unsigned short usBit,
- tBoolean bSet)
-{
- //
- // Set the flag bit to 1 or 0 using a bitband access.
- //
- HWREGBITH(pusDeferredOp, usBit) = bSet ? 1 : 0;
-}
-
-//*****************************************************************************
-//
-// Receives notifications related to data received from the host.
-//
-// \param psDevice is the device instance whose endpoint is to be processed.
-// \param ulStatus is the USB interrupt status that caused this function to
-// be called.
-//
-// This function is called from HandleEndpoints for all interrupts signaling
-// the arrival of data on the bulk OUT endpoint (in other words, whenever the
-// host has sent us a packet of data). We inform the client that a packet
-// is available and, on return, check to see if the packet has been read. If
-// not, we schedule another notification to the client for a later time.
-//
-// \return Returns \b true on success or \b false on failure.
-//
-//*****************************************************************************
-static tBoolean
-ProcessDataFromHost(const tUSBDBulkDevice *psDevice, unsigned int ulStatus,
- unsigned int ulIndex)
-{
- unsigned int ulEPStatus;
- unsigned int ulSize;
- tBulkInstance *psInst;
-
- //
- // Get a pointer to our instance data.
- //
- psInst = psDevice->psPrivateBulkData;
-
- //
- // Get the endpoint status to see why we were called.
- //
- ulEPStatus = USBEndpointStatus(g_USBInstance[ulIndex].uiBaseAddr, psInst->ucOUTEndpoint);
-
- //
- // Clear the status bits.
- //
- USBDevEndpointStatusClear(g_USBInstance[ulIndex].uiBaseAddr, psInst->ucOUTEndpoint, ulEPStatus);
-
- //
- // Has a packet been received?
- //
- if(ulEPStatus & USB_DEV_RX_PKT_RDY)
- {
- //
- // Set the flag we use to indicate that a packet read is pending. This
- // will be cleared if the packet is read. If the client doesn't read
- // the packet in the context of the USB_EVENT_RX_AVAILABLE callback,
- // the event will be signaled later during tick processing.
- //
- SetDeferredOpFlag(&psInst->usDeferredOpFlags, BULK_DO_PACKET_RX, true);
-
- //
- // How big is the packet we've just been sent?
- //
- ulSize = USBEndpointDataAvail(psInst->ulUSBBase, psInst->ucOUTEndpoint);
-
- //
- // The receive channel is not blocked so let the caller know
- // that a packet is waiting. The parameters are set to indicate
- // that the packet has not been read from the hardware FIFO yet.
- //
- psDevice->pfnRxCallback(psDevice->pvRxCBData,
- USB_EVENT_RX_AVAILABLE, ulSize,
- (void *)0);
- }
- else
- {
- //
- // No packet was received. Some error must have been reported. Check
- // and pass this on to the client if necessary.
- //
- if(ulEPStatus & USB_RX_ERROR_FLAGS)
- {
- //
- // This is an error we report to the client so...
- //
- psDevice->pfnRxCallback(psDevice->pvRxCBData,
- USB_EVENT_ERROR,
- (ulEPStatus & USB_RX_ERROR_FLAGS),
- (void *)0);
- }
- return (false);
- }
-
- return (true);
-}
-
-//*****************************************************************************
-//
-// Receives notifications related to data sent to the host.
-//
-// \param psDevice is the device instance whose endpoint is to be processed.
-// \param ulStatus is the USB interrupt status that caused this function to
-// be called.
-//
-// This function is called from HandleEndpoints for all interrupts originating
-// from the bulk IN endpoint (in other words, whenever data has been
-// transmitted to the USB host). We examine the cause of the interrupt and,
-// if due to completion of a transmission, notify the client.
-//
-// \return Returns \b true on success or \b false on failure.
-//
-//*****************************************************************************
-static tBoolean
-ProcessDataToHost(const tUSBDBulkDevice *psDevice, unsigned int ulStatus,
- unsigned int ulIndex)
-{
- tBulkInstance *psInst;
- unsigned int ulEPStatus;
- unsigned int ulSize;
-
- //
- // Get a pointer to our instance data.
- //
- psInst = psDevice->psPrivateBulkData;
-
- //
- // Get the endpoint status to see why we were called.
- //
- ulEPStatus = USBEndpointStatus(psInst->ulUSBBase, psInst->ucINEndpoint);
-
- //
- // Clear the status bits.
- //
- USBDevEndpointStatusClear(psInst->ulUSBBase, psInst->ucINEndpoint,
- ulEPStatus);
-
- //
- // Our last transmission completed. Clear our state back to idle and
- // see if we need to send any more data.
- //
- psInst->eBulkTxState = BULK_STATE_IDLE;
-
- //
- // Notify the client that the last transmission completed.
- //
- ulSize = psInst->usLastTxSize;
- psInst->usLastTxSize = 0;
- psDevice->pfnTxCallback(psDevice->pvTxCBData, USB_EVENT_TX_COMPLETE,
- ulSize, (void *)0);
-
- return (true);
-}
-
-//*****************************************************************************
-//
-// Called by the USB stack for any activity involving one of our endpoints
-// other than EP0. This function is a fan out that merely directs the call to
-// the correct handler depending upon the endpoint and transaction direction
-// signaled in ulStatus.
-//
-//*****************************************************************************
-static void
-HandleEndpoints(void *pvInstance, unsigned int ulStatus, unsigned int ulIndex)
-{
- const tUSBDBulkDevice *psBulkInst;
- tBulkInstance *psInst;
-
- ASSERT(pvInstance != 0);
-
- //
- // Determine if the serial device is in single or composite mode because
- // the meaning of ulIndex is different in both cases.
- //
- psBulkInst = (const tUSBDBulkDevice *)pvInstance;
- psInst = psBulkInst->psPrivateBulkData;
-
- //
- // Handler for the bulk OUT data endpoint.
- //
- if(ulStatus & (0x10000 << USB_EP_TO_INDEX(psInst->ucOUTEndpoint)))
- {
- //
- // Data is being sent to us from the host.
- //
- ProcessDataFromHost(pvInstance, ulStatus, ulIndex);
- }
-
- //
- // Handler for the bulk IN data endpoint.
- //
- if(ulStatus & (1 << USB_EP_TO_INDEX(psInst->ucINEndpoint)))
- {
- ProcessDataToHost(pvInstance, ulStatus, ulIndex);
- }
-}
-
-//*****************************************************************************
-//
-// Called by the USB stack whenever a configuration change occurs.
-//
-//*****************************************************************************
-static void
-HandleConfigChange(void *pvInstance, unsigned int ulInfo,
- unsigned int ulIndex)
-{
- tBulkInstance *psInst;
- const tUSBDBulkDevice *psDevice;
-
- ASSERT(pvInstance != 0);
-
- //
- // Create a device instance pointer.
- //
- psDevice = (const tUSBDBulkDevice *)pvInstance;
-
- //
- // Get a pointer to our instance data.
- //
- psInst = psDevice->psPrivateBulkData;
-
- //
- // Set all our endpoints to idle state.
- //
- psInst->eBulkRxState = BULK_STATE_IDLE;
- psInst->eBulkTxState = BULK_STATE_IDLE;
-
- //
- // If we have a control callback, let the client know we are open for
- // business.
- //
- if(psDevice->pfnRxCallback)
- {
- //
- // Pass the connected event to the client.
- //
- psDevice->pfnRxCallback(psDevice->pvRxCBData, USB_EVENT_CONNECTED, 0,
- (void *)0);
- }
-
- //
- // Remember that we are connected.
- //
- psInst->bConnected = true;
-}
-
-//*****************************************************************************
-//
-// Device instance specific handler.
-//
-//*****************************************************************************
-static void
-HandleDevice(void *pvInstance, unsigned int ulRequest, void *pvRequestData)
-{
- tBulkInstance *psInst;
- unsigned char *pucData;
-
- //
- // Create the serial instance data.
- //
- psInst = ((tUSBDBulkDevice *)pvInstance)->psPrivateBulkData;
-
- //
- // Create the char array used by the events supported by the USB CDC
- // serial class.
- //
- pucData = (unsigned char *)pvRequestData;
-
- switch(ulRequest)
- {
- //
- // This was an interface change event.
- //
- case USB_EVENT_COMP_IFACE_CHANGE:
- {
- psInst->ucInterface = pucData[1];
- break;
- }
-
- //
- // This was an endpoint change event.
- //
- case USB_EVENT_COMP_EP_CHANGE:
- {
- //
- // Determine if this is an IN or OUT endpoint that has changed.
- //
- if(pucData[0] & USB_EP_DESC_IN)
- {
- psInst->ucINEndpoint = INDEX_TO_USB_EP((pucData[1] & 0x7f));
- }
- else
- {
- //
- // Extract the new endpoint number.
- //
- psInst->ucOUTEndpoint = INDEX_TO_USB_EP(pucData[1] & 0x7f);
- }
- break;
- }
- default:
- {
- break;
- }
- }
-}
-
-//*****************************************************************************
-//
-// This function is called by the USB device stack whenever the device is
-// disconnected from the host.
-//
-//*****************************************************************************
-static void
-HandleDisconnect(void *pvInstance)
-{
- const tUSBDBulkDevice *psBulkDevice;
- tBulkInstance *psInst;
-
- ASSERT(pvInstance != 0);
-
- //
- // Create the instance pointer.
- //
- psBulkDevice = (const tUSBDBulkDevice *)pvInstance;
-
- //
- // Get a pointer to our instance data.
- //
- psInst = psBulkDevice->psPrivateBulkData;
-
- //
- // If we are not currently connected so let the client know we are open
- // for business.
- //
- if(psInst->bConnected)
- {
- //
- // Pass the disconnected event to the client.
- //
- psBulkDevice->pfnRxCallback(psBulkDevice->pvRxCBData,
- USB_EVENT_DISCONNECTED, 0, (void *)0);
- }
-
- //
- // Remember that we are no longer connected.
- //
- psInst->bConnected = false;
-}
-
-//*****************************************************************************
-//
-// This function is called by the USB device stack whenever the bus is put into
-// suspend state.
-//
-//*****************************************************************************
-static void
-HandleSuspend(void *pvInstance)
-{
- const tUSBDBulkDevice *psBulkDevice;
-
- ASSERT(pvInstance != 0);
-
- //
- // Create the instance pointer.
- //
- psBulkDevice = (const tUSBDBulkDevice *)pvInstance;
-
- //
- // Pass the event on to the client.
- //
- psBulkDevice->pfnRxCallback(psBulkDevice->pvRxCBData, USB_EVENT_SUSPEND, 0,
- (void *)0);
-}
-
-//*****************************************************************************
-//
-// This function is called by the USB device stack whenever the bus is taken
-// out of suspend state.
-//
-//*****************************************************************************
-static void
-HandleResume(void *pvInstance)
-{
- const tUSBDBulkDevice *psBulkDevice;
-
- ASSERT(pvInstance != 0);
-
- //
- // Create the instance pointer.
- //
- psBulkDevice = (const tUSBDBulkDevice *)pvInstance;
-
- //
- // Pass the event on to the client.
- //
- psBulkDevice->pfnRxCallback(psBulkDevice->pvRxCBData, USB_EVENT_RESUME, 0,
- (void *)0);
-}
-
-
-//*****************************************************************************
-//
-//! Initializes bulk device operation for a given USB controller.
-//!
-//! \param ulIndex is the index of the USB controller which is to be
-//! initialized for bulk device operation.
-//! \param psDevice points to a structure containing parameters customizing
-//! the operation of the bulk device.
-//!
-//! An application wishing to make use of a USB bulk communication channel
-//! must call this function to initialize the USB controller and attach the
-//! device to the USB bus. This function performs all required USB
-//! initialization.
-//!
-//! On successful completion, this function will return the \e psDevice pointer
-//! passed to it. This must be passed on all future calls to the device driver
-//! related to this device.
-//!
-//! The USBDBulk interface offers packet-based transmit and receive operation.
-//! If the application would rather use block based communication with
-//! transmit and receive buffers, USB buffers may be used above the bulk
-//! transmit and receive channels to offer this functionality.
-//!
-//! Transmit Operation:
-//!
-//! Calls to USBDBulkPacketWrite must send no more than 64 bytes of data at a
-//! time and may only be made when no other transmission is currently
-//! outstanding.
-//!
-//! Once a packet of data has been acknowledged by the USB host, a
-//! USB_EVENT_TX_COMPLETE event is sent to the application callback to inform
-//! it that another packet may be transmitted.
-//!
-//! Receive Operation:
-//!
-//! An incoming USB data packet will result in a call to the application
-//! callback with event USBD_EVENT_RX_AVAILABLE. The application must then
-//! call USBDBulkPacketRead(), passing a buffer capable of holding 64 bytes, to
-//! retrieve the data and acknowledge reception to the USB host.
-//!
-//! \note The application must not make any calls to the low level USB Device
-//! API if interacting with USB via the USB bulk device class API. Doing so
-//! will cause unpredictable (though almost certainly unpleasant) behavior.
-//!
-//! \return Returns NULL on failure or the psDevice pointer on success.
-//
-//*****************************************************************************
-void *
-USBDBulkInit(unsigned int ulIndex, const tUSBDBulkDevice *psDevice)
-{
- void *pvInstance;
-
- //
- // Check parameter validity.
- //
- ASSERT(ulIndex == 0);
- ASSERT(psDevice);
-
- pvInstance = USBDBulkCompositeInit(ulIndex, psDevice);
-
- if(pvInstance)
- {
- //
- // All is well so now pass the descriptors to the lower layer and put
- // the bulk device on the bus.
- //
- USBDCDInit(ulIndex, psDevice->psPrivateBulkData->psDevInfo);
- }
-
- //
- // Return the pointer to the instance indicating that everything went well.
- //
- return(pvInstance);
-}
-
-//*****************************************************************************
-//
-//! Initializes bulk device operation for a given USB controller.
-//!
-//! \param ulIndex is the index of the USB controller which is to be
-//! initialized for bulk device operation.
-//! \param psDevice points to a structure containing parameters customizing
-//! the operation of the bulk device.
-//!
-//! An application wishing to make use of a composite
-//! USB bulk communication channel needs to call this function.
-//! This function is used for initializing an instance related information of the
-//! bulk device.
-//!
-//! \return Returns zero on failure or a non-zero value that should be
-//! used with the remaining USB HID Bulk APIs.
-//
-//*****************************************************************************
-void *
-USBDBulkCompositeInit(unsigned int ulIndex, const tUSBDBulkDevice *psDevice)
-{
- tBulkInstance *psInst;
- tDeviceDescriptor *psDevDesc;
-
- //
- // Check parameter validity.
- //
- ASSERT(ulIndex == 0);
- ASSERT(psDevice);
- ASSERT(psDevice->ppStringDescriptors);
- ASSERT(psDevice->psPrivateBulkData);
- ASSERT(psDevice->pfnRxCallback);
- ASSERT(psDevice->pfnTxCallback);
-
- if(ulIndex == 0)
- {
- g_USBInstance[ulIndex].uiUSBInstance = ulIndex;
- g_USBInstance[ulIndex].uiBaseAddr = USB0_BASE;
- g_USBInstance[ulIndex].uiSubBaseAddr = USB_0_OTGBASE;
- g_USBInstance[ulIndex].uiInterruptNum = SYS_INT_USB0;
- g_USBInstance[ulIndex].uiSubInterruptNum = SYS_INT_USBSSINT;
- g_USBInstance[ulIndex].uiPHYConfigRegAddr = CFGCHIP2_USBPHYCTRL;
- }
-#if (USB_NUM_INSTANCE == 2)
- else if(ulIndex == 1)
- {
-
- g_USBInstance[ulIndex].uiUSBInstance = ulIndex;
- g_USBInstance[ulIndex].uiBaseAddr = USB1_BASE;
- g_USBInstance[ulIndex].uiSubBaseAddr = USB_1_OTGBASE;
- g_USBInstance[ulIndex].uiInterruptNum = SYS_INT_USB1;
- g_USBInstance[ulIndex].uiSubInterruptNum = SYS_INT_USBSSINT;
- g_USBInstance[ulIndex].uiPHYConfigRegAddr = CFGCHIP2_USB1PHYCTRL;
- }
-#endif
-
- //
- // Initialize the workspace in the passed instance structure.
- //
- psInst = psDevice->psPrivateBulkData;
- psInst->psConfDescriptor = (tConfigDescriptor *)g_pBulkDescriptor;
- psInst->psDevInfo = &g_sBulkDeviceInfo;
- psInst->ulUSBBase = g_USBInstance[ulIndex].uiBaseAddr;
- psInst->eBulkRxState = BULK_STATE_UNCONFIGURED;
- psInst->eBulkTxState = BULK_STATE_UNCONFIGURED;
- psInst->usDeferredOpFlags = 0;
- psInst->bConnected = false;
-
- //
- // Set the default endpoint and interface assignments.
- //
- psInst->ucINEndpoint = DATA_IN_ENDPOINT;
- psInst->ucOUTEndpoint = DATA_OUT_ENDPOINT;
- psInst->ucInterface = 0;
-
- //
- // Fix up the device descriptor with the client-supplied values.
- //
- psDevDesc = (tDeviceDescriptor *)psInst->psDevInfo->pDeviceDescriptor;
- psDevDesc->idVendor = psDevice->usVID;
- psDevDesc->idProduct = psDevice->usPID;
-
- //
- // Fix up the configuration descriptor with client-supplied values.
- //
- psInst->psConfDescriptor->bmAttributes = psDevice->ucPwrAttributes;
- psInst->psConfDescriptor->bMaxPower =
- (unsigned char)(psDevice->usMaxPowermA / 2);
-
- //
- // Plug in the client's string stable to the device information
- // structure.
- //
- psInst->psDevInfo->ppStringDescriptors = psDevice->ppStringDescriptors;
- psInst->psDevInfo->ulNumStringDescriptors
- = psDevice->ulNumStringDescriptors;
-
- //
- // Set the device instance.
- //
- psInst->psDevInfo->pvInstance = (void *)psDevice;
-
- //
- // Return the pointer to the instance indicating that everything went well.
- //
- return((void *)psDevice);
-}
-
-//*****************************************************************************
-//
-//! Shut down the bulk device.
-//!
-//! \param pvInstance is the pointer to the device instance structure as
-//! returned by USBDBulkInit().
-//!
-//! This function terminates device operation for the instance supplied and
-//! removes the device from the USB bus. This function should not be called
-//! if the bulk device is part of a composite device and instead the
-//! USBDCompositeTerm() function should be called for the full composite
-//! device.
-//!
-//! Following this call, the \e pvInstance instance should not me used in any
-//! other calls.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-USBDBulkTerm(void *pvInstance)
-{
- tBulkInstance *psInst;
- int index;
-
- ASSERT(pvInstance);
-
- //
- // Get a pointer to our instance data.
- //
- psInst = ((tUSBDBulkDevice *)pvInstance)->psPrivateBulkData;
-
- //
- // Terminate the requested instance.
- //
- USB_BASE_TO_INDEX(psInst->ulUSBBase, index);
- USBDCDTerm(index);
-
- psInst->ulUSBBase = 0;
- psInst->psDevInfo = (tDeviceInfo *)0;
- psInst->psConfDescriptor = (tConfigDescriptor *)0;
-
- return;
-}
-
-//*****************************************************************************
-//
-//! Sets the client-specific pointer parameter for the receive channel
-//! callback.
-//!
-//! \param pvInstance is the pointer to the device instance structure as
-//! returned by USBDBulkInit().
-//! \param pvCBData is the pointer that client wishes to be provided on each
-//! event sent to the receive channel callback function.
-//!
-//! The client uses this function to change the callback pointer passed in
-//! the first parameter on all callbacks to the \e pfnRxCallback function
-//! passed on USBDBulkInit().
-//!
-//! If a client wants to make runtime changes in the callback pointer, it must
-//! ensure that the \e pvInstance structure passed to USBDBulkInit() resides in
-//! RAM. If this structure is in flash, callback pointer changes will not be
-//! possible.
-//!
-//! \return Returns the previous callback pointer that was being used for
-//! this instance's receive callback.
-//
-//*****************************************************************************
-void *
-USBDBulkSetRxCBData(void *pvInstance, void *pvCBData)
-{
- void *pvOldValue;
-
- ASSERT(pvInstance);
-
- //
- // Set the callback data for the receive channel after remembering the
- // previous value.
- //
- pvOldValue = ((tUSBDBulkDevice *)pvInstance)->pvRxCBData;
- ((tUSBDBulkDevice *)pvInstance)->pvRxCBData = pvCBData;
-
- //
- // Return the previous callback pointer.
- //
- return (pvOldValue);
-}
-
-//*****************************************************************************
-//
-//! Sets the client-specific pointer parameter for the transmit callback.
-//!
-//! \param pvInstance is the pointer to the device instance structure as
-//! returned by USBDBulkInit().
-//! \param pvCBData is the pointer that client wishes to be provided on each
-//! event sent to the transmit channel callback function.
-//!
-//! The client uses this function to change the callback pointer passed in
-//! the first parameter on all callbacks to the \e pfnTxCallback function
-//! passed on USBDBulkInit().
-//!
-//! If a client wants to make runtime changes in the callback pointer, it must
-//! ensure that the \e pvInstance structure passed to USBDBulkInit() resides in
-//! RAM. If this structure is in flash, callback pointer changes will not be
-//! possible.
-//!
-//! \return Returns the previous callback pointer that was being used for
-//! this instance's transmit callback.
-//
-//*****************************************************************************
-void *
-USBDBulkSetTxCBData(void *pvInstance, void *pvCBData)
-{
- void *pvOldValue;
-
- ASSERT(pvInstance);
-
- //
- // Set the callback pointer for the transmit channel after remembering the
- // previous value.
- //
- pvOldValue = ((tUSBDBulkDevice *)pvInstance)->pvTxCBData;
- ((tUSBDBulkDevice *)pvInstance)->pvTxCBData = pvCBData;
-
- //
- // Return the previous callback pointer value.
- //
- return (pvOldValue);
-}
-
-//*****************************************************************************
-//
-//! Transmits a packet of data to the USB host via the bulk data interface.
-//!
-//! \param pvInstance is the pointer to the device instance structure as
-//! returned by USBDBulkInit().
-//! \param pcData points to the first byte of data which is to be transmitted.
-//! \param ulLength is the number of bytes of data to transmit.
-//! \param bLast indicates whether more data is to be written before a packet
-//! should be scheduled for transmission. If \b true, the client will make
-//! a further call to this function. If \b false, no further call will be
-//! made and the driver should schedule transmission of a short packet.
-//!
-//! This function schedules the supplied data for transmission to the USB
-//! host in a single USB packet. If no transmission is currently ongoing,
-//! the data is immediately copied to the relevant USB endpoint FIFO for
-//! transmission. Whenever a USB packet is acknowledged by the host, a
-//! USB_EVENT_TX_COMPLETE event will be sent to the transmit channel callback
-//! indicating that more data can now be transmitted.
-//!
-//! The maximum value for \e ulLength is 64 bytes (the maximum USB packet size
-//! for the bulk endpoints in use by the device). Attempts to send more data
-//! than this will result in a return code of 0 indicating that the data cannot
-//! be sent.
-//!
-//! The \e bLast parameter allows a client to make multiple calls to this
-//! function before scheduling transmission of the packet to the host. This
-//! can be helpful if, for example, constructing a packet on the fly or
-//! writing a packet which spans the wrap point in a ring buffer.
-//!
-//! \return Returns the number of bytes actually sent. At this level, this
-//! will either be the number of bytes passed (if less than or equal to the
-//! maximum packet size for the USB endpoint in use and no outstanding
-//! transmission ongoing) or 0 to indicate a failure.
-//
-//*****************************************************************************
-unsigned int
-USBDBulkPacketWrite(void *pvInstance, unsigned char *pcData,
- unsigned int ulLength, tBoolean bLast)
-{
- tBulkInstance *psInst;
- int iRetcode;
-
- ASSERT(pvInstance);
-
- //
- // Get our instance data pointer
- //
- psInst = ((tUSBDBulkDevice *)pvInstance)->psPrivateBulkData;
-
- //
- // Can we send the data provided?
- //
- if((ulLength > DATA_IN_EP_MAX_SIZE) ||
- (psInst->eBulkTxState != BULK_STATE_IDLE))
- {
- //
- // Either the packet was too big or we are in the middle of sending
- // another packet. Return 0 to indicate that we can't send this data.
- //
- return (0);
- }
-
- //
- // Copy the data into the USB endpoint FIFO.
- //
- iRetcode = USBEndpointDataPut(psInst->ulUSBBase, psInst->ucINEndpoint,
- pcData, ulLength);
-
- //
- // Did we copy the data successfully?
- //
- if(iRetcode != -1)
- {
- //
- // Remember how many bytes we sent.
- //
- psInst->usLastTxSize += (unsigned short)ulLength;
-
- //
- // If this is the last call for this packet, schedule transmission.
- //
- if(bLast)
- {
- //
- // Send the packet to the host if we have received all the data we
- // can expect for this packet.
- //
- psInst->eBulkTxState = BULK_STATE_WAIT_DATA;
- iRetcode = USBEndpointDataSend(psInst->ulUSBBase,
- psInst->ucINEndpoint, USB_TRANS_IN);
- }
- }
-
- //
- // Did an error occur while trying to send the data?
- //
- if(iRetcode != -1)
- {
- //
- // No - tell the caller we sent all the bytes provided.
- //
- return (ulLength);
- }
- else
- {
- //
- // Yes - tell the caller we couldn't send the data.
- //
- return (0);
- }
-}
-
-//*****************************************************************************
-//
-//! Reads a packet of data received from the USB host via the bulk data
-//! interface.
-//!
-//! \param pvInstance is the pointer to the device instance structure as
-//! returned by USBDBulkInit().
-//! \param pcData points to a buffer into which the received data will be
-//! written.
-//! \param ulLength is the size of the buffer pointed to by pcData.
-//! \param bLast indicates whether the client will make a further call to
-//! read additional data from the packet.
-//!
-//! This function reads up to \e ulLength bytes of data received from the USB
-//! host into the supplied application buffer. If the driver detects that the
-//! entire packet has been read, it is acknowledged to the host.
-//!
-//! The \e bLast parameter is ignored in this implementation since the end of
-//! a packet can be determined without relying upon the client to provide
-//! this information.
-//!
-//! \return Returns the number of bytes of data read.
-//
-//*****************************************************************************
-unsigned int
-USBDBulkPacketRead(void *pvInstance, unsigned char *pcData,
- unsigned int ulLength, tBoolean bLast)
-{
- unsigned int ulEPStatus, ulPkt;
- unsigned int ulCount;
- tBulkInstance *psInst;
- int iRetcode;
-
- ASSERT(pvInstance);
-
- //
- // Get our instance data pointer
- //
- psInst = ((tUSBDBulkDevice *)pvInstance)->psPrivateBulkData;
-
- //
- // Does the relevant endpoint FIFO have a packet waiting for us?
- //
- ulEPStatus = USBEndpointStatus(psInst->ulUSBBase, psInst->ucOUTEndpoint);
-
- if(ulEPStatus & USB_DEV_RX_PKT_RDY)
- {
- //
- // How many bytes are available for us to receive?
- //
- ulPkt = USBEndpointDataAvail(psInst->ulUSBBase, psInst->ucOUTEndpoint);
-
- //
- // Get as much data as we can.
- //
- ulCount = ulLength;
- iRetcode = USBEndpointDataGet(psInst->ulUSBBase, psInst->ucOUTEndpoint,
- pcData, &ulCount);
-
- //
- // Did we read the last of the packet data?
- //
- if(ulCount == ulPkt)
- {
- //
- // Clear the endpoint status so that we know no packet is
- // waiting.
- //
- USBDevEndpointStatusClear(psInst->ulUSBBase, psInst->ucOUTEndpoint,
- ulEPStatus);
-
- //
- // Acknowledge the data, thus freeing the host to send the
- // next packet.
- //
- USBDevEndpointDataAck(psInst->ulUSBBase, psInst->ucOUTEndpoint,
- true);
-
- //
- // Clear the flag we set to indicate that a packet read is
- // pending.
- //
- SetDeferredOpFlag(&psInst->usDeferredOpFlags, BULK_DO_PACKET_RX,
- false);
- }
-
- //
- // If all went well, tell the caller how many bytes they got.
- //
- if(iRetcode != -1)
- {
- return (ulCount);
- }
- }
-
- //
- // No packet was available or an error occurred while reading so tell
- // the caller no bytes were returned.
- //
- return (0);
-}
-
-//*****************************************************************************
-//
-//! Returns the number of free bytes in the transmit buffer.
-//!
-//! \param pvInstance is the pointer to the device instance structure as
-//! returned by USBDBulkInit().
-//!
-//! This function returns the maximum number of bytes that can be passed on a
-//! call to USBDBulkPacketWrite and accepted for transmission. The value
-//! returned will be the maximum USB packet size (64) if no transmission is
-//! currently outstanding or 0 if a transmission is in progress.
-//!
-//! \return Returns the number of bytes available in the transmit buffer.
-//
-//*****************************************************************************
-unsigned int
-USBDBulkTxPacketAvailable(void *pvInstance)
-{
- tBulkInstance *psInst;
-
- ASSERT(pvInstance);
-
- //
- // Get our instance data pointer.
- //
- psInst = ((tUSBDBulkDevice *)pvInstance)->psPrivateBulkData;
-
- //
- // Do we have a packet transmission currently ongoing?
- //
- if(psInst->eBulkTxState != BULK_STATE_IDLE)
- {
- //
- // We are not ready to receive a new packet so return 0.
- //
- return (0);
- }
- else
- {
- //
- // We can receive a packet so return the max packet size for the
- // relevant endpoint.
- //
- return (DATA_IN_EP_MAX_SIZE);
- }
-}
-
-//*****************************************************************************
-//
-//! Determines whether a packet is available and, if so, the size of the
-//! buffer required to read it.
-//!
-//! \param pvInstance is the pointer to the device instance structure as
-//! returned by USBDBulkInit().
-//!
-//! This function may be used to determine if a received packet remains to be
-//! read and allows the application to determine the buffer size needed to
-//! read the data.
-//!
-//! \return Returns 0 if no received packet remains unprocessed or the
-//! size of the packet if a packet is waiting to be read.
-//
-//*****************************************************************************
-unsigned int
-USBDBulkRxPacketAvailable(void *pvInstance)
-{
- unsigned int ulEPStatus;
- unsigned int ulSize;
- tBulkInstance *psInst;
-
- ASSERT(pvInstance);
-
- //
- // Get our instance data pointer
- //
- psInst = ((tUSBDBulkDevice *)pvInstance)->psPrivateBulkData;
-
- //
- // Does the relevant endpoint FIFO have a packet waiting for us?
- //
- ulEPStatus = USBEndpointStatus(psInst->ulUSBBase, psInst->ucOUTEndpoint);
-
- if(ulEPStatus & USB_DEV_RX_PKT_RDY)
- {
- //
- // Yes - a packet is waiting. How big is it?
- //
- ulSize = USBEndpointDataAvail(psInst->ulUSBBase, psInst->ucOUTEndpoint);
-
- return (ulSize);
- }
- else
- {
- //
- // There is no packet waiting to be received.
- //
- return (0);
- }
-}
-
-//*****************************************************************************
-//
-//! Reports the device power status (bus- or self-powered) to the USB library.
-//!
-//! \param pvInstance is the pointer to the bulk device instance structure.
-//! \param ucPower indicates the current power status, either \b
-//! USB_STATUS_SELF_PWR or \b USB_STATUS_BUS_PWR.
-//!
-//! Applications which support switching between bus- or self-powered
-//! operation should call this function whenever the power source changes
-//! to indicate the current power status to the USB library. This information
-//! is required by the USB library to allow correct responses to be provided
-//! when the host requests status from the device.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-USBDBulkPowerStatusSet(void *pvInstance, unsigned char ucPower)
-{
- ASSERT(pvInstance);
-
- //
- // Pass the request through to the lower layer.
- //
- USBDCDPowerStatusSet(0, ucPower);
-}
-
-//*****************************************************************************
-//
-//! Requests a remote wake up to resume communication when in suspended state.
-//!
-//! \param pvInstance is the pointer to the bulk device instance structure.
-//!
-//! When the bus is suspended, an application which supports remote wake up
-//! (advertised to the host via the configuration descriptor) may call this function
-//! to initiate remote wake up signaling to the host. If the remote wake up
-//! feature has not been disabled by the host, this will cause the bus to
-//! resume operation within 20mS. If the host has disabled remote wake up,
-//! \b false will be returned to indicate that the wake up request was not
-//! successful.
-//!
-//! \return Returns \b true if the remote wake up is not disabled and the
-//! signaling was started or \b false if remote wake up is disabled or if
-//! signaling is currently ongoing following a previous call to this function.
-//
-//*****************************************************************************
-tBoolean
-USBDBulkRemoteWakeupRequest(void *pvInstance)
-{
- ASSERT(pvInstance);
-
- //
- // Pass the request through to the lower layer.
- //
- return(USBDCDRemoteWakeupRequest(0));
-}
-
-//*****************************************************************************
-//
-// Close the Doxygen group.
-//! @}
-//
-//*****************************************************************************
diff --git a/SylixOS/StarterWare/usblib/device/usbdcdc.c b/SylixOS/StarterWare/usblib/device/usbdcdc.c
deleted file mode 100644
index 66f9138..0000000
--- a/SylixOS/StarterWare/usblib/device/usbdcdc.c
+++ /dev/null
@@ -1,3020 +0,0 @@
-//*****************************************************************************
-//
-// usbdcdc.c - USB CDC ACM (serial) device class driver.
-//
-// Copyright (c) 2008-2010 Texas Instruments Incorporated. All rights reserved.
-// Software License Agreement
-//
-// Texas Instruments (TI) is supplying this software for use solely and
-// exclusively on TI's microcontroller products. The software is owned by
-// TI and/or its suppliers, and is protected under applicable copyright
-// laws. You may not combine this software with "viral" open-source
-// software in order to form a larger program.
-//
-// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
-// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
-// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
-// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
-// DAMAGES, FOR ANY REASON WHATSOEVER.
-//
-// This is part of AM1808 StarterWare USB Library and reused from revision 6288
-// of the Stellaris USB Library.
-//
-//*****************************************************************************
-#include "hw_usb.h"
-#include "hw_types.h"
-#include "debug.h"
-#include "interrupt.h"
-#include "usb.h"
-#include "usblib.h"
-#include "usbdevice.h"
-#include "usbcdc.h"
-#include "usbdcdc.h"
-#include "usbdcomp.h"
-#include "usblibpriv.h"
-
-//*****************************************************************************
-//
-//! \addtogroup cdc_device_class_api
-//! @{
-//
-//*****************************************************************************
-
-//*****************************************************************************
-//
-// Some assumptions and deviations from the CDC specification
-// ----------------------------------------------------------
-//
-// 1. Although the CDC specification indicates that the following requests
-// should be supported by ACM CDC devices, these don't seem relevant to a
-// virtual COM port implementation and are never seen when connecting to a
-// Windows host and running either Hyperterminal or TeraTerm. As a result,
-// this implementation does not support them and stalls endpoint 0 if they are
-// received.
-// - SEND_ENCAPSULATED_COMMAND
-// - GET_ENCAPSULATED_RESPONSE
-// - SET_COMM_FEATURE
-// - GET_COMM_FEATURE
-// - CLEAR_COMM_FEATURE
-//
-// 2. The CDC specification is very clear on the fact that an ACM device
-// should offer two interfaces - a control interface offering an interrupt IN
-// endpoint and a data interface offering bulk IN and OUT endpoints. Using
-// this descriptor configuration, however, Windows insists on enumerating the
-// device as two separate entities resulting in two virtual COM ports or one
-// COM port and an Unknown Device (depending upon INF contents) appearing
-// in Device Manager. This implementation, derived by experimentation and
-// examination of other virtual COM and CDC solutions, uses only a single
-// interface combining all three endpoints. This appears to satisfy
-// Windows2000, XP and Vista and operates as intended using the Hyperterminal
-// and TeraTerm terminal emulators. Your mileage may vary with other
-// (untested) operating systems!
-//
-//*****************************************************************************
-
-//*****************************************************************************
-//
-// The subset of endpoint status flags that we consider to be reception
-// errors. These are passed to the client via USB_EVENT_ERROR if seen.
-//
-//*****************************************************************************
-#define USB_RX_ERROR_FLAGS (USBERR_DEV_RX_DATA_ERROR | \
- USBERR_DEV_RX_OVERRUN | \
- USBERR_DEV_RX_FIFO_FULL)
-
-//*****************************************************************************
-//
-// Size of the buffer to hold request-specific data read from the host. This
-// must be sized to accommodate the largest request structure that we intend
-// processing.
-//
-//*****************************************************************************
-#define MAX_REQUEST_DATA_SIZE sizeof(tLineCoding)
-
-//*****************************************************************************
-//This macro is used to diable the bit band operartion. Need to undefine this macro to use the
-// bit band operation.
-//***************************************************************************
-#define DISABLE_BIT_BAND
-
-//*****************************************************************************
-//
-// Flags that may appear in usDeferredOpFlags to indicate some operation that
-// has been requested but could not be processed at the time it was received.
-//
-//*****************************************************************************
-#define CDC_DO_SERIAL_STATE_CHANGE 0
-#define CDC_DO_SEND_BREAK 1
-#define CDC_DO_CLEAR_BREAK 2
-#define CDC_DO_LINE_CODING_CHANGE 3
-#define CDC_DO_LINE_STATE_CHANGE 4
-#define CDC_DO_PACKET_RX 5
-
-//*****************************************************************************
-//
-// The subset of deferred operations which result in the receive channel
-// being blocked.
-//
-//*****************************************************************************
-#define RX_BLOCK_OPS ((1 << CDC_DO_SEND_BREAK) | \
- (1 << CDC_DO_LINE_CODING_CHANGE) | \
- (1 << CDC_DO_LINE_STATE_CHANGE))
-
-//*****************************************************************************
-//
-// Macros to convert between USB controller base address and an index. These
-// are currently trivial but are included to allow for the possibility of
-// supporting more than one controller in the future.
-//
-//*****************************************************************************
-#if (USB_NUM_INSTANCE == 2)
-#define USB_BASE_TO_INDEX(BaseAddr, index) do{ \
- if(USB0_BASE==BaseAddr) \
- index = 0; \
- else if(USB1_BASE==BaseAddr) \
- index = 1; \
- else \
- index = -1; \
- }while(0)
-
-#define USB_INDEX_TO_BASE(Index, BaseAddr) ( \
- if(0==Index) \
- BaseAddr = USB0_BASE; \
- else if(1==Index) \
- BaseAddr = USB1_BASE; \
- else \
- BaseAddr = -1; \
- )
-#else
-#define USB_BASE_TO_INDEX(BaseAddr, index) do{ \
- if(USB0_BASE==BaseAddr) \
- index = 0; \
- else \
- index = -1; \
- }while(0)
-
-#define USB_INDEX_TO_BASE(Index, BaseAddr) ( \
- if(0==Index) \
- BaseAddr = USB0_BASE; \
- else \
- BaseAddr = -1; \
- )
-#endif
-
-//*****************************************************************************
-//
-// Endpoints to use for each of the required endpoints in the driver.
-//
-//*****************************************************************************
-#define CONTROL_ENDPOINT USB_EP_1
-#define DATA_IN_ENDPOINT USB_EP_2
-#define DATA_OUT_ENDPOINT USB_EP_1
-
-//*****************************************************************************
-//
-// The following are the USB interface numbers for the CDC serial device.
-//
-//*****************************************************************************
-#define SERIAL_INTERFACE_CONTROL 0
-#define SERIAL_INTERFACE_DATA 1
-
-//*****************************************************************************
-//
-// Maximum packet size for the bulk endpoints used for serial data
-// transmission and reception and the associated FIFO sizes to set aside
-// for each endpoint.
-//
-//*****************************************************************************
-#define DATA_IN_EP_FIFO_SIZE USB_FIFO_SZ_64
-#define DATA_OUT_EP_FIFO_SIZE USB_FIFO_SZ_64
-#define CTL_IN_EP_FIFO_SIZE USB_FIFO_SZ_16
-
-#define DATA_IN_EP_MAX_SIZE USB_FIFO_SZ_TO_BYTES(DATA_IN_EP_FIFO_SIZE)
-#define DATA_OUT_EP_MAX_SIZE USB_FIFO_SZ_TO_BYTES(DATA_IN_EP_FIFO_SIZE)
-#define CTL_IN_EP_MAX_SIZE USB_FIFO_SZ_TO_BYTES(CTL_IN_EP_FIFO_SIZE)
-
-//*****************************************************************************
-//
-// The collection of serial state flags indicating character errors.
-//
-//*****************************************************************************
-#define USB_CDC_SERIAL_ERRORS (USB_CDC_SERIAL_STATE_OVERRUN | \
- USB_CDC_SERIAL_STATE_PARITY | \
- USB_CDC_SERIAL_STATE_FRAMING)
-
-
-//*****************************************************************************
-//
-// USB instance Object
-//
-//*****************************************************************************
-extern tUSBInstanceObject g_USBInstance[];
-
-//*****************************************************************************
-//
-// Device Descriptor. This is stored in RAM to allow several fields to be
-// changed at runtime based on the client's requirements.
-//
-//*****************************************************************************
-unsigned char g_pCDCSerDeviceDescriptor[] =
-{
- 18, // Size of this structure.
- USB_DTYPE_DEVICE, // Type of this structure.
- USBShort(0x200), // USB version 1.1 (if we say 2.0, hosts assume
- // high-speed - see USB 2.0 spec 9.2.6.6)
- USB_CLASS_CDC, // USB Device Class (spec 5.1.1)
- 0, // USB Device Sub-class (spec 5.1.1)
- USB_CDC_PROTOCOL_NONE, // USB Device protocol (spec 5.1.1)
- 64, // Maximum packet size for default pipe.
- USBShort(0), // Vendor ID (filled in during USBDCDCInit).
- USBShort(0), // Product ID (filled in during USBDCDCInit).
- USBShort(0x100), // Device Version BCD.
- 1, // Manufacturer string identifier.
- 2, // Product string identifier.
- 3, // Product serial number.
- 1 // Number of configurations.
-};
-
-//*****************************************************************************
-//
-// CDC Serial configuration descriptor.
-//
-// It is vital that the configuration descriptor bConfigurationValue field
-// (byte 6) is 1 for the first configuration and increments by 1 for each
-// additional configuration defined here. This relationship is assumed in the
-// device stack for simplicity even though the USB 2.0 specification imposes
-// no such restriction on the bConfigurationValue values.
-//
-// Note that this structure is deliberately located in RAM since we need to
-// be able to patch some values in it based on client requirements.
-//
-//*****************************************************************************
-unsigned char g_pCDCSerDescriptor[] =
-{
- //
- // Configuration descriptor header.
- //
- 9, // Size of the configuration descriptor.
- USB_DTYPE_CONFIGURATION, // Type of this descriptor.
- USBShort(9), // The total size of this full structure, this
- // will be patched so it is just set to the
- // size of this structure.
- 2, // The number of interfaces in this
- // configuration.
- 1, // The unique value for this configuration.
- 5, // The string identifier that describes this
- // configuration.
- USB_CONF_ATTR_SELF_PWR, // Bus Powered, Self Powered, remote wake up.
- 250, // The maximum power in 2mA increments.
-};
-
-const tConfigSection g_sCDCSerConfigSection =
-{
- sizeof(g_pCDCSerDescriptor),
- g_pCDCSerDescriptor
-};
-
-//*****************************************************************************
-//
-// This is the Interface Association Descriptor for the serial device used in
-// composite devices.
-//
-//*****************************************************************************
-unsigned char g_pIADSerDescriptor[] =
-{
-
- 8, // Size of the interface descriptor.
- USB_DTYPE_INTERFACE_ASC, // Interface Association Type.
- 0x0, // Default starting interface is 0.
- 0x2, // Number of interfaces in this association.
- USB_CLASS_CDC, // The device class for this association.
- USB_CDC_SUBCLASS_ABSTRACT_MODEL, // The device subclass for this
- // association.
- USB_CDC_PROTOCOL_V25TER, // The protocol for this association.
- 0 // The string index for this association.
-};
-
-const tConfigSection g_sIADSerConfigSection =
-{
- sizeof(g_pIADSerDescriptor),
- g_pIADSerDescriptor
-};
-
-//*****************************************************************************
-//
-// This is the control interface for the serial device.
-//
-//*****************************************************************************
-const unsigned char g_pCDCSerCommInterface[] =
-{
- //
- // Communication Class Interface Descriptor.
- //
- 9, // Size of the interface descriptor.
- USB_DTYPE_INTERFACE, // Type of this descriptor.
- SERIAL_INTERFACE_CONTROL, // The index for this interface.
- 0, // The alternate setting for this interface.
- 1, // The number of endpoints used by this
- // interface.
- USB_CLASS_CDC, // The interface class constant defined by
- // USB-IF (spec 5.1.3).
- USB_CDC_SUBCLASS_ABSTRACT_MODEL, // The interface sub-class constant
- // defined by USB-IF (spec 5.1.3).
- USB_CDC_PROTOCOL_V25TER, // The interface protocol for the sub-class
- // specified above.
- 4, // The string index for this interface.
-
- //
- // Communication Class Interface Functional Descriptor - Header
- //
- 5, // Size of the functional descriptor.
- USB_CDC_CS_INTERFACE, // CDC interface descriptor
- USB_CDC_FD_SUBTYPE_HEADER, // Header functional descriptor
- USBShort(0x110), // Complies with CDC version 1.1
-
- //
- // Communication Class Interface Functional Descriptor - ACM
- //
- 4, // Size of the functional descriptor.
- USB_CDC_CS_INTERFACE, // CDC interface descriptor
- USB_CDC_FD_SUBTYPE_ABSTRACT_CTL_MGMT,
- USB_CDC_ACM_SUPPORTS_LINE_PARAMS | USB_CDC_ACM_SUPPORTS_SEND_BREAK,
-
- //
- // Communication Class Interface Functional Descriptor - Unions
- //
- 5, // Size of the functional descriptor.
- USB_CDC_CS_INTERFACE, // CDC interface descriptor
- USB_CDC_FD_SUBTYPE_UNION,
- SERIAL_INTERFACE_CONTROL,
- SERIAL_INTERFACE_DATA, // Data interface number
-
- //
- // Communication Class Interface Functional Descriptor - Call Management
- //
- 5, // Size of the functional descriptor.
- USB_CDC_CS_INTERFACE, // CDC interface descriptor
- USB_CDC_FD_SUBTYPE_CALL_MGMT,
- USB_CDC_CALL_MGMT_HANDLED,
- SERIAL_INTERFACE_DATA, // Data interface number
-
- //
- // Endpoint Descriptor (interrupt, IN)
- //
- 7, // The size of the endpoint descriptor.
- USB_DTYPE_ENDPOINT, // Descriptor type is an endpoint.
- USB_EP_DESC_IN | USB_EP_TO_INDEX(CONTROL_ENDPOINT),
- USB_EP_ATTR_INT, // Endpoint is an interrupt endpoint.
- USBShort(CTL_IN_EP_MAX_SIZE), // The maximum packet size.
- 10 // The polling interval for this endpoint.
-};
-
-const tConfigSection g_sCDCSerCommInterfaceSection =
-{
- sizeof(g_pCDCSerCommInterface),
- g_pCDCSerCommInterface
-};
-
-//*****************************************************************************
-//
-// This is the Data interface for the serial device.
-//
-//*****************************************************************************
-const unsigned char g_pCDCSerDataInterface[] =
-{
- //
- // Communication Class Data Interface Descriptor.
- //
- 9, // Size of the interface descriptor.
- USB_DTYPE_INTERFACE, // Type of this descriptor.
- SERIAL_INTERFACE_DATA, // The index for this interface.
- 0, // The alternate setting for this interface.
- 2, // The number of endpoints used by this
- // interface.
- USB_CLASS_CDC_DATA, // The interface class constant defined by
- // USB-IF (spec 5.1.3).
- 0, // The interface sub-class constant
- // defined by USB-IF (spec 5.1.3).
- USB_CDC_PROTOCOL_NONE, // The interface protocol for the sub-class
- // specified above.
- 0, // The string index for this interface.
-
- //
- // Endpoint Descriptor
- //
- 7, // The size of the endpoint descriptor.
- USB_DTYPE_ENDPOINT, // Descriptor type is an endpoint.
- USB_EP_DESC_IN | USB_EP_TO_INDEX(DATA_IN_ENDPOINT),
- USB_EP_ATTR_BULK, // Endpoint is a bulk endpoint.
- USBShort(DATA_IN_EP_MAX_SIZE), // The maximum packet size.
- 0, // The polling interval for this endpoint.
-
- //
- // Endpoint Descriptor
- //
- 7, // The size of the endpoint descriptor.
- USB_DTYPE_ENDPOINT, // Descriptor type is an endpoint.
- USB_EP_DESC_OUT | USB_EP_TO_INDEX(DATA_OUT_ENDPOINT),
- USB_EP_ATTR_BULK, // Endpoint is a bulk endpoint.
- USBShort(DATA_OUT_EP_MAX_SIZE), // The maximum packet size.
- 0, // The polling interval for this endpoint.
-};
-
-const tConfigSection g_sCDCSerDataInterfaceSection =
-{
- sizeof(g_pCDCSerDataInterface),
- g_pCDCSerDataInterface
-};
-
-//*****************************************************************************
-//
-// This array lists all the sections that must be concatenated to make a
-// single, complete CDC ACM configuration descriptor.
-//
-//*****************************************************************************
-const tConfigSection *g_psCDCSerSections[] =
-{
- &g_sCDCSerConfigSection,
- &g_sCDCSerCommInterfaceSection,
- &g_sCDCSerDataInterfaceSection,
-};
-
-#define NUM_CDCSER_SECTIONS (sizeof(g_psCDCSerSections) / \
- sizeof(tConfigSection *))
-
-//*****************************************************************************
-//
-// The header for the single configuration. This is the root of the data
-// structure that defines all the bits and pieces that are pulled together to
-// generate the configuration descriptor.
-//
-//*****************************************************************************
-const tConfigHeader g_sCDCSerConfigHeader =
-{
- NUM_CDCSER_SECTIONS,
- g_psCDCSerSections
-};
-
-//*****************************************************************************
-//
-// This array lists all the sections that must be concatenated to make a
-// single, complete CDC ACM configuration descriptor used in composite devices.
-// The only addition is the g_sIADSerConfigSection.
-//
-//*****************************************************************************
-const tConfigSection *g_psCDCCompSerSections[] =
-{
- &g_sCDCSerConfigSection,
- &g_sIADSerConfigSection,
- &g_sCDCSerCommInterfaceSection,
- &g_sCDCSerDataInterfaceSection,
-};
-
-#define NUM_COMP_CDCSER_SECTIONS (sizeof(g_psCDCCompSerSections) / \
- sizeof(tConfigSection *))
-
-//*****************************************************************************
-//
-// The header for the composite configuration. This is the root of the data
-// structure that defines all the bits and pieces that are pulled together to
-// generate the configuration descriptor.
-//
-//*****************************************************************************
-const tConfigHeader g_sCDCCompSerConfigHeader =
-{
- NUM_COMP_CDCSER_SECTIONS,
- g_psCDCCompSerSections
-};
-
-//*****************************************************************************
-//
-// Configuration Descriptor for the CDC serial class device.
-//
-//*****************************************************************************
-const tConfigHeader * const g_pCDCSerConfigDescriptors[] =
-{
- &g_sCDCSerConfigHeader
-};
-
-//*****************************************************************************
-//
-// Configuration Descriptor for the CDC serial class device used in a composite
-// device.
-//
-//*****************************************************************************
-const tConfigHeader * const g_pCDCCompSerConfigDescriptors[] =
-{
- &g_sCDCCompSerConfigHeader
-};
-
-//*****************************************************************************
-//
-// Forward references for device handler callbacks
-//
-//*****************************************************************************
-static void HandleRequests(void *pvInstance, tUSBRequest *pUSBRequest,
- unsigned int ulIndex);
-static void HandleConfigChange(void *pvInstance, unsigned int ulInfo,
- unsigned int ulIndex);
-static void HandleEP0Data(void *pvInstance, unsigned int ulDataSize,
- unsigned int ulIndex);
-static void HandleDisconnect(void *pvInstance);
-static void HandleEndpoints(void *pvInstance, unsigned int ulStatus,
- unsigned int ulIndex);
-static void HandleSuspend(void *pvInstance);
-static void HandleResume(void *pvInstance);
-static void HandleDevice(void *pvInstance, unsigned int ulRequest,
- void *pvRequestData);
-
-//*****************************************************************************
-//
-// The device information structure for the USB serial device.
-//
-//*****************************************************************************
-tDeviceInfo g_sCDCSerDeviceInfo =
-{
- //
- // Device event handler callbacks.
- //
- {
- //
- // GetDescriptor
- //
- 0,
-
- //
- // RequestHandler
- //
- HandleRequests,
-
- //
- // InterfaceChange
- //
- 0,
-
- //
- // ConfigChange
- //
- HandleConfigChange,
-
- //
- // DataReceived
- //
- HandleEP0Data,
-
- //
- // DataSentCallback
- //
- 0,
-
- //
- // ResetHandler
- //
- 0,
-
- //
- // SuspendHandler
- //
- HandleSuspend,
-
- //
- // ResumeHandler
- //
- HandleResume,
-
- //
- // DisconnectHandler
- //
- HandleDisconnect,
-
- //
- // EndpointHandler
- //
- HandleEndpoints,
-
- //
- // Device handler.
- //
- HandleDevice
- },
-
- //
- // The common device descriptor.
- //
- g_pCDCSerDeviceDescriptor,
-
- //
- // Default to no interrupt endpoint.
- //
- g_pCDCCompSerConfigDescriptors,
-
- //
- // String descriptors will be passed in.
- //
- 0,
- 0,
-
- //
- // Use the default USB FIFO configuration.
- //
- &g_sUSBDefaultFIFOConfig,
-
- //
- // Zero out the instance pointer by default.
- //
- 0
-};
-
-//*****************************************************************************
-//
-// Set or clear deferred operation flags in an "atomic" manner.
-//
-// \param pusDeferredOp points to the flags variable which is to be modified.
-// \param usBit indicates which bit number is to be set or cleared.
-// \param bSet indicates the state that the flag must be set to. If \b true,
-// the flag is set, if \b false, the flag is cleared.
-//
-// This function safely sets or clears a bit in a flag variable. The operation
-// makes use of bitbanding to ensure that the operation is atomic (no read-
-// modify-write is required).
-//
-// \return None.
-//
-//*****************************************************************************
-static void
-SetDeferredOpFlag(volatile unsigned short *pusDeferredOp,
- unsigned short usBit, tBoolean bSet)
-{
-#ifdef DISABLE_BIT_BAND
- if(bSet)
- {
- HWREG(pusDeferredOp) |= (1<<usBit);
- }
- else
- {
- HWREG(pusDeferredOp) &= ~(1<<usBit);
- }
-#else
- //
- // Set the flag bit to 1 or 0 using a bitband access.
- //
-
- HWREGBITH(pusDeferredOp, usBit) = bSet ? 1 : 0;
-#endif
-}
-
-//*****************************************************************************
-//
-// Determines whether or not a client has consumed all received data previously
-// passed to it.
-//
-//! \param psDevice is the pointer to the device instance structure as returned
-//! by USBDCDCInit().
-//
-// This function is called to determine whether or not a device has consumed
-// all data previously passed to it via its receive callback.
-//
-// \return Returns \b true on success or \b false on failure.
-//
-//*****************************************************************************
-static tBoolean
-DeviceConsumedAllData(const tUSBDCDCDevice *psDevice)
-{
- unsigned int ulRemaining;
-
- //
- // Send the device an event requesting that it tell us how many bytes
- // of data it still has to process.
- //
- ulRemaining = psDevice->pfnRxCallback(psDevice->pvRxCBData,
- USB_EVENT_DATA_REMAINING, 0, (void *)0);
-
- //
- // If any data remains to be processed, return false, else return true.
- //
- return (ulRemaining ? false : true);
-}
-
-//*****************************************************************************
-//
-// Notifies the client that it should set or clear a break condition.
-//
-// \param psDevice is the pointer to the device instance structure as returned
-// by USBDCDCInit().
-// \param bSend is \b true if a break condition is to be set or \b false if
-// it is to be cleared.
-//
-// This function is called to instruct the client to start or stop sending a
-// break condition on its serial transmit line.
-//
-// \return Returns \b true on success or \b false on failure.
-//
-//*****************************************************************************
-static void
-SendBreak(const tUSBDCDCDevice *psDevice, tBoolean bSend)
-{
- tCDCSerInstance *psInst;
-
- //
- // Get our instance data pointer.
- //
- psInst = psDevice->psPrivateCDCSerData;
-
- //
- // Set the break state flags as necessary. If we are turning the break on,
- // set the flag to tell ourselves that we need to notify the client when
- // it is time to turn it off again.
- //
- SetDeferredOpFlag(&psInst->usDeferredOpFlags, CDC_DO_SEND_BREAK, false);
- SetDeferredOpFlag(&psInst->usDeferredOpFlags, CDC_DO_CLEAR_BREAK, bSend);
-
- //
- // Tell the client to start or stop sending the break.
- //
- psDevice->pfnControlCallback(psDevice->pvControlCBData,
- (bSend ? USBD_CDC_EVENT_SEND_BREAK :
- USBD_CDC_EVENT_CLEAR_BREAK), 0,
- (void *)0);
-}
-
-//*****************************************************************************
-//
-// Notifies the client of a host request to set the serial communication
-// parameters.
-//
-// \param psDevice is the device instance whose communication parameters are to
-// be set.
-//
-// This function is called to notify the client when the host requests a change
-// in the serial communication parameters (baud rate, parity, number of bits
-// per character and number of stop bits) to use.
-//
-// \return None.
-//
-//*****************************************************************************
-static void
-SendLineCodingChange(const tUSBDCDCDevice *psDevice)
-{
- tCDCSerInstance *psInst;
-
- //
- // Get our instance data pointer.
- //
- psInst = psDevice->psPrivateCDCSerData;
-
- //
- // Clear the flag we use to tell ourselves that the line coding change has
- // yet to be notified to the client.
- //
- SetDeferredOpFlag(&psInst->usDeferredOpFlags, CDC_DO_LINE_CODING_CHANGE,
- false);
-
- //
- // Tell the client to update their serial line coding parameters.
- //
- psDevice->pfnControlCallback(psDevice->pvControlCBData,
- USBD_CDC_EVENT_SET_LINE_CODING, 0,
- &(psInst->sLineCoding));
-}
-
-//*****************************************************************************
-//
-// Notifies the client of a host request to set the RTS and DTR handshake line
-// states.
-//
-// \param psDevice is the device instance whose break condition is to be set or
-// cleared.
-//
-// This function is called to notify the client when the host requests a change
-// in the state of one or other of the RTS and DTR handshake lines.
-//
-// \return None.
-//
-//*****************************************************************************
-static void
-SendLineStateChange(const tUSBDCDCDevice *psDevice)
-{
- tCDCSerInstance *psInst;
-
- //
- // Get our instance data pointer.
- //
- psInst = psDevice->psPrivateCDCSerData;
-
- //
- // Clear the flag we use to tell ourselves that the line coding change has
- // yet to be notified to the client.
- //
- SetDeferredOpFlag(&psInst->usDeferredOpFlags, CDC_DO_LINE_STATE_CHANGE,
- false);
-
- //
- // Tell the client to update their serial line coding parameters.
- //
- psDevice->pfnControlCallback(psDevice->pvControlCBData,
- USBD_CDC_EVENT_SET_CONTROL_LINE_STATE,
- psInst->usControlLineState,
- (void *)0);
-}
-
-//*****************************************************************************
-//
-// Notifies the client of a break request if no data remains to be processed.
-//
-// \param psDevice is the device instance that is to be commanded to send a
-// break condition.
-//
-// This function is called when the host requests that the device set a break
-// condition on the serial transmit line. If no data received from the host
-// remains to be processed, the break request is passed to the control
-// callback. If data is outstanding, the call is ignored (with the operation
-// being retried on the next timer tick).
-//
-// \return Returns \b true if the break notification was sent, \b false
-// otherwise.
-//
-//*****************************************************************************
-static tBoolean
-CheckAndSendBreak(const tUSBDCDCDevice *psDevice, unsigned short usDuration)
-{
- tBoolean bCanSend;
-
- //
- // Has the client consumed all data received from the host yet?
- //
- bCanSend = DeviceConsumedAllData(psDevice);
-
- //
- // Can we send the break request?
- //
- if(bCanSend)
- {
- //
- // Pass the break request on to the client since no data remains to be
- // consumed.
- //
- SendBreak(psDevice, (usDuration ? true : false));
- }
-
- //
- // Tell the caller whether or not we sent the notification.
- //
- return (bCanSend);
-}
-
-//*****************************************************************************
-//
-// Notifies the client of a request to change the serial line parameters if no
-// data remains to be processed.
-//
-// \param psDevice is the device instance whose line coding parameters are to
-// be changed.
-//
-// This function is called when the host requests that the device change the
-// serial line coding parameters. If no data received from the host remains
-// to be processed, the request is passed to the control callback. If data is
-// outstanding, the call is ignored (with the operation being retried on the
-// next timer tick).
-//
-// \return Returns \b true if the notification was sent, \b false otherwise.
-//
-//*****************************************************************************
-static tBoolean
-CheckAndSendLineCodingChange(const tUSBDCDCDevice *psDevice)
-{
- tBoolean bCanSend;
-
- //
- // Has the client consumed all data received from the host yet?
- //
- bCanSend = DeviceConsumedAllData(psDevice);
-
- //
- // Can we send the break request?
- //
- if(bCanSend)
- {
- //
- // Pass the request on to the client since no data remains to be
- // consumed.
- //
- SendLineCodingChange(psDevice);
- }
-
- //
- // Tell the caller whether or not we sent the notification.
- //
- return (bCanSend);
-}
-
-//*****************************************************************************
-//
-// Notifies the client of a request to change the handshake line states if no
-// data remains to be processed.
-//
-// \param psDevice is the device instance whose handshake line states are to
-// be changed.
-//
-// This function is called when the host requests that the device change the
-// state of one or other of the RTS or DTR handshake lines. If no data
-// received from the host remains to be processed, the request is passed to
-// the control callback. If data is outstanding, the call is ignored (with
-// the operation being retried on the next timer tick).
-//
-// \return Returns \b true if the notification was sent, \b false otherwise.
-//
-//*****************************************************************************
-static tBoolean
-CheckAndSendLineStateChange(const tUSBDCDCDevice *psDevice)
-{
- tBoolean bCanSend;
-
- //
- // Has the client consumed all data received from the host yet?
- //
- bCanSend = DeviceConsumedAllData(psDevice);
-
- //
- // Can we send the break request?
- //
- if(bCanSend)
- {
- //
- // Pass the request on to the client since no data remains to be
- // consumed.
- //
- SendLineStateChange(psDevice);
- }
-
- //
- // Tell the caller whether or not we sent the notification.
- //
- return (bCanSend);
-}
-
-//*****************************************************************************
-//
-// Notifies the client of a change in the serial line state.
-//
-// \param psInst is the instance whose serial state is to be reported.
-//
-// This function is called to send the current serial state information to
-// the host via the the interrupt IN endpoint. This notification informs the
-// host of problems or conditions such as parity errors, breaks received,
-// framing errors, etc.
-//
-// \return Returns \b true on success or \b false on failure.
-//
-//*****************************************************************************
-static tBoolean
-SendSerialState(const tUSBDCDCDevice *psDevice)
-{
- tUSBRequest sRequest;
- unsigned short usSerialState;
- tCDCSerInstance *psInst;
- int iRetcode;
-
- //
- // Get a pointer to our instance data.
- //
- psInst = psDevice->psPrivateCDCSerData;
-
- //
- // Remember that we are in the middle of sending a notification.
- //
- psInst->eCDCInterruptState = CDC_STATE_WAIT_DATA;
-
- //
- // Clear the flag we use to indicate that a send is required.
- //
- SetDeferredOpFlag(&psInst->usDeferredOpFlags, CDC_DO_SERIAL_STATE_CHANGE,
- false);
- //
- // Take a snapshot of the serial state.
- //
- usSerialState = psInst->usSerialState;
-
- //
- // Build the request we will use to send the notification.
- //
- sRequest.bmRequestType = (USB_RTYPE_DIR_IN | USB_RTYPE_CLASS |
- USB_RTYPE_INTERFACE);
- sRequest.bRequest = USB_CDC_NOTIFY_SERIAL_STATE;
- sRequest.wValue = 0;
- sRequest.wIndex = 0;
- sRequest.wLength = USB_CDC_NOTIFY_SERIAL_STATE_SIZE;
-
- //
- // Write the request structure to the USB FIFO.
- //
- iRetcode = USBEndpointDataPut(psInst->ulUSBBase, psInst->ucControlEndpoint,
- (unsigned char *)&sRequest,
- sizeof(tUSBRequest));
- iRetcode = USBEndpointDataPut(psInst->ulUSBBase, psInst->ucControlEndpoint,
- (unsigned char *)&usSerialState,
- USB_CDC_NOTIFY_SERIAL_STATE_SIZE);
-
- //
- // Did we correctly write the data to the endpoint FIFO?
- //
- if(iRetcode != -1)
- {
- //
- // We put the data into the FIFO so now schedule it to be
- // sent.
- //
- iRetcode = USBEndpointDataSend(psInst->ulUSBBase,
- psInst->ucControlEndpoint,
- USB_TRANS_IN);
- }
-
- //
- // If an error occurred, mark the endpoint as idle (to prevent possible
- // lockup) and return an error.
- //
- if(iRetcode == -1)
- {
- psInst->eCDCInterruptState = CDC_STATE_IDLE;
- return (false);
- }
- else
- {
- //
- // Everything went fine. Clear the error bits that we just notified
- // and return true.
- //
- psInst->usSerialState &= ~(usSerialState & USB_CDC_SERIAL_ERRORS);
- return (true);
- }
-}
-
-//*****************************************************************************
-//
-// Receives notifications related to data received from the host.
-//
-// \param psDevice is the device instance whose endpoint is to be processed.
-// \param ulStatus is the USB interrupt status that caused this function to
-// be called.
-//
-// This function is called from HandleEndpoints for all interrupts signaling
-// the arrival of data on the bulk OUT endpoint (in other words, whenever the
-// host has sent us a packet of data). We inform the client that a packet
-// is available and, on return, check to see if the packet has been read. If
-// not, we schedule another notification to the client for a later time.
-//
-// \return Returns \b true on success or \b false on failure.
-//
-//*****************************************************************************
-tBoolean
-ProcessDataFromHost(const tUSBDCDCDevice *psDevice, unsigned int ulStatus,
- unsigned int ulIndex)
-{
- unsigned int ulEPStatus;
- unsigned int ulSize;
- tCDCSerInstance *psInst;
-
- //
- // Get a pointer to our instance data.
- //
- psInst = psDevice->psPrivateCDCSerData;
-
- //
- // Get the endpoint status to see why we were called.
- //
- ulEPStatus = USBEndpointStatus(psInst->ulUSBBase,
- psInst->ucBulkOUTEndpoint);
-
- //
- // Clear the status bits.
- //
- USBDevEndpointStatusClear(psInst->ulUSBBase, psInst->ucBulkOUTEndpoint,
- ulEPStatus);
-
- //
- // Has a packet been received?
- //
- if(ulEPStatus & USB_DEV_RX_PKT_RDY)
- {
- //
- // Set the flag we use to indicate that a packet read is pending. This
- // will be cleared if the packet is read. If the client doesn't read
- // the packet in the context of the USB_EVENT_RX_AVAILABLE callback,
- // the event will be notified later during tick processing.
- //
- SetDeferredOpFlag(&psInst->usDeferredOpFlags, CDC_DO_PACKET_RX, true);
-
- //
- // Is the receive channel currently blocked?
- //
- if(!psInst->bControlBlocked && !psInst->bRxBlocked)
- {
- //
- // How big is the packet we've just been sent?
- //
- ulSize = USBEndpointDataAvail(psInst->ulUSBBase,
- psInst->ucBulkOUTEndpoint);
-
- //
- // The receive channel is not blocked so let the caller know
- // that a packet is waiting. The parameters are set to indicate
- // that the packet has not been read from the hardware FIFO yet.
- //
- psDevice->pfnRxCallback(psDevice->pvRxCBData,
- USB_EVENT_RX_AVAILABLE, ulSize,
- (void *)0);
- }
-
-
- }
- else
- {
- //
- // No packet was received. Some error must have been reported. Check
- // and pass this on to the client if necessary.
- //
- if(ulEPStatus & USB_RX_ERROR_FLAGS)
- {
- //
- // This is an error we report to the client so...
- //
- psDevice->pfnRxCallback(psDevice->pvRxCBData,
- USB_EVENT_ERROR,
- (ulEPStatus & USB_RX_ERROR_FLAGS),
- (void *)0);
- }
-
- return (false);
- }
-
- return (true);
-}
-
-//*****************************************************************************
-//
-// Receives notifications related to interrupt messages sent to the host.
-//
-// \param psDevice is the device instance whose endpoint is to be processed.
-// \param ulStatus is the USB interrupt status that caused this function to
-// be called.
-//
-// This function is called from HandleEndpoints for all interrupts originating
-// from the interrupt IN endpoint (in other words, whenever a notification has
-// been transmitted to the USB host).
-//
-// \return Returns \b true on success or \b false on failure.
-//
-//*****************************************************************************
-tBoolean
-ProcessNotificationToHost(const tUSBDCDCDevice *psDevice,
- unsigned int ulStatus)
-{
- unsigned int ulEPStatus;
- tCDCSerInstance *psInst;
- tBoolean bRetcode;
-
- //
- // Assume all will go well until we have reason to believe otherwise.
- //
- bRetcode = true;
-
- //
- // Get a pointer to our instance data.
- //
- psInst = psDevice->psPrivateCDCSerData;
-
- //
- // Get the endpoint status to see why we were called.
- //
- ulEPStatus = USBEndpointStatus(psInst->ulUSBBase,
- psInst->ucControlEndpoint);
-
- //
- // Clear the status bits.
- //
- USBDevEndpointStatusClear(psInst->ulUSBBase,
- psInst->ucControlEndpoint, ulEPStatus);
-
- //
- // Did the state change while we were waiting for the previous notification
- // to complete?
- //
- if(psInst->usDeferredOpFlags & (1 << CDC_DO_SERIAL_STATE_CHANGE))
- {
- //
- // The state changed while we were waiting so we need to schedule
- // another notification immediately.
- //
- bRetcode = SendSerialState(psDevice);
- }
- else
- {
- //
- // Our last notification completed and we didn't have any new
- // notifications to make so the interrupt channel is now idle again.
- //
- psInst->eCDCInterruptState = CDC_STATE_IDLE;
- }
-
- //
- // Tell the caller how things went.
- //
- return (bRetcode);
-}
-
-//*****************************************************************************
-//
-// Receives notifications related to data sent to the host.
-//
-// \param psDevice is the device instance whose endpoint is to be processed.
-// \param ulStatus is the USB interrupt status that caused this function to
-// be called.
-//
-// This function is called from HandleEndpoints for all interrupts originating
-// from the bulk IN endpoint (in other words, whenever data has been
-// transmitted to the USB host). We examine the cause of the interrupt and,
-// if due to completion of a transmission, notify the client.
-//
-// \return Returns \b true on success or \b false on failure.
-//
-//*****************************************************************************
-tBoolean
-ProcessDataToHost(const tUSBDCDCDevice *psDevice, unsigned int ulStatus,
- unsigned int ulIndex)
-{
- tCDCSerInstance *psInst;
- unsigned int ulEPStatus, ulSize;
-
- //
- // Get a pointer to our instance data.
- //
- psInst = psDevice->psPrivateCDCSerData;
-
- //
- // Get the endpoint status to see why we were called.
- //
- ulEPStatus = USBEndpointStatus(psInst->ulUSBBase,
- psInst->ucBulkINEndpoint);
-
- //
- // Clear the status bits.
- //
- USBDevEndpointStatusClear(psInst->ulUSBBase,
- psInst->ucBulkINEndpoint, ulEPStatus);
-
- //
- // Our last transmission completed. Clear our state back to idle and
- // see if we need to send any more data.
- //
- psInst->eCDCTxState = CDC_STATE_IDLE;
-
- //
- // Notify the client that the last transmission completed.
- //
- ulSize = (unsigned int)psInst->usLastTxSize;
- psInst->usLastTxSize = 0;
- psDevice->pfnTxCallback(psDevice->pvTxCBData, USB_EVENT_TX_COMPLETE,
- ulSize, (void *)0);
-
- return (true);
-}
-
-//*****************************************************************************
-//
-// Called by the USB stack for any activity involving one of our endpoints
-// other than EP0. This function is a fan out that merely directs the call to
-// the correct handler depending upon the endpoint and transaction direction
-// signaled in ulStatus.
-//
-//*****************************************************************************
-static void
-HandleEndpoints(void *pvInstance, unsigned int ulStatus, unsigned int ulIndex)
-{
- const tUSBDCDCDevice *psDeviceInst;
- tCDCSerInstance *psInst;
-
- ASSERT(pvInstance != 0);
-
- //
- // Determine if the serial device is in single or composite mode because
- // the meaning of ulIndex is different in both cases.
- //
- psDeviceInst = pvInstance;
- psInst = psDeviceInst->psPrivateCDCSerData;
-
- //
- // Handler for the interrupt IN notification endpoint.
- //
- if(ulStatus & (1 << USB_EP_TO_INDEX(psInst->ucControlEndpoint)))
- {
- //
- // We have sent an interrupt notification to the host.
- //
- ProcessNotificationToHost(psDeviceInst, ulStatus);
- }
-
- //
- // Handler for the bulk OUT data endpoint.
- //
- if(ulStatus & (0x10000 << USB_EP_TO_INDEX(psInst->ucBulkOUTEndpoint)))
- {
- //
- // Data is being sent to us from the host.
- //
- ProcessDataFromHost(psDeviceInst, ulStatus, ulIndex);
- }
-
- //
- // Handler for the bulk IN data endpoint.
- //
- if(ulStatus & (1 << USB_EP_TO_INDEX(psInst->ucBulkINEndpoint)))
- {
- ProcessDataToHost(psDeviceInst, ulStatus, ulIndex);
- }
-}
-
-//*****************************************************************************
-//
-// Called by the USB stack whenever a configuration change occurs.
-//
-//*****************************************************************************
-static void
-HandleConfigChange(void *pvInstance, unsigned int ulInfo, unsigned int ulIndex)
-{
- tCDCSerInstance *psInst;
- const tUSBDCDCDevice *psDevice;
-
- ASSERT(pvInstance != 0);
-
- //
- // Create a device instance pointer.
- //
- psDevice = (const tUSBDCDCDevice *)pvInstance;
-
- //
- // Get a pointer to our instance data.
- //
- psInst = psDevice->psPrivateCDCSerData;
-
- //
- // Set all our endpoints to idle state.
- //
- psInst->eCDCInterruptState = CDC_STATE_IDLE;
- psInst->eCDCRequestState = CDC_STATE_IDLE;
- psInst->eCDCRxState = CDC_STATE_IDLE;
- psInst->eCDCTxState = CDC_STATE_IDLE;
-
- //
- // If we are not currently connected so let the client know we are open
- // for business.
- //
- if(!psInst->bConnected)
- {
- //
- // Pass the connected event to the client.
- //
- psDevice->pfnControlCallback(psDevice->pvControlCBData,
- USB_EVENT_CONNECTED, 0, (void *)0);
- }
-
- //
- // Remember that we are connected.
- //
- psInst->bConnected = true;
-}
-
-//*****************************************************************************
-//
-// USB data received callback.
-//
-// This function is called by the USB stack whenever any data requested from
-// EP0 is received.
-//
-//*****************************************************************************
-static void
-HandleEP0Data(void *pvInstance, unsigned int ulDataSize, unsigned int ulIndex)
-{
- const tUSBDCDCDevice *psDevice;
- tCDCSerInstance *psInst;
- tBoolean bRetcode;
-
- ASSERT(pvInstance != 0);
-
- //
- // Create a device instance pointer.
- //
- psDevice = (const tUSBDCDCDevice *)pvInstance;
-
- //
- // If we were not passed any data, just return.
- //
- if(ulDataSize == 0)
- {
- return;
- }
-
- //
- // Get our instance data pointer.
- //
- psInst = psDevice->psPrivateCDCSerData;
-
- //
- // Make sure we are actually expecting something.
- //
- if(psInst->eCDCRequestState != CDC_STATE_WAIT_DATA)
- {
- return;
- }
-
- //
- // Process the data received. This will be a request-specific data
- // block associated with the last request received.
- //
- switch (psInst->ucPendingRequest)
- {
- //
- // We just got the line coding structure. Make sure the client has
- // read all outstanding data then pass it back to initiate a change
- // in the line state.
- //
- case USB_CDC_SET_LINE_CODING:
- {
- if(ulDataSize != sizeof(tLineCoding))
- {
- USBDCDStallEP0(ulIndex);
- }
- else
- {
- //
- // Set the flag telling us that we need to send a line coding
- // notification to the client.
- //
- SetDeferredOpFlag(&psInst->usDeferredOpFlags,
- CDC_DO_LINE_CODING_CHANGE, true);
-
- //
- // See if we can send the notification immediately.
- //
- bRetcode = CheckAndSendLineCodingChange(psDevice);
-
- //
- // If we couldn't send the line coding change request to the
- // client, block reception of more data from the host until
- // previous data is processed and we send the change request.
- //
- if(!bRetcode)
- {
- psInst->bRxBlocked = true;
- }
- }
- break;
- }
-
- //
- // Oops - we seem to be waiting on a request which has not yet been
- // coded here. Flag the error and stall EP0 anyway (even though
- // this would indicate a coding error).
- //
- default:
- {
- USBDCDStallEP0(ulIndex);ASSERT(ulIndex);
- break;
- }
- }
-
- //
- // All is well. Set the state back to IDLE.
- //
- psInst->eCDCRequestState = CDC_STATE_IDLE;
-}
-
-//*****************************************************************************
-//
-// Device instance specific handler.
-//
-//*****************************************************************************
-static void
-HandleDevice(void *pvInstance, unsigned int ulRequest, void *pvRequestData)
-{
- tCDCSerInstance *psInst;
- unsigned char *pucData;
-
- //
- // Create the serial instance data.
- //
- psInst = ((tUSBDCDCDevice *)pvInstance)->psPrivateCDCSerData;
-
- //
- // Create the char array used by the events supported by the USB CDC
- // serial class.
- //
- pucData = (unsigned char *)pvRequestData;
-
- switch(ulRequest)
- {
- //
- // This was an interface change event.
- //
- case USB_EVENT_COMP_IFACE_CHANGE:
- {
- //
- // Save the change to the appropriate interface number.
- //
- if(pucData[0] == SERIAL_INTERFACE_CONTROL)
- {
- psInst->ucInterfaceControl = pucData[1];
- }
- else if(pucData[0] == SERIAL_INTERFACE_DATA)
- {
- psInst->ucInterfaceData = pucData[1];
- }
- break;
- }
-
- //
- // This was an endpoint change event.
- //
- case USB_EVENT_COMP_EP_CHANGE:
- {
- //
- // Determine if this is an IN or OUT endpoint that has changed.
- //
- if(pucData[0] & USB_EP_DESC_IN)
- {
- //
- // Determine which IN endpoint to modify.
- //
- if((pucData[0] & 0x7f) == USB_EP_TO_INDEX(CONTROL_ENDPOINT))
- {
- psInst->ucControlEndpoint =
- INDEX_TO_USB_EP((pucData[1] & 0x7f));
- }
- else
- {
- psInst->ucBulkINEndpoint =
- INDEX_TO_USB_EP((pucData[1] & 0x7f));
- }
- }
- else
- {
- //
- // Extract the new endpoint number.
- //
- psInst->ucBulkOUTEndpoint =
- INDEX_TO_USB_EP(pucData[1] & 0x7f);
- }
- break;
- }
-
- //
- // Handle class specific reconfiguring of the configuration descriptor
- // once the composite class has built the full descriptor.
- //
- case USB_EVENT_COMP_CONFIG:
- {
- //
- // This sets the bFirstInterface of the Interface Association
- // descriptor to the first interface which is the control
- // interface used by this instance.
- //
- pucData[2] = psInst->ucInterfaceControl;
-
- //
- // This sets the bMasterInterface of the Union descriptor to the
- // Control interface and the bSlaveInterface of the Union
- // Descriptor to the Data interface used by this instance.
- //
- pucData[29] = psInst->ucInterfaceControl;
- pucData[30] = psInst->ucInterfaceData;
-
- //
- // This sets the bDataInterface of the Union descriptor to the
- // Data interface used by this instance.
- pucData[35] = psInst->ucInterfaceData;
- break;
- }
-
- default:
- {
- break;
- }
- }
-}
-
-//*****************************************************************************
-//
-// USB non-standard request callback.
-//
-// This function is called by the USB stack whenever any non-standard request
-// is made to the device. The handler should process any requests that it
-// supports or stall EP0 in any unsupported cases.
-//
-//*****************************************************************************
-static void
-HandleRequests(void *pvInstance, tUSBRequest *pUSBRequest,
- unsigned int ulIndex)
-{
- const tUSBDCDCDevice *psDevice;
- tCDCSerInstance *psInst;
- tLineCoding sLineCoding;
- tBoolean bRetcode;
-
-
- ASSERT(pvInstance != 0);
-
- //
- // Create a device instance pointer.
- //
- psDevice = (const tUSBDCDCDevice *)pvInstance;
-
- //
- // Get our instance data pointer.
- //
- psInst = psDevice->psPrivateCDCSerData;
-
- //
- // Only handle requests meant for this interface.
- //
- if(pUSBRequest->wIndex != psInst->ucInterfaceControl)
- {
- return;
- }
-
- //
- // Handle each of the requests that we expect from the host.
- //
- switch(pUSBRequest->bRequest)
- {
- case USB_CDC_SEND_ENCAPSULATED_COMMAND:
- {
- //
- // This implementation makes use of no communication protocol so
- // this request is meaningless. We stall endpoint 0 if we receive
- // it.
- //
- USBDCDStallEP0(ulIndex);
- break;
- }
-
- case USB_CDC_GET_ENCAPSULATED_RESPONSE:
- {
- //
- // This implementation makes use of no communication protocol so
- // this request is meaningless. We stall endpoint 0 if we receive
- // it.
- //
- USBDCDStallEP0(ulIndex);
- break;
- }
-
- case USB_CDC_SET_COMM_FEATURE:
- {
- //
- // This request is apparently required by an ACM device but does
- // not appear relevant to a virtual COM port and is never used by
- // Windows (or, at least, is not seen when using Hyperterminal or
- // TeraTerm via a Windows virtual COM port). We stall endpoint 0
- // to indicate that we do not support the request.
- //
- USBDCDStallEP0(ulIndex);
- break;
- }
-
- case USB_CDC_GET_COMM_FEATURE:
- {
- //
- // This request is apparently required by an ACM device but does
- // not appear relevant to a virtual COM port and is never used by
- // Windows (or, at least, is not seen when using Hyperterminal or
- // TeraTerm via a Windows virtual COM port). We stall endpoint 0
- // to indicate that we do not support the request.
- //
- USBDCDStallEP0(ulIndex);
- break;
- }
-
- case USB_CDC_CLEAR_COMM_FEATURE:
- {
- //
- // This request is apparently required by an ACM device but does
- // not appear relevant to a virtual COM port and is never used by
- // Windows (or, at least, is not seen when using Hyperterminal or
- // TeraTerm via a Windows virtual COM port). We stall endpoint 0
- // to indicate that we do not support the request.
- //
- USBDCDStallEP0(ulIndex);
- break;
- }
-
- //
- // Set the serial communication parameters.
- //
- case USB_CDC_SET_LINE_CODING:
- {
- //
- // Remember the request we are processing.
- //
- psInst->ucPendingRequest = USB_CDC_SET_LINE_CODING;
-
- //
- // Set the state to indicate we are waiting for data.
- //
- psInst->eCDCRequestState = CDC_STATE_WAIT_DATA;
-
- //
- // Now read the payload of the request. We handle the actual
- // operation in the data callback once this data is received.
- //
- USBDCDRequestDataEP0(0, (unsigned char *)&psInst->sLineCoding,
- sizeof(tLineCoding));
-
- //
- // ACK what we have already received. We must do this after
- // requesting the data or we get into a race condition where the
- // data may return before we have set the stack state appropriately
- // to receive it.
- //
- USBDevEndpointDataAck(psInst->ulUSBBase, USB_EP_0, false);
-
- break;
- }
-
- //
- // Return the serial communication parameters.
- //
- case USB_CDC_GET_LINE_CODING:
- {
- //
- // ACK what we have already received
- //
- USBDevEndpointDataAck(psInst->ulUSBBase, USB_EP_0, false);
-
- //
- // Ask the client for the current line coding.
- //
- psDevice->pfnControlCallback(psDevice->pvControlCBData,
- USBD_CDC_EVENT_GET_LINE_CODING, 0,
- &sLineCoding);
- //
- // Send the line coding information back to the host.
- //
- USBDCDSendDataEP0(0, (unsigned char *)&sLineCoding,
- sizeof(tLineCoding));
-
- break;
- }
-
- case USB_CDC_SET_CONTROL_LINE_STATE:
- {
- //
- // ACK what we have already received
- //
- USBDevEndpointDataAck(psInst->ulUSBBase, USB_EP_0, false);
-
- //
- // Set the handshake lines as required.
- //
- psInst->usControlLineState = pUSBRequest->wValue;
-
- //
- // Remember that we are due to notify the client of a line
- // state change.
- //
- SetDeferredOpFlag(&psInst->usDeferredOpFlags,
- CDC_DO_LINE_STATE_CHANGE, true);
-
- //
- // See if we can notify now.
- //
- bRetcode = CheckAndSendLineStateChange(psDevice);
-
- //
- // If we couldn't send the line state change request to the
- // client, block reception of more data from the host until
- // previous data is processed and we send the change request.
- //
- if(!bRetcode)
- {
- psInst->bRxBlocked = true;
- }
-
- break;
- }
-
- case USB_CDC_SEND_BREAK:
- {
- //
- // ACK what we have already received
- //
- USBDevEndpointDataAck(psInst->ulUSBBase, USB_EP_0, false);
-
- //
- // Keep a copy of the requested break duration.
- //
- psInst->usBreakDuration = pUSBRequest->wValue;
-
- //
- // Remember that we need to send a break request.
- //
- SetDeferredOpFlag(&psInst->usDeferredOpFlags,
- CDC_DO_SEND_BREAK, true);
-
- //
- // Send the break request if all outstanding receive data has been
- // processed.
- //
- bRetcode = CheckAndSendBreak(psDevice, pUSBRequest->wValue);
-
- //
- // If we couldn't send the line coding change request to the
- // client, block reception of more data from the host until
- // previous data is processed and we send the change request.
- //
- if(!bRetcode)
- {
- psInst->bRxBlocked = true;
- }
-
- break;
- }
-
- //
- // These are valid CDC requests but not ones that an ACM device should
- // receive.
- //
- case USB_CDC_SET_AUX_LINE_STATE:
- case USB_CDC_SET_HOOK_STATE:
- case USB_CDC_PULSE_SETUP:
- case USB_CDC_SEND_PULSE:
- case USB_CDC_SET_PULSE_TIME:
- case USB_CDC_RING_AUX_JACK:
- case USB_CDC_SET_RINGER_PARMS:
- case USB_CDC_GET_RINGER_PARMS:
- case USB_CDC_SET_OPERATION_PARMS:
- case USB_CDC_GET_OPERATION_PARMS:
- case USB_CDC_SET_LINE_PARMS:
- case USB_CDC_GET_LINE_PARMS:
- case USB_CDC_DIAL_DIGITS:
- case USB_CDC_SET_UNIT_PARAMETER:
- case USB_CDC_GET_UNIT_PARAMETER:
- case USB_CDC_CLEAR_UNIT_PARAMETER:
- case USB_CDC_GET_PROFILE:
- case USB_CDC_SET_ETHERNET_MULTICAST_FILTERS:
- case USB_CDC_SET_ETHERNET_POWER_MANAGEMENT_PATTERN_FILTER:
- case USB_CDC_GET_ETHERNET_POWER_MANAGEMENT_PATTERN_FILTER:
- case USB_CDC_SET_ETHERNET_PACKET_FILTER:
- case USB_CDC_GET_ETHERNET_STATISTIC:
- case USB_CDC_SET_ATM_DATA_FORMAT:
- case USB_CDC_GET_ATM_DEVICE_STATISTICS:
- case USB_CDC_SET_ATM_DEFAULT_VC:
- case USB_CDC_GET_ATM_VC_STATISTICS:
- {
- USBDCDStallEP0(ulIndex);
- break;
- }
-
- default:
- {
- //
- // This request is not part of the CDC specification.
- //
- USBDCDStallEP0(ulIndex);
- break;
- }
- }
-}
-
-//*****************************************************************************
-//
-// This function is called by the USB device stack whenever the device is
-// disconnected from the host.
-//
-//*****************************************************************************
-static void
-HandleDisconnect(void *pvInstance)
-{
- const tUSBDCDCDevice *psCDCDevice;
- tCDCSerInstance *psInst;
-
- ASSERT(pvInstance != 0);
-
- //
- // Create the instance pointer.
- //
- psCDCDevice = (const tUSBDCDCDevice *)pvInstance;
-
- //
- // Get a pointer to our instance data.
- //
- psInst = psCDCDevice->psPrivateCDCSerData;
-
- //
- // If we are not currently connected and we have a control callback,
- // let the client know we are open for business.
- //
- if(psInst->bConnected)
- {
- //
- // Pass the disconnected event to the client.
- //
- psCDCDevice->pfnControlCallback(psCDCDevice->pvControlCBData,
- USB_EVENT_DISCONNECTED, 0, (void *)0);
- }
-
- //
- // Remember that we are no longer connected.
- //
- psInst->bConnected = false;
-}
-
-//*****************************************************************************
-//
-// This function is called by the USB device stack whenever the bus is put into
-// suspend state.
-//
-//*****************************************************************************
-static void
-HandleSuspend(void *pvInstance)
-{
- const tUSBDCDCDevice *psCDCDevice;
-
- ASSERT(pvInstance != 0);
-
- //
- // Create the instance pointer.
- //
- psCDCDevice = (const tUSBDCDCDevice *)pvInstance;
-
- //
- // Pass the event on to the client.
- //
- psCDCDevice->pfnControlCallback(psCDCDevice->pvControlCBData,
- USB_EVENT_SUSPEND, 0, (void *)0);
-}
-
-//*****************************************************************************
-//
-// This function is called by the USB device stack whenever the bus is taken
-// out of suspend state.
-//
-//*****************************************************************************
-static void
-HandleResume(void *pvInstance)
-{
- tUSBDCDCDevice *psCDCDevice;
-
- ASSERT(pvInstance != 0);
-
- //
- // Create the instance pointer.
- //
- psCDCDevice = (tUSBDCDCDevice *)pvInstance;
-
- //
- // Pass the event on to the client.
- //
- psCDCDevice->pfnControlCallback(psCDCDevice->pvControlCBData,
- USB_EVENT_RESUME, 0, (void *)0);
-}
-
-//*****************************************************************************
-//
-// This function is called periodically and provides us with a time reference
-// and method of implementing delayed or time-dependent operations.
-//
-// \param ulIndex is the index of the USB controller for which this tick
-// is being generated.
-// \param ulTimemS is the elapsed time in milliseconds since the last call
-// to this function.
-//
-// \return None.
-//
-//*****************************************************************************
-static void
-CDCTickHandler(void *pvInstance, unsigned int ulTimemS, unsigned int ulIndex)
-{
- tBoolean bCanSend;
- const tUSBDCDCDevice *psDevice;
- tCDCSerInstance *psInst;
- unsigned int ulSize;
-
- ASSERT(pvInstance != 0);
-
- //
- // Create the instance pointer.
- //
- psDevice = (const tUSBDCDCDevice *)pvInstance;
-
- //
- // Get our instance data pointer.
- //
- psInst = psDevice->psPrivateCDCSerData;
-
- //
- // Is there any outstanding operation that we should try to perform?
- //
- if(psInst->usDeferredOpFlags)
- {
- //
- // Yes - we have at least one deferred operation pending. First check
- // to see if it is time to turn off a break condition.
- //
- if(psInst->usDeferredOpFlags & (1 << CDC_DO_CLEAR_BREAK))
- {
- //
- // Will our break timer expire this time?
- //
- if(psInst->usBreakDuration <= ulTimemS)
- {
- //
- // Yes - turn off the break condition.
- //
- SendBreak(psDevice, false);
- }
- else
- {
- //
- // We have not timed out yet. Decrement the break timer.
- //
- psInst->usBreakDuration -= (unsigned short)ulTimemS;
- }
- }
-
- // Now check to see if the client has any data remaining to be
- // processed. This information is needed by the remaining deferred
- // operations which are waiting for the receive pipe to be emptied
- // before they can be carried out.
- //
- bCanSend = DeviceConsumedAllData(psDevice);
-
- //
- // Has all outstanding data been consumed?
- //
- if(bCanSend)
- {
- //
- // Yes - go ahead and notify the client of the various things
- // it has been asked to do while we waited for data to be
- // consumed.
- //
-
- //
- // Do we need to start sending a break condition?
- //
- if(psInst->usDeferredOpFlags & (1 << CDC_DO_SEND_BREAK))
- {
- SendBreak(psDevice, true);
- }
-
- //
- // Do we need to set the RTS/DTR states?
- //
- if(psInst->usDeferredOpFlags & (1 << CDC_DO_LINE_STATE_CHANGE))
- {
- SendLineStateChange(psDevice);
- }
-
- //
- // Do we need to change the line coding parameters?
- //
- if(psInst->usDeferredOpFlags & (1 << CDC_DO_LINE_CODING_CHANGE))
- {
- SendLineCodingChange(psDevice);
- }
-
- //
- // NOTE: We do not need to handle CDC_DO_SERIAL_STATE_CHANGE here
- // since this is handled in the transmission complete notification
- // for the control IN endpoint (ProcessNotificationToHost()).
- //
-
- //
- // If all the deferred operations which caused the receive channel
- // to be blocked are now handled, we can unblock receive and handle
- // any packet that is currently waiting to be received.
- //
- if(!(psInst->usDeferredOpFlags & RX_BLOCK_OPS))
- {
- //
- // We can remove the receive block.
- //
- psInst->bRxBlocked = false;
- }
- }
-
- //
- // Is the receive channel unblocked?
- //
- if(!psInst->bRxBlocked)
- {
- //
- // Do we have a deferred receive waiting
- //
- if(psInst->usDeferredOpFlags & (1 << CDC_DO_PACKET_RX))
- {
- //
- // Yes - how big is the waiting packet?
- //
- ulSize = USBEndpointDataAvail(psInst->ulUSBBase,
- psInst->ucBulkOUTEndpoint);
-
- // Tell the client that there is a packet waiting for it.
- //
- psDevice->pfnRxCallback(psDevice->pvRxCBData,
- USB_EVENT_RX_AVAILABLE, ulSize,
- (void *)0);
- }
- }
- }
-
- return;
-}
-
-//*****************************************************************************
-//
-//! Initializes CDC device operation when used with a composite device.
-//!
-//! \param ulIndex is the index of the USB controller in use.
-//! \param psCDCDevice points to a structure containing parameters customizing
-//! the operation of the CDC device.
-//!
-//! An application wishing to make use of a composite
-//! USB CDC communication channel needs to call this function.
-//! This function is used for initializing an instance related information of the
-//! CDC device.
-//!
-//! \return Returns NULL on failure or the psCDCDevice pointer on success.
-//
-//*****************************************************************************
-void *
-USBDCDCCompositeInit(unsigned int ulIndex, const tUSBDCDCDevice *psCDCDevice)
-{
- tCDCSerInstance *psInst;
- tDeviceDescriptor *psDevDesc;
-
- //
- // Check parameter validity.
- //
- ASSERT(ulIndex == 0);
- ASSERT(psCDCDevice);
- ASSERT(psCDCDevice->psPrivateCDCSerData);
- ASSERT(psCDCDevice->pfnControlCallback);
- ASSERT(psCDCDevice->pfnRxCallback);
- ASSERT(psCDCDevice->pfnTxCallback);
- if(ulIndex == 0)
- {
- g_USBInstance[ulIndex].uiUSBInstance = ulIndex;
- g_USBInstance[ulIndex].uiBaseAddr = USB0_BASE;
- g_USBInstance[ulIndex].uiSubBaseAddr = USB_0_OTGBASE;
- g_USBInstance[ulIndex].uiInterruptNum = SYS_INT_USB0;
- g_USBInstance[ulIndex].uiSubInterruptNum = SYS_INT_USBSSINT;
- g_USBInstance[ulIndex].uiPHYConfigRegAddr = CFGCHIP2_USBPHYCTRL;
- }
-#if (USB_NUM_INSTANCE == 2)
- else if(ulIndex == 1)
- {
- g_USBInstance[ulIndex].uiUSBInstance = ulIndex;
- g_USBInstance[ulIndex].uiBaseAddr = USB1_BASE;
- g_USBInstance[ulIndex].uiSubBaseAddr = USB_1_OTGBASE;
- g_USBInstance[ulIndex].uiInterruptNum = SYS_INT_USB1;
- g_USBInstance[ulIndex].uiSubInterruptNum = SYS_INT_USBSSINT;
- g_USBInstance[ulIndex].uiPHYConfigRegAddr = CFGCHIP2_USB1PHYCTRL;
- }
-#endif
-
- //
- // Create an instance pointer to the private data area.
- //
- psInst = psCDCDevice->psPrivateCDCSerData;
-
- //
- // Set the default endpoint and interface assignments.
- //
- psInst->ucBulkINEndpoint = DATA_IN_ENDPOINT;
- psInst->ucBulkOUTEndpoint = DATA_OUT_ENDPOINT;
- psInst->ucInterfaceControl = SERIAL_INTERFACE_CONTROL;
- psInst->ucInterfaceData = SERIAL_INTERFACE_DATA;
-
- //
- // By default do not use the interrupt control endpoint. The single
- // instance CDC serial device will turn this on in USBDCDCInit();
- //
- psInst->ucControlEndpoint = CONTROL_ENDPOINT;
-
- //
- // Initialize the workspace in the passed instance structure.
- //
- psInst->psConfDescriptor = (tConfigDescriptor *)g_pCDCSerDescriptor;
- psInst->psDevInfo = &g_sCDCSerDeviceInfo;
- psInst->ulUSBBase = g_USBInstance[ulIndex].uiBaseAddr;
- psInst->eCDCRxState = CDC_STATE_UNCONFIGURED;
- psInst->eCDCTxState = CDC_STATE_UNCONFIGURED;
- psInst->eCDCInterruptState = CDC_STATE_UNCONFIGURED;
- psInst->eCDCRequestState = CDC_STATE_UNCONFIGURED;
- psInst->ucPendingRequest = 0;
- psInst->usBreakDuration = 0;
- psInst->usSerialState = 0;
- psInst->usDeferredOpFlags = 0;
- psInst->usControlLineState = 0;
- psInst->bRxBlocked = false;
- psInst->bControlBlocked = false;
- psInst->bConnected = false;
-
- //
- // Fix up the device descriptor with the client-supplied values.
- //
- psDevDesc = (tDeviceDescriptor *)psInst->psDevInfo->pDeviceDescriptor;
- psDevDesc->idVendor = psCDCDevice->usVID;
- psDevDesc->idProduct = psCDCDevice->usPID;
-
- //
- // Fix up the configuration descriptor with client-supplied values.
- //
- psInst->psConfDescriptor->bmAttributes = psCDCDevice->ucPwrAttributes;
- psInst->psConfDescriptor->bMaxPower =
- (unsigned char)(psCDCDevice->usMaxPowermA / 2);
-
- //
- // Plug in the client's string stable to the device information
- // structure.
- //
- psInst->psDevInfo->ppStringDescriptors = psCDCDevice->ppStringDescriptors;
- psInst->psDevInfo->ulNumStringDescriptors
- = psCDCDevice->ulNumStringDescriptors;
-
- //
- // Register our tick handler (this must be done after USBDCDInit).
- //
- InternalUSBRegisterTickHandler(USB_TICK_HANDLER_DEVICE,
- CDCTickHandler,
- (void *)psCDCDevice);
-
- //
- // Return the pointer to the instance indicating that everything went well.
- //
- return((void *)psCDCDevice);
-}
-
-//*****************************************************************************
-//
-//! Initializes CDC device operation for a given USB controller.
-//!
-//! \param ulIndex is the index of the USB controller which is to be
-//! initialized for CDC device operation.
-//! \param psCDCDevice points to a structure containing parameters customizing
-//! the operation of the CDC device.
-//!
-//! An application wishing to make use of a USB CDC communication channel and
-//! appear as a virtual serial port on the host system must call this function
-//! to initialize the USB controller and attach the device to the USB bus.
-//! This function performs all required USB initialization.
-//!
-//! The value returned by this function is the \e psCDCDevice pointer passed
-//! to it if successful. This pointer must be passed to all later calls to the
-//! CDC class driver to identify the device instance.
-//!
-//! The USB CDC device class driver offers packet-based transmit and receive
-//! operation. If the application would rather use block based communication
-//! with transmit and receive buffers, USB buffers on the transmit and receive
-//! channels may be used to offer this functionality.
-//!
-//! Transmit Operation:
-//!
-//! Calls to USBDCDCPacketWrite() must send no more than 64 bytes of data at a
-//! time and may only be made when no other transmission is currently
-//! outstanding.
-//!
-//! Once a packet of data has been acknowledged by the USB host, a
-//! \b USB_EVENT_TX_COMPLETE event is sent to the application callback to
-//! inform it that another packet may be transmitted.
-//!
-//! Receive Operation:
-//!
-//! An incoming USB data packet will result in a call to the application
-//! callback with event \b USB_EVENT_RX_AVAILABLE. The application must then
-//! call USBDCDCPacketRead(), passing a buffer capable of holding the received
-//! packet to retrieve the data and acknowledge reception to the USB host. The
-//! size of the received packet may be queried by calling
-//! USBDCDCRxPacketAvailable().
-//!
-//! \note The application must not make any calls to the low level USB Device
-//! API if interacting with USB via the CDC device class API. Doing so
-//! will cause unpredictable (though almost certainly unpleasant) behavior.
-//!
-//! \return Returns NULL on failure or the psCDCDevice pointer on success.
-//
-//*****************************************************************************
-void *
-USBDCDCInit(unsigned int ulIndex, const tUSBDCDCDevice *psCDCDevice)
-{
- void *pvRet;
- tCDCSerInstance *psInst;
-
- //
- // Initialize the internal state for this class.
- //
- pvRet = USBDCDCCompositeInit(ulIndex, psCDCDevice);
-
- if(pvRet)
- {
- //
- // Create an instance pointer to the private data area.
- //
- psInst = psCDCDevice->psPrivateCDCSerData;
-
- //
- // Set the instance data for this device so that USBDCDInit() call can
- // have the instance data.
- //
- psInst->psDevInfo->pvInstance = (void *)psCDCDevice;
-
- //
- // Enable the default interrupt control endpoint if this class is not
- // being used in a composite device.
- //
- psInst->ucControlEndpoint = CONTROL_ENDPOINT;
-
- //
- // Use the configuration descriptor with the interrupt control endpoint.
- //
- psInst->psDevInfo->ppConfigDescriptors = g_pCDCSerConfigDescriptors;
-
- //
- // All is well so now pass the descriptors to the lower layer and put
- // the CDC device on the bus.
- //
- USBDCDInit(ulIndex, psInst->psDevInfo);
-
-
- }
-
- return(pvRet);
-}
-
-//*****************************************************************************
-//
-//! Shuts down the CDC device instance.
-//!
-//! \param pvInstance is the pointer to the device instance structure as returned
-//! by USBDCDCInit().
-//!
-//! This function terminates CDC operation for the instance supplied and
-//! removes the device from the USB bus. This function should not be called
-//! if the CDC device is part of a composite device and instead the
-//! USBDCompositeTerm() function should be called for the full composite
-//! device.
-//!
-//! Following this call, the \e pvInstance instance should not me used in any
-//! other calls.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-USBDCDCTerm(void *pvInstance)
-{
- tCDCSerInstance *psInst;
- int index;
-
- ASSERT(pvInstance);
-
- //
- // Get a pointer to our instance data.
- //
- psInst = ((tUSBDCDCDevice *)pvInstance)->psPrivateCDCSerData;
-
- //
- // Terminate the requested instance.
- //
- USB_BASE_TO_INDEX(psInst->ulUSBBase, index);
- USBDCDTerm(index);
-
- psInst->ulUSBBase = 0;
- psInst->psDevInfo = (tDeviceInfo *)0;
- psInst->psConfDescriptor = (tConfigDescriptor *)0;
-
- return;
-}
-
-//*****************************************************************************
-//
-//! Sets the client-specific pointer for the control callback.
-//!
-//! \param pvInstance is the pointer to the device instance structure as
-//! returned by USBDCDCInit().
-//! \param pvCBData is the pointer that client wishes to be provided on each
-//! event sent to the control channel callback function.
-//!
-//! The client uses this function to change the callback pointer passed in
-//! the first parameter on all callbacks to the \e pfnControlCallback function
-//! passed on USBDCDCInit().
-//!
-//! If a client wants to make runtime changes in the callback pointer, it must
-//! ensure that the psCDCDevice structure passed to USBDCDCInit() resides in
-//! RAM. If this structure is in flash, callback pointer changes will not be
-//! possible.
-//!
-//! \return Returns the previous callback pointer that was being used for
-//! this instance's control callback.
-//
-//*****************************************************************************
-void *
-USBDCDCSetControlCBData(void *pvInstance, void *pvCBData)
-{
- void *pvOldValue;
-
- ASSERT(pvInstance);
-
- //
- // Set the callback pointer for the control channel after remembering the
- // previous value.
- //
- pvOldValue = ((tUSBDCDCDevice *)pvInstance)->pvControlCBData;
- ((tUSBDCDCDevice *)pvInstance)->pvControlCBData = pvCBData;
-
- //
- // Return the previous callback data value.
- //
- return (pvOldValue);
-}
-
-//*****************************************************************************
-//
-//! Sets the client-specific data parameter for the receive channel callback.
-//!
-//! \param pvInstance is the pointer to the device instance structure as
-//! returned by USBDCDCInit().
-//! \param pvCBData is the pointer that client wishes to be provided on each
-//! event sent to the receive channel callback function.
-//!
-//! The client uses this function to change the callback pointer passed in
-//! the first parameter on all callbacks to the \e pfnRxCallback function
-//! passed on USBDCDCInit().
-//!
-//! If a client wants to make runtime changes in the callback pointer, it must
-//! ensure that the psCDCDevice structure passed to USBDCDCInit() resides in
-//! RAM. If this structure is in flash, callback data changes will not be
-//! possible.
-//!
-//! \return Returns the previous callback pointer that was being used for
-//! this instance's receive callback.
-//
-//*****************************************************************************
-void *
-USBDCDCSetRxCBData(void *pvInstance, void *pvCBData)
-{
- void *pvOldValue;
-
- ASSERT(pvInstance);
-
- //
- // Set the callback data for the receive channel after remembering the
- // previous value.
- //
- pvOldValue = ((tUSBDCDCDevice *)pvInstance)->pvRxCBData;
- ((tUSBDCDCDevice *)pvInstance)->pvRxCBData = pvCBData;
-
- //
- // Return the previous callback pointer.
- //
- return (pvOldValue);
-}
-
-//*****************************************************************************
-//
-//! Sets the client-specific data parameter for the transmit callback.
-//!
-//! \param pvInstance is the pointer to the device instance structure as
-//! returned by USBDCDCInit().
-//! \param pvCBData is the pointer that client wishes to be provided on each
-//! event sent to the transmit channel callback function.
-//!
-//! The client uses this function to change the callback pointer passed in
-//! the first parameter on all callbacks to the \e pfnTxCallback function
-//! passed on USBDCDCInit().
-//!
-//! If a client wants to make runtime changes in the callback pointer, it must
-//! ensure that the psCDCDevice structure passed to USBDCDCInit() resides in
-//! RAM. If this structure is in flash, callback data changes will not be
-//! possible.
-//!
-//! \return Returns the previous callback pointer that was being used for
-//! this instance's transmit callback.
-//
-//*****************************************************************************
-void *
-USBDCDCSetTxCBData(void *pvInstance, void *pvCBData)
-{
- void *pvOldValue;
-
- ASSERT(pvInstance);
-
- //
- // Set the callback data for the transmit channel after remembering the
- // previous value.
- //
- pvOldValue = ((tUSBDCDCDevice *)pvInstance)->pvTxCBData;
- ((tUSBDCDCDevice *)pvInstance)->pvTxCBData = pvCBData;
-
- //
- // Return the previous callback pointer.
- //
- return (pvOldValue);
-}
-
-//*****************************************************************************
-//
-//! Transmits a packet of data to the USB host via the CDC data interface.
-//!
-//! \param pvInstance is the pointer to the device instance structure as
-//! returned by USBDCDCInit().
-//! \param pcData points to the first byte of data which is to be transmitted.
-//! \param ulLength is the number of bytes of data to transmit.
-//! \param bLast indicates whether more data is to be written before a packet
-//! should be scheduled for transmission. If \b true, the client will make
-//! a further call to this function. If \b false, no further call will be
-//! made and the driver should schedule transmission of a short packet.
-//!
-//! This function schedules the supplied data for transmission to the USB
-//! host in a single USB packet. If no transmission is currently ongoing
-//! the data is immediately copied to the relevant USB endpoint FIFO. If the
-//! \e bLast parameter is \b true, the newly written packet is then scheduled
-//! for transmission. Whenever a USB packet is acknowledged by the host, a
-//! USB_EVENT_TX_COMPLETE event will be sent to the application transmit
-//! callback indicating that more data can now be transmitted.
-//!
-//! The maximum value for ulLength is 64 bytes (the maximum USB packet size
-//! for the bulk endpoints in use by CDC). Attempts to send more data than
-//! this will result in a return code of 0 indicating that the data cannot be
-//! sent.
-//!
-//! \return Returns the number of bytes actually sent. At this level, this
-//! will either be the number of bytes passed (if less than or equal to the
-//! maximum packet size for the USB endpoint in use and no outstanding
-//! transmission ongoing) or 0 to indicate a failure.
-//
-//*****************************************************************************
-unsigned int
-USBDCDCPacketWrite(void *pvInstance, unsigned char *pcData,
- unsigned int ulLength, tBoolean bLast)
-{
- tCDCSerInstance *psInst;
- int iRetcode;
-
- ASSERT(pvInstance);
-
- //
- // Get our instance data pointer
- //
- psInst = ((tUSBDCDCDevice *)pvInstance)->psPrivateCDCSerData;
-
- //
- // Can we send the data provided?
- //
- if((ulLength > DATA_IN_EP_MAX_SIZE) ||
- (psInst->eCDCTxState != CDC_STATE_IDLE))
- {
- //
- // Either the packet was too big or we are in the middle of sending
- // another packet. Return 0 to indicate that we can't send this data.
- //
- return (0);
- }
-
- //
- // Copy the data into the USB endpoint FIFO.
- //
- iRetcode = USBEndpointDataPut(psInst->ulUSBBase,
- psInst->ucBulkINEndpoint, pcData,
- ulLength);
-
- //
- // Did we copy the data successfully?
- //
- if(iRetcode != -1)
- {
- //
- // Remember how many bytes we sent.
- //
- psInst->usLastTxSize += (unsigned short)ulLength;
-
- //
- // If this is the last call for this packet, schedule transmission.
- //
- if(bLast)
- {
- //
- // Send the packet to the host if we have received all the data we
- // can expect for this packet.
- //
- psInst->eCDCTxState = CDC_STATE_WAIT_DATA;
- iRetcode = USBEndpointDataSend(psInst->ulUSBBase,
- psInst->ucBulkINEndpoint,
- USB_TRANS_IN);
- }
- }
-
- //
- // Did an error occur while trying to send the data?
- //
- if(iRetcode != -1)
- {
- //
- // No - tell the caller we sent all the bytes provided.
- //
- return (ulLength);
- }
- else
- {
- //
- // Yes - tell the caller we couldn't send the data.
- //
- return (0);
- }
-}
-
-//*****************************************************************************
-//
-//! Reads a packet of data received from the USB host via the CDC data
-//! interface.
-//!
-//! \param pvInstance is the pointer to the device instance structure as
-//! returned by USBDCDCInit().
-//! \param pcData points to a buffer into which the received data will be
-//! written.
-//! \param ulLength is the size of the buffer pointed to by pcData.
-//! \param bLast indicates whether the client will make a further call to
-//! read additional data from the packet.
-//!
-//! This function reads up to ulLength bytes of data received from the USB
-//! host into the supplied application buffer.
-//!
-//! \note The \e bLast parameter is ignored in this implementation since the
-//! end of a packet can be determined without relying upon the client to
-//! provide this information.
-//!
-//! \return Returns the number of bytes of data read.
-//
-//*****************************************************************************
-unsigned int
-USBDCDCPacketRead(void *pvInstance, unsigned char *pcData,
- unsigned int ulLength, tBoolean bLast)
-{
- unsigned int ulEPStatus, ulPkt;
- unsigned int ulCount;
- tCDCSerInstance *psInst;
- int iRetcode;
-
- ASSERT(pvInstance);
-
- //
- // Get our instance data pointer
- //
- psInst = ((tUSBDCDCDevice *)pvInstance)->psPrivateCDCSerData;
-
- //
- // Does the relevant endpoint FIFO have a packet waiting for us?
- //
- ulEPStatus = USBEndpointStatus(psInst->ulUSBBase,
- psInst->ucBulkOUTEndpoint);
-
- if(ulEPStatus & USB_DEV_RX_PKT_RDY)
- {
- //
- // If receive is currently blocked or the buffer we were passed is
- // (potentially) too small, set the flag telling us that we have a
- // packet waiting but return 0.
- //
- if(psInst->bRxBlocked || psInst->bControlBlocked)
- {
- SetDeferredOpFlag(&psInst->usDeferredOpFlags,
- CDC_DO_PACKET_RX, true);
- return (0);
- }
- else
- {
- //
- // It is OK to receive the new packet. How many bytes are
- // available for us to receive?
- //
- ulPkt = USBEndpointDataAvail(psInst->ulUSBBase,
- psInst->ucBulkOUTEndpoint);
-
- //
- // Get as much data as we can.
- //
- ulCount = ulLength;
- iRetcode = USBEndpointDataGet(psInst->ulUSBBase,
- psInst->ucBulkOUTEndpoint,
- pcData, &ulCount);
-
- //
- // Did we read the last of the packet data?
- //
- if(ulCount == ulPkt)
- {
- //
- // Clear the endpoint status so that we know no packet is
- // waiting.
- //
- USBDevEndpointStatusClear(psInst->ulUSBBase,
- psInst->ucBulkOUTEndpoint,
- ulEPStatus);
-
- //
- // Acknowledge the data, thus freeing the host to send the
- // next packet.
- //
- USBDevEndpointDataAck(psInst->ulUSBBase,
- psInst->ucBulkOUTEndpoint,
- true);
-
- //
- // Clear the flag we set to indicate that a packet read is
- // pending.
- //
- SetDeferredOpFlag(&psInst->usDeferredOpFlags,
- CDC_DO_PACKET_RX, false);
-
- }
-
- //
- // If all went well, tell the caller how many bytes they got.
- //
- if(iRetcode != -1)
- {
- return (ulCount);
- }
- }
- }
-
- //
- // No packet was available or an error occurred while reading so tell
- // the caller no bytes were returned.
- //
- return (0);
-}
-
-//*****************************************************************************
-//
-//! Returns the number of free bytes in the transmit buffer.
-//!
-//! \param pvInstance is the pointer to the device instance structure as
-//! returned by USBDCDCInit().
-//!
-//! This function returns the maximum number of bytes that can be passed on a
-//! call to USBDCDCPacketWrite and accepted for transmission. The value
-//! returned will be the maximum USB packet size (64) if no transmission is
-//! currently outstanding or 0 if a transmission is in progress.
-//!
-//! \return Returns the number of bytes available in the transmit buffer.
-//
-//*****************************************************************************
-unsigned int
-USBDCDCTxPacketAvailable(void *pvInstance)
-{
- tCDCSerInstance *psInst;
-
- ASSERT(pvInstance);
-
- //
- // Get our instance data pointer.
- //
- psInst = ((tUSBDCDCDevice *)pvInstance)->psPrivateCDCSerData;
-
- //
- // Do we have a packet transmission currently ongoing?
- //
- if(psInst->eCDCTxState != CDC_STATE_IDLE)
- {
- //
- // We are not ready to receive a new packet so return 0.
- //
- return (0);
- }
- else
- {
- //
- // We can receive a packet so return the max packet size for the
- // relevant endpoint.
- //
- return (DATA_IN_EP_MAX_SIZE);
- }
-}
-
-//*****************************************************************************
-//
-//! Determines whether a packet is available and, if so, the size of the
-//! buffer required to read it.
-//!
-//! \param pvInstance is the pointer to the device instance structure as
-//! returned by USBDCDCInit().
-//!
-//! This function may be used to determine if a received packet remains to be
-//! read and allows the application to determine the buffer size needed to
-//! read the data.
-//!
-//! \return Returns 0 if no received packet remains unprocessed or the
-//! size of the packet if a packet is waiting to be read.
-//
-//*****************************************************************************
-unsigned int
-USBDCDCRxPacketAvailable(void *pvInstance)
-{
- unsigned int ulEPStatus;
- unsigned int ulSize;
- tCDCSerInstance *psInst;
-
- ASSERT(pvInstance);
-
- //
- // Get our instance data pointer
- //
- psInst = ((tUSBDCDCDevice *)pvInstance)->psPrivateCDCSerData;
-
- //
- // If receive is currently blocked, return 0.
- //
- if(psInst->bRxBlocked || psInst->bControlBlocked)
- {
- return (0);
- }
-
- //
- // Does the relevant endpoint FIFO have a packet waiting for us?
- //
- ulEPStatus = USBEndpointStatus(psInst->ulUSBBase,
- psInst->ucBulkOUTEndpoint);
-
- if(ulEPStatus & USB_DEV_RX_PKT_RDY)
- {
- //
- // Yes - a packet is waiting. How big is it?
- //
- ulSize = USBEndpointDataAvail(psInst->ulUSBBase,
- psInst->ucBulkOUTEndpoint);
-
- return (ulSize);
- }
- else
- {
- //
- // There is no packet waiting to be received.
- //
- return (0);
- }
-}
-
-//*****************************************************************************
-//
-//! Informs the CDC module of changes in the serial control line states or
-//! receive error conditions.
-//!
-//! \param pvInstance is the pointer to the device instance structure as
-//! returned by USBDCDCInit().
-//! \param usState indicates the states of the various control lines and
-//! any receive errors detected. Bit definitions are as for the USB CDC
-//! SerialState asynchronous notification and are defined in header file
-//! usbcdc.h.
-//!
-//! The application should call this function whenever the state of any of
-//! the incoming RS232 handshake signals changes or in response to a receive
-//! error or break condition. The usState parameter is the ORed combination
-//! of the following flags with each flag indicating the presence of that
-//! condition.
-//!
-//! - USB_CDC_SERIAL_STATE_OVERRUN
-//! - USB_CDC_SERIAL_STATE_PARITY
-//! - USB_CDC_SERIAL_STATE_FRAMING
-//! - USB_CDC_SERIAL_STATE_RING_SIGNAL
-//! - USB_CDC_SERIAL_STATE_BREAK
-//! - USB_CDC_SERIAL_STATE_TXCARRIER
-//! - USB_CDC_SERIAL_STATE_RXCARRIER
-//!
-//! This function should be called only when the state of any flag changes.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-USBDCDCSerialStateChange(void *pvInstance, unsigned short usState)
-{
- tCDCSerInstance *psInst;
-
- ASSERT(pvInstance);
-
- //
- // Get our instance data pointer
- //
- psInst = ((tUSBDCDCDevice *)pvInstance)->psPrivateCDCSerData;
-
- //
- // Add the newly reported state bits to the current collection. We do this
- // in case two state changes occur back-to-back before the first has been
- // notified. There are two distinct types of signals that we report here
- // and we deal with them differently:
- //
- // 1. Errors (overrun, parity, framing error) are ORed together so that
- // any reported error is sent on the next notification.
- // 2. Signal line states (RI, break, TX carrier, RX carrier) always
- // report the last state notified to us. The implementation here will
- // send an interrupt showing the last state but, if two state changes
- // occur very quickly, the host may receive a notification containing
- // the same state that was last reported (in other words, a short pulse
- // will be lost). It would be possible to reduce the likelihood of
- // this happening by building a queue of state changes and sending
- // these in order but you are left with exactly the same problem if the
- // queue fills up. For now, therefore, we run the risk of missing very
- // short pulses on the "steady-state" signal lines.
- //
- psInst->usSerialState |= (usState & USB_CDC_SERIAL_ERRORS);
- psInst->usSerialState &= ~USB_CDC_SERIAL_ERRORS;
- psInst->usSerialState |= (usState & ~USB_CDC_SERIAL_ERRORS);
-
- //
- // Set the flag indicating that a serial state change is to be sent.
- //
- SetDeferredOpFlag(&psInst->usDeferredOpFlags, CDC_DO_SERIAL_STATE_CHANGE,
- true);
-
- //
- // Can we send the state change immediately?
- //
- if(psInst->eCDCInterruptState == CDC_STATE_IDLE)
- {
- //
- // The interrupt channel is free so send the notification immediately.
- // If we can't do this, the tick timer will catch this next time
- // round.
- //
- psInst->eCDCInterruptState = CDC_STATE_WAIT_DATA;
- SendSerialState(pvInstance);
- }
-
- return;
-}
-
-//*****************************************************************************
-//
-//! Reports the device power status (bus- or self-powered) to the USB library.
-//!
-//! \param pvInstance is the pointer to the CDC device instance structure.
-//! \param ucPower indicates the current power status, either \b
-//! USB_STATUS_SELF_PWR or \b USB_STATUS_BUS_PWR.
-//!
-//! Applications which support switching between bus- or self-powered
-//! operation should call this function whenever the power source changes
-//! to indicate the current power status to the USB library. This information
-//! is required by the USB library to allow correct responses to be provided
-//! when the host requests status from the device.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-USBDCDCPowerStatusSet(void *pvInstance, unsigned char ucPower)
-{
- ASSERT(pvInstance);
-
- //
- // Pass the request through to the lower layer.
- //
- USBDCDPowerStatusSet(0, ucPower);
-}
-
-//*****************************************************************************
-//
-//! Requests a remote wakeup to resume communication when in suspended state.
-//!
-//! \param pvInstance is the pointer to the CDC device instance structure.
-//!
-//! When the bus is suspended, an application which supports remote wakeup
-//! (advertised to the host via the config descriptor) may call this function
-//! to initiate remote wakeup signaling to the host. If the remote wakeup
-//! feature has not been disabled by the host, this will cause the bus to
-//! resume operation within 20mS. If the host has disabled remote wakeup,
-//! \b false will be returned to indicate that the wakeup request was not
-//! successful.
-//!
-//! \return Returns \b true if the remote wakeup is not disabled and the
-//! signaling was started or \b false if remote wakeup is disabled or if
-//! signaling is currently ongoing following a previous call to this function.
-//
-//*****************************************************************************
-tBoolean
-USBDCDCRemoteWakeupRequest(void *pvInstance)
-{
- ASSERT(pvInstance);
-
- //
- // Pass the request through to the lower layer.
- //
- return(USBDCDRemoteWakeupRequest(0));
-}
-
-//*****************************************************************************
-//
-// Close the Doxygen group.
-//! @}
-//
-//*****************************************************************************
diff --git a/SylixOS/StarterWare/usblib/device/usbdcdesc.c b/SylixOS/StarterWare/usblib/device/usbdcdesc.c
deleted file mode 100644
index e53ea67..0000000
--- a/SylixOS/StarterWare/usblib/device/usbdcdesc.c
+++ /dev/null
@@ -1,659 +0,0 @@
-//*****************************************************************************
-//
-// usbcdesc.c - Config descriptor parsing functions.
-//
-// Copyright (c) 2007-2010 Texas Instruments Incorporated. All rights reserved.
-// Software License Agreement
-//
-// Texas Instruments (TI) is supplying this software for use solely and
-// exclusively on TI's microcontroller products. The software is owned by
-// TI and/or its suppliers, and is protected under applicable copyright
-// laws. You may not combine this software with "viral" open-source
-// software in order to form a larger program.
-//
-// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
-// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
-// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
-// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
-// DAMAGES, FOR ANY REASON WHATSOEVER.
-//
-// This is part of AM1808 StarterWare USB Library and reused from revision 6288
-// of the Stellaris USB Library.
-//
-//*****************************************************************************
-
-#include "hw_types.h"
-#include "debug.h"
-#include "usb.h"
-#include "usblib.h"
-#include "usbdevice.h"
-
-//*****************************************************************************
-//
-// The functions in this file mirror the descriptor parsing APIs available
-// in usblib.h but parse config descriptors defined in terms of a list of
-// sections rather than as a single block of descriptor data.
-//
-//*****************************************************************************
-
-//*****************************************************************************
-//
-//! \addtogroup device_api
-//! @{
-//
-//*****************************************************************************
-
-//*****************************************************************************
-//
-//! \internal
-//!
-//! Walk to the next descriptor after the supplied one within a section-based
-//! config descriptor.
-//!
-//! \param psConfig points to the header structure for the configuration
-//! descriptor which contains \e psDesc.
-//! \param pulSec points to a variable containing the section within \e
-//! psConfig which contains \e psDesc.
-//! \param psDesc points to the descriptor that we want to step past.
-//!
-//! This function walks forward one descriptor within a config descriptor. The
-//! value returned is a pointer to the header of the next descriptor after the
-//! descriptor supplied in \e psDesc. If the next descriptor is in the next
-//! section, \e *pulSec will be incremented accordlingly.
-//!
-//! \return Returns a pointer to the next descriptor in the config descrptor.
-//
-//*****************************************************************************
-static tDescriptorHeader *
-NextConfigDescGet(const tConfigHeader *psConfig, unsigned int *pulSec,
- tDescriptorHeader *psDesc)
-{
- //
- // Determine where the next descriptor after the supplied one should be
- // assuming it is within the current section.
- //
- psDesc = NEXT_USB_DESCRIPTOR(psDesc);
-
- //
- // Did we run off the end of the section?
- //
- if((unsigned char *)psDesc >= (psConfig->psSections[*pulSec]->pucData +
- psConfig->psSections[*pulSec]->ucSize))
- {
- //
- // Yes - move to the next section.
- //
- (*pulSec)++;
-
- //
- // Are we still within the config descriptor?
- //
- if(*pulSec < psConfig->ucNumSections)
- {
- //
- // Yes - the new descriptor is at the start of the new section.
- //
- psDesc =
- (tDescriptorHeader *)psConfig->psSections[*pulSec]->pucData;
- }
- else
- {
- //
- // No - we ran off the end of the descriptor so return NULL.
- //
- psDesc = (tDescriptorHeader *)0;
- }
- }
-
- //
- // Return the new descriptor pointer.
- //
- return(psDesc);
-}
-
-//*****************************************************************************
-//
-//! \internal
-//!
-//! Returns a pointer to the n-th interface descriptor in a config descriptor
-//! with the supplied interface number.
-//!
-//! \param psConfig points to the header structure for the config descriptor
-//! that is to be searched.
-//! \param ucInterfaceNumber is the interface number of the descriptor that is
-//! being queried.
-//! \param ulIndex is the zero based index of the descriptor to return.
-//! \param pulSection points to storage which will be written with the index
-//! of the section containing the returned descriptor.
-//!
-//! This function returns a pointer to the n-th interface descriptor in the
-//! supplied configuration which has the requested interface number. It may be
-//! used by a client to retrieve the descriptors for each alternate setting
-//! of a given interface within the configuration passed.
-//!
-//! \return Returns a pointer to the n-th interface descriptor with interface
-//! number as specified or NULL of this descriptor does not exist.
-//
-//*****************************************************************************
-static tInterfaceDescriptor *
-ConfigAlternateInterfaceGet(const tConfigHeader *psConfig,
- unsigned char ucInterfaceNumber,
- unsigned int ulIndex,
- unsigned int *pulSection)
-{
- tDescriptorHeader *psDescCheck;
- unsigned int ulCount;
- unsigned int ulSec;
-
- //
- // Set up for our descriptor counting loop.
- //
- psDescCheck = (tDescriptorHeader *)psConfig->psSections[0]->pucData;
- ulCount = 0;
- ulSec = 0;
-
- //
- // Keep looking through the supplied data until we reach the end.
- //
- while(psDescCheck)
- {
- //
- // Does this descriptor match the type passed (if a specific type
- // has been specified)?
- //
- if((psDescCheck->bDescriptorType == USB_DTYPE_INTERFACE) &&
- (((tInterfaceDescriptor *)psDescCheck)->bInterfaceNumber ==
- ucInterfaceNumber))
- {
- //
- // This is an interface descriptor for interface ucInterfaceNumber.
- // Determine if this is the n-th one we have found and, if so,
- // return its pointer.
- //
- if(ulCount == ulIndex)
- {
- //
- // Found it - return the pointer and section number.
- //
- *pulSection = ulSec;
- return((tInterfaceDescriptor *)psDescCheck);
- }
-
- //
- // Increment our count of matching descriptors found and go back
- // to look for another since we have not yet reached the n-th
- // match.
- //
- ulCount++;
- }
-
- //
- // Move on to the next descriptor.
- //
- psDescCheck = NextConfigDescGet(psConfig, &ulSec, psDescCheck);
- }
-
- //
- // If we drop out the end of the loop, we did not find the requested
- // descriptor so return NULL.
- //
- return((tInterfaceDescriptor *)0);
-}
-
-//*****************************************************************************
-//
-//! \internal
-//!
-//! Determines the total length of a config descriptor defined in terms of a
-//! collection of concatenated sections.
-//!
-//! \param psConfig points to the header structure for the configuration
-//! descriptor whose size is to be determined.
-//!
-//! \return Returns the number of bytes in the config descriptor will result
-//! from concatenating the required sections.
-//
-//*****************************************************************************
-unsigned int
-USBDCDConfigDescGetSize(const tConfigHeader *psConfig)
-{
- unsigned int ulLoop;
- unsigned int ulLen;
-
- ulLen = 0;
-
- //
- // Determine the size of the whole descriptor by adding the sizes of
- // each section which will be concatenated to produce it.
- //
- for(ulLoop = 0; ulLoop < psConfig->ucNumSections; ulLoop++)
- {
- ulLen += psConfig->psSections[ulLoop]->ucSize;
- }
-
- return(ulLen);
-}
-
-//*****************************************************************************
-//
-//! \internal
-//!
-//! Determines the number of individual descriptors of a particular type within
-//! a supplied configuration descriptor.
-//!
-//! \param psConfig points to the header structure for the configuration
-//! descriptor that is to be searched.
-//! \param ulType identifies the type of descriptor that is to be counted. If
-//! the value is \b USB_DESC_ANY, the function returns the total number of
-//! descriptors regardless of type.
-//!
-//! This function can be used to count the number of descriptors of a
-//! particular type within a configuration descriptor. The caller can provide
-//! a specific type value which the function matches against the second byte
-//! of each descriptor or, alternatively, can specify \b USB_DESC_ANY to have
-//! the function count all descriptors regardless of their type.
-//!
-//! The search performed by this function traverses through the list of
-//! sections comprising the configuration descriptor. Note that the similar
-//! top-level function, USBDescGetNum(), searches through a single, contiguous
-//! block of data to perform the same enumeration.
-//!
-//! \return Returns the number of descriptors found in the supplied block of
-//! data.
-//
-//*****************************************************************************
-unsigned int
-USBDCDConfigDescGetNum(const tConfigHeader *psConfig, unsigned int ulType)
-{
- unsigned int ulSection;
- unsigned int ulNumDescs;
-
- //
- // Initialize our counts.
- //
- ulNumDescs = 0;
-
- //
- // Determine the number of descriptors of the given type in each of the
- // sections comprising the config descriptor. Note that this assumes each
- // section contains only whole descriptors!
- //
- for(ulSection = 0; ulSection < (unsigned int)psConfig->ucNumSections;
- ulSection++)
- {
- ulNumDescs += USBDescGetNum(
- (tDescriptorHeader *)psConfig->psSections[ulSection]->pucData,
- (unsigned int)psConfig->psSections[ulSection]->ucSize,
- ulType);
- }
-
- return(ulNumDescs);
-}
-
-//*****************************************************************************
-//
-//! \internal
-//!
-//! Finds the n-th descriptor of a particular type within the supplied
-//! configuration descriptor.
-//!
-//! \param psConfig points to the header structure for the configuration
-//! descriptor that is to be searched.
-//! \param ulType identifies the type of descriptor that is to be found. If
-//! the value is \b USB_DESC_ANY, the function returns a pointer to the n-th
-//! descriptor regardless of type.
-//! \param ulIndex is the zero based index of the descriptor whose pointer is
-//! to be returned. For example, passing value 1 in \e ulIndex returns the
-//! second matching descriptor.
-//! \param pulSection points to storage which will receive the section index
-//! containing the requested descriptor.
-//!
-//! Return a pointer to the n-th descriptor of a particular type found in the
-//! configuration descriptor passed.
-//!
-//! The search performed by this function traverses through the list of
-//! sections comprising the configuration descriptor. Note that the similar
-//! top-level function, USBDescGet(), searches through a single, contiguous
-//! block of data to perform the same enumeration.
-//!
-//! \return Returns a pointer to the header of the required descriptor if
-//! found or NULL otherwise.
-//
-//*****************************************************************************
-tDescriptorHeader *
-USBDCDConfigDescGet(const tConfigHeader *psConfig, unsigned int ulType,
- unsigned int ulIndex, unsigned int *pulSection)
-{
- unsigned int ulSection;
- unsigned int ulTotalDescs;
- unsigned int ulNumDescs;
-
- //
- // Initialize our counts.
- //
- ulTotalDescs = 0;
-
- //
- // Determine the number of descriptors of the given type in each of the
- // sections comprising the config descriptor. This allows us to determine
- // which section contains the descriptor we are being asked for.
- //
- for(ulSection = 0; ulSection < (unsigned int)psConfig->ucNumSections;
- ulSection++)
- {
- //
- // How many descriptors of the requested type exist in this section?
- //
- ulNumDescs = USBDescGetNum(
- (tDescriptorHeader *)psConfig->psSections[ulSection]->pucData,
- (unsigned int)psConfig->psSections[ulSection]->ucSize,
- ulType);
-
- //
- // Does this section contain the descriptor whose index we are looking
- // for?
- //
- if((ulTotalDescs + ulNumDescs) > ulIndex)
- {
- //
- // We know the requested descriptor exists in the current
- // block so write the section number to the caller's storage.
- //
- *pulSection = ulSection;
-
- //
- // Now find the actual descriptor requested and return its pointer.
- //
- return(USBDescGet(
- (tDescriptorHeader *)psConfig->psSections[ulSection]->pucData,
- (unsigned int)psConfig->psSections[ulSection]->ucSize,
- ulType,
- ulIndex - ulTotalDescs));
- }
-
- //
- // We have not found the required descriptor yet. Update our running
- // count of the number of type matches found so far then move on to
- // the next section.
- //
- ulTotalDescs += ulNumDescs;
- }
-
- //
- // If we drop out of the loop, we can't find the requested descriptor
- // so return NULL.
- //
- return((tDescriptorHeader *)0);
-}
-
-//*****************************************************************************
-//
-//! \internal
-//!
-//! Determines the number of different alternate configurations for a given
-//! interface within a config descriptor.
-//!
-//! \param psConfig points to the header structure for the configuration
-//! descriptor that is to be searched.
-//! \param ucInterfaceNumber is the interface number for which the number of
-//! alternate configurations is to be counted.
-//!
-//! This function can be used to count the number of alternate settings for a
-//! specific interface within a configuration.
-//!
-//! The search performed by this function traverses through the list of
-//! sections comprising the configuration descriptor. Note that the similar
-//! top-level function, USBDescGetNumAlternateInterfaces(), searches through
-//! a single, contiguous block of data to perform the same enumeration.
-//!
-//! \return Returns the number of alternate versions of the specified interface
-//! or 0 if the interface number supplied cannot be found in the config
-//! descriptor.
-//
-//*****************************************************************************
-unsigned int
-USBDCDConfigGetNumAlternateInterfaces(const tConfigHeader *psConfig,
- unsigned char ucInterfaceNumber)
-{
- tDescriptorHeader *psDescCheck;
- unsigned int ulCount;
- unsigned int ulSec;
-
- //
- // Set up for our descriptor counting loop.
- //
- psDescCheck = (tDescriptorHeader *)psConfig->psSections[0]->pucData;
- ulSec = 0;
- ulCount = 0;
-
- //
- // Keep looking through the supplied data until we reach the end.
- //
- while(psDescCheck)
- {
- //
- // Is this an interface descriptor with the required interface number?
- //
- if((psDescCheck->bDescriptorType == USB_DTYPE_INTERFACE) &&
- (((tInterfaceDescriptor *)psDescCheck)->bInterfaceNumber ==
- ucInterfaceNumber))
- {
- //
- // Yes - increment our count.
- //
- ulCount++;
- }
-
- //
- // Move on to the next descriptor.
- //
- psDescCheck = NextConfigDescGet(psConfig, &ulSec, psDescCheck);
- }
-
- //
- // Return the descriptor count to the caller.
- //
- return(ulCount);
-}
-
-//*****************************************************************************
-//
-//! \internal
-//!
-//! Returns a pointer to the n-th interface descriptor in a configuration
-//! descriptor that applies to the supplied alternate setting number.
-//!
-//! \param psConfig points to the header structure for the configuration
-//! descriptor that is to be searched.
-//! \param ulIndex is the zero based index of the interface that is to be
-//! found. If \e ulAlt is set to a value other than \b USB_DESC_ANY, this will
-//! be equivalent to the interface number being searched for.
-//! \param ulAlt is the alternate setting number which is to be
-//! searched for. If this value is \b USB_DESC_ANY, the alternate setting
-//! is ignored and all interface descriptors are considered in the search.
-//! \param pulSection points to storage which will receive the index of the
-//! config descriptor section which contains the requested interface
-//! descriptor.
-//!
-//! Return a pointer to the n-th interface descriptor found in the supplied
-//! configuration descriptor. If \e ulAlt is not \b USB_DESC_ANY, only
-//! interface descriptors which are part of the supplied alternate setting are
-//! considered in the search otherwise all interface descriptors are
-//! considered.
-//!
-//! Note that, although alternate settings can be applied on an interface-by-
-//! interface basis, the number of interfaces offered is fixed for a given
-//! config descriptor. Hence, this function will correctly find the unique
-//! interface descriptor for that interface's alternate setting number \e
-//! ulAlt if \e ulIndex is set to the required interface number and \e ulAlt
-//! is set to a valid alternate setting number for that interface.
-//!
-//! The search performed by this function traverses through the list of
-//! sections comprising the configuration descriptor. Note that the similar
-//! top-level function, USBDescGetInterface(), searches through a single,
-//! contiguous block of data to perform the same enumeration.
-//!
-//! \return Returns a pointer to the required interface descriptor if
-//! found or NULL otherwise.
-//
-//*****************************************************************************
-tInterfaceDescriptor *
-USBDCDConfigGetInterface(const tConfigHeader *psConfig, unsigned int ulIndex,
- unsigned int ulAlt, unsigned int *pulSection)
-{
- //
- // If we are being told to ignore the alternate configuration, this boils
- // down to a very simple query.
- //
- if(ulAlt == USB_DESC_ANY)
- {
- //
- // Return the ulIndex-th interface descriptor we find in the
- // configuration descriptor.
- //
- return((tInterfaceDescriptor *)USBDCDConfigDescGet(psConfig,
- USB_DTYPE_INTERFACE,
- ulIndex,
- pulSection));
- }
- else
- {
- //
- // In this case, a specific alternate setting number is required.
- // Given that interface numbers are zero based indices, we can
- // pass the supplied ulIndex parameter directly as the interface
- // number to USBDescGetAlternateInterface to retrieve the requested
- // interface descriptor pointer.
- //
- return(ConfigAlternateInterfaceGet(psConfig, ulIndex, ulAlt,
- pulSection));
- }
-}
-
-//*****************************************************************************
-//
-//! \internal
-//!
-//! Return a pointer to the n-th endpoint descriptor in a particular interface
-//! within a configuration descriptor.
-//!
-//! \param psConfig points to the header structure for the configuration
-//! descriptor that is to be searched.
-//! \param ulInterfaceNumber is the interface number whose endpoint is to be
-//! found.
-//! \param ulAltCfg is the alternate setting number which is to be searched
-//! for. This must be a valid alternate setting number for the requested
-//! interface.
-//! \param ulIndex is the zero based index of the endpoint that is to be
-//! found within the appropriate alternate setting for the interface.
-//!
-//! Return a pointer to the n-th endpoint descriptor found in the supplied
-//! interface descriptor. If the \e ulIndex parameter is invalid (greater
-//! than or equal to the bNumEndpoints field of the interface descriptor) or
-//! the endpoint cannot be found within \e ulSize bytes of the interface
-//! descriptor pointer, the function will return NULL.
-//!
-//! Note that, although the USB 2.0 specification states that endpoint
-//! descriptors must follow the interface descriptor that they relate to, it
-//! also states that device specific descriptors should follow any standard
-//! descriptor that they relate to. As a result, we cannot assume that each
-//! interface descriptor will be followed by nothing but an ordered list of
-//! its own endpoints and, hence, the function needs to be provided ulSize to
-//! limit the search range.
-//!
-//! The search performed by this function traverses through the list of
-//! sections comprising the configuration descriptor. Note that the similar
-//! top-level function, USBDescGetInterfaceEndpoint(), searches through a
-//! single, contiguous block of data to perform the same enumeration.
-//!
-//! \return Returns a pointer to the requested endpoint descriptor if
-//! found or NULL otherwise.
-//
-//*****************************************************************************
-tEndpointDescriptor *
-USBDCDConfigGetInterfaceEndpoint(const tConfigHeader *psConfig,
- unsigned int ulInterfaceNumber,
- unsigned int ulAltCfg, unsigned int ulIndex)
-{
- tInterfaceDescriptor *psInterface;
- tDescriptorHeader *psEndpoint;
- unsigned int ulSection;
- unsigned int ulCount;
-
- //
- // Find the requested interface descriptor.
- //
- psInterface = USBDCDConfigGetInterface(psConfig, ulInterfaceNumber,
- ulAltCfg, &ulSection);
-
- //
- // Did we find the requested interface?
- //
- if(psInterface)
- {
- //
- // Is the index passed valid?
- //
- if(ulIndex >= psInterface->bNumEndpoints)
- {
- //
- // It's out of bounds so return a NULL.
- //
- return((tEndpointDescriptor *)0);
- }
- else
- {
- //
- // Endpoint index is valid so find the descriptor. We start from
- // the interface descriptor and look for following endpoint
- // descriptors.
- //
- ulCount = 0;
- psEndpoint = (tDescriptorHeader *)psInterface;
-
- while(psEndpoint)
- {
- if(psEndpoint->bDescriptorType == USB_DTYPE_ENDPOINT)
- {
- //
- // We found an endpoint descriptor. Have we reached the
- // one we want?
- //
- if(ulCount == ulIndex)
- {
- //
- // Yes - return the descriptor pointer to the caller.
- //
- return((tEndpointDescriptor *)psEndpoint);
- }
-
- //
- // Move on to look for the next endpoint.
- //
- ulCount++;
- }
-
- //
- // Move to the next descriptor.
- //
- psEndpoint = NextConfigDescGet(psConfig, &ulSection,
- psEndpoint);
- }
- }
- }
-
- //
- // We couldn't find the requested interface or we got to the end of the
- // descriptor without finding the requested endpoint.
- //
- return((tEndpointDescriptor *)0);
-
-}
-
-//*****************************************************************************
-//
-// Close the Doxygen group.
-//! @}
-//
-//*****************************************************************************
diff --git a/SylixOS/StarterWare/usblib/device/usbdcomp.c b/SylixOS/StarterWare/usblib/device/usbdcomp.c
deleted file mode 100644
index e20602f..0000000
--- a/SylixOS/StarterWare/usblib/device/usbdcomp.c
+++ /dev/null
@@ -1,1196 +0,0 @@
-//****************************************************************************
-//
-// usbdcomp.c - USB composite device class driver.
-//
-// Copyright (c) 2010 Texas Instruments Incorporated. All rights reserved.
-// Software License Agreement
-//
-// Texas Instruments (TI) is supplying this software for use solely and
-// exclusively on TI's microcontroller products. The software is owned by
-// TI and/or its suppliers, and is protected under applicable copyright
-// laws. You may not combine this software with "viral" open-source
-// software in order to form a larger program.
-//
-// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
-// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
-// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
-// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
-// DAMAGES, FOR ANY REASON WHATSOEVER.
-//
-// This is part of AM1808 StarterWare USB Library and reused from revision 6288
-// of the Stellaris USB Library.
-//
-//****************************************************************************
-
-//#include "hw_memmap.h"
-#include "hw_types.h"
-#include "debug.h"
-#include "interrupt.h"
-//#include "sysctl.h"
-#include "usb.h"
-//#include "udma.h"
-#include "usblib.h"
-#include "usb-ids.h"
-#include "usbcdc.h"
-#include "usbdevice.h"
-#include "usbdcdc.h"
-#include "usbdcomp.h"
-#include "usblibpriv.h"
-
-//****************************************************************************
-//
-//! \addtogroup composite_device_class_api
-//! @{
-//
-//****************************************************************************
-
-//****************************************************************************
-//
-// Device Descriptor. This is stored in RAM to allow several fields to be
-// changed at runtime based on the client's requirements.
-//
-//****************************************************************************
-static unsigned char g_pCompDeviceDescriptor[] =
-{
- 18, // Size of this structure.
- USB_DTYPE_DEVICE, // Type of this structure.
- USBShort(0x110), // USB version 1.1 (if we say 2.0, hosts assume
- // high-speed - see USB 2.0 spec 9.2.6.6)
- USB_CLASS_MISC, // USB Device Class (spec 5.1.1)
- USB_MISC_SUBCLASS_COMMON, // USB Device Sub-class (spec 5.1.1)
- USB_MISC_PROTOCOL_IAD, // USB Device protocol (spec 5.1.1)
- 64, // Maximum packet size for default pipe.
- USBShort(0), // Vendor ID (filled in during USBDCompositeInit).
- USBShort(0), // Product ID (filled in during USBDCompositeInit).
- USBShort(0x100), // Device Version BCD.
- 1, // Manufacturer string identifier.
- 2, // Product string identifier.
- 3, // Product serial number.
- 1 // Number of configurations.
-};
-
-//****************************************************************************
-//
-// Composite class device configuration descriptor.
-//
-// It is vital that the configuration descriptor bConfigurationValue field
-// (byte 6) is 1 for the first configuration and increments by 1 for each
-// additional configuration defined here. This relationship is assumed in the
-// device stack for simplicity even though the USB 2.0 specification imposes
-// no such restriction on the bConfigurationValue values.
-//
-// Note that this structure is deliberately located in RAM since we need to
-// be able to patch some values in it based on client requirements.
-//
-//****************************************************************************
-static const unsigned char g_pCompConfigDescriptor[] =
-{
- //
- // Configuration descriptor header.
- //
- 9, // Size of the configuration descriptor.
- USB_DTYPE_CONFIGURATION, // Type of this descriptor.
- USBShort(0), // The total size of this full structure.
- 0, // The number of interfaces in this
- // configuration, this will be filled by
- // the class as it discovers all classes
- // supported.
- 1, // The unique value for this configuration.
- 0, // The string identifier that describes this
- // configuration.
- USB_CONF_ATTR_BUS_PWR, // .
- 250, // The maximum power in 2mA increments.
-};
-
-//****************************************************************************
-//
-// Various internal handlers needed by this class.
-//
-//****************************************************************************
-static void HandleDisconnect(void *pvInstance);
-static void InterfaceChange(void *pvInstance, unsigned char ucInterfaceNum,
- unsigned char ucAlternateSetting);
-static void ConfigChangeHandler(void *pvInstance, unsigned int ulValue,
- unsigned int ulIndex);
-static void DataSent(void *pvInstance, unsigned int ulInfo,
- unsigned int ulIndex);
-static void DataReceived(void *pvInstance, unsigned int ulInfo,
- unsigned int ulIndex);
-static void HandleEndpoints(void *pvInstance, unsigned int ulStatus,
- unsigned int ulIndex);
-static void HandleRequests(void *pvInstance, tUSBRequest *pUSBRequest,
- unsigned int ulIndex);
-static void SuspendHandler(void *pvInstance);
-static void ResumeHandler(void *pvInstance);
-static void ResetHandler(void *pvInstance);
-static void GetDescriptor(void *pvInstance, tUSBRequest *pUSBRequest,
- unsigned int ulIndex);
-
-//****************************************************************************
-//
-// Configuration Descriptor.
-//
-//****************************************************************************
-tConfigHeader *g_pCompConfigDescriptors[1];
-
-//****************************************************************************
-//
-// The FIFO configuration for USB mass storage class device.
-//
-//****************************************************************************
-tFIFOConfig g_sUSBCompositeFIFOConfig =
-{
- //
- // IN endpoints.
- //
- {
- { 1, false, USB_EP_DEV_IN },
- { 1, false, USB_EP_DEV_IN },
- { 1, false, USB_EP_DEV_IN },
- { 1, false, USB_EP_DEV_IN },
- { 1, false, USB_EP_DEV_IN },
- { 1, false, USB_EP_DEV_IN },
- { 1, false, USB_EP_DEV_IN },
- { 1, false, USB_EP_DEV_IN },
- { 1, false, USB_EP_DEV_IN },
- { 1, false, USB_EP_DEV_IN },
- { 1, false, USB_EP_DEV_IN },
- { 1, false, USB_EP_DEV_IN },
- { 1, false, USB_EP_DEV_IN },
- { 1, false, USB_EP_DEV_IN },
- { 1, false, USB_EP_DEV_IN }
- },
- //
- // OUT endpoints.
- //
- {
- { 1, false, USB_EP_DEV_OUT },
- { 1, false, USB_EP_DEV_OUT },
- { 1, false, USB_EP_DEV_OUT },
- { 1, false, USB_EP_DEV_OUT },
- { 1, false, USB_EP_DEV_OUT },
- { 1, false, USB_EP_DEV_OUT },
- { 1, false, USB_EP_DEV_OUT },
- { 1, false, USB_EP_DEV_OUT },
- { 1, false, USB_EP_DEV_OUT },
- { 1, false, USB_EP_DEV_OUT },
- { 1, false, USB_EP_DEV_OUT },
- { 1, false, USB_EP_DEV_OUT },
- { 1, false, USB_EP_DEV_OUT },
- { 1, false, USB_EP_DEV_OUT },
- { 1, false, USB_EP_DEV_OUT }
- },
-};
-
-//****************************************************************************
-//
-// The device information structure for the USB Composite device.
-//
-//****************************************************************************
-tDeviceInfo g_sCompositeDeviceInfo =
-{
- //
- // Device event handler callbacks.
- //
- {
- //
- // GetDescriptor
- //
- GetDescriptor,
-
- //
- // RequestHandler
- //
- HandleRequests,
-
- //
- // InterfaceChange
- //
- InterfaceChange,
-
- //
- // ConfigChange
- //
- ConfigChangeHandler,
-
- //
- // DataReceived
- //
- DataReceived,
-
- //
- // DataSentCallback
- //
- DataSent,
-
- //
- // ResetHandler
- //
- ResetHandler,
-
- //
- // SuspendHandler
- //
- SuspendHandler,
-
- //
- // ResumeHandler
- //
- ResumeHandler,
-
- //
- // DisconnectHandler
- //
- HandleDisconnect,
-
- //
- // EndpointHandler
- //
- HandleEndpoints
- },
- g_pCompDeviceDescriptor,
- (const tConfigHeader **)g_pCompConfigDescriptors,
- 0,
- 0,
- &g_sUSBCompositeFIFOConfig
-};
-
-//****************************************************************************
-//
-// This function will check if any device classes need a get descriptor
-// handler called.
-//
-//****************************************************************************
-static void
-GetDescriptor(void *pvInstance, tUSBRequest *pUSBRequest, unsigned int ulIndex)
-{
- unsigned int ulIdx;
- const tDeviceInfo *pDeviceInfo;
- tUSBDCompositeDevice *psDevice;
-
- //
- // Create the device instance pointer.
- //
- psDevice = (tUSBDCompositeDevice *)pvInstance;
-
- for(ulIdx = 0; ulIdx < psDevice->ulNumDevices; ulIdx++)
- {
- //
- // Create the individual device pointer.
- //
- pDeviceInfo = psDevice->psDevices[ulIdx].psDevice;
-
- if(pDeviceInfo->sCallbacks.pfnGetDescriptor)
- {
- pDeviceInfo->sCallbacks.pfnGetDescriptor(
- psDevice->psDevices[ulIdx].pvInstance, pUSBRequest, ulIndex);
- }
- }
-}
-
-//****************************************************************************
-//
-// This function will check if any device classes need an suspend handler
-// called.
-//
-//****************************************************************************
-static void
-SuspendHandler(void *pvInstance)
-{
- unsigned int ulIdx;
- tUSBDCompositeDevice *psDevice;
- const tDeviceInfo *pDeviceInfo;
- void *pvDeviceInst;
-
- ASSERT(pvInstance != 0);
-
- //
- // Create the device instance pointer.
- //
- psDevice = (tUSBDCompositeDevice *)pvInstance;
-
- //
- // Inform the application that the device has resumed.
- //
- if(psDevice->pfnCallback)
- {
- psDevice->pfnCallback(pvInstance, USB_EVENT_SUSPEND, 0, 0);
- }
-
- for(ulIdx = 0; ulIdx < psDevice->ulNumDevices; ulIdx++)
- {
- pDeviceInfo = psDevice->psDevices[ulIdx].psDevice;
- pvDeviceInst = psDevice->psDevices[ulIdx].pvInstance;
-
- if(pDeviceInfo->sCallbacks.pfnSuspendHandler)
- {
- pDeviceInfo->sCallbacks.pfnSuspendHandler(pvDeviceInst);
- }
- }
-}
-
-//****************************************************************************
-//
-// This function will check if any device classes need an resume handler
-// called.
-//
-//****************************************************************************
-static void
-ResumeHandler(void *pvInstance)
-{
- unsigned int ulIdx;
- tUSBDCompositeDevice *psDevice;
- const tDeviceInfo *pDeviceInfo;
- void *pvDeviceInst;
-
- ASSERT(pvInstance != 0);
-
- //
- // Create the device instance pointer.
- //
- psDevice = (tUSBDCompositeDevice *)pvInstance;
-
- //
- // Inform the application that the device has resumed.
- //
- if(psDevice->pfnCallback)
- {
- psDevice->pfnCallback(pvInstance, USB_EVENT_RESUME, 0, 0);
- }
-
- for(ulIdx = 0; ulIdx < psDevice->ulNumDevices; ulIdx++)
- {
- pDeviceInfo = psDevice->psDevices[ulIdx].psDevice;
- pvDeviceInst = psDevice->psDevices[ulIdx].pvInstance;
-
- if(pDeviceInfo->sCallbacks.pfnResumeHandler)
- {
- pDeviceInfo->sCallbacks.pfnResumeHandler(pvDeviceInst);
- }
- }
-}
-
-//****************************************************************************
-//
-// This function will check if any device classes need an reset handler
-// called.
-//
-//****************************************************************************
-static void
-ResetHandler(void *pvInstance)
-{
- unsigned int ulIdx;
- tUSBDCompositeDevice *psDevice;
- const tDeviceInfo *pDeviceInfo;
- void *pvDeviceInst;
-
- ASSERT(pvInstance != 0);
-
- //
- // Create the device instance pointer.
- //
- psDevice = (tUSBDCompositeDevice *)pvInstance;
-
- //
- // Inform the application that the device has been connected.
- //
- if(psDevice->pfnCallback)
- {
- psDevice->pfnCallback(pvInstance, USB_EVENT_CONNECTED, 0, 0);
- }
-
- for(ulIdx = 0; ulIdx < psDevice->ulNumDevices; ulIdx++)
- {
- pDeviceInfo = psDevice->psDevices[ulIdx].psDevice;
- pvDeviceInst = psDevice->psDevices[ulIdx].pvInstance;
-
- if(pDeviceInfo->sCallbacks.pfnResetHandler)
- {
- pDeviceInfo->sCallbacks.pfnResetHandler(pvDeviceInst);
- }
- }
-}
-
-//****************************************************************************
-//
-// This function is called to handle data being set to the host so that the
-// application callback can be called when the data has been transferred.
-//
-//****************************************************************************
-static void
-DataSent(void *pvInstance, unsigned int ulInfo, unsigned int ulIndex)
-{
- unsigned int ulIdx;
- const tDeviceInfo *pDeviceInfo;
- tUSBDCompositeDevice *psDevice;
-
- //
- // Create the device instance pointer.
- //
- psDevice = (tUSBDCompositeDevice *)pvInstance;
-
- for(ulIdx = 0; ulIdx < psDevice->ulNumDevices; ulIdx++)
- {
- pDeviceInfo = psDevice->psDevices[ulIdx].psDevice;
-
- if(pDeviceInfo->sCallbacks.pfnDataSent)
- {
- pDeviceInfo->sCallbacks.pfnDataSent(
- psDevice->psDevices[ulIdx].pvInstance, ulInfo, ulIndex);
- }
- }
-}
-
-//****************************************************************************
-//
-// This function is called to handle data being received back from the host so
-// that the application callback can be called when the new data is ready.
-//
-//****************************************************************************
-static void
-DataReceived(void *pvInstance, unsigned int ulInfo, unsigned int ulIndex)
-{
- unsigned int ulIdx;
- const tDeviceInfo *pDeviceInfo;
- tUSBDCompositeDevice *psDevice;
-
- //
- // Create the device instance pointer.
- //
- psDevice = (tUSBDCompositeDevice *)pvInstance;
-
- for(ulIdx = 0; ulIdx < psDevice->ulNumDevices; ulIdx++)
- {
- pDeviceInfo = psDevice->psDevices[ulIdx].psDevice;
-
- if(pDeviceInfo->sCallbacks.pfnDataReceived)
- {
- pDeviceInfo->sCallbacks.pfnDataReceived(
- psDevice->psDevices[ulIdx].pvInstance, ulInfo, ulIndex);
- }
- }
-}
-
-//****************************************************************************
-//
-// This function will check if any device classes need an endpoint handler
-// called.
-//
-//****************************************************************************
-static void
-HandleEndpoints(void *pvInstance, unsigned int ulStatus,
- unsigned int ulIndex)
-{
- unsigned int ulIdx;
- const tDeviceInfo *pDeviceInfo;
- tUSBDCompositeDevice *psDevice;
-
- //
- // Create the device instance pointer.
- //
- psDevice = (tUSBDCompositeDevice *)pvInstance;
-
- for(ulIdx = 0; ulIdx < psDevice->ulNumDevices; ulIdx++)
- {
- pDeviceInfo = psDevice->psDevices[ulIdx].psDevice;
-
- if(pDeviceInfo->sCallbacks.pfnEndpointHandler)
- {
- pDeviceInfo->sCallbacks.pfnEndpointHandler(
- psDevice->psDevices[ulIdx].pvInstance, ulStatus, ulIndex);
- }
- }
-}
-
-//****************************************************************************
-//
-// This function is called by the USB device stack whenever the device is
-// disconnected from the host.
-//
-//****************************************************************************
-static void
-HandleDisconnect(void *pvInstance)
-{
- unsigned int ulIdx;
- const tDeviceInfo *pDeviceInfo;
- tUSBDCompositeDevice *psDevice;
-
- ASSERT(pvInstance != 0);
-
- //
- // Create the device instance pointer.
- //
- psDevice = (tUSBDCompositeDevice *)pvInstance;
-
- //
- // Inform the application that the device has been disconnected.
- //
- if(psDevice->pfnCallback)
- {
- psDevice->pfnCallback(pvInstance, USB_EVENT_DISCONNECTED, 0, 0);
- }
-
- for(ulIdx = 0; ulIdx < psDevice->ulNumDevices; ulIdx++)
- {
- pDeviceInfo = psDevice->psDevices[ulIdx].psDevice;
-
- if(pDeviceInfo->sCallbacks.pfnEndpointHandler)
- {
- pDeviceInfo->sCallbacks.pfnDisconnectHandler(
- psDevice->psDevices[ulIdx].pvInstance);
- }
- }
-}
-
-//****************************************************************************
-//
-// This function is called by the USB device stack whenever the device
-// interface changes. It will be passed on to the device classes if they have
-// a handler for this function.
-//
-//****************************************************************************
-static void
-InterfaceChange(void *pvInstance, unsigned char ucInterfaceNum,
- unsigned char ucAlternateSetting)
-{
- unsigned int ulIdx;
- const tDeviceInfo *pDeviceInfo;
- tUSBDCompositeDevice *psDevice;
-
- ASSERT(pvInstance != 0);
-
- //
- // Create the device instance pointer.
- //
- psDevice = (tUSBDCompositeDevice *)pvInstance;
-
- for(ulIdx = 0; ulIdx < psDevice->ulNumDevices; ulIdx++)
- {
- pDeviceInfo = psDevice->psDevices[ulIdx].psDevice;
-
- if(pDeviceInfo->sCallbacks.pfnInterfaceChange)
- {
- pDeviceInfo->sCallbacks.pfnInterfaceChange(
- psDevice->psDevices[ulIdx].pvInstance, ucInterfaceNum,
- ucAlternateSetting);
- }
- }
-}
-
-//****************************************************************************
-//
-// This function is called by the USB device stack whenever the device
-// configuration changes. It will be passed on to the device classes if they
-// have a handler for this function.
-//
-//****************************************************************************
-static void
-ConfigChangeHandler(void *pvInstance, unsigned int ulValue,
- unsigned int ulIndex)
-{
- unsigned int ulIdx;
- const tDeviceInfo *pDeviceInfo;
- tUSBDCompositeDevice *psDevice;
-
- ASSERT(pvInstance != 0);
-
- //
- // Create the device instance pointer.
- //
- psDevice = (tUSBDCompositeDevice *)pvInstance;
-
- for(ulIdx = 0; ulIdx < psDevice->ulNumDevices; ulIdx++)
- {
- pDeviceInfo = psDevice->psDevices[ulIdx].psDevice;
-
- if(pDeviceInfo->sCallbacks.pfnConfigChange)
- {
- pDeviceInfo->sCallbacks.pfnConfigChange(
- psDevice->psDevices[ulIdx].pvInstance, ulValue, ulIndex);
- }
- }
-}
-
-//****************************************************************************
-//
-// This function is called by the USB device stack whenever a non-standard
-// request is received.
-//
-// \param pvInstance
-// \param pUSBRequest points to the request received.
-//
-// This call will be passed on to the device classes if they have a handler
-// for this function.
-//
-// \return None.
-//
-//****************************************************************************
-static void
-HandleRequests(void *pvInstance, tUSBRequest *pUSBRequest,
- unsigned int ulIndex)
-{
- unsigned int ulIdx;
- const tDeviceInfo *pDeviceInfo;
- tUSBDCompositeDevice *psDevice;
-
- ASSERT(pvInstance != 0);
-
- //
- // Create the device instance pointer.
- //
- psDevice = (tUSBDCompositeDevice *)pvInstance;
-
- for(ulIdx = 0; ulIdx < psDevice->ulNumDevices; ulIdx++)
- {
- pDeviceInfo = psDevice->psDevices[ulIdx].psDevice;
-
- if(pDeviceInfo->sCallbacks.pfnRequestHandler)
- {
- pDeviceInfo->sCallbacks.pfnRequestHandler(
- psDevice->psDevices[ulIdx].pvInstance, pUSBRequest, ulIndex);
- }
- }
-}
-
-//****************************************************************************
-//
-// This function handles sending interface number changes to device instances.
-//
-//****************************************************************************
-static void
-CompositeIfaceChange(tCompositeEntry *pCompDevice, unsigned char ucOld,
- unsigned char ucNew)
-{
- unsigned char pucInterfaces[2];
-
- if(pCompDevice->psDevice->sCallbacks.pfnDeviceHandler)
- {
- //
- // Create the data to pass to the device handler.
- //
- pucInterfaces[0] = ucOld;
- pucInterfaces[1] = ucNew;
-
- //
- // Call the device handler to inform the class of the interface number
- // change.
- //
- pCompDevice->psDevice->sCallbacks.pfnDeviceHandler(
- pCompDevice->pvInstance, USB_EVENT_COMP_IFACE_CHANGE,
- (void *)pucInterfaces);
- }
-}
-
-//****************************************************************************
-//
-// This function handles sending endpoint number changes to device instances.
-//
-//****************************************************************************
-static void
-CompositeEPChange(tCompositeEntry *pCompDevice, unsigned char ucOld,
- unsigned char ucNew)
-{
- unsigned char pucInterfaces[2];
- unsigned char ucIndex;
-
- if(pCompDevice->psDevice->sCallbacks.pfnDeviceHandler)
- {
- //
- // Create the data to pass to the device handler.
- //
- pucInterfaces[0] = ucOld;
- pucInterfaces[1] = ucNew;
-
- ucNew--;
-
- if(ucOld & USB_RTYPE_DIR_IN)
- {
- ucIndex = (ucOld & ~USB_RTYPE_DIR_IN) - 1;
-
- g_sUSBCompositeFIFOConfig.sIn[ucNew].bDoubleBuffer =
- pCompDevice->psDevice->psFIFOConfig->sIn[ucIndex].bDoubleBuffer;
-
- g_sUSBCompositeFIFOConfig.sIn[ucNew].cMultiplier =
- pCompDevice->psDevice->psFIFOConfig->sIn[ucIndex].cMultiplier;
-
- g_sUSBCompositeFIFOConfig.sIn[ucNew].usEPFlags =
- pCompDevice->psDevice->psFIFOConfig->sIn[ucIndex].usEPFlags;
- }
- else
- {
- ucIndex = ucOld - 1;
-
- g_sUSBCompositeFIFOConfig.sOut[ucNew].bDoubleBuffer =
- pCompDevice->psDevice->psFIFOConfig->sOut[ucIndex].bDoubleBuffer;
-
- g_sUSBCompositeFIFOConfig.sOut[ucNew].cMultiplier =
- pCompDevice->psDevice->psFIFOConfig->sOut[ucIndex].cMultiplier;
-
- g_sUSBCompositeFIFOConfig.sOut[ucNew].usEPFlags =
- pCompDevice->psDevice->psFIFOConfig->sOut[ucIndex].usEPFlags;
- }
- //
- // Call the device handler to inform the class of the interface number
- // change.
- //
- pCompDevice->psDevice->sCallbacks.pfnDeviceHandler(
- pCompDevice->pvInstance, USB_EVENT_COMP_EP_CHANGE,
- (void *)pucInterfaces);
- }
-}
-
-//****************************************************************************
-//
-// This function merges the configuration descriptors into a single multiple
-// instance device.
-//
-//****************************************************************************
-unsigned int
-BuildCompositeDescriptor(tUSBDCompositeDevice *psCompDevice)
-{
- unsigned int ulIdx, ulOffset, ulCPIdx, ulFixINT, ulDev;
- unsigned short usTotalLength, usBytes;
- unsigned char ucInterface, ucINEndpoint, ucOUTEndpoint;
- unsigned char *pucData, *pucConfig;
- const tConfigHeader *pConfigHeader;
- tDescriptorHeader *psHeader;
- const unsigned char *pucDescriptor;
- tInterfaceDescriptor *psInterface;
- tEndpointDescriptor *psEndpoint;
- const tDeviceInfo *psDevice;
-
- //
- // Save the number of devices to look through.
- //
- ulDev = 0;
- ulIdx = 0;
- ucInterface = 0;
- ucINEndpoint = 1;
- ucOUTEndpoint = 1;
- ulOffset = 0;
- ulFixINT = 0;
-
- //
- // This puts the first section pointer in the first entry in the list
- // of sections.
- //
- psCompDevice->psPrivateData->ppsCompSections[0] =
- &psCompDevice->psPrivateData->psCompSections[0];
-
- //
- // Put the pointer to this instances configuration descriptor into the
- // front of the list.
- //
- psCompDevice->psPrivateData->ppsCompSections[0]->pucData =
- (unsigned char *)&psCompDevice->psPrivateData->sConfigDescriptor;
-
- psCompDevice->psPrivateData->ppsCompSections[0]->ucSize =
- psCompDevice->psPrivateData->sConfigDescriptor.bLength;
-
- //
- // The configuration descriptor is 9 bytes so initialize the total length
- // to 9 bytes.
- //
- usTotalLength = 9;
-
- //
- // Copy the section pointer into the section array for the composite
- // device. This is awkward but is required given the definition
- // of the structures.
- //
- psCompDevice->psPrivateData->ppsCompSections[1] =
- &psCompDevice->psPrivateData->psCompSections[1];
-
- //
- // Copy the point to the application supplied space into the section list.
- //
- psCompDevice->psPrivateData->ppsCompSections[1]->ucSize = 0;
- psCompDevice->psPrivateData->ppsCompSections[1]->pucData =
- psCompDevice->psPrivateData->pucData;
-
- //
- // Create a local pointer to the data that is used to copy data from
- // the other devices into the composite descriptor.
- //
- pucData = psCompDevice->psPrivateData->pucData;
-
- while(ulDev < psCompDevice->ulNumDevices)
- {
- //
- // Save the current starting address of this descriptor.
- //
- pucConfig = pucData + ulOffset;
-
- //
- // Create a local pointer to the configuration header.
- //
- psDevice = psCompDevice->psDevices[ulDev].psDevice;
-
- pConfigHeader = psDevice->ppConfigDescriptors[0];
-
- //
- // Loop through the sections, skipping the first which is always the
- // configuration descriptor for the device.
- //
- for(ulIdx = 1; ulIdx < pConfigHeader->ucNumSections; ulIdx++)
- {
- //
- // Initialize the local offset in this descriptor.
- //
- usBytes = 0;
-
- //
- // Get a pointer to the configuration descriptor.
- //
- pucDescriptor = pConfigHeader->psSections[ulIdx]->pucData;
-
- //
- // Bounds check the allocated space and return if there is not
- // enough space.
- //
- if(ulOffset > psCompDevice->psPrivateData->ulDataSize)
- {
- return(1);
- }
-
- //
- // Copy the descriptor from the device into the descriptor list.
- //
- for(ulCPIdx = 0;
- ulCPIdx < pConfigHeader->psSections[ulIdx]->ucSize;
- ulCPIdx++)
- {
- pucData[ulCPIdx + ulOffset] = pucDescriptor[ulCPIdx];
- }
-
- //
- // Read out the descriptors in this section.
- //
- while(usBytes < pConfigHeader->psSections[ulIdx]->ucSize)
- {
- //
- // Create a descriptor header pointer.
- //
- psHeader = (tDescriptorHeader *)&pucData[ulOffset + usBytes];
-
- //
- // Check for interface descriptors and modify the numbering to
- // match the composite device.
- //
- if(psHeader->bDescriptorType == USB_DTYPE_INTERFACE)
- {
- psInterface = (tInterfaceDescriptor *)psHeader;
-
- //
- // See if this is an alternate setting or the initial
- // setting.
- //
- if(psInterface->bAlternateSetting != 0)
- {
- //
- // If this is an alternate setting then use the
- // previous interface number because the current one
- // has already been incremented.
- //
- psInterface->bInterfaceNumber = ucInterface - 1;
- }
- else
- {
- //
- // Notify the class that it's interface number has
- // changed.
- //
- CompositeIfaceChange(&psCompDevice->psDevices[ulDev],
- psInterface->bInterfaceNumber,
- ucInterface);
- //
- // This was the non-alternate setting so save the
- // value and move to the next interface number.
- //
- psInterface->bInterfaceNumber = ucInterface;
-
- //
- // No strings allowed on interface descriptors for
- // composite devices.
- //
- psInterface->iInterface = 0;
-
- ucInterface++;
- }
- }
- //
- // Check for endpoint descriptors and modify the numbering to
- // match the composite device.
- //
- else if(psHeader->bDescriptorType == USB_DTYPE_ENDPOINT)
- {
- psEndpoint = (tEndpointDescriptor *)psHeader;
-
- //
- // Check if this is an IN or OUT endpoint.
- //
- if(psEndpoint->bEndpointAddress & USB_RTYPE_DIR_IN)
- {
- //
- // Check if this is the special Fixed Interrupt class
- // and this is the interrupt endpoint.
- //
- if(((psEndpoint->bmAttributes & USB_EP_ATTR_TYPE_M) ==
- USB_EP_ATTR_INT) &&
- (psCompDevice->usPID == USB_PID_COMP_SERIAL))
- {
- //
- // Check if the Fixed Interrupt endpoint has been
- // set yet.
- //
- if(ulFixINT == 0)
- {
- //
- // Allocate he fixed interrupt endpoint and
- // save its number.
- //
- ulFixINT = ucINEndpoint++;
- }
-
- CompositeEPChange(&psCompDevice->psDevices[ulDev],
- psEndpoint->bEndpointAddress,
- ulFixINT);
-
- psEndpoint->bEndpointAddress = ulFixINT |
- USB_RTYPE_DIR_IN;
- }
- else
- {
- //
- // Notify the class that it's interface number has
- // changed.
- //
- CompositeEPChange(&psCompDevice->psDevices[ulDev],
- psEndpoint->bEndpointAddress,
- ucINEndpoint);
-
- psEndpoint->bEndpointAddress = ucINEndpoint++ |
- USB_RTYPE_DIR_IN;
- }
- }
- else
- {
- //
- // Notify the class that it's interface number has
- // changed.
- //
- CompositeEPChange(&psCompDevice->psDevices[ulDev],
- psEndpoint->bEndpointAddress,
- ucOUTEndpoint);
- psEndpoint->bEndpointAddress = ucOUTEndpoint++;
- }
- }
-
- //
- // Move on to the next descriptor.
- //
- usBytes += psHeader->bLength;
- }
-
- ulOffset += pConfigHeader->psSections[ulIdx]->ucSize;
-
- usTotalLength += usBytes;
- }
-
- //
- // Allow the device class to make adjustments to the configuration
- // descriptor.
- //
- psCompDevice->psDevices[ulDev].psDevice->sCallbacks.pfnDeviceHandler(
- psCompDevice->psDevices[ulDev].pvInstance,
- USB_EVENT_COMP_CONFIG, (void *)pucConfig);
-
- ulDev++;
- }
-
- //
- // Modify the configuration descriptor to match the number of interfaces
- // and the new total size.
- //
- psCompDevice->psPrivateData->sCompConfigHeader.ucNumSections = 2;
- psCompDevice->psPrivateData->ppsCompSections[1]->ucSize = ulOffset;
- psCompDevice->psPrivateData->sConfigDescriptor.bNumInterfaces =
- ucInterface;
- psCompDevice->psPrivateData->sConfigDescriptor.wTotalLength =
- usTotalLength;
-
- return(0);
-}
-
-//****************************************************************************
-//
-//! This function should be called once for the composite class device to
-//! initialized basic operation and prepare for enumeration.
-//!
-//! \param ulIndex is the index of the USB controller to initialize for
-//! composite device operation.
-//! \param psDevice points to a structure containing parameters customizing
-//! the operation of the composite device.
-//! \param ulSize is the size in bytes of the data pointed to by the
-//! \e pucData parameter.
-//! \param pucData is the data area that the composite class can use to build
-//! up descriptors.
-//!
-//! In order for an application to initialize the USB composite device class,
-//! it must first call this function with the a valid composite device class
-//! structure in the \e psDevice parameter. This allows this function to
-//! initialize the USB controller and device code to be prepared to enumerate
-//! and function as a USB composite device. The \e ulSize and \e pucData
-//! parameters should be large enough to hold all of the class instances
-//! passed in via the psDevice structure. This is typically the full size of
-//! the configuration descriptor for a device minus its configuration
-//! header(9 bytes).
-//!
-//! This function returns a void pointer that must be passed in to all other
-//! APIs used by the composite class.
-//!
-//! See the documentation on the tUSBDCompositeDevice structure for more
-//! information on how to properly fill the structure members.
-//!
-//! \return This function returns 0 on failure or a non-zero void pointer on
-//! success.
-//
-//****************************************************************************
-void *
-USBDCompositeInit(unsigned int ulIndex, tUSBDCompositeDevice *psDevice,
- unsigned int ulSize, unsigned char *pucData)
-{
- tCompositeInstance *psInst;
- int iIdx;
- unsigned char *pucTemp;
-
- //
- // Check parameter validity.
- //
- ASSERT(ulIndex == 0);
- ASSERT(psDevice);
- ASSERT(psDevice->ppStringDescriptors);
- ASSERT(psDevice->psPrivateData);
-
- //
- // Initialize the work space in the passed instance structure.
- //
- psInst = psDevice->psPrivateData;
- psInst->ulDataSize = ulSize;
- psInst->pucData = pucData;
-
- //
- // Set the device information for the composite device.
- //
- psInst->psDevInfo = &g_sCompositeDeviceInfo;
-
- g_pCompConfigDescriptors[0] = &psInst->sCompConfigHeader;
- g_pCompConfigDescriptors[0]->ucNumSections = 0;
- g_pCompConfigDescriptors[0]->psSections =
- (const tConfigSection * const *)psDevice->psPrivateData->ppsCompSections;
-
- //
- // Create a byte pointer to use with the copy.
- //
- pucTemp = (unsigned char *)&psInst->sConfigDescriptor;
-
- //
- // Copy the default configuration descriptor into the instance data.
- //
- for(iIdx = 0; iIdx < g_pCompConfigDescriptor[0]; iIdx++)
- {
- pucTemp[iIdx] = g_pCompConfigDescriptor[iIdx];
- }
-
- //
- // Create a byte pointer to use with the copy.
- //
- pucTemp = (unsigned char *)&psInst->sDeviceDescriptor;
-
- //
- // Copy the default configuration descriptor into the instance data.
- //
- for(iIdx = 0; iIdx < g_pCompDeviceDescriptor[0]; iIdx++)
- {
- pucTemp[iIdx] = g_pCompDeviceDescriptor[iIdx];
- }
-
- //
- // Fix up the device descriptor with the client-supplied values.
- //
- psInst->sDeviceDescriptor.idVendor = psDevice->usVID;
- psInst->sDeviceDescriptor.idProduct = psDevice->usPID;
-
- //
- // Fix up the configuration descriptor with client-supplied values.
- //
- psInst->sConfigDescriptor.bmAttributes = psDevice->ucPwrAttributes;
- psInst->sConfigDescriptor.bMaxPower =
- (unsigned char)(psDevice->usMaxPowermA>>1);
-
- g_sCompositeDeviceInfo.pDeviceDescriptor =
- (const unsigned char *)&psInst->sDeviceDescriptor;
-
- //
- // Plug in the client's string stable to the device information
- // structure.
- //
- psInst->psDevInfo->ppStringDescriptors = psDevice->ppStringDescriptors;
- psInst->psDevInfo->ulNumStringDescriptors =
- psDevice->ulNumStringDescriptors;
-
- //
- // Create the combined descriptors.
- //
- if(BuildCompositeDescriptor(psDevice))
- {
- return(0);
- }
-
- //
- // Set the instance data for this device.
- //
- psInst->psDevInfo->pvInstance = (void *)psDevice;
-
- //
- // All is well so now pass the descriptors to the lower layer and put
- // the bulk device on the bus.
- //
- USBDCDInit(ulIndex, psInst->psDevInfo);
-
- //
- // Return the pointer to the instance indicating that everything went
- // well.
- //
- return ((void *)psDevice);
-}
-
-//****************************************************************************
-//
-//! Shuts down the composite device.
-//!
-//! \param pvInstance is the pointer to the device instance structure as
-//! returned by USBDCompositeInit().
-//!
-//! This function terminates composite device interface for the instance
-//! supplied. Following this call, the \e pvInstance instance should not me
-//! used in any other calls.
-//!
-//! \return None.
-//
-//****************************************************************************
-void
-USBDCompositeTerm(void *pvInstance)
-{
- ASSERT(pvInstance != 0);
-
-}
-
-//****************************************************************************
-//
-// Close the Doxygen group.
-//! @}
-//
-//****************************************************************************
-
diff --git a/SylixOS/StarterWare/usblib/device/usbdconfig.c b/SylixOS/StarterWare/usblib/device/usbdconfig.c
deleted file mode 100644
index c96d171..0000000
--- a/SylixOS/StarterWare/usblib/device/usbdconfig.c
+++ /dev/null
@@ -1,673 +0,0 @@
-//*****************************************************************************
-//
-// usbdconfig.c - High level USB device configuration function.
-//
-// Copyright (c) 2008-2010 Texas Instruments Incorporated. All rights reserved.
-// Software License Agreement
-//
-// Texas Instruments (TI) is supplying this software for use solely and
-// exclusively on TI's microcontroller products. The software is owned by
-// TI and/or its suppliers, and is protected under applicable copyright
-// laws. You may not combine this software with "viral" open-source
-// software in order to form a larger program.
-//
-// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
-// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
-// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
-// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
-// DAMAGES, FOR ANY REASON WHATSOEVER.
-//
-// This is part of AM1808 StarterWare USB Library and reused from revision 6288
-// of the Stellaris USB Library.
-//
-//*****************************************************************************
-
-//#include "hw_memmap.h"
-#include "hw_usb.h"
-#include "hw_types.h"
-#include "debug.h"
-#include "usb.h"
-#include "usblib.h"
-#include "usbdevice.h"
-
-//*****************************************************************************
-//
-//! \addtogroup device_api
-//! @{
-//
-//*****************************************************************************
-
-//*****************************************************************************
-//
-// Mask used to preserve various endpoint configuration flags.
-//
-//*****************************************************************************
-#define EP_FLAGS_MASK (USB_EP_MODE_MASK | USB_EP_DEV_IN | \
- USB_EP_DEV_OUT)
-
-//*****************************************************************************
-//
-// Structure used in compiling FIFO size and endpoint properties from a
-// configuration descriptor.
-//
-//*****************************************************************************
-typedef struct
-{
- unsigned int ulSize[2];
- unsigned int ulType[2];
-}
-tUSBEndpointInfo;
-
-//*****************************************************************************
-//
-// Indices used when accessing the tUSBEndpointInfo structure.
-//
-//*****************************************************************************
-#define EP_INFO_IN 0
-#define EP_INFO_OUT 1
-
-//*****************************************************************************
-//
-// Given a maximum packet size and the user's FIFO scaling requirements,
-// determine the flags to use to configure the endpoint FIFO and the number
-// of bytes of FIFO space occupied.
-//
-//*****************************************************************************
-static unsigned int
-GetEndpointFIFOSize(unsigned int ulMaxPktSize, const tFIFOEntry *psFIFOParams,
- unsigned int *pupBytesUsed)
-{
- unsigned int ulBytes;
- unsigned int ulLoop;
- unsigned int ulFIFOSize;
-
- //
- // A zero multiplier would not be a good thing.
- //
- ASSERT(psFIFOParams->cMultiplier);
-
- //
- // What is the basic size required for a single buffered FIFO entry
- // containing the required number of packets?
- //
- ulBytes = ulMaxPktSize * (unsigned int)psFIFOParams->cMultiplier;
-
- //
- // Now we need to find the nearest supported size that accommodates the
- // requested size. Step through each of the supported sizes until we
- // find one that will do.
- //
- for(ulLoop = USB_FIFO_SZ_8; ulLoop <= USB_FIFO_SZ_8192; ulLoop++)
- {
- //
- // How many bytes does this FIFO value represent?
- //
- ulFIFOSize = USB_FIFO_SZ_TO_BYTES(ulLoop);
-
- //
- // Is this large enough to satisfy the request?
- //
- if(ulFIFOSize >= ulBytes)
- {
- //
- // Yes - are we being asked to double-buffer the FIFO for this
- // endpoint?
- //
- if(psFIFOParams->bDoubleBuffer)
- {
- //
- // Yes - FIFO requirement is double in this case.
- //
- *pupBytesUsed = ulFIFOSize * 2;
- return(ulLoop | USB_FIFO_SIZE_DB_FLAG);
- }
- else
- {
- //
- // No double buffering so just return the size and associated
- // flag.
- //
- *pupBytesUsed = ulFIFOSize;
- return(ulLoop);
- }
- }
- }
-
- //
- // If we drop out, we can't support the FIFO size requested. Signal a
- // problem by returning 0 in the pBytesUsed
- //
- *pupBytesUsed = 0;
- return(USB_FIFO_SZ_8);
-}
-
-//*****************************************************************************
-//
-// Translate a USB endpoint descriptor into the values we need to pass to the
-// USBDevEndpointConfigSet() API.
-//
-//*****************************************************************************
-static void
-GetEPDescriptorType(tEndpointDescriptor *psEndpoint, unsigned int *pulEPIndex,
- unsigned int *pulMaxPktSize, unsigned int *pulFlags)
-{
- //
- // Get the endpoint index.
- //
- *pulEPIndex = psEndpoint->bEndpointAddress & USB_EP_DESC_NUM_M;
-
- //
- // Extract the maximum packet size.
- //
- *pulMaxPktSize = psEndpoint->wMaxPacketSize & USB_EP_MAX_PACKET_COUNT_M;
-
- //
- // Is this an IN or an OUT endpoint?
- //
- *pulFlags = (psEndpoint->bEndpointAddress & USB_EP_DESC_IN) ?
- USB_EP_DEV_IN : USB_EP_DEV_OUT;
-
- //
- // Set the endpoint mode.
- //
- switch(psEndpoint->bmAttributes & USB_EP_ATTR_TYPE_M)
- {
- case USB_EP_ATTR_CONTROL:
- *pulFlags |= USB_EP_MODE_CTRL;
- break;
-
- case USB_EP_ATTR_BULK:
- *pulFlags |= USB_EP_MODE_BULK;
- break;
-
- case USB_EP_ATTR_INT:
- *pulFlags |= USB_EP_MODE_INT;
- break;
-
- case USB_EP_ATTR_ISOC:
- *pulFlags |= USB_EP_MODE_ISOC;
- break;
- }
-}
-
-//*****************************************************************************
-//
-//! Configure the USB controller appropriately for the device whose config
-//! descriptor is passed.
-//!
-//! \param ulIndex is the zero-based index of the USB controller which is to
-//! be configured.
-//! \param psConfig is a pointer to the configuration descriptor that the
-//! USB controller is to be set up to support.
-//! \param psFIFOConfig is a pointer to an array of NUM_USB_EP tFIFOConfig
-//! structures detailing how the FIFOs are to be set up for each endpoint
-//! used by the configuration.
-//!
-//! This function may be used to initialize a USB controller to operate as
-//! the device whose configuration descriptor is passed. The function
-//! enables the USB controller, partitions the FIFO appropriately and
-//! configures each endpoint required by the configuration. If the supplied
-//! configuration supports multiple alternate settings for any interface,
-//! the USB FIFO is set up assuming the worst case use (largest packet size
-//! for a given endpoint in any alternate setting using that endpoint) to
-//! allow for on-the-fly alternate setting changes later. On return from this
-//! function, the USB controller is configured for correct operation of
-//! the default configuration of the device described by the descriptor passed.
-//!
-//! The \e psFIFOConfig parameter allows the caller to provide additional
-//! information on USB FIFO configuration that cannot be determined merely
-//! by parsing the configuration descriptor. The descriptor provides
-//! information on the endpoints that are to be used and the maximum packet
-//! size for each but cannot determine whether, for example, double buffering
-//! is to be used or how many packets the application wants to be able to
-//! store in a given endpoint's FIFO.
-//!
-//! USBDCDConfig() is an optional call and applications may chose to make
-//! direct calls to SysCtlPeripheralEnable(), SysCtlUSBPLLEnable(),
-//! USBDevEndpointConfigSet() and USBFIFOConfigSet() instead of using this
-//! function. If this function is used, it must be called prior to
-//! USBDCDInit() since this call assumes that the low level hardware
-//! configuration has been completed before it is made.
-//!
-//! \return Returns \b true on success or \b false on failure.
-//
-//*****************************************************************************
-tBoolean
-USBDeviceConfig(unsigned int ulIndex, const tConfigHeader *psConfig,
- const tFIFOConfig *psFIFOConfig)
-{
- unsigned int ulLoop;
- unsigned int ulCount;
- unsigned int ulNumInterfaces;
- unsigned int ulEpIndex;
- unsigned int ulEpType;
- unsigned int ulMaxPkt;
- unsigned int ulNumEndpoints;
- unsigned int ulFlags;
- unsigned int ulBytesUsed;
- unsigned int ulSection;
- tInterfaceDescriptor *psInterface;
- tEndpointDescriptor *psEndpoint;
- tUSBEndpointInfo psEPInfo[NUM_USB_EP - 1];
-
- //
- // We only support 1 USB controller currently.
- //
- ASSERT(ulIndex == 0);
-
- //
- // Catch bad pointers in a debug build.
- //
- ASSERT(psConfig);
- ASSERT(psFIFOConfig);
-
- //
- // Clear out our endpoint info.
- //
- for(ulLoop = 0; ulLoop < (NUM_USB_EP - 1); ulLoop++)
- {
- psEPInfo[ulLoop].ulSize[EP_INFO_IN] = 0;
- psEPInfo[ulLoop].ulType[EP_INFO_IN] = 0;
- psEPInfo[ulLoop].ulSize[EP_INFO_OUT] = 0;
- psEPInfo[ulLoop].ulType[EP_INFO_OUT] = 0;
- }
-
- //
- // How many (total) endpoints does this configuration describe?
- //
- ulNumEndpoints = USBDCDConfigDescGetNum(psConfig,
- USB_DTYPE_ENDPOINT);
-
- //
- // How many interfaces are included?
- //
- ulNumInterfaces = USBDCDConfigDescGetNum(psConfig,
- USB_DTYPE_INTERFACE);
-
- //
- // Look at each endpoint and determine the largest max packet size for
- // each endpoint. This will determine how we partition the USB FIFO.
- //
- for(ulLoop = 0; ulLoop < ulNumEndpoints; ulLoop++)
- {
- //
- // Get a pointer to the endpoint descriptor.
- //
- psEndpoint = (tEndpointDescriptor *)USBDCDConfigDescGet(
- psConfig, USB_DTYPE_ENDPOINT, ulLoop,
- &ulSection);
-
- //
- // Extract the endpoint number and whether it is an IN or OUT
- // endpoint.
- //
- ulEpIndex = (unsigned int)
- psEndpoint->bEndpointAddress & USB_EP_DESC_NUM_M;
- ulEpType = (psEndpoint->bEndpointAddress & USB_EP_DESC_IN) ?
- EP_INFO_IN : EP_INFO_OUT;
-
- //
- // Make sure the endpoint number is valid for our controller. If not,
- // return false to indicate an error. Note that 0 is invalid since
- // you shouldn't reference endpoint 0 in the config descriptor.
- //
- if((ulEpIndex >= NUM_USB_EP) || (ulEpIndex == 0))
- {
- return(false);
- }
-
- //
- // Does this endpoint have a max packet size requirement larger than
- // any previous use we have seen?
- //
- if(psEndpoint->wMaxPacketSize >
- psEPInfo[ulEpIndex - 1].ulSize[ulEpType])
- {
- //
- // Yes - remember the new maximum packet size.
- //
- psEPInfo[ulEpIndex - 1].ulSize[ulEpType] =
- psEndpoint->wMaxPacketSize;
- }
- }
-
- //
- // At this point, we have determined the maximum packet size required
- // for each endpoint by any possible alternate setting of any interface
- // in this configuration. Now determine the endpoint settings required
- // for the interface setting we are actually going to use.
- //
- for(ulLoop = 0; ulLoop < ulNumInterfaces; ulLoop++)
- {
- //
- // Get the next interface descriptor in the config descriptor.
- //
- psInterface = USBDCDConfigGetInterface(psConfig,
- ulLoop,
- USB_DESC_ANY,
- &ulSection);
-
- //
- // Is this the default interface (bAlternateSetting set to 0)?
- //
- if(psInterface && (psInterface->bAlternateSetting == 0))
- {
- //
- // This is an interface we are interested in so gather the
- // information on its endpoints.
- //
- ulNumEndpoints = (unsigned int)psInterface->bNumEndpoints;
-
- //
- // Walk through each endpoint in this interface and configure
- // it appropriately.
- //
- for(ulCount = 0; ulCount < ulNumEndpoints; ulCount++)
- {
- //
- // Get a pointer to the endpoint descriptor.
- //
- psEndpoint = USBDCDConfigGetInterfaceEndpoint(psConfig,
- psInterface->bInterfaceNumber,
- psInterface->bAlternateSetting,
- ulCount);
-
- //
- // Make sure we got a good pointer.
- //
- if(psEndpoint)
- {
- //
- // Determine maximum packet size and flags from the
- // endpoint descriptor.
- //
- GetEPDescriptorType(psEndpoint, &ulEpIndex, &ulMaxPkt,
- &ulFlags);
-
- //
- // Make sure no-one is trying to configure endpoint 0.
- //
- if(!ulEpIndex)
- {
- return(false);
- }
-
- //
- // Include any additional flags that the user wants.
- //
- if((ulFlags & (USB_EP_DEV_IN | USB_EP_DEV_OUT)) ==
- USB_EP_DEV_IN)
- {
- //
- // This is an IN endpoint.
- //
- ulFlags |= (unsigned int)(
- psFIFOConfig->sIn[ulEpIndex - 1].usEPFlags);
- psEPInfo[ulEpIndex - 1].ulType[EP_INFO_IN] = ulFlags;
- }
- else
- {
- //
- // This is an OUT endpoint.
- //
- ulFlags |= (unsigned int)(
- psFIFOConfig->sOut[ulEpIndex - 1].usEPFlags);
- psEPInfo[ulEpIndex - 1].ulType[EP_INFO_OUT] = ulFlags;
- }
-
- //
- // Set the endpoint configuration.
- //
- USBDevEndpointConfigSet(g_USBInstance[ulIndex].uiBaseAddr,
- INDEX_TO_USB_EP(ulEpIndex),
- ulMaxPkt, ulFlags);
- }
- }
- }
- }
-
- //
- // At this point, we have configured all the endpoints that are to be
- // used by this configuration's alternate setting 0. Now we go on and
- // partition the FIFO based on the maximum packet size information we
- // extracted earlier. Endpoint 0 is automatically configured to use the
- // first MAX_PACKET_SIZE_EP0 bytes of the FIFO so we start from there.
- //
- ulCount = MAX_PACKET_SIZE_EP0;
- for(ulLoop = 1; ulLoop < NUM_USB_EP; ulLoop++)
- {
- //
- // Configure the IN endpoint at this index if it is referred to
- // anywhere.
- //
- if(psEPInfo[ulLoop - 1].ulSize[EP_INFO_IN])
- {
- //
- // What FIFO size flag do we use for this endpoint?
- //
- ulMaxPkt = GetEndpointFIFOSize(
- psEPInfo[ulLoop - 1].ulSize[EP_INFO_IN],
- &(psFIFOConfig->sIn[ulLoop - 1]),
- &ulBytesUsed);
-
- //
- // If we are told that 0 bytes of FIFO will be used, this implies
- // that there is an error in psFIFOConfig or the descriptor
- // somewhere so return an error indicator to the caller.
- //
- if(!ulBytesUsed)
- {
- return(false);
- }
-
- //
- // Now actually configure the FIFO for this endpoint.
- //
- USBFIFOConfigSet(g_USBInstance[ulIndex].uiBaseAddr,
- INDEX_TO_USB_EP(ulLoop), ulCount,
- ulMaxPkt, USB_EP_DEV_IN);
- ulCount += ulBytesUsed;
- }
-
- //
- // Configure the OUT endpoint at this index.
- //
- if(psEPInfo[ulLoop - 1].ulSize[EP_INFO_OUT])
- {
- //
- // What FIFO size flag do we use for this endpoint?
- //
- ulMaxPkt = GetEndpointFIFOSize(
- psEPInfo[ulLoop - 1].ulSize[EP_INFO_OUT],
- &(psFIFOConfig->sOut[ulLoop - 1]),
- &ulBytesUsed);
-
- //
- // If we are told that 0 bytes of FIFO will be used, this implies
- // that there is an error in psFIFOConfig or the descriptor
- // somewhere so return an error indicator to the caller.
- //
- if(!ulBytesUsed)
- {
- return(false);
- }
-
- //
- // Now actually configure the FIFO for this endpoint.
- //
- USBFIFOConfigSet(g_USBInstance[ulIndex].uiBaseAddr,
- INDEX_TO_USB_EP(ulLoop), ulCount,
- ulMaxPkt, USB_EP_DEV_OUT);
- ulCount += ulBytesUsed;
- }
-
- }
-
- //
- // If we get to the end, all is well.
- //
- return(true);
-}
-
-//*****************************************************************************
-//
-//! Configure the affected USB endpoints appropriately for one alternate
-//! interface setting.
-//!
-//! \param ulIndex is the zero-based index of the USB controller which is to
-//! be configured.
-//! \param psConfig is a pointer to the configuration descriptor that contains
-//! the interface whose alternate settings is to be configured.
-//! \param ucInterfaceNum is the number of the interface whose alternate
-//! setting is to be configured. This number corresponds to the
-//! bInterfaceNumber field in the desired interface descriptor.
-//! \param ucAlternateSetting is the alternate setting number for the desired
-//! interface. This number corresponds to the bAlternateSetting field in the
-//! desired interface descriptor.
-//!
-//! This function may be used to reconfigure the endpoints of an interface
-//! for operation in one of the interface's alternate settings. Note that this
-//! function assumes that the endpoint FIFO settings will not need to change
-//! and only the endpoint mode is changed. This assumption is valid if the
-//! USB controller was initialized using a previous call to USBDCDConfig().
-//!
-//! In reconfiguring the interface endpoints, any additional configuration
-//! bits set in the endpoint configuration other than the direction (\b
-//! USB_EP_DEV_IN or \b USB_EP_DEV_OUT) and mode (\b USB_EP_MODE_MASK) are
-//! preserved.
-//!
-//! \return Returns \b true on success or \b false on failure.
-//
-//*****************************************************************************
-tBoolean
-USBDeviceConfigAlternate(unsigned int ulIndex, const tConfigHeader *psConfig,
- unsigned char ucInterfaceNum,
- unsigned char ucAlternateSetting)
-{
- unsigned int ulNumInterfaces;
- unsigned int ulNumEndpoints;
- unsigned int ulLoop;
- unsigned int ulCount;
- unsigned int ulMaxPkt;
- unsigned int ulOldMaxPkt;
- unsigned int ulFlags;
- unsigned int ulOldFlags;
- unsigned int ulSection;
- unsigned int ulEpIndex;
- tInterfaceDescriptor *psInterface;
- tEndpointDescriptor *psEndpoint;
-
- //
- // How many interfaces are included in the descriptor?
- //
- ulNumInterfaces = USBDCDConfigDescGetNum(psConfig,
- USB_DTYPE_INTERFACE);
-
- //
- // Find the interface descriptor for the supplied interface and alternate
- // setting numbers.
- //
-
- for(ulLoop = 0; ulLoop < ulNumInterfaces; ulLoop++)
- {
- //
- // Get the next interface descriptor in the config descriptor.
- //
- psInterface = USBDCDConfigGetInterface(psConfig, ulLoop, USB_DESC_ANY,
- &ulSection);
-
- //
- // Is this the default interface (bAlternateSetting set to 0)?
- //
- if(psInterface &&
- (psInterface->bInterfaceNumber == ucInterfaceNum) &&
- (psInterface->bAlternateSetting == ucAlternateSetting))
- {
- //
- // This is an interface we are interested in and the descriptor
- // representing the alternate setting we want so go ahead and
- // reconfigure the endpoints.
- //
-
- //
- // How many endpoints does this interface have?
- //
- ulNumEndpoints = (unsigned int)psInterface->bNumEndpoints;
-
- //
- // Walk through each endpoint in turn.
- //
- for(ulCount = 0; ulCount < ulNumEndpoints; ulCount++)
- {
- //
- // Get a pointer to the endpoint descriptor.
- //
- psEndpoint = USBDCDConfigGetInterfaceEndpoint(psConfig,
- psInterface->bInterfaceNumber,
- psInterface->bAlternateSetting,
- ulCount);
-
- //
- // Make sure we got a good pointer.
- //
- if(psEndpoint)
- {
- //
- // Determine maximum packet size and flags from the
- // endpoint descriptor.
- //
- GetEPDescriptorType(psEndpoint, &ulEpIndex, &ulMaxPkt,
- &ulFlags);
-
- //
- // Make sure no-one is trying to configure endpoint 0.
- //
- if(!ulEpIndex)
- {
- return(false);
- }
-
- //
- // Get the existing endpoint configuration and mask in the
- // new mode and direction bits, leaving everything else
- // unchanged.
- //
- ulOldFlags = ulFlags;
- USBDevEndpointConfigGet(g_USBInstance[ulIndex].uiBaseAddr,
- INDEX_TO_USB_EP(ulEpIndex),
- &ulOldMaxPkt,
- &ulOldFlags);
-
- //
- // Mask in the previous DMA and auto-set bits.
- //
- ulFlags = (ulFlags & EP_FLAGS_MASK) |
- (ulOldFlags & ~EP_FLAGS_MASK);
-
- //
- // Set the endpoint configuration.
- //
- USBDevEndpointConfigSet(g_USBInstance[ulIndex].uiBaseAddr,
- INDEX_TO_USB_EP(ulEpIndex),
- ulMaxPkt, ulFlags);
- }
- }
-
- //
- // At this point, we have reconfigured the desired interface so
- // return indicating all is well.
- //
- return(true);
- }
- }
-
- return(false);
-}
-
-//*****************************************************************************
-//
-// Close the Doxygen group.
-//! @}
-//
-//*****************************************************************************
diff --git a/SylixOS/StarterWare/usblib/device/usbdenum.c b/SylixOS/StarterWare/usblib/device/usbdenum.c
deleted file mode 100644
index dd94f63..0000000
--- a/SylixOS/StarterWare/usblib/device/usbdenum.c
+++ /dev/null
@@ -1,3113 +0,0 @@
-//*****************************************************************************
-//
-// usbenum.c - Enumeration code to handle all endpoint zero traffic.
-//
-// Copyright (c) 2007-2010 Texas Instruments Incorporated. All rights reserved.
-// Software License Agreement
-//
-// Texas Instruments (TI) is supplying this software for use solely and
-// exclusively on TI's microcontroller products. The software is owned by
-// TI and/or its suppliers, and is protected under applicable copyright
-// laws. You may not combine this software with "viral" open-source
-// software in order to form a larger program.
-//
-// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
-// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
-// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
-// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
-// DAMAGES, FOR ANY REASON WHATSOEVER.
-//
-// This is part of AM1808 StarterWare USB Library and reused from revision 6288
-// of the Stellaris USB Library.
-//
-//*****************************************************************************
-
-#include "hw_usb.h"
-#include "hw_types.h"
-#include "debug.h"
-#include "usb.h"
-#include "usblib.h"
-#include "usbdevice.h"
-#include "usbdevicepriv.h"
-#include "usblibpriv.h"
-#include "delay.h"
-#include "interrupt.h"
-
-//*****************************************************************************
-//
-// External prototypes.
-//
-//*****************************************************************************
-//extern tUSBMode g_eUSBMode;
-static tUSBMode g_eUSBMode = USB_MODE_DEVICE;
-
-
-//*****************************************************************************
-//
-// USB instance Object
-//
-//*****************************************************************************
-extern tUSBInstanceObject g_USBInstance[];
-
-//*****************************************************************************
-//
-// Local functions prototypes.
-//
-//*****************************************************************************
-static void USBDGetStatus(void *pvInstance, tUSBRequest *pUSBRequest,
- unsigned int ulIndex);
-static void USBDClearFeature(void *pvInstance, tUSBRequest *pUSBRequest,
- unsigned int ulIndex);
-static void USBDSetFeature(void *pvInstance, tUSBRequest *pUSBRequest,
- unsigned int ulIndex);
-static void USBDSetAddress(void *pvInstance, tUSBRequest *pUSBRequest,
- unsigned int ulIndex);
-static void USBDGetDescriptor(void *pvInstance, tUSBRequest *pUSBRequest,
- unsigned int ulIndex);
-static void USBDSetDescriptor(void *pvInstance, tUSBRequest *pUSBRequest,
- unsigned int ulIndex);
-static void USBDGetConfiguration(void *pvInstance,
- tUSBRequest *pUSBRequest, unsigned int ulIndex);
-static void USBDSetConfiguration(void *pvInstance,
- tUSBRequest *pUSBRequest, unsigned int ulIndex);
-static void USBDGetInterface(void *pvInstance, tUSBRequest *pUSBRequest,
- unsigned int ulIndex);
-static void USBDSetInterface(void *pvInstance, tUSBRequest *pUSBRequest,
- unsigned int ulIndex);
-static void USBDSyncFrame(void *pvInstance, tUSBRequest *pUSBRequest,
- unsigned int ulIndex);
-static void USBDEP0StateTx(unsigned int ulIndex);
-static void USBDEP0StateTxConfig(unsigned int ulIndex);
-static int USBDStringIndexFromRequest(unsigned short usLang,
- unsigned short usIndex, unsigned int ulIndex);
-
-//*****************************************************************************
-//
-//! \addtogroup device_api
-//! @{
-//
-//*****************************************************************************
-
-//*****************************************************************************
-//
-//! The default USB endpoint FIFO configuration structure. This structure
-//! contains definitions to set all USB FIFOs into single buffered mode with
-//! no DMA use. Each endpoint's FIFO is sized to hold the largest maximum
-//! packet size for any interface alternate setting in the current
-//! configuration descriptor. A pointer to this structure may be passed in the
-//! psFIFOConfig field of the tDeviceInfo structure passed to USBCDCInit if the
-//! application does not require any special handling of the USB controller
-//! FIFO.
-//
-//*****************************************************************************
-const tFIFOConfig g_sUSBDefaultFIFOConfig =
-{
- {
- { 1, false, 0 },
- { 1, false, 0 },
- { 1, false, 0 },
- { 1, false, 0 },
- { 1, false, 0 },
- { 1, false, 0 },
- { 1, false, 0 },
- { 1, false, 0 },
- { 1, false, 0 },
- { 1, false, 0 },
- { 1, false, 0 },
- { 1, false, 0 },
- { 1, false, 0 },
- { 1, false, 0 },
- { 1, false, 0 }
- },
- {
- { 1, false, 0 },
- { 1, false, 0 },
- { 1, false, 0 },
- { 1, false, 0 },
- { 1, false, 0 },
- { 1, false, 0 },
- { 1, false, 0 },
- { 1, false, 0 },
- { 1, false, 0 },
- { 1, false, 0 },
- { 1, false, 0 },
- { 1, false, 0 },
- { 1, false, 0 },
- { 1, false, 0 },
- { 1, false, 0 }
- },
-};
-
-//*****************************************************************************
-//
-// Indices into the ucHalt array to select the IN or OUT endpoint group.
-//
-//*****************************************************************************
-#define HALT_EP_IN 0
-#define HALT_EP_OUT 1
-
-//*****************************************************************************
-//
-// The states for endpoint zero during enumeration.
-//
-//*****************************************************************************
-typedef enum
-{
- //
- // The USB device is waiting on a request from the host controller on
- // endpoint zero.
- //
- USB_STATE_IDLE,
-
- //
- // The USB device is sending data back to the host due to an IN request.
- //
- USB_STATE_TX,
-
- //
- // The USB device is sending the configuration descriptor back to the host
- // due to an IN request.
- //
- USB_STATE_TX_CONFIG,
-
- //
- // The USB device is receiving data from the host due to an OUT
- // request from the host.
- //
- USB_STATE_RX,
-
- //
- // The USB device has completed the IN or OUT request and is now waiting
- // for the host to acknowledge the end of the IN/OUT transaction. This
- // is the status phase for a USB control transaction.
- //
- USB_STATE_STATUS,
-
- //
- // This endpoint has signaled a stall condition and is waiting for the
- // stall to be acknowledged by the host controller.
- //
- USB_STATE_STALL
-}
-tEP0State;
-
-//*****************************************************************************
-//
-// Define the max packet size for endpoint zero.
-//
-//*****************************************************************************
-#define EP0_MAX_PACKET_SIZE 64
-
-//*****************************************************************************
-//
-// This is a flag used with g_sUSBDeviceState.ulDevAddress to indicate that a
-// device address change is pending.
-//
-//*****************************************************************************
-#define DEV_ADDR_PENDING 0x80000000
-
-//*****************************************************************************
-//
-// This label defines the default configuration number to use after a bus
-// reset. This may be overridden by calling USBDCDSetDefaultConfiguration()
-// during processing of the device reset handler if required.
-//
-//*****************************************************************************
-#define DEFAULT_CONFIG_ID 1
-
-//*****************************************************************************
-//
-// This label defines the number of milliseconds that the remote wake up signal
-// must remain asserted before removing it. Section 7.1.7.7 of the USB 2.0 spec
-// states that "the remote wake up device must hold the resume signaling for at
-// least 1ms but for no more than 15ms" so 10mS seems a reasonable choice.
-//
-//*****************************************************************************
-#define REMOTE_WAKEUP_PULSE_MS 10
-
-//*****************************************************************************
-//
-// This label defines the number of milliseconds between the point where we
-// assert the remote wake up signal and calling the client back to tell it that
-// bus operation has been resumed. This value is based on the timings provided
-// in section 7.1.7.7 of the USB 2.0 specification which indicates that the host
-// (which takes over resume signaling when the device's initial signal is
-// detected) must hold the resume signaling for at least 20mS.
-//
-//*****************************************************************************
-#define REMOTE_WAKEUP_READY_MS 20
-
-//*****************************************************************************
-//
-// The buffer for reading data coming into EP0
-//
-//*****************************************************************************
-static unsigned char g_pucDataBufferIn[EP0_MAX_PACKET_SIZE];
-
-//*****************************************************************************
-//
-// The USB controller device information.
-//
-//*****************************************************************************
-typedef struct
-{
- //
- // The device information for the USB device.
- //
- tDeviceInfo *psInfo;
-
- //
- // The instance data for the USB device.
- //
- void *pvInstance;
-
- //
- // The current state of endpoint zero.
- //
- volatile tEP0State eEP0State;
-
- //
- // The devices current address, this also has a change pending bit in the
- // MSB of this value specified by DEV_ADDR_PENDING.
- //
- volatile unsigned int ulDevAddress;
-
- //
- // This holds the current active configuration for this device.
- //
- unsigned int ulConfiguration;
-
- //
- // This holds the configuration id that will take effect after a reset.
- //
- unsigned int ulDefaultConfiguration;
-
- //
- // This holds the current alternate interface for this device.
- //
- unsigned char pucAltSetting[USB_MAX_INTERFACES_PER_DEVICE];
-
- //
- // This is the pointer to the current data being sent out or received
- // on endpoint zero.
- //
- unsigned char *pEP0Data;
-
- //
- // This is the number of bytes that remain to be sent from or received
- // into the g_sUSBDeviceState.pEP0Data data buffer.
- //
- volatile unsigned int ulEP0DataRemain;
-
- //
- // The amount of data being sent/received due to a custom request.
- //
- unsigned int ulOUTDataSize;
-
- //
- // Holds the current device status.
- //
- unsigned char ucStatus;
-
- //
- // Holds the endpoint status for the HALT condition. This array is sized
- // to hold halt status for all IN and OUT endpoints.
- //
- unsigned char ucHalt[2][NUM_USB_EP - 1];
-
- //
- // Holds the configuration descriptor section number currently being sent
- // to the host.
- //
- unsigned char ucConfigSection;
-
- //
- // Holds the offset within the configuration descriptor section currently
- // being sent to the host.
- //
- unsigned char ucSectionOffset;
-
- //
- // Holds the index of the configuration that we are currently sending back
- // to the host.
- //
- unsigned char ucConfigIndex;
-
- //
- // This flag is set to true if the client has called USBDPowerStatusSet
- // and tells the USB library not to try to determine the current power
- // status from the configuration descriptor.
- //
- tBoolean bPwrSrcSet;
-
- //
- // This flag indicates whether or not remote wake up signaling is in
- // progress.
- //
- tBoolean bRemoteWakeup;
-
- //
- // During remote wake up signaling, this counter is used to track the
- // number of milliseconds since the signaling was initiated.
- //
- unsigned char ucRemoteWakeupCount;
-}
-tDeviceInstance;
-
-tDeviceInstance g_psUSBDevice[USB_NUM_INSTANCE];
-
-//*****************************************************************************
-//
-// Function table to handle standard requests.
-//
-//*****************************************************************************
-static const tStdRequest g_psUSBDStdRequests[] =
-{
- USBDGetStatus,
- USBDClearFeature,
- 0,
- USBDSetFeature,
- 0,
- USBDSetAddress,
- USBDGetDescriptor,
- USBDSetDescriptor,
- USBDGetConfiguration,
- USBDSetConfiguration,
- USBDGetInterface,
- USBDSetInterface,
- USBDSyncFrame
-};
-
-//*****************************************************************************
-//
-// Functions accessible by USBLIB clients.
-//
-//*****************************************************************************
-
-//*****************************************************************************
-//
-//! Initialize the USB library device control driver for a given hardware
-//! controller.
-//!
-//! \param ulIndex is the index of the USB controller which is to be
-//! initialized.
-//! \param psDevice is a pointer to a structure containing information that
-//! the USB library requires to support operation of this application's
-//! device. The structure contains event handler callbacks and pointers to the
-//! various standard descriptors that the device wishes to publish to the
-//! host.
-//!
-//! This function must be called by any application which wishes to operate
-//! as a USB device. It initializes the USB device control driver for the
-//! given controller and saves the device information for future use. Prior to
-//! returning from this function, the device is connected to the USB bus.
-//! Following return, the caller can expect to receive a callback to the
-//! supplied <tt>pfnResetHandler</tt> function when a host connects to the
-//! device.
-//!
-//! The device information structure passed in \e psDevice must remain
-//! unchanged between this call and any matching call to USBDCDTerm() since
-//! it is not copied by the USB library.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-USBDCDInit(unsigned int ulIndex, tDeviceInfo *psDevice)
-{
- const tConfigHeader *psHdr;
- const tConfigDescriptor *psDesc;
-
- //
- // Check the arguments.
- //
- ASSERT(ulIndex == 0);
- ASSERT(psDevice != 0);
-
- //
- // Should not call this if the stack is in host mode.
- //
- ASSERT(g_eUSBMode != USB_MODE_HOST)
-
- //
- // Initialize a couple of fields in the device state structure.
- //
- g_psUSBDevice[ulIndex].ulConfiguration = DEFAULT_CONFIG_ID;
- g_psUSBDevice[ulIndex].ulDefaultConfiguration = DEFAULT_CONFIG_ID;
-
- //
- // Remember the device information pointer.
- //
- g_psUSBDevice[ulIndex].psInfo = psDevice;
- g_psUSBDevice[ulIndex].pvInstance = psDevice->pvInstance;
- g_psUSBDevice[ulIndex].eEP0State = USB_STATE_IDLE;
-
- //
- // If no mode is set then make the mode become device mode.
- //
- if(g_eUSBMode == USB_MODE_NONE)
- {
- g_eUSBMode = USB_MODE_DEVICE;
- }
-
- //
- // Only do hardware update if the stack is in Device mode, do not touch the
- // hardware for OTG mode operation.
- //
- if(g_eUSBMode == USB_MODE_DEVICE)
- {
- //
- // Enable Clocking to the USB controller.
- //
-
- USBModuleClkEnable(ulIndex, g_USBInstance[ulIndex].uiBaseAddr);
-
- USBReset(g_USBInstance[ulIndex].uiSubBaseAddr);
- //
- // Turn on USB Phy clock.
- //
- UsbPhyOn(ulIndex);
- }
-
-
-
- //
- // Only do hardware update if the stack is in Device mode, do not touch the
- // hardware for OTG mode operation.
- //
- if(g_eUSBMode == USB_MODE_DEVICE)
- {
- //
- // Ask for the interrupt status. As a side effect, this clears all
- // pending USB interrupts.
- //
- USBIntStatusControl(g_USBInstance[ulIndex].uiBaseAddr);
- USBIntStatusEndpoint(g_USBInstance[ulIndex].uiBaseAddr);
- if(USB_REV_AM1808 == USBVersionGet())
- {
- USBClearOtgIntr(g_USBInstance[ulIndex].uiSubBaseAddr);
- }
-
- USBEnableOtgIntr(g_USBInstance[ulIndex].uiSubBaseAddr);
- //
- // Enable USB Interrupts.
- //
- USBIntEnableControl(g_USBInstance[ulIndex].uiBaseAddr, USB_INTCTRL_RESET |
- USB_INTCTRL_DISCONNECT |
- USB_INTCTRL_RESUME |
- USB_INTCTRL_SUSPEND |
- USB_INTCTRL_SOF);
- USBIntEnableEndpoint(g_USBInstance[ulIndex].uiBaseAddr, USB_INTEP_ALL);
-
- }
-
- //
- // Get a pointer to the default configuration descriptor.
- //
- psHdr = psDevice->ppConfigDescriptors[
- g_psUSBDevice[ulIndex].ulDefaultConfiguration - 1];
- psDesc = (const tConfigDescriptor *)(psHdr->psSections[0]->pucData);
-
- //
- // Default to the state where remote wake up is disabled.
- //
- g_psUSBDevice[ulIndex].ucStatus = 0;
- g_psUSBDevice[ulIndex].bRemoteWakeup = false;
-
- //
- // Determine the self- or bus-powered state based on the flags the
- // user provided.
- //
- g_psUSBDevice[ulIndex].bPwrSrcSet = false;
-
- if((psDesc->bmAttributes & USB_CONF_ATTR_PWR_M) == USB_CONF_ATTR_SELF_PWR)
- {
- g_psUSBDevice[ulIndex].ucStatus |= USB_STATUS_SELF_PWR;
- }
- else
- {
- g_psUSBDevice[ulIndex].ucStatus &= ~USB_STATUS_SELF_PWR;
- }
-
- //
- // Only do hardware update if the stack is in Device mode, do not touch the
- // hardware for OTG mode operation.
- //
- if(g_eUSBMode == USB_MODE_DEVICE)
- {
- //
- // Make sure we disconnect from the host for a while. This ensures
- // that the host will enumerate us even if we were previously
- // connected to the bus.
- //
- USBDevDisconnect(g_USBInstance[ulIndex].uiBaseAddr);
-
- //
- // Wait about 100mS.
- //
- delay(100);
-
-
- //
- // Attach the device using the soft connect.
- //
- USBDevConnect(g_USBInstance[ulIndex].uiBaseAddr);
-
- //
- // Enable the USB interrupt.
- //
-#ifdef _TMS320C6X
- /* No DSP API to enable USB0 event */
-#else
- IntSystemEnable(g_USBInstance[ulIndex].uiInterruptNum);
-#endif
-
-
- }
-}
-
-//*****************************************************************************
-//
-//! Free the USB library device control driver for a given hardware controller.
-//!
-//! \param ulIndex is the index of the USB controller which is to be
-//! freed.
-//!
-//! This function should be called by an application if it no longer requires
-//! the use of a given USB controller to support its operation as a USB device.
-//! It frees the controller for use by another client.
-//!
-//! It is the caller's responsibility to remove its device from the USB bus
-//! prior to calling this function.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-USBDCDTerm(unsigned int ulIndex)
-{
- //
- // Check the arguments.
- //
- ASSERT(ulIndex == 0);
-
- g_psUSBDevice[ulIndex].psInfo = (tDeviceInfo *)0;
- g_psUSBDevice[ulIndex].pvInstance = 0;
-
- //
- // Disable the USB interrupts.
- //
-#ifdef _TMS320C6X
- /* No DSP API to disable USB0 event */
-#else
- IntSystemDisable(g_USBInstance[ulIndex].uiInterruptNum);
-#endif
-
- USBIntDisableControl(g_USBInstance[ulIndex].uiBaseAddr, USB_INTCTRL_ALL);
- USBIntDisableEndpoint(g_USBInstance[ulIndex].uiBaseAddr, USB_INTEP_ALL);
-
- //
- // Detach the device using the soft connect.
- //
- USBDevDisconnect(g_USBInstance[ulIndex].uiBaseAddr);
-
- //
- // Clear any pending interrupts.
- //
- USBIntStatusControl(g_USBInstance[ulIndex].uiBaseAddr);
- USBIntStatusEndpoint(g_USBInstance[ulIndex].uiBaseAddr);
- if(USB_REV_AM1808 == USBVersionGet())
- {
- USBClearOtgIntr(g_USBInstance[ulIndex].uiSubBaseAddr);
- }
-
- //
- // Turn off USB Phy clock.
- //
- UsbPhyOff(ulIndex);
-
- //
- // Disable the USB peripheral
- //
- USBModuleClkDisable(ulIndex, g_USBInstance[ulIndex].uiBaseAddr);
-
-}
-
-//*****************************************************************************
-//
-//! This function starts the request for data from the host on endpoint zero.
-//!
-//! \param ulIndex is the index of the USB controller from which the data
-//! is being requested.
-//! \param pucData is a pointer to the buffer to fill with data from the USB
-//! host.
-//! \param ulSize is the size of the buffer or data to return from the USB
-//! host.
-//!
-//! This function handles retrieving data from the host when a custom command
-//! has been issued on endpoint zero. If the application needs notification
-//! when the data has been received,
-//! <tt>tDeviceInfo.sCallbacks.pfnDataReceived</tt> should contain valid
-//! function pointer. In nearly all cases this is necessary because the caller
-//! of this function would likely need to know that the data requested was
-//! received.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-USBDCDRequestDataEP0(unsigned int ulIndex, unsigned char *pucData,
- unsigned int ulSize)
-{
- ASSERT(ulIndex == 0);
-
- //
- // Enter the RX state on end point 0.
- //
- g_psUSBDevice[ulIndex].eEP0State = USB_STATE_RX;
-
- //
- // Save the pointer to the data.
- //
- g_psUSBDevice[ulIndex].pEP0Data = pucData;
-
- //
- // Location to save the current number of bytes received.
- //
- g_psUSBDevice[ulIndex].ulOUTDataSize = ulSize;
-
- //
- // Bytes remaining to be received.
- //
- g_psUSBDevice[ulIndex].ulEP0DataRemain = ulSize;
-}
-
-//*****************************************************************************
-//
-//! This function requests transfer of data to the host on endpoint zero.
-//!
-//! \param ulIndex is the index of the USB controller which is to be used to
-//! send the data.
-//! \param pucData is a pointer to the buffer to send via endpoint zero.
-//! \param ulSize is the amount of data to send in bytes.
-//!
-//! This function handles sending data to the host when a custom command is
-//! issued or non-standard descriptor has been requested on endpoint zero. If
-//! the application needs notification when this is complete,
-//! <tt>tDeviceInfo.sCallbacks.pfnDataSent</tt> should contain a valid function
-//! pointer. This callback could be used to free up the buffer passed into
-//! this function in the \e pucData parameter. The contents of the \e pucData
-//! buffer must remain unchanged until the <tt>pfnDataSent</tt> callback is
-//! received.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-USBDCDSendDataEP0(unsigned int ulIndex, unsigned char *pucData,
- unsigned int ulSize)
-{
- ASSERT(ulIndex == 0);
-
- //
- // Return the externally provided device descriptor.
- //
- g_psUSBDevice[ulIndex].pEP0Data = pucData;
-
- //
- // The size of the device descriptor is in the first byte.
- //
- g_psUSBDevice[ulIndex].ulEP0DataRemain = ulSize;
-
- //
- // Save the total size of the data sent.
- //
- g_psUSBDevice[ulIndex].ulOUTDataSize = ulSize;
-
- //
- // Now in the transmit data state.
- //
- USBDEP0StateTx(ulIndex);
-}
-
-//*****************************************************************************
-//
-//! This function sets the default configuration for the device.
-//!
-//! \param ulIndex is the index of the USB controller whose default
-//! configuration is to be set.
-//! \param ulDefaultConfig is the configuration identifier (byte 6 of the
-//! standard configuration descriptor) which is to be presented to the host
-//! as the default configuration in cases where the configuration descriptor is
-//! queried prior to any specific configuration being set.
-//!
-//! This function allows a device to override the default configuration
-//! descriptor that will be returned to a host whenever it is queried prior
-//! to a specific configuration having been set. The parameter passed must
-//! equal one of the configuration identifiers found in the
-//! <tt>ppConfigDescriptors</tt> array for the device.
-//!
-//! If this function is not called, the USB library will return the first
-//! configuration in the <tt>ppConfigDescriptors</tt> array as the default
-//! configuration.
-//!
-//! \note The USB device stack assumes that the configuration IDs (byte 6 of
-//! the configuration descriptor, <tt>bConfigurationValue</tt>) stored within
-//! the configuration descriptor array, <tt>ppConfigDescriptors</tt>,
-//! are equal to the array index + 1. In other words, the first entry in the
-//! array must contain a descriptor with <tt>bConfigurationValue</tt> 1, the
-//! second must have <tt>bConfigurationValue</tt> 2 and so on.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-USBDCDSetDefaultConfiguration(unsigned int ulIndex,
- unsigned int ulDefaultConfig)
-{
- ASSERT(ulIndex == 0);
-
- g_psUSBDevice[ulIndex].ulDefaultConfiguration = ulDefaultConfig;
-}
-
-//*****************************************************************************
-//
-//! This function generates a stall condition on endpoint zero.
-//!
-//! \param ulIndex is the index of the USB controller whose endpoint zero is to
-//! be stalled.
-//!
-//! This function is typically called to signal an error condition to the host
-//! when an unsupported request is received by the device. It should be
-//! called from within the callback itself (in interrupt context) and not
-//! deferred until later since it affects the operation of the endpoint zero
-//! state machine in the USB library.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-USBDCDStallEP0(unsigned int ulIndex)
-{
- ASSERT(ulIndex == 0);
-
- //
- // Stall the endpoint in question.
- //
- USBDevEndpointStall(g_USBInstance[ulIndex].uiBaseAddr, USB_EP_0, USB_EP_DEV_OUT);
-
- //
- // Enter the stalled state.
- //
- g_psUSBDevice[ulIndex].eEP0State = USB_STATE_STALL;
-}
-
-//*****************************************************************************
-//
-//! Reports the device power status (bus- or self-powered) to the library.
-//!
-//! \param ulIndex is the index of the USB controller whose device power
-//! status is being reported.
-//! \param ucPower indicates the current power status, either \b
-//! USB_STATUS_SELF_PWR or \b USB_STATUS_BUS_PWR.
-//!
-//! Applications which support switching between bus- or self-powered
-//! operation should call this function whenever the power source changes
-//! to indicate the current power status to the USB library. This information
-//! is required by the library to allow correct responses to be provided when
-//! the host requests status from the device.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-USBDCDPowerStatusSet(unsigned int ulIndex, unsigned char ucPower)
-{
- //
- // Check for valid parameters.
- //
- ASSERT((ucPower == USB_STATUS_BUS_PWR) ||
- (ucPower == USB_STATUS_SELF_PWR));
- ASSERT(ulIndex == 0);
-
- //
- // Update the device status with the new power status flag.
- //
- g_psUSBDevice[ulIndex].bPwrSrcSet = true;
- g_psUSBDevice[ulIndex].ucStatus &= ~USB_STATUS_PWR_M;
- g_psUSBDevice[ulIndex].ucStatus |= ucPower;
-}
-
-//*****************************************************************************
-//
-//! Requests a remote wake up to resume communication when in suspended state.
-//!
-//! \param ulIndex is the index of the USB controller that will request
-//! a bus wake up.
-//!
-//! When the bus is suspended, an application which supports remote wake up
-//! (advertised to the host via the configuration descriptor) may call this
-//! function to initiate remote wake up signaling to the host. If the remote
-//! wake up feature has not been disabled by the host, this will cause the bus
-//! to resume operation within 20mS. If the host has disabled remote wake up,
-//! \b false will be returned to indicate that the wake up request was not
-//! successful.
-//!
-//! \return Returns \b true if the remote wake up is not disabled and the
-//! signaling was started or \b false if remote wake up is disabled or if
-//! signaling is currently ongoing following a previous call to this function.
-//
-//*****************************************************************************
-tBoolean
-USBDCDRemoteWakeupRequest(unsigned int ulIndex)
-{
- //
- // Check for parameter validity.
- //
- ASSERT(ulIndex == 0);
-
- //
- // Is remote wake up signaling currently enabled?
- //
- if(g_psUSBDevice[ulIndex].ucStatus & USB_STATUS_REMOTE_WAKE)
- {
- //
- // The host has not disabled remote wake up. Are we still in the
- // middle of a previous wake up sequence?
- //
- if(!g_psUSBDevice[ulIndex].bRemoteWakeup)
- {
- //
- // No - we are not in the middle of a wake up sequence so start
- // one here.
- //
- g_psUSBDevice[ulIndex].ucRemoteWakeupCount = 0;
- g_psUSBDevice[ulIndex].bRemoteWakeup = true;
- USBHostResume(g_USBInstance[ulIndex].uiBaseAddr, true);
- return(true);
- }
- }
-
- //
- // If we drop through to here, signaling was not initiated so return
- // false.
- return(false);
-}
-
-//*****************************************************************************
-//
-// Internal Functions, not to be called by applications
-//
-//*****************************************************************************
-
-//*****************************************************************************
-//
-// This internal function is called on the SOF interrupt to process any
-// outstanding remote wake up requests.
-//
-// \return None.
-//
-//*****************************************************************************
-void
-USBDeviceResumeTickHandler(unsigned int ulIndex)
-{
- if(g_psUSBDevice[ulIndex].bRemoteWakeup)
- {
- //
- // Increment the millisecond counter we use to time the resume
- // signaling.
- //
- g_psUSBDevice[ulIndex].ucRemoteWakeupCount++;
-
- //
- // Have we reached the 10mS mark? If so, we need to turn the signaling
- // off again.
- //
- if(g_psUSBDevice[ulIndex].ucRemoteWakeupCount == REMOTE_WAKEUP_PULSE_MS)
- {
- USBHostResume(g_USBInstance[ulIndex].uiBaseAddr, false);
- }
-
- //
- // Have we reached the point at which we can tell the client that the
- // bus has resumed? The controller doesn't give us an interrupt if we
- // initiated the wake up signaling so we just wait until 20mS have
- // passed then tell the client all is well.
- //
- if(g_psUSBDevice[ulIndex].ucRemoteWakeupCount == REMOTE_WAKEUP_READY_MS)
- {
- //
- // We are now finished with the remote wake up signaling.
- //
- g_psUSBDevice[ulIndex].bRemoteWakeup = false;
-
- //
- // If the client has registered a resume callback, call it. In the
- // case of a remote wake up request, we do not get a resume
- // interrupt from the controller so we need to fake it here.
- //
- if(g_psUSBDevice[ulIndex].psInfo->sCallbacks.pfnResumeHandler)
- {
- g_psUSBDevice[ulIndex].psInfo->sCallbacks.pfnResumeHandler(
- g_psUSBDevice[ulIndex].pvInstance);
- }
- }
- }
-}
-
-//*****************************************************************************
-//
-// This internal function reads a request data packet and dispatches it to
-// either a standard request handler or the registered device request
-// callback depending upon the request type.
-//
-// \return None.
-//
-//*****************************************************************************
-static void
-USBDReadAndDispatchRequest(unsigned int ulIndex)
-{
- unsigned int ulSize;
- tUSBRequest *pRequest;
-
- //
- // Cast the buffer to a request structure.
- //
- pRequest = (tUSBRequest *)g_pucDataBufferIn;
-
- //
- // Set the buffer size.
- //
- ulSize = EP0_MAX_PACKET_SIZE;
-
- //
- // Get the data from the USB controller end point 0.
- //
- USBEndpointDataGet(g_USBInstance[ulIndex].uiBaseAddr,
- USB_EP_0,
- g_pucDataBufferIn,
- &ulSize);
-
- //
- // If there was a null setup packet then just return.
- //
- if(!ulSize)
- {
- return;
- }
-
- //
- // See if this is a standard request or not.
- //
-
-
-
-
-
-
- if((pRequest->bmRequestType & USB_RTYPE_TYPE_M) != USB_RTYPE_STANDARD)
- {
- //
- // Since this is not a standard request, see if there is
- // an external handler present.
- //
- if(g_psUSBDevice[ulIndex].psInfo->sCallbacks.pfnRequestHandler)
- {
- g_psUSBDevice[ulIndex].psInfo->sCallbacks.pfnRequestHandler(
- g_psUSBDevice[ulIndex].pvInstance, pRequest, ulIndex);
- }
- else
- {
- //
- // If there is no handler then stall this request.
- //
- USBDCDStallEP0(ulIndex);
- }
- }
- else
- {
- //
- // Assure that the jump table is not out of bounds.
- //
- if((pRequest->bRequest <
- (sizeof(g_psUSBDStdRequests) / sizeof(tStdRequest))) &&
- (g_psUSBDStdRequests[pRequest->bRequest] != 0))
- {
- //
- // Jump table to the appropriate handler.
- //
- g_psUSBDStdRequests[pRequest->bRequest](&g_psUSBDevice[ulIndex],
- pRequest, ulIndex);
- }
- else
- {
- //
- // If there is no handler then stall this request.
- //
- USBDCDStallEP0(ulIndex);
- }
- }
-}
-
-//*****************************************************************************
-//
-// This is interrupt handler for endpoint zero.
-//
-// This function handles all interrupts on endpoint zero in order to maintain
-// the state needed for the control endpoint on endpoint zero. In order to
-// successfully enumerate and handle all USB standard requests, all requests
-// on endpoint zero must pass through this function. The endpoint has the
-// following states: \b USB_STATE_IDLE, \b USB_STATE_TX, \b USB_STATE_RX,
-// \b USB_STATE_STALL, and \b USB_STATE_STATUS. In the \b USB_STATE_IDLE
-// state the USB controller has not received the start of a request, and once
-// it does receive the data for the request it will either enter the
-// \b USB_STATE_TX, \b USB_STATE_RX, or \b USB_STATE_STALL depending on the
-// command. If the controller enters the \b USB_STATE_TX or \b USB_STATE_RX
-// then once all data has been sent or received, it must pass through the
-// \b USB_STATE_STATUS state to allow the host to acknowledge completion of
-// the request. The \b USB_STATE_STALL is entered from \b USB_STATE_IDLE in
-// the event that the USB request was not valid. Both the \b USB_STATE_STALL
-// and \b USB_STATE_STATUS are transitional states that return to the
-// \b USB_STATE_IDLE state.
-//
-// \return None.
-//
-// USB_STATE_IDLE -*--> USB_STATE_TX -*-> USB_STATE_STATUS -*->USB_STATE_IDLE
-// | | |
-// |--> USB_STATE_RX - |
-// | |
-// |--> USB_STATE_STALL ---------->---------
-//
-// ----------------------------------------------------------------
-// | Current State | State 0 | State 1 |
-// | --------------------|-------------------|----------------------
-// | USB_STATE_IDLE | USB_STATE_TX/RX | USB_STATE_STALL |
-// | USB_STATE_TX | USB_STATE_STATUS | |
-// | USB_STATE_RX | USB_STATE_STATUS | |
-// | USB_STATE_STATUS | USB_STATE_IDLE | |
-// | USB_STATE_STALL | USB_STATE_IDLE | |
-// ----------------------------------------------------------------
-//
-//*****************************************************************************
-void
-USBDeviceEnumHandler(tDeviceInstance *pDevInstance, unsigned int ulIndex)
-{
- unsigned int ulEPStatus;
-
- //
- // Get the end point 0 status.
- //
- ulEPStatus = USBEndpointStatus(g_USBInstance[ulIndex].uiBaseAddr, USB_EP_0);
-
- switch(pDevInstance->eEP0State)
- {
- //
- // Handle the status state, this is a transitory state from
- // USB_STATE_TX or USB_STATE_RX back to USB_STATE_IDLE.
- //
- case USB_STATE_STATUS:
- {
- //
- // Just go back to the idle state.
- //
- pDevInstance->eEP0State = USB_STATE_IDLE;
-
- //
- // If there is a pending address change then set the address.
- //
- if(pDevInstance->ulDevAddress & DEV_ADDR_PENDING)
- {
- //
- // Clear the pending address change and set the address.
- //
- pDevInstance->ulDevAddress &= ~DEV_ADDR_PENDING;
- USBDevAddrSet(g_USBInstance[ulIndex].uiBaseAddr,
- pDevInstance->ulDevAddress);
- }
-
- //
- // If a new packet is already pending, we need to read it
- // and handle whatever request it contains.
- //
- if(ulEPStatus & USB_DEV_EP0_OUT_PKTRDY)
- {
- //
- // Process the newly arrived packet.
- //
- USBDReadAndDispatchRequest(0);
- }
- break;
- }
-
- //
- // In the IDLE state the code is waiting to receive data from the host.
- //
- case USB_STATE_IDLE:
- {
- //
- // Is there a packet waiting for us?
- //
- if(ulEPStatus & USB_DEV_EP0_OUT_PKTRDY)
- {
- //
- // Yes - process it.
- //
- USBDReadAndDispatchRequest(0);
- }
- break;
- }
-
- //
- // Data is still being sent to the host so handle this in the
- // EP0StateTx() function.
- //
- case USB_STATE_TX:
- {
- USBDEP0StateTx(ulIndex);
- break;
- }
-
- //
- // We are still in the middle of sending the configuration descriptor
- // so handle this in the EP0StateTxConfig() function.
- //
- case USB_STATE_TX_CONFIG:
- {
- USBDEP0StateTxConfig(ulIndex);
- break;
- }
-
- //
- // Handle the receive state for commands that are receiving data on
- // endpoint zero.
- //
- case USB_STATE_RX:
- {
- unsigned int ulDataSize;
-
- //
- // Set the number of bytes to get out of this next packet.
- //
- if(pDevInstance->ulEP0DataRemain > EP0_MAX_PACKET_SIZE)
- {
- //
- // Don't send more than EP0_MAX_PACKET_SIZE bytes.
- //
- ulDataSize = EP0_MAX_PACKET_SIZE;
- }
- else
- {
- //
- // There was space so send the remaining bytes.
- //
- ulDataSize = pDevInstance->ulEP0DataRemain;
- }
-
- //
- // Get the data from the USB controller end point 0.
- //
- USBEndpointDataGet(g_USBInstance[ulIndex].uiBaseAddr, USB_EP_0,
- pDevInstance->pEP0Data, &ulDataSize);
-
- //
- // If there we not more that EP0_MAX_PACKET_SIZE or more bytes
- // remaining then this transfer is complete. If there were less than
- // EP0_MAX_PACKET_SIZE remaining then there still needs to be
- // null packet sent before this is complete.
- //
- if(pDevInstance->ulEP0DataRemain <= EP0_MAX_PACKET_SIZE)
- {
- //
- // Need to ACK the data on end point 0 in this case and set the
- // data end as this is the last of the data.
- //
- USBDevEndpointDataAck(g_USBInstance[ulIndex].uiBaseAddr, USB_EP_0, true);
-
- //
- // Return to the idle state.
- //
- pDevInstance->eEP0State = USB_STATE_IDLE;
-
- //
- // If there is a receive callback then call it.
- //
- if((pDevInstance->psInfo->sCallbacks.pfnDataReceived) &&
- (pDevInstance->ulOUTDataSize != 0))
- {
- //
- // Call the custom receive handler to handle the data
- // that was received.
- //
- pDevInstance->psInfo->sCallbacks.pfnDataReceived(
- pDevInstance->pvInstance,
- pDevInstance->ulOUTDataSize, ulIndex);
-
- //
- // Indicate that there is no longer any data being waited
- // on.
- //
- pDevInstance->ulOUTDataSize = 0;
- }
- }
- else
- {
- //
- // Need to ACK the data on end point 0 in this case
- // without setting data end because more data is coming.
- //
- USBDevEndpointDataAck(g_USBInstance[ulIndex].uiBaseAddr, USB_EP_0, false);
- }
-
- //
- // Advance the pointer.
- //
- pDevInstance->pEP0Data += ulDataSize;
-
- //
- // Decrement the number of bytes that are being waited on.
- //
- pDevInstance->ulEP0DataRemain -= ulDataSize;
-
- break;
- }
- //
- // The device stalled endpoint zero so check if the stall needs to be
- // cleared once it has been successfully sent.
- //
- case USB_STATE_STALL:
- {
- //
- // If we sent a stall then acknowledge this interrupt.
- //
- if(ulEPStatus & USB_DEV_EP0_SENT_STALL)
- {
- //
- // Clear the Setup End condition.
- //
- USBDevEndpointStatusClear(g_USBInstance[ulIndex].uiBaseAddr, USB_EP_0,
- USB_DEV_EP0_SENT_STALL);
-
- //
- // Reset the global end point 0 state to IDLE.
- //
- pDevInstance->eEP0State = USB_STATE_IDLE;
-
- }
- break;
- }
- //
- // Halt on an unknown state, but only in DEBUG mode builds.
- //
- default:
- {
-
- ASSERT(0);
- }
- }
-}
-
-//*****************************************************************************
-//
-// This function handles bus reset notifications.
-//
-// This function is called from the low level USB interrupt handler whenever
-// a bus reset is detected. It performs tidy-up as required and resets the
-// configuration back to defaults in preparation for descriptor queries from
-// the host.
-//
-// \return None.
-//
-//*****************************************************************************
-void
-USBDeviceEnumResetHandler(tDeviceInstance *pDevInstance)
-{
- unsigned int ulLoop;
-
- //
- // Disable remote wake up signaling (as per USB 2.0 spec 9.1.1.6).
- //
- pDevInstance->ucStatus &= ~USB_STATUS_REMOTE_WAKE;
- pDevInstance->bRemoteWakeup = false;
-
- //
- // Call the device dependent code to indicate a bus reset has occurred.
- //
- if(pDevInstance->psInfo->sCallbacks.pfnResetHandler)
- {
- pDevInstance->psInfo->sCallbacks.pfnResetHandler(
- pDevInstance->pvInstance);
- }
-
- //
- // Reset the default configuration identifier and alternate function
- // selections.
- //
- pDevInstance->ulConfiguration = pDevInstance->ulDefaultConfiguration;
-
- for(ulLoop = 0; ulLoop < USB_MAX_INTERFACES_PER_DEVICE; ulLoop++)
- {
- pDevInstance->pucAltSetting[ulLoop] = (unsigned char)0;
- }
-}
-
-//*****************************************************************************
-//
-// This function handles the GET_STATUS standard USB request.
-//
-// \param pvInstance is the USB device controller instance data.
-// \param pUSBRequest holds the request type and endpoint number if endpoint
-// status is requested.
-//
-// This function handles responses to a Get Status request from the host
-// controller. A status request can be for the device, an interface or an
-// endpoint. If any other type of request is made this function will cause
-// a stall condition to indicate that the command is not supported. The
-// \e pUSBRequest structure holds the type of the request in the
-// bmRequestType field. If the type indicates that this is a request for an
-// endpoint's status, then the wIndex field holds the endpoint number.
-//
-// \return None.
-//
-//*****************************************************************************
-static void
-USBDGetStatus(void *pvInstance, tUSBRequest *pUSBRequest,
- unsigned int ulIndex)
-{
- unsigned short usData;
- tDeviceInstance *psUSBControl;
-
- ASSERT(pUSBRequest != 0);
- ASSERT(pvInstance != 0);
-
- //
- // Create the device information pointer.
- //
- psUSBControl = (tDeviceInstance *)pvInstance;
-
- //
- // Need to ACK the data on end point 0 without setting last data as there
- // will be a data phase.
- //
- USBDevEndpointDataAck(g_USBInstance[ulIndex].uiBaseAddr, USB_EP_0, false);
-
- //
- // Determine what type of status was requested.
- //
- switch(pUSBRequest->bmRequestType & USB_RTYPE_RECIPIENT_M)
- {
- //
- // This was a Device Status request.
- //
- case USB_RTYPE_DEVICE:
- {
- //
- // Return the current status for the device.
- //
- usData = (unsigned short)psUSBControl->ucStatus;
-
- break;
- }
-
- //
- // This was a Interface status request.
- //
- case USB_RTYPE_INTERFACE:
- {
- //
- // Interface status always returns 0.
- //
- usData = (unsigned short)0;
-
- break;
- }
-
- //
- // This was an endpoint status request.
- //
- case USB_RTYPE_ENDPOINT:
- {
- unsigned short usIndex;
- unsigned int ulDir;
-
- //
- // Which endpoint are we dealing with?
- //
- usIndex = pUSBRequest->wIndex & USB_REQ_EP_NUM_M;
-
- //
- // Check if this was a valid endpoint request.
- //
- if((usIndex == 0) || (usIndex >= NUM_USB_EP))
- {
- USBDCDStallEP0(ulIndex);
- return;
- }
- else
- {
- //
- // Are we dealing with an IN or OUT endpoint?
- //
- ulDir = ((pUSBRequest->wIndex & USB_REQ_EP_DIR_M) ==
- USB_REQ_EP_DIR_IN) ? HALT_EP_IN : HALT_EP_OUT;
-
- //
- // Get the current halt status for this endpoint.
- //
- usData =
- (unsigned short)psUSBControl->ucHalt[ulDir][usIndex - 1];
- }
- break;
- }
-
- //
- // This was an unknown request.
- //
- default:
- {
- //
- // Anything else causes a stall condition to indicate that the
- // command was not supported.
- //
- USBDCDStallEP0(ulIndex);
- return;
- }
- }
-
- //
- // Send the two byte status response.
- //
- psUSBControl->ulEP0DataRemain = 2;
- psUSBControl->pEP0Data = (unsigned char *)&usData;
-
- //
- // Send the response.
- //
- USBDEP0StateTx(ulIndex);
-}
-
-//*****************************************************************************
-//
-// This function handles the CLEAR_FEATURE standard USB request.
-//
-// \param pvInstance is the USB device controller instance data.
-// \param pUSBRequest holds the options for the Clear Feature USB request.
-//
-// This function handles device or endpoint clear feature requests. The
-// \e pUSBRequest structure holds the type of the request in the bmRequestType
-// field and the feature is held in the wValue field. The device can only
-// clear the Remote Wake feature. This device request should only be made if
-// the descriptor indicates that Remote Wake is implemented by the device.
-// Endpoints can only clear a halt on a given endpoint. If any other
-// requests are made, then the device will stall the request to indicate to
-// the host that the command was not supported.
-//
-// \return None.
-//
-//*****************************************************************************
-static void
-USBDClearFeature(void *pvInstance, tUSBRequest *pUSBRequest,
- unsigned int ulIndex)
-{
- tDeviceInstance *psUSBControl;
-
- ASSERT(pUSBRequest != 0);
- ASSERT(pvInstance != 0);
-
- //
- // Create the device information pointer.
- //
- psUSBControl = (tDeviceInstance *)pvInstance;
-
- //
- // Need to ACK the data on end point 0 with last data set as this has no
- // data phase.
- //
- USBDevEndpointDataAck(g_USBInstance[ulIndex].uiBaseAddr, USB_EP_0, true);
-
- //
- // Determine what type of status was requested.
- //
- switch(pUSBRequest->bmRequestType & USB_RTYPE_RECIPIENT_M)
- {
- //
- // This is a clear feature request at the device level.
- //
- case USB_RTYPE_DEVICE:
- {
- //
- // Only remote wake is can be cleared by this function.
- //
- if(USB_FEATURE_REMOTE_WAKE & pUSBRequest->wValue)
- {
- //
- // Clear the remote wake up state.
- //
- psUSBControl->ucStatus &= ~USB_STATUS_REMOTE_WAKE;
- }
- else
- {
- USBDCDStallEP0(ulIndex);
- }
- break;
- }
-
- //
- // This is a clear feature request at the endpoint level.
- //
- case USB_RTYPE_ENDPOINT:
- {
- unsigned int ulDir;
- unsigned short usIndex;
-
- //
- // Which endpoint are we dealing with?
- //
- usIndex = pUSBRequest->wIndex & USB_REQ_EP_NUM_M;
-
- //
- // Not a valid endpoint.
- //
- if((usIndex == 0) || (usIndex > NUM_USB_EP))
- {
- USBDCDStallEP0(ulIndex);
- }
- else
- {
- //
- // Only the halt feature is supported.
- //
- if(USB_FEATURE_EP_HALT == pUSBRequest->wValue)
- {
- //
- // Are we dealing with an IN or OUT endpoint?
- //
- ulDir = ((pUSBRequest->wIndex & USB_REQ_EP_DIR_M) ==
- USB_REQ_EP_DIR_IN) ? HALT_EP_IN : HALT_EP_OUT;
-
- //
- // Clear the halt condition on this endpoint.
- //
- psUSBControl->ucHalt[ulDir][usIndex - 1] = 0;
-
- if(ulDir == HALT_EP_IN)
- {
- USBDevEndpointStallClear(g_USBInstance[ulIndex].uiBaseAddr,
- INDEX_TO_USB_EP(usIndex),
- USB_EP_DEV_IN);
- }
- else
- {
- USBDevEndpointStallClear(g_USBInstance[ulIndex].uiBaseAddr,
- INDEX_TO_USB_EP(usIndex),
- USB_EP_DEV_OUT);
- }
- }
- else
- {
- //
- // If any other feature is requested, this is an error.
- //
- USBDCDStallEP0(ulIndex);
- return;
- }
- }
- break;
- }
-
- //
- // This is an unknown request.
- //
- default:
- {
- USBDCDStallEP0(ulIndex);
- return;
- }
- }
-}
-
-//*****************************************************************************
-//
-// This function handles the SET_FEATURE standard USB request.
-//
-// \param pvInstance is the USB device controller instance data.
-// \param pUSBRequest holds the feature in the wValue field of the USB
-// request.
-//
-// This function handles device or endpoint set feature requests. The
-// \e pUSBRequest structure holds the type of the request in the bmRequestType
-// field and the feature is held in the wValue field. The device can only
-// set the Remote Wake feature. This device request should only be made if the
-// descriptor indicates that Remote Wake is implemented by the device.
-// Endpoint requests can only issue a halt on a given endpoint. If any other
-// requests are made, then the device will stall the request to indicate to the
-// host that the command was not supported.
-//
-// \return None.
-//
-//*****************************************************************************
-static void
-USBDSetFeature(void *pvInstance, tUSBRequest *pUSBRequest,
- unsigned int ulIndex)
-{
- tDeviceInstance *psUSBControl;
-
- ASSERT(pUSBRequest != 0);
- ASSERT(pvInstance != 0);
-
- //
- // Create the device information pointer.
- //
- psUSBControl = (tDeviceInstance *)pvInstance;
-
- //
- // Need to ACK the data on end point 0 with last data set as this has no
- // data phase.
- //
- USBDevEndpointDataAck(g_USBInstance[ulIndex].uiBaseAddr, USB_EP_0, true);
-
- //
- // Determine what type of status was requested.
- //
- switch(pUSBRequest->bmRequestType & USB_RTYPE_RECIPIENT_M)
- {
- //
- // This is a set feature request at the device level.
- //
- case USB_RTYPE_DEVICE:
- {
- //
- // Only remote wake is the only feature that can be set by this
- // function.
- //
- if(USB_FEATURE_REMOTE_WAKE & pUSBRequest->wValue)
- {
- //
- // Set the remote wake up state.
- //
- psUSBControl->ucStatus |= USB_STATUS_REMOTE_WAKE;
- }
- else
- {
- USBDCDStallEP0(ulIndex);
- }
- break;
- }
-
- //
- // This is a set feature request at the endpoint level.
- //
- case USB_RTYPE_ENDPOINT:
- {
- unsigned short usIndex;
- unsigned int ulDir;
-
- //
- // Which endpoint are we dealing with?
- //
- usIndex = pUSBRequest->wIndex & USB_REQ_EP_NUM_M;
-
- //
- // Not a valid endpoint?
- //
- if((usIndex == 0) || (usIndex >= NUM_USB_EP))
- {
- USBDCDStallEP0(ulIndex);
- }
- else
- {
- //
- // Only the Halt feature can be set.
- //
- if(USB_FEATURE_EP_HALT == pUSBRequest->wValue)
- {
- //
- // Are we dealing with an IN or OUT endpoint?
- //
- ulDir = ((pUSBRequest->wIndex & USB_REQ_EP_DIR_M) ==
- USB_REQ_EP_DIR_IN) ? HALT_EP_IN : HALT_EP_OUT;
-
- //
- // Clear the halt condition on this endpoint.
- //
- psUSBControl->ucHalt[ulDir][usIndex - 1] = 1;
- }
- else
- {
- //
- // No other requests are supported.
- //
- USBDCDStallEP0(ulIndex);
- return;
- }
- }
- break;
- }
-
- //
- // This is an unknown request.
- //
- default:
- {
- USBDCDStallEP0(ulIndex);
- return;
- }
- }
-}
-
-//*****************************************************************************
-//
-// This function handles the SET_ADDRESS standard USB request.
-//
-// \param pvInstance is the USB device controller instance data.
-// \param pUSBRequest holds the new address to use in the wValue field of the
-// USB request.
-//
-// This function is called to handle the change of address request from the
-// host controller. This can only start the sequence as the host must
-// acknowledge that the device has changed address. Thus this function sets
-// the address change as pending until the status phase of the request has
-// been completed successfully. This prevents the devices address from
-// changing and not properly responding to the status phase.
-//
-// \return None.
-//
-//*****************************************************************************
-static void
-USBDSetAddress(void *pvInstance, tUSBRequest *pUSBRequest,
- unsigned int ulIndex)
-{
- tDeviceInstance *psUSBControl;
-
- ASSERT(pUSBRequest != 0);
- ASSERT(pvInstance != 0);
-
- //
- // Create the device information pointer.
- //
- psUSBControl = (tDeviceInstance *)pvInstance;
-
- //
- // Need to ACK the data on end point 0 with last data set as this has no
- // data phase.
- //
- USBDevEndpointDataAck(g_USBInstance[ulIndex].uiBaseAddr, USB_EP_0, true);
-
- //
- // Save the device address as we cannot change address until the status
- // phase is complete.
- //
- psUSBControl->ulDevAddress = pUSBRequest->wValue | DEV_ADDR_PENDING;
-
- //
- // Transition directly to the status state since there is no data phase
- // for this request.
- //
- psUSBControl->eEP0State = USB_STATE_STATUS;
-}
-
-//*****************************************************************************
-//
-// This function handles the GET_DESCRIPTOR standard USB request.
-//
-// \param pvInstance is the USB device controller instance data.
-// \param pUSBRequest holds the data for this request.
-//
-// This function will return most of the descriptors requested by the host
-// controller. The descriptor specified by \e
-// pvInstance->psInfo->pDeviceDescriptor will be returned when the device
-// descriptor is requested. If a request for a specific configuration
-// descriptor is made, then the appropriate descriptor from the \e
-// g_pConfigDescriptors will be returned. When a request for a string
-// descriptor is made, the appropriate string from the
-// \e pvInstance->psInfo->pStringDescriptors will be returned. If the \e
-// pvInstance->psInfo->sCallbacks.GetDescriptor is specified it will be
-// called to handle the request. In this case it must call the
-// USBDCDSendDataEP0() function to send the data to the host controller. If
-// the callback is not specified, and the descriptor request is not for a
-// device, configuration, or string descriptor then this function will stall
-// the request to indicate that the request was not supported by the device.
-//
-// \return None.
-//
-//*****************************************************************************
-static void
-USBDGetDescriptor(void *pvInstance, tUSBRequest *pUSBRequest,
- unsigned int ulIndex)
-{
- tBoolean bConfig;
- tDeviceInstance *psUSBControl;
- tDeviceInfo *psDevice;
-
- ASSERT(pUSBRequest != 0);
- ASSERT(pvInstance != 0);
-
- //
- // Create the device information pointer.
- //
- psUSBControl = (tDeviceInstance *)pvInstance;
- psDevice = psUSBControl->psInfo;
-
- //
- // Need to ACK the data on end point 0 without setting last data as there
- // will be a data phase.
- //
- USBDevEndpointDataAck(g_USBInstance[ulIndex].uiBaseAddr, USB_EP_0, false);
-
- //
- // Assume we are not sending the configuration descriptor until we
- // determine otherwise.
- //
- bConfig = false;
-
- //
- // Which descriptor are we being asked for?
- //
- switch(pUSBRequest->wValue >> 8)
- {
- //
- // This request was for a device descriptor.
- //
- case USB_DTYPE_DEVICE:
- {
- //
- // Return the externally provided device descriptor.
- //
- psUSBControl->pEP0Data =
- (unsigned char *)psDevice->pDeviceDescriptor;
-
- //
- // The size of the device descriptor is in the first byte.
- //
- psUSBControl->ulEP0DataRemain = psDevice->pDeviceDescriptor[0];
-
- break;
- }
-
- //
- // This request was for a configuration descriptor.
- //
- case USB_DTYPE_CONFIGURATION:
- {
- const tConfigHeader *psConfig;
- const tDeviceDescriptor *psDeviceDesc;
- unsigned char ucIndex;
-
- //
- // Which configuration are we being asked for?
- //
- ucIndex = (unsigned char)(pUSBRequest->wValue & 0xFF);
-
- //
- // Is this valid?
- //
- psDeviceDesc =
- (const tDeviceDescriptor *)psDevice->pDeviceDescriptor;
-
- if(ucIndex >= psDeviceDesc->bNumConfigurations)
- {
- //
- // This is an invalid configuration index. Stall EP0 to
- // indicate a request error.
- //
- USBDCDStallEP0(ulIndex);
- psUSBControl->pEP0Data = 0;
- psUSBControl->ulEP0DataRemain = 0;
- }
- else
- {
- //
- // Return the externally specified configuration descriptor.
- //
- psConfig = psDevice->ppConfigDescriptors[ucIndex];
-
- //
- // Start by sending data from the beginning of the first
- // descriptor.
- //
- psUSBControl->ucConfigSection = 0;
- psUSBControl->ucSectionOffset = 0;
- psUSBControl->pEP0Data = (unsigned char *)
- psConfig->psSections[0]->pucData;
-
- //
- // Determine the total size of the configuration descriptor
- // by counting the sizes of the sections comprising it.
- //
- psUSBControl->ulEP0DataRemain =
- USBDCDConfigDescGetSize(psConfig);
-
- //
- // Remember that we need to send the configuration descriptor
- // and which descriptor we need to send.
- //
- psUSBControl->ucConfigIndex = ucIndex;
-
- bConfig = true;
- }
- break;
- }
-
- //
- // This request was for a string descriptor.
- //
- case USB_DTYPE_STRING:
- {
- int lIndex;
-
- //
- // Determine the correct descriptor index based on the requested
- // language ID and index.
- //
- lIndex = USBDStringIndexFromRequest(pUSBRequest->wIndex,
- pUSBRequest->wValue & 0xFF, ulIndex);
-
- //
- // If the mapping function returned -1 then stall the request to
- // indicate that the request was not valid.
- //
- if(lIndex == -1)
- {
- USBDCDStallEP0(ulIndex);
- break;
- }
-
- //
- // Return the externally specified configuration descriptor.
- //
- psUSBControl->pEP0Data =
- (unsigned char *)psDevice->ppStringDescriptors[lIndex];
-
- //
- // The total size of a string descriptor is in byte 0.
- //
- psUSBControl->ulEP0DataRemain =
- psDevice->ppStringDescriptors[lIndex][0];
-
- break;
- }
-
- //
- // Any other request is not handled by the default enumeration handler
- // so see if it needs to be passed on to another handler.
- //
- default:
- {
- //
- // If there is a handler for requests that are not handled then
- // call it.
- //
- if(psDevice->sCallbacks.pfnGetDescriptor)
- {
- psDevice->sCallbacks.pfnGetDescriptor(psUSBControl->pvInstance,
- pUSBRequest, ulIndex);
- return;
- }
- else
- {
- //
- // Whatever this was this handler does not understand it so
- // just stall the request.
- //
- USBDCDStallEP0(ulIndex);
- }
- break;
- }
- }
-
- //
- // If this request has data to send, then send it.
- //
- if(psUSBControl->pEP0Data)
- {
- //
- // If there is more data to send than is requested then just
- // send the requested amount of data.
- //
- if(psUSBControl->ulEP0DataRemain > pUSBRequest->wLength)
- {
- psUSBControl->ulEP0DataRemain = pUSBRequest->wLength;
- }
-
- //
- // Now in the transmit data state. Be careful to call the correct
- // function since we need to handle the configuration descriptor
- // differently from the others.
- //
- if(!bConfig)
- {
- USBDEP0StateTx(ulIndex);
- }
- else
- {
- USBDEP0StateTxConfig(ulIndex);
- }
- }
-}
-
-//*****************************************************************************
-//
-// This function determines which string descriptor to send to satisfy a
-// request for a given index and language.
-//
-// \param usLang is the requested string language ID.
-// \param usIndex is the requested string descriptor index.
-//
-// When a string descriptor is requested, the host provides a language ID and
-// index to identify the string ("give me string number 5 in French"). This
-// function maps these two parameters to an index within our device's string
-// descriptor array which is arranged as multiple groups of strings with
-// one group for each language advertised via string descriptor 0.
-//
-// We assume that there are an equal number of strings per language and
-// that the first descriptor is the language descriptor and use this fact to
-// perform the mapping.
-//
-// \return The index of the string descriptor to return or -1 if the string
-// could not be found.
-//
-//*****************************************************************************
-static int
-USBDStringIndexFromRequest(unsigned short usLang, unsigned short usIndex,
- unsigned int ulIndex)
-{
- tString0Descriptor *pLang;
- unsigned int ulNumLangs;
- unsigned int ulNumStringsPerLang;
- unsigned int ulLoop;
-
- //
- // Make sure we have a string table at all.
- //
- if((g_psUSBDevice[ulIndex].psInfo == 0) ||
- (g_psUSBDevice[ulIndex].psInfo->ppStringDescriptors == 0))
- {
- return(-1);
- }
-
- //
- // First look for the trivial case where descriptor 0 is being
- // requested. This is the special case since descriptor 0 contains the
- // language codes supported by the device.
- //
- if(usIndex == 0)
- {
- return(0);
- }
-
- //
- // How many languages does this device support? This is determined by
- // looking at the length of the first descriptor in the string table,
- // subtracting 2 for the header and dividing by two (the size of each
- // language code).
- //
- ulNumLangs = (g_psUSBDevice[ulIndex].psInfo->ppStringDescriptors[0][0] - 2) / 2;
-
- //
- // We assume that the table includes the same number of strings for each
- // supported language. We know the number of entries in the string table,
- // so how many are there for each language? This may seem an odd way to
- // do this (why not just have the application tell us in the device info
- // structure?) but it's needed since we didn't want to change the API
- // after the first release which did not support multiple languages.
- //
- ulNumStringsPerLang = ((g_psUSBDevice[ulIndex].psInfo->ulNumStringDescriptors - 1) /
- ulNumLangs);
-
- //
- // Just to be sure, make sure that the calculation indicates an equal
- // number of strings per language. We expect the string table to contain
- // (1 + (strings_per_language * languages)) entries.
- //
- if((1 + (ulNumStringsPerLang * ulNumLangs)) !=
- g_psUSBDevice[ulIndex].psInfo->ulNumStringDescriptors)
- {
- return(-1);
- }
-
- //
- // Now determine which language we are looking for. It is assumed that
- // the order of the groups of strings per language in the table is the
- // same as the order of the language IDs listed in the first descriptor.
- //
- pLang = (tString0Descriptor *)(g_psUSBDevice[ulIndex].psInfo->ppStringDescriptors[0]);
-
- //
- // Look through the supported languages looking for the one we were asked
- // for.
- //
- for(ulLoop = 0; ulLoop < ulNumLangs; ulLoop++)
- {
- //
- // Have we found the requested language?
- //
- if(pLang->wLANGID[ulLoop] == usLang)
- {
- //
- // Yes - calculate the index of the descriptor to send.
- //
- return((ulNumStringsPerLang * ulLoop) + usIndex);
- }
- }
-
- //
- // If we drop out of the loop, the requested language was not found so
- // return -1 to indicate the error.
- //
- return(-1);
-}
-
-//*****************************************************************************
-//
-// This function handles the SET_DESCRIPTOR standard USB request.
-//
-// \param pvInstance is the USB device controller instance data.
-// \param pUSBRequest holds the data for this request.
-//
-// This function currently is not supported and will respond with a Stall
-// to indicate that this command is not supported by the device.
-//
-// \return None.
-//
-//*****************************************************************************
-static void
-USBDSetDescriptor(void *pvInstance, tUSBRequest *pUSBRequest,
- unsigned int ulIndex)
-{
- //
- // Need to ACK the data on end point 0 without setting last data as there
- // will be a data phase.
- //
- USBDevEndpointDataAck(g_USBInstance[ulIndex].uiBaseAddr, USB_EP_0, false);
-
- //
- // This function is not handled by default.
- //
- USBDCDStallEP0(ulIndex);
-}
-
-//*****************************************************************************
-//
-// This function handles the GET_CONFIGURATION standard USB request.
-//
-// \param pvInstance is the USB device controller instance data.
-// \param pUSBRequest holds the data for this request.
-//
-// This function responds to a host request to return the current
-// configuration of the USB device. The function will send the configuration
-// response to the host and return. This value will either be 0 or the last
-// value received from a call to SetConfiguration().
-//
-// \return None.
-//
-//*****************************************************************************
-static void
-USBDGetConfiguration(void *pvInstance, tUSBRequest *pUSBRequest,
- unsigned int ulIndex)
-{
- unsigned char ucValue;
- tDeviceInstance *psUSBControl;
-
- ASSERT(pUSBRequest != 0);
- ASSERT(pvInstance != 0);
-
- //
- // Create the device information pointer.
- //
- psUSBControl = (tDeviceInstance *)pvInstance;
-
- //
- // Need to ACK the data on end point 0 without setting last data as there
- // will be a data phase.
- //
- USBDevEndpointDataAck(g_USBInstance[ulIndex].uiBaseAddr, USB_EP_0, false);
-
- //
- // If we still have an address pending then the device is still not
- // configured.
- //
- if(psUSBControl->ulDevAddress & DEV_ADDR_PENDING)
- {
- ucValue = 0;
- }
- else
- {
- ucValue = (unsigned char)psUSBControl->ulConfiguration;
- }
-
- psUSBControl->ulEP0DataRemain = 1;
- psUSBControl->pEP0Data = &ucValue;
-
- //
- // Send the single byte response.
- //
- USBDEP0StateTx(ulIndex);
-}
-
-//*****************************************************************************
-//
-// This function handles the SET_CONFIGURATION standard USB request.
-//
-// \param pvInstance is the USB device controller instance data.
-// \param pUSBRequest holds the data for this request.
-//
-// This function responds to a host request to change the current
-// configuration of the USB device. The actual configuration number is taken
-// from the structure passed in via \e pUSBRequest. This number should be one
-// of the configurations that was specified in the descriptors. If the
-// \e ConfigChange callback is specified in \e pvInstance->psInfo->sCallbacks,
-// it will be called so that the application can respond to a change in
-// configuration.
-//
-// \return None.
-//
-//*****************************************************************************
-static void
-USBDSetConfiguration(void *pvInstance, tUSBRequest *pUSBRequest,
- unsigned int ulIndex)
-{
- tDeviceInstance *psUSBControl;
- tDeviceInfo *psDevice;
-
- //
- // Create the device information pointer.
- //
- psUSBControl = (tDeviceInstance *)pvInstance;
- psDevice = psUSBControl->psInfo;
-
- //
- // Need to ACK the data on end point 0 with last data set as this has no
- // data phase.
- //
- USBDevEndpointDataAck(g_USBInstance[ulIndex].uiBaseAddr, USB_EP_0, true);
-
- //
- // Cannot set the configuration to one that does not exist so check the
- // enumeration structure to see how many valid configurations are present.
- //
- if(pUSBRequest->wValue > psUSBControl->psInfo->pDeviceDescriptor[17])
- {
- //
- // The passed configuration number is not valid. Stall the endpoint to
- // signal the error to the host.
- //
- USBDCDStallEP0(ulIndex);
- }
- else
- {
- //
- // Save the configuration.
- //
- psUSBControl->ulConfiguration = pUSBRequest->wValue;
-
- //
- // If passed a configuration other than 0 (which tells us that we are
- // not currently configured), configure the endpoints (other than EP0)
- // appropriately.
- //
- if(psUSBControl->ulConfiguration)
- {
- const tConfigHeader *psHdr;
- const tConfigDescriptor *psDesc;
-
- //
- // Get a pointer to the configuration descriptor. This will always
- // be the first section in the current configuration.
- //
- psHdr = psDevice->ppConfigDescriptors[pUSBRequest->wValue - 1];
- psDesc = (const tConfigDescriptor *)(psHdr->psSections[0]->pucData);
-
- //
- // Remember the new self- or bus-powered state if the user has not
- // already called us to tell us the state to report.
- //
- if(!psUSBControl->bPwrSrcSet)
- {
- if((psDesc->bmAttributes & USB_CONF_ATTR_PWR_M) ==
- USB_CONF_ATTR_SELF_PWR)
- {
- psUSBControl->ucStatus |= USB_STATUS_SELF_PWR;
- }
- else
- {
- psUSBControl->ucStatus &= ~USB_STATUS_SELF_PWR;
- }
- }
-
- //
- // Configure endpoints for the new configuration.
- //
- USBDeviceConfig(0,
- psDevice->ppConfigDescriptors[pUSBRequest->wValue - 1],
- psDevice->psFIFOConfig);
- }
-
- //
- // If there is a configuration change callback then call it.
- //
- if(psDevice->sCallbacks.pfnConfigChange)
- {
- psDevice->sCallbacks.pfnConfigChange(
- psUSBControl->pvInstance, psUSBControl->ulConfiguration, ulIndex);
- }
- }
-}
-
-//*****************************************************************************
-//
-// This function handles the GET_INTERFACE standard USB request.
-//
-// \param pvInstance is the USB device controller instance data.
-// \param pUSBRequest holds the data for this request.
-//
-// This function is called when the host controller request the current
-// interface that is in use by the device. This simply returns the value set
-// by the last call to SetInterface().
-//
-// \return None.
-//
-//*****************************************************************************
-static void
-USBDGetInterface(void *pvInstance, tUSBRequest *pUSBRequest,
- unsigned int ulIndex)
-{
- unsigned char ucValue;
- tDeviceInstance *psUSBControl;
-
- ASSERT(pUSBRequest != 0);
- ASSERT(pvInstance != 0);
-
- //
- // Create the device information pointer.
- //
- psUSBControl = (tDeviceInstance *)pvInstance;
-
- //
- // Need to ACK the data on end point 0 without setting last data as there
- // will be a data phase.
- //
- USBDevEndpointDataAck(g_USBInstance[ulIndex].uiBaseAddr, USB_EP_0, false);
-
- //
- // If we still have an address pending then the device is still not
- // configured.
- //
- if(psUSBControl->ulDevAddress & DEV_ADDR_PENDING)
- {
- ucValue = (unsigned char)0;
- }
- else
- {
- //
- // Is the interface number valid?
- //
- if(pUSBRequest->wIndex < USB_MAX_INTERFACES_PER_DEVICE)
- {
- //
- // Read the current alternate setting for the required interface.
- //
- ucValue = psUSBControl->pucAltSetting[pUSBRequest->wIndex];
- }
- else
- {
- //
- // An invalid interface number was specified.
- //
- USBDCDStallEP0(ulIndex);
- return;
- }
- }
-
- //
- // Send the single byte response.
- //
- psUSBControl->ulEP0DataRemain = 1;
- psUSBControl->pEP0Data = &ucValue;
-
- //
- // Send the single byte response.
- //
- USBDEP0StateTx(ulIndex);
-}
-
-//*****************************************************************************
-//
-// This function handles the SET_INTERFACE standard USB request.
-//
-// \param pvInstance is the USB device controller instance data.
-// \param pUSBRequest holds the data for this request.
-//
-// This function is called when a standard request for changing the interface
-// is received from the host controller. If this is a valid request the
-// function will call the function specified by the InterfaceChange in the
-// \e pvInstance->psInfo->sCallbacks variable to notify the application that the
-// interface has changed and will pass it the new alternate interface number.
-//
-// \return None.
-//
-//*****************************************************************************
-static void
-USBDSetInterface(void *pvInstance, tUSBRequest *pUSBRequest,
- unsigned int ulIndex)
-{
- const tConfigHeader *psConfig;
- tInterfaceDescriptor *psInterface;
- unsigned int ulLoop;
- unsigned int ulSection;
- unsigned int ulNumInterfaces;
- unsigned char ucInterface;
- tBoolean bRetcode;
- tDeviceInstance *psUSBControl;
- tDeviceInfo *psDevice;
-
- ASSERT(pUSBRequest != 0);
- ASSERT(pvInstance != 0);
-
- //
- // Create the device information pointer.
- //
- psUSBControl = (tDeviceInstance *)pvInstance;
- psDevice = psUSBControl->psInfo;
-
- //
- // Need to ACK the data on end point 0 with last data set as this has no
- // data phase.
- //
- USBDevEndpointDataAck(g_USBInstance[ulIndex].uiBaseAddr, USB_EP_0, true);
-
- //
- // Use the current configuration.
- //
- psConfig = psDevice->ppConfigDescriptors[psUSBControl->ulConfiguration - 1];
-
- //
- // How many interfaces are included in the descriptor?
- //
- ulNumInterfaces = USBDCDConfigDescGetNum(psConfig,
- USB_DTYPE_INTERFACE);
-
- //
- // Find the interface descriptor for the supplied interface and alternate
- // setting numbers.
- //
- for(ulLoop = 0; ulLoop < ulNumInterfaces; ulLoop++)
- {
- //
- // Get the next interface descriptor in the configuration descriptor.
- //
- psInterface = USBDCDConfigGetInterface(psConfig, ulLoop, USB_DESC_ANY,
- &ulSection);
-
- //
- // Is this the required interface with the correct alternate setting?
- //
- if(psInterface &&
- (psInterface->bInterfaceNumber == pUSBRequest->wIndex) &&
- (psInterface->bAlternateSetting == pUSBRequest->wValue))
- {
- ucInterface = psInterface->bInterfaceNumber;
-
- //
- // Make sure we don't write outside the bounds of the pucAltSetting
- // array (in a debug build, anyway, since this indicates an error
- // in the device descriptor).
- //
- ASSERT(ucInterface < USB_MAX_INTERFACES_PER_DEVICE);
-
- //
- // If anything changed, reconfigure the endpoints for the new
- // alternate setting.
- //
- if(psUSBControl->pucAltSetting[ucInterface] !=
- psInterface->bAlternateSetting)
- {
- //
- // This is the correct interface descriptor so save the
- // setting.
- //
- psUSBControl->pucAltSetting[ucInterface] =
- psInterface->bAlternateSetting;
-
- //
- // Reconfigure the endpoints to match the requirements of the
- // new alternate setting for the interface.
- //
- bRetcode = USBDeviceConfigAlternate(0, psConfig, ucInterface,
- psInterface->bAlternateSetting);
-
- //
- // If there is a callback then notify the application of the
- // change to the alternate interface.
- //
- if(bRetcode && psDevice->sCallbacks.pfnInterfaceChange)
- {
- psDevice->sCallbacks.pfnInterfaceChange(
- psUSBControl->pvInstance,
- pUSBRequest->wIndex,
- pUSBRequest->wValue);
- }
- }
-
- //
- // All done.
- //
- return;
- }
- }
-
- //
- // If we drop out of the loop, we didn't find an interface descriptor
- // matching the requested number and alternate setting or there was an
- // error while trying to set up for the new alternate setting.
- //
- USBDCDStallEP0(ulIndex);
-}
-
-//*****************************************************************************
-//
-// This function handles the SYNC_FRAME standard USB request.
-//
-// \param pvInstance is the USB device controller instance data.
-// \param pUSBRequest holds the data for this request.
-//
-// This is currently a stub function that will stall indicating that the
-// command is not supported.
-//
-// \return None.
-//
-//*****************************************************************************
-static void
-USBDSyncFrame(void *pvInstance, tUSBRequest *pUSBRequest,
- unsigned int ulIndex)
-{
- //
- // Need to ACK the data on end point 0 with last data set as this has no
- // data phase.
- //
- USBDevEndpointDataAck(g_USBInstance[ulIndex].uiBaseAddr, USB_EP_0, true);
-
- //
- // Not handled yet so stall this request.
- //
- USBDCDStallEP0(ulIndex);
-}
-
-//*****************************************************************************
-//
-// This internal function handles sending data on endpoint zero.
-//
-// \param ulIndex is the index of the USB controller which is to be
-// initialized.
-//
-// \return None.
-//
-//*****************************************************************************
-static void
-USBDEP0StateTx(unsigned int ulIndex)
-{
- unsigned int ulNumBytes;
- unsigned char *pData;
-
- ASSERT(ulIndex == 0);
-
- //
- // In the TX state on endpoint zero.
- //
- g_psUSBDevice[ulIndex].eEP0State = USB_STATE_TX;
-
- //
- // Set the number of bytes to send this iteration.
- //
- ulNumBytes = g_psUSBDevice[ulIndex].ulEP0DataRemain;
-
- //
- // Limit individual transfers to 64 bytes.
- //
- if(ulNumBytes > EP0_MAX_PACKET_SIZE)
- {
- ulNumBytes = EP0_MAX_PACKET_SIZE;
- }
-
- //
- // Save the pointer so that it can be passed to the USBEndpointDataPut()
- // function.
- //
- pData = (unsigned char *)g_psUSBDevice[ulIndex].pEP0Data;
-
- //
- // Advance the data pointer and counter to the next data to be sent.
- //
- g_psUSBDevice[ulIndex].ulEP0DataRemain -= ulNumBytes;
- g_psUSBDevice[ulIndex].pEP0Data += ulNumBytes;
-
- //
- // Put the data in the correct FIFO.
- //
- USBEndpointDataPut(g_USBInstance[ulIndex].uiBaseAddr, USB_EP_0, pData, ulNumBytes);
-
- //
- // If this is exactly 64 then don't set the last packet yet.
- //
- if(ulNumBytes == EP0_MAX_PACKET_SIZE)
- {
- //
- // There is more data to send or exactly 64 bytes were sent, this
- // means that there is either more data coming or a null packet needs
- // to be sent to complete the transaction.
- //
- USBEndpointDataSend(g_USBInstance[ulIndex].uiBaseAddr, USB_EP_0, USB_TRANS_IN);
- }
- else
- {
- //
- // Now go to the status state and wait for the transmit to complete.
- //
- g_psUSBDevice[ulIndex].eEP0State = USB_STATE_STATUS;
-
- //
- // Send the last bit of data.
- //
- USBEndpointDataSend(g_USBInstance[ulIndex].uiBaseAddr, USB_EP_0,
- USB_TRANS_IN_LAST);
-
- //
- // If there is a sent callback then call it.
- //
- if((g_psUSBDevice[ulIndex].psInfo->sCallbacks.pfnDataSent) &&
- (g_psUSBDevice[ulIndex].ulOUTDataSize != 0))
- {
- //
- // Call the custom handler.
- //
- g_psUSBDevice[ulIndex].psInfo->sCallbacks.pfnDataSent(
- g_psUSBDevice[ulIndex].pvInstance, g_psUSBDevice[ulIndex].ulOUTDataSize,
- ulIndex);
-
- //
- // There is no longer any data pending to be sent.
- //
- g_psUSBDevice[ulIndex].ulOUTDataSize = 0;
- }
- }
-}
-
-//*****************************************************************************
-//
-// This internal function handles sending the configuration descriptor on
-// endpoint zero.
-//
-// \param ulIndex is the index of the USB controller which is to be used.
-//
-//
-// \return None.
-//
-//*****************************************************************************
-static void
-USBDEP0StateTxConfig(unsigned int ulIndex)
-{
- unsigned int ulNumBytes;
- unsigned int ulSecBytes;
- unsigned int ulToSend;
- unsigned char *pData;
- tConfigDescriptor sConfDesc;
- const tConfigHeader *psConfig;
- const tConfigSection *psSection;
-
- ASSERT(ulIndex == 0);
-
- //
- // In the TX state on endpoint zero.
- //
- g_psUSBDevice[ulIndex].eEP0State = USB_STATE_TX_CONFIG;
-
- //
- // Find the current configuration descriptor definition.
- //
- psConfig = g_psUSBDevice[ulIndex].psInfo->ppConfigDescriptors[
- g_psUSBDevice[ulIndex].ucConfigIndex];
-
- //
- // Set the number of bytes to send this iteration.
- //
- ulNumBytes = g_psUSBDevice[ulIndex].ulEP0DataRemain;
-
- //
- // Limit individual transfers to 64 bytes.
- //
- if(ulNumBytes > EP0_MAX_PACKET_SIZE)
- {
- ulNumBytes = EP0_MAX_PACKET_SIZE;
- }
-
- //
- // If this is the first call, we need to fix up the total length of the
- // configuration descriptor. This has already been determined and set in
- // g_sUSBDeviceState.ulEP0DataRemain.
- //
- if((g_psUSBDevice[ulIndex].ucSectionOffset == 0) &&
- (g_psUSBDevice[ulIndex].ucConfigSection == 0))
- {
- //
- // Copy the USB configuration descriptor from the beginning of the
- // first section of the current configuration.
- //
- sConfDesc = *(tConfigDescriptor *)g_psUSBDevice[ulIndex].pEP0Data;
-
- //
- // Update the total size.
- //
- sConfDesc.wTotalLength = (unsigned short)USBDCDConfigDescGetSize(
- psConfig);
-
- //
- // Write the descriptor to the USB FIFO.
- //
- ulToSend = (ulNumBytes < sizeof(tConfigDescriptor)) ? ulNumBytes :
- sizeof(tConfigDescriptor);
- USBEndpointDataPut(g_USBInstance[ulIndex].uiBaseAddr, USB_EP_0,
- (unsigned char *)&sConfDesc, ulToSend);
-
- //
- // Did we reach the end of the first section?
- //
- if(psConfig->psSections[0]->ucSize == ulToSend)
- {
- //
- // Update our tracking indices to point to the start of the next
- // section.
- //
- g_psUSBDevice[ulIndex].ucSectionOffset = 0;
- g_psUSBDevice[ulIndex].ucConfigSection = 1;
- }
- else
- {
- //
- // Note that we have sent the first few bytes of the descriptor.
- //
- g_psUSBDevice[ulIndex].ucSectionOffset = (unsigned char)ulToSend;
- }
-
- //
- // How many bytes do we have remaining to send on this iteration?
- //
- ulToSend = ulNumBytes - ulToSend;
- }
- else
- {
- //
- // Set the number of bytes we still have to send on this call.
- //
- ulToSend = ulNumBytes;
- }
-
- //
- // Add the relevant number of bytes to the USB FIFO
- //
- while(ulToSend)
- {
- //
- // Get a pointer to the current configuration section.
- //
- psSection = psConfig->psSections[g_psUSBDevice[ulIndex].ucConfigSection];
-
- //
- // Calculate bytes are available in the current configuration section.
- //
- ulSecBytes = (unsigned int)(psSection->ucSize -
- g_psUSBDevice[ulIndex].ucSectionOffset);
-
- //
- // Save the pointer so that it can be passed to the
- // USBEndpointDataPut() function.
- //
- pData = (unsigned char *)psSection->pucData +
- g_psUSBDevice[ulIndex].ucSectionOffset;
-
- //
- // Are there more bytes in this section that we still have to send?
- //
- if(ulSecBytes > ulToSend)
- {
- //
- // Yes - send only the remaining bytes in the transfer.
- //
- ulSecBytes = ulToSend;
- }
-
- //
- // Put the data in the correct FIFO.
- //
- USBEndpointDataPut(g_USBInstance[ulIndex].uiBaseAddr, USB_EP_0, pData, ulSecBytes);
-
- //
- // Fix up our pointers for the next iteration.
- //
- ulToSend -= ulSecBytes;
- g_psUSBDevice[ulIndex].ucSectionOffset += (unsigned char)ulSecBytes;
-
- //
- // Have we reached the end of a section?
- //
- if(g_psUSBDevice[ulIndex].ucSectionOffset == psSection->ucSize)
- {
- //
- // Yes - move to the next one.
- //
- g_psUSBDevice[ulIndex].ucConfigSection++;
- g_psUSBDevice[ulIndex].ucSectionOffset = 0;
- }
- }
-
- //
- // Fix up the number of bytes remaining to be sent and the start pointer.
- //
- g_psUSBDevice[ulIndex].ulEP0DataRemain -= ulNumBytes;
-
- //
- // If we ran out of bytes in the configuration section, bail and just
- // send out what we have.
- //
- if(psConfig->ucNumSections <= g_psUSBDevice[ulIndex].ucConfigSection)
- {
- g_psUSBDevice[ulIndex].ulEP0DataRemain = 0;
- }
-
- //
- // If there is no more data don't keep looking or ucConfigSection might
- // overrun the available space.
- //
- if(g_psUSBDevice[ulIndex].ulEP0DataRemain != 0)
- {
- pData =(unsigned char *)
- psConfig->psSections[g_psUSBDevice[ulIndex].ucConfigSection]->pucData;
- ulToSend = g_psUSBDevice[ulIndex].ucSectionOffset;
- g_psUSBDevice[ulIndex].pEP0Data = (pData + ulToSend);
- }
-
- //
- // If this is exactly 64 then don't set the last packet yet.
- //
- if(ulNumBytes == EP0_MAX_PACKET_SIZE)
- {
- //
- // There is more data to send or exactly 64 bytes were sent, this
- // means that there is either more data coming or a null packet needs
- // to be sent to complete the transaction.
- //
- USBEndpointDataSend(g_USBInstance[ulIndex].uiBaseAddr, USB_EP_0, USB_TRANS_IN);
- }
- else
- {
- //
- // Send the last bit of data.
- //
- USBEndpointDataSend(g_USBInstance[ulIndex].uiBaseAddr, USB_EP_0,
- USB_TRANS_IN_LAST);
-
- //
- // If there is a sent callback then call it.
- //
- if((g_psUSBDevice[ulIndex].psInfo->sCallbacks.pfnDataSent) &&
- (g_psUSBDevice[ulIndex].ulOUTDataSize != 0))
- {
- //
- // Call the custom handler.
- //
- g_psUSBDevice[ulIndex].psInfo->sCallbacks.pfnDataSent(
- g_psUSBDevice[ulIndex].pvInstance, g_psUSBDevice[ulIndex].ulOUTDataSize,
- ulIndex);
-
- //
- // There is no longer any data pending to be sent.
- //
- g_psUSBDevice[ulIndex].ulOUTDataSize = 0;
- }
-
- //
- // Now go to the status state and wait for the transmit to complete.
- //
- g_psUSBDevice[ulIndex].eEP0State = USB_STATE_STATUS;
- }
-}
-
-//*****************************************************************************
-//
-// The internal USB device interrupt handler.
-//
-// \param ulIndex is the USB controller associated with this interrupt.
-// \param ulStatus is the current interrupt status as read via a call to
-// USBIntStatusControl().
-//
-// This function is called from either \e USB0DualModeIntHandler() or
-// \e USB0DeviceIntHandler() to process USB interrupts when in device mode.
-// This handler will branch the interrupt off to the appropriate application or
-// stack handlers depending on the current status of the USB controller.
-//
-// The two-tiered structure for the interrupt handler ensures that it is
-// possible to use the same handler code in both device and OTG modes and
-// means that host code can be excluded from applications that only require
-// support for USB device mode operation.
-//
-// \return None.
-//
-//*****************************************************************************
-void
-USBDeviceIntHandlerInternal(unsigned int ulIndex, unsigned int ulStatus,
- unsigned int *endPStatus)
-{
- static unsigned int ulSOFDivide = 0;
- tDeviceInfo *psInfo;
- void *pvInstance;
- unsigned int epStatus;
- unsigned int epnStatus = 0;
-
- //
- // Get the controller interrupt status from the wrapper registers
- // Only the lower 16bits contain EP intr data
- //
- if(endPStatus == NULL)
- {
- epStatus= 0xFFFF & ulStatus;
- ulStatus >>=16;
- }
- else
- {
- epStatus = *endPStatus;
- }
-
- ulStatus |= USBIntStatusControl(g_USBInstance[ulIndex].uiBaseAddr);
-
- //
- // If device initialization has not been performed then just disconnect
- // from the USB bus and return from the handler.
- //
- if(g_psUSBDevice[ulIndex].psInfo == 0)
- {
- USBDevDisconnect(g_USBInstance[ulIndex].uiBaseAddr);
- return;
- }
-
- psInfo = g_psUSBDevice[ulIndex].psInfo;
- pvInstance = g_psUSBDevice[ulIndex].pvInstance;
-
- //
- // Received a reset from the host.
- //
- if(ulStatus & USB_INTCTRL_RESET)
- {
- USBDeviceEnumResetHandler(&g_psUSBDevice[ulIndex]);
- }
-
- //
- // Suspend was signaled on the bus.
- //
- if(ulStatus & USB_INTCTRL_SUSPEND)
- {
- //
- // Call the SuspendHandler() if it was specified.
- //
- if(psInfo->sCallbacks.pfnSuspendHandler)
- {
- psInfo->sCallbacks.pfnSuspendHandler(pvInstance);
- }
- }
-
- //
- // Resume was signaled on the bus.
- //
- if(ulStatus & USB_INTCTRL_RESUME)
- {
- //
- // Call the ResumeHandler() if it was specified.
- //
- if(psInfo->sCallbacks.pfnResumeHandler)
- {
- psInfo->sCallbacks.pfnResumeHandler(pvInstance);
- }
- }
-
- //
- // USB device was disconnected.
- //
- if(ulStatus & USB_INTCTRL_DISCONNECT)
- {
- //
- // Call the DisconnectHandler() if it was specified.
- //
- if(psInfo->sCallbacks.pfnDisconnectHandler)
- {
- psInfo->sCallbacks.pfnDisconnectHandler(pvInstance);
- }
- }
-
- //
- // Start of Frame was received.
- //
- if(ulStatus & USB_INTCTRL_SOF)
- {
- //
- // Increment the global Start of Frame counter.
- //
- g_ulUSBSOFCount++;
-
- //
- // Increment our SOF divider.
- //
- ulSOFDivide++;
-
- //
- // Handle resume signaling if required.
- //
- USBDeviceResumeTickHandler(ulIndex);
-
- //
- // Have we counted enough SOFs to allow us to call the tick function?
- //
- if(ulSOFDivide == USB_SOF_TICK_DIVIDE)
- {
- //
- // Yes - reset the divider and call the SOF tick handler.
- //
- ulSOFDivide = 0;
- InternalUSBStartOfFrameTick(USB_SOF_TICK_DIVIDE, ulIndex);
- }
- }
-
- //
- // Handle end point 0 interrupts.
- //
- if(epStatus & USB_INTEP_0)
- {
- USBDeviceEnumHandler(&g_psUSBDevice[ulIndex], ulIndex);
- }
-
- /*
- converting the epstatus(Wrapper register data) to ulStatus( MUSB register data)
- */
-
- if(endPStatus == NULL)
- {
- epnStatus = 0xFF & epStatus;
- epnStatus = epnStatus | ((0xFF00 & epStatus)<<8);
- }
- else
- {
- epnStatus = epStatus;
- }
- //
- // Because there is no way to detect if a uDMA interrupt has occurred, the
- // check for and endpoint callback and call it if it is available.
- //
- if(psInfo->sCallbacks.pfnEndpointHandler)
- {
- psInfo->sCallbacks.pfnEndpointHandler(pvInstance, epnStatus, ulIndex);
- }
-
-}
-
-//*****************************************************************************
-//
-// Close the Doxygen group.
-//! @}
-//
-//*****************************************************************************
diff --git a/SylixOS/StarterWare/usblib/device/usbdhandler.c b/SylixOS/StarterWare/usblib/device/usbdhandler.c
deleted file mode 100644
index 525a141..0000000
--- a/SylixOS/StarterWare/usblib/device/usbdhandler.c
+++ /dev/null
@@ -1,210 +0,0 @@
-//*****************************************************************************
-//
-// usbhandler.c - General USB handling routines.
-//
-// Copyright (c) 2007-2010 Texas Instruments Incorporated. All rights reserved.
-// Software License Agreement
-//
-// Texas Instruments (TI) is supplying this software for use solely and
-// exclusively on TI's microcontroller products. The software is owned by
-// TI and/or its suppliers, and is protected under applicable copyright
-// laws. You may not combine this software with "viral" open-source
-// software in order to form a larger program.
-//
-// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
-// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
-// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
-// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
-// DAMAGES, FOR ANY REASON WHATSOEVER.
-//
-// This is part of AM1808 StarterWare USB Library and reused from revision 6288
-// of the Stellaris USB Library.
-//
-//*****************************************************************************
-
-#include "hw_usb.h"
-#include "interrupt.h"
-#include "hw_types.h"
-#include "usb.h"
-#include "usblib.h"
-#include "usbdevice.h"
-#include "usbdevicepriv.h"
-#include "usblibpriv.h"
-
-//*****************************************************************************
-//
-//! \addtogroup device_api
-//! @{
-//
-//*****************************************************************************
-
-//*****************************************************************************
-//
-// USB instance Object
-//
-//*****************************************************************************
-extern tUSBInstanceObject g_USBInstance[];
-
-//*****************************************************************************
-//
-//! The USB device interrupt handler.
-//!
-//! This the main USB interrupt handler entry point for use in USB device
-//! applications. This top-level handler will branch the interrupt off to the
-//! appropriate application or stack handlers depending on the current status
-//! of the USB controller.
-//!
-//! Applications which operate purely as USB devices (rather than dual mode
-//! applications which can operate in either device or host mode at different
-//! times) must ensure that a pointer to this function is installed in the
-//! interrupt vector table entry for the USB0 interrupt. For dual mode
-//! operation, the vector should be set to point to \e USB0DualModeIntHandler()
-//! instead.
-//!
-//! \return None.
-//
-//*****************************************************************************
-void
-USB0DeviceIntHandler(void)
-{
- unsigned int ulStatus = 0;
-
-#if defined(am335x) || defined (am335x_15x15) || defined(c6a811x) || defined(am386x) || \
- defined(c6741x)
-
- unsigned int epStatus = 0;
-
- //
- // Get the controller interrupt status.
- //
- ulStatus = HWREG(g_USBInstance[0].uiSubBaseAddr + USB_0_IRQ_STATUS_1);
- //
- // Get the EP interrupt status.
- //
- epStatus = HWREG(g_USBInstance[0].uiSubBaseAddr + USB_0_IRQ_STATUS_0);
- //
- // Clear the controller interrupt status.
- //
- HWREG(g_USBInstance[0].uiSubBaseAddr + USB_0_IRQ_STATUS_1) = ulStatus;
- //
- // Clear the EP interrupt status.
- //
- HWREG(g_USBInstance[0].uiSubBaseAddr + USB_0_IRQ_STATUS_0) = epStatus;
-
-#ifdef DMA_MODE
- HWREG(USBSS_BASE + USBSS_IRQ_STATUS) =
- HWREG(USBSS_BASE + USBSS_IRQ_STATUS);
-#endif
- //
- //Call the Interrupt Handler.
- //
- USBDeviceIntHandlerInternal(0, ulStatus, &epStatus);
- //
- //End of Interrupts.
- //
- HWREG(g_USBInstance[0].uiSubBaseAddr + USB_0_IRQ_EOI) = 0;
-
-#ifdef DMA_MODE
- HWREG(USBSS_BASE + USBSS_IRQ_EOI) = 0;
-#endif
-
-#else
- //
- // Get the controller interrupt status.
- //
- ulStatus = HWREG(g_USBInstance[0].uiSubBaseAddr + USB_0_INTR_SRC);
- // Clear the Interrupts
- HWREG(g_USBInstance[0].uiSubBaseAddr + USB_0_INTR_SRC_CLEAR) = ulStatus;
-#ifdef _TMS320C6X
- IntEventClear(g_USBInstance[0].uiInterruptNum);
-#else
- IntSystemStatusClear(g_USBInstance[0].uiInterruptNum);
-#endif
-
- //
- // Call the internal handler.
- //
- USBDeviceIntHandlerInternal(0, ulStatus, NULL);
-
- // End of Interrupts
- HWREG(g_USBInstance[0].uiSubBaseAddr + USB_0_END_OF_INTR) = 0;
-#endif
-
-}
-
-
-void
-USB1DeviceIntHandler(void)
-{
- unsigned int ulStatus = 0;
-
-#if defined (am335x_15x15) || defined(am335x) || defined(c6a811x)
-
- unsigned int epStatus = 0;
-
- //
- // Get the controller interrupt status.
- //
- ulStatus = HWREG(g_USBInstance[1].uiSubBaseAddr + USB_0_IRQ_STATUS_1);
- //
- // Get the EP interrupt status.
- //
- epStatus = HWREG(g_USBInstance[1].uiSubBaseAddr + USB_0_IRQ_STATUS_0);
- //
- // Clear the controller interrupt status.
- //
- HWREG(g_USBInstance[1].uiSubBaseAddr + USB_0_IRQ_STATUS_1) = ulStatus;
- //
- // Clear the EP interrupt status.
- //
- HWREG(g_USBInstance[1].uiSubBaseAddr + USB_0_IRQ_STATUS_0) = epStatus;
-
-#ifdef DMA_MODE
- HWREG(USBSS_BASE + USBSS_IRQ_STATUS) =
- HWREG(USBSS_BASE + USBSS_IRQ_STATUS);
-#endif
- //
- //Call the Interrupt Handler.
- //
- USBDeviceIntHandlerInternal(1, ulStatus, &epStatus);
- //
- //End of Interrupts.
- //
- HWREG(g_USBInstance[1].uiSubBaseAddr + USB_0_IRQ_EOI) = 0;
-
-#ifdef DMA_MODE
- HWREG(USBSS_BASE + USBSS_IRQ_EOI) = 0;
-#endif
-
-#else
- //
- // Get the controller interrupt status.
- //
- ulStatus = HWREG(g_USBInstance[1].uiSubBaseAddr + USB_0_INTR_SRC);
- // Clear the Interrupts
- HWREG(g_USBInstance[1].uiSubBaseAddr + USB_0_INTR_SRC_CLEAR) = ulStatus;
-#ifdef _TMS320C6X
- IntEventClear(g_USBInstance[1].uiInterruptNum);
-#else
- IntSystemStatusClear(g_USBInstance[1].uiInterruptNum);
-#endif
-
- //
- // Call the internal handler.
- //
- USBDeviceIntHandlerInternal(1, ulStatus, NULL);
-
- // End of Interrupts
- HWREG(g_USBInstance[1].uiSubBaseAddr + USB_0_END_OF_INTR) = 0;
-#endif
-
-}
-
-
-//*****************************************************************************
-//
-// Close the Doxygen group.
-//! @}
-//
-//*****************************************************************************
diff --git a/SylixOS/StarterWare/usblib/device/usbdhid.c b/SylixOS/StarterWare/usblib/device/usbdhid.c
deleted file mode 100644
index 2884452..0000000
--- a/SylixOS/StarterWare/usblib/device/usbdhid.c
+++ /dev/null
@@ -1,2665 +0,0 @@
-//*****************************************************************************
-//
-// usbdhid.c - USB HID device class driver.
-//
-// Copyright (c) 2008-2010 Texas Instruments Incorporated. All rights reserved.
-// Software License Agreement
-//
-// Texas Instruments (TI) is supplying this software for use solely and
-// exclusively on TI's microcontroller products. The software is owned by
-// TI and/or its suppliers, and is protected under applicable copyright
-// laws. You may not combine this software with "viral" open-source
-// software in order to form a larger program.
-//
-// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
-// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
-// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
-// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
-// DAMAGES, FOR ANY REASON WHATSOEVER.
-//
-// This is part of AM1808 StarterWare USB Library and reused from revision 6288
-// of the Stellaris USB Library.
-//
-//*****************************************************************************
-
-#include "hw_usb.h"
-#include "hw_types.h"
-#include "debug.h"
-#include "usb.h"
-#include "interrupt.h"
-#include "usblib.h"
-#include "usbhid.h"
-#include "usbdevice.h"
-#include "usbdhid.h"
-#include "usblibpriv.h"
-
-//*****************************************************************************
-//
-//! \addtogroup hid_device_class_api
-//! @{
-//
-//*****************************************************************************
-
-
-//*****************************************************************************
-//This macro is used to diable the bit band operartion. Need to undefine this macro to use the
-// bit band operation.
-//***************************************************************************
-#define DISABLE_BIT_BAND
-
-//*****************************************************************************
-//
-// The subset of endpoint status flags that we consider to be reception
-// errors. These are passed to the client via USB_EVENT_ERROR if seen.
-//
-//*****************************************************************************
-#define USB_RX_ERROR_FLAGS (USBERR_DEV_RX_DATA_ERROR | \
- USBERR_DEV_RX_OVERRUN | \
- USBERR_DEV_RX_FIFO_FULL)
-
-//*****************************************************************************
-//
-// Marker used to indicate that a given HID descriptor cannot be found in the
-// client-supplied list.
-//
-//*****************************************************************************
-#define HID_NOT_FOUND 0xFFFFFFFF
-
-//*****************************************************************************
-//
-// Flags that may appear in usDeferredOpFlags to indicate some operation that
-// has been requested but could not be processed at the time it was received.
-// Each deferred operation is defined as the bit number that should be set in
-// tHIDInstance->usDeferredOpFlags to indicate that the operation is pending.
-//
-//*****************************************************************************
-#define HID_DO_PACKET_RX 5
-#define HID_DO_SEND_IDLE_REPORT 6
-
-//*****************************************************************************
-//
-// Macros to convert between USB controller base address and an index. These
-// are currently trivial but are included to allow for the possibility of
-// supporting more than one controller in the future.
-//
-//*****************************************************************************
-#if (USB_NUM_INSTANCE == 2)
-#define USB_BASE_TO_INDEX(BaseAddr, index) do{ \
- if(USB0_BASE==BaseAddr) \
- index = 0; \
- else if(USB1_BASE==BaseAddr) \
- index = 1; \
- else \
- index = -1; \
- }while(0)
-
-#define USB_INDEX_TO_BASE(Index, BaseAddr) ( \
- if(0==Index) \
- BaseAddr = USB0_BASE; \
- else if(1==Index) \
- BaseAddr = USB1_BASE; \
- else \
- BaseAddr = -1; \
- )
-#else
-#define USB_BASE_TO_INDEX(BaseAddr, index) do{ \
- if(USB0_BASE==BaseAddr) \
- index = 0; \
- else \
- index = -1; \
- }while(0)
-
-#define USB_INDEX_TO_BASE(Index, BaseAddr) ( \
- if(0==Index) \
- BaseAddr = USB0_BASE; \
- else \
- BaseAddr = -1; \
- )
-#endif
-
-//*****************************************************************************
-//
-// Endpoints to use for each of the required endpoints in the driver.
-//
-//*****************************************************************************
-#define INT_IN_ENDPOINT USB_EP_3
-#define INT_OUT_ENDPOINT USB_EP_3
-
-//*****************************************************************************
-//
-// Maximum packet size for the interrupt endpoints used for report transmission
-// and reception and the associated FIFO sizes to set aside for each endpoint.
-//
-//*****************************************************************************
-#define INT_IN_EP_FIFO_SIZE USB_FIFO_SZ_64
-#define INT_OUT_EP_FIFO_SIZE USB_FIFO_SZ_64
-
-#define INT_IN_EP_MAX_SIZE USB_FIFO_SZ_TO_BYTES(INT_IN_EP_FIFO_SIZE)
-#define INT_OUT_EP_MAX_SIZE USB_FIFO_SZ_TO_BYTES(INT_IN_EP_FIFO_SIZE)
-//*****************************************************************************
-//
-// USB instance Object
-//
-//*****************************************************************************
-extern tUSBInstanceObject g_USBInstance[];
-
-
-//*****************************************************************************
-//
-// Device Descriptor. This is stored in RAM to allow several fields to be
-// changed at runtime based on the client's requirements.
-//
-//*****************************************************************************
-unsigned char g_pHIDDeviceDescriptor[] =
-{
- 18, // Size of this structure.
- USB_DTYPE_DEVICE, // Type of this structure.
- USBShort(0x200), // USB version 1.1 (if we say 2.0, hosts assume
- // high-speed - see USB 2.0 spec 9.2.6.6)
- USB_CLASS_DEVICE, // USB Device Class
- 0, // USB Device Sub-class
- USB_HID_PROTOCOL_NONE, // USB Device protocol
- 64, // Maximum packet size for default pipe.
- USBShort(0), // Vendor ID (VID).
- USBShort(0), // Product ID (PID).
- USBShort(0x100), // Device Version BCD.
- 1, // Manufacturer string identifier.
- 2, // Product string identifier.
- 3, // Product serial number.
- 1 // Number of configurations.
-};
-
-//*****************************************************************************
-//
-// HID device configuration descriptor.
-//
-// It is vital that the configuration descriptor bConfigurationValue field
-// (byte 6) is 1 for the first configuration and increments by 1 for each
-// additional configuration defined here. This relationship is assumed in the
-// device stack for simplicity even though the USB 2.0 specification imposes
-// no such restriction on the bConfigurationValue values.
-//
-// Note that this structure is deliberately located in RAM since we need to
-// be able to patch some values in it based on client requirements.
-//
-//*****************************************************************************
-unsigned char g_pHIDDescriptor[] =
-{
- //
- // Configuration descriptor header.
- //
- 9, // Size of the configuration descriptor.
- USB_DTYPE_CONFIGURATION, // Type of this descriptor.
- USBShort(34), // The total size of this full structure.
- 1, // The number of interfaces in this
- // configuration.
- 1, // The unique value for this configuration.
- 5, // The string identifier that describes this
- // configuration.
- USB_CONF_ATTR_SELF_PWR, // Bus Powered, Self Powered, remote wake up.
- 250, // The maximum power in 2mA increments.
-};
-
-//*****************************************************************************
-//
-// The remainder of the configuration descriptor is stored in flash since we
-// don't need to modify anything in it at runtime.
-//
-//*****************************************************************************
-unsigned char g_pHIDInterface[] =
-{
- //
- // HID Device Class Interface Descriptor.
- //
- 9, // Size of the interface descriptor.
- USB_DTYPE_INTERFACE, // Type of this descriptor.
- 0, // The index for this interface.
- 0, // The alternate setting for this interface.
- 2, // The number of endpoints used by this
- // interface.
- USB_CLASS_HID, // The interface class
- 0, // The interface sub-class.
- 0, // The interface protocol for the sub-class
- // specified above.
- 4, // The string index for this interface.
-};
-
-const unsigned char g_pHIDInEndpoint[] =
-{
- //
- // Interrupt IN endpoint descriptor
- //
- 7, // The size of the endpoint descriptor.
- USB_DTYPE_ENDPOINT, // Descriptor type is an endpoint.
- USB_EP_DESC_IN | USB_EP_TO_INDEX(INT_IN_ENDPOINT),
- USB_EP_ATTR_INT, // Endpoint is an interrupt endpoint.
- USBShort(INT_IN_EP_MAX_SIZE), // The maximum packet size.
- 16, // The polling interval for this endpoint.
-};
-
-const unsigned char g_pHIDOutEndpoint[] =
-{
- //
- // Interrupt OUT endpoint descriptor
- //
- 7, // The size of the endpoint descriptor.
- USB_DTYPE_ENDPOINT, // Descriptor type is an endpoint.
- USB_EP_DESC_OUT | USB_EP_TO_INDEX(INT_OUT_ENDPOINT),
- USB_EP_ATTR_INT, // Endpoint is an interrupt endpoint.
- USBShort(INT_OUT_EP_MAX_SIZE), // The maximum packet size.
- 16, // The polling interval for this endpoint.
-};
-
-//*****************************************************************************
-//
-// The HID configuration descriptor is defined as four or five sections
-// depending upon the client's configuration choice. These sections are:
-//
-// 1. The 9 byte configuration descriptor (RAM).
-// 2. The interface descriptor (RAM).
-// 3. The HID report and physical descriptors (provided by the client)
-// (FLASH).
-// 4. The mandatory interrupt IN endpoint descriptor (FLASH).
-// 5. The optional interrupt OUT endpoint descriptor (FLASH).
-//
-//*****************************************************************************
-const tConfigSection g_sHIDConfigSection =
-{
- sizeof(g_pHIDDescriptor),
- g_pHIDDescriptor
-};
-
-const tConfigSection g_sHIDInterfaceSection =
-{
- sizeof(g_pHIDInterface),
- g_pHIDInterface
-};
-
-const tConfigSection g_sHIDInEndpointSection =
-{
- sizeof(g_pHIDInEndpoint),
- g_pHIDInEndpoint
-};
-
-const tConfigSection g_sHIDOutEndpointSection =
-{
- sizeof(g_pHIDOutEndpoint),
- g_pHIDOutEndpoint
-};
-
-//*****************************************************************************
-//
-// Place holder for the user's HID descriptor block.
-//
-//*****************************************************************************
-tConfigSection g_sHIDDescriptorSection =
-{
- 0, (void *)0
-};
-
-//*****************************************************************************
-//
-// This array lists all the sections that must be concatenated to make a
-// single, complete HID configuration descriptor.
-//
-//*****************************************************************************
-const tConfigSection *g_psHIDSections[] =
-{
- &g_sHIDConfigSection,
- &g_sHIDInterfaceSection,
- &g_sHIDDescriptorSection,
- &g_sHIDInEndpointSection,
- &g_sHIDOutEndpointSection
-};
-
-#define NUM_HID_SECTIONS (sizeof(g_psHIDSections) / \
- sizeof(tConfigSection *))
-
-//*****************************************************************************
-//
-// The header for the single configuration we support. This is the root of
-// the data structure that defines all the bits and pieces that are pulled
-// together to generate the configuration descriptor. Note that this must be
-// in RAM since we need to include or exclude the final section based on
-// client supplied initialization parameters.
-//
-//*****************************************************************************
-tConfigHeader g_sHIDConfigHeader =
-{
- NUM_HID_SECTIONS,
- g_psHIDSections
-};
-
-//*****************************************************************************
-//
-// Configuration Descriptor.
-//
-//*****************************************************************************
-const tConfigHeader * const g_pHIDConfigDescriptors[] =
-{
- &g_sHIDConfigHeader
-};
-
-//*****************************************************************************
-//
-// Forward references for device handler callbacks
-//
-//*****************************************************************************
-static void HandleGetDescriptor(void *pvInstance, tUSBRequest *pUSBRequest,
- unsigned int ulIndex);
-static void HandleRequest(void *pvInstance, tUSBRequest *pUSBRequest,
- unsigned int ulIndex);
-static void HandleConfigChange(void *pvInstance, unsigned int ulInfo,
- unsigned int ulIndex);
-static void HandleEP0DataReceived(void *pvInstance, unsigned int ulInfo,
- unsigned int ulIndex);
-static void HandleEP0DataSent(void *pvInstance, unsigned int ulInfo,
- unsigned int ulIndex);
-static void HandleReset(void *pvInstance);
-static void HandleSuspend(void *pvInstance);
-static void HandleResume(void *pvInstance);
-static void HandleDisconnect(void *pvInstance);
-static void HandleEndpoints(void *pvInstance, unsigned int ulStatus,
- unsigned int ulIndex);
-static void HandleDevice(void *pvInstance, unsigned int ulRequest,
- void *pvRequestData);
-
-//*****************************************************************************
-//
-// The device information structure for the USB HID devices.
-//
-//*****************************************************************************
-tDeviceInfo g_sHIDDeviceInfo =
-{
- //
- // Device event handler callbacks.
- //
- {
- HandleGetDescriptor, // GetDescriptor
- HandleRequest, // RequestHandler
- 0, // InterfaceChange
- HandleConfigChange, // ConfigChange
- HandleEP0DataReceived, // DataReceived
- HandleEP0DataSent, // DataSentCallback
- HandleReset, // ResetHandler
- HandleSuspend, // SuspendHandler
- HandleResume, // ResumeHandler
- HandleDisconnect, // DisconnectHandler
- HandleEndpoints, // EndpointHandler
- HandleDevice // Device handler.
- },
- g_pHIDDeviceDescriptor,
- g_pHIDConfigDescriptors,
- 0, // Will be completed during USBDHIDInit().
- 0, // Will be completed during USBDHIDInit().
- &g_sUSBDefaultFIFOConfig
-};
-
-//*****************************************************************************
-//
-// Set or clear deferred operation flags in an "atomic" manner.
-//
-// \param pusDeferredOp points to the flags variable which is to be modified.
-// \param usBit indicates which bit number is to be set or cleared.
-// \param bSet indicates the state that the flag must be set to. If \b true,
-// the flag is set, if \b false, the flag is cleared.
-//
-// This function safely sets or clears a bit in a flag variable. The operation
-// makes use of bitbanding to ensure that the operation is atomic (no read-
-// modify-write is required).
-//
-// \return None.
-//
-//*****************************************************************************
-static void
-SetDeferredOpFlag(volatile unsigned short *pusDeferredOp,
- unsigned short usBit, tBoolean bSet)
-{
-#ifdef DISABLE_BIT_BAND
- if(bSet)
- {
- HWREG(pusDeferredOp) |= (1<<usBit);
- }
- else
- {
- HWREG(pusDeferredOp) &= ~(1<<usBit);
- }
-#else
- //
- // Set the flag bit to 1 or 0 using a bitband access.
- //
-
- HWREGBITH(pusDeferredOp, usBit) = bSet ? 1 : 0;
-#endif
-}
-
-//*****************************************************************************
-//
-// This function is called to clear the counter used to keep track of the time
-// elapsed since a given report was last sent.
-//
-// \param psDevice points to the HID device structure whose report timer is to
-// be cleared.
-// \param ucReportID is the first byte of the report to be sent. If this
-// device offers more than one input report, this value is used to find the
-// relevant report timer structure in the psDevice structure.
-//
-// \return None.
-//
-//*****************************************************************************
-static void
-ClearReportTimer(const tUSBDHIDDevice *psDevice, unsigned char ucReportID)
-{
- unsigned int ulLoop;
-
- if(psDevice->ucNumInputReports > 1)
- {
- //
- // We have more than 1 input report so the report must begin with a
- // byte containing the report ID. Scan the table we were provided
- // when the device was initialized to find the entry for this report.
- //
- for(ulLoop = 0; ulLoop < psDevice->ucNumInputReports; ulLoop++)
- {
- if(psDevice->psReportIdle[ulLoop].ucReportID == ucReportID)
- {
- break;
- }
- }
- }
- else
- {
- ulLoop = 0;
- }
-
- //
- // If we drop out of the loop with an index less than ucNumInputReports,
- // we found the relevant report so clear its timer.
- //
- if(ulLoop < psDevice->ucNumInputReports)
- {
- psDevice->psReportIdle[ulLoop].ulTimeSinceReportmS = 0;
- }
-}
-
-//*****************************************************************************
-//
-// This function is called to clear the idle period timers for each input
-// report supported by the device.
-//
-// \param psDevice points to the HID device structure whose timers are to be
-// cleared.
-// \param ulTimemS is the elapsed time in milliseconds since the last call
-// to this function.
-//
-// \return None.
-//
-//*****************************************************************************
-static void
-ClearIdleTimers(const tUSBDHIDDevice *psDevice)
-{
- unsigned int ulLoop;
-
- //
- // Clear the "time till next report" counters for each input report.
- //
- for(ulLoop = 0; ulLoop < psDevice->ucNumInputReports; ulLoop++)
- {
- psDevice->psReportIdle[ulLoop].usTimeTillNextmS =
- psDevice->psReportIdle[ulLoop].ucDuration4mS * 4;
- }
-}
-
-//*****************************************************************************
-//
-// This function is called periodically to allow us to process the report idle
-// timers.
-//
-// \param psDevice points to the HID device structure whose timers are to be
-// updated.
-// \param ulElapsedmS indicates the number of milliseconds that have elapsed
-// since the last call to this function.
-//
-// \return None.
-//
-//*****************************************************************************
-static void
-ProcessIdleTimers(const tUSBDHIDDevice *psDevice, unsigned int ulElapsedmS)
-{
- unsigned int ulLoop;
- unsigned int ulSizeReport;
- void *pvReport;
- tHIDInstance *psInst;
- tBoolean bDeferred;
-
- //
- // Get our instance data pointer
- //
- psInst = ((tUSBDHIDDevice *)psDevice)->psPrivateHIDData;
-
- //
- // We have not had to defer any report transmissions yet.
- //
- bDeferred = false;
-
- //
- // Look at each of the input report idle timers in turn.
- //
- for(ulLoop = 0; ulLoop < psDevice->ucNumInputReports; ulLoop++)
- {
- //
- // Update the time since the last report was sent.
- //
- psDevice->psReportIdle[ulLoop].ulTimeSinceReportmS += ulElapsedmS;
-
- //
- // Is this timer running?
- //
- if(psDevice->psReportIdle[ulLoop].ucDuration4mS)
- {
- //
- // Yes - is it about to expire?
- //
- if(psDevice->psReportIdle[ulLoop].usTimeTillNextmS <= ulElapsedmS)
- {
- //
- // The timer is about to expire. Can we send a report right
- // now?
- //
- if((psInst->eHIDTxState == HID_STATE_IDLE) &&
- (psInst->bSendInProgress == false))
- {
- //
- // We can send a report so send a message to the
- // application to retrieve its latest report for
- // transmission to the host.
- //
- ulSizeReport = psDevice->pfnRxCallback(
- psDevice->pvRxCBData,
- USBD_HID_EVENT_IDLE_TIMEOUT,
- psDevice->psReportIdle[ulLoop].ucReportID,
- &pvReport);
-
- //
- // Schedule the report for transmission.
- //
- USBDHIDReportWrite((void *)psDevice, pvReport,
- ulSizeReport, true);
-
- //
- // Reload the timer for the next period.
- //
- psDevice->psReportIdle[ulLoop].usTimeTillNextmS =
- psDevice->psReportIdle[ulLoop].ucDuration4mS * 4;
- }
- else
- {
- //
- // We can't send the report straight away so flag it for
- // transmission as soon as the previous transmission ends.
- //
- psDevice->psReportIdle[ulLoop].usTimeTillNextmS = 0;
- bDeferred = true;
- }
- }
- else
- {
- //
- // The timer is not about to expire. Update the time till the
- // next report transmission.
- //
- psDevice->psReportIdle[ulLoop].usTimeTillNextmS -= ulElapsedmS;
- }
- }
- }
-
- //
- // If we had to defer transmission of any report, remember this so that we
- // will process it as soon as possible.
- //
- SetDeferredOpFlag(&psInst->usDeferredOpFlags,
- HID_DO_SEND_IDLE_REPORT, bDeferred);
-}
-
-static void
-SetIdleTimeout(const tUSBDHIDDevice *psDevice, unsigned char ucReportID,
- unsigned char ucTimeout4mS)
-{
- unsigned int ulLoop;
- tBoolean bReportNeeded;
- tHIDReportIdle *psIdle;
-
- //
- // Remember that we have not found any report that needs to be sent
- // immediately.
- //
- bReportNeeded = false;
-
- //
- // Search through all the input reports looking for ones that fit the
- // requirements.
- //
- for(ulLoop = 0; ulLoop < psDevice->ucNumInputReports; ulLoop++)
- {
- psIdle = &psDevice->psReportIdle[ulLoop];
-
- //
- // If the report ID passed matches the report ID in the idle timer
- // control structure or we were passed a report ID of zero, which
- // indicates that all timers are to be set...
- //
- if(!ucReportID || (ucReportID == psIdle->ucReportID))
- {
- //
- // Save the new duration for the idle timer.
- //
- psIdle->ucDuration4mS = ucTimeout4mS;
-
- //
- // Are we enabling the idle timer? If so, fix up the time until it
- // needs to fire.
- //
- if(ucTimeout4mS)
- {
- //
- // Determine what the timeout is for this report given the time
- // since the last report of this type was sent.
- //
- if(psIdle->ulTimeSinceReportmS >=
- ((unsigned int)ucTimeout4mS * 4))
- {
- psIdle->usTimeTillNextmS = 0;
- bReportNeeded = true;
- }
- else
- {
- psIdle->usTimeTillNextmS =
- (((unsigned short)ucTimeout4mS * 4) -
- psIdle->ulTimeSinceReportmS);
- }
- }
- }
- }
-
- //
- // If we get to here and bReportNeeded is true, this means we need to
- // send back at least one of the input reports as soon as possible. Try
- // to do this immediately.
- //
- if(bReportNeeded)
- {
- ProcessIdleTimers(psDevice, 0);
- }
-}
-
-//*****************************************************************************
-//
-// Find the idle timeout for a given HID input report.
-//
-// \param psDevice points to the HID device whose report idle timeout is to be
-// found.
-// \param ucReportID identifies the report whose timeout is requested. If 0,
-// the timeout for the first report is returns, regardless of its ID (or
-// whether it has one).
-//
-// This function returns the current idle timeout for a given HID input report.
-// The value returned is expressed in terms of 4mS intervals. Convert to
-// milliseconds by multiplying by 4. If the return value is 0, this indicates
-// that an infinite timeout is currently set and the device will not send the
-// report unless a state change occurs.
-//
-// \return Returns the current idle timeout for the given report.
-//
-//*****************************************************************************
-static unsigned int
-GetIdleTimeout(const tUSBDHIDDevice *psDevice, unsigned char ucReportID)
-{
- unsigned int ulLoop;
- tHIDReportIdle *psIdle;
-
- //
- // Search through all the input reports looking for ones that fit the
- // requirements.
- //
- for(ulLoop = 0; ulLoop < psDevice->ucNumInputReports; ulLoop++)
- {
- psIdle = &psDevice->psReportIdle[ulLoop];
-
- //
- // If the report ID passed matches the report ID in the idle timer
- // control structure or we were passed a report ID of zero, which
- // indicates that all timers are to be set...
- //
- if(!ucReportID || (ucReportID == psIdle->ucReportID))
- {
- //
- // We found a report matching the required ID or we were not passed
- // an ID and we are looking at the first report information.
- //
- return((unsigned int)psIdle->ucDuration4mS);
- }
- }
-
- //
- // If we drop out, the report couldn't be found so we need to indicate
- // an error.
- //
- return(HID_NOT_FOUND);
-}
-
-//*****************************************************************************
-//
-// Find the n-th HID class descriptor of a given type in the client-provided
-// descriptor table.
-//
-// \param psDevice points to the HID device which is to be searched for the
-// required class descriptor.
-// \param ucType is the type of class descriptor being requested. This will
-// be either USB_HID_DTYPE_REPORT or USB_HID_DTYPE_PHYSICAL.
-// \param ulIndex is the zero-based index of the descriptor that is being
-// requested.
-//
-// This function parses the supplied HID descriptor to find the index into the
-// sClassDescriptor array that corresponds to the requested descriptor. If
-// a descriptor with the requested index does not exist, HID_NOT_FOUND will be
-// returned unless the request is for a physical descriptor and at least one
-// such descriptor exists. In this case, the index returned will be for the
-// last physical descriptor (as required by the HID spec 7.1.1).
-//
-// \return Returns the index of the descriptor within the sClassDescriptor
-// of the tHIDDevice structure if found or HID_NOT_FOUND otherwise.
-//
-//*****************************************************************************
-static unsigned int
-FindHIDDescriptor(const tUSBDHIDDevice *psDevice, unsigned char ucType,
- unsigned int ulIndex, unsigned int *pulLen)
-{
- tBoolean bFoundType;
- unsigned int ulLoop;
- unsigned int ulCount;
- unsigned int ulLastFound;
- const tHIDClassDescriptorInfo *psDesc;
-
- //
- // Remember that we have not found any descriptor with a matching type yet.
- //
- bFoundType = false;
- ulCount = 0;
- ulLastFound = 0;
-
- //
- // Walk through all the class descriptors looking for the one which
- // matches the requested index and type.
- //
- for(ulLoop = 0; ulLoop < psDevice->psHIDDescriptor->bNumDescriptors;
- ulLoop++)
- {
- psDesc = &(psDevice->psHIDDescriptor->sClassDescriptor[ulLoop]);
- if(psDesc->bDescriptorType == ucType)
- {
- //
- // We found a descriptor of the correct type. Is this the
- // correct index?
- //
- bFoundType = true;
-
- //
- // Is this the descriptor we are looking for?
- //
- if(ulCount == ulIndex)
- {
- //
- // Yes - we found it so return the index and size to the
- // caller.
- //
- *pulLen = (unsigned int)psDesc->wDescriptorLength;
- return(ulLoop);
- }
- else
- {
- //
- // Update our count and keep looking. Remember where we were
- // when we found this descriptor in case we need to return the
- // last physical descriptor.
- //
- ulCount++;
- ulLastFound = ulLoop;
- }
- }
- }
-
- //
- // If we drop out, we didn't find the requested descriptor. Now handle
- // the special case of a physical descriptor - if we found any physical
- // descriptors, return the last one.
- //
- if((ucType == USB_HID_DTYPE_PHYSICAL) && bFoundType)
- {
- //
- // Get the length of the last descriptor we found.
- //
- psDesc = &(psDevice->psHIDDescriptor->sClassDescriptor[ulLastFound]);
- *pulLen = (unsigned int)psDesc->wDescriptorLength;
-
- //
- // Return the index to the caller.
- //
- return(ulLastFound);
- }
- else
- {
- //
- // We couldn't find the descriptor so return an appropriate error.
- //
- return(HID_NOT_FOUND);
- }
-}
-
-//*****************************************************************************
-//
-// Schedule transmission of the next packet forming part of an input report.
-//
-// \param psInst points to the device instance whose input report is to be
-// sent.
-//
-// This function is called to transmit the next packet of an input report
-// passed to the driver via a call to USBDHIDReportWrite. If any data remains
-// to be sent, a USB packet is written to the FIFO and scheduled for
-// transmission to the host. The function ensures that reports are sent as
-// a sequence of full packets followed by either a single short packet or a
-// packet with no data to indicate the end of the transaction.
-//
-//*****************************************************************************
-static int
-ScheduleReportTransmission(tHIDInstance *psInst)
-{
- unsigned int ulNumBytes;
- unsigned char *pucData;
- int iRetcode;
-
- //
- // Set the number of bytes to send this iteration.
- //
- ulNumBytes = (unsigned int)(psInst->usInReportSize -
- psInst->usInReportIndex);
-
- //
- // Limit individual transfers to the maximum packet size for the endpoint.
- //
- if(ulNumBytes > INT_IN_EP_MAX_SIZE)
- {
- ulNumBytes = INT_IN_EP_MAX_SIZE;
- }
-
- //
- // Where are we sending this data from?
- //
- pucData = psInst->pucInReportData + psInst->usInReportIndex;
-
- //
- // Put the data in the correct FIFO.
- //
- iRetcode = USBEndpointDataPut(psInst->ulUSBBase, psInst->ucINEndpoint,
- pucData, ulNumBytes);
-
- if(iRetcode != -1)
- {
- //
- // Update the count and index ready for the next time round.
- //
- psInst->usInReportIndex += ulNumBytes;
-
- //
- // Send out the current data.
- //
- iRetcode = USBEndpointDataSend(psInst->ulUSBBase, psInst->ucINEndpoint,
- USB_TRANS_IN);
- }
-
- //
- // Tell the caller how we got on.
- //
- return(iRetcode);
-}
-
-//*****************************************************************************
-//
-// Receives notifications related to data received from the host.
-//
-// \param psDevice is the device instance whose endpoint is to be processed.
-// \param ulStatus is the USB interrupt status that caused this function to
-// be called.
-//
-// This function is called from HandleEndpoints for all interrupts signaling
-// the arrival of data on the interrupt OUT endpoint (in other words, whenever
-// the host has sent us a packet of data). We inform the client that a packet
-// is available and, on return, check to see if the packet has been read. If
-// not, we schedule another notification to the client for a later time.
-//
-// \return Returns \b true on success or \b false on failure.
-//
-//*****************************************************************************
-static tBoolean
-ProcessDataFromHost(const tUSBDHIDDevice *psDevice, unsigned int ulStatus,
- unsigned int ulIndex)
-{
- unsigned int ulEPStatus;
- unsigned int ulSize;
- tHIDInstance *psInst;
-
- //
- // Get a pointer to our instance data.
- //
- psInst = psDevice->psPrivateHIDData;
-
- //
- // Get the endpoint status to see why we were called.
- //
- ulEPStatus = USBEndpointStatus(g_USBInstance[ulIndex].uiBaseAddr, psInst->ucOUTEndpoint);
-
- //
- // Clear the status bits.
- //
- USBDevEndpointStatusClear(g_USBInstance[ulIndex].uiBaseAddr, psInst->ucOUTEndpoint, ulEPStatus);
-
- //
- // Has a packet been received?
- //
- if(ulEPStatus & USB_DEV_RX_PKT_RDY)
- {
- //
- // Set the flag we use to indicate that a packet read is pending. This
- // will be cleared if the packet is read. If the client doesn't read
- // the packet in the context of the USB_EVENT_RX_AVAILABLE callback,
- // the event will be signaled later during tick processing.
- //
- SetDeferredOpFlag(&psInst->usDeferredOpFlags, HID_DO_PACKET_RX, true);
-
- //
- // How big is the packet we've just been sent?
- //
- ulSize = USBEndpointDataAvail(psInst->ulUSBBase,
- psInst->ucOUTEndpoint);
-
- //
- // The receive channel is not blocked so let the caller know
- // that a packet is waiting. The parameters are set to indicate
- // that the packet has not been read from the hardware FIFO yet.
- //
- psDevice->pfnRxCallback(psDevice->pvRxCBData,
- USB_EVENT_RX_AVAILABLE, ulSize,
- (void *)0);
- }
- else
- {
- //
- // No packet was received. Some error must have been reported. Check
- // and pass this on to the client if necessary.
- //
- if(ulEPStatus & USB_RX_ERROR_FLAGS)
- {
- //
- // This is an error we report to the client so...
- //
- psDevice->pfnRxCallback(psDevice->pvRxCBData,
- USB_EVENT_ERROR,
- (ulEPStatus & USB_RX_ERROR_FLAGS),
- (void *)0);
- }
- return (false);
- }
-
- return (true);
-}
-
-//*****************************************************************************
-//
-// Receives notifications related to data sent to the host.
-//
-// \param psDevice is the device instance whose endpoint is to be processed.
-// \param ulStatus is the USB interrupt status that caused this function to
-// be called.
-//
-// This function is called from HandleEndpoints for all interrupts originating
-// from the interrupt IN endpoint (in other words, whenever data has been
-// transmitted to the USB host). We examine the cause of the interrupt and,
-// if due to completion of a transmission, notify the client.
-//
-// \return Returns \b true on success or \b false on failure.
-//
-//*****************************************************************************
-static tBoolean
-ProcessDataToHost(const tUSBDHIDDevice *psDevice, unsigned int ulStatus,
- unsigned int ulIndex)
-{
- tHIDInstance *psInst;
- unsigned int ulEPStatus;
-
- //
- // Get a pointer to our instance data.
- //
- psInst = psDevice->psPrivateHIDData;
-
- //
- // Get the endpoint status to see why we were called.
- //
- ulEPStatus = USBEndpointStatus(psInst->ulUSBBase, psInst->ucINEndpoint);
-
- //
- // Clear the status bits.
- //
- USBDevEndpointStatusClear(psInst->ulUSBBase, psInst->ucINEndpoint,
- ulEPStatus);
-
- //
- // Our last packet was transmitted successfully. Is there any more data to
- // send or have we finished sending the whole report? We know we finished
- // if the usInReportIndex has reached the usInReportSize value.
- //
- if(psInst->usInReportSize == psInst->usInReportIndex)
- {
- //
- // We finished sending the last report so are idle once again.
- //
- psInst->eHIDTxState = HID_STATE_IDLE;
-
- //
- // Notify the client that the report transmission completed.
- //
- psDevice->pfnTxCallback(psDevice->pvTxCBData, USB_EVENT_TX_COMPLETE,
- psInst->usInReportSize, (void *)0);
-
- //
- // Do we have any reports to send as a result of idle timer timeouts?
- //
- if(psInst->usDeferredOpFlags & (1 << HID_DO_SEND_IDLE_REPORT))
- {
- //
- // Yes - send reports for any timers that expired recently.
- //
- ProcessIdleTimers(psDevice, 0);
- }
- }
- else
- {
- //
- // There must be more data or a zero length packet waiting to be sent
- // so go ahead and do this.
- //
- ScheduleReportTransmission(psInst);
- }
-
- return (true);
-}
-
-//*****************************************************************************
-//
-// Called by the USB stack for any activity involving one of our endpoints
-// other than EP0. This function is a fan out that merely directs the call to
-// the correct handler depending upon the endpoint and transaction direction
-// signaled in ulStatus.
-//
-//*****************************************************************************
-static void
-HandleEndpoints(void *pvInstance, unsigned int ulStatus, unsigned int ulIndex)
-{
- const tUSBDHIDDevice *psHIDInst;
- tHIDInstance *psInst;
-
- ASSERT(pvInstance != 0);
-
- //
- // Determine if the serial device is in single or composite mode because
- // the meaning of ulIndex is different in both cases.
- //
- psHIDInst = (const tUSBDHIDDevice *)pvInstance;
- psInst = psHIDInst->psPrivateHIDData;
-
- //
- // Handler for the interrupt OUT data endpoint.
- //
- if(ulStatus & (0x10000 << USB_EP_TO_INDEX(psInst->ucOUTEndpoint)))
- {
- //
- // Data is being sent to us from the host.
- //
- ProcessDataFromHost(pvInstance, ulStatus, ulIndex);
- }
-
- //
- // Handler for the interrupt IN data endpoint.
- //
- if(ulStatus & (1 << USB_EP_TO_INDEX(psInst->ucINEndpoint)))
- {
- ProcessDataToHost(pvInstance, ulStatus, ulIndex);
- }
-}
-
-//*****************************************************************************
-//
-// Called by the USB stack whenever a configuration change occurs.
-//
-//*****************************************************************************
-static void
-HandleConfigChange(void *pvInstance, unsigned int ulInfo,
- unsigned int ulIndex)
-{
- tHIDInstance *psInst;
- const tUSBDHIDDevice *psDevice;
-
- ASSERT(pvInstance != 0);
-
- //
- // Create the instance pointer.
- //
- psDevice = pvInstance;
-
- //
- // Get a pointer to our instance data.
- //
- psInst = psDevice->psPrivateHIDData;
-
- //
- // Set all our endpoints to idle state.
- //
- psInst->eHIDRxState = HID_STATE_IDLE;
- psInst->eHIDTxState = HID_STATE_IDLE;
-
- //
- // If we are not currently connected let the client know we are open for
- // business.
- //
- if(!psInst->bConnected)
- {
- //
- // Pass the connected event to the client.
- //
- psDevice->pfnRxCallback(psDevice->pvRxCBData, USB_EVENT_CONNECTED, 0,
- (void *)0);
- }
-
- //
- // Clear the idle timers for each input report.
- //
- ClearIdleTimers(psDevice);
-
- //
- // Remember that we are connected.
- //
- psInst->bConnected = true;
-}
-
-//*****************************************************************************
-//
-// Device instance specific handler.
-//
-//*****************************************************************************
-static void
-HandleDevice(void *pvInstance, unsigned int ulRequest, void *pvRequestData)
-{
- tHIDInstance *psInst;
- unsigned char *pucData;
-
- //
- // Create the serial instance data.
- //
- psInst = ((tUSBDHIDDevice *)pvInstance)->psPrivateHIDData;
-
- //
- // Create the char array used by the events supported by the USB CDC
- // serial class.
- //
- pucData = (unsigned char *)pvRequestData;
-
- switch(ulRequest)
- {
- //
- // This was an interface change event.
- //
- case USB_EVENT_COMP_IFACE_CHANGE:
- {
- psInst->ucInterface = pucData[1];
- break;
- }
-
- //
- // This was an endpoint change event.
- //
- case USB_EVENT_COMP_EP_CHANGE:
- {
- //
- // Determine if this is an IN or OUT endpoint that has changed.
- //
- if(pucData[0] & USB_EP_DESC_IN)
- {
- psInst->ucINEndpoint =
- INDEX_TO_USB_EP((pucData[1] & 0x7f));
- }
- else
- {
- //
- // Extract the new endpoint number.
- //
- psInst->ucOUTEndpoint =
- INDEX_TO_USB_EP(pucData[1] & 0x7f);
- }
- break;
- }
- default:
- {
- break;
- }
- }
-}
-
-//*****************************************************************************
-//
-// This function is called by the USB device stack whenever the device is
-// disconnected from the host.
-//
-//*****************************************************************************
-static void
-HandleDisconnect(void *pvInstance)
-{
- const tUSBDHIDDevice *psDevice;
-
- ASSERT(pvInstance != 0);
-
- //
- // Create the instance pointer.
- //
- psDevice = (const tUSBDHIDDevice *)pvInstance;
-
- //
- // If we are not currently connected so let the client know we are open
- // for business.
- //
- if(psDevice->psPrivateHIDData->bConnected)
- {
- //
- // Pass the disconnected event to the client.
- //
- psDevice->pfnRxCallback(psDevice->pvRxCBData, USB_EVENT_DISCONNECTED,
- 0, (void *)0);
- }
-
- //
- // Remember that we are no longer connected.
- //
- psDevice->psPrivateHIDData->bConnected = false;
-}
-
-//*****************************************************************************
-//
-// This function is called by the USB device stack whenever a request for a
-// non-standard descriptor is received.
-//
-// \param pvInstance is the instance data for this request.
-// \param pUSBRequest points to the request received.
-//
-// This call parses the provided request structure and determines which
-// descriptor is being requested. Assuming the descriptor can be found, it is
-// scheduled for transmission via endpoint zero. If the descriptor cannot be
-// found, the endpoint is stalled to indicate an error to the host.
-//
-//*****************************************************************************
-static void
-HandleGetDescriptor(void *pvInstance, tUSBRequest *pUSBRequest,
- unsigned int ulIndex)
-{
- unsigned int ulSize;
- unsigned int ulDesc;
- const tUSBDHIDDevice *psDevice;
-
- ASSERT(pvInstance != 0);
-
- //
- // Which device are we dealing with?
- //
- psDevice = pvInstance;
-
- //
- // Which type of class descriptor are we being asked for?
- //
- switch(pUSBRequest->wValue >> 8)
- {
- //
- // This is a request for a HID report or physical descriptor.
- //
- case USB_HID_DTYPE_REPORT:
- case USB_HID_DTYPE_PHYSICAL:
- {
- //
- // Find the index to the descriptor that is being queried.
- //
- ulSize = 0;
- ulDesc = FindHIDDescriptor(psDevice, pUSBRequest->wValue >> 8,
- pUSBRequest->wValue & 0xFF,
- &ulSize);
-
- //
- // Did we find the descriptor?
- //
- if(ulDesc == HID_NOT_FOUND)
- {
- //
- // No - stall the endpoint and return.
- //
- USBDCDStallEP0(ulIndex);
- return;
- }
-
- //
- // If there is more data to send than the host requested then just
- // send the requested amount of data.
- //
- if(ulSize > pUSBRequest->wLength)
- {
- ulSize = pUSBRequest->wLength;
- }
-
- //
- // Send the data via endpoint 0.
- //
- USBDCDSendDataEP0(0,
- (unsigned char *)psDevice->ppClassDescriptors[ulDesc], ulSize);
-
- break;
- }
-
- //
- // This is a request for the HID descriptor (as found in the
- // configuration descriptor following the relevant interface).
- //
- case USB_HID_DTYPE_HID:
- {
- //
- // How big is the HID descriptor?
- //
- ulSize = (unsigned int)psDevice->psHIDDescriptor->bLength;
-
- //
- // If there is more data to send than the host requested then just
- // send the requested amount of data.
- //
- if(ulSize > pUSBRequest->wLength)
- {
- ulSize = pUSBRequest->wLength;
- }
-
- //
- // Send the data via endpoint 0.
- //
- USBDCDSendDataEP0(0, (unsigned char *)psDevice->psHIDDescriptor,
- ulSize);
- break;
- }
-
- //
- // This was an unknown request so stall.
- //
- default:
- {
- USBDCDStallEP0(ulIndex);
- break;
- }
- }
-}
-
-//*****************************************************************************
-//
-// This function is called by the USB device stack whenever a non-standard
-// request is received.
-//
-// \param pvInstance is the instance data for this HID device.
-// \param pUSBRequest points to the request received.
-//
-// This call parses the provided request structure. Assuming the request is
-// understood, it is handled and any required response generated. If the
-// request cannot be handled by this device class, endpoint zero is stalled to
-// indicate an error to the host.
-//
-//*****************************************************************************
-static void
-HandleRequest(void *pvInstance, tUSBRequest *pUSBRequest,
- unsigned int ulIndex)
-{
- tHIDInstance *psInst;
- unsigned char ucProtocol;
- const tUSBDHIDDevice *psDevice;
-
- ASSERT(pvInstance != 0);
-
- //
- // Which device are we dealing with?
- //
- psDevice = pvInstance;
-
- //
- // Get