From 41edfec702ba79f8554556b3a227c0f7c212b433 Mon Sep 17 00:00:00 2001 From: icex2 Date: Wed, 16 Dec 2020 22:47:43 +0100 Subject: [PATCH] bio2drv: Add implementation for iidx Basically, a copy-paste of SDVX KFCA with minor tweaks. --- src/main/bio2drv/Module.mk | 3 +- src/main/bio2drv/bi2a-iidx.c | 101 +++++++++++++++++++++++++++++++++++ src/main/bio2drv/bi2a-iidx.h | 33 ++++++++++++ 3 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 src/main/bio2drv/bi2a-iidx.c create mode 100644 src/main/bio2drv/bi2a-iidx.h diff --git a/src/main/bio2drv/Module.mk b/src/main/bio2drv/Module.mk index 3d8b063..f5bdb56 100644 --- a/src/main/bio2drv/Module.mk +++ b/src/main/bio2drv/Module.mk @@ -6,4 +6,5 @@ libs_bio2drv := \ src_bio2drv := \ detect.c \ config-bio2.c \ - bi2a-sdvx.c \ + bi2a-iidx.c \ + bi2a-sdvx.c diff --git a/src/main/bio2drv/bi2a-iidx.c b/src/main/bio2drv/bi2a-iidx.c new file mode 100644 index 0000000..d20056d --- /dev/null +++ b/src/main/bio2drv/bi2a-iidx.c @@ -0,0 +1,101 @@ +#define LOG_MODULE "bio2drv-bi2a_iidx" + +#include "bio2drv/bi2a-iidx.h" + +#include +#include + +#include "aciodrv/device.h" + +#include "util/log.h" + +static bool bio2drv_bi2a_iidx_init_io(uint8_t node_id) +{ + struct ac_io_message msg; + + msg.addr = node_id + 1; + msg.cmd.code = ac_io_u16(AC_IO_CMD_CLEAR); + msg.cmd.nbytes = 1; + msg.cmd.count = 0x3B; + + if (!aciodrv_send_and_recv( + &msg, offsetof(struct ac_io_message, cmd.raw) + 1)) { + log_warning("Init node failed"); + return 0; + } + + log_warning("Init of node %d, status: %d", node_id, msg.cmd.status); + + return 1; +} + +static bool bio2drv_bi2a_iidx_watchdog_start(uint8_t node_id) +{ + // exit early and don't actually call watchdog + // the watchdog call actually returns different sized packets depending on + // the state this results in an issue during packet processing (see: #68) + return true; + + /* + struct ac_io_message msg; + + msg.addr = node_id + 1; + msg.cmd.code = ac_io_u16(AC_IO_CMD_KFCA_WATCHDOG); + msg.cmd.nbytes = 2; + msg.cmd.nbytes = 2; + + // uint16_t: 6000 + msg.cmd.raw[0] = 23; + msg.cmd.raw[1] = 112; + + if (!aciodrv_send_and_recv( + &msg, offsetof(struct ac_io_message, cmd.raw) + 2 + )) { + log_warning("Starting watchdog failed"); return false; + } + + log_warning("Started watchdog of node %d, status: %d", + node_id, msg.cmd.status); + + return true; + */ +} + +bool bio2drv_bi2a_iidx_init(uint8_t node_id) +{ + if (!bio2drv_bi2a_iidx_init_io(node_id)) { + return false; + } + + if (!bio2drv_bi2a_iidx_watchdog_start(node_id)) { + return false; + } + + return true; +} + +bool bio2drv_bi2a_iidx_poll( + uint8_t node_id, + const struct bi2a_iidx_state_out *pout, + struct bi2a_iidx_state_in *pin) +{ + struct ac_io_message msg; + + msg.addr = node_id + 1; + msg.cmd.code = ac_io_u16(BIO2_BI2A_CMD_POLL); + msg.cmd.nbytes = sizeof(*pout); + /* buffer size of data we expect */ + *(struct bi2a_iidx_state_out *) msg.cmd.raw = *pout; + + if (!aciodrv_send_and_recv( + &msg, offsetof(struct ac_io_message, cmd.raw) + sizeof(*pin))) { + log_warning("Polling of node %d failed", node_id + 1); + return false; + } + + if (pin != NULL) { + memcpy(pin, &msg.cmd.raw, sizeof(*pin)); + } + + return true; +} diff --git a/src/main/bio2drv/bi2a-iidx.h b/src/main/bio2drv/bi2a-iidx.h new file mode 100644 index 0000000..6ec62e0 --- /dev/null +++ b/src/main/bio2drv/bi2a-iidx.h @@ -0,0 +1,33 @@ +#ifndef BIO2DRV_BI2A_IIDX_H +#define BIO2DRV_BI2A_IIDX_H + +#include "bio2/bi2a-iidx.h" + +/** + * Initialize a BI2A node. + * + * @param node_id Id of the node to initialize (0 based). + * @return True if successful, false on error. + * @note This module is supposed to be used in combination with the common + * device driver foundation. + * @see driver.h + */ +bool bio2drv_bi2a_iidx_init(uint8_t node_id); + +/** + * Poll the BI2A board + * + * @param node_id Id of the node to query (0 based). + * @param state Pointer to a state struct to return the current state to + * (optional, NULL for none). + * @return True on success, false on error. + * @note This module is supposed to be used in combination with the common + * device driver foundation. + * @see driver.h + */ +bool bio2drv_bi2a_iidx_poll( + uint8_t node_id, + const struct bi2a_iidx_state_out *pout, + struct bi2a_iidx_state_in *pin); + +#endif