Am I using mmap() incorreclty

0

I've hit a roadblock, I'm trying to read the DMTIMER_1MS internal counter. This is the code im running.

#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include "logger.c"

#define DATA_BUF 10
#define DMTIMER_BASE 0x44E31000
#define DMTIMER_SIZE 0x1000         //4096
#define TCRR 0x28

int main (int argc, char *argv[])
{

  volatile uint32_t* dmtimer_addr;
  volatile uint32_t* dmtimer_tcrr;

  int fd = open("/dev/mem", O_RDWR);

  if( fd < 0){
    log_error("Cannot open /dev/mem");
    exit_scale(nau7802_0, log_fd);
    return 0;
  }

  dmtimer_addr = mmap(NULL, DMTIMER_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd,  DMTIMER_BASE);
  dmtimer_tcrr = (dmtimer_addr+TCRR);
  close(fd);

  printf("0x%08x\n", *dmtimer_addr);
  printf("%d\n", *dmtimer_tcrr);

  return 0;
}

When I run the code I get the following output

0x00000015
0

If I run devmem from busybox for those two memory locations I get the following

xxxx@beaglebone:~/nfs$ sudo busybox devmem 0x44E31000 32
0x00000015
xxxx@beaglebone:~/nfs$ sudo busybox devmem 0x44E31028 32
0x4DC6133D
xxxx@beaglebone:~/nfs$ sudo busybox devmem 0x44E31028 32
0x4ED5FA3E
xxxx@beaglebone:~/nfs$ sudo busybox devmem 0x44E31028 32
0x4FDC84DD

This leads me to believe two things

  1. I'm setting up mmap partially correct if I'm seeing the 0x15 revision number
  2. The counter is enabled and free running

I'm not sure what I'm missing.

c
memory
timer
beagleboneblack
asked on Stack Overflow Apr 3, 2020 by Lpaulson

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0