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

📄 flashgo_refdesign.c

📁 ti的数字电视芯片 tvp9000的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/********************************************************************* 
*    Property of Texas Instruments Incorporated, Copyright 2000
*    All rights reserved
**********************************************************************/
/*********************************************************************
*
* Description:
*              Program the Hex file to the Flash 
*
* Function list:
*
**********************************************************************/
/*********************************************************************
*
* $Revision:  $
*
* $History: FlashGo.c $
*********************************************************************/

#include	<stdio.h>
#include	<stdlib.h>

#include	"flashGo.h"
#include	"TiDTV.c"

// the following data is at TiDTV.c
// get the size of the mon segment separately

static unsigned char  DQE      = DQ6|DQ2;

static unsigned long size[] =
{  
   sizeof(mon_0),
   sizeof(mon_1),
   sizeof(mon_2),
   sizeof(mon_3),
   sizeof(mon_4),
   sizeof(mon_5),
   sizeof(mon_6),
   sizeof(mon_7),
   sizeof(mon_8)
};

//the data address of the each segment
static unsigned long mon_add[] =
{
   (unsigned long)mon_0,
   (unsigned long)mon_1,
   (unsigned long)mon_2,
   (unsigned long)mon_3,
   (unsigned long)mon_4,
   (unsigned long)mon_5,
   (unsigned long)mon_6,
   (unsigned long)mon_7,
   (unsigned long)mon_8
};

static ebiset(void);
#ifdef EBI1
static unsigned long BASE     = 0x30000000; //EBI 0
#else
static unsigned long BASE     = 0x20000000; //EBI 0
#endif
/***************************************************************
*  swap(unsigned short)
*swap the bit0 ->bit15 and bit15 to bit0  
***************************************************************/
unsigned short swap(unsigned short data)
{
#if 0
int i;
unsigned short result = 0;

   for(i=0;i<16;i++)
      result |=(((data >> i) & 0x1)<<(15-i));
   
   return(result);          
#else
   return(data);
#endif
}

/***************************************************************
*  tvp_FERROR flashReset
*  
*  Input:
*     None;
*  Output:
*     None:
*  Return:
*     None;
*
*  Descriptions:
*       Reset the Flash      
***************************************************************/
static void flashReset(void)
{
   *(volatile unsigned short*)BASE  = swap(0x00f0);
   
}
/***************************************************************
* void writeSequence(CMDSEQ cmd)
*  
*  Input:
*           CMDSEQ      command sequence
*  Output:
*     None:
*  Return:
*     None:
*  Descriptions:
*       Write a series commands to the flash  
* since the data bus on the EVM board is inverse to the normal data 
* bit 0 ->bit 15,bit 15->bit 0, so all the command should be changed by
* swap functin before write to the flash    
***************************************************************/
static void writeSequence(const CMDSEQ *cmd)
{
    volatile unsigned short  *addr;

    addr = (volatile unsigned short*)BASE;          // Point to base of chip memory
    while(cmd->adr) 
    {                                       // Do number required
        addr[cmd->adr] = swap(cmd->data);         // Write the command to address
        ++cmd;                              // Next command
    }                                       //   
   
}
/***************************************************************
* tvp_FERROR flashToggleErase
*  
*  Input:
*     None;
*  Output:
*     None:
*  Return:
*     TVP_FERROR        
*                          TVP_E_ERROR
*                          TVP_E_NONE     
*
*  Descriptions:
*       Toggle the erase operation      
***************************************************************/
static unsigned char flashToggleErase(void)
{
unsigned short poll1,poll2,tog;
int i = 0;      //counter to record how many tries.


   while(1)
   {
      poll1 = *(volatile unsigned short *)BASE;       //get the toggling
      poll2 = *(volatile unsigned short *)BASE;       //get the toggling

      tog = poll1 ^ poll2;
      
      //check the toggle bit
      if((tog & DQE) ==0)
      {
         if (*(volatile unsigned short *)BASE == 0xFFFF)  //double check the earsing
            return (0);
      }
      
      if (poll2 & DQ5)         //check time out
      {
         poll1 = *(volatile unsigned short *)BASE;     //reget the toggling
         poll2 = *(volatile unsigned short *)BASE;     //reget the toggling
      
         tog = poll1 ^ poll2;
         
         //check the toggle bit
         if((tog & DQE) == 0)
         {
            if (*(volatile unsigned short *)BASE == 0xFFFF)
               return (0);
         }
         else
         {
            flashReset();
            return   (0xFF);
         }
      }
      i++;
   }
}
/***************************************************************
* tvp_FERROR flashErase
*  
*  Input:
*     None;
*  Output:
*     None:
*  Return:
*     TVP_FERROR        
*                          0xFF
*                          0     
*
*  Descriptions:
*       Erase the whole FLASH Chip      
***************************************************************/
static unsigned char  flashErase(void)
{
    static const CMDSEQ cmd[] = 
    {
     {  0x555, 0xAA  },
     {  0x2AA, 0x55  },
     {  0x555, 0x80  },
     {  0x555, 0xAA  },
     {  0x2aa, 0x55  },
     {  0x555, 0x10, },
     {  0,0          }
   };
   printf("TVP9000 STARTS TO EARSE THE F L A S H at 0x%08X\n",BASE);
   flashReset();  
   writeSequence(cmd);
   if(flashToggleErase()) 
   {
       printf("\nTVP9000 FLASH ERASING ERROR\n");
       return 0xFF;
   }
   else
   {	   
       printf("\nTVP9000 FLASH ERASING SUCCESSFUL\n");
       return 0;                    // Successfully erased flash
   }
}                            
#if 0              
/***************************************************************
* int sectorEraseTogle(void)
*  
*  Input:
*     None;
*  Output:
*     None:
*  Return:
*             
*                          
*                          
*
*  Descriptions:
*       check the DR3 bit for the section erase     
***************************************************************/
static unsigned char sectorEraseToggle(void)
{
unsigned short sectorToggle;
   sectorToggle  = *(volatile unsigned short *)BASE;
   
   if (sectorToggle & DQ3)
      return 1;               //time out start
   else
      return 0;               //time out complete
}
/***************************************************************
* tvp_FERROR flashSectorErase
*  
*  Input:
*     None;
*  Output:
*     None:
*  Return:
*     unsigned char        
*                          0xFF
*                          0     
*
*  Descriptions:
*       Erase the whole FLASH Chip      
***************************************************************/
static unsigned char flashSectorErase(unsigned short sectionNum)
{
unsigned short offset;
   
   static const CMDSEQ cmd[] = 
   {
      {0x555,0xAA},
      {0x2AA,0x55},
      {0x555,0x80},
      {0x555,0xAA},
      {0x2AA,0x55},
      {0,0       }
   };

   if (sectionNum < 8)        //first 8 sectors are 4k word(2 bytes)
      offset = sectionNum * 0x1000;         
   else                       //rest sectors  are  32k word(2bytes)
      offset = 0x8000 + (sectionNum - 8) * 0x8000; 

   flashReset();
   writeSequence(cmd);
   *(volatile unsigned short *)(BASE + offset) = swap(0x0030);   //set the last command to clean the sector      
   if (flashToggleErase())
   {
      printf("\nTVP9000 FLASH SECTOR ERASING ERROR at 0x%08x\n",BASE+offset);
      return (0xFF);
   }
   printf("\nTVP9000 FLASH SECTOR ERASING DONE at 0x%08x\n",BASE+offset);
   return (0);
}
/***************************************************************
* void flashRead(offset,*buffer,size)
*  
*  Input:
*           offse:   offset with respect to the base addr      
*           buffer:  where to put the data(in the word units-2 bytes);
*           size:    how many to read
*  Output:
*     None:
*  Return:
*     none           
*                          
*                               
*
*  Descriptions:
*       return certain number data      
***************************************************************/
static void flashRead(unsigned short offset,unsigned short *buffer,unsigned long size)
{
   while(size > 0)

⌨️ 快捷键说明

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