初次接触嵌入式开发,请教一个问题,希望大侠们指教

内核编译和嵌入式产品的设计与开发
回复
wwangxt
帖子: 5
注册时间: 2008-10-26 11:57

初次接触嵌入式开发,请教一个问题,希望大侠们指教

#1

帖子 wwangxt » 2009-05-27 9:45

问一个问题,在开发基于at91rm9200的驱动时在访问I/O端口时,在linux系统下我如何来访问这个I/O端口,可以直接通过物理地址 就行访问么?我如果这样写#define PIOA_PER (*(volatile unsigned *)0xfffff400)定义了该端口,然后通过这样PIOA_PER |=0x00000001对其进行赋值是否可行,还是通过ioremap函数将其定位到内核的虚拟地址然后进行访问?希望大侠们帮我指点一下,不胜感激!
bienilz
帖子: 5
注册时间: 2008-11-04 18:29

Re: 初次接触嵌入式开发,请教一个问题,希望大侠们指教

#2

帖子 bienilz » 2009-05-27 15:27

在 LDD 中的 Communication with Hardware 中的 Platform Dependencies 中是这样描述的:
  • ARM

    Ports are memory-mapped, and all functions are supported; string functions are
    implemented in C. Ports are of type unsigned int.
Accessing I/O Memory 中又讲到:
  • To read from I/O memory, use one of the following:
    unsigned int ioread8(void *addr);
    unsigned int ioread16(void *addr);
    unsigned int ioread32(void *addr);
    Here, addr should be an address obtained from ioremap (perhaps with an integer offset);
    the return value is what was read from the given I/O memory.
    There is a similar set of functions for writing to I/O memory:
    void iowrite8(u8 value, void *addr);
    void iowrite16(u16 value, void *addr);
    void iowrite32(u32 value, void *addr);
所以按我的理解,应该要用 ioremap 函数。
回复