X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=blobdiff_plain;f=tos%2Fchips%2Fmsp430%2Fadc12%2FMsp430Adc12ImplP.nc;h=e9e7f68e869dd8f07bee73dbd5bb08d86d407252;hb=e9bfab607e051bae6afb47b44892ce37541d1b44;hp=e815ee61e0ef5b1dcd5154fd81843957b6c3e289;hpb=60959169f556ee3dc648a69f5c8fb1ed9cd887c7;p=tinyos-2.x.git diff --git a/tos/chips/msp430/adc12/Msp430Adc12ImplP.nc b/tos/chips/msp430/adc12/Msp430Adc12ImplP.nc index e815ee61..e9e7f68e 100644 --- a/tos/chips/msp430/adc12/Msp430Adc12ImplP.nc +++ b/tos/chips/msp430/adc12/Msp430Adc12ImplP.nc @@ -34,7 +34,7 @@ */ #include -module Msp430Adc12ImplP +module Msp430Adc12ImplP @safe() { provides { interface Init; @@ -42,10 +42,10 @@ module Msp430Adc12ImplP interface Msp430Adc12MultiChannel as MultiChannel[uint8_t id]; interface Msp430Adc12Overflow as Overflow[uint8_t id]; interface AsyncStdControl as DMAExtension[uint8_t id]; - } - uses { + } + uses { interface ArbiterInfo as ADCArbiterInfo; - interface HplAdc12; + interface HplAdc12; interface Msp430Timer as TimerA;; interface Msp430TimerControl as ControlA0; interface Msp430TimerControl as ControlA1; @@ -59,11 +59,15 @@ module Msp430Adc12ImplP interface HplMsp430GeneralIO as Port65; interface HplMsp430GeneralIO as Port66; interface HplMsp430GeneralIO as Port67; - } + } } implementation { -#warning Accessing TimerA for ADC12 + +#ifdef ADC12_TIMERA_ENABLED + #warning Accessing TimerA for ADC12 +#endif + enum { SINGLE_DATA = 1, SINGLE_DATA_REPEAT = 2, @@ -79,8 +83,8 @@ implementation uint8_t state; /* see enum above */ - uint16_t *resultBuffer; /* conversion results */ uint16_t resultBufferLength; /* length of buffer */ + uint16_t *COUNT_NOK(resultBufferLength) resultBufferStart; uint16_t resultBufferIndex; /* offset into buffer */ uint8_t numChannels; /* number of channels (multi-channel conversion) */ uint8_t clientID; /* ID of client that called getData() */ @@ -218,6 +222,10 @@ implementation { error_t result = ERESERVE; #ifdef ADC12_CHECK_ARGS +#ifndef ADC12_TIMERA_ENABLED + if (jiffies>0) + return EINVAL; +#endif if (!config || jiffies == 1 || jiffies == 2) return EINVAL; #endif @@ -266,6 +274,10 @@ implementation { error_t result = ERESERVE; #ifdef ADC12_CHECK_ARGS +#ifndef ADC12_TIMERA_ENABLED + if (jiffies>0) + return EINVAL; +#endif if (!config || !buf || !length || jiffies == 1 || jiffies == 2) return EINVAL; #endif @@ -295,8 +307,9 @@ implementation ctl0.sht1 = config->sht; state = MULTIPLE_DATA; - resultBuffer = buf; + resultBufferStart = NULL; resultBufferLength = length; + resultBufferStart = buf; resultBufferIndex = 0; call HplAdc12.setCtl0(ctl0); call HplAdc12.setCtl1(ctl1); @@ -322,6 +335,10 @@ implementation { error_t result = ERESERVE; #ifdef ADC12_CHECK_ARGS +#ifndef ADC12_TIMERA_ENABLED + if (jiffies>0) + return EINVAL; +#endif if (!config || !buf || !length || length > 16 || jiffies == 1 || jiffies == 2) return EINVAL; #endif @@ -351,8 +368,9 @@ implementation ctl0.sht1 = config->sht; state = MULTIPLE_DATA_REPEAT; - resultBuffer = buf; + resultBufferStart = NULL; resultBufferLength = length; + resultBufferStart = buf; resultBufferIndex = 0; call HplAdc12.setCtl0(ctl0); @@ -377,7 +395,7 @@ implementation { atomic { if (call ADCArbiterInfo.userId() == id){ - if (state & MULTIPLE_DATA_REPEAT && !resultBuffer) + if ((state & MULTIPLE_DATA_REPEAT) && !resultBufferStart) return EINVAL; if (state & ADC_BUSY) return EBUSY; @@ -400,6 +418,10 @@ implementation { error_t result = ERESERVE; #ifdef ADC12_CHECK_ARGS +#ifndef ADC12_TIMERA_ENABLED + if (jiffies>0) + return EINVAL; +#endif if (!config || !memctl || !numMemctl || numMemctl > 15 || !numSamples || !buf || jiffies == 1 || jiffies == 2 || numSamples % (numMemctl+1) != 0) return EINVAL; @@ -430,8 +452,9 @@ implementation ctl0.sht1 = config->sht; state = MULTI_CHANNEL; - resultBuffer = buf; + resultBufferStart = NULL; resultBufferLength = numSamples; + resultBufferStart = buf; resultBufferIndex = 0; numChannels = numMemctl+1; call HplAdc12.setCtl0(ctl0); @@ -460,7 +483,7 @@ implementation uint8_t i; atomic { if (call ADCArbiterInfo.userId() == id){ - if (!resultBuffer) + if (!resultBufferStart) return EINVAL; if (state & ADC_BUSY) return EBUSY; @@ -521,6 +544,8 @@ implementation async event void HplAdc12.conversionDone(uint16_t iv) { bool overflow = FALSE; + uint16_t *resultBuffer; + if (iv <= 4){ // check for overflow if (iv == 2) signal Overflow.memOverflow[clientID](); @@ -549,6 +574,7 @@ implementation case MULTI_CHANNEL: { uint16_t i = 0, k; + resultBuffer = resultBufferStart + resultBufferIndex; do { *resultBuffer++ = call HplAdc12.getMem(i); } while (++i < numChannels); @@ -560,12 +586,13 @@ implementation resultBufferIndex = 0; signal MultiChannel.dataReady[clientID](resultBuffer, overflow ? k : resultBufferLength); - } else call HplAdc12.enableConversion(); + } } break; case MULTIPLE_DATA: { uint16_t i = 0, length, k; + resultBuffer = resultBufferStart + resultBufferIndex; if (resultBufferLength - resultBufferIndex > 16) length = 16; else @@ -594,14 +621,15 @@ implementation case MULTIPLE_DATA_REPEAT: { uint8_t i = 0; + resultBuffer = resultBufferStart; do { *resultBuffer++ = call HplAdc12.getMem(i); } while (++i < resultBufferLength); - resultBuffer = signal SingleChannel.multipleDataReady[clientID]( + resultBufferStart = signal SingleChannel.multipleDataReady[clientID]( resultBuffer-resultBufferLength, overflow ? 0 : resultBufferLength); - if (!resultBuffer) + if (!resultBufferStart) stopConversion(); break; } @@ -615,7 +643,7 @@ implementation } default async event uint16_t* SingleChannel.multipleDataReady[uint8_t id]( - uint16_t *buf, uint16_t length) + uint16_t *buf, uint16_t numSamples) { return 0; }