wm_osal_rtos.c 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394
  1. /*****************************************************************************
  2. *
  3. * File Name : wm_osal_rtos.h
  4. *
  5. * Description: rtos include Module
  6. *
  7. * Copyright (c) 2014 Winner Microelectronics Co., Ltd.
  8. * All rights reserved.
  9. *
  10. * Author : dave
  11. *
  12. * Date : 2014-8-27
  13. *****************************************************************************/
  14. #ifndef WM_OS_RTOS_H
  15. #define WM_OS_RTOS_H
  16. #include "wm_config.h"
  17. #if TLS_OS_FREERTOS
  18. #include <assert.h>
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include "wm_type_def.h"
  22. //#include "wm_irq.h"
  23. #include "FreeRTOS.h"
  24. #include "task.h"
  25. #include "rtosqueue.h"
  26. #include "semphr.h"
  27. #include "rtostimers.h"
  28. #include "FreeRTOSConfig.h"
  29. #include "wm_osal.h"
  30. #include "wm_mem.h"
  31. u8 tls_get_isr_count(void);
  32. #ifndef CONFIG_KERNEL_NONE
  33. /*
  34. *********************************************************************************************************
  35. * CREATE A TASK (Extended Version)
  36. *
  37. * Description: This function is used to have uC/OS-II manage the execution of a task. Tasks can either
  38. * be created prior to the start of multitasking or by a running task. A task cannot be
  39. * created by an ISR.
  40. *
  41. * Arguments : task is a pointer to the task'
  42. *
  43. * name is the task's name
  44. *
  45. * entry is the task's entry function
  46. *
  47. * param is a pointer to an optional data area which can be used to pass parameters to
  48. * the task when the task first executes. Where the task is concerned it thinks
  49. * it was invoked and passed the argument 'param' as follows:
  50. *
  51. * void Task (void *param)
  52. * {
  53. * for (;;) {
  54. * Task code;
  55. * }
  56. * }
  57. *
  58. * stk_start is a pointer to the task's bottom of stack.
  59. *
  60. * stk_size is the size of the stack in number of elements. If OS_STK is set to u8,
  61. * 'stk_size' corresponds to the number of bytes available. If OS_STK is set to
  62. * INT16U, 'stk_size' contains the number of 16-bit entries available. Finally, if
  63. * OS_STK is set to INT32U, 'stk_size' contains the number of 32-bit entries
  64. * available on the stack.
  65. *
  66. * prio is the task's priority. A unique priority MUST be assigned to each task and the
  67. * lower the number, the higher the priority.
  68. *
  69. * flag contains additional information about the behavior of the task.
  70. *
  71. * Returns : TLS_OS_SUCCESS if the function was successful.
  72. * TLS_OS_ERROR
  73. *********************************************************************************************************
  74. */
  75. tls_os_status_t tls_os_task_create(tls_os_task_t *task,
  76. const char* name,
  77. void (*entry)(void* param),
  78. void* param,
  79. u8 *stk_start,
  80. u32 stk_size,
  81. u32 prio,
  82. u32 flag)
  83. {
  84. u8 error;
  85. tls_os_status_t os_status;
  86. // if (((u32)stk_start >= TASK_STACK_USING_MEM_UPPER_RANGE)
  87. // ||(((u32)stk_start + stk_size) >= TASK_STACK_USING_MEM_UPPER_RANGE))
  88. // {
  89. // printf("\nCurrent Stack [0x%8x, 0x%8x) is NOT in VALID STACK range [0x20000000,0x20028000)\n", (u32)stk_start, (u32)(stk_start + stk_size));
  90. // printf("Please refer to APIs' manul and modify task stack position!!!\n");
  91. // return TLS_OS_ERROR;
  92. // }
  93. error = xTaskCreateExt(entry,
  94. (const signed char *)name,
  95. (portSTACK_TYPE *)stk_start,
  96. stk_size/sizeof(u32),
  97. param,
  98. configMAX_PRIORITIES - prio, /*优先级颠倒一下,与ucos优先级顺序相反*/
  99. task );
  100. //printf("configMAX_PRIORITIES - prio:%d\n", configMAX_PRIORITIES - prio);
  101. if (error == pdTRUE)
  102. os_status = TLS_OS_SUCCESS;
  103. else
  104. os_status = TLS_OS_ERROR;
  105. return os_status;
  106. }
  107. /*
  108. *********************************************************************************************************
  109. * DELETE A TASK
  110. *
  111. * Description: This function allows you to delete a task. The calling task can delete itself by
  112. * its own priority number. The deleted task is returned to the dormant state and can be
  113. * re-activated by creating the deleted task again.
  114. *
  115. * Arguments : prio: the task priority
  116. * freefun: function to free resource
  117. *
  118. * Returns : TLS_OS_SUCCESS if the call is successful
  119. * TLS_OS_ERROR
  120. *********************************************************************************************************
  121. */
  122. #if ( INCLUDE_vTaskDelete == 1 )
  123. tls_os_status_t tls_os_task_del(u8 prio,void (*freefun)(void))
  124. {
  125. if (0 == vTaskDeleteByPriority(configMAX_PRIORITIES - prio, freefun)){
  126. return TLS_OS_SUCCESS;
  127. }
  128. return TLS_OS_ERROR;
  129. }
  130. tls_os_status_t tls_os_task_del_by_task_handle(void *handle, void (*freefun)(void))
  131. {
  132. vTaskDeleteByHandle(handle, freefun);
  133. return TLS_OS_SUCCESS;
  134. }
  135. #endif
  136. #if (INCLUDE_vTaskSuspend == 1)
  137. /*
  138. *********************************************************************************************************
  139. * SUSPEND A TASK
  140. *
  141. * Description: This function is called to suspend a task.
  142. *
  143. * Arguments : task is a pointer to the task
  144. *
  145. * Returns : TLS_OS_SUCCESS if the requested task is suspended
  146. *
  147. * Note : You should use this function with great care. If you suspend a task that is waiting for
  148. * an event (i.e. a message, a semaphore, a queue ...) you will prevent this task from
  149. * running when the event arrives.
  150. *********************************************************************************************************
  151. */
  152. tls_os_status_t tls_os_task_suspend(tls_os_task_t *task)
  153. {
  154. vTaskSuspend(task);
  155. return TLS_OS_SUCCESS;
  156. }
  157. /*
  158. **********************************************************************************************************
  159. *
  160. * Returns: get current task handle;
  161. *
  162. **********************************************************************************************************
  163. */
  164. tls_os_task_t tls_os_task_id()
  165. {
  166. return (tls_os_task_t)xTaskGetCurrentTaskHandle();
  167. }
  168. /*
  169. **********************************************************************************************************
  170. *
  171. * Returns: get current task state;
  172. *
  173. **********************************************************************************************************
  174. */
  175. u8 tls_os_task_schedule_state()
  176. {
  177. return (u8)xTaskGetSchedulerState();
  178. }
  179. /*
  180. *********************************************************************************************************
  181. * RESUME A SUSPENDED TASK
  182. *
  183. * Description: This function is called to resume a previously suspended task.
  184. *
  185. * Arguments : task is a pointer to the task
  186. *
  187. * Returns : TLS_OS_SUCCESS if the requested task is resumed
  188. *
  189. *********************************************************************************************************
  190. */
  191. tls_os_status_t tls_os_task_resume(tls_os_task_t *task)
  192. {
  193. vTaskResume(task);
  194. return TLS_OS_SUCCESS;
  195. }
  196. #endif
  197. /*
  198. *********************************************************************************************************
  199. * CREATE A MUTUAL EXCLUSION SEMAPHORE
  200. *
  201. * Description: This function creates a mutual exclusion semaphore.
  202. *
  203. * Arguments : prio is the priority to use when accessing the mutual exclusion semaphore. In
  204. * other words, when the semaphore is acquired and a higher priority task
  205. * attempts to obtain the semaphore then the priority of the task owning the
  206. * semaphore is raised to this priority. It is assumed that you will specify
  207. * a priority that is LOWER in value than ANY of the tasks competing for the
  208. * mutex.
  209. *
  210. * mutex is a pointer to the event control clock (OS_EVENT) associated with the
  211. * created mutex.
  212. *
  213. *
  214. * Returns :TLS_OS_SUCCESS if the call was successful.
  215. * TLS_OS_ERROR
  216. *
  217. * Note(s) : 1) The LEAST significant 8 bits of '.OSEventCnt' are used to hold the priority number
  218. * of the task owning the mutex or 0xFF if no task owns the mutex.
  219. *
  220. * 2) The MOST significant 8 bits of '.OSEventCnt' are used to hold the priority number
  221. * to use to reduce priority inversion.
  222. *********************************************************************************************************
  223. */
  224. #if (1 == configUSE_MUTEXES)
  225. tls_os_status_t tls_os_mutex_create(u8 prio,
  226. tls_os_mutex_t **mutex)
  227. {
  228. tls_os_status_t os_status;
  229. *mutex = xSemaphoreCreateMutex();
  230. if (*mutex != NULL)
  231. os_status = TLS_OS_SUCCESS;
  232. else
  233. os_status = TLS_OS_ERROR;
  234. return os_status;
  235. }
  236. /*
  237. *********************************************************************************************************
  238. * DELETE A MUTEX
  239. *
  240. * Description: This function deletes a mutual exclusion semaphore and readies all tasks pending on the it.
  241. *
  242. * Arguments : mutex is a pointer to the event control block associated with the desired mutex.
  243. *
  244. * Returns : TLS_OS_SUCCESS The call was successful and the mutex was deleted
  245. * TLS_OS_ERROR error
  246. *
  247. * Note(s) : 1) This function must be used with care. Tasks that would normally expect the presence of
  248. * the mutex MUST check the return code of OSMutexPend().
  249. *
  250. * 2) This call can potentially disable interrupts for a long time. The interrupt disable
  251. * time is directly proportional to the number of tasks waiting on the mutex.
  252. *
  253. * 3) Because ALL tasks pending on the mutex will be readied, you MUST be careful because the
  254. * resource(s) will no longer be guarded by the mutex.
  255. *
  256. * 4) IMPORTANT: In the 'OS_DEL_ALWAYS' case, we assume that the owner of the Mutex (if there
  257. * is one) is ready-to-run and is thus NOT pending on another kernel object or
  258. * has delayed itself. In other words, if a task owns the mutex being deleted,
  259. * that task will be made ready-to-run at its original priority.
  260. *********************************************************************************************************
  261. */
  262. tls_os_status_t tls_os_mutex_delete(tls_os_mutex_t *mutex)
  263. {
  264. vSemaphoreDelete((xQUEUE *)mutex);
  265. return TLS_OS_SUCCESS;
  266. }
  267. /*
  268. *********************************************************************************************************
  269. * PEND ON MUTUAL EXCLUSION SEMAPHORE
  270. *
  271. * Description: This function waits for a mutual exclusion semaphore.
  272. *
  273. * Arguments : mutex is a pointer to the event control block associated with the desired
  274. * mutex.
  275. *
  276. * wait_time is an optional timeout period (in clock ticks). If non-zero, your task will
  277. * wait for the resource up to the amount of time specified by this argument.
  278. * If you specify 0, however, your task will wait forever at the specified
  279. * mutex or, until the resource becomes available.
  280. *
  281. *
  282. *
  283. * Returns : TLS_OS_SUCCESS The call was successful and your task owns the mutex
  284. * TLS_OS_ERROR
  285. *
  286. * Note(s) : 1) The task that owns the Mutex MUST NOT pend on any other event while it owns the mutex.
  287. *
  288. * 2) You MUST NOT change the priority of the task that owns the mutex
  289. *********************************************************************************************************
  290. */
  291. //不可在中断中调用
  292. tls_os_status_t tls_os_mutex_acquire(tls_os_mutex_t *mutex,
  293. u32 wait_time)
  294. {
  295. u8 error;
  296. tls_os_status_t os_status;
  297. portBASE_TYPE pxHigherPriorityTaskWoken = pdFALSE;
  298. unsigned int time;
  299. if(0 == wait_time)
  300. time = portMAX_DELAY;
  301. else
  302. time = wait_time;
  303. u8 isrcount = 0;
  304. isrcount = tls_get_isr_count();
  305. if(isrcount > 0)
  306. {
  307. error = xSemaphoreTakeFromISR((xQUEUE *)mutex, &pxHigherPriorityTaskWoken );
  308. if((pdTRUE == pxHigherPriorityTaskWoken) && (1 == isrcount))
  309. {
  310. portYIELD_FROM_ISR(TRUE);
  311. }
  312. }
  313. else
  314. {
  315. error = xSemaphoreTake((xQUEUE *)mutex, time );
  316. }
  317. if (error == pdPASS)
  318. os_status = TLS_OS_SUCCESS;
  319. else
  320. os_status = TLS_OS_ERROR;
  321. return os_status;
  322. }
  323. /*
  324. *********************************************************************************************************
  325. * POST TO A MUTUAL EXCLUSION SEMAPHORE
  326. *
  327. * Description: This function signals a mutual exclusion semaphore
  328. *
  329. * Arguments : mutex is a pointer to the event control block associated with the desired
  330. * mutex.
  331. *
  332. * Returns : TLS_OS_SUCCESS The call was successful and the mutex was signaled.
  333. * TLS_OS_ERROR
  334. *********************************************************************************************************
  335. */
  336. tls_os_status_t tls_os_mutex_release(tls_os_mutex_t *mutex)
  337. {
  338. u8 error;
  339. tls_os_status_t os_status;
  340. portBASE_TYPE pxHigherPriorityTaskWoken = pdFALSE;
  341. u8 isrcount = 0;
  342. assert(mutex != NULL);
  343. isrcount = tls_get_isr_count();
  344. if(isrcount > 0)
  345. {
  346. error = xSemaphoreGiveFromISR((xQUEUE *)mutex, &pxHigherPriorityTaskWoken );
  347. if((pdTRUE == pxHigherPriorityTaskWoken) && (1 == isrcount))
  348. {
  349. portYIELD_FROM_ISR(pdTRUE);
  350. }
  351. }
  352. else
  353. {
  354. error = xSemaphoreGive((xQUEUE *)mutex );
  355. }
  356. if (error == pdPASS)
  357. os_status = TLS_OS_SUCCESS;
  358. else
  359. os_status = TLS_OS_ERROR;
  360. return os_status;
  361. }
  362. #endif
  363. /*
  364. *********************************************************************************************************
  365. * CREATE A SEMAPHORE
  366. *
  367. * Description: This function creates a semaphore.
  368. *
  369. * Arguments :sem is a pointer to the event control block (OS_EVENT) associated with the
  370. * created semaphore
  371. * cnt is the initial value for the semaphore. If the value is 0, no resource is
  372. * available (or no event has occurred). You initialize the semaphore to a
  373. * non-zero value to specify how many resources are available (e.g. if you have
  374. * 10 resources, you would initialize the semaphore to 10).
  375. *
  376. * Returns : TLS_OS_SUCCESS The call was successful
  377. * TLS_OS_ERROR
  378. *********************************************************************************************************
  379. */
  380. #if (1 == configUSE_COUNTING_SEMAPHORES)
  381. tls_os_status_t tls_os_sem_create(tls_os_sem_t **sem, u32 cnt)
  382. {
  383. tls_os_status_t os_status;
  384. *sem = xSemaphoreCreateCounting( configSEMAPHORE_INIT_VALUE, cnt );
  385. if (*sem != NULL)
  386. os_status = TLS_OS_SUCCESS;
  387. else
  388. os_status = TLS_OS_ERROR;
  389. return os_status;
  390. }
  391. /*
  392. *********************************************************************************************************
  393. * DELETE A SEMAPHORE
  394. *
  395. * Description: This function deletes a semaphore and readies all tasks pending on the semaphore.
  396. *
  397. * Arguments : sem is a pointer to the event control block associated with the desired
  398. * semaphore.
  399. *
  400. * Returns : TLS_OS_SUCCESS The call was successful and the semaphore was deleted
  401. * TLS_OS_ERROR
  402. *
  403. *********************************************************************************************************
  404. */
  405. tls_os_status_t tls_os_sem_delete(tls_os_sem_t *sem)
  406. {
  407. vSemaphoreDelete((xQUEUE *)sem);
  408. return TLS_OS_SUCCESS;
  409. }
  410. /*
  411. *********************************************************************************************************
  412. * PEND ON SEMAPHORE
  413. *
  414. * Description: This function waits for a semaphore.
  415. *
  416. * Arguments : sem is a pointer to the event control block associated with the desired
  417. * semaphore.
  418. *
  419. * wait_time is an optional timeout period (in clock ticks). If non-zero, your task will
  420. * wait for the resource up to the amount of time specified by this argument.
  421. * If you specify 0, however, your task will wait forever at the specified
  422. * semaphore or, until the resource becomes available (or the event occurs).
  423. *
  424. * Returns : TLS_OS_SUCCESS
  425. * TLS_OS_ERROR
  426. *********************************************************************************************************
  427. */
  428. //该函数不可用于中断服务程序中
  429. tls_os_status_t tls_os_sem_acquire(tls_os_sem_t *sem,
  430. u32 wait_time)
  431. {
  432. u8 error;
  433. tls_os_status_t os_status;
  434. unsigned int time;
  435. if(0 == wait_time)
  436. time = portMAX_DELAY;
  437. else
  438. time = wait_time;
  439. portBASE_TYPE pxHigherPriorityTaskWoken = pdFALSE;
  440. u8 isrcount = 0;
  441. isrcount = tls_get_isr_count();
  442. if(isrcount > 0)
  443. {
  444. error = xSemaphoreTakeFromISR((xQUEUE *)sem, &pxHigherPriorityTaskWoken );
  445. if((pdTRUE == pxHigherPriorityTaskWoken) && (1 == isrcount))
  446. {
  447. portYIELD_FROM_ISR(TRUE);
  448. }
  449. }
  450. else
  451. {
  452. error = xSemaphoreTake((xQUEUE *)sem, time );
  453. }
  454. if (error == pdPASS)
  455. os_status = TLS_OS_SUCCESS;
  456. else
  457. os_status = TLS_OS_ERROR;
  458. return os_status;
  459. }
  460. u16 tls_os_sem_get_count(tls_os_sem_t *sem)
  461. {
  462. return (u16)xSemaphoreGetCount((xQUEUE *)sem);
  463. }
  464. /*
  465. *********************************************************************************************************
  466. * POST TO A SEMAPHORE
  467. *
  468. * Description: This function signals a semaphore
  469. *
  470. * Arguments : sem is a pointer to the event control block associated with the desired
  471. * semaphore.
  472. *
  473. * Returns : TLS_OS_SUCCESS
  474. * TLS_OS_ERROR
  475. *********************************************************************************************************
  476. */
  477. tls_os_status_t tls_os_sem_release(tls_os_sem_t *sem)
  478. {
  479. u8 error;
  480. tls_os_status_t os_status;
  481. portBASE_TYPE pxHigherPriorityTaskWoken = pdFALSE;
  482. u8 isrcount = 0;
  483. assert(sem != NULL);
  484. isrcount = tls_get_isr_count();
  485. if(isrcount > 0)
  486. {
  487. error = xSemaphoreGiveFromISR((xQUEUE *)sem, &pxHigherPriorityTaskWoken );
  488. if((pdTRUE == pxHigherPriorityTaskWoken) && (1 == isrcount))
  489. {
  490. portYIELD_FROM_ISR(pdTRUE);
  491. }
  492. }
  493. else
  494. {
  495. error = xSemaphoreGive((xQUEUE *)sem );
  496. }
  497. if (error == pdPASS)
  498. os_status = TLS_OS_SUCCESS;
  499. else
  500. os_status = TLS_OS_ERROR;
  501. return os_status;
  502. }
  503. #endif
  504. // ========================================================================= //
  505. // Message Passing //
  506. // ========================================================================= //
  507. /*
  508. *********************************************************************************************************
  509. * CREATE A MESSAGE QUEUE
  510. *
  511. * Description: This function creates a message queue if free event control blocks are available.
  512. *
  513. * Arguments : queue is a pointer to the event control clock (OS_EVENT) associated with the
  514. * created queue
  515. *
  516. * queue_start is a pointer to the base address of the message queue storage area. The
  517. * storage area MUST be declared as an array of pointers to 'void' as follows
  518. *
  519. * void *MessageStorage[size]
  520. *
  521. * queue_size is the number of elements in the storage area
  522. *
  523. * msg_size
  524. *
  525. * Returns : TLS_OS_SUCCESS
  526. * TLS_OS_ERROR
  527. *********************************************************************************************************
  528. */
  529. tls_os_status_t tls_os_queue_create(tls_os_queue_t **queue, u32 queue_size)
  530. {
  531. tls_os_status_t os_status;
  532. u32 queuesize = 10;
  533. void *queue_start = NULL;
  534. if (queue_size)
  535. {
  536. queuesize = queue_size;
  537. }
  538. queue_start = tls_mem_alloc(queuesize *(sizeof(void *)));
  539. if (NULL == queue_start)
  540. {
  541. return TLS_OS_ERROR;
  542. }
  543. *queue = xQueueCreateExt(queue_start, queuesize, sizeof(void *));
  544. if (*queue != NULL)
  545. os_status = TLS_OS_SUCCESS;
  546. else
  547. os_status = TLS_OS_ERROR;
  548. return os_status;
  549. }
  550. /*
  551. *********************************************************************************************************
  552. * DELETE A MESSAGE QUEUE
  553. *
  554. * Description: This function deletes a message queue and readies all tasks pending on the queue.
  555. *
  556. * Arguments : queue is a pointer to the event control block associated with the desired
  557. * queue.
  558. *
  559. *
  560. * Returns : TLS_OS_SUCCESS
  561. * TLS_OS_ERROR
  562. *********************************************************************************************************
  563. */
  564. extern u32 __heap_start;
  565. tls_os_status_t tls_os_queue_delete(tls_os_queue_t *queue)
  566. {
  567. if ((u32 *)(((xQUEUE *)queue)->pcHead) >= &__heap_start) //如果没有从堆申请,不用释放)
  568. {
  569. tls_mem_free(((xQUEUE *)queue)->pcHead);
  570. }
  571. vQueueDeleteExt((xQUEUE *)queue);
  572. return TLS_OS_SUCCESS;
  573. }
  574. u8 tls_os_queue_is_empty(tls_os_queue_t *queue)
  575. {
  576. return xQueueIsQueueEmptyFromISR((xQUEUE *)queue);
  577. }
  578. /*
  579. *********************************************************************************************************
  580. * POST MESSAGE TO A QUEUE
  581. *
  582. * Description: This function sends a message to a queue
  583. *
  584. * Arguments : queue is a pointer to the event control block associated with the desired queue
  585. *
  586. * msg is a pointer to the message to send.
  587. *
  588. * msg_size
  589. * Returns : TLS_OS_SUCCESS
  590. * TLS_OS_ERROR
  591. *********************************************************************************************************
  592. */
  593. tls_os_status_t tls_os_queue_send(tls_os_queue_t *queue,
  594. void *msg,
  595. u32 msg_size)
  596. {
  597. u8 error;
  598. tls_os_status_t os_status;
  599. portBASE_TYPE pxHigherPriorityTaskWoken = pdFALSE;
  600. u8 isrcount = 0;
  601. isrcount = tls_get_isr_count();
  602. if(isrcount > 0)
  603. {
  604. error = xQueueSendFromISR((xQUEUE *) queue, &msg, &pxHigherPriorityTaskWoken );
  605. if((pdTRUE == pxHigherPriorityTaskWoken) && (1 == isrcount))
  606. {
  607. portYIELD_FROM_ISR(pdTRUE);
  608. }
  609. }
  610. else
  611. {
  612. error = xQueueSend((xQUEUE *)queue, &msg, 0 );
  613. }
  614. if (error == pdPASS)
  615. os_status = TLS_OS_SUCCESS;
  616. else {
  617. os_status = TLS_OS_ERROR;
  618. }
  619. return os_status;
  620. }
  621. tls_os_status_t tls_os_queue_remove(tls_os_queue_t *queue, void* msg, u32 msg_size)
  622. {
  623. void *tmp_ev;
  624. BaseType_t ret;
  625. int i;
  626. int count;
  627. BaseType_t woken, woken2;
  628. /*
  629. * XXX We cannot extract element from inside FreeRTOS queue so as a quick
  630. * workaround we'll just remove all elements and add them back except the
  631. * one we need to remove. This is silly, but works for now - we probably
  632. * better use counting semaphore with os_queue to handle this in future.
  633. */
  634. if (tls_get_isr_count()>0) {
  635. woken = pdFALSE;
  636. count = uxQueueMessagesWaitingFromISR((xQUEUE *) queue);
  637. for (i = 0; i < count; i++) {
  638. ret = xQueueReceiveFromISR((xQUEUE *) queue, &tmp_ev, &woken2);
  639. assert(ret == pdPASS);
  640. woken |= woken2;
  641. if (tmp_ev == msg) {
  642. continue;
  643. }
  644. ret = xQueueSendToBackFromISR((xQUEUE *) queue, &tmp_ev, &woken2);
  645. assert(ret == pdPASS);
  646. woken |= woken2;
  647. }
  648. portYIELD_FROM_ISR(woken);
  649. } else {
  650. vPortEnterCritical();
  651. count = uxQueueMessagesWaiting((xQUEUE *) queue);
  652. for (i = 0; i < count; i++) {
  653. ret = xQueueReceive((xQUEUE *) queue, &tmp_ev, 0);
  654. assert(ret == pdPASS);
  655. if (tmp_ev == msg) {
  656. continue;
  657. }
  658. ret = xQueueSendToBack((xQUEUE *) queue, &tmp_ev, 0);
  659. assert(ret == pdPASS);
  660. }
  661. vPortExitCritical();
  662. }
  663. }
  664. /*
  665. *********************************************************************************************************
  666. * PEND ON A QUEUE FOR A MESSAGE
  667. *
  668. * Description: This function waits for a message to be sent to a queue
  669. *
  670. * Arguments : queue is a pointer to the event control block associated with the desired queue
  671. *
  672. * msg is a pointer to the message received
  673. *
  674. * msg_size
  675. *
  676. * wait_time is an optional timeout period (in clock ticks). If non-zero, your task will
  677. * wait for a message to arrive at the queue up to the amount of time
  678. * specified by this argument. If you specify 0, however, your task will wait
  679. * forever at the specified queue or, until a message arrives.
  680. *
  681. * Returns : TLS_OS_SUCCESS
  682. * TLS_OS_ERROR
  683. *********************************************************************************************************
  684. */
  685. tls_os_status_t tls_os_queue_receive(tls_os_queue_t *queue,
  686. void **msg,
  687. u32 msg_size,
  688. u32 wait_time)
  689. {
  690. u8 error;
  691. tls_os_status_t os_status;
  692. unsigned int xTicksToWait;
  693. portBASE_TYPE pxHigherPriorityTaskWoken = pdFALSE;
  694. u8 isrcount = 0;
  695. if(0 == wait_time)
  696. xTicksToWait = portMAX_DELAY;
  697. else
  698. xTicksToWait = wait_time;
  699. isrcount = tls_get_isr_count();
  700. if(isrcount > 0)
  701. {
  702. error = xQueueReceiveFromISR((xQUEUE *)queue, msg, &pxHigherPriorityTaskWoken);
  703. if((pdTRUE == pxHigherPriorityTaskWoken) && (1 == isrcount))
  704. {
  705. portYIELD_FROM_ISR(pdTRUE);
  706. }
  707. }
  708. else
  709. {
  710. error = xQueueReceive((xQUEUE *)queue, msg, xTicksToWait );
  711. }
  712. if (error == pdPASS)
  713. os_status = TLS_OS_SUCCESS;
  714. else
  715. os_status = TLS_OS_ERROR;
  716. return os_status;
  717. }
  718. /*
  719. *********************************************************************************************************
  720. * FLUSH QUEUE
  721. *
  722. * Description : This function is used to flush the contents of the message queue.
  723. *
  724. * Arguments : none
  725. *
  726. * Returns : TLS_OS_SUCCESS
  727. * TLS_OS_ERROR
  728. *At present, no use for freeRTOS
  729. *********************************************************************************************************
  730. */
  731. tls_os_status_t tls_os_queue_flush(tls_os_queue_t *queue)
  732. {
  733. return TLS_OS_SUCCESS;
  734. }
  735. /*
  736. *********************************************************************************************************
  737. * CREATE A MESSAGE MAILBOX
  738. *
  739. * Description: This function creates a message mailbox if free event control blocks are available.
  740. *
  741. * Arguments : mailbox is a pointer to the event control clock (OS_EVENT) associated with the
  742. * created mailbox
  743. *
  744. * mailbox_start is a pointer to a message that you wish to deposit in the mailbox. If
  745. * you set this value to the NULL pointer (i.e. (void *)0) then the mailbox
  746. * will be considered empty.
  747. *
  748. * mailbox_size
  749. *
  750. * msg_size
  751. *
  752. Returns : TLS_OS_SUCCESS
  753. * TLS_OS_ERROR
  754. *********************************************************************************************************
  755. */
  756. #if (1 == configUSE_MAILBOX)
  757. tls_os_status_t tls_os_mailbox_create(tls_os_mailbox_t **mailbox,
  758. u32 mailbox_size)
  759. {
  760. tls_os_status_t os_status;
  761. u32 mbox_size = 1;
  762. if (mailbox_size)
  763. {
  764. mbox_size = mailbox_size;
  765. }
  766. *mailbox = xQueueCreate(mbox_size, sizeof(void *));
  767. if (*mailbox != NULL)
  768. os_status = TLS_OS_SUCCESS;
  769. else
  770. os_status = TLS_OS_ERROR;
  771. return os_status;
  772. }
  773. /*
  774. *********************************************************************************************************
  775. * DELETE A MAIBOX
  776. *
  777. * Description: This function deletes a mailbox and readies all tasks pending on the mailbox.
  778. *
  779. * Arguments : mailbox is a pointer to the event control block associated with the desired
  780. * mailbox.
  781. *
  782. *
  783. Returns : TLS_OS_SUCCESS
  784. * TLS_OS_ERROR
  785. *********************************************************************************************************
  786. */
  787. tls_os_status_t tls_os_mailbox_delete(tls_os_mailbox_t *mailbox)
  788. {
  789. vQueueDelete((xQUEUE *)mailbox);
  790. return TLS_OS_SUCCESS;
  791. }
  792. /*
  793. *********************************************************************************************************
  794. * POST MESSAGE TO A MAILBOX
  795. *
  796. * Description: This function sends a message to a mailbox
  797. *
  798. * Arguments : mailbox is a pointer to the event control block associated with the desired mailbox
  799. *
  800. * msg is a pointer to the message to send. You MUST NOT send a NULL pointer.
  801. *
  802. Returns : TLS_OS_SUCCESS
  803. * TLS_OS_ERROR
  804. *********************************************************************************************************
  805. */
  806. tls_os_status_t tls_os_mailbox_send(tls_os_mailbox_t *mailbox,
  807. void *msg)
  808. {
  809. u8 error;
  810. tls_os_status_t os_status;
  811. portBASE_TYPE pxHigherPriorityTaskWoken = pdFALSE;
  812. u8 isrcount = 0;
  813. isrcount = tls_get_isr_count();
  814. if(isrcount > 0)
  815. {
  816. error = xQueueSendFromISR( (xQUEUE *)mailbox, &msg, &pxHigherPriorityTaskWoken );
  817. if((pdTRUE == pxHigherPriorityTaskWoken) && (1 == isrcount))
  818. {
  819. vTaskSwitchContext();
  820. }
  821. }
  822. else
  823. {
  824. error = xQueueSend( (xQUEUE *)mailbox, &msg, 0 );
  825. }
  826. if (error == pdPASS)
  827. os_status = TLS_OS_SUCCESS;
  828. else {
  829. os_status = TLS_OS_ERROR;
  830. }
  831. return os_status;
  832. }
  833. /*
  834. *********************************************************************************************************
  835. * PEND ON MAILBOX FOR A MESSAGE
  836. *
  837. * Description: This function waits for a message to be sent to a mailbox
  838. *
  839. * Arguments : mailbox is a pointer to the event control block associated with the desired mailbox
  840. *
  841. * msg is a pointer to the message received
  842. *
  843. * wait_time is an optional timeout period (in clock ticks). If non-zero, your task will
  844. * wait for a message to arrive at the mailbox up to the amount of time
  845. * specified by this argument. If you specify 0, however, your task will wait
  846. * forever at the specified mailbox or, until a message arrives.
  847. *
  848. *Returns : TLS_OS_SUCCESS
  849. * TLS_OS_ERROR
  850. *********************************************************************************************************
  851. */
  852. tls_os_status_t tls_os_mailbox_receive(tls_os_mailbox_t *mailbox,
  853. void **msg,
  854. u32 wait_time)
  855. {
  856. u8 error;
  857. tls_os_status_t os_status;
  858. unsigned int xTicksToWait;
  859. portBASE_TYPE pxHigherPriorityTaskWoken = pdFALSE;
  860. u8 isrcount = 0;
  861. if(0 == wait_time)
  862. xTicksToWait = portMAX_DELAY;
  863. else
  864. xTicksToWait = wait_time;
  865. isrcount = tls_get_isr_count();
  866. if(isrcount > 0)
  867. {
  868. error = xQueueReceiveFromISR((xQUEUE *)mailbox, msg, &pxHigherPriorityTaskWoken);
  869. if((pdTRUE == pxHigherPriorityTaskWoken) && (1 == isrcount))
  870. {
  871. portYIELD_FROM_ISR(pdTRUE);
  872. }
  873. }
  874. else
  875. {
  876. error = xQueueReceive( (xQUEUE *)mailbox, msg, xTicksToWait );
  877. }
  878. if (error == pdPASS)
  879. os_status = TLS_OS_SUCCESS;
  880. else
  881. os_status = TLS_OS_ERROR;
  882. return os_status;
  883. }
  884. #endif
  885. #endif //no def CONFIG_KERNEL_NONE
  886. /*
  887. *********************************************************************************************************
  888. * GET CURRENT SYSTEM TIME
  889. *
  890. * Description: This function is used by your application to obtain the current value of the 32-bit
  891. * counter which keeps track of the number of clock ticks.
  892. *
  893. * Arguments : none
  894. *
  895. * Returns : The current value of OSTime
  896. *********************************************************************************************************
  897. */
  898. u32 tls_os_get_time(void)
  899. {
  900. #ifdef CONFIG_KERNEL_NONE
  901. #ifdef TLS_CONFIG_FPGA
  902. extern volatile uint32_t sys_count;
  903. return sys_count;
  904. #else
  905. return 0;
  906. #endif
  907. #else
  908. return xTaskGetTickCountFromISR();
  909. #endif
  910. }
  911. /**********************************************************************************************************
  912. * Description: Disable interrupts by preserving the state of interrupts.
  913. *
  914. * Arguments : none
  915. *
  916. * Returns : cpu_sr
  917. ***********************************************************************************************************/
  918. u32 tls_os_set_critical(void)
  919. {
  920. #ifndef CONFIG_KERNEL_NONE
  921. vPortEnterCritical();
  922. #endif
  923. return 1;
  924. }
  925. /**********************************************************************************************************
  926. * Description: Enable interrupts by preserving the state of interrupts.
  927. *
  928. * Arguments : cpu_sr
  929. *
  930. * Returns : none
  931. ***********************************************************************************************************/
  932. void tls_os_release_critical(u32 cpu_sr)
  933. {
  934. #ifndef CONFIG_KERNEL_NONE
  935. return vPortExitCritical();
  936. #endif
  937. }
  938. /*
  939. ************************************************************************************************************************
  940. * CREATE A TIMER
  941. *
  942. * Description: This function is called by your application code to create a timer.
  943. *
  944. * Arguments : timer A pointer to an OS_TMR data structure.This is the 'handle' that your application
  945. * will use to reference the timer created.
  946. *
  947. * callback Is a pointer to a callback function that will be called when the timer expires. The
  948. * callback function must be declared as follows:
  949. *
  950. * void MyCallback (OS_TMR *ptmr, void *p_arg);
  951. *
  952. * callback_arg Is an argument (a pointer) that is passed to the callback function when it is called.
  953. *
  954. * period The 'period' being repeated for the timer.
  955. * If you specified 'OS_TMR_OPT_PERIODIC' as an option, when the timer expires, it will
  956. * automatically restart with the same period.
  957. *
  958. * repeat if repeat
  959. *
  960. * pname Is a pointer to an ASCII string that is used to name the timer. Names are useful for
  961. * debugging.
  962. *
  963. *Returns : TLS_OS_SUCCESS
  964. * TLS_OS_ERROR
  965. ************************************************************************************************************************
  966. */
  967. tls_os_status_t tls_os_timer_create(tls_os_timer_t **timer,
  968. TLS_OS_TIMER_CALLBACK callback,
  969. void *callback_arg,
  970. u32 period,
  971. bool repeat,
  972. u8 *name)
  973. {
  974. tls_os_status_t os_status;
  975. if(0 == period)
  976. period = 1;
  977. #if configUSE_TIMERS
  978. *timer = (xTIMER *)xTimerCreateExt( (signed char *)name, period, repeat, NULL, callback, callback_arg );
  979. #endif
  980. if (*timer != NULL)
  981. {
  982. os_status = TLS_OS_SUCCESS;
  983. }
  984. else
  985. {
  986. os_status = TLS_OS_ERROR;
  987. }
  988. return os_status;
  989. }
  990. /*
  991. ************************************************************************************************************************
  992. * START A TIMER
  993. *
  994. * Description: This function is called by your application code to start a timer.
  995. *
  996. * Arguments : timer Is a pointer to an OS_TMR
  997. *
  998. ************************************************************************************************************************
  999. */
  1000. void tls_os_timer_start(tls_os_timer_t *timer)
  1001. {
  1002. portBASE_TYPE pxHigherPriorityTaskWoken = pdFALSE;
  1003. u8 isrcount = 0;
  1004. isrcount = tls_get_isr_count();
  1005. if(isrcount > 0)
  1006. {
  1007. #if configUSE_TIMERS
  1008. xTimerStartFromISR((xTIMER *)timer, &pxHigherPriorityTaskWoken );
  1009. #endif
  1010. if((pdTRUE == pxHigherPriorityTaskWoken) && (1 == isrcount))
  1011. {
  1012. portYIELD_FROM_ISR(pdTRUE);
  1013. }
  1014. }
  1015. else
  1016. {
  1017. #if configUSE_TIMERS
  1018. xTimerStart((xTIMER *)timer, 0 ); //no block time
  1019. #endif
  1020. }
  1021. }
  1022. /*
  1023. ************************************************************************************************************************
  1024. * CHANGE A TIMER WAIT TIME
  1025. *
  1026. * Description: This function is called by your application code to change a timer wait time.
  1027. *
  1028. * Arguments : timer Is a pointer to an OS_TMR
  1029. *
  1030. * ticks is the wait time
  1031. ************************************************************************************************************************
  1032. */
  1033. void tls_os_timer_change(tls_os_timer_t *timer, u32 ticks)
  1034. {
  1035. portBASE_TYPE pxHigherPriorityTaskWoken = pdFALSE;
  1036. u8 isrcount = 0;
  1037. if(0 == ticks)
  1038. ticks = 1;
  1039. isrcount = tls_get_isr_count();
  1040. if(isrcount > 0)
  1041. {
  1042. #if configUSE_TIMERS
  1043. xTimerChangePeriodFromISR((xTIMER *)timer, ticks, &pxHigherPriorityTaskWoken );
  1044. xTimerStartFromISR( (xTIMER *)timer, &pxHigherPriorityTaskWoken );
  1045. #endif
  1046. if((pdTRUE == pxHigherPriorityTaskWoken) && (1 == isrcount))
  1047. {
  1048. portYIELD_FROM_ISR(pdTRUE);
  1049. }
  1050. }
  1051. else
  1052. {
  1053. #if configUSE_TIMERS
  1054. xTimerChangePeriod((xTIMER *)timer, ticks, 0 );
  1055. xTimerStart((xTIMER *)timer, 0 );
  1056. #endif
  1057. }
  1058. }
  1059. /*
  1060. ************************************************************************************************************************
  1061. * STOP A TIMER
  1062. *
  1063. * Description: This function is called by your application code to stop a timer.
  1064. *
  1065. * Arguments : timer Is a pointer to the timer to stop.
  1066. *
  1067. ************************************************************************************************************************
  1068. */
  1069. void tls_os_timer_stop(tls_os_timer_t *timer)
  1070. {
  1071. portBASE_TYPE pxHigherPriorityTaskWoken = pdFALSE;
  1072. u8 isrcount = 0;
  1073. isrcount = tls_get_isr_count();
  1074. if(isrcount > 0)
  1075. {
  1076. #if configUSE_TIMERS
  1077. xTimerStopFromISR((xTIMER *)timer, &pxHigherPriorityTaskWoken );
  1078. #endif
  1079. if((pdTRUE == pxHigherPriorityTaskWoken) && (1 == isrcount))
  1080. {
  1081. portYIELD_FROM_ISR(pdTRUE);
  1082. }
  1083. }
  1084. else
  1085. {
  1086. #if configUSE_TIMERS
  1087. xTimerStop((xTIMER *)timer, 0 );
  1088. #endif
  1089. }
  1090. }
  1091. u8 tls_os_timer_active(tls_os_timer_t *timer)
  1092. {
  1093. return (u8)xTimerIsTimerActive((xTIMER *)timer);
  1094. }
  1095. u32 tls_os_timer_expirytime(tls_os_timer_t *timer)
  1096. {
  1097. return (u32)xTimerGetExpiryTime((xTIMER *)timer);
  1098. }
  1099. /*
  1100. ************************************************************************************************************************
  1101. * Delete A TIMER
  1102. *
  1103. * Description: This function is called by your application code to delete a timer.
  1104. *
  1105. * Arguments : timer Is a pointer to the timer to delete.
  1106. *
  1107. ************************************************************************************************************************
  1108. */
  1109. tls_os_status_t tls_os_timer_delete(tls_os_timer_t *timer)
  1110. {
  1111. int ret = 0;
  1112. tls_os_status_t os_status;
  1113. /* xTimer is already active - delete it. */
  1114. ret = xTimerDelete((xTIMER *)timer, 10);
  1115. if (pdPASS == ret)
  1116. os_status = TLS_OS_SUCCESS;
  1117. else
  1118. os_status = TLS_OS_ERROR;
  1119. return os_status;
  1120. }
  1121. /*
  1122. *********************************************************************************************************
  1123. * DELAY TASK 'n' TICKS
  1124. *
  1125. * Description: This function is called to delay execution of the currently running task until the
  1126. * specified number of system ticks expires. This, of course, directly equates to delaying
  1127. * the current task for some time to expire. No delay will result If the specified delay is
  1128. * 0. If the specified delay is greater than 0 then, a context switch will result.
  1129. *
  1130. * Arguments : ticks is the time delay that the task will be suspended in number of clock 'ticks'.
  1131. * Note that by specifying 0, the task will not be delayed.
  1132. *
  1133. * Returns : none
  1134. *********************************************************************************************************
  1135. */
  1136. void tls_os_time_delay(u32 ticks)
  1137. {
  1138. vTaskDelay(ticks);
  1139. }
  1140. /*
  1141. *********************************************************************************************************
  1142. * task stat info
  1143. *
  1144. * Description: This function is used to display stat info
  1145. * Arguments :
  1146. *
  1147. * Returns : none
  1148. *********************************************************************************************************
  1149. */
  1150. void tls_os_disp_task_stat_info(void)
  1151. {
  1152. char *buf = NULL;
  1153. buf = tls_mem_alloc(1024);
  1154. if(NULL == buf)
  1155. return;
  1156. #if configUSE_TRACE_FACILITY
  1157. vTaskList((signed char *)buf);
  1158. #endif
  1159. printf("\n%s",buf);
  1160. tls_mem_free(buf);
  1161. buf = NULL;
  1162. }
  1163. /*
  1164. *********************************************************************************************************
  1165. * OS INIT function
  1166. *
  1167. * Description: This function is used to init os common resource
  1168. *
  1169. * Arguments : None;
  1170. *
  1171. * Returns : None
  1172. *********************************************************************************************************
  1173. */
  1174. void tls_os_init(void *arg)
  1175. {
  1176. }
  1177. /*
  1178. *********************************************************************************************************
  1179. * OS scheduler start function
  1180. *
  1181. * Description: This function is used to start task schedule
  1182. *
  1183. * Arguments : None;
  1184. *
  1185. * Returns : None
  1186. *********************************************************************************************************
  1187. */
  1188. void tls_os_start_scheduler(void)
  1189. {
  1190. vTaskStartScheduler();
  1191. }
  1192. /*
  1193. *********************************************************************************************************
  1194. * Get OS TYPE
  1195. *
  1196. * Description: This function is used to get OS type
  1197. *
  1198. * Arguments : None;
  1199. *
  1200. * Returns : TLS_OS_TYPE
  1201. * OS_UCOSII = 0,
  1202. * OS_FREERTOS = 1,
  1203. *********************************************************************************************************
  1204. */
  1205. int tls_os_get_type(void)
  1206. {
  1207. return (int)OS_FREERTOS;
  1208. }
  1209. /*
  1210. *********************************************************************************************************
  1211. * OS tick handler
  1212. *
  1213. * Description: This function is tick handler.
  1214. *
  1215. * Arguments : None;
  1216. *
  1217. * Returns : None
  1218. *********************************************************************************************************
  1219. */
  1220. void tls_os_time_tick(void *p){
  1221. }
  1222. static uint32_t CK_IN_INTRP(void)
  1223. {
  1224. uint32_t vec = 0;
  1225. asm volatile(
  1226. "mfcr %0, psr \n"
  1227. "lsri %0, 16\n"
  1228. "sextb %0\n"
  1229. :"=r"(vec):);
  1230. if (vec >= 32 || (vec == 10)) {
  1231. return 1;
  1232. } else {
  1233. return 0;
  1234. }
  1235. }
  1236. /**
  1237. * @brief get isr count
  1238. *
  1239. * @param[in] None
  1240. *
  1241. * @retval count
  1242. *
  1243. * @note None
  1244. */
  1245. //extern int portGET_IPSR(void);
  1246. u8 tls_get_isr_count(void)
  1247. {
  1248. // return intr_counter;
  1249. //return (portGET_IPSR() > 13);
  1250. return (u8)CK_IN_INTRP();
  1251. }
  1252. int csi_kernel_intrpt_enter(void)
  1253. {
  1254. return 0;
  1255. }
  1256. int csi_kernel_intrpt_exit(void)
  1257. {
  1258. portYIELD_FROM_ISR(pdTRUE);
  1259. return 0;
  1260. }
  1261. #endif
  1262. #endif /* end of WM_OSAL_RTOS_H */