簡體   English   中英

讀取全志H3 ARM處理器的寄存器

[英]Reading from register of Allwinner H3 ARM processor

#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();

};

它編譯但結果返回Segmentation fault消息。 我只想重置寄存器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
  • 顯然,它必須在超級用戶下運行;
  • 您的代碼可能會干擾系統的其他部分,例如訪問相同外圍設備的內核驅動程序,從而導致不可預測的結果。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM