[Tinyos-contrib-commits]
CVS: tinyos-1.x/contrib/diku/sensinode/tos/platform/micro4
LCGM.nc, NONE, 1.1 HPLKBIC.nc, NONE, 1.1 UARTFrameC.nc, NONE,
1.1 ThreeAxisAccel.nc, NONE, 1.1 MSP430ClockM.nc, NONE,
1.1 IntToLedsC.nc, NONE, 1.1 .platform, NONE, 1.1 UARTFrame.nc,
NONE, 1.1 UARTFrame.h, NONE, 1.1 LedsC.nc, NONE, 1.1 LCG.nc,
NONE, 1.1 HPLUARTM.nc, NONE, 1.1 UARTFrameM.nc, NONE,
1.1 msp430hardware.h, NONE, 1.1 Spi.nc, NONE, 1.1 CRC16.nc,
NONE, 1.1 HPL1wireM.nc, NONE, 1.1 HPLU510R1M.nc, NONE,
1.1 CRC16M.nc, NONE, 1.1 HPLSpiM.nc, NONE, 1.1 ExtLedsC.nc,
NONE, 1.1 AccelerometerC.nc, NONE, 1.1 StdOutC.nc, NONE,
1.1 HPL1wire.nc, NONE, 1.1 StdNullM.nc, NONE, 1.1 hardware.h,
NONE, 1.1 StdOut.nc, NONE, 1.1 StdNullC.nc, NONE,
1.1 hpl1wire.h, NONE, 1.1 StdOutM.nc, NONE, 1.1 ExtLeds.nc,
NONE, 1.1 IntToLedsM.nc, NONE, 1.1 TOSBoot_platform.h, NONE,
1.1 HPLSpi.h, NONE, 1.1 HPLKBI.nc, NONE, 1.1 HPLKBIM.nc, NONE, 1.1
Marcus Chang
marcus_chang at users.sourceforge.net
Thu Mar 15 07:40:11 PDT 2007
- Previous message: [Tinyos-contrib-commits]
CVS: tinyos-1.x/contrib/diku/sensinode/apps/DataCollectorMote
ProtocolClientM.nc, NONE, 1.1 DataCollectorMote.nc, NONE,
1.1 Makefile, NONE, 1.1 DataCollectorMoteM.nc, NONE,
1.1 ProtocolClientC.nc, NONE, 1.1 SamplingControllerM.nc, NONE, 1.1
- Next message: [Tinyos-contrib-commits]
CVS: tinyos-1.x/contrib/diku/sensinode/apps/DataCollector
FIFOBufferManagerM.nc, NONE, 1.1 StatisticsM.nc, NONE,
1.1 Compression.nc, NONE, 1.1 DatasetManagerM.nc, NONE,
1.1 FlashManagerReader.nc, NONE, 1.1 StatisticsReader.nc, NONE,
1.1 ProtocolStarter.nc, NONE, 1.1 CompressionM.nc, NONE,
1.1 FIFOBufferManager.nc, NONE, 1.1 ConnectionM.nc, NONE,
1.1 BufferManager.nc, NONE, 1.1 Connection.nc, NONE,
1.1 FlashManagerC.nc, NONE, 1.1 DatasetManager.nc, NONE,
1.1 Statistics.nc, NONE, 1.1 config.h, NONE,
1.1 FlashManagerM.nc, NONE, 1.1 ProtocolC.nc, NONE,
1.1 SamplingC.nc, NONE, 1.1 BufferManager.h, NONE,
1.1 FlashManagerWriter.nc, NONE, 1.1 StatisticsC.nc, NONE,
1.1 ProtocolM.nc, NONE, 1.1 BufferManagerM.nc, NONE,
1.1 SamplingM.nc, NONE, 1.1 DatasetManager.h, NONE,
1.1 CompressionC.nc, NONE, 1.1 ConnectionC.nc, NONE, 1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/tinyos/tinyos-1.x/contrib/diku/sensinode/tos/platform/micro4
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv30685/sensinode/tos/platform/micro4
Added Files:
LCGM.nc HPLKBIC.nc UARTFrameC.nc ThreeAxisAccel.nc
MSP430ClockM.nc IntToLedsC.nc .platform UARTFrame.nc
UARTFrame.h LedsC.nc LCG.nc HPLUARTM.nc UARTFrameM.nc
msp430hardware.h Spi.nc CRC16.nc HPL1wireM.nc HPLU510R1M.nc
CRC16M.nc HPLSpiM.nc ExtLedsC.nc AccelerometerC.nc StdOutC.nc
HPL1wire.nc StdNullM.nc hardware.h StdOut.nc StdNullC.nc
hpl1wire.h StdOutM.nc ExtLeds.nc IntToLedsM.nc
TOSBoot_platform.h HPLSpi.h HPLKBI.nc HPLKBIM.nc
Log Message:
* Sensinode Micro.4 platform support
* Hoghtrob Data Collection Application
--- NEW FILE: LCGM.nc ---
/*
Copyright (C) 2004 Klaus S. Madsen <klaussm at diku.dk>
Copyright (C) 2006 Marcus Chang <marcus at diku.dk>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
module LCGM {
provides {
interface LCG;
}
}
implementation {
#define A 1664525
#define B 1013904223
/* #define M 0x100000000 */
uint64_t v = 0;
command void LCG.seed(uint32_t seed)
{
v = seed;
}
command uint32_t LCG.next()
{
/* v_i+1 = (A * v_i + B) MOD M */
v = (A * v + B) & 0xFFFFFFFF;
return v;
}
}
--- NEW FILE: HPLKBIC.nc ---
/*
HPLKBI configuration
Author: Jacob Munk-Stander <jacobms at diku.dk>
Last modified: May 24, 2005
*/
configuration HPLKBIC
{
provides interface HPLKBI as KBI;
uses interface Timer;
}
implementation
{
components HPLKBIM;
KBI = HPLKBIM;
Timer = HPLKBIM;
}
--- NEW FILE: UARTFrameC.nc ---
/*
Copyright (C) 2004 Klaus S. Madsen <klaussm at diku.dk>
Copyright (C) 2006 Marcus Chang <marcus at diku.dk>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
configuration UARTFrameC {
provides {
interface StdControl;
interface UARTFrame;
}
}
implementation {
components UARTFrameM, HPLUARTC, CRC16M, LocalTimeMicroC;
StdControl = UARTFrameM;
UARTFrame = UARTFrameM;
UARTFrameM.UART -> HPLUARTC;
UARTFrameM.CRC16 -> CRC16M;
UARTFrameM.LocalTime -> LocalTimeMicroC;
}
--- NEW FILE: ThreeAxisAccel.nc ---
/*
Copyright (C) 2004 Klaus S. Madsen <klaussm at diku.dk>
Copyright (C) 2006 Marcus Chang <marcus at diku.dk>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
enum conversion_status {
ACCEL_STATUS_SUCCESS = 0x00,
ACCEL_STATUS_CONVERSION_FAILED = 0x01,
ACCEL_STATUS_BLOCKMODE_FAILED = 0x02,
ACCEL_STATUS_OUT_OF_BOUNCE = 0x04,
};
enum accelerometer_range {
ACCEL_RANGE_2x5G = 0x00,
ACCEL_RANGE_6x7G = 0x01,
ACCEL_RANGE_3x3G = 0x02,
ACCEL_RANGE_10x0G = 0x03,
};
interface ThreeAxisAccel {
command result_t setRange(uint8_t range);
command result_t getData();
event result_t dataReady(uint16_t xaxis, uint16_t yaxis, uint16_t zaxis, uint8_t status);
}
--- NEW FILE: MSP430ClockM.nc ---
//$Id: MSP430ClockM.nc,v 1.1 2007/03/15 14:40:05 marcus_chang Exp $
/* "Copyright (c) 2000-2003 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."
*/
//@author Cory Sharp <cssharp at eecs.berkeley.edu>
includes MSP430Timer;
module MSP430ClockM
{
provides interface StdControl;
provides interface MSP430ClockInit;
}
implementation
{
MSP430REG_NORACE(IE1);
MSP430REG_NORACE(TACTL);
MSP430REG_NORACE(TAIV);
MSP430REG_NORACE(TBCTL);
MSP430REG_NORACE(TBIV);
enum
{
ACLK_CALIB_PERIOD = 8,
ACLK_KHZ = 32,
#ifdef __1MHz__
TARGET_DCO_KHZ = 1024, // prescribe the cpu clock rate in kHz
#else
TARGET_DCO_KHZ = 4096, // prescribe the cpu clock rate in kHz
#endif
TARGET_DCO_DELTA = (TARGET_DCO_KHZ / ACLK_KHZ) * ACLK_CALIB_PERIOD,
};
command void MSP430ClockInit.defaultInitClocks()
{
// BCSCTL1
// .XT2OFF = 1; disable the external oscillator for SCLK and MCLK
// .XTS = 0; set low frequency mode for LXFT1
// .DIVA = 0; set the divisor on ACLK to 1
// .RSEL, do not modify
BCSCTL1 = XT2OFF | (BCSCTL1 & (RSEL2|RSEL1|RSEL0));
// BCSCTL2
// .SELM = 0; select DCOCLK as source for MCLK
// .DIVM = 0; set the divisor of MCLK to 1
// .SELS = 0; select DCOCLK as source for SCLK
// .DIVS = 0; set the divisor of SCLK to 1
// .DCOR = 0; select internal resistor for DCO
#ifdef __1MHz__
BCSCTL2 = 0;
#else
BCSCTL2 = DIVS1;
#endif
// IE1.OFIE = 0; no interrupt for oscillator fault
CLR_FLAG( IE1, OFIE );
}
command void MSP430ClockInit.defaultInitTimerA()
{
TAR = 0;
// TACTL
// .TACLGRP = 0; each TACL group latched independently
// .CNTL = 0; 16-bit counter
// .TASSEL = 2; source SMCLK = DCO/4
// .ID = 0; input divisor of 1
// .MC = 0; initially disabled
// .TACLR = 0; reset timer A
// .TAIE = 1; enable timer A interrupts
TACTL = TASSEL1 | TAIE;
}
command void MSP430ClockInit.defaultInitTimerB()
{
TBR = 0;
// TBCTL
// .TBCLGRP = 0; each TBCL group latched independently
// .CNTL = 0; 16-bit counter
// .TBSSEL = 1; source ACLK
// .ID = 0; input divisor of 1
// .MC = 0; initially disabled
// .TBCLR = 0; reset timer B
// .TBIE = 1; enable timer B interrupts
TBCTL = TBSSEL0 | TBIE;
}
default event void MSP430ClockInit.initClocks()
{
call MSP430ClockInit.defaultInitClocks();
}
default event void MSP430ClockInit.initTimerA()
{
call MSP430ClockInit.defaultInitTimerA();
}
default event void MSP430ClockInit.initTimerB()
{
call MSP430ClockInit.defaultInitTimerB();
}
void startTimerA()
{
// TACTL.MC = 2; continuous mode
TACTL = MC1 | (TACTL & ~(MC1|MC0));
}
void stopTimerA()
{
//TACTL.MC = 0; stop timer B
TACTL = TACTL & ~(MC1|MC0);
}
void startTimerB()
{
// TBCTL.MC = 2; continuous mode
TBCTL = MC1 | (TBCTL & ~(MC1|MC0));
}
void stopTimerB()
{
//TBCTL.MC = 0; stop timer B
TBCTL = TBCTL & ~(MC1|MC0);
}
void set_dco_calib( int calib )
{
BCSCTL1 = (BCSCTL1 & ~0x07) | ((calib >> 8) & 0x07);
DCOCTL = calib & 0xff;
}
uint16_t test_calib_busywait_delta( int calib )
{
int8_t aclk_count = 2;
uint16_t dco_prev = 0;
uint16_t dco_curr = 0;
set_dco_calib( calib );
while( aclk_count-- > 0 )
{
TBCCR0 = TBR + ACLK_CALIB_PERIOD; // set next interrupt
TBCCTL0 &= ~CCIFG; // clear pending interrupt
while( (TBCCTL0 & CCIFG) == 0 ); // busy wait
dco_prev = dco_curr;
dco_curr = TAR;
}
return dco_curr - dco_prev;
}
// busyCalibrateDCO
// Should take about 9ms if ACLK_CALIB_PERIOD=8.
// DCOCTL and BCSCTL1 are calibrated when done.
void busyCalibrateDCO()
{
// --- variables ---
int calib;
int step;
// --- setup ---
TACTL = TASSEL1 | MC1; // source SMCLK, continuous mode, everything else 0
TBCTL = TBSSEL0 | MC1;
BCSCTL1 = XT2OFF | RSEL2;
BCSCTL2 = 0;
TBCCTL0 = CM0;
// --- calibrate ---
// Binary search for RSEL,DCO,DCOMOD.
// It's okay that RSEL isn't monotonic.
for( calib=0,step=0x800; step!=0; step>>=1 )
{
// if the step is not past the target, commit it
if( test_calib_busywait_delta(calib|step) <= TARGET_DCO_DELTA )
calib |= step;
}
// if DCOx is 7 (0x0e0 in calib), then the 5-bit MODx is not useable, set it to 0
if( (calib & 0x0e0) == 0x0e0 )
calib &= ~0x01f;
set_dco_calib( calib );
}
command result_t StdControl.init()
{
// Reset timers and clear interrupt vectors
TACTL = TACLR;
TAIV = 0;
TBCTL = TBCLR;
TBIV = 0;
atomic
{
busyCalibrateDCO();
signal MSP430ClockInit.initClocks();
signal MSP430ClockInit.initTimerA();
signal MSP430ClockInit.initTimerB();
}
return SUCCESS;
}
command result_t StdControl.start()
{
atomic
{
startTimerA();
startTimerB();
}
return SUCCESS;
}
command result_t StdControl.stop()
{
atomic
{
stopTimerB();
stopTimerA();
}
return SUCCESS;
}
}
--- NEW FILE: IntToLedsC.nc ---
// $Id: IntToLedsC.nc,v 1.1 2007/03/15 14:40:05 marcus_chang Exp $
/* tab:4
* "Copyright (c) 2000-2003 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) 2002-2003 Intel Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached INTEL-LICENSE
* file. If you do not find these files, copies can be found by writing to
* Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
* 94704. Attention: Intel License Inquiry.
*/
/*
* Authors: Jason Hill, David Gay, Philip Levis
* Date last modified: 6/25/02
*
*/
/**
* @author Jason Hill
* @author David Gay
* @author Philip Levis
*/
configuration IntToLedsC
{
provides interface IntOutput;
provides interface StdControl;
}
implementation
{
components IntToLedsM, LedsC;
IntOutput = IntToLedsM.IntOutput;
StdControl = IntToLedsM.StdControl;
IntToLedsM.Leds -> LedsC.Leds;
}
--- NEW FILE: .platform ---
#$Id: .platform,v 1.1 2007/03/15 14:40:05 marcus_chang Exp $
# Includes that should take precedence come first. Platforms come before
# chips because they may override files. These must be specified as
# @includes instead of -I's to @opts, otherwise the %T won't be processed
# by ncc. And because of that, the current platform's include directory
# must be specified, otherwise its search order is last instead of first.
push( @includes, qw(
%T/../contrib/diku/sensinode/tos/platform/micro4
%T/../contrib/diku/sensinode/tos/platform/micro4/radio
%T/../contrib/diku/sensinode/tos/platform/micro4/flash
%T/platform/telosb
%T/platform/telos
%T/platform/msp430
%T/lib/Flash/STM25P
%T/lib/Flash
) );
@opts = ("-gcc=msp430-gcc",
"-mmcu=msp430x1611",
"-fnesc-target=msp430",
"-fnesc-no-debug");
push @opts, "-mingw-gcc" if $cygwin;
# Including -I's here like this means that the make system can't override them.
# This is why it's bad to secretly stuff build logic in a place like .platform.
#push @opts, "-I$TOSDIR/lib/Flash";
#push @opts, "-I$TOSDIR/lib/Flash/STM25P";
--- NEW FILE: UARTFrame.nc ---
/*
Copyright (C) 2004 Klaus S. Madsen <klaussm at diku.dk>
Copyright (C) 2006 Marcus Chang <marcus at diku.dk>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
includes UARTFrame;
interface UARTFrame {
/**
* send will send a packet through the UART to a PC. The packet will
* be returned when sendDone is signalled.
*
* @param packet_t *packet The packet to send
*/
command result_t sendFrame(uint8_t * frame);
event void sendFrameDone(uint8_t * frame);
event void receivedFrame(uint8_t * frame);
}
--- NEW FILE: UARTFrame.h ---
/*
Copyright (C) 2004 Klaus S. Madsen <klaussm at diku.dk>
Copyright (C) 2006 Marcus Chang <marcus at diku.dk>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef UARTFRAME_H
#define UARTFRAME_H
#define MAX_FRAME_LENGTH 128
typedef uint8_t * pointer_t __attribute__((combine(pointerCombine)));
/*
pointer_t pointerCombine(pointer_t p1, pointer_t p2)
{
if (p1 > p2)
return p1;
else
return p2;
}
*/
typedef enum
{
UART_FRAME_RETRANSMIT = 0x00,
UART_FRAME_INIT = 0x01,
UART_FRAME_FRAGMENT = 0x02,
UART_FRAME_ALIVE = 0x03,
}uart_frame_types;
#endif
--- NEW FILE: LedsC.nc ---
// $Id: LedsC.nc,v 1.1 2007/03/15 14:40:05 marcus_chang Exp $
/* tab:4
* "Copyright (c) 2000-2003 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) 2002-2003 Intel Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached INTEL-LICENSE
* file. If you do not find these files, copies can be found by writing to
* Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
* 94704. Attention: Intel License Inquiry.
*/
/*
*
* Authors: Jason Hill, David Gay, Philip Levis
* Date last modified: 6/2/03
*
*/
/**
* @author Jason Hill
* @author David Gay
* @author Philip Levis
*/
module LedsC {
provides interface Leds;
}
implementation
{
uint8_t ledsOn;
enum {
RED_BIT = 1,
GREEN_BIT = 2,
YELLOW_BIT = 4
};
async command result_t Leds.init() {
atomic {
ledsOn = 0;
dbg(DBG_BOOT, "LEDS: initialized.\n");
TOSH_MAKE_RED_LED_OUTPUT();
TOSH_MAKE_GREEN_LED_OUTPUT();
TOSH_MAKE_YELLOW_LED_OUTPUT();
TOSH_CLR_RED_LED_PIN();
TOSH_CLR_GREEN_LED_PIN();
TOSH_SET_YELLOW_LED_PIN();
}
return SUCCESS;
}
async command result_t Leds.redOn() {
dbg(DBG_LED, "LEDS: Red on.\n");
atomic {
TOSH_SET_RED_LED_PIN();
ledsOn |= RED_BIT;
}
return SUCCESS;
}
async command result_t Leds.redOff() {
dbg(DBG_LED, "LEDS: Red off.\n");
atomic {
TOSH_CLR_RED_LED_PIN();
ledsOn &= ~RED_BIT;
}
return SUCCESS;
}
async command result_t Leds.redToggle() {
result_t rval;
atomic {
if (ledsOn & RED_BIT)
rval = call Leds.redOff();
else
rval = call Leds.redOn();
}
return rval;
}
async command result_t Leds.greenOn() {
dbg(DBG_LED, "LEDS: Green on.\n");
atomic {
TOSH_SET_GREEN_LED_PIN();
ledsOn |= GREEN_BIT;
}
return SUCCESS;
}
async command result_t Leds.greenOff() {
dbg(DBG_LED, "LEDS: Green off.\n");
atomic {
TOSH_CLR_GREEN_LED_PIN();
ledsOn &= ~GREEN_BIT;
}
return SUCCESS;
}
async command result_t Leds.greenToggle() {
result_t rval;
atomic {
if (ledsOn & GREEN_BIT)
rval = call Leds.greenOff();
else
rval = call Leds.greenOn();
}
return rval;
}
async command result_t Leds.yellowOn() {
dbg(DBG_LED, "LEDS: Yellow on.\n");
atomic {
TOSH_CLR_YELLOW_LED_PIN();
ledsOn |= YELLOW_BIT;
}
return SUCCESS;
}
async command result_t Leds.yellowOff() {
dbg(DBG_LED, "LEDS: Yellow off.\n");
atomic {
TOSH_SET_YELLOW_LED_PIN();
ledsOn &= ~YELLOW_BIT;
}
return SUCCESS;
}
async command result_t Leds.yellowToggle() {
result_t rval;
atomic {
if (ledsOn & YELLOW_BIT)
rval = call Leds.yellowOff();
else
rval = call Leds.yellowOn();
}
return rval;
}
async command uint8_t Leds.get() {
uint8_t rval;
atomic {
rval = ledsOn;
}
return rval;
}
async command result_t Leds.set(uint8_t ledsNum) {
atomic {
ledsOn = (ledsNum & 0x7);
if (ledsOn & RED_BIT)
TOSH_SET_RED_LED_PIN();
else
TOSH_CLR_RED_LED_PIN();
if (ledsOn & GREEN_BIT)
TOSH_SET_GREEN_LED_PIN();
else
TOSH_CLR_GREEN_LED_PIN();
if (ledsOn & YELLOW_BIT )
TOSH_CLR_YELLOW_LED_PIN();
else
TOSH_SET_YELLOW_LED_PIN();
}
return SUCCESS;
}
}
--- NEW FILE: LCG.nc ---
/*
Copyright (C) 2004 Klaus S. Madsen <klaussm at diku.dk>
Copyright (C) 2006 Marcus Chang <marcus at diku.dk>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
interface LCG
{
command void seed(uint32_t seed);
command uint32_t next();
}
--- NEW FILE: HPLUARTM.nc ---
/*
* Copyright (c) 2004, Technische Universitat Berlin
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the Technische Universitat Berlin nor the names
* of its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* - Description ----------------------------------------------------------
* Implementation of UART0 lowlevel functionality - stateless.
* - Revision -------------------------------------------------------------
* $Revision: 1.1 $
* $Date: 2007/03/15 14:40:05 $
* @author Jan Hauer
* @author Vlado Handziski
* @author Joe Polastre
* ========================================================================
*/
includes msp430baudrates;
module HPLUARTM {
provides interface HPLUART as UART;
uses interface HPLUSARTControl as USARTControl;
uses interface HPLUSARTFeedback as USARTData;
}
implementation
{
async command result_t UART.init() {
// set up the USART to be a UART
call USARTControl.setModeUART();
// support some common default baudrates
#if DEFAULT_BAUDRATE == 9600
call USARTControl.setClockSource(SSEL_ACLK);
call USARTControl.setClockRate(UBR_ACLK_9600, UMCTL_ACLK_9600);
#elif DEFAULT_BAUDRATE == 19200
call USARTControl.setClockSource(SSEL_SMCLK);
call USARTControl.setClockRate(UBR_SMCLK_19200, UMCTL_SMCLK_19200);
#elif DEFAULT_BAUDRATE == 38400
call USARTControl.setClockSource(SSEL_SMCLK);
call USARTControl.setClockRate(UBR_SMCLK_38400, UMCTL_SMCLK_38400);
#elif DEFAULT_BAUDRATE == 57600
call USARTControl.setClockSource(SSEL_SMCLK);
call USARTControl.setClockRate(UBR_SMCLK_57600, UMCTL_SMCLK_57600);
#elif DEFAULT_BAUDRATE == 115200
call USARTControl.setClockSource(SSEL_SMCLK);
call USARTControl.setClockRate(UBR_SMCLK_115200, UMCTL_SMCLK_115200);
#elif DEFAULT_BAUDRATE == 230400
call USARTControl.setClockSource(SSEL_SMCLK);
call USARTControl.setClockRate(UBR_SMCLK_230400, UMCTL_SMCLK_230400);
#elif DEFAULT_BAUDRATE == 262144
call USARTControl.setClockSource(SSEL_SMCLK);
call USARTControl.setClockRate(UBR_SMCLK_262144, UMCTL_SMCLK_262144);
#else
#error "Error, unsupported value for DEFAULT_BAUDRATE in HPLUARTM.nc"
#endif
// enable interrupts
call USARTControl.enableRxIntr();
call USARTControl.enableTxIntr();
return SUCCESS;
}
async command result_t UART.stop() {
call USARTControl.disableRxIntr();
call USARTControl.disableTxIntr();
// disable the UART modules so that we can go in deeper LowPower mode
call USARTControl.disableUART();
return SUCCESS;
}
async event result_t USARTData.rxDone(uint8_t b) {
return signal UART.get(b);
}
async event result_t USARTData.txDone() {
return signal UART.putDone();
}
async command result_t UART.put(uint8_t data){
return call USARTControl.tx(data);
}
default async event result_t UART.get(uint8_t data) { return SUCCESS; }
default async event result_t UART.putDone() { return SUCCESS; }
}
--- NEW FILE: UARTFrameM.nc ---
/*
Copyright (C) 2004 Klaus S. Madsen <klaussm at diku.dk>
Copyright (C) 2006 Marcus Chang <marcus at diku.dk>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
module UARTFrameM {
provides {
interface StdControl;
interface UARTFrame;
}
uses {
interface HPLUART as UART;
interface LocalTime;
interface CRC16;
}
}
implementation {
#define MAX_PAYLOAD (MAX_FRAME_LENGTH - 1)
#define MAX_TIME_DELAY 1000UL // ~1050000 ticks at 4MHz clock and 0.000035s at 230400 bps
/* transmission */
bool sending;
uint8_t * sendFramePtr;
uint8_t * next_send_byte;
uint8_t send_left;
task void packet_send_done();
/* reception */
uint8_t receiveBuffer[MAX_FRAME_LENGTH];
uint8_t handleBuffer[MAX_FRAME_LENGTH];
uint8_t * receiveBufferPtr, * handleBufferPtr;
uint8_t * next_recv_byte;
uint8_t recv_left;
/* frame handling */
bool handlingFrame;
task void packet_recv();
/* timeout */
uint32_t lastTime;
/**************************************************************************
** StdControl
**************************************************************************/
command result_t StdControl.init()
{
call UART.init();
atomic {
/* transmission */
sending = FALSE;
next_send_byte = 0;
send_left = 0;
/* reception */
receiveBufferPtr = receiveBuffer;
handleBufferPtr = handleBuffer;
next_recv_byte = receiveBufferPtr;
recv_left = 0;
handlingFrame = FALSE;
}
return SUCCESS;
}
command result_t StdControl.start()
{
return SUCCESS;
}
command result_t StdControl.stop()
{
call UART.stop();
return SUCCESS;
}
/**************************************************************************
** UARTFrame
**************************************************************************/
command result_t UARTFrame.sendFrame(uint8_t * frame)
{
uint8_t size;
uint16_t crc;
if (sending)
return FAIL;
sending = TRUE;
/* store buffer pointer */
sendFramePtr = frame;
/* insert 16-bit crc at end of buffer */
size = sendFramePtr[0];
crc = call CRC16.calc(sendFramePtr, size - 1);
sendFramePtr[size-1] = crc >> 8;
sendFramePtr[size] = crc;
atomic {
/* point to next byte to be written */
next_send_byte = sendFramePtr;
/* setup remaining bytes to be written */
send_left = sendFramePtr[0] + 1;
/* initiate offload */
signal UART.putDone();
}
return SUCCESS;
}
/**************************************************************************
** UART
**************************************************************************/
async event result_t UART.putDone()
{
if (send_left) {
call UART.put(*next_send_byte++);
send_left--;
if (!send_left)
post packet_send_done();
}
return SUCCESS;
}
task void packet_send_done()
{
sending = FALSE;
/* return buffer pointer to caller */
signal UARTFrame.sendFrameDone(sendFramePtr);
}
/**************************************************************************
**************************************************************************/
async event result_t UART.get(uint8_t data)
{
uint32_t thisTime;
uint8_t * ptr;
/* buffer space available */
if (!next_recv_byte)
return FAIL;
/* reset buffer is time between chars is too high */
thisTime = call LocalTime.read();
if ( (thisTime - lastTime) > MAX_TIME_DELAY) {
next_recv_byte = receiveBufferPtr;
recv_left = 0;
}
lastTime = thisTime;
/* store byte in buffer and update pointer */
*next_recv_byte++ = data;
/* update number of remaining bytes */
if (!recv_left) {
recv_left = data;
} else {
recv_left--;
}
/* frame complete */
if (!recv_left)
{
/* check if buffer is ready */
if (handlingFrame)
{
/* buffer not ready */
next_recv_byte = 0;
} else {
handlingFrame = TRUE;
/* switch buffer */
ptr = receiveBufferPtr;
receiveBufferPtr = handleBufferPtr;
handleBufferPtr = ptr;
next_recv_byte = receiveBufferPtr;
/* handle received frame */
post packet_recv();
}
}
return SUCCESS;
}
task void packet_recv()
{
uint8_t length;
uint16_t crcval, crcframe;
uint8_t * buf, * ptr, * next_recv_byte_sync;
atomic buf = handleBufferPtr;
/* calculate crc */
length = buf[0];
crcval = call CRC16.calc(buf, length - 1);
crcframe = buf[length-1];
crcframe = (crcframe << 8) + buf[length];
/* signal frame if crc checks out */
if (crcframe == crcval)
{
signal UARTFrame.receivedFrame(buf);
}
/* frame waiting to be processed */
atomic next_recv_byte_sync = next_recv_byte;
if (!next_recv_byte_sync)
{
atomic {
/* switch buffer */
ptr = receiveBufferPtr;
receiveBufferPtr = handleBufferPtr;
handleBufferPtr = ptr;
/* unblock reception */
next_recv_byte = receiveBufferPtr;
}
/* handle receiveed frame */
post packet_recv();
} else {
/* frame handling complete */
atomic handlingFrame = FALSE;
}
}
}
--- NEW FILE: msp430hardware.h ---
// $Id: msp430hardware.h,v 1.1 2007/03/15 14:40:05 marcus_chang Exp $
/* "Copyright (c) 2000-2003 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."
*/
// @author Vlado Handziski <handzisk at tkn.tu-berlin.de>
// @author Joe Polastre <polastre at cs.berkeley.edu>
// @author Cory Sharp <cssharp at eecs.berkeley.edu>
#ifndef _H_msp430hardware_h
#define _H_msp430hardware_h
#include <io.h>
#include <signal.h>
#include "msp430regtypes.h"
// define platform constants that can be changed for different compilers
// these are all msp430-gcc specific (add as necessary)
#ifdef __msp430_headers_adc10_h
#define __msp430_have_adc10
#endif
#ifdef __msp430_headers_adc12_h
#define __msp430_have_adc12
#endif
// assign a default DEFAULT_BAUDRATE
#ifndef DEFAULT_BAUDRATE
#define DEFAULT_BAUDRATE 230400
#endif
#ifndef __1MHz__
#define __1MHz__
#endif
// CPU memory-mapped register access will cause nesc to issue race condition
// warnings. Race conditions are a significant conern when accessing CPU
// memory-mapped registers, because they can change even while interrupts
// are disabled. This means that the standard nesc tools for resolving race
// conditions, atomic statements that disable interrupt handling, do not
// resolve CPU register race conditions. So, CPU registers access must be
// treated seriously and carefully.
// The macro MSP430REG_NORACE allows individual modules to internally
// redeclare CPU registers as norace, eliminating nesc's race condition
// warnings for their access. This macro should only be used after the
// specific CPU register use has been verified safe and correct. Example
// use:
//
// module MyLowLevelModule
// {
// // ...
// }
// implementation
// {
// MSP430REG_NORACE(TACCTL0);
// // ...
// }
#undef norace
#define MSP430REG_NORACE_EXPAND(type,name,addr) \
norace static volatile type name asm(#addr)
#define MSP430REG_NORACE3(type,name,addr) \
MSP430REG_NORACE_EXPAND(type,name,addr)
// MSP430REG_NORACE and MSP430REG_NORACE2 presume naming conventions among
// type, name, and addr, which are defined in the local header
// msp430regtypes.h and mspgcc's header io.h and its children.
#define MSP430REG_NORACE2(rename,name) \
MSP430REG_NORACE3(TYPE_##name,rename,name##_)
#define MSP430REG_NORACE(name) \
MSP430REG_NORACE3(TYPE_##name,name,name##_)
// Avoid the type-punned pointer warnings from gcc 3.3, which are warning about
// creating potentially broken object code. Union casts are the appropriate work
// around. Unfortunately, they require a function definiton.
#define DEFINE_UNION_CAST(func_name,to_type,from_type) \
to_type func_name(from_type x) { union {from_type f; to_type t;} c = {f:x}; return c.t; }
// redefine ugly defines from msp-gcc
#ifndef DONT_REDEFINE_SR_FLAGS
#undef C
#undef Z
#undef N
#undef V
#undef GIE
#undef CPUOFF
#undef OSCOFF
#undef SCG0
#undef SCG1
#undef LPM0_bits
#undef LPM1_bits
#undef LPM2_bits
#undef LPM3_bits
#undef LPM4_bits
#define SR_C 0x0001
#define SR_Z 0x0002
#define SR_N 0x0004
#define SR_V 0x0100
#define SR_GIE 0x0008
#define SR_CPUOFF 0x0010
#define SR_OSCOFF 0x0020
#define SR_SCG0 0x0040
#define SR_SCG1 0x0080
#define LPM0_bits SR_CPUOFF
#define LPM1_bits SR_SCG0+SR_CPUOFF
#define LPM2_bits SR_SCG1+SR_CPUOFF
#define LPM3_bits SR_SCG1+SR_SCG0+SR_CPUOFF
#define LPM4_bits SR_SCG1+SR_SCG0+SR_OSCOFF+SR_CPUOFF
#endif//DONT_REDEFINE_SR_FLAGS
#ifdef interrupt
#undef interrupt
#endif
#ifdef wakeup
#undef wakeup
#endif
#ifdef signal
#undef signal
#endif
// I2CBusy flag is not defined by current MSP430-GCC
#ifdef __msp430_have_usart0_with_i2c
#ifndef I2CBUSY
#define I2CBUSY (0x01 << 5)
#endif
MSP430REG_NORACE2(U0CTLnr,U0CTL);
MSP430REG_NORACE2(I2CTCTLnr,I2CTCTL);
MSP430REG_NORACE2(I2CDCTLnr,I2CDCTL);
#endif
// The signal attribute has opposite meaning in msp430-gcc than in avr-gcc
#define TOSH_SIGNAL(signame) \
void sig_##signame() __attribute__((interrupt (signame), wakeup, C))
// TOSH_INTERRUPT allows nested interrupts
#define TOSH_INTERRUPT(signame) \
void isr_##signame() __attribute__((interrupt (signame), signal, wakeup, C))
inline void TOSH_wait(void)
{
nop(); nop();
}
#define TOSH_CYCLE_TIME_NS 250
inline void TOSH_wait_250ns(void)
{
// 4 MHz clock == 1 cycle per 250 ns
nop();
}
inline void TOSH_uwait(uint16_t u)
{
uint16_t i;
// 1MHz clock - not 4
#ifdef __1MHz__
u /= 8;
#endif
if (u < 500)
for (i=2; i < u; i++) {
asm volatile("nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
::);
}
else
for (i=0; i < u; i++) {
asm volatile("nop\n\t"
"nop\n\t"
"nop\n\t"
"nop\n\t"
::);
}
}
void __nesc_disable_interrupt()
{
dint();
nop();
}
void __nesc_enable_interrupt()
{
eint();
}
bool are_interrupts_enabled()
{
return ((READ_SR & SR_GIE) != 0);
}
typedef bool __nesc_atomic_t;
__nesc_atomic_t __nesc_atomic_start(void);
void __nesc_atomic_end(__nesc_atomic_t oldSreg);
#ifndef NESC_BUILD_BINARY
__nesc_atomic_t __nesc_atomic_start(void)
{
__nesc_atomic_t result = are_interrupts_enabled();
__nesc_disable_interrupt();
return result;
}
void __nesc_atomic_end( __nesc_atomic_t reenable_interrupts )
{
if( reenable_interrupts )
__nesc_enable_interrupt();
}
#endif
//Variable to keep track if Low Power Modes shoud not be used
norace bool LPMode_disabled = FALSE;
void LPMode_enable() {
LPMode_disabled = FALSE;
}
void LPMode_disable() {
LPMode_disabled = TRUE;
}
inline void __nesc_atomic_sleep() {
// The LPM we can go down to depends on the clocks used. We never go
// below LPM3, so ACLK is always enabled, also TimerB clock source
// is assumed to be ACLK.
// We check MSP430's TimerA, USART0/1, ADC12 peripheral modules if they
// use MCLK or SMCLK and switch to the lowest LPM that keeps
// the required clock(s) running.
extern uint8_t TOSH_sched_full;
extern volatile uint8_t TOSH_sched_free;
uint16_t LPMode_bits = 0;
if (LPMode_disabled) {
__nesc_enable_interrupt();
return;
} else {
LPMode_bits = LPM3_bits;
// TimerA, USART0, USART1 check
if ( ((((TACTL & MC_3) != MC_0) && (TACTL & TASSEL_3) == TASSEL_2))
|| ((ME1 & (UTXE0 | URXE0)) && (U0TCTL & SSEL1))
|| ((ME2 & (UTXE1 | URXE1)) && (U1TCTL & SSEL1))
#ifdef __msp430_have_usart0_with_i2c
// registers end in "nr" to prevent nesC race condition detection
|| ((U0CTLnr & I2CEN) && (I2CTCTLnr & SSEL1) &&
(I2CDCTLnr & I2CBUSY) && (U0CTLnr & SYNC) && (U0CTLnr & I2C))
#endif
)
LPMode_bits = LPM1_bits;
#ifdef __msp430_have_adc12
// ADC12 check
if (ADC12CTL1 & ADC12BUSY){
if (!(ADC12CTL0 & MSC) && ((TACTL & TASSEL_3) == TASSEL_2))
LPMode_bits = LPM1_bits; // TimerA for ADC12
else
switch (ADC12CTL1 & ADC12SSEL_3){
case ADC12SSEL_2: LPMode_bits = 0; break;
case ADC12SSEL_3: LPMode_bits = LPM1_bits; break;
}
}
#endif
LPMode_bits |= SR_GIE;
__asm__ __volatile__( "bis %0, r2" : : "m" ((uint16_t)LPMode_bits) );
}
}
#define SET_FLAG(port, flag) ((port) |= (flag))
#define CLR_FLAG(port, flag) ((port) &= ~(flag))
#define READ_FLAG(port, flag) ((port) & (flag))
// TOSH_ASSIGN_PIN creates functions that are effectively marked as
// "norace". This means race conditions that result from their use will not
// be detectde by nesc.
#define TOSH_ASSIGN_PIN_HEX(name, port, hex) \
void TOSH_SET_##name##_PIN() { MSP430REG_NORACE2(r,P##port##OUT); r |= hex; } \
void TOSH_CLR_##name##_PIN() { MSP430REG_NORACE2(r,P##port##OUT); r &= ~hex; } \
void TOSH_TOGGLE_##name##_PIN() { MSP430REG_NORACE2(r,P##port##OUT); r ^= hex; } \
uint8_t TOSH_READ_##name##_PIN() { MSP430REG_NORACE2(r,P##port##IN); return (r & hex); } \
void TOSH_MAKE_##name##_OUTPUT() { MSP430REG_NORACE2(r,P##port##DIR); r |= hex; } \
void TOSH_MAKE_##name##_INPUT() { MSP430REG_NORACE2(r,P##port##DIR); r &= ~hex; } \
void TOSH_SEL_##name##_MODFUNC() { MSP430REG_NORACE2(r,P##port##SEL); r |= hex; } \
void TOSH_SEL_##name##_IOFUNC() { MSP430REG_NORACE2(r,P##port##SEL); r &= ~hex; } \
bool TOSH_IS_##name##_MODFUNC() { MSP430REG_NORACE2(r,P##port##SEL); return (r & hex); } \
bool TOSH_IS_##name##_IOFUNC() { MSP430REG_NORACE2(r,P##port##SEL); return (r | ~hex); }
#define TOSH_ASSIGN_PIN(name, port, bit) \
TOSH_ASSIGN_PIN_HEX(name,port,(1<<(bit)))
#include "MSP430GeneralIO.h"
#endif//_H_msp430hardware_h
--- NEW FILE: Spi.nc ---
/*
Copyright (C) 2004 Klaus S. Madsen <klaussm at diku.dk>
Copyright (C) 2006 Marcus Chang <marcus at diku.dk>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
includes HPLSpi;
interface Spi
{
async command result_t init();
/**
* Enable the SPI bus functionality
*/
async command result_t enable(uint8_t params, uint8_t id);
/**
* Disable the SPI bus functionality
*/
async command result_t disable();
/**
* Write a byte to the SPI bus
* @param data value written to the MOSI pin
* @return value read on the MISO pin
*/
async command uint8_t write(uint8_t data);
}
--- NEW FILE: CRC16.nc ---
/*
Copyright (C) 2004 Klaus S. Madsen <klaussm at diku.dk>
Copyright (C) 2006 Marcus Chang <marcus at diku.dk>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
interface CRC16 {
command uint16_t calc(uint8_t *data, uint16_t len);
}
--- NEW FILE: HPL1wireM.nc ---
/*
Copyright (C) 2004 Klaus S. Madsen <klaussm at diku.dk>
Copyright (C) 2006 Marcus Chang <marcus at diku.dk>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
module HPL1wireM {
provides {
interface HPL1wire;
}
}
implementation {
#define B1W_0() P3OUT &= ~0x02
#define B1W_1() P3OUT |= 0x02
#define B1W_R() (P3IN & 0x04)
uint8_t read_one_bit();
void write_one_bit(bool tmp);
result_t bus_1wire_reset();
uint8_t bus_1wire_read();
void bus_1wire_write(uint8_t byte);
void bus_1wire_crc_add(uint8_t *crc, uint8_t byte);
/**********************************************************************
** Bus 1-wire mode enable/disable
**********************************************************************/
command result_t HPL1wire.enable()
{
P2OUT = (P2OUT & 0x0F); /* dont select a module */
P3DIR &= ~0x30; /*UART pins inputs*/
P3SEL &= ~0x30; /*UART pins GPIO*/
P3SEL &= ~0x0F; /*STE, MISO,MOSI,UCLK = GPIO*/
P3DIR |= 0x03; /*MOSI, STE out*/
P3DIR &= ~0x0C; /*MISO, SCK in*/
P3OUT |= 0x03; /*Select 1-wire (STE) and set idle mode (MOSI)*/
B1W_1(); /* power on 1-wire devices */
TOSH_uwait(500);
return SUCCESS;
}
command result_t HPL1wire.disable()
{
B1W_0(); /* power off 1-wire devices */
return SUCCESS;
}
/**********************************************************************
** Execute 1-wire bus reset sequence
**
** Bus reset and device present pulse detection for 1-wire bus.
**********************************************************************/
command result_t HPL1wire.reset()
{
return bus_1wire_reset();
}
result_t bus_1wire_reset()
{
uint8_t i;
result_t retval = FAIL;
/* power off devices for at least 480 microseconds */
B1W_0();
TOSH_uwait(500);
atomic {
/* power on devices */
B1W_1();
/* tPDH: 15-60 us */
// TOSH_uwait(15);
TOSH_uwait(50);
/* scan for 60 microsecond pulse */
for (i = 0; i < 60; i++) {
if (B1W_R() == 0)
retval = SUCCESS;
TOSH_uwait(1);
}
}
/* total recovery time: ~480 microseconds */
TOSH_uwait(420);
TOSH_uwait(500);
return retval;
}
/**********************************************************************
** Write one byte to 1-wire bus
**********************************************************************/
command void HPL1wire.write(uint8_t byte)
{
bus_1wire_write(byte);
}
void bus_1wire_write(uint8_t byte)
{
uint8_t i;
for (i=0; i<8; i++)
{
write_one_bit(byte & 1);
byte >>= 1;
}
}
/**********************************************************************
** Read one byte from 1-wire bus
**********************************************************************/
command uint8_t HPL1wire.read()
{
return bus_1wire_read();
}
uint8_t bus_1wire_read()
{
uint8_t i, byte = 0;
for (i = 0; i < 8; i++)
{
byte >>= 1;
if(read_one_bit())
byte |= 0x80;
}
return byte;
}
/**********************************************************************
**
**********************************************************************/
/**
* Search 1-wire bus
*
* \param device array of device structures
* \param num_id size of array
*
* \return number of devices found on the bus
*
*/
command uint8_t HPL1wire.search(b1w_reg *device, uint8_t num_id)
{
uint8_t i, tmp, byte_index, bit_mask, crc;
uint8_t bit = 0, pass = 0, last_miss = 0;
uint64_t resolved = 0;
/* each loop detects 1 device */
while (num_id > pass)
{
/* check if there are any devices present */
if (bus_1wire_reset() == FAIL)
{
return 0;
}
/* write search-command */
bus_1wire_write(0xF0);
/* resume from previous branch point? */
if (bit > 0) {
/* goto last branch point */
for (i = 0; i < bit; i++) {
byte_index = 7 - (i >> 3);
bit_mask = 0x01 << (i & 7);
/* read two consecutive bits */
tmp = read_one_bit() << 1;
tmp |= read_one_bit();
/* remember latest unresolved confict */
if (tmp == 0 && !(resolved & (0x01 << i)) )
{
last_miss = i;
}
/* select devices (branch) */
write_one_bit(device[pass][byte_index] & bit_mask);
}
/* branch point reached, choose 1 this time */
byte_index = 7 - (bit >> 3);
bit_mask = 0x01 << (bit & 7);
device[pass][byte_index] |= bit_mask;
/* read two consecutive bits */
tmp = read_one_bit() << 1;
tmp |= read_one_bit();
/* select devices (branch) */
write_one_bit(1);
/* mark branch as resolved */
resolved |= (0x01 << bit);
bit++;
}
/* binary search algorithm - queries device's ID 1 bit at a time *
* host selects which devices to include in remainder of the search */
while (bit < 64)
{
tmp = 0;
byte_index = 7 - (bit >> 3);
bit_mask = 1 << (bit & 7);
/* read two consecutive bits */
tmp = read_one_bit() << 1;
tmp |= read_one_bit();
switch(tmp)
{
/* conflicting ID bits - choose one, and branch search */
case 0: //can't tell
/* save latest suitable branch point */
last_miss = bit;
/* choose 0-branch as default */
/* all devices contains a 0 in this ID-bit */
case 1:
tmp = 0;
device[pass][byte_index] &= ~bit_mask;
break;
/* all devices contains a 1 in this ID-bit */
case 2:
tmp = 1;
device[pass][byte_index] |= bit_mask;
break;
case 3: // read error
bit = 64;
break;
}
/* select devices (branch) */
write_one_bit(tmp);
bit++;
}
/* check crc */
crc = 0;
for (i = 7; i > 0; i--) {
bus_1wire_crc_add(&crc, device[pass][i]);
}
if (crc != device[pass][0]) {
for (i = 0; i < 8; i++) {
device[pass][i] = 0xFF;
}
}
/* address scan of one device completed */
pass++;
/* check if all devices are detected (no unresolved conflicts) */
if ( (last_miss == 0) || (num_id <= pass) ) {
break;
} else {
/* back-track */
bit = last_miss;
last_miss = 0;
/* clear resolved branch points that comes after back-track point */
resolved &= (0xFFFFFFFFFFFFFFFF >> (63 - bit) );
/* remember last route in search-tree */
memcpy(device[pass], device[pass - 1], 8);
}
}
/* return number of detected devices */
return pass;
}
/*
* Read one bit
*
*/
uint8_t read_one_bit()
{
uint8_t tmp = 1, i;
atomic {
/* initiate read */
B1W_0();
/* tLOWR: 1 <= t < 15 micro seconds */
/* (best to keep it close to 1us) */
// TOSH_uwait(1);
TOSH_uwait(3);
/* send read pulse */
B1W_1();
/* tRDV: 15 micro seconds */
/* (master sampling window) */
// TOSH_uwait(1);
TOSH_uwait(10);
/* tRELEASE: 0-45 micro seconds */
/* sample for: ~40 us */
for (i = 0; i < 40; i++) {
/* sample value */
if (!B1W_R())
tmp = 0;
TOSH_uwait(1);
}
}
/* default time slot total size: 60 us */
TOSH_uwait(15);
/* minimum relaxation time: 1 us */
// TOSH_uwait(1);
TOSH_uwait(10);
return tmp;
}
/*
* Write one bit
*
*/
void write_one_bit(bool tmp)
{
atomic {
/* initiate write */
B1W_0();
/* sampling occurs 15-60 us after low */
TOSH_uwait(5);
if (tmp)
B1W_1();
/* default time slot size: 60-120 us */
TOSH_uwait(85);
/* minimum relaxation time: 1 us */
B1W_1();
// TOSH_uwait(1);
TOSH_uwait(10);
}
}
/**
* Count 8-bit CRC for 1-wire. Variable crc is updated.
*
* \param crc checksum variable, set to 0 before adding first byte
* \param byte value to add to checksum
*
*/
void bus_1wire_crc_add(uint8_t *crc, uint8_t byte)
{
uint8_t j, bit;
for (j = 0; j < 8; j++)
{
bit = (byte & 1) ^ (*crc & 1);
*crc >>= 1;
if (bit) {
*crc |= 0x80;
*crc ^= 0x0C;
}
byte >>= 1;
}
}
}
--- NEW FILE: HPLU510R1M.nc ---
/*
Copyright (C) 2004 Klaus S. Madsen <klaussm at diku.dk>
Copyright (C) 2006 Marcus Chang <marcus at diku.dk>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
module HPLU510R1M {
provides {
interface ThreeAxisAccel;
}
uses {
interface Timer;
interface Spi;
interface BusArbitration;
interface StdOut;
interface LocalTime;
}
}
implementation {
#include "HPLSpi.h"
#define CYPRESS_STARTUP_TIME 9
#define CYPRESS_SPI_ENABLE 300
#define CYPRESS_SPI_INTERVAL 100
#define CYPRESS_SPI_STATUS 500
bool sensorQueue = FALSE, startQueue = FALSE, setRangeQueue = FALSE;
int16_t x = 0, y = 0, z = 0;
uint8_t status = 0, range = 0;
task void startTask();
task void sensorTask();
task void signalTask();
task void setRangeTask();
/**********************************************************************
** BusArbitration
**********************************************************************/
event result_t BusArbitration.busFree()
{
if (startQueue) {
startQueue = FALSE;
post startTask();
}
if (sensorQueue) {
sensorQueue = FALSE;
post sensorTask();
}
if (setRangeQueue) {
setRangeQueue = FALSE;
post setRangeTask();
}
return SUCCESS;
}
/**********************************************************************
** Timer
**********************************************************************/
event result_t Timer.fired()
{
post sensorTask();
return SUCCESS;
}
/**********************************************************************
** ThreeAxisAccel
**********************************************************************/
command result_t ThreeAxisAccel.getData()
{
post startTask();
return SUCCESS;
}
task void startTask()
{
if (call BusArbitration.getBus() == FAIL) {
startQueue = TRUE;
return;
}
/***********************************************
** select SPI bus and module 3 (U510R1)
***********************************************/
call Spi.enable(BUS_CLOCK_115kHZ, 3);
TOSH_uwait(CYPRESS_SPI_ENABLE);
/* turn on PSoC */
call Spi.write(0xA1);
TOSH_uwait(CYPRESS_SPI_INTERVAL);
/* begin conversion */
call Spi.write(0x20);
TOSH_uwait(CYPRESS_SPI_INTERVAL);
call Spi.disable();
call BusArbitration.releaseBus();
call Timer.start(TIMER_ONE_SHOT, CYPRESS_STARTUP_TIME);
}
task void sensorTask()
{
uint8_t byte = 0;
uint16_t i = 0;
status = ACCEL_STATUS_CONVERSION_FAILED;
// uint32_t t0 = 0, t1 = 0, t2 = 0, t3 = 0;
if (call BusArbitration.getBus() == FAIL)
{
sensorQueue = TRUE;
return;
}
/***********************************************
** select SPI bus and module 3 (U510R1)
***********************************************/
call Spi.enable(BUS_CLOCK_115kHZ, 3);
TOSH_uwait(CYPRESS_SPI_ENABLE);
/***********************************************
** Read Accelerometer
***********************************************/
// call Spi.write(0xA1);
// TOSH_uwait(CYPRESS_SPI_STARTUP);
//t0 = call LocalTime.read();
/* wait until status is 0x70, ie. conversion complete */
do {
byte = call Spi.write(0x20);
TOSH_uwait(CYPRESS_SPI_STATUS);
} while ( byte != 0x70 && i++ < 50);
//t1 = call LocalTime.read();
/* only read value if conversion was successful */
if (byte == 0x70)
{
/* begin block mode readout and wait until ready */
byte = call Spi.write(0xB8);
TOSH_uwait(CYPRESS_SPI_INTERVAL);
//t2 = call LocalTime.read();
// i = 0;
while ( byte != 0xB8 && i++ < 50) {
byte = call Spi.write(0x20);
TOSH_uwait(CYPRESS_SPI_STATUS);
}
//t3 = call LocalTime.read();
/* block mode ready */
if (byte == 0xB8)
{
/* read xyz-acceleration as signed 12bit int */
x = call Spi.write(0x00);
TOSH_uwait(CYPRESS_SPI_INTERVAL);
x <<= 8;
x += call Spi.write(0x00);
TOSH_uwait(CYPRESS_SPI_INTERVAL);
y = call Spi.write(0x00);
TOSH_uwait(CYPRESS_SPI_INTERVAL);
y <<= 8;
y += call Spi.write(0x00);
TOSH_uwait(CYPRESS_SPI_INTERVAL);
z = call Spi.write(0x00);
TOSH_uwait(CYPRESS_SPI_INTERVAL);
z <<= 8;
z += call Spi.write(0x00);
TOSH_uwait(CYPRESS_SPI_INTERVAL);
status = ACCEL_STATUS_SUCCESS;
}
else { status = ACCEL_STATUS_BLOCKMODE_FAILED; }
}
/* shut down accelerometer board */
call Spi.write(0xA0);
TOSH_uwait(CYPRESS_SPI_INTERVAL);
call Spi.disable();
call BusArbitration.releaseBus();
// call StdOut.printBase10uint32(t1-t0);
// call StdOut.print(" ");
// call StdOut.printBase10uint32(t3-t2);
// call StdOut.print(" ");
post signalTask();
}
task void signalTask()
{
uint16_t ux, uy, uz;
/* convert signed 12-bit to unsigned 12-bit */
ux = (uint16_t) (x + 0x0800);
uy = (uint16_t) (y + 0x0800);
uz = (uint16_t) (z + 0x0800);
/* check if value indeed is 12-bit */
if ( ((0xF000 & ux) != 0) || ((0xF000 & uy) != 0) || ((0xF000 & uz) != 0) )
status |= ACCEL_STATUS_OUT_OF_BOUNCE;
/* return acceleration value and status */
signal ThreeAxisAccel.dataReady(ux, uy, uz, status);
}
/**************************************************************************/
command result_t ThreeAxisAccel.setRange(uint8_t new_range)
{
range = new_range;
post setRangeTask();
return SUCCESS;
}
task void setRangeTask()
{
if (call BusArbitration.getBus() == FAIL)
{
setRangeQueue = TRUE;
return;
}
/***********************************************
** select SPI bus and module 3 (U510R1)
***********************************************/
call Spi.enable(BUS_CLOCK_115kHZ, 3);
TOSH_uwait(CYPRESS_SPI_ENABLE);
// call Spi.write(0xA1);
// TOSH_uwait(CYPRESS_SPI_INTERVAL);
call Spi.write(0xB0 | (range & 0x03) );
TOSH_uwait(CYPRESS_SPI_INTERVAL);
// call Spi.write(0xA0);
call Spi.disable();
call BusArbitration.releaseBus();
}
/**********************************************************************
** StdOut
**********************************************************************/
async event result_t StdOut.get(uint8_t data) {
return SUCCESS;
}
}
--- NEW FILE: CRC16M.nc ---
/*
Copyright (C) 2004 Klaus S. Madsen <klaussm at diku.dk>
Copyright (C) 2006 Marcus Chang <marcus at diku.dk>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
module CRC16M
{
provides interface CRC16;
}
implementation
{
#include "crc.h"
command uint16_t CRC16.calc(uint8_t *data, uint16_t len)
{
// In order to be fully compliant with CRC16-CCITT, the CRC must
// have an initial value of 0xFFFF.
uint16_t crc = 0xFFFF;
uint16_t i;
for (i = 0; i < len; i++)
crc = crcByte(crc, data[i]);
return crc;
}
}
--- NEW FILE: HPLSpiM.nc ---
/*
Copyright (C) 2004 Klaus S. Madsen <klaussm at diku.dk>
Copyright (C) 2006 Marcus Chang <marcus at diku.dk>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
module HPLSpiM {
provides {
interface Spi;
}
}
implementation {
#include "HPLSpi.h"
MSP430REG_NORACE(P1DIR);
MSP430REG_NORACE(P1OUT);
MSP430REG_NORACE(P2OUT);
MSP430REG_NORACE(P3DIR);
MSP430REG_NORACE(P3SEL);
MSP430REG_NORACE(P3OUT);
MSP430REG_NORACE(P4DIR);
MSP430REG_NORACE(U0CTL);
MSP430REG_NORACE(U0TCTL);
MSP430REG_NORACE(U0BR1);
MSP430REG_NORACE(U0BR0);
MSP430REG_NORACE(U0MCTL);
MSP430REG_NORACE(ME1);
MSP430REG_NORACE(IE1);
MSP430REG_NORACE(IFG1);
MSP430REG_NORACE(U0TXBUF);
void bus_spi_init(bus_spi_flags flags);
uint8_t bus_spi_exchange(uint8_t out);
bool isSPI();
norace uint8_t oldPrameters, oldId;
async command result_t Spi.init() {
/* spi enable */
P2OUT |= 0xF0; /*module select none*/
bus_spi_init(BUS_STE + BUS_PHASE_INVERT);
P2OUT &= 0xE0; /*module select RF*/
P3OUT |= 0x01;
bus_spi_exchange((uint8_t) 0x10 & 0x3F);
bus_spi_exchange((uint8_t) 0x00);
bus_spi_exchange((uint8_t) 0x00);
P3OUT &= ~0x01;
P3OUT |= 0x01;
bus_spi_exchange((uint8_t) 0x10 & 0x3F);
bus_spi_exchange((uint8_t) 0xF8);
bus_spi_exchange((uint8_t) 0x01);
P3OUT &= ~0x01;
P3OUT |= 0x01;
bus_spi_exchange((uint8_t) 0x06);
P3OUT &= ~0x01;
/* spi disable */
P4DIR = 0; /*parport input mode*/
P3DIR &= ~0x3F; /*bus pins input*/
P3SEL &= ~0x3F; /*turn module i/o off*/
ME1 &= ~(UTXE0 | URXE0 | USPIE0); /* Modules off */
P2OUT |= 0xF0; /*module select none*/
/* Setup crystal oscillator control */
call Spi.enable(BUS_CLOCK_1MHZ, 0);
P1DIR |= 0x40; /*This pin is used as OSC_DISABLE*/
P1OUT |= 0x40; /*That is, 1 means clock is on, 0 disabled*/
call Spi.write((uint8_t) 0xBF); /*Select P1.4-6 as PLD controls*/
call Spi.disable();
return SUCCESS;
}
/**
* Enable the SPI bus functionality
*/
async command result_t Spi.enable(uint8_t newPrameters, uint8_t newId) {
if(isSPI() && (newPrameters == oldPrameters) && (newId == oldId) )
return SUCCESS;
oldPrameters = newPrameters;
oldId = newId;
bus_spi_init((bus_spi_flags) newPrameters);
TOSH_uwait(3);
P2OUT = (P2OUT & 0x0F)| (newId << 4);
return SUCCESS;
}
/**
* Disable the SPI bus functionality
*/
async command result_t Spi.disable() {
P2OUT |= 0xF0; /*module select none*/
P4DIR = 0; /*parport input mode*/
P3DIR &= ~0x3F; /*bus pins input*/
P3SEL &= ~0x3F; /*turn module i/o off*/
ME1 &= ~(UTXE0 | URXE0 | USPIE0); /* Modules off */
return SUCCESS;
}
/**
* Write a byte to the SPI bus
* @param data value written to the MOSI pin
* @return value read on the MISO pin
*/
async command uint8_t Spi.write(uint8_t data) {
return bus_spi_exchange(data);
}
/**
* Bus SPI check.
*
*/
bool isSPI() {
bool _ret = FALSE;
atomic{
if (ME1 & USPIE0)
_ret = TRUE;
}
return _ret;
}
/**
* Bus SPI init.
*
* \param flags SPI mode flags
*
* \return pdTRUE
* \return pdFALSE bus reserved
*/
void bus_spi_init(bus_spi_flags flags)
{
P3DIR &= ~0x30; /*UART pins inputs*/
P3SEL &= ~0x30; /*UART pins GPIO*/
if (flags & (bus_spi_flags)BUS_SPI_SLAVE)
{
return;
}
else
{
uint8_t tctl_bits = STC;
P3SEL |= 0x0E; /*MISO,MOSI,UCLK used*/
P3SEL &= ~0x01; /*STE = GPIO*/
P3DIR |= 0x0B; /*MOSI, STE and UCLK out*/
if (flags & (bus_spi_flags)BUS_STE)
{
P3OUT |= 0x01;
}
else
{
P3OUT &= ~0x01;
}
P3DIR &= ~0x04; /*MISO in*/
/* Reset UART. */
U0CTL = SWRST;
/* SPI master, 8 bit. */
U0CTL |= SYNC+MM+CHAR;
if (flags & (bus_spi_flags)BUS_PHASE_INVERT)
{
tctl_bits |= CKPH;
}
if (flags & (bus_spi_flags)BUS_CLOCK_INVERT)
{
tctl_bits |= CKPL;
}
tctl_bits |= SSEL1; /*Use SMCLK*/
if (flags & (bus_spi_flags)BUS_MULTIMASTER)
{
tctl_bits &= ~STC;
}
U0TCTL = tctl_bits;
switch (flags & 0x70)
{
case BUS_CLOCK_115kHZ:
if (SPI_115K >= 2)
{
U0BR1 = (SPI_115K >> 8);
U0BR0 = SPI_115K;
}
else
{
U0BR1 = 0;
U0BR0 = 2;
}
break;
case BUS_CLOCK_1MHZ:
if (SPI_1M >= 2)
{
U0BR1 = (SPI_1M >> 8);
U0BR0 = SPI_1M;
}
else
{
U0BR1 = 0;
U0BR0 = 2;
}
break;
case BUS_CLOCK_4MHZ:
default: /*Maximum speed*/
U0BR1 = 0;
U0BR0 = 2;
break;
}
U0MCTL = 0;
/* Set ports. */
ME1 &= ~(UTXE0 + URXE0);
ME1 |= USPIE0;
/* Set. */
U0CTL &= ~SWRST;
/* Disable interrupts. */
IE1 &= ~ (URXIE0 + UTXIE0);
}
}
/**
* Bus SPI exchange.
*
* \param out byte to transmit
*
* \return byte from SPI
*/
uint8_t bus_spi_exchange(uint8_t out)
{
U0TXBUF = out;
while(!(IFG1 & URXIFG0));
return U0RXBUF;
}
}
--- NEW FILE: ExtLedsC.nc ---
// $Id: ExtLedsC.nc,v 1.1 2007/03/15 14:40:05 marcus_chang Exp $
/* tab:4
* "Copyright (c) 2000-2003 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) 2002-2003 Intel Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached INTEL-LICENSE
* file. If you do not find these files, copies can be found by writing to
* Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
* 94704. Attention: Intel License Inquiry.
*/
/*
*
* Authors: Jason Hill, David Gay, Philip Levis
* Date last modified: 6/2/03
*
*/
/**
* @author Jason Hill
* @author David Gay
* @author Philip Levis
*/
module ExtLedsC {
provides interface ExtLeds as Leds;
}
implementation
{
uint8_t ledsOn;
enum {
RED_BIT = 1,
GREEN_BIT = 2,
};
async command result_t Leds.init() {
atomic {
ledsOn = 0;
dbg(DBG_BOOT, "LEDS: initialized.\n");
TOSH_MAKE_GIO7_OUTPUT();
TOSH_MAKE_GIO8_OUTPUT();
TOSH_SET_GIO7_PIN();
TOSH_SET_GIO8_PIN();
}
return SUCCESS;
}
async command result_t Leds.redOn() {
dbg(DBG_LED, "LEDS: Red on.\n");
atomic {
TOSH_CLR_GIO7_PIN();
ledsOn |= RED_BIT;
}
return SUCCESS;
}
async command result_t Leds.redOff() {
dbg(DBG_LED, "LEDS: Red off.\n");
atomic {
TOSH_SET_GIO7_PIN();
ledsOn &= ~RED_BIT;
}
return SUCCESS;
}
async command result_t Leds.redToggle() {
result_t rval;
atomic {
if (ledsOn & RED_BIT)
rval = call Leds.redOff();
else
rval = call Leds.redOn();
}
return rval;
}
async command result_t Leds.greenOn() {
dbg(DBG_LED, "LEDS: Green on.\n");
atomic {
TOSH_CLR_GIO8_PIN();
ledsOn |= GREEN_BIT;
}
return SUCCESS;
}
async command result_t Leds.greenOff() {
dbg(DBG_LED, "LEDS: Green off.\n");
atomic {
TOSH_SET_GIO8_PIN();
ledsOn &= ~GREEN_BIT;
}
return SUCCESS;
}
async command result_t Leds.greenToggle() {
result_t rval;
atomic {
if (ledsOn & GREEN_BIT)
rval = call Leds.greenOff();
else
rval = call Leds.greenOn();
}
return rval;
}
async command uint8_t Leds.get() {
uint8_t rval;
atomic {
rval = ledsOn;
}
return rval;
}
async command result_t Leds.set(uint8_t ledsNum) {
atomic {
ledsOn = (ledsNum & 0x7);
if (ledsOn & GREEN_BIT)
TOSH_CLR_GIO8_PIN();
else
TOSH_SET_GIO8_PIN();
if (ledsOn & RED_BIT)
TOSH_CLR_GIO7_PIN();
else
TOSH_SET_GIO7_PIN();
}
return SUCCESS;
}
}
--- NEW FILE: AccelerometerC.nc ---
/*
Copyright (C) 2004 Klaus S. Madsen <klaussm at diku.dk>
Copyright (C) 2006 Marcus Chang <marcus at diku.dk>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
configuration AccelerometerC {
provides {
interface ThreeAxisAccel;
}
uses interface StdOut;
}
implementation {
components HPLU510R1M, HPLSpiM, BusArbitrationC, TimerC, LocalTimeMicroC;
ThreeAxisAccel = HPLU510R1M;
StdOut = HPLU510R1M;
HPLU510R1M.LocalTime -> LocalTimeMicroC.LocalTime;
HPLU510R1M.Timer -> TimerC.Timer[unique("Timer")];
HPLU510R1M.Spi -> HPLSpiM.Spi;
HPLU510R1M.BusArbitration -> BusArbitrationC.BusArbitration[unique("BusArbitration")];
}
--- NEW FILE: StdOutC.nc ---
/*
StdOut configurations - module that buffers and perhaps eventually will do some
printf like thing.
Copyright (C) 2002 Mads Bondo Dydensborg <madsdyd at diku.dk>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* Simple StdOut component that uses Uart interface.
* This configuration maps onto the uart that is normally used to connect onto
* a pc. It also flashes the leds when it sends data to the uart.
*/
configuration StdOutC
{
provides interface StdOut as StdOutUart;
}
implementation
{
#ifndef DEBUG
components StdOutM, HPLUARTC;
#else
components StdOutM, HPLUARTC, IntToLedsC;
StdOutM.IntOutput -> IntToLedsC.IntOutput;
#endif
StdOutUart = StdOutM;
StdOutM.UART -> HPLUARTC;
}
--- NEW FILE: HPL1wire.nc ---
/*
Copyright (C) 2004 Klaus S. Madsen <klaussm at diku.dk>
Copyright (C) 2006 Marcus Chang <marcus at diku.dk>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
includes hpl1wire;
interface HPL1wire {
command result_t enable();
command result_t disable();
command result_t reset();
command uint8_t search(b1w_reg *device, uint8_t num_id);
command uint8_t read();
command void write(uint8_t byte);
}
--- NEW FILE: StdNullM.nc ---
/*
StdNull module - module that has a StdOut interface but just throw
stuff away.
Copyright (C) 2003 Mads Bondo Dydensborg <madsdyd at diku.dk>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Simple StdNull component
*/
/**
This component provides an implementation of the StdOut interface
that throws any message away.
*/
module StdNullM
{
provides interface StdOut;
}
implementation
{
command result_t StdOut.init() {
return SUCCESS;
}
command result_t StdOut.done() {
return SUCCESS;
}
async command int StdOut.print(const char * str) {
return 0;
}
async command int StdOut.printHex(uint8_t c) {
return 0;
}
async command int StdOut.printHexword(uint16_t c) {
return 0;
}
async command int StdOut.printHexlong(uint32_t c) {
return 0;
}
async command int StdOut.printBase10uint8(const uint8_t c)
{
return 0;
}
async command int StdOut.printBase10int8(const int8_t c)
{
return 0;
}
async command int StdOut.printBase10uint16(const uint16_t c)
{
return 0;
}
async command int StdOut.printBase10int16(const int16_t c)
{
return 0;
}
async command int StdOut.printBase10uint32(const uint32_t c)
{
return 0;
}
async command int StdOut.printBase10int32(const int32_t c)
{
return 0;
}
async command int StdOut.printBase2(uint8_t c)
{
return 0;
}
async command int StdOut.printBase2word(uint16_t c)
{
return 0;
}
async command int StdOut.printBase2long(uint32_t c)
{
return 0;
}
async command result_t StdOut.dumpHex(uint8_t ptr[], uint8_t countar, char * sep) {
return 0;
}
/* Default handler for the benefit of our users */
default async event result_t StdOut.get(uint8_t data) { return SUCCESS; }
}
--- NEW FILE: hardware.h ---
#ifndef _H_hardware_h
#define _H_hardware_h
#include "msp430hardware.h"
#include "MSP430ADC12.h"
//#include "CC2420Const.h"
#include "hplcc2420.h"
#include "AM.h"
// Port for Sensinode Micro.4, based on Telosb port
// LEDs - OK for Micro.4, colors?
TOSH_ASSIGN_PIN(RED_LED, 6, 5);
TOSH_ASSIGN_PIN(GREEN_LED, 6, 4);
TOSH_ASSIGN_PIN(YELLOW_LED, 6, 6);
// CC2420 RADIO #defines
TOSH_ASSIGN_PIN(RADIO_CSN, 3, 0);//PLD
//#define TOSH_MAKE_RADIO_CSN_OUTPUT() TOSH_MAKE_FAKE_RADIO_CSN_OUTPUT()
//#define TOSH_SET_RADIO_CSN_PIN() TOSH_CLR_FAKE_RADIO_CSN_PIN()
//#define TOSH_CLR_RADIO_CSN_PIN() TOSH_SET_FAKE_RADIO_CSN_PIN()
//TOSH_ASSIGN_PIN(RADIO_CSN, 3, 1);//PLD
//TOSH_ASSIGN_PIN(RADIO_VREF, , );
//TOSH_ASSIGN_PIN(RADIO_RESET, , );//PLD
TOSH_ASSIGN_PIN(RADIO_FIFOP, 5, 6);//OK
TOSH_ASSIGN_PIN(RADIO_SFD, 1, 7);//OK
//TOSH_ASSIGN_PIN(RADIO_GIO0, 1, 3);//?
TOSH_ASSIGN_PIN(RADIO_FIFO, 5, 5);//OK
//TOSH_ASSIGN_PIN(RADIO_GIO1, 1, 4);//?
TOSH_ASSIGN_PIN(RADIO_CCA, 5, 4);//OK
TOSH_ASSIGN_PIN(CC_FIFOP, 5, 6);
TOSH_ASSIGN_PIN(CC_FIFO, 5, 5);
TOSH_ASSIGN_PIN(CC_SFD, 1, 7);
//TOSH_ASSIGN_PIN(CC_VREN, , );
//TOSH_ASSIGN_PIN(CC_RSTN, , );
#define TOSH_CLR_CC_RSTN_PIN()
#define TOSH_SET_CC_RSTN_PIN()
#define TOSH_SET_CC_VREN_PIN()
#define TOSH_CLR_CC_VREN_PIN()
// UART pins, OK
TOSH_ASSIGN_PIN(SOMI0, 3, 2);
TOSH_ASSIGN_PIN(SIMO0, 3, 1);
TOSH_ASSIGN_PIN(UCLK0, 3, 3);
TOSH_ASSIGN_PIN(UTXD0, 3, 4);
TOSH_ASSIGN_PIN(URXD0, 3, 5);
TOSH_ASSIGN_PIN(UTXD1, 3, 6);
TOSH_ASSIGN_PIN(URXD1, 3, 7);
TOSH_ASSIGN_PIN(UCLK1, 5, 3);
TOSH_ASSIGN_PIN(SOMI1, 5, 2);
TOSH_ASSIGN_PIN(SIMO1, 5, 1);
// ADC, overloaded with Micro.4 connector GPIO
TOSH_ASSIGN_PIN(ADC3, 6, 0);
TOSH_ASSIGN_PIN(ADC4, 6, 1);
TOSH_ASSIGN_PIN(ADC5, 6, 2);
TOSH_ASSIGN_PIN(ADC6, 6, 3);
//P6.4-5 go to LED0-1
TOSH_ASSIGN_PIN(ADC7, 6, 6);
TOSH_ASSIGN_PIN(ADC8, 6, 7);
// GIO pins, corresponsing to external connector pins
TOSH_ASSIGN_PIN(GIO3, 6, 0);
TOSH_ASSIGN_PIN(GIO4, 6, 1);
TOSH_ASSIGN_PIN(GIO5, 6, 2);
TOSH_ASSIGN_PIN(GIO6, 6, 3);
TOSH_ASSIGN_PIN(GIO7, 6, 6);
TOSH_ASSIGN_PIN(GIO8, 6, 7);
TOSH_ASSIGN_PIN(GIO9, 2, 0);
TOSH_ASSIGN_PIN(GIO10, 5, 7);
// 1-Wire, used through PLD
// FLASH, flash_select goes to the PLD
//TOSH_ASSIGN_PIN(FLASH_CS, , );//PLD
// This should work also with the M25P40 on Micro.4
// send a bit via bit-banging to the flash
void TOSH_FLASH_M25P_DP_bit(bool set) {
if (set)
TOSH_SET_SIMO0_PIN();
else
TOSH_CLR_SIMO0_PIN();
TOSH_SET_UCLK0_PIN();
TOSH_CLR_UCLK0_PIN();
}
// need to undef atomic inside header files or nesC ignores the directive
#undef atomic
void TOSH_SET_PIN_DIRECTIONS(void)
{
// reset all of the ports to be input and using i/o functionality
atomic
{
P1SEL = 0x00;
P2SEL = 0x00;
P3SEL = 0x00;
P4SEL = 0x00;
P5SEL = 0x00;
// P6SEL = 0x00;
P4DIR = 0; /*parport input mode*/
P3DIR &= ~0x3F; /*bus pins input*/
P2DIR |= 0xF0;
P2OUT |= 0xF0; /*module select none*/
P3SEL |= (BIT6|BIT7);
P3DIR |= BIT6; /* Use P3.6 as TX */
P3DIR &= ~BIT7; /* Use P3.7 as RX */
P5DIR &= ~(BIT2|BIT1); /* SPI pins are hooked into these on micro.4*/
#if 0
P1OUT = 0x00;
P2OUT = 0x00;
P3OUT = 0x00;
P4OUT = 0x00;
P5OUT = 0x00;
P6OUT = 0x00;
P1DIR = 0xFF;
P2DIR = 0xFF;
P3DIR = 0xFF;
P4DIR = 0x00;
P5DIR = 0xFF;
P6DIR = 0xFF;
P1DIR = 0x00;
P2DIR = 0x00;
P3DIR = 0x00;
P4DIR = 0x00;
P5DIR = 0x00;
P6DIR = 0x00;
// BCSCTL1 = 0x80; /* XT2OFF | LFXT1=low | DIVA=00 -> 1 | XT5V=0 | RSEL=000 */
// BCSCTL2 = 0x88; /* SELMx=10 -> XT2 | DIVMx=00 -> 1 | SELS=1 -> MCLK | DIVS=00 -> 1 | DCOR=0 */
// DCOCTL = 0x00; /* DCO is not used */
//P1DIR = 0xe0;
//P1OUT = 0x00;
// P2DIR |= 0xF0;
P2OUT |= 1 << 4; //0xF0; /*module select none*/
P3OUT |= 0x01; /* unselect flash module */
// P3DIR &= ~0x3F; /*bus pins input*/
// P4DIR = 0; /*parport input mode*/
/////////////////////////////////////////////////////////////////////////
// Clear bit 1 and 2, as the HPLUSART expects this
/////////////////////////////////////////////////////////////////////////
P5DIR = 0xFB; /* Set RX1 (P5.2) as input pin */
// P5DIR = 0xf9;
// P5OUT = 0xff;
// P6DIR = 0xff;
// P6OUT = 0x00;
#endif
P1IE = 0;
P2IE = 0;
// the commands above take care of the pin directions
// there is no longer a need for explicit set pin
// directions using the TOSH_SET/CLR macros
// wait 20ms for the flash to startup
TOSH_uwait(1024*10);
TOSH_uwait(1024*10);
}//atomic
}
#endif // _H_hardware_h
--- NEW FILE: StdOut.nc ---
/*
Copyright (C) 2002 Mads Bondo Dydensborg <madsdyd at diku.dk>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* Interface that provides a primitive way to output chars, most
* likely to one of the uarts. It is also possibly to use the get
* event to get an event when chars are received from the uart.
*/
interface StdOut {
/** Initialize
@return Wheter initialization was succesful or not.
*/
command result_t init();
command result_t done();
/** Put a string into the output buffer.
@param str Nulterminated string to enter into the buffer.
@return Number of bytes actually buffered. */
async command int print(const char * str);
/** Format value as a hex string and put it into the output buffer.
@param c Numberical value to be formatted and printed.
@return Number of bytes actually buffered. */
async command int printHex(uint8_t c);
/** Format value as a hex string and put it into the output buffer.
@param c Numberical value to be formatted and printed.
@return Number of bytes actually buffered. */
async command int printHexword(uint16_t c);
/** Format value as a hex string and put it into the output buffer.
@param c Numberical value to be formatted and printed.
@return Number of bytes actually buffered. */
async command int printHexlong(uint32_t c);
/** Put an array of hex values into the buffer, formatted as a string.
@param ptr[] Array of values to be formatted and printed.
@param count Length of array.
@param sep Char to be printed between values in the buffer.
@return Number of bytes actually buffered. */
async command result_t dumpHex(uint8_t ptr[], uint8_t count, char * sep);
/** Format value as a base10 string and put it into the output buffer.
@param c Numberical value to be formatted and printed.
@return Number of bytes actually buffered. */
async command int printBase10uint8(const uint8_t c);
/** Format value as a base10 string and put it into the output buffer.
@param c Numberical value to be formatted and printed.
@return Number of bytes actually buffered. */
async command int printBase10int8(const int8_t c);
/** Format value as a base10 string and put it into the output buffer.
@param c Numberical value to be formatted and printed.
@return Number of bytes actually buffered. */
async command int printBase10uint16(const uint16_t c);
/** Format value as a base10 string and put it into the output buffer.
@param c Numberical value to be formatted and printed.
@return Number of bytes actually buffered. */
async command int printBase10int16(const int16_t c);
/** Format value as a base10 string and put it into the output buffer.
@param c Numberical value to be formatted and printed.
@return Number of bytes actually buffered. */
async command int printBase10uint32(const uint32_t c);
/** Format value as a base10 string and put it into the output buffer.
@param c Numberical value to be formatted and printed.
@return Number of bytes actually buffered. */
async command int printBase10int32(const int32_t c);
/** Format value as a base2 string and put it into the output buffer.
@param c Numberical value to be formatted and printed.
@return Number of bytes actually buffered. */
async command int printBase2(uint8_t c);
/** Format value as a base2 string and put it into the output buffer.
@param c Numberical value to be formatted and printed.
@return Number of bytes actually buffered. */
async command int printBase2word(uint16_t c);
/** Format value as a base2 string and put it into the output buffer.
@param c Numberical value to be formatted and printed.
@return Number of bytes actually buffered. */
async command int printBase2long(uint32_t c);
/** Get data from "stdin".
We need this method to be able to use the Uarts and you can connect to
it to get any data send remotely to the uart/pipe/whatever.
@param data Value received
@return Just return SUCCESS */
async event result_t get(uint8_t data);
}
--- NEW FILE: StdNullC.nc ---
/*
StdNull configurations - modulethat has a StdOut interface but just throw
stuff away.
Copyright (C) 2003 Mads Bondo Dydensborg <madsdyd at diku.dk>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
This configuration provides an implementation of the StdOut interface
that throws any message away.
*/
configuration StdNullC
{
provides interface StdOut as StdOutUart;
}
implementation
{
components StdNullM;
StdOutUart = StdNullM;
}
--- NEW FILE: hpl1wire.h ---
typedef uint8_t b1w_reg[8];
--- NEW FILE: StdOutM.nc ---
/*
StdOut module - module that buffers and perhaps eventually will do some
printf like thing.
Copyright (C) 2002 Mads Bondo Dydensborg <madsdyd at diku.dk>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Simple StdOut component, uses Uart interface, buffers into 200 char buffer
*/
/**
* Simple StdOut component that uses Uart interface.
* <p>This configuration maps onto the uart that is normally used to connect onto
* a pc.</p>
*
* <p>Please note that this component blocks interrupts and copies
* data - it is not a very good TinyOS citizen. Its a debug tool.</p>
*/
module StdOutM
{
provides interface StdOut;
uses interface HPLUART as UART;
}
#define STDOUT_BUFFER_SIZE 1000 // This will probably not be enough always.
// Use the leds to print
//#define DEBUG
implementation
{
/** The buffer used to buffer into. This is 200 bytes */
char buffer[STDOUT_BUFFER_SIZE];
char * bufferhead;
char * buffertail;
char * bufferend;
int isOutputting;
int count;
/* Init */
command result_t StdOut.init() {
dbg(DBG_USR1, "StdOut starting ......\n");
call UART.init();
atomic {
bufferhead = buffer;
buffertail = buffer;
bufferend = buffer + STDOUT_BUFFER_SIZE;
isOutputting = FALSE;
count = 0;
}
return SUCCESS;
}
command result_t StdOut.done() {
call UART.stop();
return SUCCESS;
}
/* Add a string to the circular buffer. The string must be null-terminated.
The number of chars written will be returned (not including the trailing \0).
*/
async command int StdOut.print(const char * str) {
/* Oh, the horror */
int na_countret;
atomic {
bool return_flag = FALSE;
int countret = 0;
dbg(DBG_USR1, "StdOut print \"%s\"\n", str);
/* Split into two passes - tail after head or before */
if (buffertail >= bufferhead) {
while ((buffertail < bufferend) && (*str !=0)) {
// while ((buffertail < bufferend) && (*buffertail++ = *str)) {
*buffertail = *str;
++buffertail;
// dbg(DBG_USR1, "StdOut print - copying \"%c\"\n", *str);
++str;
++countret;
};
/* Did we reach the end of the buffer ? */
if (buffertail == bufferend) {
buffertail = buffer;
} else {
/* Done with the string */
if (!isOutputting) {
// dbg(DBG_USR1, "StdOut - putting \"%c\"\n", *bufferhead);
call UART.put(*bufferhead);
isOutputting = TRUE; // Race condition!
}
return_flag = TRUE;
// return countret;
}
} /* buffertail >= buffertail */
if (!return_flag) {
// dbg(DBG_USR1, "StdOut print - past bufferend \"%s\"\n", str);
/* If we reach here, there are more string, and buffertail <= bufferhead */
while (buffertail < bufferhead && (*str != 0)) {
*buffertail = *str;
++buffertail;
++str;
++countret;
};
if (!isOutputting) {
call UART.put(*bufferhead);
isOutputting = TRUE; // Race condition!
}
/* Did we reach the end of the buffer ? */
if (buffertail == bufferhead) {
if (!isOutputting) {
// dbg(DBG_USR1, "StdOut - putting \"%c\"\n", *bufferhead);
call UART.put(*bufferhead);
isOutputting = TRUE; // Race condition!
}
return_flag = TRUE;
// return countret;
}
}
if (!return_flag) {
/* Done with the string */
if (!isOutputting) {
// dbg(DBG_USR1, "StdOut - putting \"%c\"\n", *bufferhead);
call UART.put(*bufferhead);
isOutputting = TRUE; // Race condition!
}
return_flag = TRUE;
// return countret;
}
na_countret = countret;
} /* Atomic */
return na_countret;
}
/* Add a hex number to the circular buffer
- code is meant to be easy to read */
async command int StdOut.printHex(uint8_t c) {
char str[3];
uint8_t v;
/* Left digit */
v = (0xF0 & c) >> 4;
if (v < 0xA) {
str[0] = v + '0';
} else {
str[0] = v - 0xA + 'A';
}
/* Right digit */
v = (0xF & c);
if (v < 0xA) {
str[1] = v + '0';
} else {
str[1] = v - 0xA + 'A';
}
str[2] = 0;
return call StdOut.print(str);
}
/* Add a word number to the circular buffer as hex
- code is meant to be easy to read */
async command int StdOut.printHexword(uint16_t c) {
return call StdOut.printHex((0xFF00 & c) >> 8)
+ call StdOut.printHex(0xFF & c);
}
/* Add a long number to the circular buffer as hex
- code is meant to be easy to read */
async command int StdOut.printHexlong(uint32_t c) {
return call StdOut.printHex((0xFF000000 & c) >> 24)
+ call StdOut.printHex((0xFF0000 & c) >> 16)
+ call StdOut.printHex((0xFF00 & c) >> 8)
+ call StdOut.printHex(0xFF & c);
}
/* Add a uint8_t base10 number to the circular buffer */
async command int StdOut.printBase10uint8(const uint8_t c)
{
bool print = 0;
char str[4];
uint8_t idx = 0, tmp;
uint32_t v;
v = c;
// Digit 10^2
tmp = v / 100;
if (tmp != 0 || print) {
str[idx] = tmp + 48;
idx++;
v = v % 100;
print = 1;
}
// Digit 10^1
tmp = v / 10;
if (tmp != 0 || print) {
str[idx] = tmp + 48;
idx++;
v = v % 10;
print = 1;
}
// Digit 10^0
str[idx] = v + 48;
idx++;
str[idx] = 0;
return call StdOut.print(str);
}
/* Add a uint8_t base10 number to the circular buffer */
async command int StdOut.printBase10int8(const int8_t c)
{
uint8_t counter = 0, v;
if (c < 0) {
counter = call StdOut.print("-");
v = -1 * c;
} else {
v = (uint8_t) c;
}
counter += call StdOut.printBase10uint8(v);
return counter;
}
/* Add a uint16_t base10 number to the circular buffer */
async command int StdOut.printBase10uint16(const uint16_t c)
{
bool print = 0;
char str[6];
uint8_t idx = 0, tmp;
uint32_t v;
v = c;
// Digit 10^4
tmp = v / 10000;
if (tmp != 0 || print) {
str[idx] = tmp + 48;
idx++;
v = v % 10000;
print = 1;
}
// Digit 10^3
tmp = v / 1000;
if (tmp != 0 || print) {
str[idx] = tmp + 48;
idx++;
v = v % 1000;
print = 1;
}
// Digit 10^2
tmp = v / 100;
if (tmp != 0 || print) {
str[idx] = tmp + 48;
idx++;
v = v % 100;
print = 1;
}
// Digit 10^1
tmp = v / 10;
if (tmp != 0 || print) {
str[idx] = tmp + 48;
idx++;
v = v % 10;
print = 1;
}
// Digit 10^0
str[idx] = v + 48;
idx++;
str[idx] = 0;
return call StdOut.print(str);
}
/* Add a uint16_t base10 number to the circular buffer */
async command int StdOut.printBase10int16(const int16_t c)
{
uint8_t counter = 0;
uint16_t v;
if (c < 0) {
counter = call StdOut.print("-");
v = -1 * c;
} else {
v = (uint16_t) c;
}
counter += call StdOut.printBase10uint16(v);
return counter;
}
/* Add a uint32_t base10 number to the circular buffer */
async command int StdOut.printBase10uint32(const uint32_t c)
{
bool print = 0;
char str[11];
uint8_t idx = 0, tmp;
uint32_t v;
v = c;
// Digit 10^9
tmp = v / 1000000000;
if (tmp != 0) {
str[idx] = tmp + 48;
idx++;
v = v % 1000000000;
print = 1;
}
// Digit 10^8
tmp = v / 100000000;
if (tmp != 0 || print) {
str[idx] = tmp + 48;
idx++;
v = v % 100000000;
print = 1;
}
// Digit 10^7
tmp = v / 10000000;
if (tmp != 0 || print) {
str[idx] = tmp + 48;
idx++;
v = v % 10000000;
print = 1;
}
// Digit 10^6
tmp = v / 1000000;
if (tmp != 0 || print) {
str[idx] = tmp + 48;
idx++;
v = v % 1000000;
print = 1;
}
// Digit 10^5
tmp = v / 100000;
if (tmp != 0 || print) {
str[idx] = tmp + 48;
idx++;
v = v % 100000;
print = 1;
}
// Digit 10^4
tmp = v / 10000;
if (tmp != 0 || print) {
str[idx] = tmp + 48;
idx++;
v = v % 10000;
print = 1;
}
// Digit 10^3
tmp = v / 1000;
if (tmp != 0 || print) {
str[idx] = tmp + 48;
idx++;
v = v % 1000;
print = 1;
}
// Digit 10^2
tmp = v / 100;
if (tmp != 0 || print) {
str[idx] = tmp + 48;
idx++;
v = v % 100;
print = 1;
}
// Digit 10^1
tmp = v / 10;
if (tmp != 0 || print) {
str[idx] = tmp + 48;
idx++;
v = v % 10;
print = 1;
}
// Digit 10^0
str[idx] = v + 48;
idx++;
str[idx] = 0;
return call StdOut.print(str);
}
/* Add a uint32_t base10 number to the circular buffer */
async command int StdOut.printBase10int32(const int32_t c)
{
uint8_t counter = 0;
uint32_t v;
if (c < 0) {
counter = call StdOut.print("-");
v = -1 * c;
} else {
v = (uint32_t) c;
}
counter += call StdOut.printBase10uint32(v);
return counter;
}
/* Add a 8-bit base2 number to the circular buffer */
async command int StdOut.printBase2(uint8_t c)
{
char str[9];
uint8_t i, v;
v = c;
for (i = 0; i < 8; i++)
{
str[7 - i] = ((v & 0x01) == 0x01) ? '1' : '0';
v >>= 1;
}
str[8] = 0;
return call StdOut.print(str);
}
/* Add a 16-bit base2 number to the circular buffer */
async command int StdOut.printBase2word(uint16_t c)
{
char str[17];
uint8_t i;
uint16_t v;
v = c;
for (i = 0; i < 16; i++)
{
str[15 - i] = ((v & 0x0001) == 0x0001) ? '1' : '0';
v >>= 1;
}
str[16] = 0;
return call StdOut.print(str);
}
/* Add a 32-bit base10 number to the circular buffer */
async command int StdOut.printBase2long(uint32_t c)
{
char str[33];
uint8_t i;
uint32_t v;
v = c;
for (i = 0; i < 32; i++)
{
str[31 - i] = ((v & 0x00000001) == 0x00000001) ? '1' : '0';
v >>= 1;
}
str[32] = 0;
return call StdOut.print(str);
}
/** Dump an array of hex's
*
* \param ptr - array of uint8_t values
* \param count - count of values in array
* \param sep - optional seperator string
* Always return succes, even if something went wrong.
*/
async command result_t StdOut.dumpHex(uint8_t ptr[], uint8_t countar, char * sep) {
int i;
for (i = 0; i < countar; i++) {
if (i != 0) {
call StdOut.print(sep);
}
call StdOut.printHex(ptr[i]);
}
return SUCCESS;
}
/* Handle emptying the buffer - the one in head have now been outputted
and we need to output the next, if needed. */
async event result_t UART.putDone() {
// dbg(DBG_USR1, "StdOut putDone\n");
atomic {
/* Adjust bufferhead */
++bufferhead;
++count;
if (bufferhead == bufferend) {
bufferhead = buffer;
}
/* Check for more bytes */
if (bufferhead != buffertail) {
// dbg(DBG_USR1, "StdOut - putting \"%c\"\n", *bufferhead);
call UART.put(*bufferhead);
isOutputting = TRUE;
} else {
isOutputting = FALSE;
}
}
return SUCCESS;
}
default async event result_t StdOut.get(uint8_t data) {
return SUCCESS;
}
/* Handle getting data such that the user of this interface can get data. */
async event result_t UART.get(uint8_t data) {
signal StdOut.get(data);
return SUCCESS;
}
}
--- NEW FILE: ExtLeds.nc ---
// $Id: ExtLeds.nc,v 1.1 2007/03/15 14:40:06 marcus_chang Exp $
/* tab:4
* "Copyright (c) 2000-2003 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) 2002-2003 Intel Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached INTEL-LICENSE
* file. If you do not find these files, copies can be found by writing to
* Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
* 94704. Attention: Intel License Inquiry.
*/
/*
* Authors: Jason Hill, David Gay, Philip Levis
* Date last modified: 6/1/03
*
*
*/
/**
* Abstraction of the LEDs.
*
* @author Jason Hill
* @author David Gay
* @author Philip Levis
*/
interface ExtLeds {
/**
* Initialize the LEDs; among other things, initialization turns
* them all off.
*
* @return SUCCESS always.
*
*/
async command result_t init();
/**
* Turn the red LED on.
*
* @return SUCCESS always.
*
*/
async command result_t redOn();
/**
* Turn the red LED off.
*
* @return SUCCESS always.
*
*/
async command result_t redOff();
/**
* Toggle the red LED. If it was on, turn it off. If it was off,
* turn it on.
*
* @return SUCCESS always.
*
*/
async command result_t redToggle();
/**
* Turn the green LED on.
*
* @return SUCCESS always.
*
*/
async command result_t greenOn();
/**
* Turn the green LED off.
*
* @return SUCCESS always.
*
*/
async command result_t greenOff();
/**
* Toggle the green LED. If it was on, turn it off. If it was off,
* turn it on.
*
* @return SUCCESS always.
*
*/
async command result_t greenToggle();
/**
* Get current Leds information
*
* @return A uint8_t typed value representing Leds status
*
*/
async command uint8_t get();
/**
* Set Leds to a specified value
*
* @param value ranging from 0 to 7 inclusive
*
* @return SUCCESS Always
*
*/
async command result_t set(uint8_t value);
}
--- NEW FILE: IntToLedsM.nc ---
// $Id: IntToLedsM.nc,v 1.1 2007/03/15 14:40:06 marcus_chang Exp $
/* tab:4
* "Copyright (c) 2000-2003 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) 2002-2003 Intel Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached INTEL-LICENSE
* file. If you do not find these files, copies can be found by writing to
* Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
* 94704. Attention: Intel License Inquiry.
*/
/*
* Authors: Jason Hill, David Gay, Philip Levis, Nelson Lee
* Date last modified: 6/25/02
*
*/
/**
* @author Jason Hill
* @author David Gay
* @author Philip Levis
* @author Nelson Lee
*/
module IntToLedsM {
uses interface Leds;
provides interface IntOutput;
provides interface StdControl;
}
implementation
{
command result_t StdControl.init()
{
call Leds.init();
call Leds.redOff();
call Leds.yellowOff();
call Leds.greenOff();
return SUCCESS;
}
command result_t StdControl.start() {
return SUCCESS;
}
command result_t StdControl.stop() {
return SUCCESS;
}
task void outputDone()
{
signal IntOutput.outputComplete(1);
}
async command result_t IntOutput.output(uint16_t value)
{
if (value & 1) call Leds.redOn();
else call Leds.redOff();
if (value & 2) call Leds.greenOn();
else call Leds.greenOff();
if (value & 4) call Leds.yellowOn();
else call Leds.yellowOff();
post outputDone();
return SUCCESS;
}
}
--- NEW FILE: TOSBoot_platform.h ---
// $Id: TOSBoot_platform.h,v 1.1 2007/03/15 14:40:07 marcus_chang Exp $
/* tab:2
* "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."
*/
/**
* @author Jonathan Hui <jwhui at cs.berkeley.edu>
*/
#ifndef __TOSBOOT_PLATFORM_H__
#define __TOSBOOT_PLATFORM_H__
enum {
// address of TOSBoot args in internal flash
TOSBOOT_ARGS_ADDR = 0x70,
// number of resets to force golden image
TOSBOOT_GESTURE_MAX_COUNT = 3,
// address of the golden image in external flash
TOSBOOT_GOLDEN_IMG_ADDR = 0xf0000L,
// size of each internal program flash page
TOSBOOT_INT_PAGE_SIZE = 512L,
};
enum {
DELUGE_MIN_ADV_PERIOD_LOG2 = 9,
DELUGE_QSIZE = 1,
};
#endif
--- NEW FILE: HPLSpi.h ---
#ifndef _H_HPLSpi_h
#define _H_HPLSpi_h
#define configCPU_CLOCK_HZ ( ( unsigned long ) 8000000 )
#ifndef configSMCLK_HZ
#define SPI_115K (configCPU_CLOCK_HZ / 115200)
#define SPI_1M (configCPU_CLOCK_HZ / 1000000)
#define SPI_4M (configCPU_CLOCK_HZ / 4000000)
#else
#define SPI_115K (configSMCLK_HZ / 115200)
#define SPI_1M (configSMCLK_HZ / 1000000)
#define SPI_4M (configSMCLK_HZ / 4000000)
#endif
typedef enum
{
BUS_SPI_DEFAULT = 0x00,
BUS_STE = 0x01,
BUS_PHASE_INVERT = 0x02,
BUS_CLOCK_INVERT = 0x04,
BUS_MULTIMASTER = 0x08,
BUS_CLOCK_115kHZ = 0x20,
BUS_CLOCK_1MHZ = 0x40,
BUS_CLOCK_4MHZ = 0x60,
BUS_SPI_SLAVE = 0x80
}bus_spi_flags;
#endif//_H_HPLSpi_h
--- NEW FILE: HPLKBI.nc ---
/*
HPLKBI interface
Author: Jacob Munk-Stander <jacobms at diku.dk>
Last modified: May 24, 2005
*/
interface HPLKBI
{
command result_t init();
event result_t switchDown(uint8_t sw);
}
--- NEW FILE: HPLKBIM.nc ---
/*
HPLKBI implementation for HCS08
Author: Jacob Munk-Stander <jacobms at diku.dk>
Modified: May 24, 2005
Last modified: July 6, 2006, marcus at diku.dk
*/
module HPLKBIM
{
provides interface HPLKBI as KBI;
uses interface Timer;
}
implementation
{
uint8_t sw = 0x00;
command result_t KBI.init()
{
atomic
{
TOSH_MAKE_GIO9_INPUT();
TOSH_MAKE_GIO10_INPUT();
}
call Timer.start(TIMER_REPEAT, 100);
return SUCCESS;
}
event result_t Timer.fired()
{
uint8_t i = 0;
if (TOSH_READ_GIO10_PIN() == 0x80)
i |= 0x01;
if (TOSH_READ_GIO9_PIN() == 0x01)
i |= 0x02;
if (i != sw) {
sw = i;
signal KBI.switchDown(i);
}
return SUCCESS;
}
}
- Previous message: [Tinyos-contrib-commits]
CVS: tinyos-1.x/contrib/diku/sensinode/apps/DataCollectorMote
ProtocolClientM.nc, NONE, 1.1 DataCollectorMote.nc, NONE,
1.1 Makefile, NONE, 1.1 DataCollectorMoteM.nc, NONE,
1.1 ProtocolClientC.nc, NONE, 1.1 SamplingControllerM.nc, NONE, 1.1
- Next message: [Tinyos-contrib-commits]
CVS: tinyos-1.x/contrib/diku/sensinode/apps/DataCollector
FIFOBufferManagerM.nc, NONE, 1.1 StatisticsM.nc, NONE,
1.1 Compression.nc, NONE, 1.1 DatasetManagerM.nc, NONE,
1.1 FlashManagerReader.nc, NONE, 1.1 StatisticsReader.nc, NONE,
1.1 ProtocolStarter.nc, NONE, 1.1 CompressionM.nc, NONE,
1.1 FIFOBufferManager.nc, NONE, 1.1 ConnectionM.nc, NONE,
1.1 BufferManager.nc, NONE, 1.1 Connection.nc, NONE,
1.1 FlashManagerC.nc, NONE, 1.1 DatasetManager.nc, NONE,
1.1 Statistics.nc, NONE, 1.1 config.h, NONE,
1.1 FlashManagerM.nc, NONE, 1.1 ProtocolC.nc, NONE,
1.1 SamplingC.nc, NONE, 1.1 BufferManager.h, NONE,
1.1 FlashManagerWriter.nc, NONE, 1.1 StatisticsC.nc, NONE,
1.1 ProtocolM.nc, NONE, 1.1 BufferManagerM.nc, NONE,
1.1 SamplingM.nc, NONE, 1.1 DatasetManager.h, NONE,
1.1 CompressionC.nc, NONE, 1.1 ConnectionC.nc, NONE, 1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Tinyos-contrib-commits
mailing list