1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<HTML>
3<HEAD>
4<META http-equiv="Content-Type" content="text/html; charset=windows-1252">
5<META name="GENERATOR" content="IBM WebSphere Studio Homepage Builder Version 7.0.0.0 for Windows">
6<META http-equiv="Content-Style-Type" content="text/css">
7<TITLE>OS_StartTimer</TITLE>
8<LINK rel="stylesheet" href="../../css/nitro.css" type="text/css">
9</HEAD>
10<BODY>
11<H1 align="left">OS_StartTimer* <IMG src="../../image/NTR.gif" align="middle"><IMG src="../../image/TWL.gif" align="middle"></H1>
12<H2>Syntax</H2>
13<DL>
14<DD><CODE>#include &lt;nitro/os.h&gt;</CODE><BR>
15<BR>
16<CODE>void OS_StartTimer( OS_TimerId id, u16 count, OS_TimerPrescaler preScale );<BR>
17void OS_StartTimer32( OS_Timer32Id id, u32 count, OS_TimerPrescaler preScale );<BR>
18void OS_StartTimer48( OS_Timer48Id id, u64 count, OS_TimerPrescaler preScale );<BR>
19void OS_StartTimer64( u64 count, OS_TimerPrescaler preScale );<BR></CODE>
20</DL>
21<H2>Arguments</H2>
22<TABLE border="1" width="100%">
23  <TBODY>
24    <TR>
25<TD width="13%"><CODE>id</CODE></TD>
26<TD width="87%">Timer ID of the timer to use (differs according to number of timers used)</TD>
27    </TR>
28    <TR>
29<TD width="13%"><CODE>count</CODE></TD>
30<TD width="87%">Timer count</TD>
31    </TR>
32    <TR>
33<TD><CODE>preScale</CODE></TD>
34<TD>Timer scale</TD>
35    </TR>
36  </TBODY>
37</TABLE>
38<H2>Return Values</H2>
39<P>None.</P>
40<H2>Description</H2>
41<P>Sets and starts the internal timer.</P>
42<P>There are four 16-bit counter timers available with both NITRO and TWL. The timers are count-up timers, so an interrupt will occur when they go from <CODE>0xFFFF</CODE> to <CODE>0</CODE>.</P>
43<P>Each of the four timers can be used independently, or two or more timers can be connected to create a 32-bit, 48-bit, or 64-bit count timer. However, caution must be exercised because there are also timers used by the system.</P>
44<P>Call an <CODE><A href="OS_StopTimer.html">OS_StopTimer*</A></CODE> function if one of the timers you have set is no longer needed.</P>
45<P>The <CODE>OS_StartTimer</CODE> function uses 16-bit timers individually. </P>
46<P>The <CODE>OS_StartTimer32</CODE> function uses two consecutive timers as a timer with a 32-bit count maximum. </P>
47<P>The <CODE>OS_StartTimer48</CODE> function uses three consecutive timers as a timer with a 48-bit count maximum. </P>
48<P>The <CODE>OS_StartTimer64</CODE> function uses four consecutive timers as a timer with a 64-bit count maximum. </P>
49<P>The <CODE>id</CODE> argument specifies the Timer ID of the timer to use, as shown below.</P>
50<P>For 16-bit timers (<CODE>id</CODE> specification for the <CODE>OS_StartTimer</CODE> and <CODE>OS_StopTimer</CODE> functions) </P>
51<TABLE border="1">
52  <TBODY>
53    <TR>
54<TH bgcolor="#ffe0e0" width="170">id</TH>
55<TH bgcolor="#ffe0e0" width="555">Timer to use</TH>
56    </TR>
57    <TR>
58<TD width="174"><CODE>OS_TIMER_0</CODE></TD>
59<TD width="551">Timer 0</TD>
60    </TR>
61    <TR>
62<TD width="174"><CODE>OS_TIMER_1</CODE></TD>
63<TD width="551">Timer 1</TD>
64    </TR>
65    <TR>
66<TD width="174"><CODE>OS_TIMER_2</CODE></TD>
67<TD width="551">Timer 2</TD>
68    </TR>
69    <TR>
70<TD width="174"><CODE>OS_TIMER_3</CODE></TD>
71<TD width="551">Timer 3</TD>
72    </TR>
73  </TBODY>
74</TABLE>
75<P>For 32-bit timers (<CODE>id</CODE> specification for the <CODE>OS_StartTimer32</CODE> and <CODE>OS_StopTimer32</CODE> functions)</P>
76<TABLE border="1">
77  <TBODY>
78    <TR>
79<TH bgcolor="#ffe0e0" width="174">id</TH>
80<TH bgcolor="#ffe0e0" width="551">Timer to Use</TH>
81    </TR>
82    <TR>
83<TD width="174"><CODE>OS_TIMER32_01</CODE></TD>
84<TD width="551">Timer 0, Timer 1</TD>
85    </TR>
86    <TR>
87<TD width="174"><CODE>OS_TIMER32_12</CODE></TD>
88<TD width="551">Timer 1, Timer 2</TD>
89    </TR>
90    <TR>
91<TD width="174"><CODE>OS_TIMER32_23</CODE></TD>
92<TD width="551">Timer 2, Timer 3</TD>
93    </TR>
94  </TBODY>
95</TABLE>
96<P>For 48-bit timers (<CODE>id </CODE>specification for the <CODE>OS_StartTimer48</CODE> and <CODE>OS_StopTimer48</CODE> functions) </P>
97<TABLE border="1">
98  <TBODY>
99    <TR>
100<TH bgcolor="#ffe0e0" width="174">id</TH>
101<TH bgcolor="#ffe0e0" width="551">Timer to Use</TH>
102    </TR>
103    <TR>
104<TD width="174"><CODE>OS_TIMER48_012</CODE></TD>
105<TD width="551">Timer 0, Timer 1, Timer 2</TD>
106    </TR>
107    <TR>
108<TD width="174"><CODE>OS_TIMER48_123</CODE></TD>
109<TD width="551">Timer 1, Timer 2, Timer 3</TD>
110    </TR>
111  </TBODY>
112</TABLE>
113<P><BR>
114</P>
115<P>The <CODE>count</CODE> argument is the count given to the timer: 16-bit timers take values from <CODE>0</CODE> to <CODE>0xFFFF</CODE>, 32-bit timers take values from <CODE>0</CODE> to <CODE>0xFFFFFFFF</CODE>, 48-bit timers take values from <CODE>0</CODE> to <CODE>0xFFFFFFFFFFFF</CODE>, and 64-bit timers take values from <CODE>0</CODE> to <CODE>0xFFFFFFFFFFFFFFFF</CODE>.</P>
116<P>The <CODE>preScale</CODE> argument is the parameter that sets the scale for the counting on the timer. See the table below.</P>
117<TABLE border="1">
118  <TBODY>
119    <TR>
120<TH bgcolor="#ffe0e0">Set Value</TH>
121<TH bgcolor="#ffe0e0">Prescaler (Count Interval)</TH>
122    </TR>
123    <TR>
124<TD><CODE>OS_TIMER_PRESCALER_1</CODE></TD>
125<TD>System Clock</TD>
126    </TR>
127    <TR>
128<TD><CODE>OS_TIMER_PRESCALER_64</CODE></TD>
129<TD>1/64th of the System Clock</TD>
130    </TR>
131    <TR>
132<TD><CODE>OS_TIMER_PRESCALER_256</CODE></TD>
133<TD>1/256th of the System Clock</TD>
134    </TR>
135    <TR>
136<TD><CODE>OS_TIMER_PRESCALER_1024</CODE></TD>
137<TD>1/1024th of the System Clock</TD>
138
139    </TR>
140  </TBODY>
141</TABLE>
142<P><BR>
143</P>
144<P>When using a timer that uses multiple timers, timer interrupts will be for the the timer that has the highest number. However, <FONT color="#ff0000">make sure to grant interrupt permission for <EM>all</EM> timers that you will be using.</FONT>In this case, a system-internal interrupt handler will be assigned for all timers used except for the one with the highest number.<BR>
145</P>
146
147<BLOCKQUOTE style="background-color:#ffffcc;">
148<B>Example:</B> Use timers 0, 1, and 2 [together] as a 48-bit timer
149
150<PRE>#define count 0x100000000
151
152//---- set timer 2 interrupt handler
153OS_SetIrqFunction( OS_IE_TIMER2, TimerIntr );
154
155//---- enable timer 0-2
156(void)OS_EnableIrqMask( <FONT color="#ff0000">OS_IE_TIMER0 | OS_IE_TIMER_1 | OS_IE_TIMER2 </FONT>);
157
158//---- start timer 0-2 (as 48bit timer)
159<FONT color="#ff0000">OS_StartTimer48</FONT>( OS_TIMER48_012, count, OS_TIMER_PRESCALER_64 );
160
161
162//
163// interrupt handler
164//
165void TimerIntr(void)
166{
167  OS_Printf(&quot;TIMER INTERRUPT!\n&quot;);
168  OS_StopTimer48( OS_TIMER48_012 );
169}
170</PRE></P>
171</BLOCKQUOTE>
172
173<P><B>Note:</B></P>
174<P>Based on the hardware timer specifications, set timer interrupts occur repeatedly. However, the OS releases timer settings when the first interrupt occurs so only the first timer interrupt takes place. To generate repeated timer interrupts, processing to carry out settings needs to be done again in the interrupt handler.</P>
175<H2>See Also</H2>
176<P><A href="OS_StopTimer.html"><CODE>OS_StopTimer*</CODE></A></P>
177<H2>Revision History</H2>
178<P>2008/02/05 Added a description of the multi-timer.<BR>2005/03/08 Standardized the Japanese term for &quot;interrupt.&quot; <BR>2004/11/24 Corrected a mistake in timer ID.<BR>
1792004/06/03 Added a caution about timer interrupts.<br>2003/12/01 Initial version.</P>
180<hr><p>CONFIDENTIAL</p></body>
181</HTML>