Commit 2fcc7308 authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Add eeprom functions.

Add recovery to block_vesp_tty
parent f176d76e
......@@ -280,6 +280,25 @@ err:
return -1;
}
static enum controller_bus_state vesp_tty_poll(struct controller_bus *bus)
{
struct controller_block *block = bus->owner;
int fd = block->private->fd;
if (fd >= 0)
return CONTROLLER_BUS_STATE_OK;
fd = vesp_dev_open(block);
if (fd < 0)
return CONTROLLER_BUS_STATE_ERROR;
block->private->fd = fd;
log_send(LOG_T_WARNING, "%s: re-opened %s", block->name,
block->private->devname);
return CONTROLLER_BUS_STATE_OK;
}
static speed_t int2speed_t(int baud)
{
switch (baud) {
......@@ -369,6 +388,7 @@ static struct controller_block * block_vesp_tty_create(char *name, int argc,
if (!bus)
goto err_bus;
controller_bus_output_set(bus, vesp_tx);
controller_bus_poll_set(bus, vesp_tty_poll, NULL);
vesp->private->bus = bus;
......
......@@ -405,3 +405,45 @@ int vesp_command_get_details(struct controller_bus *bus,
return 0;
}
int vesp_command_read_eeprom(struct controller_bus *bus,
uint8_t address, uint8_t offset, uint8_t *value)
{
uint8_t command[1];
uint8_t response[1];
ssize_t ret;
command[0] = offset;
ret = vesp_command(bus, address, VESP_CMD_READ_EEPROM, command, 1, response, 1);
if (ret < 1) {
log_send(LOG_T_ERROR,
"%s: Could not read eeprom byte 0x%02x @ device 0x%02x: %zd",
bus->name, offset, address, ret);
return -1;
}
*value = response[0];
return 0;
}
int vesp_command_write_eeprom(struct controller_bus *bus,
uint8_t address, uint8_t offset, uint8_t value)
{
uint8_t command[2];
ssize_t ret;
command[0] = offset;
command[1] = value;
ret = vesp_command(bus, address, VESP_CMD_WRITE_EEPROM, command, 2, NULL, 0);
if (ret < 1) {
log_send(LOG_T_ERROR,
"%s: Could not write eeprom byte 0x%02x with 0x%02x @ device 0x%02x: %zd",
bus->name, offset, value, address, ret);
return -1;
}
return 0;
}
......@@ -54,6 +54,7 @@ int vesp_input_process_pkt(struct controller_bus *bus, void *pkt, size_t size);
/* Send process data */
int vesp_output_clients(struct controller_bus *bus);
/* Some getter functions: */
size_t vesp_client_rx_size(struct controller_bus *bus);
......@@ -66,6 +67,13 @@ ssize_t vesp_command(struct controller_bus *bus,
int vesp_command_get_details(struct controller_bus *bus,
uint8_t address, uint8_t *vid, uint8_t *dev);
int vesp_command_read_eeprom(struct controller_bus *bus,
uint8_t address, uint8_t offset, uint8_t *value);
int vesp_command_write_eeprom(struct controller_bus *bus,
uint8_t address, uint8_t offset, uint8_t value);
/* VESP Protocol defines which are also shared with clients: */
#define VESP_CMD_GET_DETAILS 0x01
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment