Add transfer timeout, remove unused buf field
[kugel-rb.git] / firmware / target / arm / pnx0101 / timer-pnx0101.c
blob1ec1d2871f7f987aacb5d72e2e9077b6086b6b3a
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 Tomasz Malesinski
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 "system.h"
23 #include "timer.h"
25 static long cycles_new = 0;
27 void TIMER1_ISR(void)
29 if (cycles_new > 0)
31 TIMER1.load = cycles_new - 1;
32 cycles_new = 0;
34 if (pfn_timer != NULL)
36 cycles_new = -1;
37 /* "lock" the variable, in case timer_set_period()
38 * is called within pfn_timer() */
39 pfn_timer();
40 cycles_new = 0;
42 TIMER1.clr = 1; /* clear the interrupt */
45 bool timer_set(long cycles, bool start)
47 if (start)
49 if (pfn_unregister != NULL)
51 pfn_unregister();
52 pfn_unregister = NULL;
54 TIMER1.ctrl &= ~0x80; /* disable the counter */
55 TIMER1.ctrl |= 0x40; /* reload after counting down to zero */
56 TIMER1.ctrl &= ~0xc; /* no prescaler */
57 TIMER1.clr = 1; /* clear an interrupt event */
59 if (start || (cycles_new == -1)) /* within isr, cycles_new is "locked" */
60 { /* enable timer */
61 TIMER1.load = cycles - 1;
62 TIMER1.ctrl |= 0x80; /* enable the counter */
64 else
65 cycles_new = cycles;
67 return true;
70 bool timer_start(void)
72 irq_set_int_handler(IRQ_TIMER1, TIMER1_ISR);
73 irq_enable_int(IRQ_TIMER1);
74 return true;
77 void timer_stop(void)
79 TIMER1.ctrl &= ~0x80; /* disable timer 1 */
80 irq_disable_int(IRQ_TIMER1);