Search for last '.' just like in send_headers().
[contiki-2.x.git] / cpu / 6502 / net / ethernet.c
blobbbf06a2c533dd843372dc9463a81a8a438142e3c
1 /*
2 * Copyright (c) 2007, Swedish Institute of Computer Science
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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
27 * SUCH DAMAGE.
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 $
36 #include <modload.h>
38 #include "contiki-net.h"
39 #include "cfs/cfs.h"
40 #include "sys/log.h"
41 #include "lib/error.h"
42 #include "net/ethernet-drv.h"
44 #include "net/ethernet.h"
46 struct {
47 char signature[4];
48 struct uip_eth_addr ethernet_address;
49 u8_t *buffer;
50 u16_t buffer_size;
51 void __fastcall__ (* init)(u16_t reg);
52 u16_t (* poll)(void);
53 void __fastcall__ (* send)(u16_t len);
54 void (* exit)(void);
55 } *module;
57 /*---------------------------------------------------------------------------*/
58 void CC_FASTCALL
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};
63 u8_t byte;
65 module_control.callerdata = cfs_open(config->name, CFS_READ);
66 if(module_control.callerdata < 0) {
67 log_message(config->name, ": File not found");
68 error_exit();
71 byte = mod_load(&module_control);
72 if(byte != MLOAD_OK) {
73 log_message(config->name, byte == MLOAD_ERR_MEM? ": Out of memory":
74 ": No module");
75 error_exit();
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");
84 error_exit();
88 module->buffer = uip_buf;
89 module->buffer_size = UIP_BUFSIZE;
90 module->init(config->addr);
92 uip_setethaddr(module->ethernet_address);
94 /*---------------------------------------------------------------------------*/
95 u16_t
96 ethernet_poll(void)
98 return module->poll();
100 /*---------------------------------------------------------------------------*/
101 void
102 ethernet_send(void)
104 module->send(uip_len);
106 /*---------------------------------------------------------------------------*/
107 void
108 ethernet_exit(void)
110 module->exit();
112 mod_free(module);
114 /*---------------------------------------------------------------------------*/