Defines | Functions

flash_boot_lib.h File Reference

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

#include "config.h"
#include "lib_mcu/flash_in_boot/flash_boot_drv.h"
Include dependency graph for flash_boot_lib.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define FLASH_BLANK_VALUE   0xFF
#define Flash_read_id1()   ( flash_read_sig(0x0000))
#define Flash_read_id2()   ( flash_read_sig(0x0002))
#define Flash_read_id3()   ( flash_read_sig(0x0004))
#define Flash_read_osccal()   ( flash_read_sig(0x0001))
#define Flash_read_fuse_low()   ( flash_read_fuse(0x0000))
#define Flash_read_fuse_high()   ( flash_read_fuse(0x0003))
#define Flash_read_fuse_extended()   ( flash_read_fuse(0x0002))
#define Flash_read_lock()   ( flash_read_fuse(0x0001))

Functions

void flash_wr_byte (U16 addr_byte, Uchar value)
 This function allows to write a byte in the flash memory.
Uchar flash_wr_block (Byte _MemType_ *src, U16 dst, U16 n)
 This function allows to write up to 65535 bytes in the flash memory.
void flash_erase (void)
 This function erases the whole flash memory.
Uchar flash_rd_byte (Uchar farcode *addr)
 This function allows to read a byte in the flash memory.
Uint16 flash_rd_word (Uint16 farcode *addr)
 This function allows to read a word in the flash memory.

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_boot_lib.h.


Define Documentation

#define FLASH_BLANK_VALUE   0xFF

Definition at line 55 of file flash_boot_lib.h.

#define Flash_read_id1 (  )    ( flash_read_sig(0x0000))

Definition at line 57 of file flash_boot_lib.h.

#define Flash_read_id2 (  )    ( flash_read_sig(0x0002))

Definition at line 58 of file flash_boot_lib.h.

#define Flash_read_id3 (  )    ( flash_read_sig(0x0004))

Definition at line 59 of file flash_boot_lib.h.

#define Flash_read_osccal (  )    ( flash_read_sig(0x0001))

Definition at line 60 of file flash_boot_lib.h.

#define Flash_read_fuse_low (  )    ( flash_read_fuse(0x0000))

Definition at line 61 of file flash_boot_lib.h.

#define Flash_read_fuse_high (  )    ( flash_read_fuse(0x0003))

Definition at line 62 of file flash_boot_lib.h.

#define Flash_read_fuse_extended (  )    ( flash_read_fuse(0x0002))

Definition at line 63 of file flash_boot_lib.h.

#define Flash_read_lock (  )    ( flash_read_fuse(0x0001))

Definition at line 64 of file flash_boot_lib.h.


Function Documentation

void flash_wr_byte ( U16  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 64 of file flash_boot_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,
U16  dst,
U16  n 
)

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

This function manages alignement issue (byte and page alignements).

Parameters:
*srcAddress of data to write.
dstStart address in flash memory where write data
nnumber of byte to write

Definition at line 73 of file flash_boot_lib.c.

References flash_fill_temp_buffer(), Flash_page_erase, Flash_page_write, flash_rd_byte(), flash_rd_word(), LOW, LSB, MSB, and TRUE.

Referenced by flash_wr_byte().

{
   U16 nb_word, temp16;
   U16 address;
   U16 save_page_adr;

   while(n)  // While there is data to load from src buffer
   {
      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((Uint16 farcode*)address);
         }
         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((Uint16 farcode*)address)!=0xFFFF)
         {
            Flash_page_erase(save_page_adr);
            break;
         }
         address+=2;
      }
      Flash_page_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:

Here is the caller graph for this function:

void flash_erase ( void   )

This function erases the whole flash memory.

Definition at line 142 of file flash_boot_lib.c.

{
#if FLASH_SIZE > 0
  U16 nb_page;

  Enable_flash();
  nb_page=0;
  do {
    Flash_page_erase(nb_page);
    nb_page += FLASH_PAGE_SIZE;
  } while (nb_page<(FLASH_SIZE));
  Disable_flash();
#endif

}
Uchar flash_rd_byte ( Uchar 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 158 of file flash_boot_lib.c.

{
  unsigned char temp;

  Enable_flash();
  temp = *addr;
  Disable_flash();
  return temp;
}
Uint16 flash_rd_word ( Uint16 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 169 of file flash_boot_lib.c.

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

Referenced by flash_wr_block().

{
  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:

Here is the caller graph for this function: