void sleepRadio(){ //printf("Sleeping"); RFM69_setMode(RFM69_MODE_SLEEP); init_sleep(); sleepMicro(TX_GAP * 100); //printf("Awake"); }
void hw_init() { uint8_t c; P0DIR = 0xf0; // P0.0 P0.1 P0.2 are the LEDs and they are outputs // P0.3 is the UART TX - output // P0.5 is the push button - input // P0.6 is the MPU interrupt pin - input P0CON = 0x55; // turn on the pullup for the recenter button // cycle the LEDs LED_RED = 0; LED_YELLOW = 0; LED_GREEN = 0; for (c = 0; c < 3; ++c) { LED_RED = 1; delay_ms(40); LED_RED = 0; LED_YELLOW = 1; delay_ms(40); LED_YELLOW = 0; LED_GREEN = 1; delay_ms(40); LED_GREEN = 0; LED_YELLOW = 1; delay_ms(40); LED_YELLOW = 0; } dbgInit(); i2c_init(); dputs("init started"); LED_YELLOW = 1; mpu_init(false); dbgFlush(); rf_head_init(); // init the radio init_sleep(); // we need to wake up from RFIRQ LED_YELLOW = 0; dputs("init OK"); }
int main(void) { #ifdef ZOMBIE_MODE LPC_SYSCON->BODCTRL = 0x11; //Should be set to Level 1 (Assertion 2.3V, De-assertion 2.4V) reset #endif #if defined(GATEWAY) || defined(DEBUG) // Initialise the UART0 block for printf output uart0Init(115200); #endif // Configure the multi-rate timer for 1ms ticks mrtInit(__SYSTEM_CLOCK/1000); /* Enable AHB clock to the Switch Matrix , UART0 , GPIO , IOCON, MRT , ACMP */ LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 7) | (1 << 14) /*| (1 << 6)*//* | (1 << 18)*/ | (1 << 10) | (1 << 19); // Configure the switch matrix (setup pins for UART0 and SPI) configurePins(); #ifdef DEBUG mrtDelay(100); printf("Node Booted\r\n"); mrtDelay(100); #endif RFM69_init(); #ifdef ZOMBIE_MODE //This is to allow the setup to recover from the initial boot and // avoid a loop RFM69_setMode(RFM69_MODE_SLEEP); init_sleep(); sleepMicro(20000); #endif #ifdef DEBUG printf("Node initialized, version %s\r\n",GIT_VER); #endif //Seed random number generator, we can use our 'unique' ID random_output = NODE_ID[0] + NODE_ID[1] + NODE_ID[2]; while(1) { /* #ifdef ZOMBIE_MODE adc_result = acmpVccEstimate(); // Before transmitting if the input V is too low we could sleep again if (adc_result < 3100 || adc_result > 10000) { sleepRadio(); } #endif */ incrementPacketCount(); //Clear buffer data_temp[0] = '\0'; uint8_t n; //Create the packet int int_temp; #ifdef ZOMBIE_MODE //This is to allow the setup to recover from the initial boot and // avoid a loop RFM69_setMode(RFM69_MODE_SLEEP); init_sleep(); sleepMicro(10000); #endif int_temp = RFM69_readTemp(); // Read transmitter temperature rx_rssi = RFM69_lastRssi(); // read the rssi threshold before re-sampling noise floor which will change it rssi_threshold = RFM69_lastRssiThreshold(); floor_rssi = RFM69_sampleRssi(); #ifdef ZOMBIE_MODE //This is to allow the setup to recover from the initial boot and // avoid a loop RFM69_setMode(RFM69_MODE_SLEEP); init_sleep(); sleepMicro(10000); #endif #ifdef ZOMBIE_MODE adc_result = acmpVccEstimate(); //sleepMicro(20000); #endif #ifdef DEBUG printf("ADC: %d\r\n", adc_result); #endif #ifdef ZOMBIE_MODE //This is to allow the setup to recover from the initial boot and // avoid a loop RFM69_setMode(RFM69_MODE_SLEEP); init_sleep(); sleepMicro(10000); #endif if(data_count == 97) { n = sprintf(data_temp, "%d%cL%s[%s]", NUM_REPEATS, data_count, LOCATION_STRING, NODE_ID); } else { #ifdef DEBUG //n = sprintf(data_temp, "%d%cT%dR%d,%dC%dX%d,%dV%d[%s]", NUM_REPEATS, data_count, int_temp, rx_rssi, floor_rssi, rx_packets, rx_restarts, rssi_threshold, adc_result, NODE_ID); n = sprintf(data_temp, "%d%cT%dV%d[%s]", NUM_REPEATS, data_count, int_temp, adc_result, NODE_ID); #elif defined(ZOMBIE_MODE) n = sprintf(data_temp, "%d%cT%dV%d[%s]", NUM_REPEATS, data_count, int_temp, adc_result, NODE_ID); #else n = sprintf(data_temp, "%d%cT%dR%d[%s]", NUM_REPEATS, data_count, int_temp, rx_rssi, NODE_ID); #endif } transmitData(n); #ifdef ZOMBIE_MODE sleepRadio(); #else awaitData(TX_GAP); #endif } }