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

📄 main.c

📁 flashdownloader, 利用此程序可以对AMD flash 进行编程操作
💻 C
字号:
/*
** Copyright (C) ARM Limited, 2000. All rights reserved.
*/

/*
** This application flashes the LEDs on the ARM Integrator board.
** It reads the board's switches to determine the flash speed and pattern.
*/


#include <stdio.h>
#include "stand_i.h"

/* #include "rpsarmul.h" */ /* EITHER: to use with the ARMulator */
#include "intgrt.h"         /* OR: to use with the Integrator board */

#include "lld.h"
#include "lld_hal.h"

int IntCT1;
int IntCT2;

char switch_val  = 17,  // Set out of range to ensure values
     cur_sw_val  = 0,   // are different at program start.
     sequence    = 0, 
     seq_init    = 0,
     count       = 0,
     flash_speed = 0, 
     toggle      = 0;


int  Read_Switch(void);
void Led_Write(char val);
void Init_Timers(void);
void Set_Timers(char time);

extern int lld_BytesPerOpInitFromDataCfg
(
int *bytes_per_op,    /* width of each write/read operation */
PARAM data_cfg,       /* data config (data width, # of devices) */
PARAM *err_code_ptr,  /* variable in which to store error code */
char *err_buf         /* buffer to store textual error info */
);

extern int lld_ResetCmd
(
ADDRESS base_addr,                       /* device base address in system */
ADDRESS offset,                          /* address offset from base address */
PARAM data_cfg,                          /* flash data width and # of devices */
PARAM *err_code_ptr,                     /* variable to store error code */
char *err_buf                            /* buffer to store error text */
);

extern int lld_SecErsOp
(
ADDRESS base_addr,    /* device base address is system */
ADDRESS offset,       /* address offset from base address */
PARAM data_cfg,       /* data config (data width, # of devices) */
PARAM *err_code_ptr,  /* variable in which to store error code */
char *err_buf         /* buffer to store textual error info */
);

extern int lld_PgmOp
(
ADDRESS base_addr,      /* device base address is system */
ADDRESS offset,         /* address offset from base address */
PARAM data_cfg,         /* data config (data width, # of devices) */
FLASHDATA write_data,   /* variable containing data to program */
PARAM *err_code_ptr,    /* variable in which to store error code */
char *err_buf           /* buffer to store textual error info */
);

extern int HalWrite
 (
 ADDRESS   sys_addr,     /* system level flash BYTE address */
 FLASHDATA source,       /* data to write */
 PARAM*    err_code_ptr, /* variable in which to store error code */
 char*     err_buf       /* buffer to store textual error info */
 );


extern int HalRead
 (
 ADDRESS    sys_addr,     /* system level flash BYTE address */
 FLASHDATA* target,       /* variable in which to store read data */
 PARAM*     err_code_ptr, /* variable in which to store error code */
 char*      err_buf       /* buffer to store textual error info */
 );
 
#define H_EBUF_SIZE     (256)  /* Error Buffer Size */
#define RBUF          (256)

#define BINFILERAMADDR 0xc0100000
#define BINFILESIZE    0x00010000


#define BLOB_SDRAM_ADDR    0xc0100000
#define PARAM_SDRAM_ADDR   0xc0110000
//#define KERNEL_SDRAM_ADDR  0xc0114000
#define KERNEL_SDRAM_ADDR  0xc0200000
#define RAMDISK_SDRAM_ADDR 0xc0400000

#define BLOB_FLASH_ADDR    0xc8000000
#define PARAM_FLASH_ADDR   0xc8010000
//#define KERNEL_FLASH_ADDR  0xc8014000
#define KERNEL_FLASH_ADDR  0xc8100000
//#define RAMDISK_FLASH_ADDR 0xc8200000
#define RAMDISK_FLASH_ADDR 0xc8300000

#define BLOB_FLASH_SIZE    0x00010000
#define PARAM_FLASH_SIZE   0x00004000
//#define KERNEL_FLASH_SIZE  0x001EC000
#define KERNEL_FLASH_SIZE  0x00200000
#define RAMDISK_FLASH_SIZE 0x00800000


int BLOB_Prog(void);
int PARAM_Prog(void);
int KERNEL_Prog(void);
int RAMDISK_Prog(void);
 
#define FLASH_DATA_CFG   X16_AS_X32
#define FLASH_BASE_ADDR  0xc8000000

int main(void)
{
  #pragma import(__use_no_semihosting_swi)   // ensure no functions that use semihosting
                                             // SWIs are linked in from the C library
   
    char            err_buf[H_EBUF_SIZE];
    PARAM           err_code;
    long            result;
    //FLASHDATA       data;
    int             addr_shift;   
    //int i;
    //FLASHDATA *p_data;
    hal_BusWidthInit(4);
    
    *(volatile unsigned short *)0xcc800000 = 0xC000;
    
    lld_BytesPerOpInitFromDataCfg(&addr_shift, FLASH_DATA_CFG, &err_code, err_buf);
    
    /*    Reset device to place into Read Mode */
    
    fprintf(stdout, "\nReset\n");   
    lld_ResetCmd(FLASH_BASE_ADDR, 0, FLASH_DATA_CFG, &err_code, err_buf);
    
    
    fprintf(stdout, "\nSectErsOp Sect.0\n");  
    lld_SecErsOp(FLASH_BASE_ADDR, 0, FLASH_DATA_CFG, &err_code, err_buf);
    
    fprintf(stdout, "\nSectErsOp Sect.1\n");  
    lld_SecErsOp(FLASH_BASE_ADDR, 0x4000, FLASH_DATA_CFG, &err_code, err_buf);
    
    fprintf(stdout, "\nSectErsOp Sect.2\n");  
    lld_SecErsOp(FLASH_BASE_ADDR, 0x8000, FLASH_DATA_CFG, &err_code, err_buf);
    
    fprintf(stdout, "\nSectErsOp Sect.3\n");  
    lld_SecErsOp(FLASH_BASE_ADDR, 0xc000, FLASH_DATA_CFG, &err_code, err_buf);
    
    /*fprintf(stdout, "\nChipErsOp \n");  
    lld_ChipErsOp(FLASH_BASE_ADDR, 0x00000, FLASH_DATA_CFG, &err_code, err_buf);
    */
       
    BLOB_Prog();
    //PARAM_Prog();
    //KERNEL_Prog();
    //RAMDISK_Prog();
    
    /*
    i=0;
    p_data = (FLASHDATA *)BINFILERAMADDR;
    while(i<BINFILESIZE)
    {
    
    	lld_PgmOp(base_addr, i, data_cfg, *p_data, &err_code, err_buf);
    	
    	i+=4;
    	p_data += 1;
    }*/	

    while(1);
 }
 
int BLOB_Prog()
{
	char            err_buf[H_EBUF_SIZE];
    PARAM           err_code;
   
    int i;
    FLASHDATA *p_data;
    
    fprintf(stdout, "\nBLOB Program Start...\n");
    i=0;
    p_data = (FLASHDATA *)BLOB_SDRAM_ADDR;
    while(i<BLOB_FLASH_SIZE)
    {
    
    	lld_PgmOp(BLOB_FLASH_ADDR , i, FLASH_DATA_CFG, *p_data, &err_code, err_buf);    	
    	i+=4;
    	p_data += 1;
    }	

    fprintf(stdout, "\nBLOB Program Over!\n");
}

int PARAM_Prog(void)
{
    char            err_buf[H_EBUF_SIZE];
    PARAM           err_code;
   
    int i;
    FLASHDATA *p_data;
    
    fprintf(stdout, "\nPARAM Program Start...\n");
    i=0;
    p_data = (FLASHDATA *)PARAM_SDRAM_ADDR;
    while(i<PARAM_FLASH_SIZE)
    {
    
    	lld_PgmOp(PARAM_FLASH_ADDR , i, FLASH_DATA_CFG, *p_data, &err_code, err_buf);    	
    	i+=4;
    	p_data += 1;
    }	

    fprintf(stdout, "\nPARAM Program Over!\n");
}
   
   
int KERNEL_Prog(void)
{
    char            err_buf[H_EBUF_SIZE];
    PARAM           err_code;
   
    int i;
    FLASHDATA *p_data;
    
    fprintf(stdout, "\nKERNEL Program Start...\n");
    i=0;
    p_data = (FLASHDATA *)KERNEL_SDRAM_ADDR;
    while(i<KERNEL_FLASH_SIZE)
    {
    
    	lld_PgmOp(KERNEL_FLASH_ADDR , i, FLASH_DATA_CFG, *p_data, &err_code, err_buf);    	
    	i+=4;
    	p_data += 1;
    }	

    fprintf(stdout, "\nKERNEL Program Over!\n");
}    
    
int RAMDISK_Prog(void)
{
    char            err_buf[H_EBUF_SIZE];
    PARAM           err_code;
   
    int i;
    FLASHDATA *p_data;
    
    fprintf(stdout, "\nRAMDISK Program Start...\n");
    i=0;
    p_data = (FLASHDATA *)RAMDISK_SDRAM_ADDR;
    while(i<RAMDISK_FLASH_SIZE)
    {
    
    	lld_PgmOp(RAMDISK_FLASH_ADDR , i, FLASH_DATA_CFG, *p_data, &err_code, err_buf);    	
    	i+=4;
    	p_data += 1;
    }	

    fprintf(stdout, "\nRAMDISK Program Over!\n");
}    
/**************************************************************************
* Read_Switch                                                             *
* This function reads the current switch setting.                         *
* The 2 least significant bits control the sequence speed, the upper 2    *
* bits control the sequence type. This module returns the full switch     *
* value.                                                                  *
**************************************************************************/
int Read_Switch(void)
{
  char switch_val;
  switch_val = (*LED_SWITCHES & 0x0F);
  return switch_val;
}


/**************************************************************************
* Led_Write                                                               *
* This function writes the current sequence to the LEDs                   *
**************************************************************************/
void Led_Write(char val)
{
  while (*LED_ALPHA & LED_IDLE)  // Wait until the LEDs are 
    ;                            // ready to be written to
  *LED_LIGHTS = val;
}


/**************************************************************************
* Init_Timers                                                             *
* Initializes the Interrupt and sets the counter timers to zero, also     *
* ensures that the Interrupts from the timers are fully reset.            *
**************************************************************************/
void Init_Timers(void)
{
  // Disable all interrupts
  *IRQEnableClear = ~0;

  // Disable counters by clearing the control bytes
  *Timer1Control = 0;
  *Timer2Control = 0;

  // Clear counter/timer interrupts by writing to the clear register
  *Timer1Clear = 0 ; // any data will work
  *Timer2Clear = 0 ; // any data will work
}


/**************************************************************************
* Set_Timers                                                              *
* This module controls the setting up and loading of the counter timers   *
* with the required time to set the sequence speed - a value of 0 - 3 is  *
* passed into the routine which decides the load value of the two timers. *
* The timer controls and interrupts are set on exit.                      *
***************************************************************************/
void Set_Timers(char time)
{
  // Select load time from input value 
  switch (time)
  {
    case SLOW:
      *Timer1Load = SLOW_LOAD;
      *Timer2Load = SLOW_LOAD;
      break;

    case SLOW_MED:
      *Timer1Load = SLOW_MED_LOAD;
      *Timer2Load = SLOW_MED_LOAD;
      break;

    case MED_FAST:
      *Timer1Load = MED_FAST_LOAD;
      *Timer2Load = MED_FAST_LOAD;
      break;

    case FAST:
      *Timer1Load = FAST_LOAD;
      *Timer2Load = FAST_LOAD;
      break;
  }

  // Set Up the Counter Timers Control Registers
  *Timer1Control = (TimerEnable   |   // Enable the Timer   
                    TimerPeriodic |   // Periodic Timer producing interrupt
                    TimerPrescale8 ); // Set Maximum Prescale - 8  bits    

  *Timer2Control = (TimerEnable   |   // Enable the Timer                  
                    TimerPeriodic |   // Periodic Timer producing interrupt
                    TimerPrescale8 ); // Set Maximum Prescale - 8  bits    

  // Now initialize the System Interrupts and Enable the Timer 1 Interrupt
  *IRQEnableClear = ~0;       // Clear all interrupts
  IntCT1 = 0;                 // Clear CT 1 Flag     
  IntCT2 = 0;                 // Clear CT 2 Flag     

  *IRQEnableSet = IRQTimer1 | IRQTimer2; 
  // Enable the counter timer interrupts
}

⌨️ 快捷键说明

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