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

📄 l2_supp.c

📁 凌阳MP3 spSPCA755yuanma
💻 C
字号:
/*++

Copyright (c) 2001 Sunplus Technology Co., Ltd.

Module Name:

        l2_supp.c

Abstract:

        USB L2 function

Environment:

        Keil C51 Compiler

Revision History:

        11/12/2001      cclin    created                 

--*/

//=============================================================================
//Header file
//=============================================================================
#include "general.h"
#include "main.h"
#include "initio.h"
//#include "quantdef.h"
#include "setmode.h"
#include "dosusr.h"
#include "doslink.h"

//=============================================================================
//Symbol
//=============================================================================
//-----------------------------------------------------------------------------
//Constant
//-----------------------------------------------------------------------------
#define K_SMC_Read1             	0x00
#define K_SMC_SequentialDataInput       0x80
#define K_SMC_Reset                     0xFF
//-----------------------------------------------------------------------------
//Variable
//-----------------------------------------------------------------------------

//=============================================================================
//Program
//=============================================================================
UCHAR SMC_CheckReady(void);
void SMC_CommandLatchCycle(UCHAR command);
void SMC_ReadWriteAddressLatchCycle(ULONG address);

// 110102@wyeo
#if 0
//-----------------------------------------------------------------------------
//L2_SRAMLow2High
//-----------------------------------------------------------------------------
UCHAR L2_SRAMLow2High(USHORT siz,UCHAR* buffer) USING_0
{
     USHORT i;

	#if (K_CHIP_SET == K_CHIP_533)
	    XBYTE[0x2C11] &= 0xFC;   //High bank sram can is addressed from 0x1000 to 0x1fff
	#elif (K_CHIP_SET == K_CHIP_8591)
	    XBYTE[0x2111] &= 0xFC;   //High bank sram can is addressed from 0x1000 to 0x1fff
	#endif


     for (i = 0; i < siz; i++)
     {
          XBYTE[0x1400 + i] = buffer[i];
     }

     return L2K_SUCCESS;
}

//-----------------------------------------------------------------------------
//L2_SRAMHigh2Low
//-----------------------------------------------------------------------------
UCHAR L2_SRAMHigh2Low(USHORT siz,UCHAR* buffer) USING_0
{
     USHORT i;

	#if (K_CHIP_SET == K_CHIP_533)
	    XBYTE[0x2C11] &= 0xFC;   //High bank sram can is addressed from 0x1000 to 0x1fff
	#elif (K_CHIP_SET == K_CHIP_8591)
	    XBYTE[0x2111] &= 0xFC;   //High bank sram can is addressed from 0x1000 to 0x1fff
	#endif

     for (i = 0; i < siz; i++)
     {
          buffer[i] = XBYTE[0x1400 + i];
     }

     return L2K_SUCCESS;
}
#endif

//--------------------
#if (CFA)
//-----------------------------------------------------------------------------
//L2_SetCFDestDMA
//-----------------------------------------------------------------------------
/* 
routine description:
        CF DMA setting
arguments:
        source: CF as a DMA source or destination.
        LBAaddr: the absolute address to read write CF (will be transfer to sector address)
        size: DMA size
return value:
        0x00   - success
        others - error
*/
UCHAR L2_SetCFDMA(BIT source,ULONG logAddr, ULONG siz) USING_0  //ada@1128
{
     UCHAR   temp1,temp2,temp3,temp4,temp5;

     #if (CFAMEM)
     UCHAR   sts1;        
     #endif

     #if (CFAIDE)
     USHORT sts2;
     #endif          

	logAddr = logAddr/G_Card_BytePerSector;	    //transfer to sector address(1 sector=512 bytes)

     if (logAddr < G_Card_SectorPerCard)
     {
          temp1 = (BYTE)(((logAddr & 0x0f000000) >> 24) | 0xE0);        //in LBA mode 
          temp2 = (BYTE)((logAddr & 0x00ff0000) >> 16);
          temp3 = (BYTE)((logAddr & 0x0000ff00) >> 8);
          temp4 = (BYTE)(logAddr & 0x000000ff);

          if ((siz % G_Card_BytePerSector) == 0)
          {
               temp5 = siz/G_Card_BytePerSector;
          }
          else
          {
               temp5 = siz/G_Card_BytePerSector + 1;
          }

          #if (CFAMEM)
          sts1 = 0x00;
          while ((sts1 & 0xc0) != 0x40)            //check CF status register not busy and ready
          {
               L2_CFComMemRd(0x00,0x07,&sts1);
          }

          L2_CFComMemWr(0x00,0x02,temp5);          //sector count
          L2_CFComMemWr(0x00,0x03,temp4);          //LBA 7-0
          L2_CFComMemWr(0x00,0x04,temp3);          //LBA 15-8
          L2_CFComMemWr(0x00,0x05,temp2);          //LBA 23-16
          L2_CFComMemWr(0x00,0x06,temp1);          //LBA 27-24     

          if (source == 0)
          {
               L2_CFComMemWr(0x00,0x07,0x30);        //write sector command   
          }
          else
          {
               L2_CFComMemWr(0x00,0x07,0x20);        //read sector command   
          }

          sts1 = 0x00;
          while (sts1 != 0x58)
          {
               L2_CFComMemRd(0x00,0x07,&sts1);     //CF status register ready and data request(0x58)
          }     

          L2_CFSetMemA(0x00,0x00);                        //set CF port address in DMA
          #endif

          #if (CFAIDE)
          sts2 = 0x0000;
          while ((sts2 & 0x00c0) != 0x0040)            //check CF status register not busy and ready
          {
               L2_CFSetWordCsARd(0x17,&sts2);  
          }

          L2_CFSetWordCsAWr(0x12,0x01);        
          L2_CFSetWordCsAWr(0x13,temp4);      
          L2_CFSetWordCsAWr(0x14,temp3);      
          L2_CFSetWordCsAWr(0x15,temp2);     
          L2_CFSetWordCsAWr(0x16,temp1);

          if (source == 0)
          {
               L2_CFSetWordCsAWr(0x17,0x30); //write sector command   
          }
          else
          {
               L2_CFSetWordCsAWr(0x17,0x20); //read sector command   
          }

          sts2 = 0x0000;
          while (sts2 != 0x0058)
          {
               L2_CFSetWordCsARd(0x17,&sts2);     //CF status register ready and data request(0x0058)
          }             

          L2_CFSetCsA(0x10);                      //set CF port address in DMA
          #endif

          return L2K_SUCCESS;
     }
     else
     {
          return L2K_ERROR_GENERAL;
     }
}
#endif

//-----------------------------------------------------------------------------
//L2_CardDetect
//-----------------------------------------------------------------------------
/* 
routine description:
        Detect whether storage media card is inserted
arguments:
        detect: 
          0: Card is not inserted
		1: Card is inserted
return value:
        0x00   - success
        others - error
*/
/* SGJM TEMP DEL
UCHAR L2_CardDetect(UCHAR* detect) USING_0
{
     *detect = 0;

     XBYTE[0x2405] &= 0xdf;

     if (!(XBYTE[0x2409] & 0x20))
     {
          *detect = 1;
          //version4.0@ada@0513 for Card Write Protect
          #if (SD)
          XBYTE[0x2405] &= 0x7f;

          if (XBYTE[0x2409] & 0x80)
          {
               G_Card_WriteProtect = 1;
               //DbgPrint("This SD card is write-protected\n");
          }
          else
          {
               G_Card_WriteProtect = 0;
          }

          #endif

          //version4.0@ada@0513 for Card Write Protect
          #if (SMC)
          XBYTE[0x2406] &= 0xfd;

          if (!(XBYTE[0x240a] & 0x02))
          {
               if (G_Card_WriteProtect == 0)
               {
                    G_Card_WriteProtect = 1;
                    //DbgPrint("This SMC card is write-protected\n");
               }
          }
          #endif
     }
     else
     {
#if (FirmwareDetectMMCSD_OPTION==1)
#if (SD)
	if (L1_SDIdentification(K_Card_PageSize) == 0)
	{
		*detect = 1;
	}
	else
#endif
	{
#if (MMC)
		if (L1_MMCIdentification(K_Card_PageSize) == 0)
		{
			*detect = 1;
		}
#endif
	}
#endif
         G_Card_WriteProtect = 0;
     }
	return L2K_SUCCESS;
}*/

#if (SMC || NAND)
//-----------------------------------------------------------------------------
//L2_SetSMCDMA
//-----------------------------------------------------------------------------
/*
routine description:
        SMC DMA setting
arguments:
        source: SMC as a DMA source or destination.
        phyAddr: the physical address to read write SMC (will be transfer to sector address)
        DMA size: 512 bytes
return value:
        0x00   - success
        others - error
*/
UCHAR L2_SetSMCDMA(BIT source,ULONG phyAddr) USING_0
{
        UCHAR sts = 0x00;

        if (SMC_CheckReady())
        {
                if (source)
                {
                        SMC_CommandLatchCycle(K_SMC_Read1);    //Read from nandf
                }
                else
                {
                        SMC_CommandLatchCycle(K_SMC_SequentialDataInput);    //Write to nandf
                }

                SMC_ReadWriteAddressLatchCycle(phyAddr);
        }
        else
        {
                SMC_CommandLatchCycle(K_SMC_Reset);     //reset
                sts = 0x01;
        }

        return sts;
}
#endif


⌨️ 快捷键说明

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