/********************************************************************************************** Copyright 2004-2007 Texas Instruments Incorporated. All rights reserved. IMPORTANT: Your use of this Software is limited to those specific rights granted under the terms of a software license agreement between the user who downloaded the software, his/her employer (which must be your employer) and Texas Instruments Incorporated (the "License"). You may not use this Software unless you agree to abide by the terms of the License. The License limits your use, and you acknowledge, that the Software may not be modified, copied or distributed unless embedded on a Texas Instruments microcontroller or used solely and exclusively in conjunction with a Texas Instruments radio frequency transceiver, which is integrated into your product. Other than for the foregoing purpose, you may not use, reproduce, copy, prepare derivative works of, modify, distribute, perform, display or sell this Software and/or its documentation for any purpose. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS. Should you have any questions regarding your right to use this Software, contact Texas Instruments Incorporated at www.TI.com. **************************************************************************************************/ // ************************************************************************************************* // Include section #include #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 "simpliciti.h" #include "project.h" // ************************************************************************************************* // Defines section #define BIT0 (0x0001) #define BIT1 (0x0002) #define BIT2 (0x0004) #define BIT3 (0x0008) #define BIT4 (0x0010) #define BIT5 (0x0020) #define BIT6 (0x0040) #define BIT7 (0x0080) #define BIT8 (0x0100) #define BIT9 (0x0200) #define BITA (0x0400) #define BITB (0x0800) #define BITC (0x1000) #define BITD (0x2000) #define BITE (0x4000) #define BITF (0x8000) // ************************************************************************************************* // Prototypes section /* callback handler */ uint8_t sCB(linkID_t); // ************************************************************************************************* // Extern section extern uint8_t sInit_done; // ************************************************************************************************* // Global Variable section /* reserve space for the maximum possible peer Link IDs */ void toggleLED(uint8_t); static uint8_t sRxTid = 0; static linkID_t sLinkID2 = 0; static volatile uint8_t sSemaphore = 0; /* Rx callback handler */ static uint8_t sRxCallback(linkID_t); /* work loop semaphores */ static volatile uint8_t sPeerFrameSem = 0; static volatile uint8_t sJoinSem = 0; volatile unsigned char simpliciti_flag; unsigned char simpliciti_data[SIMPLICITI_MAX_PAYLOAD_LENGTH]; unsigned char ed_data[SIMPLICITI_MAX_PAYLOAD_LENGTH]; // AP main routine void simpliciti_main(void) { uint8_t pwr; // Init variables simpliciti_flag = SIMPLICITI_STATUS_LINKING; // Initialize Timer A1 BSP_Init(); // 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) { uint8_t msg[2], tid = 0; toggleLED(1); /* listen for link forever... */ while (1) { /* SMPL_LinkListen handles FHSS implicittly */ if (SMPL_SUCCESS == SMPL_LinkListen(&sLinkID2)) { break; } /* Implement fail-to-link policy here. otherwise, listen again. */ } /* turn on LED1 on the peer in response to receiving a frame. */ *msg = 0x01; /* turn on RX. default is RX off. */ SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_RXON, 0); while (1) { //FHSS_ACTIVE( nwk_pllBackgrounder(FALSE) ); /* manage FHSS */ /* Wait for a frame to be received. The Rx handler, which is running in * ISR thread, will post to this semaphore allowing the application to * send the reply message in the user thread. */ if (sSemaphore) { *(msg+1) = ++tid; SMPL_Send(sLinkID2, msg, 2); /* Reset semaphore. This is not properly protected and there is a race * here. In theory we could miss a message. Good enough for a demo, though. */ sSemaphore = 0; } } } } void toggleLED(uint8_t which) { if (1 == which) { BSP_TOGGLE_LED1(); } else if (2 == which) { BSP_TOGGLE_LED2(); } return; } /* handle received messages */ static uint8_t sRxCallback(linkID_t port) { uint8_t msg[2], len, tid; /* is the callback for the link ID we want to handle? */ if (port == sLinkID2) { /* yes. go get the frame. we know this call will succeed. */ if ((SMPL_SUCCESS == SMPL_Receive(sLinkID2, msg, &len)) && len) { /* Check the application sequence number to detect * late or missing frames... */ tid = *(msg+1); if (tid) { if (tid > sRxTid) { /* we're good. toggle LED */ toggleLED(*msg); sRxTid = tid; } } else { /* wrap case... */ if (sRxTid) { /* we're good. toggle LED */ toggleLED(*msg); sRxTid = tid; } } /* Post to the semaphore to let application know so it sends * the reply */ sSemaphore = 1; /* drop frame. we're done with it. */ return 1; } } /* keep frame for later handling */ return 0; } /* Runs in ISR context. Reading the frame should be done in the */ /* application thread not in the ISR thread. */ uint8_t sCB(linkID_t lid) { if (lid) { sPeerFrameSem++; } else { sJoinSem++; } /* leave frame to be read by application. */ return 0; }