This is Webservice SDK for mbed. LPCXpresso1769/LPC1768/FRDM-K64F/LPC4088

Dependents:   MbedFileServer_1768MiniDK2 RedWireBridge IssueDebug_gcc MiMicRemoteMCU-for-Mbed ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers NyLPC_cMiMicConfiglation_LPCxxx.c Source File

NyLPC_cMiMicConfiglation_LPCxxx.c

00001 #include "NyLPC_config.h"
00002 #if NyLPC_MCU==NyLPC_MCU_LPC4088 || NyLPC_MCU==NyLPC_MCU_LPC17xx
00003 #include "NyLPC_flash.h"
00004 #include "NyLPC_http.h"
00005 #include "NyLPC_cOnchipFlashWriter.h"
00006 #include "NyLPC_net.h"
00007 /**
00008  * Onchip flashを使ったコンフィギュレーション保存システムです。
00009  */
00010 
00011 
00012 
00013 
00014 #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)))))
00015 /**
00016  * コンフィギュレーションの保存セクタ
00017  */
00018 #define MIMIC_CONFIGLATION_FLASH_SECTOR 29
00019 #define MIMIC_CONFIGLATION_FLASH_SECTOR_ADDR 0x00078000
00020 
00021 /**
00022  * コンフィギュレーション値はホストオーダーで保存する。
00023  */
00024 const struct NyLPC_TMiMicConfigulation factory_default=
00025 {
00026     0xffffffff,             //fastboot
00027     "MiMic020102030405",
00028     0x02010203,0x0405ffff,  //Mac addr
00029     //IPv4
00030     NyLPC_TcNetConfig_IPV4_FLAG_MODE_MANUAL,    //flags
00031     IP2Int(192,168,0,39),
00032     IP2Int(255,255,255,0),
00033     IP2Int(192,168,0,254),
00034     //ServerFlags
00035     NyLPC_TcNetConfig_SERVICE_FLAG_MDNS|NyLPC_TcNetConfig_SERVICE_FLAG_UPNP,
00036     //HTTP
00037     80, //HTTP-Port
00038     0   //padding
00039 };
00040 
00041 
00042 
00043 const static NyLPC_TUInt32 FAST_BOOT_DATA=0xfffffffe;
00044 /**
00045  * ユーザコンフィギュレーションを更新する。
00046  * この関数をコールするときは、割込/FreeRTOSを一時停止すること。
00047  */
00048 NyLPC_TBool NyLPC_cMiMicConfiglation_updateConfigulation(const struct NyLPC_TMiMicConfigulation* i_congfiglation)
00049 {
00050     const NyLPC_TUInt32* volatile fast_boot=&(factory_default.fast_boot);
00051     //イレース
00052     if(!NyLPC_cOnchipFlashWriter_elase(MIMIC_CONFIGLATION_FLASH_SECTOR,MIMIC_CONFIGLATION_FLASH_SECTOR)){
00053         NyLPC_OnErrorGoto(Error);
00054     }
00055     //コンフィギュレーションを書き込む。
00056     if(!NyLPC_cOnchipFlashWriter_writeSector(MIMIC_CONFIGLATION_FLASH_SECTOR,0x00000000,i_congfiglation,sizeof(struct NyLPC_TMiMicConfigulation))){
00057         NyLPC_OnErrorGoto(Error);
00058     }
00059     //プログラム済フラッシュの一部を書き換えてユーザコンフィギュレーションをONにする。
00060     if(*fast_boot==0xffffffff){
00061         //フラグ値のアドレスが4バイトアライメントにあるFlashメモリか確認する。
00062         if(((NyLPC_TUInt32)fast_boot)%4==0 && (!NyLPC_cOnchipFlashWriter_isOnchipFlash(fast_boot))){
00063             //書き込み
00064             NyLPC_cOnchipFlashWriter_write(fast_boot,&FAST_BOOT_DATA,4);
00065         }else{
00066             NyLPC_OnErrorGoto(Error);
00067         }
00068     }
00069     return NyLPC_TBool_TRUE;
00070 Error:
00071     return NyLPC_TBool_FALSE;
00072 }
00073 /**
00074  * コンフィギュレーション値を返す。
00075  */
00076 const struct NyLPC_TMiMicConfigulation* NyLPC_cMiMicConfiglation_loadFromFlash(void)
00077 {
00078     if(NyLPC_cMiMicConfiglation_hasUserConfigulation()){
00079         //userコンフィギュレーション読むよ
00080         return (const struct NyLPC_TMiMicConfigulation*)(MIMIC_CONFIGLATION_FLASH_SECTOR_ADDR);
00081     }else{
00082         //Userコンフィギュレーションない
00083         return &factory_default;
00084     }
00085 }
00086 const struct NyLPC_TMiMicConfigulation* NyLPC_cMiMicConfiglation_loadFactoryDefault(void)
00087 {
00088     return &factory_default;
00089 }
00090 
00091 
00092 
00093 
00094 
00095 /**
00096  * ユーザコンフィギュレーションが存在すると、true.
00097  */
00098 NyLPC_TBool NyLPC_cMiMicConfiglation_hasUserConfigulation(void)
00099 {
00100     volatile const NyLPC_TUInt32* fast_boot=&(factory_default.fast_boot);
00101     return (*fast_boot)!=0xffffffff;
00102 }
00103 
00104 
00105 #endif