*/
#include "Timer.h"
-module AdcStreamP {
+module AdcStreamP @safe() {
provides {
interface Init @atleastonce();
interface ReadStream<uint16_t>[uint8_t client];
};
struct list_entry_t *bufferQueue[NSTREAM];
struct list_entry_t * ONE_NOK * bufferQueueEnd[NSTREAM];
- uint16_t * ONE_NOK lastBuffer, lastCount;
+ uint16_t * COUNT_NOK(lastCount) lastBuffer, lastCount;
norace uint16_t count;
norace uint16_t * COUNT_NOK(count) buffer;
call SingleChannel.getData[client]();
}
- command error_t ReadStream.postBuffer[uint8_t c](uint16_t *buf, uint16_t n) {
+ error_t postBuffer(uint8_t c, uint16_t *buf, uint16_t n)
+ {
if (n < sizeof(struct list_entry_t))
return ESIZE;
atomic
return SUCCESS;
}
+ command error_t ReadStream.postBuffer[uint8_t c](uint16_t *buf, uint16_t n) {
+ return postBuffer(c, buf, n);
+ }
+
task void readStreamDone() {
uint8_t c = client;
uint32_t actualPeriod = period;
bufferQueue[client] = entry->next;
if (!bufferQueue[client])
bufferQueueEnd[client] = &bufferQueue[client];
+ pos = buffer = NULL;
count = entry->count;
tmp_count = count;
pos = buffer = TCAST(uint16_t * COUNT_NOK(tmp_count), entry);
msp430adc12_channel_config_t config = *call AdcConfigure.getConfiguration[c]();
config.sampcon_ssel = SAMPCON_SOURCE_SMCLK; // assumption: SMCLK runs at 1 MHz
config.sampcon_id = SAMPCON_CLOCK_DIV_1;
- call SingleChannel.configureMultiple[c]( &config, pos, count, period);
- call SingleChannel.getData[c]();
+ if (call SingleChannel.configureMultiple[c]( &config, pos, count, period) == SUCCESS)
+ call SingleChannel.getData[c]();
+ else {
+ postBuffer(c, pos, count);
+ post readStreamFail();
+ }
}
}
else
{
*pos++ = data;
- if (!--count)
+ if (pos == buffer + count)
{
atomic
{
}
else
{
+ lastCount = count;
lastBuffer = buffer;
- lastCount = pos - buffer;
}
}
post bufferDone();