cpu_port.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. /*
  2. ************************************************************************************************************************
  3. * File : cpu_port.c
  4. * By : xyou
  5. * Version : V1.00.00
  6. *
  7. * By : prife
  8. * Version : V1.00.01
  9. ************************************************************************************************************************
  10. */
  11. /*
  12. *********************************************************************************************************
  13. * INCLUDE FILES
  14. *********************************************************************************************************
  15. */
  16. #include <rtthread.h>
  17. #include <windows.h>
  18. #include <mmsystem.h>
  19. #include <stdio.h>
  20. #include "cpu_port.h"
  21. /*
  22. *********************************************************************************************************
  23. * WinThread STRUCTURE
  24. * Windows runs each task in a thread.
  25. * The context switch is managed by the threads.So the task stack does not have to be managed directly,
  26. * although the stack stack is still used to hold an WinThreadState structure this is the only thing it
  27. * will be ever hold.
  28. * YieldEvent used to make sure the thread does not execute before asynchronous SuspendThread() operation
  29. * actually being performed.
  30. * the structure indirectly maps the task handle to a thread handle
  31. *********************************************************************************************************
  32. */
  33. typedef struct
  34. {
  35. void *Param; //Thread param
  36. void (*Entry)(void *); //Thread entry
  37. void (*Exit)(void); //Thread exit
  38. HANDLE YieldEvent;
  39. HANDLE ThreadHandle;
  40. DWORD ThreadID;
  41. }win_thread_t;
  42. const DWORD MS_VC_EXCEPTION=0x406D1388;
  43. #pragma pack(push,8)
  44. typedef struct tagTHREADNAME_INFO
  45. {
  46. DWORD dwType; // Must be 0x1000.
  47. LPCSTR szName; // Pointer to name (in user addr space).
  48. DWORD dwThreadID; // Thread ID (-1=caller thread).
  49. DWORD dwFlags; // Reserved for future use, must be zero.
  50. } THREADNAME_INFO;
  51. #pragma pack(pop)
  52. /*
  53. *********************************************************************************************************
  54. * LOCAL DEFINES
  55. *********************************************************************************************************
  56. */
  57. #define MAX_INTERRUPT_NUM ((rt_uint32_t)sizeof(rt_uint32_t) * 8)
  58. /*
  59. * Simulated interrupt waiting to be processed.this is a bit mask where each bit represent one interrupt
  60. * so a maximum of 32 interrupts can be simulated
  61. */
  62. static volatile rt_uint32_t CpuPendingInterrupts = 0;
  63. /*
  64. * An event used to inform the simulated interrupt processing thread (a high priority thread
  65. * that simulated interrupt processing) that an interrupt is pending
  66. */
  67. static HANDLE hInterruptEventHandle = NULL;
  68. /*
  69. * Mutex used to protect all the simulated interrupt variables that are accessed by multiple threads
  70. */
  71. static HANDLE hInterruptEventMutex = NULL;
  72. /*
  73. * Handler for all the simulate software interrupts.
  74. * The first two positions are used the Yield and Tick interrupt so are handled slightly differently
  75. * all the other interrupts can be user defined
  76. */
  77. static rt_uint32_t (*CpuIsrHandler[MAX_INTERRUPT_NUM])(void) = {0};
  78. /*
  79. * Handler for OSTick Thread
  80. */
  81. static HANDLE OSTick_Thread;
  82. static DWORD OSTick_ThreadID;
  83. static HANDLE OSTick_SignalPtr;
  84. static TIMECAPS OSTick_TimerCap;
  85. static MMRESULT OSTick_TimerID;
  86. /*
  87. * flag in interrupt handling
  88. */
  89. volatile rt_ubase_t rt_interrupt_from_thread = 0;
  90. volatile rt_ubase_t rt_interrupt_to_thread = 0;
  91. volatile rt_uint32_t rt_thread_switch_interrupt_flag = 0;
  92. /*
  93. *********************************************************************************************************
  94. * PRIVATE FUNCTION PROTOTYPES
  95. *********************************************************************************************************
  96. */
  97. //static void WinThreadScheduler(void);
  98. void WinThreadScheduler(void);
  99. rt_uint32_t YieldInterruptHandle(void);
  100. rt_uint32_t SysTickInterruptHandle(void);
  101. static DWORD WINAPI ThreadforSysTickTimer(LPVOID lpParam);
  102. static DWORD WINAPI ThreadforKeyGet(LPVOID lpParam);
  103. static void SetThreadName(DWORD dwThreadID, char* threadName)
  104. {
  105. #if defined(_MSC_VER)
  106. THREADNAME_INFO info;
  107. info.dwType = 0x1000;
  108. info.szName = threadName;
  109. info.dwThreadID = dwThreadID;
  110. info.dwFlags = 0;
  111. __try
  112. {
  113. RaiseException( MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info );
  114. }
  115. __except(EXCEPTION_EXECUTE_HANDLER)
  116. {
  117. }
  118. #endif
  119. }
  120. /*
  121. *********************************************************************************************************
  122. * rt_hw_stack_init()
  123. * Description : Initialize stack of thread
  124. * Argument(s) : void *pvEntry,void *pvParam,rt_uint8_t *pStackAddr,void *pvExit
  125. * Return(s) : rt_uint8_t*
  126. * Caller(s) : rt_thread_init or rt_thread_create
  127. * Note(s) : none
  128. *********************************************************************************************************
  129. */
  130. static DWORD WINAPI thread_run( LPVOID lpThreadParameter )
  131. {
  132. rt_thread_t tid = rt_thread_self();
  133. win_thread_t *pWinThread = (win_thread_t *)lpThreadParameter;
  134. SetThreadName(GetCurrentThreadId(), tid->parent.name);
  135. pWinThread->Entry(pWinThread->Param);
  136. pWinThread->Exit();
  137. return 0;
  138. }
  139. rt_uint8_t* rt_hw_stack_init(void *pEntry,void *pParam,rt_uint8_t *pStackAddr,void *pExit)
  140. {
  141. win_thread_t *pWinThread = NULL;
  142. /*
  143. * In this simulated case a stack is not initialized
  144. * The thread handles the context switching itself. The WinThreadState object is placed onto the stack
  145. * that was created for the task
  146. * so the stack buffer is still used,just not in the conventional way.
  147. */
  148. pWinThread = (win_thread_t *)(pStackAddr - sizeof(win_thread_t));
  149. pWinThread->Entry = pEntry;
  150. pWinThread->Param = pParam;
  151. pWinThread->Exit = pExit;
  152. pWinThread->ThreadHandle = NULL;
  153. pWinThread->ThreadID = 0;
  154. pWinThread->YieldEvent = CreateEvent(NULL,
  155. FALSE,
  156. FALSE,
  157. NULL);
  158. /* Create the winthread */
  159. pWinThread->ThreadHandle = CreateThread(NULL,
  160. 0,
  161. (LPTHREAD_START_ROUTINE) thread_run,
  162. pWinThread,
  163. CREATE_SUSPENDED,
  164. &(pWinThread->ThreadID));
  165. SetThreadAffinityMask(pWinThread->ThreadHandle,
  166. 0x01);
  167. SetThreadPriorityBoost(pWinThread->ThreadHandle,
  168. TRUE);
  169. SetThreadPriority(pWinThread->ThreadHandle,
  170. THREAD_PRIORITY_IDLE);
  171. return (rt_uint8_t*)pWinThread;
  172. } /*** rt_hw_stack_init ***/
  173. /*
  174. *********************************************************************************************************
  175. * rt_hw_interrupt_disable()
  176. * Description : disable cpu interrupts
  177. * Argument(s) : void
  178. * Return(s) : rt_base_t
  179. * Caller(s) : Applicatios or os_kernel
  180. * Note(s) : none
  181. *********************************************************************************************************
  182. */
  183. rt_base_t rt_hw_interrupt_disable(void)
  184. {
  185. if(hInterruptEventMutex != NULL)
  186. {
  187. WaitForSingleObject(hInterruptEventMutex,INFINITE);
  188. }
  189. return 0;
  190. } /*** rt_hw_interrupt_disable ***/
  191. /*
  192. *********************************************************************************************************
  193. * rt_hw_interrupt_enable()
  194. * Description : enable cpu interrupts
  195. * Argument(s) : rt_base_t level
  196. * Return(s) : void
  197. * Caller(s) : Applications or os_kernel
  198. * Note(s) : none
  199. *********************************************************************************************************
  200. */
  201. void rt_hw_interrupt_enable(rt_base_t level)
  202. {
  203. level = level;
  204. if (hInterruptEventMutex != NULL)
  205. {
  206. ReleaseMutex(hInterruptEventMutex);
  207. }
  208. } /*** rt_hw_interrupt_enable ***/
  209. /*
  210. *********************************************************************************************************
  211. * rt_hw_context_switch_interrupt()
  212. * Description : switch thread's contex
  213. * Argument(s) : void
  214. * Return(s) : void
  215. * Caller(s) : os kernel
  216. * Note(s) : none
  217. *********************************************************************************************************
  218. */
  219. void rt_hw_context_switch_interrupt(rt_ubase_t from, rt_ubase_t to, rt_thread_t from_thread, rt_thread_t to_thread)
  220. {
  221. if(rt_thread_switch_interrupt_flag != 1)
  222. {
  223. rt_thread_switch_interrupt_flag = 1;
  224. // set rt_interrupt_from_thread
  225. rt_interrupt_from_thread = *((rt_ubase_t *)(from));
  226. }
  227. rt_interrupt_to_thread = *((rt_ubase_t *)(to));
  228. //trigger YIELD exception(cause context switch)
  229. TriggerSimulateInterrupt(CPU_INTERRUPT_YIELD);
  230. } /*** rt_hw_context_switch_interrupt ***/
  231. void rt_hw_context_switch(rt_ubase_t from, rt_ubase_t to)
  232. {
  233. if(rt_thread_switch_interrupt_flag != 1)
  234. {
  235. rt_thread_switch_interrupt_flag = 1;
  236. // set rt_interrupt_from_thread
  237. rt_interrupt_from_thread = *((rt_ubase_t *)(from));
  238. }
  239. // set rt_interrupt_to_thread
  240. rt_interrupt_to_thread = *((rt_ubase_t *)(to));
  241. //trigger YIELD exception(cause contex switch)
  242. TriggerSimulateInterrupt(CPU_INTERRUPT_YIELD);
  243. // make sure the event is not already signaled
  244. win_thread_t *WinThread = (win_thread_t *)rt_interrupt_from_thread;
  245. ResetEvent(WinThread->YieldEvent);
  246. /*
  247. * enable interrupt in advance so that scheduler can be executed.please note that interrupt
  248. * maybe disable twice before.
  249. */
  250. rt_hw_interrupt_enable(0);
  251. rt_hw_interrupt_enable(0);
  252. // wait to suspend.
  253. WaitForSingleObject(WinThread->YieldEvent, INFINITE);
  254. } /*** rt_hw_context_switch ***/
  255. /*
  256. *********************************************************************************************************
  257. * rt_hw_context_switch_to()
  258. * Description : switch to new thread
  259. * Argument(s) : rt_uint32_t to //the stack address of the thread which will switch to
  260. * Return(s) : void
  261. * Caller(s) : rt_thread schecale
  262. * Note(s) : this function is used to perform the first thread switch
  263. *********************************************************************************************************
  264. */
  265. void rt_hw_context_switch_to(rt_ubase_t to)
  266. {
  267. //set to thread
  268. rt_interrupt_to_thread = *((rt_ubase_t *)(to));
  269. //clear from thread
  270. rt_interrupt_from_thread = 0;
  271. //set interrupt to 1
  272. rt_thread_switch_interrupt_flag = 1;
  273. //start WinThreadScheduler
  274. WinThreadScheduler();
  275. //never reach here!
  276. return;
  277. } /*** rt_hw_context_switch_to ***/
  278. /*
  279. *********************************************************************************************************
  280. * TriggerSimulateInterrupt()
  281. * Description : Trigger a simulated interrupts handle
  282. * Argument(s) : t_uint32_t IntIndex
  283. * Return(s) : void
  284. * Caller(s) : Applications
  285. * Note(s) : none
  286. *********************************************************************************************************
  287. */
  288. void TriggerSimulateInterrupt(rt_uint32_t IntIndex)
  289. {
  290. if((IntIndex < MAX_INTERRUPT_NUM) && (hInterruptEventMutex != NULL))
  291. {
  292. /* Yield interrupts are processed even when critical nesting is non-zero */
  293. WaitForSingleObject(hInterruptEventMutex,
  294. INFINITE);
  295. CpuPendingInterrupts |= (1 << IntIndex);
  296. SetEvent(hInterruptEventHandle);
  297. ReleaseMutex(hInterruptEventMutex);
  298. }
  299. } /*** TriggerSimulateInterrupt ***/
  300. /*
  301. *********************************************************************************************************
  302. * RegisterSimulateInterrupt()
  303. * Description : Register a interrupt handle to simulate paltform
  304. * Argument(s) : rt_uint32_t IntIndex,rt_uint32_t (*IntHandler)(void)
  305. * Return(s) : void
  306. * Caller(s) : Applications
  307. * Note(s) : none
  308. *********************************************************************************************************
  309. */
  310. void RegisterSimulateInterrupt(rt_uint32_t IntIndex,rt_uint32_t (*IntHandler)(void))
  311. {
  312. if(IntIndex < MAX_INTERRUPT_NUM)
  313. {
  314. if (hInterruptEventMutex != NULL)
  315. {
  316. WaitForSingleObject(hInterruptEventMutex,
  317. INFINITE);
  318. CpuIsrHandler[IntIndex] = IntHandler;
  319. ReleaseMutex(hInterruptEventMutex);
  320. }
  321. else
  322. {
  323. CpuIsrHandler[IntIndex] = IntHandler;
  324. }
  325. }
  326. } /*** RegisterSimulateInterrupt ***/
  327. /*
  328. *********************************************************************************************************
  329. * PRIVATE FUNCTION
  330. *********************************************************************************************************
  331. */
  332. /*
  333. *********************************************************************************************************
  334. * WinThreadScheduler()
  335. * Description : Handle all simulate interrupts
  336. * Argument(s) : void
  337. * Return(s) : static void
  338. * Caller(s) : os scachle
  339. * Note(s) : none
  340. *********************************************************************************************************
  341. */
  342. #define WIN_WM_MIN_RES (1)
  343. void WinThreadScheduler(void)
  344. {
  345. HANDLE hInterruptObjectList[2];
  346. HANDLE hThreadHandle;
  347. rt_uint32_t SwitchRequiredMask;
  348. rt_uint32_t i;
  349. win_thread_t *WinThreadFrom;
  350. win_thread_t *WinThreadTo;
  351. /*
  352. * Install the interrupt handlers used bye scheduler itself
  353. */
  354. RegisterSimulateInterrupt(CPU_INTERRUPT_YIELD,
  355. YieldInterruptHandle);
  356. RegisterSimulateInterrupt(CPU_INTERRUPT_TICK,
  357. SysTickInterruptHandle);
  358. /*
  359. * Create the events and mutex that are used to synchronise all the WinThreads
  360. */
  361. hInterruptEventMutex = CreateMutex(NULL,
  362. FALSE,
  363. NULL);
  364. hInterruptEventHandle = CreateEvent(NULL,
  365. FALSE,
  366. FALSE,
  367. NULL);
  368. if((hInterruptEventMutex == NULL) || (hInterruptEventHandle == NULL))
  369. {
  370. return;
  371. }
  372. /*
  373. * Set the priority of this WinThread such that it is above the priority of the WinThreads
  374. * that run rt-threads.
  375. * This is higher priority is required to ensure simulate interrupts take priority over rt-threads
  376. */
  377. hThreadHandle = GetCurrentThread();
  378. if(hThreadHandle == NULL)
  379. {
  380. return;
  381. }
  382. if (SetThreadPriority(hThreadHandle,
  383. THREAD_PRIORITY_HIGHEST) == 0)
  384. {
  385. return;
  386. }
  387. SetThreadPriorityBoost(hThreadHandle,
  388. TRUE);
  389. SetThreadAffinityMask(hThreadHandle,
  390. 0x01);
  391. /*
  392. * Start the thread that simulates the timer peripheral to generate tick interrupts.
  393. */
  394. OSTick_Thread = CreateThread(NULL,
  395. 0,
  396. ThreadforSysTickTimer,
  397. 0,
  398. CREATE_SUSPENDED,
  399. &OSTick_ThreadID);
  400. if(OSTick_Thread == NULL)
  401. {
  402. //Display Error Message
  403. return;
  404. }
  405. SetThreadPriority(OSTick_Thread,
  406. THREAD_PRIORITY_NORMAL);
  407. SetThreadPriorityBoost(OSTick_Thread,
  408. TRUE);
  409. SetThreadAffinityMask(OSTick_Thread,
  410. 0x01);
  411. /*
  412. * Set timer Caps
  413. */
  414. if (timeGetDevCaps(&OSTick_TimerCap,
  415. sizeof(OSTick_TimerCap)) != TIMERR_NOERROR)
  416. {
  417. CloseHandle(OSTick_Thread);
  418. return;
  419. }
  420. if (OSTick_TimerCap.wPeriodMin < WIN_WM_MIN_RES)
  421. {
  422. OSTick_TimerCap.wPeriodMin = WIN_WM_MIN_RES;
  423. }
  424. if(timeBeginPeriod(OSTick_TimerCap.wPeriodMin) != TIMERR_NOERROR)
  425. {
  426. CloseHandle(OSTick_Thread);
  427. return;
  428. }
  429. OSTick_SignalPtr = CreateEvent(NULL,TRUE,FALSE,NULL);
  430. if(OSTick_SignalPtr == NULL)
  431. {
  432. // disp error message
  433. timeEndPeriod(OSTick_TimerCap.wPeriodMin);
  434. CloseHandle(OSTick_Thread);
  435. return;
  436. }
  437. OSTick_TimerID = timeSetEvent((UINT ) (1000 / RT_TICK_PER_SECOND) ,
  438. (UINT ) OSTick_TimerCap.wPeriodMin,
  439. (LPTIMECALLBACK ) OSTick_SignalPtr,
  440. (DWORD_PTR ) NULL,
  441. (UINT ) (TIME_PERIODIC | TIME_CALLBACK_EVENT_SET));
  442. if(OSTick_TimerID == 0)
  443. {
  444. //disp
  445. CloseHandle(OSTick_SignalPtr);
  446. timeEndPeriod(OSTick_TimerCap.wPeriodMin);
  447. CloseHandle(OSTick_Thread);
  448. return;
  449. }
  450. /*
  451. * Start OS Tick Thread an release Interrupt Mutex
  452. */
  453. ResumeThread(OSTick_Thread);
  454. ReleaseMutex( hInterruptEventMutex );
  455. //trigger YEILD INTERRUPT
  456. TriggerSimulateInterrupt(CPU_INTERRUPT_YIELD);
  457. /*
  458. * block on the mutex that ensure exclusive access to the simulated interrupt objects
  459. * and the events that signals that a simulated interrupt should be processed.
  460. */
  461. hInterruptObjectList[0] = hInterruptEventHandle;
  462. hInterruptObjectList[1] = hInterruptEventMutex;
  463. while (1)
  464. {
  465. WaitForMultipleObjects(sizeof(hInterruptObjectList) / sizeof(HANDLE),
  466. hInterruptObjectList,
  467. TRUE,
  468. INFINITE);
  469. /*
  470. * Used to indicate whether the simulate interrupt processing has necessitated a contex
  471. * switch to another thread
  472. */
  473. SwitchRequiredMask = 0;
  474. /*
  475. * For each interrupt we are interested in processing ,each of which is represented
  476. * by a bit in the 32bit CpuPendingInterrupts variable.
  477. */
  478. for (i = 0; i < MAX_INTERRUPT_NUM; ++i)
  479. {
  480. /* is the simulated interrupt pending ? */
  481. if (CpuPendingInterrupts & (1UL << i))
  482. {
  483. /* Is a handler installed ?*/
  484. if (CpuIsrHandler[i] != NULL)
  485. {
  486. /* Run the actual handler */
  487. if (CpuIsrHandler[i]() != 0)
  488. {
  489. SwitchRequiredMask |= (1UL << i);
  490. }
  491. }
  492. /* Clear the interrupt pending bit */
  493. CpuPendingInterrupts &= ~(1UL << i);
  494. }
  495. }
  496. if(SwitchRequiredMask != 0)
  497. {
  498. WinThreadFrom = (win_thread_t *)rt_interrupt_from_thread;
  499. WinThreadTo = (win_thread_t *)rt_interrupt_to_thread;
  500. if ((WinThreadFrom != NULL) && (WinThreadFrom->ThreadHandle != NULL))
  501. {
  502. SuspendThread(WinThreadFrom->ThreadHandle);
  503. SetEvent(WinThreadFrom->YieldEvent);
  504. }
  505. ResumeThread(WinThreadTo->ThreadHandle);
  506. }
  507. ReleaseMutex(hInterruptEventMutex);
  508. }
  509. } /*** WinThreadScheduler ***/
  510. /*
  511. *********************************************************************************************************
  512. * ThreadforSysTickTimer()
  513. * Description : win thread to simulate a systick timer
  514. * Argument(s) : LPVOID lpParam
  515. * Return(s) : static DWORD WINAPI
  516. * Caller(s) : none
  517. * Note(s) : This is not a real time way of generating tick events as the next wake time should be relative
  518. * to the previous wake time,not the time Sleep() is called.
  519. * It is done this way to prevent overruns in this very non real time simulated/emulated environment
  520. *********************************************************************************************************
  521. */
  522. static DWORD WINAPI ThreadforSysTickTimer(LPVOID lpParam)
  523. {
  524. (void)lpParam; //prevent compiler warnings
  525. for(;;)
  526. {
  527. /*
  528. * Wait until the timer expires and we can access the simulated interrupt variables.
  529. */
  530. WaitForSingleObject(OSTick_SignalPtr,INFINITE);
  531. ResetEvent(OSTick_SignalPtr);
  532. /*
  533. * Trigger a systick interrupt
  534. */
  535. TriggerSimulateInterrupt(CPU_INTERRUPT_TICK);
  536. }
  537. return 0;
  538. } /*** prvThreadforSysTickTimer ***/
  539. /*
  540. *********************************************************************************************************
  541. * SysTickInterruptHandle()
  542. * Description : Interrupt handle for systick
  543. * Argument(s) : void
  544. * Return(s) : rt_uint32_t
  545. * Caller(s) : none
  546. * Note(s) : none
  547. *********************************************************************************************************
  548. */
  549. rt_uint32_t SysTickInterruptHandle(void)
  550. {
  551. /* enter interrupt */
  552. rt_interrupt_enter();
  553. rt_tick_increase();
  554. /* leave interrupt */
  555. rt_interrupt_leave();
  556. return 0;
  557. } /*** SysTickInterruptHandle ***/
  558. /*
  559. *********************************************************************************************************
  560. * YieldInterruptHandle()
  561. * Description : Interrupt handle for Yield
  562. * Argument(s) : void
  563. * Return(s) : rt_uint32_t
  564. * Caller(s) : none
  565. * Note(s) : none
  566. *********************************************************************************************************
  567. */
  568. rt_uint32_t YieldInterruptHandle(void)
  569. {
  570. /*
  571. * if rt_thread_switch_interrupt_flag = 1 yield already handled
  572. */
  573. if(rt_thread_switch_interrupt_flag != 0)
  574. {
  575. rt_thread_switch_interrupt_flag = 0;
  576. /* return thread switch request = 1 */
  577. return 1;
  578. }
  579. return 0;
  580. } /*** YieldInterruptHandle ***/