Tom Martins
/
Probleme_implementation_lwip2
test public
Fork of Probleme_implementation_lwip by
ethernetif.cpp@2:9e76d51d9fb6, 2018-07-02 (annotated)
- Committer:
- TomTom83
- Date:
- Mon Jul 02 15:18:18 2018 +0000
- Revision:
- 2:9e76d51d9fb6
- Parent:
- 1:a3ee8cb24540
probl?mes d'adaptation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
TomTom83 | 1:a3ee8cb24540 | 1 | /** |
TomTom83 | 1:a3ee8cb24540 | 2 | * @file |
TomTom83 | 1:a3ee8cb24540 | 3 | * Ethernet Interface for standalone applications (without RTOS) - works only for |
TomTom83 | 1:a3ee8cb24540 | 4 | * ethernet polling mode (polling for ethernet frame reception) |
TomTom83 | 1:a3ee8cb24540 | 5 | * |
TomTom83 | 1:a3ee8cb24540 | 6 | */ |
TomTom83 | 1:a3ee8cb24540 | 7 | |
TomTom83 | 1:a3ee8cb24540 | 8 | /* |
TomTom83 | 1:a3ee8cb24540 | 9 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. |
TomTom83 | 1:a3ee8cb24540 | 10 | * All rights reserved. |
TomTom83 | 1:a3ee8cb24540 | 11 | * |
TomTom83 | 1:a3ee8cb24540 | 12 | * Redistribution and use in source and binary forms, with or without modification, |
TomTom83 | 1:a3ee8cb24540 | 13 | * are permitted provided that the following conditions are met: |
TomTom83 | 1:a3ee8cb24540 | 14 | * |
TomTom83 | 1:a3ee8cb24540 | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
TomTom83 | 1:a3ee8cb24540 | 16 | * this list of conditions and the following disclaimer. |
TomTom83 | 1:a3ee8cb24540 | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
TomTom83 | 1:a3ee8cb24540 | 18 | * this list of conditions and the following disclaimer in the documentation |
TomTom83 | 1:a3ee8cb24540 | 19 | * and/or other materials provided with the distribution. |
TomTom83 | 1:a3ee8cb24540 | 20 | * 3. The name of the author may not be used to endorse or promote products |
TomTom83 | 1:a3ee8cb24540 | 21 | * derived from this software without specific prior written permission. |
TomTom83 | 1:a3ee8cb24540 | 22 | * |
TomTom83 | 1:a3ee8cb24540 | 23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
TomTom83 | 1:a3ee8cb24540 | 24 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
TomTom83 | 1:a3ee8cb24540 | 25 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT |
TomTom83 | 1:a3ee8cb24540 | 26 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
TomTom83 | 1:a3ee8cb24540 | 27 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT |
TomTom83 | 1:a3ee8cb24540 | 28 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
TomTom83 | 1:a3ee8cb24540 | 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
TomTom83 | 1:a3ee8cb24540 | 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
TomTom83 | 1:a3ee8cb24540 | 31 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY |
TomTom83 | 1:a3ee8cb24540 | 32 | * OF SUCH DAMAGE. |
TomTom83 | 1:a3ee8cb24540 | 33 | * |
TomTom83 | 1:a3ee8cb24540 | 34 | * This file is part of the lwIP TCP/IP stack. |
TomTom83 | 1:a3ee8cb24540 | 35 | * |
TomTom83 | 1:a3ee8cb24540 | 36 | * Author: Adam Dunkels <adam@sics.se> |
TomTom83 | 1:a3ee8cb24540 | 37 | * |
TomTom83 | 1:a3ee8cb24540 | 38 | */ |
TomTom83 | 1:a3ee8cb24540 | 39 | |
TomTom83 | 1:a3ee8cb24540 | 40 | #include "lwip/mem.h" |
TomTom83 | 1:a3ee8cb24540 | 41 | #include "netif/etharp.h" |
TomTom83 | 1:a3ee8cb24540 | 42 | #include "ethernetif.h" |
TomTom83 | 1:a3ee8cb24540 | 43 | #include "main.h" |
TomTom83 | 1:a3ee8cb24540 | 44 | #include <string.h> |
TomTom83 | 1:a3ee8cb24540 | 45 | |
TomTom83 | 1:a3ee8cb24540 | 46 | /* Network interface name */ |
TomTom83 | 1:a3ee8cb24540 | 47 | #define IFNAME0 's' |
TomTom83 | 1:a3ee8cb24540 | 48 | #define IFNAME1 't' |
TomTom83 | 1:a3ee8cb24540 | 49 | |
TomTom83 | 1:a3ee8cb24540 | 50 | |
TomTom83 | 1:a3ee8cb24540 | 51 | /* Ethernet Rx & Tx DMA Descriptors */ |
TomTom83 | 1:a3ee8cb24540 | 52 | extern ETH_DMADESCTypeDef DMARxDscrTab[ETH_RXBUFNB], DMATxDscrTab[ETH_TXBUFNB]; |
TomTom83 | 1:a3ee8cb24540 | 53 | |
TomTom83 | 1:a3ee8cb24540 | 54 | /* Ethernet Driver Receive buffers */ |
TomTom83 | 1:a3ee8cb24540 | 55 | extern uint8_t Rx_Buff[ETH_RXBUFNB][ETH_RX_BUF_SIZE]; |
TomTom83 | 1:a3ee8cb24540 | 56 | |
TomTom83 | 1:a3ee8cb24540 | 57 | /* Ethernet Driver Transmit buffers */ |
TomTom83 | 1:a3ee8cb24540 | 58 | extern uint8_t Tx_Buff[ETH_TXBUFNB][ETH_TX_BUF_SIZE]; |
TomTom83 | 1:a3ee8cb24540 | 59 | |
TomTom83 | 1:a3ee8cb24540 | 60 | /* Global pointers to track current transmit and receive descriptors */ |
TomTom83 | 1:a3ee8cb24540 | 61 | extern ETH_DMADESCTypeDef *DMATxDescToSet; |
TomTom83 | 1:a3ee8cb24540 | 62 | extern ETH_DMADESCTypeDef *DMARxDescToGet; |
TomTom83 | 1:a3ee8cb24540 | 63 | |
TomTom83 | 1:a3ee8cb24540 | 64 | /* Global pointer for last received frame infos */ |
TomTom83 | 1:a3ee8cb24540 | 65 | extern ETH_DMA_Rx_Frame_infos *DMA_RX_FRAME_infos; |
TomTom83 | 1:a3ee8cb24540 | 66 | |
TomTom83 | 1:a3ee8cb24540 | 67 | |
TomTom83 | 1:a3ee8cb24540 | 68 | |
TomTom83 | 1:a3ee8cb24540 | 69 | |
TomTom83 | 1:a3ee8cb24540 | 70 | /** |
TomTom83 | 1:a3ee8cb24540 | 71 | * In this function, the hardware should be initialized. |
TomTom83 | 1:a3ee8cb24540 | 72 | * Called from ethernetif_init(). |
TomTom83 | 1:a3ee8cb24540 | 73 | * |
TomTom83 | 1:a3ee8cb24540 | 74 | * @param netif the already initialized lwip network interface structure |
TomTom83 | 1:a3ee8cb24540 | 75 | * for this ethernetif |
TomTom83 | 1:a3ee8cb24540 | 76 | */ |
TomTom83 | 1:a3ee8cb24540 | 77 | static void low_level_init(struct netif *netif) |
TomTom83 | 1:a3ee8cb24540 | 78 | { |
TomTom83 | 1:a3ee8cb24540 | 79 | #ifdef CHECKSUM_BY_HARDWARE |
TomTom83 | 1:a3ee8cb24540 | 80 | int i; |
TomTom83 | 1:a3ee8cb24540 | 81 | #endif |
TomTom83 | 1:a3ee8cb24540 | 82 | /* set MAC hardware address length */ |
TomTom83 | 1:a3ee8cb24540 | 83 | netif->hwaddr_len = ETHARP_HWADDR_LEN; |
TomTom83 | 1:a3ee8cb24540 | 84 | |
TomTom83 | 1:a3ee8cb24540 | 85 | /* set MAC hardware address */ |
TomTom83 | 1:a3ee8cb24540 | 86 | netif->hwaddr[0] = MAC_ADDR0; |
TomTom83 | 1:a3ee8cb24540 | 87 | netif->hwaddr[1] = MAC_ADDR1; |
TomTom83 | 1:a3ee8cb24540 | 88 | netif->hwaddr[2] = MAC_ADDR2; |
TomTom83 | 1:a3ee8cb24540 | 89 | netif->hwaddr[3] = MAC_ADDR3; |
TomTom83 | 1:a3ee8cb24540 | 90 | netif->hwaddr[4] = MAC_ADDR4; |
TomTom83 | 1:a3ee8cb24540 | 91 | netif->hwaddr[5] = MAC_ADDR5; |
TomTom83 | 1:a3ee8cb24540 | 92 | |
TomTom83 | 1:a3ee8cb24540 | 93 | /* initialize MAC address in ethernet MAC */ |
TomTom83 | 1:a3ee8cb24540 | 94 | ETH_MACAddressConfig(ETH_MAC_Address0, netif->hwaddr); |
TomTom83 | 1:a3ee8cb24540 | 95 | |
TomTom83 | 1:a3ee8cb24540 | 96 | /* maximum transfer unit */ |
TomTom83 | 1:a3ee8cb24540 | 97 | netif->mtu = 1500; |
TomTom83 | 1:a3ee8cb24540 | 98 | |
TomTom83 | 1:a3ee8cb24540 | 99 | /* device capabilities */ |
TomTom83 | 1:a3ee8cb24540 | 100 | /* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */ |
TomTom83 | 1:a3ee8cb24540 | 101 | netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP; |
TomTom83 | 1:a3ee8cb24540 | 102 | |
TomTom83 | 1:a3ee8cb24540 | 103 | /* Initialize Tx Descriptors list: Chain Mode */ |
TomTom83 | 1:a3ee8cb24540 | 104 | ETH_DMATxDescChainInit(DMATxDscrTab, &Tx_Buff[0][0], ETH_TXBUFNB); |
TomTom83 | 1:a3ee8cb24540 | 105 | /* Initialize Rx Descriptors list: Chain Mode */ |
TomTom83 | 1:a3ee8cb24540 | 106 | ETH_DMARxDescChainInit(DMARxDscrTab, &Rx_Buff[0][0], ETH_RXBUFNB); |
TomTom83 | 1:a3ee8cb24540 | 107 | |
TomTom83 | 1:a3ee8cb24540 | 108 | #ifdef CHECKSUM_BY_HARDWARE |
TomTom83 | 1:a3ee8cb24540 | 109 | /* Enable the TCP, UDP and ICMP checksum insertion for the Tx frames */ |
TomTom83 | 1:a3ee8cb24540 | 110 | for(i=0; i<ETH_TXBUFNB; i++) |
TomTom83 | 1:a3ee8cb24540 | 111 | { |
TomTom83 | 1:a3ee8cb24540 | 112 | ETH_DMATxDescChecksumInsertionConfig(&DMATxDscrTab[i], ETH_DMATxDesc_ChecksumTCPUDPICMPFull); |
TomTom83 | 1:a3ee8cb24540 | 113 | } |
TomTom83 | 1:a3ee8cb24540 | 114 | #endif |
TomTom83 | 1:a3ee8cb24540 | 115 | |
TomTom83 | 1:a3ee8cb24540 | 116 | /* Note: TCP, UDP, ICMP checksum checking for received frame are enabled in DMA config */ |
TomTom83 | 1:a3ee8cb24540 | 117 | |
TomTom83 | 1:a3ee8cb24540 | 118 | /* Enable MAC and DMA transmission and reception */ |
TomTom83 | 1:a3ee8cb24540 | 119 | ETH_Start(); |
TomTom83 | 1:a3ee8cb24540 | 120 | |
TomTom83 | 1:a3ee8cb24540 | 121 | } |
TomTom83 | 1:a3ee8cb24540 | 122 | |
TomTom83 | 1:a3ee8cb24540 | 123 | /** |
TomTom83 | 1:a3ee8cb24540 | 124 | * This function should do the actual transmission of the packet. The packet is |
TomTom83 | 1:a3ee8cb24540 | 125 | * contained in the pbuf that is passed to the function. This pbuf |
TomTom83 | 1:a3ee8cb24540 | 126 | * might be chained. |
TomTom83 | 1:a3ee8cb24540 | 127 | * |
TomTom83 | 1:a3ee8cb24540 | 128 | * @param netif the lwip network interface structure for this ethernetif |
TomTom83 | 1:a3ee8cb24540 | 129 | * @param p the MAC packet to send (e.g. IP packet including MAC addresses and type) |
TomTom83 | 1:a3ee8cb24540 | 130 | * @return ERR_OK if the packet could be sent |
TomTom83 | 1:a3ee8cb24540 | 131 | * an err_t value if the packet couldn't be sent |
TomTom83 | 1:a3ee8cb24540 | 132 | * |
TomTom83 | 1:a3ee8cb24540 | 133 | * @note Returning ERR_MEM here if a DMA queue of your MAC is full can lead to |
TomTom83 | 1:a3ee8cb24540 | 134 | * strange results. You might consider waiting for space in the DMA queue |
TomTom83 | 1:a3ee8cb24540 | 135 | * to become availale since the stack doesn't retry to send a packet |
TomTom83 | 1:a3ee8cb24540 | 136 | * dropped because of memory failure (except for the TCP timers). |
TomTom83 | 1:a3ee8cb24540 | 137 | */ |
TomTom83 | 1:a3ee8cb24540 | 138 | |
TomTom83 | 1:a3ee8cb24540 | 139 | static err_t low_level_output(struct netif *netif, struct pbuf *p) |
TomTom83 | 1:a3ee8cb24540 | 140 | { |
TomTom83 | 1:a3ee8cb24540 | 141 | struct pbuf *q; |
TomTom83 | 1:a3ee8cb24540 | 142 | int framelength = 0; |
TomTom83 | 1:a3ee8cb24540 | 143 | u8 *buffer = (u8 *)(DMATxDescToSet->Buffer1Addr); |
TomTom83 | 1:a3ee8cb24540 | 144 | |
TomTom83 | 1:a3ee8cb24540 | 145 | /* copy frame from pbufs to driver buffers */ |
TomTom83 | 1:a3ee8cb24540 | 146 | for(q = p; q != NULL; q = q->next) |
TomTom83 | 1:a3ee8cb24540 | 147 | { |
TomTom83 | 1:a3ee8cb24540 | 148 | memcpy((u8_t*)&buffer[framelength], q->payload, q->len); |
TomTom83 | 1:a3ee8cb24540 | 149 | framelength = framelength + q->len; |
TomTom83 | 1:a3ee8cb24540 | 150 | } |
TomTom83 | 1:a3ee8cb24540 | 151 | |
TomTom83 | 1:a3ee8cb24540 | 152 | /* Note: padding and CRC for transmitted frame |
TomTom83 | 1:a3ee8cb24540 | 153 | are automatically inserted by DMA */ |
TomTom83 | 1:a3ee8cb24540 | 154 | |
TomTom83 | 1:a3ee8cb24540 | 155 | /* Prepare transmit descriptors to give to DMA*/ |
TomTom83 | 1:a3ee8cb24540 | 156 | ETH_Prepare_Transmit_Descriptors(framelength); |
TomTom83 | 1:a3ee8cb24540 | 157 | |
TomTom83 | 1:a3ee8cb24540 | 158 | return ERR_OK; |
TomTom83 | 1:a3ee8cb24540 | 159 | } |
TomTom83 | 1:a3ee8cb24540 | 160 | |
TomTom83 | 1:a3ee8cb24540 | 161 | /** |
TomTom83 | 1:a3ee8cb24540 | 162 | * Should allocate a pbuf and transfer the bytes of the incoming |
TomTom83 | 1:a3ee8cb24540 | 163 | * packet from the interface into the pbuf. |
TomTom83 | 1:a3ee8cb24540 | 164 | * |
TomTom83 | 1:a3ee8cb24540 | 165 | * @param netif the lwip network interface structure for this ethernetif |
TomTom83 | 1:a3ee8cb24540 | 166 | * @return a pbuf filled with the received packet (including MAC header) |
TomTom83 | 1:a3ee8cb24540 | 167 | * NULL on memory error |
TomTom83 | 1:a3ee8cb24540 | 168 | */ |
TomTom83 | 1:a3ee8cb24540 | 169 | static struct pbuf * low_level_input(struct netif *netif) |
TomTom83 | 1:a3ee8cb24540 | 170 | { |
TomTom83 | 1:a3ee8cb24540 | 171 | struct pbuf *p, *q; |
TomTom83 | 1:a3ee8cb24540 | 172 | u16_t len; |
TomTom83 | 1:a3ee8cb24540 | 173 | int l =0; |
TomTom83 | 1:a3ee8cb24540 | 174 | FrameTypeDef frame; |
TomTom83 | 1:a3ee8cb24540 | 175 | u8 *buffer; |
TomTom83 | 1:a3ee8cb24540 | 176 | uint32_t i=0; |
TomTom83 | 1:a3ee8cb24540 | 177 | __IO ETH_DMADESCTypeDef *DMARxNextDesc; |
TomTom83 | 1:a3ee8cb24540 | 178 | |
TomTom83 | 1:a3ee8cb24540 | 179 | |
TomTom83 | 1:a3ee8cb24540 | 180 | p = NULL; |
TomTom83 | 1:a3ee8cb24540 | 181 | |
TomTom83 | 1:a3ee8cb24540 | 182 | /* get received frame */ |
TomTom83 | 1:a3ee8cb24540 | 183 | frame = ETH_Get_Received_Frame(); |
TomTom83 | 1:a3ee8cb24540 | 184 | |
TomTom83 | 1:a3ee8cb24540 | 185 | /* Obtain the size of the packet and put it into the "len" variable. */ |
TomTom83 | 1:a3ee8cb24540 | 186 | len = frame.length; |
TomTom83 | 1:a3ee8cb24540 | 187 | buffer = (u8 *)frame.buffer; |
TomTom83 | 1:a3ee8cb24540 | 188 | |
TomTom83 | 1:a3ee8cb24540 | 189 | /* We allocate a pbuf chain of pbufs from the Lwip buffer pool */ |
TomTom83 | 1:a3ee8cb24540 | 190 | p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL); |
TomTom83 | 1:a3ee8cb24540 | 191 | |
TomTom83 | 1:a3ee8cb24540 | 192 | /* copy received frame to pbuf chain */ |
TomTom83 | 1:a3ee8cb24540 | 193 | if (p != NULL) |
TomTom83 | 1:a3ee8cb24540 | 194 | { |
TomTom83 | 1:a3ee8cb24540 | 195 | for (q = p; q != NULL; q = q->next) |
TomTom83 | 1:a3ee8cb24540 | 196 | { |
TomTom83 | 1:a3ee8cb24540 | 197 | memcpy((u8_t*)q->payload, (u8_t*)&buffer[l], q->len); |
TomTom83 | 1:a3ee8cb24540 | 198 | l = l + q->len; |
TomTom83 | 1:a3ee8cb24540 | 199 | } |
TomTom83 | 1:a3ee8cb24540 | 200 | } |
TomTom83 | 1:a3ee8cb24540 | 201 | |
TomTom83 | 1:a3ee8cb24540 | 202 | /* Release descriptors to DMA */ |
TomTom83 | 1:a3ee8cb24540 | 203 | /* Check if frame with multiple DMA buffer segments */ |
TomTom83 | 1:a3ee8cb24540 | 204 | if (DMA_RX_FRAME_infos->Seg_Count > 1) |
TomTom83 | 1:a3ee8cb24540 | 205 | { |
TomTom83 | 1:a3ee8cb24540 | 206 | DMARxNextDesc = DMA_RX_FRAME_infos->FS_Rx_Desc; |
TomTom83 | 1:a3ee8cb24540 | 207 | } |
TomTom83 | 1:a3ee8cb24540 | 208 | else |
TomTom83 | 1:a3ee8cb24540 | 209 | { |
TomTom83 | 1:a3ee8cb24540 | 210 | DMARxNextDesc = frame.descriptor; |
TomTom83 | 1:a3ee8cb24540 | 211 | } |
TomTom83 | 1:a3ee8cb24540 | 212 | |
TomTom83 | 1:a3ee8cb24540 | 213 | /* Set Own bit in Rx descriptors: gives the buffers back to DMA */ |
TomTom83 | 1:a3ee8cb24540 | 214 | for (i=0; i<DMA_RX_FRAME_infos->Seg_Count; i++) |
TomTom83 | 1:a3ee8cb24540 | 215 | { |
TomTom83 | 1:a3ee8cb24540 | 216 | DMARxNextDesc->Status = ETH_DMARxDesc_OWN; |
TomTom83 | 1:a3ee8cb24540 | 217 | DMARxNextDesc = (ETH_DMADESCTypeDef *)(DMARxNextDesc->Buffer2NextDescAddr); |
TomTom83 | 1:a3ee8cb24540 | 218 | } |
TomTom83 | 1:a3ee8cb24540 | 219 | |
TomTom83 | 1:a3ee8cb24540 | 220 | /* Clear Segment_Count */ |
TomTom83 | 1:a3ee8cb24540 | 221 | DMA_RX_FRAME_infos->Seg_Count =0; |
TomTom83 | 1:a3ee8cb24540 | 222 | |
TomTom83 | 1:a3ee8cb24540 | 223 | /* When Rx Buffer unavailable flag is set: clear it and resume reception */ |
TomTom83 | 1:a3ee8cb24540 | 224 | if ((ETH->DMASR & ETH_DMASR_RBUS) != (u32)RESET) |
TomTom83 | 1:a3ee8cb24540 | 225 | { |
TomTom83 | 1:a3ee8cb24540 | 226 | /* Clear RBUS ETHERNET DMA flag */ |
TomTom83 | 1:a3ee8cb24540 | 227 | ETH->DMASR = ETH_DMASR_RBUS; |
TomTom83 | 1:a3ee8cb24540 | 228 | /* Resume DMA reception */ |
TomTom83 | 1:a3ee8cb24540 | 229 | ETH->DMARPDR = 0; |
TomTom83 | 1:a3ee8cb24540 | 230 | } |
TomTom83 | 1:a3ee8cb24540 | 231 | return p; |
TomTom83 | 1:a3ee8cb24540 | 232 | } |
TomTom83 | 1:a3ee8cb24540 | 233 | |
TomTom83 | 1:a3ee8cb24540 | 234 | /** |
TomTom83 | 1:a3ee8cb24540 | 235 | * This function should be called when a packet is ready to be read |
TomTom83 | 1:a3ee8cb24540 | 236 | * from the interface. It uses the function low_level_input() that |
TomTom83 | 1:a3ee8cb24540 | 237 | * should handle the actual reception of bytes from the network |
TomTom83 | 1:a3ee8cb24540 | 238 | * interface. Then the type of the received packet is determined and |
TomTom83 | 1:a3ee8cb24540 | 239 | * the appropriate input function is called. |
TomTom83 | 1:a3ee8cb24540 | 240 | * |
TomTom83 | 1:a3ee8cb24540 | 241 | * @param netif the lwip network interface structure for this ethernetif |
TomTom83 | 1:a3ee8cb24540 | 242 | */ |
TomTom83 | 1:a3ee8cb24540 | 243 | err_t ethernetif_input(struct netif *netif) |
TomTom83 | 1:a3ee8cb24540 | 244 | { |
TomTom83 | 1:a3ee8cb24540 | 245 | err_t err; |
TomTom83 | 1:a3ee8cb24540 | 246 | struct pbuf *p; |
TomTom83 | 1:a3ee8cb24540 | 247 | |
TomTom83 | 1:a3ee8cb24540 | 248 | /* move received packet into a new pbuf */ |
TomTom83 | 1:a3ee8cb24540 | 249 | p = low_level_input(netif); |
TomTom83 | 1:a3ee8cb24540 | 250 | |
TomTom83 | 1:a3ee8cb24540 | 251 | /* no packet could be read, silently ignore this */ |
TomTom83 | 1:a3ee8cb24540 | 252 | if (p == NULL) return ERR_MEM; |
TomTom83 | 1:a3ee8cb24540 | 253 | |
TomTom83 | 1:a3ee8cb24540 | 254 | /* entry point to the LwIP stack */ |
TomTom83 | 1:a3ee8cb24540 | 255 | err = netif->input(p, netif); |
TomTom83 | 1:a3ee8cb24540 | 256 | |
TomTom83 | 1:a3ee8cb24540 | 257 | if (err != ERR_OK) |
TomTom83 | 1:a3ee8cb24540 | 258 | { |
TomTom83 | 1:a3ee8cb24540 | 259 | LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n")); |
TomTom83 | 1:a3ee8cb24540 | 260 | pbuf_free(p); |
TomTom83 | 1:a3ee8cb24540 | 261 | p = NULL; |
TomTom83 | 1:a3ee8cb24540 | 262 | } |
TomTom83 | 1:a3ee8cb24540 | 263 | return err; |
TomTom83 | 1:a3ee8cb24540 | 264 | } |
TomTom83 | 1:a3ee8cb24540 | 265 | |
TomTom83 | 1:a3ee8cb24540 | 266 | /** |
TomTom83 | 1:a3ee8cb24540 | 267 | * Should be called at the beginning of the program to set up the |
TomTom83 | 1:a3ee8cb24540 | 268 | * network interface. It calls the function low_level_init() to do the |
TomTom83 | 1:a3ee8cb24540 | 269 | * actual setup of the hardware. |
TomTom83 | 1:a3ee8cb24540 | 270 | * |
TomTom83 | 1:a3ee8cb24540 | 271 | * This function should be passed as a parameter to netif_add(). |
TomTom83 | 1:a3ee8cb24540 | 272 | * |
TomTom83 | 1:a3ee8cb24540 | 273 | * @param netif the lwip network interface structure for this ethernetif |
TomTom83 | 1:a3ee8cb24540 | 274 | * @return ERR_OK if the loopif is initialized |
TomTom83 | 1:a3ee8cb24540 | 275 | * ERR_MEM if private data couldn't be allocated |
TomTom83 | 1:a3ee8cb24540 | 276 | * any other err_t on error |
TomTom83 | 1:a3ee8cb24540 | 277 | */ |
TomTom83 | 1:a3ee8cb24540 | 278 | err_t ethernetif_init(struct netif *netif) |
TomTom83 | 1:a3ee8cb24540 | 279 | { |
TomTom83 | 1:a3ee8cb24540 | 280 | LWIP_ASSERT("netif != NULL", (netif != NULL)); |
TomTom83 | 1:a3ee8cb24540 | 281 | |
TomTom83 | 1:a3ee8cb24540 | 282 | #if LWIP_NETIF_HOSTNAME |
TomTom83 | 1:a3ee8cb24540 | 283 | /* Initialize interface hostname */ |
TomTom83 | 1:a3ee8cb24540 | 284 | netif->hostname = "RAIMA"; |
TomTom83 | 1:a3ee8cb24540 | 285 | #endif /* LWIP_NETIF_HOSTNAME */ |
TomTom83 | 1:a3ee8cb24540 | 286 | |
TomTom83 | 1:a3ee8cb24540 | 287 | strncpy(netif->name,"RAIMA",5); |
TomTom83 | 1:a3ee8cb24540 | 288 | |
TomTom83 | 1:a3ee8cb24540 | 289 | /* We directly use etharp_output() here to save a function call. |
TomTom83 | 1:a3ee8cb24540 | 290 | * You can instead declare your own function an call etharp_output() |
TomTom83 | 1:a3ee8cb24540 | 291 | * from it if you have to do some checks before sending (e.g. if link |
TomTom83 | 1:a3ee8cb24540 | 292 | * is available...) */ |
TomTom83 | 1:a3ee8cb24540 | 293 | netif->output = etharp_output; |
TomTom83 | 1:a3ee8cb24540 | 294 | netif->linkoutput = low_level_output; |
TomTom83 | 1:a3ee8cb24540 | 295 | |
TomTom83 | 1:a3ee8cb24540 | 296 | /* initialize the hardware */ |
TomTom83 | 1:a3ee8cb24540 | 297 | low_level_init(netif); |
TomTom83 | 1:a3ee8cb24540 | 298 | |
TomTom83 | 1:a3ee8cb24540 | 299 | return ERR_OK; |
TomTom83 | 1:a3ee8cb24540 | 300 | } |
TomTom83 | 1:a3ee8cb24540 | 301 | |
TomTom83 | 1:a3ee8cb24540 | 302 | |
TomTom83 | 1:a3ee8cb24540 | 303 | |
TomTom83 | 1:a3ee8cb24540 | 304 |