2008-11-06 02:31:40 +00:00
|
|
|
|
/***************************************************************************
|
|
|
|
|
* __________ __ ___.
|
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
|
* $Id$
|
|
|
|
|
*
|
|
|
|
|
* Copyright <EFBFBD> 2008 Rafa<EFBFBD>l Carr<EFBFBD>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
|
* KIND, either express or implied.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#include "system.h"
|
|
|
|
|
#include "kernel.h"
|
2008-11-06 14:34:37 +00:00
|
|
|
|
#include "panic.h"
|
2008-11-26 14:42:40 +00:00
|
|
|
|
#include "timer-target.h"
|
2008-11-06 14:34:37 +00:00
|
|
|
|
|
2009-06-04 14:50:07 +00:00
|
|
|
|
#ifdef HAVE_SCROLLWHEEL
|
|
|
|
|
/* let the timer interrupt twice as often for the scrollwheel polling */
|
|
|
|
|
#define KERNEL_TIMER_FREQ (TIMER_FREQ/2)
|
|
|
|
|
#else
|
|
|
|
|
#define KERNEL_TIMER_FREQ TIMER_FREQ
|
|
|
|
|
#endif
|
|
|
|
|
|
2009-04-13 10:28:06 +00:00
|
|
|
|
#ifdef HAVE_SCROLLWHEEL
|
2009-04-13 17:10:52 +00:00
|
|
|
|
#include "button-target.h"
|
2009-04-13 10:28:06 +00:00
|
|
|
|
/* The scrollwheel is polled every 5 ms (the tick tasks only every 10) */
|
2009-06-04 14:50:07 +00:00
|
|
|
|
static int poll_scrollwheel = 0;
|
2009-04-13 10:28:06 +00:00
|
|
|
|
|
|
|
|
|
void INT_TIMER2(void)
|
|
|
|
|
{
|
|
|
|
|
if (!poll_scrollwheel)
|
2009-06-04 14:50:07 +00:00
|
|
|
|
call_tick_tasks(); /* Run through the list of tick tasks
|
|
|
|
|
* (that includes reading the scrollwheel) */
|
2009-04-13 10:28:06 +00:00
|
|
|
|
else
|
2009-04-13 17:10:52 +00:00
|
|
|
|
{
|
|
|
|
|
if (!button_hold())
|
2009-06-04 14:50:07 +00:00
|
|
|
|
button_read_dbop(); /* Read the scrollwheel */
|
2009-04-13 17:10:52 +00:00
|
|
|
|
}
|
2009-04-13 10:28:06 +00:00
|
|
|
|
|
|
|
|
|
poll_scrollwheel ^= 1;
|
|
|
|
|
TIMER2_INTCLR = 0; /* clear interrupt */
|
|
|
|
|
}
|
|
|
|
|
#else
|
2008-11-06 14:34:37 +00:00
|
|
|
|
void INT_TIMER2(void)
|
|
|
|
|
{
|
|
|
|
|
call_tick_tasks(); /* Run through the list of tick tasks */
|
|
|
|
|
|
|
|
|
|
TIMER2_INTCLR = 0; /* clear interrupt */
|
|
|
|
|
}
|
2009-04-13 10:28:06 +00:00
|
|
|
|
#endif
|
2008-11-06 02:31:40 +00:00
|
|
|
|
|
|
|
|
|
void tick_start(unsigned int interval_in_ms)
|
|
|
|
|
{
|
2009-06-04 14:50:07 +00:00
|
|
|
|
int cycles = KERNEL_TIMER_FREQ / 1000 * interval_in_ms;
|
2008-11-06 14:34:37 +00:00
|
|
|
|
|
|
|
|
|
CGU_PERI |= CGU_TIMER2_CLOCK_ENABLE; /* enable peripheral */
|
2008-12-05 14:37:28 +00:00
|
|
|
|
VIC_INT_ENABLE |= INTERRUPT_TIMER2; /* enable interrupt */
|
2008-11-06 14:34:37 +00:00
|
|
|
|
|
|
|
|
|
TIMER2_LOAD = TIMER2_BGLOAD = cycles; /* timer period */
|
|
|
|
|
|
|
|
|
|
/* /!\ bit 4 (reserved) must not be modified
|
2009-06-12 21:11:45 +00:00
|
|
|
|
* periodic mode, interrupt enabled, no prescale, 32 bits counter */
|
|
|
|
|
TIMER2_CONTROL = (TIMER2_CONTROL & (1<<4)) |
|
|
|
|
|
TIMER_ENABLE |
|
|
|
|
|
TIMER_PERIODIC |
|
|
|
|
|
TIMER_INT_ENABLE |
|
|
|
|
|
TIMER_32_BIT;
|
2008-11-06 02:31:40 +00:00
|
|
|
|
}
|