git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1192 35acf78f-673a-0410-8e92-d51de3d6d3f4

master
gdisirio 2009-09-27 18:48:47 +00:00
parent ee0d07151a
commit c9bfcaa15e
6 changed files with 88 additions and 96 deletions

View File

@ -1,61 +1,41 @@
/*
ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio.
This file is part of ChibiOS/RT.
ChibiOS/RT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
ChibiOS/RT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
**** This file incorporates work covered by the following copyright and ****
**** permission notice: ****
Copyright (c) 2001-2004 Swedish Institute of Computer Science.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
This file is part of the lwIP TCP/IP stack.
Author: Adam Dunkels <adam@sics.se>
*/
/** /**
* @file * @file
* Ethernet Interface Skeleton * Ethernet Interface Skeleton
* *
*/ */
/*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
/* /*
* This file is a skeleton for developing Ethernet network interface * This file is a skeleton for developing Ethernet network interface
* drivers for lwIP. Add code to the low_level functions and do a * drivers for lwIP. Add code to the low_level functions and do a
@ -65,7 +45,7 @@
#include "lwip/opt.h" #include "lwip/opt.h"
#if 1 /* don't build, this is only a skeleton, see previous comment */ #if 0 /* don't build, this is only a skeleton, see previous comment */
#include "lwip/def.h" #include "lwip/def.h"
#include "lwip/mem.h" #include "lwip/mem.h"
@ -105,23 +85,23 @@ static void
low_level_init(struct netif *netif) low_level_init(struct netif *netif)
{ {
struct ethernetif *ethernetif = netif->state; struct ethernetif *ethernetif = netif->state;
/* set MAC hardware address length */ /* set MAC hardware address length */
netif->hwaddr_len = ETHARP_HWADDR_LEN; netif->hwaddr_len = ETHARP_HWADDR_LEN;
/* set MAC hardware address */ /* set MAC hardware address */
////////// netif->hwaddr[0] = ; netif->hwaddr[0] = ;
////////// ... ...
////////// netif->hwaddr[5] = ; netif->hwaddr[5] = ;
/* maximum transfer unit */ /* maximum transfer unit */
netif->mtu = 1500; netif->mtu = 1500;
/* device capabilities */ /* device capabilities */
/* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */ /* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP; netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;
/* Do whatever else is needed to initialize interface. */ /* Do whatever else is needed to initialize interface. */
} }
/** /**
@ -146,8 +126,8 @@ low_level_output(struct netif *netif, struct pbuf *p)
struct ethernetif *ethernetif = netif->state; struct ethernetif *ethernetif = netif->state;
struct pbuf *q; struct pbuf *q;
////////// initiate transfer(); initiate transfer();
#if ETH_PAD_SIZE #if ETH_PAD_SIZE
pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */ pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
#endif #endif
@ -156,15 +136,15 @@ low_level_output(struct netif *netif, struct pbuf *p)
/* Send the data from the pbuf to the interface, one pbuf at a /* Send the data from the pbuf to the interface, one pbuf at a
time. The size of the data in each pbuf is kept in the ->len time. The size of the data in each pbuf is kept in the ->len
variable. */ variable. */
////////// send data from(q->payload, q->len); send data from(q->payload, q->len);
} }
////////// signal that packet should be sent(); signal that packet should be sent();
#if ETH_PAD_SIZE #if ETH_PAD_SIZE
pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */ pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
#endif #endif
LINK_STATS_INC(link.xmit); LINK_STATS_INC(link.xmit);
return ERR_OK; return ERR_OK;
@ -187,7 +167,7 @@ low_level_input(struct netif *netif)
/* Obtain the size of the packet and put it into the "len" /* Obtain the size of the packet and put it into the "len"
variable. */ variable. */
////////// len = ; len = ;
#if ETH_PAD_SIZE #if ETH_PAD_SIZE
len += ETH_PAD_SIZE; /* allow room for Ethernet padding */ len += ETH_PAD_SIZE; /* allow room for Ethernet padding */
@ -195,7 +175,7 @@ low_level_input(struct netif *netif)
/* We allocate a pbuf chain of pbufs from the pool. */ /* We allocate a pbuf chain of pbufs from the pool. */
p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL); p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
if (p != NULL) { if (p != NULL) {
#if ETH_PAD_SIZE #if ETH_PAD_SIZE
@ -208,9 +188,9 @@ low_level_input(struct netif *netif)
/* Read enough bytes to fill this pbuf in the chain. The /* Read enough bytes to fill this pbuf in the chain. The
* available data in the pbuf is given by the q->len * available data in the pbuf is given by the q->len
* variable. */ * variable. */
////////// read data into(q->payload, q->len); read data into(q->payload, q->len);
} }
////////// acknowledge that packet has been read(); acknowledge that packet has been read();
#if ETH_PAD_SIZE #if ETH_PAD_SIZE
pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */ pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
@ -218,12 +198,12 @@ low_level_input(struct netif *netif)
LINK_STATS_INC(link.recv); LINK_STATS_INC(link.recv);
} else { } else {
////////// drop packet(); drop packet();
LINK_STATS_INC(link.memerr); LINK_STATS_INC(link.memerr);
LINK_STATS_INC(link.drop); LINK_STATS_INC(link.drop);
} }
return p; return p;
} }
/** /**
@ -293,7 +273,7 @@ ethernetif_init(struct netif *netif)
struct ethernetif *ethernetif; struct ethernetif *ethernetif;
LWIP_ASSERT("netif != NULL", (netif != NULL)); LWIP_ASSERT("netif != NULL", (netif != NULL));
ethernetif = mem_malloc(sizeof(struct ethernetif)); ethernetif = mem_malloc(sizeof(struct ethernetif));
if (ethernetif == NULL) { if (ethernetif == NULL) {
LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_init: out of memory\n")); LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_init: out of memory\n"));
@ -310,7 +290,7 @@ ethernetif_init(struct netif *netif)
* The last argument should be replaced with your link speed, in units * The last argument should be replaced with your link speed, in units
* of bits per second. * of bits per second.
*/ */
NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, ???); NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, LINK_SPEED_OF_YOUR_NETIF_IN_BPS);
netif->state = ethernetif; netif->state = ethernetif;
netif->name[0] = IFNAME0; netif->name[0] = IFNAME0;
@ -321,9 +301,9 @@ ethernetif_init(struct netif *netif)
* is available...) */ * is available...) */
netif->output = etharp_output; netif->output = etharp_output;
netif->linkoutput = low_level_output; netif->linkoutput = low_level_output;
ethernetif->ethaddr = (struct eth_addr *)&(netif->hwaddr[0]); ethernetif->ethaddr = (struct eth_addr *)&(netif->hwaddr[0]);
/* initialize the hardware */ /* initialize the hardware */
low_level_init(netif); low_level_init(netif);

View File

@ -65,13 +65,17 @@ CSRC = ${PORTSRC} \
${USRC} \ ${USRC} \
${CHIBIOS}/os/io/pal.c \ ${CHIBIOS}/os/io/pal.c \
${CHIBIOS}/os/io/serial.c \ ${CHIBIOS}/os/io/serial.c \
${CHIBIOS}/os/io/phy.c \
${CHIBIOS}/os/io/mac.c \
${CHIBIOS}/os/io/platforms/AT91SAM7X/pal_lld.c \ ${CHIBIOS}/os/io/platforms/AT91SAM7X/pal_lld.c \
${CHIBIOS}/os/io/platforms/AT91SAM7X/serial_lld.c \ ${CHIBIOS}/os/io/platforms/AT91SAM7X/serial_lld.c \
${CHIBIOS}/os/io/platforms/AT91SAM7X/sam7x_emac.c \ ${CHIBIOS}/os/io/platforms/AT91SAM7X/phy_lld.c \
${CHIBIOS}/os/io/platforms/AT91SAM7X/mac_lld.c \
${CHIBIOS}/os/io/platforms/AT91SAM7X/at91lib/aic.c \ ${CHIBIOS}/os/io/platforms/AT91SAM7X/at91lib/aic.c \
${CHIBIOS}/os/various/evtimer.c \ ${CHIBIOS}/os/various/evtimer.c \
web/webthread.c \ web/webthread.c \
board.c main.c board.c main.c
# ${CHIBIOS}/os/io/platforms/AT91SAM7X/sam7x_emac.c \
# C++ sources that can be compiled in ARM or THUMB mode depending on the global # C++ sources that can be compiled in ARM or THUMB mode depending on the global
# setting. # setting.

View File

@ -20,7 +20,8 @@
#include <ch.h> #include <ch.h>
#include <pal.h> #include <pal.h>
#include <serial.h> #include <serial.h>
#include <sam7x_emac.h> #include <mac.h>
//#include <sam7x_emac.h>
#include "board.h" #include "board.h"
#include "at91lib/aic.h" #include "at91lib/aic.h"
@ -178,7 +179,8 @@ void hwinit1(void) {
/* /*
* EMAC driver initialization. * EMAC driver initialization.
*/ */
emac_init(AT91C_AIC_PRIOR_HIGHEST - 3); // emac_init(AT91C_AIC_PRIOR_HIGHEST - 3);
macInit();
/* /*
* ChibiOS/RT initialization. * ChibiOS/RT initialization.

View File

@ -28,7 +28,7 @@
#include "web/webthread.h" #include "web/webthread.h"
static WORKING_AREA(waWebThread, 512); static WORKING_AREA(waWebThread, 512);
static WORKING_AREA(waThread1, 64); static WORKING_AREA(waThread1, 128);
static msg_t Thread1(void *arg) { static msg_t Thread1(void *arg) {

View File

@ -21,7 +21,7 @@
#include <ch.h> #include <ch.h>
#include <evtimer.h> #include <evtimer.h>
#include <sam7x_emac.h> #include <mac.h>
#include <uip.h> #include <uip.h>
#include <uip_arp.h> #include <uip_arp.h>
@ -47,11 +47,11 @@ static const struct uip_eth_addr macaddr = {
*/ */
static void network_device_send(void) { static void network_device_send(void) {
int i; int i;
BufDescriptorEntry *bdep; MACTransmitDescriptor *tdp;
for (i = 0; i < SEND_RETRY_MAX; i++) { for (i = 0; i < SEND_RETRY_MAX; i++) {
if ((bdep = EMACGetTransmitBuffer()) != NULL) { if ((tdp = macWaitTransmitDescriptor(&MAC1, uip_len, TIME_IMMEDIATE)) != NULL) {
uint8_t *bp = (uint8_t *)bdep->w1; uint8_t *bp = macGetTransmitBuffer(tdp);
if(uip_len <= UIP_LLH_LEN + UIP_TCPIP_HLEN) if(uip_len <= UIP_LLH_LEN + UIP_TCPIP_HLEN)
memcpy(bp, &uip_buf[0], uip_len); memcpy(bp, &uip_buf[0], uip_len);
@ -61,7 +61,7 @@ static void network_device_send(void) {
uip_appdata, uip_appdata,
uip_len - (UIP_LLH_LEN + UIP_TCPIP_HLEN)); uip_len - (UIP_LLH_LEN + UIP_TCPIP_HLEN));
} }
EMACTransmit(bdep, uip_len); macReleaseTransmitDescriptor(&MAC1, tdp);
return; return;
} }
chThdSleep(SEND_RETRY_INTERVAL); chThdSleep(SEND_RETRY_INTERVAL);
@ -73,10 +73,16 @@ static void network_device_send(void) {
* uIP receive function wrapping the EMAC function. * uIP receive function wrapping the EMAC function.
*/ */
static size_t network_device_read(void) { static size_t network_device_read(void) {
size_t size = UIP_CONF_BUFFER_SIZE; MACReceiveDescriptor *rdp;
if (EMACReceive(uip_buf, &size)) size_t size;
return size; uint8_t *bp;
return 0;
if ((rdp = macWaitReceiveDescriptor(&MAC1, &size, TIME_IMMEDIATE)) == NULL)
return 0;
bp = macGetReceiveBuffer(rdp);
memcpy(&uip_buf[0], bp, size);
macReleaseReceiveDescriptor(&MAC1, rdp);
return size;
} }
void clock_init(void) {} void clock_init(void) {}
@ -107,7 +113,7 @@ static void PeriodicTimerHandler(eventid_t id) {
static void ARPTimerHandler(eventid_t id) { static void ARPTimerHandler(eventid_t id) {
uip_arp_timer(); uip_arp_timer();
(void)EMACGetLinkStatus(); (void)macPollLinkStatus(&MAC1);
} }
/* /*
@ -150,7 +156,7 @@ msg_t WebThread(void *p) {
/* /*
* Event sources setup. * Event sources setup.
*/ */
chEvtRegister(&EMACFrameReceived, &el0, FRAME_RECEIVED_ID); chEvtRegister(macGetReceiveEventSource(&MAC1), &el0, FRAME_RECEIVED_ID);
chEvtPend(EVENT_MASK(FRAME_RECEIVED_ID)); /* In case some frames are already buffered */ chEvtPend(EVENT_MASK(FRAME_RECEIVED_ID)); /* In case some frames are already buffered */
evtInit(&evt1, MS2ST(500)); evtInit(&evt1, MS2ST(500));
@ -164,8 +170,8 @@ msg_t WebThread(void *p) {
/* /*
* EMAC settings. * EMAC settings.
*/ */
EMACSetAddress(&macaddr.addr[0]); macSetAddress(&MAC1, &macaddr.addr[0]);
(void)EMACGetLinkStatus(); (void)macPollLinkStatus(&MAC1);
/* /*
* uIP initialization. * uIP initialization.

View File

@ -84,7 +84,7 @@ static void serve_interrupt(void) {
chSysLockFromIsr(); chSysLockFromIsr();
chSemResetI(&MAC1.md_rdsem, 0); chSemResetI(&MAC1.md_rdsem, 0);
#if CH_USE_EVENTS #if CH_USE_EVENTS
chEvtBroadcast(&MAC1.md_rdevent); chEvtBroadcastI(&MAC1.md_rdevent);
#endif #endif
chSysUnlockFromIsr(); chSysUnlockFromIsr();
} }
@ -202,9 +202,9 @@ void mac_lld_init(void) {
*/ */
void mac_lld_set_address(MACDriver *macp, const uint8_t *p) { void mac_lld_set_address(MACDriver *macp, const uint8_t *p) {
AT91C_BASE_EMAC->EMAC_SA1L = (AT91_REG)((p[2] << 24) | (p[3] << 16) | AT91C_BASE_EMAC->EMAC_SA1L = (AT91_REG)((p[3] << 24) | (p[2] << 16) |
(p[4] << 8) | p[5]); (p[1] << 8) | p[0]);
AT91C_BASE_EMAC->EMAC_SA1H = (AT91_REG)((p[0] << 8) | p[1]); AT91C_BASE_EMAC->EMAC_SA1H = (AT91_REG)((p[5] << 8) | p[4]);
} }
/** /**