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_SetAlarm</TITLE> 8<LINK rel="stylesheet" href="../../css/nitro.css" type="text/css"> 9</HEAD> 10<BODY> 11<H1 align="left">OS_SetAlarm <IMG src="../../image/NTR.gif" align="middle"><IMG src="../../image/TWL.gif" align="middle"></H1> 12<H2>Syntax</H2> 13<DL> 14 <DD> 15<PRE><CODE>#include <nitro/os.h></CODE></PRE> 16 <PRE><CODE>void OS_SetAlarm( 17 OSAlarm* alarm, 18 OSTick tick, 19 OSAlarmHandler handler, 20 void* arg ); 21 </CODE></PRE> 22</DL> 23<H2>Arguments</H2> 24<TABLE border="1" width="100%"> 25 <TBODY> 26 <TR> 27<TD width="13%"><CODE>alarm</CODE></TD> 28<TD width="87%">Pointer to an alarm structure that is initialized for this alarm.</TD> 29 </TR> 30 <TR> 31<TD width="13%"><CODE>tick</CODE></TD> 32<TD width="87%">Tick count until the alarm goes off (the handler is called).</TD> 33 </TR> 34 <TR> 35<TD><CODE>handler</CODE></TD> 36<TD>Alarm handler.</TD> 37 </TR> 38 <TR> 39<TD><CODE>arg</CODE></TD> 40<TD>Argument when the handler is called.</TD> 41 </TR> 42 </TBODY> 43</TABLE> 44<H2>Return Values</H2> 45<P>None.</P> 46<H2>Description</H2> 47<P>Sets up a one-time alarm.</P> 48<P>A <code>handler</code> is called after the tick count that is specified by <code>tick</code>. The V-Count alarm handler <code>handler</code> is an <code>OSVAlarmHandler</code> function defined by the following.</P> 49<BLOCKQUOTE><CODE>typedef void (*OSAlarmHandler)( void* );</CODE></BLOCKQUOTE> 50<P> When the <code>handler</code> is called, it takes <code>arg</code> as an argument. The <code>handler</code> argument is passed from the OS timer interrupt handler. Therefore, interrupts are prohibited.</P> 51<P>One tick count unit is 1/64 of the hardware system clock.</P> 52<P>If <code>alarm</code> is specified for the pointer to the <code>OSAlarm</code> structure in which the alarm has been set, it stops with <code>OS_Panic</code>.</P> 53<P>In the following example, by setting an alarm, the <CODE>handler</CODE> function is called 0.5 seconds later, and "<code>handler called. arg=0x12345678</code>" is displayed.</P> 54<BLOCKQUOTE style="background:#ffffcc;">Example:<BR> 55<PRE>#define COUNT  OS_MilliSecondsToTicks( 500 ) 56#define ARG 0x12345678 57OSAlarm  alarm; 58 59main() 60{ 61 : 62 OS_InitTick(); 63 OS_InitAlarm(); 64 : 65 OS_CreateAlarm( &alarm ); 66 OS_SetAlarm( &alarm, COUNT, handler, (void*)ARG ); 67 : 68} 69 70void handler( void* arg ) 71{ 72 OS_Printf( "handler called. arg=0x%x\n", arg ); 73}</PRE></BLOCKQUOTE> 74<H2>See Also</H2> 75<P><A href="OS_InitAlarm.html"><CODE>OS_InitAlarm</CODE></A><BR> 76<A href="OS_CancelAlarm.html"><CODE>OS_CancelAlarm</CODE></A><BR> 77<A href="OS_SetPeriodicAlarm.html"><CODE>OS_SetPeriodicAlarm</CODE></A><BR> 78<A href="OS_SetAlarmTag.html"><CODE>OS_SetAlarmTag</CODE></A><BR> 79<A href="../time/OS_SecondsToTicks.html"><CODE>OS_*SecondsToTicks</CODE></A></P> 80<H2>Revision History</H2> 81<P> 822005/03/08 Standardized the use of the term "interrupt" in Japanese.<BR> 832004/12/22 Added a statement about the alarm handler's being called from the timer interrupt handler.<BR> 842004/08/30 Added a statement about not being able to use the set alarm structure.<BR> 852004/02/25 Changed <CODE>systemClock</CODE> to <CODE>tick</CODE>.<BR> 862004/02/04 Initial version.</P> 87<hr><p>CONFIDENTIAL</p></body> 88</HTML>