raspberry3_bare/utils.c

74 lines
1.1 KiB
C
Raw Normal View History

2022-03-15 23:09:55 +01:00
#include <stdint.h>
#include "uart.h"
2022-03-17 22:35:47 +01:00
#include "clock.h"
2022-03-15 23:09:55 +01:00
// K&R inspirated
void printhex(unsigned int d)
{
char n;
for(int c=28;c>=0;c-=4) {
// get highest tetrad
n=(d>>c)&0xF;
// 0-9 => '0'-'9', 10-15 => 'A'-'F'
n+=n>9?0x37:0x30;
putc(n);
}
}
int strlen(char s[])
{
int i=0;
while(s[i]!= '\0') {
++i;
}
return i;
}
void reverse(char s[])
{
int c, i, j;
for(i=0, j=strlen(s)-1; i<j; i++, j--) {
c=s[i];
s[i]=s[j];
s[j]=c;
}
}
void itoa(unsigned int n, char s[])
{
int i=0;
do {
s[i++]=n%10+'0';
} while((n/=10)>0);
s[i]='\0';
reverse(s);
}
void printdec(unsigned int d)
{
char s[16];
itoa(d, s);
for(int i=0; i<strlen(s); i++) {
putc(s[i]);
}
}
2022-03-17 22:35:47 +01:00
void printclock()
{
static const char *clocktxts[] = {"reserved", "EMMC", "UART", "ARM", "CORE",
"V3D", "H264", "ISP", "SDRAM", "PIXEL",
"PWM", "HEVC", "EMMC2", "M2MC", "PIXEL_BVB"};
puts("Clocks:\n");
for(int i =1; i <= CLK_PIXEL_BVB; i++ ){
puts(" ");
puts(clocktxts[i]);
puts(": ");
printdec(getclock(i, 0));
puts("/");
printdec(getclock(i, 1));
puts(" Hz\n");
}
}