1
0
Fork 0
forked from len0rd/rockbox

gigabeat S: Set the tick speed correctly (calced from clocking regdump). Use bit #defines instead as well. Throw a header in the file.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16928 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Michael Sevakis 2008-04-02 05:17:05 +00:00
parent 404a204e58
commit dd88663fe0

View file

@ -1,9 +1,26 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2007 by Michael Sevakis
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include "config.h" #include "config.h"
#include "system.h" #include "system.h"
#include "avic-imx31.h" #include "avic-imx31.h"
#include "kernel.h" #include "kernel.h"
#include "thread.h" #include "thread.h"
#include <stdio.h>
extern void (*tick_funcs[MAX_NUM_TICK_TASKS])(void); extern void (*tick_funcs[MAX_NUM_TICK_TASKS])(void);
@ -11,7 +28,7 @@ static __attribute__((interrupt("IRQ"))) void EPIT1_HANDLER(void)
{ {
int i; int i;
EPITSR1 = 1; /* Clear the pending status */ EPITSR1 = EPITSR_OCIF; /* Clear the pending status */
/* Run through the list of tick tasks */ /* Run through the list of tick tasks */
for(i = 0;i < MAX_NUM_TICK_TASKS;i++) for(i = 0;i < MAX_NUM_TICK_TASKS;i++)
@ -25,31 +42,35 @@ static __attribute__((interrupt("IRQ"))) void EPIT1_HANDLER(void)
void tick_start(unsigned int interval_in_ms) void tick_start(unsigned int interval_in_ms)
{ {
CLKCTL_CGR0 |= (3 << 6); /* EPIT1 module clock ON - before writing regs! */ CLKCTL_CGR0 |= CGR0_EPIT1(CG_ON_ALL); /* EPIT1 module clock ON -
EPITCR1 &= ~((1 << 2) | (1 << 0)); /* Disable the counter */ before writing regs! */
CLKCTL_WIMR0 &= ~(1 << 23); /* Clear wakeup mask */ EPITCR1 &= ~(EPITCR_OCIEN | EPITCR_EN); /* Disable the counter */
CLKCTL_WIMR0 &= ~(1 << 23); /* Clear wakeup mask */
/* NOTE: This isn't really accurate yet but it's close enough to work /* mcu_main_clk = 528MHz = 27MHz * 2 * ((9 + 7/9) / 1)
* with for the moment */ * CLKSRC = ipg_clk = 528MHz / 4 / 2 = 66MHz,
* EPIT Output Disconnected,
/* CLKSRC=32KHz, EPIT Output Disconnected, Enabled * Enabled in wait mode
* prescale 1/32, Reload from modulus register, Compare interrupt enabled, * Prescale 1/2640 for 25KHz
* Reload from modulus register,
* Compare interrupt enabled,
* Count from load value */ * Count from load value */
EPITCR1 = (3 << 24) | (1 << 19) | (32 << 4) | EPITCR1 = EPITCR_CLKSRC_IPG_CLK | EPITCR_WAITEN | EPITCR_IOVW |
(1 << 3) | (1 << 2) | (1 << 1); EPITCR_PRESCALER(2640-1) | EPITCR_RLD | EPITCR_OCIEN |
EPITCR_ENMOD;
EPITLR1 = interval_in_ms; /* Count down from interval */ EPITLR1 = interval_in_ms*25; /* Count down from interval */
EPITCMPR1 = 0; /* Event when counter reaches 0 */ EPITCMPR1 = 0; /* Event when counter reaches 0 */
EPITSR1 = 1; /* Clear any pending interrupt */ EPITSR1 = EPITSR_OCIF; /* Clear any pending interrupt */
avic_enable_int(EPIT1, IRQ, 7, EPIT1_HANDLER); avic_enable_int(EPIT1, IRQ, 7, EPIT1_HANDLER);
EPITCR1 |= (1 << 0); /* Enable the counter */ EPITCR1 |= EPITCR_EN; /* Enable the counter */
} }
#ifdef BOOTLOADER #ifdef BOOTLOADER
void tick_stop(void) void tick_stop(void)
{ {
avic_disable_int(EPIT1); /* Disable insterrupt */ avic_disable_int(EPIT1); /* Disable insterrupt */
EPITCR1 &= ~((1 << 2) | (1 << 0)); /* Disable counter */ EPITCR1 &= ~(EPITCR_OCIEN | EPITCR_EN); /* Disable counter */
CLKCTL_CGR0 &= ~(3 << 6); /* EPIT1 module clock OFF */ CLKCTL_CGR0 &= ~CGR0_EPIT1(CG_MASK); /* EPIT1 module clock OFF */
} }
#endif #endif