int urj_pld_read_register (urj_chain_t *chain, uint32_t reg) { urj_part_t *part; uint32_t value; part = urj_tap_chain_active_part (chain); if (part == NULL) return URJ_STATUS_FAIL; if (set_pld_driver (chain, part) != URJ_STATUS_OK) return URJ_STATUS_FAIL; if (pld_driver->read_register == NULL) { urj_error_set (URJ_ERROR_UNSUPPORTED, _("PLD doesn't support this operation")); return URJ_STATUS_FAIL; } if (pld_driver->read_register (&pld, reg, &value) != URJ_STATUS_OK) return URJ_STATUS_FAIL; urj_log (URJ_LOG_LEVEL_NORMAL, N_("REG[%d]=0x%0*x\n"), reg, pld_driver->register_width * 2, value); return URJ_STATUS_OK; }
static int cmd_initbus_run (urj_chain_t *chain, char *params[]) { int drv, i; const urj_param_t **bus_params; if (urj_cmd_params (params) < 2) { urj_error_set (URJ_ERROR_SYNTAX, "%s: #parameters should be >= %d, not %d", params[0], 2, urj_cmd_params (params)); return URJ_STATUS_FAIL; } if (urj_cmd_test_cable (chain) != URJ_STATUS_OK) return URJ_STATUS_FAIL; if (urj_tap_chain_active_part (chain) == NULL) return URJ_STATUS_FAIL; for (drv = 0; urj_bus_drivers[drv] != NULL; drv++) if (strcasecmp (urj_bus_drivers[drv]->name, params[1]) == 0) break; if (urj_bus_drivers[drv] == NULL) { urj_error_set (URJ_ERROR_NOTFOUND, _("Unknown bus: %s"), params[1]); return URJ_STATUS_FAIL; } urj_param_init (&bus_params); for (i = 2; params[i] != NULL; i++) if (urj_param_push (&urj_bus_param_list, &bus_params, params[i]) != URJ_STATUS_OK) { urj_param_clear (&bus_params); return URJ_STATUS_FAIL; } if (urj_bus_init_bus(chain, urj_bus_drivers[drv], bus_params) == NULL) { urj_param_clear (&bus_params); return URJ_STATUS_FAIL; } urj_param_clear (&bus_params); return URJ_STATUS_OK; }
static int cmd_get_run (urj_chain_t *chain, char *params[]) { int data; urj_part_signal_t *s; urj_part_t *part; if (urj_cmd_params (params) != 3) { urj_error_set (URJ_ERROR_SYNTAX, "%s: #parameters should be %d, not %d", params[0], 3, urj_cmd_params (params)); return URJ_STATUS_FAIL; } if (strcasecmp (params[1], "signal") != 0) { urj_error_set (URJ_ERROR_SYNTAX, "params[1] must be 'signal', not '%s'", params[1]); return URJ_STATUS_FAIL; } if (urj_cmd_test_cable (chain) != URJ_STATUS_OK) return URJ_STATUS_FAIL; part = urj_tap_chain_active_part (chain); if (part == NULL) return URJ_STATUS_FAIL; s = urj_part_find_signal (part, params[2]); if (!s) { urj_error_set (URJ_ERROR_NOTFOUND, _("signal '%s' not found"), params[2]); return URJ_STATUS_FAIL; } data = urj_part_get_signal (part, s); if (data == -1) return URJ_STATUS_FAIL; urj_log (URJ_LOG_LEVEL_NORMAL, _("%s = %d\n"), params[2], data); return URJ_STATUS_OK; }
static int cmd_salias_run (urj_chain_t *chain, char *params[]) { urj_part_t *part; urj_part_signal_t *s; urj_part_salias_t *sa; if (urj_cmd_params (params) != 3) { urj_error_set (URJ_ERROR_SYNTAX, "%s: #parameters should be %d, not %d", params[0], 3, urj_cmd_params (params)); return URJ_STATUS_FAIL; } if (urj_cmd_test_cable (chain) != URJ_STATUS_OK) return URJ_STATUS_FAIL; part = urj_tap_chain_active_part (chain); if (part == NULL) return URJ_STATUS_FAIL; if (urj_part_find_signal (part, params[1]) != NULL) { return URJ_STATUS_FAIL; } s = urj_part_find_signal (part, params[2]); if (s == NULL) { urj_error_set (URJ_ERROR_NOTFOUND, _("Signal '%s' not found"), params[2]); return URJ_STATUS_FAIL; } sa = urj_part_salias_alloc (params[1], s); if (!sa) return URJ_STATUS_FAIL; sa->next = part->saliases; part->saliases = sa; return URJ_STATUS_OK; }
int urj_pld_configure (urj_chain_t *chain, FILE *pld_file) { urj_part_t *part; part = urj_tap_chain_active_part (chain); if (part == NULL) return URJ_STATUS_FAIL; if (set_pld_driver (chain, part) != URJ_STATUS_OK) return URJ_STATUS_FAIL; if (pld_driver->configure == NULL) { urj_error_set (URJ_ERROR_UNSUPPORTED, _("PLD doesn't support this operation")); return URJ_STATUS_FAIL; } return pld_driver->configure (&pld, pld_file); }
int urj_pld_write_register (urj_chain_t *chain, uint32_t reg, uint32_t data) { urj_part_t *part; part = urj_tap_chain_active_part (chain); if (part == NULL) return URJ_STATUS_FAIL; if (set_pld_driver (chain, part) != URJ_STATUS_OK) return URJ_STATUS_FAIL; if (pld_driver->write_register == NULL) { urj_error_set (URJ_ERROR_UNSUPPORTED, _("PLD doesn't support this operation")); return URJ_STATUS_FAIL; } return pld_driver->write_register (&pld, reg, data); }
int urj_pld_print_status (urj_chain_t *chain) { urj_part_t *part; part = urj_tap_chain_active_part (chain); if (part == NULL) return URJ_STATUS_FAIL; if (set_pld_driver (chain, part) != URJ_STATUS_OK) return URJ_STATUS_FAIL; if (pld_driver->print_status == NULL) { urj_error_set (URJ_ERROR_UNSUPPORTED, _("PLD doesn't support this operation")); return URJ_STATUS_FAIL; } return pld_driver->print_status (&pld); }
urj_bus_t * urj_bus_init_bus (urj_chain_t *chain, const urj_bus_driver_t *bus_driver, const urj_param_t *param[]) { urj_bus_t *abus; int i; if (urj_tap_chain_active_part (chain) == NULL) return NULL; abus = bus_driver->new_bus (chain, bus_driver, param); if (abus == NULL) // retain error state return NULL; if (urj_bus_buses_add (abus) != URJ_STATUS_OK) { // @@@@ RFHH I added this FREE() + bail out. Is that correct? URJ_BUS_FREE(abus); return NULL; } if (URJ_BUS_INIT (abus) != URJ_STATUS_OK) { // @@@@ RFHH I added this FREE() + bail out. Is that correct? URJ_BUS_FREE(abus); return NULL; } for (i = 0; i < urj_buses.len; i++) if (urj_buses.buses[i] == urj_bus) break; if (i != urj_buses.len - 1) urj_log (URJ_LOG_LEVEL_NORMAL, _("Initialized bus %d, active bus %d\n"), urj_buses.len - 1, i); return abus; }
urj_part_signal_t * urj_part_signal_define_pin (urj_chain_t *chain, const char *signal_name, const char *pin_name) { urj_part_t *part; urj_part_signal_t *s; part = urj_tap_chain_active_part (chain); if (urj_part_find_signal (part, signal_name) != NULL) { urj_error_set (URJ_ERROR_ALREADY, _("Signal '%s' already defined"), signal_name); return NULL; } s = urj_part_signal_alloc (signal_name); if (!s) return NULL; if (pin_name != NULL) { /* Add pin number */ /* Allocate the space for the pin number & copy it */ s->pin = strdup (pin_name); if (s->pin == NULL) { urj_part_signal_free (s); urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "strdup(%s) fails", pin_name); return NULL; } } s->next = part->signals; part->signals = s; return s; }
static int cmd_dr_run (urj_chain_t *chain, char *params[]) { int dir = 1; urj_part_t *part; urj_tap_register_t *r; urj_data_register_t *dr; urj_part_instruction_t *active_ir; if (urj_cmd_params (params) < 1 || urj_cmd_params (params) > 2) { urj_error_set (URJ_ERROR_SYNTAX, "%s: #parameters should be >= 1 and <= 2, not %d", params[0], urj_cmd_params (params)); return URJ_STATUS_FAIL; } if (urj_cmd_test_cable (chain) != URJ_STATUS_OK) return URJ_STATUS_FAIL; part = urj_tap_chain_active_part (chain); if (part == NULL) return URJ_STATUS_FAIL; active_ir = part->active_instruction; if (active_ir == NULL) { urj_error_set (URJ_ERROR_ILLEGAL_STATE, _("%s: part without active instruction"), "dr"); return URJ_STATUS_FAIL; } dr = active_ir->data_register; if (dr == NULL) { urj_error_set (URJ_ERROR_ILLEGAL_STATE, _("%s: instruction without active data register"), "dr"); return URJ_STATUS_FAIL; } if (params[1]) { if (strcasecmp (params[1], "in") == 0) dir = 0; else if (strcasecmp (params[1], "out") == 0) dir = 1; else { int ret = urj_tap_register_set_string (dr->in, params[1]); if (ret != URJ_STATUS_OK) return ret; dir = 0; } } if (dir) r = dr->out; else r = dr->in; urj_log (URJ_LOG_LEVEL_NORMAL, "%s (0x%0*" PRIX64 ")\n", urj_tap_register_get_string (r), r->len / 4, urj_tap_register_get_value (r)); return URJ_STATUS_OK; }
static int cmd_set_run (urj_chain_t *chain, char *params[]) { int dir; long unsigned data = 0; urj_part_signal_t *s; urj_part_t *part; if (urj_cmd_params (params) < 4 || urj_cmd_params (params) > 5) { urj_error_set (URJ_ERROR_SYNTAX, "%s: #parameters should be 4 or 5, not %d", params[0], urj_cmd_params (params)); return URJ_STATUS_FAIL; } if (strcasecmp (params[1], "signal") != 0) { urj_error_set (URJ_ERROR_SYNTAX, "%s: second parameter must be '%s'", params[0], params[1]); return URJ_STATUS_FAIL; } if (urj_cmd_test_cable (chain) != URJ_STATUS_OK) return URJ_STATUS_FAIL; part = urj_tap_chain_active_part (chain); if (part == NULL) return URJ_STATUS_FAIL; /* direction */ if (strcasecmp (params[3], "in") != 0 && strcasecmp (params[3], "out") != 0) { urj_error_set (URJ_ERROR_SYNTAX, "%s: DIR parameter must be 'in' or 'out', not '%s'", params[0], params[3]); return URJ_STATUS_FAIL; } dir = (strcasecmp (params[3], "in") == 0) ? 0 : 1; if (dir) { if (urj_cmd_get_number (params[4], &data) != URJ_STATUS_OK) return URJ_STATUS_FAIL; if (data > 1) { urj_error_set (URJ_ERROR_SYNTAX, "%s: DATA parameter must be '0' or '1', not '%s'", params[0], params[4]); return URJ_STATUS_FAIL; } } s = urj_part_find_signal (part, params[2]); if (!s) { urj_error_set (URJ_ERROR_NOTFOUND, _("signal '%s' not found"), params[2]); return URJ_STATUS_FAIL; } return urj_part_set_signal (part, s, dir, data); }