summaryrefslogtreecommitdiff
path: root/firmware/target/arm/pnx0101/timer-pnx0101.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/pnx0101/timer-pnx0101.c')
-rw-r--r--firmware/target/arm/pnx0101/timer-pnx0101.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/firmware/target/arm/pnx0101/timer-pnx0101.c b/firmware/target/arm/pnx0101/timer-pnx0101.c
new file mode 100644
index 0000000000..6e685aa20f
--- /dev/null
+++ b/firmware/target/arm/pnx0101/timer-pnx0101.c
@@ -0,0 +1,82 @@
1/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8* $Id$
9*
10* Copyright (C) 2007 Tomasz Malesinski
11*
12* This program is free software; you can redistribute it and/or
13* modify it under the terms of the GNU General Public License
14* as published by the Free Software Foundation; either version 2
15* of the License, or (at your option) any later version.
16*
17* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18* KIND, either express or implied.
19*
20****************************************************************************/
21
22#include "timer-target.h"
23#include "system.h"
24#include "timer.h"
25
26static long cycles_new = 0;
27
28void TIMER1_ISR(void)
29{
30 if (cycles_new > 0)
31 {
32 TIMER1.load = cycles_new - 1;
33 cycles_new = 0;
34 }
35 if (pfn_timer != NULL)
36 {
37 cycles_new = -1;
38 /* "lock" the variable, in case timer_set_period()
39 * is called within pfn_timer() */
40 pfn_timer();
41 cycles_new = 0;
42 }
43 TIMER1.clr = 1; /* clear the interrupt */
44}
45
46bool __timer_set(long cycles, bool start)
47{
48 if (start)
49 {
50 if (pfn_unregister != NULL)
51 {
52 pfn_unregister();
53 pfn_unregister = NULL;
54 }
55 TIMER1.ctrl &= ~0x80; /* disable the counter */
56 TIMER1.ctrl |= 0x40; /* reload after counting down to zero */
57 TIMER1.ctrl &= ~0xc; /* no prescaler */
58 TIMER1.clr = 1; /* clear an interrupt event */
59 }
60 if (start || (cycles_new == -1)) /* within isr, cycles_new is "locked" */
61 { /* enable timer */
62 TIMER1.load = cycles - 1;
63 TIMER1.ctrl |= 0x80; /* enable the counter */
64 }
65 else
66 cycles_new = cycles;
67
68 return true;
69}
70
71bool __timer_start(void)
72{
73 irq_set_int_handler(IRQ_TIMER1, TIMER1_ISR);
74 irq_enable_int(IRQ_TIMER1);
75 return true;
76}
77
78void __timer_stop(void)
79{
80 TIMER1.ctrl &= ~0x80; /* disable timer 1 */
81 irq_disable_int(IRQ_TIMER1);
82}