FS#8961 - Anti-Aliased Fonts.
[kugel-rb.git] / firmware / target / mips / ingenic_jz47xx / timer-jz4740.c
blob538547041dd0cab8b3da14350ce64d52a03c17bf
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2008 by Maurus Cuelenaere
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 "jz4740.h"
24 #include "system.h"
25 #include "timer.h"
27 /* Interrupt handler */
28 void TCU1(void)
30 __tcu_clear_full_match_flag(1);
32 if (pfn_timer != NULL)
33 pfn_timer();
36 bool timer_set(long cycles, bool start)
38 unsigned int divider = cycles, prescaler_bit = 0, prescaler = 1, old_irq;
40 if(cycles < 1)
41 return false;
43 if(start && pfn_unregister != NULL)
45 pfn_unregister();
46 pfn_unregister = NULL;
49 /* Increase prescale values starting from 0 to make the cycle count fit */
50 while(divider > 65535 && prescaler <= 1024)
52 prescaler <<= 2; /* 1, 4, 16, 64, 256, 1024 */
53 prescaler_bit++;
54 divider = cycles / prescaler;
57 old_irq = disable_irq_save();
59 __tcu_stop_counter(1);
60 if(start)
62 __tcu_disable_pwm_output(1);
64 __tcu_mask_half_match_irq(1);
65 __tcu_unmask_full_match_irq(1);
67 /* EXTAL clock = CFG_EXTAL (12Mhz in most targets) */
68 __tcu_select_extalclk(1);
71 REG_TCU_TCSR(1) = (REG_TCU_TCSR(1) & ~TCU_TCSR_PRESCALE_MASK) | (prescaler_bit << TCU_TCSR_PRESCALE_BIT);
72 REG_TCU_TCNT(1) = 0;
73 REG_TCU_TDHR(1) = 0;
74 REG_TCU_TDFR(1) = divider;
76 __tcu_clear_full_match_flag(1);
78 if(start)
80 system_enable_irq(IRQ_TCU1);
81 __tcu_start_counter(1);
84 restore_irq(old_irq);
86 return true;
89 bool timer_start(void)
91 __tcu_start_counter(1);
93 return true;
96 void timer_stop(void)
98 unsigned int old_irq = disable_irq_save();
99 __tcu_stop_counter(1);
100 restore_irq(old_irq);