OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [src/] [drivers/] [timer/] [sp804/] [timer.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
/*
2
 * SP804 primecell driver honoring generic
3
 * timer library API
4
 *
5
 * Copyright (C) 2010 B Labs Ltd.
6
 *
7
 * Author: Bahadir Balban
8
 */
9
#include INC_ARCH(io.h)
10
#include <l4/drivers/timer/sp804/timer.h>
11
 
12
unsigned long timer_secondary_base(unsigned long timer_base)
13
{
14
        return timer_base + SP804_SECONDARY_OFFSET;
15
}
16
 
17
void timer_irq_clear(unsigned long timer_base)
18
{
19
        write(1, timer_base + SP804_INTCLR);
20
}
21
 
22
/* Enable timer with its current configuration */
23
void timer_start(unsigned long timer_base)
24
{
25
        volatile u32 reg = read(timer_base + SP804_CTRL);
26
 
27
        reg |= SP804_ENABLE;
28
 
29
        write(reg, timer_base + SP804_CTRL);
30
 
31
}
32
 
33
/* Load the timer with ticks value */
34
void timer_load(u32 loadval, unsigned long timer_base)
35
{
36
        write(loadval, timer_base + SP804_LOAD);
37
}
38
 
39
u32 timer_read(unsigned long timer_base)
40
{
41
        return read(timer_base + SP804_VALUE);
42
}
43
 
44
void timer_stop(unsigned long timer_base)
45
{
46
        write(0, timer_base + SP804_CTRL);
47
}
48
 
49
void timer_init_periodic(unsigned long timer_base, unsigned int load_value)
50
{
51
        volatile u32 reg;
52
 
53
        /* Periodic, wraparound, 32 bit, irq on wraparound */
54
        reg = SP804_PERIODIC | SP804_32BIT | SP804_IRQEN;
55
 
56
        write(reg, timer_base + SP804_CTRL);
57
 
58
        /* 1 tick per usec, 1 irq per msec */
59
        if (load_value)
60
                timer_load(load_value, timer_base);
61
        else
62
                timer_load(1000, timer_base);
63
}
64
 
65
void timer_init_oneshot(unsigned long timer_base)
66
{
67
        volatile u32 reg = read(timer_base + SP804_CTRL);
68
 
69
        /* One shot, 32 bits, no irqs */
70
        reg |= SP804_32BIT | SP804_ONESHOT;
71
 
72
        write(reg, timer_base + SP804_CTRL);
73
}
74
 
75
void timer_init(unsigned long timer_base, unsigned int load_value)
76
{
77
        timer_init_periodic(timer_base, load_value);
78
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.