int main(void) { int i, j, k, l; unsigned button[3]; unsigned steps[3]; unsigned hz; /*------------------------------------------------------------- * First things first: Start the watchdog */ fido_setup(0x1000); /*------------------------------------------------------------- * Setup GPIO */ LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 6); // GPIO LPC_SYSCON->PRESETCTRL &= ~(1 << 10); // GPIO reset LPC_SYSCON->PRESETCTRL |= (1 << 10); LPC_IOCON->PIO0_0 = 0 | (1 << 3) // Pull down | (1 << 5) // Hysteresis ; LPC_IOCON->PIO0_1 = 0 | (2 << 3) // Pull up | (1 << 5) // Hysteresis ; LPC_IOCON->PIO0_2 = 0 | (2 << 3) // Pull up | (1 << 5) // Hysteresis ; LPC_IOCON->PIO0_3 = 0 | (2 << 3) // Pull up | (1 << 5) // Hysteresis ; LPC_IOCON->PIO0_5 = 0 | (2 << 3) // Pull up | (1 << 5) // Hysteresis ; /*------------------------------------------------------------- * Provide a chance to enter the boot-loader */ check_bootloader(); /*------------------------------------------------------------- * Enable UART for startup-debugging */ uart0Init(115200); uart_enable(); /*------------------------------------------------------------- * Start timer */ mrtInit(__SYSTEM_CLOCK/1000); /*------------------------------------------------------------- * Enable reset pin */ LPC_SWM->PINENABLE0 = ~(1 << 6); // PIO0_5 RESET_EN /*------------------------------------------------------------- * Hello World */ welcome(); /*------------------------------------------------------------- * Detect pin-configuration by counting edges on the two possible * possible clock inputs. * * If neither is active the watch-dog will trigger. */ do { /* Measure input frequency on PIO0_1 and PIO0_2 */ for (i = 1; i < 3; i++) { sct_setup(i); k = LPC_SCT->COUNT_U; mrtDelay(100); l = LPC_SCT->COUNT_U; hz = 10 * (l-k); printf("Rate PIO0_%d = %u\r\n", i, hz); if (hz > 1000) break; } } while (hz < 1000); /*------------------------------------------------------------- * Configure counter */ mrtDelay(100); printf("Using PIO0_%d\r\n", i); mrtDelay(100); uart_disable(); button[0] = 1<<(3-i); steps[0] = 1; button[1] = 1<<3; steps[1] = 60; button[2] = 1<<5; steps[2] = 3600; if (i == 1) { LPC_SWM->PINENABLE0 &= ~(1 << 7); // Enable CLKIN LPC_SYSCON->MAINCLKSEL = 0x1; // PLL input LPC_SYSCON->MAINCLKUEN = 0x0; LPC_SYSCON->MAINCLKUEN = 0x1; LPC_SYSCON->SYSPLLCLKSEL = 0x3; // CLKIN LPC_SYSCON->SYSPLLCLKUEN = 0x0; LPC_SYSCON->SYSPLLCLKUEN = 0x1; LPC_SYSCON->SYSAHBCLKDIV = 1; sct_setup(0xff); mrtInit(FREQ/1000); /* Calibrated to look like 0x00 at 115200 bps */ pulse_lo = 29; pulse_hi = 10; } else { sct_setup(2); } sct_output(4); /*------------------------------------------------------------- * Until the clock is set, have it run 11 times too fast */ while (1) { fido_pat(); if (!(LPC_GPIO_PORT->PIN0 & button[0])) break; if (!(LPC_GPIO_PORT->PIN0 & button[1])) break; if (!(LPC_GPIO_PORT->PIN0 & button[2])) break; mrtDelay(100); run_pulse(); } LPC_SWM->PINENABLE0 |= (1 << 6); // Disable RESET j = 0; while(1) { if (j == 0 && LPC_SCT->COUNT_U < 10000) { fido_pat(); j = 1; } if (j == 1 && LPC_SCT->COUNT_U > 10000) { j = 0; } for (i = 0; i < 3; i++) { if (LPC_GPIO_PORT->PIN0 & button[i]) continue; fido_pat(); for(k = 0; k < steps[i]; k++) run_pulse(); if (i > 0) { /* * Min/Hour button release * If you hold them for 10+ seconds * The watch-dog bites */ for(k = 0; k < 1000; k++) { if (LPC_GPIO_PORT->PIN0 & button[i]) continue; k = 0; } continue; } /* Check if the Sec button is held for >1s */ mrt_counter = 0; for(k = 0; k < 1000; k++) { if (LPC_GPIO_PORT->PIN0 & button[i]) break; if (mrt_counter > 1000) break; k = 0; } if (k == 1000) continue; /* Stop counter */ sct_stop(); /* * Restart counter on button release * or sync input */ for(k = 0; k < 1000; k++) { if (LPC_GPIO_PORT->PIN0 & button[i]) break; l = LPC_GPIO_PORT->PIN0 & (1<<0); if (l) k = 0; } l = (1 << 0) | button[i]; while (!(LPC_GPIO_PORT->PIN0 & l)) continue; /* * Calibrated for falling edge = PPI rising edge * PPSO comes 164ns after PPS1 */ LPC_SCT->COUNT_U = FREQ - 366; LPC_SCT->CTRL_L &= ~(1 << 2); // Start for(k = 0; k < 1000; k++) { if (LPC_GPIO_PORT->PIN0 & button[i]) continue; k = 0; } } } }
int main(void) { // Initialise the GPIO block gpioInit(); #ifdef GPS // Initialise the UART0 block for printf output uart0Init(9600); #else // Initialise the UART0 block for printf output uart0Init(115200); #endif // Configure the multi-rate timer for 1ms ticks mrtInit(__SYSTEM_CLOCK/1000); // Configure the switch matrix (setup pins for UART0 and SPI) configurePins(); //Seed random number generator, we can use our 'unique' ID random_output = NODE_ID[0] + NODE_ID[1] + NODE_ID[2]; //printf("random: %d\r\n", random_output); RFM69_init(); #ifdef GPS int navmode = 9; setupGPS(); #endif #ifdef DEBUG printf("Node initialized, version %s\r\n",GIT_VER); #endif while(1) { #ifdef GPS mrtDelay(5000); navmode = gps_check_nav(); if (navmode != 6){ setupGPS(); } mrtDelay(500); gps_get_position(); mrtDelay(500); gps_check_lock(); mrtDelay(500); //printf("Data: %d,%d,%d,%d,%d,%d\r\n", lat, lon, alt, navmode, lock, sats); //printf("Errors: %d,%d\r\n", GPSerror, serialBuffer_write); #endif incrementPacketCount(); //Clear buffer data_temp[0] = '\0'; uint8_t n; //Create the packet int int_temp = RFM69_readTemp(); // Read transmitter temperature rx_rssi = RFM69_lastRssi(); floor_rssi = RFM69_sampleRssi(); #ifdef GPS n = sprintf(data_temp, "%d%cL%d,%d,%dT%dR%d[%s]", NUM_REPEATS, data_count, lat, lon, alt, int_temp, rx_rssi, NODE_ID); #else if(data_count == 97) { n = sprintf(data_temp, "%d%cL%s[%s]", NUM_REPEATS, data_count, LOCATION_STRING, NODE_ID); } else { n = sprintf(data_temp, "%d%cT%dR%d,%dC%d[%s]", NUM_REPEATS, data_count, int_temp, rx_rssi, floor_rssi, rx_packets, NODE_ID); } #endif transmitData(n); awaitData(TX_GAP); } }
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 } }
int main(void) { /* Initialise the GPIO block */ gpioInit(); /* Initialise the UART0 block for printf output */ //uart0Init(115200); uart0Init(9600); /* Configure the multi-rate timer for 1ms ticks */ mrtInit(__SYSTEM_CLOCK/1000); /* Configure the switch matrix (setup pins for UART0 and GPIO) */ //configurePins(); spiInit(LPC_SPI0, 6, 0); SwitchMatrix_Init(); //uart & spi LPC_GPIO_PORT->DIR0 |= (1 << CSN); LPC_GPIO_PORT->DIR0 |= (1 << CE); uint8_t temp = 0; nrf24_init(); /* Set the LED pin to output (1 = output, 0 = input) */ #if !defined(USE_SWD) LPC_GPIO_PORT->DIR0 |= (1 << LED_LOCATION); #endif //printf("write"); mrtDelay(500); nrf24_config(2,16); #if TX_NODE nrf24_tx_address(tx_address); nrf24_rx_address(rx_address); #else nrf24_tx_address(rx_address); //backwards looking but is fine nrf24_rx_address(tx_address); #endif uint8_t i = 0; while(1) { /* Turn LED On by setting the GPIO pin high */ LPC_GPIO_PORT->SET0 = 1 << LED_LOCATION; mrtDelay(500); /* Turn LED Off by setting the GPIO pin low */ LPC_GPIO_PORT->CLR0 = 1 << LED_LOCATION; mrtDelay(500); /* printf("Send\r\n"); for(i=0; i<16; i++){ printf("%d: %d\n\r", i, tx_data_array[i]); } */ nrf24_send(tx_data_array); while(nrf24_isSending()); nrf24_powerUpRx(); //done transmitting, set back to rx mode for(i=0; i<16; i++){ tx_data_array[i]++; } /* if(nrf24_dataReady()){ printf("\n\rGot data\n\r"); nrf24_getData(rx_data_array); for(i=0; i<16; i++){ printf("%d: %d\n\r", i, rx_data_array[i]); } } */ } }
int main(void) { #if defined(GATEWAY) || defined(DEBUG) || defined(GPS) // 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(); LPC_GPIO_PORT->DIR0 |= (1 << GSM_PWR); RFM69_init(); #if defined(GATEWAY) || defined(DEBUG) || defined(GPS) mrtDelay(100); printf("Node Booted\r\n"); mrtDelay(100); #endif uart1Init(115200); GSM_On(); //GSM_AT(); #if defined(GATEWAY) || defined(DEBUG) || defined(GPS) 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]; mrtDelay(5000); GSM_AT(); mrtDelay(5000); GSM_upload(); while(1) { GSM_AT(); incrementPacketCount(); //Clear buffer data_temp[0] = '\0'; uint8_t n; //Create the packet int int_temp; 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(); 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); #else n = sprintf(data_temp, "%d%cT%dR%dX%d[%s]", NUM_REPEATS, data_count, int_temp, rx_rssi, rx_packets, NODE_ID); #endif } transmitData(n); GSM_upload(); awaitData(TX_GAP); } }