ProjetoBB

Dependencies:   F7_Ethernet WebSocketClient mbed mcp3008

Fork of Nucleo_F746ZG_Ethernet by Dieter Graef

Committer:
DieterGraef
Date:
Sat Jun 18 10:49:12 2016 +0000
Revision:
0:f9b6112278fe
Ethernet for the NUCLEO STM32F746 Board Testprogram uses DHCP and NTP to set the clock

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DieterGraef 0:f9b6112278fe 1 /**
DieterGraef 0:f9b6112278fe 2 * @file
DieterGraef 0:f9b6112278fe 3 * Network Interface Sequential API module
DieterGraef 0:f9b6112278fe 4 *
DieterGraef 0:f9b6112278fe 5 */
DieterGraef 0:f9b6112278fe 6
DieterGraef 0:f9b6112278fe 7 /*
DieterGraef 0:f9b6112278fe 8 * Redistribution and use in source and binary forms, with or without modification,
DieterGraef 0:f9b6112278fe 9 * are permitted provided that the following conditions are met:
DieterGraef 0:f9b6112278fe 10 *
DieterGraef 0:f9b6112278fe 11 * 1. Redistributions of source code must retain the above copyright notice,
DieterGraef 0:f9b6112278fe 12 * this list of conditions and the following disclaimer.
DieterGraef 0:f9b6112278fe 13 * 2. Redistributions in binary form must reproduce the above copyright notice,
DieterGraef 0:f9b6112278fe 14 * this list of conditions and the following disclaimer in the documentation
DieterGraef 0:f9b6112278fe 15 * and/or other materials provided with the distribution.
DieterGraef 0:f9b6112278fe 16 * 3. The name of the author may not be used to endorse or promote products
DieterGraef 0:f9b6112278fe 17 * derived from this software without specific prior written permission.
DieterGraef 0:f9b6112278fe 18 *
DieterGraef 0:f9b6112278fe 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
DieterGraef 0:f9b6112278fe 20 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
DieterGraef 0:f9b6112278fe 21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
DieterGraef 0:f9b6112278fe 22 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
DieterGraef 0:f9b6112278fe 23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
DieterGraef 0:f9b6112278fe 24 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
DieterGraef 0:f9b6112278fe 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
DieterGraef 0:f9b6112278fe 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
DieterGraef 0:f9b6112278fe 27 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
DieterGraef 0:f9b6112278fe 28 * OF SUCH DAMAGE.
DieterGraef 0:f9b6112278fe 29 *
DieterGraef 0:f9b6112278fe 30 * This file is part of the lwIP TCP/IP stack.
DieterGraef 0:f9b6112278fe 31 *
DieterGraef 0:f9b6112278fe 32 */
DieterGraef 0:f9b6112278fe 33
DieterGraef 0:f9b6112278fe 34 #include "lwip/opt.h"
DieterGraef 0:f9b6112278fe 35
DieterGraef 0:f9b6112278fe 36 #if LWIP_NETIF_API /* don't build if not configured for use in lwipopts.h */
DieterGraef 0:f9b6112278fe 37
DieterGraef 0:f9b6112278fe 38 #include "lwip/netifapi.h"
DieterGraef 0:f9b6112278fe 39 #include "lwip/tcpip.h"
DieterGraef 0:f9b6112278fe 40
DieterGraef 0:f9b6112278fe 41 /**
DieterGraef 0:f9b6112278fe 42 * Call netif_add() inside the tcpip_thread context.
DieterGraef 0:f9b6112278fe 43 */
DieterGraef 0:f9b6112278fe 44 void
DieterGraef 0:f9b6112278fe 45 do_netifapi_netif_add(struct netifapi_msg_msg *msg)
DieterGraef 0:f9b6112278fe 46 {
DieterGraef 0:f9b6112278fe 47 if (!netif_add( msg->netif,
DieterGraef 0:f9b6112278fe 48 msg->msg.add.ipaddr,
DieterGraef 0:f9b6112278fe 49 msg->msg.add.netmask,
DieterGraef 0:f9b6112278fe 50 msg->msg.add.gw,
DieterGraef 0:f9b6112278fe 51 msg->msg.add.state,
DieterGraef 0:f9b6112278fe 52 msg->msg.add.init,
DieterGraef 0:f9b6112278fe 53 msg->msg.add.input)) {
DieterGraef 0:f9b6112278fe 54 msg->err = ERR_IF;
DieterGraef 0:f9b6112278fe 55 } else {
DieterGraef 0:f9b6112278fe 56 msg->err = ERR_OK;
DieterGraef 0:f9b6112278fe 57 }
DieterGraef 0:f9b6112278fe 58 TCPIP_NETIFAPI_ACK(msg);
DieterGraef 0:f9b6112278fe 59 }
DieterGraef 0:f9b6112278fe 60
DieterGraef 0:f9b6112278fe 61 /**
DieterGraef 0:f9b6112278fe 62 * Call netif_set_addr() inside the tcpip_thread context.
DieterGraef 0:f9b6112278fe 63 */
DieterGraef 0:f9b6112278fe 64 void
DieterGraef 0:f9b6112278fe 65 do_netifapi_netif_set_addr(struct netifapi_msg_msg *msg)
DieterGraef 0:f9b6112278fe 66 {
DieterGraef 0:f9b6112278fe 67 netif_set_addr( msg->netif,
DieterGraef 0:f9b6112278fe 68 msg->msg.add.ipaddr,
DieterGraef 0:f9b6112278fe 69 msg->msg.add.netmask,
DieterGraef 0:f9b6112278fe 70 msg->msg.add.gw);
DieterGraef 0:f9b6112278fe 71 msg->err = ERR_OK;
DieterGraef 0:f9b6112278fe 72 TCPIP_NETIFAPI_ACK(msg);
DieterGraef 0:f9b6112278fe 73 }
DieterGraef 0:f9b6112278fe 74
DieterGraef 0:f9b6112278fe 75 /**
DieterGraef 0:f9b6112278fe 76 * Call the "errtfunc" (or the "voidfunc" if "errtfunc" is NULL) inside the
DieterGraef 0:f9b6112278fe 77 * tcpip_thread context.
DieterGraef 0:f9b6112278fe 78 */
DieterGraef 0:f9b6112278fe 79 void
DieterGraef 0:f9b6112278fe 80 do_netifapi_netif_common(struct netifapi_msg_msg *msg)
DieterGraef 0:f9b6112278fe 81 {
DieterGraef 0:f9b6112278fe 82 if (msg->msg.common.errtfunc != NULL) {
DieterGraef 0:f9b6112278fe 83 msg->err = msg->msg.common.errtfunc(msg->netif);
DieterGraef 0:f9b6112278fe 84 } else {
DieterGraef 0:f9b6112278fe 85 msg->err = ERR_OK;
DieterGraef 0:f9b6112278fe 86 msg->msg.common.voidfunc(msg->netif);
DieterGraef 0:f9b6112278fe 87 }
DieterGraef 0:f9b6112278fe 88 TCPIP_NETIFAPI_ACK(msg);
DieterGraef 0:f9b6112278fe 89 }
DieterGraef 0:f9b6112278fe 90
DieterGraef 0:f9b6112278fe 91 /**
DieterGraef 0:f9b6112278fe 92 * Call netif_add() in a thread-safe way by running that function inside the
DieterGraef 0:f9b6112278fe 93 * tcpip_thread context.
DieterGraef 0:f9b6112278fe 94 *
DieterGraef 0:f9b6112278fe 95 * @note for params @see netif_add()
DieterGraef 0:f9b6112278fe 96 */
DieterGraef 0:f9b6112278fe 97 err_t
DieterGraef 0:f9b6112278fe 98 netifapi_netif_add(struct netif *netif,
DieterGraef 0:f9b6112278fe 99 ip_addr_t *ipaddr,
DieterGraef 0:f9b6112278fe 100 ip_addr_t *netmask,
DieterGraef 0:f9b6112278fe 101 ip_addr_t *gw,
DieterGraef 0:f9b6112278fe 102 void *state,
DieterGraef 0:f9b6112278fe 103 netif_init_fn init,
DieterGraef 0:f9b6112278fe 104 netif_input_fn input)
DieterGraef 0:f9b6112278fe 105 {
DieterGraef 0:f9b6112278fe 106 struct netifapi_msg msg;
DieterGraef 0:f9b6112278fe 107 msg.function = do_netifapi_netif_add;
DieterGraef 0:f9b6112278fe 108 msg.msg.netif = netif;
DieterGraef 0:f9b6112278fe 109 msg.msg.msg.add.ipaddr = ipaddr;
DieterGraef 0:f9b6112278fe 110 msg.msg.msg.add.netmask = netmask;
DieterGraef 0:f9b6112278fe 111 msg.msg.msg.add.gw = gw;
DieterGraef 0:f9b6112278fe 112 msg.msg.msg.add.state = state;
DieterGraef 0:f9b6112278fe 113 msg.msg.msg.add.init = init;
DieterGraef 0:f9b6112278fe 114 msg.msg.msg.add.input = input;
DieterGraef 0:f9b6112278fe 115 TCPIP_NETIFAPI(&msg);
DieterGraef 0:f9b6112278fe 116 return msg.msg.err;
DieterGraef 0:f9b6112278fe 117 }
DieterGraef 0:f9b6112278fe 118
DieterGraef 0:f9b6112278fe 119 /**
DieterGraef 0:f9b6112278fe 120 * Call netif_set_addr() in a thread-safe way by running that function inside the
DieterGraef 0:f9b6112278fe 121 * tcpip_thread context.
DieterGraef 0:f9b6112278fe 122 *
DieterGraef 0:f9b6112278fe 123 * @note for params @see netif_set_addr()
DieterGraef 0:f9b6112278fe 124 */
DieterGraef 0:f9b6112278fe 125 err_t
DieterGraef 0:f9b6112278fe 126 netifapi_netif_set_addr(struct netif *netif,
DieterGraef 0:f9b6112278fe 127 ip_addr_t *ipaddr,
DieterGraef 0:f9b6112278fe 128 ip_addr_t *netmask,
DieterGraef 0:f9b6112278fe 129 ip_addr_t *gw)
DieterGraef 0:f9b6112278fe 130 {
DieterGraef 0:f9b6112278fe 131 struct netifapi_msg msg;
DieterGraef 0:f9b6112278fe 132 msg.function = do_netifapi_netif_set_addr;
DieterGraef 0:f9b6112278fe 133 msg.msg.netif = netif;
DieterGraef 0:f9b6112278fe 134 msg.msg.msg.add.ipaddr = ipaddr;
DieterGraef 0:f9b6112278fe 135 msg.msg.msg.add.netmask = netmask;
DieterGraef 0:f9b6112278fe 136 msg.msg.msg.add.gw = gw;
DieterGraef 0:f9b6112278fe 137 TCPIP_NETIFAPI(&msg);
DieterGraef 0:f9b6112278fe 138 return msg.msg.err;
DieterGraef 0:f9b6112278fe 139 }
DieterGraef 0:f9b6112278fe 140
DieterGraef 0:f9b6112278fe 141 /**
DieterGraef 0:f9b6112278fe 142 * call the "errtfunc" (or the "voidfunc" if "errtfunc" is NULL) in a thread-safe
DieterGraef 0:f9b6112278fe 143 * way by running that function inside the tcpip_thread context.
DieterGraef 0:f9b6112278fe 144 *
DieterGraef 0:f9b6112278fe 145 * @note use only for functions where there is only "netif" parameter.
DieterGraef 0:f9b6112278fe 146 */
DieterGraef 0:f9b6112278fe 147 err_t
DieterGraef 0:f9b6112278fe 148 netifapi_netif_common(struct netif *netif, netifapi_void_fn voidfunc,
DieterGraef 0:f9b6112278fe 149 netifapi_errt_fn errtfunc)
DieterGraef 0:f9b6112278fe 150 {
DieterGraef 0:f9b6112278fe 151 struct netifapi_msg msg;
DieterGraef 0:f9b6112278fe 152 msg.function = do_netifapi_netif_common;
DieterGraef 0:f9b6112278fe 153 msg.msg.netif = netif;
DieterGraef 0:f9b6112278fe 154 msg.msg.msg.common.voidfunc = voidfunc;
DieterGraef 0:f9b6112278fe 155 msg.msg.msg.common.errtfunc = errtfunc;
DieterGraef 0:f9b6112278fe 156 TCPIP_NETIFAPI(&msg);
DieterGraef 0:f9b6112278fe 157 return msg.msg.err;
DieterGraef 0:f9b6112278fe 158 }
DieterGraef 0:f9b6112278fe 159
DieterGraef 0:f9b6112278fe 160 #endif /* LWIP_NETIF_API */