Functions | Variables

flash_lib.c File Reference

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

#include "config.h"
#include "flash_lib.h"
#include "flash_drv.h"
Include dependency graph for flash_lib.c:

Go to the source code of this file.

Functions

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))(LAST_BOOT_ENTRY-12)
U8(* boot_flash_read_sig )(unsigned long adr) = (U8 (*)(unsigned long))(LAST_BOOT_ENTRY-10)
U8(* boot_flash_read_fuse )(unsigned long adr) = (U8 (*)(unsigned long))(LAST_BOOT_ENTRY-8)
void(* boot_flash_fill_temp_buffer )(unsigned int data, unsigned int adr) = (void (*)(unsigned int, unsigned int))(LAST_BOOT_ENTRY-6)
void(* boot_flash_prg_page )(unsigned long adr) = (void (*)(unsigned long))(LAST_BOOT_ENTRY-4)
void(* boot_flash_page_erase )(unsigned long adr) = (void (*)(unsigned long))(LAST_BOOT_ENTRY-2)
void(* boot_lock_wr_bits )(unsigned char val) = (void (*)(unsigned char))(LAST_BOOT_ENTRY)

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.


Function Documentation

void flash_wr_byte ( Uint32  addr_byte,
Uchar  value 
)

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

Parameters:
addr_byteAddress in flash memory to write the byte.
valueValue to write in the flash memory

Definition at line 75 of file flash_lib.c.

References flash_wr_block().

{
  Enable_flash();
  flash_wr_block(&value, addr_byte, 1);
  Disable_flash();
}

Here is the call graph for this function:

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:
*srcAddress of data to write.
dstStart address in flash memory where write data
nnumber of byte to write

Definition at line 92 of file flash_lib.c.

References FALSE, flash_rd_byte(), flash_rd_word(), LOW, LSB, MSB, and TRUE.

{
   U16 nb_word, temp16;
   U32 address;
   U32 save_page_adr;
   U8 page_is_blank;

   while(n)  // While there is data to load from src buffer
   {
      page_is_blank=TRUE;
      address=dst-(LOW(dst)%FLASH_PAGE_SIZE); // Compute the start of the page to be modified
      save_page_adr=address; //memorize page addr

      // For each word in this page
      for(nb_word=0;nb_word<FLASH_PAGE_SIZE/2;nb_word++)
      {
         if(n) //Still some data to load from src
         {
            if(address>=dst) //current address is inside the target range adr
            {
               MSB(temp16)=(*(U8*)src); //load MSB of word from buffer src
               src++; n--;
               if(n) //Still some data to load ?
               {
                  LSB(temp16)=(*(U8*)src); //load LSB of word from buffer src
                  src++; n--;
               }
               else  //only the MSB of the working belong to src buffer
               {     //load LSB form exisying flash
                  LSB(temp16)=flash_rd_byte((U8 farcode*)address+1);
               }
            }
            else  //current word addr out of dst target
            {     //load MSB from existing flash
               MSB(temp16)=flash_rd_byte((U8 farcode*)address);
               if(address+1==dst) // Is LSB word addr in dst range ?
               {
                  LSB(temp16)=(*(U8*)src);
                  src++; n--;
               }
               else // LSB read from existing flash
               {
                  LSB(temp16)=flash_rd_byte((U8 farcode*)address+1);
               }
            }
         }
         else  //complete page with words from existing flash
         {
            temp16=flash_rd_word((U16 farcode*)address);
         }
         //Load temp buffer
         (*boot_flash_fill_temp_buffer)(temp16,address);
         address+=2;
      }
      address=save_page_adr;
      for(nb_word=0;nb_word<FLASH_PAGE_SIZE/2;nb_word++)
      {
         if(flash_rd_word((U16 farcode*)address)!=0xFFFF) //Check for Blank page
         {
            page_is_blank=FALSE;
            break;
         }
         address+=2;
      }
      // Now launch prog sequence (with or without page erase)
      address=save_page_adr;
      if(page_is_blank)  { (*boot_flash_prg_page)(save_page_adr); }
      else{(*boot_flash_page_erase_and_write)(save_page_adr);}
      //- First Flash address update for the next page
      address = save_page_adr + FLASH_PAGE_SIZE;
   }
   return TRUE;
}

Here is the call graph for this function:

U8 flash_rd_byte ( U8 farcode *  addr )

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

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

Definition at line 174 of file flash_lib.c.

{
  unsigned char temp;
  Enable_flash();
  temp = *addr;
  Disable_flash();
  return temp;
}
U16 flash_rd_word ( U16 farcode *  addr )

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

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

Definition at line 190 of file flash_lib.c.

References Union16::b, flash_rd_byte(), and Union16::w.

{
  Union16 temp;
  Enable_flash();
  temp.b[1] = flash_rd_byte ((Uchar farcode*) addr);
  temp.b[0] = flash_rd_byte ((Uchar farcode*)addr+1);
  Disable_flash();
  return temp.w;
}

Here is the call graph for this function:


Variable Documentation

void(* boot_flash_page_erase_and_write)(unsigned long adr) = (void (*)(unsigned long))(LAST_BOOT_ENTRY-12)

Definition at line 51 of file flash_lib.c.

U8(* boot_flash_read_sig)(unsigned long adr) = (U8 (*)(unsigned long))(LAST_BOOT_ENTRY-10)

Definition at line 52 of file flash_lib.c.

U8(* boot_flash_read_fuse)(unsigned long adr) = (U8 (*)(unsigned long))(LAST_BOOT_ENTRY-8)

Definition at line 53 of file flash_lib.c.

void(* boot_flash_fill_temp_buffer)(unsigned int data, unsigned int adr) = (void (*)(unsigned int, unsigned int))(LAST_BOOT_ENTRY-6)

Definition at line 54 of file flash_lib.c.

void(* boot_flash_prg_page)(unsigned long adr) = (void (*)(unsigned long))(LAST_BOOT_ENTRY-4)

Definition at line 55 of file flash_lib.c.

void(* boot_flash_page_erase)(unsigned long adr) = (void (*)(unsigned long))(LAST_BOOT_ENTRY-2)

Definition at line 56 of file flash_lib.c.

void(* boot_lock_wr_bits)(unsigned char val) = (void (*)(unsigned char))(LAST_BOOT_ENTRY)

Definition at line 57 of file flash_lib.c.