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

Committer:
nyatla
Date:
Thu May 22 12:59:50 2014 +0000
Revision:
68:f7def7eb5504
Child:
69:8c5f220441f5
MiMic-core ?344???;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nyatla 68:f7def7eb5504 1 /*
nyatla 68:f7def7eb5504 2 * EthDev_LPC1769.c
nyatla 68:f7def7eb5504 3 *
nyatla 68:f7def7eb5504 4 * Created on: 2011/12/07
nyatla 68:f7def7eb5504 5 * Author: nyatla
nyatla 68:f7def7eb5504 6 */
nyatla 68:f7def7eb5504 7 #include "NyLPC_config.h"
nyatla 68:f7def7eb5504 8 #if NyLPC_MCU==NyLPC_MCU_LPC17xx
nyatla 68:f7def7eb5504 9 #include "LPC17xx.h"
nyatla 68:f7def7eb5504 10 #include "EthDev_LPC17xx.h"
nyatla 68:f7def7eb5504 11 #include "NyLPC_os.h"
nyatla 68:f7def7eb5504 12 /* If no buffers are available, then wait this long before looking again.... */
nyatla 68:f7def7eb5504 13 #define emacBUFFER_WAIT_DELAY_MS 3
nyatla 68:f7def7eb5504 14 #define emacBUFFER_WAIT_EMPTY_DELAY_MS 10
nyatla 68:f7def7eb5504 15 //--------------------------------------------------
nyatla 68:f7def7eb5504 16 // common function.
nyatla 68:f7def7eb5504 17 //--------------------------------------------------
nyatla 68:f7def7eb5504 18
nyatla 68:f7def7eb5504 19
nyatla 68:f7def7eb5504 20
nyatla 68:f7def7eb5504 21 /**
nyatla 68:f7def7eb5504 22 * 送信デスクリプタを準備します。
nyatla 68:f7def7eb5504 23 */
nyatla 68:f7def7eb5504 24 void EthDev_LPC17xx_prevTxDescriptor(void)
nyatla 68:f7def7eb5504 25 {
nyatla 68:f7def7eb5504 26 long x;
nyatla 68:f7def7eb5504 27 //デスクリプタの設定
nyatla 68:f7def7eb5504 28 for( x = 0; x < NUM_TX_FRAG; x++ )
nyatla 68:f7def7eb5504 29 {
nyatla 68:f7def7eb5504 30 TX_DESC_PACKET( x ) = ( unsigned long ) NULL;
nyatla 68:f7def7eb5504 31 TX_DESC_CTRL( x ) = 0;
nyatla 68:f7def7eb5504 32 TX_STAT_INFO( x ) = 0;
nyatla 68:f7def7eb5504 33 }
nyatla 68:f7def7eb5504 34 /* Set LPC_EMAC Transmit Descriptor Registers. */
nyatla 68:f7def7eb5504 35 LPC_EMAC->TxDescriptor = TX_DESC_BASE;
nyatla 68:f7def7eb5504 36 LPC_EMAC->TxStatus = TX_STAT_BASE;
nyatla 68:f7def7eb5504 37 LPC_EMAC->TxDescriptorNumber = NUM_TX_FRAG - 1;
nyatla 68:f7def7eb5504 38 }
nyatla 68:f7def7eb5504 39
nyatla 68:f7def7eb5504 40
nyatla 68:f7def7eb5504 41 /**
nyatla 68:f7def7eb5504 42 * 送信中のイーサフレームを処理する機会を与えて、送信キューが空くまで待ちます。
nyatla 68:f7def7eb5504 43 * LPC1769の場合は、非同期に更新したディスクリプタの内容から、送信メモリのフラグを更新します。
nyatla 68:f7def7eb5504 44 * @return
nyatla 68:f7def7eb5504 45 * 次に書き込むことが出来る送信キュー。
nyatla 68:f7def7eb5504 46 */
nyatla 68:f7def7eb5504 47 static NyLPC_TUInt32 waitForTxEthFrameEmpty(void)
nyatla 68:f7def7eb5504 48 {
nyatla 68:f7def7eb5504 49 NyLPC_TUInt32 IndexNext;
nyatla 68:f7def7eb5504 50 struct NyLPC_TTxBufferHeader *b;
nyatla 68:f7def7eb5504 51 void* p;
nyatla 68:f7def7eb5504 52 NyLPC_TUInt32 i;
nyatla 68:f7def7eb5504 53
nyatla 68:f7def7eb5504 54 //送信キューの決定
nyatla 68:f7def7eb5504 55 IndexNext = (LPC_EMAC->TxProduceIndex + 1)%NUM_TX_FRAG;
nyatla 68:f7def7eb5504 56
nyatla 68:f7def7eb5504 57 //送信キューフルが解除されるまで待ち
nyatla 68:f7def7eb5504 58 while(IndexNext == LPC_EMAC->TxConsumeIndex)
nyatla 68:f7def7eb5504 59 {
nyatla 68:f7def7eb5504 60 //
nyatla 68:f7def7eb5504 61 NyLPC_cThread_sleep(emacBUFFER_WAIT_EMPTY_DELAY_MS);
nyatla 68:f7def7eb5504 62 }
nyatla 68:f7def7eb5504 63
nyatla 68:f7def7eb5504 64 //(TxProduceIndex+1)→TxConsumeIndexにあるデータのsentフラグを消去
nyatla 68:f7def7eb5504 65 for(i=IndexNext;i!=LPC_EMAC->TxConsumeIndex;i=(i+1)%NUM_TX_FRAG)
nyatla 68:f7def7eb5504 66 {
nyatla 68:f7def7eb5504 67 p=(void*)TX_DESC_PACKET(i);
nyatla 68:f7def7eb5504 68 if(p!=NULL){
nyatla 68:f7def7eb5504 69 b=((struct NyLPC_TTxBufferHeader*)p)-1;
nyatla 68:f7def7eb5504 70 b->is_lock=NyLPC_TUInt8_FALSE;
nyatla 68:f7def7eb5504 71 TX_DESC_PACKET(i)=0;
nyatla 68:f7def7eb5504 72 }
nyatla 68:f7def7eb5504 73 }
nyatla 68:f7def7eb5504 74 p=(void*)TX_DESC_PACKET(i);
nyatla 68:f7def7eb5504 75 if(p!=NULL){
nyatla 68:f7def7eb5504 76 b=((struct NyLPC_TTxBufferHeader*)p)-1;
nyatla 68:f7def7eb5504 77 b->is_lock=NyLPC_TUInt8_FALSE;
nyatla 68:f7def7eb5504 78 TX_DESC_PACKET(i)=0;
nyatla 68:f7def7eb5504 79 }
nyatla 68:f7def7eb5504 80 return IndexNext;
nyatla 68:f7def7eb5504 81 }
nyatla 68:f7def7eb5504 82
nyatla 68:f7def7eb5504 83 void EthDev_LPC17xx_processTx(void)
nyatla 68:f7def7eb5504 84 {
nyatla 68:f7def7eb5504 85 waitForTxEthFrameEmpty();
nyatla 68:f7def7eb5504 86 }
nyatla 68:f7def7eb5504 87
nyatla 68:f7def7eb5504 88 /**
nyatla 68:f7def7eb5504 89 * Ethernetパケットを送信します。
nyatla 68:f7def7eb5504 90 * allocTxBufで得たバッファか、NyLPC_TTxBufferHeaderのペイロード部分を指定すること。
nyatla 68:f7def7eb5504 91 * <p>関数仕様</p>
nyatla 68:f7def7eb5504 92 * この関数は、i_bufが
nyatla 68:f7def7eb5504 93 * </div>
nyatla 68:f7def7eb5504 94 */
nyatla 68:f7def7eb5504 95 void EthDev_LPC17xx_sendTxEthFrame(struct NyLPC_TTxBufferHeader* i_buf,unsigned short i_size)
nyatla 68:f7def7eb5504 96 {
nyatla 68:f7def7eb5504 97 NyLPC_TUInt32 IndexNext,Index;
nyatla 68:f7def7eb5504 98
nyatla 68:f7def7eb5504 99 //サイズ0なら送信の必要なし
nyatla 68:f7def7eb5504 100 if(i_size == 0)
nyatla 68:f7def7eb5504 101 {
nyatla 68:f7def7eb5504 102 return;
nyatla 68:f7def7eb5504 103 }
nyatla 68:f7def7eb5504 104 //送信デスクリプタの反映
nyatla 68:f7def7eb5504 105 IndexNext =waitForTxEthFrameEmpty();
nyatla 68:f7def7eb5504 106
nyatla 68:f7def7eb5504 107 //送信対象のメモリブロックを送信中に設定。
nyatla 68:f7def7eb5504 108 // b=(i_buf+1);
nyatla 68:f7def7eb5504 109 //送信中のメモリブロックなら無視
nyatla 68:f7def7eb5504 110 if(i_buf->is_lock){
nyatla 68:f7def7eb5504 111 return;
nyatla 68:f7def7eb5504 112 }
nyatla 68:f7def7eb5504 113 //送信中にセット
nyatla 68:f7def7eb5504 114 i_buf->is_lock=NyLPC_TUInt8_TRUE;
nyatla 68:f7def7eb5504 115
nyatla 68:f7def7eb5504 116 //送信データのセット
nyatla 68:f7def7eb5504 117 Index = LPC_EMAC->TxProduceIndex;
nyatla 68:f7def7eb5504 118 if (i_size > ETH_FRAG_SIZE){
nyatla 68:f7def7eb5504 119 i_size = ETH_FRAG_SIZE;
nyatla 68:f7def7eb5504 120 }
nyatla 68:f7def7eb5504 121
nyatla 68:f7def7eb5504 122 //送信処理
nyatla 68:f7def7eb5504 123 TX_DESC_PACKET( Index ) = ( unsigned long )(i_buf+1);
nyatla 68:f7def7eb5504 124 //See UM10360.pdf Table 181. Transmit descriptor control word
nyatla 68:f7def7eb5504 125 TX_DESC_CTRL( Index ) = ((i_size-1) | TCTRL_LAST | TCTRL_INT );
nyatla 68:f7def7eb5504 126 LPC_EMAC->TxProduceIndex = IndexNext;
nyatla 68:f7def7eb5504 127 return;
nyatla 68:f7def7eb5504 128 }
nyatla 68:f7def7eb5504 129
nyatla 68:f7def7eb5504 130 /***********************************************************************
nyatla 68:f7def7eb5504 131 * RXバッファ
nyatla 68:f7def7eb5504 132 ***********************************************************************/
nyatla 68:f7def7eb5504 133
nyatla 68:f7def7eb5504 134 void EthDev_LPC17xx_prevRxDescriptor(void)
nyatla 68:f7def7eb5504 135 {
nyatla 68:f7def7eb5504 136 int x;
nyatla 68:f7def7eb5504 137 //デスクリプタの設定
nyatla 68:f7def7eb5504 138 for( x = 0; x < NUM_RX_FRAG; x++ )
nyatla 68:f7def7eb5504 139 {
nyatla 68:f7def7eb5504 140 /* Allocate the next Ethernet buffer to this descriptor. */
nyatla 68:f7def7eb5504 141 RX_DESC_PACKET(x) = ETH_BUF(x);
nyatla 68:f7def7eb5504 142 RX_DESC_CTRL(x) = RCTRL_INT | ( ETH_FRAG_SIZE - 1 );
nyatla 68:f7def7eb5504 143 RX_STAT_INFO(x) = 0;
nyatla 68:f7def7eb5504 144 RX_STAT_HASHCRC(x) = 0;
nyatla 68:f7def7eb5504 145 }
nyatla 68:f7def7eb5504 146
nyatla 68:f7def7eb5504 147 /* Set LPC_EMAC Receive Descriptor Registers. */
nyatla 68:f7def7eb5504 148 LPC_EMAC->RxDescriptor = RX_DESC_BASE;
nyatla 68:f7def7eb5504 149 LPC_EMAC->RxStatus = RX_STAT_BASE;
nyatla 68:f7def7eb5504 150 LPC_EMAC->RxDescriptorNumber = NUM_RX_FRAG - 1;
nyatla 68:f7def7eb5504 151
nyatla 68:f7def7eb5504 152 }
nyatla 68:f7def7eb5504 153
nyatla 68:f7def7eb5504 154
nyatla 68:f7def7eb5504 155 /**
nyatla 68:f7def7eb5504 156 * 受信キューの先頭にあるRXフレームのポインタを返します。
nyatla 68:f7def7eb5504 157 * 関数は、受信キューのポインタを操作しません。続けて読み出したとしても、同じポインターを返します。
nyatla 68:f7def7eb5504 158 * 制限として、返却したポインタの内容は、一時的に書き換え可としてください。(この制限は将来削除します。)
nyatla 68:f7def7eb5504 159 * @return
nyatla 68:f7def7eb5504 160 * 成功した場合、受信データを格納したバッファポインターです。
nyatla 68:f7def7eb5504 161 * 次回nextRxEthFrameを呼び出すまで有効です。
nyatla 68:f7def7eb5504 162 */
nyatla 68:f7def7eb5504 163 void* EthDev_LPC17xx_getRxEthFrame(unsigned short* o_len_of_data)
nyatla 68:f7def7eb5504 164 {
nyatla 68:f7def7eb5504 165
nyatla 68:f7def7eb5504 166 if( LPC_EMAC->RxProduceIndex != LPC_EMAC->RxConsumeIndex )
nyatla 68:f7def7eb5504 167 {
nyatla 68:f7def7eb5504 168 //受信データを返却する。
nyatla 68:f7def7eb5504 169 *o_len_of_data = (unsigned short)(( RX_STAT_INFO( LPC_EMAC->RxConsumeIndex ) & RINFO_SIZE ) - 3);
nyatla 68:f7def7eb5504 170 return ( unsigned char * ) RX_DESC_PACKET( LPC_EMAC->RxConsumeIndex );
nyatla 68:f7def7eb5504 171 }
nyatla 68:f7def7eb5504 172 return NULL;
nyatla 68:f7def7eb5504 173 }
nyatla 68:f7def7eb5504 174
nyatla 68:f7def7eb5504 175
nyatla 68:f7def7eb5504 176 /**
nyatla 68:f7def7eb5504 177 * 受信キューを進行します。
nyatla 68:f7def7eb5504 178 */
nyatla 68:f7def7eb5504 179 void EthDev_LPC17xx_nextRxEthFrame(void)
nyatla 68:f7def7eb5504 180 {
nyatla 68:f7def7eb5504 181 long lIndex;
nyatla 68:f7def7eb5504 182 if( LPC_EMAC->RxProduceIndex != LPC_EMAC->RxConsumeIndex )
nyatla 68:f7def7eb5504 183 {
nyatla 68:f7def7eb5504 184 //キューすすめる。
nyatla 68:f7def7eb5504 185 lIndex = LPC_EMAC->RxConsumeIndex;
nyatla 68:f7def7eb5504 186 lIndex++;
nyatla 68:f7def7eb5504 187 if( lIndex >= NUM_RX_FRAG )
nyatla 68:f7def7eb5504 188 {
nyatla 68:f7def7eb5504 189 lIndex = 0;
nyatla 68:f7def7eb5504 190 }
nyatla 68:f7def7eb5504 191 LPC_EMAC->RxConsumeIndex = lIndex;
nyatla 68:f7def7eb5504 192 }
nyatla 68:f7def7eb5504 193 }
nyatla 68:f7def7eb5504 194 #endif
nyatla 68:f7def7eb5504 195
nyatla 68:f7def7eb5504 196