Exemplo n.º 1
0
// ------------------------------------------------------------------------
void
net_test(cyg_addrword_t param)
{
    int results = 0;
    diag_printf("Start set_mac_address\n");
#ifdef CYGHWR_NET_DRIVER_ETH0
#ifdef DO_SET_ETH0
    diag_printf("Setting MAC of eth0 to %02x:%02x:%02x:%02x:%02x:%02x\n",
                new_eth0_addr[0],new_eth0_addr[1],
                new_eth0_addr[2],new_eth0_addr[3],
                new_eth0_addr[4],new_eth0_addr[5] );
    results += set_mac_address( "eth0", new_eth0_addr );
#endif
#endif
#ifdef CYGHWR_NET_DRIVER_ETH1
#ifdef DO_SET_ETH1
    diag_printf("Setting MAC of eth1 to %02x:%02x:%02x:%02x:%02x:%02x\n",
                new_eth1_addr[0],new_eth1_addr[1],
                new_eth1_addr[2],new_eth1_addr[3],
                new_eth1_addr[4],new_eth1_addr[5] );
    results += set_mac_address( "eth1", new_eth1_addr );
#endif
#endif

    if ( 0 == results )
        diag_printf( "**** Did not set any MAC addresses ****\n" );

    diag_printf("Init Network Interfaces\n");
    init_all_network_interfaces();
    diag_printf("After init.\n");

    cyg_test_exit();
}
Exemplo n.º 2
0
void ethmac_start(const uint8_t* address)
{
    // Copy MAC address
    int i;
    for (i = 0; i < 6; i++)
    {
        mac.mac_address[i] = address[i];
    }

    /* MAC clocks activation and commanded reset procedure.*/
    *ethmac_get_DMABMR() |= ETHMAC_DMABMR__SR;
    while (*ethmac_get_DMABMR() & ETHMAC_DMABMR__SR)
        ;

    // Reset the descriptors
    ethmac_descriptors_reset();

    /* ISR vector enabled.*/
    nvic_enable_interrupt_line(NVIC_IRQ_LINE_ETH);

    /* PHY in power up mode.*/
    mii_write(MII_BMCR, mii_read(MII_BMCR) & ~MII_BMCR__PDOWN);

    /* MAC configuration.*/
    *ethmac_get_MACFFR() = 0;
    *ethmac_get_MACFCR() = 0;
    *ethmac_get_MACVLANTR() = 0;

    /* MAC address setup.*/
    set_mac_address(mac.mac_address);

    /* Transmitter and receiver enabled.
     Note that the complete setup of the MAC is performed when the link
     status is detected.*/
    // No checksum offload
    *ethmac_get_MACCR() = ETHMAC_MACCR__RE | ETHMAC_MACCR__TE;

    /* DMA configuration:
     Descriptor chains pointers.*/
    *ethmac_get_DMARDLAR() = (uint32_t) ethmac_rx_des;
    *ethmac_get_DMATDLAR() = (uint32_t) ethmac_tx_des;

    /* Enabling required interrupt sources.*/
    *ethmac_get_DMASR() = (uint32_t) (*ethmac_get_DMASR());
    *ethmac_get_DMAIER() = ETHMAC_DMAIER__NISE | ETHMAC_DMAIER__AISE
            | ETHMAC_DMAIER__RIE | ETHMAC_DMAIER__TIE;

    /* DMA general settings.*/
    *ethmac_get_DMABMR() = ETHMAC_DMABMR__AAB | ETHMAC_DMABMR__RDP_1Beat
            | ETHMAC_DMABMR__PBL_1Beat;

    /* Transmit FIFO flush.*/
    *ethmac_get_DMAOMR() = ETHMAC_DMAOMR__FTF;
    while (*ethmac_get_DMAOMR() & ETHMAC_DMAOMR__FTF)
        ;

    /* DMA final configuration and start.*/
    *ethmac_get_DMAOMR() = ETHMAC_DMAOMR__DTCEFD | ETHMAC_DMAOMR__RSF
            | ETHMAC_DMAOMR__TSF | ETHMAC_DMAOMR__ST | ETHMAC_DMAOMR__SR;
}
Exemplo n.º 3
0
int dtsec_modify_mac_address(struct fman_mac *dtsec, enet_addr_t *enet_addr)
{
	if (!is_init_done(dtsec->dtsec_drv_param))
		return -EINVAL;

	/* Initialize MAC Station Address registers (1 & 2)
	 * Station address have to be swapped (big endian to little endian
	 */
	dtsec->addr = ENET_ADDR_TO_UINT64(*enet_addr);
	set_mac_address(dtsec->regs, (u8 *)(*enet_addr));

	return 0;
}
Exemplo n.º 4
0
int EthernetInterface::init(const char* ip, const char* mask, const char* gateway) {
    use_dhcp = false;
    
    set_mac_address();
    strcpy(ip_addr, ip);
    
    ip_addr_t ip_n, mask_n, gateway_n;
    inet_aton(ip, &ip_n);
    inet_aton(mask, &mask_n);
    inet_aton(gateway, &gateway_n);
    init_netif(&ip_n, &mask_n, &gateway_n);
    
    return 0;
}
Exemplo n.º 5
0
void main()
{
	int i=0;
	char mymac[6]={0x74,0xf7,0x26,0x00,0x00,0x01};
	unsigned char data[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x04,0x74,0xf7,0x26,0x00,0x00,0x01,0x65,0x00,0x00,0x0a,0x05,0x00,0x01,0x02,0x03,0x05,0x06,0x07,0x08,0x09};

	bowler4_header bh;
	for (i=0; i<sizeof(bowler4_header); i++) bh.bytes[i]=0;
	bh.fields.version=0x04;
	bh.fields.affect=setPriority(5,setState(setAsync(bh.fields.affect)));
	bh.fields.payloadLength=10;
	bh.fields.payloadType=0;


	set_mac_address(mymac,&bh);
	calculate_checksum(&bh);
	printf("Verify?\t%d\n",verify_checksum(&bh));
	printf("Verify?\t%d\n",verify_checksum(&bh));
printf("%X\n",check_mac_address(mymac,&bh) );
	printHeader(bh);


	V4MicroParser_state parser;
	parser.state=align;
	parser.macaddr=&mymac;
	fifoInit(&parser.fifo);
	fifoPrint(&parser.fifo);

	for (i=0; i<sizeof(data); i++){
 		fifoPush(&parser.fifo,data[i]);
		int delta=parser.fifo.inPointer;
		printf("Pushing:\t%i\n",i);
		/*fifoPrint(&parser.fifo);*/
		runParserSM(&parser);
		if (parser.fifo.inPointer!=delta) {printf("\nNew Contents of FIFO:");fifoPrint(&parser.fifo);}

		printf("===================\n");
		

	}
		/* fifoPull(&fifo,15); */
		/* fifoPrint(&fifo); */
}
Exemplo n.º 6
0
int do_mac(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
    char cmd;

    if (argc == 1) {
        show_eeprom();
        return 0;
    }

    cmd = argv[1][0];

    if (cmd == 'r') {
        read_eeprom();
        return 0;
    }

    if (cmd == 'i') {
#ifdef CONFIG_SYS_I2C_EEPROM_NXID
        memcpy(e.id, "NXID", sizeof(e.id));
        e.version = 0;
#else
        memcpy(e.id, "CCID", sizeof(e.id));
#endif
        return 0;
    }

    if (!is_valid) {
        printf("Please read the EEPROM ('r') and/or set the ID ('i') first.\n");
        return 0;
    }

    if (argc == 2) {
        switch (cmd) {
        case 's':	/* save */
            prog_eeprom();
            break;
        default:
            return cmd_usage(cmdtp);
        }

        return 0;
    }

    /* We know we have at least one parameter  */

    switch (cmd) {
    case 'n':	/* serial number */
        memset(e.sn, 0, sizeof(e.sn));
        strncpy((char *)e.sn, argv[2], sizeof(e.sn) - 1);
        update_crc();
        break;
    case 'e':	/* errata */
#ifdef CONFIG_SYS_I2C_EEPROM_NXID
        memset(e.errata, 0, 5);
        strncpy((char *)e.errata, argv[2], 4);
#else
        e.errata[0] = argv[2][0];
        e.errata[1] = argv[2][1];
#endif
        update_crc();
        break;
    case 'd':	/* date BCD format YYMMDDhhmmss */
        set_date(argv[2]);
        break;
    case 'p':	/* MAC table size */
        e.mac_count = simple_strtoul(argv[2], NULL, 16);
        update_crc();
        break;
    case '0' ... '7':	/* "mac 0" through "mac 7" */
        set_mac_address(cmd - '0', argv[2]);
        break;
    case 'h':	/* help */
    default:
        return cmd_usage(cmdtp);
    }

    return 0;
}
Exemplo n.º 7
0
int do_mac(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	char cmd;

	if (argc == 1) {
		show_eeprom();
		return 0;
	}

	cmd = argv[1][0];

	if (cmd == 'r') {
#ifdef DEBUG
		printf("%s read\n", __func__);
#endif
		read_eeprom();
		return 0;
	}

	if (argc == 2) {
		switch (cmd) {
		case 's':	/* save */
#ifdef DEBUG
			printf("%s save\n", __func__);
#endif
			prog_eeprom();
			break;
		default:
			return cmd_usage(cmdtp);
		}

		return 0;
	}

	/* We know we have at least one parameter  */

	switch (cmd) {
	case 'n':	/* serial number */
#ifdef DEBUG
		printf("%s serial number\n", __func__);
#endif
		memset(e.sn, 0, sizeof(e.sn));
		strncpy((char *)e.sn, argv[2], sizeof(e.sn) - 1);
		update_crc();
		break;
	case 'd':	/* date BCD format YYMMDDhhmmss */
		set_date(argv[2]);
		break;
	case 'e':	/* errata */
		printf("mac errata not implemented\n");
		break;
	case 'i':	/* id */
		memset(e.id, 0, sizeof(e.id));
		strncpy((char *)e.id, argv[2], sizeof(e.id) - 1);
		update_crc();
		break;
	case 'p':	/* ports */
		printf("mac ports not implemented (always 1 port)\n");
		break;
	case '0' ... '9':
		/* we only have "mac 0" but any digit can be used here */
		set_mac_address(argv[2]);
		break;
	case 'h':	/* help */
	default:
		return cmd_usage(cmdtp);
	}

	return 0;
}
Exemplo n.º 8
0
/* Open/initialize the board.  This is called (in the current kernel)
   sometime after booting when the 'ifconfig' program is run.

   This routine should set everything up anew at each open, even
   registers that "should" only need to be set once at boot, so that
   there is non-reboot way to recover if something goes wrong.
   */
static int
net_open(struct device *dev)
{
	struct net_local *lp = (struct net_local *)dev->priv;
	int result = 0;
//	int i;

	write_irq(dev, lp->chip_type, 0);

	irq2dev_map[/* FIXME */ 0] = dev;
	writereg(dev, PP_BusCTL, 0); /* ints off! */

#ifdef CONFIG_UCSIMM
	*(volatile unsigned short *)0xfffff302 |= 0x0080; /* +ve pol irq */

        if (request_irq(IRQ_MACHSPEC | IRQ5_IRQ_NUM,
                        cs8900_interrupt,
                        IRQ_FLG_STD,
                        "CrystalLAN_cs8900a", NULL))
                panic("Unable to attach cs8900 intr\n");
#endif

#ifdef CONFIG_ARCH_ATMEL
	/* We use IRQ_IRQ1 for the network interrupt */
        if (request_irq(IRQ_MACHSPEC | IRQ_IRQ1,
                        cs8900_interrupt,
                        IRQ_FLG_STD,
                        "CrystalLAN_cs8900a", NULL))
                panic("Unable to attach cs8900 intr\n");                        
#endif

#ifdef CONFIG_ALMA_ANS
	/* We use positive polarity IRQ3 as a network interrupt */
	ICR |= ICR_POL3;

        if (request_irq(IRQ_MACHSPEC | IRQ3_IRQ_NUM,
                        cs8900_interrupt,
                        IRQ_FLG_STD,
                        "CrystalLAN_cs8900a", NULL))
                panic("Unable to attach cs8900 intr\n");                        
#endif

#ifdef CONFIG_MWI

	/* We use vector position 28 as network interrupt */
	if (request_irq(IRQ_MACHSPEC| 28,
			cs8900_interrupt,
			IRQ_FLG_STD,
			"cs8900a", NULL))
		panic("Unable to attach cs8900 intr\n");

	/* setup porte */
	*(volatile unsigned char *)0xfffa15 &= 0xfb;
	*(volatile unsigned char *)0xfffa17 |= 0x04;
	
	/* setup portf */
	*(volatile unsigned char *)0xfffa1d &= 0x7f;
	*(volatile unsigned char *)0xfffa1f |= 0x10;
#endif
	/* set the Ethernet address */
	set_mac_address(dev, dev->dev_addr);

	/* Set the LineCTL */
	lp->linectl = 0;

        /* check to make sure that they have the "right" hardware available */
	switch(lp->adapter_cnf & A_CNF_MEDIA_TYPE) {
	case A_CNF_MEDIA_10B_T:
		result = lp->adapter_cnf & A_CNF_10B_T;
		break;
	case A_CNF_MEDIA_AUI:
		result = lp->adapter_cnf & A_CNF_AUI;
		break;
	case A_CNF_MEDIA_10B_2:
		result = lp->adapter_cnf & A_CNF_10B_2;
		break;
        default:
		result = lp->adapter_cnf & 
		         (A_CNF_10B_T | A_CNF_AUI | A_CNF_10B_2);
        }
        if (!result) {
                printk("%s: EEPROM is configured for unavailable media\n", dev->name);
        release_irq:
                writereg(dev, PP_LineCTL, readreg(dev, PP_LineCTL) & ~(SERIAL_TX_ON | SERIAL_RX_ON));
                irq2dev_map[dev->irq] = 0;
		return -EAGAIN;
	}

        /* set the hardware to the configured choice */
	switch(lp->adapter_cnf & A_CNF_MEDIA_TYPE) {
	case A_CNF_MEDIA_10B_T:
                result = detect_tp(dev);
                if (!result) printk("%s: 10Base-T (RJ-45) has no cable\n", dev->name);
                if (lp->auto_neg_cnf & IMM_BIT) /* check "ignore missing media" bit */
                        result = A_CNF_MEDIA_10B_T; /* Yes! I don't care if I see a link pulse */
		break;
	case A_CNF_MEDIA_AUI:
	  printk("AUI?  What stinking AUI?\n");
		break;
	case A_CNF_MEDIA_10B_2:
	  printk("10Base2?  What stinking 10Base2?\n");
		break;
	case A_CNF_MEDIA_AUTO:
		writereg(dev, PP_LineCTL, lp->linectl | AUTO_AUI_10BASET);
		if (lp->adapter_cnf & A_CNF_10B_T)
			if ((result = detect_tp(dev)) != 0)
				break;

		printk("%s: no media detected\n", dev->name);
                goto release_irq;
	}
	switch(result) {
	case 0: printk("%s: no network cable attached to configured media\n", dev->name);
                goto release_irq;
	case A_CNF_MEDIA_10B_T: printk("%s: using 10Base-T (RJ-45)\n", dev->name);break;
	case A_CNF_MEDIA_AUI:   printk("%s: using 10Base-5 (AUI)\n", dev->name);break;
	case A_CNF_MEDIA_10B_2: printk("%s: using 10Base-2 (BNC)\n", dev->name);break;
	default: printk("%s: unexpected result was %x\n", dev->name, result); goto release_irq;
	}

	/* Turn on both receive and transmit operations */
	writereg(dev, PP_LineCTL, readreg(dev, PP_LineCTL) | SERIAL_RX_ON | SERIAL_TX_ON);

	/* Receive only error free packets addressed to this card */
	lp->rx_mode = 0;
	writereg(dev, PP_RxCTL, DEF_RX_ACCEPT);

	lp->curr_rx_cfg = RX_OK_ENBL | RX_CRC_ERROR_ENBL;
	if (lp->isa_config & STREAM_TRANSFER)
		lp->curr_rx_cfg |= RX_STREAM_ENBL;

	writereg(dev, PP_RxCFG, lp->curr_rx_cfg);

	writereg(dev, PP_TxCFG, TX_LOST_CRS_ENBL | TX_SQE_ERROR_ENBL | TX_OK_ENBL |
	       TX_LATE_COL_ENBL | TX_JBR_ENBL | TX_ANY_COL_ENBL | TX_16_COL_ENBL);

	writereg(dev, PP_BufCFG, READY_FOR_TX_ENBL | RX_MISS_COUNT_OVRFLOW_ENBL |
		 TX_COL_COUNT_OVRFLOW_ENBL | TX_UNDERRUN_ENBL);

	/* now that we've got our act together, enable everything */
	writereg(dev, PP_BusCTL, ENABLE_IRQ
                 );
	dev->tbusy = 0;
	dev->interrupt = 0;
	dev->start = 1;
	return 0;
}
Exemplo n.º 9
0
int main(void) {
	SOCKET bcast_s, server_s;
	int connected = 0, disconnect = 0;
	
	/* Setup Hardware */
	init_hw();
	
/* Test SPI and PWM */
#if CONFIG_TEST_HW
#if CONFIG_BOARD == CONFIG_BOARD_ADC
	trigger_isr_start(dspi_read);
#endif
#if CONFIG_BOARD == CONFIG_BOARD_PWM
	pwm_start();
#endif
	while(1);
#endif
	
	/* Initialise 7 Seg */
	sevenseg_set(CONFIG_7SEG_DEFAULT,DP_0);
	sevenseg_init();
	
	/* Initialise UART */
	fnet_cpu_serial_init(FNET_CFG_CPU_SERIAL_PORT_DEFAULT, 115200);

	/* Clear some screen */
	fnet_printf("\n\n\n");
	
	/* Print board type and firmware version */
	fnet_printf("Board Type: %s Firmware compiled %s %s \n",
			CONFIG_BOARD_TYPE_STRING, __TIME__, __DATE__);
	
	/* Initialise FNET stack */
	init_fnet();
	
	/* Set MAC address based on K60 UID*/
	set_mac_address();
	
	/* Wait for Ethernet connection */
	fnet_printf("Waiting for Connection \n");
	sevenseg_set(CONFIG_7SEG_DEFAULT,DP_1); /* First dot = waiting for connection */
	while (!check_connected()) {
		fnet_timer_delay(FNET_TIMER_TICK_IN_SEC * 1); /* 1 Sec */
		fnet_printf("."); /* Print some errors */
	}
	
	/* Wait for DHCP server, if it fails use link local */
	wait_dhcp(CONFIG_DHCP_TRIES);  
	
	/* Print current IP address */
	fnet_printf("Current IP Address:");
	print_cur_ip();
	fnet_printf("\n");
	
	sevenseg_set(CONFIG_7SEG_DEFAULT,DP_2); /* Second dot = have IP Address */
	
	/* Start UDP receiver */
	bcast_s = bcast_setup_listener(CONFIG_BCAST_PORT);
	if (bcast_s == -1) {
		fnet_printf("BCAST: Error, could not initialise port \n");
		while (1);
	}
	
	sevenseg_set(CONFIG_7SEG_DEFAULT,DP_3); /* Third dot = waiting for UDP */

	/* MAIN LOOP */
	while (1) {
		/* CONNECT IF NEEDED */
		if(!connected) {
			connected = netprot_connect(bcast_s, &server_s);
			#if CONFIG_BOARD == CONFIG_BOARD_PWM
				if(connected) {
					sevenseg_set("8888",DP_0); /* Change the screen, this will do for now */
				}
			#endif	
			fnet_poll_services(); /* Poll DHCP while unconnected */
		}
		
		/* WHEN CONNECTED */
		if (connected) {
			int sent = 0, err;
			
			/* Check for disconnection */
			if (disconnect) {
				disconnect = 0; /* Reset */
				netprot_goodbye(&server_s);
				/* Flush UDP port to prevent reconnecting to dead server */
				bcast_flush(bcast_s);
				sevenseg_set(CONFIG_7SEG_DEFAULT,DP_3); /* Third dot = waiting for UDP */
				/* Stop what you are doing */
				#if CONFIG_BOARD == CONFIG_BOARD_ADC
					trigger_isr_stop();
					capture_set_empty();
				#endif
				fnet_printf("Server Disconnected \n");
				connected = 0;
				continue;
			}
			
			/* Send data first if we are a capture type board */
			#if CONFIG_CAPTURE_SUPPORT
				sent = netprot_send_capture(server_s);
				if (sent<0) { /* Error - Disconnect */
					disconnect = 1;
					continue;
				}
			#endif
			
			/* Get commands */
			if (sent <= 0) { /* We have sent nothing or error */
				err = netprot_get_commands(server_s);
				if (err) { /* Error - Disconnect */
					disconnect = 1;
					continue;
				}
			}
		}
	}
	/* END OF MAIN LOOP */
	
	/* Should never end up here */
	return 0;
}
Exemplo n.º 10
0
void demo_mode(){
	int n = 2010;
	
	unsigned long long rec_point[n];
	unsigned long long sched_point[n];
	
	static unsigned long long receive_point;
	static unsigned long long send_point;

  	unsigned char CT[] = {0xAB,0xAD,0xBA,0xBE};
	unsigned char VL2[] = {0x0F,0xA3};
	unsigned int send_addr[] = {0x800,0xE00,0x1400,0x1A00,0x2000};
	unsigned char send_i = 0;

	int sched_errors=0;
	int tte=0;
	int eth=0;
	unsigned char reply;
	unsigned int cur_RX = 0x000;
	unsigned int ext_RX = 0x800;
	unsigned int cur_RX_BD = 0x600;
	unsigned int ext_RX_BD = 0x608;

	set_mac_address(0x1D000400,0x00000289);

	//int_period = 10ms, cluster cycle=20ms, CT, 1 VL sending, max_delay, comp_delay, precision
	tte_initialize(100,200,CT,1,0x2A60,0xFA0,0x33E);

	//initialize other ethmac
	eth_iowr1(0x00, 0x0000A423);

	tte_init_VL(0, 82,100); //VL 4003 starts at 8.2ms and has a period of 10ms
	tte_start_ticking(1,0,0);
	eth_iowr(0x04, 0x00000004); //clear receive frame bit in int_source
        eth_iowr(cur_RX_BD+4, cur_RX); //set first receive buffer to store frame in 0x000
	eth_iowr(cur_RX_BD, 0x0000C000); //set empty and IRQ and not wrap
	eth_iowr(ext_RX_BD+4, ext_RX); //set second receive buffer to store frame in 0x800
	eth_iowr(ext_RX_BD, 0x00006000); //set NOT empty, IRQ and wrap

	for (int i =0; i<n;){
	  tte_wait_for_message(&receive_point); //eth0

	  tte_clear_free_rx_buffer(ext_RX_BD); //start receiving in other buffer

	  reply=tte_receive(cur_RX,receive_point);

	  if(reply==0){ //failed pcf
            printf("pcf out of schedule \n");
	    n=i+1;
	    break;
          }
	  if(reply==1){ //successfull pcf
	    if(i>=10){
	      send_point=*(_iodev_ptr_t)(__PATMOS_TIMER_LOCLK);
	      tte_prepare_test_data(0x2600,VL2,0x11,64);
  	      if(!tte_schedule_send(0x2600,64,0)) sched_errors++;
	      
	      reply=0;
	      while(reply==0){
	        //set a buffer descriptor to receive in other ethmac controller
	        eth_iowr1(0x04, 0x00000004); 
                eth_iowr1(0x604, 0x00); 
	        eth_iowr1(0x600, 0x0000E000); 

	        //wait for it to be received on other ethmac controller
	        while ((eth_iord1(0x04) & 0x4)==0){
	          receive_point = *(_iodev_ptr_t)(__PATMOS_TIMER_LOCLK); //to avoid delay error
	        };
	        receive_point = *(_iodev_ptr_t)(__PATMOS_TIMER_LOCLK);
	      
	        //check if received message is tte and correct VL
		if(mem_iord_byte1(0x00)==CT[0] &&
		  mem_iord_byte1(0x01)==CT[1] &&
		  mem_iord_byte1(0x02)==CT[2] &&
		  mem_iord_byte1(0x03)==CT[3] &&
		  mem_iord_byte1(0x04)==VL2[0] &&
		  mem_iord_byte1(0x05)==VL2[1]){
		  reply=1; 
		}
	      }
	      rec_point[i]=receive_point;
	      sched_point[i]=send_point;
	    }
	    i++;
          } else if (reply==2){ //incoming tte
	    tte++;
	  }
	  else{ //incoming ethernet msg
	    eth++;
	  }
	  unsigned int extra = cur_RX;
	  cur_RX = ext_RX;
	  ext_RX = extra;
	  extra = cur_RX_BD;
	  cur_RX_BD = ext_RX_BD;
	  ext_RX_BD = extra;
	} 
	tte_stop_ticking();
	printf("sched errors: %d\n",sched_errors);
	printf("received tte: %d\n",tte);
	printf("received eth: %d\n",eth); 
	for (int i =10; i<n; i++){ //logging
		printf("%lld %lld %lld\n",sched_point[i],send_times[i-10],rec_point[i]);
	}
	return;
}
Exemplo n.º 11
0
int EthernetInterface::init() {
    use_dhcp = true;
    set_mac_address();
    init_netif(NULL, NULL, NULL);
    return 0;
}
Exemplo n.º 12
0
/* Open/initialize the board.  This is called (in the current kernel)
   sometime after booting when the 'ifconfig' program is run.

   This routine should set everything up anew at each open, even
   registers that "should" only need to be set once at boot, so that
   there is non-reboot way to recover if something goes wrong.
   */
static int
net_open(struct net_device *dev)
{
	struct net_local *lp = (struct net_local *)dev->priv;
	int result = 0;

	write_irq(dev, lp->chip_type, 0);

/*	irq2dev_map[0] = dev;   */
	writereg(dev, PP_BusCTL, 0); /* ints off! */

#ifdef CONFIG_UCSIMM
	*(volatile unsigned short *)0xfffff302 |= 0x0080; /* +ve pol irq */
	dev->irq = IRQ5_IRQ_NUM;
        if (request_irq(dev->irq | IRQ_MACHSPEC,
                        cs8900_interrupt,
                        IRQ_FLG_STD,
                        "CrystalLAN_cs8900a", NULL))
                panic("Unable to attach cs8900 intr\n");
#endif

#ifdef CONFIG_ARCH_ATMEL
	/* Set IRQ1 with high level sensitive & priority level 6. */
	*(volatile unsigned int *) AIC_SMR(IRQ_IRQ1) = 0x46;

	/* We use IRQ_IRQ1 for the network interrupt */
	dev->irq = IRQ_IRQ1;
        if (request_irq(dev->irq,
                        cs8900_interrupt,
                        IRQ_FLG_STD,
                        "CrystalLAN_cs8900a", NULL))
                panic("Unable to attach cs8900 intr\n");                        
#endif

#if defined (CONFIG_BOARD_UCLINKII)     || \
    defined (CONFIG_BOARD_EVS3C4530LII) || \
    defined (CONFIG_BOARD_EVS3C4530HEI)
	
	*(volatile unsigned int *)IOPCON0 |= (xINTREQ0_ENABLE | xINTREQ0_ACT_HI);
	dev->irq = _IRQ0;
	if (request_irq (dev->irq, cs8900_interrupt, 0,
			 "Crystal_CS8900", dev))
 	  panic("Unable to attach cs8900 intr\n");
#endif

#ifdef CONFIG_ALMA_ANS
	/* We use positive polarity IRQ3 as a network interrupt */
	ICR |= ICR_POL3;
	dev->irq = IRQ3_IRQ_NUM;
	if (request_irq(dev->irq | IRQ_MACHSPEC,
                        cs8900_interrupt,
                        IRQ_FLG_STD,
                        "CrystalLAN_cs8900a", NULL))
                panic("Unable to attach cs8900 intr\n");                        
#endif

	/* set the Ethernet address */
	set_mac_address(dev, dev->dev_addr);

	/* Set the LineCTL */
	lp->linectl = 0;

        /* check to make sure that they have the "right" hardware available */
	switch(lp->adapter_cnf & A_CNF_MEDIA_TYPE) {
	case A_CNF_MEDIA_10B_T:
		result = lp->adapter_cnf & A_CNF_10B_T;
		break;
	case A_CNF_MEDIA_AUI:
		result = lp->adapter_cnf & A_CNF_AUI;
		break;
	case A_CNF_MEDIA_10B_2:
		result = lp->adapter_cnf & A_CNF_10B_2;
		break;
        default:
		result = lp->adapter_cnf & 
		         (A_CNF_10B_T | A_CNF_AUI | A_CNF_10B_2);
        }
        if (!result) {
                printk("%s: EEPROM is configured for unavailable media\n", dev->name);
        release_irq:
                writereg(dev, PP_LineCTL, readreg(dev, PP_LineCTL) & ~(SERIAL_TX_ON | SERIAL_RX_ON));
		/* so subsequent opens don't fail we release the IRQ ...MaTed--- */
		free_irq( dev->irq, dev);
/*                irq2dev_map[dev->irq] = 0;    */
		return -EAGAIN;
	}

        /* set the hardware to the configured choice */
	switch(lp->adapter_cnf & A_CNF_MEDIA_TYPE) {
	case A_CNF_MEDIA_10B_T:
                result = detect_tp(dev);
                if (!result) { 
		  printk("%s: 10Base-T (RJ-45) has no cable\n", dev->name);
		  if (lp->auto_neg_cnf & IMM_BIT) { /* check "ignore missing media" bit */
		    printk("%s: but ignore the fact.\n", dev->name);
		    result = A_CNF_MEDIA_10B_T; /* Yes! I don't care if I see a link pulse */
		  }
                }
		break;
	case A_CNF_MEDIA_AUI:
	  printk("AUI is not supported by uCcs8900\n");
		break;
	case A_CNF_MEDIA_10B_2:
	  printk("10Base2 is not supported by uCcs8900\n");
		break;
	case A_CNF_MEDIA_AUTO:
		writereg(dev, PP_LineCTL, lp->linectl | AUTO_AUI_10BASET);
		if (lp->adapter_cnf & A_CNF_10B_T)
			if ((result = detect_tp(dev)) != 0)
				break;

		printk("%s: no media detected\n", dev->name);
                goto release_irq;
	}
	switch(result) {
	case 0: printk("%s: no network cable attached to configured media\n", dev->name);
                goto release_irq;
	case A_CNF_MEDIA_10B_T: printk("%s: using 10Base-T (RJ-45)\n", dev->name);break;
	case A_CNF_MEDIA_AUI:   printk("%s: using 10Base-5 (AUI)\n", dev->name);break;
	case A_CNF_MEDIA_10B_2: printk("%s: using 10Base-2 (BNC)\n", dev->name);break;
	default: printk("%s: unexpected result was %x\n", dev->name, result); goto release_irq;
	}

	/* Turn on both receive and transmit operations */
	writereg(dev, PP_LineCTL, readreg(dev, PP_LineCTL) | SERIAL_RX_ON | SERIAL_TX_ON);

	/* Receive only error free packets addressed to this card */
	lp->rx_mode = 0;
	writereg(dev, PP_RxCTL, DEF_RX_ACCEPT);

	lp->curr_rx_cfg = RX_OK_ENBL | RX_CRC_ERROR_ENBL;
	if (lp->isa_config & STREAM_TRANSFER)
		lp->curr_rx_cfg |= RX_STREAM_ENBL;

	writereg(dev, PP_RxCFG, lp->curr_rx_cfg);

	writereg(dev, PP_TxCFG, TX_LOST_CRS_ENBL | TX_SQE_ERROR_ENBL | TX_OK_ENBL |
	       TX_LATE_COL_ENBL | TX_JBR_ENBL | TX_ANY_COL_ENBL | TX_16_COL_ENBL);

	writereg(dev, PP_BufCFG, READY_FOR_TX_ENBL | RX_MISS_COUNT_OVRFLOW_ENBL |
		 TX_COL_COUNT_OVRFLOW_ENBL | TX_UNDERRUN_ENBL);

	/* now that we've got our act together, enable everything */
	writereg(dev, PP_BusCTL, ENABLE_IRQ );
	
	netif_start_queue(dev);
	
	return 0;
}