00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #include "lwip/opt.h"
00047
00048 #include "lwip/def.h"
00049 #include "lwip/mem.h"
00050 #include "lwip/pbuf.h"
00051 #include "lwip/sys.h"
00052 #include <lwip/stats.h>
00053 #include <lwip/snmp.h>
00054 #include "netif/etharp.h"
00055 #include "netif/ppp_oe.h"
00056
00057 #include "conf_eth.h"
00058 #include "macb.h"
00059
00060
00061
00062 #define IFNAME0 'e'
00063 #define IFNAME1 'n'
00064
00065 #define netifGUARD_BLOCK_NBTICKS ( 250 )
00066
00073 struct ethernetif {
00074 struct eth_addr *ethaddr;
00075
00076 };
00077
00078
00079 static void ethernetif_input(void * );
00080
00088 static void
00089 low_level_init(struct netif *netif)
00090 {
00091 unsigned portBASE_TYPE uxPriority;
00092
00093
00094
00095 netif->hwaddr_len = ETHARP_HWADDR_LEN;
00096
00097
00098 netif->hwaddr[0] = ETHERNET_CONF_ETHADDR0;
00099 netif->hwaddr[1] = ETHERNET_CONF_ETHADDR1;
00100 netif->hwaddr[2] = ETHERNET_CONF_ETHADDR2;
00101 netif->hwaddr[3] = ETHERNET_CONF_ETHADDR3;
00102 netif->hwaddr[4] = ETHERNET_CONF_ETHADDR4;
00103 netif->hwaddr[5] = ETHERNET_CONF_ETHADDR5;
00104
00105
00106 netif->mtu = 1500;
00107
00108
00109
00110 netif->flags |= NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP;
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 uxPriority = uxTaskPriorityGet( NULL );
00121
00122 vTaskPrioritySet( NULL, tskIDLE_PRIORITY );
00123
00124 while( xMACBInit(&AVR32_MACB) == FALSE )
00125 {
00126 __asm__ __volatile__ ( "nop" );
00127 }
00128
00129 vTaskPrioritySet( NULL, uxPriority );
00130
00131
00132 sys_thread_new( "ETHINT", ethernetif_input, netif, netifINTERFACE_TASK_STACK_SIZE,
00133 netifINTERFACE_TASK_PRIORITY );
00134 }
00135
00152 static err_t
00153 low_level_output(struct netif *netif, struct pbuf *p)
00154 {
00155 struct pbuf *q;
00156 static xSemaphoreHandle xTxSemaphore = NULL;
00157 err_t xReturn = ERR_OK;
00158
00159
00160 ( void )netif;
00161
00162 if( xTxSemaphore == NULL )
00163 {
00164 vSemaphoreCreateBinary( xTxSemaphore );
00165 }
00166
00167 #if ETH_PAD_SIZE
00168 pbuf_header( p, -ETH_PAD_SIZE );
00169 #endif
00170
00171
00172 if( xSemaphoreTake( xTxSemaphore, netifGUARD_BLOCK_NBTICKS ) )
00173 {
00174 for( q = p; q != NULL; q = q->next )
00175 {
00176
00177
00178
00179
00180 if( !lMACBSend(&AVR32_MACB, q->payload, q->len, ( q->next == NULL ) ) )
00181 {
00182 xReturn = ~ERR_OK;
00183 }
00184 }
00185 xSemaphoreGive( xTxSemaphore );
00186 }
00187
00188 #if ETH_PAD_SIZE
00189 pbuf_header( p, ETH_PAD_SIZE );
00190 #endif
00191
00192 LINK_STATS_INC(link.xmit);
00193
00194 return ERR_OK;
00195 }
00196
00205 static struct pbuf *low_level_input(struct netif *netif)
00206 {
00207 struct pbuf *p = NULL;
00208 struct pbuf *q;
00209 u16_t len;
00210 static xSemaphoreHandle xRxSemaphore = NULL;
00211
00212
00213
00214 ( void ) netif;
00215
00216 if( xRxSemaphore == NULL )
00217 {
00218 vSemaphoreCreateBinary( xRxSemaphore );
00219 }
00220
00221
00222 if( xSemaphoreTake( xRxSemaphore, netifGUARD_BLOCK_NBTICKS ) )
00223 {
00224
00225 len = ulMACBInputLength();
00226
00227 if( len )
00228 {
00229 #if ETH_PAD_SIZE
00230 len += ETH_PAD_SIZE;
00231 #endif
00232
00233
00234 p = pbuf_alloc( PBUF_RAW, len, PBUF_POOL );
00235
00236 if( p != NULL )
00237 {
00238 #if ETH_PAD_SIZE
00239 pbuf_header( p, -ETH_PAD_SIZE );
00240 #endif
00241
00242
00243 vMACBRead( NULL, 0, len );
00244
00245
00246
00247 for( q = p; q != NULL; q = q->next )
00248 {
00249
00250
00251 vMACBRead( q->payload, q->len, len );
00252 }
00253
00254 #if ETH_PAD_SIZE
00255 pbuf_header( p, ETH_PAD_SIZE );
00256 #endif
00257 LINK_STATS_INC(link.recv);
00258 }
00259 else
00260 {
00261 LINK_STATS_INC(link.memerr);
00262 LINK_STATS_INC(link.drop);
00263 }
00264 }
00265 xSemaphoreGive( xRxSemaphore );
00266 }
00267
00268 return p;
00269 }
00270
00280 static void ethernetif_input(void * pvParameters)
00281 {
00282 struct netif *netif = (struct netif *)pvParameters;
00283 struct pbuf *p;
00284
00285
00286 for( ;; )
00287 {
00288 do
00289 {
00290
00291 p = low_level_input( netif );
00292 if( p == NULL )
00293 {
00294
00295
00296 vMACBWaitForInput(100);
00297 }
00298 }while( p == NULL );
00299
00300 if( ERR_OK != ethernet_input( p, netif ) )
00301 {
00302 pbuf_free(p);
00303 p = NULL;
00304 }
00305 }
00306 }
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00333 err_t
00334 ethernetif_init(struct netif *netif)
00335 {
00336
00337
00338 LWIP_ASSERT("netif != NULL", (netif != NULL));
00339
00340
00341
00342
00343
00344
00345
00346
00347 #if LWIP_NETIF_HOSTNAME
00348
00349 netif->hostname = "lwip";
00350 #endif
00351
00352
00353
00354
00355
00356
00357 #if LWIP_SNMP
00358 NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, 100000000);
00359 #endif
00360
00361 netif->state = NULL;
00362
00363 netif->name[0] = IFNAME0;
00364 netif->name[1] = IFNAME1;
00365
00366
00367
00368
00369 netif->output = etharp_output;
00370 netif->linkoutput = low_level_output;
00371
00372
00373 low_level_init(netif);
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383 return ERR_OK;
00384 }