⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 etd.h

📁 Usb Host/Periphel Control TD1120 codes
💻 H
字号:
/*-----------------------------------------------------------------------------
$File: //hodad/usblink/3.4/source/hostctrl/otg242/etd.h $
$DateTime: 2003/09/08 15:17:45 $
$Revision: #1 $
Purpose:   OTG242 ETD data and macro definitions.

CONFIDENTIAL AND PROPRIETARY INFORMATION OF SOFTCONNEX TECHNOLOGIES, INC.

THIS NOTICE IS NOT TO BE DELETED, MODIFIED, MOVED OR CHANGED IN ANY WAY.

Copyright (c) 1999 - 2003 by SoftConnex Technologies, Inc. 

This software is protected by copyright laws and international copyright 
treaties, as well as other intellectual property laws and treaties.  This
software is a CONFIDENTIAL, unpublished work of authorship, and with portions 
constituting TRADE SECRETS of SoftConnex Technologies, Inc., a Delaware USA 
corporation.  Any unauthorized use, disclosure, and/or reproduction of this 
software, or any part of this software; or distribution of this software in any 
form or by any means; or storage of this software in any database or retrieval 
system, without the express written consent of, and license from, SoftConnex 
Technologies, Inc. is strictly prohibited.  This software is protected under the
copyright and/or trade secret laws in other countries in addition to USA.  All 
Rights Reserved.  Failure to abide by the use, disclosure and/or reproduction 
restrictions may result in civil and /or criminal penalties, and will be 
prosecuted to the maximum extent of the law.
-----------------------------------------------------------------------------*/

#ifndef _SOFTCONNEX_OTG242ETD_H_
#define _SOFTCONNEX_OTG242ETD_H_


#define OTG242ETD_FORMAT_CTRL            0x00000000
#define OTG242ETD_FORMAT_ISOC            0x00004000
#define OTG242ETD_FORMAT_BULK            0x00008000
#define OTG242ETD_FORMAT_INTR            0x0000C000


/* ED field definitions - dword 0, use as masks 
 ***********************************************/
#define OTG242ETD_FUNCTION_ADDRESS 0x0000007F
#define OTG242ETD_EP_NUMBER        0x00000780
#define OTG242ETD_DIRECTION        0x00001800
#define OTG242ETD_SPEED            0x00002000
#define OTG242ETD_MAX_PACKET_SIZE  0x03FF0000
#define OTG242ETD_HALTED           0x08000000
#define OTG242ETD_TOGGLE_CARRY     0x10000000
#define OTG242ETD_STOP_ON_NAK      0x40000000


/* Control,Bulk, Interrupt TD field definitions of dword1-dword2 
 ***************************************************************/ 
#define OTG242ETD_XBUFSTARTADDR    0x0000FFFF       /* dword 1 */
#define OTG242ETD_YBUFSTARTADDR    0xFFFF0000       /* dword 1 */
#define OTG242ETD_RETRY_DELAY      0x000000FF       /* dword 2 */
#define OTG242ETD_DIRECTION_PID    0x00030000       /* dword 2 */
#define OTG242ETD_BUFFER_ROUNDING  0x00040000       /* dword 2 */
#define OTG242ETD_DELAY_INTERRUPT  0x00380000       /* dword 2 */
#define OTG242ETD_DELAY_INTERRUPT_ISOC   0x00380000 /* dword 2 */
#define OTG242ETD_DATA_TOGGLE      0x00C00000       /* dword 2 */
#define OTG242ETD_ERROR_COUNT      0x0F000000       /* dword 2 */
#define OTG242ETD_COMPLETION_CODE  0xF0000000       /* dword 2 */

/* for interrupt TD, two more fields dword2 
 ******************************************/

#define OTG242ETD_POLLINGINTERVAL  0x000000FF       /* dword 2 */
#define OTG242ETD_RELPOLLINGPOS    0x0000FF00       /* dword 2 */

/* Iso TD field definitions dword2
 *********************************/

#define OTG242ETD_STARTING_FRAME   0x0000FFFF       /* dword 2 */
#define OTG242ETD_FRAME_COUNT      0x01000000       /* dword 2 */
#define OTG242ETD_ISO_AUTOISO      0x08000000       /* dword 2 */
#define OTG242ETD_ISO_NO_AUTOISO   0x00000000       /* dword 2 */


/* Control,Bulk, Interrupt TD field definitions of dword3 
 ***************************************************************/ 

#define OTG242ETD_TOTBYTECOUNT     0x001FFFFF       /* dword 3 */
#define OTG242ETD_BUFFSIZE         0xFFE00000       /* dword 3 */

/* Iso TD dword 3 info:  
 **********************/
#define OTG242ETD_ISO_PKTLEN0      0x000003FF       /* dword 3 */
#define OTG242ETD_ISO_COMPCODE0    0x0000F000       /* dword 3 */
#define OTG242ETD_ISO_PKTLEN1      0x03FF0000       /* dword 3 */
#define OTG242ETD_ISO_COMPCODE1    0xF0000000       /* dword 3 */


/* Completion Codes for the TDs 
 ******************************/

#define OTG242ETD_COMPLETION_CODE_NO_ERROR      0x00000000
#define OTG242ETD_CC_CRC                        0x10000000
#define OTG242ETD_CC_BITSTUFFING                0x20000000
#define OTG242ETD_CC_DATATOGGLEMISMATCH         0x30000000
#define OTG242ETD_CC_STALL                      0x40000000
#define OTG242ETD_CC_DEVICENOTRESPONDING        0x50000000
#define OTG242ETD_CC_PIDFAILURE                 0x60000000
#define OTG242ETD_COMPLETION_CODE_DATA_OVERRUN  0x80000000
#define OTG242ETD_COMPLETION_CODE_DATA_UNDERRUN 0x90000000
#define OTG242ETD_COMPLETION_CODE_ACK           0xA0000000       
#define OTG242ETD_COMPLETION_CODE_NAK           0xB0000000       
#define OTG242ETD_CC_BUFFEROVERRUN              0xC0000000
#define OTG242ETD_CC_BUFFERUNDERRUN             0xD0000000
#define OTG242ETD_CC_SCHEDULEOVERRUN            0xE0000000
#define OTG242ETD_COMPLETION_CODE_NOT_ACCESSED  0xF0000000    


#define OTG242ETD_FRAMECOUNT_PER_ETD            2
#define OTG242ETD_ETD_PER_OHCI                  (8/OTG242ETD_FRAMECOUNT_PER_ETD)



typedef struct _Otg242Etd
   {
   U32 desc;
   U32 buffer;
   U32 control;

   union
      {
      U32 packetControl;
      U32 packetStatus[OTG242ETD_FRAMECOUNT_PER_ETD/2];
      }
   td;

   }
Otg242Etd;

#define OTG242ETD_MAX      16

#define OTG242ETD_GetStatusLength(etd, i)      \
   ((i & 1)? ((etd->td.packetStatus[i >> 1] >> 16) & 0xFFFF) : (etd->td.packetStatus[i >> 1] & 0xFFFF))

void OTG242ETD_SetStatusLength(Otg242Etd* etd, int index, U32 val);


typedef enum _EpType
   {
   EpTypeUndefined,
   EpTypeCtrl,
   EpTypeBulk,
   EpTypeIntr,
   EpTypeIsoc
   }
EpType;

struct _Otg242Hc;

typedef struct _Otg242EtdBank
   {
   struct _Otg242Etd etd;

   OhciEd* ed;
   OhciTd* td;

   SctBool  filled;
   SctBool  isDirectionIn;
   SctBool  cancelled;
   EpType   type;
   S32   maxPacketSize;
   
   S32   totalLength;
   S32   finishedLength;
   S32   xBuffer;
   S32   yBuffer;
   S32   xBufferLength;
   S32   yBufferLength;
   U32   xPacketCount;
   U32   yPacketCount;

   U32   intrIndex; /* For check cancelled ED */

   /* These are for Isoc only */
   U32   totalFrameCount;
   U32   finishedFrameCount;

   U32   index;
   U32   memoryAddress;

   struct _Otg242EtdBank   *nextEtd;
   struct _Otg242Hc* hc;
   }
Otg242EtdBank;

#define OTG242ETD_ReadReg(etd, reg)            HW_ReadOtg242Register(etd->hc->regBase, reg)
#define OTG242ETD_WriteReg(etd, reg, val)      HW_WriteOtg242Register(etd->hc->regBase, reg, val)

#define OTG242ETD_EnableEtd(index)                (1 << index)
#define OTG242ETD_SetXBuffer(etd, addr)           { etd.buffer &= 0xFFFF0000; etd.buffer |= addr; }
#define OTG242ETD_SetYBuffer(etd, addr)           { etd.buffer &= 0x0000FFFF; etd.buffer |= addr << 16; }
#define OTG242ETD_XBufferFilled(index)            (1 << index)
#define OTG242ETD_YBufferFilled(index)            (1 << index)
#define OTG242ETD_XYIntrEnable(index)             (1 << index)



#define OTG242ETD_SetStartingFrame(etd, frame)    etd->control |= frame
#define OTG242ETD_SetFrameCount(etd, count)       etd->control |= count
#define OTG242ETD_SetFrameCountValue243(etd, count)  etd->control |= (count & 0xF) << 24
#define OTG242ETD_SetFrameCountValue(etd, count)  etd->control |= (count & 0x1) << 24
#define OTG242ETD_SetAutoISO(etd, iso)            etd->control |= iso << 27
#define OTG242ETD_SetDelayIntr(etd, di)           etd->control |= di >> 1
#define OTG242ETD_SetRetryDelay(etd, delay)       etd->control |= delay
#define OTG242ETD_SetDirectionPid(etd, pid)       etd->control |= pid >> 3
#define OTG242ETD_SetBufferRounding(etd, rounding) etd->control |= rounding
#define OTG242ETD_SetDelayIntrIsoc(etd, delay)    etd->control |= delay >> 2
#define OTG242ETD_SetDataToggle(etd, toggle)      etd->control |= toggle >> 2
#define OTG242ETD_SetErrorCount(etd, toggle)      etd->control |= toggle >> 2
#define OTG242ETD_SetCompletionCode(etd, code)    etd->control |= code
#define OTG242ETD_SetPollingInterval(etd, val)    etd->control |= val
#define OTG242ETD_SetPollingPos(etd, pos)         etd->control |= pos << 8


#define OTG242ETD_SetTotByteCount(etd, count)     etd->td.packetControl |= count
#define OTG242ETD_SetBufSize(etd, size)           etd->td.packetControl |= (size) << 21

#define OTG242ETD_SetFunctionAddress(etd, addr)   etd->desc |= addr
#define OTG242ETD_SetEpNumber(etd, ep)            etd->desc |= ep
#define OTG242ETD_SetDirection(etd, direction)    etd->desc |= direction
#define OTG242ETD_SetSpeed(etd, speed)            etd->desc |= speed
#define OTG242ETD_SetMaxPacketSize(etd, size)     etd->desc |= size
#define OTG242ETD_SetHalted(etd, halted)          etd->desc |= halted << 27
#define OTG242ETD_SetToggleCarry(etd, carry)      etd->desc |= carry << 27
#define OTG242ETD_SetFormat(etd, format)          etd->desc |= format
#define OTG242ETD_SetStopOnNak(etd)               etd->desc |= OTG242ETD_STOP_ON_NAK;

#define OTG242ETD_GetStopOnNak(etd)       (etd->desc & OTG242ETD_STOP_ON_NAK)
#define OTG242ETD_GetStartingFrame(etd)   (etd->control & OTG242ETD_STARTING_FRAME)
#define OTG242ETD_GetFrameCount(etd)      ((etd->control & OTG242ETD_FRAME_COUNT) >> 24)
#define OTG242ETD_GetDelayIntrIsoc(etd)   ((etd->control & OTG242ETD_DELAY_INTERRUPT_ISOC) << 1)
#define OTG242ETD_GetRetryDelay(etd)      (etd->control & OTG242ETD_RETRY_DELAY)
#define OTG242ETD_GetDirectionPid(etd)    ((etd->control & OTG242ETD_DIRECTION_PID) << 3)
#define OTG242ETD_GetBufferRounding(etd)  (etd->control & OTG242ETD_BUFFER_ROUNDING)
#define OTG242ETD_GetDelayIntr(etd)       ((etd->control & OTG242ETD_DELAY_INTERRUPT) << 2)
#define OTG242ETD_GetDataToggle(etd)      ((etd->control & OTG242ETD_DATA_TOGGLE) << 2)
#define OTG242ETD_GetErrorCount(etd)      ((etd->control & 0x03000000) << 2)


#define OTG242ETD_GetTotByteCount(etd)     (etd->td.packetControl & OTG242ETD_TOTBYTECOUNT)
#define OTG242ETD_GetBufSize(etd)         ((etd->td.packetControl & OTG242ETD_BUFFSIZE) >> 21)

#define OTG242ETD_GetFunctionAddress(etd) (etd->desc & OTG242ETD_FUNCTION_ADDRESS)
#define OTG242ETD_GetEpNumber(etd)        (etd->desc & OTG242ETD_EP_NUMBER)
#define OTG242ETD_GetDirection(etd)       (etd->desc & OTG242ETD_DIRECTION)
#define OTG242ETD_GetSpeed(etd)           (etd->desc & OTG242ETD_SPEED)
#define OTG242ETD_GetMaxPacketSize(etd)   (etd->desc & OTG242ETD_MAX_PACKET_SIZE)
#define OTG242ETD_GetHalted(etd)          ((etd->desc & OTG242ETD_HALTED) >> 27)
#define OTG242ETD_GetToggleCarry(etd)     ((etd->desc & OTG242ETD_TOGGLE_CARRY) >> 27)
#define OTG242ETD_GetCompletionCode(etd)  (etd->control & OTG242ETD_COMPLETION_CODE)

#define OTG242ETD_OverMaxErrorCount(etd)  ((etd->desc & OTG242ETD_ERROR_COUNT) > 0x02000000)

int OTG242ETD_Create(Otg242EtdBank* etdBank, struct _Otg242Hc *hc);
Otg242EtdBank* OTG242ETD_IsInChip(Otg242EtdBank* etdBank, OhciEd* ed);

SctBool OTG242ETD_FillEtd(Otg242EtdBank* etdBank);
SctBool OTG242ETD_FillEtdIsoc(Otg242EtdBank *etdBank);

SctBool OTG242ETD_FillTd(Otg242EtdBank *etdBank);
SctBool OTG242ETD_FillTdIsoc(Otg242EtdBank *etdBank);
SctBool OTG242ETD_FillEd(Otg242EtdBank* etdBank);

void OTG242ETD_EtdDone(Otg242EtdBank* etdBank);
void OTG242ETD_CtrlDone(Otg242EtdBank* etdBank);
void OTG242ETD_IsocDone(Otg242EtdBank* etdBank);
void OTG242ETD_NextPacket(Otg242EtdBank* etdBank);

SctBool OTG242ETD_DoXBufferOut(Otg242EtdBank* etdBank);
SctBool OTG242ETD_DoYBufferOut(Otg242EtdBank* etdBank);
SctBool OTG242ETD_DoXBufferIn(Otg242EtdBank* etdBank);
SctBool OTG242ETD_DoYBufferIn(Otg242EtdBank* etdBank);

void OTG242ETD_ReadData(Otg242EtdBank* etdBank, int actualLength, SctBool yBuffer);

Otg242EtdBank* OTG242ETD_Allocate(Otg242EtdBank* etdBank);
void OTG242ETD_Free(Otg242EtdBank* etdBank);
void OTG242ETD_Clean(Otg242EtdBank *etdBank);

SctBool OTG242ETD_UseTwoEtds(Otg242EtdBank* etdBank);

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -