Forked from STM32F7 internet for nucleo F746ZG

Dependents:   Nucleo_F746ZG_Ethernet_MQTT_Ultrasound

Fork of F7_Ethernet by Dieter Graef

Committer:
DieterGraef
Date:
Sun Jun 19 16:23:40 2016 +0000
Revision:
0:d26c1b55cfca
Ethernet Library for Nucleo stm32f746ZG and Disco stm32f746NG  works under arm and gcc environment

Who changed what in which revision?

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