This patch detects presence of SLEEP_SMODE<n>_bm bit definition and
defines set_sleep_mode accordingly, for XMEGA devices. Previously, the
code assumed that all xmegas have 3 bits - this patch removes that
assumption and generalizes it work with devices that have fewer bits.

Committed as rev #2458.

Regards
Senthil

2014-11-20  Senthil Kumar Selvaraj <senthil_kumar.selva...@atmel.com>

    * include/avr/sleep.h (set_sleep_mode): Branch on presence of 
    SLEEP_SMODE<n>_bm for xmegas.

Index: include/avr/sleep.h
===================================================================
--- include/avr/sleep.h (revision 2457)
+++ include/avr/sleep.h (working copy)
@@ -180,8 +180,9 @@
         EMCUCR = ((EMCUCR & ~_BV(SM0)) | ((mode) == SLEEP_MODE_PWR_SAVE || 
(mode) == SLEEP_MODE_EXT_STANDBY ? _BV(SM0) : 0)); \
     } while(0)
 
-/* All xmegas work the same way */
+/* For xmegas, check presence of SLEEP_SMODE<n>_bm and define set_sleep_mode 
accordingly. */
 #elif defined(__AVR_XMEGA__)
+#if defined(SLEEP_SMODE2_bm)
 
     #define set_sleep_mode(mode) \
     do { \
@@ -188,6 +189,23 @@
         _SLEEP_CONTROL_REG = ((_SLEEP_CONTROL_REG & ~(SLEEP_SMODE2_bm | 
SLEEP_SMODE1_bm | SLEEP_SMODE0_bm)) | (mode)); \
     } while(0)
 
+#elif defined(SLEEP_SMODE1_bm)
+
+    #define set_sleep_mode(mode) \
+    do { \
+        _SLEEP_CONTROL_REG = ((_SLEEP_CONTROL_REG & ~(SLEEP_SMODE1_bm | 
SLEEP_SMODE0_bm)) | (mode)); \
+    } while(0)
+
+#else
+
+    #define set_sleep_mode(mode) \
+    do { \
+        _SLEEP_CONTROL_REG = ((_SLEEP_CONTROL_REG & ~( SLEEP_SMODE0_bm)) | 
(mode)); \
+    } while(0)
+
+
+#endif /* #if defined(SLEEP_SMODE2_bm) */
+
 /* For everything else, check for presence of SM<n> and define set_sleep_mode 
accordingly. */
 #else
 #if defined(SM2)




_______________________________________________
AVR-libc-dev mailing list
AVR-libc-dev@nongnu.org
https://lists.nongnu.org/mailman/listinfo/avr-libc-dev

Reply via email to