OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [lwIP_AVR32_UC3/] [NETWORK/] [ethernet.c] - Blame information for rev 587

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 583 jeremybenn
/*This file has been prepared for Doxygen automatic documentation generation.*/
2
/*! \file *********************************************************************
3
 *
4
 * \brief ethernet management for AVR32 UC3.
5
 *
6
 * - Compiler:           IAR EWAVR32 and GNU GCC for AVR32
7
 * - Supported devices:  All AVR32 devices can be used.
8
 * - AppNote:
9
 *
10
 * \author               Atmel Corporation: http://www.atmel.com \n
11
 *                       Support and FAQ: http://support.atmel.no/
12
 *
13
 *****************************************************************************/
14
 
15
/* Copyright (c) 2007, Atmel Corporation All rights reserved.
16
 *
17
 * Redistribution and use in source and binary forms, with or without
18
 * modification, are permitted provided that the following conditions are met:
19
 *
20
 * 1. Redistributions of source code must retain the above copyright notice,
21
 * this list of conditions and the following disclaimer.
22
 *
23
 * 2. Redistributions in binary form must reproduce the above copyright notice,
24
 * this list of conditions and the following disclaimer in the documentation
25
 * and/or other materials provided with the distribution.
26
 *
27
 * 3. The name of ATMEL may not be used to endorse or promote products derived
28
 * from this software without specific prior written permission.
29
 *
30
 * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED
31
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
32
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
33
 * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
34
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
35
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
36
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
37
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
39
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40
 */
41
 
42
 
43
 
44
#include <string.h>
45
 
46
#include "conf_eth.h"
47
 
48
/* Scheduler include files. */
49
#include "FreeRTOS.h"
50
#include "task.h"
51
 
52
/* Demo program include files. */
53
#include "partest.h"
54
#include "serial.h"
55
 
56
 
57
/* ethernet includes */
58
#include "ethernet.h"
59
#include "conf_eth.h"
60
#include "macb.h"
61
#include "gpio.h"
62
 
63
#if (HTTP_USED == 1)
64
  #include "BasicWEB.h"
65
#endif
66
 
67
#if (TFTP_USED == 1)
68
  #include "BasicTFTP.h"
69
#endif
70
 
71
#if (SMTP_USED == 1)
72
  #include "BasicSMTP.h"
73
#endif
74
 
75
/* lwIP includes */
76
#include "lwip/sys.h"
77
#include "lwip/api.h" 
78
#include "lwip/tcpip.h"
79
#include "lwip/memp.h" 
80
#include "lwip/stats.h"
81
#include "netif/loopif.h"
82
 
83
 
84
//_____ M A C R O S ________________________________________________________
85
 
86
 
87
//_____ D E F I N I T I O N S ______________________________________________
88
 
89
/* global variable containing MAC Config (hw addr, IP, GW, ...) */
90
struct netif MACB_if;
91
 
92
//_____ D E C L A R A T I O N S ____________________________________________
93
 
94
/* Initialisation required by lwIP. */
95
static void prvlwIPInit( void );
96
 
97
/* Initialisation of ethernet interfaces by reading config file */
98
static void prvEthernetConfigureInterface(void * param);
99
 
100
 
101
/*! \brief create ethernet task, for ethernet management.
102
 *
103
 *  \param uxPriority   Input. priority for the task, it should be low
104
 *
105
 */
106
void vStartEthernetTask( unsigned portBASE_TYPE uxPriority )
107
{
108
static const gpio_map_t MACB_GPIO_MAP =
109
{
110
  {AVR32_MACB_MDC_0_PIN,    AVR32_MACB_MDC_0_FUNCTION   },
111
  {AVR32_MACB_MDIO_0_PIN,   AVR32_MACB_MDIO_0_FUNCTION  },
112
  {AVR32_MACB_RXD_0_PIN,    AVR32_MACB_RXD_0_FUNCTION   },
113
  {AVR32_MACB_TXD_0_PIN,    AVR32_MACB_TXD_0_FUNCTION   },
114
  {AVR32_MACB_RXD_1_PIN,    AVR32_MACB_RXD_1_FUNCTION   },
115
  {AVR32_MACB_TXD_1_PIN,    AVR32_MACB_TXD_1_FUNCTION   },
116
  {AVR32_MACB_TX_EN_0_PIN,  AVR32_MACB_TX_EN_0_FUNCTION },
117
  {AVR32_MACB_RX_ER_0_PIN,  AVR32_MACB_RX_ER_0_FUNCTION },
118
  {AVR32_MACB_RX_DV_0_PIN,  AVR32_MACB_RX_DV_0_FUNCTION },
119
  {AVR32_MACB_TX_CLK_0_PIN, AVR32_MACB_TX_CLK_0_FUNCTION}
120
};
121
 
122
  // Assign GPIO to MACB
123
  gpio_enable_module(MACB_GPIO_MAP, sizeof(MACB_GPIO_MAP) / sizeof(MACB_GPIO_MAP[0]));
124
 
125
  /* Setup lwIP. */
126
  prvlwIPInit();
127
 
128
#if (HTTP_USED == 1)
129
  /* Create the WEB server task.  This uses the lwIP RTOS abstraction layer.*/
130
  sys_thread_new( vBasicWEBServer, ( void * ) NULL, ethWEBSERVER_PRIORITY );
131
#endif
132
 
133
#if (TFTP_USED == 1)
134
  /* Create the TFTP server task.  This uses the lwIP RTOS abstraction layer.*/
135
  sys_thread_new( vBasicTFTPServer, ( void * ) NULL, ethTFTPSERVER_PRIORITY );
136
#endif
137
 
138
#if (SMTP_USED == 1)
139
  /* Create the SMTP Client task.  This uses the lwIP RTOS abstraction layer.*/
140
  sys_thread_new( vBasicSMTPClient, ( void * ) NULL, ethSMTPCLIENT_PRIORITY );
141
#endif
142
 
143
}
144
 
145
 
146
/*!
147
 *  \brief start lwIP layer.
148
 */
149
static void prvlwIPInit( void )
150
{
151
        /* Initialize lwIP and its interface layer. */
152
        #if LWIP_STATS
153
                stats_init();
154
        #endif
155
 
156
        sys_init();
157
        mem_init();
158
        memp_init();
159
        pbuf_init();
160
        netif_init();
161
 
162
        /* once TCP stack has been initalized, set hw and IP parameters, initialize MACB too */
163
        tcpip_init( prvEthernetConfigureInterface, NULL );
164
}
165
 
166
/*!
167
 *  \brief set ethernet config
168
 */
169
static void prvEthernetConfigureInterface(void * param)
170
{
171
struct ip_addr xIpAddr, xNetMask, xGateway;
172
extern err_t ethernetif_init( struct netif *netif );
173
portCHAR MacAddress[6];
174
 
175
   /* Default MAC addr. */
176
   MacAddress[0] = ETHERNET_CONF_ETHADDR0;
177
   MacAddress[1] = ETHERNET_CONF_ETHADDR1;
178
   MacAddress[2] = ETHERNET_CONF_ETHADDR2;
179
   MacAddress[3] = ETHERNET_CONF_ETHADDR3;
180
   MacAddress[4] = ETHERNET_CONF_ETHADDR4;
181
   MacAddress[5] = ETHERNET_CONF_ETHADDR5;
182
 
183
   /* pass the MAC address to MACB module */
184
   vMACBSetMACAddress( MacAddress );
185
 
186
   /* set MAC hardware address length to be used by lwIP */
187
   MACB_if.hwaddr_len = 6;
188
 
189
   /* set MAC hardware address to be used by lwIP */
190
   memcpy( MACB_if.hwaddr, MacAddress, MACB_if.hwaddr_len );
191
 
192
   /* Default ip addr. */
193
   IP4_ADDR( &xIpAddr,ETHERNET_CONF_IPADDR0,ETHERNET_CONF_IPADDR1,ETHERNET_CONF_IPADDR2,ETHERNET_CONF_IPADDR3 );
194
 
195
   /* Default Subnet mask. */
196
   IP4_ADDR( &xNetMask,ETHERNET_CONF_NET_MASK0,ETHERNET_CONF_NET_MASK1,ETHERNET_CONF_NET_MASK2,ETHERNET_CONF_NET_MASK3 );
197
 
198
   /* Default Gw addr. */
199
   IP4_ADDR( &xGateway,ETHERNET_CONF_GATEWAY_ADDR0,ETHERNET_CONF_GATEWAY_ADDR1,ETHERNET_CONF_GATEWAY_ADDR2,ETHERNET_CONF_GATEWAY_ADDR3 );
200
 
201
   /* add data to netif */
202
   netif_add( &MACB_if, &xIpAddr, &xNetMask, &xGateway, NULL, ethernetif_init, tcpip_input );
203
 
204
   /* make it the default interface */
205
   netif_set_default( &MACB_if );
206
 
207
   /* bring it up */
208
   netif_set_up( &MACB_if );
209
}
210
 
211
 
212
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.