Esempio n. 1
0
uint8_t eeprom_read_byte(const uint16_t address) {

  /* Start data transmission on the bus. */
  eeprom_start();

  /* Send a dummy write to the bus with the requested read address. */
  eeprom_i2c_write(EEPROM_I2C_WRITE_ADDRESS);
  eeprom_i2c_write(address >> 8);
  eeprom_i2c_write(address);

  /* Start data transmission on the bus. */
  eeprom_start();

  /* Send to the bus a read request. */
  eeprom_i2c_write(EEPROM_I2C_READ_ADDRESS);

  /* Read the byte from the EEPROM. */
  uint8_t byte = eeprom_i2c_read();

  /* Return a NACK for acknowledgement. */
  eeprom_i2c_send_ack(EEPROM_I2C_NACK);

  /* Stop data transmission on the bus. */
  eeprom_stop();

  return byte;
}
Esempio n. 2
0
static void
eeprom_write(int addr, cyg_uint8 val)
{
    cyg_uint8 start_byte;
    int i;

    start_byte = 0xA0;  // write

    if (addr & (1 << 8))
	start_byte |= 2;

    for (i = 0; i < 10; i++)
	if (eeprom_start(start_byte))
	    break;

    if (i == 10) {
	diag_printf("eeprom_write: Can't get start ACK\n");
	return;
    }

    if (!eeprom_putb(addr & 0xff)) {
	diag_printf("eeprom_write: Can't get address ACK\n");
	return;
    }

    if (!eeprom_putb(val)) {
	diag_printf("eeprom_write: no data ACK\n");
	return;
    }
    eeprom_stop();
}
Esempio n. 3
0
int eeprom_main(int argc, char *argv[])
{
	if (argc >= 2) {
		if (!strcmp(argv[1], "start"))
			eeprom_start();

		if (!strcmp(argv[1], "save_param"))
			eeprom_save(argv[2]);

		if (!strcmp(argv[1], "load_param"))
			eeprom_load(argv[2]);

		if (!strcmp(argv[1], "erase"))
			eeprom_erase();

		if (!strcmp(argv[1], "test"))
			eeprom_test();

		if (0) {	/* these actually require a file on the filesystem... */

			if (!strcmp(argv[1], "reformat"))
				eeprom_ioctl(FIOC_REFORMAT);

			if (!strcmp(argv[1], "repack"))
				eeprom_ioctl(FIOC_OPTIMIZE);
		}
	}

	errx(1, "expected a command, try 'start'\n\t'save_param /eeprom/parameters'\n\t'load_param /eeprom/parameters'\n\t'erase'\n");
}
Esempio n. 4
0
static int
eeprom_read(int addr, cyg_uint8 *buf, int nbytes)
{
    cyg_uint8 start_byte;
    int i;

    start_byte = 0xA0;  // write

    if (addr & (1 << 8))
	start_byte |= 2;

    
    for (i = 0; i < 10; i++)
	if (eeprom_start(start_byte))
	    break;

    if (i == 10) {
	diag_printf("eeprom_read: Can't get write start ACK\n");
	return 0;
    }

    if (!eeprom_putb(addr & 0xff)) {
	diag_printf("eeprom_read: Can't get address ACK\n");
	return 0;
    }

    start_byte |= 1; // READ command
    if (!eeprom_start(start_byte)) {
	diag_printf("eeprom_read: Can't get read start ACK\n");
	return 0;
    }

    for (i = 0; i < (nbytes - 1); i++)
	*buf++ = eeprom_getb(1);

    *buf++ = eeprom_getb(0);
    hal_delay_us(5);
    eeprom_stop();

    return nbytes;
}
Esempio n. 5
0
bool eeprom_write_byte(const uint8_t value, const uint16_t address) {

  /* Start data transmission on the bus. */
  eeprom_start();

  /* Send a write request containing the target address to the bus. */
  eeprom_i2c_write(EEPROM_I2C_WRITE_ADDRESS);
  eeprom_i2c_write(address >> 8);
  eeprom_i2c_write(address);

  /* Send the byte to write to the bus. */
  eeprom_i2c_write(value);

  /* Read the acknowledgement result from the operation. */
  bool result = eeprom_i2c_get_ack();

  /* Stop data transmission on the bus. */
  eeprom_stop();

  return result;
}