[Cryptech-Commits] [sw/libhal] 01/02: Use environment variables to specify serial device rather than hard-wiring it.
git at cryptech.is
git at cryptech.is
Fri Jul 1 23:33:08 UTC 2016
This is an automated email from the git hooks/post-receive script.
sra at hactrn.net pushed a commit to branch macosx
in repository sw/libhal.
commit 904361120ef5eed8b0bb06da8ec90e4b7f1ef81a
Author: Rob Austein <sra at hactrn.net>
AuthorDate: Fri Jul 1 18:44:13 2016 -0400
Use environment variables to specify serial device rather than hard-wiring it.
---
hal_internal.h | 7 +++++++
rpc_client_serial.c | 12 +++++++++++-
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/hal_internal.h b/hal_internal.h
index 7a97a87..5bdc83f 100644
--- a/hal_internal.h
+++ b/hal_internal.h
@@ -478,6 +478,13 @@ typedef enum {
#define HAL_CLIENT_SERIAL_DEFAULT_SPEED 921600
#endif
+/*
+ * Names of environment variables for setting the above in RPC clients.
+ */
+
+#define HAL_CLIENT_SERIAL_DEVICE_ENVVAR "HAL_CLIENT_SERIAL_DEVICE"
+#define HAL_CLIENT_SERIAL_SPEED_ENVVAR "HAL_CLIENT_SERIAL_SPEED"
+
#endif /* _HAL_INTERNAL_H_ */
/*
diff --git a/rpc_client_serial.c b/rpc_client_serial.c
index 149998e..34da852 100644
--- a/rpc_client_serial.c
+++ b/rpc_client_serial.c
@@ -47,7 +47,17 @@
hal_error_t hal_rpc_client_transport_init(void)
{
- return hal_serial_init(HAL_CLIENT_SERIAL_DEFAULT_DEVICE, HAL_CLIENT_SERIAL_DEFAULT_SPEED);
+ const char *device = getenv(HAL_CLIENT_SERIAL_DEVICE_ENVVAR);
+ const char *speed_ = getenv(HAL_CLIENT_SERIAL_SPEED_ENVVAR);
+ uint32_t speed = HAL_CLIENT_SERIAL_DEFAULT_SPEED;
+
+ if (device == NULL)
+ device = HAL_CLIENT_SERIAL_DEFAULT_DEVICE;
+
+ if (speed_ != NULL)
+ speed = (uint32_t) strtoul(speed_, NULL, 10);
+
+ return hal_serial_init(device, speed);
}
hal_error_t hal_rpc_client_transport_close(void)
More information about the Commits
mailing list