[Tinyos-commits] CVS: tinyos-1.x/apps/TestMSP430DMA Makefile, NONE,
1.1 README, NONE, 1.1 TestADC12DMAC.nc, NONE,
1.1 TestADC12DMAM.nc, NONE, 1.1 TestDAC12DMAC.nc, NONE,
1.1 TestDAC12DMAM.nc, NONE, 1.1
Joe Polastre
jpolastre at users.sourceforge.net
Wed Sep 28 03:53:41 PDT 2005
Update of /cvsroot/tinyos/tinyos-1.x/apps/TestMSP430DMA
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1853
Added Files:
Makefile README TestADC12DMAC.nc TestADC12DMAM.nc
TestDAC12DMAC.nc TestDAC12DMAM.nc
Log Message:
This directory includes two test applications for the MSP430 DMA controller
TestADC12DMAC is an application that continuously samples the ADC,
transfers the results to a buffer using the DMA, and then requests a new
buffer when the DMA's buffer is full.
TestDAC12DMAC is an application that continuously outputs a sine wave
on DAC0. After each iteration of the sine wave is complete, the DMA
notifies the application that the transfer has completed. The application
restarts the transfer immediately, and the sine wave continues.
To compile:
COMP=ADC make <platform>
and
COMP=DAC make <platform>
where <platform> must be a MSP430-based platform, such as
telos, telosb, or tmote.
--- NEW FILE: Makefile ---
COMP ?= ADC
COMPONENT ?= Test$(COMP)12DMAC
include $(MAKERULES)
--- NEW FILE: README ---
README for Test applications for the MSP430 DMA controller
Author/Contact: info at moteiv.com
Description:
This directory includes two test applications for the MSP430 DMA controller
TestADC12DMAC is an application that continuously samples the ADC,
transfers the results to a buffer using the DMA, and then requests a new
buffer when the DMA's buffer is full.
TestDAC12DMAC is an application that continuously outputs a sine wave
on DAC0. After each iteration of the sine wave is complete, the DMA
notifies the application that the transfer has completed. The application
restarts the transfer immediately, and the sine wave continues.
To compile:
COMP=ADC make <platform>
and
COMP=DAC make <platform>
where <platform> must be a MSP430-based platform, such as
telos, telosb, or tmote.
Tools:
None.
Known bugs/limitations:
Only applicable to MSP430 platforms with a DMA controller, ADC12 module,
and DAC12 module. Will not compile or work on any other platform.
--- NEW FILE: TestADC12DMAC.nc ---
// $Id: TestADC12DMAC.nc,v 1.1 2005/09/28 10:53:39 jpolastre Exp $
/*
* Copyright (c) 2005 Moteiv Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached MOTEIV-LICENSE
* file. If you do not find these files, copies can be found at
* http://www.moteiv.com/MOTEIV-LICENSE.txt and by emailing info at moteiv.com.
*/
/**
* @author Joe Polastre
*/
configuration TestADC12DMAC {
}
implementation {
components MSP430DMAC, MSP430ADC12C, Main, TimerC, TestADC12DMAM as Impl, LedsC;
Main.StdControl -> TimerC;
Main.StdControl -> Impl;
Impl.DMA0 -> MSP430DMAC.MSP430DMA[unique("DMA")];
Impl.DMAControl -> MSP430DMAC;
Impl.ADCControl -> MSP430ADC12C;
Impl.Timer -> TimerC.Timer[unique("Timer")];
Impl.ADC -> MSP430ADC12C.MSP430ADC12Single[unique("MSP430ADC12")];
Impl.Leds -> LedsC;
}
--- NEW FILE: TestADC12DMAM.nc ---
// $Id: TestADC12DMAM.nc,v 1.1 2005/09/28 10:53:39 jpolastre Exp $
/*
* "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
* Copyright (c) 2005 Moteiv Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached MOTEIV-LICENSE
* file. If you do not find these files, copies can be found at
* http://www.moteiv.com/MOTEIV-LICENSE.txt and by emailing info at moteiv.com.
*/
includes AM;
/**
* @author Joe Polastre
* @author Ben Greenstein
*/
module TestADC12DMAM {
provides {
interface StdControl;
}
uses {
interface StdControl as ADCControl;
interface MSP430DMAControl as DMAControl;
interface MSP430DMA as DMA0;
interface MSP430ADC12Single as ADC;
interface Leds;
interface Timer;
}
}
implementation {
enum {
RATE_8_000_HZ = 125
};
uint16_t gWriteBuffer[256];
void start_sampling();
command result_t StdControl.init() {
TOSH_SEL_ADC0_MODFUNC();
TOSH_MAKE_ADC0_INPUT();
call Leds.init();
call Leds.redOn();
return call ADCControl.init();
}
command result_t StdControl.start() {
call ADCControl.start();
call Timer.start(TIMER_ONE_SHOT, 1000);
return SUCCESS;
}
command result_t StdControl.stop() {
call ADCControl.stop();
return SUCCESS;
}
event result_t Timer.fired() {
call Leds.greenOn();
start_sampling();
return SUCCESS;
}
async event void DMA0.transferDone(result_t s){
// Now gWriteBuffer has been filled; do what you want with it.
call Leds.yellowToggle();
// Give the DMA another buffer, and tell it to start over
call ADC.pauseSampling();
call DMA0.repeatTransfer((void *)ADC12MEM0_,
gWriteBuffer,
256);
call ADC.resumeSampling();
}
void start_sampling(){
call ADC.bind(ADC12_SETTINGS(INPUT_CHANNEL_A0,
REFERENCE_VREFplus_AVss,
SAMPLE_HOLD_4_CYCLES,
SHT_SOURCE_ADC12OSC,
SHT_CLOCK_DIV_2,
SAMPCON_SOURCE_SMCLK,
SAMPCON_CLOCK_DIV_1,
REFVOLT_LEVEL_2_5));
call DMAControl.init();
call DMAControl.setFlags(FALSE,FALSE,FALSE);
call DMA0.setupTransfer(DMA_SINGLE_TRANSFER,
DMA_TRIGGER_ADC12IFGx,
DMA_EDGE_SENSITIVE,
(void *)ADC12MEM0_,
&(gWriteBuffer[0]),
256,
DMA_WORD, DMA_WORD,
DMA_ADDRESS_UNCHANGED,
DMA_ADDRESS_INCREMENTED);
call DMA0.startTransfer();
call ADC.startSampling(RATE_8_000_HZ);
}
async event result_t ADC.dataReady(uint16_t data) {
return SUCCESS;
}
}
--- NEW FILE: TestDAC12DMAC.nc ---
//$Id: TestDAC12DMAC.nc,v 1.1 2005/09/28 10:53:39 jpolastre Exp $
/*
* Copyright (c) 2005 Moteiv Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached MOTEIV-LICENSE
* file. If you do not find these files, copies can be found at
* http://www.moteiv.com/MOTEIV-LICENSE.txt and by emailing info at moteiv.com.
*/
/**
* @author Joe Polastre
*/
configuration TestDAC12DMAC {
}
implementation {
components Main
, MSP430DAC12C
, TimerC
, LedsC
, TestDAC12DMAM as Impl
, MSP430TimerAExclusiveC as TAC
, MSP430DMAC
;
Main.StdControl -> TimerC;
Main.StdControl -> TAC;
Main.StdControl -> MSP430DAC12C;
Main.StdControl -> Impl;
Impl.DAC -> MSP430DAC12C.DAC0; // use DAC0
Impl.DMAControl -> MSP430DMAC.MSP430DMAControl;
Impl.DMA -> MSP430DMAC.MSP430DMA[unique("DMA")]; // use DMA0
Impl.Timer -> TimerC.Timer[unique("Timer")];
Impl.TimerExclusive -> TAC.TimerExclusive[unique("TimerA")];
Impl.Leds -> LedsC;
}
--- NEW FILE: TestDAC12DMAM.nc ---
//$Id: TestDAC12DMAM.nc,v 1.1 2005/09/28 10:53:39 jpolastre Exp $
/*
* Copyright (c) 2005 Moteiv Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached MOTEIV-LICENSE
* file. If you do not find these files, copies can be found at
* http://www.moteiv.com/MOTEIV-LICENSE.txt and by emailing info at moteiv.com.
*/
/**
* @author Joe Polastre
*/
module TestDAC12DMAM {
provides {
interface StdControl;
}
uses {
interface MSP430DAC as DAC;
interface Timer;
interface Leds;
interface TimerExclusive;
interface MSP430DMA as DMA;
interface MSP430DMAControl as DMAControl;
}
}
implementation {
#ifndef SINE_PERIOD
#define SINE_PERIOD 50 // default period of 50 ms
#endif
uint8_t state;
enum {
IDLE,
START,
ENABLE
};
uint16_t gSineWave[100] = {2047, 2151, 2254, 2357, 2458, 2558, 2656, 2751, 2843, 2933, 3018, 3100, 3177, 3250, 3318, 3381, 3439, 3491, 3537, 3577, 3611, 3639, 3660, 3675, 3683, 3685, 3680, 3668, 3650, 3626, 3595, 3558, 3515, 3466, 3411, 3350, 3285, 3214, 3139, 3060, 2976, 2888, 2798, 2704, 2607, 2508, 2408, 2306, 2203, 2099, 1995, 1891, 1788, 1686, 1586, 1487, 1390, 1296, 1206, 1118, 1034, 955, 880, 809, 744, 683, 628, 579, 536, 499, 468, 444, 426, 414, 409, 411, 419, 434, 455, 483, 517, 557, 603, 655, 713, 776, 844, 917, 994, 1076, 1161, 1251, 1343, 1438, 1536, 1636, 1737, 1840, 1943, 2047};
void startOutput();
command result_t StdControl.init() {
state = IDLE;
call Leds.init();
return SUCCESS;
}
command result_t StdControl.start() {
state = START;
call Timer.start(TIMER_ONE_SHOT, 1024);
return SUCCESS;
}
command result_t StdControl.stop() {
return SUCCESS;
}
event result_t Timer.fired() {
result_t result;
if (state == START) {
state = ENABLE;
// get TimerA
result = call TimerExclusive.get();
call TimerExclusive.stopTimer();
call DAC.bind(DAC12_REF_VREF,
DAC12_RES_12BIT,
DAC12_LOAD_TAOUT1, /* load on TimerA output */
DAC12_FSOUT_1X,
DAC12_AMP_HIGH_HIGH,
DAC12_DF_STRAIGHT,
DAC12_GROUP_OFF);
call DAC.enable();
if (result == SUCCESS)
call Leds.redOn();
}
else if (state == IDLE) {
}
return SUCCESS;
}
event void DAC.enableDone(result_t success) {
state = IDLE;
call DAC.enableOutput();
call DAC.set(gSineWave[0]);
// enable TimerA, set DMA, and go.
startOutput();
}
void startOutput() {
result_t result = SUCCESS;
// set Timer params
result &= call TimerExclusive.prepareTimer((uint16_t)((uint32_t)1024 * (uint32_t)SINE_PERIOD / 100),
MSP430TIMER_SMCLK,
MSP430TIMER_CLOCKDIV_1
);
// setup DMA
call DMAControl.init();
call DMAControl.setFlags(FALSE,FALSE,FALSE);
result &= call DMA.setupTransfer(DMA_SINGLE_TRANSFER,
DMA_TRIGGER_DAC12IFG, /* Trigger on DAC12 DAC0 */
DMA_EDGE_SENSITIVE,
&(gSineWave[0]), /* Source */
(void *)DAC12_0DAT_, /* Destination */
100,
DMA_WORD, DMA_WORD,
DMA_ADDRESS_INCREMENTED, /* Source Increment */
DMA_ADDRESS_UNCHANGED /* Dest Increment */
);
result &= call DMA.startTransfer();
// start TimerA running
result &= call TimerExclusive.startTimer();
if (result == SUCCESS)
call Leds.greenOn();
}
async event void DMA.transferDone(result_t s){
atomic {
call Leds.yellowToggle();
call DMA.startTransfer();
}
}
event void DAC.disableDone(result_t success) { }
event void TimerExclusive.free() { }
}
More information about the Tinyos-commits
mailing list