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:
Wed Oct 01 13:58:53 2014 +0000
Revision:
92:4f77028cce64
?????????????????; K64F??????????????; LPC?????????????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nyatla 92:4f77028cce64 1 /*
nyatla 92:4f77028cce64 2 * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
nyatla 92:4f77028cce64 3 * All rights reserved.
nyatla 92:4f77028cce64 4 *
nyatla 92:4f77028cce64 5 * Redistribution and use in source and binary forms, with or without modification,
nyatla 92:4f77028cce64 6 * are permitted provided that the following conditions are met:
nyatla 92:4f77028cce64 7 *
nyatla 92:4f77028cce64 8 * o Redistributions of source code must retain the above copyright notice, this list
nyatla 92:4f77028cce64 9 * of conditions and the following disclaimer.
nyatla 92:4f77028cce64 10 *
nyatla 92:4f77028cce64 11 * o Redistributions in binary form must reproduce the above copyright notice, this
nyatla 92:4f77028cce64 12 * list of conditions and the following disclaimer in the documentation and/or
nyatla 92:4f77028cce64 13 * other materials provided with the distribution.
nyatla 92:4f77028cce64 14 *
nyatla 92:4f77028cce64 15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
nyatla 92:4f77028cce64 16 * contributors may be used to endorse or promote products derived from this
nyatla 92:4f77028cce64 17 * software without specific prior written permission.
nyatla 92:4f77028cce64 18 *
nyatla 92:4f77028cce64 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
nyatla 92:4f77028cce64 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
nyatla 92:4f77028cce64 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
nyatla 92:4f77028cce64 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
nyatla 92:4f77028cce64 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
nyatla 92:4f77028cce64 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
nyatla 92:4f77028cce64 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
nyatla 92:4f77028cce64 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
nyatla 92:4f77028cce64 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
nyatla 92:4f77028cce64 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
nyatla 92:4f77028cce64 29 */
nyatla 92:4f77028cce64 30
nyatla 92:4f77028cce64 31 /* Modified by mbed for the lwIP port */
nyatla 92:4f77028cce64 32 #include "NyLPC_config.h"
nyatla 92:4f77028cce64 33 #if NyLPC_MCU==NyLPC_MCU_K64F
nyatla 92:4f77028cce64 34 #include "fsl_enet_driver.h"
nyatla 92:4f77028cce64 35 #include "fsl_enet_hal.h"
nyatla 92:4f77028cce64 36 #include "fsl_clock_manager.h"
nyatla 92:4f77028cce64 37 #include "fsl_interrupt_manager.h"
nyatla 92:4f77028cce64 38 #include <string.h>
nyatla 92:4f77028cce64 39
nyatla 92:4f77028cce64 40 //#include "sys_arch.h"
nyatla 92:4f77028cce64 41
nyatla 92:4f77028cce64 42 /*******************************************************************************
nyatla 92:4f77028cce64 43 * Variables
nyatla 92:4f77028cce64 44 ******************************************************************************/
nyatla 92:4f77028cce64 45 /*! @brief Define ENET's IRQ list */
nyatla 92:4f77028cce64 46
nyatla 92:4f77028cce64 47 void *enetIfHandle;
nyatla 92:4f77028cce64 48
nyatla 92:4f77028cce64 49 /*! @brief Define MAC driver API structure and for application of stack adaptor layer*/
nyatla 92:4f77028cce64 50 const enet_mac_api_t g_enetMacApi =
nyatla 92:4f77028cce64 51 {
nyatla 92:4f77028cce64 52 enet_mac_init,
nyatla 92:4f77028cce64 53 NULL, // enet_mac_deinit,
nyatla 92:4f77028cce64 54 NULL, // enet_mac_send,
nyatla 92:4f77028cce64 55 #if !ENET_RECEIVE_ALL_INTERRUPT
nyatla 92:4f77028cce64 56 NULL, // enet_mac_receive,
nyatla 92:4f77028cce64 57 #endif
nyatla 92:4f77028cce64 58 enet_mii_read,
nyatla 92:4f77028cce64 59 enet_mii_write,
nyatla 92:4f77028cce64 60 NULL, // enet_mac_add_multicast_group,
nyatla 92:4f77028cce64 61 NULL, //enet_mac_leave_multicast_group,
nyatla 92:4f77028cce64 62 };
nyatla 92:4f77028cce64 63 /*******************************************************************************
nyatla 92:4f77028cce64 64 * Code
nyatla 92:4f77028cce64 65 ******************************************************************************/
nyatla 92:4f77028cce64 66
nyatla 92:4f77028cce64 67 // NOTE: we need these functions to be non-blocking fpr the PHY task, hence the
nyatla 92:4f77028cce64 68 // osDelay() below
nyatla 92:4f77028cce64 69
nyatla 92:4f77028cce64 70 /*FUNCTION****************************************************************
nyatla 92:4f77028cce64 71 *
nyatla 92:4f77028cce64 72 * Function Name: enet_mii_read
nyatla 92:4f77028cce64 73 * Return Value: The execution status.
nyatla 92:4f77028cce64 74 * Description: Read function.
nyatla 92:4f77028cce64 75 * This interface read data over the (R)MII bus from the specified PHY register,
nyatla 92:4f77028cce64 76 * This function is called by all PHY interfaces.
nyatla 92:4f77028cce64 77 *END*********************************************************************/
nyatla 92:4f77028cce64 78 uint32_t enet_mii_read(uint32_t instance, uint32_t phyAddr, uint32_t phyReg, uint32_t *dataPtr)
nyatla 92:4f77028cce64 79 {
nyatla 92:4f77028cce64 80 uint32_t counter;
nyatla 92:4f77028cce64 81
nyatla 92:4f77028cce64 82 /* Check the input parameters*/
nyatla 92:4f77028cce64 83 if (!dataPtr)
nyatla 92:4f77028cce64 84 {
nyatla 92:4f77028cce64 85 return kStatus_ENET_InvalidInput;
nyatla 92:4f77028cce64 86 }
nyatla 92:4f77028cce64 87
nyatla 92:4f77028cce64 88 /* Check if the mii is enabled*/
nyatla 92:4f77028cce64 89 if (!enet_hal_is_mii_enabled(instance))
nyatla 92:4f77028cce64 90 {
nyatla 92:4f77028cce64 91 return kStatus_ENET_Miiuninitialized;
nyatla 92:4f77028cce64 92 }
nyatla 92:4f77028cce64 93
nyatla 92:4f77028cce64 94 /* Clear the MII interrupt event*/
nyatla 92:4f77028cce64 95 enet_hal_clear_interrupt(instance, kEnetMiiInterrupt);
nyatla 92:4f77028cce64 96
nyatla 92:4f77028cce64 97 /* Read command operation*/
nyatla 92:4f77028cce64 98 enet_hal_set_mii_command(instance, phyAddr, phyReg, kEnetReadValidFrame, 0);
nyatla 92:4f77028cce64 99
nyatla 92:4f77028cce64 100 /* Poll for MII complete*/
nyatla 92:4f77028cce64 101 for (counter = 0; counter < kEnetMaxTimeout; counter++)
nyatla 92:4f77028cce64 102 {
nyatla 92:4f77028cce64 103 if (enet_hal_get_interrupt_status(instance, kEnetMiiInterrupt))
nyatla 92:4f77028cce64 104 {
nyatla 92:4f77028cce64 105 break;
nyatla 92:4f77028cce64 106 }
nyatla 92:4f77028cce64 107 osDelay(1);
nyatla 92:4f77028cce64 108 }
nyatla 92:4f77028cce64 109
nyatla 92:4f77028cce64 110 /* Check for timeout*/
nyatla 92:4f77028cce64 111 if (counter == kEnetMaxTimeout)
nyatla 92:4f77028cce64 112 {
nyatla 92:4f77028cce64 113 return kStatus_ENET_TimeOut;
nyatla 92:4f77028cce64 114 }
nyatla 92:4f77028cce64 115
nyatla 92:4f77028cce64 116 /* Get data from mii register*/
nyatla 92:4f77028cce64 117 *dataPtr = enet_hal_get_mii_data(instance);
nyatla 92:4f77028cce64 118
nyatla 92:4f77028cce64 119 /* Clear MII interrupt event*/
nyatla 92:4f77028cce64 120 enet_hal_clear_interrupt(instance, kEnetMiiInterrupt);
nyatla 92:4f77028cce64 121
nyatla 92:4f77028cce64 122 return kStatus_ENET_Success;
nyatla 92:4f77028cce64 123 }
nyatla 92:4f77028cce64 124
nyatla 92:4f77028cce64 125 /*FUNCTION****************************************************************
nyatla 92:4f77028cce64 126 *
nyatla 92:4f77028cce64 127 * Function Name: enet_mii_write
nyatla 92:4f77028cce64 128 * Return Value: The execution status.
nyatla 92:4f77028cce64 129 * Description: Write function.
nyatla 92:4f77028cce64 130 * This interface write data over the (R)MII bus to the specified PHY register.
nyatla 92:4f77028cce64 131 * This function is called by all PHY interfaces.
nyatla 92:4f77028cce64 132 *END*********************************************************************/
nyatla 92:4f77028cce64 133 uint32_t enet_mii_write(uint32_t instance, uint32_t phyAddr, uint32_t phyReg, uint32_t data)
nyatla 92:4f77028cce64 134 {
nyatla 92:4f77028cce64 135 uint32_t counter;
nyatla 92:4f77028cce64 136
nyatla 92:4f77028cce64 137 /* Check if the mii is enabled*/
nyatla 92:4f77028cce64 138 if (!enet_hal_is_mii_enabled(instance))
nyatla 92:4f77028cce64 139 {
nyatla 92:4f77028cce64 140 return kStatus_ENET_Miiuninitialized;
nyatla 92:4f77028cce64 141 }
nyatla 92:4f77028cce64 142
nyatla 92:4f77028cce64 143 /* Clear the MII interrupt event*/
nyatla 92:4f77028cce64 144 enet_hal_clear_interrupt(instance, kEnetMiiInterrupt);
nyatla 92:4f77028cce64 145
nyatla 92:4f77028cce64 146 /* Read command operation*/
nyatla 92:4f77028cce64 147 enet_hal_set_mii_command(instance, phyAddr, phyReg, kEnetWriteValidFrame, data);
nyatla 92:4f77028cce64 148
nyatla 92:4f77028cce64 149 /* Poll for MII complete*/
nyatla 92:4f77028cce64 150 for (counter = 0; counter < kEnetMaxTimeout; counter++)
nyatla 92:4f77028cce64 151 {
nyatla 92:4f77028cce64 152 if (enet_hal_get_interrupt_status(instance, kEnetMiiInterrupt))
nyatla 92:4f77028cce64 153 {
nyatla 92:4f77028cce64 154 break;
nyatla 92:4f77028cce64 155 }
nyatla 92:4f77028cce64 156 osDelay(1);
nyatla 92:4f77028cce64 157 }
nyatla 92:4f77028cce64 158
nyatla 92:4f77028cce64 159 /* Check for timeout*/
nyatla 92:4f77028cce64 160 if (counter == kEnetMaxTimeout)
nyatla 92:4f77028cce64 161 {
nyatla 92:4f77028cce64 162 return kStatus_ENET_TimeOut;
nyatla 92:4f77028cce64 163 }
nyatla 92:4f77028cce64 164
nyatla 92:4f77028cce64 165 /* Clear MII intrrupt event*/
nyatla 92:4f77028cce64 166 enet_hal_clear_interrupt(instance, kEnetMiiInterrupt);
nyatla 92:4f77028cce64 167
nyatla 92:4f77028cce64 168 return kStatus_ENET_Success;
nyatla 92:4f77028cce64 169 }
nyatla 92:4f77028cce64 170 /*FUNCTION****************************************************************
nyatla 92:4f77028cce64 171 *
nyatla 92:4f77028cce64 172 * Function Name: enet_mac_mii_init
nyatla 92:4f77028cce64 173 * Return Value: The execution status.
nyatla 92:4f77028cce64 174 * Description:Initialize the ENET Mac mii(mdc/mdio)interface.
nyatla 92:4f77028cce64 175 *END*********************************************************************/
nyatla 92:4f77028cce64 176 uint32_t enet_mac_mii_init(enet_dev_if_t * enetIfPtr)
nyatla 92:4f77028cce64 177 {
nyatla 92:4f77028cce64 178 uint32_t frequency;
nyatla 92:4f77028cce64 179
nyatla 92:4f77028cce64 180 /* Check the input parameters*/
nyatla 92:4f77028cce64 181 if (enetIfPtr == NULL)
nyatla 92:4f77028cce64 182 {
nyatla 92:4f77028cce64 183 return kStatus_ENET_InvalidInput;
nyatla 92:4f77028cce64 184 }
nyatla 92:4f77028cce64 185
nyatla 92:4f77028cce64 186 /* Configure mii speed*/
nyatla 92:4f77028cce64 187 clock_manager_get_frequency(kSystemClock, &frequency);
nyatla 92:4f77028cce64 188 enet_hal_config_mii(enetIfPtr->deviceNumber, (frequency/(2 * enetIfPtr->macCfgPtr->miiClock) + 1),
nyatla 92:4f77028cce64 189 kEnetMdioHoldOneClkCycle, false);
nyatla 92:4f77028cce64 190
nyatla 92:4f77028cce64 191 return kStatus_ENET_Success;
nyatla 92:4f77028cce64 192 }
nyatla 92:4f77028cce64 193
nyatla 92:4f77028cce64 194 /*FUNCTION****************************************************************
nyatla 92:4f77028cce64 195 *
nyatla 92:4f77028cce64 196 * Function Name: enet_mac_rxbd_init
nyatla 92:4f77028cce64 197 * Return Value: The execution status.
nyatla 92:4f77028cce64 198 * Description:Initialize the ENET receive buffer descriptors.
nyatla 92:4f77028cce64 199 * Note: If you do receive on receive interrupt handler the receive
nyatla 92:4f77028cce64 200 * data buffer number can be the same as the receive descriptor numbers.
nyatla 92:4f77028cce64 201 * But if you are polling receive frames please make sure the receive data
nyatla 92:4f77028cce64 202 * buffers are more than buffer descriptors to guarantee a good performance.
nyatla 92:4f77028cce64 203 *END*********************************************************************/
nyatla 92:4f77028cce64 204 uint32_t enet_mac_rxbd_init(enet_dev_if_t * enetIfPtr, enet_rxbd_config_t *rxbdCfg)
nyatla 92:4f77028cce64 205 {
nyatla 92:4f77028cce64 206 /* Check the input parameters*/
nyatla 92:4f77028cce64 207 if ((!enetIfPtr) || (!rxbdCfg))
nyatla 92:4f77028cce64 208 {
nyatla 92:4f77028cce64 209 return kStatus_ENET_InvalidInput;
nyatla 92:4f77028cce64 210 }
nyatla 92:4f77028cce64 211
nyatla 92:4f77028cce64 212 enetIfPtr->macContextPtr->bufferdescSize = enet_hal_get_bd_size();
nyatla 92:4f77028cce64 213
nyatla 92:4f77028cce64 214 /* Initialize the bd status*/
nyatla 92:4f77028cce64 215 enetIfPtr->macContextPtr->isRxFull = false;
nyatla 92:4f77028cce64 216
nyatla 92:4f77028cce64 217 /* Initialize receive bd base address and current address*/
nyatla 92:4f77028cce64 218 enetIfPtr->macContextPtr->rxBdBasePtr = rxbdCfg->rxBdPtrAlign;
nyatla 92:4f77028cce64 219 enetIfPtr->macContextPtr->rxBdCurPtr = enetIfPtr->macContextPtr->rxBdBasePtr;
nyatla 92:4f77028cce64 220 enetIfPtr->macContextPtr->rxBdDirtyPtr = enetIfPtr->macContextPtr->rxBdBasePtr;
nyatla 92:4f77028cce64 221 enet_hal_set_rxbd_address(enetIfPtr->deviceNumber, (uint32_t)(enetIfPtr->macContextPtr->rxBdBasePtr));
nyatla 92:4f77028cce64 222
nyatla 92:4f77028cce64 223 return kStatus_ENET_Success;
nyatla 92:4f77028cce64 224 }
nyatla 92:4f77028cce64 225
nyatla 92:4f77028cce64 226 /*FUNCTION****************************************************************
nyatla 92:4f77028cce64 227 *
nyatla 92:4f77028cce64 228 * Function Name: enet_mac_txbd_init
nyatla 92:4f77028cce64 229 * Return Value: The execution status.
nyatla 92:4f77028cce64 230 * Description:Initialize the ENET transmit buffer descriptors.
nyatla 92:4f77028cce64 231 * This function prepare all of the transmit buffer descriptors.
nyatla 92:4f77028cce64 232 *END*********************************************************************/
nyatla 92:4f77028cce64 233 uint32_t enet_mac_txbd_init(enet_dev_if_t * enetIfPtr, enet_txbd_config_t *txbdCfg)
nyatla 92:4f77028cce64 234 {
nyatla 92:4f77028cce64 235 /* Check the input parameters*/
nyatla 92:4f77028cce64 236 if ((!enetIfPtr) || (!txbdCfg))
nyatla 92:4f77028cce64 237 {
nyatla 92:4f77028cce64 238 return kStatus_ENET_InvalidInput;
nyatla 92:4f77028cce64 239 }
nyatla 92:4f77028cce64 240
nyatla 92:4f77028cce64 241 /* Initialize the bd status*/
nyatla 92:4f77028cce64 242 enetIfPtr->macContextPtr->isTxFull = false;
nyatla 92:4f77028cce64 243
nyatla 92:4f77028cce64 244 /* Initialize transmit bd base address and current address*/
nyatla 92:4f77028cce64 245 enetIfPtr->macContextPtr->txBdBasePtr = txbdCfg->txBdPtrAlign;
nyatla 92:4f77028cce64 246 enetIfPtr->macContextPtr->txBdCurPtr = enetIfPtr->macContextPtr->txBdBasePtr;
nyatla 92:4f77028cce64 247 enetIfPtr->macContextPtr->txBdDirtyPtr = enetIfPtr->macContextPtr->txBdBasePtr;
nyatla 92:4f77028cce64 248 enet_hal_set_txbd_address(enetIfPtr->deviceNumber, (uint32_t)(enetIfPtr->macContextPtr->txBdBasePtr));
nyatla 92:4f77028cce64 249 return kStatus_ENET_Success;
nyatla 92:4f77028cce64 250 }
nyatla 92:4f77028cce64 251
nyatla 92:4f77028cce64 252 /*FUNCTION****************************************************************
nyatla 92:4f77028cce64 253 *
nyatla 92:4f77028cce64 254 * Function Name: enet_mac_configure_fifo_accel
nyatla 92:4f77028cce64 255 * Return Value: The execution status.
nyatla 92:4f77028cce64 256 * Description: Configure the ENET FIFO and Accelerator.
nyatla 92:4f77028cce64 257 *END*********************************************************************/
nyatla 92:4f77028cce64 258 uint32_t enet_mac_configure_fifo_accel(enet_dev_if_t * enetIfPtr)
nyatla 92:4f77028cce64 259 {
nyatla 92:4f77028cce64 260 enet_config_rx_fifo_t rxFifo;
nyatla 92:4f77028cce64 261 enet_config_tx_fifo_t txFifo;
nyatla 92:4f77028cce64 262
nyatla 92:4f77028cce64 263 /* Check the input parameters*/
nyatla 92:4f77028cce64 264 if (!enetIfPtr)
nyatla 92:4f77028cce64 265 {
nyatla 92:4f77028cce64 266 return kStatus_ENET_InvalidInput;
nyatla 92:4f77028cce64 267 }
nyatla 92:4f77028cce64 268
nyatla 92:4f77028cce64 269 /* Initialize values that will not be initialized later on */
nyatla 92:4f77028cce64 270 rxFifo.rxEmpty = 0;
nyatla 92:4f77028cce64 271 rxFifo.rxFull = 0;
nyatla 92:4f77028cce64 272 txFifo.isStoreForwardEnabled = 0;
nyatla 92:4f77028cce64 273 txFifo.txFifoWrite = 0;
nyatla 92:4f77028cce64 274 txFifo.txEmpty = 0;
nyatla 92:4f77028cce64 275
nyatla 92:4f77028cce64 276 /* Configure tx/rx accelerator*/
nyatla 92:4f77028cce64 277 if (enetIfPtr->macCfgPtr->isRxAccelEnabled)
nyatla 92:4f77028cce64 278 {
nyatla 92:4f77028cce64 279 enet_hal_config_rx_accelerator(enetIfPtr->deviceNumber,
nyatla 92:4f77028cce64 280 (enet_config_rx_accelerator_t *)&(enetIfPtr->macCfgPtr->rxAcceler));
nyatla 92:4f77028cce64 281 if ((enetIfPtr->macCfgPtr->rxAcceler.isIpcheckEnabled) || (enetIfPtr->macCfgPtr->rxAcceler.isProtocolCheckEnabled))
nyatla 92:4f77028cce64 282 {
nyatla 92:4f77028cce64 283 rxFifo.rxFull = 0;
nyatla 92:4f77028cce64 284 }
nyatla 92:4f77028cce64 285 }
nyatla 92:4f77028cce64 286 if (enetIfPtr->macCfgPtr->isTxAccelEnabled)
nyatla 92:4f77028cce64 287 {
nyatla 92:4f77028cce64 288 enet_hal_config_tx_accelerator(enetIfPtr->deviceNumber,
nyatla 92:4f77028cce64 289 (enet_config_tx_accelerator_t *)&(enetIfPtr->macCfgPtr->txAcceler));
nyatla 92:4f77028cce64 290 if ((enetIfPtr->macCfgPtr->txAcceler.isIpCheckEnabled) || (enetIfPtr->macCfgPtr->txAcceler.isProtocolCheckEnabled))
nyatla 92:4f77028cce64 291 {
nyatla 92:4f77028cce64 292 txFifo.isStoreForwardEnabled = 1;
nyatla 92:4f77028cce64 293 }
nyatla 92:4f77028cce64 294 }
nyatla 92:4f77028cce64 295 if (enetIfPtr->macCfgPtr->isStoreAndFwEnabled)
nyatla 92:4f77028cce64 296 {
nyatla 92:4f77028cce64 297 rxFifo.rxFull = 0;
nyatla 92:4f77028cce64 298 txFifo.isStoreForwardEnabled = 1;
nyatla 92:4f77028cce64 299 }
nyatla 92:4f77028cce64 300
nyatla 92:4f77028cce64 301
nyatla 92:4f77028cce64 302 /* Set TFWR value if STRFWD is not being used */
nyatla 92:4f77028cce64 303 if (txFifo.isStoreForwardEnabled == 1)
nyatla 92:4f77028cce64 304 txFifo.txFifoWrite = 0;
nyatla 92:4f77028cce64 305 else
nyatla 92:4f77028cce64 306 /* TFWR value is a trade-off between transmit latency and risk of transmit FIFO underrun due to contention for the system bus
nyatla 92:4f77028cce64 307 TFWR = 15 means transmission will begin once 960 bytes has been written to the Tx FIFO (for frames larger than 960 bytes)
nyatla 92:4f77028cce64 308 See Section 45.4.18 - Transmit FIFO Watermark Register of the K64F Reference Manual for details */
nyatla 92:4f77028cce64 309 txFifo.txFifoWrite = 15;
nyatla 92:4f77028cce64 310
nyatla 92:4f77028cce64 311 /* Configure tx/rx FIFO with default value*/
nyatla 92:4f77028cce64 312 rxFifo.rxAlmostEmpty = 4;
nyatla 92:4f77028cce64 313 rxFifo.rxAlmostFull = 4;
nyatla 92:4f77028cce64 314 txFifo.txAlmostEmpty = 4;
nyatla 92:4f77028cce64 315 txFifo.txAlmostFull = 8;
nyatla 92:4f77028cce64 316 enet_hal_config_rx_fifo(enetIfPtr->deviceNumber, &rxFifo);
nyatla 92:4f77028cce64 317 enet_hal_config_tx_fifo(enetIfPtr->deviceNumber, &txFifo);
nyatla 92:4f77028cce64 318
nyatla 92:4f77028cce64 319 return kStatus_ENET_Success;
nyatla 92:4f77028cce64 320 }
nyatla 92:4f77028cce64 321
nyatla 92:4f77028cce64 322 /*FUNCTION****************************************************************
nyatla 92:4f77028cce64 323 *
nyatla 92:4f77028cce64 324 * Function Name: enet_mac_configure_controller
nyatla 92:4f77028cce64 325 * Return Value: The execution status.
nyatla 92:4f77028cce64 326 * Description: Configure the ENET controller with the basic configuration.
nyatla 92:4f77028cce64 327 *END*********************************************************************/
nyatla 92:4f77028cce64 328 uint32_t enet_mac_configure_controller(enet_dev_if_t * enetIfPtr)
nyatla 92:4f77028cce64 329 {
nyatla 92:4f77028cce64 330 uint32_t macCtlCfg;
nyatla 92:4f77028cce64 331
nyatla 92:4f77028cce64 332 /* Check the input parameters*/
nyatla 92:4f77028cce64 333 if (enetIfPtr == NULL)
nyatla 92:4f77028cce64 334 {
nyatla 92:4f77028cce64 335 return kStatus_ENET_InvalidInput;
nyatla 92:4f77028cce64 336 }
nyatla 92:4f77028cce64 337
nyatla 92:4f77028cce64 338 macCtlCfg = enetIfPtr->macCfgPtr->macCtlConfigure;
nyatla 92:4f77028cce64 339 /* Configure rmii/mii interface*/
nyatla 92:4f77028cce64 340 enet_hal_config_rmii(enetIfPtr->deviceNumber, enetIfPtr->macCfgPtr->rmiiCfgMode,
nyatla 92:4f77028cce64 341 enetIfPtr->macCfgPtr->speed, enetIfPtr->macCfgPtr->duplex, false,
nyatla 92:4f77028cce64 342 (macCtlCfg & kEnetRxMiiLoopback));
nyatla 92:4f77028cce64 343 /* Configure receive buffer size*/
nyatla 92:4f77028cce64 344 if (enetIfPtr->macCfgPtr->isVlanEnabled)
nyatla 92:4f77028cce64 345 {
nyatla 92:4f77028cce64 346 enetIfPtr->maxFrameSize = kEnetMaxFrameVlanSize;
nyatla 92:4f77028cce64 347 enet_hal_set_rx_max_size(enetIfPtr->deviceNumber,
nyatla 92:4f77028cce64 348 enetIfPtr->macContextPtr->rxBufferSizeAligned, kEnetMaxFrameVlanSize);
nyatla 92:4f77028cce64 349 }
nyatla 92:4f77028cce64 350 else
nyatla 92:4f77028cce64 351 {
nyatla 92:4f77028cce64 352 enetIfPtr->maxFrameSize = kEnetMaxFrameSize;
nyatla 92:4f77028cce64 353 enet_hal_set_rx_max_size(enetIfPtr->deviceNumber,
nyatla 92:4f77028cce64 354 enetIfPtr->macContextPtr->rxBufferSizeAligned, kEnetMaxFrameSize);
nyatla 92:4f77028cce64 355 }
nyatla 92:4f77028cce64 356
nyatla 92:4f77028cce64 357 /* Set receive controller promiscuous */
nyatla 92:4f77028cce64 358 enet_hal_config_promiscuous(enetIfPtr->deviceNumber, macCtlCfg & kEnetRxPromiscuousEnable);
nyatla 92:4f77028cce64 359 /* Set receive flow control*/
nyatla 92:4f77028cce64 360 enet_hal_enable_flowcontrol(enetIfPtr->deviceNumber, (macCtlCfg & kEnetRxFlowControlEnable));
nyatla 92:4f77028cce64 361 /* Set received PAUSE frames are forwarded/terminated*/
nyatla 92:4f77028cce64 362 enet_hal_enable_pauseforward(enetIfPtr->deviceNumber, (macCtlCfg & kEnetRxPauseFwdEnable));
nyatla 92:4f77028cce64 363 /* Set receive broadcast frame reject*/
nyatla 92:4f77028cce64 364 enet_hal_enable_broadcastreject(enetIfPtr->deviceNumber, (macCtlCfg & kEnetRxBcRejectEnable));
nyatla 92:4f77028cce64 365 /* Set padding is removed from the received frame*/
nyatla 92:4f77028cce64 366 enet_hal_enable_padremove(enetIfPtr->deviceNumber, (macCtlCfg & kEnetRxPadRemoveEnable));
nyatla 92:4f77028cce64 367 /* Set the crc of the received frame is stripped from the frame*/
nyatla 92:4f77028cce64 368 enet_hal_enable_rxcrcforward(enetIfPtr->deviceNumber, (macCtlCfg & kEnetRxCrcFwdEnable));
nyatla 92:4f77028cce64 369 /* Set receive payload length check*/
nyatla 92:4f77028cce64 370 enet_hal_enable_payloadcheck(enetIfPtr->deviceNumber, (macCtlCfg & kEnetPayloadlenCheckEnable));
nyatla 92:4f77028cce64 371 /* Set control sleep mode*/
nyatla 92:4f77028cce64 372 enet_hal_enable_sleep(enetIfPtr->deviceNumber, (macCtlCfg & kEnetSleepModeEnable));
nyatla 92:4f77028cce64 373 return kStatus_ENET_Success;
nyatla 92:4f77028cce64 374 }
nyatla 92:4f77028cce64 375
nyatla 92:4f77028cce64 376 /*FUNCTION****************************************************************
nyatla 92:4f77028cce64 377 *
nyatla 92:4f77028cce64 378 * Function Name: enet_mac_init
nyatla 92:4f77028cce64 379 * Return Value: The execution status.
nyatla 92:4f77028cce64 380 * Description:Initialize the ENET device with the basic configuration
nyatla 92:4f77028cce64 381 * When ENET is used, this function need to be called by the NET initialize
nyatla 92:4f77028cce64 382 * interface.
nyatla 92:4f77028cce64 383 *END*********************************************************************/
nyatla 92:4f77028cce64 384 uint32_t enet_mac_init(enet_dev_if_t * enetIfPtr, enet_rxbd_config_t *rxbdCfg,
nyatla 92:4f77028cce64 385 enet_txbd_config_t *txbdCfg)
nyatla 92:4f77028cce64 386 {
nyatla 92:4f77028cce64 387 uint32_t timeOut = 0;
nyatla 92:4f77028cce64 388 uint32_t devNumber, result = 0;
nyatla 92:4f77028cce64 389
nyatla 92:4f77028cce64 390 /* Check the input parameters*/
nyatla 92:4f77028cce64 391 if (enetIfPtr == NULL)
nyatla 92:4f77028cce64 392 {
nyatla 92:4f77028cce64 393 return kStatus_ENET_InvalidInput;
nyatla 92:4f77028cce64 394 }
nyatla 92:4f77028cce64 395
nyatla 92:4f77028cce64 396 /* Get device number and check the parameter*/
nyatla 92:4f77028cce64 397 devNumber = enetIfPtr->deviceNumber;
nyatla 92:4f77028cce64 398
nyatla 92:4f77028cce64 399 /* Store the global ENET structure for ISR input parameters for instance 0*/
nyatla 92:4f77028cce64 400 if (!devNumber)
nyatla 92:4f77028cce64 401 {
nyatla 92:4f77028cce64 402 enetIfHandle = enetIfPtr;
nyatla 92:4f77028cce64 403 }
nyatla 92:4f77028cce64 404
nyatla 92:4f77028cce64 405 /* Turn on ENET module clock gate */
nyatla 92:4f77028cce64 406 clock_manager_set_gate(kClockModuleENET, 0U, true);
nyatla 92:4f77028cce64 407
nyatla 92:4f77028cce64 408 /* Reset ENET mac*/
nyatla 92:4f77028cce64 409 enet_hal_reset_ethernet(devNumber);
nyatla 92:4f77028cce64 410 while ((!enet_hal_is_reset_completed(devNumber)) && (timeOut < kEnetMaxTimeout))
nyatla 92:4f77028cce64 411 {
nyatla 92:4f77028cce64 412 time_delay(1);
nyatla 92:4f77028cce64 413 timeOut++;
nyatla 92:4f77028cce64 414 }
nyatla 92:4f77028cce64 415
nyatla 92:4f77028cce64 416 /* Check out if timeout*/
nyatla 92:4f77028cce64 417 if (timeOut == kEnetMaxTimeout)
nyatla 92:4f77028cce64 418 {
nyatla 92:4f77028cce64 419 return kStatus_ENET_TimeOut;
nyatla 92:4f77028cce64 420 }
nyatla 92:4f77028cce64 421
nyatla 92:4f77028cce64 422 /* Disable all ENET mac interrupt and Clear all interrupt events*/
nyatla 92:4f77028cce64 423 enet_hal_config_interrupt(devNumber, kEnetAllInterrupt, false);
nyatla 92:4f77028cce64 424 enet_hal_clear_interrupt(devNumber, kEnetAllInterrupt);
nyatla 92:4f77028cce64 425
nyatla 92:4f77028cce64 426 /* Program this station's physical address*/
nyatla 92:4f77028cce64 427 enet_hal_set_mac_address(devNumber, enetIfPtr->macCfgPtr->macAddr);
nyatla 92:4f77028cce64 428
nyatla 92:4f77028cce64 429 /* Clear group and individual hash register*/
nyatla 92:4f77028cce64 430 enet_hal_set_group_hashtable(devNumber, 0, kEnetSpecialAddressInit);
nyatla 92:4f77028cce64 431 enet_hal_set_individual_hashtable(devNumber, 0, kEnetSpecialAddressInit);
nyatla 92:4f77028cce64 432
nyatla 92:4f77028cce64 433 /* Configure mac controller*/
nyatla 92:4f77028cce64 434 result = enet_mac_configure_controller(enetIfPtr);
nyatla 92:4f77028cce64 435 if(result != kStatus_ENET_Success)
nyatla 92:4f77028cce64 436 {
nyatla 92:4f77028cce64 437 return result;
nyatla 92:4f77028cce64 438 }
nyatla 92:4f77028cce64 439 /* Clear mib zero counters*/
nyatla 92:4f77028cce64 440 enet_hal_clear_mib(devNumber, true);
nyatla 92:4f77028cce64 441
nyatla 92:4f77028cce64 442 /* Initialize FIFO and accelerator*/
nyatla 92:4f77028cce64 443 result = enet_mac_configure_fifo_accel(enetIfPtr);
nyatla 92:4f77028cce64 444 if(result != kStatus_ENET_Success)
nyatla 92:4f77028cce64 445 {
nyatla 92:4f77028cce64 446 return result;
nyatla 92:4f77028cce64 447 }
nyatla 92:4f77028cce64 448 /* Initialize receive buffer descriptors*/
nyatla 92:4f77028cce64 449 result = enet_mac_rxbd_init(enetIfPtr, rxbdCfg);
nyatla 92:4f77028cce64 450 if(result != kStatus_ENET_Success)
nyatla 92:4f77028cce64 451 {
nyatla 92:4f77028cce64 452 return result;
nyatla 92:4f77028cce64 453 }
nyatla 92:4f77028cce64 454 /* Initialize transmit buffer descriptors*/
nyatla 92:4f77028cce64 455 result = enet_mac_txbd_init(enetIfPtr, txbdCfg);
nyatla 92:4f77028cce64 456 if(result != kStatus_ENET_Success)
nyatla 92:4f77028cce64 457 {
nyatla 92:4f77028cce64 458 return result;
nyatla 92:4f77028cce64 459 }
nyatla 92:4f77028cce64 460 /* Initialize rmii/mii interface*/
nyatla 92:4f77028cce64 461 result = enet_mac_mii_init(enetIfPtr);
nyatla 92:4f77028cce64 462 if (result != kStatus_ENET_Success)
nyatla 92:4f77028cce64 463 {
nyatla 92:4f77028cce64 464 return result;
nyatla 92:4f77028cce64 465 }
nyatla 92:4f77028cce64 466
nyatla 92:4f77028cce64 467 return kStatus_ENET_Success;
nyatla 92:4f77028cce64 468 }
nyatla 92:4f77028cce64 469
nyatla 92:4f77028cce64 470 /*******************************************************************************
nyatla 92:4f77028cce64 471 * EOF
nyatla 92:4f77028cce64 472 ******************************************************************************/
nyatla 92:4f77028cce64 473
nyatla 92:4f77028cce64 474 #endif
nyatla 92:4f77028cce64 475