2 * Copyright (c) 2007, Swedish Institute of Computer Science
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the Institute nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * This file is part of the Contiki operating system.
31 * Author: Oliver Schmidt <ol.sc@web.de>
33 * @(#)$Id: ethernet.c,v 1.6 2007/12/23 15:37:28 oliverschmidt Exp $
38 #include "contiki-net.h"
41 #include "lib/error.h"
42 #include "net/ethernet-drv.h"
44 #include "net/ethernet.h"
48 struct uip_eth_addr ethernet_address
;
51 void __fastcall__ (* init
)(u16_t reg
);
53 void __fastcall__ (* send
)(u16_t len
);
57 /*---------------------------------------------------------------------------*/
59 ethernet_init(struct ethernet_config
*config
)
61 static const char signature
[4] = {0x65, 0x74, 0x68, 0x01};
62 struct mod_ctrl module_control
= {cfs_read
};
65 module_control
.callerdata
= cfs_open(config
->name
, CFS_READ
);
66 if(module_control
.callerdata
< 0) {
67 log_message(config
->name
, ": File not found");
71 byte
= mod_load(&module_control
);
72 if(byte
!= MLOAD_OK
) {
73 log_message(config
->name
, byte
== MLOAD_ERR_MEM
? ": Out of memory":
78 cfs_close(module_control
.callerdata
);
79 module
= module_control
.module
;
81 for(byte
= 0; byte
< 4; ++byte
) {
82 if(module
->signature
[byte
] != signature
[byte
]) {
83 log_message(config
->name
, ": No ETH driver");
88 module
->buffer
= uip_buf
;
89 module
->buffer_size
= UIP_BUFSIZE
;
90 module
->init(config
->addr
);
92 uip_setethaddr(module
->ethernet_address
);
94 /*---------------------------------------------------------------------------*/
98 return module
->poll();
100 /*---------------------------------------------------------------------------*/
104 module
->send(uip_len
);
106 /*---------------------------------------------------------------------------*/
114 /*---------------------------------------------------------------------------*/