1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
|
2 <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> |
|
3 <title>CanFestival: /home/epimerde/documents/tc11/CanFestival-3/drivers/timers_xeno/timers_xeno.c Source File</title> |
|
4 <link href="doxygen.css" rel="stylesheet" type="text/css"> |
|
5 <link href="tabs.css" rel="stylesheet" type="text/css"> |
|
6 </head><body> |
|
7 <!-- Generated by Doxygen 1.5.1 --> |
|
8 <div class="tabs"> |
|
9 <ul> |
|
10 <li><a href="main.html"><span>Main Page</span></a></li> |
|
11 <li><a href="namespaces.html"><span>Namespaces</span></a></li> |
|
12 <li><a href="annotated.html"><span>Data Structures</span></a></li> |
|
13 <li id="current"><a href="files.html"><span>Files</span></a></li> |
|
14 </ul></div> |
|
15 <div class="tabs"> |
|
16 <ul> |
|
17 <li><a href="files.html"><span>File List</span></a></li> |
|
18 <li><a href="globals.html"><span>Globals</span></a></li> |
|
19 </ul></div> |
|
20 <h1>/home/epimerde/documents/tc11/CanFestival-3/drivers/timers_xeno/timers_xeno.c</h1><a href="timers__xeno_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 <stdlib.h></span> |
|
21 <a name="l00002"></a>00002 <span class="preprocessor">#include <unistd.h></span> |
|
22 <a name="l00003"></a>00003 <span class="preprocessor">#include <sys/mman.h></span> |
|
23 <a name="l00004"></a>00004 |
|
24 <a name="l00005"></a>00005 <span class="preprocessor">#include <native/task.h></span> |
|
25 <a name="l00006"></a>00006 <span class="preprocessor">#include <native/timer.h></span> |
|
26 <a name="l00007"></a>00007 <span class="preprocessor">#include <native/mutex.h></span> |
|
27 <a name="l00008"></a>00008 <span class="preprocessor">#include <native/alarm.h></span> |
|
28 <a name="l00009"></a>00009 |
|
29 <a name="l00010"></a>00010 <span class="preprocessor">#include "<a class="code" href="win32_2applicfg_8h.html">applicfg.h</a>"</span> |
|
30 <a name="l00011"></a>00011 <span class="preprocessor">#include "<a class="code" href="can__driver_8h.html">can_driver.h</a>"</span> |
|
31 <a name="l00012"></a>00012 <span class="preprocessor">#include "<a class="code" href="timer_8h.html">timer.h</a>"</span> |
|
32 <a name="l00013"></a>00013 |
|
33 <a name="l00014"></a><a class="code" href="timers__xeno_8c.html#3e43352afeb0977d4e99f3590026c9ee">00014</a> <span class="preprocessor">#define TIMERLOOP_TASK_CREATED 1</span> |
|
34 <a name="l00015"></a>00015 <span class="preprocessor"></span> |
|
35 <a name="l00016"></a><a class="code" href="timers__xeno_8c.html#b6ebfe5bfc980bae026866758af3a7ff">00016</a> RT_MUTEX <a class="code" href="timers__unix_8c.html#93ad8a5a5e353192bfa45ae850df337f">CanFestival_mutex</a>; |
|
36 <a name="l00017"></a><a class="code" href="timers__xeno_8c.html#3921261b6599c37eb3830a799d05f32e">00017</a> RT_TASK <a class="code" href="timers__xeno_8c.html#3921261b6599c37eb3830a799d05f32e">timerloop_task</a>; |
|
37 <a name="l00018"></a><a class="code" href="timers__xeno_8c.html#b64940b870e06e40ac13634a9e2b9ac2">00018</a> RTIME <a class="code" href="timers__xeno_8c.html#b64940b870e06e40ac13634a9e2b9ac2">last_time_read</a>; |
|
38 <a name="l00019"></a><a class="code" href="timers__xeno_8c.html#faf0ed3ab58750ccf1a09c52f7304cc3">00019</a> RTIME <a class="code" href="timers__xeno_8c.html#faf0ed3ab58750ccf1a09c52f7304cc3">last_occured_alarm</a>; |
|
39 <a name="l00020"></a><a class="code" href="timers__xeno_8c.html#e2985cf19e9415625d21f0f79b580fd0">00020</a> RTIME <a class="code" href="timers__xeno_8c.html#e2985cf19e9415625d21f0f79b580fd0">last_alarm_set</a>; |
|
40 <a name="l00021"></a>00021 |
|
41 <a name="l00022"></a><a class="code" href="timers__xeno_8c.html#c006a038004f458645d9f7ef06c7bd04">00022</a> <span class="keywordtype">char</span> <a class="code" href="timers__xeno_8c.html#c006a038004f458645d9f7ef06c7bd04">stop_timer</a>=0; |
|
42 <a name="l00023"></a>00023 |
|
43 <a name="l00024"></a><a class="code" href="timers__xeno_8c.html#f37d89241d0a9ac0430a0db6c1ead3d2">00024</a> <span class="keywordtype">void</span> <a class="code" href="timers__xeno_8c.html#f37d89241d0a9ac0430a0db6c1ead3d2">cleanup_all</a>(<span class="keywordtype">void</span>) |
|
44 <a name="l00025"></a>00025 { |
|
45 <a name="l00026"></a>00026 rt_task_delete(&<a class="code" href="timers__xeno_8c.html#3921261b6599c37eb3830a799d05f32e">timerloop_task</a>); |
|
46 <a name="l00027"></a>00027 } |
|
47 <a name="l00028"></a><a class="code" href="timers__xeno_8c.html#8758484f3cebb0cd44bb247c3f23d5e3">00028</a> <span class="keywordtype">void</span> <a class="code" href="timers__unix_8c.html#8758484f3cebb0cd44bb247c3f23d5e3">StopTimerLoop</a>(<span class="keywordtype">void</span>) |
|
48 <a name="l00029"></a>00029 { |
|
49 <a name="l00030"></a>00030 <a class="code" href="timers__xeno_8c.html#c006a038004f458645d9f7ef06c7bd04">stop_timer</a> = 1; |
|
50 <a name="l00031"></a>00031 rt_task_unblock(&<a class="code" href="timers__xeno_8c.html#3921261b6599c37eb3830a799d05f32e">timerloop_task</a>); |
|
51 <a name="l00032"></a>00032 } |
|
52 <a name="l00033"></a>00033 |
|
53 <a name="l00034"></a>00034 |
|
54 <a name="l00035"></a><a class="code" href="timers__xeno_8c.html#d7fee43b8a44cf8b7036853593044037">00035</a> <span class="keywordtype">void</span> <a class="code" href="timers__unix_8c.html#d7fee43b8a44cf8b7036853593044037">EnterMutex</a>(<span class="keywordtype">void</span>) |
|
55 <a name="l00036"></a>00036 { |
|
56 <a name="l00037"></a>00037 rt_mutex_lock(&<a class="code" href="timers__unix_8c.html#93ad8a5a5e353192bfa45ae850df337f">CanFestival_mutex</a>, TM_INFINITE); |
|
57 <a name="l00038"></a>00038 } |
|
58 <a name="l00039"></a>00039 |
|
59 <a name="l00040"></a><a class="code" href="timers__xeno_8c.html#73d9a4eb941fb20cf6b597840510394b">00040</a> <span class="keywordtype">void</span> <a class="code" href="timers__unix_8c.html#73d9a4eb941fb20cf6b597840510394b">LeaveMutex</a>(<span class="keywordtype">void</span>) |
|
60 <a name="l00041"></a>00041 { |
|
61 <a name="l00042"></a>00042 rt_mutex_unlock(&<a class="code" href="timers__unix_8c.html#93ad8a5a5e353192bfa45ae850df337f">CanFestival_mutex</a>); |
|
62 <a name="l00043"></a>00043 } |
|
63 <a name="l00044"></a>00044 |
|
64 <a name="l00045"></a><a class="code" href="timers__xeno_8c.html#15986eb72a64e72df6600dc23c1e19c8">00045</a> <span class="keywordtype">void</span> <a class="code" href="timers__xeno_8c.html#15986eb72a64e72df6600dc23c1e19c8">timerloop_task_proc</a>(<span class="keywordtype">void</span> *arg) |
|
65 <a name="l00046"></a>00046 { |
|
66 <a name="l00047"></a>00047 <span class="keywordtype">int</span> ret; |
|
67 <a name="l00048"></a>00048 <span class="keywordflow">do</span>{ |
|
68 <a name="l00049"></a>00049 <span class="keywordflow">do</span>{ |
|
69 <a name="l00050"></a>00050 <a class="code" href="timers__xeno_8c.html#faf0ed3ab58750ccf1a09c52f7304cc3">last_occured_alarm</a> = <a class="code" href="timers__xeno_8c.html#e2985cf19e9415625d21f0f79b580fd0">last_alarm_set</a>; |
|
70 <a name="l00051"></a>00051 <a class="code" href="timers__unix_8c.html#d7fee43b8a44cf8b7036853593044037">EnterMutex</a>(); |
|
71 <a name="l00052"></a>00052 <a class="code" href="timer_8c.html#fa75192a3238525618f8cb83004930cc">TimeDispatch</a>(); |
|
72 <a name="l00053"></a>00053 <a class="code" href="timers__unix_8c.html#73d9a4eb941fb20cf6b597840510394b">LeaveMutex</a>(); |
|
73 <a name="l00054"></a>00054 <span class="keywordflow">while</span> ((ret = rt_task_sleep_until(<a class="code" href="timers__xeno_8c.html#e2985cf19e9415625d21f0f79b580fd0">last_alarm_set</a>)) == -EINTR); |
|
74 <a name="l00055"></a>00055 }<span class="keywordflow">while</span> (ret == 0); |
|
75 <a name="l00056"></a>00056 }<span class="keywordflow">while</span> (!<a class="code" href="timers__xeno_8c.html#c006a038004f458645d9f7ef06c7bd04">stop_timer</a>); |
|
76 <a name="l00057"></a>00057 printf(<span class="stringliteral">"End of TimerLoop, code %d\n"</span>,ret); |
|
77 <a name="l00058"></a>00058 } |
|
78 <a name="l00059"></a>00059 |
|
79 <a name="l00060"></a><a class="code" href="timers__xeno_8c.html#c9e1731843825eb55e7a94894e6a8ec5">00060</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) |
|
80 <a name="l00061"></a>00061 { |
|
81 <a name="l00062"></a>00062 <span class="keywordtype">int</span> ret; |
|
82 <a name="l00063"></a>00063 <a class="code" href="timers__xeno_8c.html#c006a038004f458645d9f7ef06c7bd04">stop_timer</a> = 0; |
|
83 <a name="l00064"></a>00064 <span class="keywordtype">char</span> taskname[32]; |
|
84 <a name="l00065"></a>00065 snprintf(taskname, <span class="keyword">sizeof</span>(taskname), <span class="stringliteral">"timerloop-%d"</span>, getpid()); |
|
85 <a name="l00066"></a>00066 |
|
86 <a name="l00067"></a>00067 mlockall(MCL_CURRENT | MCL_FUTURE); |
|
87 <a name="l00068"></a>00068 |
|
88 <a name="l00069"></a>00069 <span class="comment">//create timerloop_task</span> |
|
89 <a name="l00070"></a>00070 ret = rt_task_create(&<a class="code" href="timers__xeno_8c.html#3921261b6599c37eb3830a799d05f32e">timerloop_task</a>, taskname, 0, 50, 0); |
|
90 <a name="l00071"></a>00071 <span class="keywordflow">if</span> (ret) { |
|
91 <a name="l00072"></a>00072 printf(<span class="stringliteral">"Failed to create timerloop_task, code %d\n"</span>,errno); |
|
92 <a name="l00073"></a>00073 <span class="keywordflow">return</span>; |
|
93 <a name="l00074"></a>00074 } |
|
94 <a name="l00075"></a>00075 |
|
95 <a name="l00076"></a>00076 <a class="code" href="canOpenDriver_8c.html#24dbe63e88d184388542037d16a8208d">getElapsedTime</a>(); |
|
96 <a name="l00077"></a>00077 <a class="code" href="timers__xeno_8c.html#e2985cf19e9415625d21f0f79b580fd0">last_alarm_set</a> = <a class="code" href="timers__xeno_8c.html#b64940b870e06e40ac13634a9e2b9ac2">last_time_read</a>; |
|
97 <a name="l00078"></a>00078 <a class="code" href="timers__xeno_8c.html#faf0ed3ab58750ccf1a09c52f7304cc3">last_occured_alarm</a> = <a class="code" href="timers__xeno_8c.html#e2985cf19e9415625d21f0f79b580fd0">last_alarm_set</a>; |
|
98 <a name="l00079"></a>00079 <a class="code" href="timer_8c.html#11c2616d78f06ed9144ef662f757b128">SetAlarm</a>(NULL, 0, init_callback, 0, 0); |
|
99 <a name="l00080"></a>00080 <span class="comment">// start timerloop_task</span> |
|
100 <a name="l00081"></a>00081 ret = rt_task_start(&<a class="code" href="timers__xeno_8c.html#3921261b6599c37eb3830a799d05f32e">timerloop_task</a>,&<a class="code" href="timers__xeno_8c.html#15986eb72a64e72df6600dc23c1e19c8">timerloop_task_proc</a>,NULL); |
|
101 <a name="l00082"></a>00082 <span class="keywordflow">if</span> (ret) { |
|
102 <a name="l00083"></a>00083 printf(<span class="stringliteral">"Failed to start timerloop_task, code %d\n"</span>,errno); |
|
103 <a name="l00084"></a>00084 <span class="keywordflow">goto</span> error; |
|
104 <a name="l00085"></a>00085 } |
|
105 <a name="l00086"></a>00086 |
|
106 <a name="l00087"></a>00087 <span class="keywordflow">return</span>; |
|
107 <a name="l00088"></a>00088 |
|
108 <a name="l00089"></a>00089 error: |
|
109 <a name="l00090"></a>00090 <a class="code" href="timers__xeno_8c.html#f37d89241d0a9ac0430a0db6c1ead3d2">cleanup_all</a>(); |
|
110 <a name="l00091"></a>00091 } |
|
111 <a name="l00092"></a>00092 |
|
112 <a name="l00093"></a><a class="code" href="timers__xeno_8c.html#d009be934c04ee04b8e5a1cb5af08efd">00093</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> fd0, <a class="code" href="timers__unix_2timerscfg_8h.html#07c1b78efc83716fac9e31b9862f7e60">TASK_HANDLE</a> *ReceiveLoop_task, <span class="keywordtype">void</span>* ReceiveLoop_task_proc) |
|
113 <a name="l00094"></a>00094 { |
|
114 <a name="l00095"></a>00095 <span class="keywordtype">int</span> ret; |
|
115 <a name="l00096"></a>00096 <span class="keyword">static</span> <span class="keywordtype">int</span> <span class="keywordtype">id</span> = 0; |
|
116 <a name="l00097"></a>00097 <span class="keywordtype">char</span> taskname[32]; |
|
117 <a name="l00098"></a>00098 snprintf(taskname, <span class="keyword">sizeof</span>(taskname), <span class="stringliteral">"canloop%d-%d"</span>, <span class="keywordtype">id</span>, getpid()); |
|
118 <a name="l00099"></a>00099 <span class="keywordtype">id</span>++; |
|
119 <a name="l00100"></a>00100 |
|
120 <a name="l00101"></a>00101 mlockall(MCL_CURRENT | MCL_FUTURE); |
|
121 <a name="l00102"></a>00102 |
|
122 <a name="l00103"></a>00103 <span class="comment">//create timerloop_task</span> |
|
123 <a name="l00104"></a>00104 ret = rt_task_create(ReceiveLoop_task,taskname,0,50,0); |
|
124 <a name="l00105"></a>00105 <span class="keywordflow">if</span> (ret) { |
|
125 <a name="l00106"></a>00106 printf(<span class="stringliteral">"Failed to create ReceiveLoop_task number %d, code %d\n"</span>, <span class="keywordtype">id</span>, errno); |
|
126 <a name="l00107"></a>00107 <span class="keywordflow">return</span>; |
|
127 <a name="l00108"></a>00108 } |
|
128 <a name="l00109"></a>00109 <span class="comment">// start timerloop_task</span> |
|
129 <a name="l00110"></a>00110 ret = rt_task_start(ReceiveLoop_task,ReceiveLoop_task_proc,(<span class="keywordtype">void</span>*)fd0); |
|
130 <a name="l00111"></a>00111 <span class="keywordflow">if</span> (ret) { |
|
131 <a name="l00112"></a>00112 printf(<span class="stringliteral">"Failed to start ReceiveLoop_task number %d, code %d\n"</span>, <span class="keywordtype">id</span>, errno); |
|
132 <a name="l00113"></a>00113 <span class="keywordflow">return</span>; |
|
133 <a name="l00114"></a>00114 } |
|
134 <a name="l00115"></a>00115 } |
|
135 <a name="l00116"></a>00116 |
|
136 <a name="l00117"></a><a class="code" href="timers__xeno_8c.html#aee2aa5ebcc60c3f2231f59c1c7beab0">00117</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) |
|
137 <a name="l00118"></a>00118 { |
|
138 <a name="l00119"></a>00119 rt_task_delete(Thread); |
|
139 <a name="l00120"></a>00120 } |
|
140 <a name="l00121"></a>00121 |
|
141 <a name="l00122"></a><a class="code" href="timers__xeno_8c.html#b8d05dee70f04b5c5190ab00e84da106">00122</a> <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) |
|
142 <a name="l00123"></a>00123 { |
|
143 <a name="l00124"></a>00124 <a class="code" href="timers__xeno_8c.html#e2985cf19e9415625d21f0f79b580fd0">last_alarm_set</a> = (value == <a class="code" href="hcs12_2applicfg_8h.html#35b2fd1a5f6b88bf3842ba3663e6f85e">TIMEVAL_MAX</a>) ? <a class="code" href="hcs12_2applicfg_8h.html#35b2fd1a5f6b88bf3842ba3663e6f85e">TIMEVAL_MAX</a> : <a class="code" href="timers__xeno_8c.html#b64940b870e06e40ac13634a9e2b9ac2">last_time_read</a> + value; |
|
144 <a name="l00125"></a>00125 rt_task_unblock(&<a class="code" href="timers__xeno_8c.html#3921261b6599c37eb3830a799d05f32e">timerloop_task</a>); |
|
145 <a name="l00126"></a>00126 } |
|
146 <a name="l00127"></a>00127 |
|
147 <a name="l00128"></a><a class="code" href="timers__xeno_8c.html#4dccc204d52176bd547ab34d6858f5ba">00128</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>) |
|
148 <a name="l00129"></a>00129 { |
|
149 <a name="l00130"></a>00130 <a class="code" href="timers__xeno_8c.html#b64940b870e06e40ac13634a9e2b9ac2">last_time_read</a> = rt_timer_ticks2ns(rt_timer_read()); |
|
150 <a name="l00131"></a>00131 <span class="keywordflow">return</span> <a class="code" href="timers__xeno_8c.html#b64940b870e06e40ac13634a9e2b9ac2">last_time_read</a> - <a class="code" href="timers__xeno_8c.html#faf0ed3ab58750ccf1a09c52f7304cc3">last_occured_alarm</a>; |
|
151 <a name="l00132"></a>00132 } |
|
152 </pre></div><hr size="1"><address style="align: right;"><small>Generated on Mon Jun 4 16:29:06 2007 for CanFestival by |
|
153 <a href="http://www.doxygen.org/index.html"> |
|
154 <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.1 </small></address> |
|
155 </body> |
|
156 </html> |
|