#include "config.h"#include "flash.h"#include "flash_lib.h"
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) ) |
Definition in file flash_lib.c.
| #define Enable_flash | ( | ) |
Definition at line 54 of file flash_lib.c.
Referenced by flash_rd_byte(), flash_rd_word(), and flash_wr_byte().
| #define Disable_flash | ( | ) |
Definition at line 55 of file flash_lib.c.
Referenced by flash_rd_byte(), flash_rd_word(), and flash_wr_byte().
| Bool flash_lib_check | ( | void | ) |
This function checks the presence of bootloader.
Definition at line 75 of file flash_lib.c.
Referenced by launch_test().
00076 { 00077 return (*((code U16*)((U32)boot_flash_page_erase_and_write*2)) != 0xFFFF); 00078 }
This function allows to write a byte in the flash memory.
| addr_byte | Address in flash memory to write the byte. | |
| value | Value to write in the flash memory |
Definition at line 86 of file flash_lib.c.
00087 { 00088 Enable_flash(); 00089 flash_wr_block(&value, addr_byte, 1); 00090 Disable_flash(); 00091 }
This function allows to write up to 65535 bytes in the flash memory.
This function manages alignement issue.
| src | Address of data to write. | |
| dst | Start address in flash memory where write data | |
| n | number of byte to write |
Definition at line 101 of file flash_lib.c.
Referenced by flash_wr_byte(), and launch_test().
00102 { 00103 U16 nb_word, temp16; 00104 U32 address; 00105 U32 save_page_adr; 00106 U8 page_is_blank; 00107 00108 while(n) // While there is data to load from src buffer 00109 { 00110 page_is_blank=TRUE; 00111 address=dst-(LOW(dst)%FLASH_PAGE_SIZE); // Compute the start of the page to be modified 00112 save_page_adr=address; // Memorize page addr 00113 00114 // For each word in this page 00115 for(nb_word=0;nb_word<FLASH_PAGE_SIZE/2;nb_word++) 00116 { 00117 if(n) // Still some data to load from src 00118 { 00119 if(address>=dst) // Current address is inside the target range adr 00120 { 00121 MSB(temp16)=(*(U8*)src); // Load MSB of word from buffer src 00122 src++; n--; 00123 if(n) // Still some data to load ? 00124 { 00125 LSB(temp16)=(*(U8*)src); // Load LSB of word from buffer src 00126 src++; n--; 00127 } 00128 else // Only the MSB of the working belong to src buffer 00129 { // Load LSB form exisying flash 00130 LSB(temp16)=flash_rd_byte((U8 farcode*)address+1); 00131 } 00132 } 00133 else // Current word addr out of dst target 00134 { // Load MSB from existing flash 00135 MSB(temp16)=flash_rd_byte((U8 farcode*)address); 00136 if(address+1==dst) // Is LSB word addr in dst range ? 00137 { 00138 LSB(temp16)=(*(U8*)src); 00139 src++; n--; 00140 } 00141 else // LSB read from existing flash 00142 { 00143 LSB(temp16)=flash_rd_byte((U8 farcode*)address+1); 00144 } 00145 } 00146 } 00147 else // Complete page with words from existing flash 00148 { 00149 temp16=flash_rd_word((U16 farcode*)address); 00150 } 00151 //Load temp buffer 00152 (*boot_flash_fill_temp_buffer)(temp16,address); 00153 address+=2; 00154 } 00155 address=save_page_adr; 00156 for(nb_word=0;nb_word<FLASH_PAGE_SIZE/2;nb_word++) 00157 { 00158 if(flash_rd_word((U16 farcode*)address)!=0xFFFF) // Check for Blank page 00159 { 00160 page_is_blank=FALSE; 00161 break; 00162 } 00163 address+=2; 00164 } 00165 // Now launch prog sequence (with or without page erase) 00166 address=save_page_adr; 00167 if(page_is_blank) { (*boot_flash_prg_page)(save_page_adr); } 00168 else{(*boot_flash_page_erase_and_write)(save_page_adr);} 00169 //- First Flash address update for the next page 00170 address = save_page_adr + FLASH_PAGE_SIZE; 00171 } 00172 return TRUE; 00173 }
This function allows to read a byte in the flash memory.
| *add | Address of flash memory to read. |
Definition at line 181 of file flash_lib.c.
Referenced by flash_rd_word(), and flash_wr_block().
00182 { 00183 unsigned char temp; 00184 Enable_flash(); 00185 temp = *addr; 00186 Disable_flash(); 00187 return temp; 00188 }
This function allows to read a word in the flash memory.
| *add | Address of flash memory to read. |
Definition at line 196 of file flash_lib.c.
Referenced by flash_wr_block().
00197 { 00198 Union16 temp; 00199 Enable_flash(); 00200 temp.b[1] = flash_rd_byte ((Uchar farcode*) addr); 00201 temp.b[0] = flash_rd_byte ((Uchar farcode*)addr+1); 00202 Disable_flash(); 00203 return temp.w; 00204 }
| 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) |
Definition at line 60 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 61 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 62 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 63 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 64 of file flash_lib.c.
| void(* boot_lock_wr_bits)(unsigned char val) = (void (*)(unsigned char))( (((FLASH_END+1)/2)-2) ) |
Definition at line 65 of file flash_lib.c.
1.5.3