Commit 21818eb9 by triazo

Adds hex output to serial

parent 3e6dc6c2
Showing with 25 additions and 0 deletions
...@@ -32,3 +32,18 @@ void serial_writestring(char* s) { ...@@ -32,3 +32,18 @@ void serial_writestring(char* s) {
s++; s++;
} }
} }
const char* hexchars = "0123456789abcdef";
void serial_hexword(uint32_t x) {
for (int i = 8; i != 0; i--) {
serial_writechar(hexchars[x>>i*4&0xf]);
}
}
void serial_hexstring(void* s, uint32_t n) {
char* d = (char*)s;
for (uint32_t i = 0; i < n; i++) {
serial_writechar(hexchars[(d[i]>>4)&0xf]);
serial_writechar(hexchars[d[i]&0xf]);
}
}
...@@ -2,7 +2,11 @@ ...@@ -2,7 +2,11 @@
serial.h contains headers for the serial interaction functions serial.h contains headers for the serial interaction functions
*/ */
#ifndef _SERIAL_INC
#define _SERIAL_INC
#include "asm.h" #include "asm.h"
#include <stdint.h>
// Initilizes the first serial port // Initilizes the first serial port
void serial_init(); void serial_init();
...@@ -15,3 +19,9 @@ void serial_writechar(char a); ...@@ -15,3 +19,9 @@ void serial_writechar(char a);
// Write a null terminated string to serial // Write a null terminated string to serial
void serial_writestring(char* s); void serial_writestring(char* s);
// Function to write a 4 byte word toserial in hex
void serial_hexword(uint32_t x);
void serial_hexstring(void* s, uint32_t n);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment