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

📄 l2_supp.c

📁 台湾凌阳方案300万数码相机源代码
💻 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 "quantdef.h"
#include "setmode.h"
#include "dosusr.h"
#include "doslink.h"
#include "smcfunc.h"
#include "smccon.h"

//version4.0@ada@0513 for Card Write Protect
#include "cardusr.h"

//=============================================================================
//Symbol
//=============================================================================
//-----------------------------------------------------------------------------
//Constant
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
//Variable
//-----------------------------------------------------------------------------

//=============================================================================
//Program
//=============================================================================
//-----------------------------------------------------------------------------
//L2_CheckReadData2UsbDmaDone
//-----------------------------------------------------------------------------
UCHAR L2_CheckReadData2UsbDmaDone(USHORT size) USING_0
/*
Routine Description:

        check if DMA to USB has done

Arguments:

        size - size of DMA

Return Value:

        DMA success or not

*/
{
        UCHAR i;
        UCHAR status = TRUE;

        for (i = 0; i < (size / 0x40); i++)
        {
                while (XBYTE[K_USB_CLASS_IN_BUF_SIZE] != 0x40)
                {
                        if (USR_UploadCheck(G_ucState3))
                        {
                                status = FALSE;
                                break;
                        }
                }
                XBYTE[0x25a1] |= K_USB_CLASS_IN_OPEN;//0x01;
                while ((XBYTE[0x25c2] & K_USB_CLASS_IN_ACK_MASK) == 0)
                {
                        if (USR_UploadCheck(G_ucState3))
                        {
                                status = FALSE;
                                break;
                        }
                }
                XBYTE[0x25c2] = 0x00;
        }

        return(status);
}

//-----------------------------------------------------------------------------
//L2_WriteZigZagQTable
//-----------------------------------------------------------------------------
UCHAR L2_WriteZigZagQTable(UCHAR component, PUCHAR pTable) USING_0
/*
Routine Description:
        set zig-zag quantization table

Arguments:
        pTable - pointer to quantization table

Return Value:

        success or not

*/
{
     USHORT i, j;

     XBYTE[0x2882] = 1;

     if (component == 0)
     {
          for (j = 0; j < 0x40; j++)
          {
               i = zigzagTable[j];
               XBYTE[0x2800 + i] = pTable[j];
          }
     }
     else
     {
          for (j = 0; j < 0x40; j++)
          {
               i = zigzagTable[j];
               XBYTE[0x2840 + i] = pTable[j];
          }
     }

     XBYTE[0x2882] = 0;

     return(TRUE);
}

#if 0
//-----------------------------------------------------------------------------
//L2_GetUsbAudioAlternateSetting
//-----------------------------------------------------------------------------
UCHAR L2_GetUsbAudioAlternateSetting(void) USING_0
/*
Routine Description:

        set zig-zag quantization table

Arguments:

        none

Return Value:

        alernate setting of audio pipe

*/
{
        UCHAR as = XBYTE[0x25b2];        

        return(((as >> 4) & 0x0f));
}
#endif

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

     XBYTE[0x2C11] &= 0xFC;   //High bank sram can is addressed from 0x1000 to 0x1fff

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

     return L2K_SUCCESS;
}

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

     XBYTE[0x2C11] &= 0xFC;   //High bank sram can is addressed from 0x1000 to 0x1fff

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

     return L2K_SUCCESS;
}

#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;        

	//patch4.5@ada@Add timeout count begin
	UCHAR error;
	//patch4.5@ada@Add timeout count end
     #endif

     #if (CFAIDE)
     USHORT sts2;

	//patch4.5@ada@Add timeout count begin
	UCHAR  tmp;
	//patch4.5@ada@Add timeout count end
     #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;
          }

		//patch4.5@ada@Add timeout count begin
          #if (CFAMEM)
          sts1 = 0x00;
          while ((sts1 & 0xc0) != 0x40)            //check CF status register not busy and ready
          {
               error = L2_CFComMemRd(0x00,0x07,&sts1);

			if (error != 0)
			{
				return L2K_ERROR_GENERAL;
			}
          }

          error = L2_CFComMemWr(0x00,0x02,temp5);          //sector count

		if (error != 0)
		{
			return L2K_ERROR_GENERAL;
		}

          error = L2_CFComMemWr(0x00,0x03,temp4);          //LBA 7-0

		if (error != 0)
		{
			return L2K_ERROR_GENERAL;
		}

          error = L2_CFComMemWr(0x00,0x04,temp3);          //LBA 15-8

		if (error != 0)
		{
			return L2K_ERROR_GENERAL;
		}

          error = L2_CFComMemWr(0x00,0x05,temp2);          //LBA 23-16

		if (error != 0)
		{
			return L2K_ERROR_GENERAL;
		}

          error = L2_CFComMemWr(0x00,0x06,temp1);          //LBA 27-24     

		if (error != 0)
		{
			return L2K_ERROR_GENERAL;
		}

          if (source == 0)
          {
               error = L2_CFComMemWr(0x00,0x07,0x30);        //write sector command   

			if (error != 0)
			{	
				return L2K_ERROR_GENERAL;
			}
          }
          else
          {
               error = L2_CFComMemWr(0x00,0x07,0x20);        //read sector command   

			if (error != 0)
			{
				return L2K_ERROR_GENERAL;
			}
          }

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

			if (error != 0)
			{
				return L2K_ERROR_GENERAL;
			}
          }     

          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
          {
               tmp = L2_CFSetWordCsARd(0x17,&sts2);  

				if (tmp > 0)
				{
					return L2K_ERROR_GENERAL;
				}
          }

          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)
          {
               tmp = L2_CFSetWordCsARd(0x17,&sts2);     //CF status register ready and data request(0x0058)

				if (tmp > 0)
				{
				return L2K_ERROR_GENERAL;
				}
          }             

          L2_CFSetCsA(0x10);                      //set CF port address in DMA
          #endif
		//patch4.5@ada@Add timeout count end

          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
*/
UCHAR L2_CardDetect(UCHAR* detect) USING_0
{
     *detect = 0;
  
     XBYTE[0x2405] &= 0xdf;//wendy@2004/7/14 bug

     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;
               //printf("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;
                    //printf("This SMC card is write-protected\n");
               }
          } 
          #endif
     }
     else
     {
          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 + -