]> granicus.if.org Git - esp-idf/commitdiff
Change inline assembly bits from macros to inline functions
authorJeroen Domburg <git@j0h.nl>
Thu, 20 Oct 2016 03:23:59 +0000 (11:23 +0800)
committerJeroen Domburg <git@j0h.nl>
Thu, 20 Oct 2016 03:23:59 +0000 (11:23 +0800)
components/freertos/include/freertos/portable.h
components/freertos/include/freertos/portmacro.h
components/freertos/port.c

index 58e6903664b824a26109d9310dc418e4159d7747..a3d39bd5a2ee70e34f39550847c6e44ea8e05e94 100644 (file)
@@ -192,7 +192,14 @@ void vPortEndScheduler( void ) PRIVILEGED_FUNCTION;
 #endif
 
 /* Multi-core: get current core ID */
-#define xPortGetCoreID() __extension__({int id; asm volatile("rsr.prid %0; extui %0,%0,13,1":"=r"(id)); id;})
+inline uint32_t xPortGetCoreID() {
+    int id;
+    asm volatile(
+        "rsr.prid %0\n"
+        " extui %0,%0,13,1"
+        :"=r"(id));
+    return id;
+}
 
 #ifdef __cplusplus
 }
index ab83b0e05af7acc12e4ac63447935e01e939eadd..5e2386d721ebf47f61fde8cbd507e5c633d1301f 100644 (file)
@@ -225,6 +225,26 @@ static inline unsigned portENTER_CRITICAL_NESTED() { unsigned state = XTOS_SET_I
 #define portCLEAR_INTERRUPT_MASK_FROM_ISR(state)     portEXIT_CRITICAL_NESTED(state)
 
 
+/*
+ * Wrapper for the Xtensa compare-and-set instruction. This subroutine will atomically compare
+ * *mux to compare, and if it's the same, will set *mux to set. It will return the old value
+ * of *addr in *set.
+ *
+ * Warning: From the ISA docs: in some (unspecified) cases, the s32c1i instruction may return the
+ * *bitwise inverse* of the old mem if the mem wasn't written. This doesn't seem to happen on the
+ * ESP32, though. (Would show up directly if it did because the magic wouldn't match.)
+ */
+inline void uxPortCompareSet(volatile uint32_t *addr, uint32_t compare, uint32_t *set) {
+    __asm__ __volatile__(
+        "WSR       %2,SCOMPARE1 \n"
+        "ISYNC      \n"
+        "S32C1I     %0, %1, 0   \n"
+        :"=r"(*set)
+        :"r"(addr), "r"(compare), "0"(*set)
+        );
+}
+
+
 /*-----------------------------------------------------------*/
 
 /* Architecture specifics. */
index ef72b1cb5e34b6f6b595de821f0cb98092ecfe0e..a982db7d42f6dcae92ccdc5b41ed07eacb9cbcaf 100644 (file)
@@ -253,25 +253,6 @@ void vPortAssertIfInISR()
        configASSERT(port_interruptNesting[xPortGetCoreID()]==0)
 }
 
-
-/*
- * Wrapper for the Xtensa compare-and-set instruction. This subroutine will atomically compare
- * *mux to compare, and if it's the same, will set *mux to set. It will return the old value
- * of *addr.
- *
- * Warning: From the ISA docs: in some (unspecified) cases, the s32c1i instruction may return the
- * *bitwise inverse* of the old mem if the mem wasn't written. This doesn't seem to happen on the
- * ESP32, though. (Would show up directly if it did because the magic wouldn't match.)
- */
-#define uxPortCompareSet(mux, compare, set) \
-               __asm__ __volatile__( \
-                       "WSR        %2,SCOMPARE1 \n" \
-                       "ISYNC      \n" \
-                       "S32C1I     %0, %1, 0    \n"  \
-                       :"=r"(*set) \
-                       :"r"(mux), "r"(compare), "0"(*set) \
-                       ); \
-
 /*
  * For kernel use: Initialize a per-CPU mux. Mux will be initialized unlocked.
  */