diff options
Diffstat (limited to 'firmware/target')
-rw-r--r-- | firmware/target/arm/pnx0101/timer-pnx0101.c | 82 | ||||
-rw-r--r-- | firmware/target/arm/pnx0101/timer-target.h | 39 |
2 files changed, 121 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 | |||
26 | static long cycles_new = 0; | ||
27 | |||
28 | void 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 | |||
46 | bool __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 | |||
71 | bool __timer_start(void) | ||
72 | { | ||
73 | irq_set_int_handler(IRQ_TIMER1, TIMER1_ISR); | ||
74 | irq_enable_int(IRQ_TIMER1); | ||
75 | return true; | ||
76 | } | ||
77 | |||
78 | void __timer_stop(void) | ||
79 | { | ||
80 | TIMER1.ctrl &= ~0x80; /* disable timer 1 */ | ||
81 | irq_disable_int(IRQ_TIMER1); | ||
82 | } | ||
diff --git a/firmware/target/arm/pnx0101/timer-target.h b/firmware/target/arm/pnx0101/timer-target.h new file mode 100644 index 0000000000..853da07838 --- /dev/null +++ b/firmware/target/arm/pnx0101/timer-target.h | |||
@@ -0,0 +1,39 @@ | |||
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 | #ifndef TIMER_TARGET_H | ||
22 | #define TIMER_TARGET_H | ||
23 | |||
24 | bool __timer_set(long cycles, bool start); | ||
25 | bool __timer_start(void); | ||
26 | void __timer_stop(void); | ||
27 | |||
28 | #define TIMER_FREQ 3000000 | ||
29 | |||
30 | #define __TIMER_SET(cycles, set) \ | ||
31 | __timer_set(cycles, set) | ||
32 | |||
33 | #define __TIMER_START() \ | ||
34 | __timer_start() | ||
35 | |||
36 | #define __TIMER_STOP(...) \ | ||
37 | __timer_stop() | ||
38 | |||
39 | #endif /* TIMER_TARGET_H */ | ||