2007-11-20 22:10:20 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2007, 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. Neither the name of the Institute nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``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 INSTITUTE OR CONTRIBUTORS 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 Contiki operating system.
|
|
|
|
*
|
|
|
|
* Author: Oliver Schmidt <ol.sc@web.de>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <modload.h>
|
|
|
|
|
|
|
|
#include "contiki-net.h"
|
2007-12-23 16:37:28 +01:00
|
|
|
#include "cfs/cfs.h"
|
2007-12-16 18:02:37 +01:00
|
|
|
#include "sys/log.h"
|
2007-11-27 21:52:52 +01:00
|
|
|
#include "lib/error.h"
|
|
|
|
#include "net/ethernet-drv.h"
|
2007-11-20 22:10:20 +01:00
|
|
|
|
2007-11-27 21:52:52 +01:00
|
|
|
#include "net/ethernet.h"
|
2007-11-20 22:10:20 +01:00
|
|
|
|
|
|
|
struct {
|
|
|
|
char signature[4];
|
|
|
|
struct uip_eth_addr ethernet_address;
|
2012-02-20 19:42:51 +01:00
|
|
|
uint8_t *buffer;
|
|
|
|
uint16_t buffer_size;
|
2014-06-12 22:56:35 +02:00
|
|
|
char jmp_init;
|
|
|
|
char __fastcall__ (* init)(uint16_t reg);
|
|
|
|
char jmp_poll;
|
2012-02-20 19:42:51 +01:00
|
|
|
uint16_t (* poll)(void);
|
2014-06-12 22:56:35 +02:00
|
|
|
char jmp_send;
|
2012-02-20 19:42:51 +01:00
|
|
|
void __fastcall__ (* send)(uint16_t len);
|
2014-06-12 22:56:35 +02:00
|
|
|
char jmp_exit;
|
2007-11-20 22:10:20 +01:00
|
|
|
void (* exit)(void);
|
|
|
|
} *module;
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2015-11-01 18:10:17 +01:00
|
|
|
void
|
2007-11-20 22:10:20 +01:00
|
|
|
ethernet_init(struct ethernet_config *config)
|
|
|
|
{
|
|
|
|
static const char signature[4] = {0x65, 0x74, 0x68, 0x01};
|
2010-09-29 01:02:16 +02:00
|
|
|
|
2017-01-27 00:18:25 +01:00
|
|
|
#ifndef STATIC_DRIVER
|
2010-09-29 01:02:16 +02:00
|
|
|
|
2007-12-23 16:37:28 +01:00
|
|
|
struct mod_ctrl module_control = {cfs_read};
|
2012-02-20 19:42:51 +01:00
|
|
|
uint8_t byte;
|
2007-11-20 22:10:20 +01:00
|
|
|
|
2007-12-23 16:37:28 +01:00
|
|
|
module_control.callerdata = cfs_open(config->name, CFS_READ);
|
2007-11-22 12:41:18 +01:00
|
|
|
if(module_control.callerdata < 0) {
|
2007-12-16 18:02:37 +01:00
|
|
|
log_message(config->name, ": File not found");
|
2007-11-20 22:10:20 +01:00
|
|
|
error_exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
byte = mod_load(&module_control);
|
|
|
|
if(byte != MLOAD_OK) {
|
2007-12-16 18:02:37 +01:00
|
|
|
log_message(config->name, byte == MLOAD_ERR_MEM? ": Out of memory":
|
2013-01-28 23:43:08 +01:00
|
|
|
": No module");
|
2007-11-20 22:10:20 +01:00
|
|
|
error_exit();
|
|
|
|
}
|
|
|
|
|
2007-12-23 16:37:28 +01:00
|
|
|
cfs_close(module_control.callerdata);
|
2007-11-20 22:10:20 +01:00
|
|
|
module = module_control.module;
|
|
|
|
|
2007-12-16 18:02:37 +01:00
|
|
|
for(byte = 0; byte < 4; ++byte) {
|
2007-11-20 22:10:20 +01:00
|
|
|
if(module->signature[byte] != signature[byte]) {
|
2007-12-16 18:02:37 +01:00
|
|
|
log_message(config->name, ": No ETH driver");
|
2007-11-20 22:10:20 +01:00
|
|
|
error_exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-27 00:18:25 +01:00
|
|
|
#else /* !STATIC_DRIVER */
|
2010-09-29 01:02:16 +02:00
|
|
|
|
2017-01-27 00:18:25 +01:00
|
|
|
extern void STATIC_DRIVER;
|
2010-09-29 01:02:16 +02:00
|
|
|
|
2017-01-27 00:18:25 +01:00
|
|
|
module = &STATIC_DRIVER;
|
2010-09-29 01:02:16 +02:00
|
|
|
|
2017-01-27 00:18:25 +01:00
|
|
|
#endif /* !STATIC_DRIVER */
|
2010-09-29 01:02:16 +02:00
|
|
|
|
2007-11-20 22:10:20 +01:00
|
|
|
module->buffer = uip_buf;
|
|
|
|
module->buffer_size = UIP_BUFSIZE;
|
2014-06-12 22:56:35 +02:00
|
|
|
if(module->init(config->addr)) {
|
|
|
|
log_message(config->name, ": No hardware");
|
|
|
|
error_exit();
|
|
|
|
}
|
2007-11-20 22:10:20 +01:00
|
|
|
|
|
|
|
uip_setethaddr(module->ethernet_address);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2012-02-20 19:42:51 +01:00
|
|
|
uint16_t
|
2007-11-20 22:10:20 +01:00
|
|
|
ethernet_poll(void)
|
|
|
|
{
|
|
|
|
return module->poll();
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
ethernet_send(void)
|
|
|
|
{
|
|
|
|
module->send(uip_len);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
ethernet_exit(void)
|
|
|
|
{
|
|
|
|
module->exit();
|
|
|
|
|
2017-01-27 00:18:25 +01:00
|
|
|
#ifndef STATIC_DRIVER
|
2007-11-20 22:10:20 +01:00
|
|
|
mod_free(module);
|
2017-01-27 00:18:25 +01:00
|
|
|
#endif /* !STATIC_DRIVER */
|
2007-11-20 22:10:20 +01:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|