From f54b823a562c351f3b064fe24e234d7c8310702b Mon Sep 17 00:00:00 2001 From: "jan.hauer" Date: Wed, 9 Mar 2011 15:26:12 +0000 Subject: [PATCH] Added a temporary workaround that allows to compile msp430 ADC code with mspgcc version >= 4. The workaround is re-defining the ADC bitfield structs, see also https://www.millennium.berkeley.edu/pipermail/tinyos-devel/2011-March/004804.html git-svn-id: http://tinyos-main.googlecode.com/svn/trunk@5503 285f258d-8064-b571-fbc6-9656dc998e90 --- tos/chips/msp430/adc12/Msp430Adc12.h | 70 ++++++++++++++++++----- tos/chips/msp430/adc12/Msp430Adc12DMAP.nc | 6 +- 2 files changed, 60 insertions(+), 16 deletions(-) diff --git a/tos/chips/msp430/adc12/Msp430Adc12.h b/tos/chips/msp430/adc12/Msp430Adc12.h index 6e6854e8..da9e8359 100644 --- a/tos/chips/msp430/adc12/Msp430Adc12.h +++ b/tos/chips/msp430/adc12/Msp430Adc12.h @@ -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 diff --git a/tos/chips/msp430/adc12/Msp430Adc12DMAP.nc b/tos/chips/msp430/adc12/Msp430Adc12DMAP.nc index bd8c8a0a..a07d38cf 100644 --- a/tos/chips/msp430/adc12/Msp430Adc12DMAP.nc +++ b/tos/chips/msp430/adc12/Msp430Adc12DMAP.nc @@ -92,7 +92,7 @@ implementation DMA_REPEATED_SINGLE_TRANSFER, DMA_TRIGGER_ADC12IFGx, DMA_EDGE_SENSITIVE, - ADC12MEM, + (void*) ADC12MEM_, buf, length, DMA_WORD, @@ -127,7 +127,7 @@ implementation async command error_t SingleChannel.getData[uint8_t id]() { if (mode == MULTIPLE_SINGLE_AGAIN) - call DMAChannel.repeatTransfer(ADC12MEM, buffer, numSamples); + call DMAChannel.repeatTransfer((void*) ADC12MEM_, buffer, numSamples); return call SubSingleChannel.getData[id](); } @@ -154,7 +154,7 @@ implementation next = signal SingleChannel.multipleDataReady[client](buffer, numSamples); if (oldMode == MULTIPLE_REPEAT) if (next){ - call DMAChannel.repeatTransfer(ADC12MEM, next, numSamples); + call DMAChannel.repeatTransfer((void*) ADC12MEM_, next, numSamples); call AsyncAdcControl.start[client](); } else call AsyncAdcControl.stop[client](); -- 2.39.2