pulp-platform / apb_timer

APB Timer Unit
Other
11 stars 22 forks source link

Documentation #5

Open HamzaShabbir517 opened 3 years ago

HamzaShabbir517 commented 3 years ago

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 commented 6 months ago

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:

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.