⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ahbeth.c

📁 altera epxa1的例子程序
💻 C
字号:
// file: ahbeth.c
//
// This file implements the
// low level routines for an
// adapter that the "plugs"
// embedded tcp/ip stack can
// use.
//
#define PLUGS_DEBUG 1

#include <stdio.h>
#include <stdlib.h>

#include "plugs.h"
#include "ahbeth.h"

#include "stripe.h"
#include "mode_ctrl00.h"
#include "adam.h"

#include "utils.h"
//============================================
// globals
type_eth_descriptors eth;
//============================================


// --------------------------------------
// Reset the chip to a usable state.
//
//
int nr_ahbeth_reset(void *hardware_base_address,ns_plugs_network_settings *s)
	{
	unsigned char *macp;

	// +------------------------------------
	// | 1: set the mac address

	// +-----------------------------------
	// | 2: set the chip to a friendly mode
	// | rx_ctl: What kinds of packets to accept
	// | rx_cfg: What kinds of events to notice and enqueue (hw irq is not on though)
	// | line_ctl: What features of the wire to enable

	        // promiscuous, good crc's only
        	// all err events, and good packets
        	// enable receiver & transmitter


    eth_config(&eth);   // use the 'default' configuration

    // set the mac address
    macp = (unsigned char *)(&s->ethernet_address);
    eth.macaddr[0] = macp[0];
    eth.macaddr[1] = macp[1];
    eth.macaddr[2] = macp[2];
    eth.macaddr[3] = macp[3];
    eth.macaddr[4] = macp[4];
    eth.macaddr[5] = macp[5];

    // configure the core
    eth_init(&eth);

	return 0;
	}

// --------------------------------------
// Set loopback mode: pass 0 for off,
// 1 for on.

int nr_ahbeth_set_loopback(void *hardware_base_address,int loopback_onoff)
	{
	printf("*** loopback not supported ***\n");
    return 0;
	}

// --------------------------------------
// Set the LED manually: pass 0 for off,
// 1 for on, or -1 to let the chip do with
// it as it will.

int nr_ahbeth_set_led(void *hardware_base_address,int led_onoff)
	{
    printf("*** led not supported ***\n");

	return 0;
	}


// ---------------------------------
// check for event:
// check the rx_fda descriptor, and if it's something
// we understand, dispatch it.
// else ignore it.

int nr_ahbeth_check_for_events(void *hardware_base_address,dispatch_packet_proc proc,void *context)
	{
	int err;
	int watchdog = 50;	// read no more than this many packets

read_isq:

    err = eth_receive(&eth, (rx_callback_proc) proc, context);

	// keep trying til eth comes up blank
	if(!err && watchdog-- > 0)
		goto read_isq;

	return watchdog ? -1 : 0;
	}




// The low-level transmit routine
//
// return 0 for AOK, or -1 if we couldn't send for some reason
//

int nr_ahbeth_tx_frame(void *hardware_base_address,char *ethernet_frame,int frame_length)
	{
	int err;

    err = eth_transmit(&eth, (void *)ethernet_frame, frame_length, 0);

	return (err) ? -1 : 0;
	}


int nr_ahbeth_dump_registers(void *hardware_base_address)
	{
#if PLUGS_DEBUG
    int i,j;
    ULONG mddata;
	printf("-------------------------\n");
	printf("*** dump registers ***\n");

            // dump ethernet regs
            printf("mac regs");
            for (i=0x000; i<0x040; i+=0x10)
            {
                printf("\nREG %02x: ",i);
                for (j=0; j<0x10; j+=4)
                    printf("%08lx ",*(volatile ULONG *)(EXC_PLD_BLOCK0_BASE+i+j));
            }
            printf("\ndma regs");
            for (i=0x100; i<0x140; i+=0x10)
            {
                printf("\nREG %02x: ",i);
                for (j=0; j<0x10; j+=4)
                    printf("%08lx ",*(volatile ULONG *)(EXC_PLD_BLOCK0_BASE+i+j));
            }
            printf("\n");
            // dump phy regs
            for (i=0; i<19; i+=0x4)
            {
                printf("\nMII REG %02x: ",i);
                for (j=0; j<0x4; j+=1)
                {
                    mddata = eth_mdread(0x1f, i+j);
                    printf("%08lx ",mddata);
                }
            }
            printf("\n");
#endif
	return 0;
	}

ns_plugs_adapter_description ng_ahbeth =
	{
	&nr_ahbeth_reset,
	&nr_ahbeth_set_led,
	&nr_ahbeth_set_loopback,
	&nr_ahbeth_check_for_events,
	&nr_ahbeth_tx_frame,
	&nr_ahbeth_dump_registers,
	"ahbeth"
	};




// end of file

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -