00001 /* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved. 00002 * 00003 * The information contained herein is confidential property of Nordic 00004 * Semiconductor ASA.Terms and conditions of usage are described in detail 00005 * in NORDIC SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 00006 * 00007 * Licensees are granted free, non-transferable use of the information. NO 00008 * WARRENTY of ANY KIND is provided. This heading must NOT be removed from 00009 * the file. 00010 * 00011 * $LastChangedRevision: 133 $ 00012 */ 00013 00033 //lint -e534 00034 //lint -e746 00035 00036 #include "gzll_mcu.h" 00037 #include "gzll.h" 00038 #include "hal_clk.h" 00039 00040 void main(void) 00041 { 00042 uint8_t poll_cnt = 0; 00043 uint8_t payload[GZLL_MAX_PAYLOAD_LENGTH]; 00044 00045 mcu_init(); 00046 gzll_init(); 00047 00048 // Always run on 16MHz crystal oscillator 00049 hal_clk_set_16m_source(HAL_CLK_XOSC16M); 00050 00051 //wait for external crystal to activate 00052 while(hal_clk_get_16m_source() != HAL_CLK_XOSC16M){} 00053 // Use Gazell Link Layer synchronous device mode 2 for minimizing 00054 // transmit attempts 00055 gzll_set_param(GZLL_PARAM_DEVICE_MODE, 2); 00056 00057 EA = 1; 00058 00059 for(;;) 00060 { 00061 // If gazell link layer idle 00062 if(gzll_get_state() == GZLL_IDLE) 00063 { 00064 // Send a packet for every 20 wakeup, equals every ~20 ms 00065 if(poll_cnt > 20) 00066 { 00067 // Read P0 and put in payload[0] 00068 payload[0] = ~P0; 00069 // Transmits 1 byte ( payload[0] ) to pipe 0 address 00070 gzll_tx_data(&payload[0], 1, 0); 00071 poll_cnt = 0; 00072 } 00073 } 00074 00075 EA = 0; 00076 // If radio not active, enter "register retention" 00077 if(!gzll_radio_active()) 00078 { 00079 PWRDWN = 0x04; // Enter "register retention", will wake up on pre-tick 00080 } 00081 PWRDWN = 0x07; // Enter "standby", will wake up on tick 00082 EA = 1; 00083 00084 poll_cnt++; 00085 } 00086 } 00087