|
1 /* |
|
2 * osapi.cpp |
|
3 * |
|
4 * Copyright(c) 1998 - 2010 Texas Instruments. All rights reserved. |
|
5 * All rights reserved. |
|
6 * |
|
7 * This program and the accompanying materials are made available under the |
|
8 * terms of the Eclipse Public License v1.0 or BSD License which accompanies |
|
9 * this distribution. The Eclipse Public License is available at |
|
10 * http://www.eclipse.org/legal/epl-v10.html and the BSD License is as below. |
|
11 * |
|
12 * Redistribution and use in source and binary forms, with or without |
|
13 * modification, are permitted provided that the following conditions |
|
14 * are met: |
|
15 * |
|
16 * * Redistributions of source code must retain the above copyright |
|
17 * notice, this list of conditions and the following disclaimer. |
|
18 * * Redistributions in binary form must reproduce the above copyright |
|
19 * notice, this list of conditions and the following disclaimer in |
|
20 * the documentation and/or other materials provided with the |
|
21 * distribution. |
|
22 * * Neither the name Texas Instruments nor the names of its |
|
23 * contributors may be used to endorse or promote products derived |
|
24 * from this software without specific prior written permission. |
|
25 * |
|
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
29 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
30 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
31 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
32 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
33 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
34 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
35 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
36 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
37 */ |
|
38 |
|
39 |
|
40 |
|
41 /** \file osapi.cpp |
|
42 * \brief Interface between the generic os abstration to symbian OSA |
|
43 * |
|
44 * \see |
|
45 */ |
|
46 |
|
47 #include "TIWhaDef.h" |
|
48 #include "timerclient.h" |
|
49 |
|
50 |
|
51 extern "C" |
|
52 { |
|
53 #include "tidef.h" |
|
54 #include "cdebugoutput.h" |
|
55 #include "osApi.h" |
|
56 #define __FILE_ID__ FILE_ID_138 |
|
57 |
|
58 /**************************************************************************************** |
|
59 * OS Print API * |
|
60 ****************************************************************************************/ |
|
61 |
|
62 /** |
|
63 * \fn os_setDebugMode |
|
64 * \brief not in use |
|
65 * |
|
66 * \note |
|
67 * \param |
|
68 * \return |
|
69 * \sa |
|
70 */ |
|
71 void os_setDebugMode (TI_BOOL enable) |
|
72 { |
|
73 |
|
74 } |
|
75 |
|
76 |
|
77 /** |
|
78 * \fn os_printf |
|
79 * \brief Print formatted output |
|
80 * |
|
81 * \note |
|
82 * \param format - Specifies the string, to be printed |
|
83 * \return |
|
84 * \sa |
|
85 */ |
|
86 #include <libc/stdarg.h> |
|
87 extern "C" {void wlanPrintf(const char* const pPrefix, const char* const pFormat, va_list args);} |
|
88 void os_printf (const char *format ,...) |
|
89 { |
|
90 #if _DEBUG |
|
91 VA_LIST args; |
|
92 VA_START(args, format); |
|
93 wlanPrintf("TI_TRC: ", format, args); |
|
94 VA_END(args); |
|
95 #endif |
|
96 } |
|
97 |
|
98 /** |
|
99 * \fn os_InterruptServiced |
|
100 * \brief inform that interrupt was serviced (i.e. enable WLAN IRQ in LEVEL_IRQ) |
|
101 * |
|
102 * \param OsContext |
|
103 * \return |
|
104 * \sa |
|
105 */ |
|
106 void os_InterruptServiced (TI_HANDLE OsContext) |
|
107 { |
|
108 /* Mark that interrupt was serviced */ |
|
109 GET_HPA(OsContext)->InterruptServiced(); |
|
110 } |
|
111 |
|
112 /**************************************************************************************** |
|
113 * OS Memory API * |
|
114 ****************************************************************************************/ |
|
115 |
|
116 /** |
|
117 * \fn os_memoryAlloc |
|
118 * \brief Allocates resident (nonpaged) system-space memory |
|
119 * |
|
120 * \note |
|
121 * \param OsContext - os context. |
|
122 * \param Size - Specifies the size, in bytes, to be allocated |
|
123 * \return Pointer to the allocated memory. |
|
124 NULL if there is insufficient memory available |
|
125 * \sa |
|
126 */ |
|
127 void *os_memoryAlloc (TI_HANDLE OsContext,TI_UINT32 Size,TI_BOOL MemoryType) |
|
128 { |
|
129 #if defined DMA_CAPABLE_BUFFERS |
|
130 MWlanOsa::TOsaMemoryType iOsMemType; |
|
131 if (MemoryType == MemoryNormal) |
|
132 { |
|
133 iOsMemType = MWlanOsa::ENormalMemory; |
|
134 } |
|
135 else |
|
136 { |
|
137 iOsMemType = MWlanOsa::EInterconnectMemory; |
|
138 } |
|
139 return GET_OSA(OsContext)->Alloc(iOsMemType,Size,0); |
|
140 #else |
|
141 MWlanOsa::TOsaMemoryType iOsMemType = MWlanOsa::ENormalMemory; |
|
142 return GET_OSA(OsContext)->Alloc(iOsMemType,Size,0); |
|
143 #endif |
|
144 |
|
145 } |
|
146 |
|
147 |
|
148 /** |
|
149 * \fn os_memorySet |
|
150 * \brief This function fills a block of memory with given value |
|
151 * |
|
152 * \note |
|
153 * \param OsContext - os context. |
|
154 * \param pMemPtr - Specifies the base address of a block of memory |
|
155 * \param Value - Specifies the value to set |
|
156 * \param Length - Specifies the size, in bytes, to copy. |
|
157 * \return |
|
158 * \sa |
|
159 */ |
|
160 void os_memorySet (TI_HANDLE OsContext, void *pMemPtr, TI_INT32 Value, TI_UINT32 Length) |
|
161 { |
|
162 MWlanOsa::MemSet(pMemPtr,Value,Length); |
|
163 } |
|
164 |
|
165 |
|
166 /** |
|
167 * \fn os_memoryZero |
|
168 * \brief This function fills a block of memory with 0s. |
|
169 * |
|
170 * \note |
|
171 * \param OsContext - os context. |
|
172 * \param pMemPtr - Specifies the base address of a block of memory |
|
173 * \param Length - Specifies how many bytes to fill with 0s. |
|
174 * \return |
|
175 * \sa |
|
176 */ |
|
177 void os_memoryZero (TI_HANDLE OsContext, void *pMemPtr, TI_UINT32 Length) |
|
178 { |
|
179 MWlanOsa::MemClr(pMemPtr,Length); |
|
180 } |
|
181 |
|
182 |
|
183 /** |
|
184 * \fn os_memoryCopy |
|
185 * \brief This function copies a specified number of bytes from one caller-supplied |
|
186 location to another. |
|
187 * |
|
188 * \note |
|
189 * \param OsContext - os context. |
|
190 * \param pDstPtr - Destination buffer |
|
191 * \param pSrcPtr - Source buffer |
|
192 * \param Size - Specifies the size, in bytes, to copy. |
|
193 * \return |
|
194 * \sa |
|
195 */ |
|
196 void os_memoryCopy (TI_HANDLE pOsContext, void *pDestination, void *pSource, TI_UINT32 Size) |
|
197 { |
|
198 MWlanOsa::MemCpy(pDestination,(const void *)pSource,Size); |
|
199 } |
|
200 |
|
201 |
|
202 /** |
|
203 * \fn os_memoryFree |
|
204 * \brief This function releases a block of memory previously allocated with the |
|
205 os_memoryAlloc function. |
|
206 * |
|
207 * \note |
|
208 * \param OsContext - os context. |
|
209 * \param pMemPtr - Pointer to the base virtual address of the allocated memory. |
|
210 This address was returned by the os_memoryAlloc function. |
|
211 * \param Size - Specifies the size, in bytes, of the memory block to be released. |
|
212 This parameter must be identical to the Length that was passed to |
|
213 os_memoryAlloc. |
|
214 * \return |
|
215 * \sa |
|
216 */ |
|
217 void os_memoryFree (TI_HANDLE pOsContext, void *pMemPtr, TI_UINT32 Size) |
|
218 { |
|
219 GET_OSA(pOsContext)->Free(pMemPtr); |
|
220 } |
|
221 |
|
222 /** |
|
223 * \fn os_memoryCompare |
|
224 * |
|
225 * \note |
|
226 * \return |
|
227 * \sa |
|
228 */ |
|
229 TI_INT32 os_memoryCompare (TI_HANDLE OsContext, TI_UINT8* Buf1, TI_UINT8* Buf2, TI_INT32 Count) |
|
230 { |
|
231 return (TI_INT32)(MWlanOsa::MemCmp( Buf1, Buf2, Count )); |
|
232 |
|
233 } |
|
234 |
|
235 |
|
236 /** |
|
237 * \fn os_timeStampMs |
|
238 * \brief This function returns the number of milliseconds that have elapsed since |
|
239 the system was booted. |
|
240 * |
|
241 * \note |
|
242 * \param OsContext - os context. |
|
243 * \return |
|
244 * \sa |
|
245 */ |
|
246 TI_INT32 os_timeStampMs (TI_HANDLE OsContext) |
|
247 { |
|
248 TInt64 iTime; |
|
249 |
|
250 iTime = MWlanOsa::Time() / 1000; |
|
251 |
|
252 /* return only LSB */ |
|
253 return ((TUint32*)&iTime)[0]; |
|
254 } |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 /** |
|
260 * \fn os_StalluSec |
|
261 * \brief This function make delay in microseconds. |
|
262 * |
|
263 * \note |
|
264 * \param OsContext - os context. |
|
265 * \param uSec - delay time in microseconds |
|
266 * \return |
|
267 * \sa |
|
268 */ |
|
269 void os_StalluSec (TI_HANDLE OsContext, TI_UINT32 uSec) |
|
270 { |
|
271 MWlanOsa::BusyWait(uSec); |
|
272 } |
|
273 |
|
274 /***************************************************************************************** |
|
275 * Timer functions * |
|
276 *****************************************************************************************/ |
|
277 |
|
278 /** |
|
279 * \fn os_timerCreate |
|
280 * \brief Create timer client |
|
281 * |
|
282 * \param OsContext - os context. |
|
283 * \param pRoutine - CB function |
|
284 * \param hFuncHandle - CB handle |
|
285 * |
|
286 * \note |
|
287 * \return Timer client handle |
|
288 * \sa |
|
289 */ |
|
290 TI_HANDLE os_timerCreate (TI_HANDLE OsContext, fTimerFunction pRoutine, TI_HANDLE hFuncHandle) |
|
291 { |
|
292 return (TI_HANDLE)(new TimerClient (OsContext, pRoutine, hFuncHandle)); |
|
293 |
|
294 } |
|
295 |
|
296 /** |
|
297 * \fn os_timerDestroy |
|
298 * \brief Destroy timer client |
|
299 * |
|
300 * \param OsContext - os context. |
|
301 * \param TimerHandle - timer client handle |
|
302 * \note |
|
303 * \return |
|
304 * \sa |
|
305 */ |
|
306 void os_timerDestroy (TI_HANDLE OsContext, TI_HANDLE TimerHandle) |
|
307 { |
|
308 if (TimerHandle) |
|
309 { |
|
310 delete (TimerClient *)TimerHandle; |
|
311 } |
|
312 } |
|
313 |
|
314 /** |
|
315 * \fn os_timerStart |
|
316 * \brief start timer |
|
317 * |
|
318 * \param OsContext - os context. |
|
319 * \param TimerHandle - timer client handle |
|
320 * \param DelayMs |
|
321 * |
|
322 * \note |
|
323 * \return |
|
324 * \sa |
|
325 */ |
|
326 void os_timerStart (TI_HANDLE OsContext, TI_HANDLE TimerHandle, TI_UINT32 DelayMs) |
|
327 { |
|
328 ((TimerClient *)TimerHandle)->Start(DelayMs); |
|
329 } |
|
330 |
|
331 /** |
|
332 * \fn os_timerStop |
|
333 * \brief stop timer |
|
334 * |
|
335 * \param OsContext - os context. |
|
336 * \param TimerHandle - timer client handle |
|
337 * \note |
|
338 * \return |
|
339 * \sa |
|
340 */ |
|
341 void os_timerStop (TI_HANDLE OsContext, TI_HANDLE TimerHandle) |
|
342 { |
|
343 ((TimerClient *)TimerHandle)->Stop(); |
|
344 } |
|
345 |
|
346 |
|
347 /**************************************************************************************** |
|
348 * Protection services API * |
|
349 ****************************************************************************************/ |
|
350 |
|
351 /** |
|
352 * \fn os_protectCreate |
|
353 * \brief |
|
354 * |
|
355 * \note |
|
356 * \param OsContext - os context. |
|
357 * \return A handle of the created mutex/spinlock. |
|
358 TI_HANDLE_INVALID if there is insufficient memory available or problems |
|
359 initializing the mutex |
|
360 * \sa |
|
361 */ |
|
362 TI_HANDLE os_protectCreate (TI_HANDLE OsContext) { return TI_OK;} |
|
363 |
|
364 |
|
365 /** |
|
366 * \fn os_protectDestroy |
|
367 * \brief the WVSS dose not use protection |
|
368 * |
|
369 * \note |
|
370 * \param OsContext - os context. |
|
371 * \return |
|
372 * \sa |
|
373 */ |
|
374 void os_protectDestroy (TI_HANDLE OsContext, TI_HANDLE ProtectContext) {} |
|
375 |
|
376 } //extern "C" |
|
377 |