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

📄 etd.c

📁 Usb Host/Periphel Control TD1120 codes
💻 C
📖 第 1 页 / 共 4 页
字号:
/*-----------------------------------------------------------------------------
$File: //hodad/usblink/3.4/source/hostctrl/otg242/etd.c $
$DateTime: 2003/09/08 15:17:45 $
$Revision: #1 $
Purpose:   OTG242 ETD operations.

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.
-----------------------------------------------------------------------------*/

#include "usblink.h"
#include "top.h"
#include "etd.h"

/******************************************************************************
Private definitions
******************************************************************************/

#define ETD_TOGGLE_CARRY_FIX 1

#define ETD_MASS_STORAGE_NEW 1
 
#define ETD_NEW_PACKET_PER_BUF 1

#ifdef  ETD_NEW_PACKET_PER_BUF
#define ETD_PACKETPERBUF 2
#endif

/******************************************************************************
Private Functions
******************************************************************************/


/*------------------------------------------------------------------------------
Name      : OTG242ETD_XBufferInterruptStatusClear
Purpose   : Xbuffer interrupt status clear
Arguments : IO: 
            IO:
Returns   : 
Notes     : 
-----------------------------------------------------------------------------*/
STATIC void OTG242ETD_XBufferInterruptStatusClear(Otg242EtdBank *etd, U8 index)
   {
   U32 mask = (1 << index);

   if(OTG242ETD_ReadReg(etd, OTG242HC_XBUFFERINTERRUPTSTATUS) & mask) 
      {
      OTG242ETD_WriteReg(etd, OTG242HC_XBUFFERINTERRUPTSTATUS, mask);
      }
   }


/*------------------------------------------------------------------------------
Name      : OTG242ETD_YBufferInterruptStatusClear
Purpose   : Ybuffer interrupt status clear
Arguments : IO: 
            IO:
Returns   : 
Notes     : 
-----------------------------------------------------------------------------*/
STATIC void OTG242ETD_YBufferInterruptStatusClear(Otg242EtdBank *etd, U8 index)
   {
   U32 mask = (1 << index);

   if(OTG242ETD_ReadReg(etd, OTG242HC_YBUFFERINTERRUPTSTATUS) & mask) 
      {
      OTG242ETD_WriteReg(etd, OTG242HC_YBUFFERINTERRUPTSTATUS, mask);
      }
   }


/*------------------------------------------------------------------------------
Name      : OTG242ETD_XYInterruptEnablesSet
Purpose   : XYInterruptEnable set
Arguments : IO: 
            IO:
Returns   : 
Notes     : 
-----------------------------------------------------------------------------*/
STATIC void OTG242ETD_XYInterruptEnablesSet(Otg242EtdBank *etd, U8 index)
   {
   U32 Read;
   
   Read = OTG242ETD_ReadReg(etd, OTG242HC_XYINTERRUPTENABLES);
   OTG242ETD_WriteReg( etd, OTG242HC_XYINTERRUPTENABLES, Read | (1 << index) );

   }


/*------------------------------------------------------------------------------
Name      : OTG242ETD_XYInterruptEnablesClear
Purpose   : XYInterrrupt enable clear
Arguments : IO: 
            IO:
Returns   : 
Notes     : 
-----------------------------------------------------------------------------*/
STATIC void OTG242ETD_XYInterruptEnablesClear(Otg242EtdBank *etd, U8 index)
   {
   U32 Read;
   
   Read = OTG242ETD_ReadReg(etd, OTG242HC_XYINTERRUPTENABLES);
   OTG242ETD_WriteReg( etd, OTG242HC_XYINTERRUPTENABLES, Read & ~(1 << index));
   }


/*------------------------------------------------------------------------------
Name      : OTG242ETD_XBufFilledStatusSet
Purpose   : Xbuffer filled status set
Arguments : IO: 
            IO:
Returns   : 
Notes     : 
-----------------------------------------------------------------------------*/
STATIC void OTG242ETD_XBufFilledStatusSet(Otg242EtdBank *etd, U8 index)
   {
   U32 mask = (1 << index);

   if((OTG242ETD_ReadReg(etd, OTG242HC_XBUFFILLEDSTATUS) & mask) != mask) 
      {
      OTG242ETD_WriteReg( etd, OTG242HC_XBUFFILLEDSTATUS, mask);
      }

   }
   
/*------------------------------------------------------------------------------
Name      : OTG242ETD_XBufFilledStatusClear
Purpose   : Xbuffer Filled status clear
Arguments : IO: 
            IO:
Returns   : 
Notes     : 
-----------------------------------------------------------------------------*/
   
STATIC void OTG242ETD_XBufFilledStatusClear(Otg242EtdBank *etd, U8 index)
  {
  U32 mask = (1 << index);

  if(OTG242ETD_ReadReg(etd, OTG242HC_XBUFFILLEDSTATUS) & mask) 
    {
    OTG242ETD_WriteReg( etd, OTG242HC_XBUFFILLEDSTATUS, mask);
    }

  }

/*------------------------------------------------------------------------------
Name      : OTG242ETD_YBufFilledStatusSet
Purpose   : Ybuffer filled status set
Arguments : IO: 
            IO:
Returns   : 
Notes     : 
-----------------------------------------------------------------------------*/
STATIC void OTG242ETD_YBufFilledStatusSet(Otg242EtdBank *etd, U8 index)
   {
   U32 mask = (1 << index);

   if((OTG242ETD_ReadReg(etd, OTG242HC_YBUFFILLEDSTATUS) & mask) != mask) 
      {
      OTG242ETD_WriteReg( etd, OTG242HC_YBUFFILLEDSTATUS, mask);
      }

   }


/*------------------------------------------------------------------------------
Name      : OTG242ETD_YBufFilledStatusClear
Purpose   : Ybuffer Filled status clear
Arguments : IO: 
            IO:
Returns   : 
Notes     : 
-----------------------------------------------------------------------------*/
   
STATIC void OTG242ETD_YBufFilledStatusClear(Otg242EtdBank *etd, U8 index)
  {
  U32 mask = (1 << index);

  if(OTG242ETD_ReadReg(etd, OTG242HC_YBUFFILLEDSTATUS) & mask) 
    {
    OTG242ETD_WriteReg( etd, OTG242HC_YBUFFILLEDSTATUS, mask);
    }

  }



/*------------------------------------------------------------------------------
Name      : OTG242ETD_EtdEnableSet
Purpose   : ETD enable
Arguments : IO: 
            IO:
Returns   : 
Notes     : 
-----------------------------------------------------------------------------*/
STATIC void OTG242ETD_EtdEnableSet(Otg242EtdBank *etd, U8 index)
  {
  if(OTG242ETD_ReadReg(etd, OTG242HC_ETD_ENABLE) & (1 << index)) 
     {
     return;
     }

  OTG242ETD_WriteReg( etd, OTG242HC_ETD_ENABLE, 1 << index);
  }
  
/*------------------------------------------------------------------------------
Name      : OTG242ETD_EtdEnableClear
Purpose   : ETD enable clear
Arguments : IO: 
            IO:
Returns   : 
Notes     : 
-----------------------------------------------------------------------------*/
  
STATIC void OTG242ETD_EtdEnableClear(Otg242EtdBank *etd, U8 index)
  {
  U32 mask = (1 << index);

  if( OTG242ETD_ReadReg(etd, OTG242HC_ETD_ENABLE) & mask) 
     {
     OTG242ETD_WriteReg( etd, OTG242HC_ETD_ENABLE, mask);
     }

  }

/*------------------------------------------------------------------------------
Name      : OTG242ETD_ETDDoneEnableSet
Purpose   : ETD DONE set
Arguments : IO: 
            IO:
Returns   : 
Notes     : 
-----------------------------------------------------------------------------*/
  
STATIC void OTG242ETD_ETDDoneEnableSet(Otg242EtdBank *etd, U8 index)
   {
   U32 Read;
   
   Read = OTG242ETD_ReadReg(etd, OTG242HC_ETDDONEENABLE);
   
   OTG242ETD_WriteReg(etd, OTG242HC_ETDDONEENABLE, Read | (1 << index));
   }
   
/*------------------------------------------------------------------------------
Name      : OTG242ETD_ETDDoneEnableClear
Purpose   : ETD DONE clear
Arguments : IO: 
            IO:
Returns   : 
Notes     : 
-----------------------------------------------------------------------------*/

STATIC void OTG242ETD_ETDDoneEnableClear(Otg242EtdBank *etd, U8 index)
   {
   U32 Read;
   
   Read = OTG242ETD_ReadReg(etd, OTG242HC_ETDDONEENABLE);
   OTG242ETD_WriteReg(etd, OTG242HC_ETDDONEENABLE, Read & ~(1 << index));
   }
 
/*------------------------------------------------------------------------------
Name      : OTG242ETD_EndpointDoneStatusClear
Purpose   : ETD DONE status clear
Arguments : IO: 
            IO:
Returns   : 
Notes     : 
-----------------------------------------------------------------------------*/

STATIC void OTG242ETD_EndpointDoneStatusClear(Otg242EtdBank *etd, U8 index)
   {
   U32 mask = (1 << index);

   if(OTG242ETD_ReadReg(etd, OTG242HC_ENDPOINTDONESTATUS) & mask) 
      {
      OTG242ETD_WriteReg(etd, OTG242HC_ENDPOINTDONESTATUS, mask);
      }
   }

   
/*------------------------private functions end -----------------------------*/



S32 OTG242ETD_Create(Otg242EtdBank *etdBank, Otg242Hc *hc)
   {
   Otg242EtdBank* etd;
   S32 index;

   for (index = 0, etd = etdBank; index < OTG242ETD_MAX; index++, etd++)
      {
      etd->ed = NULL;
      etd->td = NULL;
      etd->filled = SCC_FALSE;
#if ETD_MASS_STORAGE_NEW

#else      
      etd->cancelled = SCC_FALSE;
#endif
      
      etd->xBuffer = -1;
      etd->yBuffer = -1;   
      etd->index = index;
      etd->hc = hc;
      etd->nextEtd = NULL;
      }

   return 0;
   }

void OTG242ETD_Clean(Otg242EtdBank *etdBank)
   {
   Otg242EtdBank* etd;
   S32 index;

   for (index = 0, etd = etdBank; index < OTG242ETD_MAX; index++, etd++)
      {
      OTG242ETD_EtdEnableClear(etd, (U8)index);
      
      OTG242ETD_XBufFilledStatusClear(etd, (U8)index);
      OTG242ETD_YBufFilledStatusClear(etd, (U8)index);
      
      OTG242ETD_ETDDoneEnableClear(etd, (U8)index);
      
      if (etd->xBuffer >= 0)
         {
         OTG242HC_FreeMemory(etdBank->hc, etd->xBuffer);
         }

      if (etd->yBuffer >= 0)
         {
         OTG242HC_FreeMemory(etdBank->hc, etd->yBuffer);
         }

      etd->ed = NULL;
      etd->td = NULL;
      etd->filled = SCC_FALSE;
      etd->xBuffer = -1;
      etd->yBuffer = -1;  
#if ETD_MASS_STORAGE_NEW

#else
      etd->cancelled = SCC_FALSE;
#endif      
      etd->nextEtd = NULL;
      }
   }

/*
 * Find a free ETD slot. Return NULL if not found.
 */
Otg242EtdBank* OTG242ETD_Allocate(Otg242EtdBank *etdBank)
   {
   Otg242EtdBank* etd;
   S32 slot;

   for (slot = 0, etd = etdBank; slot < OTG242ETD_MAX; slot++, etd++)
      {
      if (etd->filled == SCC_FALSE)
         {
         etd->filled = SCC_TRUE;

         OTG242HC_DecFreeEtd(etd->hc);
         return etd;
         }
      }

   return NULL;
   }

void OTG242ETD_Free(Otg242EtdBank* etdBank)
   {
   if (etdBank->xBuffer >= 0)
      {
      OTG242HC_FreeMemory(etdBank->hc, etdBank->xBuffer);
      etdBank->xBuffer = -1;
      }
   
   if (etdBank->yBuffer >= 0)
      {
      OTG242HC_FreeMemory(etdBank->hc, etdBank->yBuffer);
      etdBank->yBuffer = -1;
      }

   etdBank->ed = NULL;
   etdBank->td = NULL;
   etdBank->filled = SCC_FALSE;
#if ETD_MASS_STORAGE_NEW

#else   
   etdBank->cancelled = SCC_FALSE;
#endif

   if (NULL != etdBank->nextEtd)
      {
      etdBank->nextEtd->nextEtd = NULL;
      etdBank->nextEtd = NULL;
      }

   OTG242HC_IncFreeEtd(etdBank->hc);
   }

Otg242EtdBank* OTG242ETD_IsInChip(Otg242EtdBank* etdBank, OhciEd* ed)
   {
   Otg242EtdBank* etd;
   S32 slot;

   for (slot = 0, etd = etdBank; slot < OTG242ETD_MAX; slot++, etd++)
      {

⌨️ 快捷键说明

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