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

📄 flash_49bv.c

📁 ARM入门的好帮手.包含了从简单到相对较复杂的程序.
💻 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_49BV.c//* Object                  : FLASH procedure//*//* 1.0 27/04/99 JPP        : Creation//*-----------------------------------------------------------------------------/* Include Standard c Libraries to allow stand alone compiling and operation */#include <stdio.h>#include "flash_49BV.h"#include "desc_flash_16x4.h"#include "global_def.h"//*----------------------------------------------------------------------------//* Function Name       : at91_init_flash_table//* Object              : indentify flash sector//* Input Parameters    : flash_word sector_id : sector id//* Output Parameters   : flash_word sector id or FLASH_SECTOR_ERROR//* Functions called    : none//*----------------------------------------------------------------------------void at91_init_flash_table ( FlashDef *FlashTable )//* Begin{    int cmpt;    //* init sector table    for ( cmpt = 0; cmpt < FlashTable->sector_nb ; cmpt ++ )    {        FlashTable->erase_sector[cmpt].sector=ERASED_SECTOR;    }//* End}//*----------------------------------------------------------------------------//* Function Name       : at91_check_erase_sector//* Object              : indentify flash sector//* Input Parameters    : flash_word sector_id : sector id//* Output Parameters   : flash_word sector id or FLASH_SECTOR_ERROR//* Functions called    : none//*----------------------------------------------------------------------------unsigned int at91_check_erase_sector ( FlashDef *FlashTable,flash_word sector_id)//* Begin{    return ( FlashTable->erase_sector[sector_id].sector);//* End}//*----------------------------------------------------------------------------//* Function Name       : at91_set_erase_sector//* Object              : set the sector errased//* Input Parameters    : flash_word sector_id : sector id//* Output Parameters   : flash_word sector id or FLASH_SECTOR_ERROR//* Functions called    : none//*----------------------------------------------------------------------------void at91_set_erase_sector ( FlashDef *FlashTable,flash_word sector_id)//* Begin{    FlashTable->erase_sector[sector_id].sector= UNERASED_SECTOR;//* End}//*----------------------------------------------------------------------------//* Function Name       : at91_get_flash_sector_size//* Object              : indentify flash sector//* Input Parameters    : flash_word *load_addr: Flash data address//* Output Parameters   : size for the sector//* Functions called    : none//*----------------------------------------------------------------------------flash_word  at91_get_flash_sector_size ( FlashDef *FlashTable, int sector){    flash_word  current_addr ;    int         sector_id;    int         block;    //* calculate the internal Flash address    current_addr =0;    sector_id = 0 ; block=0;    current_addr =  (FlashTable->org[block].sector_size);    //* determine the sector in the sector table    for (sector_id = 0 , block=0;         (sector_id < sector );         sector_id++)    {        //* Check if new block        if ( sector >= FlashTable->org[block].sector_number)        {            block ++ ;            sector = 0 ;        }        //* caculate the curent address        current_addr =  current_addr +(FlashTable->org[block].sector_size);    }    return ( current_addr) ;//* End}//*----------------------------------------------------------------------------//* Function Name       : at91_get_flash_sector//* Object              : indentify flash sector//* Input Parameters    : flash_word *load_addr : Flash data address//* Output Parameters   : flash_word sector id or FLASH_SECTOR_ERROR//* Functions called    : none//*----------------------------------------------------------------------------int at91_get_flash_sector ( FlashDef *FlashTable,flash_word load_addr, flash_word base_addr){    flash_word  current_addr ;    int         sector_id;    int         sector;    int         block;    //* calculate the internal Flash address    current_addr =((int)load_addr -(int)base_addr);    //* if current_addr is to low    if ( current_addr < 0)  return (FLASH_SECTOR_ERROR);    //* determine the sector in the sector table    for (sector_id = 0 , block=0,sector = 0;         (sector_id < (FlashTable->sector_nb)+1)&( current_addr >= 0 );         sector_id++,sector++)    {        //* Check if new block        if ( sector >= FlashTable->org[block].sector_number)        {            block ++ ;            sector = 0 ;        }        //* caculate the curent address        current_addr =  current_addr - (FlashTable->org[block].sector_size);    }    if ( sector_id > FlashTable->sector_nb)  return (FLASH_SECTOR_ERROR);     //* Return sector_id    sector_id-- ;    return ( sector_id) ;//* End}//*----------------------------------------------------------------------------//* Function Name       : printFlashInfo//* Object              : Format print info//* Input Parameters    : char * addresse of message, Len//* Output Parameters   ://* Functions called    : sprintf//*----------------------------------------------------------------------------void printFlashInfo ( char *message,int * len,FlashDef *FlashTable)//* Begin{    if (        (FlashTable->type !=0 )&&        (FlashTable->manufacturer != 0)       )    {        *len += sprintf(message+*len,"- Flash: %s, %d sectors \nStart address: 0x%08X  \nLoad address: 0x%08X\n",            FlashTable->name,            FlashTable->sector_nb,            FlashTable->add,            FlashTable->load_add            );        *len += sprintf(message+*len,"Type: 0x%04X, Manufactured: 0x%04X",            FlashTable->type,            FlashTable->manufacturer            );    }    else    {        *len += sprintf(message+*len,"- Flash :unknow\n");    }//* end}//* End of file

⌨️ 快捷键说明

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