aboutsummaryrefslogtreecommitdiff
path: root/src/jtag/drivers/angie.c
diff options
context:
space:
mode:
authorAhmed BOUDJELIDA <aboudjelida@nanoxplore.com>2023-12-11 14:39:57 +0100
committerEvgeniy Naydanov <109669442+en-sc@users.noreply.github.com>2024-01-29 13:36:27 +0300
commitba860abcab58e244bc4cc14b24cec7a5e8e30069 (patch)
tree75041a61767e6de9bb3e94fee3751786618939d8 /src/jtag/drivers/angie.c
parentf064c670f180a3aedb431297cbb6f32e09d5f6f2 (diff)
downloadriscv-openocd-ba860abcab58e244bc4cc14b24cec7a5e8e30069.zip
riscv-openocd-ba860abcab58e244bc4cc14b24cec7a5e8e30069.tar.gz
riscv-openocd-ba860abcab58e244bc4cc14b24cec7a5e8e30069.tar.bz2
jtag/drivers: Add GPIO extender configuration function to ANGIE driver
Add GPIO extender initial configuration that is needed to configure some important GPIOs and ensure that the dev board is ready to work. Add i2c_write function that make a write transfer to any slave device. Give a new Product ID to ANGIE to make it different than the non programmed ANGIE. Change-Id: I0a8dacb7fe218145b7d3ed1cb75f106ed6256714 Signed-off-by: Ahmed BOUDJELIDA <aboudjelida@nanoxplore.com> Reviewed-on: https://review.openocd.org/c/openocd/+/8072 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Diffstat (limited to 'src/jtag/drivers/angie.c')
-rw-r--r--src/jtag/drivers/angie.c118
1 files changed, 114 insertions, 4 deletions
diff --git a/src/jtag/drivers/angie.c b/src/jtag/drivers/angie.c
index d4219d3..dfe65a2 100644
--- a/src/jtag/drivers/angie.c
+++ b/src/jtag/drivers/angie.c
@@ -167,7 +167,8 @@ static int angie_load_firmware_and_renumerate(struct angie *device, const char *
uint32_t delay_us);
static int angie_load_firmware(struct angie *device, const char *filename);
static int angie_load_bitstream(struct angie *device, const char *filename);
-
+static int angie_i2c_write(struct angie *device, uint8_t *i2c_data, uint8_t i2c_data_size);
+static void angie_io_extender_config(struct angie *device, uint8_t i2c_adr, uint8_t cfg_value, uint8_t value);
static int angie_write_firmware_section(struct angie *device,
struct image *firmware_image, int section_index);
@@ -338,7 +339,15 @@ static int angie_load_firmware_and_renumerate(struct angie *device,
usleep(delay_us);
- return angie_usb_open(device);
+ ret = angie_usb_open(device);
+ if (ret != ERROR_OK)
+ return ret;
+
+ ret = libusb_claim_interface(angie_handle->usb_device_handle, 0);
+ if (ret != LIBUSB_SUCCESS)
+ return ERROR_FAIL;
+
+ return ERROR_OK;
}
/**
@@ -476,6 +485,72 @@ static int angie_load_bitstream(struct angie *device, const char *filename)
}
/**
+ * Send an i2c write operation to dev-board components.
+ *
+ * @param device pointer to struct angie identifying ANGIE driver instance.
+ * @param i2c_data table of i2c data that we want to write to slave device.
+ * @param i2c_data_size the size of i2c data table.
+ * @return on success: ERROR_OK
+ * @return on failure: ERROR_FAIL
+ */
+static int angie_i2c_write(struct angie *device, uint8_t *i2c_data, uint8_t i2c_data_size)
+{
+ char i2c_data_buffer[i2c_data_size + 2];
+ char buffer_received[1];
+ int ret, transferred;
+ i2c_data_buffer[0] = 0; // write = 0
+ i2c_data_buffer[1] = i2c_data_size - 1; // i2c_data count (without address)
+
+ for (uint8_t i = 0; i < i2c_data_size; i++)
+ i2c_data_buffer[i + 2] = i2c_data[i];
+
+ // Send i2c packet to Dev-board and configure its clock source /
+ ret = jtag_libusb_bulk_write(device->usb_device_handle, 0x06, i2c_data_buffer,
+ i2c_data_size + 2, 1000, &transferred);
+ if (ret != ERROR_OK) {
+ LOG_ERROR("Error in i2c clock gen configuration : ret ERROR");
+ angie_quit();
+ return ret;
+ }
+ if (transferred != i2c_data_size + 2) {
+ LOG_ERROR("Error in i2c clock gen configuration : bytes transferred");
+ angie_quit();
+ return ERROR_FAIL;
+ }
+
+ usleep(500);
+
+ // Receive packet from ANGIE /
+ ret = jtag_libusb_bulk_write(device->usb_device_handle, 0x88, buffer_received, 1, 1000, &transferred);
+ if (ret != ERROR_OK) {
+ LOG_ERROR("Error in i2c clock gen configuration : ret ERROR");
+ angie_quit();
+ return ret;
+ }
+ return ERROR_OK;
+}
+
+/**
+ * Configure dev-board gpio extender modules by configuring their
+ * register 3 and register 1 responsible for IO directions and values.
+ *
+ * @param device pointer to struct angie identifying ANGIE driver instance.
+ * @param i2c_adr i2c address of the gpio extender.
+ * @param cfg_value IOs configuration to be written in register Number 3.
+ * @param value the IOs value to be written in register Number 1.
+ * @return on success: ERROR_OK
+ * @return on failure: ERROR_FAIL
+ */
+static void angie_io_extender_config(struct angie *device, uint8_t i2c_adr, uint8_t cfg_value, uint8_t value)
+{
+ uint8_t ioconfig[3] = {i2c_adr, 3, cfg_value};
+ angie_i2c_write(device, ioconfig, 3);
+ uint8_t iovalue[3] = {i2c_adr, 1, value};
+ angie_i2c_write(device, iovalue, 3);
+ usleep(500);
+}
+
+/**
* Send one contiguous firmware section to the ANGIE's EZ-USB microcontroller
* over the USB bus.
*
@@ -2175,7 +2250,7 @@ static int angie_init(void)
if (download_firmware) {
LOG_INFO("Loading ANGIE firmware. This is reversible by power-cycling ANGIE device.");
- if (libusb_claim_interface(angie_handle->usb_device_handle, 0) != ERROR_OK)
+ if (libusb_claim_interface(angie_handle->usb_device_handle, 0) != LIBUSB_SUCCESS)
LOG_ERROR("Could not claim interface");
ret = angie_load_firmware_and_renumerate(angie_handle,
@@ -2191,14 +2266,49 @@ static int angie_init(void)
angie_quit();
return ret;
}
+ if (libusb_claim_interface(angie_handle->usb_device_handle, 1) != LIBUSB_SUCCESS) {
+ LOG_ERROR("Could not claim interface 1");
+ angie_quit();
+ return ERROR_FAIL;
+ }
+ angie_io_extender_config(angie_handle, 0x22, 0xFF, 0xFF);
+ if (ret != ERROR_OK) {
+ LOG_ERROR("Could not configure io extender 22");
+ angie_quit();
+ return ret;
+ }
+ angie_io_extender_config(angie_handle, 0x23, 0xFF, 0xFF);
+ if (ret != ERROR_OK) {
+ LOG_ERROR("Could not configure io extender 23");
+ angie_quit();
+ return ret;
+ }
+ angie_io_extender_config(angie_handle, 0x24, 0x1F, 0x9F);
+ if (ret != ERROR_OK) {
+ LOG_ERROR("Could not configure io extender 24");
+ angie_quit();
+ return ret;
+ }
+ angie_io_extender_config(angie_handle, 0x25, 0x07, 0x00);
+ if (ret != ERROR_OK) {
+ LOG_ERROR("Could not configure io extender 25");
+ angie_quit();
+ return ret;
+ }
+ if (libusb_release_interface(angie_handle->usb_device_handle, 1) != LIBUSB_SUCCESS) {
+ LOG_ERROR("Fail release interface 1");
+ angie_quit();
+ return ERROR_FAIL;
+ }
} else {
LOG_INFO("ANGIE device is already running ANGIE firmware");
}
/* Get ANGIE USB IN/OUT endpoints and claim the interface */
ret = jtag_libusb_choose_interface(angie_handle->usb_device_handle,
- &angie_handle->ep_in, &angie_handle->ep_out, -1, -1, -1, -1);
+ &angie_handle->ep_in, &angie_handle->ep_out, 0xFF, 0, 0, -1);
if (ret != ERROR_OK) {
+ LOG_ERROR("Choose and claim interface failed");
angie_quit();
return ret;
}