]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Source/portable/GCC/ARM_CM4F/portmacro.h
Update PIC32 port to make use of configUSE_PORT_OPTIMISED_TASK_SELECTION.
[freertos] / FreeRTOS / Source / portable / GCC / ARM_CM4F / portmacro.h
index 798be5e0931070b1181efd113656e8cac4ebfc4d..afd7256e1427b5a022245e64350eaa4ae6c5de62 100644 (file)
@@ -170,6 +170,33 @@ portALIGNMENT_ASSERT_pxCurrentTCB() will trigger false positive asserts. */
 \r
 #define portNOP()\r
 \r
+#if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1\r
+\r
+       /* Generic helper function. */\r
+       __attribute__( ( always_inline ) ) static inline unsigned char ucPortCountLeadingZeros( ulBitmap )\r
+       {\r
+       unsigned char ucReturn;\r
+\r
+               __asm volatile ( "clz %0, %1" : "=r" ( ucReturn ) : "r" ( ulBitmap ) );\r
+               return ucReturn;\r
+       }\r
+\r
+       /* Check the configuration. */\r
+       #if( configMAX_PRIORITIES > 32 )\r
+               #error configUSE_PORT_OPTIMISED_TASK_SELECTION can only be set to 1 when configMAX_PRIORITIES is less than or equal to 32.  It is very rare that a system requires more than 10 to 15 difference priorities as tasks that share a priority will time slice.\r
+       #endif\r
+\r
+       /* Store/clear the ready priorities in a bit map. */\r
+       #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )\r
+       #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )\r
+\r
+       /*-----------------------------------------------------------*/\r
+\r
+       #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31 - ucPortCountLeadingZeros( ( uxReadyPriorities ) ) )\r
+\r
+#endif /* taskRECORD_READY_PRIORITY */\r
+\r
+\r
 #ifdef __cplusplus\r
 }\r
 #endif\r