Esempio n. 1
0
/******************************************************************************
 * @fn          nwk_radioControl
 *
 * @brief       Handle radio control functions.
 *
 * input parameters
 * @param   action   - radio operation to perform. currently suppoerted:
 *                         sleep/unsleep
 * output parameters
 *
 * @return   Status of operation.
 */
smplStatus_t nwk_radioControl(ioctlAction_t action, void *val)
{
  smplStatus_t rc = SMPL_SUCCESS;

  if (IOCTL_ACT_RADIO_SLEEP == action)
  {
    /* go to sleep mode. */
    MRFI_RxIdle();
    MRFI_Sleep();
  }
  else if (IOCTL_ACT_RADIO_AWAKE == action)
  {
    MRFI_WakeUp();

#if !defined( END_DEVICE )
    MRFI_RxOn();
#endif

  }
  else if (IOCTL_ACT_RADIO_SIGINFO == action)
  {
    ioctlRadioSiginfo_t *pSigInfo = (ioctlRadioSiginfo_t *)val;
    connInfo_t          *pCInfo   = nwk_getConnInfo(pSigInfo->lid);

    if (!pCInfo)
    {
      return SMPL_BAD_PARAM;
    }
    memcpy(&pSigInfo->sigInfo, &pCInfo->sigInfo, sizeof(pCInfo->sigInfo));
  }
  else if (IOCTL_ACT_RADIO_RSSI == action)
  {
    *((rssi_t *)val) = MRFI_Rssi();
  }
  else if (IOCTL_ACT_RADIO_RXON == action)
  {
    MRFI_RxOn();
  }
  else if (IOCTL_ACT_RADIO_RXIDLE == action)
  {
    MRFI_RxIdle();
  }
  else
  {
    rc = SMPL_BAD_PARAM;
  }
  return rc;
}
Esempio n. 2
0
/**
 * swStop
 *
 * Stop SWAP comms
 */
void swStop(void)
{
  // New SWAP state = SWAP stopped
  setChronosState(SYSTATE_STOPSWAP);

  // Go to sleep mode
  MRFI_RxIdle();
  MRFI_Sleep();
}
Esempio n. 3
0
/**************************************************************************************************
 * @fn          MRFI_Sleep
 *
 * @brief       Request radio go to sleep.
 *
 * @param       none
 *
 * @return      none
 **************************************************************************************************
 */
void MRFI_Sleep(void)
{
  /* If radio is not asleep, put it to sleep */
  if(mrfiRadioState != MRFI_RADIO_STATE_OFF)
  {
    /* go to idle so radio is in a known state before sleeping */
    MRFI_RxIdle();

    /* Our new state is OFF */
    mrfiRadioState = MRFI_RADIO_STATE_OFF;
  }
}
Esempio n. 4
0
void ReadChannelsAndSendRSSI()
{
  uint8_t channel;
  int8_t rssi;
  
  for (channel=0;channel<255;channel++)
  {
    MRFI_RxIdle();
    mrfiSpiWriteReg(CHANNR,channel);
    MRFI_RxOn();
    rssi=MRFI_Rssi();
    print_rssi(rssi);
  }
}
__interrupt void Timer_A (void)
{
  P2OUT |= 0x04;
  uint16_t i;
  /* stop timer */
  TACTL=MC_0;
  TACCTL0=0;
  /* send probe packet */
  for (i=0;i<1000;i++) {
     P1OUT |=  0x01;
     packet.frame[0]=8+20;
     MRFI_Transmit(&packet, MRFI_TX_TYPE_FORCED);
     P1OUT &= ~0x01;
  }
  /* return to Rx mode on channel 26 */
  MRFI_RxIdle();
  mrfiSpiWriteReg(CHANNR,0xBC); // channel 26
  MRFI_RxOn();
  P2OUT &= ~0x04;
}
void MRFI_RxCompleteISR()
{
  P1OUT |= 0x02;
  P2OUT |= 0x04;
  uint8_t erase_me=0;
  uint8_t channel;
  MRFI_Receive(&packet);
  channel = (uint8_t)((packet.frame[9]-'0')*10+(packet.frame[10]-'0'));
  erase_me++;
  if (channel>=11 && channel<=26) {
     /* set timer */
     BCSCTL3 |= LFXT1S_2;
     TACCR0=1000; //~.1sec
     TACTL=TASSEL_1+MC_1;
     TACCTL0=CCIE;
     /* set frequency */
     MRFI_RxIdle();
     switch(channel) {
        case 11: mrfiSpiWriteReg(CHANNR,0x00); break;
        case 12: mrfiSpiWriteReg(CHANNR,0x0D); break;
        case 13: mrfiSpiWriteReg(CHANNR,0x19); break;
        case 14: mrfiSpiWriteReg(CHANNR,0x26); break;
        case 15: mrfiSpiWriteReg(CHANNR,0x32); break;
        case 16: mrfiSpiWriteReg(CHANNR,0x3F); break;
        case 17: mrfiSpiWriteReg(CHANNR,0x4B); break;
        case 18: mrfiSpiWriteReg(CHANNR,0x58); break;
        case 19: mrfiSpiWriteReg(CHANNR,0x64); break;
        case 20: mrfiSpiWriteReg(CHANNR,0x71); break;
        case 21: mrfiSpiWriteReg(CHANNR,0x7D); break;
        case 22: mrfiSpiWriteReg(CHANNR,0x8A); break;
        case 23: mrfiSpiWriteReg(CHANNR,0x96); break;
        case 24: mrfiSpiWriteReg(CHANNR,0xA3); break;
        case 25: mrfiSpiWriteReg(CHANNR,0xAF); break;
        case 26: mrfiSpiWriteReg(CHANNR,0xBC); break;
     }
  }
  P2OUT &= ~0x04;
  P1OUT &= ~0x02;
}
smplStatus_t nwk_radioControl(ioctlAction_t action, void *val)
{
    smplStatus_t rc = SMPL_SUCCESS;

    if (IOCTL_ACT_RADIO_SLEEP == action)
    {
        /* go to sleep mode. */
        MRFI_RxIdle();
        MRFI_Sleep();
    }
    else if (IOCTL_ACT_RADIO_AWAKE == action)
    {
        MRFI_WakeUp();

#if !defined(END_DEVICE)
        MRFI_RxOn();
#endif

    }
    else if (IOCTL_ACT_RADIO_SIGINFO == action)
    {
        ioctlRadioSiginfo_t *pSigInfo = (ioctlRadioSiginfo_t *)val;
        connInfo_t          *pCInfo   = nwk_getConnInfo(pSigInfo->lid);

        if (!pCInfo)
        {
            return SMPL_BAD_PARAM;
        }
        memcpy(&pSigInfo->sigInfo, &pCInfo->sigInfo, sizeof(pCInfo->sigInfo));
    }
    else if (IOCTL_ACT_RADIO_RSSI == action)
    {
        *((rssi_t *)val) = MRFI_Rssi();
    }
    else if (IOCTL_ACT_RADIO_RXON == action)
    {
        MRFI_RxOn();
    }
    else if (IOCTL_ACT_RADIO_RXIDLE == action)
    {
        MRFI_RxIdle();
    }
#ifdef EXTENDED_API
    else if (IOCTL_ACT_RADIO_SETPWR == action)
    {
        uint8_t idx;

        switch (*(ioctlLevel_t *)val)
        {
            case IOCTL_LEVEL_2:
                idx = 2;
                break;

            case IOCTL_LEVEL_1:
                idx = 1;
                break;

            case IOCTL_LEVEL_0:
                idx = 0;
                break;

            default:
                return SMPL_BAD_PARAM;
        }
        MRFI_SetRFPwr(idx);
        return SMPL_SUCCESS;
    }
#endif  /* EXTENDED_API */
    else
    {
        rc = SMPL_BAD_PARAM;
    }
    return rc;
}
Esempio n. 8
0
//=============================================
void gradient_wakeup_rx()
{
  mrfiPacket_t packetReceived;
  frameInfo_t * freeSlot;
  MRFI_Receive(&packetReceived);
  uint8_t pkt_next_hop;
  uint8_t pkt_type = packetReceived.frame[F_TYPE];
  switch (gradient_state) {
  //--------------------------------------- transmitter
  case (GRADIENT_RXACK):                                  //rx
    pkt_next_hop = packetReceived.frame[F_ACK_NEXT_HOP];
    if (pkt_type==F_TYPE_ACK && pkt_next_hop==myAddr) {
      gradient_add_neighbor(&packetReceived);
    }
    break;
  case (GRADIENT_RXFIN):                                  //rx
    pkt_next_hop = packetReceived.frame[F_FIN_NEXT_HOP];
    if (pkt_type==F_TYPE_FIN && pkt_next_hop==myAddr) {
      stop_timer();
      print_success("\r\nTX successful",15);
      QfreeSlot(dataToSend);
      gradient_end_txrx();
    }
    break;
  //--------------------------------------- receiver
  case (GRADIENT_IDLE):                                   //rx
    if (pkt_type==F_TYPE_UF) {
      /* stop preamble sampling */
      wor_stop(IS_SINK_NODE);
      /* stop possible timers (if OUTQ not empty) */
      stop_timer();
      gradient_set_state(GRADIENT_RXUF);
      addr_initiator = packetReceived.frame[F_SRC];
      MRFI_RxIdle();
      set_timer((packetReceived.frame[F_UF_COUNTER])*UF_PERIOD-GUARD_CW);
    }
    break;
  case (GRADIENT_RXCW):                                   //rx
    if (pkt_type==F_TYPE_CW) {
      stop_timer();
      gradient_set_state(GRADIENT_BACKOFFACK);
      MRFI_RxIdle();
      /* second timer to send my ACK */
      set_second_random_timer((packetReceived.frame[F_CW_CWDURATION])-GUARD_DATA-ACK_DURATION);
      /* main timer at the end of CW */
      set_timer((packetReceived.frame[F_CW_CWDURATION])-GUARD_DATA);
    } else if (pkt_type==F_TYPE_UF) {
      set_timer(TIMEOUT_CW);
    }
    break;
  case (GRADIENT_RXDATA):                                 //rx
    pkt_next_hop = packetReceived.frame[F_DATA_NEXT_HOP];
    if (pkt_type==F_TYPE_DATA && pkt_next_hop==myAddr) {
      stop_timer();
      gradient_build_DATA_path(&packetReceived); //add myAddr to packet
      if (myHeight!=0) { //I'm not a sink
        /* add packet to outQ for later relaying if not sink */
        print_debug("\r\nQueued for relay",18);
        freeSlot = QfindFreeSlot(OUTQ);
        if (freeSlot) {
          freeSlot->mrfiPkt = packetReceived;
        }
      } else {       //I'm a sink
        /* process incoming packet through INQ */
        frameInfo_t * freeSlot = QfindFreeSlot(INQ);
        if (freeSlot) {
          freeSlot->mrfiPkt = packetReceived;
          lastData = packetReceived;
          QfreeSlot(freeSlot);
        }
      }
      /* delay before sending FIN */      
      gradient_set_state(GRADIENT_TXFIN);
      MRFI_RxIdle();
      set_timer(DELAY_FIN);
    }
    break;
  }
}
Esempio n. 9
0
//=============================================
void gradient_wakeup_timer()
{
  uint8_t next_hop_addr;
  mrfiPacket_t packetToSend;
  switch (gradient_state) {
  //--------------------------------------- transmitter
  case (GRADIENT_IDLE):                                   //wake_up timer
    /* stop preamble sampling */
    wor_stop(IS_SINK_NODE);
    /* stop possible timers */
    stop_timer();
    /* check that there is data to send */
    dataToSend = QgetInUseSlot(OUTQ);
    if (!dataToSend) {
      gradient_end_txrx();
      print_debug("\r\nno data to send",17);
      return;
    }
    /* TODO. check that the medium is free */
    set_timer(UF_PERIOD);                                  //wake_up timer
    /* send first uF */
    gradient_set_state(GRADIENT_TXUF);
    uf_counter = NUMBER_UF-1;
    gradient_build_UF(&packetToSend, uf_counter);
    MRFI_justTransmit(&packetToSend);
    break;
  case (GRADIENT_TXUF):                                   //wake_up timer
    if (uf_counter > 0) {
      uf_counter--;
      /* send uF */
      gradient_build_UF(&packetToSend, uf_counter);
      MRFI_justTransmit(&packetToSend);
    } else {
      stop_timer();
      /* send CW */
      gradient_set_state(GRADIENT_TXCW);
      gradient_build_CW(&packetToSend, CW_LENGTH);
      MRFI_justTransmit(&packetToSend);
      /* wait for ACK */
      gradient_set_state(GRADIENT_RXACK);
      gradient_init_neighbor_table();
      MRFI_RxOn();
      set_timer(CW_LENGTH);
    }
    break;
  case (GRADIENT_RXACK):                                  //wake_up timer
    stop_timer();
    print_neighbor_table(neighbors);
    gradient_update_height();
    print_height(myAddr,myHeight);
    next_hop_addr = gradient_next_hop();
    if (next_hop_addr==0) {
      gradient_end_txrx();
      print_fail("\r\nTX failed: no neighbor",24);
    } else {
      /* send DATA */
      gradient_set_state(GRADIENT_TXDATA);
      //if mine, complete with current neighbor list and empty hop count
      if ( (&(dataToSend->mrfiPkt))->frame[F_SRC]==myAddr) {
        gradient_build_DATA_headers(dataToSend);
      }
      (&(dataToSend->mrfiPkt))->frame[F_DATA_NEXT_HOP]=next_hop_addr;
      MRFI_justTransmit(&(dataToSend->mrfiPkt));
      /* wait for FIN */
      gradient_set_state(GRADIENT_RXFIN);
      MRFI_RxOn();
      set_timer(TIMEOUT_FIN);
    }
    break;
  case (GRADIENT_RXFIN):                                  //wake_up timer
    gradient_end_txrx();
    print_fail("\r\nTX failed: no FIN",19);
    break;
  //--------------------------------------- receiver
  case (GRADIENT_RXUF):                                   //wake_up timer
    stop_timer();
    /* wait for CW */
    gradient_set_state(GRADIENT_RXCW);
    MRFI_RxOn();
    set_timer(TIMEOUT_CW);
    break;
  case (GRADIENT_RXCW):                                   //wake_up timer
    gradient_end_txrx();
    print_fail("\r\nRX failed: no CW",18);
    break;
  case (GRADIENT_BACKOFFACK):                             //wake_up timer
    stop_second_random_timer();
    /* send ACK */
    gradient_set_state(GRADIENT_TXACK);
    gradient_build_ACK(&packetToSend, addr_initiator);
    MRFI_justTransmit(&packetToSend);
    gradient_set_state(GRADIENT_SENTACK);
    MRFI_RxIdle();
    break;
  case (GRADIENT_SENTACK):                                //wake_up timer
    stop_timer();
    /* wait for DATA */
    gradient_set_state(GRADIENT_RXDATA);
    MRFI_RxOn();
    set_timer(TIMEOUT_DATA);
    break;
  case (GRADIENT_RXDATA):                                 //wake_up timer
    gradient_end_txrx();
    print_fail("\r\nRX failed: no DATA",20);
    break;
  case (GRADIENT_TXFIN):                                  //wake_up timer
    stop_timer();
    /* send FIN */
    gradient_build_FIN(&packetToSend, addr_initiator);
    MRFI_justTransmit(&packetToSend);
    print_success("\r\nRX successful",15);
    print_DATA(&lastData, myAddr);
    gradient_end_txrx();
    break;
  }
}
Esempio n. 10
0
void SetBaseFrequencyRegisters(uint8_t range)
{
    MRFI_RxIdle();
    
    //if Channel spacing = 25.390625 (min)
    switch(range)
    {
        // 2399.999634
      case 1:
        mrfiSpiWriteReg(FREQ0,0xC4);
        mrfiSpiWriteReg(FREQ1,0x4E);
        mrfiSpiWriteReg(FREQ2,0x5C);
        break;
        
        //needed 2406.474243
        //seted 2406.473846
      case 2:
        mrfiSpiWriteReg(FREQ0,0x83);
        mrfiSpiWriteReg(FREQ1,0x8E);
        mrfiSpiWriteReg(FREQ2,0x5C);
        break;
        
        //needed 2412.948456
        //seted 2412.948456
      case 3:
        mrfiSpiWriteReg(FREQ0,0x43);
        mrfiSpiWriteReg(FREQ1,0xCE);
        mrfiSpiWriteReg(FREQ2,0x5C);
        break;
        
        //needed 2419.423065
        //seted 2419.423065
      case 4:
        mrfiSpiWriteReg(FREQ0,0x03);
        mrfiSpiWriteReg(FREQ1,0x0E);
        mrfiSpiWriteReg(FREQ2,0x5D);
        break;
        
        //needed 2425.897675
        //seted 2425.897675
      case 5:
        mrfiSpiWriteReg(FREQ0,0xC3);
        mrfiSpiWriteReg(FREQ1,0x4D);
        mrfiSpiWriteReg(FREQ2,0x5D);
        break;

        //needed 2432.372284
        //seted 2432.372284
      case 6:
        mrfiSpiWriteReg(FREQ0,0x83);
        mrfiSpiWriteReg(FREQ1,0x8D);
        mrfiSpiWriteReg(FREQ2,0x5D);
        break;
        
        //needed 2438.846893
        //seted 2438.846893
      case 7:
        mrfiSpiWriteReg(FREQ0,0x43);
        mrfiSpiWriteReg(FREQ1,0xCD);
        mrfiSpiWriteReg(FREQ2,0x5D);
        break;
        
        //needed 2445.321503
        //seted 2445.321503
      case 8:
        mrfiSpiWriteReg(FREQ0,0x03);
        mrfiSpiWriteReg(FREQ1,0x0D);
        mrfiSpiWriteReg(FREQ2,0x5E);
        break;
        
        //needed 2451.796112
        //seted 2451.796112
      case 9:
        mrfiSpiWriteReg(FREQ0,0xC3);
        mrfiSpiWriteReg(FREQ1,0x4C);
        mrfiSpiWriteReg(FREQ2,0x5E);
        break;
        
        //needed 2458.270721
        //seted 2458.270721
      case 10:
        mrfiSpiWriteReg(FREQ0,0x83);
        mrfiSpiWriteReg(FREQ1,0x8C);
        mrfiSpiWriteReg(FREQ2,0x5E);
        break;
        
        //needed 2464.745331
        //seted 2464.745331
      case 11:
        mrfiSpiWriteReg(FREQ0,0x43);
        mrfiSpiWriteReg(FREQ1,0xCC);
        mrfiSpiWriteReg(FREQ2,0x5E);
        break;
        
        //needed 2471.219940
        //seted 2471.219940
      case 12:
        mrfiSpiWriteReg(FREQ0,0x03);
        mrfiSpiWriteReg(FREQ1,0x0C);
        mrfiSpiWriteReg(FREQ2,0x5F);
        break;
        
        //needed 2477.694550
        //seted 2477.694550
        //with chanell 228 carrier freq = 2483.483612 (max)
      case 13:
        mrfiSpiWriteReg(FREQ0,0xC3);
        mrfiSpiWriteReg(FREQ1,0x4B);
        mrfiSpiWriteReg(FREQ2,0x5F);
        break;
        
        
        // 2399.999634
      default:
        mrfiSpiWriteReg(FREQ0,0xC4);
        mrfiSpiWriteReg(FREQ1,0x4E);
        mrfiSpiWriteReg(FREQ2,0x5C);
        break;
    }
}
Esempio n. 11
0
void SetBaseFrequencyRegisters(uint8_t range)
{
    MRFI_RxIdle();
    
    //if Channel spacing = 25.390625 (min)
    switch(range)
    {
        // 2399.999634
      case 1:
        mrfiSpiWriteReg(FREQ0,0xC4);
        mrfiSpiWriteReg(FREQ1,0x4E);
        mrfiSpiWriteReg(FREQ2,0x5C);
        break;
        
        //needed 2406.474243
        //seted 2406.473846
      case 2:
        mrfiSpiWriteReg(FREQ0,0x83);
        mrfiSpiWriteReg(FREQ1,0x8E);
        mrfiSpiWriteReg(FREQ2,0x5C);
        break;
        
        //needed 2412.948456
        //seted 2412.948456
      case 3:
        mrfiSpiWriteReg(FREQ0,0x43);
        mrfiSpiWriteReg(FREQ1,0xCE);
        mrfiSpiWriteReg(FREQ2,0x5C);
        break;
        
        //needed 2419.423065
        //seted 2419.423065
      case 4:
        mrfiSpiWriteReg(FREQ0,0x03);
        mrfiSpiWriteReg(FREQ1,0x0E);
        mrfiSpiWriteReg(FREQ2,0x5D);
        break;
        
        //needed 2425.897675
        //seted 2425.897675
      case 5:
        mrfiSpiWriteReg(FREQ0,0xC3);
        mrfiSpiWriteReg(FREQ1,0x4D);
        mrfiSpiWriteReg(FREQ2,0x5D);
        break;

        //needed 2432.372284
        //seted 2432.372284
      case 6:
        mrfiSpiWriteReg(FREQ0,0x83);
        mrfiSpiWriteReg(FREQ1,0x8D);
        mrfiSpiWriteReg(FREQ2,0x5D);
        break;
        
        //needed 2438.846893
        //seted 2438.846893
      case 7:
        mrfiSpiWriteReg(FREQ0,0x43);
        mrfiSpiWriteReg(FREQ1,0xCD);
        mrfiSpiWriteReg(FREQ2,0x5D);
        break;
        
        //needed 2445.321503
        //seted 2445.321503
      case 8:
        mrfiSpiWriteReg(FREQ0,0x03);
        mrfiSpiWriteReg(FREQ1,0x0D);
        mrfiSpiWriteReg(FREQ2,0x5E);
        break;
        
        // 2399.999634
      default:
        mrfiSpiWriteReg(FREQ0,0xC4);
        mrfiSpiWriteReg(FREQ1,0x4E);
        mrfiSpiWriteReg(FREQ2,0x5C);
        break;
    }
}