1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2007 Tomasz Malesinski
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 ****************************************************************************/
25 static long cycles_new
= 0;
31 TIMER1
.load
= cycles_new
- 1;
34 if (pfn_timer
!= NULL
)
37 /* "lock" the variable, in case timer_set_period()
38 * is called within pfn_timer() */
42 TIMER1
.clr
= 1; /* clear the interrupt */
45 bool timer_set(long cycles
, bool start
)
49 if (pfn_unregister
!= NULL
)
52 pfn_unregister
= NULL
;
54 TIMER1
.ctrl
&= ~0x80; /* disable the counter */
55 TIMER1
.ctrl
|= 0x40; /* reload after counting down to zero */
56 TIMER1
.ctrl
&= ~0xc; /* no prescaler */
57 TIMER1
.clr
= 1; /* clear an interrupt event */
59 if (start
|| (cycles_new
== -1)) /* within isr, cycles_new is "locked" */
61 TIMER1
.load
= cycles
- 1;
62 TIMER1
.ctrl
|= 0x80; /* enable the counter */
70 bool timer_start(void)
72 irq_set_int_handler(IRQ_TIMER1
, TIMER1_ISR
);
73 irq_enable_int(IRQ_TIMER1
);
79 TIMER1
.ctrl
&= ~0x80; /* disable timer 1 */
80 irq_disable_int(IRQ_TIMER1
);