Meg F/X: Radically changing divider settings messed up the fake sleep in the bootload...
[kugel-rb.git] / firmware / target / arm / s3c2440 / gigabeat-fx / kernel-meg-fx.c
blob6a750c32e2ec6817b8bae8ab424788a4a0a2ca9e
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 by Michael Sevakis
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 "timer.h"
25 #include "thread.h"
27 static inline void tick_set(unsigned int interval_in_ms)
30 * Based on default PCLK of 49.1568MHz - scaling chosen to give
31 * remainder-free result for tick interval of 10ms (100Hz)
32 * Timer input clock frequency =
33 * fPCLK / {prescaler value+1} / {divider value}
34 * TIMER_FREQ = 49156800 / 2
35 * 146300 = TIMER_FREQ / 21 / 8
36 * 49156800 = 19*11*(7)*7*5*5*(3)*2*2*2*2*2*2
37 * 21 = 7*3
40 /* stop timer 4 */
41 TCON &= ~(1 << 20);
42 /* Set the count for timer 4 */
43 TCNTB4 = (TIMER_FREQ / TIMER234_PRESCALE / 8) * interval_in_ms / 1000;
44 /* Set the the prescaler value for timers 2,3, and 4 */
45 TCFG0 = (TCFG0 & ~0xff00) | ((TIMER234_PRESCALE-1) << 8);
46 /* DMA mode off, MUX4 = 1/16 */
47 TCFG1 = (TCFG1 & ~0xff0000) | 0x030000;
48 /* set manual bit */
49 TCON |= 1 << 21;
50 /* reset manual bit */
51 TCON &= ~(1 << 21);
54 void tick_start(unsigned int interval_in_ms)
56 tick_set(interval_in_ms);
58 /* interval mode */
59 TCON |= 1 << 22;
60 /* start timer 4 */
61 TCON |= (1 << 20);
63 /* timer 4 unmask interrupts */
64 INTMSK &= ~TIMER4_MASK;
67 #ifdef BOOTLOADER
68 void delay(int ticks)
70 volatile unsigned long counter;
72 INTMSK |= TIMER4_MASK;
74 tick_set(1000 * ticks / HZ);
76 /* autoreload Off */
77 TCON &= ~(1 << 22);
78 /* start timer 4 */
79 TCON |= (1 << 20);
81 do {
82 counter = TCNTO4;
83 } while(counter > 0);
85 #endif /* BOOTLOADER */
87 void TIMER4(void)
89 /* Run through the list of tick tasks */
90 call_tick_tasks();
92 SRCPND = TIMER4_MASK;
93 INTPND = TIMER4_MASK;