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

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [conts/] [libdev/] [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 <l4lib/types.h>
10
#include "timer.h"
11
 
12
/* Enable timer with its current configuration */
13
void timer_start(unsigned long timer_base)
14
{
15
        volatile u32 reg = read(timer_base + SP804_CTRL);
16
 
17
        reg |= SP804_ENABLE;
18
 
19
        write(reg, timer_base + SP804_CTRL);
20
 
21
}
22
 
23
/* Load the timer with ticks value */
24
void timer_load(u32 loadval, unsigned long timer_base)
25
{
26
        write(loadval, timer_base + SP804_LOAD);
27
}
28
 
29
u32 timer_read(unsigned long timer_base)
30
{
31
        return read(timer_base + SP804_VALUE);
32
}
33
 
34
void timer_stop(unsigned long timer_base)
35
{
36
        write(0, timer_base + SP804_CTRL);
37
}
38
 
39
void timer_init_periodic(unsigned long timer_base, u32 load_value)
40
{
41
        volatile u32 reg = read(timer_base + SP804_CTRL);
42
 
43
        reg |= SP804_PERIODIC | SP804_32BIT | SP804_IRQEN;
44
 
45
        write(reg, timer_base + SP804_CTRL);
46
 
47
        if (load_value)
48
                timer_load(load_value, timer_base);
49
        else
50
                /* 1 tick per usec, 1 irq per msec */
51
                timer_load(1000, timer_base);
52
}
53
 
54
void timer_init_oneshot(unsigned long timer_base)
55
{
56
        volatile u32 reg = read(timer_base + SP804_CTRL);
57
 
58
        /* One shot, 32 bits, no irqs */
59
        reg |= SP804_32BIT | SP804_ONESHOT;
60
 
61
        write(reg, timer_base + SP804_CTRL);
62
}
63
 
64
void timer_init(unsigned long timer_base, u32 load_value)
65
{
66
        timer_stop(timer_base);
67
        timer_init_periodic(timer_base, load_value);
68
}

powered by: WebSVN 2.1.0

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