Import of the contiki-2.x development code from the SICS internal CVS server

This commit is contained in:
adamdunkels 2006-06-17 22:41:10 +00:00
commit c9e808d638
671 changed files with 95332 additions and 0 deletions

54
cpu/avr/dev/clock.c Normal file
View file

@ -0,0 +1,54 @@
#include "sys/clock.h"
#include "sys/etimer.h"
#include <avr/io.h>
#include <avr/interrupt.h>
// Hack to see if this sets the blue led...
/* #include "hal_emwinet_demoboard.h" */
static unsigned short count;
/*---------------------------------------------------------------------------*/
SIGNAL(SIG_OUTPUT_COMPARE0)
{
/* if ((count % 10) > 5) SET_BLUE_LED(); */
/* else CLEAR_BLUE_LED(); */
++count;
if(etimer_pending()) {
etimer_request_poll();
}
}
/*---------------------------------------------------------------------------*/
void
clock_init(void)
{
#if 0
#if __AVR_ENHANCED__
outp(_BV(CS00) | _BV(CS02) | _BV(WGM01), TCCR0);
#else
outp(_BV(CS00) | _BV(CS02) | _BV(CTC0), TCCR0);
#endif
outp(0, TCNT0);
outp((NUT_CPU_FREQ / (128L * CLOCK_CONF_SECOND) + 0.5/*round*/), OCR0);
sbi(TIMSK, OCIE0);
#endif /* 0 */
TCCR0 = _BV(CS00) | _BV(CS02) | _BV(WGM01);
TCNT0 = 0;
/* OCR0 = AVR_CLK_COUNT;*/
TIMSK |= _BV(OCIE0);
count = 0;
}
/*---------------------------------------------------------------------------*/
clock_time_t
clock_time(void)
{
return count;
}
/*---------------------------------------------------------------------------*/

39
cpu/avr/dev/compiler.h Normal file
View file

@ -0,0 +1,39 @@
#ifndef __COMPILER_H__
#define __COMPILER_H__
#ifdef __IMAGECRAFT__
// choose your AVR device here
#include <iom128.h>
#include <macros.h>
#define outp(val, reg) (reg = val)
#define inp(reg) (reg)
#define cli() CLI()
#define sei() SEI()
#define cbi(reg, bit) (reg &= ~BIT(bit))
#define sbi(reg, bit) (reg |= BIT(bit))
#define SIGNAL(x) void x(void)
#define nop() NOP()
#else /* --- GCC --- */
#ifndef __AVR_ATmega128__
#define __AVR_ATmega128__
#endif
#include <avr/signal.h>
#include <avr/interrupt.h>
#include <avr/io.h>
#define nop() asm volatile("nop\n\t"::);
#endif /* Compiler Used */
#endif /* __COMPILER_H__ */

72
cpu/avr/dev/debug.c Normal file
View file

@ -0,0 +1,72 @@
#include "compiler.h"
#include "delay.h"
#include <avr/pgmspace.h>
/*-----------------------------------------------------------------------------------*/
static void
delay(void)
{
unsigned char i;
for(i = 0; i < 1; ++i) {
Delay_10ms(1);
}
}
/*-----------------------------------------------------------------------------------*/
static char buffer[40];
static prog_char hextab[] =
{'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
/*-----------------------------------------------------------------------------------*/
static void
print_buffer(unsigned char len)
{
unsigned char i;
for(i = 0; i < len; ++i) {
delay();
UDR0 = buffer[i];
}
}
/*-----------------------------------------------------------------------------------*/
void
debug_print8(unsigned char v)
{
/* buffer[0] = v / 100 + '0';
buffer[1] = (v / 10) % 10 + '0';
buffer[2] = v % 10 + '0';
buffer[3] = ' ';
buffer[4] = PRG_RDB(hextab + (v >> 4));
buffer[5] = PRG_RDB(hextab + (v & 0x0f));
buffer[6] = '\n';
print_buffer(7);*/
}
/*-----------------------------------------------------------------------------------*/
void
debug_print16(unsigned short v)
{
/* buffer[0] = v / 10000 + '0';
buffer[1] = (v / 1000) % 10 + '0';
buffer[2] = (v / 100) % 10 + '0';
buffer[3] = (v / 10) % 10 + '0';
buffer[4] = v % 10 + '0';
buffer[5] = ' ';
buffer[6] = PRG_RDB(hextab + ((v & 0xf000) >> 12));
buffer[7] = PRG_RDB(hextab + ((v & 0x0f00) >> 8));
buffer[8] = PRG_RDB(hextab + ((v & 0xf0) >> 4));
buffer[9] = PRG_RDB(hextab + (v & 0x0f));
buffer[10] = '\n';
print_buffer(11);*/
}
/*-----------------------------------------------------------------------------------*/
void
debug_print(prog_char *str)
{
/* unsigned char i;
for(i = 0; PRG_RDB(str + i) != 0; ++i) {
buffer[i] = PRG_RDB(str + i);
}
print_buffer(i);*/
}
/*-----------------------------------------------------------------------------------*/

20
cpu/avr/dev/debug.h Normal file
View file

@ -0,0 +1,20 @@
#ifndef __DEBUG_H__
#define __DEBUG_H__
#if 0
#define debug_print(x)
#define debug_print8(x)
#else
#include "avr/pgmspace.h"
void debug_print(char *str);
void debug_print8(unsigned char v);
void debug_print16(unsigned short v);
#endif
#endif /* __DEBUG_H__ */

29
cpu/avr/dev/delay.c Normal file
View file

@ -0,0 +1,29 @@
#include "delay.h"
//----------------------------------------------------------------------------
// Wait for a specific time in 100 uSec
// (15 + t*( ((K_DELAY_100us-1)*6)+5 ))
//----------------------------------------------------------------------------
void Delay_100us(unsigned char t) {
unsigned int i;
if (t==0) return;
while (t--) for(i=0;i<K_DELAY_100us; i++);
}
//----------------------------------------------------------------------------
// Wait for a specific time in 1 mSec
// (15 + t*( ((K_DELAY_1ms-1)*6)+5 ))
//----------------------------------------------------------------------------
void Delay_1ms(unsigned char t) {
unsigned int i;
if (t==0) return;
while (t--) for(i=0;i<K_DELAY_1ms; i++);
}
//----------------------------------------------------------------------------
// Wait for a specific time in 10 mSec
// (15 + t*( ((K_DELAY_10ms-1)*6)+5 ))
//----------------------------------------------------------------------------
void Delay_10ms(unsigned char t) {
unsigned int i;
if (t==0) return;
while (t--) for(i=0;i<K_DELAY_10ms; i++);
}

9
cpu/avr/dev/delay.h Normal file
View file

@ -0,0 +1,9 @@
#define F_CPU 15000000
#define K_DELAY_100us F_CPU/61349
#define K_DELAY_1ms F_CPU/6013
#define K_DELAY_10ms F_CPU/600
void Delay_100us(unsigned char t);
void Delay_1ms(unsigned char t);
void Delay_10ms(unsigned char t);

55
cpu/avr/dev/eeprom.c Normal file
View file

@ -0,0 +1,55 @@
/*
* Copyright (c) 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. 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: Adam Dunkels <adam@sics.se>
*
* $Id: eeprom.c,v 1.1 2006/06/17 22:41:21 adamdunkels Exp $
*/
#include "eeprom.h"
#include <avr/eeprom.h>
#include <stdio.h>
/*---------------------------------------------------------------------------*/
void
eeprom_write(eeprom_addr_t addr, unsigned char *buf, int size)
{
while(!eeprom_is_ready());
eeprom_write_block(buf, (unsigned short *)addr, size);
}
/*---------------------------------------------------------------------------*/
void
eeprom_read(eeprom_addr_t addr, unsigned char *buf, int size)
{
while(!eeprom_is_ready());
eeprom_read_block(buf, (unsigned short *)addr, size);
}
/*---------------------------------------------------------------------------*/

50
cpu/avr/dev/flash.c Normal file
View file

@ -0,0 +1,50 @@
#include "dev/flash.h"
#include <avr/boot.h>
#include <inttypes.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
/*---------------------------------------------------------------------------*/
/*
* The following code was taken from the avr-libc manual:
*/
void
flash_write_page(uint32_t page, uint8_t *buf)
{
uint16_t i;
uint8_t sreg;
/* Disable interrupts. */
sreg = SREG;
cli();
eeprom_busy_wait();
boot_page_erase(page);
boot_spm_busy_wait(); /* Wait until the memory is erased. */
for(i = 0; i < SPM_PAGESIZE; i += 2) {
/* Set up little-endian word. */
uint16_t w = *buf++;
w += (*buf++) << 8;
boot_page_fill(page + i, w);
}
boot_page_write(page); /* Store buffer in flash page. */
boot_spm_busy_wait(); /* Wait until the memory is written. */
/* Reenable RWW-section again. We need this if we want to jump back
* to the application after bootloading. */
boot_rww_enable();
/* Re-enable interrupts (if they were ever enabled). */
SREG = sreg;
}
/*---------------------------------------------------------------------------*/

8
cpu/avr/dev/flash.h Normal file
View file

@ -0,0 +1,8 @@
#ifndef __FLASH_H__
#define __FLASH_H__
#include <inttypes.h>
void flash_write_page(uint32_t page, uint8_t *buf);
#endif /* __FLASH_H__ */

1362
cpu/avr/dev/lanc111.c Normal file

File diff suppressed because it is too large Load diff

130
cpu/avr/dev/rs232.c Normal file
View file

@ -0,0 +1,130 @@
/*
* Copyright (c) 2005, 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.
*
* @(#)$Id: rs232.c,v 1.1 2006/06/17 22:41:21 adamdunkels Exp $
*/
#include <avr/io.h>
#include <avr/signal.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include "contiki.h"
#include "dev/slip.h"
#include "dev/serial.h"
#include "dev/rs232.h"
static volatile unsigned char txwait;
/*static unsigned char slipmode;*/
static int (* input_handler)(unsigned char) = NULL;
/*---------------------------------------------------------------------------*/
SIGNAL(SIG_UART0_TRANS)
{
txwait = 0;
}
/*---------------------------------------------------------------------------*/
SIGNAL(SIG_UART0_RECV)
{
unsigned char c;
c = UDR0;
if(input_handler != NULL) {
input_handler(c);
}
/* if(slipmode) {
slip_input_byte(c);
} else {
serial_input_byte(c);
}*/
}
/*---------------------------------------------------------------------------*/
void
rs232_init(void)
{
/* Enable transmit. */
UCSR0B = _BV(RXCIE) | _BV(TXCIE) | _BV(RXEN) | _BV(TXEN);
/* Set baud rate (23 =~ 38400) */
UBRR0H = 0;
UBRR0L = 23;
/* slipmode = 0;*/
txwait = 0;
input_handler = NULL;
}
/*---------------------------------------------------------------------------*/
/*void
rs232_init_slip(void)
{
rs232_init();
slipmode = 1;
}*/
/*---------------------------------------------------------------------------*/
void
rs232_print_p(prog_char *buf)
{
while(pgm_read_byte(buf)) {
rs232_send(pgm_read_byte(buf));
++buf;
}
}
/*---------------------------------------------------------------------------*/
void
rs232_print(char *buf)
{
while(*buf) {
rs232_send(*buf++);
}
}
/*---------------------------------------------------------------------------*/
void
rs232_send(unsigned char c)
{
txwait = 1;
UDR0 = c;
while(txwait);
}
/*---------------------------------------------------------------------------*/
void
rs232_set_input(int (*f)(unsigned char))
{
input_handler = f;
}
/*---------------------------------------------------------------------------*/
void
slip_arch_writeb(unsigned char c)
{
rs232_send(c);
}
/*---------------------------------------------------------------------------*/

100
cpu/avr/dev/rs232.h Normal file
View file

@ -0,0 +1,100 @@
/*
* Copyright (c) 2005, 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.
*
* @(#)$Id: rs232.h,v 1.1 2006/06/17 22:41:21 adamdunkels Exp $
*/
#ifndef __RS232_H__
#define __RS232_H__
#include <avr/pgmspace.h>
/**
* \brief Initialize the RS232 module
*
* This function is called from the boot up code to
* initalize the RS232 module.
*/
void rs232_init(void);
/**
* \brief Set an input handler for incoming RS232 data
* \param f A pointer to a byte input handler
*
* This function sets the input handler for incoming RS232
* data. The input handler function is called for every
* incoming data byte. The function is called from the
* RS232 interrupt handler, so care must be taken when
* implementing the input handler to avoid race
* conditions.
*
* The return value of the input handler affects the sleep
* mode of the CPU: if the input handler returns non-zero
* (true), the CPU is awakened to let other processing
* take place. If the input handler returns zero, the CPU
* is kept sleeping.
*/
void rs232_set_input(int (* f)(unsigned char));
/**
* \brief Print a text string from program memory on RS232
* \param str A pointer to the string that is to be printed
*
* This function prints a string from program memory to
* RS232. The string must be terminated by a null
* byte. The RS232 module must be correctly initalized and
* configured for this function to work.
*/
void rs232_print_p(prog_char *buf);
/**
* \brief Print a text string on RS232
* \param str A pointer to the string that is to be printed
*
* This function prints a string to RS232. The string must
* be terminated by a null byte. The RS232 module must be
* correctly initalized and configured for this function
* to work.
*/
void rs232_print(char *buf);
/**
* \brief Print a character on RS232
* \param c The character to be printed
*
* This function prints a character to RS232. The RS232
* module must be correctly initalized and configured for
* this function to work.
*/
void rs232_send(unsigned char c);
#endif /* __RS232_H__ */

94
cpu/avr/dev/rtl8019-drv.c Normal file
View file

@ -0,0 +1,94 @@
/*-----------------------------------------------------------------------------------*/
/*
* Copyright (c) 2001-2004, Adam Dunkels.
* 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 uIP TCP/IP stack.
*
* $Id: rtl8019-drv.c,v 1.1 2006/06/17 22:41:21 adamdunkels Exp $
*
*/
#include "net/packet-service.h"
#include "dev/rtl8019dev.h"
#include "net/uip_arp.h"
#include <stdio.h>
static u8_t output(void);
SERVICE(rtl8019_drv_service, packet_service, { output });
PROCESS(rtl8019_drv_process, "RTL8019 driver");
PROCESS_THREAD(rtl8019_drv_process, ev, data)
{
PROCESS_BEGIN();
SERVICE_REGISTER(rtl8019_drv_service);
RTL8019dev_init();
while(1) {
process_poll(&rtl8019_drv_process);
PROCESS_WAIT_EVENT();
uip_len = RTL8019dev_poll();
if(uip_len > 0) {
#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
/* A frame was avaliable (and is now read into the uip_buf), so
we process it. */
if(BUF->type == HTONS(UIP_ETHTYPE_IP)) {
uip_arp_ipin();
uip_len -= sizeof(struct uip_eth_hdr);
tcpip_input();
} else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) {
uip_arp_arpin();
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0. */
if(uip_len > 0) {
RTL8019dev_send();
}
}
}
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
static u8_t
output(void)
{
uip_arp_out();
RTL8019dev_send();
return 0;
}
/*---------------------------------------------------------------------------*/

44
cpu/avr/dev/rtl8019-drv.h Normal file
View file

@ -0,0 +1,44 @@
/*
* Copyright (c) 2001, Adam Dunkels.
* 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. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Adam Dunkels.
* 4. 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 uIP TCP/IP stack.
*
* $Id: rtl8019-drv.h,v 1.1 2006/06/17 22:41:21 adamdunkels Exp $
*
*/
#ifndef __RTL8019_DRV_H__
#define __RTL8019_DRV_H__
#include "contiki.h"
PROCESS_NAME(rtl8019_drv_process);
#endif /* __RTL8019_DRV_H__ */

936
cpu/avr/dev/rtl8019.c Normal file
View file

@ -0,0 +1,936 @@
#include "rtl8019.h"
#include "delay.h"
#include "debug.h"
#include "avr/pgmspace.h"
#include "rtlregs.h"
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
#define outp(val, port) do { (port) = (val); } while(0)
#define inp(port) (port)
/*****************************************************************************
* Module Name: Realtek 8019AS Driver
*
* Created By: Louis Beaudoin (www.embedded-creations.com)
*
* Original Release: September 21, 2002
*
* Module Description:
* Provides functions to initialize the Realtek 8019AS, and send and retreive
* packets
*
* November 15, 2002 - Louis Beaudoin
* processRTL8019Interrupt() - bit mask mistake fixed
*
* September 30, 2002 - Louis Beaudoin
* Receive functions modified to handle errors encountered when receiving a
* fast data stream. Functions now manually retreive data instead of
* using the send packet command. Interface improved by checking for
* overruns and data in the buffer internally.
* Corrected the overrun function - overrun flag was not reset after overrun
* Added support for the Imagecraft Compiler
* Added support to communicate with the NIC using general I/O ports
*
*****************************************************************************/
/*****************************************************************************
* writeRTL( RTL_ADDRESS, RTL_DATA )
* Args: 1. unsigned char RTL_ADDRESS - register offset of RTL register
* 2. unsigned char RTL_DATA - data to write to register
* Created By: Louis Beaudoin
* Date: September 21, 2002
* Description: Writes byte to RTL8019 register.
*
* Notes - If using the External SRAM Interface, performs a write to
* address MEMORY_MAPPED_RTL8019_OFFSET + (RTL_ADDRESS<<8)
* The address is sent in the non-multiplxed upper address port so
* no latch is required.
*
* If using general I/O ports, the data port is left in the input
* state with pullups enabled
*
*****************************************************************************/
#if MEMORY_MAPPED_NIC == 1
/*#define writeRTL(RTL_ADDRESS,RTL_DATA) do{ *(volatile unsigned char *) \
(MEMORY_MAPPED_RTL8019_OFFSET \
+ (((unsigned char)(RTL_ADDRESS)) << 8)) = \
(unsigned char)(RTL_DATA); } while(0)*/
#define writeRTL nic_write
#else
void writeRTL(unsigned char address, unsigned char data)
{
// put the address and data in the port registers - data port is output
outp( address, RTL8019_ADDRESS_PORT );
outp( 0xFF, RTL8019_DATA_DDR );
outp( data, RTL8019_DATA_PORT );
// toggle write pin
RTL8019_CLEAR_WRITE;
RTL8019_SET_WRITE;
// set data port back to input with pullups enabled
outp( 0x00, RTL8019_DATA_DDR );
outp( 0xFF, RTL8019_DATA_PORT );
}
#endif
/*****************************************************************************
* readRTL(RTL_ADDRESS)
* Args: unsigned char RTL_ADDRESS - register offset of RTL register
* Created By: Louis Beaudoin
* Date: September 21, 2002
* Description: Reads byte from RTL8019 register
*
* Notes - If using the External SRAM Interface, performs a read from
* address MEMORY_MAPPED_RTL8019_OFFSET + (RTL_ADDRESS<<8)
* The address is sent in the non-multiplxed upper address port so
* no latch is required.
*
* If using general I/O ports, the data port is assumed to already be
* an input, and is left as an input port when done
*
*****************************************************************************/
#if MEMORY_MAPPED_NIC == 1
/*#define readRTL(RTL_ADDRESS) (*(volatile unsigned char *) \
(MEMORY_MAPPED_RTL8019_OFFSET \
+ (((unsigned char)(RTL_ADDRESS)) << 8)) )*/
#define readRTL nic_read
#else
unsigned char readRTL(unsigned char address)
{
unsigned char byte;
// drive the read address
outp( address, RTL8019_ADDRESS_PORT );
//nop();
// assert read
RTL8019_CLEAR_READ;
nop();
// read in the data
byte = inp( RTL8019_DATA_PIN );
// negate read
RTL8019_SET_READ;
return byte;
}
#endif
/*****************************************************************************
* RTL8019setupPorts(void);
*
* Created By: Louis Beaudoin
* Date: September 21, 2002
* Description: Sets up the ports used for communication with the RTL8019 NIC
* (data bus, address bus, read, write, and reset)
*****************************************************************************/
void RTL8019setupPorts(void)
{
volatile unsigned char *base = (unsigned char *)0x8300;
#if MEMORY_MAPPED_NIC == 1
// enable external SRAM interface - no wait states
outp(inp(MCUCR) | (1<<SRE), MCUCR);
#else
// make the address port output
outp( 0xFF, RTL8019_ADDRESS_DDR );
// make the data port input with pull-ups
outp( 0xFF, RTL8019_DATA_PORT );
// make the control port read and write pins outputs and asserted
//outp( inp(RTL8019_CONTROL_DDR) | (1<<RTL8019_CONTROL_READPIN) |
// (1<<RTL8019_CONTROL_WRITEPIN), RTL8019_CONTROL_DDR );
sbi( RTL8019_CONTROL_DDR, RTL8019_CONTROL_READPIN );
sbi( RTL8019_CONTROL_DDR, RTL8019_CONTROL_WRITEPIN );
//outp( inp(RTL8019_CONTROL_PORT) | (1<<RTL8019_CONTROL_READPIN) |
// (1<<RTL8019_CONTROL_WRITEPIN), RTL8019_CONTROL_PORT );
sbi( RTL8019_CONTROL_PORT, RTL8019_CONTROL_READPIN );
sbi( RTL8019_CONTROL_PORT, RTL8019_CONTROL_WRITEPIN );
#endif
// enable output pin for Resetting the RTL8019
sbi( RTL8019_RESET_DDR, RTL8019_RESET_PIN );
}
/*****************************************************************************
* HARD_RESET_RTL8019()
*
* Created By: Louis Beaudoin
* Date: September 21, 2002
* Description: Simply toggles the pin that resets the NIC
*****************************************************************************/
/*#define HARD_RESET_RTL8019() do{ sbi(RTL8019_RESET_PORT, RTL8019_RESET_PIN); \
Delay_10ms(1); \
cbi(RTL8019_RESET_PORT, RTL8019_RESET_PIN);} \
while(0)*/
/*****************************************************************************
* overrun(void);
*
* Created By: Louis Beaudoin
* Date: September 21, 2002
* Description: "Canned" receive buffer overrun function originally from
* a National Semiconductor appnote
* Notes: This function must be called before retreiving packets from
* the NIC if there is a buffer overrun
*****************************************************************************/
void overrun(void);
//******************************************************************
//* REALTEK CONTROL REGISTER OFFSETS
//* All offsets in Page 0 unless otherwise specified
//* All functions accessing CR must leave CR in page 0 upon exit
//******************************************************************
#define CR 0x00
#define PSTART 0x01
#define PAR0 0x01 // Page 1
#define CR9346 0x01 // Page 3
#define PSTOP 0x02
#define BNRY 0x03
#define TSR 0x04
#define TPSR 0x04
#define TBCR0 0x05
#define NCR 0x05
#define TBCR1 0x06
#define ISR 0x07
#define CURR 0x07 // Page 1
#define RSAR0 0x08
#define CRDA0 0x08
#define RSAR1 0x09
#define CRDA1 0x09
#define RBCR0 0x0A
#define RBCR1 0x0B
#define RSR 0x0C
#define RCR 0x0C
#define TCR 0x0D
#define CNTR0 0x0D
#define DCR 0x0E
#define CNTR1 0x0E
#define IMR 0x0F
#define CNTR2 0x0F
#define RDMAPORT 0x10
#define RSTPORT 0x18
/*****************************************************************************
*
* RTL ISR Register Bits
*
*****************************************************************************/
#define ISR_RST 7
#define ISR_OVW 4
#define ISR_PRX 0
#define ISR_RDC 6
#define ISR_PTX 1
/*****************************************************************************
*
* RTL Register Initialization Values
*
*****************************************************************************/
// RCR : accept broadcast packets and packets destined to this MAC
// drop short frames and receive errors
#define RCR_INIT 0x04
// TCR : default transmit operation - CRC is generated
#define TCR_INIT 0x00
// DCR : allows send packet to be used for packet retreival
// FIFO threshold: 8-bits (works)
// 8-bit transfer mode
#define DCR_INIT 0x58
// IMR : interrupt enabled for receive and overrun events
#define IMR_INIT 0x11
// buffer boundaries - transmit has 6 256-byte pages
// receive has 26 256-byte pages
// entire available packet buffer space is allocated
#define TXSTART_INIT 0x40
#define RXSTART_INIT 0x46
#define RXSTOP_INIT 0x60
void RTL8019beginPacketSend(unsigned int packetLength)
{
volatile unsigned char *base = (unsigned char *)0x8300;
unsigned int sendPacketLength;
sendPacketLength = (packetLength>=ETHERNET_MIN_PACKET_LENGTH) ?
packetLength : ETHERNET_MIN_PACKET_LENGTH ;
//start the NIC
writeRTL(CR,0x22);
// still transmitting a packet - wait for it to finish
while( readRTL(CR) & 0x04 );
//load beginning page for transmit buffer
writeRTL(TPSR,TXSTART_INIT);
//set start address for remote DMA operation
writeRTL(RSAR0,0x00);
writeRTL(RSAR1,0x40);
//clear the packet stored interrupt
writeRTL(ISR,(1<<ISR_PTX));
//load data byte count for remote DMA
writeRTL(RBCR0, (unsigned char)(packetLength));
writeRTL(RBCR1, (unsigned char)(packetLength>>8));
writeRTL(TBCR0, (unsigned char)(sendPacketLength));
writeRTL(TBCR1, (unsigned char)((sendPacketLength)>>8));
//do remote write operation
writeRTL(CR,0x12);
}
void RTL8019sendPacketData(unsigned char * localBuffer, unsigned int length)
{
unsigned int i;
volatile unsigned char *base = (unsigned char *)0x8300;
for(i=0;i<length;i++)
writeRTL(RDMAPORT, localBuffer[i]);
}
void RTL8019endPacketSend(void)
{
volatile unsigned char *base = (unsigned char *)0x8300;
//send the contents of the transmit buffer onto the network
writeRTL(CR,0x24);
// clear the remote DMA interrupt
writeRTL(ISR, (1<<ISR_RDC));
}
// pointers to locations in the RTL8019 receive buffer
static unsigned char nextPage;
static unsigned int currentRetreiveAddress;
// location of items in the RTL8019's page header
#define enetpacketstatus 0x00
#define nextblock_ptr 0x01
#define enetpacketLenL 0x02
#define enetpacketLenH 0x03
unsigned int RTL8019beginPacketRetreive(void)
{
volatile unsigned char *base = (unsigned char *)0x8300;
unsigned char i;
unsigned char bnry;
unsigned char pageheader[4];
unsigned int rxlen;
// check for and handle an overflow
processRTL8019Interrupt();
// read CURR from page 1
writeRTL(CR,0x62);
i = readRTL(CURR);
// return to page 0
writeRTL(CR,0x22);
// read the boundary register - pointing to the beginning of the packet
bnry = readRTL(BNRY) ;
/* debug_print(PSTR("bnry: "));
debug_print8(bnry);*/
/* debug_print(PSTR("RXSTOP_INIT: "));
debug_print8(RXSTOP_INIT);
debug_print(PSTR("RXSTART_INIT: "));
debug_print8(RXSTART_INIT);*/
// return if there is no packet in the buffer
if( bnry == i ) {
return 0;
}
// clear the packet received interrupt flag
writeRTL(ISR, (1<<ISR_PRX));
// the boundary pointer is invalid, reset the contents of the buffer and exit
if( (bnry >= RXSTOP_INIT) || (bnry < RXSTART_INIT) )
{
writeRTL(BNRY, RXSTART_INIT);
writeRTL(CR, 0x62);
writeRTL(CURR, RXSTART_INIT);
writeRTL(CR, 0x22);
return 0;
}
// initiate DMA to transfer the RTL8019 packet header
writeRTL(RBCR0, 4);
writeRTL(RBCR1, 0);
writeRTL(RSAR0, 0);
writeRTL(RSAR1, bnry);
writeRTL(CR, 0x0A);
/* debug_print(PSTR("Page header: "));*/
for(i=0;i<4;i++) {
pageheader[i] = readRTL(RDMAPORT);
/* debug_print8(pageheader[i]);*/
}
// end the DMA operation
writeRTL(CR, 0x22);
for(i = 0; i <= 20; i++) {
if(readRTL(ISR) & 1<<6) {
break;
}
}
writeRTL(ISR, 1<<6);
rxlen = (pageheader[enetpacketLenH]<<8) + pageheader[enetpacketLenL];
nextPage = pageheader[nextblock_ptr] ;
currentRetreiveAddress = (bnry<<8) + 4;
/* debug_print(PSTR("nextPage: "));
debug_print8(nextPage);*/
// if the nextPage pointer is invalid, the packet is not ready yet - exit
if( (nextPage >= RXSTOP_INIT) || (nextPage < RXSTART_INIT) ) {
/* UDR0 = '0';*/
return 0;
}
return rxlen-4;
}
void RTL8019retreivePacketData(unsigned char * localBuffer, unsigned int length)
{
unsigned int i;
volatile unsigned char *base = (unsigned char *)0x8300;
// initiate DMA to transfer the data
writeRTL(RBCR0, (unsigned char)length);
writeRTL(RBCR1, (unsigned char)(length>>8));
writeRTL(RSAR0, (unsigned char)currentRetreiveAddress);
writeRTL(RSAR1, (unsigned char)(currentRetreiveAddress>>8));
writeRTL(CR, 0x0A);
for(i=0;i<length;i++)
localBuffer[i] = readRTL(RDMAPORT);
// end the DMA operation
writeRTL(CR, 0x22);
for(i = 0; i <= 20; i++)
if(readRTL(ISR) & 1<<6)
break;
writeRTL(ISR, 1<<6);
currentRetreiveAddress += length;
if( currentRetreiveAddress >= 0x6000 )
currentRetreiveAddress = currentRetreiveAddress - (0x6000-0x4600) ;
}
void RTL8019endPacketRetreive(void)
{
volatile unsigned char *base = (unsigned char *)0x8300;
unsigned char i;
// end the DMA operation
writeRTL(CR, 0x22);
for(i = 0; i <= 20; i++)
if(readRTL(ISR) & 1<<6)
break;
writeRTL(ISR, 1<<6);
// set the boundary register to point to the start of the next packet
writeRTL(BNRY, nextPage);
}
void overrun(void)
{
volatile unsigned char *base = (unsigned char *)0x8300;
unsigned char data_L, resend;
data_L = readRTL(CR);
writeRTL(CR, 0x21);
Delay_1ms(2);
writeRTL(RBCR0, 0x00);
writeRTL(RBCR1, 0x00);
if(!(data_L & 0x04))
resend = 0;
else if(data_L & 0x04)
{
data_L = readRTL(ISR);
if((data_L & 0x02) || (data_L & 0x08))
resend = 0;
else
resend = 1;
}
writeRTL(TCR, 0x02);
writeRTL(CR, 0x22);
writeRTL(BNRY, RXSTART_INIT);
writeRTL(CR, 0x62);
writeRTL(CURR, RXSTART_INIT);
writeRTL(CR, 0x22);
writeRTL(ISR, 0x10);
writeRTL(TCR, TCR_INIT);
writeRTL(ISR, 0xFF);
}
/*!
* \brief Size of a single ring buffer page.
*/
#define NIC_PAGE_SIZE 0x100
/*!
* \brief First ring buffer page address.
*/
#define NIC_START_PAGE 0x40
/*!
* \brief Last ring buffer page address plus 1.
*/
#define NIC_STOP_PAGE 0x60
/*!
* \brief Number of pages in a single transmit buffer.
*
* This should be at least the MTU size.
*/
#define NIC_TX_PAGES 6
/*!
* \brief Number of transmit buffers.
*/
#define NIC_TX_BUFFERS 2
/*!
* \brief Controller memory layout:
*
* 0x4000 - 0x4bff 3k bytes transmit buffer
* 0x4c00 - 0x5fff 5k bytes receive buffer
*/
#define NIC_FIRST_TX_PAGE NIC_START_PAGE
#define NIC_FIRST_RX_PAGE (NIC_FIRST_TX_PAGE + NIC_TX_PAGES * NIC_TX_BUFFERS)
/*!
* \brief Standard sizing information
*/
#define TX_PAGES 12 /* Allow for 2 back-to-back frames */
static unsigned char mac[6] = {0x00,0x06,0x98,0x01,0x02,0x29};
void Delay(long nops)
{
volatile long i;
for(i = 0; i < nops; i++)
#ifdef __IMAGECRAFT__
asm("nop\n");
#else
asm volatile("nop\n\t"::);
#endif
}
static int NicReset(void)
{
volatile unsigned char *base = (unsigned char *)0x8300;
unsigned char i;
unsigned char j;
for(j = 0; j < 20; j++) {
debug_print(PSTR("SW-Reset..."));
i = nic_read(NIC_RESET);
Delay(500);
nic_write(NIC_RESET, i);
for(i = 0; i < 20; i++) {
Delay(5000);
/*
* ID detection added for version 1.1 boards.
*/
if((nic_read(NIC_PG0_ISR) & NIC_ISR_RST) != 0 &&
nic_read(NIC_PG0_RBCR0) == 0x50 &&
nic_read(NIC_PG0_RBCR1) == 0x70) {
debug_print(PSTR("OK\r\n"));
return 0;
}
}
debug_print(PSTR("failed\r\n\x07"));
/*
* Toggle the hardware reset line. Since Ethernut version 1.3 the
* hardware reset pin of the nic is no longer connected to bit 4
* on port E, but wired to the board reset line.
*/
if(j == 10) {
debug_print(PSTR("Ethernut 1.1 HW-Reset\r\n"));
sbi(DDRE, 4);
sbi(PORTE, 4);
Delay(100000);
cbi(PORTE, 4);
Delay(250000);
}
}
return -1;
}
void initRTL8019(void)
{
unsigned char i, rb;
volatile unsigned char *base = (unsigned char *)0x8300;
RTL8019setupPorts();
/*#define nic_write writeRTL
#define nic_read readRTL*/
/*
* Disable NIC interrupts.
*/
cbi(EIMSK, INT5);
/* if(NicReset(base))
return -1;*/
#if 0
/*
* Mask all interrupts and clear any interrupt status flag to set the
* INT pin back to low.
*/
nic_write(NIC_PG0_IMR, 0);
nic_write(NIC_PG0_ISR, 0xff);
/*
* During reset the nic loaded its initial configuration from an
* external eeprom. On the ethernut board we do not have any
* configuration eeprom, but simply tied the eeprom data line to
* high level. So we have to clear some bits in the configuration
* register. Switch to register page 3.
*/
nic_write(NIC_CR, NIC_CR_STP | NIC_CR_RD2 | NIC_CR_PS0 | NIC_CR_PS1);
/*
* The nic configuration registers are write protected unless both
* EEM bits are set to 1.
*/
nic_write(NIC_PG3_EECR, NIC_EECR_EEM0 | NIC_EECR_EEM1);
/*
* Disable sleep and power down.
*/
nic_write(NIC_PG3_CONFIG3, 0);
/*
* Network media had been set to 10Base2 by the virtual EEPROM and
* will be set now to auto detect. This will initiate a link test.
* We don't force 10BaseT, because this would disable the link test.
*/
nic_write(NIC_PG3_CONFIG2, NIC_CONFIG2_BSELB);
/*
* Reenable write protection of the nic configuration registers
* and wait for link test to complete.
*/
nic_write(NIC_PG3_EECR, 0);
/* NutSleep(WAIT500);*/
Delay_10ms(50);
/*
* Switch to register page 0 and set data configuration register
* to byte-wide DMA transfers, normal operation (no loopback),
* send command not executed and 8 byte fifo threshold.
*/
nic_write(NIC_CR, NIC_CR_STP | NIC_CR_RD2);
nic_write(NIC_PG0_DCR, NIC_DCR_LS | NIC_DCR_FT1);
/*
* Clear remote dma byte count register.
*/
nic_write(NIC_PG0_RBCR0, 0);
nic_write(NIC_PG0_RBCR1, 0);
/*
* Temporarily set receiver to monitor mode and transmitter to
* internal loopback mode. Incoming packets will not be stored
* in the nic ring buffer and no data will be send to the network.
*/
nic_write(NIC_PG0_RCR, NIC_RCR_MON);
nic_write(NIC_PG0_TCR, NIC_TCR_LB0);
/*
* Configure the nic's ring buffer page layout.
* NIC_PG0_BNRY: Last page read.
* NIC_PG0_PSTART: First page of receiver buffer.
* NIC_PG0_PSTOP: Last page of receiver buffer.
*/
nic_write(NIC_PG0_TPSR, NIC_FIRST_TX_PAGE);
nic_write(NIC_PG0_BNRY, NIC_STOP_PAGE - 1);
nic_write(NIC_PG0_PSTART, NIC_FIRST_RX_PAGE);
nic_write(NIC_PG0_PSTOP, NIC_STOP_PAGE);
/*
* Once again clear interrupt status register.
*/
nic_write(NIC_PG0_ISR, 0xff);
/*
* Switch to register page 1 and copy our MAC address into the nic.
* We are still in stop mode.
*/
nic_write(NIC_CR, NIC_CR_STP | NIC_CR_RD2 | NIC_CR_PS0);
for(i = 0; i < 6; i++)
nic_write(NIC_PG1_PAR0 + i, mac[i]);
/*
* Clear multicast filter bits to disable all packets.
*/
for(i = 0; i < 8; i++)
nic_write(NIC_PG1_MAR0 + i, 0);
/*
* Set current page pointer to one page after the boundary pointer.
*/
nic_write(NIC_PG1_CURR, NIC_START_PAGE + TX_PAGES);
/*
* Switch back to register page 0, remaining in stop mode.
*/
nic_write(NIC_CR, NIC_CR_STP | NIC_CR_RD2);
/*
* Take receiver out of monitor mode and enable it for accepting
* broadcasts.
*/
nic_write(NIC_PG0_RCR, NIC_RCR_AB);
/*
* Clear all interrupt status flags and enable interrupts.
*/
nic_write(NIC_PG0_ISR, 0xff);
nic_write(NIC_PG0_IMR, NIC_IMR_PRXE | NIC_IMR_PTXE | NIC_IMR_RXEE |
NIC_IMR_TXEE | NIC_IMR_OVWE);
/*
* Fire up the nic by clearing the stop bit and setting the start bit.
* To activate the local receive dma we must also take the nic out of
* the local loopback mode.
*/
nic_write(NIC_CR, NIC_CR_STA | NIC_CR_RD2);
nic_write(NIC_PG0_TCR, 0);
/* NutSleep(WAIT500);*/
Delay_10ms(50);
#endif /* 0 */
NicReset();
debug_print(PSTR("Init controller..."));
nic_write(NIC_PG0_IMR, 0);
nic_write(NIC_PG0_ISR, 0xff);
nic_write(NIC_CR, NIC_CR_STP | NIC_CR_RD2 | NIC_CR_PS0 | NIC_CR_PS1);
nic_write(NIC_PG3_EECR, NIC_EECR_EEM0 | NIC_EECR_EEM1);
nic_write(NIC_PG3_CONFIG3, 0);
nic_write(NIC_PG3_CONFIG2, NIC_CONFIG2_BSELB);
nic_write(NIC_PG3_EECR, 0);
/* Delay(50000);*/
Delay_10ms(200);
nic_write(NIC_CR, NIC_CR_STP | NIC_CR_RD2);
nic_write(NIC_PG0_DCR, NIC_DCR_LS | NIC_DCR_FT1);
nic_write(NIC_PG0_RBCR0, 0);
nic_write(NIC_PG0_RBCR1, 0);
nic_write(NIC_PG0_RCR, NIC_RCR_MON);
nic_write(NIC_PG0_TCR, NIC_TCR_LB0);
nic_write(NIC_PG0_TPSR, NIC_FIRST_TX_PAGE);
nic_write(NIC_PG0_BNRY, NIC_STOP_PAGE - 1);
nic_write(NIC_PG0_PSTART, NIC_FIRST_RX_PAGE);
nic_write(NIC_PG0_PSTOP, NIC_STOP_PAGE);
nic_write(NIC_PG0_ISR, 0xff);
nic_write(NIC_CR, NIC_CR_STP | NIC_CR_RD2 | NIC_CR_PS0);
for(i = 0; i < 6; i++)
nic_write(NIC_PG1_PAR0 + i, mac[i]);
for(i = 0; i < 8; i++)
nic_write(NIC_PG1_MAR0 + i, 0);
nic_write(NIC_PG1_CURR, NIC_START_PAGE + TX_PAGES);
nic_write(NIC_CR, NIC_CR_STP | NIC_CR_RD2);
nic_write(NIC_PG0_RCR, NIC_RCR_AB);
nic_write(NIC_PG0_ISR, 0xff);
nic_write(NIC_PG0_IMR, 0);
nic_write(NIC_CR, NIC_CR_STA | NIC_CR_RD2);
nic_write(NIC_PG0_TCR, 0);
/* Delay(1000000)*/
Delay_10ms(200);
nic_write(NIC_CR, NIC_CR_STA | NIC_CR_RD2 | NIC_CR_PS0 | NIC_CR_PS1);
rb = nic_read(NIC_PG3_CONFIG0);
debug_print8(rb);
switch(rb & 0xC0) {
case 0x00:
debug_print(PSTR("RTL8019AS "));
if(rb & 0x08)
debug_print(PSTR("jumper mode: "));
if(rb & 0x20)
debug_print(PSTR("AUI "));
if(rb & 0x10)
debug_print(PSTR("PNP "));
break;
case 0xC0:
debug_print(PSTR("RTL8019 "));
if(rb & 0x08)
debug_print(PSTR("jumper mode: "));
break;
default:
debug_print(PSTR("Unknown chip "));
debug_print8(rb);
break;
}
if(rb & 0x04)
debug_print(PSTR("BNC\x07 "));
if(rb & 0x03)
debug_print(PSTR("Failed\x07 "));
/* rb = nic_read(NIC_PG3_CONFIG1);
debug_print8(rb);*/
/* NutPrintFormat(0, "IRQ%u ", (rb >> 4) & 7);*/
/* debug_print("IRQ ");
debug_print8((rb >> 4) & 7);*/
rb = nic_read(NIC_PG3_CONFIG2);
debug_print8(rb);
switch(rb & 0xC0) {
case 0x00:
debug_print(PSTR("Auto "));
break;
case 0x40:
debug_print(PSTR("10BaseT "));
break;
case 0x80:
debug_print(PSTR("10Base5 "));
break;
case 0xC0:
debug_print(PSTR("10Base2 "));
break;
}
return;
/* HARD_RESET_RTL8019();*/
// do soft reset
writeRTL( ISR, readRTL(ISR) ) ;
Delay_10ms(5);
writeRTL(CR,0x21); // stop the NIC, abort DMA, page 0
Delay_1ms(2); // make sure nothing is coming in or going out
writeRTL(DCR, DCR_INIT); // 0x58
writeRTL(RBCR0,0x00);
writeRTL(RBCR1,0x00);
writeRTL(RCR,0x04);
writeRTL(TPSR, TXSTART_INIT);
writeRTL(TCR,0x02);
writeRTL(PSTART, RXSTART_INIT);
writeRTL(BNRY, RXSTART_INIT);
writeRTL(PSTOP, RXSTOP_INIT);
writeRTL(CR, 0x61);
Delay_1ms(2);
writeRTL(CURR, RXSTART_INIT);
writeRTL(PAR0+0, MYMAC_0);
writeRTL(PAR0+1, MYMAC_1);
writeRTL(PAR0+2, MYMAC_2);
writeRTL(PAR0+3, MYMAC_3);
writeRTL(PAR0+4, MYMAC_4);
writeRTL(PAR0+5, MYMAC_5);
writeRTL(CR,0x21);
writeRTL(DCR, DCR_INIT);
writeRTL(CR,0x22);
writeRTL(ISR,0xFF);
writeRTL(IMR, IMR_INIT);
writeRTL(TCR, TCR_INIT);
writeRTL(CR, 0x22); // start the NIC
}
void processRTL8019Interrupt(void)
{
volatile unsigned char *base = (unsigned char *)0x8300;
unsigned char byte = readRTL(ISR);
if( byte & (1<<ISR_OVW) )
overrun();
}
/*
unsigned char RTL8019ReceiveEmpty(void)
{
unsigned char temp;
// read CURR from page 1
writeRTL(CR,0x62);
temp = readRTL(CURR);
// return to page 0
writeRTL(CR,0x22);
return ( readRTL(BNRY) == temp );
}*/

265
cpu/avr/dev/rtl8019.h Normal file
View file

@ -0,0 +1,265 @@
#ifndef __RTL8019_H__
#define __RTL8019_H__
/*****************************************************************************
* Module Name: Realtek 8019AS Driver
*
* Created By: Louis Beaudoin (www.embedded-creations.com)
*
* Original Release: September 21, 2002
*
* Module Description:
* Provides functions to initialize the Realtek 8019AS, and send and retreive
* packets
*
* September 30, 2002 - Louis Beaudoin
* Receive functions modified to handle errors encountered when receiving a
* fast data stream. Functions now manually retreive data instead of
* using the send packet command. Interface improved by checking for
* overruns and data in the buffer internally.
* Corrected the overrun function - overrun flag was not reset after overrun
* Added support for the Imagecraft Compiler
* Added support to communicate with the NIC using general I/O ports
*
*****************************************************************************/
/*#include "delay.h"*/
#include "compiler.h"
/*****************************************************************************
* RTL8019beginPacketSend(unsigned int packetLength)
* Args: unsigned int - length of the Ethernet frame (see note)
* Created By: Louis Beaudoin
* Date: September 21, 2002
* Description: Sets up the NIC to send a packet
* Notes: The NIC will not send packets less than 60 bytes long (the min
* Ethernet frame length. The transmit length is automatically
* increased to 60 bytes if packetLength is < 60
*****************************************************************************/
void RTL8019beginPacketSend(unsigned int packetLength);
/*****************************************************************************
* RTL8019sendPacketData(unsigned char * localBuffer, unsigned int length)
* Args: 1. unsigned char * localBuffer - Pointer to the beginning of
* the buffer to load into the NIC
* 2. unsigned char length - number of bytes to copy to
* the NIC
* Created By: Louis Beaudoin
* Date: September 21, 2002
* Description: Loads length # of bytes from a local buffer to the transmit
* packet buffer
* Notes: RTL8019beginPacketSend() must be called before sending
* any data.
* Several calls to RTL8019retreivePacketData() may be made to
* copy packet data from different buffers
*****************************************************************************/
void RTL8019sendPacketData(unsigned char * localBuffer, unsigned int length);
/*****************************************************************************
* RTL8019endPacketSend()
* Created By: Louis Beaudoin
* Date: September 21, 2002
* Description: Ends a packet send operation and instructs the NIC to transmit
* the frame over the network
*****************************************************************************/
void RTL8019endPacketSend(void);
/*****************************************************************************
* initRTL8019(void);
*
* Created By: Louis Beaudoin
* Date: September 21, 2002
* Description: Sets up the RTL8019 NIC hardware interface, and initializes
* the buffers and configuration of the NIC
*****************************************************************************/
void initRTL8019(void);
/*****************************************************************************
* processRTL8019Interrupt(void);
*
* Created By: Louis Beaudoin
* Date: September 21, 2002
* Description: Reads the NIC's ISR register looking for a receive buffer
* overrun - which is then handled.
* Notes: The function does not need to be called in response to an
* interrupt. The function can be polled and the NIC's INT
* line not used. This function should be called before
* attempting to retreive a packet from the NIC
*****************************************************************************/
void processRTL8019Interrupt(void);
/*****************************************************************************
* unsigned char RTL8019ReceiveEmpty(void);
*
* Returns: non-zero (true) if buffer is empty, zero if data in buffer
* Created By: Louis Beaudoin
* Date: September 21, 2002
* Description: Compares the BNRY and CURR receive buffer pointers to see if
* there is a packet in the receive buffer
* ** Removed as of version 0.60.1 **
*****************************************************************************/
//unsigned char RTL8019ReceiveEmpty(void);
/*****************************************************************************
* unsigned int RTL8019beginPacketRetreive()
* Returns: unsigned int - length of the Ethernet frame (see note)
* Created By: Louis Beaudoin
* Date: September 21, 2002
* Description: Sets up the NIC to retreive a packet
* Notes: The size returned is the size of all the data in the Ethernet
* frame minus the Ethernet checksum. This may include unused
* trailer bytes appended if data is less than the minimum
* Ethernet frame length (60 bytes). A size of zero indicates
* there are no packets available.
* A call to RTL8019beginPacketRetreive() must be followed by a
* call to RTL8019endPacketRetreive() regardless if data is
* retreived, unless 0 is returned.
*****************************************************************************/
unsigned int RTL8019beginPacketRetreive(void);
/*****************************************************************************
* RTL8019retreivePacketData(unsigned char * localBuffer, unsigned int length)
* Args: 1. unsigned char * localBuffer - Pointer to the beginning of
* the buffer to store the ethernet frame.
* 2. unsigned char length - number of bytes to copy to
* localBuffer
* Created By: Louis Beaudoin
* Date: September 21, 2002
* Description: Loads length # of bytes from the receive packet buffer to
* a local buffer
* Notes: RTL8019beginPacketRetreive() must be called before retreiving
* any data.
* Several calls to RTL8019retreivePacketData() may be made to
* copy packet data to different buffers
*****************************************************************************/
void RTL8019retreivePacketData(unsigned char * localBuffer,
unsigned int length);
/*****************************************************************************
* RTL8019endPacketRetreive()
* Created By: Louis Beaudoin
* Date: September 21, 2002
* Description: Ends a packet retreive operation begun by calling
* RTL8019beginPacketRetreive(). The NIC buffer space used by
* the retreived packet is freed
* Notes: A packet may be removed from the buffer without being read
* by calling RTL8019endPacketRetreive() after
* RTL8019beginPacketRetreive().
*****************************************************************************/
void RTL8019endPacketRetreive(void);
/*****************************************************************************
*
* AVR hardware setup
*
* External SRAM Interface:
* The five NIC address lines are taken from A8-A12 (uses the
* non-multiplexed address port so no latch is required)
*
* General I/O Interface:
* Two full ports are required for the address and data buses. Two pins
* from another port are used to control the read and write lines
*
* One output pin is required for hard resetting the NIC
*
*****************************************************************************/
// set to 1 to use the External SRAM Interface - 0 for General I/O
#define MEMORY_MAPPED_NIC 1
#if MEMORY_MAPPED_NIC /*** NIC Interface through External SRAM Interface ****/
// NIC is mapped from address 0x8000 - 0x9F00
#define MEMORY_MAPPED_RTL8019_OFFSET 0x8300
#else /************ NIC Interface through General I/O *******************/
// RTL8019 address port
#define RTL8019_ADDRESS_PORT PORTC
#define RTL8019_ADDRESS_DDR DDRC
// RTL8019 data port
#define RTL8019_DATA_PORT PORTA
#define RTL8019_DATA_DDR DDRA
#define RTL8019_DATA_PIN PINA
// RTL8019 control port
#define RTL8019_CONTROL_PORT PORTD
#define RTL8019_CONTROL_DDR DDRD
#define RTL8019_CONTROL_READPIN PD7
#define RTL8019_CONTROL_WRITEPIN PD6
// macros to control the read and write pins
#define RTL8019_CLEAR_READ cbi(RTL8019_CONTROL_PORT,\
RTL8019_CONTROL_READPIN)
#define RTL8019_SET_READ sbi(RTL8019_CONTROL_PORT,\
RTL8019_CONTROL_READPIN)
#define RTL8019_CLEAR_WRITE cbi(RTL8019_CONTROL_PORT,\
RTL8019_CONTROL_WRITEPIN)
#define RTL8019_SET_WRITE sbi(RTL8019_CONTROL_PORT,\
RTL8019_CONTROL_WRITEPIN)
#endif /** NIC Interface **/
// RTL RESET - Port B pin 0
#define RTL8019_RESET_PORT PORTE
#define RTL8019_RESET_DDR DDRE
#define RTL8019_RESET_PIN PORTE0
/*****************************************************************************
*
* Ethernet constants
*
*****************************************************************************/
#define ETHERNET_MIN_PACKET_LENGTH 0x3C
#define ETHERNET_HEADER_LENGTH 0x0E
/*****************************************************************************
*
* MAC address assigned to the RTL8019
*
*****************************************************************************/
/*#define MYMAC_0 '0'
#define MYMAC_1 'F'
#define MYMAC_2 'F'
#define MYMAC_3 'I'
#define MYMAC_4 'C'
#define MYMAC_5 'E'*/
#define MYMAC_0 0x00
#define MYMAC_1 0x06
#define MYMAC_2 0x98
#define MYMAC_3 0x01
#define MYMAC_4 0x02
#define MYMAC_5 0x26
#endif /* __RTL8019_H__ */

160
cpu/avr/dev/rtl8019as-drv.c Normal file
View file

@ -0,0 +1,160 @@
/*
* Copyright (c) 2003, Adam Dunkels.
* 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. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Adam Dunkels.
* 4. 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 uIP TCP/IP stack.
*
* $Id: rtl8019as-drv.c,v 1.1 2006/06/17 22:41:21 adamdunkels Exp $
*
*/
/* uip_main.c: initialization code and main event loop. */
#define NULL (void *)0
#include "uip.h"
#include "uip_arp.h"
#include "uip-signal.h"
#include "loader.h"
#include "rtl8019dev.h"
#include "dispatcher.h"
#include "ek.h"
#include "debug.h"
#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
static u8_t i, arptimer;
static u16_t start, current;
static void rtl8019_drv_idle(void);
static DISPATCHER_SIGHANDLER(rtl8019_drv_sighandler, s, data);
static struct dispatcher_proc p =
{DISPATCHER_PROC("TCP/IP/RTL8019 driver", rtl8019_drv_idle,
rtl8019_drv_sighandler, NULL)};
ek_id_t id = EK_ID_NONE;
/*-----------------------------------------------------------------------------------*/
static void
timer(void)
{
for(i = 0; i < UIP_CONNS; ++i) {
uip_periodic(i);
if(uip_len > 0) {
uip_arp_out();
rtl8019as_send();
}
}
for(i = 0; i < UIP_UDP_CONNS; i++) {
uip_udp_periodic(i);
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0. */
if(uip_len > 0) {
uip_arp_out();
rtl8019as_send();
}
}
}
/*-----------------------------------------------------------------------------------*/
static void
rtl8019_drv_idle(void)
{
/* Poll Ethernet device to see if there is a frame avaliable. */
uip_len = rtl8019as_poll();
if(uip_len > 0) {
/* A frame was avaliable (and is now read into the uip_buf), so
we process it. */
if(BUF->type == htons(UIP_ETHTYPE_IP)) {
/* debug_print16(uip_len);*/
uip_arp_ipin();
uip_len -= sizeof(struct uip_eth_hdr);
uip_input();
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0. */
if(uip_len > 0) {
/* debug_print(PSTR("Sending packet\n"));*/
uip_arp_out();
rtl8019as_send();
}
} else if(BUF->type == htons(UIP_ETHTYPE_ARP)) {
uip_arp_arpin();
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0. */
if(uip_len > 0) {
rtl8019as_send();
}
}
}
/* Check the clock so see if we should call the periodic uIP
processing. */
current = ek_clock();
if((current - start) >= CLK_TCK/2 ||
(current - start) < 0) {
timer();
start = current;
}
}
/*-----------------------------------------------------------------------------------*/
LOADER_INIT_FUNC(rtl8019_drv_init)
{
if(id == EK_ID_NONE) {
id = dispatcher_start(&p);
arptimer = 0;
start = ek_clock();
rtl8019as_init();
dispatcher_listen(uip_signal_uninstall);
}
}
/*-----------------------------------------------------------------------------------*/
static
DISPATCHER_SIGHANDLER(rtl8019_drv_sighandler, s, data)
{
DISPATCHER_SIGHANDLER_ARGS(s, data);
if(s == uip_signal_uninstall) {
dispatcher_exit(&p);
id = EK_ID_NONE;
LOADER_UNLOAD();
}
}
/*-----------------------------------------------------------------------------------*/

77
cpu/avr/dev/rtl8019dev.c Normal file
View file

@ -0,0 +1,77 @@
#include "net/uip.h"
#include "dev/rtl8019dev.h"
/*****************************************************************************
* Module Name: Realtek 8019AS Driver Interface for uIP-AVR Port
*
* Created By: Louis Beaudoin (www.embedded-creations.com)
*
* Original Release: September 21, 2002
*
* Module Description:
* Provides three functions to interface with the Realtek 8019AS driver
* These functions can be called directly from the main uIP control loop
* to send packets from uip_buf and uip_appbuf, and store incoming packets to
* uip_buf
*
* September 30, 2002 - Louis Beaudoin
* Modifications required to handle the packet receive function changes in
* rtl8019.c. There is no longer a need to poll for an empty buffer or
* an overflow.
* Added support for the Imagecraft Compiler
*
*****************************************************************************/
#define IP_TCP_HEADER_LENGTH 40
#define TOTAL_HEADER_LENGTH (IP_TCP_HEADER_LENGTH+ETHERNET_HEADER_LENGTH)
void RTL8019dev_init(void)
{
initRTL8019();
}
void RTL8019dev_send(void)
{
RTL8019beginPacketSend(uip_len);
// send packet, using data in uip_appdata if over the IP+TCP header size
if( uip_len <= TOTAL_HEADER_LENGTH ) {
RTL8019sendPacketData(uip_buf, uip_len);
} else {
uip_len -= TOTAL_HEADER_LENGTH;
RTL8019sendPacketData(uip_buf, TOTAL_HEADER_LENGTH);
RTL8019sendPacketData((unsigned char *)uip_appdata, uip_len);
}
RTL8019endPacketSend();
}
unsigned int RTL8019dev_poll(void)
{
unsigned int packetLength;
packetLength = RTL8019beginPacketRetreive();
// if there's no packet or an error - exit without ending the operation
if( !packetLength )
return 0;
// drop anything too big for the buffer
if( packetLength > UIP_BUFSIZE )
{
RTL8019endPacketRetreive();
return 0;
}
// copy the packet data into the uIP packet buffer
RTL8019retreivePacketData( uip_buf, packetLength );
RTL8019endPacketRetreive();
return packetLength;
}

60
cpu/avr/dev/rtl8019dev.h Normal file
View file

@ -0,0 +1,60 @@
#ifndef __RTL8019DEV_H__
#define __RTL8019DEV_H__
/*****************************************************************************
* Module Name: Realtek 8019AS Driver Interface for uIP-AVR Port
*
* Created By: Louis Beaudoin (www.embedded-creations.com)
*
* Original Release: September 21, 2002
*
* Module Description:
* Provides three functions to interface with the Realtek 8019AS driver
* These functions can be called directly from the main uIP control loop
* to send packets from uip_buf and uip_appbuf, and store incoming packets to
* uip_buf
*
* September 30, 2002 - Louis Beaudoin
* Modifications required to handle the packet receive function changes in
* rtl8019.c. There is no longer a need to poll for an empty buffer or
* an overflow.
* Added support for the Imagecraft Compiler
*
*****************************************************************************/
#include "net/uip.h"
#include "dev/rtl8019.h"
/*****************************************************************************
* RTL8019dev_init()
* Created By: Louis Beaudoin
* Date: September 21, 2002
* Description: Power-up initialization of the RTL8019
*****************************************************************************/
void RTL8019dev_init(void);
/*****************************************************************************
* RTL8019dev_send()
* Created By: Louis Beaudoin
* Date: September 21, 2002
* Description: Sends the packet contained in uip_buf and uip_appdata over
* the network
*****************************************************************************/
void RTL8019dev_send(void);
/*****************************************************************************
* unsigned char/int RTL8019dev_poll()
* Returns: Length of the packet retreived, or zero if no packet retreived
* Created By: Louis Beaudoin
* Date: September 21, 2002
* Description: Polls the RTL8019 looking for an overflow condition or a new
* packet in the receive buffer. If a new packet exists and
* will fit in uip_buf, it is retreived, and the length is
* returned. A packet bigger than the buffer is discarded
*****************************************************************************/
unsigned int RTL8019dev_poll(void);
#endif /* __RTL8019DEV_H__ */

354
cpu/avr/dev/rtlregs.h Normal file
View file

@ -0,0 +1,354 @@
#ifndef _DEV_RTLREGS_H_
#define _DEV_RTLREGS_H_
/*
* Copyright (C) 2001-2002 by egnite Software GmbH. 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. All advertising materials mentioning features or use of this
* software must display the following acknowledgement:
*
* This product includes software developed by egnite Software GmbH
* and its contributors.
*
* THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH 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 EGNITE
* SOFTWARE GMBH 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.
*
* For additional information see http://www.ethernut.de/
*
* -
* Portions Copyright (C) 2000 David J. Hudson <dave@humbug.demon.co.uk>
*
* This file 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.
*
* You can redistribute this file and/or modify it under the terms of the GNU
* General Public License (GPL) as published by the Free Software Foundation;
* either version 2 of the License, or (at your discretion) any later version.
* See the accompanying file "copying-gpl.txt" for more details.
*
* As a special exception to the GPL, permission is granted for additional
* uses of the text contained in this file. See the accompanying file
* "copying-liquorice.txt" for details.
* -
* Portions Copyright (c) 1983, 1993 by
* The Regents of the University of California. 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. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
*/
/*
* $Log: rtlregs.h,v $
* Revision 1.1 2006/06/17 22:41:21 adamdunkels
* Import of the contiki-2.x development code from the SICS internal CVS server
*
* Revision 1.1 2005/09/19 23:05:35 adam
* AVR device drivers
*
* Revision 1.1 2005/05/18 19:03:23 adam
* Initial import of Contiki AVR port
*
* Revision 1.1 2003/07/04 10:54:52 adamdunkels
* First version of the AVR port
*
* Revision 1.1 2003/02/05 20:49:07 adam
* *** empty log message ***
*
* Revision 1.6 2002/10/29 15:27:36 harald
* *** empty log message ***
*
* Revision 1.5 2002/06/26 17:29:08 harald
* First pre-release with 2.4 stack
*
*/
/*!
* \brief Realtek 8019AS register definitions.
*/
/*@{*/
/*
* Register offset applicable to all register pages.
*/
#define NIC_CR 0x00 /*!< \brief Command register */
#define NIC_IOPORT 0x10 /*!< \brief I/O data port */
#define NIC_RESET 0x1f /*!< \brief Reset port */
/*
* Page 0 register offsets.
*/
#define NIC_PG0_CLDA0 0x01 /*!< \brief Current local DMA address 0 */
#define NIC_PG0_PSTART 0x01 /*!< \brief Page start register */
#define NIC_PG0_CLDA1 0x02 /*!< \brief Current local DMA address 1 */
#define NIC_PG0_PSTOP 0x02 /*!< \brief Page stop register */
#define NIC_PG0_BNRY 0x03 /*!< \brief Boundary pointer */
#define NIC_PG0_TSR 0x04 /*!< \brief Transmit status register */
#define NIC_PG0_TPSR 0x04 /*!< \brief Transmit page start address */
#define NIC_PG0_NCR 0x05 /*!< \brief Number of collisions register */
#define NIC_PG0_TBCR0 0x05 /*!< \brief Transmit byte count register 0 */
#define NIC_PG0_FIFO 0x06 /*!< \brief FIFO */
#define NIC_PG0_TBCR1 0x06 /*!< \brief Transmit byte count register 1 */
#define NIC_PG0_ISR 0x07 /*!< \brief Interrupt status register */
#define NIC_PG0_CRDA0 0x08 /*!< \brief Current remote DMA address 0 */
#define NIC_PG0_RSAR0 0x08 /*!< \brief Remote start address register 0
Low byte address to read from the buffer. */
#define NIC_PG0_CRDA1 0x09 /*!< \brief Current remote DMA address 1 */
#define NIC_PG0_RSAR1 0x09 /*!< \brief Remote start address register 1
High byte address to read from the buffer. */
#define NIC_PG0_RBCR0 0x0a /*!< \brief Remote byte count register 0
Low byte of the number of bytes to read
from the buffer. */
#define NIC_PG0_RBCR1 0x0b /*!< \brief Remote byte count register 1
High byte of the number of bytes to read
from the buffer. */
#define NIC_PG0_RSR 0x0c /*!< \brief Receive status register */
#define NIC_PG0_RCR 0x0c /*!< \brief Receive configuration register */
#define NIC_PG0_CNTR0 0x0d /*!< \brief Tally counter 0 (frame alignment errors) */
#define NIC_PG0_TCR 0x0d /*!< \brief Transmit configuration register */
#define NIC_PG0_CNTR1 0x0e /*!< \brief Tally counter 1 (CRC errors) */
#define NIC_PG0_DCR 0x0e /*!< \brief Data configuration register */
#define NIC_PG0_CNTR2 0x0f /*!< \brief Tally counter 2 (Missed packet errors) */
#define NIC_PG0_IMR 0x0f /*!< \brief Interrupt mask register */
/*
* Page 1 register offsets.
*/
#define NIC_PG1_PAR0 0x01 /*!< \brief Physical address register 0 */
#define NIC_PG1_PAR1 0x02 /*!< \brief Physical address register 1 */
#define NIC_PG1_PAR2 0x03 /*!< \brief Physical address register 2 */
#define NIC_PG1_PAR3 0x04 /*!< \brief Physical address register 3 */
#define NIC_PG1_PAR4 0x05 /*!< \brief Physical address register 4 */
#define NIC_PG1_PAR5 0x06 /*!< \brief Physical address register 5 */
#define NIC_PG1_CURR 0x07 /*!< \brief Current page register
The next incoming packet will be stored
at this page address. */
#define NIC_PG1_MAR0 0x08 /*!< \brief Multicast address register 0 */
#define NIC_PG1_MAR1 0x09 /*!< \brief Multicast address register 1 */
#define NIC_PG1_MAR2 0x0a /*!< \brief Multicast address register 2 */
#define NIC_PG1_MAR3 0x0b /*!< \brief Multicast address register 3 */
#define NIC_PG1_MAR4 0x0c /*!< \brief Multicast address register 4 */
#define NIC_PG1_MAR5 0x0d /*!< \brief Multicast address register 5 */
#define NIC_PG1_MAR6 0x0e /*!< \brief Multicast address register 6 */
#define NIC_PG1_MAR7 0x0f /*!< \brief Multicast address register 7 */
/*
* Page 2 register offsets.
*/
#define NIC_PG2_PSTART 0x01 /*!< \brief Page start register */
#define NIC_PG2_CLDA0 0x01 /*!< \brief Current local DMA address 0 */
#define NIC_PG2_PSTOP 0x02 /*!< \brief Page stop register */
#define NIC_PG2_CLDA1 0x02 /*!< \brief Current local DMA address 1 */
#define NIC_PG2_RNP 0x03 /*!< \brief Remote next packet pointer */
#define NIC_PG2_TSPR 0x04 /*!< \brief Transmit page start register */
#define NIC_PG2_LNP 0x05 /*!< \brief Local next packet pointer */
#define NIC_PG2_ACU 0x06 /*!< \brief Address counter (upper) */
#define NIC_PG2_ACL 0x07 /*!< \brief Address counter (lower) */
#define NIC_PG2_RCR 0x0c /*!< \brief Receive configuration register */
#define NIC_PG2_TCR 0x0d /*!< \brief Transmit configuration register */
#define NIC_PG2_DCR 0x0e /*!< \brief Data configuration register */
#define NIC_PG2_IMR 0x0f /*!< \brief Interrupt mask register */
/*
* Page 3 register offsets.
*/
#define NIC_PG3_EECR 0x01 /*!< \brief EEPROM command register */
#define NIC_PG3_BPAGE 0x02 /*!< \brief Boot-ROM page register */
#define NIC_PG3_CONFIG0 0x03 /*!< \brief Configuration register 0 (r/o) */
#define NIC_PG3_CONFIG1 0x04 /*!< \brief Configuration register 1 */
#define NIC_PG3_CONFIG2 0x05 /*!< \brief Configuration register 2 */
#define NIC_PG3_CONFIG3 0x06 /*!< \brief Configuration register 3 */
#define NIC_PG3_CSNSAV 0x08 /*!< \brief CSN save register (r/o) */
#define NIC_PG3_HLTCLK 0x09 /*!< \brief Halt clock */
#define NIC_PG3_INTR 0x0b /*!< \brief Interrupt pins (r/o) */
/*
* Command register bits.
*/
#define NIC_CR_STP 0x01 /*!< \brief Stop */
#define NIC_CR_STA 0x02 /*!< \brief Start */
#define NIC_CR_TXP 0x04 /*!< \brief Transmit packet */
#define NIC_CR_RD0 0x08 /*!< \brief Remote DMA command bit 0 */
#define NIC_CR_RD1 0x10 /*!< \brief Remote DMA command bit 1 */
#define NIC_CR_RD2 0x20 /*!< \brief Remote DMA command bit 2 */
#define NIC_CR_PS0 0x40 /*!< \brief Page select bit 0 */
#define NIC_CR_PS1 0x80 /*!< \brief Page select bit 1 */
/*
* Interrupt status register bits.
*/
#define NIC_ISR_PRX 0x01 /*!< \brief Packet received */
#define NIC_ISR_PTX 0x02 /*!< \brief Packet transmitted */
#define NIC_ISR_RXE 0x04 /*!< \brief Receive error */
#define NIC_ISR_TXE 0x08 /*!< \brief Transmit error */
#define NIC_ISR_OVW 0x10 /*!< \brief Overwrite warning */
#define NIC_ISR_CNT 0x20 /*!< \brief Counter overflow */
#define NIC_ISR_RDC 0x40 /*!< \brief Remote DMA complete */
#define NIC_ISR_RST 0x80 /*!< \brief Reset status */
/*
* Interrupt mask register bits.
*/
#define NIC_IMR_PRXE 0x01 /*!< \brief Packet received interrupt enable */
#define NIC_IMR_PTXE 0x02 /*!< \brief Packet transmitted interrupt enable */
#define NIC_IMR_RXEE 0x04 /*!< \brief Receive error interrupt enable */
#define NIC_IMR_TXEE 0x08 /*!< \brief Transmit error interrupt enable */
#define NIC_IMR_OVWE 0x10 /*!< \brief Overwrite warning interrupt enable */
#define NIC_IMR_CNTE 0x20 /*!< \brief Counter overflow interrupt enable */
#define NIC_IMR_RCDE 0x40 /*!< \brief Remote DMA complete interrupt enable */
/*
* Data configuration register bits.
*/
#define NIC_DCR_WTS 0x01 /*!< \brief Word transfer select */
#define NIC_DCR_BOS 0x02 /*!< \brief Byte order select */
#define NIC_DCR_LAS 0x04 /*!< \brief Long address select */
#define NIC_DCR_LS 0x08 /*!< \brief Loopback select */
#define NIC_DCR_AR 0x10 /*!< \brief Auto-initialize remote */
#define NIC_DCR_FT0 0x20 /*!< \brief FIFO threshold select bit 0 */
#define NIC_DCR_FT1 0x40 /*!< \brief FIFO threshold select bit 1 */
/*
* Transmit configuration register bits.
*/
#define NIC_TCR_CRC 0x01 /*!< \brief Inhibit CRC */
#define NIC_TCR_LB0 0x02 /*!< \brief Encoded loopback control bit 0 */
#define NIC_TCR_LB1 0x04 /*!< \brief Encoded loopback control bit 1 */
#define NIC_TCR_ATD 0x08 /*!< \brief Auto transmit disable */
#define NIC_TCR_OFST 0x10 /*!< \brief Collision offset enable */
/*
* Transmit status register bits.
*/
#define NIC_TSR_PTX 0x01 /*!< \brief Packet transmitted */
#define NIC_TSR_COL 0x04 /*!< \brief Transmit collided */
#define NIC_TSR_ABT 0x08 /*!< \brief Transmit aborted */
#define NIC_TSR_CRS 0x10 /*!< \brief Carrier sense lost */
#define NIC_TSR_FU 0x20 /*!< \brief FIFO underrun */
#define NIC_TSR_CDH 0x40 /*!< \brief CD heartbeat */
#define NIC_TSR_OWC 0x80 /*!< \brief Out of window collision */
/*
* Receive configuration register bits.
*/
#define NIC_RCR_SEP 0x01 /*!< \brief Save errored packets */
#define NIC_RCR_AR 0x02 /*!< \brief Accept runt packets */
#define NIC_RCR_AB 0x04 /*!< \brief Accept broadcast */
#define NIC_RCR_AM 0x08 /*!< \brief Accept multicast */
#define NIC_RCR_PRO 0x10 /*!< \brief Promiscuous physical */
#define NIC_RCR_MON 0x20 /*!< \brief Monitor mode */
/*
* Receive status register bits.
*/
#define NIC_RSR_PRX 0x01 /*!< \brief Packet received intact */
#define NIC_RSR_CRC 0x02 /*!< \brief CRC error */
#define NIC_RSR_FAE 0x04 /*!< \brief Frame alignment error */
#define NIC_RSR_FO 0x08 /*!< \brief FIFO overrun */
#define NIC_RSR_MPA 0x10 /*!< \brief Missed packet */
#define NIC_RSR_PHY 0x20 /*!< \brief Physical/multicast address */
#define NIC_RSR_DIS 0x40 /*!< \brief Receiver disabled */
#define NIC_RSR_DFR 0x80 /*!< \brief Deferring */
/*
* EEPROM command register bits.
*/
#define NIC_EECR_EEM1 0x80 /*!< \brief EEPROM Operating Mode */
#define NIC_EECR_EEM0 0x40 /*!< \brief EEPROM Operating Mode
- 0 0 Normal operation
- 0 1 Auto-load
- 1 0 9346 programming
- 1 1 Config register write enab */
#define NIC_EECR_EECS 0x08 /*!< \brief EEPROM Chip Select */
#define NIC_EECR_EESK 0x04 /*!< \brief EEPROM Clock */
#define NIC_EECR_EEDI 0x02 /*!< \brief EEPROM Data In */
#define NIC_EECR_EEDO 0x01 /*!< \brief EEPROM Data Out */
/*
* Configuration register 2 bits.
*/
#define NIC_CONFIG2_PL1 0x80 /*!< \brief Network media type */
#define NIC_CONFIG2_PL0 0x40 /*!< \brief Network media type
- 0 0 TP/CX auto-detect
- 0 1 10baseT
- 1 0 10base5
- 1 1 10base2 */
#define NIC_CONFIG2_BSELB 0x20 /*!< \brief BROM disable */
#define NIC_CONFIG2_BS4 0x10 /*!< \brief BROM size/base */
#define NIC_CONFIG2_BS3 0x08
#define NIC_CONFIG2_BS2 0x04
#define NIC_CONFIG2_BS1 0x02
#define NIC_CONFIG2_BS0 0x01
/*
* Configuration register 3 bits
*/
#define NIC_CONFIG3_PNP 0x80 /*!< \brief PnP Mode */
#define NIC_CONFIG3_FUDUP 0x40 /*!< \brief Full duplex */
#define NIC_CONFIG3_LEDS1 0x20 /*!< \brief LED1/2 pin configuration
- 0 LED1 == LED_RX, LED2 == LED_TX
- 1 LED1 == LED_CRS, LED2 == MCSB */
#define NIC_CONFIG3_LEDS0 0x10 /*!< \brief LED0 pin configration
- 0 LED0 pin == LED_COL
- 1 LED0 pin == LED_LINK */
#define NIC_CONFIG3_SLEEP 0x04 /*!< \brief Sleep mode */
#define NIC_CONFIG3_PWRDN 0x02 /*!< \brief Power Down */
#define NIC_CONFIG3_ACTIVEB 0x01 /*!< \brief inverse of bit 0 in PnP Act Reg */
/*@}*/
/*!
* \brief Read byte from controller register.
*/
#define nic_read(reg) *(base + (reg))
/*!
* \brief Write byte to controller register.
*/
#define nic_write(reg, data) *(base + (reg)) = data
#endif