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_boot_lib.h"
00047 #include "flash_boot_drv.h"
00048
00049
00050 #ifndef FLASH_SIZE
00051 #error You must define FLASH_SIZE in bytes in config.h
00052 #endif
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 #pragma location="BOOT"
00064 void flash_wr_byte(U16 addr_byte, Uchar value)
00065 {
00066 Enable_flash();
00067 flash_wr_block(&value, addr_byte, 1);
00068 Disable_flash();
00069 }
00070
00071
00072 #pragma location="BOOT"
00073 Uchar flash_wr_block(Byte _MemType_* src, U16 dst, U16 n)
00074 {
00075 U16 nb_word, temp16;
00076 U16 address;
00077 U16 save_page_adr;
00078
00079 while(n)
00080 {
00081 address=dst-(LOW(dst)%FLASH_PAGE_SIZE);
00082 save_page_adr=address;
00083
00084 for(nb_word=0;nb_word<FLASH_PAGE_SIZE/2;nb_word++)
00085 {
00086 if(n)
00087 {
00088 if(address>=dst)
00089 {
00090 MSB(temp16)=(*(U8*)src);
00091 src++; n--;
00092 if(n)
00093 {
00094 LSB(temp16)=(*(U8*)src);
00095 src++; n--;
00096 }
00097 else
00098 {
00099 LSB(temp16)=flash_rd_byte((U8 farcode*)address+1);
00100 }
00101 }
00102 else
00103 {
00104 MSB(temp16)=flash_rd_byte((U8 farcode*)address);
00105 if(address+1==dst)
00106 {
00107 LSB(temp16)=(*(U8*)src);
00108 src++; n--;
00109 }
00110 else
00111 {
00112 LSB(temp16)=flash_rd_byte((U8 farcode*)address+1);
00113 }
00114 }
00115 }
00116 else
00117 {
00118 temp16=flash_rd_word((Uint16 farcode*)address);
00119 }
00120 flash_fill_temp_buffer(temp16,address);
00121 address+=2;
00122 }
00123 address=save_page_adr;
00124 for(nb_word=0;nb_word<FLASH_PAGE_SIZE/2;nb_word++)
00125 {
00126 if(flash_rd_word((Uint16 farcode*)address)!=0xFFFF)
00127 {
00128 Flash_page_erase(save_page_adr);
00129 break;
00130 }
00131 address+=2;
00132 }
00133 Flash_page_write(save_page_adr);
00134
00135
00136 address = save_page_adr + FLASH_PAGE_SIZE;
00137
00138 }
00139 return TRUE;
00140 }
00141 #pragma location="BOOT"
00142 void flash_erase(void)
00143 {
00144 #if FLASH_SIZE > 0
00145 U16 nb_page;
00146
00147 Enable_flash();
00148 nb_page=0;
00149 do {
00150 Flash_page_erase(nb_page);
00151 nb_page += FLASH_PAGE_SIZE;
00152 } while (nb_page<(FLASH_SIZE));
00153 Disable_flash();
00154 #endif
00155
00156 }
00157
00158 Uchar flash_rd_byte(Uchar farcode* addr)
00159 {
00160 unsigned char temp;
00161
00162 Enable_flash();
00163 temp = *addr;
00164 Disable_flash();
00165 return temp;
00166 }
00167
00168
00169 Uint16 flash_rd_word(Uint16 farcode* addr)
00170 {
00171 Union16 temp;
00172
00173 Enable_flash();
00174 temp.b[1] = flash_rd_byte ((Uchar farcode*) addr);
00175 temp.b[0] = flash_rd_byte ((Uchar farcode*)addr+1);
00176 Disable_flash();
00177
00178 return temp.w;
00179 }
00180
00181
00182