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

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

libMiMic(MiMic library for mbed)は、WebService機能を提供するSDKです。 mbedでWebAPIに対応したネットワークデバイスを簡単に作ることが出来ます。

libMiMicはMiMic projectで開発しています。MiMic projectについてはこちらをご覧ください。 http://nyatla.jp/mimic/wp/

構成

libMiMicはmbedRTOS上で動作し、ユーザアプリケーションにAPIを提供します。コアAPIはC言語で記述されていますが、使用頻度の高いものについてはmbed向けのC++APIが準備されています。

/media/uploads/nyatla/libmimic-sdk.png

※libMiMicはmbedの標準イーサネットドライバをしようしていません。

標準イーサネットドライバと同時に使用することはできません。

  • MiMicIP - IPv4スタックです。レテンシとメモリ消費量を抑えたuipベースのライブラリです。
  • ARP/ICMP/UDP/TCP - 基礎的なソケットAPIを提供します。APIは独自です。
  • HTTP/1.1 Server - HTTP/1.1に対応したサーバです。マルチセッション・Chunked・持続性接続に対応しています。
  • HTTP Modules - HTTP/1.1の機能モジュールです。以下のモジュールがあります。
    • ROM file provider - ROMに格納したファイルイメージを公開します。
    • File system provider - mbedファイルシステムを公開します。
    • Onchip configuration - プログラムフラッシュを利用して設定を保存します。
    • MiMicVM processor - RPCリクエスト(MiMicVM)を処理します。
    • FileUpload - ファイルアップロードを受け取ります。
    • URL decoder - HTTPリクエストを解析します。
    • UPnP handler -UPnPメッセージを処理します。
    • WebSocket - Websocketサーバです。
  • mDNS - マルチキャストDNSサービスです。
  • UPnP - UPnP/1.0の機能を提供します。UPnP handlerと協調して動作します。(現在はデバイス探索(SSDP)・デスクリプション(Description)のみ実装してあります。)
  • DHCP/APIPA - ゼロコンフィギュレーション用のモジュールです。
  • HTTP/1.1 Client
  • mbed C++ class library - mbed向けのC++CPIです。C言語のものより簡単です。

対応機種

  • mbed(mbed LPC1768)
  • LPCXpresso1769

プログラム

Import programMiMicRemoteMCU-for-Mbed

MiMic RemoteMCU for mbed. This program provides MCU control API over REST API. It can control MCU from Javascript,PHP or any HTTP rest client directly. And, The application has self development environment.

Import programMbedFileServer

The program publishes files at local directory and SD filesystem. It is a full-fledged webServer somewhat.

サンプル

Import programMiMicSimpleHttpd

This is a simplest HTTP server made ​​of libMiMic. It will echo back a request path.

Import programUPnPBasicDevice

Simplest UPnP basic device example. This program to run UPnP basic device on the mbed.

Import programWebSocketSample

MiMicSDK Websocket module sample program.

Import programHttpClientSamlpe

A http client sample program.

Import programTcpSocketClientSamlpe

MiMicSDK Tcp client socket sample program.

Import programUdpSocketSamlpe

Udp socket sample program. This program will send back the received packet.

チュートリアル

English

libMiMic(MiMic library for mbed) is SDK which provides Webservice functions. It can be created networking device easily using mbed.

See more MiMic information, See MiMic project website. http://nyatla.jp/mimic/wp/

Structure

libMiMic run on mbed RTOS and provides networking API to user application. This library has C++ class API for the mbed, and low-level C language API.

/media/uploads/nyatla/libmimic-sdk.png

For WebService general, it can be written in a simple C + + API.

libMiMic does not have the standard Ethernet driver of mbed. It is not possible that will be used with the standard Ethernet driver.

  • MiMicIP - IPv4 protocol stack. This is based uip which is reduced memory and latency.
  • ARP / ICMP / UDP / TCP - Those are provide basic IP protocols.
  • HTTP/1.1 Server - The Http server compatible HTTP/1.1. It supports multi-session, chunked transport, persistent connection.
  • HTTP Modules - There are addon-module for HTTP server. The following modules.
    • ROM file module - Publish the file images in ROM.
    • File system module - Publish thefiles in mbed file system.
    • Onchip configuration module - To save the network settings to the program flash via REST.
    • MiMicVM module - To handle the (MiMicVM) RPC request.
    • FileUpload module - Accept a file via HTTP POST.
    • URL dedoce module - A versatility URL decoder.
    • UPnP handle module - To handle UPnP messages.
    • UPnP - This provides UPnP/1.0 device functions. It works together with UPnP handler.
    • Websocket - websocket (version13) server
  • mDNS Service - DNS-SD protocol server.
  • UPnP - This provides UPnP/1.0 device functions which works with UPnP handler. (You have been implemented (SSDP) ? description only (Description) device search now.) It is a module zero configuration for - DHCP / APIPA. mbed C + + class library - C of mbed for + + is the CPI. It is simple than that of the C language.
  • DHCP/APIPA - It support zero-cpnfigulation.
  • mbed C++ class library. Almost APIs for Web applications are available.
  • HTTP/1.1 Client

Supported target

  • mbed(mbed LPC1768)
  • LPCXpresso1769

Application

Import programMiMicRemoteMCU-for-Mbed

MiMic RemoteMCU for mbed. This program provides MCU control API over REST API. It can control MCU from Javascript,PHP or any HTTP rest client directly. And, The application has self development environment.

Import programMbedFileServer

The program publishes files at local directory and SD filesystem. It is a full-fledged webServer somewhat.

Sample

Import programMiMicSimpleHttpd

This is a simplest HTTP server made ​​of libMiMic. It will echo back a request path.

Import programUPnPBasicDevice

Simplest UPnP basic device example. This program to run UPnP basic device on the mbed.

Import programWebSocketSample

MiMicSDK Websocket module sample program.

Import programHttpClientSamlpe

A http client sample program.

Import programTcpSocketClientSamlpe

MiMicSDK Tcp client socket sample program.

Import programUdpSocketSamlpe

Udp socket sample program. This program will send back the received packet.

Tutorial

Files at this revision

API Documentation at this revision

Comitter:
nyatla
Date:
Wed Oct 01 13:58:53 2014 +0000
Parent:
91:db8279c869d3
Child:
93:6afc7c06037f
Commit message:
?????????????????; K64F??????????????; LPC?????????????????

Changed in this revision

core/driver/ethernet/NyLPC_cEthernetMM.h Show annotated file Show diff for this revision Revisions of this file
core/driver/ethernet/k64f/EthDev.c Show annotated file Show diff for this revision Revisions of this file
core/driver/ethernet/k64f/EthDev_K64F.c Show annotated file Show diff for this revision Revisions of this file
core/driver/ethernet/k64f/EtherDev_K64F_protected.h Show annotated file Show diff for this revision Revisions of this file
core/driver/ethernet/k64f/fsl/fsl_enet_driver.c Show annotated file Show diff for this revision Revisions of this file
core/driver/ethernet/k64f/fsl/hardware_init_MK64F12.c Show annotated file Show diff for this revision Revisions of this file
core/driver/ethernet/k64f/k64f_emac_config.h Show annotated file Show diff for this revision Revisions of this file
core/driver/ethernet/lpc17xx/EthDev_LPC17xx.c Show annotated file Show diff for this revision Revisions of this file
core/driver/ethernet/lpc17xx/EtherDev_DP83848C.c Show annotated file Show diff for this revision Revisions of this file
core/driver/ethernet/lpc4088/EthDev_LPC4088.c Show annotated file Show diff for this revision Revisions of this file
core/driver/flash/LPC17xx_IAP.c Show diff for this revision Revisions of this file
core/driver/flash/LPC17xx_IAP.h Show diff for this revision Revisions of this file
core/driver/flash/LPCxxx/LPC17xx_IAP.c Show annotated file Show diff for this revision Revisions of this file
core/driver/flash/LPCxxx/LPC17xx_IAP.h Show annotated file Show diff for this revision Revisions of this file
core/driver/flash/LPCxxx/NyLPC_cMiMicConfiglation_LPCxxx.c Show annotated file Show diff for this revision Revisions of this file
core/driver/flash/LPCxxx/NyLPC_cOnchipFlashWriter.c Show annotated file Show diff for this revision Revisions of this file
core/driver/flash/LPCxxx/NyLPC_cOnchipFlashWriter.h Show annotated file Show diff for this revision Revisions of this file
core/driver/flash/k64f/K64F_IAP.c Show annotated file Show diff for this revision Revisions of this file
core/driver/flash/k64f/K64F_IAP.h Show annotated file Show diff for this revision Revisions of this file
core/driver/flash/k64f/NyLPC_cMiMicConfiglation_K64F.c Show annotated file Show diff for this revision Revisions of this file
core/flash/NyLPC_cMiMicConfiglation.c Show diff for this revision Revisions of this file
core/flash/NyLPC_cMiMicConfiglation.h Show annotated file Show diff for this revision Revisions of this file
core/flash/NyLPC_cOnchipFlashWriter.c Show diff for this revision Revisions of this file
core/flash/NyLPC_cOnchipFlashWriter.h Show diff for this revision Revisions of this file
core/include/NyLPC_config.h Show annotated file Show diff for this revision Revisions of this file
core/include/NyLPC_flash.h Show annotated file Show diff for this revision Revisions of this file
core/net/httpd/mod/NyLPC_cMocMiMicSetting.c Show annotated file Show diff for this revision Revisions of this file
core/uip/NyLPC_cUipService.c Show annotated file Show diff for this revision Revisions of this file
core/uip/NyLPC_cUipService_protected.h Show annotated file Show diff for this revision Revisions of this file
--- a/core/driver/ethernet/NyLPC_cEthernetMM.h	Sat Sep 27 13:33:26 2014 +0000
+++ b/core/driver/ethernet/NyLPC_cEthernetMM.h	Wed Oct 01 13:58:53 2014 +0000
@@ -49,6 +49,13 @@
 #endif
 
 /**
+ *バッファメモリのパディングサイズ
+ */
+#ifndef NyLPC_TcEthernetMM_BUF_PADDING
+#	define NyLPC_TcEthernetMM_BUF_PADDING 0
+#endif
+
+/**
  * 送信バッフメモリのヘッダ。
  * この構造体は、TXバッファメモリブロックのヘッダーです。
  * TXバッファメモリブロックは、この構造体の後ろに、sizeに一致したメモリを連結したもので表現します。
@@ -100,6 +107,7 @@
  */
 #define NyLPC_TcEthernetMM_MAX_TX_ETHERNET_PADDING		22
 
+
 /**
  * TXメモリブロックの定義配列
  */
@@ -108,23 +116,23 @@
 	struct{
 		struct NyLPC_TTxBufferHeader h;
 		NyLPC_TUInt8 b[NyLPC_TcEthernetMM_MAX_TX_ETHERNET_FRAME_SIZE];
-		NyLPC_TUInt8 _padding[NyLPC_TcEthernetMM_MAX_TX_ETHERNET_PADDING];
+		NyLPC_TUInt8 _padding[NyLPC_TcEthernetMM_MAX_TX_ETHERNET_PADDING+NyLPC_TcEthernetMM_BUF_PADDING];
 	}buf_max[NyLPC_TcEthernetMM_NUM_OF_MAX_BUF];//(4+MAX_TX_ETHERNET_FRAME_SIZE(1514))*3=? default=4554
 	struct{
 		struct NyLPC_TTxBufferHeader h;
-		NyLPC_TUInt8 b[512];
+		NyLPC_TUInt8 b[512+NyLPC_TcEthernetMM_BUF_PADDING];
 	}buf_512[NyLPC_TcEthernetMM_NUM_OF_512_BUF];//(4+512)*3=1548
 	struct{
 		struct NyLPC_TTxBufferHeader h;
-		NyLPC_TUInt8 b[256];
+		NyLPC_TUInt8 b[256+NyLPC_TcEthernetMM_BUF_PADDING];
 	}buf_256[NyLPC_TcEthernetMM_NUM_OF_256_BUF];//(4+256)*4=1560
 	struct{
 		struct NyLPC_TTxBufferHeader h;
-		NyLPC_TUInt8 b[128];
+		NyLPC_TUInt8 b[128+NyLPC_TcEthernetMM_BUF_PADDING];
 	}buf_128[NyLPC_TcEthernetMM_NUM_OF_128_BUF];//(4+128)*16=1584
 	struct{
 		struct NyLPC_TTxBufferHeader h;
-		NyLPC_TUInt8 b[64];
+		NyLPC_TUInt8 b[64+NyLPC_TcEthernetMM_BUF_PADDING];
 	}buf_64[NyLPC_TcEthernetMM_NUM_OF_64_BUF];//(4+64)*4=272
 }PACK_STRUCT_END;
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/driver/ethernet/k64f/EthDev.c	Wed Oct 01 13:58:53 2014 +0000
@@ -0,0 +1,21 @@
+#include "NyLPC_config.h"
+#if NyLPC_MCU==NyLPC_MCU_K64F
+
+#include "../EthDev.h"
+#include "EtherDev_K64F_protected.h"
+
+
+
+const struct TiEthernetDevice* getEthernetDevicePnP(void)
+{
+	const struct TiEthernetDevice* ret;
+	if(EthDev_K64F_getInterface(&ret)){
+		return ret;
+	}
+	return NULL;
+}
+
+
+#endif
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/driver/ethernet/k64f/EthDev_K64F.c	Wed Oct 01 13:58:53 2014 +0000
@@ -0,0 +1,534 @@
+#include "NyLPC_config.h"
+#if NyLPC_MCU==NyLPC_MCU_K64F
+#include "NyLPC_stdlib.h"
+#include "NyLPC_os.h"
+#include "copy_of_ethernet_api.h"
+#include "NyLPC_IEthernetDevice.h"
+#include "NyLPC_cEthernetMM.h"
+//////////
+#include "fsl_enet_driver.h"
+#include "fsl_enet_hal.h"
+#include "fsl_device_registers.h"
+#include "fsl_phy_driver.h"
+#include "fsl_interrupt_manager.h"
+#include "k64f_emac_config.h"
+#include <string.h>
+#include <stdlib.h>
+
+/**
+ */
+static NyLPC_TBool start(const struct NyLPC_TEthAddr* i_eth_addr,NyLPC_TiEthernetDevice_onEvent i_handler,void* i_param);
+static void stop(void);
+static void* getRxEthFrame(unsigned short* o_len_of_data);
+static void nextRxEthFrame(void);
+static void* allocTxBuf(NyLPC_TUInt16 i_hint,NyLPC_TUInt16* o_size);
+static void releaseTxBuf(void* i_buf);
+static void sendTxEthFrame(void* i_buf,unsigned short i_size);
+
+const static struct TiEthernetDevice _interface_KSZ8081RNACA=
+{
+	"KSZ8081RNACA",
+	start,
+	stop,
+	getRxEthFrame,
+	nextRxEthFrame,
+	allocTxBuf,
+	releaseTxBuf,
+	sendTxEthFrame,
+	NULL	//deleted API
+};
+
+
+
+struct TEtherDriver{
+    int rx_idx;
+    int tx_idx;
+	uint8_t *tx_desc_start_addr; /**< TX descriptor start address */
+	uint8_t *rx_desc_start_addr; /**< RX descriptor start address */
+};
+
+static struct TEtherDriver _driver;
+static void* _event_param;
+static NyLPC_TiEthernetDevice_onEvent _event_handler;
+
+////////////////////////////////////////////////////////////////////////////////
+// LANパケットバッファ
+////////////////////////////////////////////////////////////////////////////////
+#define NUM_OF_RX_BUF 4
+#define SIZE_OF_ETH_PACKET (1536)   //16バイト単位であること
+static void* RX_BUF_BASE;       	//[NUM_OF_RX_BUF][SIZE_OF_ETH_PACKET]
+static unsigned char* RX_BUF;   	//[NUM_OF_RX_BUF][SIZE_OF_ETH_PACKET]
+static void* TX_BUF_BASE;       	//
+static unsigned char* TX_BUF;   	//sizeof(struct NyLPC_TcEthernetMM_TxMemoryBlock)
+
+#define NUM_OF_RX_RING NUM_OF_RX_BUF
+#define NUM_OF_TX_RING 4
+
+////////////////////////////////////////////////////////////////////////////////
+//private function
+////////////////////////////////////////////////////////////////////////////////
+
+
+static NyLPC_TBool low_level_init(const unsigned char* i_ethaddr,int i_addr_len);
+static void setRxDesc(void* rx_buf, int idx);
+static void updateRxDesc(int idx);
+static void setTxDesc(int idx);
+static void updateTxDesc(int idx, uint8_t *buffer, uint16_t length, bool isLast);
+static void eth_arch_enable_interrupts(void);
+static void eth_arch_disable_interrupts(void);
+static NyLPC_TUInt32 waitForTxEthFrameEmpty(void);
+
+////////////////////////////////////////////////////////////////////////////////
+//LAN API
+////////////////////////////////////////////////////////////////////////////////
+NyLPC_TBool EthDev_K64F_getInterface(
+	const struct TiEthernetDevice** o_dev)
+{
+	*o_dev=&_interface_KSZ8081RNACA;
+    RX_BUF_BASE=(unsigned char*)malloc(SIZE_OF_ETH_PACKET*NUM_OF_RX_BUF+RX_BUF_ALIGNMENT);
+    RX_BUF=(unsigned char*)ENET_ALIGN((NyLPC_TUInt32)RX_BUF_BASE,RX_BUF_ALIGNMENT);
+	TX_BUF_BASE=malloc(sizeof(struct NyLPC_TcEthernetMM_TxMemoryBlock)+TX_BUF_ALIGNMENT);
+	TX_BUF=(unsigned char*)ENET_ALIGN((NyLPC_TUInt32)TX_BUF_BASE,TX_BUF_ALIGNMENT);
+	
+	return NyLPC_TBool_TRUE;
+}
+
+static NyLPC_TBool start(const struct NyLPC_TEthAddr* i_eth_addr,NyLPC_TiEthernetDevice_onEvent i_handler,void* i_param)
+{
+    _driver.rx_idx=0;
+    _driver.tx_idx=0;
+    //ISRw割り込み設定
+    _event_handler=i_handler;
+    _event_param=i_param;
+    
+    if(!low_level_init((const NyLPC_TUInt8*)(i_eth_addr->addr),6)){
+        return NyLPC_TBool_FALSE;
+    }
+    //TXメモリマネージャの準備(バッファのアライメントは16,パディングも16にしてね。謎バイトが2個いるから。)
+	NyLPC_cEthernetMM_initialize(TX_BUF);
+
+    //Ethernetの割込み開始設定
+    NyLPC_cIsr_enterCritical();
+    //Ethernetの初期化シーケンス。割込みONとか
+    {
+    	eth_arch_enable_interrupts();
+    }
+    NyLPC_cIsr_exitCritical();
+
+    return NyLPC_TBool_TRUE;
+}
+
+static void stop(void)
+{
+    NyLPC_cIsr_enterCritical();
+    {
+    	eth_arch_disable_interrupts();
+    }
+    NyLPC_cIsr_exitCritical();
+   return;
+}
+
+
+#define err_mask (kEnetRxBdTrunc | kEnetRxBdCrc | kEnetRxBdNoOctet | kEnetRxBdLengthViolation)
+
+static void* getRxEthFrame(unsigned short* o_len_of_data)
+{
+    int idx=_driver.rx_idx;
+    enet_bd_struct_t * bdPtr = (enet_bd_struct_t*)_driver.rx_desc_start_addr;
+    if((bdPtr[idx].control & kEnetRxBdEmpty)!=0){
+        //パケット未着
+        return NULL;
+    }
+    if((bdPtr[idx].control & err_mask) != 0){
+        //エラー:パケットバッファを再設定して返却
+        setRxDesc(RX_BUF+(idx*SIZE_OF_ETH_PACKET),idx);        
+        _driver.rx_idx=(idx+1)%NUM_OF_RX_BUF;
+        return NULL;
+    }
+    *o_len_of_data =(unsigned short)enet_hal_get_bd_length(&(bdPtr[idx]))-2;
+    return &RX_BUF[idx*SIZE_OF_ETH_PACKET+2];
+}
+
+static void nextRxEthFrame(void)
+{
+    int idx=_driver.rx_idx;
+    enet_bd_struct_t * bdPtr = (enet_bd_struct_t*)_driver.rx_desc_start_addr;
+    //現在のRXメモリが有効かを確認
+    if((bdPtr[idx].control & kEnetRxBdEmpty)==0){
+        //パケットバッファを復活させる
+        updateRxDesc(idx);
+        //キューのエントリを進行
+        _driver.rx_idx=(idx+1)%NUM_OF_RX_BUF;
+        return;
+    }
+}
+
+static void* allocTxBuf(NyLPC_TUInt16 i_hint,NyLPC_TUInt16* o_size)
+{
+	return ((NyLPC_TUInt8*)NyLPC_cEthernetMM_alloc(i_hint,o_size))+2;
+}
+static void releaseTxBuf(void* i_buf)
+{
+	NyLPC_cEthernetMM_release((NyLPC_TUInt8*)i_buf-2);
+}
+
+
+static void sendTxEthFrame(void* i_buf,unsigned short i_size)
+{
+	int Index;
+	struct NyLPC_TTxBufferHeader* bh=NyLPC_TTxBufferHeader_getBufferHeaderAddr(i_buf-2);
+	//サイズ0なら送信の必要なし
+	if(i_size == 0)
+	{
+		return;
+	}
+	//送信デスクリプタが使えるようになるのを待つよ!
+	waitForTxEthFrameEmpty();
+
+	//送信対象のメモリブロックを送信中に設定。
+	if(bh->is_lock){
+		//送信中のメモリブロックなら無視
+		return;
+	}
+
+	//送信中にセット
+	bh->is_lock=NyLPC_TUInt8_TRUE;
+
+	//最大送信サイズの制限
+	if (i_size > ETH_FRAG_SIZE){
+		i_size = ETH_FRAG_SIZE;
+	}
+	Index=_driver.tx_idx;
+
+	updateTxDesc(Index,(uint8_t*)((unsigned char*)i_buf-2),i_size+2,Index==(NUM_OF_TX_RING-1));
+	_driver.tx_idx=(_driver.tx_idx+1)%NUM_OF_TX_RING;
+	return;
+}
+
+/**
+ * 送信キューが空くまで待ちます。
+ * @return
+ * 次に書き込むことが出来る送信キューのIDだけど使わないで
+ */
+static NyLPC_TUInt32 waitForTxEthFrameEmpty(void)
+{
+	int idx;
+	int i;
+	struct NyLPC_TTxBufferHeader *b;
+	volatile void* p;
+	volatile enet_bd_struct_t * bdPtr = (enet_bd_struct_t*)_driver.tx_desc_start_addr;
+
+
+	//送信キューフルが解除されるまで待ち.現在のTQDescがReady状態の間ループ
+	
+	while((bdPtr[_driver.tx_idx].control & kEnetTxBdReady)!=0)
+	{
+		NyLPC_cThread_sleep(10);
+	}
+	//インデクスを起点にReady状態が0のデスクリプタを全て解放(無駄があるけど無視)
+	for(i=0;i<NUM_OF_TX_RING;i++){
+		idx=(_driver.tx_idx+i)%NUM_OF_TX_RING;
+		if((bdPtr[idx].control & kEnetTxBdReady)!=0){
+			//if Ready state then break!
+			break;
+		}
+		bdPtr[idx].control=(bdPtr[idx].control)&(~kEnetTxBdReady);
+		//バッファを参照してたらそいつのロックビットも解放
+		p=(void*)NTOHL(bdPtr[idx].buffer);
+		if(p!=NULL){
+			b=((struct NyLPC_TTxBufferHeader*)p)-1;
+			b->is_lock=NyLPC_TUInt8_FALSE;
+			bdPtr[idx].buffer=0;
+		}
+	}
+	return _driver.tx_idx;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// Ethernet interdface functions
+////////////////////////////////////////////////////////////////////////////////
+
+
+// K64F-specific macros
+#define RX_PBUF_AUTO_INDEX    (-1)
+extern void k64f_init_eth_hardware(void);
+
+
+//static struct k64f_enetdata k64f_enetdata;
+
+static enet_dev_if_t enetDevIf[HW_ENET_INSTANCE_COUNT];
+static enet_mac_config_t g_enetMacCfg[HW_ENET_INSTANCE_COUNT] = 
+{
+  {
+    ENET_ETH_MAX_FLEN ,  /*!< enet receive buffer size*/
+    ENET_RX_LARGE_BUFFER_NUM, /*!< enet large receive buffer number*/
+    NUM_OF_RX_RING,        /*!< enet receive bd number*/
+    NUM_OF_TX_RING,        /*!< enet transmit bd number*/
+    {0},                /*!< enet mac address*/
+    kEnetCfgRmii,       /*!< enet rmii interface*/
+    kEnetCfgSpeed100M,  /*!< enet rmii 100M*/
+    kEnetCfgFullDuplex, /*!< enet rmii Full- duplex*/
+     /*!< enet mac control flag recommended to use enet_mac_control_flag_t
+      we send frame with crc so receive crc forward for data length check test*/
+    kEnetRxCrcFwdEnable | kEnetRxFlowControlEnable,
+    true,         /*!< enet txaccelerator enabled*/
+    true,        /*!< enet rxaccelerator enabled*/
+    false,        /*!< enet store and forward*/
+    {false, false, true, false, true},  /*!< enet rxaccelerator config*/
+    {false, false, true},          /*!< enet txaccelerator config*/
+    true,               /*!< vlan frame support*/
+    true,               /*!< phy auto discover*/
+    ENET_MII_CLOCK,     /*!< enet MDC clock*/
+  },
+};
+static enet_phy_config_t g_enetPhyCfg[HW_ENET_INSTANCE_COUNT] =
+{
+	{0, false}
+};
+
+static NyLPC_TBool k64f_rx_setup(enet_rxbd_config_t *rxbdCfg);
+static NyLPC_TBool k64f_tx_setup(enet_txbd_config_t *txbdCfg);
+
+
+/**
+ * i_idx番目のデスクリプタにバッファをセット
+ */
+static void setRxDesc(void* rx_buf, int idx)
+{
+    enet_bd_struct_t *start = (enet_bd_struct_t *)_driver.rx_desc_start_addr;
+    /* Setup descriptor and clear statuses */
+    enet_hal_init_rxbds(start + idx, (uint8_t*)rx_buf,idx ==(NUM_OF_RX_RING - 1));
+    enet_hal_active_rxbd(BOARD_DEBUG_ENET_INSTANCE);
+}
+static void updateRxDesc(int idx)
+{
+    enet_bd_struct_t *start = (enet_bd_struct_t *)_driver.rx_desc_start_addr;
+    /* Setup descriptor and clear statuses */
+    enet_hal_update_rxbds(start + idx,NULL,false);
+    enet_hal_active_rxbd(BOARD_DEBUG_ENET_INSTANCE);
+}
+static void setTxDesc(int idx)
+{
+    enet_bd_struct_t *start = (enet_bd_struct_t *)_driver.tx_desc_start_addr;
+    /* Setup descriptor and clear statuses */
+    enet_hal_init_txbds(start + idx,idx ==(NUM_OF_RX_RING - 1));
+    enet_hal_active_txbd(BOARD_DEBUG_ENET_INSTANCE);
+}
+
+static void updateTxDesc(int idx, uint8_t *buffer, uint16_t length, bool isLast)
+{
+	volatile enet_bd_struct_t * bdPtr = (enet_bd_struct_t *)(_driver.tx_desc_start_addr + idx * enet_hal_get_bd_size());
+	
+	bdPtr->length = HTONS(length); /* Set data length*/
+	bdPtr->buffer = (uint8_t *)HTONL((uint32_t)buffer); /* Set data buffer*/
+	bdPtr->control |= kEnetTxBdLast;//最終フラグメントのフラグね
+	bdPtr->controlExtend1 |= kEnetTxBdTxInterrupt;
+	bdPtr->controlExtend2 &= ~TX_DESC_UPDATED_MASK; // descriptor not updated by DMA
+	bdPtr->control |= kEnetTxBdTransmitCrc | kEnetTxBdReady;
+	if(isLast){
+		//これはデスクリプタの終了位置のフラグ
+		bdPtr->control |=kEnetTxBdWrap;
+	}
+	enet_hal_active_txbd(BOARD_DEBUG_ENET_INSTANCE);	
+}
+
+static void* ENET_MAC_CONTEXT_BUF=NULL;
+
+/** \brief  Low level init of the MAC and PHY.
+ *
+ *  \param[in]      netif  Pointer to LWIP netif structure
+ */
+NyLPC_TBool low_level_init(const unsigned char* i_ethaddr,int i_addr_len)
+{
+    enet_dev_if_t * enetIfPtr;
+    uint32_t device = BOARD_DEBUG_ENET_INSTANCE;
+    enet_rxbd_config_t rxbdCfg;
+    enet_txbd_config_t txbdCfg;
+    enet_phy_speed_t phy_speed;
+    enet_phy_duplex_t phy_duplex;
+    
+    //RX/TXメモリはデバイス選択時に確保
+    k64f_init_eth_hardware();
+  
+    /* Initialize device*/
+    enetIfPtr = (enet_dev_if_t *)&enetDevIf[device];
+    enetIfPtr->deviceNumber = device;
+    enetIfPtr->macCfgPtr = &g_enetMacCfg[device];
+    enetIfPtr->phyCfgPtr = &g_enetPhyCfg[device];
+    enetIfPtr->macApiPtr = &g_enetMacApi;
+    enetIfPtr->phyApiPtr = (void *)&g_enetPhyApi;
+    //macアドレスのコピー
+    memcpy(enetIfPtr->macCfgPtr->macAddr,(char*)i_ethaddr,i_addr_len);
+	//enetIfPtr->macContextPtrはgetInterface
+	if(ENET_MAC_CONTEXT_BUF!=NULL){
+		free(ENET_MAC_CONTEXT_BUF);
+		ENET_MAC_CONTEXT_BUF=NULL;
+	}
+	ENET_MAC_CONTEXT_BUF=calloc(1, sizeof(enet_mac_context_t));
+	if(ENET_MAC_CONTEXT_BUF==NULL){
+		return NyLPC_TBool_FALSE;//ERR_BUF;
+	}
+	enetIfPtr->macContextPtr = (enet_mac_context_t *)ENET_MAC_CONTEXT_BUF;
+
+	/* Initialize enet buffers*/
+	if(!k64f_rx_setup(&rxbdCfg)) {
+		return NyLPC_TBool_FALSE;//ERR_BUF;
+	}
+	/* Initialize enet buffers*/
+	if(!k64f_tx_setup(&txbdCfg)) {
+		return NyLPC_TBool_FALSE;//ERR_BUF;
+	}
+	/* Initialize enet module*/
+	if (enet_mac_init(enetIfPtr, &rxbdCfg, &txbdCfg) == kStatus_ENET_Success)
+	{
+		/* Initialize PHY*/
+		if (enetIfPtr->macCfgPtr->isPhyAutoDiscover) {
+			if (((enet_phy_api_t *)(enetIfPtr->phyApiPtr))->phy_auto_discover(enetIfPtr) != kStatus_PHY_Success)
+				return NyLPC_TBool_FALSE;//ERR_IF;
+		}
+		if (((enet_phy_api_t *)(enetIfPtr->phyApiPtr))->phy_init(enetIfPtr) != kStatus_PHY_Success)
+			return NyLPC_TBool_FALSE;//ERR_IF;		
+		enetIfPtr->isInitialized = true;
+	}else{
+		// TODOETH: cleanup memory
+		return NyLPC_TBool_FALSE;//ERR_IF;
+	}
+	
+	/* Get link information from PHY */
+	phy_get_link_speed(enetIfPtr, &phy_speed);
+	phy_get_link_duplex(enetIfPtr, &phy_duplex);
+	BW_ENET_RCR_RMII_10T(enetIfPtr->deviceNumber, phy_speed == kEnetSpeed10M ? kEnetCfgSpeed10M : kEnetCfgSpeed100M);
+	BW_ENET_TCR_FDEN(enetIfPtr->deviceNumber, phy_duplex == kEnetFullDuplex ? kEnetCfgFullDuplex : kEnetCfgHalfDuplex);
+	
+	/* Enable Ethernet module*/
+	enet_hal_config_ethernet(device, true, true);
+	
+	/* Active Receive buffer descriptor must be done after module enable*/
+	enet_hal_active_rxbd(enetIfPtr->deviceNumber);
+	enet_hal_active_txbd(enetIfPtr->deviceNumber);
+	
+	return NyLPC_TBool_TRUE;//ERR_OK;
+}
+
+
+static void* RX_DESC_BUF_BASE=NULL;
+
+
+/** \brief  Sets up the RX descriptor ring buffers.
+ *
+ *  This function sets up the descriptor list used for receive packets.
+ *
+ *  \param[in]  netif  Pointer to driver data structure
+ *  \returns    true/false
+ */
+static NyLPC_TBool k64f_rx_setup(enet_rxbd_config_t *rxbdCfg)
+{   
+//    struct k64f_enetdata *k64f_enet = &(netif->state);
+    enet_dev_if_t *enetIfPtr = (enet_dev_if_t *)&enetDevIf[BOARD_DEBUG_ENET_INSTANCE];
+    uint32_t rxBufferSizeAligned;
+    int i;
+
+    // Allocate RX descriptors
+    if(RX_DESC_BUF_BASE!=NULL){
+    	free(RX_DESC_BUF_BASE);
+    	RX_DESC_BUF_BASE=NULL;
+    }
+    RX_DESC_BUF_BASE = (void*)calloc(1, enet_hal_get_bd_size() * enetIfPtr->macCfgPtr->rxBdNumber + ENET_BD_ALIGNMENT);
+    if(RX_DESC_BUF_BASE==NULL){
+        return NyLPC_TBool_FALSE;
+    }
+    //16byteアライメントに修正
+    _driver.rx_desc_start_addr = (uint8_t *)ENET_ALIGN((NyLPC_TUInt32)RX_DESC_BUF_BASE, ENET_BD_ALIGNMENT);
+    rxBufferSizeAligned = ENET_ALIGN(enetIfPtr->macCfgPtr->rxBufferSize, ENET_RX_BUFFER_ALIGNMENT);
+    enetIfPtr->macContextPtr->rxBufferSizeAligned = rxBufferSizeAligned;
+    rxbdCfg->rxBdPtrAlign = _driver.rx_desc_start_addr;
+    rxbdCfg->rxBdNum = enetIfPtr->macCfgPtr->rxBdNumber;
+    rxbdCfg->rxBufferNum = enetIfPtr->macCfgPtr->rxBdNumber;
+    
+    //初期化
+    enet_hal_active_rxbd(BOARD_DEBUG_ENET_INSTANCE);
+    for(i=0;i<NUM_OF_RX_RING;i++){
+        setRxDesc(RX_BUF+(i*SIZE_OF_ETH_PACKET),i);
+    }
+    //  k64f_rx_queue(netif, RX_PBUF_AUTO_INDEX);
+    return NyLPC_TBool_TRUE;
+}
+
+
+
+
+static void* TX_DESC_BUF_BASE=NULL;
+/** \brief  Sets up the TX descriptor ring buffers.
+ *
+ *  This function sets up the descriptor list used for transmit packets.
+ *
+ *  \param[in]      netif  Pointer to driver data structure
+ *  \returns        true/false
+ */
+static NyLPC_TBool k64f_tx_setup(enet_txbd_config_t *txbdCfg)
+{
+	int i;
+
+	enet_dev_if_t *enetIfPtr = (enet_dev_if_t *)&enetDevIf[BOARD_DEBUG_ENET_INSTANCE];
+	
+	// Allocate TX descriptors
+    if(TX_DESC_BUF_BASE!=NULL){
+    	free(TX_DESC_BUF_BASE);
+    	TX_DESC_BUF_BASE=NULL;
+    } 	
+	TX_DESC_BUF_BASE = (void*)calloc(1, enet_hal_get_bd_size() * enetIfPtr->macCfgPtr->txBdNumber + ENET_BD_ALIGNMENT);
+	if(TX_DESC_BUF_BASE==NULL){
+		return NyLPC_TBool_FALSE;
+	}
+	
+	_driver.tx_desc_start_addr = (uint8_t *)ENET_ALIGN((uint32_t)TX_DESC_BUF_BASE, ENET_BD_ALIGNMENT);
+	
+	txbdCfg->txBdPtrAlign = _driver.tx_desc_start_addr;
+	txbdCfg->txBufferNum = enetIfPtr->macCfgPtr->txBdNumber;
+	txbdCfg->txBufferSizeAlign = ENET_ALIGN(enetIfPtr->maxFrameSize, ENET_TX_BUFFER_ALIGNMENT);
+	
+	// Make the TX descriptor ring circular
+	for(i=0;i<NUM_OF_TX_RING;i++){
+		setTxDesc(i);
+	}
+	return NyLPC_TBool_TRUE;
+}
+
+
+//--------------------------------------------------------------------------------
+// ISR
+//--------------------------------------------------------------------------------
+extern IRQn_Type enet_irq_ids[HW_ENET_INSTANCE_COUNT][FSL_FEATURE_ENET_INTERRUPT_COUNT];
+extern uint8_t enetIntMap[kEnetIntNum];
+extern void *enetIfHandle;
+
+static void eth_arch_enable_interrupts(void)
+{
+	enet_hal_config_interrupt(BOARD_DEBUG_ENET_INSTANCE, (kEnetTxFrameInterrupt | kEnetRxFrameInterrupt), true);  
+	interrupt_enable(enet_irq_ids[BOARD_DEBUG_ENET_INSTANCE][enetIntMap[kEnetRxfInt]]);
+	interrupt_enable(enet_irq_ids[BOARD_DEBUG_ENET_INSTANCE][enetIntMap[kEnetTxfInt]]); 
+}
+
+static void eth_arch_disable_interrupts(void)
+{
+	interrupt_disable(enet_irq_ids[BOARD_DEBUG_ENET_INSTANCE][enetIntMap[kEnetRxfInt]]);
+	interrupt_disable(enet_irq_ids[BOARD_DEBUG_ENET_INSTANCE][enetIntMap[kEnetTxfInt]]);  
+}
+void ENET_Transmit_IRQHandler(void)
+{
+//	led(0,-1);
+	enet_hal_clear_interrupt(((enet_dev_if_t *)enetIfHandle)->deviceNumber, kEnetTxFrameInterrupt);
+	_event_handler(_event_param,NyLPC_TiEthernetDevice_EVENT_ON_TX);
+}
+
+void ENET_Receive_IRQHandler(void)
+{
+	enet_hal_clear_interrupt(((enet_dev_if_t *)enetIfHandle)->deviceNumber, kEnetRxFrameInterrupt);
+	_event_handler(_event_param,NyLPC_TiEthernetDevice_EVENT_ON_RX);
+}
+
+
+#endif
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/driver/ethernet/k64f/EtherDev_K64F_protected.h	Wed Oct 01 13:58:53 2014 +0000
@@ -0,0 +1,19 @@
+#ifndef EtherDev_K64F_protected_h
+#define EtherDev_K64F_protected_h
+#include "NyLPC_stdlib.h"
+#include "../NyLPC_IEthernetDevice.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+NyLPC_TBool EthDev_K64F_getInterface(
+	const struct TiEthernetDevice** o_dev);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/driver/ethernet/k64f/fsl/fsl_enet_driver.c	Wed Oct 01 13:58:53 2014 +0000
@@ -0,0 +1,475 @@
+/*
+* Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification,
+* are permitted provided that the following conditions are met:
+*
+* o Redistributions of source code must retain the above copyright notice, this list
+*   of conditions and the following disclaimer.
+*
+* o Redistributions in binary form must reproduce the above copyright notice, this
+*   list of conditions and the following disclaimer in the documentation and/or
+*   other materials provided with the distribution.
+*
+* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+*   contributors may be used to endorse or promote products derived from this
+*   software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* Modified by mbed for the lwIP port */
+#include "NyLPC_config.h"
+#if NyLPC_MCU==NyLPC_MCU_K64F
+#include "fsl_enet_driver.h"
+#include "fsl_enet_hal.h"
+#include "fsl_clock_manager.h"
+#include "fsl_interrupt_manager.h"
+#include <string.h>
+
+//#include "sys_arch.h"
+
+/*******************************************************************************
+ * Variables
+ ******************************************************************************/
+/*! @brief Define ENET's IRQ list */
+
+void *enetIfHandle;
+
+/*! @brief Define MAC driver API structure and for application of stack adaptor layer*/
+const enet_mac_api_t g_enetMacApi = 
+{
+    enet_mac_init,
+    NULL, // enet_mac_deinit,
+    NULL, // enet_mac_send,
+#if !ENET_RECEIVE_ALL_INTERRUPT
+    NULL, // enet_mac_receive,
+#endif
+    enet_mii_read,
+    enet_mii_write,
+    NULL, // enet_mac_add_multicast_group,
+    NULL, //enet_mac_leave_multicast_group,
+};
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+
+// NOTE: we need these functions to be non-blocking fpr the PHY task, hence the
+// osDelay() below
+
+/*FUNCTION****************************************************************
+ *
+ * Function Name: enet_mii_read
+ * Return Value: The execution status.
+ * Description: Read function.
+ * This interface read data over the (R)MII bus from the specified PHY register,
+ * This function is called by all PHY interfaces.
+ *END*********************************************************************/
+uint32_t enet_mii_read(uint32_t instance, uint32_t phyAddr, uint32_t phyReg, uint32_t *dataPtr)
+{
+    uint32_t  counter;
+	
+    /* Check the input parameters*/
+    if (!dataPtr)
+    {
+        return kStatus_ENET_InvalidInput;
+    }
+
+    /* Check if the mii is enabled*/
+    if (!enet_hal_is_mii_enabled(instance))
+    {
+        return kStatus_ENET_Miiuninitialized;
+    }
+
+    /* Clear the MII interrupt event*/
+    enet_hal_clear_interrupt(instance, kEnetMiiInterrupt);
+
+    /* Read command operation*/
+    enet_hal_set_mii_command(instance, phyAddr, phyReg, kEnetReadValidFrame, 0);
+
+    /* Poll for MII complete*/
+    for (counter = 0; counter < kEnetMaxTimeout; counter++)
+    {
+        if (enet_hal_get_interrupt_status(instance, kEnetMiiInterrupt))
+        {
+            break;
+        }	
+        osDelay(1);
+    }
+
+    /* Check for timeout*/
+    if (counter == kEnetMaxTimeout)
+    {
+        return kStatus_ENET_TimeOut;
+    }
+
+    /* Get data from mii register*/
+    *dataPtr = enet_hal_get_mii_data(instance);
+
+    /* Clear MII interrupt event*/
+    enet_hal_clear_interrupt(instance, kEnetMiiInterrupt);
+	
+    return kStatus_ENET_Success;
+}
+
+/*FUNCTION****************************************************************
+ *
+ * Function Name: enet_mii_write
+ * Return Value: The execution status.
+ * Description: Write function.
+ * This interface write data over the (R)MII bus to the specified PHY register.   
+ * This function is called by all PHY interfaces.
+ *END*********************************************************************/
+uint32_t enet_mii_write(uint32_t instance, uint32_t phyAddr, uint32_t phyReg, uint32_t data)
+{
+    uint32_t counter;
+
+    /* Check if the mii is enabled*/
+    if (!enet_hal_is_mii_enabled(instance))
+    {
+        return kStatus_ENET_Miiuninitialized;
+    }
+
+    /* Clear the MII interrupt event*/
+    enet_hal_clear_interrupt(instance, kEnetMiiInterrupt);
+
+    /* Read command operation*/
+    enet_hal_set_mii_command(instance, phyAddr, phyReg, kEnetWriteValidFrame, data);
+
+    /* Poll for MII complete*/
+    for (counter = 0; counter < kEnetMaxTimeout; counter++)
+    {
+        if (enet_hal_get_interrupt_status(instance, kEnetMiiInterrupt))
+        {
+            break;
+        }		
+        osDelay(1);
+    }
+
+    /* Check for timeout*/
+    if (counter == kEnetMaxTimeout)
+    {
+        return kStatus_ENET_TimeOut;
+    }
+
+    /* Clear MII intrrupt event*/
+    enet_hal_clear_interrupt(instance, kEnetMiiInterrupt);
+	
+    return kStatus_ENET_Success;
+}
+/*FUNCTION****************************************************************
+ *
+ * Function Name: enet_mac_mii_init
+ * Return Value: The execution status.
+ * Description:Initialize the ENET Mac mii(mdc/mdio)interface.
+ *END*********************************************************************/
+uint32_t enet_mac_mii_init(enet_dev_if_t * enetIfPtr)
+{
+    uint32_t frequency;
+	
+    /* Check the input parameters*/
+    if (enetIfPtr == NULL)
+    {
+        return kStatus_ENET_InvalidInput;
+    }   
+
+    /* Configure mii speed*/
+    clock_manager_get_frequency(kSystemClock, &frequency);
+    enet_hal_config_mii(enetIfPtr->deviceNumber, (frequency/(2 * enetIfPtr->macCfgPtr->miiClock) + 1), 
+                 kEnetMdioHoldOneClkCycle, false);
+
+    return kStatus_ENET_Success;
+}
+
+/*FUNCTION****************************************************************
+ *
+ * Function Name: enet_mac_rxbd_init
+ * Return Value: The execution status.
+ * Description:Initialize the ENET receive buffer descriptors.
+ * Note: If you do receive on receive interrupt handler the receive 
+ * data buffer number can be the same as the receive descriptor numbers. 
+ * But if you are polling receive frames please make sure the receive data 
+ * buffers are more than buffer descriptors to guarantee a good performance.
+ *END*********************************************************************/
+uint32_t enet_mac_rxbd_init(enet_dev_if_t * enetIfPtr, enet_rxbd_config_t *rxbdCfg)
+{
+    /* Check the input parameters*/
+    if ((!enetIfPtr) || (!rxbdCfg))
+    {
+        return kStatus_ENET_InvalidInput;
+    }
+
+    enetIfPtr->macContextPtr->bufferdescSize = enet_hal_get_bd_size();
+
+    /* Initialize the bd status*/
+    enetIfPtr->macContextPtr->isRxFull = false;
+		
+    /* Initialize receive bd base address and current address*/
+    enetIfPtr->macContextPtr->rxBdBasePtr = rxbdCfg->rxBdPtrAlign;
+    enetIfPtr->macContextPtr->rxBdCurPtr = enetIfPtr->macContextPtr->rxBdBasePtr;
+    enetIfPtr->macContextPtr->rxBdDirtyPtr = enetIfPtr->macContextPtr->rxBdBasePtr;	
+    enet_hal_set_rxbd_address(enetIfPtr->deviceNumber, (uint32_t)(enetIfPtr->macContextPtr->rxBdBasePtr));
+	
+    return kStatus_ENET_Success;
+}
+
+/*FUNCTION****************************************************************
+ *
+ * Function Name: enet_mac_txbd_init
+ * Return Value: The execution status.
+ * Description:Initialize the ENET transmit buffer descriptors.
+ * This function prepare all of the transmit buffer descriptors.
+ *END*********************************************************************/
+uint32_t enet_mac_txbd_init(enet_dev_if_t * enetIfPtr, enet_txbd_config_t *txbdCfg)
+{
+    /* Check the input parameters*/
+    if ((!enetIfPtr) || (!txbdCfg))
+    {
+        return kStatus_ENET_InvalidInput;
+    }
+
+    /* Initialize the bd status*/
+    enetIfPtr->macContextPtr->isTxFull = false;
+
+    /* Initialize transmit bd base address and current address*/
+    enetIfPtr->macContextPtr->txBdBasePtr = txbdCfg->txBdPtrAlign;
+    enetIfPtr->macContextPtr->txBdCurPtr = enetIfPtr->macContextPtr->txBdBasePtr;
+    enetIfPtr->macContextPtr->txBdDirtyPtr = enetIfPtr->macContextPtr->txBdBasePtr;
+    enet_hal_set_txbd_address(enetIfPtr->deviceNumber, (uint32_t)(enetIfPtr->macContextPtr->txBdBasePtr));
+    return kStatus_ENET_Success;
+}
+
+/*FUNCTION****************************************************************
+ *
+ * Function Name: enet_mac_configure_fifo_accel
+ * Return Value: The execution status.
+ * Description: Configure the ENET FIFO and Accelerator.
+ *END*********************************************************************/
+uint32_t enet_mac_configure_fifo_accel(enet_dev_if_t * enetIfPtr)
+{
+    enet_config_rx_fifo_t rxFifo;
+    enet_config_tx_fifo_t txFifo;
+	
+    /* Check the input parameters*/
+    if (!enetIfPtr)
+    {
+        return kStatus_ENET_InvalidInput;
+    }
+		
+		/* Initialize values that will not be initialized later on */
+    rxFifo.rxEmpty = 0;
+    rxFifo.rxFull = 0;
+    txFifo.isStoreForwardEnabled = 0;
+    txFifo.txFifoWrite = 0;
+    txFifo.txEmpty = 0;
+
+    /* Configure tx/rx accelerator*/
+    if (enetIfPtr->macCfgPtr->isRxAccelEnabled)
+    {
+        enet_hal_config_rx_accelerator(enetIfPtr->deviceNumber, 
+           (enet_config_rx_accelerator_t *)&(enetIfPtr->macCfgPtr->rxAcceler));
+        if ((enetIfPtr->macCfgPtr->rxAcceler.isIpcheckEnabled) || (enetIfPtr->macCfgPtr->rxAcceler.isProtocolCheckEnabled))
+        {
+            rxFifo.rxFull = 0;
+        }
+    }
+    if (enetIfPtr->macCfgPtr->isTxAccelEnabled)
+    {
+        enet_hal_config_tx_accelerator(enetIfPtr->deviceNumber, 
+            (enet_config_tx_accelerator_t *)&(enetIfPtr->macCfgPtr->txAcceler));
+        if ((enetIfPtr->macCfgPtr->txAcceler.isIpCheckEnabled) || (enetIfPtr->macCfgPtr->txAcceler.isProtocolCheckEnabled))
+        {
+            txFifo.isStoreForwardEnabled = 1;
+        }
+    }
+    if (enetIfPtr->macCfgPtr->isStoreAndFwEnabled)
+    {
+          rxFifo.rxFull = 0;
+          txFifo.isStoreForwardEnabled = 1;
+    }
+
+
+    /* Set TFWR value if STRFWD is not being used  */		
+    if (txFifo.isStoreForwardEnabled == 1)
+          txFifo.txFifoWrite = 0;
+    else
+          /* TFWR value is a trade-off between transmit latency and risk of transmit FIFO underrun due to contention for the system bus
+		      TFWR = 15 means transmission will begin once 960 bytes has been written to the Tx FIFO (for frames larger than 960 bytes)
+          See Section 45.4.18 - Transmit FIFO Watermark Register of the K64F Reference Manual for details		*/
+          txFifo.txFifoWrite = 15;
+		
+    /* Configure tx/rx FIFO with default value*/
+    rxFifo.rxAlmostEmpty = 4;
+    rxFifo.rxAlmostFull = 4;
+    txFifo.txAlmostEmpty = 4;
+    txFifo.txAlmostFull = 8;
+    enet_hal_config_rx_fifo(enetIfPtr->deviceNumber, &rxFifo);
+    enet_hal_config_tx_fifo(enetIfPtr->deviceNumber, &txFifo); 
+
+    return kStatus_ENET_Success;
+}
+
+/*FUNCTION****************************************************************
+ *
+ * Function Name: enet_mac_configure_controller
+ * Return Value: The execution status.
+ * Description: Configure the ENET controller with the basic configuration.
+ *END*********************************************************************/
+uint32_t enet_mac_configure_controller(enet_dev_if_t * enetIfPtr)
+{
+    uint32_t macCtlCfg;
+
+    /* Check the input parameters*/
+    if (enetIfPtr == NULL)
+    {
+        return kStatus_ENET_InvalidInput;
+    }   
+
+    macCtlCfg = enetIfPtr->macCfgPtr->macCtlConfigure;	
+    /* Configure rmii/mii interface*/
+    enet_hal_config_rmii(enetIfPtr->deviceNumber, enetIfPtr->macCfgPtr->rmiiCfgMode, 
+        enetIfPtr->macCfgPtr->speed, enetIfPtr->macCfgPtr->duplex, false, 
+        (macCtlCfg & kEnetRxMiiLoopback));
+     /* Configure receive buffer size*/
+    if (enetIfPtr->macCfgPtr->isVlanEnabled)
+    {
+        enetIfPtr->maxFrameSize = kEnetMaxFrameVlanSize;
+        enet_hal_set_rx_max_size(enetIfPtr->deviceNumber, 
+              enetIfPtr->macContextPtr->rxBufferSizeAligned, kEnetMaxFrameVlanSize);
+    }
+    else
+    {   
+        enetIfPtr->maxFrameSize = kEnetMaxFrameSize;
+        enet_hal_set_rx_max_size(enetIfPtr->deviceNumber, 
+              enetIfPtr->macContextPtr->rxBufferSizeAligned, kEnetMaxFrameSize); 
+    }
+
+	/* Set receive controller promiscuous */
+    enet_hal_config_promiscuous(enetIfPtr->deviceNumber, macCtlCfg & kEnetRxPromiscuousEnable);
+    /* Set receive flow control*/
+    enet_hal_enable_flowcontrol(enetIfPtr->deviceNumber, (macCtlCfg & kEnetRxFlowControlEnable));
+    /* Set received PAUSE frames are forwarded/terminated*/
+    enet_hal_enable_pauseforward(enetIfPtr->deviceNumber, (macCtlCfg & kEnetRxPauseFwdEnable));
+    /* Set receive broadcast frame reject*/
+    enet_hal_enable_broadcastreject(enetIfPtr->deviceNumber, (macCtlCfg & kEnetRxBcRejectEnable));
+    /* Set padding is removed from the received frame*/
+    enet_hal_enable_padremove(enetIfPtr->deviceNumber, (macCtlCfg & kEnetRxPadRemoveEnable));
+    /* Set the crc of the received frame is stripped from the frame*/
+    enet_hal_enable_rxcrcforward(enetIfPtr->deviceNumber, (macCtlCfg & kEnetRxCrcFwdEnable));
+    /* Set receive payload length check*/
+    enet_hal_enable_payloadcheck(enetIfPtr->deviceNumber, (macCtlCfg & kEnetPayloadlenCheckEnable));
+    /* Set control sleep mode*/
+    enet_hal_enable_sleep(enetIfPtr->deviceNumber, (macCtlCfg & kEnetSleepModeEnable));
+    return kStatus_ENET_Success;
+}
+
+/*FUNCTION****************************************************************
+ *
+ * Function Name: enet_mac_init
+ * Return Value: The execution status.
+ * Description:Initialize the ENET device with the basic configuration
+ * When ENET is used, this function need to be called by the NET initialize 
+ * interface.
+ *END*********************************************************************/
+uint32_t enet_mac_init(enet_dev_if_t * enetIfPtr, enet_rxbd_config_t *rxbdCfg,
+                            enet_txbd_config_t *txbdCfg)
+{   
+    uint32_t timeOut = 0;
+    uint32_t devNumber, result = 0; 
+	
+    /* Check the input parameters*/
+    if (enetIfPtr == NULL)
+    {
+        return kStatus_ENET_InvalidInput;
+    }
+
+    /* Get device number and check the parameter*/
+    devNumber = enetIfPtr->deviceNumber;
+
+    /* Store the global ENET structure for ISR input parameters for instance 0*/
+    if (!devNumber)
+    {
+        enetIfHandle = enetIfPtr;
+    }
+
+    /* Turn on ENET module clock gate */
+    clock_manager_set_gate(kClockModuleENET, 0U, true);
+
+    /* Reset ENET mac*/
+    enet_hal_reset_ethernet(devNumber);
+    while ((!enet_hal_is_reset_completed(devNumber)) && (timeOut < kEnetMaxTimeout))
+    {
+        time_delay(1);
+        timeOut++;
+    }
+
+    /* Check out if timeout*/
+    if (timeOut == kEnetMaxTimeout)
+    {
+        return kStatus_ENET_TimeOut;
+    }
+	
+    /* Disable all ENET mac interrupt and Clear all interrupt events*/
+    enet_hal_config_interrupt(devNumber, kEnetAllInterrupt, false);
+    enet_hal_clear_interrupt(devNumber, kEnetAllInterrupt);
+	
+    /* Program this station's physical address*/
+    enet_hal_set_mac_address(devNumber, enetIfPtr->macCfgPtr->macAddr);
+
+    /* Clear group and individual hash register*/
+    enet_hal_set_group_hashtable(devNumber, 0, kEnetSpecialAddressInit);
+    enet_hal_set_individual_hashtable(devNumber, 0, kEnetSpecialAddressInit);
+
+	  /* Configure mac controller*/
+    result = enet_mac_configure_controller(enetIfPtr);
+    if(result != kStatus_ENET_Success)
+    {
+        return result;
+    }
+    /* Clear mib zero counters*/
+    enet_hal_clear_mib(devNumber, true);
+
+    /* Initialize FIFO and accelerator*/
+    result = enet_mac_configure_fifo_accel(enetIfPtr);
+    if(result != kStatus_ENET_Success)
+    {
+        return result;
+    }
+    /* Initialize receive buffer descriptors*/
+    result = enet_mac_rxbd_init(enetIfPtr, rxbdCfg);
+    if(result != kStatus_ENET_Success)
+    {
+        return result;
+    }
+    /* Initialize transmit buffer descriptors*/
+	  result = enet_mac_txbd_init(enetIfPtr, txbdCfg);
+    if(result != kStatus_ENET_Success)
+    {
+        return result;
+    }	
+    /* Initialize rmii/mii interface*/
+    result = enet_mac_mii_init(enetIfPtr);
+    if (result != kStatus_ENET_Success)
+    {
+        return result;
+    }
+    
+    return kStatus_ENET_Success;
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+
+#endif
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/driver/ethernet/k64f/fsl/hardware_init_MK64F12.c	Wed Oct 01 13:58:53 2014 +0000
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ *   of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ *   list of conditions and the following disclaimer in the documentation and/or
+ *   other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ *   contributors may be used to endorse or promote products derived from this
+ *   software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "NyLPC_config.h"
+#if NyLPC_MCU==NyLPC_MCU_K64F
+#include "fsl_port_hal.h"
+#include "fsl_clock_manager.h"
+#include "fsl_device_registers.h"
+#include "fsl_sim_hal.h"
+
+/*******************************************************************************
+ * Code
+ ******************************************************************************/
+void k64f_init_eth_hardware(void)
+{
+    uint8_t count;
+
+    /* Disable the mpu*/
+    BW_MPU_CESR_VLD(0);
+    
+    /* Open POTR clock gate*/
+    for (count = 0; count < HW_PORT_INSTANCE_COUNT; count++)
+    {
+        clock_manager_set_gate(kClockModulePORT, count, true);
+    }
+
+    /* Configure gpio*/
+    port_hal_mux_control(HW_PORTA, 12, kPortMuxAlt4);  /*!< ENET RMII0_RXD1/MII0_RXD1*/
+    port_hal_mux_control(HW_PORTA, 13, kPortMuxAlt4);  /*!< ENET RMII0_RXD0/MII0_RXD0*/
+    port_hal_mux_control(HW_PORTA, 14, kPortMuxAlt4);  /*!< ENET RMII0_CRS_DV/MII0_RXDV*/
+    port_hal_mux_control(HW_PORTA, 15, kPortMuxAlt4);  /*!< ENET RMII0_TXEN/MII0_TXEN*/
+    port_hal_mux_control(HW_PORTA, 16, kPortMuxAlt4);  /*!< ENET RMII0_TXD0/MII0_TXD0*/
+    port_hal_mux_control(HW_PORTA, 17, kPortMuxAlt4);  /*!< ENET RMII0_TXD01/MII0_TXD1*/
+    port_hal_mux_control(HW_PORTB, 0, kPortMuxAlt4);   /*!< ENET RMII0_MDIO/MII0_MDIO*/
+    port_hal_configure_open_drain(HW_PORTB,0, true);   /*!< ENET RMII0_MDC/MII0_MDC*/
+
+    // Added for FRDM-K64F
+    port_hal_pull_select(HW_PORTB, 0, kPortPullUp);
+    port_hal_configure_pull(HW_PORTB, 0, true);
+  
+    port_hal_mux_control(HW_PORTB, 1, kPortMuxAlt4);
+    /* Configure GPIO for MII interface */
+    port_hal_mux_control(HW_PORTA, 9, kPortMuxAlt4);   /*!< ENET MII0_RXD3*/
+    port_hal_mux_control(HW_PORTA, 10, kPortMuxAlt4);   /*!< ENET MII0_RXD2*/
+    port_hal_mux_control(HW_PORTA, 11, kPortMuxAlt4);   /*!< ENET MII0_RXCLK*/
+    port_hal_mux_control(HW_PORTA, 24, kPortMuxAlt4);   /*!< ENET MII0_TXD2*/
+    port_hal_mux_control(HW_PORTA, 25, kPortMuxAlt4);   /*!< ENET MII0_TXCLK*/
+    port_hal_mux_control(HW_PORTA, 26, kPortMuxAlt4);   /*!< ENET MII0_TXD3*/
+    port_hal_mux_control(HW_PORTA, 27, kPortMuxAlt4);   /*!< ENET MII0_CRS*/
+    port_hal_mux_control(HW_PORTA, 28, kPortMuxAlt4);   /*!< ENET MII0_TXER*/
+    port_hal_mux_control(HW_PORTA, 29, kPortMuxAlt4);   /*!< ENET MII0_COL*/  
+#if FSL_FEATURE_ENET_SUPPORT_PTP
+    port_hal_mux_control(HW_PORTC, (16 + ENET_TIMER_CHANNEL_NUM), kPortMuxAlt4); /* ENET ENET0_1588_TMR0*/
+    port_hal_configure_drive_strength(HW_PORTC, (16 + ENET_TIMER_CHANNEL_NUM), kPortHighDriveStrength); 
+#endif
+
+    /* Open ENET clock gate*/
+    clock_manager_set_gate(kClockModuleENET,0,true);
+
+    /* Select the ptp timer  outclk*/
+    clock_hal_set_clock_source(kSimClockTimeSrc, 2);
+}
+
+/*******************************************************************************
+ * EOF
+ ******************************************************************************/
+#endif
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/driver/ethernet/k64f/k64f_emac_config.h	Wed Oct 01 13:58:53 2014 +0000
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice, this list
+ *   of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice, this
+ *   list of conditions and the following disclaimer in the documentation and/or
+ *   other materials provided with the distribution.
+ *
+ * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
+ *   contributors may be used to endorse or promote products derived from this
+ *   software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef K64F_EMAC_CONFIG_H__
+#define K64F_EMAC_CONFIG_H__
+ 
+//#define ENET_RX_RING_LEN              (16)
+//#define ENET_TX_RING_LEN              (8)
+#define ENET_RX_LARGE_BUFFER_NUM      (0)
+#define ENET_RX_BUFFER_ALIGNMENT      (16)  
+#define ENET_TX_BUFFER_ALIGNMENT      (16)
+#define ENET_BD_ALIGNMENT             (16)
+#define ENET_MII_CLOCK                (2500000L)
+#define RX_BUF_ALIGNMENT              (16)
+#define TX_BUF_ALIGNMENT              (8)
+#define BOARD_DEBUG_ENET_INSTANCE     (0)
+
+#define ENET_ETH_MAX_FLEN             (1522) // recommended size for a VLAN frame
+
+#endif // #define K64F_EMAC_CONFIG_H__
+
+
--- a/core/driver/ethernet/lpc17xx/EthDev_LPC17xx.c	Sat Sep 27 13:33:26 2014 +0000
+++ b/core/driver/ethernet/lpc17xx/EthDev_LPC17xx.c	Wed Oct 01 13:58:53 2014 +0000
@@ -69,14 +69,14 @@
 	{
 		p=(void*)TX_DESC_PACKET(i);
 		if(p!=NULL){
-			b=((struct NyLPC_TTxBufferHeader*)p)-1;
+			b=NyLPC_TTxBufferHeader_getBufferHeaderAddr(p);
 			b->is_lock=NyLPC_TUInt8_FALSE;
 			TX_DESC_PACKET(i)=0;
 		}
 	}
 	p=(void*)TX_DESC_PACKET(i);
 	if(p!=NULL){
-		b=((struct NyLPC_TTxBufferHeader*)p)-1;
+		b=NyLPC_TTxBufferHeader_getBufferHeaderAddr(p);
 		b->is_lock=NyLPC_TUInt8_FALSE;
 		TX_DESC_PACKET(i)=0;
 	}
@@ -90,7 +90,7 @@
 
 /**
  * Ethernetパケットを送信します。
- * allocTxBufで得たバッファか、NyLPC_TTxBufferHeaderのペイロード部分を指定すること。
+ * allocTxBufで得たバッファを指定すること。
  * <p>関数仕様</p>
  * この関数は、i_bufが
  * </div>
@@ -123,7 +123,7 @@
 	}
 
 	//送信処理
-	TX_DESC_PACKET( Index ) = ( unsigned long )(bh+1);
+	TX_DESC_PACKET( Index ) = ( unsigned long )i_buf;
 	//See UM10360.pdf Table 181. Transmit descriptor control word
 	TX_DESC_CTRL( Index ) = ((i_size-1) | TCTRL_LAST | TCTRL_INT );
 	LPC_EMAC->TxProduceIndex = IndexNext;
--- a/core/driver/ethernet/lpc17xx/EtherDev_DP83848C.c	Sat Sep 27 13:33:26 2014 +0000
+++ b/core/driver/ethernet/lpc17xx/EtherDev_DP83848C.c	Wed Oct 01 13:58:53 2014 +0000
@@ -136,8 +136,8 @@
 
 static NyLPC_TBool start(const struct NyLPC_TEthAddr* i_eth_addr,NyLPC_TiEthernetDevice_onEvent i_handler,void* i_param);
 static void stop(void);
-static struct NyLPC_TTxBufferHeader* allocTxBuf(NyLPC_TUInt16 i_hint,NyLPC_TUInt16* o_size);
-static void releaseTxBuf(struct NyLPC_TTxBufferHeader* i_buf);
+static void* allocTxBuf(NyLPC_TUInt16 i_hint,NyLPC_TUInt16* o_size);
+static void releaseTxBuf(void* i_buf);
 /*-----------------------------------------------------------*/
 #define ETH_TX_BUF_BASE (void*)(ETH_BUF_BASE+ETH_FRAG_SIZE*NUM_RX_FRAG)
 
@@ -255,11 +255,11 @@
     return;
 }
 
-static struct NyLPC_TTxBufferHeader* allocTxBuf(NyLPC_TUInt16 i_hint,NyLPC_TUInt16* o_size)
+static void* allocTxBuf(NyLPC_TUInt16 i_hint,NyLPC_TUInt16* o_size)
 {
 	return NyLPC_cEthernetMM_alloc(i_hint,o_size);
 }
-static void releaseTxBuf(struct NyLPC_TTxBufferHeader* i_buf)
+static void releaseTxBuf(void* i_buf)
 {
 	NyLPC_cEthernetMM_release(i_buf);
 }
--- a/core/driver/ethernet/lpc4088/EthDev_LPC4088.c	Sat Sep 27 13:33:26 2014 +0000
+++ b/core/driver/ethernet/lpc4088/EthDev_LPC4088.c	Wed Oct 01 13:58:53 2014 +0000
@@ -49,9 +49,9 @@
 static void stop(void);
 static void* getRxEthFrame(unsigned short* o_len_of_data);
 static void nextRxEthFrame(void);
-static struct NyLPC_TTxBufferHeader* allocTxBuf(NyLPC_TUInt16 i_hint,NyLPC_TUInt16* o_size);
-static void releaseTxBuf(struct NyLPC_TTxBufferHeader* i_buf);
-static void sendTxEthFrame(struct NyLPC_TTxBufferHeader* i_buf,unsigned short i_size);
+static struct void* allocTxBuf(NyLPC_TUInt16 i_hint,NyLPC_TUInt16* o_size);
+static void releaseTxBuf(void* i_buf);
+static void sendTxEthFrame(void* i_buf,unsigned short i_size);
 static void processTx(void);
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -253,11 +253,11 @@
 	NyLPC_cEthernetMM_finalize();
 }
 
-static struct NyLPC_TTxBufferHeader* allocTxBuf(NyLPC_TUInt16 i_hint,NyLPC_TUInt16* o_size)
+static void* allocTxBuf(NyLPC_TUInt16 i_hint,NyLPC_TUInt16* o_size)
 {
 	return NyLPC_cEthernetMM_alloc(i_hint,o_size);
 }
-static void releaseTxBuf(struct NyLPC_TTxBufferHeader* i_buf)
+static void releaseTxBuf(void* i_buf)
 {
 	NyLPC_cEthernetMM_release(i_buf);
 }
@@ -274,14 +274,15 @@
 
 /**
  * Ethernetパケットを送信します。
- * allocTxBufで得たバッファか、NyLPC_TTxBufferHeaderのペイロード部分を指定すること。
+ * allocTxBufで得たバッファを指定すること。
  * <p>関数仕様</p>
  * この関数は、i_bufが
  * </div>
  */
-static void sendTxEthFrame(struct NyLPC_TTxBufferHeader* i_buf,unsigned short i_size)
+static void sendTxEthFrame(void* i_buf,unsigned short i_size)
 {
 	NyLPC_TUInt32	IndexNext,Index;
+	struct NyLPC_TTxBufferHeader* bh=NyLPC_TTxBufferHeader_getBufferHeaderAddr(i_buf);
 
 	//サイズ0なら送信の必要なし
 	if(i_size == 0)
@@ -294,11 +295,11 @@
 	//送信対象のメモリブロックを送信中に設定。
 //	b=(i_buf+1);
 	//送信中のメモリブロックなら無視
-	if(i_buf->is_lock){
+	if(bh->is_lock){
 		return;
 	}
 	//送信中にセット
-	i_buf->is_lock=NyLPC_TUInt8_TRUE;
+	bh->is_lock=NyLPC_TUInt8_TRUE;
 
 	//送信データのセット
 	Index = LPC_EMAC->TxProduceIndex;
@@ -306,7 +307,7 @@
 		i_size = ETH_FRAG_SIZE;
 	}
 	//送信処理
-	TX_DESC_PACKET( Index ) = ( unsigned long )(i_buf+1);
+	TX_DESC_PACKET( Index ) = ( unsigned long )i_buf;
 	//See UM10360.pdf Table 181. Transmit descriptor control word
 	TX_DESC_CTRL( Index ) = ((i_size-1) | TCTRL_LAST | TCTRL_INT );
 	LPC_EMAC->TxProduceIndex = IndexNext;
@@ -423,14 +424,14 @@
 	{
 		p=(void*)TX_DESC_PACKET(i);
 		if(p!=NULL){
-			b=((struct NyLPC_TTxBufferHeader*)p)-1;
+			b=NyLPC_TTxBufferHeader_getBufferHeaderAddr(p);
 			b->is_lock=NyLPC_TUInt8_FALSE;
 			TX_DESC_PACKET(i)=0;
 		}
 	}
 	p=(void*)TX_DESC_PACKET(i);
 	if(p!=NULL){
-		b=((struct NyLPC_TTxBufferHeader*)p)-1;
+		b=NyLPC_TTxBufferHeader_getBufferHeaderAddr(p);
 		b->is_lock=NyLPC_TUInt8_FALSE;
 		TX_DESC_PACKET(i)=0;
 	}
--- a/core/driver/flash/LPC17xx_IAP.c	Sat Sep 27 13:33:26 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,124 +0,0 @@
-/*
- * LPC17xx_IAP.c
- *
- *  Created on: 2011/10/17
- *      Author: nyatla
- */
-
-#include "LPC17xx_IAP.h"
-
-/**
- * IPAに通知するCPUクロック。
- * ここで指定したクロック以上で動作させないでください。
- */
-#define IPA_CPU_FREQ_IN_HZ ( ( unsigned long ) 100000000 )
-#define LPC17xx_FLASH_SECTOR_ADDR_16 ((void*)0x00010000)
-
-//Define data structure or pointers to pass IAP command table and result table to the IAP
-#define IAP_LOCATION 0x1FFF1FF1;
-/**
- * @param command
- *
- * @param result
- */
-typedef void (*_LPCXpresso_IAP_FUNC)(unsigned long command[],unsigned long result[]);
-/**
- *
- */
-_LPCXpresso_IAP_FUNC LPCXpresso_iap_entry=(_LPCXpresso_IAP_FUNC) IAP_LOCATION;
-
-
-/**
- * アドレスをフラッシュメモリのセクタ番号へ変換する。
- */
-int LPC17xx_IAP_addr2Sector(const void* addr,unsigned long* o_sector)
-{
-    unsigned long t;
-    if(addr>=LPC17xx_FLASH_SECTOR_ADDR_16){
-        t=((((unsigned long)addr)-((unsigned long)LPC17xx_FLASH_SECTOR_ADDR_16))/0x8000)+16;
-        if(t>29){
-            return LPC17xx_IAP_FALSE;//Error
-        }
-        *o_sector=t;
-    }else{
-        *o_sector=((unsigned long)addr)/0x1000;
-    }
-    return LPC17xx_IAP_TRUE;//Error
-}
-/**
- * セクタ番号をフラッシュメモリのアドレスへ変換する。
- */
-int LPC17xx_IAP_sector2Addr(unsigned int i_sector,void** o_addr)
-{
-    if(i_sector<16){
-        *o_addr=(void*)(0x1000*i_sector);
-    }else if(i_sector>29){
-        return LPC17xx_IAP_FALSE;
-    }else{
-        *o_addr=(void*)(((unsigned int)LPC17xx_FLASH_SECTOR_ADDR_16)+(i_sector-16)*0x8000);
-    }
-    return LPC17xx_IAP_TRUE;
-}
-
-
-unsigned long LPC17xx_IAP_getSectorSize(unsigned int i_sector)
-{
-    if(i_sector<16){
-        return 0x1000;
-    }else if(i_sector>29){
-        return 0;
-    }else{
-        return 0x8000;
-    }
-}
-/**
- * IAPのprepareコマンドを実行
- */
-unsigned long LPC17xx_IAP_prepare(unsigned long i_start,unsigned long i_end)
-{
-    unsigned long b[8];
-    unsigned long c[5];
-    unsigned long r[5];
-    c[0]=50;
-    c[1]=i_start;
-    c[2]=i_end;
-    memcpy(b,(void*)0x10000000,32);
-    LPCXpresso_iap_entry(c,r);
-    memcpy((void*)0x10000000,b,32);
-    return r[0];
-}
-/**
- * IAPのcopy ram to flashコマンドを実行。
- */
-unsigned long LPC17xx_IAP_copyRam2Flash(const void* i_flash_addr,const void* i_src_addr,unsigned long i_size)
-{
-    unsigned long b[8];
-    unsigned long c[5];
-    unsigned long r[5];
-    c[0]=51;
-    c[1]=(unsigned long)i_flash_addr;
-    c[2]=(unsigned long)i_src_addr;
-    c[3]=i_size;
-    c[4]=IPA_CPU_FREQ_IN_HZ/1000;
-    memcpy(b,(void*)0x10000000,32);
-    LPCXpresso_iap_entry(c,r);
-    memcpy((void*)0x10000000,b,32);
-    return r[0];
-}
-/**
- * IAPのeraseコマンドを実行
- */
-unsigned long LPC17xx_IAP_erase(unsigned long i_start,unsigned long i_end)
-{
-    unsigned long b[8];
-    unsigned long c[5];
-    unsigned long r[5];
-    c[0]=52;
-    c[1]=i_start;
-    c[2]=i_end;
-    c[3]=IPA_CPU_FREQ_IN_HZ/1000;
-    memcpy(b,(void*)0x10000000,32);
-    LPCXpresso_iap_entry(c,r);
-    memcpy((void*)0x10000000,b,32);
-    return r[0];
-}
--- a/core/driver/flash/LPC17xx_IAP.h	Sat Sep 27 13:33:26 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-#ifndef LPC17xx_IAP_h
-#define LPC17xx_IAP_h
-
-#include <string.h>
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
-#define LPC17xx_IAP_TRUE (0==0)
-#define LPC17xx_IAP_FALSE (0!=0)
-//Command is executed successfully.
-#define LPC17xx_IAP_CMD_SUCCESS 0
-
-int LPC17xx_IAP_addr2Sector(const void* addr,unsigned long* o_sector);
-int LPC17xx_IAP_sector2Addr(unsigned int i_sector,void** o_addr);
-
-unsigned long LPC17xx_IAP_getSectorSize(unsigned int i_sector);
-unsigned long LPC17xx_IAP_prepare(unsigned long i_start,unsigned long i_end);
-unsigned long LPC17xx_IAP_copyRam2Flash(const void* i_flash_addr,const void* i_src_addr,unsigned long i_size);
-unsigned long LPC17xx_IAP_erase(unsigned long i_start,unsigned long i_end);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/driver/flash/LPCxxx/LPC17xx_IAP.c	Wed Oct 01 13:58:53 2014 +0000
@@ -0,0 +1,126 @@
+/*
+ * LPC17xx_IAP.c
+ *
+ *  Created on: 2011/10/17
+ *      Author: nyatla
+ */
+#include "NyLPC_config.h"
+#if NyLPC_MCU==NyLPC_MCU_LPC4088 || NyLPC_MCU==NyLPC_MCU_LPC17xx
+
+#include "LPC17xx_IAP.h"
+/**
+ * IPAに通知するCPUクロック。
+ * ここで指定したクロック以上で動作させないでください。
+ */
+#define IPA_CPU_FREQ_IN_HZ ( ( unsigned long ) 100000000 )
+#define LPC17xx_FLASH_SECTOR_ADDR_16 ((void*)0x00010000)
+
+//Define data structure or pointers to pass IAP command table and result table to the IAP
+#define IAP_LOCATION 0x1FFF1FF1;
+/**
+ * @param command
+ *
+ * @param result
+ */
+typedef void (*_LPCXpresso_IAP_FUNC)(unsigned long command[],unsigned long result[]);
+/**
+ *
+ */
+_LPCXpresso_IAP_FUNC LPCXpresso_iap_entry=(_LPCXpresso_IAP_FUNC) IAP_LOCATION;
+
+
+/**
+ * アドレスをフラッシュメモリのセクタ番号へ変換する。
+ */
+int LPC17xx_IAP_addr2Sector(const void* addr,unsigned long* o_sector)
+{
+    unsigned long t;
+    if(addr>=LPC17xx_FLASH_SECTOR_ADDR_16){
+        t=((((unsigned long)addr)-((unsigned long)LPC17xx_FLASH_SECTOR_ADDR_16))/0x8000)+16;
+        if(t>29){
+            return LPC17xx_IAP_FALSE;//Error
+        }
+        *o_sector=t;
+    }else{
+        *o_sector=((unsigned long)addr)/0x1000;
+    }
+    return LPC17xx_IAP_TRUE;//Error
+}
+/**
+ * セクタ番号をフラッシュメモリのアドレスへ変換する。
+ */
+int LPC17xx_IAP_sector2Addr(unsigned int i_sector,void** o_addr)
+{
+    if(i_sector<16){
+        *o_addr=(void*)(0x1000*i_sector);
+    }else if(i_sector>29){
+        return LPC17xx_IAP_FALSE;
+    }else{
+        *o_addr=(void*)(((unsigned int)LPC17xx_FLASH_SECTOR_ADDR_16)+(i_sector-16)*0x8000);
+    }
+    return LPC17xx_IAP_TRUE;
+}
+
+
+unsigned long LPC17xx_IAP_getSectorSize(unsigned int i_sector)
+{
+    if(i_sector<16){
+        return 0x1000;
+    }else if(i_sector>29){
+        return 0;
+    }else{
+        return 0x8000;
+    }
+}
+/**
+ * IAPのprepareコマンドを実行
+ */
+unsigned long LPC17xx_IAP_prepare(unsigned long i_start,unsigned long i_end)
+{
+    unsigned long b[8];
+    unsigned long c[5];
+    unsigned long r[5];
+    c[0]=50;
+    c[1]=i_start;
+    c[2]=i_end;
+    memcpy(b,(void*)0x10000000,32);
+    LPCXpresso_iap_entry(c,r);
+    memcpy((void*)0x10000000,b,32);
+    return r[0];
+}
+/**
+ * IAPのcopy ram to flashコマンドを実行。
+ */
+unsigned long LPC17xx_IAP_copyRam2Flash(const void* i_flash_addr,const void* i_src_addr,unsigned long i_size)
+{
+    unsigned long b[8];
+    unsigned long c[5];
+    unsigned long r[5];
+    c[0]=51;
+    c[1]=(unsigned long)i_flash_addr;
+    c[2]=(unsigned long)i_src_addr;
+    c[3]=i_size;
+    c[4]=IPA_CPU_FREQ_IN_HZ/1000;
+    memcpy(b,(void*)0x10000000,32);
+    LPCXpresso_iap_entry(c,r);
+    memcpy((void*)0x10000000,b,32);
+    return r[0];
+}
+/**
+ * IAPのeraseコマンドを実行
+ */
+unsigned long LPC17xx_IAP_erase(unsigned long i_start,unsigned long i_end)
+{
+    unsigned long b[8];
+    unsigned long c[5];
+    unsigned long r[5];
+    c[0]=52;
+    c[1]=i_start;
+    c[2]=i_end;
+    c[3]=IPA_CPU_FREQ_IN_HZ/1000;
+    memcpy(b,(void*)0x10000000,32);
+    LPCXpresso_iap_entry(c,r);
+    memcpy((void*)0x10000000,b,32);
+    return r[0];
+}
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/driver/flash/LPCxxx/LPC17xx_IAP.h	Wed Oct 01 13:58:53 2014 +0000
@@ -0,0 +1,26 @@
+#ifndef LPC17xx_IAP_h
+#define LPC17xx_IAP_h
+
+#include <string.h>
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#define LPC17xx_IAP_TRUE (0==0)
+#define LPC17xx_IAP_FALSE (0!=0)
+//Command is executed successfully.
+#define LPC17xx_IAP_CMD_SUCCESS 0
+
+int LPC17xx_IAP_addr2Sector(const void* addr,unsigned long* o_sector);
+int LPC17xx_IAP_sector2Addr(unsigned int i_sector,void** o_addr);
+
+unsigned long LPC17xx_IAP_getSectorSize(unsigned int i_sector);
+unsigned long LPC17xx_IAP_prepare(unsigned long i_start,unsigned long i_end);
+unsigned long LPC17xx_IAP_copyRam2Flash(const void* i_flash_addr,const void* i_src_addr,unsigned long i_size);
+unsigned long LPC17xx_IAP_erase(unsigned long i_start,unsigned long i_end);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/driver/flash/LPCxxx/NyLPC_cMiMicConfiglation_LPCxxx.c	Wed Oct 01 13:58:53 2014 +0000
@@ -0,0 +1,105 @@
+#include "NyLPC_config.h"
+#if NyLPC_MCU==NyLPC_MCU_LPC4088 || NyLPC_MCU==NyLPC_MCU_LPC17xx
+#include "NyLPC_flash.h"
+#include "NyLPC_http.h"
+#include "NyLPC_cOnchipFlashWriter.h"
+#include "NyLPC_net.h"
+/**
+ * Onchip flashを使ったコンフィギュレーション保存システムです。
+ */
+
+
+
+
+#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)))))
+/**
+ * コンフィギュレーションの保存セクタ
+ */
+#define MIMIC_CONFIGLATION_FLASH_SECTOR 29
+#define MIMIC_CONFIGLATION_FLASH_SECTOR_ADDR 0x00078000
+
+/**
+ * コンフィギュレーション値はホストオーダーで保存する。
+ */
+const struct NyLPC_TMiMicConfigulation factory_default=
+{
+    0xffffffff,             //fastboot
+    "MiMic020102030405",
+    0x02010203,0x0405ffff,  //Mac addr
+    //IPv4
+    NyLPC_TcNetConfig_IPV4_FLAG_MODE_MANUAL,    //flags
+    IP2Int(192,168,0,39),
+    IP2Int(255,255,255,0),
+    IP2Int(192,168,0,254),
+    //ServerFlags
+    NyLPC_TcNetConfig_SERVICE_FLAG_MDNS|NyLPC_TcNetConfig_SERVICE_FLAG_UPNP,
+    //HTTP
+    80, //HTTP-Port
+    0   //padding
+};
+
+
+
+const static NyLPC_TUInt32 FAST_BOOT_DATA=0xfffffffe;
+/**
+ * ユーザコンフィギュレーションを更新する。
+ * この関数をコールするときは、割込/FreeRTOSを一時停止すること。
+ */
+NyLPC_TBool NyLPC_cMiMicConfiglation_updateConfigulation(const struct NyLPC_TMiMicConfigulation* i_congfiglation)
+{
+    const NyLPC_TUInt32* volatile fast_boot=&(factory_default.fast_boot);
+    //イレース
+    if(!NyLPC_cOnchipFlashWriter_elase(MIMIC_CONFIGLATION_FLASH_SECTOR,MIMIC_CONFIGLATION_FLASH_SECTOR)){
+        NyLPC_OnErrorGoto(Error);
+    }
+    //コンフィギュレーションを書き込む。
+    if(!NyLPC_cOnchipFlashWriter_writeSector(MIMIC_CONFIGLATION_FLASH_SECTOR,0x00000000,i_congfiglation,sizeof(struct NyLPC_TMiMicConfigulation))){
+        NyLPC_OnErrorGoto(Error);
+    }
+    //プログラム済フラッシュの一部を書き換えてユーザコンフィギュレーションをONにする。
+    if(*fast_boot==0xffffffff){
+        //フラグ値のアドレスが4バイトアライメントにあるFlashメモリか確認する。
+        if(((NyLPC_TUInt32)fast_boot)%4==0 && (!NyLPC_cOnchipFlashWriter_isOnchipFlash(fast_boot))){
+            //書き込み
+            NyLPC_cOnchipFlashWriter_write(fast_boot,&FAST_BOOT_DATA,4);
+        }else{
+            NyLPC_OnErrorGoto(Error);
+        }
+    }
+    return NyLPC_TBool_TRUE;
+Error:
+    return NyLPC_TBool_FALSE;
+}
+/**
+ * コンフィギュレーション値を返す。
+ */
+const struct NyLPC_TMiMicConfigulation* NyLPC_cMiMicConfiglation_loadFromFlash(void)
+{
+    if(NyLPC_cMiMicConfiglation_hasUserConfigulation()){
+        //userコンフィギュレーション読むよ
+        return (const struct NyLPC_TMiMicConfigulation*)(MIMIC_CONFIGLATION_FLASH_SECTOR_ADDR);
+    }else{
+        //Userコンフィギュレーションない
+        return &factory_default;
+    }
+}
+const struct NyLPC_TMiMicConfigulation* NyLPC_cMiMicConfiglation_loadFactoryDefault(void)
+{
+    return &factory_default;
+}
+
+
+
+
+
+/**
+ * ユーザコンフィギュレーションが存在すると、true.
+ */
+NyLPC_TBool NyLPC_cMiMicConfiglation_hasUserConfigulation(void)
+{
+    volatile const NyLPC_TUInt32* fast_boot=&(factory_default.fast_boot);
+    return (*fast_boot)!=0xffffffff;
+}
+
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/driver/flash/LPCxxx/NyLPC_cOnchipFlashWriter.c	Wed Oct 01 13:58:53 2014 +0000
@@ -0,0 +1,131 @@
+#include "NyLPC_config.h"
+#if NyLPC_MCU==NyLPC_MCU_LPC4088 || NyLPC_MCU==NyLPC_MCU_LPC17xx
+#include "LPC17xx_IAP.h"
+#include "NyLPC_cOnchipFlashWriter.h"
+
+
+/**
+ * 指定したアドレスが、オンチップフラッシュかどうか
+ */
+NyLPC_TBool NyLPC_cOnchipFlashWriter_isOnchipFlash(const void* i_addr)
+{
+    unsigned long snum;
+    return LPC17xx_IAP_addr2Sector(i_addr,&snum)==LPC17xx_IAP_CMD_SUCCESS;
+}
+
+NyLPC_TUInt8 _work[256];
+
+
+NyLPC_TBool NyLPC_cOnchipFlashWriter_write(const void* i_dest,const void* i_src,NyLPC_TUInt32 i_size)
+{
+    NyLPC_TUInt32 size;
+    const char* src;
+    NyLPC_TUInt32 snum;
+    const char* fblock_addr;
+    const char* dest_addr;
+    NyLPC_TUInt32 wsize;
+    NyLPC_TUInt16 s_padding;
+    NyLPC_TUInt16 free_size;
+    if(i_size%4!=0){
+        NyLPC_OnErrorGoto(Error);
+    }
+    if(((NyLPC_TUInt32)i_dest)%4!=0){
+        NyLPC_OnErrorGoto(Error);
+    }
+    size=i_size;
+    src=(const char*)i_src;
+    dest_addr=(const char*)i_dest;
+    for(;size>0;){
+        //開始位置の端数を調べる
+        s_padding=((NyLPC_TUInt32)dest_addr)%256;
+        //書き込みアドレス取得
+        fblock_addr=dest_addr-s_padding;
+        //書込み可能サイズを計算
+        free_size=256-s_padding;
+        //書込みサイズを決定
+        wsize=(free_size>size)?size:free_size;
+        //Flashから一時RAMへ前方パディングを読む
+        if(s_padding>0){
+            memcpy(_work,fblock_addr,s_padding);
+        }
+        //書き込むデータを一時RAMへ書き込む
+        memcpy(_work+s_padding,src,wsize);
+        //後半
+        if(256-(wsize+s_padding)>0){
+            memcpy(_work+s_padding+wsize,fblock_addr+(wsize+s_padding),256-(wsize+s_padding));
+        }
+
+        //Flashへ書込み
+        //開始セクタ
+        if(!LPC17xx_IAP_addr2Sector(fblock_addr,&snum)){
+            NyLPC_OnErrorGoto(Error);
+        }
+        //IAPのprepareコマンド
+
+        if(LPC17xx_IAP_CMD_SUCCESS!=LPC17xx_IAP_prepare(snum,snum)){
+            NyLPC_OnErrorGoto(Error);
+        }
+        //IAPのwriteコマンド
+        if(LPC17xx_IAP_CMD_SUCCESS!=LPC17xx_IAP_copyRam2Flash(fblock_addr,_work,256)){
+            NyLPC_OnErrorGoto(Error);
+        }
+        dest_addr+=wsize;
+        src+=wsize;
+        size-=wsize;
+    }
+    return NyLPC_TBool_TRUE;
+Error:
+    return NyLPC_TBool_FALSE;
+}
+
+/**
+ * セクタ+オフセット形式で、データを書き込みます。
+ */
+NyLPC_TBool NyLPC_cOnchipFlashWriter_writeSector(NyLPC_TUInt16 i_sector,NyLPC_TUInt32 i_offset,const void* i_src,NyLPC_TUInt32 i_size)
+{
+    void* addr;
+    if(!LPC17xx_IAP_sector2Addr(i_sector,&addr)){
+        return NyLPC_TBool_FALSE;
+    }
+    addr=(void*)((NyLPC_TUInt32)addr+i_offset);
+    return NyLPC_cOnchipFlashWriter_write(addr,i_src,i_size);
+
+}
+/**
+ * FlashRomのセクタ番号Nにイレースを実行します。
+ */
+NyLPC_TBool NyLPC_cOnchipFlashWriter_elase(NyLPC_TUInt16 i_sector_s,NyLPC_TUInt16 i_sector_e)
+{
+    if(LPC17xx_IAP_CMD_SUCCESS!=LPC17xx_IAP_prepare(i_sector_s,i_sector_e)){
+        return NyLPC_TBool_FALSE;
+    }
+    if(LPC17xx_IAP_CMD_SUCCESS!=LPC17xx_IAP_erase(i_sector_s,i_sector_e)){
+        return NyLPC_TBool_FALSE;
+    }
+    return NyLPC_TBool_TRUE;
+}
+
+
+
+#ifdef TEST
+#include "stdio.h"
+unsigned long buf[128]={0x1,0x2,0x03,0x04,0x05};
+#define MIMIC_CONFIG_ADDR ((long*)(0x00018000+1280))
+void setup(void)
+{
+    NyLPC_TcFlashWriter_t writer;
+    NyLPC_cFlashWriter_initialize(&writer);
+    unsigned long p;
+    NyLPC_cFlashWriter_elase(&writer,29);
+//  NyLPC_cFlashWriter_write(&writer,MIMIC_CONFIG_ADDR-8,buf,5*4);
+    NyLPC_cFlashWriter_finalize(&writer);
+    return;
+}
+void loop(void)
+{
+    //Implementation
+    //ここにメインタスクを書きます。
+    for(;;){}
+}
+#endif
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/driver/flash/LPCxxx/NyLPC_cOnchipFlashWriter.h	Wed Oct 01 13:58:53 2014 +0000
@@ -0,0 +1,34 @@
+#ifndef cOnchipFlashWriter_h
+#define cOnchipFlashWriter_h
+
+
+#include "NyLPC_stdlib.h"
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+
+
+/**
+ * アドレスi_destに、i_srcの内容を書き込みます。
+ * 書き込みは、FlashROMがイレース済なものとして実行します。書込み範囲以外のデータは、変更されません。
+ * 既に書込み済みのデータがある場合(0xFFFFFFFF以外)は、期待した結果が得られないので、注意してください。
+ * この関数は、IAPインタフェイス経由で256バイト単位でデータを書き込みます。
+ * IAPは0x1000000から32バイトをワークエリアとして使用します。
+ * 関数はワークエリアの待避と復帰を行いますが、安全の為、使用前にRTOSを一旦停止させてください。
+ * この関数はリエントラントではありません。
+ */
+NyLPC_TBool NyLPC_cOnchipFlashWriter_write(const void* i_dest,const void* i_src,NyLPC_TUInt32 i_size);
+/**
+ * この関数はリエントラントではありません。
+ */
+NyLPC_TBool NyLPC_cOnchipFlashWriter_writeSector(NyLPC_TUInt16 i_sector,NyLPC_TUInt32 i_offset,const void* i_src,NyLPC_TUInt32 i_size);
+NyLPC_TBool NyLPC_cOnchipFlashWriter_elase(NyLPC_TUInt16 i_sector_s,NyLPC_TUInt16 i_sector_e);
+NyLPC_TBool NyLPC_cOnchipFlashWriter_isOnchipFlash(const void* i_addr);
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/driver/flash/k64f/K64F_IAP.c	Wed Oct 01 13:58:53 2014 +0000
@@ -0,0 +1,225 @@
+/**
+ * Copyright 2014 MiMicProject
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * This file based on https://mbed.org/users/Sissors/code/FreescaleIAP/
+ */
+#include "NyLPC_config.h"
+#if NyLPC_MCU==NyLPC_MCU_K64F
+#include "K64F_IAP.h"
+//For K64F
+#   include "MK64F12.h"
+#   define USE_ProgramPhrase 1
+#   define FTFA                        FTFE
+#   define FTFA_FSTAT_FPVIOL_MASK      FTFE_FSTAT_FPVIOL_MASK 
+#   define FTFA_FSTAT_ACCERR_MASK      FTFE_FSTAT_ACCERR_MASK
+#   define FTFA_FSTAT_RDCOLERR_MASK    FTFE_FSTAT_RDCOLERR_MASK
+#   define FTFA_FSTAT_CCIF_MASK        FTFE_FSTAT_CCIF_MASK
+#   define FTFA_FSTAT_MGSTAT0_MASK     FTFE_FSTAT_MGSTAT0_MASK
+
+enum FCMD {
+    Read1s = 0x01,
+    ProgramCheck = 0x02,
+    ReadResource = 0x03,
+    ProgramLongword = 0x06,
+    ProgramPhrase = 0x07,    
+    EraseSector = 0x09,
+    Read1sBlock = 0x40,
+    ReadOnce = 0x41,
+    ProgramOnce = 0x43,
+    EraseAll = 0x44,
+    VerifyBackdoor = 0x45
+    };
+
+
+#define INT_FALSE (0!=0)
+#define INT_TRUE (0==0)
+
+static inline void run_command(void);
+//static int check_boundary(int address, unsigned int length);
+static int check_align(int address);
+
+static K64F_IAP_TIAPCode verify_erased(int address, unsigned int length);
+static K64F_IAP_TIAPCode check_error(void);
+static K64F_IAP_TIAPCode program_word(int address, char *data);
+    
+K64F_IAP_TIAPCode K64F_IAP_erase_sector(int address) {
+    #ifdef IAPDEBUG
+    printf("IAP: Erasing at %x\r\n", address);
+    #endif
+    if (check_align(address))
+        return K64F_IAP_TIAPCode_AlignError;
+    
+    //Setup command
+    FTFA->FCCOB0 = EraseSector;
+    FTFA->FCCOB1 = (address >> 16) & 0xFF;
+    FTFA->FCCOB2 = (address >> 8) & 0xFF;
+    FTFA->FCCOB3 = address & 0xFF;
+    
+    run_command();
+    
+    return check_error();
+}
+
+K64F_IAP_TIAPCode K64F_IAP_program_flash(int address, char *data, unsigned int length) {
+    #ifdef IAPDEBUG
+    printf("IAP: Programming flash at %x with length %d\r\n", address, length);
+    #endif
+    if (check_align(address))
+        return K64F_IAP_TIAPCode_AlignError;
+        
+    K64F_IAP_TIAPCode eraseCheck = verify_erased(address, length);
+    if (eraseCheck != K64F_IAP_TIAPCode_Success)
+        return eraseCheck;
+    
+    K64F_IAP_TIAPCode progResult;
+    for (int i = 0; i < length; i+=8) {
+        progResult = program_word(address + i, data + i);
+        if (progResult != K64F_IAP_TIAPCode_Success)
+            return progResult;
+    }
+    return K64F_IAP_TIAPCode_Success;
+}
+
+unsigned int K64F_IAP_flash_size(void) {
+    unsigned int retval = (SIM->FCFG2 & 0x7F000000u) >> (24-13);
+    if (SIM->FCFG2 & (1<<23))           //Possible second flash bank
+        retval += (SIM->FCFG2 & 0x007F0000u) >> (16-13);
+    return retval;
+}
+
+static K64F_IAP_TIAPCode program_word(int address, char *data) {
+    #ifdef IAPDEBUG
+    printf("IAP: Programming word at %x, %d - %d - %d - %d - %d - %d - %d - %d\r\n", address, data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]);
+    #endif
+    if (check_align(address)){
+        return K64F_IAP_TIAPCode_AlignError;
+    }
+    FTFA->FCCOB0 = ProgramPhrase;
+    FTFA->FCCOB1 = (address >> 16) & 0xFF;
+    FTFA->FCCOB2 = (address >> 8) & 0xFF;
+    FTFA->FCCOB3 = address & 0xFF;
+    FTFA->FCCOB4 = data[3];
+    FTFA->FCCOB5 = data[2];
+    FTFA->FCCOB6 = data[1];
+    FTFA->FCCOB7 = data[0];
+    FTFA->FCCOB8 = data[7];
+    FTFA->FCCOB9 = data[6];
+    FTFA->FCCOBA = data[5];
+    FTFA->FCCOBB = data[4];    
+    run_command();    
+    return check_error();
+}
+
+/* Clear possible flags which are set, run command, wait until done */
+static inline void run_command(void) {
+    //Clear possible old errors, start command, wait until done
+    __disable_irq();            //Disable IRQs, preventing IRQ routines from trying to access flash (thanks to https://mbed.org/users/mjr/)
+    FTFA->FSTAT = FTFA_FSTAT_FPVIOL_MASK | FTFA_FSTAT_ACCERR_MASK | FTFA_FSTAT_RDCOLERR_MASK;
+    FTFA->FSTAT = FTFA_FSTAT_CCIF_MASK;
+    while (!(FTFA->FSTAT & FTFA_FSTAT_CCIF_MASK));
+    __enable_irq();
+}    
+    
+    
+
+/* Check if no flash boundary is violated
+   Returns true on violation *//*
+static int check_boundary(int address, unsigned int length) {
+    int temp = (address+length - 1) / K64F_IAP_SECTOR_SIZE;
+    address /= K64F_IAP_SECTOR_SIZE;
+    int retval = (address != temp);
+    #ifdef IAPDEBUG
+    if (retval)
+        printf("IAP: Boundary violation\r\n");
+    #endif
+    return retval;
+}*/
+
+/* Check if address is correctly aligned
+   Returns true on violation */
+static int check_align(int address) {
+    int retval = address & 0x03;
+    #ifdef IAPDEBUG
+    if (retval)
+        printf("IAP: Alignment violation\r\n");
+    #endif
+    return retval;
+}
+
+/* Check if an area of flash memory is erased
+   Returns error code or Success (in case of fully erased) */
+static K64F_IAP_TIAPCode verify_erased(int address, unsigned int length) {
+    #ifdef IAPDEBUG
+    printf("IAP: Verify erased at %x with length %d\r\n", address, length);
+    #endif
+    
+    if (check_align(address)){
+        return K64F_IAP_TIAPCode_AlignError;
+    }
+    
+    //Setup command
+    FTFA->FCCOB0 = Read1s;
+    FTFA->FCCOB1 = (address >> 16) & 0xFF;
+    FTFA->FCCOB2 = (address >> 8) & 0xFF;
+    FTFA->FCCOB3 = address & 0xFF;
+    FTFA->FCCOB4 = (length >> 10) & 0xFF;
+    FTFA->FCCOB5 = (length >> 2) & 0xFF;
+    FTFA->FCCOB6 = 0;
+    
+    run_command();
+    
+    K64F_IAP_TIAPCode retval = check_error();
+    if (retval == K64F_IAP_TIAPCode_RuntimeError) {
+        #ifdef IAPDEBUG
+        printf("IAP: Flash was not erased\r\n");
+        #endif
+        return K64F_IAP_TIAPCode_EraseError;
+    }
+    return retval;        
+}
+
+/* Check if an error occured 
+   Returns error code or Success*/
+static K64F_IAP_TIAPCode check_error(void) {
+    if (FTFA->FSTAT & FTFA_FSTAT_FPVIOL_MASK) {
+        #ifdef IAPDEBUG
+        printf("IAP: Protection violation\r\n");
+        #endif
+        return K64F_IAP_TIAPCode_ProtectionError;
+    }
+    if (FTFA->FSTAT & FTFA_FSTAT_ACCERR_MASK) {
+        #ifdef IAPDEBUG
+        printf("IAP: Flash access error\r\n");
+        #endif
+        return K64F_IAP_TIAPCode_AccessError;
+    }
+    if (FTFA->FSTAT & FTFA_FSTAT_RDCOLERR_MASK) {
+        #ifdef IAPDEBUG
+        printf("IAP: Collision error\r\n");
+        #endif
+        return K64F_IAP_TIAPCode_CollisionError;
+    }
+    if (FTFA->FSTAT & FTFA_FSTAT_MGSTAT0_MASK) {
+        #ifdef IAPDEBUG
+        printf("IAP: Runtime error\r\n");
+        #endif
+        return K64F_IAP_TIAPCode_RuntimeError;
+    }
+    #ifdef IAPDEBUG
+    printf("IAP: No error reported\r\n");
+    #endif
+    return K64F_IAP_TIAPCode_Success;
+}
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/driver/flash/k64f/K64F_IAP.h	Wed Oct 01 13:58:53 2014 +0000
@@ -0,0 +1,73 @@
+/**
+ * Copyright 2014 MiMicProject
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * This file based on https://mbed.org/users/Sissors/code/FreescaleIAP/
+ */
+#ifndef K64F_IAP_h
+#define K64F_IAP_h
+#include "NyLPC_config.h"
+#if NyLPC_MCU==NyLPC_MCU_K64F
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#define K64F_IAP_SECTOR_SIZE    4096
+
+typedef int K64F_IAP_TIAPCode;
+
+#define K64F_IAP_TIAPCode_BoundaryError     -99 //Commands may not span several sectors
+#define K64F_IAP_TIAPCode_AlignError        -98 //Data must be aligned on longword (two LSBs zero)
+#define K64F_IAP_TIAPCode_ProtectionError   -97 //Flash sector is protected
+#define K64F_IAP_TIAPCode_AccessError       -96 //Something went wrong
+#define K64F_IAP_TIAPCode_CollisionError    -95 //During writing something tried to flash which was written to
+#define K64F_IAP_TIAPCode_LengthError       -94 //The length must be multiples of 4
+#define K64F_IAP_TIAPCode_RuntimeError      -93        
+#define K64F_IAP_TIAPCode_EraseError        -92 //The flash was not erased before writing to it
+#define K64F_IAP_TIAPCode_Success           0
+
+
+/** Erase a flash sector
+ *
+ * The size erased depends on the used device
+ *
+ * @param address address in the sector which needs to be erased
+ * @param return Success if no errors were encountered, otherwise one of the error states
+ */
+K64F_IAP_TIAPCode K64F_IAP_erase_sector(int address);
+
+/** Program flash
+ *
+ * Before programming the used area needs to be erased. The erase state is checked
+ * before programming, and will return an error if not erased.
+ *
+ * @param address starting address where the data needs to be programmed (must be longword alligned: two LSBs must be zero)
+ * @param data pointer to array with the data to program
+ * @param length number of bytes to program (must be a multiple of 4. must be a multiple of 8 when K64F)
+ * @param return Success if no errors were encountered, otherwise one of the error states
+ */
+K64F_IAP_TIAPCode K64F_IAP_program_flash(int address, char *data, unsigned int length);
+
+/**
+ * Returns size of flash memory
+ * 
+ * This is the first address which is not flash
+ *
+ * @param return length of flash memory in bytes
+ */
+unsigned int K64F_IAP_flash_size(void);
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/driver/flash/k64f/NyLPC_cMiMicConfiglation_K64F.c	Wed Oct 01 13:58:53 2014 +0000
@@ -0,0 +1,111 @@
+#include "NyLPC_config.h"
+#if NyLPC_MCU==NyLPC_MCU_K64F
+#include "NyLPC_stdlib.h"
+#include "NyLPC_flash.h"
+#include "NyLPC_http.h"
+#include "NyLPC_net.h"
+#include "K64F_IAP.h"
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+/**
+ * Onchip flashを使ったコンフィギュレーション保存システムです。
+ * K64Fの0x0080000に構造体NyLPC_TMiMicConfigulationを保存します。
+ */
+
+
+
+
+#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)))))
+/**
+ * コンフィギュレーションの保存セクタ
+ */
+#define MIMIC_CONFIGLATION_FLASH_ADDR ((void*)0x00080000)
+
+/**
+ * コンフィギュレーション値はホストオーダーで保存する。
+ */
+const struct NyLPC_TMiMicConfigulation factory_default=
+{
+    0xffffffff,             //fastboot
+    "MiMic020102030405",
+    0x02010203,0x0405ffff,  //Mac addr
+    //IPv4
+    NyLPC_TcNetConfig_IPV4_FLAG_MODE_MANUAL,    //flags
+    IP2Int(192,168,0,39),
+    IP2Int(255,255,255,0),
+    IP2Int(192,168,0,254),
+    //ServerFlags
+    NyLPC_TcNetConfig_SERVICE_FLAG_MDNS|NyLPC_TcNetConfig_SERVICE_FLAG_UPNP,
+    //HTTP
+    80, //HTTP-Port
+    0   //padding
+};
+
+
+#define FAST_BOOT_DATA 0xfffffffe
+/**
+ * ユーザコンフィギュレーションを更新する。
+ * この関数をコールするときは、割込/FreeRTOSを一時停止すること。
+ */
+NyLPC_TBool NyLPC_cMiMicConfiglation_updateConfigulation(const struct NyLPC_TMiMicConfigulation* i_congfiglation)
+{
+    struct NyLPC_TMiMicConfigulation d;
+    d.fast_boot=FAST_BOOT_DATA;
+    memcpy(d.hostname,i_congfiglation->hostname,NyLPC_TcNetConfig_HOSTNAME_LEN);
+    d.mac_00_01_02_03=i_congfiglation->mac_00_01_02_03;
+    d.mac_04_05_xx_xx=i_congfiglation->mac_04_05_xx_xx;
+    d.ipv4_flags=i_congfiglation->ipv4_flags;
+    d.ipv4_addr_net=i_congfiglation->ipv4_addr_net;
+    d.srv_flags=i_congfiglation->srv_flags;
+    d.http_port=i_congfiglation->http_port;
+    d.padding32=0xffff;
+    d.padding64=0xffffffff;  
+    
+    
+    if(K64F_IAP_erase_sector((int)MIMIC_CONFIGLATION_FLASH_ADDR)!=K64F_IAP_TIAPCode_Success){
+        NyLPC_OnErrorGoto(Error);
+    }
+    if(K64F_IAP_program_flash((int)MIMIC_CONFIGLATION_FLASH_ADDR,(char*)(&d), sizeof(struct NyLPC_TMiMicConfigulation))!=K64F_IAP_TIAPCode_Success){
+        NyLPC_OnErrorGoto(Error);
+    }
+    return NyLPC_TBool_TRUE;
+Error:
+    return NyLPC_TBool_FALSE;
+}
+/**
+ * コンフィギュレーション値を返す。
+ */
+const struct NyLPC_TMiMicConfigulation* NyLPC_cMiMicConfiglation_loadFromFlash(void)
+{
+    if(NyLPC_cMiMicConfiglation_hasUserConfigulation()){
+        //userコンフィギュレーション読むよ
+        return (const struct NyLPC_TMiMicConfigulation*)(MIMIC_CONFIGLATION_FLASH_ADDR);
+    }else{
+        //Userコンフィギュレーションない
+        return &factory_default;
+    }
+}
+const struct NyLPC_TMiMicConfigulation* NyLPC_cMiMicConfiglation_loadFactoryDefault(void)
+{
+    return &factory_default;
+}
+
+
+
+
+
+/**
+ * ユーザコンフィギュレーションが存在すると、true.
+ */
+NyLPC_TBool NyLPC_cMiMicConfiglation_hasUserConfigulation(void)
+{
+    //初回読出しはFlashにFFFFFFFFが格納されているのを期待する。
+    volatile const NyLPC_TUInt32* fast_boot=((NyLPC_TUInt32*)MIMIC_CONFIGLATION_FLASH_ADDR);
+    return (*fast_boot)!=0xffffffff;
+}
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif
--- a/core/flash/NyLPC_cMiMicConfiglation.c	Sat Sep 27 13:33:26 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,102 +0,0 @@
-#include "NyLPC_flash.h"
-#include "NyLPC_http.h"
-#include "NyLPC_cMiMicConfiglation.h"
-#include "NyLPC_net.h"
-/**
- * Onchip flashを使ったコンフィギュレーション保存システムです。
- */
-
-
-
-
-#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)))))
-/**
- * コンフィギュレーションの保存セクタ
- */
-#define MIMIC_CONFIGLATION_FLASH_SECTOR 29
-#define MIMIC_CONFIGLATION_FLASH_SECTOR_ADDR 0x00078000
-
-/**
- * コンフィギュレーション値はホストオーダーで保存する。
- */
-const struct NyLPC_TMiMicConfigulation factory_default=
-{
-    0xffffffff,             //fastboot
-    "MiMic020102030405",
-    0x02010203,0x0405ffff,  //Mac addr
-    //IPv4
-    NyLPC_TcNetConfig_IPV4_FLAG_MODE_MANUAL,    //flags
-    IP2Int(192,168,0,39),
-    IP2Int(255,255,255,0),
-    IP2Int(192,168,0,254),
-    //ServerFlags
-    NyLPC_TcNetConfig_SERVICE_FLAG_MDNS|NyLPC_TcNetConfig_SERVICE_FLAG_UPNP,
-    //HTTP
-    80, //HTTP-Port
-    0   //padding
-};
-
-
-
-const static NyLPC_TUInt32 FAST_BOOT_DATA=0xfffffffe;
-/**
- * ユーザコンフィギュレーションを更新する。
- * この関数をコールするときは、割込/FreeRTOSを一時停止すること。
- */
-NyLPC_TBool NyLPC_cMiMicConfiglation_updateConfigulation(const struct NyLPC_TMiMicConfigulation* i_congfiglation)
-{
-    const NyLPC_TUInt32* volatile fast_boot=&(factory_default.fast_boot);
-    //イレース
-    if(!NyLPC_cOnchipFlashWriter_elase(MIMIC_CONFIGLATION_FLASH_SECTOR,MIMIC_CONFIGLATION_FLASH_SECTOR)){
-        NyLPC_OnErrorGoto(Error);
-    }
-    //コンフィギュレーションを書き込む。
-    if(!NyLPC_cOnchipFlashWriter_writeSector(MIMIC_CONFIGLATION_FLASH_SECTOR,0x00000000,i_congfiglation,sizeof(struct NyLPC_TMiMicConfigulation))){
-        NyLPC_OnErrorGoto(Error);
-    }
-    //プログラム済フラッシュの一部を書き換えてユーザコンフィギュレーションをONにする。
-    if(*fast_boot==0xffffffff){
-        //フラグ値のアドレスが4バイトアライメントにあるFlashメモリか確認する。
-        if(((NyLPC_TUInt32)fast_boot)%4==0 && (!NyLPC_cOnchipFlashWriter_isOnchipFlash(fast_boot))){
-            //書き込み
-            NyLPC_cOnchipFlashWriter_write(fast_boot,&FAST_BOOT_DATA,4);
-        }else{
-            NyLPC_OnErrorGoto(Error);
-        }
-    }
-    return NyLPC_TBool_TRUE;
-Error:
-    return NyLPC_TBool_FALSE;
-}
-/**
- * コンフィギュレーション値を返す。
- */
-const struct NyLPC_TMiMicConfigulation* NyLPC_cMiMicConfiglation_loadFromFlash(void)
-{
-    if(NyLPC_cMiMicConfiglation_hasUserConfigulation()){
-        //userコンフィギュレーション読むよ
-        return (const struct NyLPC_TMiMicConfigulation*)(MIMIC_CONFIGLATION_FLASH_SECTOR_ADDR);
-    }else{
-        //Userコンフィギュレーションない
-        return &factory_default;
-    }
-}
-const struct NyLPC_TMiMicConfigulation* NyLPC_cMiMicConfiglation_loadFactoryDefault(void)
-{
-    return &factory_default;
-}
-
-
-
-
-
-/**
- * ユーザコンフィギュレーションが存在すると、true.
- */
-NyLPC_TBool NyLPC_cMiMicConfiglation_hasUserConfigulation(void)
-{
-    volatile const NyLPC_TUInt32* fast_boot=&(factory_default.fast_boot);
-    return (*fast_boot)!=0xffffffff;
-}
-
-
--- a/core/flash/NyLPC_cMiMicConfiglation.h	Sat Sep 27 13:33:26 2014 +0000
+++ b/core/flash/NyLPC_cMiMicConfiglation.h	Wed Oct 01 13:58:53 2014 +0000
@@ -17,7 +17,7 @@
 
 /**
  * IPアドレスはネットワークオーダーで格納する。
- * 構造体は4バイトアライメントであること。
+ * 構造体は8バイトアライメントであること。
  */
 struct NyLPC_TMiMicConfigulation{
     /** ROM焼検出用。0xFFFFFFFFを書く */
@@ -27,7 +27,7 @@
     /** MACアドレスの下位4bit*/
     NyLPC_TUInt32   mac_00_01_02_03;
     /** MACアドレスの上位2bit*/
-    NyLPC_TUInt32   mac_04_05_xx_xx;
+    NyLPC_TUInt32   mac_04_05_xx_xx;    //12+NyLPC_TcNetConfig_HOSTNAME_LEN
     /*
      * IPv4設定
      */
@@ -40,7 +40,7 @@
     /** IPV4アドレス*/
     NyLPC_TUInt32   ipv4_addr_net;
     NyLPC_TUInt32   ipv4_mask_net;
-    NyLPC_TUInt32   ipv4_drut_net;
+    NyLPC_TUInt32   ipv4_drut_net;      //16
 
     /*
      * Service setting
@@ -52,9 +52,10 @@
      */
     NyLPC_TUInt32   srv_flags;
     /** HTTPポート番号*/
-    NyLPC_TUInt16   http_port;
-    NyLPC_TUInt16   padding;
-
+    NyLPC_TUInt16   http_port;          //6
+                                        //total=(34=(12+16+6)+NyLPC_TcNetConfig_HOSTNAME_LEN)
+    NyLPC_TUInt16   padding32;
+    NyLPC_TUInt32   padding64;          //total=40+NyLPC_TcNetConfig_HOSTNAME_LEN
 };
 
 /**
--- a/core/flash/NyLPC_cOnchipFlashWriter.c	Sat Sep 27 13:33:26 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,128 +0,0 @@
-#include "../driver/flash/LPC17xx_IAP.h"
-#include "NyLPC_cOnchipFlashWriter.h"
-
-
-/**
- * 指定したアドレスが、オンチップフラッシュかどうか
- */
-NyLPC_TBool NyLPC_cOnchipFlashWriter_isOnchipFlash(const void* i_addr)
-{
-    unsigned long snum;
-    return LPC17xx_IAP_addr2Sector(i_addr,&snum)==LPC17xx_IAP_CMD_SUCCESS;
-}
-
-NyLPC_TUInt8 _work[256];
-
-
-NyLPC_TBool NyLPC_cOnchipFlashWriter_write(const void* i_dest,const void* i_src,NyLPC_TUInt32 i_size)
-{
-    NyLPC_TUInt32 size;
-    const char* src;
-    NyLPC_TUInt32 snum;
-    const char* fblock_addr;
-    const char* dest_addr;
-    NyLPC_TUInt32 wsize;
-    NyLPC_TUInt16 s_padding;
-    NyLPC_TUInt16 free_size;
-    if(i_size%4!=0){
-        NyLPC_OnErrorGoto(Error);
-    }
-    if(((NyLPC_TUInt32)i_dest)%4!=0){
-        NyLPC_OnErrorGoto(Error);
-    }
-    size=i_size;
-    src=(const char*)i_src;
-    dest_addr=(const char*)i_dest;
-    for(;size>0;){
-        //開始位置の端数を調べる
-        s_padding=((NyLPC_TUInt32)dest_addr)%256;
-        //書き込みアドレス取得
-        fblock_addr=dest_addr-s_padding;
-        //書込み可能サイズを計算
-        free_size=256-s_padding;
-        //書込みサイズを決定
-        wsize=(free_size>size)?size:free_size;
-        //Flashから一時RAMへ前方パディングを読む
-        if(s_padding>0){
-            memcpy(_work,fblock_addr,s_padding);
-        }
-        //書き込むデータを一時RAMへ書き込む
-        memcpy(_work+s_padding,src,wsize);
-        //後半
-        if(256-(wsize+s_padding)>0){
-            memcpy(_work+s_padding+wsize,fblock_addr+(wsize+s_padding),256-(wsize+s_padding));
-        }
-
-        //Flashへ書込み
-        //開始セクタ
-        if(!LPC17xx_IAP_addr2Sector(fblock_addr,&snum)){
-            NyLPC_OnErrorGoto(Error);
-        }
-        //IAPのprepareコマンド
-
-        if(LPC17xx_IAP_CMD_SUCCESS!=LPC17xx_IAP_prepare(snum,snum)){
-            NyLPC_OnErrorGoto(Error);
-        }
-        //IAPのwriteコマンド
-        if(LPC17xx_IAP_CMD_SUCCESS!=LPC17xx_IAP_copyRam2Flash(fblock_addr,_work,256)){
-            NyLPC_OnErrorGoto(Error);
-        }
-        dest_addr+=wsize;
-        src+=wsize;
-        size-=wsize;
-    }
-    return NyLPC_TBool_TRUE;
-Error:
-    return NyLPC_TBool_FALSE;
-}
-
-/**
- * セクタ+オフセット形式で、データを書き込みます。
- */
-NyLPC_TBool NyLPC_cOnchipFlashWriter_writeSector(NyLPC_TUInt16 i_sector,NyLPC_TUInt32 i_offset,const void* i_src,NyLPC_TUInt32 i_size)
-{
-    void* addr;
-    if(!LPC17xx_IAP_sector2Addr(i_sector,&addr)){
-        return NyLPC_TBool_FALSE;
-    }
-    addr=(void*)((NyLPC_TUInt32)addr+i_offset);
-    return NyLPC_cOnchipFlashWriter_write(addr,i_src,i_size);
-
-}
-/**
- * FlashRomのセクタ番号Nにイレースを実行します。
- */
-NyLPC_TBool NyLPC_cOnchipFlashWriter_elase(NyLPC_TUInt16 i_sector_s,NyLPC_TUInt16 i_sector_e)
-{
-    if(LPC17xx_IAP_CMD_SUCCESS!=LPC17xx_IAP_prepare(i_sector_s,i_sector_e)){
-        return NyLPC_TBool_FALSE;
-    }
-    if(LPC17xx_IAP_CMD_SUCCESS!=LPC17xx_IAP_erase(i_sector_s,i_sector_e)){
-        return NyLPC_TBool_FALSE;
-    }
-    return NyLPC_TBool_TRUE;
-}
-
-
-
-#ifdef TEST
-#include "stdio.h"
-unsigned long buf[128]={0x1,0x2,0x03,0x04,0x05};
-#define MIMIC_CONFIG_ADDR ((long*)(0x00018000+1280))
-void setup(void)
-{
-    NyLPC_TcFlashWriter_t writer;
-    NyLPC_cFlashWriter_initialize(&writer);
-    unsigned long p;
-    NyLPC_cFlashWriter_elase(&writer,29);
-//  NyLPC_cFlashWriter_write(&writer,MIMIC_CONFIG_ADDR-8,buf,5*4);
-    NyLPC_cFlashWriter_finalize(&writer);
-    return;
-}
-void loop(void)
-{
-    //Implementation
-    //ここにメインタスクを書きます。
-    for(;;){}
-}
-#endif
--- a/core/flash/NyLPC_cOnchipFlashWriter.h	Sat Sep 27 13:33:26 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,34 +0,0 @@
-#ifndef cOnchipFlashWriter_h
-#define cOnchipFlashWriter_h
-
-
-#include "NyLPC_stdlib.h"
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
-
-
-/**
- * アドレスi_destに、i_srcの内容を書き込みます。
- * 書き込みは、FlashROMがイレース済なものとして実行します。書込み範囲以外のデータは、変更されません。
- * 既に書込み済みのデータがある場合(0xFFFFFFFF以外)は、期待した結果が得られないので、注意してください。
- * この関数は、IAPインタフェイス経由で256バイト単位でデータを書き込みます。
- * IAPは0x1000000から32バイトをワークエリアとして使用します。
- * 関数はワークエリアの待避と復帰を行いますが、安全の為、使用前にRTOSを一旦停止させてください。
- * この関数はリエントラントではありません。
- */
-NyLPC_TBool NyLPC_cOnchipFlashWriter_write(const void* i_dest,const void* i_src,NyLPC_TUInt32 i_size);
-/**
- * この関数はリエントラントではありません。
- */
-NyLPC_TBool NyLPC_cOnchipFlashWriter_writeSector(NyLPC_TUInt16 i_sector,NyLPC_TUInt32 i_offset,const void* i_src,NyLPC_TUInt32 i_size);
-NyLPC_TBool NyLPC_cOnchipFlashWriter_elase(NyLPC_TUInt16 i_sector_s,NyLPC_TUInt16 i_sector_e);
-NyLPC_TBool NyLPC_cOnchipFlashWriter_isOnchipFlash(const void* i_addr);
-
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-#endif
--- a/core/include/NyLPC_config.h	Sat Sep 27 13:33:26 2014 +0000
+++ b/core/include/NyLPC_config.h	Wed Oct 01 13:58:53 2014 +0000
@@ -135,7 +135,8 @@
 #ifdef TARGET_K64F
 #   undef NyLPC_MCU
 #   define NyLPC_MCU NyLPC_MCU_K64F
-#   define NyLPC_TTxBufferHeader_ALIGNMENT 16   //EthernetのTXメモリブロックヘッダを16バイトアラインメントにする
+#   define NyLPC_TTxBufferHeader_ALIGNMENT  16  //EthernetのTXメモリブロックヘッダを16バイトアラインメントにする
+#   define NyLPC_TcEthernetMM_BUF_PADDING   16  //2バイトでいいんだけど16バイトアライメントにするために16
 #endif
 
 #ifdef __cplusplus
--- a/core/include/NyLPC_flash.h	Sat Sep 27 13:33:26 2014 +0000
+++ b/core/include/NyLPC_flash.h	Wed Oct 01 13:58:53 2014 +0000
@@ -30,7 +30,6 @@
 #ifndef NyLPC_flash_h
 #define NyLPC_flash_h
 #include "NyLPC_stdlib.h"
-#include "../flash/NyLPC_cOnchipFlashWriter.h"
 #include "../flash/NyLPC_cMiMicConfiglation.h"
 #ifdef __cplusplus
 extern "C" {
--- a/core/net/httpd/mod/NyLPC_cMocMiMicSetting.c	Sat Sep 27 13:33:26 2014 +0000
+++ b/core/net/httpd/mod/NyLPC_cMocMiMicSetting.c	Wed Oct 01 13:58:53 2014 +0000
@@ -476,7 +476,8 @@
 //          cfg_image.srv_flags =i_req->content.setup.param_buf[6];
 //          strcpy(cfg_image.hostname,i_req->content.setup.host_name);
             i_req->content.setup.memimg.http_port =(NyLPC_TUInt16)(i_req->content.setup.tmp.param_buf[7]>>16);
-            i_req->content.setup.memimg.padding=0xffff;
+            i_req->content.setup.memimg.padding32=0xffff;
+            i_req->content.setup.memimg.padding64=0xffffffff;
             //一応確認。
             if(i_req->content.setup.memimg.http_port==0){
                 NyLPC_cHttpdUtils_sendErrorResponse(i_connection,500);
--- a/core/uip/NyLPC_cUipService.c	Sat Sep 27 13:33:26 2014 +0000
+++ b/core/uip/NyLPC_cUipService.c	Wed Oct 01 13:58:53 2014 +0000
@@ -403,7 +403,7 @@
 /**
  * allocTxBufで取得したペイロードメモリを"IPパケットとして"送信します。
  * @param i_eth_payload
- * [NyLPC_TTxBufferHeader][NyLPC_TEthernetIIHeader][payload]メモリの、[payload]のアドレスを指定します。
+ * [NyLPC_TEthernetIIHeader][payload]メモリの、[payload]のアドレスを指定します。
  * 通常は、NyLPC_cUipService_allocTxBufの返却したメモリを指定します。
  */
 
--- a/core/uip/NyLPC_cUipService_protected.h	Sat Sep 27 13:33:26 2014 +0000
+++ b/core/uip/NyLPC_cUipService_protected.h	Wed Oct 01 13:58:53 2014 +0000
@@ -58,12 +58,6 @@
     /** (Ethernetメモリ排他制御用)*/
     NyLPC_TcMutex_t _mutex;
     const struct TiEthernetDevice* _ethif;
-//  /** ipタスクが使う小サイズ送信バッファ*/
-//  struct
-//  {
-//      struct NyLPC_TTxBufferHeader h;
-//      NyLPC_TUInt8 buf[NyLPC_TcUipService_SIZE_OF_REPLY_BUF];
-//  }stx;
 };