[Tinyos-contrib-commits]
CVS: tinyos-1.x/contrib/shockfish/apps/TOSBaseGPRS
Makefile, NONE, 1.1 TOSBaseGPRS.nc, NONE, 1.1 TOSBaseGPRSM.nc,
NONE, 1.1
rogmeier
rogmeier at users.sourceforge.net
Wed Sep 13 00:54:38 PDT 2006
Update of /cvsroot/tinyos/tinyos-1.x/contrib/shockfish/apps/TOSBaseGPRS
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv15657
Added Files:
Makefile TOSBaseGPRS.nc TOSBaseGPRSM.nc
Log Message:
TOSBaseGPRS for MamaBoard. (Maxime Muller)
--- NEW FILE: Makefile ---
COMPONENT=TOSBaseGPRS
SENSORBOARD = mamaboard
CFLAGS += -DTOSH_MAX_TASKS_LOG2=8
ifeq ($(SENSORBOARD),mamaboard)
PFLAGS += -DMAMABOARD
PFLAGS += -I$(TOSDIR)/../contrib/shockfish/tos/sensorboards/mamaboard/
endif
include $(MAKERULES)
--- NEW FILE: TOSBaseGPRS.nc ---
// $Id: TOSBaseGPRS.nc,v 1.1 2006/09/13 07:54:36 rogmeier 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.
*/
/**
* @author Phil Buonadonna
* @author Gilman Tolle
* @author Maxime Muller
*/
configuration TOSBaseGPRS {
}
implementation {
components Main,
TOSBaseGPRSM,
RadioCRCPacket as Comm,
FramerM,
UART,
TimerC,
LedsC;
Main.StdControl -> TOSBaseGPRSM;
Main.StdControl -> TimerC;
TOSBaseGPRSM.UARTControl -> FramerM;
TOSBaseGPRSM.UARTSend -> FramerM;
TOSBaseGPRSM.UARTReceive -> FramerM;
TOSBaseGPRSM.UARTTokenReceive -> FramerM;
TOSBaseGPRSM.RadioControl -> Comm;
TOSBaseGPRSM.RadioSend -> Comm;
TOSBaseGPRSM.RadioReceive -> Comm;
TOSBaseGPRSM.Leds -> LedsC;
TOSBaseGPRSM.InitGPRS -> TimerC.Timer[unique("Timer")];
TOSBaseGPRSM.RefreshGPRS -> TimerC.Timer[unique("Timer")];
FramerM.ByteControl -> UART;
FramerM.ByteComm -> UART;
}
--- NEW FILE: TOSBaseGPRSM.nc ---
// $Id: TOSBaseGPRSM.nc,v 1.1 2006/09/13 07:54:36 rogmeier 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.
*/
/*
* @author Maxime Muller
* (derived from Phil Buonadonna, Gilman Tolle's TOSBase)
*/
/*
* TOSBaseM bridges packets between a serial channel and the radio.
* Messages moving from serial to radio will be tagged with the group
* ID compiled into the TOSBase, and messages moving from radio to
* serial will be filtered by that same group id.
*/
#ifndef TOSBASE_BLINK_ON_DROP
#define TOSBASE_BLINK_ON_DROP
#endif
includes sensorboard;
module TOSBaseGPRSM {
provides interface StdControl;
uses {
interface StdControl as UARTControl;
interface BareSendMsg as UARTSend;
interface ReceiveMsg as UARTReceive;
interface TokenReceiveMsg as UARTTokenReceive;
interface StdControl as RadioControl;
interface BareSendMsg as RadioSend;
interface ReceiveMsg as RadioReceive;
interface Timer as InitGPRS;
interface Timer as RefreshGPRS;
interface Leds;
}
}
implementation
{
enum {
UART_QUEUE_LEN = 12,
RADIO_QUEUE_LEN = 12,
REFRESH_GPRS_PERIOD = 30000,
};
TOS_Msg uartQueueBufs[UART_QUEUE_LEN];
uint8_t uartIn, uartOut;
bool uartBusy, uartCount;
TOS_Msg radioQueueBufs[RADIO_QUEUE_LEN];
uint8_t radioIn, radioOut;
bool radioBusy, radioCount;
task void UARTSendTask();
task void RadioSendTask();
void failBlink();
void dropBlink();
void processUartPacket(TOS_MsgPtr Msg, bool wantsAck, uint8_t Token);
command result_t StdControl.init() {
result_t ok1, ok2, ok3;
// IGT line
TOSH_CLR_GPRS_IGT_PIN();
TOSH_MAKE_GPRS_IGT_OUTPUT();
// GPIO2 and SYNC inputs
TOSH_MAKE_GPRS_GPIO2_INPUT();
TOSH_MAKE_GPRS_SYNC_INPUT();
// enable GPRS voltage regulator
TOSH_MAKE_GPRS_EN_OUTPUT();
TOSH_SEL_GPRS_EN_IOFUNC();
TOSH_SET_GPRS_EN_PIN();
uartIn = uartOut = uartCount = 0;
uartBusy = FALSE;
radioIn = radioOut = radioCount = 0;
radioBusy = FALSE;
ok1 = call UARTControl.init();
ok2 = call RadioControl.init();
ok3 = call Leds.init();
dbg(DBG_BOOT, "TOSBase initialized\n");
return rcombine3(ok1, ok2, ok3);
}
command result_t StdControl.start() {
result_t res;
res = call UARTControl.start();
res = rcombine(res, call RadioControl.start());
res = rcombine(res, call InitGPRS.start(TIMER_ONE_SHOT, 1000));
res = rcombine(res, call RefreshGPRS.start(TIMER_REPEAT,REFRESH_GPRS_PERIOD));
TOSH_SET_GPRS_IGT_PIN();
TOSH_SET_RED_LED_PIN();
return res;
}
command result_t StdControl.stop() {
result_t ok1, ok2;
ok1 = call UARTControl.stop();
ok2 = call RadioControl.stop();
return rcombine(ok1, ok2);
}
event result_t InitGPRS.fired() {
TOSH_CLR_GPRS_IGT_PIN();
TOSH_CLR_RED_LED_PIN();
return SUCCESS;
}
event result_t RefreshGPRS.fired() {
TOSH_SET_GPRS_IGT_PIN();
TOSH_SET_RED_LED_PIN();
return call InitGPRS.start(TIMER_ONE_SHOT, 1000);
}
event TOS_MsgPtr RadioReceive.receive(TOS_MsgPtr Msg) {
dbg(DBG_USR1, "TOSBase received radio packet.\n");
if ((!Msg->crc) || (Msg->group != TOS_AM_GROUP))
return Msg;
if (uartCount < UART_QUEUE_LEN) {
memcpy(&uartQueueBufs[uartIn], Msg, sizeof(TOS_Msg));
uartCount++;
if( ++uartIn >= UART_QUEUE_LEN ) uartIn = 0;
if (!uartBusy) {
if (post UARTSendTask()) {
uartBusy = TRUE;
}
}
} else {
dropBlink();
}
return Msg;
}
task void UARTSendTask() {
dbg (DBG_USR1, "TOSBase forwarding Radio packet to UART\n");
if (uartCount == 0) {
uartBusy = FALSE;
} else {
if (call UARTSend.send(&uartQueueBufs[uartOut]) == SUCCESS) {
call Leds.greenToggle();
} else {
failBlink();
post UARTSendTask();
}
}
}
event result_t UARTSend.sendDone(TOS_MsgPtr msg, result_t success) {
if (!success) {
failBlink();
} else {
uartCount--;
if( ++uartOut >= UART_QUEUE_LEN ) uartOut = 0;
}
post UARTSendTask();
return SUCCESS;
}
event TOS_MsgPtr UARTReceive.receive(TOS_MsgPtr Msg) {
processUartPacket(Msg, FALSE, 0);
return Msg;
}
event TOS_MsgPtr UARTTokenReceive.receive(TOS_MsgPtr Msg, uint8_t Token) {
processUartPacket(Msg, TRUE, Token);
return Msg;
}
void processUartPacket(TOS_MsgPtr Msg, bool wantsAck, uint8_t Token) {
bool reflectToken = FALSE;
dbg(DBG_USR1, "TOSBase received UART token packet.\n");
if (radioCount < RADIO_QUEUE_LEN) {
reflectToken = TRUE;
memcpy(&radioQueueBufs[radioIn], Msg, sizeof(TOS_Msg));
radioCount++;
if( ++radioIn >= RADIO_QUEUE_LEN ) radioIn = 0;
if (!radioBusy) {
if (post RadioSendTask()) {
radioBusy = TRUE;
}
}
} else {
dropBlink();
}
if (wantsAck && reflectToken) {
call UARTTokenReceive.ReflectToken(Token);
}
}
task void RadioSendTask() {
dbg(DBG_USR1, "TOSBase forwarding UART packet to Radio\n");
if (radioCount == 0) {
radioBusy = FALSE;
} else {
radioQueueBufs[radioOut].group = TOS_AM_GROUP;
if (call RadioSend.send(&radioQueueBufs[radioOut]) == SUCCESS) {
call Leds.redToggle();
} else {
failBlink();
post RadioSendTask();
}
}
}
event result_t RadioSend.sendDone(TOS_MsgPtr msg, result_t success) {
if (!success) {
failBlink();
} else {
radioCount--;
if( ++radioOut >= RADIO_QUEUE_LEN ) radioOut = 0;
}
post RadioSendTask();
return SUCCESS;
}
void dropBlink() {
#ifdef TOSBASE_BLINK_ON_DROP
call Leds.yellowToggle();
#endif
}
void failBlink() {
#ifdef TOSBASE_BLINK_ON_FAIL
call Leds.yellowToggle();
#endif
}
}
More information about the Tinyos-contrib-commits
mailing list