]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/arm/bsp/imx/timer-arm-mptimer-imx6.cpp
def5bc32335c9894236f00bc344401499f86c698
[l4.git] / kernel / fiasco / src / kern / arm / bsp / imx / timer-arm-mptimer-imx6.cpp
1 // --------------------------------------------------------------------------
2 IMPLEMENTATION[arm && imx6 && mptimer]:
3
4 #include "config.h"
5 #include "io.h"
6 #include "mem_layout.h"
7
8 PRIVATE static Mword Timer::interval()
9 {
10   enum
11   {
12     GPT_CR  = Mem_layout::Gpt_map_base + 0x00,
13     GPT_PR  = Mem_layout::Gpt_map_base + 0x04,
14     GPT_SR  = Mem_layout::Gpt_map_base + 0x08,
15     GPT_IR  = Mem_layout::Gpt_map_base + 0x0c,
16     GPT_CNT = Mem_layout::Gpt_map_base + 0x24,
17
18     GPT_CR_EN                 = 1 << 0,
19     GPT_CR_CLKSRC_MASK        = 7 << 6,
20     GPT_CR_CLKSRC_CRYSTAL_OSC = 7 << 6,
21     GPT_CR_CLKSRC_32KHZ       = 4 << 6,
22     GPT_CR_FRR                = 1 << 9,
23     GPT_CR_RESET              = 1 << 15,
24
25     Timer_freq = 32768,
26     Ticks = 50,
27     Gpt_ticks = (Timer_freq * Ticks) / Config::Scheduler_granularity,
28   };
29
30   Io::write<Mword>(0, GPT_CR);
31   Io::write<Mword>(GPT_CR_RESET, GPT_CR);
32   while (Io::read<Mword>(GPT_CR) & GPT_CR_RESET)
33     ;
34
35   Io::write<Mword>(GPT_CR_CLKSRC_32KHZ | GPT_CR_FRR, GPT_CR);
36   Io::write<Mword>(0, GPT_PR);
37
38   Io::set<Mword>(GPT_CR_EN, GPT_CR);
39   Mword vc = start_as_counter();
40   while (Io::read<Mword>(GPT_CNT) < Gpt_ticks)
41     ;
42   Mword interval = (vc - stop_counter()) / Ticks;
43   Io::write<Mword>(0, GPT_CR);
44   return interval;
45 }