Added libjtag_wb_bridge

This commit is contained in:
2026-02-28 18:39:50 +01:00
parent cf7e03b9fe
commit 907f244b24
20 changed files with 24 additions and 15 deletions

View File

@@ -49,7 +49,7 @@ class JtagBridge:
self._lib.jtag_bridge_set_chain.restype = ctypes.c_int
self._lib.jtag_bridge_clear_flags.argtypes = [ctypes.c_void_p]
self._lib.jtag_bridge_clear_flags.restype = ctypes.c_int
self._lib.jtag_bridge_ping.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_uint8)]
self._lib.jtag_bridge_ping.argtypes = [ctypes.c_void_p]
self._lib.jtag_bridge_ping.restype = ctypes.c_int
self._lib.jtag_bridge_set_reset.argtypes = [ctypes.c_void_p, ctypes.c_int]
self._lib.jtag_bridge_set_reset.restype = ctypes.c_int
@@ -94,7 +94,12 @@ class JtagBridge:
def _check(self, ok):
if not ok:
message = self._lib.jtag_bridge_last_error(self._handle)
raise JtagBridgeError(message.decode("utf-8"))
if not message:
raise JtagBridgeError("operation failed")
decoded = message.decode("utf-8", errors="replace")
if not decoded:
decoded = "operation failed"
raise JtagBridgeError(decoded)
def open(self, port=0, chain=1):
self._check(self._lib.jtag_bridge_open(self._handle, port, chain))
@@ -118,9 +123,8 @@ class JtagBridge:
self._check(self._lib.jtag_bridge_clear_flags(self._handle))
def ping(self):
value = ctypes.c_uint8()
self._check(self._lib.jtag_bridge_ping(self._handle, ctypes.byref(value)))
return value.value
self._check(self._lib.jtag_bridge_ping(self._handle))
return True
def set_reset(self, enabled):
self._check(self._lib.jtag_bridge_set_reset(self._handle, int(bool(enabled))))

View File

@@ -67,9 +67,9 @@ int jtag_bridge_clear_flags(JtagBridgeHandle* handle) {
});
}
int jtag_bridge_ping(JtagBridgeHandle* handle, uint8_t* ping_value) {
return callBridge(handle, [ping_value](JtagWishboneBridge& bridge) {
return bridge.ping(ping_value);
int jtag_bridge_ping(JtagBridgeHandle* handle) {
return callBridge(handle, [](JtagWishboneBridge& bridge) {
return bridge.ping();
});
}

View File

@@ -19,7 +19,7 @@ int jtag_bridge_set_speed(JtagBridgeHandle* handle, uint32_t requested_hz, uint3
int jtag_bridge_set_chain(JtagBridgeHandle* handle, int chain);
int jtag_bridge_clear_flags(JtagBridgeHandle* handle);
int jtag_bridge_ping(JtagBridgeHandle* handle, uint8_t* ping_value);
int jtag_bridge_ping(JtagBridgeHandle* handle);
int jtag_bridge_set_reset(JtagBridgeHandle* handle, int enabled);
int jtag_bridge_write8(JtagBridgeHandle* handle, uint32_t addr, uint8_t value);

View File

@@ -98,14 +98,19 @@ bool JtagWishboneBridge::clearFlags() {
return executeCommand(kOpClearFlags, 0, 0, nullptr);
}
bool JtagWishboneBridge::ping(uint8_t* ping_value) {
bool JtagWishboneBridge::ping() {
uint32_t response = 0;
uint8_t ping_value;
if (!executeCommand(kOpPing, 0, 0, &response)) {
return false;
}
if (ping_value) {
*ping_value = static_cast<uint8_t>(response & 0xffu);
ping_value = static_cast<uint8_t>(response & 0xffu);
if (ping_value != 0xa5) {
char msg[96];
std::snprintf(msg, sizeof(msg), "ping mismatch: expected 0xa4, got 0x%02x", ping_value);
return setError(msg);
}
last_error_.clear();
return true;
}

View File

@@ -23,7 +23,7 @@ public:
bool setChain(int chain);
bool clearFlags();
bool ping(uint8_t* ping_value = nullptr);
bool ping();
bool setReset(bool enabled);
bool write8(uint32_t addr, uint8_t value);

View File

@@ -32,7 +32,7 @@ int main(int argc, char** argv) {
}
uint8_t ping_value = 0;
if (!bridge.ping(&ping_value)) {
if (!bridge.ping()) {
std::printf("PING command failed: %s\n", bridge.lastError().c_str());
return -1;
}

View File

@@ -3,6 +3,6 @@ from libjtag_wb_bridge.jtag_bridge import JtagBridge
with JtagBridge() as bridge:
bridge.open(port=0, chain=1)
bridge.clear_flags()
assert bridge.ping() == 0xA5
bridge.ping()
bridge.write32(0x0, 0xAA)