diff options
Diffstat (limited to 'firmware/target/arm/olympus/mrobe-500/timer-mr500.c')
-rw-r--r-- | firmware/target/arm/olympus/mrobe-500/timer-mr500.c | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/firmware/target/arm/olympus/mrobe-500/timer-mr500.c b/firmware/target/arm/olympus/mrobe-500/timer-mr500.c new file mode 100644 index 0000000000..cd3cec5663 --- /dev/null +++ b/firmware/target/arm/olympus/mrobe-500/timer-mr500.c | |||
@@ -0,0 +1,108 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: $ | ||
9 | * | ||
10 | * Copyright (C) 2007 by Karl Kurbjun | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #include "config.h" | ||
21 | #include "cpu.h" | ||
22 | #include "system.h" | ||
23 | #include "timer.h" | ||
24 | #include "logf.h" | ||
25 | |||
26 | /* GPB0/TOUT0 should already have been configured as output so that pin | ||
27 | should not be a functional pin and TIMER0 output unseen there */ | ||
28 | void TIMER0(void) | ||
29 | { | ||
30 | if (pfn_timer != NULL) | ||
31 | pfn_timer(); | ||
32 | } | ||
33 | |||
34 | static void stop_timer(void) | ||
35 | { | ||
36 | } | ||
37 | |||
38 | bool __timer_set(long cycles, bool start) | ||
39 | { | ||
40 | /* taken from linux/arch/arm/mach-itdm320-20/time.c and timer-meg-fx.c */ | ||
41 | |||
42 | /* Turn off all timers */ | ||
43 | /* outw(CONFIG_TIMER0_TMMD_STOP, IO_TIMER0_TMMD); | ||
44 | outw(CONFIG_TIMER1_TMMD_STOP, IO_TIMER1_TMMD); | ||
45 | outw(CONFIG_TIMER2_TMMD_STOP, IO_TIMER2_TMMD); | ||
46 | outw(CONFIG_TIMER3_TMMD_STOP, IO_TIMER3_TMMD); | ||
47 | */ | ||
48 | /* Turn Timer0 to Free Run mode */ | ||
49 | // outw(CONFIG_TIMER0_TMMD_FREE_RUN, IO_TIMER0_TMMD); | ||
50 | |||
51 | bool retval = false; | ||
52 | |||
53 | /* Find the minimum factor that puts the counter in range 1-65535 */ | ||
54 | unsigned int prescaler = (cycles + 65534) / 65535; | ||
55 | |||
56 | /* Test this by writing 1's to registers to see how many bits we have */ | ||
57 | /* Maximum divider setting is x / 1024 / 65536 = x / 67108864 */ | ||
58 | { | ||
59 | int oldlevel; | ||
60 | unsigned int divider; | ||
61 | |||
62 | if (start && pfn_unregister != NULL) | ||
63 | { | ||
64 | pfn_unregister(); | ||
65 | pfn_unregister = NULL; | ||
66 | } | ||
67 | |||
68 | oldlevel = set_irq_level(HIGHEST_IRQ_LEVEL); | ||
69 | |||
70 | /* Max prescale is 1023+1 */ | ||
71 | for (divider = 0; prescaler > 1024; prescaler >>= 1, divider++); | ||
72 | |||
73 | /* Setup the Prescalar */ | ||
74 | outw(prescaler, IO_TIMER0_TMPRSCL); | ||
75 | |||
76 | /* Setup the Divisor */ | ||
77 | outw(divider, IO_TIMER0_TMDIV); | ||
78 | |||
79 | set_irq_level(oldlevel); | ||
80 | |||
81 | retval = true; | ||
82 | } | ||
83 | |||
84 | return retval; | ||
85 | } | ||
86 | |||
87 | bool __timer_register(void) | ||
88 | { | ||
89 | bool retval = true; | ||
90 | |||
91 | int oldstatus = set_interrupt_status(IRQ_FIQ_DISABLED, IRQ_FIQ_STATUS); | ||
92 | |||
93 | stop_timer(); | ||
94 | |||
95 | /* Turn Timer0 to Free Run mode */ | ||
96 | outw(0x0002, IO_TIMER0_TMMD); | ||
97 | |||
98 | set_interrupt_status(oldstatus, IRQ_FIQ_STATUS); | ||
99 | |||
100 | return retval; | ||
101 | } | ||
102 | |||
103 | void __timer_unregister(void) | ||
104 | { | ||
105 | int oldstatus = set_interrupt_status(IRQ_FIQ_DISABLED, IRQ_FIQ_STATUS); | ||
106 | stop_timer(); | ||
107 | set_interrupt_status(oldstatus, IRQ_FIQ_STATUS); | ||
108 | } | ||