int urj_tap_cable_get_signal_late (urj_cable_t *cable, urj_pod_sigsel_t sig) { int i; urj_tap_cable_flush (cable, URJ_TAP_CABLE_TO_OUTPUT); i = urj_tap_cable_get_queue_item (cable, &cable->done); if (i >= 0) { if (cable->done.data[i].action != URJ_TAP_CABLE_GET_SIGNAL) { urj_warning ( _("Internal error: Got wrong type of result from queue (%d? %p.%d)\n"), cable->done.data[i].action, &cable->done, i); urj_tap_cable_purge_queue (&cable->done, 1); } else if (cable->done.data[i].arg.value.sig != sig) { urj_warning ( _("Internal error: Got wrong signal's value from queue (%d? %p.%d)\n"), cable->done.data[i].action, &cable->done, i); urj_tap_cable_purge_queue (&cable->done, 1); } else { return cable->done.data[i].arg.value.val; } } return cable->driver->get_signal (cable, sig); }
int urj_tap_chain_shift_instructions_mode (urj_chain_t *chain, int capture_output, int capture, int chain_exit) { int i; urj_parts_t *ps; if (!chain || !chain->parts) { urj_error_set (URJ_ERROR_NO_CHAIN, "no chain or no part"); return URJ_STATUS_FAIL; } ps = chain->parts; for (i = 0; i < ps->len; i++) { if (ps->parts[i]->active_instruction == NULL) { urj_error_set (URJ_ERROR_NO_ACTIVE_INSTRUCTION, _("Part %d without active instruction"), i); return URJ_STATUS_FAIL; } } if (capture) urj_tap_capture_ir (chain); /* new implementation: split into defer + retrieve part shift the data register of each part in the chain one by one */ for (i = 0; i < ps->len; i++) { urj_tap_defer_shift_register (chain, ps->parts[i]->active_instruction->value, capture_output ? ps->parts[i]->active_instruction->out : NULL, (i + 1) == ps->len ? chain_exit : URJ_CHAIN_EXITMODE_SHIFT); } if (capture_output) { for (i = 0; i < ps->len; i++) { urj_tap_shift_register_output (chain, ps->parts[i]->active_instruction->value, ps->parts[i]->active_instruction->out, (i + 1) == ps->len ? chain_exit : URJ_CHAIN_EXITMODE_SHIFT); } } else { /* give the cable driver a chance to flush if it's considered useful */ urj_tap_cable_flush (chain->cable, URJ_TAP_CABLE_TO_OUTPUT); } return URJ_STATUS_OK; }
int urj_tap_cable_defer_get_tdo (urj_cable_t *cable) { int i = urj_tap_cable_add_queue_item (cable, &cable->todo); if (i < 0) return URJ_STATUS_FAIL; /* report failure */ cable->todo.data[i].action = URJ_TAP_CABLE_GET_TDO; urj_tap_cable_flush (cable, URJ_TAP_CABLE_OPTIONALLY); return URJ_STATUS_OK; /* success */ }
int urj_tap_cable_defer_get_signal (urj_cable_t *cable, urj_pod_sigsel_t sig) { int i = urj_tap_cable_add_queue_item (cable, &cable->todo); if (i < 0) return URJ_STATUS_FAIL; /* report failure */ cable->todo.data[i].action = URJ_TAP_CABLE_GET_SIGNAL; cable->todo.data[i].arg.value.sig = sig; urj_tap_cable_flush (cable, URJ_TAP_CABLE_OPTIONALLY); return URJ_STATUS_OK; /* success */ }
void urj_tap_cable_done (urj_cable_t *cable) { urj_tap_cable_flush (cable, URJ_TAP_CABLE_COMPLETELY); if (cable->todo.data != NULL) { free (cable->todo.data); free (cable->done.data); } cable->driver->done (cable); }
int urj_tap_cable_defer_set_signal (urj_cable_t *cable, int mask, int val) { int i = urj_tap_cable_add_queue_item (cable, &cable->todo); if (i < 0) return URJ_STATUS_FAIL; /* report failure */ cable->todo.data[i].action = URJ_TAP_CABLE_SET_SIGNAL; cable->todo.data[i].arg.value.mask = mask; cable->todo.data[i].arg.value.val = val; urj_tap_cable_flush (cable, URJ_TAP_CABLE_OPTIONALLY); return URJ_STATUS_OK; /* success */ }
int urj_tap_cable_defer_clock (urj_cable_t *cable, int tms, int tdi, int n) { int i = urj_tap_cable_add_queue_item (cable, &cable->todo); if (i < 0) return URJ_STATUS_FAIL; /* report failure */ cable->todo.data[i].action = URJ_TAP_CABLE_CLOCK; cable->todo.data[i].arg.clock.tms = tms; cable->todo.data[i].arg.clock.tdi = tdi; cable->todo.data[i].arg.clock.n = n; urj_tap_cable_flush (cable, URJ_TAP_CABLE_OPTIONALLY); return URJ_STATUS_OK; /* success */ }
/** * Use UrJTAG's driver to write 32-bit data (int type). * MOSI (Master Output Slave Input) is a SWD Write Operation. * \param *libswdctx swd context to work on. * \param *cmd point to the actual command being sent. * \param *data points to the char buffer array. * \bits tells how many bits to send (at most 32). * \bits nLSBfirst tells the shift direction: 0 = LSB first, other MSB first. * \return data count transferred, or negative LIBSWD_ERROR code on failure. */ int libswd_drv_mosi_32(libswd_ctx_t *libswdctx, libswd_cmd_t *cmd, int *data, int bits, int nLSBfirst){ if (data==NULL) return LIBSWD_ERROR_NULLPOINTER; if (bits<0 && bits>8) return LIBSWD_ERROR_PARAM; if (nLSBfirst!=0 && nLSBfirst!=1) return LIBSWD_ERROR_PARAM; static unsigned int i; static signed int res; static char misodata[32], mosidata[32]; //UrJTAG drivers shift data LSB-First. for (i=0;i<32;i++) mosidata[(nLSBfirst==LIBSWD_DIR_LSBFIRST)?(i):(31-i)]=((1<<i)&(*data))?1:0; res=urj_tap_cable_transfer((urj_cable_t *)libswdctx->driver->device, bits, mosidata, misodata); if (res<0) return LIBSWD_ERROR_DRIVER; urj_tap_cable_flush((urj_cable_t *)libswdctx->driver->device, URJ_TAP_CABLE_COMPLETELY); return i; }
/** * Use UrJTAG's driver to read 32-bit data (int type). * MISO (Master Input Slave Output) is a SWD Read Operation. * \param *libswdctx swd context to work on. * \param *cmd point to the actual command being sent. * \param *data points to the char buffer array. * \bits tells how many bits to send (at most 32). * \bits nLSBfirst tells the shift direction: 0 = LSB first, other MSB first. * \return data count transferred, or negative LIBSWD_ERROR code on failure. */ int libswd_drv_miso_32(libswd_ctx_t *libswdctx, libswd_cmd_t *cmd, int *data, int bits, int nLSBfirst){ if (data==NULL) return LIBSWD_ERROR_NULLPOINTER; if (bits<0 && bits>8) return LIBSWD_ERROR_PARAM; if (nLSBfirst!=0 && nLSBfirst!=1) return LIBSWD_ERROR_PARAM; static unsigned int i; static signed int res; static char misodata[32], mosidata[32]; res=urj_tap_cable_transfer((urj_cable_t *)libswdctx->driver->device, bits, mosidata, misodata); if (res<0) return LIBSWD_ERROR_DRIVER; urj_tap_cable_flush((urj_cable_t *)libswdctx->driver->device, URJ_TAP_CABLE_COMPLETELY); //Now we need to reconstruct the data byte from shifted in LSBfirst byte array. *data=0; for (i=0;i<bits;i++) *data|=(misodata[(nLSBfirst==LIBSWD_DIR_LSBFIRST)?(bits-1-i):(i)]?(1<<i):0); return i; }
int urj_tap_cable_defer_transfer (urj_cable_t *cable, int len, char *in, char *out) { char *ibuf, *obuf = NULL; int i; ibuf = malloc (len); if (ibuf == NULL) { urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "malloc(%zd) fails", (size_t) len); return URJ_STATUS_FAIL; } if (out) { obuf = malloc (len); if (obuf == NULL) { free (ibuf); urj_error_set (URJ_ERROR_OUT_OF_MEMORY, "malloc(%zd) fails", (size_t) len); return URJ_STATUS_FAIL; } } i = urj_tap_cable_add_queue_item (cable, &cable->todo); if (i < 0) { free (ibuf); if (obuf) free (obuf); return URJ_STATUS_FAIL; /* report failure */ } cable->todo.data[i].action = URJ_TAP_CABLE_TRANSFER; cable->todo.data[i].arg.transfer.len = len; if (in) memcpy (ibuf, in, len); cable->todo.data[i].arg.transfer.in = ibuf; cable->todo.data[i].arg.transfer.out = obuf; urj_tap_cable_flush (cable, URJ_TAP_CABLE_OPTIONALLY); return URJ_STATUS_OK; /* success */ }
int urj_tap_cable_get_tdo_late (urj_cable_t *cable) { int i; urj_tap_cable_flush (cable, URJ_TAP_CABLE_TO_OUTPUT); i = urj_tap_cable_get_queue_item (cable, &cable->done); if (i >= 0) { if (cable->done.data[i].action != URJ_TAP_CABLE_GET_TDO) { urj_warning ( _("Internal error: Got wrong type of result from queue (%d? %p.%d)\n"), cable->done.data[i].action, &cable->done, i); urj_tap_cable_purge_queue (&cable->done, 1); } else { return cable->done.data[i].arg.value.val; } } return cable->driver->get_tdo (cable); }
int urj_tap_cable_transfer_late (urj_cable_t *cable, char *out) { int i; urj_tap_cable_flush (cable, URJ_TAP_CABLE_TO_OUTPUT); i = urj_tap_cable_get_queue_item (cable, &cable->done); if (i >= 0 && cable->done.data[i].action == URJ_TAP_CABLE_TRANSFER) { #if 0 urj_log (URJ_LOG_LEVEL_DEBUG, "Got queue item (%p.%d) len=%d out=%p\n", &cable->done, i, cable->done.data[i].arg.xferred.len, cable->done.data[i].arg.xferred.out); #endif if (out) memcpy (out, cable->done.data[i].arg.xferred.out, cable->done.data[i].arg.xferred.len); free (cable->done.data[i].arg.xferred.out); return cable->done.data[i].arg.xferred.res; } if (cable->done.data[i].action != URJ_TAP_CABLE_TRANSFER) { urj_warning ( _("Internal error: Got wrong type of result from queue (#%d %p.%d)\n"), cable->done.data[i].action, &cable->done, i); urj_tap_cable_purge_queue (&cable->done, 1); } else { urj_warning ( _("Internal error: Wanted transfer result but none was queued\n")); } return 0; }
void urj_tap_cable_set_frequency (urj_cable_t *cable, uint32_t new_frequency) { urj_tap_cable_flush (cable, URJ_TAP_CABLE_COMPLETELY); cable->driver->set_frequency (cable, new_frequency); }
int urj_tap_cable_transfer (urj_cable_t *cable, int len, char *in, char *out) { urj_tap_cable_flush (cable, URJ_TAP_CABLE_COMPLETELY); return cable->driver->transfer (cable, len, in, out); }
int urj_tap_cable_get_signal (urj_cable_t *cable, urj_pod_sigsel_t sig) { urj_tap_cable_flush (cable, URJ_TAP_CABLE_COMPLETELY); return cable->driver->get_signal (cable, sig); }
int urj_tap_cable_set_signal (urj_cable_t *cable, int mask, int val) { urj_tap_cable_flush (cable, URJ_TAP_CABLE_COMPLETELY); return cable->driver->set_signal (cable, mask, val); }
void urj_tap_chain_flush (urj_chain_t *chain) { if (chain->cable != NULL) urj_tap_cable_flush (chain->cable, URJ_TAP_CABLE_COMPLETELY); }
int urj_tap_cable_get_tdo (urj_cable_t *cable) { urj_tap_cable_flush (cable, URJ_TAP_CABLE_COMPLETELY); return cable->driver->get_tdo (cable); }
void urj_tap_cable_clock (urj_cable_t *cable, int tms, int tdi, int n) { urj_tap_cable_flush (cable, URJ_TAP_CABLE_COMPLETELY); cable->driver->clock (cable, tms, tdi, n); }