Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9218159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:47:53+00:00 2026-06-18T02:47:53+00:00

I am asked this: Using your RPi, write a C function that reads the

  • 0

I am asked this:

Using your RPi, write a C function that reads the free running system
timer. The system timer counts up every microsecond. Place the
source for this function its own file. The free running timer is a 64
bit value located at physical memory address 0x20003004, however, the
RPi can only access 32 bits at a time in this memory area. To access
these memory locations mmap() will be called on the file /dev/mem.
Be sure to always check for and act appropriately to errors. To
access the system timer:
(a) Check to see if the counter is mapped by
testing a static variable.

(b) If the counter is not mapped then

i.
open /dev/men read only.

ii. get the system page size

iii. call
mmap() and save the returned address (pointer to 32 bit integers) in a
static variable. call mmap() by allowing mmap() to set the address
mapping. Set the length to the page size. Set the protection to
read only. Set the flags to a shared map. Next, pass the file
descriptor returned by open(), and then set the offset to 0x20003000.
Remember, for this case, mmap() can only operate on pages of
__SC_PAGESIZE bytes, so the address 0x20003004 cannot be directly mapped – the address must be __SC_PAGESIZE aligned.

iv. Set the
static variable to indicate that initialization has occurred.

v.
Close the open file.

(c) If initialization is successful, return a 64
bit number by combing the 32 bit value at index 1 with the 32 bit
value at index 2. The 32 bit value at index 1 contains the least
significant 32 bits of the counter. The 32 bit value at index 2
contains the most significant 32 bits of the counter. Otherwise
return 0.

I was able to get the contents of the timer for the first memory location 0x20003000 :

int main(int argc, char * argv[])
{
    int temp;
    int page_size;
    int *map;

    temp = open("/dev/mem", O_RDONLY);
    page_size = sysconf(_SC_PAGESIZE);


    map = mmap(0, page_size, PROT_READ, MAP_SHARED, temp, 0x20003000);
    printf("%X \n", map);

    close(temp);
    return 0;
}

I am lost at the part where it asks me to get the other 32 bit number 0x20003004 and combine it with the original. Any help or guidance it welcome.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T02:47:54+00:00Added an answer on June 18, 2026 at 2:47 am

    From your quoted description:

    Remember, for this case, mmap() can only operate on pages of
    __SC_PAGESIZE bytes, so the address 0x20003004 cannot be directly mapped – the address must be __SC_PAGESIZE aligned.

    What this means is that mmap() can only map to addresses that are aligned to __SC_PAGESIZE. It also means that the address returned by mmap() can be dereferenced up to page_size. I.e., if the call to mmap() with 0x20003000 returns 0x20003000, you can dereference pointers within [0x20003000, 0x20003000 + page_size).

    I’ll leave the rest as an exercise for the reader.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am asked: Using your raspberry pi, write a python script that determines the
I know that this has already been asked here but the answer (using a
Earlier I asked this question ( and after some googling I read Using your
I have asked this on the castle list as i'm using the nh facility
This question is a furtherance of the one asked in this thread . Using
I am new to python, apologies if this has been asked already. Using python
Is this a common task in your Drupal work when you're asked to create
This was A Question Asked by my teacher. How Would You Stop Your Script
Somebody asked me this question: Two processes P1 and P2 are using a shared
This web page suggests that if your lex program has a large number of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.