Fix a bunch of boot.lds files so that they build with newer ld. The stack/bss section...
[kugel-rb.git] / firmware / target / arm / tms320dm320 / timer-dm320.c
blob030d64566466eac67910e182467aee04d2311b24
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 by Karl Kurbjun
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 ****************************************************************************/
22 #include "config.h"
23 #include "cpu.h"
24 #include "system.h"
25 #include "timer.h"
26 #include "logf.h"
28 /* GPB0/TOUT0 should already have been configured as output so that pin
29 should not be a functional pin and TIMER0 output unseen there */
30 void TIMER0(void) __attribute__ ((section(".icode")));
31 void TIMER0(void)
33 IO_INTC_IRQ0 = INTR_IRQ0_TMR0; /* clear TIMER0 interrupt */
34 if (pfn_timer != NULL)
35 pfn_timer();
38 bool timer_set(long cycles, bool start)
40 int oldlevel;
41 unsigned int divider=cycles, prescaler=0;
43 if(cycles<1)
44 return false;
46 oldlevel = set_irq_level(HIGHEST_IRQ_LEVEL);
48 IO_CLK_MOD2 |= CLK_MOD2_TMR0; //enable TIMER0 clock!!!!!!!!!
50 IO_TIMER0_TMMD = CONFIG_TIMER0_TMMD_STOP;
52 if (start && pfn_unregister != NULL)
54 pfn_unregister();
55 pfn_unregister = NULL;
58 oldlevel = disable_irq_save();
60 /* Increase prescale values starting from 0 to make the cycle count fit */
61 while(divider>65535 && prescaler<1024)
63 prescaler++;
64 divider=cycles/(prescaler+1);
67 IO_TIMER0_TMPRSCL = prescaler;
68 IO_TIMER0_TMDIV = divider;
70 restore_irq(oldlevel);
72 return true;
75 static void stop_timer(void)
77 IO_INTC_EINT0 &= ~INTR_EINT0_TMR0; //disable TIMER0 interrupt
79 IO_INTC_IRQ0 = INTR_IRQ0_TMR0; //clear TIMER0 interrupt
81 IO_TIMER0_TMMD = CONFIG_TIMER0_TMMD_STOP;
83 IO_CLK_MOD2 &= ~CLK_MOD2_TMR0; //disable TIMER0 clock
86 bool timer_start(void)
88 int oldstatus = disable_interrupt_save(IRQ_FIQ_STATUS);
90 stop_timer();
92 IO_CLK_MOD2 |= CLK_MOD2_TMR0; //enable TIMER0 clock!!!!!!!!!
94 /* Turn Timer0 to Free Run mode */
95 IO_TIMER0_TMMD = CONFIG_TIMER0_TMMD_FREE_RUN;
97 IO_INTC_EINT0 |= INTR_EINT0_TMR0; //enable TIMER0 interrupt
99 restore_interrupt(oldstatus);
101 return true;
104 void timer_stop(void)
106 int oldstatus = disable_interrupt_save(IRQ_FIQ_STATUS);
107 stop_timer();
108 restore_interrupt(oldstatus);