rtthread_service.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151
  1. /* rtthread includes */
  2. #include <osdep_service.h>
  3. #include <rtthread_service.h>
  4. #ifdef SECTION
  5. #undef SECTION
  6. #endif
  7. #include <rthw.h>
  8. #include <rtthread.h>
  9. #include <stdio.h>
  10. // #define RTTHREAD_SERVICE_DEBUG
  11. #define RTTHREAD_SERVICE_DEBUG_LEVEL 2
  12. /********************* os depended utilities ********************/
  13. #ifdef RTTHREAD_SERVICE_DEBUG
  14. #define DEBUG_LOG(_level, fmt, args...) if ((_level) >= RTTHREAD_SERVICE_DEBUG_LEVEL) rt_kprintf(fmt, args)
  15. #else
  16. #define DEBUG_LOG(level, fmt, args...)
  17. #endif
  18. #ifndef USE_MUTEX_FOR_SPINLOCK
  19. #define USE_MUTEX_FOR_SPINLOCK 1
  20. #endif
  21. extern uint32_t pmu_yield_os_check(void);
  22. extern _LONG_CALL_ void DelayUs(u32 us);
  23. extern _LONG_CALL_ void DelayMs(u32 ms);
  24. extern uint32_t pmu_set_sysactive_time(uint32_t timeout_ms);
  25. void save_and_cli(void)
  26. {
  27. DEBUG_LOG(1, "L:%d fun:%s runing...\n", __LINE__, __FUNCTION__);
  28. rt_enter_critical();
  29. }
  30. void restore_flags(void)
  31. {
  32. DEBUG_LOG(1, "L:%d fun:%s runing...\n", __LINE__, __FUNCTION__);
  33. rt_exit_critical();
  34. }
  35. void cli(void)
  36. {
  37. DEBUG_LOG(1, "L:%d fun:%s runing...\n", __LINE__, __FUNCTION__);
  38. rt_hw_interrupt_disable();
  39. }
  40. /* Not needed on 64bit architectures */
  41. static unsigned int __div64_32(u64 *n, unsigned int base)
  42. {
  43. u64 rem = *n;
  44. u64 b = base;
  45. u64 res, d = 1;
  46. unsigned int high = rem >> 32;
  47. /* Reduce the thing a bit first */
  48. res = 0;
  49. if (high >= base) {
  50. high /= base;
  51. res = (u64) high << 32;
  52. rem -= (u64) (high * base) << 32;
  53. }
  54. while ((u64)b > 0 && b < rem) {
  55. b = b+b;
  56. d = d+d;
  57. }
  58. do {
  59. if (rem >= b) {
  60. rem -= b;
  61. res += d;
  62. }
  63. b >>= 1;
  64. d >>= 1;
  65. } while (d);
  66. *n = res;
  67. return rem;
  68. }
  69. /********************* os depended service ********************/
  70. u8* _rtthread_malloc(u32 sz)
  71. {
  72. void *pbuf;
  73. DEBUG_LOG(2, "L:%d fun:%s sz:%d\n", __LINE__, __FUNCTION__, sz);
  74. pbuf = rt_malloc(sz);
  75. return pbuf;
  76. }
  77. u8* _rtthread_zmalloc(u32 sz)
  78. {
  79. void *pbuf = rt_malloc(sz);
  80. DEBUG_LOG(2, "L:%d fun:%s sz:%d\n", __LINE__, __FUNCTION__, sz);
  81. if (pbuf != RT_NULL)
  82. memset(pbuf, 0, sz);
  83. return pbuf;
  84. }
  85. void _rtthread_mfree(u8 *pbuf, u32 sz)
  86. {
  87. DEBUG_LOG(2, "L:%d fun:%s\n", __LINE__, __FUNCTION__);
  88. rt_free(pbuf);
  89. }
  90. static void _rtthread_memcpy(void* dst, void* src, u32 sz)
  91. {
  92. DEBUG_LOG(1, "L:%d fun:%s dst:0x%08x src:0x%08x sz:%d\n", __LINE__, __FUNCTION__, dst, src, sz);
  93. memcpy(dst, src, sz);
  94. }
  95. static int _rtthread_memcmp(void *dst, void *src, u32 sz)
  96. {
  97. //under Linux/GNU/GLibc, the return value of memcmp for two same mem. chunk is 0
  98. DEBUG_LOG(1, "L:%d fun:%s dst:0x%08x src:0x%08x sz:%d\n", __LINE__, __FUNCTION__, dst, src, sz);
  99. if (!(memcmp(dst, src, sz)))
  100. return 1;
  101. return 0;
  102. }
  103. static void _rtthread_memset(void *pbuf, int c, u32 sz)
  104. {
  105. DEBUG_LOG(1, "L:%d fun:%s buf:0x%08x c:%c sz:%d\n", __LINE__, __FUNCTION__, pbuf, c, sz);
  106. memset(pbuf, c, sz);
  107. }
  108. static void _rtthread_init_sema(_sema *sema, int init_val)
  109. {
  110. char name[RT_NAME_MAX];
  111. static int ameba_sem = 0;
  112. DEBUG_LOG(3, "L:%d fun:%s begin val:%d\n", __LINE__, __FUNCTION__, init_val);
  113. memset(name, 0, RT_NAME_MAX);
  114. snprintf(name, RT_NAME_MAX, "sem-%03d", ameba_sem);
  115. *sema = rt_sem_create(name, init_val, RT_IPC_FLAG_FIFO);
  116. if (*sema != RT_NULL)
  117. ameba_sem ++;
  118. DEBUG_LOG(3, "L:%d fun:%s end sema:0x%08x num:%d\n", __LINE__, __FUNCTION__, *sema, ameba_sem);
  119. }
  120. static void _rtthread_free_sema(_sema *sema)
  121. {
  122. RT_ASSERT(*sema != RT_NULL);
  123. DEBUG_LOG(2, "L:%d fun:%s sema:0x%08x\n", __LINE__, __FUNCTION__, *sema);
  124. rt_sem_delete(*sema);
  125. *sema = RT_NULL;
  126. }
  127. static void _rtthread_up_sema(_sema *sema)
  128. {
  129. if (*sema == RT_NULL)
  130. {
  131. rt_kprintf("err!! up sema is NULL\n");
  132. return;
  133. }
  134. DEBUG_LOG(2, "L:%d fun:%s sema:0x%08x\n", __LINE__, __FUNCTION__, *sema);
  135. rt_sem_release(*sema);
  136. }
  137. static void _rtthread_up_sema_from_isr(_sema *sema)
  138. {
  139. if (*sema == RT_NULL)
  140. {
  141. rt_kprintf("err!! up sema from isr is NULL\n");
  142. return;
  143. }
  144. DEBUG_LOG(2, "L:%d fun:%s sema:0x%08x\n", __LINE__, __FUNCTION__, *sema);
  145. rt_sem_release(*sema);
  146. }
  147. static u32 _rtthread_down_sema(_sema *sema, u32 timeout)
  148. {
  149. rt_int32_t tick;
  150. RT_ASSERT(*sema != RT_NULL);
  151. DEBUG_LOG(2, "L:%d fun:%s sema:0x%08x timeout:%d\n", __LINE__, __FUNCTION__, *sema, timeout);
  152. if(timeout >= RT_TICK_MAX / 2)
  153. tick = RT_WAITING_FOREVER;
  154. else
  155. tick = rtw_ms_to_systime(timeout);
  156. if(rt_sem_take(*sema, tick) != RT_EOK)
  157. return RT_FALSE;
  158. return RT_TRUE;
  159. }
  160. static void _rtthread_mutex_init(_mutex *pmutex)
  161. {
  162. char name[RT_NAME_MAX];
  163. static int ameba_mutex = 0;
  164. DEBUG_LOG(3, "L:%d fun:%s begin\n", __LINE__, __FUNCTION__);
  165. memset(name, 0, RT_NAME_MAX);
  166. snprintf(name, RT_NAME_MAX, "mux-%03d", ameba_mutex);
  167. *pmutex = rt_mutex_create(name, RT_IPC_FLAG_FIFO);
  168. if (*pmutex != RT_NULL)
  169. ameba_mutex ++;
  170. DEBUG_LOG(3, "L:%d fun:%s end pmutex:0x%08x\n", __LINE__, __FUNCTION__, *pmutex);
  171. }
  172. static void _rtthread_mutex_free(_mutex *pmutex)
  173. {
  174. RT_ASSERT(*pmutex != RT_NULL);
  175. DEBUG_LOG(2, "L:%d fun:%s pmutex:0x%08x\n", __LINE__, __FUNCTION__, *pmutex);
  176. rt_mutex_delete(*pmutex);
  177. *pmutex = RT_NULL;
  178. }
  179. static void _rtthread_mutex_get(_lock *plock)
  180. {
  181. RT_ASSERT(*plock != RT_NULL);
  182. DEBUG_LOG(2, "L:%d fun:%s pmutex:0x%08x\n", __LINE__, __FUNCTION__, *plock);
  183. rt_mutex_take(*plock, RT_WAITING_FOREVER);
  184. }
  185. static int _rtthread_mutex_get_timeout(_lock *plock, u32 timeout_ms)
  186. {
  187. rt_int32_t tick;
  188. RT_ASSERT(*plock != RT_NULL);
  189. DEBUG_LOG(2, "L:%d fun:%s plock:0x%08x timeout_ms:%d\n", __LINE__, __FUNCTION__, *plock, timeout_ms);
  190. if(timeout_ms >= RT_TICK_MAX / 2)
  191. tick = RT_WAITING_FOREVER;
  192. else
  193. tick = rtw_ms_to_systime(timeout_ms);
  194. return rt_mutex_take(*plock, tick);
  195. }
  196. static void _rtthread_mutex_put(_lock *plock)
  197. {
  198. if (*plock == RT_NULL)
  199. {
  200. rt_kprintf("err!! mutex put is null\n");
  201. return;
  202. }
  203. DEBUG_LOG(2, "L:%d fun:%s pmutex:0x%08x\n", __LINE__, __FUNCTION__, *plock);
  204. rt_mutex_release(*plock);
  205. }
  206. static void _rtthread_enter_critical(_lock *plock, _irqL *pirqL)
  207. {
  208. DEBUG_LOG(1, "L:%d fun:%s *pirqL:0x%08x\n", __LINE__, __FUNCTION__, *pirqL);
  209. rt_enter_critical();
  210. }
  211. static void _rtthread_exit_critical(_lock *plock, _irqL *pirqL)
  212. {
  213. DEBUG_LOG(1, "L:%d fun:%s *pirqL:0x%08x\n", __LINE__, __FUNCTION__, *pirqL);
  214. rt_exit_critical();
  215. }
  216. // static rt_base_t level;
  217. static void _rtthread_enter_critical_from_isr(_lock *plock, _irqL *pirqL)
  218. {
  219. DEBUG_LOG(1, "L:%d fun:%s *pirqL:0x%08x\n", __LINE__, __FUNCTION__, *pirqL);
  220. *pirqL = rt_hw_interrupt_disable();
  221. }
  222. static void _rtthread_exit_critical_from_isr(_lock *plock, _irqL *pirqL)
  223. {
  224. DEBUG_LOG(1, "L:%d fun:%s *pirqL:0x%08x\n", __LINE__, __FUNCTION__, *pirqL);
  225. rt_hw_interrupt_enable(*pirqL);
  226. }
  227. static int _rtthread_enter_critical_mutex(_mutex *pmutex, _irqL *pirqL)
  228. {
  229. RT_ASSERT(*pmutex != RT_NULL);
  230. DEBUG_LOG(1, "L:%d fun:%s *pirqL:0x%08x\n", __LINE__, __FUNCTION__, *pirqL);
  231. if(rt_mutex_take(*pmutex, RT_WAITING_FOREVER) != RT_EOK)
  232. return RT_FALSE;
  233. return RT_TRUE;
  234. }
  235. static void _rtthread_exit_critical_mutex(_mutex *pmutex, _irqL *pirqL)
  236. {
  237. if (*pmutex == RT_NULL)
  238. {
  239. rt_kprintf("err!! critical mutex is null\n");
  240. return;
  241. }
  242. DEBUG_LOG(1, "L:%d fun:%s *pirqL:0x%08x\n", __LINE__, __FUNCTION__, *pirqL);
  243. rt_mutex_release(*pmutex);
  244. }
  245. static void _rtthread_spinlock_init(_lock *plock)
  246. {
  247. #if USE_MUTEX_FOR_SPINLOCK
  248. char name[RT_NAME_MAX];
  249. static int ameba_spin = 0;
  250. DEBUG_LOG(3, "L:%d fun:%s begin\n", __LINE__, __FUNCTION__);
  251. memset(name, 0, RT_NAME_MAX);
  252. snprintf(name, RT_NAME_MAX, "spn-03d", ameba_spin);
  253. *plock = rt_mutex_create(name, RT_IPC_FLAG_FIFO);
  254. if (*plock != RT_NULL)
  255. ameba_spin ++;
  256. DEBUG_LOG(3, "L:%d fun:%s end plock:0x%08x ameba_spin:%d\n", __LINE__, __FUNCTION__, *plock, ameba_spin);
  257. #endif
  258. }
  259. static void _rtthread_spinlock_free(_lock *plock)
  260. {
  261. #if USE_MUTEX_FOR_SPINLOCK
  262. // RT_ASSERT(*plock != RT_NULL);
  263. if (*plock == RT_NULL)
  264. return;
  265. DEBUG_LOG(2, "L:%d fun:%s plock:0x%08x\n", __LINE__, __FUNCTION__, *plock);
  266. rt_mutex_delete(*plock);
  267. *plock = NULL;
  268. #endif
  269. }
  270. static void _rtthread_spinlock(_lock *plock)
  271. {
  272. #if USE_MUTEX_FOR_SPINLOCK
  273. RT_ASSERT(*plock != RT_NULL);
  274. DEBUG_LOG(2, "L:%d fun:%s plock:0x%08x\n", __LINE__, __FUNCTION__, *plock);
  275. rt_mutex_take(*plock, RT_WAITING_FOREVER);
  276. #endif
  277. }
  278. static void _rtthread_spinunlock(_lock *plock)
  279. {
  280. #if USE_MUTEX_FOR_SPINLOCK
  281. if (*plock == RT_NULL)
  282. {
  283. rt_kprintf("err!! spinunlock is null\n");
  284. return;
  285. }
  286. DEBUG_LOG(2, "L:%d fun:%s plock:0x%08x\n", __LINE__, __FUNCTION__, *plock);
  287. rt_mutex_release(*plock);
  288. #endif
  289. }
  290. static void _rtthread_spinlock_irqsave(_lock *plock, _irqL *irqL)
  291. {
  292. #if USE_MUTEX_FOR_SPINLOCK
  293. if (*plock == RT_NULL)
  294. rt_kprintf("err!! spinlock irqsave null\n");
  295. DEBUG_LOG(2, "L:%d fun:%s plock:0x%08x irqL:0x%08x\n", __LINE__, __FUNCTION__, *plock, *irqL);
  296. *irqL = 0xdeadbeff;
  297. while (rt_mutex_take(*plock, 0) != RT_EOK)
  298. {
  299. rt_kprintf("spinlock_irqsave failed!\n");
  300. }
  301. #endif
  302. }
  303. static void _rtthread_spinunlock_irqsave(_lock *plock, _irqL *irqL)
  304. {
  305. #if USE_MUTEX_FOR_SPINLOCK
  306. if (*plock == RT_NULL)
  307. rt_kprintf("err!! spinunlock irqsave null\n");
  308. DEBUG_LOG(2, "L:%d fun:%s plock:0x%08x irqL:0x%08x\n", __LINE__, __FUNCTION__, *plock, *irqL);
  309. rt_mutex_release(*plock);
  310. #endif
  311. }
  312. static int _rtthread_init_xqueue( _xqueue* queue, const char* name, u32 message_size, u32 number_of_messages )
  313. {
  314. DEBUG_LOG(3, "L:%d fun:%s begin name:%s size:%d msgs:%d\n", __LINE__, __FUNCTION__, name, message_size, number_of_messages);
  315. *queue = rt_mq_create(name, message_size, number_of_messages, RT_IPC_FLAG_FIFO);
  316. if (*queue == RT_NULL)
  317. {
  318. rt_kprintf("err!! create xqueue fail\n");
  319. return -1;
  320. }
  321. DEBUG_LOG(3, "L:%d fun:%s end queue:0x%08x\n", __LINE__, __FUNCTION__, *queue);
  322. return 0;
  323. }
  324. static int _rtthread_push_to_xqueue( _xqueue* queue, void* message, u32 timeout_ms )
  325. {
  326. RT_ASSERT(*queue != RT_NULL);
  327. DEBUG_LOG(2, "L:%d fun:%s queue:0x%08x timeout_ms:%d\n", __LINE__, __FUNCTION__, *queue, timeout_ms);
  328. if (rt_mq_send(*queue, message, ((rt_mq_t)*queue)->msg_size) != RT_EOK)
  329. {
  330. return -1;
  331. }
  332. return 0;
  333. }
  334. static int _rtthread_pop_from_xqueue( _xqueue* queue, void* message, u32 timeout_ms )
  335. {
  336. rt_uint32_t tick;
  337. RT_ASSERT(*queue != RT_NULL);
  338. DEBUG_LOG(2, "L:%d fun:%s queue:0x%08x msg:0x%08x timeout_ms:%d\n", __LINE__, __FUNCTION__, *queue, message, timeout_ms);
  339. if(timeout_ms >= RT_TICK_MAX / 2)
  340. tick = RT_WAITING_FOREVER;
  341. else
  342. tick = rtw_ms_to_systime(timeout_ms);
  343. if (rt_mq_recv(*queue, message, ((rt_mq_t)*queue)->msg_size, tick) != RT_EOK)
  344. {
  345. return -1;
  346. }
  347. return 0;
  348. }
  349. static int _rtthread_deinit_xqueue( _xqueue* queue )
  350. {
  351. RT_ASSERT(*queue != RT_NULL);
  352. DEBUG_LOG(2, "L:%d fun:%s queue:0x%08x\n", __LINE__, __FUNCTION__, *queue);
  353. rt_mq_delete(*queue);
  354. return 0;
  355. }
  356. static u32 _rtthread_get_current_time(void)
  357. {
  358. return (u32)rt_tick_get();
  359. }
  360. static u32 _rtthread_systime_to_ms(u32 systime)
  361. {
  362. return systime * 1000 / RT_TICK_PER_SECOND;
  363. }
  364. static u32 _rtthread_systime_to_sec(u32 systime)
  365. {
  366. return systime / RT_TICK_PER_SECOND;
  367. }
  368. static u32 _rtthread_ms_to_systime(u32 ms)
  369. {
  370. return rt_tick_from_millisecond(ms);
  371. }
  372. static u32 _rtthread_sec_to_systime(u32 sec)
  373. {
  374. return sec * RT_TICK_PER_SECOND;
  375. }
  376. static void _rtthread_msleep_os(int ms)
  377. {
  378. DEBUG_LOG(2, "L:%d fun:%s ms:%d\n", __LINE__, __FUNCTION__, ms);
  379. #if defined(CONFIG_PLATFORM_8195A)
  380. rt_thread_delay(rt_tick_from_millisecond(ms));
  381. #elif defined(CONFIG_PLATFORM_8711B)
  382. if (pmu_yield_os_check())
  383. rt_thread_delay(rt_tick_from_millisecond(ms));
  384. else
  385. DelayMs(ms);
  386. #endif
  387. }
  388. static void _rtthread_usleep_os(int us)
  389. {
  390. #if defined(STM32F2XX) || defined(STM32F4XX) || defined(STM32F10X_XL)
  391. // rtthread does not provide us level delay. Use busy wait
  392. WLAN_BSP_UsLoop(us);
  393. #elif defined(CONFIG_PLATFORM_8195A)
  394. //DBG_ERR("%s: Please Implement micro-second delay\n", __FUNCTION__);
  395. #elif defined(CONFIG_PLATFORM_8711B)
  396. DelayUs(us);
  397. #endif
  398. }
  399. static void _rtthread_mdelay_os(int ms)
  400. {
  401. rt_thread_delay(rt_tick_from_millisecond(ms));
  402. }
  403. static void _rtthread_udelay_os(int us)
  404. {
  405. #if defined(STM32F2XX) || defined(STM32F4XX) || defined(STM32F10X_XL)
  406. // rtthread does not provide us level delay. Use busy wait
  407. WLAN_BSP_UsLoop(us);
  408. #elif defined(CONFIG_PLATFORM_8195A)
  409. HalDelayUs(us);
  410. #elif defined(CONFIG_PLATFORM_8711B)
  411. DelayUs(us);
  412. #else
  413. #error "Please implement hardware dependent micro second level sleep here"
  414. #endif
  415. }
  416. static void _rtthread_yield_os(void)
  417. {
  418. #if defined(CONFIG_PLATFORM_8195A)
  419. rt_thread_yield();
  420. #elif defined(CONFIG_PLATFORM_8711B)
  421. if (pmu_yield_os_check())
  422. rt_thread_yield();
  423. else
  424. DelayMs(1);
  425. #endif
  426. }
  427. static void _rtthread_ATOMIC_SET(ATOMIC_T *v, int i)
  428. {
  429. atomic_set(v,i);
  430. }
  431. static int _rtthread_ATOMIC_READ(ATOMIC_T *v)
  432. {
  433. return atomic_read(v);
  434. }
  435. static void _rtthread_ATOMIC_ADD(ATOMIC_T *v, int i)
  436. {
  437. save_and_cli();
  438. v->counter += i;
  439. restore_flags();
  440. }
  441. static void _rtthread_ATOMIC_SUB(ATOMIC_T *v, int i)
  442. {
  443. save_and_cli();
  444. v->counter -= i;
  445. restore_flags();
  446. }
  447. static void _rtthread_ATOMIC_INC(ATOMIC_T *v)
  448. {
  449. _rtthread_ATOMIC_ADD(v, 1);
  450. }
  451. static void _rtthread_ATOMIC_DEC(ATOMIC_T *v)
  452. {
  453. _rtthread_ATOMIC_SUB(v, 1);
  454. }
  455. static int _rtthread_ATOMIC_ADD_RETURN(ATOMIC_T *v, int i)
  456. {
  457. int temp;
  458. save_and_cli();
  459. temp = v->counter;
  460. temp += i;
  461. v->counter = temp;
  462. restore_flags();
  463. return temp;
  464. }
  465. static int _rtthread_ATOMIC_SUB_RETURN(ATOMIC_T *v, int i)
  466. {
  467. int temp;
  468. save_and_cli();
  469. temp = v->counter;
  470. temp -= i;
  471. v->counter = temp;
  472. restore_flags();
  473. return temp;
  474. }
  475. static int _rtthread_ATOMIC_INC_RETURN(ATOMIC_T *v)
  476. {
  477. return _rtthread_ATOMIC_ADD_RETURN(v, 1);
  478. }
  479. static int _rtthread_ATOMIC_DEC_RETURN(ATOMIC_T *v)
  480. {
  481. return _rtthread_ATOMIC_SUB_RETURN(v, 1);
  482. }
  483. static u64 _rtthread_modular64(u64 n, u64 base)
  484. {
  485. unsigned int __base = (base);
  486. unsigned int __rem;
  487. if (((n) >> 32) == 0) {
  488. __rem = (unsigned int)(n) % __base;
  489. (n) = (unsigned int)(n) / __base;
  490. }
  491. else
  492. __rem = __div64_32(&(n), __base);
  493. return __rem;
  494. }
  495. /* Refer to ecos bsd tcpip codes */
  496. static int _rtthread_arc4random(void)
  497. {
  498. u32 res = _rtthread_get_current_time();
  499. static unsigned long seed = 0xDEADB00B;
  500. #if CONFIG_PLATFORM_8711B
  501. if(random_seed){
  502. seed = random_seed;
  503. random_seed = 0;
  504. }
  505. #endif
  506. seed = ((seed & 0x007F00FF) << 7) ^
  507. ((seed & 0x0F80FF00) >> 8) ^ // be sure to stir those low bits
  508. (res << 13) ^ (res >> 9); // using the clock too!
  509. return (int)seed;
  510. }
  511. static int _rtthread_get_random_bytes(void *buf, u32 len)
  512. {
  513. #if 1 //becuase of 4-byte align, we use the follow code style.
  514. unsigned int ranbuf;
  515. unsigned int *lp;
  516. int i, count;
  517. count = len / sizeof(unsigned int);
  518. lp = (unsigned int *) buf;
  519. for(i = 0; i < count; i ++) {
  520. lp[i] = _rtthread_arc4random();
  521. len -= sizeof(unsigned int);
  522. }
  523. if(len > 0) {
  524. ranbuf = _rtthread_arc4random();
  525. _rtthread_memcpy(&lp[i], &ranbuf, len);
  526. }
  527. return 0;
  528. #else
  529. unsigned long ranbuf, *lp;
  530. lp = (unsigned long *)buf;
  531. while (len > 0) {
  532. ranbuf = _rtthread_arc4random();
  533. *lp++ = ranbuf; //this op need the pointer is 4Byte-align!
  534. len -= sizeof(ranbuf);
  535. }
  536. return 0;
  537. #endif
  538. }
  539. static u32 _rtthread_GetFreeHeapSize(void)
  540. {
  541. return 16 * 1024;
  542. }
  543. #ifndef RT_USING_LWIP
  544. #define RT_LWIP_TCPTHREAD_PRIORITY 10
  545. #endif
  546. static int _rtthread_create_task(struct task_struct *ptask, const char *name,
  547. u32 stack_size, u32 priority, thread_func_t func, void *thctx)
  548. {
  549. rt_thread_t tid;
  550. DEBUG_LOG(3, "L:%d fun:%s begin name:%s stack_size:%d priority:%d func:0x%08x thctx:0x%08x\n", \
  551. __LINE__, __FUNCTION__, name, stack_size, priority, func, thctx);
  552. rt_memset(ptask, 0, sizeof(struct task_struct));
  553. ptask->task_name = name;
  554. ptask->blocked = 0;
  555. ptask->callback_running = 0;
  556. _rtthread_init_sema(&ptask->wakeup_sema, 0);
  557. if (ptask->wakeup_sema == RT_NULL)
  558. {
  559. rt_kprintf("L:%d create wakeup sem fail\n");
  560. goto _thread_err;
  561. }
  562. _rtthread_init_sema(&ptask->terminate_sema, 0);
  563. if (ptask->terminate_sema == RT_NULL)
  564. {
  565. rt_kprintf("L:%d terminate sem fail\n");
  566. goto _thread_err;
  567. }
  568. stack_size = (stack_size * 3);
  569. priority = RT_LWIP_TCPTHREAD_PRIORITY + priority;
  570. if(priority >= RT_THREAD_PRIORITY_MAX)
  571. priority = RT_THREAD_PRIORITY_MAX - 1;
  572. tid = rt_thread_create(name, func, thctx, stack_size, priority, 10);
  573. if (tid == RT_NULL)
  574. {
  575. rt_kprintf("L:%d thread create fail\n");
  576. goto _thread_err;
  577. }
  578. ptask->task = tid;
  579. rt_thread_startup(tid);
  580. DEBUG_LOG(3, "L:%d fun:%s end stack_size:%d priority:%d wakeup:0x%08x terminate:0x%08x\n", \
  581. __LINE__, __FUNCTION__, stack_size, priority, ptask->wakeup_sema, ptask->terminate_sema);
  582. return RT_TRUE;
  583. _thread_err:
  584. if (ptask->wakeup_sema)
  585. _rtthread_free_sema(&ptask->wakeup_sema);
  586. if (ptask->terminate_sema)
  587. _rtthread_free_sema(&ptask->terminate_sema);
  588. rt_memset(ptask, 0, sizeof(struct task_struct));
  589. return RT_FALSE;
  590. }
  591. static void _rtthread_delete_task(struct task_struct *ptask)
  592. {
  593. if (!ptask->task)
  594. {
  595. rt_kprintf("_rtthread_delete_task(): ptask is NULL!\n");
  596. return;
  597. }
  598. DEBUG_LOG(2, "L:%d fun:%s name:%s\n", __LINE__, __FUNCTION__, ptask->task_name);
  599. ptask->blocked = 1;
  600. _rtthread_up_sema(&ptask->wakeup_sema);
  601. _rtthread_down_sema(&ptask->terminate_sema, TIMER_MAX_DELAY);
  602. _rtthread_free_sema(&ptask->wakeup_sema);
  603. _rtthread_free_sema(&ptask->terminate_sema);
  604. ptask->task = 0;
  605. }
  606. void _rtthread_wakeup_task(struct task_struct *ptask)
  607. {
  608. DEBUG_LOG(2, "L:%d fun:%s name:%s\n", __LINE__, __FUNCTION__, ptask->task_name);
  609. _rtthread_up_sema(&ptask->wakeup_sema);
  610. }
  611. static void _rtthread_thread_enter(char *name)
  612. {
  613. DEBUG_LOG(3, "L:%d fun:%s name:%s\n", __LINE__, __FUNCTION__, name);
  614. }
  615. static void _rtthread_thread_exit(void)
  616. {
  617. DEBUG_LOG(3, "L:%d fun:%s\n", __LINE__, __FUNCTION__);
  618. }
  619. _timerHandle _rtthread_timerCreate( const signed char *pcTimerName,
  620. osdepTickType xTimerPeriodInTicks,
  621. u32 uxAutoReload,
  622. void * pvTimerID,
  623. TIMER_FUN pxCallbackFunction )
  624. {
  625. rt_timer_t timer;
  626. rt_tick_t time;
  627. rt_uint8_t flag;
  628. DEBUG_LOG(3, "L:%d fun:%s begin name:%s reload:%d tick:%d fun:0x%08x ID:0x%08x\n",
  629. __LINE__, __FUNCTION__, pcTimerName, uxAutoReload, xTimerPeriodInTicks, pxCallbackFunction, pvTimerID);
  630. if(uxAutoReload == 1)
  631. flag = (RT_TIMER_FLAG_SOFT_TIMER | RT_TIMER_FLAG_PERIODIC);
  632. else
  633. flag = (RT_TIMER_FLAG_SOFT_TIMER | RT_TIMER_FLAG_ONE_SHOT);
  634. if( xTimerPeriodInTicks >= (RT_TICK_MAX / 2) )
  635. time = (RT_TICK_MAX / 2) - 1;
  636. else
  637. time = xTimerPeriodInTicks;
  638. timer = rt_timer_create(pcTimerName, pxCallbackFunction, RT_NULL, time, flag);
  639. if(timer == RT_NULL)
  640. {
  641. rt_kprintf("timer create fail\n");
  642. return RT_NULL;
  643. }
  644. timer->parameter = timer;
  645. DEBUG_LOG(3, "L:%d fun:%s end timer:0x%08x\n", __LINE__, __FUNCTION__, timer);
  646. return (_timerHandle)timer;
  647. }
  648. u32 _rtthread_timerDelete(_timerHandle xTimer, osdepTickType xBlockTime)
  649. {
  650. DEBUG_LOG(3, "L:%d fun:%s timer:0x%08x\n", __LINE__, __FUNCTION__, xTimer);
  651. RT_ASSERT(xTimer != RT_NULL);
  652. rt_timer_delete(xTimer);
  653. return RT_TRUE;
  654. }
  655. u32 _rtthread_timerIsTimerActive( _timerHandle xTimer )
  656. {
  657. rt_timer_t pxTimer = (rt_timer_t)xTimer;
  658. DEBUG_LOG(3, "L:%d fun:%s timer:0x%08x\n", __LINE__, __FUNCTION__, xTimer);
  659. if(!xTimer)
  660. {
  661. rt_kprintf("err!! timer is active null\n");
  662. return 0;
  663. }
  664. return (pxTimer->parent.flag & RT_TIMER_FLAG_ACTIVATED) ? 1 : 0;
  665. }
  666. u32 _rtthread_timerStop(_timerHandle xTimer, osdepTickType xBlockTime)
  667. {
  668. RT_ASSERT(xTimer != RT_NULL);
  669. DEBUG_LOG(3, "L:%d fun:%s timer:0x%08x\n", __LINE__, __FUNCTION__, xTimer);
  670. if (rt_timer_stop(xTimer) != RT_EOK)
  671. {
  672. // rt_kprintf("timer stop fail\n");
  673. return RT_FALSE;
  674. }
  675. return RT_TRUE;
  676. }
  677. u32 _rtthread_timerChangePeriod( _timerHandle xTimer, osdepTickType xNewPeriod, osdepTickType xBlockTime )
  678. {
  679. int time;
  680. RT_ASSERT(xTimer != RT_NULL);
  681. DEBUG_LOG(3, "L:%d fun:%s timer:0x%08x new_tick:%d\n", __LINE__, __FUNCTION__, xTimer, xNewPeriod);
  682. if(xNewPeriod == 0)
  683. time = 1;
  684. else if(xNewPeriod >= (RT_TICK_MAX / 2))
  685. time = (RT_TICK_MAX / 2) - 1;
  686. else
  687. time = xNewPeriod;
  688. rt_timer_stop(xTimer);
  689. rt_timer_control(xTimer, RT_TIMER_CTRL_SET_TIME, (void *)&time);
  690. if(rt_timer_start(xTimer) != RT_EOK)
  691. {
  692. rt_kprintf("change time and timer start fail\n");
  693. return RT_FALSE;
  694. }
  695. return RT_TRUE;
  696. }
  697. void *_rtthread_timerGetID( _timerHandle xTimer )
  698. {
  699. return xTimer;
  700. }
  701. u32 _rtthread_timerStart( _timerHandle xTimer, osdepTickType xBlockTime )
  702. {
  703. RT_ASSERT(xTimer != RT_NULL);
  704. DEBUG_LOG(3, "L:%d fun:%s timer:0x%08x\n", __LINE__, __FUNCTION__, xTimer);
  705. if(rt_timer_start(xTimer) != RT_EOK)
  706. {
  707. rt_kprintf("change time and timer start fail\n");
  708. return RT_FALSE;
  709. }
  710. return RT_TRUE;
  711. }
  712. u32 _rtthread_timerStartFromISR( _timerHandle xTimer, osdepBASE_TYPE *pxHigherPriorityTaskWoken )
  713. {
  714. DEBUG_LOG(1, "L:%d fun:%s timer:0x%08x\n", __LINE__, __FUNCTION__, xTimer);
  715. if (xTimer == RT_NULL)
  716. {
  717. rt_kprintf("timer start from isr null\n");
  718. return RT_FALSE;
  719. }
  720. if(rt_timer_start(xTimer) != RT_EOK)
  721. {
  722. rt_kprintf("timer start from isr fail\n");
  723. return RT_FALSE;
  724. }
  725. return RT_TRUE;
  726. }
  727. u32 _rtthread_timerStopFromISR( _timerHandle xTimer, osdepBASE_TYPE *pxHigherPriorityTaskWoken )
  728. {
  729. DEBUG_LOG(1, "L:%d fun:%s timer:0x%08x\n", __LINE__, __FUNCTION__, xTimer);
  730. if (xTimer == RT_NULL)
  731. {
  732. rt_kprintf("timer start from isr null\n");
  733. return RT_FALSE;
  734. }
  735. if(rt_timer_stop(xTimer) != RT_EOK)
  736. {
  737. rt_kprintf("timer stop from isr fail\n");
  738. return RT_FALSE;
  739. }
  740. return RT_TRUE;
  741. }
  742. u32 _rtthread_timerResetFromISR( _timerHandle xTimer, osdepBASE_TYPE *pxHigherPriorityTaskWoken )
  743. {
  744. DEBUG_LOG(1, "L:%d fun:%s timer:0x%08x\n", __LINE__, __FUNCTION__, xTimer);
  745. if (xTimer == RT_NULL)
  746. {
  747. rt_kprintf("timer Reset from isr null\n");
  748. return RT_FALSE;
  749. }
  750. if(rt_timer_stop(xTimer) != RT_EOK)
  751. {
  752. rt_kprintf("timer Reset from isr stop fail\n");
  753. return RT_FALSE;
  754. }
  755. if(rt_timer_start(xTimer) != RT_EOK)
  756. {
  757. rt_kprintf("timer Reset from isr start fail\n");
  758. return RT_FALSE;
  759. }
  760. return RT_TRUE;
  761. }
  762. u32 _rtthread_timerChangePeriodFromISR( _timerHandle xTimer,
  763. osdepTickType xNewPeriod,
  764. osdepBASE_TYPE *pxHigherPriorityTaskWoken )
  765. {
  766. int time;
  767. DEBUG_LOG(1, "L:%d fun:%s timer:0x%08x\n", __LINE__, __FUNCTION__, xTimer);
  768. if (xTimer == RT_NULL)
  769. {
  770. rt_kprintf("timer Change Period from isr null\n");
  771. return RT_FALSE;
  772. }
  773. if(xNewPeriod == 0)
  774. time = 1;
  775. else if(xNewPeriod >= (RT_TICK_MAX / 2))
  776. time = (RT_TICK_MAX / 2) - 1;
  777. else
  778. time = xNewPeriod;
  779. rt_timer_stop(xTimer);
  780. rt_timer_control(xTimer, RT_TIMER_CTRL_SET_TIME, (void *)&time);
  781. if(rt_timer_start(xTimer) != RT_EOK)
  782. {
  783. rt_kprintf("timer Change Period from isr start fail\n");
  784. return RT_FALSE;
  785. }
  786. return RT_TRUE;
  787. }
  788. u32 _rtthread_timerReset( _timerHandle xTimer,
  789. osdepTickType xBlockTime )
  790. {
  791. RT_ASSERT(xTimer != RT_NULL);
  792. DEBUG_LOG(2, "L:%d fun:%s timer:0x%08x\n", __LINE__, __FUNCTION__, xTimer);
  793. rt_timer_stop(xTimer);
  794. if(rt_timer_start(xTimer) != RT_EOK)
  795. {
  796. rt_kprintf("timer reset fail\n");
  797. return RT_FALSE;
  798. }
  799. return RT_TRUE;
  800. }
  801. void _rtthread_acquire_wakelock(void)
  802. {
  803. #if defined(CONFIG_PLATFORM_8195A)
  804. #if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
  805. pmu_acquire_wakelock(PMU_WLAN_DEVICE);
  806. #endif
  807. #elif defined(CONFIG_PLATFORM_8711B)
  808. #if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
  809. if (pmu_yield_os_check())
  810. pmu_acquire_wakelock(PMU_WLAN_DEVICE);
  811. #endif
  812. #endif
  813. }
  814. void _rtthread_release_wakelock(void)
  815. {
  816. #if defined(CONFIG_PLATFORM_8195A)
  817. #if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
  818. pmu_release_wakelock(PMU_WLAN_DEVICE);
  819. #endif
  820. #elif defined(CONFIG_PLATFORM_8711B)
  821. #if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
  822. if (pmu_yield_os_check())
  823. pmu_release_wakelock(PMU_WLAN_DEVICE);
  824. #endif
  825. #endif
  826. }
  827. void _rtthread_wakelock_timeout(uint32_t timeout)
  828. {
  829. #if defined(CONFIG_PLATFORM_8195A)
  830. #elif defined(CONFIG_PLATFORM_8711B)
  831. if (pmu_yield_os_check())
  832. pmu_set_sysactive_time(/*PMU_WLAN_DEVICE, */timeout);
  833. else
  834. printf("can't aquire wake during suspend flow!!\n");
  835. #endif
  836. }
  837. u8 _rtthread_get_scheduler_state(void)
  838. {
  839. rt_thread_t thread = rt_thread_self();
  840. #if defined(RT_VERSION_CHECK) && (RTTHREAD_VERSION > RT_VERSION_CHECK(5, 1, 0))
  841. u8 state =(RT_SCHED_CTX(thread).stat & RT_THREAD_STAT_MASK);
  842. #else
  843. u8 state = thread->stat;
  844. #endif
  845. switch(state){
  846. case RT_THREAD_INIT: state = OS_SCHEDULER_NOT_STARTED; break;
  847. case RT_THREAD_RUNNING: state = OS_SCHEDULER_RUNNING; break;
  848. case RT_THREAD_SUSPEND: state = OS_SCHEDULER_SUSPENDED; break;
  849. }
  850. rt_kprintf("[func]:%s [line]:%d state:%d\n", __FUNCTION__, __LINE__, state);
  851. return state;
  852. }
  853. const struct osdep_service_ops osdep_service = {
  854. _rtthread_malloc, //rtw_vmalloc
  855. _rtthread_zmalloc, //rtw_zvmalloc
  856. _rtthread_mfree, //rtw_vmfree
  857. _rtthread_malloc, //rtw_malloc
  858. _rtthread_zmalloc, //rtw_zmalloc
  859. _rtthread_mfree, //rtw_mfree
  860. _rtthread_memcpy, //rtw_memcpy
  861. _rtthread_memcmp, //rtw_memcmp
  862. _rtthread_memset, //rtw_memset
  863. _rtthread_init_sema, //rtw_init_sema
  864. _rtthread_free_sema, //rtw_free_sema
  865. _rtthread_up_sema, //rtw_up_sema
  866. _rtthread_up_sema_from_isr, //rtw_up_sema_from_isr
  867. _rtthread_down_sema, //rtw_down_sema
  868. _rtthread_mutex_init, //rtw_mutex_init
  869. _rtthread_mutex_free, //rtw_mutex_free
  870. _rtthread_mutex_get, //rtw_mutex_get
  871. _rtthread_mutex_get_timeout,//rtw_mutex_get_timeout
  872. _rtthread_mutex_put, //rtw_mutex_put
  873. _rtthread_enter_critical, //rtw_enter_critical
  874. _rtthread_exit_critical, //rtw_exit_critical
  875. _rtthread_enter_critical_from_isr, //rtw_enter_critical_from_isr
  876. _rtthread_exit_critical_from_isr, //rtw_exit_critical_from_isr
  877. NULL, //rtw_enter_critical_bh
  878. NULL, //rtw_exit_critical_bh
  879. _rtthread_enter_critical_mutex, //rtw_enter_critical_mutex
  880. _rtthread_exit_critical_mutex, //rtw_exit_critical_mutex
  881. _rtthread_spinlock_init, //rtw_spinlock_init
  882. _rtthread_spinlock_free, //rtw_spinlock_free
  883. _rtthread_spinlock, //rtw_spin_lock
  884. _rtthread_spinunlock, //rtw_spin_unlock
  885. _rtthread_spinlock_irqsave, //rtw_spinlock_irqsave
  886. _rtthread_spinunlock_irqsave, //rtw_spinunlock_irqsave
  887. _rtthread_init_xqueue, //rtw_init_xqueue
  888. _rtthread_push_to_xqueue, //rtw_push_to_xqueue
  889. _rtthread_pop_from_xqueue, //rtw_pop_from_xqueue
  890. _rtthread_deinit_xqueue, //rtw_deinit_xqueue
  891. _rtthread_get_current_time, //rtw_get_current_time
  892. _rtthread_systime_to_ms, //rtw_systime_to_ms
  893. _rtthread_systime_to_sec, //rtw_systime_to_sec
  894. _rtthread_ms_to_systime, //rtw_ms_to_systime
  895. _rtthread_sec_to_systime, //rtw_sec_to_systime
  896. _rtthread_msleep_os, //rtw_msleep_os
  897. _rtthread_usleep_os, //rtw_usleep_os
  898. _rtthread_mdelay_os, //rtw_mdelay_os
  899. _rtthread_udelay_os, //rtw_udelay_os
  900. _rtthread_yield_os, //rtw_yield_os
  901. _rtthread_ATOMIC_SET, //ATOMIC_SET
  902. _rtthread_ATOMIC_READ, //ATOMIC_READ
  903. _rtthread_ATOMIC_ADD, //ATOMIC_ADD
  904. _rtthread_ATOMIC_SUB, //ATOMIC_SUB
  905. _rtthread_ATOMIC_INC, //ATOMIC_INC
  906. _rtthread_ATOMIC_DEC, //ATOMIC_DEC
  907. _rtthread_ATOMIC_ADD_RETURN, //ATOMIC_ADD_RETURN
  908. _rtthread_ATOMIC_SUB_RETURN, //ATOMIC_SUB_RETURN
  909. _rtthread_ATOMIC_INC_RETURN, //ATOMIC_INC_RETURN
  910. _rtthread_ATOMIC_DEC_RETURN, //ATOMIC_DEC_RETURN
  911. _rtthread_modular64, //rtw_modular64
  912. _rtthread_get_random_bytes, //rtw_get_random_bytes
  913. _rtthread_GetFreeHeapSize, //rtw_getFreeHeapSize
  914. _rtthread_create_task, //rtw_create_task
  915. _rtthread_delete_task, //rtw_delete_task
  916. _rtthread_wakeup_task, //rtw_wakeup_task
  917. _rtthread_thread_enter, //rtw_thread_enter
  918. _rtthread_thread_exit, //rtw_thread_exit
  919. _rtthread_timerCreate, //rtw_timerCreate,
  920. _rtthread_timerDelete, //rtw_timerDelete,
  921. _rtthread_timerIsTimerActive, //rtw_timerIsTimerActive,
  922. _rtthread_timerStop, //rtw_timerStop,
  923. _rtthread_timerChangePeriod, //rtw_timerChangePeriod
  924. _rtthread_timerGetID, //rtw_timerGetID
  925. _rtthread_timerStart, //rtw_timerStart
  926. _rtthread_timerStartFromISR, //rtw_timerStartFromISR
  927. _rtthread_timerStopFromISR, //rtw_timerStopFromISR
  928. _rtthread_timerResetFromISR, //rtw_timerResetFromISR
  929. _rtthread_timerChangePeriodFromISR, //rtw_timerChangePeriodFromISR
  930. _rtthread_timerReset, //rtw_timerReset
  931. _rtthread_acquire_wakelock, //rtw_acquire_wakelock
  932. _rtthread_release_wakelock, //rtw_release_wakelock
  933. _rtthread_wakelock_timeout, //rtw_wakelock_timeout
  934. _rtthread_get_scheduler_state //rtw_get_scheduler_state
  935. };
  936. void vTaskDelay( const rt_uint32_t xTicksToDelay )
  937. {
  938. rt_thread_delay(xTicksToDelay);
  939. }
  940. void *pvPortMalloc( size_t xWantedSize )
  941. {
  942. return rt_malloc(xWantedSize);
  943. }
  944. void vPortFree( void *pv )
  945. {
  946. rt_free(pv);
  947. }
  948. uint32_t xTaskGetTickCount( void )
  949. {
  950. return rt_tick_get();
  951. }