C++/c++
Expert: Prince M. Premnath - 2/28/2010
QuestionHi, I was looking through the TI website and some of their code. And I tried to compile it on my compiler, but it gives me errors on both of these programs. The errors are pointed on the include# on top. Here are the two programs. It would be great if you could tell me how to fix these problems.
This is the first program.
//******************************************************************************
// THIS PROGRAM IS PROVIDED "AS IS". TI MAKES NO WARRANTIES OR
// REPRESENTATIONS, EITHER EXPRESS, IMPLIED OR STATUTORY,
// INCLUDING ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR
// COMPLETENESS OF RESPONSES, RESULTS AND LACK OF NEGLIGENCE.
// TI DISCLAIMS ANY WARRANTY OF TITLE, QUIET ENJOYMENT, QUIET
// POSSESSION, AND NON-INFRINGEMENT OF ANY THIRD PARTY
// INTELLECTUAL PROPERTY RIGHTS WITH REGARD TO THE PROGRAM OR
// YOUR USE OF THE PROGRAM.
//
// IN NO EVENT SHALL TI BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
// CONSEQUENTIAL OR INDIRECT DAMAGES, HOWEVER CAUSED, ON ANY
// THEORY OF LIABILITY AND WHETHER OR NOT TI HAS BEEN ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGES, ARISING IN ANY WAY OUT
// OF THIS AGREEMENT, THE PROGRAM, OR YOUR USE OF THE PROGRAM.
// EXCLUDED DAMAGES INCLUDE, BUT ARE NOT LIMITED TO, COST OF
// REMOVAL OR REINSTALLATION, COMPUTER TIME, LABOR COSTS, LOSS
// OF GOODWILL, LOSS OF PROFITS, LOSS OF SAVINGS, OR LOSS OF
// USE OR INTERRUPTION OF BUSINESS. IN NO EVENT WILL TI'S
// AGGREGATE LIABILITY UNDER THIS AGREEMENT OR ARISING OUT OF
// YOUR USE OF THE PROGRAM EXCEED FIVE HUNDRED DOLLARS
// (U.S.$500).
//
// Unless otherwise stated, the Program written and copyrighted
// by Texas Instruments is distributed as "freeware". You may,
// only under TI's copyright in the Program, use and modify the
// Program without any charge or restriction. You may
// distribute to third parties, provided that you transfer a
// copy of this license to the third party and the third party
// agrees to these terms by its first use of the Program. You
// must reproduce the copyright notice and any other legend of
// ownership on each copy or partial copy, of the Program.
//
// You acknowledge and agree that the Program contains
// copyrighted material, trade secrets and other TI proprietary
// information and is protected by copyright laws,
// international copyright treaties, and trade secret laws, as
// well as other intellectual property laws. To protect TI's
// rights in the Program, you agree not to decompile, reverse
// engineer, disassemble or otherwise translate any object code
// versions of the Program to a human-readable form. You agree
// that in no event will you alter, remove or destroy any
// copyright notice included in the Program. TI reserves all
// rights not specifically granted under this license. Except
// as specifically provided herein, nothing in this agreement
// shall be construed as conferring by implication, estoppel,
// or otherwise, upon you, any license or other right under any
// TI patents, copyrights or trade secrets.
//
// You may not use the Program in non-TI devices.
//
//******************************************************************************
// eZ430-RF2500 Temperature Sensor End Device
//
// Description: This is the End Device software for the eZ430-2500RF
// Temperature Sensing demo
//
//
// L. Westlund
// Version 1.02
// Texas Instruments, Inc
// November 2007
// Built with IAR Embedded Workbench Version: 4.09A
//******************************************************************************
//Change Log:
//******************************************************************************
//Version: 1.03
//Comments: Added support for SimpliciTI 1.1.0
// Added support for Code Composer Studio
// Added security (Enabled with -DSMPL_SECURE in smpl_nwk_config.dat)
// Added acknowledgement (Enabled with -DAPP_AUTO_ACK in smpl_nwk_config.dat)
// Based the modifications on the AP_as_Data_Hub example code
//Version: 1.02
//Comments: Changed Port toggling to abstract method
// Fixed comment typos
//Version: 1.01
//Comments: Added support for SimpliciTI 1.0.3
// Added Flash storage/check of Random address
// Moved LED toggle to HAL
//Version: 1.00
//Comments: Initial Release Version
//******************************************************************************
#define I_WANT_TO_CHANGE_DEFAULT_ROM_DEVICE_ADDRESS_PSEUDO_CODE
#include "bsp.h"
#include "mrfi.h"
#include "nwk_types.h"
#include "nwk_api.h"
#include "bsp_leds.h"
#include "bsp_buttons.h"
#include "vlo_rand.h"
#ifndef APP_AUTO_ACK
#error ERROR: Must define the macro APP_AUTO_ACK for this application.
#endif
void toggleLED(uint8_t);
static void linkTo(void);
static linkID_t sLinkID1 = 0;
#define SPIN_ABOUT_A_SECOND NWK_DELAY(1000)
#define SPIN_ABOUT_A_QUARTER_SECOND NWK_DELAY(250)
/* How many times to try a Tx and miss an acknowledge before doing a scan */
#define MISSES_IN_A_ROW 2
void createRandomAddress(void);
volatile int * tempOffset = (int *)0x10F4; // Temperature offset set at production
char * Flash_Addr = (char *)0x10F0; // Initialize radio address location
__interrupt void ADC10_ISR(void);
__interrupt void Timer_A (void);
/* work loop semaphores */
static volatile uint8_t sSelfMeasureSem = 0;
void main (void)
{
addr_t lAddr;
BSP_Init();
if(Flash_Addr[0] == 0xFF && Flash_Addr[1] == 0xFF &&
Flash_Addr[2] == 0xFF && Flash_Addr[3] == 0xFF )
{
createRandomAddress(); // set Random device address at initial startup
}
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_Ioctl(IOCTL_OBJ_ADDR, IOCTL_ACT_SET, &lAddr);
/* 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);
}
BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO
TACCTL0 = CCIE; // TACCR0 interrupt enabled
TACCR0 = 12000; // ~ 1 sec
TACTL = TASSEL_1 + MC_1; // ACLK, upmode
/* Unconditional link to AP which is listening due to successful join. */
linkTo();
while (1) ;
}
static void linkTo()
{
uint8_t msg[3];
uint8_t misses, done;
/* Keep trying to link... */
while (SMPL_SUCCESS != SMPL_Link(&sLinkID1))
{
toggleLED(1);
toggleLED(2);
SPIN_ABOUT_A_SECOND;
}
/* Turn off LEDs. */
if (BSP_LED2_IS_ON())
{
toggleLED(2);
}
if (BSP_LED1_IS_ON())
{
toggleLED(1);
}
SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SLEEP, 0);
while (1)
{
__bis_SR_register(LPM3_bits+GIE); // LPM3 with interrupts enabled
if (sSelfMeasureSem) {
volatile long temp;
int degC, volt;
int results[2];
uint8_t noAck;
smplStatus_t rc;
/* get radio ready...awakens in idle state */
SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_AWAKE, 0);
ADC10CTL1 = INCH_10 + ADC10DIV_4; // Temp Sensor ADC10CLK/5
ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE + ADC10SR;
for( degC = 240; degC > 0; degC-- ); // delay to allow reference to settle
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled
results[0] = ADC10MEM;
ADC10CTL0 &= ~ENC;
ADC10CTL1 = INCH_11; // AVcc/2
ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE + REF2_5V;
for( degC = 240; degC > 0; degC-- ); // delay to allow reference to settle
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled
results[1] = ADC10MEM;
ADC10CTL0 &= ~ENC;
ADC10CTL0 &= ~(REFON + ADC10ON); // turn off A/D to save power
// oC = ((A10/1024)*1500mV)-986mV)*1/3.55mV = A10*423/1024 - 278
// the temperature is transmitted as an integer where 32.1 = 321
// hence 4230 instead of 423
temp = results[0];
degC = ((temp - 673) * 4230) / 1024;
if( (*tempOffset) != 0xFFFF )
{
degC += (*tempOffset);
}
/* message format, UB = upper Byte, LB = lower Byte
-------------------------------
|degC LB | degC UB | volt LB |
-------------------------------
0 1 2
*/
temp = results[1];
volt = (temp*25)/512;
msg[0] = degC&0xFF;
msg[1] = (degC>>8)&0xFF;
msg[2] = volt;
done = 0;
while (!done)
{
noAck = 0;
/* Try sending message MISSES_IN_A_ROW times looking for ack */
for (misses=0; misses < MISSES_IN_A_ROW; ++misses)
{
if (SMPL_SUCCESS == (rc=SMPL_SendOpt(sLinkID1, msg, sizeof(msg), SMPL_TXOPTION_ACKREQ)))
{
/* Message acked. We're done. Toggle LED 1 to indicate ack received. */
toggleLED(1); // Toggle On LED1
__delay_cycles(2000);
toggleLED(1);
break;
}
if (SMPL_NO_ACK == rc)
{
/* Count ack failures. Could also fail becuase of CCA and
* we don't want to scan in this case.
*/
noAck++;
}
}
if (MISSES_IN_A_ROW == noAck)
{
/* Message not acked. Toggle LED 2. */
toggleLED(2); // Turn On LED2
__delay_cycles(2000);
toggleLED(2);
#ifdef FREQUENCY_AGILITY
/* Assume we're on the wrong channel so look for channel by
* using the Ping to initiate a scan when it gets no reply. With
* a successful ping try sending the message again. Otherwise,
* for any error we get we will wait until the next button
* press to try again.
*/
if (SMPL_SUCCESS != SMPL_Ping(sLinkID1))
{
done = 1;
}
#else
done = 1;
#endif /* FREQUENCY_AGILITY */
}
else
{
/* Got the ack or we don't care. We're done. */
done = 1;
}
}
/* radio back to sleep */
SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SLEEP, 0);
}
}
}
void toggleLED(uint8_t which)
{
if (1 == which)
{
BSP_TOGGLE_LED1();
}
else if (2 == which)
{
BSP_TOGGLE_LED2();
}
return;
}
void createRandomAddress()
{
unsigned int rand, rand2;
do
{
rand = TI_getRandomIntegerFromVLO(); // first byte can not be 0x00 of 0xFF
}
while( (rand & 0xFF00)==0xFF00 || (rand & 0xFF00)==0x0000 );
rand2 = TI_getRandomIntegerFromVLO();
BCSCTL1 = CALBC1_1MHZ; // Set DCO to 1MHz
DCOCTL = CALDCO_1MHZ;
FCTL2 = FWKEY + FSSEL0 + FN1; // MCLK/3 for Flash Timing Generator
FCTL3 = FWKEY + LOCKA; // Clear LOCK & LOCKA bits
FCTL1 = FWKEY + WRT; // Set WRT bit for write operation
Flash_Addr[0]=(rand>>8) & 0xFF;
Flash_Addr[1]=rand & 0xFF;
Flash_Addr[2]=(rand2>>8) & 0xFF;
Flash_Addr[3]=rand2 & 0xFF;
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY + LOCKA + LOCK; // Set LOCK & LOCKA bit
}
/*------------------------------------------------------------------------------
* ADC10 interrupt service routine
------------------------------------------------------------------------------*/
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
}
/*------------------------------------------------------------------------------
* Timer A0 interrupt service routine
------------------------------------------------------------------------------*/
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
sSelfMeasureSem = 1;
__bic_SR_register_on_exit(LPM3_bits); // Clear LPM3 bit from 0(SR)
}
Here is the second program:
//******************************************************************************
// THIS PROGRAM IS PROVIDED "AS IS". TI MAKES NO WARRANTIES OR
// REPRESENTATIONS, EITHER EXPRESS, IMPLIED OR STATUTORY,
// INCLUDING ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR
// COMPLETENESS OF RESPONSES, RESULTS AND LACK OF NEGLIGENCE.
// TI DISCLAIMS ANY WARRANTY OF TITLE, QUIET ENJOYMENT, QUIET
// POSSESSION, AND NON-INFRINGEMENT OF ANY THIRD PARTY
// INTELLECTUAL PROPERTY RIGHTS WITH REGARD TO THE PROGRAM OR
// YOUR USE OF THE PROGRAM.
//
// IN NO EVENT SHALL TI BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
// CONSEQUENTIAL OR INDIRECT DAMAGES, HOWEVER CAUSED, ON ANY
// THEORY OF LIABILITY AND WHETHER OR NOT TI HAS BEEN ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGES, ARISING IN ANY WAY OUT
// OF THIS AGREEMENT, THE PROGRAM, OR YOUR USE OF THE PROGRAM.
// EXCLUDED DAMAGES INCLUDE, BUT ARE NOT LIMITED TO, COST OF
// REMOVAL OR REINSTALLATION, COMPUTER TIME, LABOR COSTS, LOSS
// OF GOODWILL, LOSS OF PROFITS, LOSS OF SAVINGS, OR LOSS OF
// USE OR INTERRUPTION OF BUSINESS. IN NO EVENT WILL TI'S
// AGGREGATE LIABILITY UNDER THIS AGREEMENT OR ARISING OUT OF
// YOUR USE OF THE PROGRAM EXCEED FIVE HUNDRED DOLLARS
// (U.S.$500).
//
// Unless otherwise stated, the Program written and copyrighted
// by Texas Instruments is distributed as "freeware". You may,
// only under TI's copyright in the Program, use and modify the
// Program without any charge or restriction. You may
// distribute to third parties, provided that you transfer a
// copy of this license to the third party and the third party
// agrees to these terms by its first use of the Program. You
// must reproduce the copyright notice and any other legend of
// ownership on each copy or partial copy, of the Program.
//
// You acknowledge and agree that the Program contains
// copyrighted material, trade secrets and other TI proprietary
// information and is protected by copyright laws,
// international copyright treaties, and trade secret laws, as
// well as other intellectual property laws. To protect TI's
// rights in the Program, you agree not to decompile, reverse
// engineer, disassemble or otherwise translate any object code
// versions of the Program to a human-readable form. You agree
// that in no event will you alter, remove or destroy any
// copyright notice included in the Program. TI reserves all
// rights not specifically granted under this license. Except
// as specifically provided herein, nothing in this agreement
// shall be construed as conferring by implication, estoppel,
// or otherwise, upon you, any license or other right under any
// TI patents, copyrights or trade secrets.
//
// You may not use the Program in non-TI devices.
//
//******************************************************************************
// eZ430-RF2500 Temperature Sensor Access Point
//
// Description: This is the Access Point software for the eZ430-2500RF
// Temperature Sensing demo
//
//
// L. Westlund
// Version 1.03
// Texas Instruments, Inc
// August 2009
// Built with IAR Embedded Workbench Version: 4.20
//******************************************************************************
//Change Log:
//******************************************************************************
//Version: 1.03
//Comments: Added support for SimpliciTI 1.1.0
// Added support for Code Composer Studio
// Added security (Enabled with -DSMPL_SECURE in smpl_nwk_config.dat)
// Added acknowledgement (Enabled with -DAPP_AUTO_ACK in smpl_nwk_config.dat)
// Based the modifications on the AP_as_Data_Hub example code
//Version: 1.02
//Comments: Changed Port toggling to abstract method
// Removed ToggleLED
// Fixed comment typos/errors
// Changed startup string to 1.02
//Version: 1.01
//Comments: Added support for SimpliciTI 1.0.3
// Changed RSSI read method
// Added 3 digit temperature output for 100+F
// Changed startup string to 1.01
//Version: 1.00
//Comments: Initial Release Version
//******************************************************************************
#include <string.h>
#include "bsp.h"
#include "mrfi.h"
#include "bsp_leds.h"
#include "bsp_buttons.h"
#include "nwk_types.h"
#include "nwk_api.h"
#include "nwk_frame.h"
#include "nwk.h"
#include "virtual_com_cmds.h"
#include "app_remap_led.h"
#ifndef APP_AUTO_ACK
#error ERROR: Must define the macro APP_AUTO_ACK for this application.
#endif
void toggleLED(uint8_t);
/**************************** COMMENTS ON ASYNC LISTEN APPLICATION ***********************
Summary:
This AP build includes implementation of an unknown number of end device peers in
addition to AP functionality. In this scenario all End Devices establish a link to
the AP and only to the AP. The AP acts as a data hub. All End Device peers are on
the AP and not on other distinct ED platforms.
There is still a limit to the number of peers supported on the AP that is defined
by the macro NUM_CONNECTIONS. The AP will support NUM_CONNECTIONS or fewer peers
but the exact number does not need to be known at build time.
In this special but common scenario SimpliciTI restricts each End Device object to a
single connection to the AP. If multiple logical connections are required these must
be accommodated by supporting contexts in the application payload itself.
Solution overview:
When a new peer connection is required the AP main loop must be notified. In essence
the main loop polls a semaphore to know whether to begin listening for a peer Link
request from a new End Device. There are two solutions: automatic notification and
external notification. The only difference between the automatic notification
solution and the external notification solution is how the listen semaphore is
set. In the external notification solution the sempahore is set by the user when the
AP is stimulated for example by a button press or a commend over a serial link. In the
automatic scheme the notification is accomplished as a side effect of a new End Device
joining.
The Rx callback must be implemented. When the callback is invoked with a non-zero
Link ID the handler could set a semaphore that alerts the main work loop that a
SMPL_Receive() can be executed successfully on that Link ID.
If the callback conveys an argument (LinkID) of 0 then a new device has joined the
network. A SMPL_LinkListen() should be executed.
Whether the joining device supports ED objects is indirectly inferred on the joining
device from the setting of the NUM_CONNECTIONS macro. The value of this macro should
be non-zero only if ED objects exist on the device. This macro is always non-zero
for ED-only devices. But Range Extenders may or may not support ED objects. The macro
should be be set to 0 for REs that do not also support ED objects. This prevents the
Access Point from reserving resources for a joinng device that does not support any
End Device Objects and it prevents the AP from executing a SMPL_LinkListen(). The
Access Point will not ever see a Link frame if the joining device does not support
any connections.
Each joining device must execute a SMPL_Link() after receiving the join reply from the
Access Point. The Access Point will be listening.
*************************** END COMMENTS ON ASYNC LISTEN APPLICATION ********************/
/************ THIS SOURCE FILE REPRESENTS THE AUTOMATIC NOTIFICATION SOLUTION ************/
/* reserve space for the maximum possible peer Link IDs */
static linkID_t sLID[NUM_CONNECTIONS] = {0};
static uint8_t sNumCurrentPeers = 0;
/* callback handler */
static uint8_t sCB(linkID_t);
/* received message handler */
static void processMessage(linkID_t, uint8_t *, uint8_t);
/* Frequency Agility helper functions */
static void checkChangeChannel(void);
static void changeChannel(void);
/* work loop semaphores */
static volatile uint8_t sPeerFrameSem = 0;
static volatile uint8_t sJoinSem = 0;
static volatile uint8_t sSelfMeasureSem = 0;
#ifdef FREQUENCY_AGILITY
/* ************** BEGIN interference detection support */
#define INTERFERNCE_THRESHOLD_DBM (-70)
#define SSIZE 25
#define IN_A_ROW 3
static int8_t sSample[SSIZE];
static uint8_t sChannel = 0;
#endif /* FREQUENCY_AGILITY */
/* blink LEDs when channel changes... */
static volatile uint8_t sBlinky = 0;
//data for terminal output
const char splash[] = {"\r\n--------------------------------------------------\r\n ****\r\n **** eZ430-RF2500\r\n ******o**** Temperature Sensor Network\r\n********_///_**** Copyright 2009\r\n ******/_//_/***** Texas Instruments Incorporated\r\n ** ***(__/***** All rights reserved.\r\n ********* SimpliciTI1.1.0\r\n *****\r\n ***\r\n--------------------------------------------------\r\n"};
volatile int * tempOffset = (int *)0x10F4;
__interrupt void ADC10_ISR(void);
__interrupt void Timer_A (void);
/* ************** END interference detection support */
#define SPIN_ABOUT_A_QUARTER_SECOND NWK_DELAY(250)
using namespace std;
void main (void)
{
bspIState_t intState;
memset(sSample, 0x0, sizeof(sSample));
BSP_Init();
BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO
TACCTL0 = CCIE; // TACCR0 interrupt enabled
TACCR0 = 12000; // ~1 second
TACTL = TASSEL_1 + MC_1; // ACLK, upmode
COM_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);
/* 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)
{
/* 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)
{
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);
}
// if it is time to measure our own temperature...
if(sSelfMeasureSem)
{
char msg [6];
char addr[] = {"HUB0"};
char rssi[] = {"000"};
int degC, volt;
volatile long temp;
int results[2];
ADC10CTL1 = INCH_10 + ADC10DIV_4; // Temp Sensor ADC10CLK/5
ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE + ADC10SR;
for( degC = 240; degC > 0; degC-- ); // delay to allow reference to settle
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled
results[0] = ADC10MEM;
ADC10CTL0 &= ~ENC;
ADC10CTL1 = INCH_11; // AVcc/2
ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE + REF2_5V;
for( degC = 240; degC > 0; degC-- ); // delay to allow reference to settle
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled
results[1] = ADC10MEM;
ADC10CTL0 &= ~ENC;
ADC10CTL0 &= ~(REFON + ADC10ON); // turn off A/D to save power
// oC = ((A10/1024)*1500mV)-986mV)*1/3.55mV = A10*423/1024 - 278
// the temperature is transmitted as an integer where 32.1 = 321
// hence 4230 instead of 423
temp = results[0];
degC = (((temp - 673) * 4230) / 1024);
if( (*tempOffset) != 0xFFFF )
{
degC += (*tempOffset);
}
temp = results[1];
volt = (temp*25)/512;
msg[0] = degC&0xFF;
msg[1] = (degC>>8)&0xFF;
msg[2] = volt;
transmitDataString(1, addr, rssi, msg );
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[MAX_APP_PAYLOAD], len, i;
/* process all frames waiting */
for (i=0; i<sNumCurrentPeers; ++i)
{
if (SMPL_SUCCESS == SMPL_Receive(sLID[i], msg, &len))
{
ioctlRadioSiginfo_t sigInfo;
processMessage(sLID[i], msg, len);
sigInfo.lid = sLID[i];
SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SIGINFO, (void *)&sigInfo);
transmitData( i, sigInfo.sigInfo.rssi, (char*)msg );
BSP_TOGGLE_LED2();
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);
}
}
void toggleLED(uint8_t which)
{
if (1 == which)
{
BSP_TOGGLE_LED1();
}
else if (2 == which)
{
BSP_TOGGLE_LED2();
}
return;
}
/* Runs in ISR context. Reading the frame should be done in the */
/* application thread not in the ISR thread. */
static uint8_t sCB(linkID_t lid)
{
if (lid)
{
sPeerFrameSem++;
sBlinky = 0;
}
else
{
sJoinSem++;
}
/* leave frame to be read by application. */
return 0;
}
static void processMessage(linkID_t lid, uint8_t *msg, uint8_t len)
{
/* do something useful */
if (len)
{
toggleLED(*msg);
}
return;
}
static void changeChannel(void)
{
#ifdef FREQUENCY_AGILITY
freqEntry_t freq;
if (++sChannel >= NWK_FREQ_TBL_SIZE)
{
sChannel = 0;
}
freq.logicalChan = sChannel;
SMPL_Ioctl(IOCTL_OBJ_FREQ, IOCTL_ACT_SET, &freq);
BSP_TURN_OFF_LED1();
BSP_TURN_OFF_LED2();
sBlinky = 1;
#endif
return;
}
/* implement auto-channel-change policy here... */
static void checkChangeChannel(void)
{
#ifdef FREQUENCY_AGILITY
int8_t dbm, inARow = 0;
uint8_t i;
memset(sSample, 0x0, SSIZE);
for (i=0; i<SSIZE; ++i)
{
/* quit if we need to service an app frame */
if (sPeerFrameSem || sJoinSem)
{
return;
}
NWK_DELAY(1);
SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_RSSI, (void *)&dbm);
sSample[i] = dbm;
if (dbm > INTERFERNCE_THRESHOLD_DBM)
{
if (++inARow == IN_A_ROW)
{
changeChannel();
break;
}
}
else
{
inARow = 0;
}
}
#endif
return;
}
/*------------------------------------------------------------------------------
* ADC10 interrupt service routine
------------------------------------------------------------------------------*/
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
}
/*------------------------------------------------------------------------------
* Timer A0 interrupt service routine
------------------------------------------------------------------------------*/
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
sSelfMeasureSem = 1;
}
AnswerHi Dear Ari!
If you get errors regarding the include files , ensure that the files requires to be included in your programme do really exists ?
#include "bsp.h"
#include "mrfi.h"
#include "nwk_types.h"
#include "nwk_api.h"
#include "bsp_leds.h"
#include "bsp_buttons.h"
#include "vlo_rand.h"
if so then ensure that the files what mentioned above all are located in the proper location where the compiler makes a search for include files ?
Will be good if you mention your compiler name and version as well .
Ensure the mentioned things and get back to me if the issue still persists
Thanks and Regards
Prince M. Premnath