AMS SoC's: Some register bit changes need interrupt protection: timer API and CGU_PERI.
[kugel-rb.git] / firmware / target / arm / as3525 / timer-as3525.c
blob420eb489fbb125733f8d24296ce3ca9e41d9bba6
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 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 ****************************************************************************/
22 #include "config.h"
23 #include "system.h"
24 #include "timer.h"
25 #include "stdlib.h"
27 void INT_TIMER1(void)
29 if (pfn_timer != NULL)
30 pfn_timer();
32 TIMER1_INTCLR = 0; /* clear interrupt */
35 bool timer_set(long cycles, bool start)
37 int oldstatus = disable_irq_save();
39 if (start)
41 if (pfn_unregister != NULL)
43 pfn_unregister();
44 pfn_unregister = NULL;
48 TIMER1_LOAD = TIMER1_BGLOAD = cycles;
49 /* /!\ bit 4 (reserved) must not be modified
50 * periodic mode, interrupt enabled, no prescale, 32 bits counter */
51 TIMER1_CONTROL = (TIMER1_CONTROL & (1<<4)) |
52 TIMER_ENABLE |
53 TIMER_PERIODIC |
54 TIMER_INT_ENABLE |
55 TIMER_32_BIT;
57 restore_irq(oldstatus);
59 return true;
62 bool timer_start(void)
64 int oldstatus = disable_irq_save();
65 CGU_PERI |= CGU_TIMER1_CLOCK_ENABLE; /* enable peripheral */
66 VIC_INT_ENABLE = INTERRUPT_TIMER1;
67 restore_irq(oldstatus);
68 return true;
71 void timer_stop(void)
73 int oldstatus = disable_irq_save();
74 TIMER1_CONTROL &= 0x10; /* disable timer 1 (don't modify bit 4) */
75 VIC_INT_EN_CLEAR = INTERRUPT_TIMER1; /* disable interrupt */
76 CGU_PERI &= ~CGU_TIMER1_CLOCK_ENABLE; /* disable peripheral */
77 restore_irq(oldstatus);