added dbug's fec and network routines

This commit is contained in:
Markus Fröschle
2013-12-20 15:01:54 +00:00
parent 87e594a928
commit aea881f0b0
23 changed files with 3219 additions and 438 deletions

View File

@@ -7,6 +7,8 @@
#ifndef _MCD_API_H
#define _MCD_API_H
#include "bas_types.h"
/*
* Turn Execution Unit tasks ON (#define) or OFF (#undef)
*/
@@ -47,39 +49,33 @@
/*
* Portability typedefs
*/
typedef int s32;
typedef unsigned int u32;
typedef short s16;
typedef unsigned short u16;
typedef char s8;
typedef unsigned char u8;
/*
* These structures represent the internal registers of the
* multi-channel DMA
*/
struct dmaRegs_s {
u32 taskbar; /* task table base address register */
u32 currPtr;
u32 endPtr;
u32 varTablePtr;
u16 dma_rsvd0;
u16 ptdControl; /* ptd control */
u32 intPending; /* interrupt pending register */
u32 intMask; /* interrupt mask register */
u16 taskControl[16]; /* task control registers */
u8 priority[32]; /* priority registers */
u32 initiatorMux; /* initiator mux control */
u32 taskSize0; /* task size control register 0. */
u32 taskSize1; /* task size control register 1. */
u32 dma_rsvd1; /* reserved */
u32 dma_rsvd2; /* reserved */
u32 debugComp1; /* debug comparator 1 */
u32 debugComp2; /* debug comparator 2 */
u32 debugControl; /* debug control */
u32 debugStatus; /* debug status */
u32 ptdDebug; /* priority task decode debug */
u32 dma_rsvd3[31]; /* reserved */
uint32_t taskbar; /* task table base address register */
uint32_t currPtr;
uint32_t endPtr;
uint32_t varTablePtr;
uint16_t dma_rsvd0;
uint16_t ptdControl; /* ptd control */
uint32_t intPending; /* interrupt pending register */
uint32_t intMask; /* interrupt mask register */
uint16_t taskControl[16]; /* task control registers */
uint8_t priority[32]; /* priority registers */
uint32_t initiatorMux; /* initiator mux control */
uint32_t taskSize0; /* task size control register 0. */
uint32_t taskSize1; /* task size control register 1. */
uint32_t dma_rsvd1; /* reserved */
uint32_t dma_rsvd2; /* reserved */
uint32_t debugComp1; /* debug comparator 1 */
uint32_t debugComp2; /* debug comparator 2 */
uint32_t debugControl; /* debug control */
uint32_t debugStatus; /* debug status */
uint32_t ptdDebug; /* priority task decode debug */
uint32_t dma_rsvd3[31]; /* reserved */
};
typedef volatile struct dmaRegs_s dmaRegs;
@@ -165,7 +161,7 @@ typedef volatile struct dmaRegs_s dmaRegs;
*/
/* Byte swapping: */
#define MCD_NO_BYTE_SWAP 0x00045670 /* to disable byte swapping. */
#define MCD_BYTE_REVERSE 0x00076540 /* to reverse the bytes of each u32 of the DMAed data. */
#define MCD_BYTE_REVERSE 0x00076540 /* to reverse the bytes of each uint32_t of the DMAed data. */
#define MCD_U16_REVERSE 0x00067450 /* to reverse the 16-bit halves of
each 32-bit data value being DMAed.*/
#define MCD_U16_BYTE_REVERSE 0x00054760 /* to reverse the byte halves of each
@@ -232,44 +228,44 @@ typedef volatile struct dmaRegs_s dmaRegs;
/* Task Table Entry struct*/
typedef struct {
u32 TDTstart; /* task descriptor table start */
u32 TDTend; /* task descriptor table end */
u32 varTab; /* variable table start */
u32 FDTandFlags; /* function descriptor table start and flags */
volatile u32 descAddrAndStatus;
volatile u32 modifiedVarTab;
u32 contextSaveSpace; /* context save space start */
u32 literalBases;
uint32_t TDTstart; /* task descriptor table start */
uint32_t TDTend; /* task descriptor table end */
uint32_t varTab; /* variable table start */
uint32_t FDTandFlags; /* function descriptor table start and flags */
volatile uint32_t descAddrAndStatus;
volatile uint32_t modifiedVarTab;
uint32_t contextSaveSpace; /* context save space start */
uint32_t literalBases;
} TaskTableEntry;
/* Chained buffer descriptor */
typedef volatile struct MCD_bufDesc_struct MCD_bufDesc;
struct MCD_bufDesc_struct {
u32 flags; /* flags describing the DMA */
u32 csumResult; /* checksum from checksumming performed since last checksum reset */
s8 *srcAddr; /* the address to move data from */
s8 *destAddr; /* the address to move data to */
s8 *lastDestAddr; /* the last address written to */
u32 dmaSize; /* the number of bytes to transfer independent of the transfer size */
uint32_t flags; /* flags describing the DMA */
uint32_t csumResult; /* checksum from checksumming performed since last checksum reset */
int8_t *srcAddr; /* the address to move data from */
int8_t *destAddr; /* the address to move data to */
int8_t *lastDestAddr; /* the last address written to */
uint32_t dmaSize; /* the number of bytes to transfer independent of the transfer size */
MCD_bufDesc *next; /* next buffer descriptor in chain */
u32 info; /* private information about this descriptor; DMA does not affect it */
uint32_t info; /* private information about this descriptor; DMA does not affect it */
};
/* Progress Query struct */
typedef volatile struct MCD_XferProg_struct {
s8 *lastSrcAddr; /* the most-recent or last, post-increment source address */
s8 *lastDestAddr; /* the most-recent or last, post-increment destination address */
u32 dmaSize; /* the amount of data transferred for the current buffer */
int8_t *lastSrcAddr; /* the most-recent or last, post-increment source address */
int8_t *lastDestAddr; /* the most-recent or last, post-increment destination address */
uint32_t dmaSize; /* the amount of data transferred for the current buffer */
MCD_bufDesc *currBufDesc;/* pointer to the current buffer descriptor being DMAed */
} MCD_XferProg;
/* FEC buffer descriptor */
typedef volatile struct MCD_bufDescFec_struct {
u16 statCtrl;
u16 length;
u32 dataPointer;
uint16_t statCtrl;
uint16_t length;
uint32_t dataPointer;
} MCD_bufDescFec;
@@ -283,16 +279,16 @@ typedef volatile struct MCD_bufDescFec_struct {
*/
int MCD_startDma (
int channel, /* the channel on which to run the DMA */
s8 *srcAddr, /* the address to move data from, or buffer-descriptor address */
s16 srcIncr, /* the amount to increment the source address per transfer */
s8 *destAddr, /* the address to move data to */
s16 destIncr, /* the amount to increment the destination address per transfer */
u32 dmaSize, /* the number of bytes to transfer independent of the transfer size */
u32 xferSize, /* the number bytes in of each data movement (1, 2, or 4) */
u32 initiator, /* what device initiates the DMA */
int8_t *srcAddr, /* the address to move data from, or buffer-descriptor address */
int16_t srcIncr, /* the amount to increment the source address per transfer */
int8_t *destAddr, /* the address to move data to */
int16_t destIncr, /* the amount to increment the destination address per transfer */
uint32_t dmaSize, /* the number of bytes to transfer independent of the transfer size */
uint32_t xferSize, /* the number bytes in of each data movement (1, 2, or 4) */
uint32_t initiator, /* what device initiates the DMA */
int priority, /* priority of the DMA */
u32 flags, /* flags describing the DMA */
u32 funcDesc /* a description of byte swapping, bit swapping, and CRC actions */
uint32_t flags, /* flags describing the DMA */
uint32_t funcDesc /* a description of byte swapping, bit swapping, and CRC actions */
);
/*
@@ -300,7 +296,7 @@ int MCD_startDma (
* registers, relocating and creating the appropriate task structures, and
* setting up some global settings
*/
int MCD_initDma (dmaRegs *sDmaBarAddr, void *taskTableDest, u32 flags);
int MCD_initDma (dmaRegs *sDmaBarAddr, void *taskTableDest, uint32_t flags);
/*
* MCD_dmaStatus() returns the status of the DMA on the requested channel.
@@ -339,7 +335,7 @@ int MCD_resumeDma (int channel);
/*
* MCD_csumQuery provides the checksum/CRC after performing a non-chained DMA
*/
int MCD_csumQuery (int channel, u32 *csum);
int MCD_csumQuery (int channel, uint32_t *csum);
/*
* MCD_getCodeSize provides the packed size required by the microcoded task
@@ -354,7 +350,7 @@ int MCD_getCodeSize(void);
int MCD_getVersion(char **longVersion);
/* macro for setting a location in the variable table */
#define MCD_SET_VAR(taskTab,idx,value) ((u32 *)(taskTab)->varTab)[idx] = value
#define MCD_SET_VAR(taskTab,idx,value) ((uint32_t *)(taskTab)->varTab)[idx] = value
/* Note that MCD_SET_VAR() is invoked many times in firing up a DMA function,
so I'm avoiding surrounding it with "do {} while(0)" */

99
BaS_gcc/include/arp.h Normal file
View File

@@ -0,0 +1,99 @@
/*
* File: arp.h
* Purpose: ARP definitions.
*
* Notes:
*/
#ifndef _ARP_H
#define _ARP_H
/********************************************************************/
/*
* This data definition is defined for Ethernet only!
*/
typedef struct
{
uint16_t ar_hrd;
uint16_t ar_pro;
uint8_t ar_hln;
uint8_t ar_pln;
uint16_t opcode;
uint8_t ar_sha[6]; /* ethernet hw address */
uint8_t ar_spa[4]; /* ip address */
uint8_t ar_tha[6]; /* ethernet hw address */
uint8_t ar_tpa[4]; /* ip address */
} arp_frame_hdr;
#define ARP_HDR_LEN sizeof(arp_frame_hdr)
/*
* ARP table entry definition. Note that this table only designed
* with Ethernet and IP in mind.
*/
#define MAX_HWA_SIZE (6) /* 6 is enough for Ethernet address */
#define MAX_PA_SIZE (4) /* 4 is enough for Protocol address */
typedef struct
{
uint16_t protocol;
uint8_t hwa_size;
uint8_t hwa[MAX_HWA_SIZE];
uint8_t pa_size;
uint8_t pa[MAX_PA_SIZE];
int longevity;
} ARPENTRY;
#define MAX_ARP_ENTRY (10)
typedef struct
{
unsigned int tab_size;
ARPENTRY table[MAX_ARP_ENTRY];
} ARP_INFO;
#define ARP_ENTRY_EMPTY (0)
#define ARP_ENTRY_PERM (1)
#define ARP_ENTRY_TEMP (2)
#define ETHERNET (1)
#define ARP_REQUEST (1)
#define ARP_REPLY (2)
#define ARP_TIMEOUT (1) /* Timeout in seconds */
/* Protocol Header information */
#define ARP_HDR_OFFSET ETH_HDR_LEN
/********************************************************************/
uint8_t *
arp_get_mypa (void);
uint8_t *
arp_get_myha (void);
uint8_t *
arp_get_broadcast (void);
void
arp_merge (ARP_INFO *, uint16_t, int, uint8_t *, int, uint8_t *, int);
void
arp_remove (ARP_INFO *, uint16_t, uint8_t *, uint8_t *);
void
arp_request (NIF *, uint8_t *);
void
arp_handler (NIF *, NBUF *);
uint8_t *
arp_resolve (NIF *, uint16_t, uint8_t *);
void
arp_init (ARP_INFO *);
/********************************************************************/
#endif /* _ARP_H */

View File

@@ -28,10 +28,7 @@
#ifndef BAS_TYPES_H_
#define BAS_TYPES_H_
#ifndef __cplusplus
#include <stdint.h>
#include <stdbool.h>
#endif /* __cplusplus */
#endif /* BAS_TYPES_H_ */

View File

@@ -20,12 +20,21 @@
* Author: Markus Fröschle
*/
#ifndef _SPIDMA_H_
#define _SPIDMA_H_
#ifndef _DMA_H_
#define _DMA_H_
#include <MCF5475.h>
#define DMA_INTC_LVL 6
#define DMA_INTC_PRI 0
extern int dma_init(void);
extern int dma_get_channel(int requestor);
extern int dma_set_channel(int, void (*)(void));
extern void dma_free_channel(int requestor);
extern uint32_t dma_get_initiator(int requestor);
extern int dma_set_initiator(int initiator);
extern void dma_free_initiator(int initiator);
#endif /* _SPIDMA_H_ */
#endif /* _DMA_H_ */

57
BaS_gcc/include/eth.h Normal file
View File

@@ -0,0 +1,57 @@
/*
* File: eth.h
* Purpose: Definitions for Ethernet Frames.
*
* Modifications:
*/
#ifndef _ETH_H
#define _ETH_H
#include "bas_types.h"
/*******************************************************************/
/* Ethernet standard lengths in bytes*/
#define ETH_ADDR_LEN (6)
#define ETH_TYPE_LEN (2)
#define ETH_CRC_LEN (4)
#define ETH_MAX_DATA (1500)
#define ETH_MIN_DATA (46)
#define ETH_HDR_LEN (ETH_ADDR_LEN * 2 + ETH_TYPE_LEN)
/* Defined Ethernet Frame Types */
#define ETH_FRM_IP (0x0800)
#define ETH_FRM_ARP (0x0806)
#define ETH_FRM_RARP (0x8035)
#define ETH_FRM_TEST (0xA5A5)
/* Maximum and Minimum Ethernet Frame Sizes */
#define ETH_MAX_FRM (ETH_HDR_LEN + ETH_MAX_DATA + ETH_CRC_LEN)
#define ETH_MIN_FRM (ETH_HDR_LEN + ETH_MIN_DATA + ETH_CRC_LEN)
#define ETH_MTU (ETH_HDR_LEN + ETH_MAX_DATA)
/* Ethernet Addresses */
typedef uint8_t ETH_ADDR[ETH_ADDR_LEN];
/* 16-bit Ethernet Frame Type, ie. Protocol */
typedef uint16_t ETH_FRM_TYPE;
/* Ethernet Frame Header definition */
typedef struct
{
ETH_ADDR dest;
ETH_ADDR src;
ETH_FRM_TYPE type;
} ETH_HDR;
/* Ethernet Frame definition */
typedef struct
{
ETH_HDR head;
uint8_t* data;
} ETH_FRAME;
/*******************************************************************/
#endif /* _ETH_H */

164
BaS_gcc/include/fec.h Normal file
View File

@@ -0,0 +1,164 @@
/*
* File: fec.h
* Purpose: Driver for the Fast Ethernet Controller (FEC)
*
* Notes:
*/
#ifndef _FEC_H_
#define _FEC_H_
/********************************************************************/
/* MII Speed Settings */
#define FEC_MII_10BASE_T 0
#define FEC_MII_100BASE_TX 1
/* MII Duplex Settings */
#define FEC_MII_HALF_DUPLEX 0
#define FEC_MII_FULL_DUPLEX 1
/* Timeout for MII communications */
#define FEC_MII_TIMEOUT 0x10000
/* External Interface Modes */
#define FEC_MODE_7WIRE 0
#define FEC_MODE_MII 1
#define FEC_MODE_LOOPBACK 2 /* Internal Loopback */
/*
* FEC Event Log
*/
typedef struct {
int total; /* total count of errors */
int hberr; /* heartbeat error */
int babr; /* babbling receiver */
int babt; /* babbling transmitter */
int gra; /* graceful stop complete */
int txf; /* transmit frame */
int mii; /* MII */
int lc; /* late collision */
int rl; /* collision retry limit */
int xfun; /* transmit FIFO underrrun */
int xferr; /* transmit FIFO error */
int rferr; /* receive FIFO error */
int dtxf; /* DMA transmit frame */
int drxf; /* DMA receive frame */
int rfsw_inv; /* Invalid bit in RFSW */
int rfsw_l; /* RFSW Last in Frame */
int rfsw_m; /* RFSW Miss */
int rfsw_bc; /* RFSW Broadcast */
int rfsw_mc; /* RFSW Multicast */
int rfsw_lg; /* RFSW Length Violation */
int rfsw_no; /* RFSW Non-octet */
int rfsw_cr; /* RFSW Bad CRC */
int rfsw_ov; /* RFSW Overflow */
int rfsw_tr; /* RFSW Truncated */
} FEC_EVENT_LOG;
int
fec_mii_write(uint8_t , uint8_t , uint8_t , uint16_t );
int
fec_mii_read(uint8_t , uint8_t , uint8_t , uint16_t *);
void
fec_mii_init(uint8_t, uint32_t);
void
fec_mib_init(uint8_t);
void
fec_mib_dump(uint8_t);
void
fec_log_init(uint8_t);
void
fec_log_dump(uint8_t);
void
fec_debug_dump(uint8_t);
void
fec_duplex (uint8_t, uint8_t);
uint8_t
fec_hash_address(const uint8_t *);
void
fec_set_address (uint8_t ch, const uint8_t *);
void
fec_reset (uint8_t);
void
fec_init (uint8_t, uint8_t, const uint8_t *);
void
fec_rx_start(uint8_t, int8_t *);
void
fec_rx_restart(uint8_t);
void
fec_rx_stop (uint8_t);
void
fec_rx_frame(uint8_t, NIF *);
void
fec0_rx_frame(void);
void
fec1_rx_frame(void);
void
fec_tx_start(uint8_t, int8_t *);
void
fec_tx_restart(uint8_t);
void
fec_tx_stop (uint8_t);
void
fec0_tx_frame(void);
void
fec1_tx_frame(void);
int fec_send(uint8_t, NIF *, uint8_t *, uint8_t *, uint16_t , NBUF *);
int
fec0_send(NIF *, uint8_t *, uint8_t *, uint16_t , NBUF *);
int
fec1_send(NIF *, uint8_t *, uint8_t *, uint16_t , NBUF *);
void
fec_irq_enable(uint8_t, uint8_t, uint8_t);
void
fec_irq_disable(uint8_t);
void
fec_interrupt_handler(uint8_t);
int
fec0_interrupt_handler(void *, void *);
int
fec1_interrupt_handler(void *, void *);
void
fec_eth_setup(uint8_t, uint8_t, uint8_t, uint8_t, const uint8_t *);
void
fec_eth_reset(uint8_t);
void
fec_eth_stop(uint8_t);
/********************************************************************/
#endif /* _FEC_H_ */

99
BaS_gcc/include/fecbd.h Normal file
View File

@@ -0,0 +1,99 @@
/*
* File: fecbd.h
* Purpose:
*
* Purpose: Provide a simple buffer management driver
*/
#ifndef _FECBD_H_
#define _FECBD_H_
/********************************************************************/
#define Rx 1
#define Tx 0
/*
* Buffer sizes in bytes
*/
#ifndef RX_BUF_SZ
#define RX_BUF_SZ NBUF_SZ
#endif
#ifndef TX_BUF_SZ
#define TX_BUF_SZ NBUF_SZ
#endif
/*
* Number of Rx and Tx Buffers and Buffer Descriptors
*/
#ifndef NRXBD
#define NRXBD 10
#endif
#ifndef NTXBD
#define NTXBD 4
#endif
/*
* Buffer Descriptor Format
*/
typedef struct
{
uint16_t status; /* control and status */
uint16_t length; /* transfer length */
uint8_t *data; /* buffer address */
} FECBD;
/*
* Bit level definitions for status field of buffer descriptors
*/
#define TX_BD_R 0x8000
#define TX_BD_TO1 0x4000
#define TX_BD_W 0x2000
#define TX_BD_TO2 0x1000
#define TX_BD_INTERRUPT 0x1000 /* MCF547x/8x Only */
#define TX_BD_L 0x0800
#define TX_BD_TC 0x0400
#define TX_BD_DEF 0x0200 /* MCF5272 Only */
#define TX_BD_ABC 0x0200
#define TX_BD_HB 0x0100 /* MCF5272 Only */
#define TX_BD_LC 0x0080 /* MCF5272 Only */
#define TX_BD_RL 0x0040 /* MCF5272 Only */
#define TX_BD_UN 0x0002 /* MCF5272 Only */
#define TX_BD_CSL 0x0001 /* MCF5272 Only */
#define RX_BD_E 0x8000
#define RX_BD_R01 0x4000
#define RX_BD_W 0x2000
#define RX_BD_R02 0x1000
#define RX_BD_INTERRUPT 0x1000 /* MCF547x/8x Only */
#define RX_BD_L 0x0800
#define RX_BD_M 0x0100
#define RX_BD_BC 0x0080
#define RX_BD_MC 0x0040
#define RX_BD_LG 0x0020
#define RX_BD_NO 0x0010
#define RX_BD_CR 0x0004
#define RX_BD_OV 0x0002
#define RX_BD_TR 0x0001
#define RX_BD_ERROR (RX_BD_NO | RX_BD_CR | RX_BD_OV | RX_BD_TR)
/*
* Functions provided in fec_bd.c
*/
void
fecbd_init(uint8_t);
uint32_t fecbd_get_start(uint8_t, uint8_t);
FECBD *
fecbd_rx_alloc(uint8_t);
FECBD *
fecbd_tx_alloc(uint8_t);
FECBD *
fecbd_tx_free(uint8_t);
/*******************************************************************/
#endif /* _FECBD_H_ */

121
BaS_gcc/include/icmp.h Normal file
View File

@@ -0,0 +1,121 @@
/*
* File: icmp.h
* Purpose: Handle Internet Control Message Protocol packets.
*
* Notes: See RFC 792 "Internet Control Message Protocol"
* for more details.
*/
#ifndef _ICMP_H
#define _ICMP_H
/********************************************************************/
typedef struct
{
uint32_t unused;
uint8_t ih_dg;
} icmp_dest_unreachable;
#define ICMP_DEST_UNREACHABLE (3) /* type */
#define ICMP_NET_UNREACHABLE (0) /* code */
#define ICMP_HOST_UNREACHABLE (1)
#define ICMP_PROTOCOL_UNREACHABLE (2)
#define ICMP_PORT_UNREACHABLE (3)
#define ICMP_FRAG_NEEDED (4)
#define ICMP_ROUTE_FAILED (5)
typedef struct
{
uint32_t unused;
uint8_t ih_dg;
} icmp_time_exceeded;
#define ICMP_TIME_EXCEEDED (11) /* type */
#define ICMP_TTL_EXCEEDED (0) /* code */
#define ICMP_FRAG_TIME_EXCEEDED (1)
typedef struct
{
uint8_t pointer;
uint8_t unused1;
uint16_t unused2;
uint8_t ih_dg;
} icmp_parameter_problem;
#define ICMP_PARAMETER_PROBLEM (12) /* type */
#define ICMP_POINTER (0) /* code -- not */
typedef struct
{
uint32_t unused;
uint8_t ih_dg;
} icmp_source_quench;
#define ICMP_SOURCE_QUENCH (4) /* type */
typedef struct
{
uint32_t gateway_addr;
uint8_t ih_dg;
} icmp_redirect;
#define ICMP_REDIRECT (5) /* type */
#define ICMP_REDIRECT_NET (0) /* code */
#define ICMP_REDIRECT_HOST (1)
#define ICMP_REDIRECT_TOS_NET (2)
#define ICMP_REDIRECT_TOS_HOST (3)
typedef struct
{
uint16_t identifier;
uint16_t sequence;
uint8_t data;
} icmp_echo;
#define ICMP_ECHO (8) /* type */
#define ICMP_ECHO_REPLY (0) /* type */
typedef struct
{
uint16_t identifier;
uint16_t sequence;
} icmp_information;
#define ICMP_INFORMATION_REQUEST (15) /* type */
#define ICMP_INFORMATION_REPLY (16) /* type */
typedef struct
{
uint16_t identifier;
uint16_t sequence;
uint32_t originate_ts;
uint32_t receive_ts;
uint32_t transmit_ts;
} icmp_timestamp;
#define ICMP_TIMESTAMP (13) /* type */
#define ICMP_TIMESTAMP_REPLY (14) /* type */
typedef struct
{
uint8_t type;
uint8_t code;
uint16_t chksum;
union
{
icmp_dest_unreachable dest_unreachable;
icmp_source_quench source_quench;
icmp_redirect redirect;
icmp_time_exceeded time_exceeded;
icmp_parameter_problem parameter_problem;
icmp_timestamp timestamp;
icmp_information information;
icmp_echo echo;
} msg;
} icmp_message;
/********************************************************************/
/* Protocol Header information */
#define ICMP_HDR_OFFSET (ETH_HDR_LEN + IP_HDR_SIZE)
#define ICMP_HDR_SIZE 8
void
icmp_handler(NIF *, NBUF *);
/********************************************************************/
#endif /* _ICMP_H */

View File

@@ -76,6 +76,25 @@
#define INT_SOURCE_GPT1 61 // GPT1 timer interrupt
#define INT_SOURCE_GPT0 62 // GPT0 timer interrupt
#define DMA_INTC_LVL 6 /* interrupt level for DMA interrupt */
#define DMA_INTC_PRI 0 /* interrupt priority for DMA interrupt */
#define FEC0_INTC_LVL 5 /* interrupt level for FEC0 */
#define FEC0_INTC_PRI 0 /* interrupt priority for FEC0 */
#define FEC1_INTC_LVL 5 /* interrupt level for FEC1 */
#define FEC1_INTC_PRI 1 /* interrupt priority for FEC1 */
#define FEC_INTC_LVL(x) ((x == 0) ? FEC0_INTC_LVL : FEC1_INTC_LVL)
#define FEC_INTC_PRI(x) ((x == 0) ? FEC0_INTC_PRI : FEC1_INTC_PRI)
#define FEC0RX_DMA_PRI 5
#define FEC1RX_DMA_PRI 5
#define FECRX_DMA_PRI(x) ((x == 0) ? FEC0RX_DMA_PRI : FEC1RX_DMA_PRI)
#define FEC0TX_DMA_PRI 6
#define FEC1TX_DMA_PRI 6
#define FECTX_DMA_PRI(x) ((x == 0) ? FEC0TX_DMA_PRI : FEC1TX_DMA_PRI)
extern int register_interrupt_handler(uint8_t source, uint8_t level, uint8_t priority, uint8_t intr, void (*handler)(void));
#endif /* _INTERRUPTS_H_ */

100
BaS_gcc/include/ip.h Normal file
View File

@@ -0,0 +1,100 @@
/*
* File: ip.h
* Purpose: Definitions for the Internet Protocol, IP.
*
* Notes: See RFC 791 "DARPA Internet Program Protocol
* Specification" for more details.
*/
#ifndef _IP_H
#define _IP_H
/********************************************************************/
/* 32-bit IP Addresses */
typedef uint8_t IP_ADDR[4];
/* Pointer to an IP Address */
typedef uint8_t IP_ADDR_P[];
/* Definition of an IP packet header */
typedef struct
{
uint8_t version_ihl;
uint8_t service_type;
uint16_t total_length;
uint16_t identification;
uint16_t flags_frag_offset;
uint8_t ttl;
uint8_t protocol;
uint16_t checksum;
IP_ADDR source_addr;
IP_ADDR dest_addr;
uint8_t options; /* actually an array of undetermined length */
} ip_frame_hdr;
/* Macros for accessing an IP datagram. */
#define IP_VERSION(a) ((a->version_ihl & 0x00F0) >> 4)
#define IP_IHL(a) ((a->version_ihl & 0x000F))
#define IP_SERVICE(a) (a->service_type)
#define IP_LENGTH(a) (a->total_length)
#define IP_IDENT(a) (a->identification)
#define IP_FLAGS(a) ((a->flags_frag_offset & 0x0000E000) >> 13)
#define IP_FRAGMENT(a) ((a->flags_frag_offset & 0x00001FFF))
#define IP_TTL(a) (a->ttl)
#define IP_PROTOCOL(a) (a->protocol)
#define IP_CHKSUM(a) (a->checksum)
#define IP_SRC(a) (&a->source_addr[0])
#define IP_DEST(a) (&a->dest_addr[0])
#define IP_OPTIONS(a) (&a->options)
#define IP_DATA(a) (&((uint8_t *)a)[IP_IHL(a) * 4])
/* Defined IP protocols */
#define IP_PROTO_ICMP (1)
#define IP_PROTO_UDP (17)
/* Protocol Header information */
#define IP_HDR_OFFSET ETH_HDR_LEN
#define IP_HDR_SIZE 20 /* no options */
/********************************************************************/
typedef struct
{
IP_ADDR myip;
IP_ADDR gateway;
IP_ADDR netmask;
IP_ADDR broadcast;
unsigned int rx;
unsigned int rx_unsup;
unsigned int tx;
unsigned int err;
} IP_INFO;
/********************************************************************/
void
ip_handler (NIF *, NBUF *);
uint16_t
ip_chksum (uint16_t *, int);
int
ip_send (NIF *,
uint8_t *, /* destination IP */
uint8_t *, /* source IP */
uint8_t, /* protocol */
NBUF * /* buffer descriptor */);
void
ip_init (IP_INFO *, IP_ADDR_P, IP_ADDR_P, IP_ADDR_P);
uint8_t *
ip_get_myip (IP_INFO *);
uint8_t *
ip_resolve_route (NIF *, IP_ADDR_P);
/********************************************************************/
#endif /* _IP_H */

85
BaS_gcc/include/nbuf.h Normal file
View File

@@ -0,0 +1,85 @@
/*
* File: nbuf.h
* Purpose: Definitions for network buffer management
*
* Notes: These routines implement a network buffer scheme
*/
#ifndef _NBUF_H_
#define _NBUF_H_
/********************************************************************/
/*
* Include the Queue structure definitions
*/
#include "queue.h"
/*
* Number of network buffers to use
*/
#define NBUF_MAX 30
/*
* Size of each buffer in bytes
*/
#ifndef NBUF_SZ
#define NBUF_SZ 1520
#endif
/*
* Defines to identify all the buffer queues
* - FREE must always be defined as 0
*/
#define NBUF_FREE 0 /* available buffers */
#define NBUF_TX_RING 1 /* buffers in the Tx BD ring */
#define NBUF_RX_RING 2 /* buffers in the Rx BD ring */
#define NBUF_SCRATCH 3 /* misc */
#define NBUF_MAXQ 4 /* total number of queueus */
/*
* Buffer Descriptor Format
*
* Fields:
* next Pointer to next node in the queue
* data Pointer to the data buffer
* offset Index into buffer
* length Remaining bytes in buffer from (data + offset)
*/
typedef struct
{
QNODE node;
uint8_t *data;
uint16_t offset;
uint16_t length;
} NBUF;
/*
* Functions to manipulate the network buffers.
*/
int
nbuf_init(void);
void
nbuf_flush(void);
NBUF *
nbuf_alloc (void);
void
nbuf_free(NBUF *);
NBUF *
nbuf_remove(int);
void
nbuf_add(int, NBUF *);
void
nbuf_reset(void);
void
nbuf_debug_dump(void);
/********************************************************************/
#endif /* _NBUF_H_ */

32
BaS_gcc/include/net.h Normal file
View File

@@ -0,0 +1,32 @@
/*
* File: net.h
* Purpose: Network definitions and prototypes for dBUG.
*
* Notes:
*/
#ifndef _NET_H
#define _NET_H
/********************************************************************/
/*
* Include information and prototypes for all protocols
*/
#include "eth.h"
#include "nbuf.h"
#include "nif.h"
#include "ip.h"
#include "icmp.h"
#include "arp.h"
#include "udp.h"
#include "tftp.h"
/********************************************************************/
int net_init(void);
/********************************************************************/
#endif /* _NET_H */

62
BaS_gcc/include/nif.h Normal file
View File

@@ -0,0 +1,62 @@
/*
* File: nif.h
* Purpose: Definition of a Network InterFace.
*
* Notes:
*/
#ifndef _NIF_H
#define _NIF_H
/********************************************************************/
/*
* Maximum number of supported protoocls: IP, ARP, RARP
*/
#define MAX_SUP_PROTO (3)
typedef struct NIF_t
{
ETH_ADDR hwa; /* ethernet card hardware address */
ETH_ADDR broadcast; /* broadcast address */
int mtu; /* hardware maximum transmission unit */
int ch; /* ethernet channel associated with this NIF */
struct SUP_PROTO_t
{
uint16_t protocol;
void (*handler)(struct NIF_t *, NBUF *);
void *info;
} protocol[MAX_SUP_PROTO];
unsigned short num_protocol;
int (*send)(struct NIF_t *, uint8_t *, uint8_t *, uint16_t, NBUF *);
unsigned int f_rx;
unsigned int f_tx;
unsigned int f_rx_err;
unsigned int f_tx_err;
unsigned int f_err;
} NIF;
/********************************************************************/
NIF *
nif_init (NIF *);
int
nif_protocol_exist (NIF *, uint16_t);
void
nif_protocol_handler (NIF *, uint16_t, NBUF *);
void *
nif_get_protocol_info (NIF *, uint16_t);
int
nif_bind_protocol (NIF *, uint16_t, void (*)(NIF *, NBUF *), void *);
/********************************************************************/
#endif /* _NIF_H */

53
BaS_gcc/include/queue.h Normal file
View File

@@ -0,0 +1,53 @@
/*
* File: queue.h
* Purpose: Implement a first in, first out linked list
*
* Notes:
*/
#ifndef _QUEUE_H_
#define _QUEUE_H_
/********************************************************************/
/*
* Individual queue node
*/
typedef struct NODE
{
struct NODE *next;
} QNODE;
/*
* Queue Struture - linked list of qentry items
*/
typedef struct
{
QNODE *head;
QNODE *tail;
} QUEUE;
/*
* Functions provided by queue.c
*/
void
queue_init(QUEUE *);
int
queue_isempty(QUEUE *);
void
queue_add(QUEUE *, QNODE *);
QNODE*
queue_remove(QUEUE *);
QNODE*
queue_peek(QUEUE *);
void
queue_move(QUEUE *, QUEUE *);
/********************************************************************/
#endif /* _QUEUE_H_ */

158
BaS_gcc/include/tftp.h Normal file
View File

@@ -0,0 +1,158 @@
/*
* File: tftp.h
* Purpose: Data definitions for TFTP
*
* Notes:
*/
#ifndef _TFTP_H
#define _TFTP_H
/********************************************************************/
#define TFTP_RRQ (1)
#define TFTP_WRQ (2)
#define TFTP_DATA (3)
#define TFTP_ACK (4)
#define TFTP_ERROR (5)
#define TFTP_ERR_FNF 1
#define TFTP_ERR_AV 2
#define TFTP_ERR_DF 3
#define TFTP_ERR_ILL 4
#define TFTP_ERR_TID 5
#define TFTP_FE 6
#define TFTP_NSU 7
#define TFTP_ERR_UD 0
#define OCTET "octet"
#define NETASCII "netascii"
/* Protocol Header information */
#define TFTP_HDR_OFFSET (ETH_HDR_LEN + IP_HDR_SIZE + UDP_HDR_SIZE)
/* Timeout in seconds */
#define TFTP_TIMEOUT 2
/* Maximum TFTP Packet Size (payload only - no header) */
#define TFTP_PKTSIZE 512
/* Number of TFTP Data Buffers */
#define NUM_TFTPBD 6
/********************************************************************/
/* Data Buffer Pointer Structure */
typedef struct
{
uint8_t data[TFTP_PKTSIZE];
uint16_t bytes;
} DATA_BUF;
/* TFTP RRQ/WRQ Packet */
typedef struct
{
uint16_t opcode;
char filename_mode[TFTP_PKTSIZE - 2];
} RWRQ;
/* TFTP DATA Packet */
typedef struct
{
uint16_t opcode;
uint16_t blocknum;
uint8_t data[TFTP_PKTSIZE - 4];
} DATA;
/* TFTP Acknowledge Packet */
typedef struct
{
uint16_t opcode;
uint16_t blocknum;
} ACK;
/* TFTP Error Packet */
typedef struct
{
uint16_t opcode;
uint16_t code;
char msg[TFTP_PKTSIZE - 4];
} ERROR;
/* TFTP Generic Packet */
typedef struct
{
uint16_t opcode;
} GEN;
union TFTPpacket
{
RWRQ rwrq;
DATA data;
ACK ack;
ERROR error;
GEN generic;
};
/* TFTP Connection Status */
typedef struct
{
/* Pointer to next character in buffer ring */
uint8_t *next_char;
/* Direction of current connection, read or write */
uint8_t dir;
/* Connection established flag */
uint8_t open;
/* Pointer to our Network InterFace */
NIF *nif;
/* File being transferred */
char *file;
/* Server IP address */
IP_ADDR server_ip;
/* Queue to hold the TFTP packets */
QUEUE queue;
/* Bytes received counter */
uint32_t bytes_recv;
/* Bytes sent counter */
uint32_t bytes_sent;
/* Bytes remaining in current Rx buffer */
uint32_t rem_bytes;
/* Server UDP port */
uint16_t server_port;
/* My UDP port */
uint16_t my_port;
/* Expected TFTP block number */
uint16_t exp_blocknum;
/* Keep track of the last packet acknowledged */
uint16_t last_ack;
/* Error Flag */
uint8_t error;
} TFTP_Connection;
/********************************************************************/
void tftp_handler(NIF *, NBUF *) ;
int tftp_write (NIF *, char *, IP_ADDR_P, uint32_t, uint32_t);
int tftp_read(NIF *, char *, IP_ADDR_P);
void tftp_end(int);
int tftp_in_char(void);
/********************************************************************/
#endif /* _TFTP_H */

61
BaS_gcc/include/udp.h Normal file
View File

@@ -0,0 +1,61 @@
/*
* File: udp.h
* Purpose: User Datagram Protocol, UDP, data definitions
*
* Notes:
*/
#ifndef _UDP_H
#define _UDP_H
/********************************************************************/
typedef struct
{
uint16_t src_port;
uint16_t dest_port;
uint16_t length;
uint16_t chksum;
} udp_frame_hdr;
#define UDP_SOURCE(a) (a->src_port)
#define UDP_DEST(a) (a->dest_port)
#define UDP_LENGTH(a) (a->length)
#define UDP_CHKSUM(a) (a->chksum)
#define DEFAULT_UDP_PORT (0x4321)
#define UDP_PORT_TELNET (23)
#define UDP_PORT_FTP (21)
#define UDP_PORT_TFTP (69)
/* Protocol Header information */
#define UDP_HDR_OFFSET (ETH_HDR_LEN + IP_HDR_SIZE)
#define UDP_HDR_SIZE 8
/********************************************************************/
void
udp_init (void);
void
udp_prime_port (uint16_t);
uint16_t
udp_obtain_free_port (void);
void
udp_bind_port ( uint16_t, void (*)(NIF *,NBUF *));
void
udp_free_port (uint16_t);
int
udp_send (NIF *, uint8_t *, int, int, NBUF *);
void
udp_handler (NIF *, NBUF *);
/********************************************************************/
#endif /* _UDP_H */