os_api.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. /******************************************************************************
  2. ** File Name: os_api.h *
  3. ** Author: Xueliang.Wang *
  4. ** DATE: 11/14/2002 *
  5. ** Copyright: 2002 Spreatrum, Incoporated. All Rights Reserved. *
  6. ** Description: This file defines the basic Application Interface (API) *
  7. ** to the high-performance RTOS. *
  8. ** All service prototypes for user and some data structure *
  9. ** definitions are defined in this file. *
  10. ** Basic data type definitions is contained in sci_types.h *
  11. ******************************************************************************
  12. ******************************************************************************
  13. ** Edit History *
  14. ** ------------------------------------------------------------------------- *
  15. ** DATE NAME DESCRIPTION *
  16. ** 11/14/2002 Xueliang.Wang Create. *
  17. ** 09/12/2003 Zhemin.Lin Modify according to CR:MS00004678 *
  18. ** 10/11/2004 Richard.Yang Add Trace interface and server interface *
  19. ** 11/28/2005 Shujing.Dong Modify according to CR:MS00035616 *
  20. ******************************************************************************/
  21. #ifndef _OS_API_H
  22. #define _OS_API_H
  23. /**---------------------------------------------------------------------------*
  24. ** Dependencies *
  25. **---------------------------------------------------------------------------*/
  26. // Basic data types.
  27. #include "sci_types.h"
  28. #include "dal_time.h"
  29. /**---------------------------------------------------------------------------*
  30. ** Compiler Flag *
  31. **---------------------------------------------------------------------------*/
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. /**---------------------------------------------------------------------------*
  36. ** Constant Variables *
  37. **---------------------------------------------------------------------------*/
  38. //---------------------------------------------
  39. // API return values.
  40. //---------------------------------------------
  41. //---------------------------------------------
  42. // API input parameters.
  43. //---------------------------------------------
  44. // Auto start option on timer.
  45. #define SCI_NO_ACTIVATE 0
  46. #define SCI_AUTO_ACTIVATE 1
  47. //priority inherit mode for mutex
  48. #define SCI_NO_INHERIT 0
  49. #define SCI_INHERIT 1
  50. //---------------------------------------------
  51. // General constants.
  52. //---------------------------------------------
  53. //---------------------------------------------
  54. // Type define.
  55. //---------------------------------------------
  56. typedef osiMutex_t *SCI_MUTEX_PTR;
  57. typedef osiSemaphore_t *SCI_SEMAPHORE_PTR;
  58. // The prototype of C funtion which execute when timer expires.
  59. typedef void (*TIMER_FUN)(uint32);
  60. // Signal head structure.
  61. // Signal vars used when send signals from one task to anther.
  62. // The pointer is a structure whose head is SIGNAL_VARS.
  63. #define _SIGNAL_VARS \
  64. uint16 SignalCode; \
  65. uint16 SignalSize; \
  66. xSignalHeader Pre; \
  67. xSignalHeader Suc; \
  68. BLOCK_ID Sender;
  69. #ifndef _BSSIM
  70. #define SIGNAL_VARS \
  71. _SIGNAL_VARS
  72. #else
  73. #define SIGNAL_VARS \
  74. _SIGNAL_VARS \
  75. void *SigP;
  76. #endif // End of _BSSIM
  77. // Signal head structure.
  78. typedef struct xSignalHeaderStruct *xSignalHeader;
  79. typedef struct xSignalHeaderStruct
  80. {
  81. SIGNAL_VARS
  82. } xSignalHeaderRec;
  83. /*================App Memory Pool Defined==================*/
  84. /********************Defined RTOS Tick Time ***************************************/
  85. typedef struct SCI_TICK_TIME_Tag
  86. {
  87. uint32 milliseconds;
  88. uint32 second;
  89. } SCI_TICK_TIME_T;
  90. /**---------------------------------------------------------------------------*
  91. ** MACROES:
  92. **---------------------------------------------------------------------------*/
  93. /**---------------------------------------------------------------------------*
  94. ** Function Prototypes *
  95. **---------------------------------------------------------------------------*/
  96. /**---------------------------------------------------------------------------*
  97. ** THREAD
  98. **---------------------------------------------------------------------------*/
  99. /*****************************************************************************/
  100. // Description: The function creates a dynamic thread.
  101. // The control block, stack and queue used in the thread to
  102. // be created are alloced in this function.
  103. // Global resource dependence:
  104. // Author: Richard.Yang
  105. // Note:
  106. /*****************************************************************************/
  107. /**---------------------------------------------------------------------------*
  108. ** THREAD
  109. **---------------------------------------------------------------------------*/
  110. /*****************************************************************************/
  111. // Description: The function creates a dynamic thread.
  112. // The control block, stack and queue used in the thread to
  113. // be created are alloced in this function.
  114. // Global resource dependence:
  115. // Author:
  116. // Note:
  117. /*****************************************************************************/
  118. PUBLIC BLOCK_ID SCI_CreateThread( // If successful, returns the thread ID
  119. // of the new created thread,
  120. // else returns SCI_INVALID_BLOCK_ID
  121. const char *thread_name, // Name string of the thread
  122. const char *queue_name, // Queue name string of the thread
  123. void (*entry)(uint32, void *), // Entry function of the thread
  124. uint32 argc, // First parameter for entry function,
  125. void *argv, // Second parameter for entry function,
  126. uint32 stack_size, // Size of the thread stack in bytes
  127. uint32 queue_num, // Number of messages which can be enqueued
  128. uint32 priority, // Prority of the thread.
  129. uint32 preempt, // Indicates if the thread is preemptable.
  130. uint32 auto_start // Specifies whether the thread starts
  131. // immediately or stays in a pure suspended
  132. // state. Legal options are SCI_AUTO_START
  133. // and SCI_DONT_START.
  134. );
  135. /*****************************************************************************/
  136. // Description: The function terminates a specified thread.
  137. // Global resource dependence:
  138. // Author:
  139. // Note:
  140. /*****************************************************************************/
  141. PUBLIC uint32 SCI_TerminateThread( // If terminate successful, return
  142. // SCI_SUCCESS; else return SCI_ERROR.
  143. BLOCK_ID thread_id // ID of the thread to be terminated.
  144. );
  145. /*****************************************************************************/
  146. // Description: The function deletes a thread created before.
  147. // Global resource dependence:
  148. // Author:
  149. // Note:
  150. /*****************************************************************************/
  151. PUBLIC uint32 SCI_DeleteThread( // If delete successful,return SCI_SUCCESS;
  152. // else return SCI_ERROR.
  153. BLOCK_ID thread_id // ID of the thread to be deleted.
  154. );
  155. /**---------------------------------------------------------------------------*
  156. ** TIMER
  157. **---------------------------------------------------------------------------*/
  158. /*****************************************************************************/
  159. // Description: The function create a timer with call back function.
  160. // Global resource dependence:
  161. // Author:
  162. // Note:
  163. /*****************************************************************************/
  164. PUBLIC SCI_TIMER_PTR SCI_CreateTimer( // If successful, returns pointer to
  165. // the control block of the timer,
  166. // else return SCI_NULL.
  167. const char *timer_name, // Name string of the timer
  168. TIMER_FUN timer_fun, // Timer callback function
  169. uint32 input, // Input value for timer callback function
  170. uint32 timer_expire, // Specifies the timer expire value in
  171. // milliseconds.
  172. uint32 auto_activate // Option to check if auto active the timer
  173. // after create.
  174. // SCI_NO_ACTIVATE Don't auto active
  175. // SCI_AUTO_ACTIVATE Auto active
  176. );
  177. /*****************************************************************************/
  178. // Description: The function create a period timer with call back function.
  179. // Global resource dependence:
  180. // Author:
  181. // Note:
  182. /*****************************************************************************/
  183. PUBLIC SCI_TIMER_PTR SCI_CreatePeriodTimer( // If successful, returns pointer to
  184. // the control block of the timer,
  185. // else return SCI_NULL.
  186. const char *timer_name, // Name string of the timer
  187. TIMER_FUN timer_fun, // Timer callback function
  188. uint32 input, // Input value for timer callback function
  189. uint32 timer_expire, // Specifies the timer expire value in
  190. // milliseconds.
  191. uint32 auto_activate // Option to check if auto active the timer
  192. // after create.
  193. );
  194. /*****************************************************************************/
  195. // Description: The function deletes a timer created before.
  196. // Global resource dependence:
  197. // Author:
  198. // Note:
  199. /*****************************************************************************/
  200. PUBLIC uint32 SCI_DeleteTimer( // If successful, returns SCI_SUCCESS,
  201. // else return SCI_ERROR
  202. SCI_TIMER_PTR timer_ptr // Pointer to a previously created application
  203. // timer.
  204. );
  205. /*****************************************************************************/
  206. // Description: The function changed timer's callback function and
  207. // expire time.
  208. // Global resource dependence:
  209. // Author:
  210. // Note: User should deactive the timer before call this function
  211. // to change it.
  212. /*****************************************************************************/
  213. PUBLIC uint32 SCI_ChangeTimer( // If successful, returns SCI_SUCCESS,
  214. // else return SCI_ERROR
  215. SCI_TIMER_PTR timer_ptr, // Timer control block
  216. TIMER_FUN timer_fun, // Timer callback function
  217. uint32 timer_expire // Specifies the expire value in milliseconds.
  218. );
  219. /*****************************************************************************/
  220. // Description: The function checks if the timer is still active.
  221. // Global resource dependence:
  222. // Author:
  223. // Note:
  224. /*****************************************************************************/
  225. PUBLIC BOOLEAN SCI_IsTimerActive( // If it is active, returns SCI_TRUE,
  226. // else return SCI_FALSE
  227. SCI_TIMER_PTR timer_ptr // Pointer to a previously created
  228. // application timer.
  229. );
  230. /*****************************************************************************/
  231. // Description: The function activate a timer created before.
  232. // Global resource dependence:
  233. // Author:
  234. // Note:
  235. /*****************************************************************************/
  236. PUBLIC uint32 SCI_ActiveTimer( // If active successful, returns SCI_SUCCESS,
  237. // else return SCI_ERROR
  238. SCI_TIMER_PTR timer_ptr // Pointer to a previously created application
  239. // timer.
  240. );
  241. /*****************************************************************************/
  242. // Description: The function deactive a timer created before.
  243. // Global resource dependence:
  244. // Author:
  245. // Note:
  246. /*****************************************************************************/
  247. PUBLIC uint32 SCI_DeactiveTimer( // If successful, returns SCI_SUCCESS,
  248. // else return SCI_ERROR
  249. SCI_TIMER_PTR timer_ptr // Pointer to a previously created
  250. // application timer.
  251. );
  252. /**---------------------------------------------------------------------------*
  253. ** Mutex
  254. **---------------------------------------------------------------------------*/
  255. /*****************************************************************************/
  256. // Description: The function is used to create a mutex for inter-thread
  257. // mutual exclusion for resource protection.
  258. // Global resource dependence:
  259. // Author:
  260. // Note:
  261. /*****************************************************************************/
  262. SCI_MUTEX_PTR SCI_CreateMutex( //if successful, return the muxtex pointer,
  263. //else return SCI_NULL
  264. const char *name_ptr, //mutex name
  265. uint32 priority_inherit //inherit option, SCI_INHERIT or SCI_NO_INHERIT
  266. );
  267. /*****************************************************************************/
  268. // Description: The function is used to destroy a mutex.
  269. // Global resource dependence:
  270. // Author:
  271. // Note:
  272. /*****************************************************************************/
  273. uint32 SCI_DeleteMutex( //if successful, return SCI_SUCCESS,
  274. //else return SCI_ERROR
  275. SCI_MUTEX_PTR mutex_ptr //mutex pointer
  276. );
  277. /*****************************************************************************/
  278. // Description: The function is used to obtain exclusive ownership of the
  279. // specified mutex.
  280. // Global resource dependence:
  281. // Author:
  282. // Note:
  283. /*****************************************************************************/
  284. uint32 SCI_GetMutex( //if successful, return SCI_SUCCESS,
  285. //else return SCI_ERROR
  286. SCI_MUTEX_PTR mutex_ptr, //mutex pointer
  287. uint32 wait_option //wait option: SCI_WAIT_FOREVER, SCI_NO_WAIT,
  288. // 1~0x0FFFFFFFE wait time(ms)
  289. );
  290. /*****************************************************************************/
  291. // Description: The function is used to renounce ownership of a mutex
  292. // Global resource dependence:
  293. // Author:
  294. // Note:
  295. /*****************************************************************************/
  296. uint32 SCI_PutMutex( //if successful, return SCI_SUCCESS,
  297. //else return SCI_ERROR
  298. SCI_MUTEX_PTR mutex_ptr //mutex pointer
  299. );
  300. /**---------------------------------------------------------------------------*
  301. ** Semaphore
  302. **---------------------------------------------------------------------------*/
  303. /*****************************************************************************/
  304. // Description: The function is used to create a counting semaphore.
  305. // Global resource dependence:
  306. // Author:
  307. // Note:
  308. /*****************************************************************************/
  309. SCI_SEMAPHORE_PTR SCI_CreateSemaphore( //if successful, return semaphore
  310. //pointer, else return SCI_NULL
  311. const char *name_ptr, //name of the semaphore
  312. uint32 initial_count //initial value of semaphore counter
  313. );
  314. /*****************************************************************************/
  315. // Description: The function is used to puts an instance into the specified
  316. // counting semaphore, which in reality increments the counting
  317. // semaphore by one.
  318. // Global resource dependence:
  319. // Author:
  320. // Note:
  321. /*****************************************************************************/
  322. uint32 SCI_PutSemaphore( //if successful return SCI_SUCCESS,
  323. //else return SCI_ERROR
  324. SCI_SEMAPHORE_PTR sem_ptr //semaphore pointer
  325. );
  326. /*****************************************************************************/
  327. // Description: The function is used to retrieve an instance from the specified
  328. // counting semaphore. As a result, the specified semaphore's count
  329. // is decreased by one.
  330. // Global resource dependence:
  331. // Author:
  332. // Note:
  333. /*****************************************************************************/
  334. uint32 SCI_GetSemaphore( //if successful return SCI_SUCCESS,
  335. //else return SCI_ERROR
  336. SCI_SEMAPHORE_PTR sem_ptr, //semaphore pointer
  337. uint32 wait_option //wait option: SCI_WAIT_FOREVER, SCI_NO_WAIT,
  338. // 1~0x0FFFFFFFE wait time(ms)
  339. );
  340. /**---------------------------------------------------------------------------*
  341. ** MESSAGE
  342. **---------------------------------------------------------------------------*/
  343. /*****************************************************************************/
  344. // Description: The function gets a signal from a thread.
  345. // If no signal, function wait forever.
  346. // Global resource dependence:
  347. // Author:
  348. // Note:
  349. /*****************************************************************************/
  350. PUBLIC xSignalHeader SCI_GetSignal( // Return received signal.
  351. BLOCK_ID thread_id // ID of the thread which receives signal
  352. );
  353. /*****************************************************************************/
  354. // Description: Send a signal.
  355. // Global resource dependence:
  356. // Author:
  357. // Parameter: _SIG_PTR Pointer to the signal which will be sent
  358. // _RECEIVER ID of thread whihc receives this signal.
  359. // Return: None.
  360. // Note:
  361. /*****************************************************************************/
  362. PUBLIC uint32 SCI_SendSignal(
  363. xSignalHeader sig_ptr, // Signal pointer to be sent
  364. BLOCK_ID revicer // Dest thread ID
  365. );
  366. /*****************************************************************************/
  367. // Description: The function create a signal to send.
  368. // Global resource dependence:
  369. // Author:
  370. // Note:
  371. /*****************************************************************************/
  372. PUBLIC void SCI_CreateSignal(
  373. xSignalHeader sig_ptr,
  374. uint32 sig_code,
  375. uint32 sig_size,
  376. BLOCK_ID sender);
  377. /*****************************************************************************/
  378. // Description: This function retrieves the number of milliseconds that
  379. // have elapsed since the system was started.
  380. // Global resource dependence:
  381. // Author:
  382. // Note: The elapsed time is stored as a uint32 value. Therefore,
  383. // the time will wrap around to zero if the system is run
  384. // continuously for 49.7 days.
  385. /*****************************************************************************/
  386. PUBLIC uint32 SCI_GetTickCount(void);
  387. /*****************************************************************************/
  388. // Description : Get system time (hour/min/sec)
  389. // Global resource dependence :
  390. // Author:
  391. // Note:
  392. /*****************************************************************************/
  393. PUBLIC ERR_TM_E TM_GetSysTime( // If successful, return ERR_TM_NONE;
  394. // else return ERR_TM_PNULL.
  395. SCI_TIME_T *time_ptr // Save time value gotten.
  396. );
  397. void TM_SendTestPointRequest(uint32 param1, BLOCK_ID param2);
  398. /**---------------------------------------------------------------------------*
  399. ** Compiler Flag *
  400. **---------------------------------------------------------------------------*/
  401. #ifdef __cplusplus
  402. }
  403. #endif
  404. #endif // End of _OS_API_H