Go to the documentation of this file.00001
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 #include "config.h"
00046 #include "flash_lib.h"
00047 #include "flash_drv.h"
00048
00049
00050
00051 void (*boot_flash_page_erase_and_write)(unsigned long adr)=(void (*)(unsigned long))(LAST_BOOT_ENTRY-12);
00052 U8 (*boot_flash_read_sig) (unsigned long adr)=(U8 (*)(unsigned long))(LAST_BOOT_ENTRY-10);
00053 U8 (*boot_flash_read_fuse) (unsigned long adr)=(U8 (*)(unsigned long))(LAST_BOOT_ENTRY-8);
00054 void (*boot_flash_fill_temp_buffer) (unsigned int data,unsigned int adr)=(void (*)(unsigned int, unsigned int))(LAST_BOOT_ENTRY-6);
00055 void (*boot_flash_prg_page) (unsigned long adr)=(void (*)(unsigned long))(LAST_BOOT_ENTRY-4);
00056 void (*boot_flash_page_erase) (unsigned long adr)=(void (*)(unsigned long))(LAST_BOOT_ENTRY-2);
00057 void (*boot_lock_wr_bits) (unsigned char val)=(void (*)(unsigned char))(LAST_BOOT_ENTRY);
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00075 void flash_wr_byte(Uint32 addr_byte, Uchar value)
00076 {
00077 Enable_flash();
00078 flash_wr_block(&value, addr_byte, 1);
00079 Disable_flash();
00080 }
00081
00082
00092 Uchar flash_wr_block(Byte _MemType_* src, Uint32 dst, U16 n)
00093 {
00094 U16 nb_word, temp16;
00095 U32 address;
00096 U32 save_page_adr;
00097 U8 page_is_blank;
00098
00099 while(n)
00100 {
00101 page_is_blank=TRUE;
00102 address=dst-(LOW(dst)%FLASH_PAGE_SIZE);
00103 save_page_adr=address;
00104
00105
00106 for(nb_word=0;nb_word<FLASH_PAGE_SIZE/2;nb_word++)
00107 {
00108 if(n)
00109 {
00110 if(address>=dst)
00111 {
00112 MSB(temp16)=(*(U8*)src);
00113 src++; n--;
00114 if(n)
00115 {
00116 LSB(temp16)=(*(U8*)src);
00117 src++; n--;
00118 }
00119 else
00120 {
00121 LSB(temp16)=flash_rd_byte((U8 farcode*)address+1);
00122 }
00123 }
00124 else
00125 {
00126 MSB(temp16)=flash_rd_byte((U8 farcode*)address);
00127 if(address+1==dst)
00128 {
00129 LSB(temp16)=(*(U8*)src);
00130 src++; n--;
00131 }
00132 else
00133 {
00134 LSB(temp16)=flash_rd_byte((U8 farcode*)address+1);
00135 }
00136 }
00137 }
00138 else
00139 {
00140 temp16=flash_rd_word((U16 farcode*)address);
00141 }
00142
00143 (*boot_flash_fill_temp_buffer)(temp16,address);
00144 address+=2;
00145 }
00146 address=save_page_adr;
00147 for(nb_word=0;nb_word<FLASH_PAGE_SIZE/2;nb_word++)
00148 {
00149 if(flash_rd_word((U16 farcode*)address)!=0xFFFF)
00150 {
00151 page_is_blank=FALSE;
00152 break;
00153 }
00154 address+=2;
00155 }
00156
00157 address=save_page_adr;
00158 if(page_is_blank) { (*boot_flash_prg_page)(save_page_adr); }
00159 else{(*boot_flash_page_erase_and_write)(save_page_adr);}
00160
00161 address = save_page_adr + FLASH_PAGE_SIZE;
00162 }
00163 return TRUE;
00164 }
00165
00166
00174 U8 flash_rd_byte(U8 farcode* addr)
00175 {
00176 unsigned char temp;
00177 Enable_flash();
00178 temp = *addr;
00179 Disable_flash();
00180 return temp;
00181 }
00182
00190 U16 flash_rd_word(U16 farcode* addr)
00191 {
00192 Union16 temp;
00193 Enable_flash();
00194 temp.b[1] = flash_rd_byte ((Uchar farcode*) addr);
00195 temp.b[0] = flash_rd_byte ((Uchar farcode*)addr+1);
00196 Disable_flash();
00197 return temp.w;
00198 }
00199
00200
00201
00202
00203
00204
00205