]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/chips/msp430/adc12/Msp430Adc12.h
Added a temporary workaround that allows to compile msp430 ADC code with mspgcc versi...
[tinyos-2.x.git] / tos / chips / msp430 / adc12 / Msp430Adc12.h
index 6e6854e8850ef04fb08f747a0243c6b900d7e80a..da9e8359bd8e590b3f051e1fe5af86e04dec4f16 100644 (file)
@@ -164,19 +164,63 @@ enum sampcon_id_enum
 // The unique string for accessing HAL2 via ReadStream
 #define ADCC_READ_STREAM_SERVICE "AdcC.ReadStream.Client"
 
-/* Test for GCC bug (bitfield access) - only version 3.2.3 is known to be stable */
-// TODO: check whether this is still relevant...
-#define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__ * 10 + __GNUC_PATCHLEVEL__)
-#if GCC_VERSION == 332
-#error "The msp430-gcc version (3.3.2) contains a bug which results in false accessing \
-of bitfields in structs and makes MSP430ADC12M.nc fail ! Use version 3.2.3 instead."
-#elif GCC_VERSION != 323
-#warning "This version of msp430-gcc might contain a bug which results in false accessing \
-of bitfields in structs (MSP430ADC12M.nc would fail). Use version 3.2.3 instead."
-#endif  
-
-#ifndef __msp430_have_adc12
-#error MSP430ADC12C: Target msp430 device does not have ADC12 module
+
+
+#ifdef __MSP430_TI_HEADERS__
+//#if __GNUC__ >= 4
+  
+  // "The bitfield structures that overlay peripheral registers are not part of
+  // mspgcc in the future; the recommended way of accessing those fields is to
+  // use the masks defined in the TI headers."
+  // (https://www.millennium.berkeley.edu/pipermail/tinyos-devel/2011-March/004804.html)
+  //
+  // Until the ADC driver is updated our temporary workaround is to re-define
+  // the old structures -- this may may result in faulty ADC code and should be
+  // checked carefully for your specific device (note: msp430x1611 is safe)!
+
+#warning "Accessing Adc12 registers via bitfield structures: this is discouraged mspgcc version >= 4 as it may result in faulty code!" 
+
+typedef struct {
+  volatile unsigned
+    adc12sc:1,
+    enc:1,
+    adc12tovie:1,
+    adc12ovie:1,
+    adc12on:1,
+    refon:1,
+    r2_5v:1,
+    msc:1,
+    sht0:4,
+    sht1:4;
+} __attribute__ ((packed)) adc12ctl0_t;
+
+typedef struct {
+  volatile unsigned
+    adc12busy:1,
+    conseq:2,
+    adc12ssel:2,
+    adc12div:3,
+    issh:1,
+    shp:1,
+    shs:2,
+    cstartadd:4;
+} __attribute__ ((packed)) adc12ctl1_t;
+
+#else
+
+  /* Test for GCC bug (bitfield access) - only version 3.2.3 is known to be stable */
+  #define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__ * 10 + __GNUC_PATCHLEVEL__)
+  #if GCC_VERSION == 332
+    #error "This msp430-gcc version (3.3.2) is known to contain a bug when accessing bitfield structs."
+  #elif GCC_VERSION != 323
+    #warning "This version of msp430-gcc might contain a bug when accessing bitfield structs (version 3.2.3 is safe - anything else is on your own risk)"
+  #endif  
+
+#endif
+
+
+#if !defined(__msp430_have_adc12) && !defined(__MSP430_HAS_ADC12__)
+#error Target msp430 device does not have ADC12 module
 #endif
 
 #endif