void cph_deca_force_wakeup() { reset_DW1000(); spi_set_rate_low(); uint32_t id = dwt_readdevid(); if (id == 0xFFFFFFFF) { TRACE("DW asleep..waking\r\n"); // asleep, wakeup pio_set_pin_high(DW_WAKEUP_PIO_IDX); cph_millis_delay(1); pio_set_pin_low(DW_WAKEUP_PIO_IDX); cph_millis_delay(1); } }
int main(void) { system_init(); cph_millis_init(); cph_stdio_init(); TRACE("DECAWAVE CPH \r\n"); TRACE(SOFTWARE_VER_STRING); TRACE("\r\n"); uint32_t f = system_gclk_gen_get_hz(0); TRACE("CPU FREQ: %lu\r\n", f); // Blink LED for 5 seconds for (int i = 0; i < (5 * 4); i++) { port_pin_set_output_level(LED_PIN, false); cph_millis_delay(125); port_pin_set_output_level(LED_PIN, true); cph_millis_delay(125); } // init cph_deca //#ifdef ANCHOR // anchor_init(); //#else // tag_init(); //#endif ss_twr_init(); // blocks system_interrupt_enable_global(); uint32_t count = 0; uint32_t timestamp = cph_get_millis(); uint32_t elapsed = 0; while (1) { cph_deca_run(); elapsed = (cph_get_millis() - timestamp); if (elapsed > 5000) { timestamp = cph_get_millis(); cph_deca_print_status(count++); } } }
void cph_deca_reset(void) { // low gate - turn on MOSFET and drive to ground pio_set_pin_low(DW_RSTn_PIO_IDX); // sleep here?? // high gate - turn off MOSFET and open drain pio_set_pin_high(DW_RSTn_PIO_IDX); // Why sleep here? Left over from original code. cph_millis_delay(1); }
uint32_t baro_get_pressure(void) { uint32_t pressure; write8(MPL3115A2_CTRL_REG1, MPL3115A2_CTRL_REG1_SBYB | MPL3115A2_CTRL_REG1_OS128 | MPL3115A2_CTRL_REG1_BAR); uint8_t sta = 0; while (! (sta & MPL3115A2_REGISTER_STATUS_PDR)) { sta = read8(MPL3115A2_REGISTER_STATUS); cph_millis_delay(125); } // Wire.beginTransmission(MPL3115A2_ADDRESS); // start transmission to device // Wire.write(MPL3115A2_REGISTER_PRESSURE_MSB); // Wire.endTransmission(false); // end transmission bool status = writeBit(MPL3115A2_ADDRESS, MPL3115A2_REGISTER_PRESSURE_MSB, MPL3115A2_OUT_P_DELTA_MSB, true); // Wire.requestFrom((uint8_t)MPL3115A2_ADDRESS, (uint8_t)3);// send data n-bytes read // pressure = Wire.read(); // receive DATA // pressure <<= 8; // pressure |= Wire.read(); // receive DATA // pressure <<= 8; // pressure |= Wire.read(); // receive DATA // pressure >>= 4; readBits(MPL3115A2_ADDRESS, 0x01, 0x00, 3, baro_buffer, I2CDEV_DEFAULT_READ_TIMEOUT); pressure = (((int32_t)baro_buffer[0]) << 8) | (((int32_t)baro_buffer[1]) << 8) | (((int32_t)baro_buffer[2]) << 4); float baro = pressure; baro /= 4.0; return baro; }
void cph_deca_reset(void) { struct port_config config_port = DW_RST_PIN_CONFIG; // Safety extint_chan_disable_callback(DW_RST_LINE, EXTINT_CALLBACK_TYPE_DETECT); // Pull the pin low config_port.direction = PORT_PIN_DIR_OUTPUT; config_port.input_pull = PORT_PIN_PULL_NONE; port_pin_set_output_level(DW_RST_PIN, false); port_pin_set_config(DW_RST_PIN, &config_port); // Now release it config_port.direction = PORT_PIN_DIR_INPUT; config_port.input_pull = PORT_PIN_PULL_NONE; port_pin_set_config(DW_RST_PIN, &config_port); // Why sleep here? Left over from original code. cph_millis_delay(1); }
void configure_main(void) { uint8_t buffer[10]; config_idx = -1; cph_config = cph_config_init(); while (1) { TRACE("\r\n\r\nMain Menu\r\n"); TRACE("==============\r\n"); for (int i=0;i<G_CONFIG_COUNT - 1;i++) { TRACE("%d) ", i); configure_print_dwt_config(&g_dwt_configs[i]); TRACE("\r\n"); } TRACE("U) User defined\r\n"); TRACE("P) Set parameters\r\n"); TRACE("A) Exit and run as ANCHOR\r\n"); TRACE("C) Exit and run as COORDINATOR\r\n"); TRACE("T) Exit and run as TAG\r\n"); TRACE("L) Exit and run as LISTENER\r\n"); TRACE("S) Exit and run as SENDER\r\n"); TRACE("D) Exit and run with compiled DEFAULTS\r\n"); TRACE("F) Test flash\r\n"); TRACE("\r\nCurrent Config : "); configure_print_dwt_config(&cph_config->dwt_config); TRACE("\r\nNew Config : "); if (config_idx == -1) { TRACE("none selected"); } else { configure_print_dwt_config(&g_dwt_configs[config_idx]); } TRACE("\r\n"); TRACE("\r\n> "); choice = getchar() & 0xFF; TRACE("%c - ", choice); if (choice >= '0' && choice <= ('0' + G_CONFIG_COUNT - 1 - 1)) { TRACE("VALID\r\n"); config_idx = choice - '0'; } else if (choice == 'u' || choice == 'U') { configure_user_defined(); } else if (choice == 'p' || choice == 'P') { configure_parameters(); } else if (choice == 'a' || choice == 'A') { cph_config->mode = CPH_MODE_ANCHOR; TRACE("Exiting as CPH_MODE_ANCHOR\r\n"); break; } else if (choice == 'c' || choice == 'C') { cph_config->mode = CPH_MODE_COORD; TRACE("Exiting as CPH_MODE_COORD\r\n"); break; } else if (choice == 't' || choice == 'T') { cph_config->mode = CPH_MODE_TAG; TRACE("Exiting as CPH_MODE_TAG\r\n"); break; } else if (choice == 'l' || choice == 'L') { cph_config->mode = CPH_MODE_LISTENER; TRACE("Exiting as CPH_MODE_LISTENER\r\n"); break; } else if (choice == 's' || choice == 'S') { cph_config->mode = CPH_MODE_SENDER; TRACE("Exiting as CPH_MODE_SENDER\r\n"); break; } else if (choice == 'd' || choice == 'D') { memset(cph_config, 0, sizeof(cph_config_t)); cph_config_write(); TRACE("Exiting as compiled DEFAULT\r\n"); break; } else if (choice == 'f' || choice == 'F') { test_flash(); } else { TRACE("NOT VALID\r\n"); } }; TRACE("\r\n"); TRACE("Writing config..."); if (config_idx >= 0) { memcpy(&cph_config->dwt_config, &g_dwt_configs[config_idx], sizeof(dwt_config_t)); } cph_config_write(); TRACE("done.\r\n"); TRACE("Starting in "); for (int i=3;i>0;i--) { TRACE("%d ", i); cph_millis_delay(1000); } TRACE("\r\n"); }