📄 flash_menu.c
字号:
//*----------------------------------------------------------------------------
//* 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 : Flash tool
//* This project can be run on all EBxx Targes
//*
//* 1.0 01/11/00 JPP : Creation
//*----------------------------------------------------------------------------
//* --------------------------- include file ----------------------------------
#include <stdio.h>
//* Driver description
#include "drivers/com/com.h" //* Communication driver
#include "drivers/flash/lib_flash_at49.h"
//* --------------------------- Constant definition ---------------------------
//* ------------------------------ extern function --------------------------
extern int get_val( int val ,char * type);
extern int Get_Command(const char * menu);
//* ------------------------------ extern global data -----------------------
extern const FlashAt49BVDef FlashTable[NB_FLASH_SUPPORTED];
//* ------------------------------ Local variable ----------------------------
static const char flash_menu_msg[]=
{
"\n\r COMMAND MENU: flash\n\r"
" 0) Info\n\r"
" 1) Get global value\n\r"
" 2) Test Flash Erase\n\r"
" 3) Erase all sector\n\r"
" 4) Write Contant in all sector\n\r"
" 5) Erase all chip\n\r"
"Enter command to execute: "
};
extern char message[512];
extern ComDesc COM;
extern int base_address;
extern FlashAt49BVDef *flash;
//*----------------------------------------------------------------------------
//* Function Name : flash_menu
//* Object : flash tools
//* Input Parameters : None
//* Output Parameters : None
//*----------------------------------------------------------------------------
void flash_menu(void)
{
int command = 0;
int cmpt,sector,sector_nb;
u_int current_address;
flash_word data;
//init global data
while(command!=99)
{
command = Get_Command(flash_menu_msg);
switch(command)
{
case 1: /* Get global value */
//* work Base address
at91_print(&COM,"Get the base addres to write:");
base_address = get_val(base_address,"%08X");
//* Constant for write Flash
at91_print(&COM,"Get constant to write:");
data = get_val(data,"%04X");
//* Input data echo
case 0: //* print Info
sprintf(message,"Echo base flash address: 0x%08X const value 0x%04X \n\r",
base_address,data);
at91_print(&COM,message);
break;
case 2: //* Test Flash Erase
if ( flash !=0)
{ //* if is Flash
for (cmpt = 0 , sector_nb = 0 , current_address = base_address ;cmpt < flash->flash_block_nb ; cmpt++)
{
for (sector = 0 ;sector < flash->flash_org[cmpt].sector_number ; sector++,sector_nb++,current_address += flash->flash_org[cmpt].sector_size)
{
if ( flash_at49_check_sector_erased ((flash_word *)current_address,flash->flash_org[cmpt].sector_size))
{
sprintf(message,"sector %d OK",sector_nb);
}
else
{
sprintf(message,"sector %d NOK",sector_nb);
}
at91_print(&COM,message);
at91_print_crlf(&COM);
}
}
}
else
{ //* no Flash detect
at91_print(&COM,"Flash Unknow or RAM");
}
break;
case 3://* Erase all sector
if ( flash !=0)
{ //* if is Flash
for (cmpt = 0 , current_address = base_address ;cmpt < flash->flash_block_nb ; cmpt++)
{
for (sector = 0 ;sector < flash->flash_org[cmpt].sector_number ; sector++,current_address += flash->flash_org[cmpt].sector_size)
{
if (flash_at49_erase_sector ((flash_word *)base_address,(flash_word *)current_address))
{
at91_print(&COM,".");
}
else
{
at91_print(&COM,"ERROR");
}
}
}
}
else
{ //* no Flash detect
at91_print(&COM,"Flash Unknow or RAM");
}
at91_print_crlf(&COM);
break;
case 4: //* Write Contant in all sector
if ( flash !=0)
{ //* if is Flash
for (cmpt = 0 , sector_nb = 0 , current_address = base_address ;cmpt < ((flash->flash_size)/2) ; cmpt++, current_address+=2)
{
if ( flash_at49_write_flash ( (flash_word *)base_address,(flash_word *) current_address,(flash_word) data ))
{
sector++;
if ( (sector % 2048)==0) at91_print(&COM,"+");
}
else
{
at91_print(&COM,"Write ERROR !!!!\n\r");
cmpt =flash->flash_size;
}
}
}
else
{ //* no Flash detect
at91_print(&COM,"Flash Unknow or RAM");
}
break;
case 5: //* Erase all chip
if ( flash !=0)
{ //* if is Flash
if (flash_at49_erase_flash ( flash,(flash_word *)base_address ))
{
at91_print(&COM,"Flash esared\n\r");
}
else
{
at91_print(&COM,"Flash not esare !!!!\n\r");
}
}
else
{ //* no Flash detect
at91_print(&COM,"Flash Unknow or RAM");
}
break;
default: /* invalid command */
at91_print(&COM,"Invalid command entered. Please enter again!\n\r");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -