common fw: Add hexval() utility function

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I724c14d1dee9e268f666030053fbf62ce5e1ba71
This commit is contained in:
Sylvain Munaut 2022-01-12 11:49:00 +01:00
parent 1b89f3bcca
commit 7bed9039e4
2 changed files with 14 additions and 0 deletions

View File

@ -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, ...)

View File

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