Hi all,
I have to port CounterM.nc allocated in MDA300CA Crossbow's driver to
TinyOS 2.1 (see bellow the code), but there are some macros that I don't
know how to manage in TinyOS 2.. so I would appreciate any help.
There are some thing that are direct to convert to, but there are others
more complex, like defines that enable and disable the interruption 5,
as can be seen in 'sbi(EIMSK, 5)' and 'cbi(EIMSK, 5)', but I think I
could solve it using a GpioInterrupt associated to INT 5 pin. In
addition 'TOSH_uwait' could be solved as well making use of
BusyWaitMicroC component. The 'TOSH_MAKE_PW4_OUTPUT()' and
'TOSH_CLR_PW4_PIN()' could be solved using GeneralIO interface
associated to that PW4 pin. Am I right?
But the problem arise now when trying to port 'cbi(DDRE,5)', it is
trying to make INT5 (port E5) as input pin?? So, maybe I need to
associate this pin to GeneralIO so I could control whether it is input
or output?.
But the next instruction is 'sbi(PORTE,5)'.. as far as I could search
the register PORTX sets the output value of PORTX . So this instruction
is setting the output value of PORT E5 (INT5), and I dont know how to do
this in TinyOS 2.1
Finally the TOSH_SIGNAL is managed by GpioInterrupt.fired() event?????
Thanks very much indeed for all your help
p.d. the code.....
module CounterM {
provides {
interface StdControl as CounterControl;
interface Dio as Counter;
command result_t Plugged();
}
uses {
interface Leds;
}
}
implementation {
#define INT_ENABLE() sbi(EIMSK , 5)
#define INT_DISABLE() cbi(EIMSK , 5)
uint16_t count;
uint8_t state;
uint8_t mode;
result_t boardConnected;
command result_t CounterControl.init() {
char c;
INT_DISABLE();
TOSH_MAKE_PW4_OUTPUT();
TOSH_CLR_PW4_PIN();
TOSH_uwait(1);
c =(inp(PINE) >> 5) & 0x1; //PORTE pin 5
TOSH_SET_PW4_PIN();
TOSH_uwait(1);
if(c == ((inp(PINE) >> 5) & 0x1) ) boardConnected=FALSE;
else boardConnected=TRUE;
TOSH_CLR_PW4_PIN();
atomic {
mode=RISING_EDGE;
count=0;
state=0;
}
cbi(DDRE,5); //Making INT pin input (PORT E 5->INT5)
sbi(PORTE,5); //and pull-up so that when the board is
not there still operates (Set the output value of PORT E 5->INT5)
//cbi(EICRB,ISC50); //Making INT sensitive to falling edge
//sbi(EICRB,ISC51);
return SUCCESS;
}
command result_t CounterControl.start() {
TOSH_CLR_PW4_PIN();
atomic {
count=0;
state=0;
}
INT_ENABLE();
return SUCCESS;
}
command result_t CounterControl.stop() {
INT_DISABLE();
return SUCCESS;
}
command result_t Counter.setparam(uint8_t modeToSet)
{
//The available INT that is IN0-INT4 are not configurable
//io is always input
atomic{
mode=modeToSet;
if( ((mode & RISING_EDGE) == 0) & ((mode & FALLING_EDGE) ==
0) )
mode |= RISING_EDGE;
}
return SUCCESS;
}
command result_t Plugged(){
return boardConnected;
}
command result_t Counter.high()
{
return SUCCESS;
}
command result_t Counter.low()
{
return SUCCESS;
}
command result_t Counter.Toggle()
{
return SUCCESS;
}
command result_t Counter.getData()
{
uint16_t counter;
atomic {
counter = count;
if(RESET_ZERO_AFTER_READ & mode) count=0;
}
signal Counter.dataReady(counter);
return SUCCESS;
}
default event result_t Counter.dataReady(uint16_t data)
{
return SUCCESS;
}
task void count_ready()
{
uint16_t counter;
atomic {
counter = count;
}
signal Counter.dataReady(counter);
}
TOSH_SIGNAL(SIG_INTERRUPT5)
{
atomic {
//INT_DISABLE();
if(state==0){
TOSH_CLR_PW4_PIN();
state=1;
if(mode & FALLING_EDGE) {
count++;
if(EVENT & mode) post count_ready();
}
}
else {
TOSH_SET_PW4_PIN();
state=0;
if(mode & RISING_EDGE) {
count++;
if(EVENT & mode) post count_ready();
}
}
//INT_ENABLE();
}
return;
}
}
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help