1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright © 2008 Rafaël Carré
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 #include "timer-target.h"
27 #ifdef HAVE_SCROLLWHEEL
28 #include "button-target.h"
29 /* The scrollwheel is polled every 5 ms (the tick tasks only every 10) */
30 static volatile int poll_scrollwheel
= 0;
34 if (!poll_scrollwheel
)
35 call_tick_tasks(); /* Run through the list of tick tasks */
42 poll_scrollwheel
^= 1;
43 TIMER2_INTCLR
= 0; /* clear interrupt */
48 call_tick_tasks(); /* Run through the list of tick tasks */
50 TIMER2_INTCLR
= 0; /* clear interrupt */
54 void tick_start(unsigned int interval_in_ms
)
56 int phi
= 0; /* prescaler bits */
58 int cycles
= TIMER_FREQ
/ 1000 * interval_in_ms
;
60 while(cycles
> 0x10000)
68 panicf("%s : interval too big", __func__
);
70 CGU_PERI
|= CGU_TIMER2_CLOCK_ENABLE
; /* enable peripheral */
71 VIC_INT_ENABLE
|= INTERRUPT_TIMER2
; /* enable interrupt */
73 TIMER2_LOAD
= TIMER2_BGLOAD
= cycles
; /* timer period */
75 /* /!\ bit 4 (reserved) must not be modified
76 * periodic mode, interrupt enabled, 16 bits counter */
77 TIMER2_CONTROL
= (TIMER2_CONTROL
& (1<<4)) | 0xe0 | (phi
<<2);