Change the timer interrupt setup so that TIMER_FREQ is changed for HAVE_SCROLLWHEEL...
[kugel-rb.git] / firmware / target / arm / as3525 / kernel-as3525.c
blob0f907f61e3de2baf6ee4e8bc357b288f54377baf
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
21 #include "config.h"
22 #include "system.h"
23 #include "kernel.h"
24 #include "panic.h"
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;
32 void INT_TIMER2(void)
34 if (!poll_scrollwheel)
35 call_tick_tasks(); /* Run through the list of tick tasks */
36 else
38 if (!button_hold())
39 button_read_dbop();
42 poll_scrollwheel ^= 1;
43 TIMER2_INTCLR = 0; /* clear interrupt */
45 #else
46 void INT_TIMER2(void)
48 call_tick_tasks(); /* Run through the list of tick tasks */
50 TIMER2_INTCLR = 0; /* clear interrupt */
52 #endif
54 void tick_start(unsigned int interval_in_ms)
56 int phi = 0; /* prescaler bits */
57 int prescale = 1;
58 int cycles = TIMER_FREQ / 1000 * interval_in_ms;
60 while(cycles > 0x10000)
62 phi++;
63 prescale <<= 4;
64 cycles >>= 4;
67 if(prescale > 256)
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);