i was trying to the read the system timer, to do some calibration stuff for another piece.
Thats my code:
- Code: Select all
#define BCM2708_PERI_BASE 0x20000000
#define SYST_BASE (BCM2708_PERI_BASE + 0x3000) /* SYST controller */
#define SYST_CS 0x0
#define SYST_CLO 0x4
#define SYST_CHI 0x8
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <dirent.h>
#include <fcntl.h>
#include <assert.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#define PAGE_SIZE (4*1024)
#define BLOCK_SIZE (4*1024)
int mem_fd;
char *syst_mem, *syst_map;
volatile unsigned *syst;
void setup_io();
void restore_io();
void prnt_syst();
int main(int argc, char **argv)
{
setup_io();
prnt_syst();
restore_io();
}
void prnt_syst()
{
int syst_cs, syst_clo, syst_chi;
syst_cs = *(syst + SYST_CS);
syst_clo = *(syst + SYST_CLO);
syst_chi = *(syst + SYST_CHI);
printf("syst: %08lx\n",(unsigned int)syst);
printf("syst_cs syst_clo syst_chi\n");
printf("%08lx %08lx %08lx\n",syst_cs,syst_clo,syst_chi);
}
void setup_io()
{
if ((mem_fd = open("/dev/mem", O_RDWR|O_SYNC) ) < 0) {
printf("can't open /dev/mem \n");
exit (-1);
}
if ((syst_mem = malloc(BLOCK_SIZE + (PAGE_SIZE-1))) == NULL) {
printf("allocation error \n");
exit (-1);
}
if ((unsigned long)syst_mem % PAGE_SIZE)
syst_mem += PAGE_SIZE - ((unsigned long)syst_mem % PAGE_SIZE);
syst_map = (unsigned char *)mmap(
(caddr_t)syst_mem, BLOCK_SIZE, PROT_READ|PROT_WRITE,
MAP_SHARED|MAP_FIXED, mem_fd, SYST_BASE);
if ((long)syst_map < 0) {
printf("mmap error %d\n", (int)syst_map);
exit (-1);
}
syst = (volatile unsigned *)syst_map;
}
void restore_io()
{
munmap(syst_map,BLOCK_SIZE);
}
Thats the output of this short program:
- Code: Select all
syst: 0152f000
syst_cs syst_clo syst_chi
00000002 00000000 74696d65
The 74696d65 seems to be ASCII: "time", but not the system timer.
Whats wrong?
Any hints appreciated.
Best Regards