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_cNetConfig.c
00001 /********************************************************************************* 00002 * PROJECT: MiMic 00003 * -------------------------------------------------------------------------------- 00004 * 00005 * This file is part of MiMic 00006 * Copyright (C)2011 Ryo Iizuka 00007 * 00008 * MiMic is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License as published 00010 * by the Free Software Foundation, either version 3 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public License 00019 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00020 * 00021 * For further information please contact. 00022 * http://nyatla.jp/ 00023 * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp> 00024 * 00025 *********************************************************************************/ 00026 #include "NyLPC_cNetConfig.h" 00027 #include "../flash/NyLPC_cMiMicConfiglation.h" 00028 00029 00030 static void update(NyLPC_TcNetConfig_t* i_inst,const struct NyLPC_TMiMicConfigulation* pdata); 00031 00032 00033 void NyLPC_cNetConfig_initialize(NyLPC_TcNetConfig_t* i_inst,NyLPC_TBool i_is_factory_default) 00034 { 00035 if(i_is_factory_default) 00036 { 00037 update(i_inst,NyLPC_cMiMicConfiglation_loadFactoryDefault()); 00038 }else{ 00039 update(i_inst,NyLPC_cMiMicConfiglation_loadFromFlash()); 00040 } 00041 } 00042 00043 00044 /** 00045 * ユーザコンフィギュレーションを更新する。 00046 * この関数をコールするときは、割込/FreeRTOSを一時停止すること。 00047 */ 00048 /* 00049 NyLPC_TBool NyLPC_cNetConfig_saveToOnchipFlash(NyLPC_TcNetConfig_t* i_inst) 00050 { 00051 NyLPC_TUInt8* pdata; 00052 NyLPC_TcOnchipFlashWriter_t s; 00053 struct TNetConfigMemMap tmp; 00054 NyLPC_cOnchipFlashWriter_initialize(&s); 00055 //書込みデータを作成 00056 tmp.fast_boot=0xffffffff; 00057 tmp.version =i_inst->version; 00058 tmp.interface_type=NyLPC_cNetConfig_INTERFACE_TYPE_ETHERNET; 00059 pdata=i_inst->interface_setting.ethernet.eth_mac.addr; 00060 tmp.mac_00_01_02_03=(((NyLPC_TUInt32)pdata[0])<<24)|(((NyLPC_TUInt32)pdata[1])<<16)|(((NyLPC_TUInt32)pdata[2])<<8)|(((NyLPC_TUInt32)pdata[3])<<0); 00061 tmp.mac_04_05_xx_xx=(((NyLPC_TUInt32)pdata[4])<<24)|(((NyLPC_TUInt32)pdata[5])<<16); 00062 tmp.ipv4_addr_net=i_inst->interface_setting.ethernet.ip_addr.v; 00063 tmp.ipv4_mask_net=i_inst->interface_setting.ethernet.netmask.v; 00064 tmp.ipv4_drut_net=i_inst->interface_setting.ethernet.dr_addr.v; 00065 00066 //イレース 00067 if(!NyLPC_cOnchipFlashWriter_elase(&s,MIMIC_CONFIGLATION_FLASH_SECTOR,MIMIC_CONFIGLATION_FLASH_SECTOR)){ 00068 NyLPC_OnErrorGoto(Error); 00069 } 00070 //コンフィギュレーションを書き込む。 00071 if(!NyLPC_cOnchipFlashWriter_writeSector(&s,MIMIC_CONFIGLATION_FLASH_SECTOR,0x00000000,&tmp,sizeof(struct TNetConfigMemMap))){ 00072 NyLPC_OnErrorGoto(Error); 00073 } 00074 //ユーザコンフィギュレーションをONにする。 00075 if(setUserConfigulation()){ 00076 NyLPC_OnErrorGoto(Error); 00077 } 00078 NyLPC_cOnchipFlashWriter_finalize(&s); 00079 return NyLPC_TBool_TRUE; 00080 Error: 00081 NyLPC_cOnchipFlashWriter_finalize(&s); 00082 return NyLPC_TBool_FALSE; 00083 } 00084 */ 00085 00086 00087 /** 00088 * ETHERNET NETWORKのみなら 1480 00089 * インターネットを通過するなら 1400程度が妥当。 00090 */ 00091 //#define ETHERNET_FRAME_LEN 1480 00092 #define ETHERNET_FRAME_LEN 1400 00093 static void update(NyLPC_TcNetConfig_t* i_inst,const struct NyLPC_TMiMicConfigulation* pdata) 00094 { 00095 struct NyLPC_TEthAddr ea; 00096 struct NyLPC_TIPv4Addr ip,mask,drt; 00097 //値の読み出し 00098 ea.addr[0]=(NyLPC_TUInt8)((pdata->mac_00_01_02_03>>24)&0xff); 00099 ea.addr[1]=(NyLPC_TUInt8)((pdata->mac_00_01_02_03>>16)&0xff); 00100 ea.addr[2]=(NyLPC_TUInt8)((pdata->mac_00_01_02_03>> 8)&0xff); 00101 ea.addr[3]=(NyLPC_TUInt8)((pdata->mac_00_01_02_03>> 0)&0xff); 00102 ea.addr[4]=(NyLPC_TUInt8)((pdata->mac_04_05_xx_xx>>24)&0xff); 00103 ea.addr[5]=(NyLPC_TUInt8)((pdata->mac_04_05_xx_xx>>16)&0xff); 00104 ip.v=NyLPC_htonl(pdata->ipv4_addr_net); 00105 mask.v=NyLPC_htonl(pdata->ipv4_mask_net); 00106 drt.v=NyLPC_htonl(pdata->ipv4_drut_net); 00107 strcpy(i_inst->hostname,pdata->hostname); 00108 NyLPC_cIPv4Config_initialzeForEthernet(&i_inst->super,&ea,ETHERNET_FRAME_LEN); 00109 NyLPC_cIPv4Config_setDefaultRoute(&i_inst->super,&drt); 00110 NyLPC_cIPv4Config_setIp(&i_inst->super,&ip,&mask); 00111 i_inst->services.flags=pdata->srv_flags; 00112 i_inst->services.http_port=pdata->http_port; 00113 i_inst->tcp_mode=pdata->ipv4_flags; 00114 return; 00115 } 00116 00117 00118
Generated on Tue Jul 12 2022 16:22:59 by
