-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathprintk.c
43 lines (37 loc) · 787 Bytes
/
printk.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
* Raspberry PI Remote Serial Protocol.
* Copyright 2012 Jamie Iles, jamie@jamieiles.com.
* Licensed under GPLv2.
*/
#include "printk.h"
#include "uart.h"
void puts(const char *str)
{
const char *p = str;
while (*p)
uart_putc(*p++);
}
void put_hex_byte(char *dst, char b)
{
char digits[] = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
};
*dst++ = digits[(b & 0xf0) >> 4];
*dst++ = digits[b & 0xf];
*dst = '\0';
}
void print_hex(unsigned long r)
{
char buf[9] = {};
char digits[] = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
};
int i;
for (i = 0; i < 8; i++) {
unsigned long t = (r & (0xf << (i * 4))) >> (i * 4);
buf[7 - i] = digits[t];
}
puts(buf);
}