Hi all,
I'm facing problems with triggering the LEDs whenever the tmote sky revceives a 
packet over the UART0.
The main problem is that I am not sure how to use the TOS_SIGNAL / 
TOS_INTERRUPT correctly.

I am aware that the initialisation of the uart is probably not correct, but i 
wanted to have a code, which deals with the interrupt correctly, first. 

I will appreciate any comment,

Thanks for your help,

Christopher




BlinkC.nc

#include "Timer.h"
#include "Serial.h"
#include <msp430x16x.h>
//#include "msp430usart.h"
#include <signal.h>
#define USART0RX_VECTOR     18

module BlinkC @safe()
{
  uses interface Timer<TMilli> as Timer0;
  uses interface Timer<TMilli> as Timer1;
  uses interface Timer<TMilli> as Timer2;
  uses interface Leds;
  uses interface Boot;
  uses interface receivebuffer;

}
implementation
{
  uint8_t P3SEL;

  event void Boot.booted()
  {
    call Timer0.startPeriodic( 250 );
    call Timer1.startPeriodic( 500 );
    call Timer2.startPeriodic( 1000 );
  }

void InitUSART(char USART0, char USART1, unsigned int baudrate1, unsigned int 
baudrate2, char IR0, char IR1)
{
  if (USART0) ME1 |= UTXE0 + URXE0;    // falls gesetzt, USART0 einschalten 
(TX- und RX-teil)
  if (USART1) ME2 |= UTXE1 + URXE1;    // falls gesetzt, USART1 einschalten 
(TX- und RX-teil)
  UCTL0 |= CHAR;                       // 8 data bits, 1 stop bit, no parity 
(8N1)
  UCTL1 |= CHAR;
  UTCTL0 |= SSEL1;                     // SMCLK als UCLK festlegen
  UTCTL1 |= SSEL1;
  if (baudrate1==19200)
  {
    UBR00 = 0xA0;                      // 19200 baud aus 8 MHz erzeugen
    UBR10 = 0x01;                      // siehe application note tabelle 1, 
seite 9
    UMCTL0 = 0x00;                     // keine korrektur der division noetig
  }
  if (baudrate2==19200)
  {
    UBR01 = 0xA0;                      // 19200 baud aus 8 MHz erzeugen
    UBR11 = 0x01;                      // siehe application note tabelle 1, 
seite 9
    UMCTL1 = 0x00;                     // keine korrektur der division noetig
  }
  if (USART0) UCTL0 &= ~SWRST;         // USART freigeben
  if (USART1) UCTL1 &= ~SWRST;
  if (IR0==0) IE1 |= URXIE0;           // IR0: 0 -> nur RX-interrupt anschalten
  if (IR0==1) IE1 |= UTXIE0;           //      1 -> nur TX-interrupt anschalten
  if (IR0==2) IE1 |= URXIE0 + UTXIE0;  //      2 -> TX- und RX-interrupt 
anschalten
  if (IR1==1||IR1==2) IFG1 &= ~UTXIFG0;  // initales interrupt-flag loeschen
  if (IR1==0) IE2 |= URXIE1;           // IR1: 0 -> nur RX-interrupt anschalten
  if (IR1==1) IE2 |= UTXIE1;           //      1 -> nur TX-interrupt anschalten
  if (IR1==2) IE2 |= URXIE1 + UTXIE1;  //      2 -> TX- und RX-interrupt 
anschalten
  if (IR1==1||IR1==2) IFG1 &= ~UTXIFG1;  // initales interrupt-flag loeschen
}


async event void receivebuffer.fired()
 {
    call Leds.led0Toggle();
    call Leds.led1Toggle();
    call Leds.led2Toggle();
 }   
    
    
TOSH_SIGNAL(USART0RX_VECTOR){
 signal receivebuffer.fired();

}

  event void Timer0.fired()
  {
    dbg("BlinkC", "Timer 0 fired @ %s.\n", sim_time_string());
    call Leds.led0Toggle();
    while (!(IFG1 & UTXIFG0));           // warten, bis USART0 TX-buffer 
sendebereit
   TXBUF0 = 0xF;
  }
  
  event void Timer1.fired()
  {
    dbg("BlinkC", "Timer 1 fired @ %s \n", sim_time_string());
  }
  
  event void Timer2.fired()
  {
    dbg("BlinkC", "Timer 2 fired @ %s.\n", sim_time_string());
  }


}







BlinkAppC.nc

configuration BlinkAppC

{

}

implementation

{

components MainC, BlinkC, LedsC;

components new TimerMilliC() as Timer0;

components new TimerMilliC() as Timer1;

components new TimerMilliC() as Timer2;

components receivebuffer;




BlinkC -> MainC.Boot;


BlinkC.Timer0 -> Timer0;

BlinkC.Timer1 -> Timer1;

BlinkC.Timer2 -> Timer2;

BlinkC.Leds -> LedsC;

BlinkC.receivebuffer -> receivebuffer;

}





receivebuffer.nc

interface receivebuffer{

async event void fired();

}
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to