tnt has uploaded this change for review.

View Change

common fw: Add hexval() utility function

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I724c14d1dee9e268f666030053fbf62ce5e1ba71
---
M firmware/ice40-riscv/common/utils.c
M firmware/ice40-riscv/common/utils.h
2 files changed, 14 insertions(+), 0 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/osmo-e1-hardware refs/changes/12/26912/1
diff --git a/firmware/ice40-riscv/common/utils.c b/firmware/ice40-riscv/common/utils.c
index 1ac111b..7c7d3d0 100644
--- a/firmware/ice40-riscv/common/utils.c
+++ b/firmware/ice40-riscv/common/utils.c
@@ -36,6 +36,19 @@
return buf;
}

+uint8_t
+hexval(char c)
+{
+ if (c >= '0' && c <= '9')
+ return c - '0';
+ else if (c >= 'a' && c <= 'f')
+ return 10 + (c - 'a');
+ else if (c >= 'A' && c <= 'F')
+ return 10 + (c - 'A');
+ else
+ return 0;
+}
+

void
_panic(const char *file, int lineno, const char *fmt, ...)
diff --git a/firmware/ice40-riscv/common/utils.h b/firmware/ice40-riscv/common/utils.h
index 03359ae..37cc88e 100644
--- a/firmware/ice40-riscv/common/utils.h
+++ b/firmware/ice40-riscv/common/utils.h
@@ -10,6 +10,7 @@
#include <stdbool.h>

char *hexstr(void *d, int n, bool space);
+uint8_t hexval(char c);

void _panic(const char *file, int lineno, const char *fmt, ...);
#define panic(fmt, ...) _panic(__FILE__, __LINE__, fmt, ##__VA_ARGS__)

To view, visit change 26912. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: osmo-e1-hardware
Gerrit-Branch: master
Gerrit-Change-Id: I724c14d1dee9e268f666030053fbf62ce5e1ba71
Gerrit-Change-Number: 26912
Gerrit-PatchSet: 1
Gerrit-Owner: tnt <tnt@246tNt.com>
Gerrit-MessageType: newchange