I think you are right, the way I used to change frequency is fairly
easy. Here is my code, I hope anyone could spot the problems and give me
some suggestions please?
includes CountMsg;
includes Timer;
module CountDualM
{
provides interface StdControl;
uses interface Timer as TimerTx;
uses interface Timer as TimerTxRx;
uses interface SendMsg;
uses interface ReceiveMsg;
uses interface Leds;
uses interface CC2420Control;
uses interface MacControl;
}
implementation
{
TOS_Msg m_msg;
int m_int;
int freq_int;
int switch_now;
bool m_sending;
uint8_t freq_channel[16] =
{11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26}; // Frequency channels
from 11 to 26 (2405 MHz to 2480 MHz).
command result_t StdControl.init()
{
m_int = 0;
freq_int = 0;
switch_now = 0;
m_sending = FALSE;
call Leds.init();
return SUCCESS;
}
command result_t StdControl.start()
{
call MacControl.enableAck();
if( TOS_LOCAL_ADDRESS == 1 )
{
call TimerTx.start( TIMER_REPEAT, 200 );
}
return SUCCESS;
}
command result_t StdControl.stop()
{
return SUCCESS;
}
/**
* Tim0 is only called in the transmitter.
*/
event result_t TimerTx.fired()
{
if( m_sending == FALSE )
{
CountMsg_t* body = (CountMsg_t*)m_msg.data;
body->n = m_int;
body->src = TOS_LOCAL_ADDRESS;
if( call SendMsg.send( 0, sizeof(CountMsg_t), &m_msg ) == SUCCESS )
{
call Leds.set(call CC2420Control.GetPreset());//m_int);
m_sending = TRUE;
}
}
m_int++;
return SUCCESS;
}
event result_t TimerTxRx.fired()
{
if (freq_int <= 15)
{
call CC2420Control.TunePreset(freq_channel[freq_int]);
freq_int++;
}
else
{
freq_int = 0;
call CC2420Control.TunePreset(freq_channel[freq_int]);
}
return SUCCESS;
}
event result_t SendMsg.sendDone(TOS_MsgPtr msg, result_t success)
{
if (!(msg->ack)){
m_int--;
call Leds.yellowToggle();
}
if ((msg->ack) == 1)
{
call MacControl.disableAck();
call TimerTx.stop();
call TimerTx.start( TIMER_REPEAT, 200 );
call TimerTxRx.start( TIMER_REPEAT, 5120 );
}
m_sending = FALSE;
return SUCCESS;
}
event TOS_MsgPtr ReceiveMsg.receive(TOS_MsgPtr msg)
{
CountMsg_t* body = (CountMsg_t*)(&msg->data[0]);
call Leds.set(body->n);
return msg;
}
}
Siirtola Harri wrote:
Why don't you post your code for the frequency change as I suggested
before? There's no way anyone can help you without knowing how you try
to do it. The problem isn't the timer, or at least it's very easy to
check if they're firing. I'm almost sure you do something wrong in
changing frequencies, there are many things that should be done right.
Harri
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Ruoshui Liu
Sent: Thursday, November 22, 2007 11:08 PM
To: [email protected]
Subject: [Tinyos-help] My 2nd Timer never get called?
Dear all,
I implemented two timers, 1st (Timer0) for the counter, 2nd (Timer1) is
for the frequency change. In the code below:
event result_t SendMsg.sendDone(TOS_MsgPtr msg, result_t success)
{
if (!(msg->ack)){
m_int--;
call Leds.yellowToggle();
}
else {
call MacControl.disableAck();
call Timer1.start( TIMER_REPEAT, 5120 );
}
m_sending = FALSE;
return SUCCESS;
}
Here, although I did call Timer1.start, and implemented the frequency
change in the Timer1.fired(), I never got the fequency changed
successfully. The transmit frequency always stays the same. Any
suggestions please? I have been stuck here trying to find the problem
for a long time:(
Ruoshui Liu
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help