cpu_port.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  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. rt_uint32_t rt_interrupt_from_thread, rt_interrupt_to_thread;
  90. rt_uint32_t rt_thread_switch_interrupt_flag;
  91. /*
  92. *********************************************************************************************************
  93. * PRIVATE FUNCTION PROTOTYPES
  94. *********************************************************************************************************
  95. */
  96. //static void WinThreadScheduler(void);
  97. void WinThreadScheduler(void);
  98. rt_uint32_t YieldInterruptHandle(void);
  99. rt_uint32_t SysTickInterruptHandle(void);
  100. static DWORD WINAPI ThreadforSysTickTimer(LPVOID lpParam);
  101. static DWORD WINAPI ThreadforKeyGet(LPVOID lpParam);
  102. static void SetThreadName(DWORD dwThreadID, char* threadName)
  103. {
  104. #if defined(_MSC_VER)
  105. THREADNAME_INFO info;
  106. info.dwType = 0x1000;
  107. info.szName = threadName;
  108. info.dwThreadID = dwThreadID;
  109. info.dwFlags = 0;
  110. __try
  111. {
  112. RaiseException( MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info );
  113. }
  114. __except(EXCEPTION_EXECUTE_HANDLER)
  115. {
  116. }
  117. #endif
  118. }
  119. /*
  120. *********************************************************************************************************
  121. * rt_hw_stack_init()
  122. * Description : Initialize stack of thread
  123. * Argument(s) : void *pvEntry,void *pvParam,rt_uint8_t *pStackAddr,void *pvExit
  124. * Return(s) : rt_uint8_t*
  125. * Caller(s) : rt_thread_init or rt_thread_create
  126. * Note(s) : none
  127. *********************************************************************************************************
  128. */
  129. static DWORD WINAPI thread_run( LPVOID lpThreadParameter )
  130. {
  131. rt_thread_t tid = rt_thread_self();
  132. win_thread_t *pWinThread = (win_thread_t *)lpThreadParameter;
  133. SetThreadName(GetCurrentThreadId(), tid->parent.name);
  134. pWinThread->Entry(pWinThread->Param);
  135. pWinThread->Exit();
  136. return 0;
  137. }
  138. rt_uint8_t* rt_hw_stack_init(void *pEntry,void *pParam,rt_uint8_t *pStackAddr,void *pExit)
  139. {
  140. win_thread_t *pWinThread = NULL;
  141. /*
  142. * In this simulated case a stack is not initialized
  143. * The thread handles the context switching itself. The WinThreadState object is placed onto the stack
  144. * that was created for the task
  145. * so the stack buffer is still used,just not in the conventional way.
  146. */
  147. pWinThread = (win_thread_t *)(pStackAddr - sizeof(win_thread_t));
  148. pWinThread->Entry = pEntry;
  149. pWinThread->Param = pParam;
  150. pWinThread->Exit = pExit;
  151. pWinThread->ThreadHandle = NULL;
  152. pWinThread->ThreadID = 0;
  153. pWinThread->YieldEvent = CreateEvent(NULL,
  154. FALSE,
  155. FALSE,
  156. NULL);
  157. /* Create the winthread */
  158. pWinThread->ThreadHandle = CreateThread(NULL,
  159. 0,
  160. (LPTHREAD_START_ROUTINE) thread_run,
  161. pWinThread,
  162. CREATE_SUSPENDED,
  163. &(pWinThread->ThreadID));
  164. SetThreadAffinityMask(pWinThread->ThreadHandle,
  165. 0x01);
  166. SetThreadPriorityBoost(pWinThread->ThreadHandle,
  167. TRUE);
  168. SetThreadPriority(pWinThread->ThreadHandle,
  169. THREAD_PRIORITY_IDLE);
  170. return (rt_uint8_t*)pWinThread;
  171. } /*** rt_hw_stack_init ***/
  172. /*
  173. *********************************************************************************************************
  174. * rt_hw_interrupt_disable()
  175. * Description : disable cpu interrupts
  176. * Argument(s) : void
  177. * Return(s) : rt_base_t
  178. * Caller(s) : Applicatios or os_kernel
  179. * Note(s) : none
  180. *********************************************************************************************************
  181. */
  182. rt_base_t rt_hw_interrupt_disable(void)
  183. {
  184. if(hInterruptEventMutex != NULL)
  185. {
  186. WaitForSingleObject(hInterruptEventMutex,INFINITE);
  187. }
  188. return 0;
  189. } /*** rt_hw_interrupt_disable ***/
  190. /*
  191. *********************************************************************************************************
  192. * rt_hw_interrupt_enable()
  193. * Description : enable cpu interrupts
  194. * Argument(s) : rt_base_t level
  195. * Return(s) : void
  196. * Caller(s) : Applications or os_kernel
  197. * Note(s) : none
  198. *********************************************************************************************************
  199. */
  200. void rt_hw_interrupt_enable(rt_base_t level)
  201. {
  202. level = level;
  203. if (hInterruptEventMutex != NULL)
  204. {
  205. ReleaseMutex(hInterruptEventMutex);
  206. }
  207. } /*** rt_hw_interrupt_enable ***/
  208. /*
  209. *********************************************************************************************************
  210. * rt_hw_context_switch_interrupt()
  211. * Description : switch thread's contex
  212. * Argument(s) : void
  213. * Return(s) : void
  214. * Caller(s) : os kernel
  215. * Note(s) : none
  216. *********************************************************************************************************
  217. */
  218. void rt_hw_context_switch_interrupt(rt_uint32_t from,
  219. rt_uint32_t to)
  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_uint32_t *)(from));
  226. }
  227. rt_interrupt_to_thread = *((rt_uint32_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_uint32_t from,
  232. rt_uint32_t to)
  233. {
  234. if(rt_thread_switch_interrupt_flag != 1)
  235. {
  236. rt_thread_switch_interrupt_flag = 1;
  237. // set rt_interrupt_from_thread
  238. rt_interrupt_from_thread = *((rt_uint32_t *)(from));
  239. }
  240. // set rt_interrupt_to_thread
  241. rt_interrupt_to_thread = *((rt_uint32_t *)(to));
  242. //trigger YIELD exception(cause contex switch)
  243. TriggerSimulateInterrupt(CPU_INTERRUPT_YIELD);
  244. // make sure the event is not already signaled
  245. win_thread_t *WinThread = (win_thread_t *)rt_interrupt_from_thread;
  246. ResetEvent(WinThread->YieldEvent);
  247. /*
  248. * enable interrupt in advance so that scheduler can be executed.please note that interrupt
  249. * maybe disable twice before.
  250. */
  251. rt_hw_interrupt_enable(0);
  252. rt_hw_interrupt_enable(0);
  253. // wait to suspend.
  254. WaitForSingleObject(WinThread->YieldEvent, INFINITE);
  255. } /*** rt_hw_context_switch ***/
  256. /*
  257. *********************************************************************************************************
  258. * rt_hw_context_switch_to()
  259. * Description : switch to new thread
  260. * Argument(s) : rt_uint32_t to //the stack address of the thread which will switch to
  261. * Return(s) : void
  262. * Caller(s) : rt_thread schecale
  263. * Note(s) : this function is used to perform the first thread switch
  264. *********************************************************************************************************
  265. */
  266. void rt_hw_context_switch_to(rt_uint32_t to)
  267. {
  268. //set to thread
  269. rt_interrupt_to_thread = *((rt_uint32_t *)(to));
  270. //clear from thread
  271. rt_interrupt_from_thread = 0;
  272. //set interrupt to 1
  273. rt_thread_switch_interrupt_flag = 1;
  274. //start WinThreadScheduler
  275. WinThreadScheduler();
  276. //never reach here!
  277. return;
  278. } /*** rt_hw_context_switch_to ***/
  279. /*
  280. *********************************************************************************************************
  281. * TriggerSimulateInterrupt()
  282. * Description : Trigger a simulated interrupts handle
  283. * Argument(s) : t_uint32_t IntIndex
  284. * Return(s) : void
  285. * Caller(s) : Applications
  286. * Note(s) : none
  287. *********************************************************************************************************
  288. */
  289. void TriggerSimulateInterrupt(rt_uint32_t IntIndex)
  290. {
  291. if((IntIndex < MAX_INTERRUPT_NUM) && (hInterruptEventMutex != NULL))
  292. {
  293. /* Yield interrupts are processed even when critical nesting is non-zero */
  294. WaitForSingleObject(hInterruptEventMutex,
  295. INFINITE);
  296. CpuPendingInterrupts |= (1 << IntIndex);
  297. SetEvent(hInterruptEventHandle);
  298. ReleaseMutex(hInterruptEventMutex);
  299. }
  300. } /*** TriggerSimulateInterrupt ***/
  301. /*
  302. *********************************************************************************************************
  303. * RegisterSimulateInterrupt()
  304. * Description : Register a interrupt handle to simulate paltform
  305. * Argument(s) : rt_uint32_t IntIndex,rt_uint32_t (*IntHandler)(void)
  306. * Return(s) : void
  307. * Caller(s) : Applications
  308. * Note(s) : none
  309. *********************************************************************************************************
  310. */
  311. void RegisterSimulateInterrupt(rt_uint32_t IntIndex,rt_uint32_t (*IntHandler)(void))
  312. {
  313. if(IntIndex < MAX_INTERRUPT_NUM)
  314. {
  315. if (hInterruptEventMutex != NULL)
  316. {
  317. WaitForSingleObject(hInterruptEventMutex,
  318. INFINITE);
  319. CpuIsrHandler[IntIndex] = IntHandler;
  320. ReleaseMutex(hInterruptEventMutex);
  321. }
  322. else
  323. {
  324. CpuIsrHandler[IntIndex] = IntHandler;
  325. }
  326. }
  327. } /*** RegisterSimulateInterrupt ***/
  328. /*
  329. *********************************************************************************************************
  330. * PRIVATE FUNCTION
  331. *********************************************************************************************************
  332. */
  333. /*
  334. *********************************************************************************************************
  335. * WinThreadScheduler()
  336. * Description : Handle all simulate interrupts
  337. * Argument(s) : void
  338. * Return(s) : static void
  339. * Caller(s) : os scachle
  340. * Note(s) : none
  341. *********************************************************************************************************
  342. */
  343. #define WIN_WM_MIN_RES (1)
  344. void WinThreadScheduler(void)
  345. {
  346. HANDLE hInterruptObjectList[2];
  347. HANDLE hThreadHandle;
  348. rt_uint32_t SwitchRequiredMask;
  349. rt_uint32_t i;
  350. win_thread_t *WinThreadFrom;
  351. win_thread_t *WinThreadTo;
  352. /*
  353. * Install the interrupt handlers used bye scheduler itself
  354. */
  355. RegisterSimulateInterrupt(CPU_INTERRUPT_YIELD,
  356. YieldInterruptHandle);
  357. RegisterSimulateInterrupt(CPU_INTERRUPT_TICK,
  358. SysTickInterruptHandle);
  359. /*
  360. * Create the events and mutex that are used to synchronise all the WinThreads
  361. */
  362. hInterruptEventMutex = CreateMutex(NULL,
  363. FALSE,
  364. NULL);
  365. hInterruptEventHandle = CreateEvent(NULL,
  366. FALSE,
  367. FALSE,
  368. NULL);
  369. if((hInterruptEventMutex == NULL) || (hInterruptEventHandle == NULL))
  370. {
  371. return;
  372. }
  373. /*
  374. * Set the priority of this WinThread such that it is above the priority of the WinThreads
  375. * that run rt-threads.
  376. * This is higher priority is required to ensure simulate interrupts take priority over rt-threads
  377. */
  378. hThreadHandle = GetCurrentThread();
  379. if(hThreadHandle == NULL)
  380. {
  381. return;
  382. }
  383. if (SetThreadPriority(hThreadHandle,
  384. THREAD_PRIORITY_HIGHEST) == 0)
  385. {
  386. return;
  387. }
  388. SetThreadPriorityBoost(hThreadHandle,
  389. TRUE);
  390. SetThreadAffinityMask(hThreadHandle,
  391. 0x01);
  392. /*
  393. * Start the thread that simulates the timer peripheral to generate tick interrupts.
  394. */
  395. OSTick_Thread = CreateThread(NULL,
  396. 0,
  397. ThreadforSysTickTimer,
  398. 0,
  399. CREATE_SUSPENDED,
  400. &OSTick_ThreadID);
  401. if(OSTick_Thread == NULL)
  402. {
  403. //Display Error Message
  404. return;
  405. }
  406. SetThreadPriority(OSTick_Thread,
  407. THREAD_PRIORITY_NORMAL);
  408. SetThreadPriorityBoost(OSTick_Thread,
  409. TRUE);
  410. SetThreadAffinityMask(OSTick_Thread,
  411. 0x01);
  412. /*
  413. * Set timer Caps
  414. */
  415. if (timeGetDevCaps(&OSTick_TimerCap,
  416. sizeof(OSTick_TimerCap)) != TIMERR_NOERROR)
  417. {
  418. CloseHandle(OSTick_Thread);
  419. return;
  420. }
  421. if (OSTick_TimerCap.wPeriodMin < WIN_WM_MIN_RES)
  422. {
  423. OSTick_TimerCap.wPeriodMin = WIN_WM_MIN_RES;
  424. }
  425. if(timeBeginPeriod(OSTick_TimerCap.wPeriodMin) != TIMERR_NOERROR)
  426. {
  427. CloseHandle(OSTick_Thread);
  428. return;
  429. }
  430. OSTick_SignalPtr = CreateEvent(NULL,TRUE,FALSE,NULL);
  431. if(OSTick_SignalPtr == NULL)
  432. {
  433. // disp error message
  434. timeEndPeriod(OSTick_TimerCap.wPeriodMin);
  435. CloseHandle(OSTick_Thread);
  436. return;
  437. }
  438. OSTick_TimerID = timeSetEvent((UINT ) (1000 / RT_TICK_PER_SECOND) ,
  439. (UINT ) OSTick_TimerCap.wPeriodMin,
  440. (LPTIMECALLBACK ) OSTick_SignalPtr,
  441. (DWORD_PTR ) NULL,
  442. (UINT ) (TIME_PERIODIC | TIME_CALLBACK_EVENT_SET));
  443. if(OSTick_TimerID == 0)
  444. {
  445. //disp
  446. CloseHandle(OSTick_SignalPtr);
  447. timeEndPeriod(OSTick_TimerCap.wPeriodMin);
  448. CloseHandle(OSTick_Thread);
  449. return;
  450. }
  451. /*
  452. * Start OS Tick Thread an release Interrupt Mutex
  453. */
  454. ResumeThread(OSTick_Thread);
  455. ReleaseMutex( hInterruptEventMutex );
  456. //trigger YEILD INTERRUPT
  457. TriggerSimulateInterrupt(CPU_INTERRUPT_YIELD);
  458. /*
  459. * block on the mutex that ensure exclusive access to the simulated interrupt objects
  460. * and the events that signals that a simulated interrupt should be processed.
  461. */
  462. hInterruptObjectList[0] = hInterruptEventHandle;
  463. hInterruptObjectList[1] = hInterruptEventMutex;
  464. while (1)
  465. {
  466. WaitForMultipleObjects(sizeof(hInterruptObjectList) / sizeof(HANDLE),
  467. hInterruptObjectList,
  468. TRUE,
  469. INFINITE);
  470. /*
  471. * Used to indicate whether the simulate interrupt processing has necessitated a contex
  472. * switch to another thread
  473. */
  474. SwitchRequiredMask = 0;
  475. /*
  476. * For each interrupt we are interested in processing ,each of which is represented
  477. * by a bit in the 32bit CpuPendingInterrupts variable.
  478. */
  479. for (i = 0; i < MAX_INTERRUPT_NUM; ++i)
  480. {
  481. /* is the simulated interrupt pending ? */
  482. if (CpuPendingInterrupts & (1UL << i))
  483. {
  484. /* Is a handler installed ?*/
  485. if (CpuIsrHandler[i] != NULL)
  486. {
  487. /* Run the actual handler */
  488. if (CpuIsrHandler[i]() != 0)
  489. {
  490. SwitchRequiredMask |= (1UL << i);
  491. }
  492. }
  493. /* Clear the interrupt pending bit */
  494. CpuPendingInterrupts &= ~(1UL << i);
  495. }
  496. }
  497. if(SwitchRequiredMask != 0)
  498. {
  499. WinThreadFrom = (win_thread_t *)rt_interrupt_from_thread;
  500. WinThreadTo = (win_thread_t *)rt_interrupt_to_thread;
  501. if ((WinThreadFrom != NULL) && (WinThreadFrom->ThreadHandle != NULL))
  502. {
  503. SuspendThread(WinThreadFrom->ThreadHandle);
  504. SetEvent(WinThreadFrom->YieldEvent);
  505. }
  506. ResumeThread(WinThreadTo->ThreadHandle);
  507. }
  508. ReleaseMutex(hInterruptEventMutex);
  509. }
  510. } /*** WinThreadScheduler ***/
  511. /*
  512. *********************************************************************************************************
  513. * ThreadforSysTickTimer()
  514. * Description : win thread to simulate a systick timer
  515. * Argument(s) : LPVOID lpParam
  516. * Return(s) : static DWORD WINAPI
  517. * Caller(s) : none
  518. * Note(s) : This is not a real time way of generating tick events as the next wake time should be relative
  519. * to the previous wake time,not the time Sleep() is called.
  520. * It is done this way to prevent overruns in this very non real time simulated/emulated environment
  521. *********************************************************************************************************
  522. */
  523. static DWORD WINAPI ThreadforSysTickTimer(LPVOID lpParam)
  524. {
  525. (void)lpParam; //prevent compiler warnings
  526. for(;;)
  527. {
  528. /*
  529. * Wait until the timer expires and we can access the simulated interrupt variables.
  530. */
  531. WaitForSingleObject(OSTick_SignalPtr,INFINITE);
  532. ResetEvent(OSTick_SignalPtr);
  533. /*
  534. * Trigger a systick interrupt
  535. */
  536. TriggerSimulateInterrupt(CPU_INTERRUPT_TICK);
  537. }
  538. return 0;
  539. } /*** prvThreadforSysTickTimer ***/
  540. /*
  541. *********************************************************************************************************
  542. * SysTickInterruptHandle()
  543. * Description : Interrupt handle for systick
  544. * Argument(s) : void
  545. * Return(s) : rt_uint32_t
  546. * Caller(s) : none
  547. * Note(s) : none
  548. *********************************************************************************************************
  549. */
  550. rt_uint32_t SysTickInterruptHandle(void)
  551. {
  552. /* enter interrupt */
  553. rt_interrupt_enter();
  554. rt_tick_increase();
  555. /* leave interrupt */
  556. rt_interrupt_leave();
  557. return 0;
  558. } /*** SysTickInterruptHandle ***/
  559. /*
  560. *********************************************************************************************************
  561. * YieldInterruptHandle()
  562. * Description : Interrupt handle for Yield
  563. * Argument(s) : void
  564. * Return(s) : rt_uint32_t
  565. * Caller(s) : none
  566. * Note(s) : none
  567. *********************************************************************************************************
  568. */
  569. rt_uint32_t YieldInterruptHandle(void)
  570. {
  571. /*
  572. * if rt_thread_switch_interrupt_flag = 1 yield already handled
  573. */
  574. if(rt_thread_switch_interrupt_flag != 0)
  575. {
  576. rt_thread_switch_interrupt_flag = 0;
  577. /* return thread switch request = 1 */
  578. return 1;
  579. }
  580. return 0;
  581. } /*** YieldInterruptHandle ***/
  582. /* system entry */
  583. extern int rtthread_startup(void);
  584. int wmain(int argc, char* argv[])
  585. {
  586. /* disable interrupt first */
  587. rt_hw_interrupt_disable();
  588. /* startup RT-Thread RTOS */
  589. rtthread_startup();
  590. }
  591. #pragma comment(linker, "/subsystem:console /entry:wmainCRTStartup")