port.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. /*
  2. * FreeRTOS Kernel V10.4.6
  3. * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * SPDX-License-Identifier: MIT
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  8. * this software and associated documentation files (the "Software"), to deal in
  9. * the Software without restriction, including without limitation the rights to
  10. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  11. * the Software, and to permit persons to whom the Software is furnished to do so,
  12. * subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in all
  15. * copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  19. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  20. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  21. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * https://www.FreeRTOS.org
  25. * https://github.com/FreeRTOS
  26. *
  27. */
  28. /*-----------------------------------------------------------
  29. * Implementation of functions defined in portable.h for the RXv3 DPFPU port.
  30. *----------------------------------------------------------*/
  31. #warning Testing for DFPU support in this port is not yet complete
  32. /* Scheduler includes. */
  33. #include "FreeRTOS.h"
  34. #include "task.h"
  35. /* Library includes. */
  36. #include "string.h"
  37. /* Hardware specifics. */
  38. #if ( configINCLUDE_PLATFORM_H_INSTEAD_OF_IODEFINE_H == 1 )
  39. #include "platform.h"
  40. #else /* configINCLUDE_PLATFORM_H_INSTEAD_OF_IODEFINE_H */
  41. #include "iodefine.h"
  42. #endif /* configINCLUDE_PLATFORM_H_INSTEAD_OF_IODEFINE_H */
  43. /*-----------------------------------------------------------*/
  44. /* Tasks should start with interrupts enabled and in Supervisor mode, therefore
  45. * PSW is set with U and I set, and PM and IPL clear. */
  46. #define portINITIAL_PSW ( ( StackType_t ) 0x00030000 )
  47. #define portINITIAL_FPSW ( ( StackType_t ) 0x00000100 )
  48. #define portINITIAL_DPSW ( ( StackType_t ) 0x00000100 )
  49. #define portINITIAL_DCMR ( ( StackType_t ) 0x00000000 )
  50. #define portINITIAL_DECNT ( ( StackType_t ) 0x00000001 )
  51. /* Tasks are not created with a DPFPU context, but can be given a DPFPU context
  52. * after they have been created. A variable is stored as part of the tasks context
  53. * that holds portNO_DPFPU_CONTEXT if the task does not have a DPFPU context, or
  54. * any other value if the task does have a DPFPU context. */
  55. #define portNO_DPFPU_CONTEXT ( ( StackType_t ) 0 )
  56. #define portHAS_DPFPU_CONTEXT ( ( StackType_t ) 1 )
  57. /* The space on the stack required to hold the DPFPU data registers. This is 16
  58. * 64-bit registers. */
  59. #define portDPFPU_DATA_REGISTER_WORDS ( 16 * 2 )
  60. /* These macros allow a critical section to be added around the call to
  61. * xTaskIncrementTick(), which is only ever called from interrupts at the kernel
  62. * priority - ie a known priority. Therefore these local macros are a slight
  63. * optimisation compared to calling the global SET/CLEAR_INTERRUPT_MASK macros,
  64. * which would require the old IPL to be read first and stored in a local variable. */
  65. #define portMASK_INTERRUPTS_FROM_KERNEL_ISR() __asm volatile ( "MVTIPL %0" ::"i" ( configMAX_SYSCALL_INTERRUPT_PRIORITY ) )
  66. #define portUNMASK_INTERRUPTS_FROM_KERNEL_ISR() __asm volatile ( "MVTIPL %0" ::"i" ( configKERNEL_INTERRUPT_PRIORITY ) )
  67. /*-----------------------------------------------------------*/
  68. /*
  69. * Function to start the first task executing - written in asm code as direct
  70. * access to registers is required.
  71. */
  72. static void prvStartFirstTask( void ) __attribute__( ( naked ) );
  73. /*
  74. * Software interrupt handler. Performs the actual context switch (saving and
  75. * restoring of registers). Written in asm code as direct register access is
  76. * required.
  77. */
  78. #if ( configINCLUDE_PLATFORM_H_INSTEAD_OF_IODEFINE_H == 1 )
  79. R_BSP_PRAGMA_INTERRUPT( vSoftwareInterruptISR, VECT( ICU, SWINT ) )
  80. R_BSP_ATTRIB_INTERRUPT void vSoftwareInterruptISR( void ) __attribute__( ( naked ) );
  81. #else /* configINCLUDE_PLATFORM_H_INSTEAD_OF_IODEFINE_H */
  82. void vSoftwareInterruptISR( void ) __attribute__( ( naked ) );
  83. #endif /* configINCLUDE_PLATFORM_H_INSTEAD_OF_IODEFINE_H */
  84. /*
  85. * The tick ISR handler. The peripheral used is configured by the application
  86. * via a hook/callback function.
  87. */
  88. #if ( configINCLUDE_PLATFORM_H_INSTEAD_OF_IODEFINE_H == 1 )
  89. R_BSP_PRAGMA_INTERRUPT( vTickISR, _VECT( configTICK_VECTOR ) )
  90. R_BSP_ATTRIB_INTERRUPT void vTickISR( void ); /* Do not add __attribute__( ( interrupt ) ). */
  91. #else /* configINCLUDE_PLATFORM_H_INSTEAD_OF_IODEFINE_H */
  92. void vTickISR( void ) __attribute__( ( interrupt ) );
  93. #endif /* configINCLUDE_PLATFORM_H_INSTEAD_OF_IODEFINE_H */
  94. /*-----------------------------------------------------------*/
  95. /* Saved as part of the task context. If ulPortTaskHasDPFPUContext is non-zero
  96. * then a DPFPU context must be saved and restored for the task. */
  97. #if ( configUSE_TASK_DPFPU_SUPPORT == 1 )
  98. StackType_t ulPortTaskHasDPFPUContext = portNO_DPFPU_CONTEXT;
  99. #endif /* configUSE_TASK_DPFPU_SUPPORT */
  100. /* This is accessed by the inline assembler functions so is file scope for
  101. * convenience. */
  102. extern void * pxCurrentTCB;
  103. extern void vTaskSwitchContext( void );
  104. /*-----------------------------------------------------------*/
  105. /*
  106. * See header file for description.
  107. */
  108. StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,
  109. TaskFunction_t pxCode,
  110. void * pvParameters )
  111. {
  112. /* R0 is not included as it is the stack pointer. */
  113. *pxTopOfStack = 0x00;
  114. pxTopOfStack--;
  115. *pxTopOfStack = portINITIAL_PSW;
  116. pxTopOfStack--;
  117. *pxTopOfStack = ( StackType_t ) pxCode;
  118. /* When debugging it can be useful if every register is set to a known
  119. * value. Otherwise code space can be saved by just setting the registers
  120. * that need to be set. */
  121. #ifdef USE_FULL_REGISTER_INITIALISATION
  122. {
  123. pxTopOfStack--;
  124. *pxTopOfStack = 0xffffffff; /* r15. */
  125. pxTopOfStack--;
  126. *pxTopOfStack = 0xeeeeeeee;
  127. pxTopOfStack--;
  128. *pxTopOfStack = 0xdddddddd;
  129. pxTopOfStack--;
  130. *pxTopOfStack = 0xcccccccc;
  131. pxTopOfStack--;
  132. *pxTopOfStack = 0xbbbbbbbb;
  133. pxTopOfStack--;
  134. *pxTopOfStack = 0xaaaaaaaa;
  135. pxTopOfStack--;
  136. *pxTopOfStack = 0x99999999;
  137. pxTopOfStack--;
  138. *pxTopOfStack = 0x88888888;
  139. pxTopOfStack--;
  140. *pxTopOfStack = 0x77777777;
  141. pxTopOfStack--;
  142. *pxTopOfStack = 0x66666666;
  143. pxTopOfStack--;
  144. *pxTopOfStack = 0x55555555;
  145. pxTopOfStack--;
  146. *pxTopOfStack = 0x44444444;
  147. pxTopOfStack--;
  148. *pxTopOfStack = 0x33333333;
  149. pxTopOfStack--;
  150. *pxTopOfStack = 0x22222222;
  151. pxTopOfStack--;
  152. }
  153. #else /* ifdef USE_FULL_REGISTER_INITIALISATION */
  154. {
  155. pxTopOfStack -= 15;
  156. }
  157. #endif /* ifdef USE_FULL_REGISTER_INITIALISATION */
  158. *pxTopOfStack = ( StackType_t ) pvParameters; /* R1 */
  159. pxTopOfStack--;
  160. *pxTopOfStack = portINITIAL_FPSW;
  161. pxTopOfStack--;
  162. *pxTopOfStack = 0x11111111; /* Accumulator 1. */
  163. pxTopOfStack--;
  164. *pxTopOfStack = 0x22222222; /* Accumulator 1. */
  165. pxTopOfStack--;
  166. *pxTopOfStack = 0x33333333; /* Accumulator 1. */
  167. pxTopOfStack--;
  168. *pxTopOfStack = 0x44444444; /* Accumulator 0. */
  169. pxTopOfStack--;
  170. *pxTopOfStack = 0x55555555; /* Accumulator 0. */
  171. pxTopOfStack--;
  172. *pxTopOfStack = 0x66666666; /* Accumulator 0. */
  173. #if ( configUSE_TASK_DPFPU_SUPPORT == 1 )
  174. {
  175. /* The task will start without a DPFPU context. A task that
  176. * uses the DPFPU hardware must call vPortTaskUsesDPFPU() before
  177. * executing any floating point instructions. */
  178. pxTopOfStack--;
  179. *pxTopOfStack = portNO_DPFPU_CONTEXT;
  180. }
  181. #elif ( configUSE_TASK_DPFPU_SUPPORT == 2 )
  182. {
  183. /* The task will start with a DPFPU context. Leave enough
  184. * space for the registers - and ensure they are initialised if desired. */
  185. #ifdef USE_FULL_REGISTER_INITIALISATION
  186. {
  187. pxTopOfStack -= 2;
  188. *(double *)pxTopOfStack = 1515.1515; /* DR15. */
  189. pxTopOfStack -= 2;
  190. *(double *)pxTopOfStack = 1414.1414; /* DR14. */
  191. pxTopOfStack -= 2;
  192. *(double *)pxTopOfStack = 1313.1313; /* DR13. */
  193. pxTopOfStack -= 2;
  194. *(double *)pxTopOfStack = 1212.1212; /* DR12. */
  195. pxTopOfStack -= 2;
  196. *(double *)pxTopOfStack = 1111.1111; /* DR11. */
  197. pxTopOfStack -= 2;
  198. *(double *)pxTopOfStack = 1010.1010; /* DR10. */
  199. pxTopOfStack -= 2;
  200. *(double *)pxTopOfStack = 909.0909; /* DR9. */
  201. pxTopOfStack -= 2;
  202. *(double *)pxTopOfStack = 808.0808; /* DR8. */
  203. pxTopOfStack -= 2;
  204. *(double *)pxTopOfStack = 707.0707; /* DR7. */
  205. pxTopOfStack -= 2;
  206. *(double *)pxTopOfStack = 606.0606; /* DR6. */
  207. pxTopOfStack -= 2;
  208. *(double *)pxTopOfStack = 505.0505; /* DR5. */
  209. pxTopOfStack -= 2;
  210. *(double *)pxTopOfStack = 404.0404; /* DR4. */
  211. pxTopOfStack -= 2;
  212. *(double *)pxTopOfStack = 303.0303; /* DR3. */
  213. pxTopOfStack -= 2;
  214. *(double *)pxTopOfStack = 202.0202; /* DR2. */
  215. pxTopOfStack -= 2;
  216. *(double *)pxTopOfStack = 101.0101; /* DR1. */
  217. pxTopOfStack -= 2;
  218. *(double *)pxTopOfStack = 9876.54321;/* DR0. */
  219. }
  220. #else /* ifdef USE_FULL_REGISTER_INITIALISATION */
  221. {
  222. pxTopOfStack -= portDPFPU_DATA_REGISTER_WORDS;
  223. memset( pxTopOfStack, 0x00, portDPFPU_DATA_REGISTER_WORDS * sizeof( StackType_t ) );
  224. }
  225. #endif /* ifdef USE_FULL_REGISTER_INITIALISATION */
  226. pxTopOfStack--;
  227. *pxTopOfStack = portINITIAL_DECNT; /* DECNT. */
  228. pxTopOfStack--;
  229. *pxTopOfStack = portINITIAL_DCMR; /* DCMR. */
  230. pxTopOfStack--;
  231. *pxTopOfStack = portINITIAL_DPSW; /* DPSW. */
  232. }
  233. #elif ( configUSE_TASK_DPFPU_SUPPORT == 0 )
  234. {
  235. /* Omit DPFPU support. */
  236. }
  237. #else /* if ( configUSE_TASK_DPFPU_SUPPORT == 1 ) */
  238. {
  239. #error Invalid configUSE_TASK_DPFPU_SUPPORT setting - configUSE_TASK_DPFPU_SUPPORT must be set to 0, 1, 2, or left undefined.
  240. }
  241. #endif /* if ( configUSE_TASK_DPFPU_SUPPORT == 1 ) */
  242. return pxTopOfStack;
  243. }
  244. /*-----------------------------------------------------------*/
  245. #if ( configUSE_TASK_DPFPU_SUPPORT == 1 )
  246. void vPortTaskUsesDPFPU( void )
  247. {
  248. /* A task is registering the fact that it needs a DPFPU context. Set the
  249. * DPFPU flag (which is saved as part of the task context). */
  250. ulPortTaskHasDPFPUContext = portHAS_DPFPU_CONTEXT;
  251. }
  252. #endif /* configUSE_TASK_DPFPU_SUPPORT */
  253. /*-----------------------------------------------------------*/
  254. BaseType_t xPortStartScheduler( void )
  255. {
  256. extern void vApplicationSetupTimerInterrupt( void );
  257. /* Use pxCurrentTCB just so it does not get optimised away. */
  258. if( pxCurrentTCB != NULL )
  259. {
  260. /* Call an application function to set up the timer that will generate the
  261. * tick interrupt. This way the application can decide which peripheral to
  262. * use. A demo application is provided to show a suitable example. */
  263. vApplicationSetupTimerInterrupt();
  264. /* Enable the software interrupt. */
  265. _IEN( _ICU_SWINT ) = 1;
  266. /* Ensure the software interrupt is clear. */
  267. _IR( _ICU_SWINT ) = 0;
  268. /* Ensure the software interrupt is set to the kernel priority. */
  269. _IPR( _ICU_SWINT ) = configKERNEL_INTERRUPT_PRIORITY;
  270. /* Start the first task. */
  271. prvStartFirstTask();
  272. }
  273. /* Should not get here. */
  274. return pdFAIL;
  275. }
  276. /*-----------------------------------------------------------*/
  277. void vPortEndScheduler( void )
  278. {
  279. /* Not implemented in ports where there is nothing to return to.
  280. * Artificially force an assert. */
  281. configASSERT( pxCurrentTCB == NULL );
  282. }
  283. /*-----------------------------------------------------------*/
  284. static void prvStartFirstTask( void )
  285. {
  286. __asm volatile
  287. (
  288. /* When starting the scheduler there is nothing that needs moving to the
  289. * interrupt stack because the function is not called from an interrupt.
  290. * Just ensure the current stack is the user stack. */
  291. "SETPSW U \n"\
  292. /* Obtain the location of the stack associated with which ever task
  293. * pxCurrentTCB is currently pointing to. */
  294. "MOV.L #_pxCurrentTCB, R15 \n"\
  295. "MOV.L [R15], R15 \n"\
  296. "MOV.L [R15], R0 \n"\
  297. /* Restore the registers from the stack of the task pointed to by
  298. * pxCurrentTCB. */
  299. #if ( configUSE_TASK_DPFPU_SUPPORT == 1 )
  300. /* The restored ulPortTaskHasDPFPUContext is to be zero here.
  301. * So, it is never necessary to restore the DPFPU context here. */
  302. "POP R15 \n"\
  303. "MOV.L #_ulPortTaskHasDPFPUContext, R14 \n"\
  304. "MOV.L R15, [R14] \n"\
  305. #elif ( configUSE_TASK_DPFPU_SUPPORT == 2 )
  306. /* Restore the DPFPU context. */
  307. "DPOPM.L DPSW-DECNT \n"\
  308. "DPOPM.D DR0-DR15 \n"\
  309. #endif /* if ( configUSE_TASK_DPFPU_SUPPORT == 1 ) */
  310. "POP R15 \n"\
  311. /* Accumulator low 32 bits. */
  312. "MVTACLO R15, A0 \n"\
  313. "POP R15 \n"\
  314. /* Accumulator high 32 bits. */
  315. "MVTACHI R15, A0 \n"\
  316. "POP R15 \n"\
  317. /* Accumulator guard. */
  318. "MVTACGU R15, A0 \n"\
  319. "POP R15 \n"\
  320. /* Accumulator low 32 bits. */
  321. "MVTACLO R15, A1 \n"\
  322. "POP R15 \n"\
  323. /* Accumulator high 32 bits. */
  324. "MVTACHI R15, A1 \n"\
  325. "POP R15 \n"\
  326. /* Accumulator guard. */
  327. "MVTACGU R15, A1 \n"\
  328. "POP R15 \n"\
  329. /* Floating point status word. */
  330. "MVTC R15, FPSW \n"\
  331. /* R1 to R15 - R0 is not included as it is the SP. */
  332. "POPM R1-R15 \n"\
  333. /* This pops the remaining registers. */
  334. "RTE \n"\
  335. "NOP \n"\
  336. "NOP \n"
  337. );
  338. }
  339. /*-----------------------------------------------------------*/
  340. void vSoftwareInterruptISR( void )
  341. {
  342. __asm volatile
  343. (
  344. /* Re-enable interrupts. */
  345. "SETPSW I \n"\
  346. /* Move the data that was automatically pushed onto the interrupt stack when
  347. * the interrupt occurred from the interrupt stack to the user stack.
  348. *
  349. * R15 is saved before it is clobbered. */
  350. "PUSH.L R15 \n"\
  351. /* Read the user stack pointer. */
  352. "MVFC USP, R15 \n"\
  353. /* Move the address down to the data being moved. */
  354. "SUB #12, R15 \n"\
  355. "MVTC R15, USP \n"\
  356. /* Copy the data across, R15, then PC, then PSW. */
  357. "MOV.L [ R0 ], [ R15 ] \n"\
  358. "MOV.L 4[ R0 ], 4[ R15 ] \n"\
  359. "MOV.L 8[ R0 ], 8[ R15 ] \n"\
  360. /* Move the interrupt stack pointer to its new correct position. */
  361. "ADD #12, R0 \n"\
  362. /* All the rest of the registers are saved directly to the user stack. */
  363. "SETPSW U \n"\
  364. /* Save the rest of the general registers (R15 has been saved already). */
  365. "PUSHM R1-R14 \n"\
  366. /* Save the FPSW and accumulators. */
  367. "MVFC FPSW, R15 \n"\
  368. "PUSH.L R15 \n"\
  369. "MVFACGU #0, A1, R15 \n"\
  370. "PUSH.L R15 \n"\
  371. "MVFACHI #0, A1, R15 \n"\
  372. "PUSH.L R15 \n"\
  373. "MVFACLO #0, A1, R15 \n" /* Low order word. */ \
  374. "PUSH.L R15 \n"\
  375. "MVFACGU #0, A0, R15 \n"\
  376. "PUSH.L R15 \n"\
  377. "MVFACHI #0, A0, R15 \n"\
  378. "PUSH.L R15 \n"\
  379. "MVFACLO #0, A0, R15 \n" /* Low order word. */ \
  380. "PUSH.L R15 \n"\
  381. #if ( configUSE_TASK_DPFPU_SUPPORT == 1 )
  382. /* Does the task have a DPFPU context that needs saving? If
  383. * ulPortTaskHasDPFPUContext is 0 then no. */
  384. "MOV.L #_ulPortTaskHasDPFPUContext, R15 \n"\
  385. "MOV.L [R15], R15 \n"\
  386. "CMP #0, R15 \n"\
  387. /* Save the DPFPU context, if any. */
  388. "BEQ.B ?+ \n"\
  389. "DPUSHM.D DR0-DR15 \n"\
  390. "DPUSHM.L DPSW-DECNT \n"\
  391. "?: \n"\
  392. /* Save ulPortTaskHasDPFPUContext itself. */
  393. "PUSH.L R15 \n"\
  394. #elif ( configUSE_TASK_DPFPU_SUPPORT == 2 )
  395. /* Save the DPFPU context, always. */
  396. "DPUSHM.D DR0-DR15 \n"\
  397. "DPUSHM.L DPSW-DECNT \n"\
  398. #endif /* if ( configUSE_TASK_DPFPU_SUPPORT == 1 ) */
  399. /* Save the stack pointer to the TCB. */
  400. "MOV.L #_pxCurrentTCB, R15 \n"\
  401. "MOV.L [ R15 ], R15 \n"\
  402. "MOV.L R0, [ R15 ] \n"\
  403. /* Ensure the interrupt mask is set to the syscall priority while the kernel
  404. * structures are being accessed. */
  405. "MVTIPL %0 \n"\
  406. /* Select the next task to run. */
  407. "BSR.A _vTaskSwitchContext \n"\
  408. /* Reset the interrupt mask as no more data structure access is required. */
  409. "MVTIPL %1 \n"\
  410. /* Load the stack pointer of the task that is now selected as the Running
  411. * state task from its TCB. */
  412. "MOV.L #_pxCurrentTCB,R15 \n"\
  413. "MOV.L [ R15 ], R15 \n"\
  414. "MOV.L [ R15 ], R0 \n"\
  415. /* Restore the context of the new task. The PSW (Program Status Word) and
  416. * PC will be popped by the RTE instruction. */
  417. #if ( configUSE_TASK_DPFPU_SUPPORT == 1 )
  418. /* Is there a DPFPU context to restore? If the restored
  419. * ulPortTaskHasDPFPUContext is zero then no. */
  420. "POP R15 \n"\
  421. "MOV.L #_ulPortTaskHasDPFPUContext, R14 \n"\
  422. "MOV.L R15, [R14] \n"\
  423. "CMP #0, R15 \n"\
  424. /* Restore the DPFPU context, if any. */
  425. "BEQ.B ?+ \n"\
  426. "DPOPM.L DPSW-DECNT \n"\
  427. "DPOPM.D DR0-DR15 \n"\
  428. "?: \n"\
  429. #elif ( configUSE_TASK_DPFPU_SUPPORT == 2 )
  430. /* Restore the DPFPU context, always. */
  431. "DPOPM.L DPSW-DECNT \n"\
  432. "DPOPM.D DR0-DR15 \n"\
  433. #endif /* if( configUSE_TASK_DPFPU_SUPPORT == 1 ) */
  434. "POP R15 \n"\
  435. /* Accumulator low 32 bits. */
  436. "MVTACLO R15, A0 \n"\
  437. "POP R15 \n"\
  438. /* Accumulator high 32 bits. */
  439. "MVTACHI R15, A0 \n"\
  440. "POP R15 \n"\
  441. /* Accumulator guard. */
  442. "MVTACGU R15, A0 \n"\
  443. "POP R15 \n"\
  444. /* Accumulator low 32 bits. */
  445. "MVTACLO R15, A1 \n"\
  446. "POP R15 \n"\
  447. /* Accumulator high 32 bits. */
  448. "MVTACHI R15, A1 \n"\
  449. "POP R15 \n"\
  450. /* Accumulator guard. */
  451. "MVTACGU R15, A1 \n"\
  452. "POP R15 \n"\
  453. "MVTC R15, FPSW \n"\
  454. "POPM R1-R15 \n"\
  455. "RTE \n"\
  456. "NOP \n"\
  457. "NOP "
  458. ::"i" ( configMAX_SYSCALL_INTERRUPT_PRIORITY ), "i" ( configKERNEL_INTERRUPT_PRIORITY )
  459. );
  460. }
  461. /*-----------------------------------------------------------*/
  462. void vTickISR( void )
  463. {
  464. /* Re-enabled interrupts. */
  465. __asm volatile ( "SETPSW I");
  466. /* Increment the tick, and perform any processing the new tick value
  467. * necessitates. Ensure IPL is at the max syscall value first. */
  468. portMASK_INTERRUPTS_FROM_KERNEL_ISR();
  469. {
  470. if( xTaskIncrementTick() != pdFALSE )
  471. {
  472. taskYIELD();
  473. }
  474. }
  475. portUNMASK_INTERRUPTS_FROM_KERNEL_ISR();
  476. }
  477. /*-----------------------------------------------------------*/
  478. uint32_t ulPortGetIPL( void )
  479. {
  480. __asm volatile
  481. (
  482. "MVFC PSW, R1 \n"\
  483. "SHLR #24, R1 \n"\
  484. "RTS "
  485. );
  486. /* This will never get executed, but keeps the compiler from complaining. */
  487. return 0;
  488. }
  489. /*-----------------------------------------------------------*/
  490. void vPortSetIPL( uint32_t ulNewIPL )
  491. {
  492. /* Avoid compiler warning about unreferenced parameter. */
  493. ( void ) ulNewIPL;
  494. __asm volatile
  495. (
  496. "PUSH R5 \n"\
  497. "MVFC PSW, R5 \n"\
  498. "SHLL #24, R1 \n"\
  499. "AND #-0F000001H, R5 \n"\
  500. "OR R1, R5 \n"\
  501. "MVTC R5, PSW \n"\
  502. "POP R5 \n"\
  503. "RTS "
  504. );
  505. }
  506. /*-----------------------------------------------------------*/