flash_menu.c

来自「使用JTAG口对AT91R40008芯片进行FLASH编程的程序」· C语言 代码 · 共 210 行

C
210
字号
//*----------------------------------------------------------------------------
//*      ATMEL Microcontroller Software Support  -  ROUSSET  -
//*----------------------------------------------------------------------------
//* The software is delivered "AS IS" without warranty or condition of any
//* kind, either express, implied or statutory. This includes without
//* limitation any warranty or condition with respect to merchantability or
//* fitness for any particular purpose, or against the infringements of
//* intellectual property rights of others.
//*----------------------------------------------------------------------------
//* File Name           : flash_menu.c
//* Object              : Load Flash for EB40a with Flash :
//*                             AT49BV1604
//*                             AT49BV8011/AT49BV8011T
//*                       This project can be run on all EB40a Targets with MEC
//*
//* 1.0 05/01/01 JPP    : Creation
//* 1.1 29/05/01 JPP    : Get the Chip select value
//* 1.2 30/05/01 JPP    : Change CD for Main Clock and Change Usart descriptor
//*----------------------------------------------------------------------------

//* --------------------------- include file ----------------------------------

#include <string.h>
#include    "parts/r40008/lib_r40008.h"
#include    "targets/eb40a/eb40a.h"
#include    "parts/r40008/reg_r40008.h"

#include "periph/aic/lib_aic.h"
#include "lib_flash_at49.h"
#include "at24c512.h"

#include "xmodem.h"
#include "../global.h"

extern char addr_msg[];
extern int Get_Value(const char * menu);

//* --------------------------- Constant definition ---------------------------


#define EBI_BA              0xFFF00000

#define CHIP_SELECT 3

#define FLASH_BEGIN_DATA	0x080000  		//* 256 short for PGM

static const char Flash_menu_msg[]=
{
"\n\r  COMMAND MENU: Xmodem\n\r"
" 0) Info 1) Transmit 2) transmit block 3)Receive 4) Recivied write only \n\r"

"Enter command to execute: "
};

//* ------------------------------  Local variable ----------------------------
/* External Interrupt Sources Descriptor */

ComDesc         *Xmodem_COM;

extern FlashAt49BVDef FlashTable[];
flash_word 		*FlashBaseAddress;
unsigned int    flash_size=0x200000;   //* set to 2 Mbyte
FlashAt49BVDef  *flash_type =0;
flash_word 	    type;
//* Begin

//*----------------------------------------------------------------------------
//* Function Name       : print_result
//* Object              : Print xmodem Result
//* Input Parameters    : Status
//* Output Parameters   : none
//*----------------------------------------------------------------------------
void print_result(int status)
//* Begin
{
    if (status==FALSE)
        at91_print(&COM0,"\n\rError\n\r");
    else
        at91_print(&COM0,"\n\rOK\n\r");
//* End
}
//*----------------------------------------------------------------------------
//* Function Name       : print_falsh
//* Object              : Print FLASH
//* Input Parameters    : Status
//* Output Parameters   : none
//*----------------------------------------------------------------------------
void print_falsh(void)
{
				at91_print(&COM0,"FLASH\n\r");
}
//*----------------------------------------------------------------------------
//* Function Name       : print_status
//* Object              : Print xmodem status
//* Input Parameters    : Status
//* Output Parameters   : none
//*----------------------------------------------------------------------------
void print_status(void)
{
int cmpt;
		print_falsh();
		sprintf(message,"Works base address 0x%08X\n\r",(u_int)FlashBaseAddress);
		at91_print(&COM0,message);
		sprintf(message,"Flash size 0x%08X (%d Kbyte)\n\r",flash_size,flash_size/1024);
		at91_print(&COM0,message);
		sprintf(message,"Flash type 0x%04X\n\r",type);
		at91_print(&COM0,message);

   	for (cmpt=0 ; cmpt < 8 ;cmpt ++)
    {
		sprintf(message,"EBI_CSR%d = 0x%08X\n\r", cmpt,EBI_BASE->EBI_CSR[cmpt]);
		at91_print(&COM0,message);
	}
}
//*----------------------------------------------------------------------------
//* Function Name       : flash_menu
//* Object              : Main function of Polling USART 0
//* Input Parameters    : none
//* Output Parameters   : True
//*----------------------------------------------------------------------------
void flash_menu( void )
//* Begin
{
    int 			cmpt;
	u_int addr;
    //* Set the Xmodem transaction on USART COM
    Xmodem_COM = &COM0;
	FlashBaseAddress = (flash_word *)(EBI_BASE->EBI_CSR[0]&EBI_BA);

	// check flash
    type = flash_at49_identify( FlashBaseAddress);

    for (cmpt=0 ; cmpt < NB_FLASH_SUPPORTED ; cmpt ++)
    {
        if ( type == FlashTable[cmpt].flash_id )
        {
            at91_print(&COM0,FlashTable[cmpt].flash_name);
            flash_size = FlashTable[cmpt].flash_size;
            flash_type = &FlashTable[cmpt];
        }
    }
	print_status();

    while(command!=99)
  	{
        command = Get_Command(Flash_menu_msg);
    	switch (command)
    	{
        case 0:
        	print_status();
		break;

		case 1:
            at91_print(&COM0,"Wait 'C'\n\r");
				print_falsh();
				print_result( xmodem_transmit((u_char *)FlashBaseAddress,(flash_size-FLASH_BEGIN_DATA)));
        break;

		case 2:
            at91_print(&COM0,"Wait 'C'\n\r");
				print_falsh();
				at91_print(&COM0,"address\n\r");
				addr = Get_Value(addr_msg);
				FlashBaseAddress =  (flash_word *) addr;
				at91_print(&COM0,"Size\n\r");
				addr = Get_Value(addr_msg);
				print_result( xmodem_transmit((u_char *)FlashBaseAddress,addr));
        break;

        case 3:
            if (flash_type != 0)
            {
                at91_print(&COM0,"Send 'C'\n\r");
				print_falsh();
              	flash_at49_init_write( (flash_word *)(EBI_BASE->EBI_CSR[0]&EBI_BA),	FlashBaseAddress,  flash_type);
                print_result ( xmodem_receive(&flash_at49_erase_write_block));
            }
            else
            {
                at91_print(&COM0,"Flash not available !\n\r");
            }
        break;

        case 4:
            if (flash_type != 0)
            {
                at91_print(&COM0,"Send 'C'\n\r");
				print_falsh();
				addr = Get_Value(addr_msg);
				FlashBaseAddress =  (flash_word *) addr;
              	flash_at49_init_write( (flash_word *)(EBI_BASE->EBI_CSR[0]&EBI_BA),	FlashBaseAddress,  flash_type);
                print_result ( xmodem_receive(&flash_at49_write_block));
            }
            else
            {
                at91_print(&COM0,"Flash not available !\n\r");
            }
        break;

		default:
			 print_default();
        break;

        }//* End switch
    }//* End for
    if (cmpt ==1) command= 0;

//* End
}

⌨️ 快捷键说明

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