Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of libMiMic by
NyLPC_cMiMicConfiglation_K64F.c
00001 #include "NyLPC_config.h" 00002 #if NyLPC_MCU==NyLPC_MCU_K64F 00003 #include "NyLPC_stdlib.h" 00004 #include "NyLPC_flash.h" 00005 #include "NyLPC_http.h" 00006 #include "NyLPC_net.h" 00007 #include "K64F_IAP.h" 00008 #ifdef __cplusplus 00009 extern "C" { 00010 #endif /* __cplusplus */ 00011 /** 00012 * Onchip flashを使ったコンフィギュレーション保存システムです。 00013 * K64Fの0x0080000に構造体NyLPC_TMiMicConfigulationを保存します。 00014 */ 00015 00016 00017 00018 00019 #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))))) 00020 /** 00021 * コンフィギュレーションの保存セクタ 00022 */ 00023 #define MIMIC_CONFIGLATION_FLASH_ADDR ((void*)0x00080000) 00024 00025 /** 00026 * コンフィギュレーション値はホストオーダーで保存する。 00027 */ 00028 const struct NyLPC_TMiMicConfigulation factory_default= 00029 { 00030 0xffffffff, //fastboot 00031 "MiMic020102030405", 00032 0x02010203,0x0405ffff, //Mac addr 00033 //IPv4 00034 NyLPC_TcNetConfig_IPV4_FLAG_MODE_MANUAL, //flags 00035 IP2Int(192,168,0,39), 00036 IP2Int(255,255,255,0), 00037 IP2Int(192,168,0,254), 00038 //ServerFlags 00039 NyLPC_TcNetConfig_SERVICE_FLAG_MDNS|NyLPC_TcNetConfig_SERVICE_FLAG_UPNP, 00040 //HTTP 00041 80, //HTTP-Port 00042 0 //padding 00043 }; 00044 00045 00046 #define FAST_BOOT_DATA 0xfffffffe 00047 /** 00048 * ユーザコンフィギュレーションを更新する。 00049 * この関数をコールするときは、割込/FreeRTOSを一時停止すること。 00050 */ 00051 NyLPC_TBool NyLPC_cMiMicConfiglation_updateConfigulation(const struct NyLPC_TMiMicConfigulation* i_congfiglation) 00052 { 00053 struct NyLPC_TMiMicConfigulation d; 00054 d.fast_boot=FAST_BOOT_DATA; 00055 memcpy(d.hostname,i_congfiglation->hostname,NyLPC_TcNetConfig_HOSTNAME_LEN); 00056 d.mac_00_01_02_03=i_congfiglation->mac_00_01_02_03; 00057 d.mac_04_05_xx_xx=i_congfiglation->mac_04_05_xx_xx; 00058 d.ipv4_flags=i_congfiglation->ipv4_flags; 00059 d.ipv4_addr_net=i_congfiglation->ipv4_addr_net; 00060 d.ipv4_mask_net=i_congfiglation->ipv4_mask_net; 00061 d.ipv4_drut_net=i_congfiglation->ipv4_drut_net; 00062 d.srv_flags=i_congfiglation->srv_flags; 00063 d.http_port=i_congfiglation->http_port; 00064 d.padding32=0xffff; 00065 d.padding64=0xffffffff; 00066 00067 00068 if(K64F_IAP_erase_sector((int)MIMIC_CONFIGLATION_FLASH_ADDR)!=K64F_IAP_TIAPCode_Success){ 00069 NyLPC_OnErrorGoto(Error); 00070 } 00071 if(K64F_IAP_program_flash((int)MIMIC_CONFIGLATION_FLASH_ADDR,(char*)(&d), sizeof(struct NyLPC_TMiMicConfigulation))!=K64F_IAP_TIAPCode_Success){ 00072 NyLPC_OnErrorGoto(Error); 00073 } 00074 return NyLPC_TBool_TRUE; 00075 Error: 00076 return NyLPC_TBool_FALSE; 00077 } 00078 /** 00079 * コンフィギュレーション値を返す。 00080 */ 00081 const struct NyLPC_TMiMicConfigulation* NyLPC_cMiMicConfiglation_loadFromFlash(void) 00082 { 00083 if(NyLPC_cMiMicConfiglation_hasUserConfigulation()){ 00084 //userコンフィギュレーション読むよ 00085 return (const struct NyLPC_TMiMicConfigulation*)(MIMIC_CONFIGLATION_FLASH_ADDR); 00086 }else{ 00087 //Userコンフィギュレーションない 00088 return &factory_default; 00089 } 00090 } 00091 const struct NyLPC_TMiMicConfigulation* NyLPC_cMiMicConfiglation_loadFactoryDefault(void) 00092 { 00093 return &factory_default; 00094 } 00095 00096 00097 00098 00099 00100 /** 00101 * ユーザコンフィギュレーションが存在すると、true. 00102 */ 00103 NyLPC_TBool NyLPC_cMiMicConfiglation_hasUserConfigulation(void) 00104 { 00105 //初回読出しはFlashにFFFFFFFFが格納されているのを期待する。 00106 volatile const NyLPC_TUInt32* fast_boot=((NyLPC_TUInt32*)MIMIC_CONFIGLATION_FLASH_ADDR); 00107 return (*fast_boot)!=0xffffffff; 00108 } 00109 00110 #ifdef __cplusplus 00111 } 00112 #endif /* __cplusplus */ 00113 #endif
Generated on Tue Jul 12 2022 16:22:57 by
