doc/doxygen/html/timers__unix_8c-source.html
changeset 240 34654679f262
parent 215 f49e5a6b7804
equal deleted inserted replaced
239:f45fd4cd3832 240:34654679f262
    16   <ul>
    16   <ul>
    17     <li><a href="files.html"><span>File&nbsp;List</span></a></li>
    17     <li><a href="files.html"><span>File&nbsp;List</span></a></li>
    18     <li><a href="globals.html"><span>Globals</span></a></li>
    18     <li><a href="globals.html"><span>Globals</span></a></li>
    19   </ul></div>
    19   </ul></div>
    20 <div class="nav">
    20 <div class="nav">
    21 <a class="el" href="dir_d58fb241e647de6212c31ecccf9cbace.html">drivers</a>&nbsp;&raquo&nbsp;<a class="el" href="dir_48aec78d2c68f8c6a53202ad028bcb76.html">timers_unix</a></div>
    21 <a class="el" href="dir_65dd258ff9b9ef4cd7bd0d22f5e58dba.html">drivers</a>&nbsp;&raquo&nbsp;<a class="el" href="dir_ef7bbe78f2bc1c31fd793635a3143fcc.html">timers_unix</a></div>
    22 <h1>timers_unix.c</h1><a href="timers__unix_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
    22 <h1>timers_unix.c</h1><a href="timers__unix_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
    23 <a name="l00002"></a>00002 
    23 <a name="l00002"></a>00002 
    24 <a name="l00003"></a>00003 <span class="preprocessor">#include &lt;sys/time.h&gt;</span>
    24 <a name="l00003"></a>00003 <span class="preprocessor">#include &lt;sys/time.h&gt;</span>
    25 <a name="l00004"></a>00004 <span class="preprocessor">#include &lt;pthread.h&gt;</span> 
    25 <a name="l00004"></a>00004 <span class="preprocessor">#include &lt;pthread.h&gt;</span> 
    26 <a name="l00005"></a>00005 <span class="preprocessor">#include &lt;signal.h&gt;</span>
    26 <a name="l00005"></a>00005 <span class="preprocessor">#include &lt;signal.h&gt;</span>
    27 <a name="l00006"></a>00006 
    27 <a name="l00006"></a>00006 
    28 <a name="l00007"></a>00007 <span class="preprocessor">#include "<a class="code" href="win32_2applicfg_8h.html">applicfg.h</a>"</span>
    28 <a name="l00007"></a>00007 <span class="preprocessor">#include "<a class="code" href="win32_2applicfg_8h.html">applicfg.h</a>"</span>
    29 <a name="l00008"></a>00008 <span class="preprocessor">#include "<a class="code" href="timer_8h.html">timer.h</a>"</span>
    29 <a name="l00008"></a>00008 <span class="preprocessor">#include "<a class="code" href="timer_8h.html">timer.h</a>"</span>
    30 <a name="l00009"></a>00009 
    30 <a name="l00009"></a>00009 
    31 <a name="l00010"></a><a class="code" href="timers__unix_8c.html#93ad8a5a5e353192bfa45ae850df337f">00010</a> pthread_mutex_t <a class="code" href="timers__unix_8c.html#93ad8a5a5e353192bfa45ae850df337f">CanFestival_mutex</a> = PTHREAD_MUTEX_INITIALIZER;
    31 <a name="l00010"></a><a class="code" href="timers__unix_8c.html#16cebc4fb81e0421b9d57fcb5d7b2515">00010</a> pthread_mutex_t <a class="code" href="timers__unix_8c.html#16cebc4fb81e0421b9d57fcb5d7b2515">CanFestival_mutex</a> = PTHREAD_MUTEX_INITIALIZER;
    32 <a name="l00011"></a>00011 
    32 <a name="l00011"></a>00011 
    33 <a name="l00012"></a><a class="code" href="timers__unix_8c.html#ef197e4f64855d2ac4ccbc40595d6bdd">00012</a> <a class="code" href="timers__unix_2timerscfg_8h.html#07c1b78efc83716fac9e31b9862f7e60">TASK_HANDLE</a> <a class="code" href="timers__unix_8c.html#ef197e4f64855d2ac4ccbc40595d6bdd">TimerLoopThread</a>;
    33 <a name="l00012"></a><a class="code" href="timers__unix_8c.html#f62736ba59e8abc802e4b27965525bfa">00012</a> <a class="code" href="timers__unix_2timerscfg_8h.html#69c1aff70ae463b42314dc6689cb7400">TASK_HANDLE</a> <a class="code" href="timers__unix_8c.html#f62736ba59e8abc802e4b27965525bfa">TimerLoopThread</a>;
    34 <a name="l00013"></a>00013 
    34 <a name="l00013"></a>00013 
    35 <a name="l00014"></a><a class="code" href="timers__unix_8c.html#9b886230a6b35bdd1532a27ee7400d10">00014</a> <a class="code" href="hcs12_2applicfg_8h.html#6ae11f09e1ebf40f3562857272fab8bf">TIMEVAL</a> <a class="code" href="timers__unix_8c.html#9b886230a6b35bdd1532a27ee7400d10">last_time_set</a> = <a class="code" href="hcs12_2applicfg_8h.html#35b2fd1a5f6b88bf3842ba3663e6f85e">TIMEVAL_MAX</a>;
    35 <a name="l00014"></a><a class="code" href="timers__unix_8c.html#ed17ba940066a6220122e40c59387729">00014</a> <a class="code" href="hcs12_2applicfg_8h.html#dea5fb459bddd6fd539cdf665dd657e6">TIMEVAL</a> <a class="code" href="timers__unix_8c.html#ed17ba940066a6220122e40c59387729">last_time_set</a> = <a class="code" href="hcs12_2applicfg_8h.html#9b8b68779cc690a9f699155420328d0f">TIMEVAL_MAX</a>;
    36 <a name="l00015"></a>00015 
    36 <a name="l00015"></a>00015 
    37 <a name="l00016"></a><a class="code" href="timers__unix_8c.html#bcf9307062fc6f0a7906547a892e38df">00016</a> <span class="keyword">struct </span>timeval <a class="code" href="timers__unix_8c.html#bcf9307062fc6f0a7906547a892e38df">last_sig</a>;
    37 <a name="l00016"></a><a class="code" href="timers__unix_8c.html#ed3ab12fbab0a49f4643a662d72332e7">00016</a> <span class="keyword">struct </span>timeval <a class="code" href="timers__unix_8c.html#ed3ab12fbab0a49f4643a662d72332e7">last_sig</a>;
    38 <a name="l00017"></a>00017 
    38 <a name="l00017"></a>00017 
    39 <a name="l00018"></a><a class="code" href="timers__unix_8c.html#1a1e2de3a80567484c9b4d4f20d5a3d0">00018</a> timer_t <a class="code" href="timers__unix_8c.html#1a1e2de3a80567484c9b4d4f20d5a3d0">timer</a>;
    39 <a name="l00018"></a><a class="code" href="timers__unix_8c.html#bfccb49fc2d68544485b740a56da0f47">00018</a> timer_t <a class="code" href="timers__unix_8c.html#bfccb49fc2d68544485b740a56da0f47">timer</a>;
    40 <a name="l00019"></a>00019 
    40 <a name="l00019"></a>00019 
    41 <a name="l00020"></a><a class="code" href="timers__driver_8h.html#d7fee43b8a44cf8b7036853593044037">00020</a> <span class="keywordtype">void</span> <a class="code" href="timers__unix_8c.html#d7fee43b8a44cf8b7036853593044037">EnterMutex</a>(<span class="keywordtype">void</span>)
    41 <a name="l00020"></a><a class="code" href="timers__driver_8h.html#aa3c568288a54a9398524255602bbce8">00020</a> <span class="keywordtype">void</span> <a class="code" href="timers__unix_8c.html#aa3c568288a54a9398524255602bbce8">EnterMutex</a>(<span class="keywordtype">void</span>)
    42 <a name="l00021"></a>00021 {
    42 <a name="l00021"></a>00021 {
    43 <a name="l00022"></a>00022         pthread_mutex_lock(&amp;<a class="code" href="timers__unix_8c.html#93ad8a5a5e353192bfa45ae850df337f">CanFestival_mutex</a>); 
    43 <a name="l00022"></a>00022         pthread_mutex_lock(&amp;<a class="code" href="timers__unix_8c.html#16cebc4fb81e0421b9d57fcb5d7b2515">CanFestival_mutex</a>); 
    44 <a name="l00023"></a>00023 }
    44 <a name="l00023"></a>00023 }
    45 <a name="l00024"></a>00024 
    45 <a name="l00024"></a>00024 
    46 <a name="l00025"></a><a class="code" href="timers__driver_8h.html#73d9a4eb941fb20cf6b597840510394b">00025</a> <span class="keywordtype">void</span> <a class="code" href="timers__unix_8c.html#73d9a4eb941fb20cf6b597840510394b">LeaveMutex</a>(<span class="keywordtype">void</span>)
    46 <a name="l00025"></a><a class="code" href="timers__driver_8h.html#887d197b991c23bc11f626ae688abec7">00025</a> <span class="keywordtype">void</span> <a class="code" href="timers__unix_8c.html#887d197b991c23bc11f626ae688abec7">LeaveMutex</a>(<span class="keywordtype">void</span>)
    47 <a name="l00026"></a>00026 {
    47 <a name="l00026"></a>00026 {
    48 <a name="l00027"></a>00027         pthread_mutex_unlock(&amp;<a class="code" href="timers__unix_8c.html#93ad8a5a5e353192bfa45ae850df337f">CanFestival_mutex</a>);
    48 <a name="l00027"></a>00027         pthread_mutex_unlock(&amp;<a class="code" href="timers__unix_8c.html#16cebc4fb81e0421b9d57fcb5d7b2515">CanFestival_mutex</a>);
    49 <a name="l00028"></a>00028 }
    49 <a name="l00028"></a>00028 }
    50 <a name="l00029"></a>00029 
    50 <a name="l00029"></a>00029 
    51 <a name="l00030"></a><a class="code" href="timers__unix_8c.html#4cd19302f57b08fc0403a05017332735">00030</a> <span class="keywordtype">void</span> <a class="code" href="timers__unix_8c.html#4cd19302f57b08fc0403a05017332735">timer_notify</a>(sigval_t val)
    51 <a name="l00030"></a><a class="code" href="timers__unix_8c.html#40e7943587a24eae55dd73d80a913750">00030</a> <span class="keywordtype">void</span> <a class="code" href="timers__unix_8c.html#40e7943587a24eae55dd73d80a913750">timer_notify</a>(sigval_t val)
    52 <a name="l00031"></a>00031 {
    52 <a name="l00031"></a>00031 {
    53 <a name="l00032"></a>00032         gettimeofday(&amp;<a class="code" href="timers__unix_8c.html#bcf9307062fc6f0a7906547a892e38df">last_sig</a>,NULL);
    53 <a name="l00032"></a>00032         gettimeofday(&amp;<a class="code" href="timers__unix_8c.html#ed3ab12fbab0a49f4643a662d72332e7">last_sig</a>,NULL);
    54 <a name="l00033"></a>00033         <a class="code" href="timers__unix_8c.html#d7fee43b8a44cf8b7036853593044037">EnterMutex</a>();
    54 <a name="l00033"></a>00033         <a class="code" href="timers__unix_8c.html#aa3c568288a54a9398524255602bbce8">EnterMutex</a>();
    55 <a name="l00034"></a>00034         <a class="code" href="timer_8c.html#fa75192a3238525618f8cb83004930cc">TimeDispatch</a>();
    55 <a name="l00034"></a>00034         <a class="code" href="timer_8c.html#7a5a515821c2e4fb2f66bac72389da00">TimeDispatch</a>();
    56 <a name="l00035"></a>00035         <a class="code" href="timers__unix_8c.html#73d9a4eb941fb20cf6b597840510394b">LeaveMutex</a>();
    56 <a name="l00035"></a>00035         <a class="code" href="timers__unix_8c.html#887d197b991c23bc11f626ae688abec7">LeaveMutex</a>();
    57 <a name="l00036"></a>00036 <span class="comment">//      printf("getCurrentTime() return=%u\n", p.tv_usec);</span>
    57 <a name="l00036"></a>00036 <span class="comment">//      printf("getCurrentTime() return=%u\n", p.tv_usec);</span>
    58 <a name="l00037"></a>00037 }
    58 <a name="l00037"></a>00037 }
    59 <a name="l00038"></a>00038 
    59 <a name="l00038"></a>00038 
    60 <a name="l00039"></a><a class="code" href="timers__unix_8c.html#02922529b60419a94afe8f369dda070b">00039</a> <span class="keywordtype">void</span> <a class="code" href="canOpenDriver_8c.html#02922529b60419a94afe8f369dda070b">initTimer</a>(<span class="keywordtype">void</span>)
    60 <a name="l00039"></a><a class="code" href="timers__unix_8c.html#607bd2711b85a87fce51334bb36bad1a">00039</a> <span class="keywordtype">void</span> <a class="code" href="canOpenDriver_8c.html#607bd2711b85a87fce51334bb36bad1a">initTimer</a>(<span class="keywordtype">void</span>)
    61 <a name="l00040"></a>00040 {
    61 <a name="l00040"></a>00040 {
    62 <a name="l00041"></a>00041         <span class="keyword">struct </span>sigevent sigev;
    62 <a name="l00041"></a>00041         <span class="keyword">struct </span>sigevent sigev;
    63 <a name="l00042"></a>00042 
    63 <a name="l00042"></a>00042 
    64 <a name="l00043"></a>00043         <span class="comment">// Take first absolute time ref.</span>
    64 <a name="l00043"></a>00043         <span class="comment">// Take first absolute time ref.</span>
    65 <a name="l00044"></a>00044         gettimeofday(&amp;<a class="code" href="timers__unix_8c.html#bcf9307062fc6f0a7906547a892e38df">last_sig</a>,NULL);
    65 <a name="l00044"></a>00044         gettimeofday(&amp;<a class="code" href="timers__unix_8c.html#ed3ab12fbab0a49f4643a662d72332e7">last_sig</a>,NULL);
    66 <a name="l00045"></a>00045 
    66 <a name="l00045"></a>00045 
    67 <a name="l00046"></a>00046         memset (&amp;sigev, 0, <span class="keyword">sizeof</span> (<span class="keyword">struct</span> sigevent));
    67 <a name="l00046"></a>00046         memset (&amp;sigev, 0, <span class="keyword">sizeof</span> (<span class="keyword">struct</span> sigevent));
    68 <a name="l00047"></a>00047         sigev.sigev_value.sival_int = 0;
    68 <a name="l00047"></a>00047         sigev.sigev_value.sival_int = 0;
    69 <a name="l00048"></a>00048         sigev.sigev_notify = SIGEV_THREAD;
    69 <a name="l00048"></a>00048         sigev.sigev_notify = SIGEV_THREAD;
    70 <a name="l00049"></a>00049         sigev.sigev_notify_attributes = NULL;
    70 <a name="l00049"></a>00049         sigev.sigev_notify_attributes = NULL;
    71 <a name="l00050"></a>00050         sigev.sigev_notify_function = <a class="code" href="timers__unix_8c.html#4cd19302f57b08fc0403a05017332735">timer_notify</a>;
    71 <a name="l00050"></a>00050         sigev.sigev_notify_function = <a class="code" href="timers__unix_8c.html#40e7943587a24eae55dd73d80a913750">timer_notify</a>;
    72 <a name="l00051"></a>00051 
    72 <a name="l00051"></a>00051 
    73 <a name="l00052"></a>00052         timer_create (CLOCK_REALTIME, &amp;sigev, &amp;<a class="code" href="timers__unix_8c.html#1a1e2de3a80567484c9b4d4f20d5a3d0">timer</a>);
    73 <a name="l00052"></a>00052         timer_create (CLOCK_REALTIME, &amp;sigev, &amp;<a class="code" href="timers__unix_8c.html#bfccb49fc2d68544485b740a56da0f47">timer</a>);
    74 <a name="l00053"></a>00053 }
    74 <a name="l00053"></a>00053 }
    75 <a name="l00054"></a>00054 
    75 <a name="l00054"></a>00054 
    76 <a name="l00055"></a><a class="code" href="timers__driver_8h.html#8758484f3cebb0cd44bb247c3f23d5e3">00055</a> <span class="keywordtype">void</span> <a class="code" href="timers__unix_8c.html#8758484f3cebb0cd44bb247c3f23d5e3">StopTimerLoop</a>(<span class="keywordtype">void</span>)
    76 <a name="l00055"></a><a class="code" href="timers__driver_8h.html#8d52f2db8b505e53ace5dd1c2a789d94">00055</a> <span class="keywordtype">void</span> <a class="code" href="timers__unix_8c.html#8d52f2db8b505e53ace5dd1c2a789d94">StopTimerLoop</a>(<span class="keywordtype">void</span>)
    77 <a name="l00056"></a>00056 {
    77 <a name="l00056"></a>00056 {
    78 <a name="l00057"></a>00057         <a class="code" href="timers__unix_8c.html#d7fee43b8a44cf8b7036853593044037">EnterMutex</a>();
    78 <a name="l00057"></a>00057         <a class="code" href="timers__unix_8c.html#aa3c568288a54a9398524255602bbce8">EnterMutex</a>();
    79 <a name="l00058"></a>00058         timer_delete (<a class="code" href="timers__unix_8c.html#1a1e2de3a80567484c9b4d4f20d5a3d0">timer</a>);
    79 <a name="l00058"></a>00058         timer_delete (<a class="code" href="timers__unix_8c.html#bfccb49fc2d68544485b740a56da0f47">timer</a>);
    80 <a name="l00059"></a>00059         <a class="code" href="timers__unix_8c.html#73d9a4eb941fb20cf6b597840510394b">LeaveMutex</a>();
    80 <a name="l00059"></a>00059         <a class="code" href="timers__unix_8c.html#887d197b991c23bc11f626ae688abec7">LeaveMutex</a>();
    81 <a name="l00060"></a>00060 }
    81 <a name="l00060"></a>00060 }
    82 <a name="l00061"></a>00061 
    82 <a name="l00061"></a>00061 
    83 <a name="l00062"></a><a class="code" href="timers__driver_8h.html#c9e1731843825eb55e7a94894e6a8ec5">00062</a> <span class="keywordtype">void</span> <a class="code" href="timers__unix_8c.html#c9e1731843825eb55e7a94894e6a8ec5">StartTimerLoop</a>(<a class="code" href="timer_8h.html#f7d102e060339d3730ceae5fea03691b">TimerCallback_t</a> init_callback)
    83 <a name="l00062"></a><a class="code" href="timers__driver_8h.html#dd08f21a7c3fcbcd53a2c41b00879fdd">00062</a> <span class="keywordtype">void</span> <a class="code" href="timers__unix_8c.html#dd08f21a7c3fcbcd53a2c41b00879fdd">StartTimerLoop</a>(<a class="code" href="timer_8h.html#c8436e7543fa1329b00e570246071313">TimerCallback_t</a> init_callback)
    84 <a name="l00063"></a>00063 {
    84 <a name="l00063"></a>00063 {
    85 <a name="l00064"></a>00064         <a class="code" href="canOpenDriver_8c.html#02922529b60419a94afe8f369dda070b">initTimer</a>();
    85 <a name="l00064"></a>00064         <a class="code" href="canOpenDriver_8c.html#607bd2711b85a87fce51334bb36bad1a">initTimer</a>();
    86 <a name="l00065"></a>00065         <a class="code" href="timers__unix_8c.html#d7fee43b8a44cf8b7036853593044037">EnterMutex</a>();
    86 <a name="l00065"></a>00065         <a class="code" href="timers__unix_8c.html#aa3c568288a54a9398524255602bbce8">EnterMutex</a>();
    87 <a name="l00066"></a>00066         <span class="comment">// At first, TimeDispatch will call init_callback.</span>
    87 <a name="l00066"></a>00066         <span class="comment">// At first, TimeDispatch will call init_callback.</span>
    88 <a name="l00067"></a>00067         <a class="code" href="timer_8c.html#11c2616d78f06ed9144ef662f757b128">SetAlarm</a>(NULL, 0, init_callback, 0, 0);
    88 <a name="l00067"></a>00067         <a class="code" href="timer_8c.html#956b22f24089db4c367f40199f838a20">SetAlarm</a>(NULL, 0, init_callback, 0, 0);
    89 <a name="l00068"></a>00068         <a class="code" href="timers__unix_8c.html#73d9a4eb941fb20cf6b597840510394b">LeaveMutex</a>();
    89 <a name="l00068"></a>00068         <a class="code" href="timers__unix_8c.html#887d197b991c23bc11f626ae688abec7">LeaveMutex</a>();
    90 <a name="l00069"></a>00069 }
    90 <a name="l00069"></a>00069 }
    91 <a name="l00070"></a>00070 
    91 <a name="l00070"></a>00070 
    92 <a name="l00071"></a><a class="code" href="timers__driver_8h.html#3e8cb5b8159f655ee0bac1ea1d2358d4">00071</a> <span class="keywordtype">void</span> <a class="code" href="timers__unix_8c.html#a3a7df911baa20b01c4374a9677a154a">CreateReceiveTask</a>(<a class="code" href="unix_2applicfg_8h.html#7ef59f941603c6680e74fc335523f17e">CAN_PORT</a> port, <a class="code" href="timers__unix_2timerscfg_8h.html#07c1b78efc83716fac9e31b9862f7e60">TASK_HANDLE</a>* Thread, <span class="keywordtype">void</span>* ReceiveLoopPtr)
    92 <a name="l00071"></a><a class="code" href="timers__driver_8h.html#1a890f533adc9b50e2a454fab1a7dc8c">00071</a> <span class="keywordtype">void</span> <a class="code" href="timers__unix_8c.html#09c921f9537f26895843a3c21620855b">CreateReceiveTask</a>(<a class="code" href="unix_2applicfg_8h.html#c5a917a8cacf5edd42ba6486c0c8a243">CAN_PORT</a> port, <a class="code" href="timers__unix_2timerscfg_8h.html#69c1aff70ae463b42314dc6689cb7400">TASK_HANDLE</a>* Thread, <span class="keywordtype">void</span>* ReceiveLoopPtr)
    93 <a name="l00072"></a>00072 {
    93 <a name="l00072"></a>00072 {
    94 <a name="l00073"></a>00073         pthread_create(Thread, NULL, ReceiveLoopPtr, (<span class="keywordtype">void</span>*)port);
    94 <a name="l00073"></a>00073         pthread_create(Thread, NULL, ReceiveLoopPtr, (<span class="keywordtype">void</span>*)port);
    95 <a name="l00074"></a>00074 }
    95 <a name="l00074"></a>00074 }
    96 <a name="l00075"></a>00075 
    96 <a name="l00075"></a>00075 
    97 <a name="l00076"></a><a class="code" href="timers__driver_8h.html#c492d1b5ebd2d99020e72c137beda878">00076</a> <span class="keywordtype">void</span> <a class="code" href="timers__unix_8c.html#4b2486891ee01e06e2deead4cf963727">WaitReceiveTaskEnd</a>(<a class="code" href="timers__unix_2timerscfg_8h.html#07c1b78efc83716fac9e31b9862f7e60">TASK_HANDLE</a> Thread)
    97 <a name="l00076"></a><a class="code" href="timers__driver_8h.html#13098034e0ff8ee9fe20d193c82ecb1b">00076</a> <span class="keywordtype">void</span> <a class="code" href="timers__unix_8c.html#b21b041545f4dfc5660514fbc3c2f89c">WaitReceiveTaskEnd</a>(<a class="code" href="timers__unix_2timerscfg_8h.html#69c1aff70ae463b42314dc6689cb7400">TASK_HANDLE</a> Thread)
    98 <a name="l00077"></a>00077 {
    98 <a name="l00077"></a>00077 {
    99 <a name="l00078"></a>00078         pthread_kill(Thread, SIGTERM);
    99 <a name="l00078"></a>00078         pthread_kill(Thread, SIGTERM);
   100 <a name="l00079"></a>00079         pthread_join(Thread, NULL);
   100 <a name="l00079"></a>00079         pthread_join(Thread, NULL);
   101 <a name="l00080"></a>00080 }
   101 <a name="l00080"></a>00080 }
   102 <a name="l00081"></a>00081 
   102 <a name="l00081"></a>00081 
   103 <a name="l00082"></a><a class="code" href="timers__unix_8c.html#016587a4d6fc754357c47c9df9f0bde4">00082</a> <span class="preprocessor">#define maxval(a,b) ((a&gt;b)?a:b)</span>
   103 <a name="l00082"></a><a class="code" href="timers__unix_8c.html#191df9418bfcc2c4774dc16d694c3ae9">00082</a> <span class="preprocessor">#define maxval(a,b) ((a&gt;b)?a:b)</span>
   104 <a name="l00083"></a><a class="code" href="timer_8h.html#b8d05dee70f04b5c5190ab00e84da106">00083</a> <span class="preprocessor"></span><span class="keywordtype">void</span> <a class="code" href="timers__unix_8c.html#b8d05dee70f04b5c5190ab00e84da106">setTimer</a>(<a class="code" href="hcs12_2applicfg_8h.html#6ae11f09e1ebf40f3562857272fab8bf">TIMEVAL</a> value)
   104 <a name="l00083"></a><a class="code" href="timer_8h.html#7996006c628d2df030b9684d7a86acd1">00083</a> <span class="preprocessor"></span><span class="keywordtype">void</span> <a class="code" href="timers__unix_8c.html#7996006c628d2df030b9684d7a86acd1">setTimer</a>(<a class="code" href="hcs12_2applicfg_8h.html#dea5fb459bddd6fd539cdf665dd657e6">TIMEVAL</a> value)
   105 <a name="l00084"></a>00084 {
   105 <a name="l00084"></a>00084 {
   106 <a name="l00085"></a>00085 <span class="comment">//      printf("setTimer(TIMEVAL value=%d)\n", value);</span>
   106 <a name="l00085"></a>00085 <span class="comment">//      printf("setTimer(TIMEVAL value=%d)\n", value);</span>
   107 <a name="l00086"></a>00086         <span class="comment">// TIMEVAL is us whereas setitimer wants ns...</span>
   107 <a name="l00086"></a>00086         <span class="comment">// TIMEVAL is us whereas setitimer wants ns...</span>
   108 <a name="l00087"></a>00087         <span class="keywordtype">long</span> tv_nsec = 1000 * (<a class="code" href="timers__unix_8c.html#016587a4d6fc754357c47c9df9f0bde4">maxval</a>(value,1)%1000000);
   108 <a name="l00087"></a>00087         <span class="keywordtype">long</span> tv_nsec = 1000 * (<a class="code" href="timers__unix_8c.html#191df9418bfcc2c4774dc16d694c3ae9">maxval</a>(value,1)%1000000);
   109 <a name="l00088"></a>00088         time_t tv_sec = value/1000000;
   109 <a name="l00088"></a>00088         time_t tv_sec = value/1000000;
   110 <a name="l00089"></a>00089         <span class="keyword">struct </span>itimerspec timerValues;
   110 <a name="l00089"></a>00089         <span class="keyword">struct </span>itimerspec timerValues;
   111 <a name="l00090"></a>00090         timerValues.it_value.tv_sec = tv_sec;
   111 <a name="l00090"></a>00090         timerValues.it_value.tv_sec = tv_sec;
   112 <a name="l00091"></a>00091         timerValues.it_value.tv_nsec = tv_nsec;
   112 <a name="l00091"></a>00091         timerValues.it_value.tv_nsec = tv_nsec;
   113 <a name="l00092"></a>00092         timerValues.it_interval.tv_sec = 0;
   113 <a name="l00092"></a>00092         timerValues.it_interval.tv_sec = 0;
   114 <a name="l00093"></a>00093         timerValues.it_interval.tv_nsec = 0;
   114 <a name="l00093"></a>00093         timerValues.it_interval.tv_nsec = 0;
   115 <a name="l00094"></a>00094 
   115 <a name="l00094"></a>00094 
   116 <a name="l00095"></a>00095         timer_settime (<a class="code" href="timers__unix_8c.html#1a1e2de3a80567484c9b4d4f20d5a3d0">timer</a>, 0, &amp;timerValues, NULL);
   116 <a name="l00095"></a>00095         timer_settime (<a class="code" href="timers__unix_8c.html#bfccb49fc2d68544485b740a56da0f47">timer</a>, 0, &amp;timerValues, NULL);
   117 <a name="l00096"></a>00096 }
   117 <a name="l00096"></a>00096 }
   118 <a name="l00097"></a>00097 
   118 <a name="l00097"></a>00097 
   119 <a name="l00098"></a><a class="code" href="timers__unix_8c.html#4dccc204d52176bd547ab34d6858f5ba">00098</a> <a class="code" href="hcs12_2applicfg_8h.html#6ae11f09e1ebf40f3562857272fab8bf">TIMEVAL</a> <a class="code" href="canOpenDriver_8c.html#24dbe63e88d184388542037d16a8208d">getElapsedTime</a>(<span class="keywordtype">void</span>)
   119 <a name="l00098"></a><a class="code" href="timers__unix_8c.html#75efe30105165658d05d871255f8c0a2">00098</a> <a class="code" href="hcs12_2applicfg_8h.html#dea5fb459bddd6fd539cdf665dd657e6">TIMEVAL</a> <a class="code" href="canOpenDriver_8c.html#38b23a8ee3748bca3415967b90df1e15">getElapsedTime</a>(<span class="keywordtype">void</span>)
   120 <a name="l00099"></a>00099 {
   120 <a name="l00099"></a>00099 {
   121 <a name="l00100"></a>00100         <span class="keyword">struct </span>timeval p;
   121 <a name="l00100"></a>00100         <span class="keyword">struct </span>timeval p;
   122 <a name="l00101"></a>00101         gettimeofday(&amp;p,NULL);
   122 <a name="l00101"></a>00101         gettimeofday(&amp;p,NULL);
   123 <a name="l00102"></a>00102 <span class="comment">//      printf("getCurrentTime() return=%u\n", p.tv_usec);</span>
   123 <a name="l00102"></a>00102 <span class="comment">//      printf("getCurrentTime() return=%u\n", p.tv_usec);</span>
   124 <a name="l00103"></a>00103         <span class="keywordflow">return</span> (p.tv_sec - <a class="code" href="timers__unix_8c.html#bcf9307062fc6f0a7906547a892e38df">last_sig</a>.tv_sec)* 1000000 + p.tv_usec - <a class="code" href="timers__unix_8c.html#bcf9307062fc6f0a7906547a892e38df">last_sig</a>.tv_usec;
   124 <a name="l00103"></a>00103         <span class="keywordflow">return</span> (p.tv_sec - <a class="code" href="timers__unix_8c.html#ed3ab12fbab0a49f4643a662d72332e7">last_sig</a>.tv_sec)* 1000000 + p.tv_usec - <a class="code" href="timers__unix_8c.html#ed3ab12fbab0a49f4643a662d72332e7">last_sig</a>.tv_usec;
   125 <a name="l00104"></a>00104 }
   125 <a name="l00104"></a>00104 }
   126 </pre></div><hr size="1"><address style="align: right;"><small>Generated on Fri Jun 8 08:51:38 2007 for CanFestival by&nbsp;
   126 </pre></div><hr size="1"><address style="align: right;"><small>Generated on Mon Jul 2 19:10:16 2007 for CanFestival by&nbsp;
   127 <a href="http://www.doxygen.org/index.html">
   127 <a href="http://www.doxygen.org/index.html">
   128 <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.1 </small></address>
   128 <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.1 </small></address>
   129 </body>
   129 </body>
   130 </html>
   130 </html>