如何在C中打印寄存器的内容 [英] How to print contents of register in c

查看:873
本文介绍了如何在C中打印寄存器的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调试调试的驱动程序,该驱动程序是为UART编写的,该驱动程序从串行控制台读取chars的字符串,直到用户按下"l"为止.该函数在下面称为"getstring()".

I'm trying to debug a driver that I'm writing for a UART that reads a string of chars from a serial console until the user press 'l'. The function is called 'getstring()' below.

我想检查状态寄存器的内容以查看设置了哪些位.状态寄存器偏移2.我需要在调用"getstring()"时打印它.我可以使用printf().

I want to examine the contents of a status register to see which bits are set. The status register is offset by 2. I need to print it when 'getstring()' is called. I can use printf().

这是UART的寄存器映射.

This is the register map for the UART.

当我打电话给我时,如何打印c中寄存器的内容?

When I call the How could I print out the contents of a register in c?

#define UART 0x00080000
void getchar(char *str) {

volatile uint32_t *uart = (volatile uint32_t*) UART;

char c = 0;
do
{
    while ((uart[2] & (1<<7)) == 0);
    c = uart[0];
    *str++ = c;
}
while (c!='l');

}

`

推荐答案

要将二进制文件转换为1和0的ASCII字符串,只需执行以下操作:

To convert from binary to an ASCII string of ones and zeroes, simply do this:

uint32_t local = *uart;
for(size_t i=0; i<32; i++)
{
  *str = (local & (1u << 31-i) ? '1' : '0';
  str++;
}
*str = '\0';

这篇关于如何在C中打印寄存器的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆