Example #1
0
void
metering_init(void)
{
  /* Load reference values from EEPROM */
  metering_reference_value = eeprom_read_word((void*) EE_METERING_REF );
  metering_calibration_power = eeprom_read_word((void*)EE_METERING_CAL_LOAD);

#if METERING_ENERGY
  // reset energy metering value
  metering_pulses = metering_pulses_total = 0;
#if METERING_ENERGY_PERSISTENT
  DDRB &= ~(1 << METERING_POWERDOWN_DETECT_PIN); // Set PB3 as input -> Cut trace to relay, add voltage divider instead.
  DDRB &= ~(1 << METERING_ANALOG_COMPARATOR_REF_PIN); // Set PB2 as input
  PORTB &= ~(1 << METERING_POWERDOWN_DETECT_PIN); // no internal pullup
  PORTB &= ~(1 << METERING_ANALOG_COMPARATOR_REF_PIN); // no internal pullup
  ENABLE_POWERDOWN_INTERRUPT();
  sei(); // global interrupt enable

  eeprom_read((uint8_t*)EE_ENERGY_METERING_PULSES_TOTAL, (uint8_t*)&metering_pulses_total, sizeof(metering_pulses));
  eeprom_read((uint8_t*)EE_ENERGY_METERING_PULSES, (uint8_t*)&metering_pulses, sizeof(metering_pulses));
#endif // METERING_ENERGY_PERSISTENT
#endif // METERING_ENERGY

  SET_METERING_INT();

  metering_start();

	ENDPOINT_REGISTER(endpoint_power);
#if METERING_ENERGY
	ENDPOINT_REGISTER(endpoint_energy_total);
	ENDPOINT_REGISTER(endpoint_energy);
#endif
}
Example #2
0
/*==============================================================================
Name    : read_settings_from_eeprom
--------------------------------------------------------------------------------
Purpose : Will read settings from EEPROM
Input   :
Output  :
Notes   : Data is stored in 'eeprom_gv_block[]' in the format shown above
==============================================================================*/
void read_settings_from_eeprom(void)
{
   uint8_t i;
   /* Read Global configuration */
   qt_config_data.qt_recal_threshold =(recal_threshold_t)
      eeprom_read(EEPROM_LIB_CONFIG_START_ADDRESS + 0u);
   qt_config_data.qt_di              =
      eeprom_read(EEPROM_LIB_CONFIG_START_ADDRESS + 1u);
   qt_config_data.qt_drift_hold_time =
      eeprom_read(EEPROM_LIB_CONFIG_START_ADDRESS + 2u);
   qt_config_data.qt_max_on_duration =
      eeprom_read(EEPROM_LIB_CONFIG_START_ADDRESS + 3u);
   qt_config_data.qt_neg_drift_rate  =
      eeprom_read(EEPROM_LIB_CONFIG_START_ADDRESS + 4u);
   qt_config_data.qt_pos_drift_rate  =
      eeprom_read(EEPROM_LIB_CONFIG_START_ADDRESS + 5u);
   qt_config_data.qt_pos_recal_delay =
      eeprom_read(EEPROM_LIB_CONFIG_START_ADDRESS + 6u);
   /* Read Sensor specific configuration */
   for(i = 0u; i < num_sensors; i++)
   {
      sensors[i].threshold =
         eeprom_read(EEPROM_LIB_CONFIG_START_ADDRESS + 7u + (i * 2u));
      sensors[i].type_aks_pos_hyst =
         eeprom_read(EEPROM_LIB_CONFIG_START_ADDRESS + 8u + (i * 2u));
   }
   /* Read burst length for all channels */
   #ifdef _QMATRIX_
      uint16_t address = EEPROM_LIB_CONFIG_START_ADDRESS + 7u + (num_sensors * 2u);
      for(i = 0u; i < QT_NUM_CHANNELS; i++)
      {
         qt_burst_lengths[i] = eeprom_read((address + i));
      }
   #endif
}
Example #3
0
//**************************************************************************
void eeprom_apply_settings(void)
{
  if(eeprom_read(contrast_address)!=Settings.contrast)       
	{
		display_off();
		delay_ms(200);
		display_on();
	}
	// -------------------------------------------------------------------
  if(eeprom_read(Display_reverse_address)!=Settings.Display_reverse)
	{
		display_off();
		delay_ms(200);
		display_on();
	}
	// -------------------------------------------------------------------
  if(eeprom_read(v4_target_pump_address)!=Settings.v4_target_pump)
	{
		reset_TIM_prescallers_and_Compare();	
	}
	// -------------------------------------------------------------------
	if(eeprom_read(Geiger_voltage_address) !=Settings.Geiger_voltage) 
 	{
		dac_reload(); //перезагрузить в ЦАП новое напряжение отсечки накачки
 	}
	// -------------------------------------------------------------------
	if(eeprom_read(LSI_freq_address)       !=Settings.LSI_freq)
  {
		if(Settings.LSI_freq != 0x00) // если запустился кварц, попытки сохранения игнорировать
		{
			eeprom_write(LSI_freq_address,Settings.LSI_freq);   NVIC_SystemReset();
		}
	}
}
Example #4
0
/***********************************************************************
		module		:	[WIFI]
		function	:	[连接网络]
  		return		:	[无]
		comment		:	[全局普通函数]
		machine		:	[EH-0818]
		language	:	[CHN]
 		keyword		:	[WIFI]
		date		:	[11/07/27]
 		author		:	[chen-zhengkai]
************************************************************************/
void connectWifi()
{
	//u16 pHandle[1] = {0};	//wifi连接句柄
	//unsigned char pHandle_char[2] = {0};	//wifi连接句柄存放数组
	char dspBuf[20] = {0};
	char serverPort[20] = {0};
	unsigned char serverIPAdd[16] = {0};
	
	//CWiFi_OpenMould();
	if (eeprom_read(serverIPAdd, sizeof(serverIPAdd), EEPROM_OFFSET_SERVERIPADD)) {
		strcpy(dspBuf, "读取IP失败");
	}
	if (eeprom_read(serverPort, 8, EEPROM_OFFSET_SERVERPORT)) {
		strcpy(dspBuf, "读取端口失败");
	}
	else if(NaNo_OK == CWiFi_Connect(g_pHandle, (char*)serverIPAdd, serverPort, 0)) {
		strcpy(dspBuf, "连接成功");
		//shortTochar(g_pHandle, pHandle_char);
		//eeprom_write(pHandle_char, sizeof(pHandle_char), EEPROM_OFFSET_WIFI_HANDLE);
	}
	else {
		//..注:若连接失败,则需要30秒后再次连接
		strcpy(dspBuf, "连接失败");
		CWiFi_ConnState(0);
	}

	DispStr_CE(0,6,dspBuf,DISP_CENTER|DISP_NORMAL|DISP_CLRSCR);
	DispStr_CE(0,8,"按任意键继续",DISP_CENTER);
	delay_and_wait_key( 3, EXIT_KEY_ALL, 0 );
}
void eeprom_restore_data()
{
    uint8_t buf_req[200] = {0};  // ThingSet request buffer, initialize with zeros

    // EEPROM header
    uint8_t buf_header[EEPROM_HEADER_SIZE];
    if (eeprom_read(0, buf_header, EEPROM_HEADER_SIZE) < 0) {
        printf("EEPROM: read error!\n");
        return;
    }
    uint16_t version = *((uint16_t*)&buf_header[0]);
    uint16_t len     = *((uint16_t*)&buf_header[2]);
    uint32_t crc     = *((uint32_t*)&buf_header[4]);

    //printf("EEPROM header restore: ver %d, len %d, CRC %.8x\n", version, len, (unsigned int)crc);
    //printf("Header: %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x\n",
    //    buf_header[0], buf_header[1], buf_header[2], buf_header[3],
    //    buf_header[4], buf_header[5], buf_header[6], buf_header[7]);

    if (version == EEPROM_VERSION && len <= sizeof(buf_req)) {
        eeprom_read(EEPROM_HEADER_SIZE, buf_req, len);

        //printf("Data (len=%d): ", len);
        //for (int i = 0; i < len; i++) printf("%.2x ", buf_req[i]);

        if (_calc_crc(buf_req, len) == crc) {
            int status = ts.init_cbor(buf_req, sizeof(buf_req));     // first byte is ignored
            printf("EEPROM: Data objects read and updated, ThingSet result: %d\n", status);
        }
        else {
            printf("EEPROM: CRC of data not correct, expected 0x%x (data_len = %d)\n", (unsigned int)crc, len);
        }
    }
}
boolean calLibRead(byte device, CALLIB_DATA *calData)
{
  byte *ptr = (byte *)calData;
  byte length = sizeof(CALLIB_DATA);
  int eeprom = MPU9150_CAL + sizeof(CALLIB_DATA) * device;

  calData->magValid = false;
  calData->accelValid = false;

  char d[2];
  memset(d, 0, sizeof d);
  eeprom_read(&d[0], eeprom, 1);
  eeprom_read(&d[1], eeprom+1, 1);
  if ((d[0] != CALLIB_DATA_VALID_LOW) ||
      (d[1] != CALLIB_DATA_VALID_HIGH)) {
    printf("NO CALIBRATION DATA FOUND\n");
    return false;                                  // invalid data
  }
    
  for (unsigned i = 0; i < length; i++)
    eeprom_read(ptr++, eeprom + i, 1);

  printf("Calibration data found\n");
  return true;  
}
Example #7
0
File: xpl.c Project: cobree/hasy
//////////////////////////////////////////////////////////
// xpl_init_instance_id
// Get the instance id from EEPROM, and set to 'default'
//  if no ID is present in the EEPROM
void xpl_init_instance_id(void) {
    char count;

	xpl_node_configuration = 0;

	// Get the instance ID from EEPROM
	// Maximum size = 16 chars + 1 null char
	for (count = 0; count < 16; count++){
		xpl_instance_id[count] = eeprom_read(count+XPL_EEPROM_INSTANCE_ID_OFFSET);

		// When we encounter the null, stop reading
		if (xpl_instance_id[count] == '\0') { 
			xpl_node_configuration |= NODE_CONFIGURED;
			break;
		} 

		// When the first char is 0xFF, flash is uninitialised
		if (count == 0 && xpl_instance_id[0] == 0xFF) {
			sprintf(xpl_instance_id, "default");
			eeprom_write(XPL_EEPROM_OUPUTS_COUNT,'0');
            eeprom_write(XPL_EEPROM_INPUTS_COUNT,'0');
			break;
		}
	}
	output_count = eeprom_read(XPL_EEPROM_OUPUTS_COUNT);
	input_count = eeprom_read(XPL_EEPROM_INPUTS_COUNT);
}    
Example #8
0
unsigned int load_int_from_eeprom( unsigned char add )
{
  unsigned int a;
  a = eeprom_read( add );
  a <<= 8;
  a += eeprom_read( add + 1 );
  return a;
}
Example #9
0
void read_alerts()
{
unsigned char i=0;
a.min=eeprom_read(0);
a.hour=eeprom_read(1);
a.ae=eeprom_read(2);
for (i=3; i<10; i++) a.dow[i-3]=eeprom_read(i);
t_delay=eeprom_read(10);
}
Example #10
0
unsigned int is_valid_card(){
	eeprom_read(0x00);
	eeprom_read(0x00);
	if (dataword==0xe8){
		return 1;
	} else {
		return 0;
	}
}
Example #11
0
/*==============================================================================
Name    : read_info_from_eeprom
--------------------------------------------------------------------------------
Purpose : Read Info block from EEPROM
Input   :
Output  :
Notes   : Returns library version currently on chip
==============================================================================*/
uint16_t read_info_from_eeprom( void )
{
   uint16_t rtnval;

   /* The first two bytes stored in EEPROM is the library version */
   rtnval = (uint16_t)(eeprom_read(EEPROM_START_ADDRESS));
   rtnval |= (uint16_t)(eeprom_read(EEPROM_START_ADDRESS + 1u)) << 8u;
   return rtnval;
}
Example #12
0
unsigned int firmware_get_sector_length(unsigned char sector)
{
    unsigned int length;

    // little endian...
    length  = ( (unsigned int) eeprom_read(2L*sector + 1) ) << 8;
    length += eeprom_read(2L*sector);

    return length;
}
Example #13
0
static int
ex_isa_attach(device_t dev)
{
    struct ex_softc *	sc = device_get_softc(dev);
    int			error = 0;
    u_int16_t		temp;

    sc->dev = dev;
    sc->ioport_rid = 0;
    sc->irq_rid = 0;

    if ((error = ex_alloc_resources(dev)) != 0) {
        device_printf(dev, "ex_alloc_resources() failed!\n");
        goto bad;
    }

    /*
     * Fill in several fields of the softc structure:
     *	- I/O base address.
     *	- Hardware Ethernet address.
     *	- IRQ number (if not supplied in config file, read it from EEPROM).
     *	- Connector type.
     */
    sc->iobase = rman_get_start(sc->ioport);
    sc->irq_no = rman_get_start(sc->irq);

    ex_get_address(sc->iobase, sc->arpcom.ac_enaddr);

    temp = eeprom_read(sc->iobase, EE_W0);
    device_printf(sc->dev, "%s config, %s bus, ",
                  (temp & EE_W0_PNP) ? "PnP" : "Manual",
                  (temp & EE_W0_BUS16) ? "16-bit" : "8-bit");

    temp = eeprom_read(sc->iobase, EE_W6);
    printf("board id 0x%03x, stepping 0x%01x\n",
           (temp & EE_W6_BOARD_MASK) >> EE_W6_BOARD_SHIFT,
           temp & EE_W6_STEP_MASK);

    if ((error = ex_attach(dev)) != 0) {
        device_printf(dev, "ex_attach() failed!\n");
        goto bad;
    }

    error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET,
                           ex_intr, (void *)sc, &sc->ih);
    if (error) {
        device_printf(dev, "bus_setup_intr() failed!\n");
        goto bad;
    }

    return(0);
bad:
    ex_release_resources(dev);
    return (error);
}
Example #14
0
////////////////////////////////////////////////////////////
// LOAD PORT INFO FROM EEPROM
void loadPortInfo(byte forceReload)
{
	byte cs = 0;
	for(int i=0; i<NUM_PORTS; ++i)
	{
		PORT_INFO *p = port[i];
		memset(p, 0, sizeof(PORT_INFO));
		
		int eepromAddr = 16 * i;
		p->cfg.triggerChannel 	 = eeprom_read(eepromAddr + 0);
		p->cfg.triggerNote 		 = eeprom_read(eepromAddr + 1);
		p->cfg.durationMax		 = (int)eeprom_read(eepromAddr + 2) << 8;
		p->cfg.durationMax	    |= (int)eeprom_read(eepromAddr + 3);
		p->cfg.durationModulator = eeprom_read(eepromAddr + 4);
		p->cfg.dutyMax			 = eeprom_read(eepromAddr + 5);
		p->cfg.dutyModulator	 = eeprom_read(eepromAddr + 6);		
		byte flags = eeprom_read(eepromAddr + 7);
		p->cfg.invert = !!(flags & EEPROM_FLAG_INVERT);
		
		// default to full duration/duty
		p->status.duration = p->cfg.durationMax;
		p->status.duty = p->cfg.dutyMax;
		
		calcCheckSum((byte*)&p->cfg, sizeof(PORT_CONFIG), &cs); 
	}
	
	if(forceReload || eeprom_read(EEPROM_ADDR_CHECKSUM) != cs)
	{
		// failed checksum (possibly no previous stored config)
		flashLed(10);
		initPortInfo();
		savePortInfo();
	}
}
Example #15
0
static void read_mac(void) {
	if (has_eeprom) {
		uint32_t t;
		t = eeprom_read(0);
		mac[0] = t & 0xFF;
		mac[1] = t >> 8;
		t = eeprom_read(1);
		mac[2] = t & 0xFF;
		mac[3] = t >> 8;
		t = eeprom_read(2);
		mac[4] = t & 0xFF;
		mac[5] = t >> 8;
	} else {
Example #16
0
/*---------------------------------------------------------------------------*/
void
node_id_restore(void)
{
  unsigned char buf[2];
  eeprom_read(NODE_ID_EEPROM_OFFSET, buf, 2);
  if(buf[0] == 0xad &&
     buf[1] == 0xde) {
    eeprom_read(NODE_ID_EEPROM_OFFSET + 2, buf, 2);
    node_id = (buf[0] << 8) | buf[1];
  } else {
    node_id = 0;
  }
}
Example #17
0
/*****************************************************************************
 * read "factory" part of EEPROM and set some environment variables
 *****************************************************************************/
void read_factory_r (void)
{
	/* read 'factory' part of EEPROM */
	uchar buf[81];
	uchar *p;
	uint length;
	uint addr;
	uint len;

	/* get length first */
	addr = CFG_FACT_OFFSET;
	if (eeprom_read (CFG_I2C_FACT_ADDR, addr, buf, 2)) {
	  bailout:
		printf ("cannot read factory configuration\n");
		printf ("be sure to set ethaddr	yourself!\n");
		return;
	}
	length = buf[0] + (buf[1] << 8);
	addr += 2;

	/* sanity check */
	if (length < 20 || length > CFG_FACT_SIZE - 2)
		goto bailout;

	/* read lines */
	while (length > 0) {
		/* read one line */
		len = length > 80 ? 80 : length;
		if (eeprom_read (CFG_I2C_FACT_ADDR, addr, buf, len))
			goto bailout;
		/* mark end of buffer */
		buf[len] = 0;
		/* search end of line */
		for (p = buf; *p && *p != 0x0a; p++);
		if (!*p)
			goto bailout;
		*p++ = 0;
		/* advance to next line start */
		length -= p - buf;
		addr += p - buf;
		/*printf ("%s\n", buf); */
		/* search for our specific entry */
		if (!strncmp ((char *) buf, "[RLA/lan/Ethernet] ", 19)) {
			setenv ("ethaddr", (char *)(buf + 19));
		} else if (!strncmp ((char *) buf, "[BOARD/SERIAL] ", 15)) {
			setenv ("serial#", (char *)(buf + 15));
		} else if (!strncmp ((char *) buf, "[BOARD/TYPE] ", 13)) {
			setenv ("board_id", (char *)(buf + 13));
		}
	}
}
Example #18
0
static inline void _read_loramac_config(semtech_loramac_t *mac)
{
    DEBUG("[semtech-loramac] reading configuration from EEPROM\n");

    uint8_t magic[SEMTECH_LORAMAC_EEPROM_MAGIC_LEN] = {0};
    size_t pos = SEMTECH_LORAMAC_EEPROM_START;

    pos += eeprom_read(pos, magic, SEMTECH_LORAMAC_EEPROM_MAGIC_LEN);
    if (strncmp((char*)magic, "RIOT", SEMTECH_LORAMAC_EEPROM_MAGIC_LEN) != 0) {
        DEBUG("[semtech-loramac] no configuration present on EEPROM "
              "(invalid magic '%s')\n", magic);
        return;
    }

    /* LoRaWAN EUIs, Keys and device address */
    pos += eeprom_read(pos, mac->deveui, LORAMAC_DEVEUI_LEN);
    pos += eeprom_read(pos, mac->appeui, LORAMAC_APPEUI_LEN);
    pos += eeprom_read(pos, mac->appkey, LORAMAC_APPKEY_LEN);
    pos += eeprom_read(pos, mac->appskey, LORAMAC_APPSKEY_LEN);
    pos += eeprom_read(pos, mac->nwkskey, LORAMAC_NWKSKEY_LEN);
    pos += eeprom_read(pos, mac->devaddr, LORAMAC_DEVADDR_LEN);

    /* uplink counter, mainly used for ABP activation */
    uint8_t counter[4] = { 0 };
    pos += eeprom_read(pos, counter, 4);
    _set_uplink_counter(mac, counter);
}
Example #19
0
void Modbus(uint8_t u8serno, uint8_t u8txenpin)
{
    uint8_t tmpModbusId = eeprom_read(EE_MODBUS_ID);
    if(tmpModbusId == 0xff)
        tmpModbusId = DEFAULT_MODBUS_ID;
    ModbusInit(tmpModbusId, u8serno, u8txenpin);
}
Example #20
0
BOOL handle_vendorcommand(BYTE cmd)  
{
  WORD addr=SETUP_VALUE(),len=SETUP_LENGTH();

  switch ( cmd ) {

  case VC_EPSTAT:
    {
      xdata BYTE* pep= ep_addr(SETUPDAT[2]);
      if (pep) {
	EP0BUF[0] = *pep;
	EP0BCH=0;
	EP0BCL=1;
	return TRUE;
      }
    }
    break;
  case VC_EEPROM:
    {            
      // wait for ep0 not busy
      switch (SETUP_TYPE) {
      case 0xc0:
	while (len) { // still have bytes to read
	  // can't read more than 64 bytes at a time
	  BYTE cur_read = len > 64 ? 64 : len; 
	  while (EP0CS&bmEPBUSY); // can't do this until EP0 is ready
	  eeprom_read(0x51, addr, cur_read, EP0BUF );
	  EP0BCH=0;
	  SYNCDELAY();
	  EP0BCL=cur_read;
	  len -= cur_read;
	  addr += cur_read;
	}
	break;
      case 0x40:    
	while (len) {
	  BYTE cur_write;
	  EP0BCL = 0; // allow pc transfer in
	  while(EP0CS & bmEPBUSY); // wait
	  cur_write=EP0BCL;
	  if ( !eeprom_write(0x51, addr, cur_write, EP0BUF ) ) return FALSE;
	  addr += cur_write;
	  len -= cur_write;
	}
	break;
      default:
	return FALSE; // bad type
      }
      printf ( "All OK\n" );
      return TRUE;
    }
    break;
  default:
    {
    printf ( "Need to implement vendor command: %02x\n", cmd );
    return FALSE;
    }
  }
  return FALSE;
}
Example #21
0
void env_relocate_spec (void)
{
	eeprom_read (CONFIG_SYS_DEF_EEPROM_ADDR,
		     CONFIG_ENV_OFFSET,
		     (uchar*)env_ptr,
		     CONFIG_ENV_SIZE);
}
Example #22
0
/**
 * read_eeprom - read the EEPROM into memory
 */
static int read_eeprom(void)
{
	int ret;
#ifdef CONFIG_SYS_EEPROM_BUS_NUM
	unsigned int bus;
#endif

	if (has_been_read)
		return 0;

#ifdef CONFIG_SYS_EEPROM_BUS_NUM
	bus = i2c_get_bus_num();
	i2c_set_bus_num(CONFIG_SYS_EEPROM_BUS_NUM);
#endif

	ret = eeprom_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0,
		(uchar *)&e, sizeof(e));

#ifdef CONFIG_SYS_EEPROM_BUS_NUM
	i2c_set_bus_num(bus);
#endif

#ifdef DEBUG
	show_eeprom();
#endif

	has_been_read = (ret == 0) ? 1 : 0;

	return ret;
}
Example #23
0
static int eeprom_bus_read (unsigned dev_addr, unsigned offset, uchar *buffer,
				unsigned cnt)
{
	int rcode;
#if defined(CONFIG_I2C_ENV_EEPROM_BUS)
	int old_bus = i2c_get_bus_num();

	if (gd->flags & GD_FLG_RELOC) {
		if (env_eeprom_bus == -1) {
			I2C_MUX_DEVICE *dev = NULL;
			dev = i2c_mux_ident_muxstring(
				(uchar *)CONFIG_I2C_ENV_EEPROM_BUS);
			if (dev != NULL) {
				env_eeprom_bus = dev->busid;
			} else
				printf ("error adding env eeprom bus.\n");
		}
		if (old_bus != env_eeprom_bus) {
			i2c_set_bus_num(env_eeprom_bus);
			old_bus = env_eeprom_bus;
		}
	} else {
		rcode = i2c_mux_ident_muxstring_f(
				(uchar *)CONFIG_I2C_ENV_EEPROM_BUS);
	}
#endif

	rcode = eeprom_read (dev_addr, offset, buffer, cnt);
#if defined(CONFIG_I2C_ENV_EEPROM_BUS)
	if (old_bus != env_eeprom_bus)
		i2c_set_bus_num(old_bus);
#endif
	return rcode;
}
Example #24
0
static int nd_3c59x_probe(void)
{
	struct netdev *nd = &net_dev_3com_3c59x;
	unsigned long pci_config_base;
	int i;

	pci_config_base = pci_lookup_vendor_device(0x10b7, 0x5900);
	if (!pci_config_base)
		pci_config_base = pci_lookup_vendor_device(0x10b7, 0x5950);
	if (!pci_config_base)
		pci_config_base = pci_lookup_vendor_device(0x10b7, 0x5951);
	if (!pci_config_base)
		pci_config_base = pci_lookup_vendor_device(0x10b7, 0x5952);

	if (pci_config_base) {
		nd->io_base = pci_read_config_long(pci_config_base, PCI_BASE0) & ~3;

		for (i = 0; i < 3; i++) {
			int addr;

			addr = eeprom_read(nd, i + 10);

			nd->hw_addr[i * 2] = addr >> 8;
			nd->hw_addr[i * 2 + 1] = addr;
		}
		eth_setup(nd);
	}

	return net_dev_3com_3c59x.io_base ? 0 : -1;
}
Example #25
0
static void eeprom_rw_test_1()
{
	int i, cnt = 0;
	uint8_t *wbuf = &g_eeprom_param;
	uint8_t *rbuf = &tmp_eeprom_param;

	while (1) {
		// write something
		for (i = 0; i < 1024; i++)
			wbuf[i] = i;
		memset(wbuf, cnt, NBYTES);
		cnt++;
		eeprom_write(0, wbuf, NBYTES);
		// read back
		memset(rbuf, 0xFF, NBYTES);
		eeprom_read(0, rbuf, NBYTES);
		// check
		for (i = 0; i < NBYTES; i++) {
			if (rbuf[i] != wbuf[i]) {
				trace_err("check failed begin at %#x!", i);
				hex_dump("write", &wbuf[i], NBYTES - i);
				hex_dump("read", &rbuf[i], NBYTES - i);
				break;
			}
		}
		if (i == NBYTES) {
			trace_info("check passed");
		}

		sleep(2);
		//break;
	}
	exit(0);
}
void readMAC(void) {
	uint8_t eeprom_rd_buffer[32];
	
	// If the eeprom (first sector) matches our version string, use the configuration
	// found in the eeprom, otherwise generate a random MAC and persist it for this board.
	
	printf("main: loading from eeprom read sz=%d address=%04x\n", sizeof(eeprom_rd_buffer), EEPROM_CONFIG_BASE);
	eeprom_read(EEPROM_CONFIG_BASE, (unsigned char *)&eeprom_rd_buffer, sizeof(eeprom_rd_buffer));
	
	if (strcmp(version, (char*)&eeprom_rd_buffer ) == 0) {
		printf("main: using stored configuration\n");	
	} else {	
		printf("main: setting new MAC with DHCP\n");
		memset((void *)&eeprom_rd_buffer, 0, sizeof(eeprom_rd_buffer));
		memcpy((unsigned char *)&eeprom_rd_buffer[0], version, strlen(version)+1);
		
		// use microchip OUI database range, since it's a microchip part
		eeprom_rd_buffer[24] = 0x00;
		eeprom_rd_buffer[25] = 0x04;
		eeprom_rd_buffer[26] = 0xA3;		
		eeprom_rd_buffer[27] = (unsigned char) rand31pmc_ranlui() & 0xFF;
		eeprom_rd_buffer[29] = (unsigned char) rand31pmc_ranlui() & 0xFF;
		eeprom_rd_buffer[30] = (unsigned char) rand31pmc_ranlui() & 0xFF;
		
		printf("main: writing to eeprom\n");
		eeprom_write(EEPROM_CONFIG_BASE, (unsigned char *)&eeprom_rd_buffer, sizeof(eeprom_rd_buffer));
				
	}
	
	memcpy((unsigned char *)&eth_mac_addr, (char*)&eeprom_rd_buffer[24], sizeof(eth_mac_addr));
}
Example #27
0
int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
{
#if defined(CONFIG_ZYNQ_GEM_EEPROM_ADDR) && \
    defined(CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET)
	if (eeprom_read(CONFIG_ZYNQ_GEM_EEPROM_ADDR,
			CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET,
			ethaddr, 6))
		printf("I2C EEPROM MAC address read failed\n");
#endif

#if defined(CONFIG_ZYNQ_QSPI) && \
    defined(CONFIG_ZYNQ_GEM_SPI_MAC_OFFSET)
#define CMD_OTPREAD_ARRAY_FAST		0x4b
	struct spi_flash *flash;
	flash = spi_flash_probe(CONFIG_SF_DEFAULT_BUS,
				CONFIG_SF_DEFAULT_CS,
				CONFIG_SF_DEFAULT_SPEED,
				CONFIG_SF_DEFAULT_MODE);
	if (!flash) {
		printf("SPI(bus:%u cs:%u) probe failed\n",
			CONFIG_SF_DEFAULT_BUS,
			CONFIG_SF_DEFAULT_CS);
		return 0;
	}
	/* set the cmd to otp read */
	flash->read_cmd = CMD_OTPREAD_ARRAY_FAST;
	if (spi_flash_read(flash, CONFIG_ZYNQ_GEM_SPI_MAC_OFFSET, 6, ethaddr))
		printf("SPI MAC address read failed\n");

	if (flash)
		spi_flash_free(flash);
#endif
	return 0;
}
Example #28
0
/*---------------------------------------------------------------------*/
static u16_t
send_udpdata(struct codeprop_udphdr *uh)
{
  u16_t len;
  
  uh->type = HTONS(TYPE_DATA);
  uh->addr = htons(s.addr);
  uh->id = htons(s.id);

  if(s.len - s.addr > UDPDATASIZE) {
    len = UDPDATASIZE;
  } else {
    len = s.len - s.addr;
  }

  eeprom_read(EEPROMFS_ADDR_CODEPROP + s.addr,
	      &uh->data[0], len);
  
  uh->len = htons(s.len);

  PRINTF(("codeprop: sending packet from address 0x%04x\n", s.addr));
  uip_udp_send(len + UDPHEADERSIZE);

  return len;
}
Example #29
0
/*
 * vpd_reader() - reads VPD data from I2C EEPROMS.
 *                returns pointer to buffer or NULL.
 */
static unsigned char *
vpd_reader(unsigned char *buf, unsigned dev_addr, unsigned off, unsigned count)
{
    unsigned offset = off;			/* Calculated offset */

    /*
     * The main board EEPROM contains
     * SDRAM SPD in the first 128 bytes,
     * so skew the offset.
     */
    if (dev_addr == CFG_DEF_EEPROM_ADDR)
	offset += SDRAM_SPD_DATA_SIZE;

    /* Try to read the I2C EEPROM */
#if defined(VXWORKS)
    {
	int i;
	for( i = 0; i < count; ++i ) {
	    buf[ i ] = iicReadByte( dev_addr, offset+i );
	}
    }
#else
    if (eeprom_read(dev_addr, offset, buf, count)) {
	printf("Failed to read %d bytes from VPD EEPROM 0x%x @ 0x%x\n",
	       count, dev_addr, offset);
	return NULL;
    }
#endif

    return buf;
} /* vpd_reader() */
Example #30
0
bool
sis900_getMACAddress(struct sis_info *info)
{
	if (info->pciInfo->revision >= SiS900_REVISION_SiS96x) {
		// SiS 962 & 963 are using a different method to access the EEPROM
		// than the standard SiS 630
		addr_t eepromAccess = info->registers + SiS900_MAC_EEPROM_ACCESS;
		uint32 tries = 0;

		write32(eepromAccess, SiS96x_EEPROM_CMD_REQ);

		while (tries < 1000) {
			if (read32(eepromAccess) & SiS96x_EEPROM_CMD_GRANT) {
				int i;

				/* get MAC address from EEPROM */
				for (i = 0; i < 3; i++) {
					uint16 id;

					id = eeprom_read(info, SiS900_EEPROM_MAC_ADDRESS + i);
					info->address.ebyte[i*2 + 1] = id >> 8;
					info->address.ebyte[i*2] = id & 0xff;
				}

				write32(eepromAccess, SiS96x_EEPROM_CMD_DONE);
				return true;
			} else {