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

📄 flash.c

📁 Infineon公司有一款实现SHDSL协议(ADSL协议的变种)的芯片
💻 C
字号:
/*******************************************************************************
       Copyright (c) 2000, Infineon Technologies.  All rights reserved.
  
                               No Warranty                                                 
   Because the program is licensed free of charge, there is no warranty for 
   the program, to the extent permitted by applicable law.  Except when     
   otherwise stated in writing the copyright holders and/or other parties   
   provide the program "as is" without warranty of any kind, either         
   expressed or implied, including, but not limited to, the implied         
   warranties of merchantability and fitness for a particular purpose. The  
   entire risk as to the quality and performance of the program is with     
   you.  should the program prove defective, you assume the cost of all     
   necessary servicing, repair or correction.                               
                                                                            
   In no event unless required by applicable law or agreed to in writing    
   will any copyright holder, or any other party who may modify and/or      
   redistribute the program as permitted above, be liable to you for        
   damages, including any general, special, incidental or consequential     
   damages arising out of the use or inability to use the program           
   (including but not limited to loss of data or data being rendered        
   inaccurate or losses sustained by you or third parties or a failure of   
   the program to operate with any other programs), even if such holder or  
   other party has been advised of the possibility of such damages. 
 *******************************************************************************       
   
   Module:        FLASH
   Product ID:    22622.1.0.1
   Description:   Contains all subroutines for flash programming. 

 ******************************************************************************/
  
//  Group= FLASH 

/* ============================= */
/* Includes                      */
/* ============================= */

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

#include "sysdef.h"       
#include "dds.h"          
#include "sysvar.h"
#include "sysfunc.h"

#include "reg165.h"




/* ============================= */
/* Local Macros & Definitions    */
/* ============================= */


#define BLOCK_SIZE     0x4000
#define MAX_FILE_LEN   0x8000

                                       /* Addr. 555                           */
#define EEPROM_555     XVAR(WORD8, 0x0555+AOM_BASE+0x8000) 
 
                                       /* Addr. 2AA                          
                                         Watch up: different to data sheet    */
#define EEPROM_2AA     XVAR(WORD8, 0x02AA+AOM_BASE+0x8000)  

/* ============================= */
/* Local Variable Definitions    */
/* ============================= */


/* ============================= */
/* Local function definition     */
/* ============================= */

static void Flash_Erase (void);
static void Flash_Write_Byte (WORD32 address, WORD8 date);

/* ============================= */
/* Global function definition    */
/* ============================= */

/*******************************************************************************
Description:
   Download program code to Flash.
Arguments:
   start    -  Pointer to data part of binary file.
   length   -  Number of Bytes to be written.
Return:
   NONE.   
Remarks:
   Write binary file into flash. Start address must be from type xhuge
   to avoid boundary problems.
 ******************************************************************************/
void Flash_Download (WORD8 xhuge *start, WORD32 length)
{
   WORD32 i;
   
   FL_PGM_SET;
     
   if (length > MAX_FILE_LEN)
   {
      V24_PRINT(("\nWarning: max file length exceeded, skip end!"));
      length = MAX_FILE_LEN;
   }
 
   V24_PRINT(("\nErase flash"));
   Flash_Erase();

   V24_PRINT(("\nWrite flash: "));  
   for (i = 0;i < length; i++)
   {
      if ( i%2000 == 0 )     
         V24_PRINT(("*"));

      Flash_Write_Byte( FLASH_BUFFER_START+i, start[i] ); 
   }

   FL_PGM_CLEAR;
     
   V24_PRINT(("\nFlash programmed successfully\n"));
}

/*******************************************************************************
Description:
   Write byte into flash.
Arguments:
   address - Address to write in.
   data   - Data to be written.
Return:
   NONE.
Remarks:
   This function writes a data value to flash as long as the identical
   value is written out of the same address.
*******************************************************************************/
static void Flash_Write_Byte (WORD32 address, WORD8 date)
{ 
   WORD8 read_value;

                                       /* Write byte into flash till    
                                          written byte is identical     
                                          to read byte.                       */
   do
   {
      EEPROM_555 = 0x00AA;
      EEPROM_2AA = 0x0055;
      EEPROM_555 = 0x00A0;
      XVAR(WORD8, address) = date;
      do 
      {
         read_value = XVAR(WORD8, address);
      }
      while ((read_value & 0x80) != (date & 0x80));
   }
   while (read_value != date);
}


/*******************************************************************************
Description:
   Erase flash for device data.
Arguments:
   address  -  Start address for erase procedure.
   length   -  Defines how many byte shall be erased.
Return:
   NONE.
Remarks: 
   NONE.
*******************************************************************************/
static void Flash_Erase (void)
{
    EEPROM_555 = 0x00AA;
    EEPROM_2AA = 0x0055;
    EEPROM_555 = 0x0080;
    EEPROM_555 = 0x00AA;
    EEPROM_2AA = 0x0055;
    EEPROM_555 = 0x0010;
    while((XVAR(WORD8, FLASH_BUFFER_START) & 0x80) != 0x80);
}

⌨️ 快捷键说明

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