goodjesse
goodjesse

Reputation: 105

How to use global timer on Cortex A9 in Linux?

I write a program to read the global timer on on the cortex A9 of the OMAP4460 (Pandaboard ES). From the OMAP4 TRM [section 4.4.1] and the Cortex-A9 MPCore TRM section 1.5 , I can tell that the base address for the ARM9 gloabal timer registers is 0x4824 0200. The Cortex-A9 MPCore TRM section 4.4.1 says "There are two timer counter registers. They are the lower 32-bit timer counter at offset 0x00 and the upper 32-bit timer counter at offset 0x04". So the codes I wrote is as following , but it abort with segment fault . I don't what's wrong ? Does anyone know how exactly to read global timer on cortex A9 in Linux?

#define GLOBAL_TIMER_BASE 0X48240200U

void  rdGlobalTimer()
{
  unsigned int _low,_high;
  unsigned int addr = GLOBAL_TIMER_BASE;
  __asm__ __volatile__("ldr %0, [%1]\n\t"\
        : "=&r"(_low)
            : "r" (addr)
        : "memory");

  __asm__ __volatile__("ldr %0, [%1]\n\t"\
        : "=&r"(_high)
            : "r" (addr + 4)
        : "memory");



   printf("low:%x,high:%x\n",_low,_high);
}

Upvotes: 1

Views: 1955

Answers (1)

auselen
auselen

Reputation: 28087

You need to map (mmap) that address space, and most obvious way of doing that is via /dev/mem.

Try to compile and use devmem2.c for your target, for example

devmem2 0X48240200

You should study the example but idea is just about

...
if((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1) FATAL;
map_base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, target & ~MAP_MASK);
if(map_base == (void *) -1) FATAL;
...

Upvotes: 1

Related Questions