]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/chips/msp430/adc12/Msp430Adc12.h
Mass platform updates for GCC 4.6.3
[tinyos-2.x.git] / tos / chips / msp430 / adc12 / Msp430Adc12.h
index a8f9aa6712f9bb08c7b17ed7ed33a3b5d278bfb5..b3c22323427f2e58e4f91258edea57969f74077f 100644 (file)
@@ -1,5 +1,5 @@
 /* 
- * Copyright (c) 2004, Technische Universitaet Berlin
+ * Copyright (c) 2006, Technische Universitaet Berlin
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 #define MSP430ADC12_H
 #include "Msp430RefVoltGenerator.h"
 
-#define P6PIN_AUTO_CONFIGURE
+#define ADC12_TIMERA_ENABLED
+#define ADC12_P6PIN_AUTO_CONFIGURE
+#define ADC12_CHECK_ARGS
+//#define ADC12_ONLY_WITH_DMA
+
+// for HIL clients 
 #define REF_VOLT_AUTO_CONFIGURE
-#define CHECK_ARGS
-
-/*
- * The msp430adc12_channel_config_t encapsulates all relevant flags for
- * sampling a single ADC12 channel on a per-client basis.  They are taken from
- * the following MSP430 registers: ADC12CTL0, ADC12CTL1, ADC12MCTLx and TACTL
- * of TimerA (if applicable) and named according to section "17.3 ADC12
- * Registers" of the "MSP430x1xx Family User's Guide",
- * http://focus.ti.com/lit/ug/slau049e/slau049e.pdf).
- *
- * .inch: ADC12 input channel (ADC12MCTLx register). An (external) input channel 
- *        maps to one of msp430's A0-A7 pins (see device specific data sheet).
- *
- * .sref: reference voltage (ADC12MCTLx register). If
- *        REFERENCE_VREFplus_AVss or REFERENCE_VREFplus_VREFnegterm is chosen
- *        AND the client wires to Msp430Adc12RefVoltAutoClientC (or
- *        REF_VOLT_AUTO_CONFIGURE is defined and the client wires to
- *        AdcReadClientC, AdcReadNowClientC or AdcReadStreamClientC) then the
- *        reference voltage generator is automatically switched on to the
- *        voltage level defined by the "ref2_5v" flag (see below) whenever the
- *        client accesses the ADC12. Otherwise both flags are ignored.
- * 
- * .ref2_5v: Reference generator voltage level (ADC12CTL0 register). See
- *        explanation to "sref" flag.
- * 
- * .adc12ssel: ADC12 clock source select for the sample-hold-time
- *        (ADC12CTL1 register). In combination the "adc12ssel", "adc12div" and
- *        "sht" define the sample-hold-time: "adc12ssel" defines the clock
- *        source, "adc12div" defines the ADC12 clock divider and "sht" define
- *        the time expressed in jiffies.
- *
- * .adc12div: ADC12 clock divider (ADC12CTL1 register). See "adc12ssel".
- *
- * .sht: Sample-and-hold time (ADC12CTL1 register). See "adc12ssel".
- * 
- * .sampcon_ssel: In combination with "sampcon_id" and the "jiffies"
- *        parameter in the Msp430Adc12SingleChannel interface commands the
- *        "sampcon_ssel" defines the sampling rate (TASSEL in TACTL register,
- *        TimerA). It is the clock source for the SAMPCON signal, which
- *        triggers the actual sampling. It is ignored when
- *        Msp430Adc12SingleChannel.getSingleData() is used or the "jiffies"
- *        parameter is zero; otherwise the SAMPCON signal is sourced from
- *        TimerA, so that the multiple conversion mode can be made with the
- *        user defined sampling rate.
- * 
- * .sampcon_id: Input divider for "sampcon_ssel"  (IDx in TACTL
- *        register, TimerA). See "sampcon_ssel".
- *
- * 
- *                   **********************************
- *                    
- * EXAMPLE: Assuming that SMCLK runs at 1 MHz the following command fills the
- * user buffer with 2000 conversion results sampled on channel A2 with a
- * sampling rate of 4000 Hz, i.e. the multipleDataReady() event is signalled
- * after 500 ms. Note that the sampling rate is defined by the combination of
- * SAMPCON_SOURCE_SMCLK, SAMPCON_CLOCK_DIV_1 and the "jiffies" parameter of
- * 250.  
- *
- * 
- * uint16_t buffer[2000];
- * msp430adc12_channel_config_t config = {
- *   INPUT_CHANNEL_A2, REFERENCE_VREFplus_AVss, REFVOLT_LEVEL_1_5,
- *   SHT_SOURCE_SMCLK, SHT_CLOCK_DIV_1, SAMPLE_HOLD_64_CYCLES,
- *   SAMPCON_SOURCE_SMCLK, SAMPCON_CLOCK_DIV_1 
- * };
- * 
- * event void Resource.granted() 
- * { 
- *  if (call SingleChannel.getMultipleData(&config, buffer, 2000, 250)
- *       == SUCCESS)
- *   {
- *     // .. multipleDataReady() event will be signalled in 500ms
- *   } else {
- *     // check error
- *   } 
- * }
- */
 
 typedef struct { 
+  // see README.txt
   unsigned int inch: 4;            // input channel 
   unsigned int sref: 3;            // reference voltage 
   unsigned int ref2_5v: 1;         // reference voltage level 
@@ -130,6 +58,15 @@ typedef struct {
   unsigned int : 0;                // align to a word boundary 
 } msp430adc12_channel_config_t;
 
+typedef struct 
+{
+  // see README.txt
+  volatile unsigned
+  inch: 4,                                     // input channel
+  sref: 3,                                     // reference voltage
+  eos: 1;                                      // end of sequence flag
+} __attribute__ ((packed)) adc12memctl_t;
+
 enum inch_enum
 {  
    // see device specific data sheet which pin Ax is mapped to
@@ -228,23 +165,62 @@ enum sampcon_id_enum
 #define ADCC_READ_STREAM_SERVICE "AdcC.ReadStream.Client"
 
 
-typedef struct 
-{
+
+#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: msp430f1611 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
-  inch: 4,                                     // input channel
-  sref: 3,                                     // reference voltage
-  eos: 1;                                      // end of sequence flag
-} __attribute__ ((packed)) adc12memctl_t;
+    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  
 
-/* Test for GCC bug (bitfield access) - only version 3.2.3 is known to be stable */
-// check: is this relevant anymore ?
-#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  
+#endif
+
+
+#if !defined(__msp430_have_adc12) && !defined(__MSP430_HAS_ADC12__)
+#error Target msp430 device does not have ADC12 module
+#endif
 
 #endif