aboutsummaryrefslogtreecommitdiff
path: root/src/pld/gowin.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pld/gowin.c')
-rw-r--r--src/pld/gowin.c71
1 files changed, 44 insertions, 27 deletions
diff --git a/src/pld/gowin.c b/src/pld/gowin.c
index 467b799..c42b2f2 100644
--- a/src/pld/gowin.c
+++ b/src/pld/gowin.c
@@ -29,6 +29,9 @@
#define ERASE_FLASH 0x75
#define ENABLE_2ND_FLASH 0x78
+#define USER1 0x42
+#define USER2 0x43
+
#define STAUS_MASK_MEMORY_ERASE BIT(5)
#define STAUS_MASK_SYSTEM_EDIT_MODE BIT(7)
@@ -449,17 +452,37 @@ static int gowin_reload_command(struct pld_device *pld_device)
return gowin_reload(gowin_info->tap);
}
-COMMAND_HANDLER(gowin_read_status_command_handler)
+static int gowin_get_ipdbg_hub(int user_num, struct pld_device *pld_device, struct pld_ipdbg_hub *hub)
{
- int dev_id;
+ if (!pld_device)
+ return ERROR_FAIL;
+
+ struct gowin_pld_device *pld_device_info = pld_device->driver_priv;
+
+ if (!pld_device_info || !pld_device_info->tap)
+ return ERROR_FAIL;
+
+ hub->tap = pld_device_info->tap;
+
+ if (user_num == 1) {
+ hub->user_ir_code = USER1;
+ } else if (user_num == 2) {
+ hub->user_ir_code = USER2;
+ } else {
+ LOG_ERROR("gowin devices only have user register 1 & 2");
+ return ERROR_FAIL;
+ }
+ return ERROR_OK;
+}
+COMMAND_HANDLER(gowin_read_status_command_handler)
+{
if (CMD_ARGC != 1)
return ERROR_COMMAND_SYNTAX_ERROR;
- COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], dev_id);
- struct pld_device *device = get_pld_device_by_num(dev_id);
+ struct pld_device *device = get_pld_device_by_name_or_numstr(CMD_ARGV[0]);
if (!device) {
- command_print(CMD, "pld device '#%s' is out of bounds", CMD_ARGV[0]);
+ command_print(CMD, "pld device '#%s' is out of bounds or unknown", CMD_ARGV[0]);
return ERROR_FAIL;
}
@@ -474,15 +497,12 @@ COMMAND_HANDLER(gowin_read_status_command_handler)
COMMAND_HANDLER(gowin_read_user_register_command_handler)
{
- int dev_id;
-
if (CMD_ARGC != 1)
return ERROR_COMMAND_SYNTAX_ERROR;
- COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], dev_id);
- struct pld_device *device = get_pld_device_by_num(dev_id);
+ struct pld_device *device = get_pld_device_by_name_or_numstr(CMD_ARGV[0]);
if (!device) {
- command_print(CMD, "pld device '#%s' is out of bounds", CMD_ARGV[0]);
+ command_print(CMD, "pld device '#%s' is out of bounds or unknown", CMD_ARGV[0]);
return ERROR_FAIL;
}
@@ -497,15 +517,12 @@ COMMAND_HANDLER(gowin_read_user_register_command_handler)
COMMAND_HANDLER(gowin_reload_command_handler)
{
- int dev_id;
-
if (CMD_ARGC != 1)
return ERROR_COMMAND_SYNTAX_ERROR;
- COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], dev_id);
- struct pld_device *device = get_pld_device_by_num(dev_id);
+ struct pld_device *device = get_pld_device_by_name_or_numstr(CMD_ARGV[0]);
if (!device) {
- command_print(CMD, "pld device '#%s' is out of bounds", CMD_ARGV[0]);
+ command_print(CMD, "pld device '#%s' is out of bounds or unknown", CMD_ARGV[0]);
return ERROR_FAIL;
}
@@ -518,19 +535,19 @@ static const struct command_registration gowin_exec_command_handlers[] = {
.mode = COMMAND_EXEC,
.handler = gowin_read_status_command_handler,
.help = "reading status register from FPGA",
- .usage = "num_pld",
+ .usage = "pld_name",
}, {
.name = "read_user",
.mode = COMMAND_EXEC,
.handler = gowin_read_user_register_command_handler,
.help = "reading user register from FPGA",
- .usage = "num_pld",
+ .usage = "pld_name",
}, {
.name = "reload",
.mode = COMMAND_EXEC,
.handler = gowin_reload_command_handler,
.help = "reloading bitstream from flash to SRAM",
- .usage = "num_pld",
+ .usage = "pld_name",
},
COMMAND_REGISTRATION_DONE
};
@@ -546,22 +563,21 @@ static const struct command_registration gowin_command_handler[] = {
COMMAND_REGISTRATION_DONE
};
-PLD_DEVICE_COMMAND_HANDLER(gowin_pld_device_command)
+PLD_CREATE_COMMAND_HANDLER(gowin_pld_create_command)
{
- struct jtag_tap *tap;
-
- struct gowin_pld_device *gowin_info;
+ if (CMD_ARGC != 4)
+ return ERROR_COMMAND_SYNTAX_ERROR;
- if (CMD_ARGC != 2)
+ if (strcmp(CMD_ARGV[2], "-chain-position") != 0)
return ERROR_COMMAND_SYNTAX_ERROR;
- tap = jtag_tap_by_string(CMD_ARGV[1]);
+ struct jtag_tap *tap = jtag_tap_by_string(CMD_ARGV[3]);
if (!tap) {
- command_print(CMD, "Tap: %s does not exist", CMD_ARGV[1]);
+ command_print(CMD, "Tap: %s does not exist", CMD_ARGV[3]);
return ERROR_FAIL;
}
- gowin_info = malloc(sizeof(struct gowin_pld_device));
+ struct gowin_pld_device *gowin_info = malloc(sizeof(struct gowin_pld_device));
if (!gowin_info) {
LOG_ERROR("Out of memory");
return ERROR_FAIL;
@@ -576,6 +592,7 @@ PLD_DEVICE_COMMAND_HANDLER(gowin_pld_device_command)
struct pld_driver gowin_pld = {
.name = "gowin",
.commands = gowin_command_handler,
- .pld_device_command = &gowin_pld_device_command,
+ .pld_create_command = &gowin_pld_create_command,
.load = &gowin_load_to_sram,
+ .get_ipdbg_hub = gowin_get_ipdbg_hub,
};