flash_lib.c File Reference

#include "config.h"
#include "flash.h"
#include "flash_lib.h"

Include dependency graph for flash_lib.c:

Go to the source code of this file.

Defines

#define Enable_flash()
#define Disable_flash()

Functions

Bool flash_lib_check (void)
 This function checks the presence of bootloader.
void flash_wr_byte (Uint32 addr_byte, Uchar value)
 This function allows to write a byte in the flash memory.
Uchar flash_wr_block (Byte _MemType_ *src, Uint32 dst, U16 n)
 This function allows to write up to 65535 bytes in the flash memory.
U8 flash_rd_byte (U8 farcode *addr)
 This function allows to read a byte in the flash memory.
U16 flash_rd_word (U16 farcode *addr)
 This function allows to read a word in the flash memory.

Variables

void(* boot_flash_page_erase_and_write )(unsigned long adr) = (void (*)(unsigned long))( (((FLASH_END+1)/2)-2) -12)
U8(* boot_flash_read_sig )(unsigned long adr) = (U8 (*)(unsigned long))( (((FLASH_END+1)/2)-2) -10)
U8(* boot_flash_read_fuse )(unsigned long adr) = (U8 (*)(unsigned long))( (((FLASH_END+1)/2)-2) -8)
void(* boot_flash_fill_temp_buffer )(unsigned int data, unsigned int adr) = (void (*)(unsigned int, unsigned int))( (((FLASH_END+1)/2)-2) -6)
void(* boot_flash_prg_page )(unsigned long adr) = (void (*)(unsigned long))( (((FLASH_END+1)/2)-2) -4)
void(* boot_flash_page_erase )(unsigned long adr) = (void (*)(unsigned long))( (((FLASH_END+1)/2)-2) -2)
void(* boot_lock_wr_bits )(unsigned char val) = (void (*)(unsigned char))( (((FLASH_END+1)/2)-2) )


Detailed Description

This file contains a set of routines to perform flash access.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file flash_lib.c.


Define Documentation

 
#define Enable_flash (  ) 

Definition at line 51 of file flash_lib.c.

Referenced by flash_rd_byte(), flash_rd_word(), and flash_wr_byte().

 
#define Disable_flash (  ) 

Definition at line 52 of file flash_lib.c.

Referenced by flash_rd_byte(), flash_rd_word(), and flash_wr_byte().


Function Documentation

Bool flash_lib_check ( void   ) 

This function checks the presence of bootloader.

Returns:
FALSE, if no code loaded in bootloader area

Definition at line 72 of file flash_lib.c.

Referenced by firm_upgrade_run().

00073 {
00074    return (*((code U16*)((U32)boot_flash_page_erase_and_write*2)) != 0xFFFF);
00075 }

Here is the caller graph for this function:

void flash_wr_byte ( Uint32  addr_byte,
Uchar  value 
)

This function allows to write a byte in the flash memory.

Parameters:
addr_byte Address in flash memory to write the byte.
value Value to write in the flash memory

Definition at line 83 of file flash_lib.c.

00084 {
00085    Enable_flash();
00086    flash_wr_block(&value, addr_byte, 1);
00087    Disable_flash();
00088 }

Uchar flash_wr_block ( Byte _MemType_ *  src,
Uint32  dst,
U16  n 
)

This function allows to write up to 65535 bytes in the flash memory.

This function manages alignement issue.

Parameters:
src Address of data to write.
dst Start address in flash memory where write data
n number of byte to write

Definition at line 98 of file flash_lib.c.

Referenced by firm_upgrade_run(), and flash_wr_byte().

00099 {
00100    U16 nb_word, temp16;
00101    U32 address;
00102    U32 save_page_adr;
00103    U8 page_is_blank;
00104 
00105    while(n)                                     // While there is data to load from src buffer
00106    {
00107       page_is_blank=TRUE;
00108       address=dst-(LOW(dst)%FLASH_PAGE_SIZE);   // Compute the start of the page to be modified
00109       save_page_adr=address;                    // Memorize page addr
00110 
00111       // For each word in this page
00112       for(nb_word=0;nb_word<FLASH_PAGE_SIZE/2;nb_word++)
00113       {
00114          if(n)                                  // Still some data to load from src
00115          {
00116             if(address>=dst)                    // Current address is inside the target range adr
00117             {
00118                MSB(temp16)=(*(U8*)src);         // Load MSB of word from buffer src
00119                src++; n--;
00120                if(n)                            // Still some data to load ?
00121                {
00122                   LSB(temp16)=(*(U8*)src);      // Load LSB of word from buffer src
00123                   src++; n--;
00124                }
00125                else                             // Only the MSB of the working belong to src buffer
00126                {                                // Load LSB form exisying flash
00127                   LSB(temp16)=flash_rd_byte((U8 farcode*)address+1);
00128                }
00129             }
00130             else                                // Current word addr out of dst target
00131             {                                   // Load MSB from existing flash
00132                MSB(temp16)=flash_rd_byte((U8 farcode*)address);
00133                if(address+1==dst)               // Is LSB word addr in dst range ?
00134                {
00135                   LSB(temp16)=(*(U8*)src);
00136                   src++; n--;
00137                }
00138                else                             // LSB read from existing flash
00139                {
00140                   LSB(temp16)=flash_rd_byte((U8 farcode*)address+1);
00141                }
00142             }
00143          }
00144          else                                   // Complete page with words from existing flash
00145          {
00146             temp16=flash_rd_word((U16 farcode*)address);
00147          }
00148          //Load temp buffer
00149          (*boot_flash_fill_temp_buffer)(temp16,address);
00150          address+=2;
00151       }
00152       address=save_page_adr;
00153       for(nb_word=0;nb_word<FLASH_PAGE_SIZE/2;nb_word++)
00154       {
00155          if(flash_rd_word((U16 farcode*)address)!=0xFFFF)   // Check for Blank page
00156          {
00157             page_is_blank=FALSE;
00158             break;
00159          }
00160          address+=2;
00161       }
00162       // Now launch prog sequence (with or without page erase)
00163       address=save_page_adr;
00164       if(page_is_blank)  { (*boot_flash_prg_page)(save_page_adr); }
00165       else{(*boot_flash_page_erase_and_write)(save_page_adr);}
00166       //- First Flash address update for the next page
00167       address = save_page_adr + FLASH_PAGE_SIZE;
00168    }
00169    return TRUE;
00170 }

Here is the caller graph for this function:

U8 flash_rd_byte ( U8 farcode *  addr  ) 

This function allows to read a byte in the flash memory.

Parameters:
*add Address of flash memory to read.
Returns:
byte Read value

Definition at line 178 of file flash_lib.c.

Referenced by firm_upgrade_run(), flash_rd_word(), and flash_wr_block().

00179 {
00180    unsigned char temp;
00181    Enable_flash();
00182    temp = *addr;
00183    Disable_flash();
00184    return temp;
00185 }

Here is the caller graph for this function:

U16 flash_rd_word ( U16 farcode *  addr  ) 

This function allows to read a word in the flash memory.

Parameters:
*add Address of flash memory to read.
Returns:
word Read value

Definition at line 193 of file flash_lib.c.

Referenced by flash_wr_block().

00194 {
00195    Union16 temp;
00196    Enable_flash();
00197    temp.b[1] = flash_rd_byte ((Uchar farcode*) addr);
00198    temp.b[0] = flash_rd_byte ((Uchar farcode*)addr+1);
00199    Disable_flash();
00200    return temp.w;
00201 }

Here is the caller graph for this function:


Variable Documentation

void(* boot_flash_page_erase_and_write)(unsigned long adr) = (void (*)(unsigned long))( (((FLASH_END+1)/2)-2) -12)

Definition at line 56 of file flash_lib.c.

Referenced by flash_lib_check().

U8(* boot_flash_read_sig)(unsigned long adr) = (U8 (*)(unsigned long))( (((FLASH_END+1)/2)-2) -10)

Definition at line 57 of file flash_lib.c.

U8(* boot_flash_read_fuse)(unsigned long adr) = (U8 (*)(unsigned long))( (((FLASH_END+1)/2)-2) -8)

Definition at line 58 of file flash_lib.c.

void(* boot_flash_fill_temp_buffer)(unsigned int data, unsigned int adr) = (void (*)(unsigned int, unsigned int))( (((FLASH_END+1)/2)-2) -6)

Definition at line 59 of file flash_lib.c.

void(* boot_flash_prg_page)(unsigned long adr) = (void (*)(unsigned long))( (((FLASH_END+1)/2)-2) -4)

Definition at line 60 of file flash_lib.c.

void(* boot_flash_page_erase)(unsigned long adr) = (void (*)(unsigned long))( (((FLASH_END+1)/2)-2) -2)

Definition at line 61 of file flash_lib.c.

void(* boot_lock_wr_bits)(unsigned char val) = (void (*)(unsigned char))( (((FLASH_END+1)/2)-2) )

Definition at line 62 of file flash_lib.c.


Generated on Fri May 15 15:41:41 2009 for ATMEL by  doxygen 1.5.3