#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
static void foo(void){
volatile uint32_t *temp_addr;
temp_addr = (uint32_t*)(0x01C20C00);
*temp_addr =0;
}
int main(){
tinit();
};
它编译但返回段错误
消息作为结果。我只想重置寄存器0x01c200c00
中的所有位。
最佳答案
你的程序无法运行,因为0x01C20C00是物理地址,但你的程序使用了虚拟地址。为了进行实验,您可以访问 GPIO、定时器或其他外设,而无需编写内核驱动程序。为此,您需要创建一个内存映射,如下所示:
#define ALLWINNER_TIMER_BASE 0x01C20C00
struct allwinner_timer
{
volatile uint32_t IRQ_EN_REG;
// add other registers from the datasheet, or find a kernel driver source with these definitions
};
int fd = open("/dev/mem", O_RDWR);
struct allwinner_timer *t = (struct allwinner_timer *)mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, ALLWINNER_TIMER_BASE);
// TODO: check for errors
t->IRQ_EN_REG = 0;
请注意:
- 如果内核限制对
/dev/mem
的访问,它可能无法工作。这可以通过查看内核选项来找到,例如CONFIG_STRICT_DEVMEM 并使用dmesg
; - 显然,它必须在 super 用户下运行;
- 您的代码可能会干扰系统的其他部分,例如内核驱动程序访问同一外设,导致不可预测的结果。
关于c - 读取全志H3 ARM处理器的寄存器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59749160/