Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation #5

Open
HamzaShabbir517 opened this issue Jul 30, 2021 · 1 comment
Open

Documentation #5

HamzaShabbir517 opened this issue Jul 30, 2021 · 1 comment

Comments

@HamzaShabbir517
Copy link

Hello i wanted to use the APB peripherals from your repo but i cant find the proper documentation regarding the registers each peripheral have and their purpose and working. Can you provide the documentation you guys have followed to design these modules

@Juan-Gg
Copy link

Juan-Gg commented Apr 25, 2024

Hi there. I was facing the same situation. I do not know why is it so hard to leave a simple usage example ....

Anyways, for future reference:

  • There is some information here, page 22, for the "pulpino" platform, that uses the same timer.
  • Here is an example I cobbled together for use in the cva6 platform, that uses the same timer (with a different base address).

A header file:

#define REG_32(addr) (*(volatile uint32_t*)(addr))


#define TIMER_BASE_ADDRESS 0x18000000

#define TIMER0_VALUE    REG_32(TIMER_BASE_ADDRESS + 0)

#define TIMER0_CTRL     REG_32(TIMER_BASE_ADDRESS + 4)
    #define TIMER_CTRL_BIT_EN 1
    #define TIMER_CTRL_BITS_PRESCALER(a) ((a & 0x7) << 3)

#define TIMER0_CMP      REG_32(TIMER_BASE_ADDRESS + 8)


#define TIMER0_START()  (TIMER0_CTRL |= TIMER_CTRL_BIT_EN)
#define TIMER0_STOP()   (TIMER0_CTRL &= ~TIMER_CTRL_BIT_EN)
#define TIMER0_RESET()  (TIMER0_CMP = 0)

In use:

// Start
TIMER0_RESET();
TIMER0_START();

// Do something

TIMER0_STOP();

uart_print("Timer Cycles: ");
uart_print_unsigned_dec(TIMER0_VALUE);
uart_print("\n\r");

Notes: Per the sv source, writing to the CMP register clears the counter. I have not used it for anything else. Likewise, I did not test the prescaler, or the second timer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants