aboutsummaryrefslogtreecommitdiff
path: root/bcmclock.h
blob: dd7136bcfbbe907ccfff7ebbf46ef13580638a9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#ifndef BCMCLOCK_H
#define BCMCLOCK_H

#include <stdint.h>

#include "global.h"

#define ST_BASE (PERIF_BASE + 0x3000) // System Timer

#define ST_CS  (ST_BASE + 0x0)  // System Timer Control/Status
#define ST_CLO (ST_BASE + 0x4)  // System Timer Counter Lower 32 bits
#define ST_CHI (ST_BASE + 0x8)  // System Timer Counter Higher 32 bits
#define ST_C0  (ST_BASE + 0xC)  // System Timer Compare 0
#define ST_C1  (ST_BASE + 0x10) // System Timer Compare 1
#define ST_C2  (ST_BASE + 0x14) // System Timer Compare 2
#define ST_C3  (ST_BASE + 0x18) // System Timer Compare 3

static inline void bcmclk_enable_timer_irq(void)
{
  *(uint32_t volatile*) ARM_ENABLE_IRQS_1 = 1 << 3;
}

static inline void bcmclk_disable_timer_irq(void)
{
  *(uint32_t volatile*) ARM_DISABLE_IRQS_1 = 1 << 3;
}

static inline void bcmclk_irq_settimeout(uint32_t timeout)
{
  uint32_t clock_now = *(uint32_t volatile*) ST_CLO;
  *(uint32_t volatile*) ST_C3 = clock_now + timeout;
  *(uint32_t volatile*) ST_CS = 1 << 3;
}

#endif // BCMCLOCK_H