common fw: Add hexval() utility function

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I724c14d1dee9e268f666030053fbf62ce5e1ba71
changes/12/26912/2
Sylvain Munaut 1 year ago
parent 1b89f3bcca
commit 7bed9039e4
  1. 13
      firmware/ice40-riscv/common/utils.c
  2. 1
      firmware/ice40-riscv/common/utils.h

@ -36,6 +36,19 @@ hexstr(void *d, int n, bool space)
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, ...)

@ -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__)

Loading…
Cancel
Save