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

📄 flashgo_refdesign.c

📁 ti的数字电视芯片 tvp9000的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
   {
      *buffer++ = *(volatile unsigned short *)(BASE + offset);
      size--;
   }
   
}
#endif
/***************************************************************
* tvp_FERROR deviceId
*  
*  Input:
*     None;
*  Output:
*     None:
*  Return:
*     unsigned char        
*
*  Descriptions:
*       Get the Identification of FLASh      
***************************************************************/
static void getDeviceId(void)
{
    static const CMDSEQ cmd[] =
    {
       {  0x555,  0xAA   },
       {  0x2AA,  0x55   },
       {  0x555,  0x90   },
       {  0,0}
    };
    flashReset();
    writeSequence(cmd);                    // Write the command sequence
}
/***************************************************************
* void flashByPassReset()
*  
*  Input:
*     None;
*  Output:
*     None:
*  Return:
*     none           
*                          
*                               
*
*  Descriptions:
*       reset the flash to read mode from by pass mode      
***************************************************************/
static void flashByPassReset(void)
{
   *(volatile unsigned short *)BASE = swap(0x0090);
   *(volatile unsigned short *)BASE = swap(0x0000);
   
}

/***************************************************************
* tvp_FERROR flashToggle
*  
*  Input:
*     None;
*  Output:
*     None:
*  Return:
*     unsigned char        
*                          0xFF
*                          0     
*
*  Descriptions:
*       Toggle the flash program operation      
***************************************************************/
static unsigned char flashToggle(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 & DQ6) ==0)
      {
         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 & DQ6) == 0)
         {
            return (0);
         }
         else
         {
            flashByPassReset();
            return   (0xFF);
         }
      }
      i++;
      if( i > 0x5000)       //over the limits but still try
      {
         flashByPassReset();
         return (0xFF);
      }
   }
}

/***************************************************************
* void flashProgram()
*  
*  Input:
*           offse:   offset with respect to the base addr      
*           data :   source data address;
*           size:    how many to read (bytes )
*  Output:
*     None:
*  Return:
*     none           
*                          
*                               
*
*  Descriptions:
*       return certain number data with by pass program      
***************************************************************/
static unsigned char flashProgram(unsigned long offset,unsigned long dat,unsigned long length)
{
   static const CMDSEQ cmd[]=    //by pass program mode
   {
       {  0x555,  0xAA   },
       {  0x2AA,  0x55   },
       {  0x555,  0x20   },
       {  0,0 }
   };
   
   unsigned char        err;
   volatile unsigned short    *adr,*data;

   length = (length + 1)/2;                      //conver to short word type
   flashReset();                          // Start with chip reset.
   adr  = (volatile unsigned short *)(BASE + offset);         
   data = (volatile unsigned short *)dat;
   while(length--) 
   {                                       // Program flash words
      writeSequence(cmd);                 // Write the command sequence
      
      *(volatile unsigned short *)BASE = swap(0xA0);      
      *adr = *data;                       // Data to program it with

      err = flashToggle();                  // Wait for it to finish.
      if(err)                                //not completed!
         break;  
      flashByPassReset();
      if( *adr != *data)                //double check the written data
      {
         err= 0xFF;
         printf("\nERROR at ADDR 0x%8x Write %04x Read %04x\n",adr,*data,*adr);
         break;                   //
      }
      ++adr;
      ++data;
      if(((unsigned long)adr & 0xffff) == 0) 
      {
         printf(".");
         if(((unsigned long)adr & 0xfffff) == 0) 
         {
            printf("\n");
         }
      }
   }                                      //
   if(err) 
   {
      printf("\nTVP9000 FLASH FAILED at  0x%08X\n",adr);
   }

   return (err);   
}

/***************************************************************
* void main()
*  
*  Input:
*
*  Output:
*     None:
*  Return:
*     none           
*                          
*                               
*
*  Descriptions:
*             
***************************************************************/
void  main (void)
{
int i;
unsigned long totalSize = 0;
unsigned long offset = 0;
unsigned long chipSize=0;
unsigned char err;
unsigned char segment_length;
unsigned short data[3];   

   segment_length = 9;
   
	//disable the FIQ and IRQ
	*(volatile unsigned long *)0x2001c = 1;
	*(volatile unsigned long *)0x2003c = 1;
	//Reset all the hardware modules except MI and CCP:
	*(volatile unsigned long *)0x20820 = 0xFBF;
  
   /*enable the EBI0*/
   ebiset();
   //get the total size of the hex file  
   for (i=0;i<segment_length;i++)
      totalSize += size[i];
      
   
   getDeviceId();
   data[0]=swap(*(volatile unsigned short *)BASE);
   data[1]=swap(*((volatile unsigned short *)BASE + 0x1));
   data[2]=swap(*((volatile unsigned short *)BASE + 0xe));

   // Since TVP9000 EVM will use either 32Mb or 64Mb chip. The only ID difference of these two chips is on the second word       
   if (data[2] == 0x2210)
      chipSize = MEG4*2;      
   else if(data[2] == 0x221A)
      chipSize = MEG4;  
   
   
   printf("\nDetected %d MB chip\n",4*chipSize/MEG4);
  
   if(chipSize == 0)
   {
   	printf("\nDo not detect the Flash\n");
      while(1);   
   }

    if (chipSize < totalSize)
   {
      printf("\nThe flash is too small to hold the code.\n"); 
      while(1);      
   }	

   flashReset();
   err = flashErase();




   //Program the mon.c to the flash   
   if (!err)   
   {
      printf("\nT V P 9 0 0 0 P R O G R A M M I N G   F L A S H\n");
      for (i=0;i<segment_length;i++)
      {
         
         err = flashProgram(offset,mon_add[i],size[i]);      
         if (err)
         {
            printf("\nTVP9000 FLASH PROGRAMMING FAILED AT MON_%d\n",i);
            break;
         }
         else
            printf("\nTVP9000 FLASH PROGRAMMING SUCCESSFUL at MON_%d\n",i);

         offset += size[i]; 
      }
      printf("\nFLASH PRGORAMMING DONE!\n");
   }
   else
      printf("\nTVP9000 FLASH ERASE FAILED\n");   
   printf("\n");  
}

/***************************************************************
* void ebiset()
*  
*  Input:
*
*  Output:
*     None:
*  Return:
*     none           
*                          
*                               
*
*  Descriptions:
*             
***************************************************************/
static ebiset(void)
{
   volatile unsigned long *EBI = (volatile unsigned long *)0x10000; //ebi0 = cs 0
   EBI[0] = 0x040B0B30;   // pol low  w/16
   EBI[1] = 0x1F00010B; 
   EBI[2] = 0x0000000C; 
   EBI[3] = 0x010C020A; 
   EBI[4] = 0x0C0B0100;             

   //EBI 1 setting

   EBI[8] = 0x040B0B30;   // pol low  w/16
   EBI[9] = 0x1F00010B; 
   EBI[10] = 0x0000000C; 
   EBI[11] = 0x010C020A; 
   EBI[12] = 0x0C0B0100;             
}

⌨️ 快捷键说明

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