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 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
DieterGraef 0:f9b6112278fe 3 * All rights reserved.
DieterGraef 0:f9b6112278fe 4 *
DieterGraef 0:f9b6112278fe 5 * Redistribution and use in source and binary forms, with or without modification,
DieterGraef 0:f9b6112278fe 6 * are permitted provided that the following conditions are met:
DieterGraef 0:f9b6112278fe 7 *
DieterGraef 0:f9b6112278fe 8 * 1. Redistributions of source code must retain the above copyright notice,
DieterGraef 0:f9b6112278fe 9 * this list of conditions and the following disclaimer.
DieterGraef 0:f9b6112278fe 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
DieterGraef 0:f9b6112278fe 11 * this list of conditions and the following disclaimer in the documentation
DieterGraef 0:f9b6112278fe 12 * and/or other materials provided with the distribution.
DieterGraef 0:f9b6112278fe 13 * 3. The name of the author may not be used to endorse or promote products
DieterGraef 0:f9b6112278fe 14 * derived from this software without specific prior written permission.
DieterGraef 0:f9b6112278fe 15 *
DieterGraef 0:f9b6112278fe 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
DieterGraef 0:f9b6112278fe 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
DieterGraef 0:f9b6112278fe 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
DieterGraef 0:f9b6112278fe 19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
DieterGraef 0:f9b6112278fe 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
DieterGraef 0:f9b6112278fe 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
DieterGraef 0:f9b6112278fe 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
DieterGraef 0:f9b6112278fe 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
DieterGraef 0:f9b6112278fe 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
DieterGraef 0:f9b6112278fe 25 * OF SUCH DAMAGE.
DieterGraef 0:f9b6112278fe 26 *
DieterGraef 0:f9b6112278fe 27 * This file is part of the lwIP TCP/IP stack.
DieterGraef 0:f9b6112278fe 28 *
DieterGraef 0:f9b6112278fe 29 * Author: Adam Dunkels <adam@sics.se>
DieterGraef 0:f9b6112278fe 30 *
DieterGraef 0:f9b6112278fe 31 */
DieterGraef 0:f9b6112278fe 32 #ifndef __LWIP_API_MSG_H__
DieterGraef 0:f9b6112278fe 33 #define __LWIP_API_MSG_H__
DieterGraef 0:f9b6112278fe 34
DieterGraef 0:f9b6112278fe 35 #include "lwip/opt.h"
DieterGraef 0:f9b6112278fe 36
DieterGraef 0:f9b6112278fe 37 #if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */
DieterGraef 0:f9b6112278fe 38
DieterGraef 0:f9b6112278fe 39 #include <stddef.h> /* for size_t */
DieterGraef 0:f9b6112278fe 40
DieterGraef 0:f9b6112278fe 41 #include "lwip/ip_addr.h"
DieterGraef 0:f9b6112278fe 42 #include "lwip/err.h"
DieterGraef 0:f9b6112278fe 43 #include "lwip/sys.h"
DieterGraef 0:f9b6112278fe 44 #include "lwip/igmp.h"
DieterGraef 0:f9b6112278fe 45 #include "lwip/api.h"
DieterGraef 0:f9b6112278fe 46
DieterGraef 0:f9b6112278fe 47 #ifdef __cplusplus
DieterGraef 0:f9b6112278fe 48 extern "C" {
DieterGraef 0:f9b6112278fe 49 #endif
DieterGraef 0:f9b6112278fe 50
DieterGraef 0:f9b6112278fe 51 /* For the netconn API, these values are use as a bitmask! */
DieterGraef 0:f9b6112278fe 52 #define NETCONN_SHUT_RD 1
DieterGraef 0:f9b6112278fe 53 #define NETCONN_SHUT_WR 2
DieterGraef 0:f9b6112278fe 54 #define NETCONN_SHUT_RDWR (NETCONN_SHUT_RD | NETCONN_SHUT_WR)
DieterGraef 0:f9b6112278fe 55
DieterGraef 0:f9b6112278fe 56 /* IP addresses and port numbers are expected to be in
DieterGraef 0:f9b6112278fe 57 * the same byte order as in the corresponding pcb.
DieterGraef 0:f9b6112278fe 58 */
DieterGraef 0:f9b6112278fe 59 /** This struct includes everything that is necessary to execute a function
DieterGraef 0:f9b6112278fe 60 for a netconn in another thread context (mainly used to process netconns
DieterGraef 0:f9b6112278fe 61 in the tcpip_thread context to be thread safe). */
DieterGraef 0:f9b6112278fe 62 struct api_msg_msg {
DieterGraef 0:f9b6112278fe 63 /** The netconn which to process - always needed: it includes the semaphore
DieterGraef 0:f9b6112278fe 64 which is used to block the application thread until the function finished. */
DieterGraef 0:f9b6112278fe 65 struct netconn *conn;
DieterGraef 0:f9b6112278fe 66 /** The return value of the function executed in tcpip_thread. */
DieterGraef 0:f9b6112278fe 67 err_t err;
DieterGraef 0:f9b6112278fe 68 /** Depending on the executed function, one of these union members is used */
DieterGraef 0:f9b6112278fe 69 union {
DieterGraef 0:f9b6112278fe 70 /** used for do_send */
DieterGraef 0:f9b6112278fe 71 struct netbuf *b;
DieterGraef 0:f9b6112278fe 72 /** used for do_newconn */
DieterGraef 0:f9b6112278fe 73 struct {
DieterGraef 0:f9b6112278fe 74 u8_t proto;
DieterGraef 0:f9b6112278fe 75 } n;
DieterGraef 0:f9b6112278fe 76 /** used for do_bind and do_connect */
DieterGraef 0:f9b6112278fe 77 struct {
DieterGraef 0:f9b6112278fe 78 ip_addr_t *ipaddr;
DieterGraef 0:f9b6112278fe 79 u16_t port;
DieterGraef 0:f9b6112278fe 80 } bc;
DieterGraef 0:f9b6112278fe 81 /** used for do_getaddr */
DieterGraef 0:f9b6112278fe 82 struct {
DieterGraef 0:f9b6112278fe 83 ip_addr_t *ipaddr;
DieterGraef 0:f9b6112278fe 84 u16_t *port;
DieterGraef 0:f9b6112278fe 85 u8_t local;
DieterGraef 0:f9b6112278fe 86 } ad;
DieterGraef 0:f9b6112278fe 87 /** used for do_write */
DieterGraef 0:f9b6112278fe 88 struct {
DieterGraef 0:f9b6112278fe 89 const void *dataptr;
DieterGraef 0:f9b6112278fe 90 size_t len;
DieterGraef 0:f9b6112278fe 91 u8_t apiflags;
DieterGraef 0:f9b6112278fe 92 #if LWIP_SO_SNDTIMEO
DieterGraef 0:f9b6112278fe 93 u32_t time_started;
DieterGraef 0:f9b6112278fe 94 #endif /* LWIP_SO_SNDTIMEO */
DieterGraef 0:f9b6112278fe 95 } w;
DieterGraef 0:f9b6112278fe 96 /** used for do_recv */
DieterGraef 0:f9b6112278fe 97 struct {
DieterGraef 0:f9b6112278fe 98 u32_t len;
DieterGraef 0:f9b6112278fe 99 } r;
DieterGraef 0:f9b6112278fe 100 /** used for do_close (/shutdown) */
DieterGraef 0:f9b6112278fe 101 struct {
DieterGraef 0:f9b6112278fe 102 u8_t shut;
DieterGraef 0:f9b6112278fe 103 } sd;
DieterGraef 0:f9b6112278fe 104 #if LWIP_IGMP
DieterGraef 0:f9b6112278fe 105 /** used for do_join_leave_group */
DieterGraef 0:f9b6112278fe 106 struct {
DieterGraef 0:f9b6112278fe 107 ip_addr_t *multiaddr;
DieterGraef 0:f9b6112278fe 108 ip_addr_t *netif_addr;
DieterGraef 0:f9b6112278fe 109 enum netconn_igmp join_or_leave;
DieterGraef 0:f9b6112278fe 110 } jl;
DieterGraef 0:f9b6112278fe 111 #endif /* LWIP_IGMP */
DieterGraef 0:f9b6112278fe 112 #if TCP_LISTEN_BACKLOG
DieterGraef 0:f9b6112278fe 113 struct {
DieterGraef 0:f9b6112278fe 114 u8_t backlog;
DieterGraef 0:f9b6112278fe 115 } lb;
DieterGraef 0:f9b6112278fe 116 #endif /* TCP_LISTEN_BACKLOG */
DieterGraef 0:f9b6112278fe 117 } msg;
DieterGraef 0:f9b6112278fe 118 };
DieterGraef 0:f9b6112278fe 119
DieterGraef 0:f9b6112278fe 120 /** This struct contains a function to execute in another thread context and
DieterGraef 0:f9b6112278fe 121 a struct api_msg_msg that serves as an argument for this function.
DieterGraef 0:f9b6112278fe 122 This is passed to tcpip_apimsg to execute functions in tcpip_thread context. */
DieterGraef 0:f9b6112278fe 123 struct api_msg {
DieterGraef 0:f9b6112278fe 124 /** function to execute in tcpip_thread context */
DieterGraef 0:f9b6112278fe 125 void (* function)(struct api_msg_msg *msg);
DieterGraef 0:f9b6112278fe 126 /** arguments for this function */
DieterGraef 0:f9b6112278fe 127 struct api_msg_msg msg;
DieterGraef 0:f9b6112278fe 128 };
DieterGraef 0:f9b6112278fe 129
DieterGraef 0:f9b6112278fe 130 #if LWIP_DNS
DieterGraef 0:f9b6112278fe 131 /** As do_gethostbyname requires more arguments but doesn't require a netconn,
DieterGraef 0:f9b6112278fe 132 it has its own struct (to avoid struct api_msg getting bigger than necessary).
DieterGraef 0:f9b6112278fe 133 do_gethostbyname must be called using tcpip_callback instead of tcpip_apimsg
DieterGraef 0:f9b6112278fe 134 (see netconn_gethostbyname). */
DieterGraef 0:f9b6112278fe 135 struct dns_api_msg {
DieterGraef 0:f9b6112278fe 136 /** Hostname to query or dotted IP address string */
DieterGraef 0:f9b6112278fe 137 const char *name;
DieterGraef 0:f9b6112278fe 138 /** Rhe resolved address is stored here */
DieterGraef 0:f9b6112278fe 139 ip_addr_t *addr;
DieterGraef 0:f9b6112278fe 140 /** This semaphore is posted when the name is resolved, the application thread
DieterGraef 0:f9b6112278fe 141 should wait on it. */
DieterGraef 0:f9b6112278fe 142 sys_sem_t *sem;
DieterGraef 0:f9b6112278fe 143 /** Errors are given back here */
DieterGraef 0:f9b6112278fe 144 err_t *err;
DieterGraef 0:f9b6112278fe 145 };
DieterGraef 0:f9b6112278fe 146 #endif /* LWIP_DNS */
DieterGraef 0:f9b6112278fe 147
DieterGraef 0:f9b6112278fe 148 void do_newconn ( struct api_msg_msg *msg);
DieterGraef 0:f9b6112278fe 149 void do_delconn ( struct api_msg_msg *msg);
DieterGraef 0:f9b6112278fe 150 void do_bind ( struct api_msg_msg *msg);
DieterGraef 0:f9b6112278fe 151 void do_connect ( struct api_msg_msg *msg);
DieterGraef 0:f9b6112278fe 152 void do_disconnect ( struct api_msg_msg *msg);
DieterGraef 0:f9b6112278fe 153 void do_listen ( struct api_msg_msg *msg);
DieterGraef 0:f9b6112278fe 154 void do_send ( struct api_msg_msg *msg);
DieterGraef 0:f9b6112278fe 155 void do_recv ( struct api_msg_msg *msg);
DieterGraef 0:f9b6112278fe 156 void do_write ( struct api_msg_msg *msg);
DieterGraef 0:f9b6112278fe 157 void do_getaddr ( struct api_msg_msg *msg);
DieterGraef 0:f9b6112278fe 158 void do_close ( struct api_msg_msg *msg);
DieterGraef 0:f9b6112278fe 159 void do_shutdown ( struct api_msg_msg *msg);
DieterGraef 0:f9b6112278fe 160 #if LWIP_IGMP
DieterGraef 0:f9b6112278fe 161 void do_join_leave_group( struct api_msg_msg *msg);
DieterGraef 0:f9b6112278fe 162 #endif /* LWIP_IGMP */
DieterGraef 0:f9b6112278fe 163
DieterGraef 0:f9b6112278fe 164 #if LWIP_DNS
DieterGraef 0:f9b6112278fe 165 void do_gethostbyname(void *arg);
DieterGraef 0:f9b6112278fe 166 #endif /* LWIP_DNS */
DieterGraef 0:f9b6112278fe 167
DieterGraef 0:f9b6112278fe 168 struct netconn* netconn_alloc(enum netconn_type t, netconn_callback callback);
DieterGraef 0:f9b6112278fe 169 void netconn_free(struct netconn *conn);
DieterGraef 0:f9b6112278fe 170
DieterGraef 0:f9b6112278fe 171 #ifdef __cplusplus
DieterGraef 0:f9b6112278fe 172 }
DieterGraef 0:f9b6112278fe 173 #endif
DieterGraef 0:f9b6112278fe 174
DieterGraef 0:f9b6112278fe 175 #endif /* LWIP_NETCONN */
DieterGraef 0:f9b6112278fe 176
DieterGraef 0:f9b6112278fe 177 #endif /* __LWIP_API_MSG_H__ */