Nut/OS  5.0.5
API Reference
nicrtl.c File Reference
#include <cfg/os.h>
#include <cfg/arch/avr.h>
#include <cfg/dev.h>
#include <string.h>
#include <sys/atom.h>
#include <sys/heap.h>
#include <sys/thread.h>
#include <sys/event.h>
#include <sys/timer.h>
#include <sys/confnet.h>
#include <net/ether.h>
#include <net/if_var.h>
#include <dev/irqreg.h>
#include <dev/nicrtl.h>
#include "rtlregs.h"
#include <sys/osdebug.h>
#include <net/netdebug.h>
Include dependency graph for nicrtl.c:

Data Structures

struct  nic_pkt_header

Defines

#define NUT_THREAD_NICRXSTACK   640
#define RTL_EE_MEMBUS
#define RTL_EESK_PIN   PINC
#define RTL_EESK_DDR   DDRC
#define RTL_EE_MEMBUS
#define RTL_EEDO_PORT   PORTC
#define RTL_EEDO_DDR   DDRC
#define RTL_EE_MEMBUS
#define RTL_EEMU_PORT   PORTC
#define RTL_EEMU_DDR   DDRC
#define RTL_SIGNAL   sig_INTERRUPT0
 Interrupt used.
#define RTL_RISING_EDGE_MODE()   sbi(EICRA, ISC00); sbi(EICRA, ISC01)
#define NIC_PAGE_SIZE   0x100
 Size of a single ring buffer page.
#define NIC_START_PAGE   0x40
 First ring buffer page address.
#define NIC_STOP_PAGE   0x60
 Last ring buffer page address plus 1.
#define NIC_TX_PAGES   6
 Number of pages in a single transmit buffer.
#define NIC_TX_BUFFERS   1
 Number of transmit buffers.
#define NIC_FIRST_TX_PAGE   NIC_START_PAGE
#define NIC_FIRST_RX_PAGE   (NIC_FIRST_TX_PAGE + NIC_TX_PAGES * NIC_TX_BUFFERS)
#define NIC_CR_PAGE0   (0)
#define NIC_CR_PAGE1   (NIC_CR_PS0)
#define NIC_CR_PAGE2   (NIC_CR_PS1)
#define NIC_CR_PAGE3   (NIC_CR_PS1 | NIC_CR_PS0)
#define NICINB(reg)   (*((volatile uint8_t *)RTL_BASE_ADDR + reg))
#define NICOUTB(reg, val)   (*((volatile uint8_t *)RTL_BASE_ADDR + reg) = val)

Functions

void NicRx (void *arg)
 NIC receiver thread.
int NicOutput (NUTDEVICE *dev, NETBUF *nb)
 Send Ethernet packet.
int NicInit (NUTDEVICE *dev)
 Initialize Ethernet hardware.

Define Documentation

#define NUT_THREAD_NICRXSTACK   640

Referenced by NicInit().

#define RTL_EE_MEMBUS
#define RTL_EESK_PIN   PINC
#define RTL_EESK_DDR   DDRC
#define RTL_EE_MEMBUS
#define RTL_EEDO_PORT   PORTC
#define RTL_EEDO_DDR   DDRC
#define RTL_EE_MEMBUS
#define RTL_EEMU_PORT   PORTC
#define RTL_EEMU_DDR   DDRC
#define RTL_SIGNAL   sig_INTERRUPT0

Interrupt used.

Referenced by NicInit().

#define RTL_RISING_EDGE_MODE ( )    sbi(EICRA, ISC00); sbi(EICRA, ISC01)

Referenced by NicInit().

#define NIC_PAGE_SIZE   0x100

Size of a single ring buffer page.

#define NIC_START_PAGE   0x40

First ring buffer page address.

#define NIC_STOP_PAGE   0x60

Last ring buffer page address plus 1.

#define NIC_TX_PAGES   6

Number of pages in a single transmit buffer.

This should be at least the MTU size.

#define NIC_TX_BUFFERS   1

Number of transmit buffers.

The initial value had been 2. The idea was to use two alternating buffers. However, this had never been implemented and we took over Bengt Florin's change, defining 1 transmit buffer only and give more buffer space to the receiver.

The controller memory layout is now

  • 0x4000..0x45ff 1.5K bytes transmit buffer
  • 0x4600..0x5fff 6.5K bytes receive buffer

The routines are still not using the buffers in an optimal way, as transmission is limited to 1 packet at a time. In fact several smaller packets would fit into the 1.5 kByte buffer. On the other hand, filling the buffer with more than one transmission packet may result in other bad effects, like pulling the IORDY line more often.

#define NIC_FIRST_TX_PAGE   NIC_START_PAGE
#define NIC_FIRST_RX_PAGE   (NIC_FIRST_TX_PAGE + NIC_TX_PAGES * NIC_TX_BUFFERS)
#define NIC_CR_PAGE0   (0)
#define NIC_CR_PAGE1   (NIC_CR_PS0)
#define NIC_CR_PAGE2   (NIC_CR_PS1)
#define NIC_CR_PAGE3   (NIC_CR_PS1 | NIC_CR_PS0)