summaryrefslogtreecommitdiff
path: root/firmware/target/arm/s5l8702/timer-s5l8702.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/s5l8702/timer-s5l8702.c')
-rw-r--r--firmware/target/arm/s5l8702/timer-s5l8702.c188
1 files changed, 94 insertions, 94 deletions
diff --git a/firmware/target/arm/s5l8702/timer-s5l8702.c b/firmware/target/arm/s5l8702/timer-s5l8702.c
index fb56a9ffcf..61d4d590e4 100644
--- a/firmware/target/arm/s5l8702/timer-s5l8702.c
+++ b/firmware/target/arm/s5l8702/timer-s5l8702.c
@@ -1,94 +1,94 @@
1/*************************************************************************** 1/***************************************************************************
2* __________ __ ___. 2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___ 3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/ 7* \/ \/ \/ \/ \/
8* $Id: timer-s5l8700.c 23103 2009-10-11 11:35:14Z theseven $ 8* $Id: timer-s5l8700.c 23103 2009-10-11 11:35:14Z theseven $
9* 9*
10* Copyright (C) 2009 Bertrik Sikken 10* Copyright (C) 2009 Bertrik Sikken
11* 11*
12* This program is free software; you can redistribute it and/or 12* This program is free software; you can redistribute it and/or
13* modify it under the terms of the GNU General Public License 13* modify it under the terms of the GNU General Public License
14* as published by the Free Software Foundation; either version 2 14* as published by the Free Software Foundation; either version 2
15* of the License, or (at your option) any later version. 15* of the License, or (at your option) any later version.
16* 16*
17* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 17* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18* KIND, either express or implied. 18* KIND, either express or implied.
19* 19*
20****************************************************************************/ 20****************************************************************************/
21 21
22#include "config.h" 22#include "config.h"
23 23
24#include "inttypes.h" 24#include "inttypes.h"
25#include "s5l8702.h" 25#include "s5l8702.h"
26#include "system.h" 26#include "system.h"
27#include "timer.h" 27#include "timer.h"
28 28
29//TODO: This needs calibration once we figure out the clocking 29//TODO: This needs calibration once we figure out the clocking
30 30
31void INT_TIMERC(void) 31void INT_TIMERC(void)
32{ 32{
33 /* clear interrupt */ 33 /* clear interrupt */
34 TCCON = TCCON; 34 TCCON = TCCON;
35 35
36 if (pfn_timer != NULL) { 36 if (pfn_timer != NULL) {
37 pfn_timer(); 37 pfn_timer();
38 } 38 }
39} 39}
40 40
41bool timer_set(long cycles, bool start) 41bool timer_set(long cycles, bool start)
42{ 42{
43 static const int cs_table[] = {1, 2, 4, 6}; 43 static const int cs_table[] = {1, 2, 4, 6};
44 int prescale, cs; 44 int prescale, cs;
45 long count; 45 long count;
46 46
47 /* stop and clear timer */ 47 /* stop and clear timer */
48 TCCMD = (1 << 1); /* TD_CLR */ 48 TCCMD = (1 << 1); /* TD_CLR */
49 49
50 /* optionally unregister any previously registered timer user */ 50 /* optionally unregister any previously registered timer user */
51 if (start) { 51 if (start) {
52 if (pfn_unregister != NULL) { 52 if (pfn_unregister != NULL) {
53 pfn_unregister(); 53 pfn_unregister();
54 pfn_unregister = NULL; 54 pfn_unregister = NULL;
55 } 55 }
56 } 56 }
57 57
58 /* scale the count down with the clock select */ 58 /* scale the count down with the clock select */
59 for (cs = 0; cs < 4; cs++) { 59 for (cs = 0; cs < 4; cs++) {
60 count = cycles >> cs_table[cs]; 60 count = cycles >> cs_table[cs];
61 if ((count < 65536) || (cs == 3)) { 61 if ((count < 65536) || (cs == 3)) {
62 break; 62 break;
63 } 63 }
64 } 64 }
65 65
66 /* scale the count down with the prescaler */ 66 /* scale the count down with the prescaler */
67 prescale = 1; 67 prescale = 1;
68 while (count >= 65536) { 68 while (count >= 65536) {
69 count >>= 1; 69 count >>= 1;
70 prescale <<= 1; 70 prescale <<= 1;
71 } 71 }
72 72
73 /* configure timer */ 73 /* configure timer */
74 TCCON = (1 << 12) | /* TD_INT0_EN */ 74 TCCON = (1 << 12) | /* TD_INT0_EN */
75 (cs << 8) | /* TS_CS */ 75 (cs << 8) | /* TS_CS */
76 (0 << 4); /* TD_MODE_SEL, 0 = interval mode */ 76 (0 << 4); /* TD_MODE_SEL, 0 = interval mode */
77 TCPRE = prescale - 1; 77 TCPRE = prescale - 1;
78 TCDATA0 = count; 78 TCDATA0 = count;
79 TCCMD = (1 << 0); /* TD_ENABLE */ 79 TCCMD = (1 << 0); /* TD_ENABLE */
80 80
81 return true; 81 return true;
82} 82}
83 83
84bool timer_start(void) 84bool timer_start(void)
85{ 85{
86 TCCMD = (1 << 0); /* TD_ENABLE */ 86 TCCMD = (1 << 0); /* TD_ENABLE */
87 return true; 87 return true;
88} 88}
89 89
90void timer_stop(void) 90void timer_stop(void)
91{ 91{
92 TCCMD = (0 << 0); /* TD_ENABLE */ 92 TCCMD = (0 << 0); /* TD_ENABLE */
93} 93}
94 94