void main (void)
{
	
	BSP_Init( );
	
	SET_MAIN_CLOCK_SOURCE(CRYSTAL);  
	initUART();
	printf( "Start iwsn system...\n" );
	
	InitRFIO(); /* set io as normal io, not uart */
	
	//P0DIR &= ~0x03; /* Set button as input */
	EnableRecv();
	SMPL_Init( NULL );
	
	/* turn on the radio so we are always able to receive data asynchronously */
	SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_RXON, NULL );
	
	/* turn on LED. */
	BSP_TURN_ON_LED1( );
	BSP_TURN_ON_LED2( );
	
  /* never coming back... */
  framework_entry();

  /* but in case we do... */
  while (1) ;
}
Exemple #2
0
void main(void)
{
	BSP_Init(); // Initialisation de la librairie BSP
	NWK_DELAY(500);
	
	SMPL_Init(&RxCallBack); // Initialisation de la librairie simpliciTI
	SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_AWAKE, 0);
	SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_RXON, 0); // Activation de la radio pour permettre la réception des messages
	
	COM_Init(); // Initialisation du port COM
		
	while (1)
	{
		if(broadSem)
		{
			memset(msg, 0, sizeof(msg));
			if ((SMPL_Receive(SMPL_LINKID_USER_UUD, msg, &msgLen)) == SMPL_SUCCESS) // Cette fonction permet de stocker les messages reçu par un périphérique en spécifiant son linkID
			{
				sigInfo.lid = SMPL_LINKID_USER_UUD; // Permet d'indiquer les informations de quel périphérique sont demandées
				SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SIGINFO, &sigInfo); // On récupère les informations sur la force de connexion dans la structure sigInfo
			  	msg[5] = 'S';
			  	msg[6] = sigInfo.sigInfo.rssi+128;
			  	msg[7] = 'L';
			  	msg[8] = sigInfo.sigInfo.lqi;
			  	msg[9] = 0xFF;
				broadSem--;
				TXString(msg, sizeof(msg));
			}
		}
	}
}
Exemple #3
0
void main (void)
{
  BSP_Init();

  /* If an on-the-fly device address is generated it must be done before the
   * call to SMPL_Init(). If the address is set here the ROM value will not
   * be used. If SMPL_Init() runs before this IOCTL is used the IOCTL call
   * will not take effect. One shot only. The IOCTL call below is conformal.
   */
#ifdef I_WANT_TO_CHANGE_DEFAULT_ROM_DEVICE_ADDRESS_PSEUDO_CODE
  {
    addr_t lAddr;
	lAddr.addr[0]=0x35;
	lAddr.addr[1]=0x35;
	lAddr.addr[2]=0x35;
	lAddr.addr[3]=0x35;

    //createRandomAddress(&lAddr);
    SMPL_Ioctl(IOCTL_OBJ_ADDR, IOCTL_ACT_SET, &lAddr);
  }
#endif /* I_WANT_TO_CHANGE_DEFAULT_ROM_DEVICE_ADDRESS_PSEUDO_CODE */

  /* This call will fail because the join will fail since there is no Access Point
   * in this scenario. But we don't care -- just use the default link token later.
   * We supply a callback pointer to handle the message returned by the peer.
   */
  SMPL_Init(sRxCallback);

  /* turn on LEDs. */
  if (!BSP_RED_LED_IS_ON())
  {
    toggleLED(RED);
  }
  if (!BSP_GREEN_LED_IS_ON())
  {
    toggleLED(GREEN);
  }

  /* wait for a button press... */
  do {
    if (BSP_BUTTON() )
    {
      break;
    }
  } while (1);

  /* never coming back... */
  linkFrom();

  /* but in case we do... */
  while (1) ;
}
int main (void)
{
  WDTCTL = WDTPW + WDTHOLD;
  BSP_Init();

  /* If an on-the-fly device address is generated it must be done before the
   * call to SMPL_Init(). If the address is set here the ROM value will not
   * be used. If SMPL_Init() runs before this IOCTL is used the IOCTL call
   * will not take effect. One shot only. The IOCTL call below is conformal.
   */
#ifdef I_WANT_TO_CHANGE_DEFAULT_ROM_DEVICE_ADDRESS_PSEUDO_CODE
  {
    addr_t lAddr;

    createRandomAddress(&lAddr);
    SMPL_Ioctl(IOCTL_OBJ_ADDR, IOCTL_ACT_SET, &lAddr);
  }
#endif /* I_WANT_TO_CHANGE_DEFAULT_ROM_DEVICE_ADDRESS_PSEUDO_CODE */

  /* This call will fail because the join will fail since there is no Access Point
   * in this scenario. But we don't care -- just use the default link token later.
   * We supply a callback pointer to handle the message returned by the peer.
   */

  toggleLED(1);

  SMPL_Init(sRxCallback);

  /* turn on LEDs. */
  toggleLED(2);
  NWK_DELAY(500);
  int i;
  for (i = 10; --i >= 0; ) {
    toggleLED(1);
    toggleLED(2);
    NWK_DELAY(100);
  }
  toggleLED(2);


  /* never coming back... */
  linkFrom();

  /* but in case we do... */
  while (1) ;
}
void main (void)
{
  BSP_Init();

  /* If an on-the-fly device address is generated it must be done before the
   * call to SMPL_Init(). If the address is set here the ROM value will not
   * be used. If SMPL_Init() runs before this IOCTL is used the IOCTL call
   * will not take effect. One shot only. The IOCTL call below is conformal.
   */
#ifdef I_WANT_TO_CHANGE_DEFAULT_ROM_DEVICE_ADDRESS_PSEUDO_CODE
  {
    addr_t lAddr;

    createRandomAddress(&lAddr);
    SMPL_Ioctl(IOCTL_OBJ_ADDR, IOCTL_ACT_SET, &lAddr);
  }
#endif /* I_WANT_TO_CHANGE_DEFAULT_ROM_DEVICE_ADDRESS_PSEUDO_CODE */

  /* Keep trying to join (a side effect of successful initialization) until
   * successful. Toggle LEDS to indicate that joining has not occurred.
   */
  while (SMPL_SUCCESS != SMPL_Init(0))
  {
    toggleLED(1);
    toggleLED(2);
    SPIN_ABOUT_A_SECOND;
  }

  /* LEDs on solid to indicate successful join. */
  if (!BSP_LED2_IS_ON())
  {
    toggleLED(2);
  }
  if (!BSP_LED1_IS_ON())
  {
    toggleLED(1);
  }

  /* Unconditional link to AP which is listening due to successful join. */
  linkTo();

  while (1) ;
}
Exemple #6
0
int main (void)
{
	BSP_Init();

	/* If an on-the-fly device address is generated it must be done before the
	 * call to SMPL_Init(). If the address is set here the ROM value will not 
	 * be used. If SMPL_Init() runs before this IOCTL is used the IOCTL call 
	 * will not take effect. One shot only. The IOCTL call below is conformal.
	 */
#ifdef I_WANT_TO_CHANGE_DEFAULT_ROM_DEVICE_ADDRESS_PSEUDO_CODE
	{
		addr_t lAddr;

		createRandomAddress(&lAddr);
		SMPL_Ioctl(IOCTL_OBJ_ADDR, IOCTL_ACT_SET, &lAddr);
	}
#endif /* I_WANT_TO_CHANGE_DEFAULT_ROM_DEVICE_ADDRESS_PSEUDO_CODE */

	/* This call will fail because the join will fail since there is no Access Point
	 * in this scenario. but we don't care -- just use the default link token later.
	 * we supply a callback pointer to handle the message returned by the peer.
	 */
	SMPL_Init(0);

	/* turn on LEDs. */
	if (!BSP_LED2_IS_ON())	toggleLED(2);
	if (!BSP_LED1_IS_ON())	toggleLED(1);

	/* wait for a button press... */
	do
	{
		FHSS_ACTIVE( nwk_pllBackgrounder( false ) ); /* manage FHSS */
		if (BSP_BUTTON1() || BSP_BUTTON2())
			break;
	} while (1);

	/* never coming back... */
	monitorForBadNews();

	/* but in case we do... */
	while (1) ;
}
Exemple #7
0
void main()
{
	BSP_Init(); // Initialisation de la librairie BSP 
	NWK_DELAY(500);
	
	SMPL_Init(0); // Initialisation de la librairie SimpliciTI
	SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_AWAKE, 0);
		
	// Initialisation Timer A
	BCSCTL3 |= LFXT1S_2;                      // LFXT1 = VLO
	TACCTL0 = CCIE;                           // TACCR0 interrupt enabled
	
	msg[0] = '#';
	msg[1] = REPERE_ID;
	msg[2] = ':';
	msg[3] = 'V';
	msg[4] = 0;
	msg[5] = 0xFF;
	
	timeCounter = 250;
	
	unsyncRepere();
	
	while (1)
	{
		SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SLEEP, 0);
		__bis_SR_register(LPM3_bits + GIE);
		SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_AWAKE, 0);
		SMPL_SendOpt(SMPL_LINKID_USER_UUD, msg, sizeof(msg), SMPL_TXOPTION_NONE);
		BSP_TOGGLE_LED1();
		
		if (timeCounter >= 300) // Quand timeCounter a été incrémenté depuis 1 minute (0.2sec x 300)
		{
			voltAction();
			msg[4] = ((uint8_t*)&volt)[3];
			timeCounter = 0;
  		}  		
	}
}
Exemple #8
0
int main (void)
{
  WDTCTL = WDTPW + WDTHOLD;

  (void)TimerMasterInit(10); //tick every 0.1ms  

  //void PwmCtor( /*@out@*/Pwm_t * pwm, DioPort_t my_port, DioPin_t my_pin);
  PwmCtor(&pwm_left_fwd,  kPort4, kPin3);
  PwmCtor(&pwm_left_rev,  kPort4, kPin4);
  PwmCtor(&pwm_right_fwd, kPort4, kPin5);
  PwmCtor(&pwm_right_rev, kPort4, kPin6);

  MotorSet( 50, 50);

  BSP_Init();

  LedCtor(&led_red,   kPort1, kPin0); //P1.0 (red)
  LedCtor(&led_green, kPort1, kPin1); //P1.1 (green)

  LedOn(&led_red);

#ifdef I_WANT_TO_CHANGE_DEFAULT_ROM_DEVICE_ADDRESS_PSEUDO_CODE
  {
    addr_t lAddr;

    createRandomAddress(&lAddr);
    SMPL_Ioctl(IOCTL_OBJ_ADDR, IOCTL_ACT_SET, &lAddr);
  }
#endif /* I_WANT_TO_CHANGE_DEFAULT_ROM_DEVICE_ADDRESS_PSEUDO_CODE */

  SMPL_Init(sRxCallback);

  /* never coming back... */
  Connect();

  /* but in case we do... */
  while (1);
}
//*****************************************************************************
//
// Main application entry function.
//
//*****************************************************************************
int
main(void)
{
    tBoolean bSuccess, bRetcode;
    unsigned char pucMsg[2];
    unsigned char ucTid;
    unsigned char ucDelay;
    unsigned long ulLastRxCount, ulLastTxCount;
    smplStatus_t eRetcode;

    //
    // Set the system clock to run at 50MHz from the PLL
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // NB: We don't call PinoutSet() in this testcase since the EM header
    // expansion board doesn't currently have an I2C ID EEPROM.  If we did
    // call PinoutSet() this would configure all the EPI pins for SDRAM and
    // we don't want to do this.
    //
    g_eDaughterType = DAUGHTER_NONE;

    //
    // Enable peripherals required to drive the LCD.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);

    //
    // Configure SysTick for a 10Hz interrupt.
    //
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND);
    ROM_SysTickEnable();
    ROM_SysTickIntEnable();

    //
    // Initialize the display driver.
    //
    Kitronix320x240x16_SSD2119Init();

    //
    // Initialize the touch screen driver.
    //
    TouchScreenInit();

    //
    // Set the touch screen event handler.
    //
    TouchScreenCallbackSet(WidgetPointerMessage);

    //
    // Add the compile-time defined widgets to the widget tree.
    //
    WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sHeading);

    //
    // Initialize the status string.
    //
    UpdateStatus(true, "Please choose the operating mode.");

    //
    // Paint the widget tree to make sure they all appear on the display.
    //
    WidgetPaint(WIDGET_ROOT);

    //
    // Initialize the SimpliciTI BSP.
    //
    BSP_Init();

    //
    // Set the SimpliciTI device address using the current Ethernet MAC address
    // to ensure something like uniqueness.
    //
    bRetcode = SetSimpliciTIAddress();
    if(!bRetcode)
    {
        //
        // The board does not have a MAC address configured so we can't set
        // the SimpliciTI device address (which we derive from the MAC address).
        //
        while(1);
    }

    //
    // Initialize the SimpliciTI stack and supply our receive callback
    // function pointer.
    //
    SMPL_Init(RxCallback);

    //
    // Initialize our message ID, initial inter-message delay and packet
    // counters.
    //
    ucTid = 0;
    ucDelay = 0;
    ulLastRxCount = 0;
    ulLastTxCount = 0;

    //
    // Fall into the command line processing loop.
    //
    while (1)
    {
        //
        // Process any messages from or for the widgets.
        //
        WidgetMessageQueueProcess();

        //
        // Check to see if we've been told to do anything.
        //
        if(g_ulCommandFlags)
        {
            //
            // Has the mode been set?  If so, set up the display to show the
            // "LEDs" and then start communication.
            //
            if(HWREGBITW(&g_ulCommandFlags, COMMAND_MODE_SET))
            {
                //
                // Clear the bit now that we have seen it.
                //
                HWREGBITW(&g_ulCommandFlags, COMMAND_MODE_SET) = 0;

                //
                // Remove the buttons and replace them with the LEDs then
                // repaint the display.
                //
                WidgetRemove((tWidget *)&g_sBtnContainer);
                WidgetAdd((tWidget *)&g_sBackground,
                          (tWidget *)&g_sLEDContainer);
                WidgetPaint((tWidget *)&g_sBackground);

                //
                // Now call the function that initiates communication in
                // the desired mode.  Note that these functions will not return
                // until communication is established or an error occurs.
                //
                if(g_ulMode == MODE_TALKER)
                {
                    bSuccess = LinkTo();
                }
                else
                {
                    bSuccess = LinkFrom();
                }

                //
                // If we were unsuccessfull, go back to the mode selection
                // display.
                //
                if(!bSuccess)
                {
                    //
                    // Remove the LEDs and show the buttons again.
                    //
                    WidgetRemove((tWidget *)&g_sLEDContainer);
                    WidgetAdd((tWidget *)&g_sBackground,
                              (tWidget *)&g_sBtnContainer);
                    WidgetPaint((tWidget *)&g_sBackground);

                    //
                    // Tell the user what happened.
                    //
                    UpdateStatus(false, "Error establishing communication!");
                    UpdateStatus(true, "Please choose the operating mode.");

                    //
                    // Remember that we don't have an operating mode chosen.
                    //
                    g_ulMode = MODE_UNDEFINED;
                }
            }

            //
            // Have we been asked to toggle the first "LED"?
            //
            if(HWREGBITW(&g_ulCommandFlags, COMMAND_LED1_TOGGLE))
            {
                //
                // Clear the bit now that we have seen it.
                //
                HWREGBITW(&g_ulCommandFlags, COMMAND_LED1_TOGGLE) = 0;

                //
                // Toggle the LED.
                //
                ToggleLED(1);
            }

            //
            // Have we been asked to toggle the second "LED"?
            //
            if(HWREGBITW(&g_ulCommandFlags, COMMAND_LED2_TOGGLE))
            {
                //
                // Clear the bit now that we have seen it.
                //
                HWREGBITW(&g_ulCommandFlags, COMMAND_LED2_TOGGLE) = 0;

                //
                // Toggle the LED.
                //
                ToggleLED(2);
            }

            //
            // Have we been asked to send a packet back to our peer?  This
            // command is only ever sent to the main loop when we are running
            // in listener mode (LinkListen).
            //
            if(HWREGBITW(&g_ulCommandFlags, COMMAND_SEND_REPLY))
            {
                //
                // Clear the bit now that we have seen it.
                //
                HWREGBITW(&g_ulCommandFlags, COMMAND_SEND_REPLY) = 0;

                //
                // Create the message.  The first byte tells the receiver to
                // toggle LED1 and the second is a sequence counter.
                //
                pucMsg[0] = 1;
                pucMsg[1] = ++ucTid;
                eRetcode = SMPL_Send(sLinkID, pucMsg, 2);

                //
                // Update our transmit counter if we transmitted the packet
                // successfully.
                //
                if(eRetcode == SMPL_SUCCESS)
                {
                    g_ulTxCount++;
                }
                else
                {
                    UpdateStatus(false, "TX error %s (%d)", MapSMPLStatus(eRetcode),
                                 eRetcode);
                }
            }
        }

        //
        // If we are the talker (LinkTo mode), check to see if it's time to
        // send another packet to our peer.
        //
        if((g_ulMode == MODE_TALKER) &&
           (g_ulSysTickCount >= g_ulNextPacketTick))
        {
            //
            // Create the message.  The first byte tells the receiver to
            // toggle LED1 and the second is a sequence counter.
            //
            pucMsg[0] = 1;
            pucMsg[1] = ++ucTid;
            eRetcode = SMPL_Send(sLinkID, pucMsg, 2);

            //
            // Update our transmit counter if we transmitted the packet
            // correctly.
            //
            if(eRetcode == SMPL_SUCCESS)
            {
                g_ulTxCount++;
            }
            else
            {
                UpdateStatus(false, "TX error %s (%d)", MapSMPLStatus(eRetcode),
                             eRetcode);
            }

            //
            // Set the delay before the next message.
            //
#ifndef USE_2_SECOND_DELAY
            //
            // Set the delay before the next message.  We increase this from 1
            // second to 4 seconds then cycle back to 1.
            //
            ucDelay = (ucDelay == 4) ? 1 : (ucDelay + 1);
#else
            //
            // Wait 2 seconds before sending the next message.
            //
            ucDelay = 2;
#endif

            //
            // Calculate the system tick count when our delay has completed.
            // This algorithm will generate a spurious packet every 13.7 years
            // since I don't handle the rollover case in the comparison above
            // but I'm pretty sure you will forgive me for this oversight.
            //
            g_ulNextPacketTick = g_ulSysTickCount +
                                 (TICKS_PER_SECOND * ucDelay);
        }

        //
        // If either the transmit or receive packet count changed, update
        // the status on the display.
        //
        if((g_ulRxCount != ulLastRxCount) || (g_ulTxCount != ulLastTxCount))
        {
            ulLastTxCount = g_ulTxCount;
            ulLastRxCount = g_ulRxCount;
            UpdateStatus(false, "Received %d pkts, sent %d (%d)",
                         ulLastRxCount, ulLastTxCount);
        }
    }
}
void main (void)
{
  BSP_Init();

  /* If an on-the-fly device address is generated it must be done before the
   * call to SMPL_Init(). If the address is set here the ROM value will not
   * be used. If SMPL_Init() runs before this IOCTL is used the IOCTL call
   * will not take effect. One shot only. The IOCTL call below is conformal.
   */
#ifdef I_WANT_TO_CHANGE_DEFAULT_ROM_DEVICE_ADDRESS_PSEUDO_CODE
  {
    addr_t lAddr;

    createRandomAddress(&lAddr);
    SMPL_Ioctl(IOCTL_OBJ_ADDR, IOCTL_ACT_SET, &lAddr);
  }
#endif /* I_WANT_TO_CHANGE_DEFAULT_ROM_DEVICE_ADDRESS_PSEUDO_CODE */

  while (SMPL_SUCCESS != SMPL_Init((uint8_t (*)(linkID_t))0))
  {
    toggleLED(1);
    toggleLED(2);
    SPIN_ABOUT_A_SECOND;
  }

  toggleLED(1);
  toggleLED(2);

#ifdef ACCESS_POINT
  /* This code example changes the Link token to be distributed to those who
   * Join. For the example here this should be done before anyone joins so
   * the Join context is defaulted to OFF for this scenario. See the
   * smpl_config.dat file. After the link token is set the Join context must
   * be enabled.
   *
   * NOTE that this is done after initialization. For APs the init sequence
   * consists of a step in which a link token is generated. The sequence here
   * overrides that setting. It can be used to distribute different link tokens
   * to different devices. The sequence here is a simple example of how to use
   * the IOCTL interface to set the Link token for subsequent Joiners.
   *
   * You might want to be careful about following this particular example if you
   * are restoring from NV unless you are setting a fixed value as is done here.
   * Unconditionally setting a random value will make it esentially impossible
   * for newly joining devices to link to devices that joined before the AP was
   * reset since they will have different link tokens.
   */
  {
    ioctlToken_t t;

    t.tokenType       = TT_LINK;
    t.token.linkToken = 0x78563412;

    SMPL_Ioctl(IOCTL_OBJ_TOKEN, IOCTL_ACT_SET, &t);

    /* enable join context */
    SMPL_Ioctl(IOCTL_OBJ_AP_JOIN, IOCTL_ACT_ON, 0);
  }
#endif
  while (1) ;
}
//*****************************************************************************
//
// Main application entry function.
//
//*****************************************************************************
int
main(void)
{
    tBoolean bRetcode;
    bspIState_t intState;
    uint8_t ucLastChannel;

    //
    // Set the system clock to run at 50MHz from the PLL
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // NB: We don't call PinoutSet() in this testcase since the EM header
    // expansion board doesn't currently have an I2C ID EEPROM.  If we did
    // call PinoutSet() this would configure all the EPI pins for SDRAM and
    // we don't want to do this.
    //
    g_eDaughterType = DAUGHTER_NONE;

    //
    // Enable peripherals required to drive the LCD.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);

    //
    // Configure SysTick for a 10Hz interrupt.
    //
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND);
    ROM_SysTickEnable();
    ROM_SysTickIntEnable();

    //
    // Initialize the display driver.
    //
    Kitronix320x240x16_SSD2119Init();

    //
    // Initialize the touch screen driver.
    //
    TouchScreenInit();

    //
    // Set the touch screen event handler.
    //
    TouchScreenCallbackSet(WidgetPointerMessage);

    //
    // Add the compile-time defined widgets to the widget tree.
    //
    WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sHeading);

    //
    // Initialize the status string.
    //
    UpdateStatus(true, "Initializing...");

    //
    // Paint the widget tree to make sure they all appear on the display.
    //
    WidgetPaint(WIDGET_ROOT);

    //
    // Initialize the SimpliciTI BSP.
    //
    BSP_Init();

    //
    // Set the SimpliciTI device address using the current Ethernet MAC address
    // to ensure something like uniqueness.
    //
    bRetcode = SetSimpliciTIAddress();

    //
    // Did we have a problem with the address?
    //
    if(!bRetcode)
    {
        //
        // Yes - make sure the display is updated then hang the app.
        //
        WidgetMessageQueueProcess();
        while(1)
        {
            //
            // MAC address is not set so hang the app.
            //
        }
    }

    //
    // Turn on both our LEDs
    //
    SetLED(1, true);
    SetLED(2, true);

    UpdateStatus(true, "Waiting for a device...");

    //
    // Initialize the SimpliciTI stack and register our receive callback.
    //
    SMPL_Init(ReceiveCallback);

    //
    // Tell the user what's up.
    //
    UpdateStatus(true, "Access point active.");

    //
    // Do nothing after this - the SimpliciTI stack code handles all the
    // access point function required.
    //
    while(1)
    {
        //
        // Wait for the Join semaphore to be set by the receipt of a Join
        // frame from a device that supports an end device.
        //
        // An external method could be used as well. A button press could be
        // connected to an ISR and the ISR could set a semaphore that is
        // checked by a function call here, or a command shell running in
        // support of a serial connection could set a semaphore that is
        // checked by a function call.
        //
        if (g_ucJoinSem && (g_ucNumCurrentPeers < NUM_CONNECTIONS))
        {
            //
            // Listen for a new incoming connection.
            //
            while (1)
            {
                if (SMPL_SUCCESS == SMPL_LinkListen(&g_sLID[g_ucNumCurrentPeers]))
                {
                    //
                    // The connection attempt succeeded so break out of the
                    // loop.
                    //
                    break;
                }

                //
                // Process our widget message queue.
                //
                WidgetMessageQueueProcess();

                //
                // A "real" application would implement its fail-to-link
                // policy here.  We go back and listen again.
                //
            }

            //
            // Increment our peer counter.
            //
            g_ucNumCurrentPeers++;

            //
            // Decrement the join semaphore.
            //
            BSP_ENTER_CRITICAL_SECTION(intState);
            g_ucJoinSem--;
            BSP_EXIT_CRITICAL_SECTION(intState);

            //
            // Tell the user how many devices we are now connected to.
            //
            UpdateStatus(false, "%d devices connected.", g_ucNumCurrentPeers);
        }

        //
        // Have we received a frame on one of the ED connections? We don't use
        // a critical section here since it doesn't really matter much if we
        // miss a poll.
        //
        if (g_ucPeerFrameSem)
        {
            uint8_t     pucMsg[MAX_APP_PAYLOAD], ucLen, ucLoop;

            /* process all frames waiting */
            for (ucLoop = 0; ucLoop < g_ucNumCurrentPeers; ucLoop++)
            {
                //
                // Receive the message.
                //
                if (SMPL_SUCCESS == SMPL_Receive(g_sLID[ucLoop], pucMsg,
                                                 &ucLen))
                {
                    //
                    // ...and pass it to the function that processes it.
                    //
                    ProcessMessage(g_sLID[ucLoop], pucMsg, ucLen);

                    //
                    // Decrement our frame semaphore.
                    //
                    BSP_ENTER_CRITICAL_SECTION(intState);
                    g_ucPeerFrameSem--;
                    BSP_EXIT_CRITICAL_SECTION(intState);
                }
            }
        }

        //
        // Have we been asked to change channel?
        //
        ucLastChannel = g_ucChannel;
        if (g_bChangeChannel)
        {
            //
            // Yes - go ahead and change to the next radio channel.
            //
            g_bChangeChannel = false;
            ChangeChannel();
        }
        else
        {
            //
            // No - check to see if we need to automatically change channel
            // due to interference on the current one.
            //
            CheckChangeChannel();
        }

        //
        // If the channel changed, update the display.
        //
        if(g_ucChannel != ucLastChannel)
        {
            UpdateStatus(false, "Changed to channel %d.", g_ucChannel);
        }

        //
        // If required, blink the "LEDs" to indicate we are waiting for a
        // message following a channel change.
        //
        BSP_ENTER_CRITICAL_SECTION(intState);
        if (g_ulBlinky)
        {
            if (++g_ulBlinky >= 0xF)
            {
                g_ulBlinky = 1;
                ToggleLED(1);
                ToggleLED(2);
            }
        }
        BSP_EXIT_CRITICAL_SECTION(intState);

        //
        // Process our widget message queue.
        //
        WidgetMessageQueueProcess();
    }
}
void main (void)
{
  addr_t lAddr;
  bspIState_t intState;
  char *Flash_Addr;                         // Initialize radio address location
  Flash_Addr = (char *)0x10F0;

  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  // delay loop to ensure proper startup before SimpliciTI increases DCO
  // This is typically tailored to the power supply used, and in this case
  // is overkill for safety due to wide distribution.
  __delay_cycles(65000);

  if( CALBC1_8MHZ == 0xFF && CALDCO_8MHZ == 0xFF )// Do not run if cal values
  {
    P1DIR |= 0x03;
    BSP_TURN_ON_LED1();
    BSP_TURN_OFF_LED2();
    while(1)
    {
      __delay_cycles(65000);
      BSP_TOGGLE_LED2();
      BSP_TOGGLE_LED1();
    }
  }

  BSP_Init();

  if( Flash_Addr[0] == 0xFF &&
      Flash_Addr[1] == 0xFF &&
      Flash_Addr[2] == 0xFF &&
      Flash_Addr[3] == 0xFF )
    {
      createRandomAddress();                // Create Random device address at
    }                                       // initial startup if missing
  lAddr.addr[0]=Flash_Addr[0];
  lAddr.addr[1]=Flash_Addr[1];
  lAddr.addr[2]=Flash_Addr[2];
  lAddr.addr[3]=Flash_Addr[3];

  //SMPL_Init();
  SMPL_Ioctl(IOCTL_OBJ_ADDR, IOCTL_ACT_SET, &lAddr);

  MCU_Init();
  //Transmit splash screen and network init notification
  TXString( (char*)splash, sizeof splash);
  TXString( "\r\nInitializing Network....", 26 );

  SMPL_Init(sCB);

  // network initialized
  TXString( "Done\r\n", 6);

  // main work loop
  while(1)
  {
    // Wait for the Join semaphore to be set by the receipt of a Join frame from a
    // device that supports and End Device.

    if (sJoinSem && (sNumCurrentPeers < NUM_CONNECTIONS))
    {
      // listen for a new connection
      SMPL_LinkListen(&sLID[sNumCurrentPeers]);
      sNumCurrentPeers++;
      BSP_ENTER_CRITICAL_SECTION(intState);
      if (sJoinSem)
      {
        sJoinSem--;
      }
      BSP_EXIT_CRITICAL_SECTION(intState);
    }

    // if it is time to measure our own temperature...
    if(sSelfMeasureSem)
    {
//    	TXString("\r\n...", 5);
      BSP_TOGGLE_LED1();
      sSelfMeasureSem = 0;
    }

    // Have we received a frame on one of the ED connections?
    // No critical section -- it doesn't really matter much if we miss a poll
    if (sPeerFrameSem)
    {
    	  uint8_t  msg[MESSAGE_LENGTH], len, i;

      // process all frames waiting
      for (i=0; i<sNumCurrentPeers; ++i)
      {
        if (SMPL_Receive(sLID[i], msg, &len) == SMPL_SUCCESS)
        {
          ioctlRadioSiginfo_t sigInfo;
          sigInfo.lid = sLID[i];
          SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SIGINFO, (void *)&sigInfo);
          transmitData( i, (signed char)sigInfo.sigInfo.rssi, (char*)msg );
          BSP_TURN_ON_LED2();               // Toggle LED2 when received packet
          BSP_ENTER_CRITICAL_SECTION(intState);
          sPeerFrameSem--;
          BSP_EXIT_CRITICAL_SECTION(intState);
          __delay_cycles(10000);
          BSP_TURN_OFF_LED2();
        }
      }
    }
  }
}
//*****************************************************************************
//
// Main application entry function.
//
//*****************************************************************************
int
main(void)
{
    tBoolean bRetcode;

    //
    // Set the system clock to run at 50MHz from the PLL
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // NB: We don't call PinoutSet() in this testcase since the EM header
    // expansion board doesn't currently have an I2C ID EEPROM.  If we did
    // call PinoutSet() this would configure all the EPI pins for SDRAM and
    // we don't want to do this.
    //
    g_eDaughterType = DAUGHTER_NONE;

    //
    // Enable peripherals required to drive the LCD.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);

    //
    // Configure SysTick for a 10Hz interrupt.
    //
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND);
    ROM_SysTickEnable();
    ROM_SysTickIntEnable();

    //
    // Initialize the display driver.
    //
    Kitronix320x240x16_SSD2119Init();

    //
    // Initialize the touch screen driver.
    //
    TouchScreenInit();

    //
    // Set the touch screen event handler.
    //
    TouchScreenCallbackSet(WidgetPointerMessage);

    //
    // Add the compile-time defined widgets to the widget tree.
    //
    WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sHeading);

    //
    // Initialize the status string.
    //
    UpdateStatus(true, "Monitoring...");

    //
    // Paint the widget tree to make sure they all appear on the display.
    //
    WidgetPaint(WIDGET_ROOT);

    //
    // Initialize the SimpliciTI BSP.
    //
    BSP_Init();

    //
    // Set the SimpliciTI device address using the current Ethernet MAC address
    // to ensure something like uniqueness.
    //
    bRetcode = SetSimpliciTIAddress();

    //
    // Did we have a problem with the address?
    //
    if(!bRetcode)
    {
        //
        // Yes - make sure the display is updated then hang the app.
        //
        WidgetMessageQueueProcess();
        while(1)
        {
            //
            // MAC address is not set so hang the app.
            //
        }
    }

    //
    // Initialize the SimpliciTI stack but don't set any receive callback.
    //
    SMPL_Init(0);

    //
    // Start monitoring for alert messages from other devices.  This function
    // doesn't return.
    //
    MonitorForBadNews();
}
void main (void)
{
  bspIState_t intState;

#ifdef FREQUENCY_AGILITY
  memset(sSample, 0x0, sizeof(sSample));
#endif

  BSP_Init();

  /* If an on-the-fly device address is generated it must be done before the
   * call to SMPL_Init(). If the address is set here the ROM value will not
   * be used. If SMPL_Init() runs before this IOCTL is used the IOCTL call
   * will not take effect. One shot only. The IOCTL call below is conformal.
   */
#ifdef I_WANT_TO_CHANGE_DEFAULT_ROM_DEVICE_ADDRESS_PSEUDO_CODE
  {
    addr_t lAddr;

    createRandomAddress(&lAddr);
    SMPL_Ioctl(IOCTL_OBJ_ADDR, IOCTL_ACT_SET, &lAddr);
  }
#endif /* I_WANT_TO_CHANGE_DEFAULT_ROM_DEVICE_ADDRESS_PSEUDO_CODE */

  SMPL_Init(sCB);

  /* green and red LEDs on solid to indicate waiting for a Join. */
  if (!BSP_LED2_IS_ON())
  {
    toggleLED(2);
  }
  if (!BSP_LED1_IS_ON())
  {
    toggleLED(1);
  }

  /* main work loop */
  while (1)
  {
    /* manage FHSS schedule if FHSS is active */
    FHSS_ACTIVE( nwk_pllBackgrounder( false ) );
    
    /* Wait for the Join semaphore to be set by the receipt of a Join frame from a
     * device that supports an End Device.
     *
     * An external method could be used as well. A button press could be connected
     * to an ISR and the ISR could set a semaphore that is checked by a function
     * call here, or a command shell running in support of a serial connection
     * could set a semaphore that is checked by a function call.
     */
    if (sJoinSem && (sNumCurrentPeers < NUM_CONNECTIONS))
    {
      /* listen for a new connection */
      while (1)
      { /* SMPL_LinkListen will call nwk_PllBackgrounder for us if FHSS active */
        if (SMPL_SUCCESS == SMPL_LinkListen(&sLID[sNumCurrentPeers]))
        {
          break;
        }
        /* Implement fail-to-link policy here. otherwise, listen again. */
      }

      sNumCurrentPeers++;

      BSP_ENTER_CRITICAL_SECTION(intState);
      sJoinSem--;
      BSP_EXIT_CRITICAL_SECTION(intState);
    }

    /* Have we received a frame on one of the ED connections?
     * No critical section -- it doesn't really matter much if we miss a poll
     */
    if (sPeerFrameSem)
    {
      uint8_t     msg[MAX_APP_PAYLOAD], len, i;

      /* process all frames waiting */
      for (i=0; i<sNumCurrentPeers; ++i)
      {
        if (SMPL_SUCCESS == SMPL_Receive(sLID[i], msg, &len))
        {
          processMessage(sLID[i], msg, len);

          BSP_ENTER_CRITICAL_SECTION(intState);
          sPeerFrameSem--;
          BSP_EXIT_CRITICAL_SECTION(intState);
        }
      }
    }
    if (BSP_BUTTON1())
    {
      SPIN_ABOUT_A_QUARTER_SECOND;  /* debounce */
      changeChannel();
    }
    else
    {
      checkChangeChannel();
    }
    BSP_ENTER_CRITICAL_SECTION(intState);
    if (sBlinky)
    {
      if (++sBlinky >= 0xF)
      {
        sBlinky = 1;
        toggleLED(1);
        toggleLED(2);
      }
    }
    BSP_EXIT_CRITICAL_SECTION(intState);
  }

}
//*****************************************************************************
//
// Main application entry function.
//
//*****************************************************************************
int
main(void)
{
    tBoolean bSuccess, bRetcode, bInitialized;

    //
    // Set the system clock to run at 50MHz from the PLL
    //
    MAP_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // NB: We don't call PinoutSet() in this testcase since the EM header
    // expansion board doesn't currently have an I2C ID EEPROM.  If we did
    // call PinoutSet() this would configure all the EPI pins for SDRAM and
    // we don't want to do this.
    //
    g_eDaughterType = DAUGHTER_NONE;

    //
    // Enable peripherals required to drive the LCD.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);

    //
    // Configure SysTick for a 10Hz interrupt.
    //
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND);
    ROM_SysTickEnable();
    ROM_SysTickIntEnable();

    //
    // Initialize the display driver.
    //
    Kitronix320x240x16_SSD2119Init();

    //
    // Initialize the touch screen driver.
    //
    TouchScreenInit();

    //
    // Set the touch screen event handler.
    //
    TouchScreenCallbackSet(WidgetPointerMessage);

    //
    // Add the compile-time defined widgets to the widget tree.
    //
    WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sHeading);

    //
    // Paint the widget tree to make sure they all appear on the display.
    //
    WidgetPaint(WIDGET_ROOT);

    //
    // Initialize the SimpliciTI BSP.
    //
    BSP_Init();

    //
    // Set the SimpliciTI device address using the current Ethernet MAC address
    // to ensure something like uniqueness.
    //
    bRetcode = SetSimpliciTIAddress();
    if(!bRetcode)
    {
        //
        // The Ethernet MAC address can't have been set so hang here since we
        // don't have an address to use for SimpliciTI.
        //
        WidgetMessageQueueProcess();
        while(1)
        {
            //
            // MAC address is not set so hang the app.
            //
        }
    }

    //
    // First time through, we need to initialize the SimpliciTI stack.
    //
    bInitialized = false;

    //
    // The main loop starts here now that we have joined the network.
    //
    while(1)
    {
        //
        // Tell the user what to do.
        //
        UpdateStatus(true, "Please choose the operating mode.");

        //
        // Now wait until the user selects whether we should run as the sender
        // or the receiver.
        //
        while(g_ulMode == MODE_UNDEFINED)
        {
            //
            // Just spin, processing UI messages and waiting for someone to
            // press one of the mode buttons.
            //
            WidgetMessageQueueProcess();
        }

        //
        // At this point, the mode is set so remove the buttons from the
        // display and replace them with the LEDs.
        //
        WidgetRemove((tWidget *)&g_sBtnContainer);
        WidgetAdd((tWidget *)&g_sBackground,
                  (tWidget *)&g_sLEDContainer);
        WidgetPaint((tWidget *)&g_sBackground);

        //
        // Tell the user what we're doing now.
        //
        UpdateStatus(false, "Joining network...");

        if(!bInitialized)
        {
            //
            // Initialize the SimpliciTI stack  We keep trying to initialize until
            // we get a success return code.  This indicates that we have also
            // successfully joined the network.
            //
            while(SMPL_SUCCESS != SMPL_Init((uint8_t (*)(linkID_t))0))
            {
                ToggleLED(1);
                ToggleLED(2);
                SPIN_ABOUT_A_SECOND;
            }

            //
            // Now that we are initialized, remember not to call this again.
            //
            bInitialized = true;
        }

        //
        // Once we have joined, turn both LEDs on and tell the user what we want
        // them to do.
        //
        SetLED(1, true);
        SetLED(2, true);

        //
        // Now call the function that initiates communication in
        // the desired mode.  Note that these functions will not return
        // until communication is established or an error occurs.
        //
        if(g_ulMode == MODE_SENDER)
        {
            bSuccess = LinkTo();
        }
        else
        {
            bSuccess = LinkFrom();
        }

        //
        // If we were unsuccessfull, go back to the mode selection
        // display.
        //
        if(!bSuccess)
        {
            //
            // Remove the LEDs and show the buttons again.
            //
            WidgetRemove((tWidget *)&g_sLEDContainer);
            WidgetAdd((tWidget *)&g_sBackground, (tWidget *)&g_sBtnContainer);
            WidgetPaint((tWidget *)&g_sBackground);

            //
            // Tell the user what happened.
            //
            UpdateStatus(false, "Error establishing communication!");

            //
            // Remember that we don't have an operating mode chosen.
            //
            g_ulMode = MODE_UNDEFINED;
        }
    }
}
// AP main routine
void simpliciti_main(void)
{
  bspIState_t intState;
  uint8_t j;
  uint8_t len;
  uint32_t led_toggle = 0;
  uint8_t   pwr;

  // Init variables  
  simpliciti_flag = SIMPLICITI_STATUS_LINKING;

  // Init SimpliciTI
  SMPL_Init(sCB);
  
  // Set output power to +1.1dBm (868MHz) / +1.3dBm (915MHz)
  pwr = IOCTL_LEVEL_2;
  SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SETPWR, &pwr);
  
   // LED off
  BSP_TURN_OFF_LED1();
    
  /* main work loop */
  while (1)
  {
    // Wait for the Join semaphore to be set by the receipt of a Join frame from a
    //device that supports an End Device.
    if (sJoinSem && !sNumCurrentPeers)
    {
      /* listen for a new connection */
      while (1)
      {
        if (SMPL_SUCCESS == SMPL_LinkListen(&linkID0))
        {
          // We have a connection
          simpliciti_flag = SIMPLICITI_STATUS_LINKED;
          BSP_TURN_ON_LED1();
          break;
        }
        /* Implement fail-to-link policy here. otherwise, listen again. */
      }

      sNumCurrentPeers++;

      BSP_ENTER_CRITICAL_SECTION(intState);
      sJoinSem--;
      BSP_EXIT_CRITICAL_SECTION(intState);
    }

    /* Have we received a frame on one of the ED connections?
     * No critical section -- it doesn't really matter much if we miss a poll
     */
    if (sPeerFrameSem)
    {
      // Continuously try to receive end device packets
      if (SMPL_SUCCESS == SMPL_Receive(linkID0, ed_data, &len))
      {
        // Acceleration / ppt data packets are 4 byte long
        if (len == 4)
        {
          BSP_TOGGLE_LED1();
          memcpy(simpliciti_data, ed_data, 4);
          setFlag(simpliciti_flag, SIMPLICITI_TRIGGER_RECEIVED_DATA);

#ifdef EMBEDDED_UART        
          uart_analyze_packet(simpliciti_data[0],simpliciti_data[1],simpliciti_data[2],simpliciti_data[3]);
#endif              
        }        
        // Sync packets are either R2R (2 byte) or data (19 byte) long
        else if ((len == 2) || (len == 19))
        {
          // Indicate received packet
          BSP_TOGGLE_LED1();

          // Decode end device packet
          switch (ed_data[0])
          {
              case SYNC_ED_TYPE_R2R: 
                                    // Send reply
                                    if (getFlag(simpliciti_flag, SIMPLICITI_TRIGGER_SEND_CMD))
                                    {
                                      // Clear flag
                                      clearFlag(simpliciti_flag, SIMPLICITI_TRIGGER_SEND_CMD);
                                      // Command data was set by USB buffer previously
                                      len = BM_SYNC_DATA_LENGTH;
                                    }
                                    else // No command currently available
                                    {
                                      simpliciti_data[0] = SYNC_AP_CMD_NOP;
                                      simpliciti_data[1] = 0x55;
                                      len = 2;
                                    }
                
                                    // Send reply packet to end device
                                    SMPL_Send(linkID0, simpliciti_data, len);
                                    break;
                                 
            case SYNC_ED_TYPE_MEMORY: 
            case SYNC_ED_TYPE_STATUS:
                                    // If buffer is empty, copy received end device data to intermediate buffer
                                    if (!simpliciti_sync_buffer_status)
                                    {
                                      for (j=0; j<BM_SYNC_DATA_LENGTH; j++) simpliciti_data[j] = ed_data[j];
                                      simpliciti_sync_buffer_status = 1;
                                    }
                                    // Set buffer status to full
                                    break;

          }
        }
      }
    }
    
    // Exit function if SIMPLICITI_TRIGGER_STOP flag bit is set in USB driver    
    if (getFlag(simpliciti_flag, SIMPLICITI_TRIGGER_STOP)) 
    {
      // Immediately turn off RF interrupt
      IEN2 &= ~BIT0;
      RFIM = 0;
      RFIF = 0;
      // Clean up after SimpliciTI and enable restarting the stack
      linkID0 = 0;
      sNumCurrentPeers = 0;
      sJoinSem = 0;
      sPeerFrameSem = 0;
      sInit_done = 0;
      // LED off
      BSP_TURN_OFF_LED1();
      return;
    }
    
    // Blink slowly to indicate that access point is on
    if (!sNumCurrentPeers)
    {
      if (led_toggle++>150000)
      {
        BSP_TOGGLE_LED1();
        led_toggle = 0;
      }
    }
  }
}
//*****************************************************************************
//
// Main application entry function.
//
//*****************************************************************************
int
main(void)
{
    tBoolean bRetcode;
    smplStatus_t eRetcode;

    //
    // Set the system clock to run at 50MHz from the PLL
    //
    MAP_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // NB: We don't call PinoutSet() in this testcase since the EM header
    // expansion board doesn't currently have an I2C ID EEPROM.  If we did
    // call PinoutSet() this would configure all the EPI pins for SDRAM and
    // we don't want to do this.
    //
    g_eDaughterType = DAUGHTER_NONE;

    //
    // Enable peripherals required to drive the LCD.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);

    //
    // Configure SysTick for a 10Hz interrupt.
    //
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND);
    ROM_SysTickEnable();
    ROM_SysTickIntEnable();

    //
    // Initialize the display driver.
    //
    Kitronix320x240x16_SSD2119Init();

    //
    // Initialize the touch screen driver.
    //
    TouchScreenInit();

    //
    // Set the touch screen event handler.
    //
    TouchScreenCallbackSet(WidgetPointerMessage);

    //
    // Add the compile-time defined widgets to the widget tree.
    //
    WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sHeading);

    //
    // Initialize the status string.
    //
    UpdateStatus("Initializing...");

    //
    // Paint the widget tree to make sure they all appear on the display.
    //
    WidgetPaint(WIDGET_ROOT);

    //
    // Initialize the SimpliciTI BSP.
    //
    BSP_Init();

    //
    // Set the SimpliciTI device address using the current Ethernet MAC address
    // to ensure something like uniqueness.
    //
    bRetcode = SetSimpliciTIAddress();

    //
    // Did we have a problem with the address?
    //
    if(!bRetcode)
    {
        //
        // Yes - make sure the display is updated then hang the app.
        //
        WidgetMessageQueueProcess();
        while(1)
        {
            //
            // MAC address is not set so hang the app.
            //
        }
    }

    //
    // Turn on both our LEDs
    //
    SetLED(1, true);
    SetLED(2, true);

    UpdateStatus("Waiting...");

    //
    // Initialize the SimpliciTI stack but don't set any receive callback.
    //
    while(1)
    {
        eRetcode = SMPL_Init((uint8_t (*)(linkID_t))0);

        if(eRetcode == SMPL_SUCCESS)
        {
            break;
        }

        ToggleLED(1);
        ToggleLED(2);
        SPIN_ABOUT_A_SECOND;
    }

    //
    // Tell the user what's up.
    //
    UpdateStatus("Range Extender active.");

    //
    // Do nothing after this - the SimpliciTI stack code handles all the
    // access point function required.
    //
    while(1)
    {
        //
        // Process the widget message queue.
        //
        WidgetMessageQueueProcess();
    }
}
//*****************************************************************************
//
// Main application entry function.
//
//*****************************************************************************
int
main(void)
{
    tBoolean bRetcode;
    smplStatus_t eRetcode;
    ioctlToken_t eToken;

    //
    // Set the system clock to run at 50MHz from the PLL
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // NB: We don't call PinoutSet() in this testcase since the EM header
    // expansion board doesn't currently have an I2C ID EEPROM.  If we did
    // call PinoutSet() this would configure all the EPI pins for SDRAM and
    // we don't want to do this.
    //
    g_eDaughterType = DAUGHTER_NONE;

    //
    // Enable peripherals required to drive the LCD.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);

    //
    // Configure SysTick for a 10Hz interrupt.
    //
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND);
    ROM_SysTickEnable();
    ROM_SysTickIntEnable();

    //
    // Initialize the display driver.
    //
    Kitronix320x240x16_SSD2119Init();

    //
    // Initialize the touch screen driver.
    //
    TouchScreenInit();

    //
    // Set the touch screen event handler.
    //
    TouchScreenCallbackSet(WidgetPointerMessage);

    //
    // Add the compile-time defined widgets to the widget tree.
    //
    WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sHeading);

    //
    // Initialize the status string.
    //
    UpdateStatus("Initializing...");

    //
    // Paint the widget tree to make sure they all appear on the display.
    //
    WidgetPaint(WIDGET_ROOT);

    //
    // Initialize the SimpliciTI BSP.
    //
    BSP_Init();

    //
    // Set the SimpliciTI device address using the current Ethernet MAC address
    // to ensure something like uniqueness.
    //
    bRetcode = SetSimpliciTIAddress();

    //
    // Did we have a problem with the address?
    //
    if(!bRetcode)
    {
        //
        // Yes - make sure the display is updated then hang the app.
        //
        WidgetMessageQueueProcess();
        while(1)
        {
            //
            // MAC address is not set so hang the app.
            //
        }
    }

    //
    // Turn on both our LEDs
    //
    SetLED(1, true);
    SetLED(2, true);

    UpdateStatus("Waiting...");

    //
    // Initialize the SimpliciTI stack but don't set any receive callback.
    //
    while(1)
    {
        eRetcode = SMPL_Init((uint8_t (*)(linkID_t))0);

        if(eRetcode == SMPL_SUCCESS)
        {
            break;
        }

        ToggleLED(1);
        ToggleLED(2);
        SPIN_ABOUT_A_SECOND;
    }

    // This code example changes the Link token to be distributed to those who
    // Join. For the example here this should be done before anyone joins so
    // the Join context is defaulted to OFF for this scenario. See the
    // smpl_config.dat file. After the link token is set the Join context must
    // be enabled.
    //
    // NOTE that this is done after initialization. For APs the init sequence
    // consists of a step in which a link token is generated. The sequence here
    // overrides that setting. It can be used to distribute different link
    // tokens to different devices. The sequence here is a simple example of
    // how to use the IOCTL interface to set the Link token for subsequent
    // Joiners.
    //
    // You might want to be careful about following this particular example if
    // you are restoring from NV unless you are setting a fixed value as is
    // done here.  Unconditionally setting a random value will make it
    // essentially impossible for newly joining devices to link to devices that
    // joined before the AP was reset since they will have different link
    // tokens.
    //
    eToken.tokenType       = TT_LINK;
    eToken.token.linkToken = 0x78563412;

    SMPL_Ioctl(IOCTL_OBJ_TOKEN, IOCTL_ACT_SET, &eToken);

    //
    // Enable join context.
    //
    SMPL_Ioctl(IOCTL_OBJ_AP_JOIN, IOCTL_ACT_ON, 0);

    //
    // Tell the user what's up.
    //
    UpdateStatus("Access point active.");

    //
    // Do nothing after this - the SimpliciTI stack code handles all the
    // access point function required.
    //
    while(1)
    {
        //
        // Process the widget message queue.
        //
        WidgetMessageQueueProcess();
    }
}
void main (void)
{
  ioctlScanChan_t scan;
  freqEntry_t     freq[NWK_FREQ_TBL_SIZE];
  uint8_t         firstTimeThru = 1;

  BSP_Init();

  /* Keep trying to join (a side effect of successful initialization) until
   * successful. Toggle LEDS to indicate that joining has not occurred.
   */
  while (SMPL_SUCCESS != SMPL_Init(0))
  {
    toggleLED(1);
    toggleLED(2);
    SPIN_ABOUT_A_SECOND;
  }

  scan.freq = freq;
  while (1)
  {
    SPIN_ABOUT_A_QUARTER_SECOND;

    SMPL_Ioctl(IOCTL_OBJ_FREQ, IOCTL_ACT_SCAN, &scan);
    if (1 == scan.numChan)
    {
      if (firstTimeThru)
      {
        BSP_TURN_OFF_LED1();
        BSP_TURN_ON_LED2();
        {
          uint8_t i=15;

          while (i--)
          {
            toggleLED(1);
            toggleLED(2);
            SPIN_ABOUT_A_QUARTER_SECOND;
          }
        }
        firstTimeThru = 0;
      }
      switch(freq[0].logicalChan)
      {
        case 0:
          /* GREEN OFF */
          /* RED   OFF */
          BSP_TURN_OFF_LED1();
          BSP_TURN_OFF_LED2();
          break;

        case 1:
          /* GREEN OFF */
          /* RED   ON */
          BSP_TURN_OFF_LED1();
          BSP_TURN_ON_LED2();
          break;

        case 2:
          /* GREEN ON */
          /* RED   OFF */
          BSP_TURN_ON_LED1();
          BSP_TURN_OFF_LED2();
          break;

        case 3:
          /* GREEN ON */
          /* RED   ON */
          BSP_TURN_ON_LED1();
          BSP_TURN_ON_LED2();
          break;

        case 4:
          /* blink them both... */
          BSP_TURN_OFF_LED1();
          BSP_TURN_OFF_LED2();
          SPIN_ABOUT_A_QUARTER_SECOND;
          BSP_TURN_ON_LED1();
          BSP_TURN_ON_LED2();
          SPIN_ABOUT_A_QUARTER_SECOND;
          BSP_TURN_OFF_LED1();
          BSP_TURN_OFF_LED2();
      }
    }
  }
}
//*****************************************************************************
//
// Main application entry function.
//
//*****************************************************************************
int
main(void)
{
    tBoolean bRetcode;
    smplStatus_t eRetcode;
    ioctlScanChan_t sScan;
    freqEntry_t pFreq[NWK_FREQ_TBL_SIZE];
    tBoolean bFirstTimeThrough;
    unsigned long ulLoop;
    uint8_t ucLast;

    //
    // Set the system clock to run at 50MHz from the PLL
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // NB: We don't call PinoutSet() in this testcase since the EM header
    // expansion board doesn't currently have an I2C ID EEPROM.  If we did
    // call PinoutSet() this would configure all the EPI pins for SDRAM and
    // we don't want to do this.
    //
    g_eDaughterType = DAUGHTER_NONE;

    //
    // Enable peripherals required to drive the LCD.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);

    //
    // Configure SysTick for a 10Hz interrupt.
    //
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND);
    ROM_SysTickEnable();
    ROM_SysTickIntEnable();

    //
    // Initialize the display driver.
    //
    Kitronix320x240x16_SSD2119Init();

    //
    // Initialize the touch screen driver.
    //
    TouchScreenInit();

    //
    // Set the touch screen event handler.
    //
    TouchScreenCallbackSet(WidgetPointerMessage);

    //
    // Add the compile-time defined widgets to the widget tree.
    //
    WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sHeading);

    //
    // Initialize the status string.
    //
    UpdateStatus("Initializing...");

    //
    // Paint the widget tree to make sure they all appear on the display.
    //
    WidgetPaint(WIDGET_ROOT);

    //
    // Initialize the SimpliciTI BSP.
    //
    BSP_Init();

    //
    // Set the SimpliciTI device address using the current Ethernet MAC address
    // to ensure something like uniqueness.
    //
    bRetcode = SetSimpliciTIAddress();

    //
    // Did we have a problem with the address?
    //
    if(!bRetcode)
    {
        //
        // Yes - make sure the display is updated then hang the app.
        //
        WidgetMessageQueueProcess();
        while(1)
        {
            //
            // MAC address is not set so hang the app.
            //
        }
    }

    //
    // Turn on both our LEDs
    //
    SetLED(1, true);
    SetLED(2, true);

    UpdateStatus("Joining network...");

    //
    // Initialize the SimpliciTI stack but don't set any receive callback.
    //
    while(1)
    {
        eRetcode = SMPL_Init((uint8_t (*)(linkID_t))0);

        if(eRetcode == SMPL_SUCCESS)
        {
            break;
        }

        ToggleLED(1);
        ToggleLED(2);
        SPIN_ABOUT_A_SECOND;
    }

    //
    // Tell the user what's up.
    //
    UpdateStatus("Sniffing...");

    //
    // Set up for our first sniff.
    //
    sScan.freq = pFreq;
    bFirstTimeThrough = true;
    ucLast = 0xFF;

    //
    // Keep sniffing forever.
    //
    while (1)
    {
        //
        // Wait a while.
        //
        SPIN_ABOUT_A_QUARTER_SECOND;

        //
        // Scan for the active channel.
        //
        SMPL_Ioctl(IOCTL_OBJ_FREQ, IOCTL_ACT_SCAN, &sScan);

        //
        // Did we find a signal?
        //
        if (1 == sScan.numChan)
        {
            if (bFirstTimeThrough)
            {
                //
                // Set the initial LED state.
                //
                SetLED(1, false);
                SetLED(2, true);

                //
                // Wait a while.
                //
                for(ulLoop = 0; ulLoop < 15; ulLoop--)
                {
                    //
                    // Toggle both LEDs and wait a bit.
                    //
                    ToggleLED(1);
                    ToggleLED(2);
                    SPIN_ABOUT_A_QUARTER_SECOND;
                }
                bFirstTimeThrough = false;
            }

            //
            // Has the channel changed since the last time we updated the
            // display?
            //
            if(pFreq[0].logicalChan != ucLast)
            {
                //
                // Remember the channel we just detected.
                //
                ucLast = pFreq[0].logicalChan;

                //
                // Tell the user which channel we found to be active.
                //
                UpdateStatus("Active channel is %d.", pFreq[0].logicalChan);

                //
                // Set the "LEDs" to mimic the behavior of the MSP430 versions
                // of this application.
                //
                switch(pFreq[0].logicalChan)
                {
                    case 0:
                    {
                        /* GREEN OFF */
                        /* RED   OFF */
                        SetLED(1, false);
                        SetLED(2, false);
                        break;
                    }

                    case 1:
                    {
                        /* GREEN OFF */
                        /* RED   ON */
                        SetLED(1, false);
                        SetLED(2, true);
                        break;
                    }

                    case 2:
                    {
                        /* GREEN ON */
                        /* RED   OFF */
                        SetLED(1, true);
                        SetLED(2, false);
                        break;
                    }

                    case 3:
                    {
                        /* GREEN ON */
                        /* RED   ON */
                        SetLED(1, true);
                        SetLED(2, true);
                        break;
                    }

                    case 4:
                    {
                        /* blink them both... */
                        SetLED(1, false);
                        SetLED(2, false);
                        SPIN_ABOUT_A_QUARTER_SECOND;
                        SetLED(1, true);
                        SetLED(2, true);
                        SPIN_ABOUT_A_QUARTER_SECOND;
                        SetLED(1, false);
                        SetLED(2, false);
                    }
                }
            }
        }
    }
}
// *************************************************************************************************
// @fn          simpliciti_link
// @brief       Init hardware and try to link to access point.
// @param       none
// @return      unsigned char		0 = Could not link, timeout or external cancel.
//									1 = Linked successful.
// *************************************************************************************************
unsigned char simpliciti_link(void)
{
    uint8_t timeout;
    addr_t lAddr;
    uint8_t i;
    uint8_t pwr;

    // Configure timer
    BSP_InitBoard();

    // Change network address to value set in calling function
    for (i = 0; i < NET_ADDR_SIZE; i++)
    {
        lAddr.addr[i] = simpliciti_ed_address[i];
    }
    SMPL_Ioctl(IOCTL_OBJ_ADDR, IOCTL_ACT_SET, &lAddr);

    // Set flag
    simpliciti_flag = SIMPLICITI_STATUS_LINKING;

    /* Keep trying to join (a side effect of successful initialization) until
     * successful. Toggle LEDS to indicate that joining has not occurred.
     */
    timeout = 0;
    while (SMPL_SUCCESS != SMPL_Init(0))
    {
        NWK_DELAY(1000);

        // Service watchdog
        WDTCTL = WDTPW + WDTIS__512K + WDTSSEL__ACLK + WDTCNTCL;

        // Stop connecting after defined numbers of seconds (15)
        if (timeout++ > TIMEOUT)
        {
            // Clean up SimpliciTI stack to enable restarting
            sInit_done = 0;
            simpliciti_flag = SIMPLICITI_STATUS_ERROR;
            return (0);
        }

        // Break when flag bit SIMPLICITI_TRIGGER_STOP is set
        if (getFlag(simpliciti_flag, SIMPLICITI_TRIGGER_STOP))
        {
            // Clean up SimpliciTI stack to enable restarting
            sInit_done = 0;
            return (0);
        }
    }

    // Set output power to +3.3dmB
    pwr = IOCTL_LEVEL_2;
    SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SETPWR, &pwr);

    /* Unconditional link to AP which is listening due to successful join. */
    timeout = 0;
    while (SMPL_SUCCESS != SMPL_Link(&sLinkID1))
    {
        NWK_DELAY(1000);

        // Service watchdog
        WDTCTL = WDTPW + WDTIS__512K + WDTSSEL__ACLK + WDTCNTCL;

        // Stop linking after timeout
        if (timeout++ > TIMEOUT)
        {
            // Clean up SimpliciTI stack to enable restarting
            sInit_done = 0;
            simpliciti_flag = SIMPLICITI_STATUS_ERROR;
            return (0);
        }

        // Exit when flag bit SIMPLICITI_TRIGGER_STOP is set
        if (getFlag(simpliciti_flag, SIMPLICITI_TRIGGER_STOP))
        {
            // Clean up SimpliciTI stack to enable restarting
            sInit_done = 0;
            return (0);
        }
    }
    simpliciti_flag = SIMPLICITI_STATUS_LINKED;

    return (1);
}
Exemple #22
0
void main(void)
{

	sensor.cadc = 'A';
	sensor.iadc = 125;

	trigger(0x5 + (0x6 << 3) + (0x1 << 6) + (0x7 << 9));

  	BSP_Init();                               // init bsp first, then simpliciti

  	BCSCTL3 = LFXT1S_2; 					// aclk = vlo

  	// address check and creation
	Flash_Addr = (char *)0x10F0;              // RF Address = 0x10F0
	if( Flash_Addr[0] == 0xFF &&              // Check if device Address is missing
    	Flash_Addr[1] == 0xFF &&
    	Flash_Addr[2] == 0xFF &&
    	Flash_Addr[3] == 0xFF )
  	{
    	createRandomAddress();                  // Create Random device address at
	}                                         // initial startup if missing
	lAddr.addr[0] = Flash_Addr[0];
	lAddr.addr[1] = Flash_Addr[1];
	lAddr.addr[2] = Flash_Addr[2];
	lAddr.addr[3] = Flash_Addr[3];
	// load address
	SMPL_Ioctl(IOCTL_OBJ_ADDR, IOCTL_ACT_SET, &lAddr);

  	SMPL_Init(NULL);                          // null callback for TX

  	Init_ADC10();
  	Init_TIMER0A0();

  	do {                                       // wait for button
    if (BSP_BUTTON1())
    {
      break;
    }
  } while (1);

  while (SMPL_SUCCESS != SMPL_Link(&linkIDTemp))    // link to Rx
  {
    BSP_TOGGLE_LED1();                      // toggle red for not linked
  }

  	BSP_TURN_OFF_LED1();                      // red off
  	BSP_Delay(2000);                             // for 2 seconds
  	BSP_TURN_ON_LED1();

  	_EINT();                                  // Enable Global Interupts

  while (1)
  {
	  BSP_TOGGLE_LED2();
    // adc with dtc in use
    ADC10CTL0 &= ~ENC;						// turn off adc10
    while (ADC10CTL1 & BUSY);               // wait if adc10 core is active
    ADC10SA = (unsigned int)ADCdata;    	// data buffer start
    ADC10CTL0 |= ENC + ADC10SC;             // sampling and conversion start

    LPM3;

    // insert sensor calculations here
  	// or
    // send raw adc data from P1.0
  	sensor.iadc = ADCdata[0];

	// turn on radio and tx sensor struct
    SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_AWAKE, 0);
    SMPL_Send(linkIDTemp, (uint8_t *)&sensor, sizeof( my_sensors ));

  }
}
void main1 (void)
{
  /* holds length of current message */
  uint8_t len; 
  
  /* the link token */
  linkID_t LinkID = 0;
  
  /* the transmit and receive buffers */
  uint8_t rx[MAX_APP_PAYLOAD], tx[MAX_APP_PAYLOAD];

  /* holds led indicator time out counts */
  uint16_t led_tmr;
  
  int8_t rssi_value;
  

  BSP_Init( );

  SMPL_Init( NULL );
  
  uart_intfc_init( );

  /* turn on the radio so we are always able to receive data asynchronously */
  SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_RXON, NULL );
  
  /* turn on LED. */
  BSP_TURN_ON_LED1( );

#ifdef  LINK_TO
  {
    uint8_t cnt = 0;
    tx_send_wait( "Linking to...\r\n", 15 );
    while (SMPL_SUCCESS != SMPL_Link(&LinkID))
      if( cnt++ == 0 )
      {
        /* blink LED until we link successfully */
        BSP_TOGGLE_LED1( );
      }
  }
#else // ifdef LINK_LISTEN
  tx_send_wait( "Listening for Link...\r\n", 23 );
  while (SMPL_SUCCESS != SMPL_LinkListen(&LinkID))
  {
    /* blink LED until we link successfully */
    BSP_TOGGLE_LED1( );
  }
#endif

  tx_send_wait( "Link Established!\r\nReady...\r\n", 29 );
  
  /* turn off the led */
  BSP_TURN_OFF_LED1( );
  
  main_loop:
    /* Check to see if we received any characters from the other radio
     * and if we have send them out the uart and reset indicator timeout.
     * Prioritize on radio received links as that buffer is the most time
     * critical with respect to the UART buffers.
     */
    if( SMPL_Receive( LinkID, tx, &len ) == SMPL_SUCCESS )
    {
      /* blocking call but should be ok if both ends have same uart buad rate */
      //tx_send_wait( tx, len );
      led_tmr = INDICATOR_TIME_OUT;   /* update activity time out */
      
      
      /*
      int8_t dbm;
      SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_RSSI, (void *)&dbm);
      sSample= dbm;
      tx_send_wait(&char2send, 1 );//input only (unsigned char)
      tx_send_wait("\n", 1 );*/
      
      
      unsigned char Test2;
      //unsigned char Test;
      rssi_value = 0 ;
      
       ioctlRadioSiginfo_t sigInfo1;
       sigInfo1.lid=LinkID; 
       smplStatus_t SMPL_SUCCESS = SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SIGINFO, (void *)&sigInfo1);
    
      //if( SMPL_SUCCESS == SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_RSSI,(void*)&rssi_value) )
      {
        
   
        //transmitData( i, (signed char)sigInfo.sigInfo.rssi, (char*)msg );
        
        //MRFI_Rssi()
        //Test2=RSSI;
        //Test=rssi_value;
        //int8_t i =-127;
        //int i =-127;
        unsigned char rssi_tmp[10];
        int8_t rssi_int = sigInfo1.sigInfo.rssi;
        itoa(rssi_int,rssi_tmp);
        //tx_send_wait("This is Test :", sizeof("This is Test :") );
        //tx_send_wait(&Test2, strlen(&Test2));
        tx_send_wait(&rssi_tmp, strlen(rssi_tmp));
        //tx_send_wait("\r\n", sizeof("\r\n") );
        
        int8_t mk=0x01,bitshift=0;
              
        tx_send_wait("=",1);  
        
        for (bitshift=0;bitshift<8;bitshift++)
        {
          if( (mk<<bitshift) & rssi_int ) 
            tx_send_wait("1",1);
          else
            tx_send_wait("0",1);
          //tx_send_wait("x",1);
          MRFI_DelayMs( 5 );
        }
        tx_send_wait("\r\n", sizeof("\r\n") );
        
        
         
        
        /*        
        tx_send_wait("This is Test2 :", sizeof("This is Test2 :") );
        tx_send_wait( &Test2, sizeof(Test2) );
        tx_send_wait("\n", sizeof("\n") );
        */
      }
      
    }

    FHSS_ACTIVE( if( nwk_pllBackgrounder( false ) != false ) );
    {
      /* check to see if the host has sent any characters and if it has
      * then send them over the radio link and reset indicator timeout.
      */
      len = rx_receive( rx, MAX_APP_PAYLOAD );
      if( len != 0 )
      {
        while( SMPL_Send( LinkID, rx, len ) != SMPL_SUCCESS )
          ;
        /*
        if( SMPL_SUCCESS == SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_RSSI,&rssi_value ) ){
          SMPL_Send( LinkID, &rssi_value, sizeof(rssi_value) );
        }*/
        led_tmr = INDICATOR_TIME_OUT;   /* update activity time out */
        
        /* By forcing a minimum delay between transmissions we guarantee
        * a window for receiving packets.  This is necessary as the radio
        * link is half duplex while the UART is full duplex.  Without this
        * delay mechanism, packets can get lost as both ends may attempt to
        * transmit at the same time which the CCA algorithm fails to handle.
        */
        MRFI_DelayMs( 5 );
      }
    }
    
    /* manage led indicator */
    if( led_tmr != 0 )
    {
      led_tmr--;
      BSP_TURN_ON_LED1( );
    }
    else
      BSP_TURN_OFF_LED1( );

    
    goto main_loop; /* do it again and again and again and ... */
    

}
//*****************************************************************************
//
// Main application entry function.
//
//*****************************************************************************
int
main(void)
{
    tBoolean bRetcode;

    //
    // Set the system clock to run at 50MHz from the PLL
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // NB: We don't call PinoutSet() in this testcase since the EM header
    // expansion board doesn't currently have an I2C ID EEPROM.  If we did
    // call PinoutSet() this would configure all the EPI pins for SDRAM and
    // we don't want to do this.
    //
    g_eDaughterType = DAUGHTER_NONE;

    //
    // Enable peripherals required to drive the LCD.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);

    //
    // Configure SysTick for a 10Hz interrupt.
    //
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND);
    ROM_SysTickEnable();
    ROM_SysTickIntEnable();

    //
    // Initialize the display driver.
    //
    Kitronix320x240x16_SSD2119Init();

    //
    // Initialize the touch screen driver.
    //
    TouchScreenInit();

    //
    // Set the touch screen event handler.
    //
    TouchScreenCallbackSet(WidgetPointerMessage);

    //
    // Add the compile-time defined widgets to the widget tree.
    //
    WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sHeading);

    //
    // Initialize the status string.
    //
    UpdateStatus(true, "Joining network...");

    //
    // Paint the widget tree to make sure they all appear on the display.
    //
    WidgetPaint(WIDGET_ROOT);

    //
    // Initialize the SimpliciTI BSP.
    //
    BSP_Init();

    //
    // Set the SimpliciTI device address using the current Ethernet MAC address
    // to ensure something like uniqueness.
    //
    bRetcode = SetSimpliciTIAddress();

    //
    // Did we have a problem with the address?
    //
    if(!bRetcode)
    {
        //
        // Yes - make sure the display is updated then hang the app.
        //
        WidgetMessageQueueProcess();
        while(1)
        {
            //
            // MAC address is not set so hang the app.
            //
        }
    }

    //
    // Turn both "LEDs" off.
    //
    SetLED(1, false);
    SetLED(2, false);

    //
    // Keep trying to join (a side effect of successful initialization) until
    // successful.  Toggle LEDS to indicate that joining has not occurred.
    //
    while(SMPL_SUCCESS != SMPL_Init(0))
    {
      ToggleLED(1);
      ToggleLED(2);
      SPIN_ABOUT_A_SECOND;
    }

    //
    // We have joined the network so turn on both "LEDs" to indicate this.
    //
    SetLED(1, true);
    SetLED(2, true);
    UpdateStatus(true, "Joined network");

    //
    // Link to the access point which is now listening for us and continue
    // processing.  This function does not return.
    //
    LinkTo();
}