1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2006 Thom Johansen
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
26 static long SHAREDBSS_ATTR cycles_new
= 0;
30 TIMER2_VAL
; /* ACK interrupt */
33 TIMER2_CFG
= 0xc0000000 | (cycles_new
- 1);
36 if (pfn_timer
!= NULL
)
39 /* "lock" the variable, in case timer_set_period()
40 * is called within pfn_timer() */
46 bool timer_set(long cycles
, bool start
)
48 if (cycles
> 0x20000000 || cycles
< 2)
53 if (pfn_unregister
!= NULL
)
56 pfn_unregister
= NULL
;
58 CPU_INT_DIS
= TIMER2_MASK
;
59 COP_INT_DIS
= TIMER2_MASK
;
61 if (start
|| (cycles_new
== -1)) /* within isr, cycles_new is "locked" */
62 TIMER2_CFG
= 0xc0000000 | (cycles
- 1); /* enable timer */
69 bool timer_start(IF_COP_VOID(int core
))
71 /* unmask interrupt source */
74 COP_INT_EN
= TIMER2_MASK
;
77 CPU_INT_EN
= TIMER2_MASK
;
83 TIMER2_CFG
= 0; /* stop timer 2 */
84 CPU_INT_DIS
= TIMER2_MASK
;
85 COP_INT_DIS
= TIMER2_MASK
;