1 #include "NyLPC_flash.h"
\r
2 #include "NyLPC_http.h"
\r
3 #include "NyLPC_cMiMicConfiglation.h"
\r
6 * Onchip flashを使ったコンフィギュレーション保存システムです。
\r
12 #define IP2Int(a0,a1,a2,a3) ((0xff000000&(((NyLPC_TUInt32)(a0))<<24))|(0x00ff0000&(((NyLPC_TUInt32)(a1))<<16))|(0x0000ff00&(((NyLPC_TUInt32)(a2))<<8))|(0x000000ff&(((NyLPC_TUInt32)(a3)))))
\r
16 #define MIMIC_CONFIGLATION_FLASH_SECTOR 29
\r
17 #define MIMIC_CONFIGLATION_FLASH_SECTOR_ADDR 0x00078000
\r
20 * コンフィギュレーション値はホストオーダーで保存する。
\r
22 const struct NyLPC_TMimicConfigulation factory_default=
\r
25 0x02010203,0x0405ffff,
\r
26 IP2Int(192,168,0,39),
\r
27 IP2Int(255,255,255,0),
\r
28 IP2Int(192,168,0,254),
\r
35 const static NyLPC_TUInt32 FAST_BOOT_DATA=0xfffffffe;
\r
37 * ユーザコンフィギュレーションを更新する。
\r
38 * この関数をコールするときは、割込/FreeRTOSを一時停止すること。
\r
40 NyLPC_TBool NyLPC_cMiMicConfiglation_updateConfigulation(const struct NyLPC_TMimicConfigulation* i_congfiglation)
\r
42 const NyLPC_TUInt32* volatile fast_boot=&(factory_default.fast_boot);
\r
44 if(!NyLPC_cOnchipFlashWriter_elase(MIMIC_CONFIGLATION_FLASH_SECTOR,MIMIC_CONFIGLATION_FLASH_SECTOR)){
\r
45 NyLPC_OnErrorGoto(Error);
\r
48 if(!NyLPC_cOnchipFlashWriter_writeSector(MIMIC_CONFIGLATION_FLASH_SECTOR,0x00000000,i_congfiglation,sizeof(struct NyLPC_TMimicConfigulation))){
\r
49 NyLPC_OnErrorGoto(Error);
\r
51 //プログラム済フラッシュの一部を書き換えてユーザコンフィギュレーションをONにする。
\r
52 if(*fast_boot==0xffffffff){
\r
53 //フラグ値のアドレスが4バイトアライメントにあるFlashメモリか確認する。
\r
54 if(((NyLPC_TUInt32)fast_boot)%4==0 && (!NyLPC_cOnchipFlashWriter_isOnchipFlash(fast_boot))){
\r
56 NyLPC_cOnchipFlashWriter_write(fast_boot,&FAST_BOOT_DATA,4);
\r
58 NyLPC_OnErrorGoto(Error);
\r
61 return NyLPC_TBool_TRUE;
\r
63 return NyLPC_TBool_FALSE;
\r
68 const struct NyLPC_TMimicConfigulation* NyLPC_cMiMicConfiglation_loadFromFlash(void)
\r
70 if(NyLPC_cMiMicConfiglation_hasUserConfigulation()){
\r
71 //userコンフィギュレーション読むよ
\r
72 return (const struct NyLPC_TMimicConfigulation*)(MIMIC_CONFIGLATION_FLASH_SECTOR_ADDR);
\r
75 return &factory_default;
\r
78 const struct NyLPC_TMimicConfigulation* NyLPC_cMiMicConfiglation_loadFactoryDefault(void)
\r
80 return &factory_default;
\r
88 * ユーザコンフィギュレーションが存在すると、true.
\r
90 NyLPC_TBool NyLPC_cMiMicConfiglation_hasUserConfigulation(void)
\r
92 volatile const NyLPC_TUInt32* fast_boot=&(factory_default.fast_boot);
\r
93 return (*fast_boot)!=0xffffffff;
\r