[PATCH 3/8] qi-add-hex-sprintf-type-functions.patch
Andy Green
andy at openmoko.com
Tue Feb 3 19:12:28 CET 2009
We need to print hex into string buffers now, only in
phase 2
Signed-off-by: Andy Green <andy at openmoko.com>
---
include/qi.h | 4 ++++
src/utils-phase2.c | 23 +++++++++++++++++++++++
2 files changed, 27 insertions(+), 0 deletions(-)
diff --git a/include/qi.h b/include/qi.h
index 8d46ac0..84fdc50 100644
--- a/include/qi.h
+++ b/include/qi.h
@@ -126,6 +126,10 @@ void printdec(int n);
void hexdump(unsigned char *start, int len);
void udelay(int n);
+/* phase2 only */
+void setnybble(char *p, unsigned char n);
+void set8(char *p, unsigned char n);
+void set32(char *p, unsigned int u);
unsigned long crc32(unsigned long crc, const unsigned char *buf,
unsigned int len);
diff --git a/src/utils-phase2.c b/src/utils-phase2.c
index f02d5b1..bbbd672 100644
--- a/src/utils-phase2.c
+++ b/src/utils-phase2.c
@@ -109,3 +109,26 @@ void hexdump(unsigned char *start, int len)
len -= 16;
}
}
+
+void setnybble(char *p, unsigned char n)
+{
+ if (n < 10)
+ *p = '0' + n;
+ else
+ *p = 'a' + n - 10;
+}
+
+void set8(char *p, unsigned char n)
+{
+ setnybble(p, (n >> 4) & 15);
+ setnybble(p + 1, n & 15);
+}
+
+void set32(char *p, unsigned int u)
+{
+ set8(p, u >> 24);
+ set8(p + 2, u >> 16);
+ set8(p + 4, u >> 8);
+ set8(p + 6, u);
+}
+
More information about the openmoko-kernel
mailing list