コード例 #1
0
ファイル: ne2100.c プロジェクト: yeonsh/Amoeba
/*
 * Get ethernet address and compute checksum to be sure
 * that there is a board at this address.
 */
int
eth_init()
{
    uint16 checksum, sum;
    register int i;

    for (i = 0; i < 6; i++)
	eth_myaddr[i] = in_byte(NE_BASEREG + i);

    sum = 0;
    for (i = 0x00; i <= 0x0B; i++)
	sum += in_byte(NE_BASEREG + i);
    for (i = 0x0E; i <= 0xF; i++)
	sum += in_byte(NE_BASEREG + i);
    checksum = in_byte(NE_BASEREG + 0x0C) | (in_byte(NE_BASEREG + 0x0D) << 8);
    if (sum != checksum)
	return 0;

    /* initblock, tmd, and rmd should be 8 byte aligned ! */
    initblock = (initblock_t *) aalloc(sizeof(initblock_t), 8);
    tmd = (tmde_t *) aalloc(sizeof(tmde_t), 8);
    rmd = (rmde_t *) aalloc(NRCVRING * sizeof(rmde_t), 8);
    eth_reset();
    return 1;
}
コード例 #2
0
ファイル: jz_cs8900.c プロジェクト: carlos-wong/uboot_jz4755
static int jz_eth_init (struct eth_device* dev, bd_t * bd)
{
    u16 id;
	
    dev = dev;
   
	
    /* verify chip id */
	id = get_reg_init_bus (PP_ChipID);
	if (id != 0x630e) {
		printf ("CS8900 jz_eth_init error!\n");
		return 0;
	}

	eth_reset ();
	/* set the ethernet address */
	//printf("MAC = %02x:%02x:%02x:%02x:%02x:%02x\r\n",
	//	   bd->bi_enetaddr[5],bd->bi_enetaddr[4],
	//	   bd->bi_enetaddr[3],bd->bi_enetaddr[2],
	//	   bd->bi_enetaddr[1],bd->bi_enetaddr[0]);
	
	put_reg (PP_IA + 0, bd->bi_enetaddr[0] | (bd->bi_enetaddr[1] << 8));
	put_reg (PP_IA + 2, bd->bi_enetaddr[2] | (bd->bi_enetaddr[3] << 8));
	put_reg (PP_IA + 4, bd->bi_enetaddr[4] | (bd->bi_enetaddr[5] << 8));

	eth_reginit ();
	return 0;
}
コード例 #3
0
void cs8900_get_enetaddr (void)
{
	int i;
	uchar enetaddr[6];

	/* if the env is setup, then bail */
	if (eth_getenv_enetaddr("ethaddr", enetaddr))
		return;

	/* verify chip id */
	if (get_reg_init_bus (PP_ChipID) != 0x630e)
		return;
	eth_reset ();
	if ((get_reg (PP_SelfSTAT) & (PP_SelfSTAT_EEPROM | PP_SelfSTAT_EEPROM_OK)) ==
			(PP_SelfSTAT_EEPROM | PP_SelfSTAT_EEPROM_OK)) {

		/* Load the MAC from EEPROM */
		for (i = 0; i < 6 / 2; i++) {
			unsigned int Addr;

			Addr = get_reg (PP_IA + i * 2);
			enetaddr[i * 2] = Addr & 0xFF;
			enetaddr[i * 2 + 1] = Addr >> 8;
		}

		eth_setenv_enetaddr("ethaddr", enetaddr);
		debug("### Set environment from HW MAC addr = \"%pM\"\n", enetaddr);
	}
}
コード例 #4
0
ファイル: jz_cs8900.c プロジェクト: carlos-wong/uboot_jz4755
static void cs8900_get_enetaddr (uchar * addr)
{
	int i;
	unsigned char env_enetaddr[6];
	char *tmp = getenv ("ethaddr");
	char *end;

	for (i=0; i<6; i++) {
		env_enetaddr[i] = tmp ? simple_strtoul(tmp, &end, 16) : 0;
		if (tmp)
			tmp = (*end) ? end+1 : end;
	}

	/* verify chip id */
	if (get_reg_init_bus (PP_ChipID) != 0x630e)
		return;
	eth_reset ();
	if ((get_reg (PP_SelfST) & (PP_SelfSTAT_EEPROM | PP_SelfSTAT_EEPROM_OK)) ==
			(PP_SelfSTAT_EEPROM | PP_SelfSTAT_EEPROM_OK)) {

		/* Load the MAC from EEPROM */
		for (i = 0; i < 6 / 2; i++) {
			unsigned int Addr;

			Addr = get_reg (PP_IA + i * 2);
			addr[i * 2] = Addr & 0xFF;
			addr[i * 2 + 1] = Addr >> 8;
		}

		if (memcmp(env_enetaddr, "\0\0\0\0\0\0", 6) != 0 &&
		    memcmp(env_enetaddr, addr, 6) != 0) {
			printf ("\nWarning: MAC addresses don't match:\n");
			printf ("\tHW MAC address:  "
				"%02X:%02X:%02X:%02X:%02X:%02X\n",
				addr[0], addr[1],
				addr[2], addr[3],
				addr[4], addr[5] );
			printf ("\t\"ethaddr\" value: "
				"%02X:%02X:%02X:%02X:%02X:%02X\n",
				env_enetaddr[0], env_enetaddr[1],
				env_enetaddr[2], env_enetaddr[3],
				env_enetaddr[4], env_enetaddr[5]) ;
			debug ("### Set MAC addr from environment\n");
			memcpy (addr, env_enetaddr, 6);
		}
		if (!tmp) {
			char ethaddr[20];
			sprintf (ethaddr, "%02X:%02X:%02X:%02X:%02X:%02X",
				 addr[0], addr[1],
				 addr[2], addr[3],
				 addr[4], addr[5]) ;
			debug ("### Set environment from HW MAC addr = \"%s\"\n",				ethaddr);
			setenv ("ethaddr", ethaddr);
		}

	}
}
コード例 #5
0
ファイル: cs8900.c プロジェクト: bk1472/d2a_prj
/* Send a data block via Ethernet. */
extern int eth_send (volatile void *packet, int length)
{
	volatile unsigned short *addr;
	int tmo;
	unsigned short s;

retry:
	/* initiate a transmit sequence */
	CS8900_TxCMD = PP_TxCmd_TxStart_Full;
	CS8900_TxLEN = length;

	/* Test to see if the chip has allocated memory for the packet */
	if ((get_reg (PP_BusSTAT) & (PP_BusSTAT_TxRDY)) == 0) {
		/* Oops... this should not happen! */
#ifdef DEBUG
		printf ("cs: unable to send packet; retrying...\n");
#endif
		for (tmo = get_timer (0) + 5 * CFG_HZ; get_timer (0) < tmo;)
			/*NOP*/;
		eth_reset ();
		eth_reginit ();
		goto retry;
	}

	/* Write the contents of the packet */
	/* assume even number of bytes */
	for (addr = packet; length > 0; length -= 2)
	{
		unsigned short data = *addr;
		CS8900_RTDATA = SW(data);
		addr++;
	}

	/* wait for transfer to succeed */
	tmo = get_timer (0) + 5 * CFG_HZ;
	while ((s = get_reg (PP_TER) & ~0x1F) == 0) {
		if (get_timer (0) >= tmo)
			break;
	}

	/* nothing */ ;
	if ((s & (PP_TER_CRS | PP_TER_TxOK)) != PP_TER_TxOK) {
#ifdef DEBUG
		printf ("\ntransmission error %#x\n", s);
#endif
	}

	return 0;
}
コード例 #6
0
int retrieve_VotingErrorCounts(unsigned int* counters){
  if(DEBUG>10) std::cout<<"DEBUG[commands.cpp]  retrieve_VotingErrorCounts("<<*counters<<")"<<std::endl;
// *** the counters array *must* have places for at least 12 elements
// fill coutners array
// return value!=0 indicates failure

  //// testing >>>
  /*
  if(time(0)%10==0) counters[0]++;
  if(time(0)%10==1) counters[1]++;
  if(time(0)%10==2) counters[2]++;
  if(time(0)%10==3) counters[3]++;
  if(time(0)%10==4) counters[4]++;
  if(time(0)%10==5) counters[5]++;
  if(time(0)%10==3) counters[6]++;
  if(time(0)%10==4) counters[7]++;
  if(time(0)%10==5) counters[8]++;
  if(time(0)%10==6) counters[9]++;
  if(time(0)%10==7) counters[10]++;
  if(time(0)%10==6) counters[11]++;
  return 0;
  */
  // <<< testing

  int commandnum=5;

  eth_reset();  // first, clear the buffers

  if(write_command(commandnum) != 0){
    if(DEBUG>10) std::cout<<"DEBUG[commands.cpp]  retrieve_VotingErrorCounts return -1  <== error sending command"<<std::endl;
    return -1;  // send command
  }
  char* pkt;
  if(read_command(&pkt) != commandnum){
    if(DEBUG>10) std::cout<<"DEBUG[commands.cpp]  retrieve_VotingErrorCounts return -2  <== error reading command"<<std::endl;
    return -2;  // get responce
  }
  if(sizeof(int)!=4){ // make sure int is 4 bytes
    std::cerr<<"ERROR: sizeof(int)="<<sizeof(int)<<"  This code assume sizeof(int)==4!"<<std::endl;
    return -3;
  }
  memcpy(counters, (const void*)&pkt[2], 12*4);  // fill error counts: 12x 4-byte counters
  // Note: this will thrash memory if the counters array does not have 12 places!
  // It is also possible that the bytes in the array are reversed from how they should be in the int, which will take more work to unpack

  if(DEBUG>10) std::cout<<"DEBUG[commands.cpp]  retrieve_VotingErrorCounts return 0"<<std::endl;
  return 0;
}
コード例 #7
0
ファイル: cs8900.c プロジェクト: dsdbook/dsd_sopc
int eth_init (bd_t * bd)
{
	/* verify chip id */
	if (get_reg_init_bus (PP_ChipID) != 0x630e) {
		printf ("CS8900 Ethernet chip not found?!\n");
		return 0;
	}

	eth_reset ();
	/* set the ethernet address */
	put_reg (PP_IA + 0, bd->bi_enetaddr[0] | (bd->bi_enetaddr[1] << 8));
	put_reg (PP_IA + 2, bd->bi_enetaddr[2] | (bd->bi_enetaddr[3] << 8));
	put_reg (PP_IA + 4, bd->bi_enetaddr[4] | (bd->bi_enetaddr[5] << 8));

	eth_reginit ();
	return 0;
}
コード例 #8
0
int send_RAMPage(int pageid, char* block){
  if(DEBUG>10) std::cout<<"DEBUG[commands.cpp]  send_RAMPage("<<pageid<<",{"<<HEX(0xff&block[0])<<HEX(0xff&block[1])<<"...})"<<std::endl;
// *** block must be at least a 4KB buffer
// pageid should be a page number of RAM
// fill block buffer with 4KB block
// return value!=0 indicates failure

  int commandnum=7;
  //nn=0;  // testing

  eth_reset();  // first, clear all the buffers
  
  if(write_command(commandnum, pageid, block) != 0){
    if(DEBUG>10) std::cout<<"DEBUG[commands.cpp]  send_RAMPage return -1  <== error sending command"<<std::endl;
    return -1;  // send command
  }
  
  char* pkt;
  int errnum = read_command(&pkt);

  if(errnum == commandnum){
    // a final check that the address that the board said it wrote actually matches what we wanted
    char tmp[2];
    tmp[0]=pageid&0x00ff;
    tmp[1]=(pageid&0xff00)>>8;
    if(DEBUG>20){
      std::cout<<"DEBUG[commands.cpp]  send_RAMPage, compare address bytes:"<<std::endl;
      std::cout<<HEX(tmp[0])<<" "<<HEX(pkt[2]&0xff)<<std::endl;
      std::cout<<HEX(tmp[1])<<" "<<HEX(pkt[3]&0xff - 0xd0)<<std::endl;
      std::cout<<DEC();
    }
    if( (tmp[0]&0xff) != (pkt[2]&0xff) ||
	(tmp[1]&0xff) != ((pkt[3]&0xff) - 0xd0) ){
      if(DEBUG>10){
	std::cout<<"DEBUG[commands.cpp]  Address word does not match pageid("<<HEX(pageid)<<") : "<<HEX(pkt[2]&0xff)<<HEX(pkt[3]&0xff)<<DEC()<<std::endl;
      }
      if(DEBUG>10) std::cout<<"DEBUG[commands.cpp]  send_RAMPage return 98"<<std::endl;
      return 98;  
    }
    if(DEBUG>10) std::cout<<"DEBUG[commands.cpp]  send_RAMPage return 0"<<std::endl;
    return 0;  
  }else if(errnum == -commandnum){
コード例 #9
0
ファイル: cs8900.c プロジェクト: kangear/S-BOOT
//int eth_init (bd_t * bd)
int eth_init ()
{
	/* verify chip id */
	if (get_reg_init_bus (PP_ChipID) != 0x630e) {
		printf ("CS8900 Ethernet chip not found?!\n");
		return 0;
	}

	eth_reset ();
	/* set the ethernet address */
	//put_reg (PP_IA + 0, 0x09 | 0x00 << 8);
	//put_reg (PP_IA + 2, 0xD8 | 0x58 << 8);
	//put_reg (PP_IA + 4, 0x22 | 0x11 << 8);

	put_reg (PP_IA + 0, 0x00 | 0x09 << 8);
	put_reg (PP_IA + 2, 0x58 | 0xD8 << 8);
	put_reg (PP_IA + 4, 0x11 | 0x22 << 8);
	eth_reginit ();
	return 0;
}
コード例 #10
0
  int eth_init (bd_t * bd)
{
	uchar enetaddr[6];

	gpio_init_cs8900();
	/* verify chip id */
	if (get_reg_init_bus (PP_ChipID) != 0x630e) {
		printf ("CS8900 Ethernet chip not found?!\n");
		return 0;
	}

	eth_reset ();
	/* set the ethernet address */
	eth_getenv_enetaddr("ethaddr", enetaddr);
	put_reg (PP_IA + 0, enetaddr[0] | (enetaddr[1] << 8));
	put_reg (PP_IA + 2, enetaddr[2] | (enetaddr[3] << 8));
	put_reg (PP_IA + 4, enetaddr[4] | (enetaddr[5] << 8));

	eth_reginit ();
	return 0;
}
コード例 #11
0
int retrieve_TranslatorErrorCounts(unsigned short* counters){
  if(DEBUG>10) std::cout<<"DEBUG[commands.cpp]  retrieve_TranslatorErrorCounts("<<*counters<<")"<<std::endl;
// *** the counters array *must* have places for at least 24 elements
// fill coutners array
// return value!=0 indicates failure

  //// testing >>>
  //counters[0]++;
  //counters[0]++;
  //if(time(0)%20==11) counters[0]++;
  //return 0;
  // <<< testing

  int commandnum=2;

  eth_reset();  // first, clear all the buffers
  
  if(write_command(commandnum) != 0){
    if(DEBUG>10) std::cout<<"DEBUG[commands.cpp]  retrieve_TranslatorErrorCounts return -1  <== error sending command"<<std::endl;
    return -1;  // send command
  }

  char* pkt;
  if(read_command(&pkt) != commandnum){
    if(DEBUG>10) std::cout<<"DEBUG[commands.cpp]  retrieve_TranslatorErrorCounts return -2  <== error reading command"<<std::endl;
    return -2;  // get responce
  }

  if(sizeof(short)!=2){ // make sure short is 2 bytes
    std::cerr<<"ERROR: sizeof(short)="<<sizeof(short)<<"  This code assume sizeof(short)==2!"<<std::endl;
    return -3;
  }

  memcpy(counters, (const void*)&pkt[2], 24*2);  // fill error counts: 24x 2-byte counters
  // this will thrash memory if the counters array does not have 24 places!
  // Also, bytes in the array are probably reversed from how they should be for a short.  If so, that will have to be fixed!
  
  if(DEBUG>10) std::cout<<"DEBUG[commands.cpp]  retrieve_TranslatorErrorCounts return 0"<<std::endl;
  return 0;  
}