int main(void) { static Thread *shelltp = NULL; static const evhandler_t evhndl_main[] = { extdetail_WKUP_button_handler }; struct EventListener el0; /* * System initializations. * - HAL initialization, this also initializes the configured device drivers * and performs the board-specific initializations. * - Kernel initialization, the main() function becomes a thread and the * RTOS is active. */ halInit(); chSysInit(); extdetail_init(); palSetPad(GPIOC, GPIOC_LED); palSetPad(GPIOA, GPIOA_SPI1_SCK); palSetPad(GPIOA, GPIOA_SPI1_NSS); /* * SPI1 I/O pins setup. */ palSetPadMode(adis_connections.spi_sck_port, adis_connections.spi_sck_pad, PAL_MODE_ALTERNATE(5) | PAL_STM32_OSPEED_HIGHEST); palSetPadMode(adis_connections.spi_miso_port, adis_connections.spi_miso_pad, PAL_MODE_ALTERNATE(5) | PAL_STM32_OSPEED_HIGHEST| PAL_STM32_PUDR_FLOATING); palSetPadMode(adis_connections.spi_mosi_port, adis_connections.spi_mosi_pad, PAL_MODE_ALTERNATE(5) | PAL_STM32_OSPEED_HIGHEST ); palSetPadMode(adis_connections.spi_cs_port, adis_connections.spi_cs_pad, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); palSetPad(GPIOA, GPIOA_SPI1_SCK); palSetPad(GPIOA, GPIOA_SPI1_NSS); /*! * Initializes a serial-over-USB CDC driver. */ sduObjectInit(&SDU_PSAS); sduStart(&SDU_PSAS, &serusbcfg); /*! * Activates the USB driver and then the USB bus pull-up on D+. * Note, a delay is inserted in order to not have to disconnect the cable * after a reset. */ usbDisconnectBus(serusbcfg.usbp); chThdSleepMilliseconds(1000); usbStart(serusbcfg.usbp, &usbcfg); usbConnectBus(serusbcfg.usbp); shellInit(); iwdg_begin(); /*! * Activates the serial driver 6 and SDC driver 1 using default * configuration. */ sdStart(&SD6, NULL); spiStart(&SPID1, &adis_spicfg); /* Set transfer parameters. */ chThdSleepMilliseconds(300); adis_init(); adis_reset(); /*! Activates the EXT driver 1. */ extStart(&EXTD1, &extcfg); chThdCreateStatic(waThread_blinker, sizeof(waThread_blinker), NORMALPRIO, Thread_blinker, NULL); chThdCreateStatic(waThread_adis_dio1, sizeof(waThread_adis_dio1), NORMALPRIO, Thread_adis_dio1, NULL); chThdCreateStatic(waThread_adis_newdata, sizeof(waThread_adis_newdata), NORMALPRIO, Thread_adis_newdata, NULL); chThdCreateStatic(waThread_indwatchdog, sizeof(waThread_indwatchdog), NORMALPRIO, Thread_indwatchdog, NULL); chEvtRegister(&extdetail_wkup_event, &el0, 0); while (TRUE) { if (!shelltp && (SDU_PSAS.config->usbp->state == USB_ACTIVE)) shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); else if (chThdTerminated(shelltp)) { chThdRelease(shelltp); /* Recovers memory of the previous shell. */ shelltp = NULL; /* Triggers spawning of a new shell. */ } chEvtDispatch(evhndl_main, chEvtWaitOneTimeout((eventmask_t)1, MS2ST(500))); } }
int main(void) { static const evhandler_t evhndl_main[] = { extdetail_WKUP_button_handler }; struct EventListener el0; /* * System initializations. * - HAL initialization, this also initializes the configured device drivers * and performs the board-specific initializations. * - Kernel initialization, the main() function becomes a thread and the * RTOS is active. */ halInit(); chSysInit(); extdetail_init(); palSetPad(GPIOC, GPIOC_LED); /*! * GPIO Pins for generating pulses at data input detect and data output send. * Used for measuring latency timing of data * * \sa board.h */ palClearPad( TIMEOUTPUT_PORT, TIMEOUTPUT_PIN); palSetPadMode(TIMEOUTPUT_PORT, TIMEOUTPUT_PIN, PAL_MODE_OUTPUT_PUSHPULL); palSetPad( TIMEINPUT_PORT, TIMEINPUT_PIN); palSetPadMode(TIMEINPUT_PORT, TIMEINPUT_PIN, PAL_MODE_OUTPUT_PUSHPULL ); /* * I2C2 I/O pins setup */ palSetPadMode(si_i2c_connections.i2c_sda_port , si_i2c_connections.i2c_sda_pad, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_OSPEED_HIGHEST |PAL_STM32_PUDR_FLOATING ); palSetPadMode(si_i2c_connections.i2c_scl_port, si_i2c_connections.i2c_scl_pad, PAL_MODE_ALTERNATE(4) | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_PUDR_FLOATING); palSetPad(si_i2c_connections.i2c_scl_port, si_i2c_connections.i2c_scl_pad ); static const ShellCommand commands[] = { {"mem", cmd_mem}, {"threads", cmd_threads}, {NULL, NULL} }; usbSerialShellStart(commands); mpu9150_start(&I2CD2); i2cStart(mpu9150_driver.i2c_instance, &si_i2c_config); mpu9150_init(mpu9150_driver.i2c_instance); /* Administrative threads */ chThdCreateStatic(waThread_blinker, sizeof(waThread_blinker), NORMALPRIO, Thread_blinker, NULL); chThdCreateStatic(waThread_indwatchdog, sizeof(waThread_indwatchdog), NORMALPRIO, Thread_indwatchdog, NULL); /* MAC */ /*! * Use a locally administered MAC address second LSbit of MSB of MAC should be 1 * Use unicast address LSbit of MSB of MAC should be 0 */ data_udp_init(); chThdCreateStatic(wa_lwip_thread , sizeof(wa_lwip_thread) , NORMALPRIO + 2, lwip_thread , SENSOR_LWIP); chThdCreateStatic(wa_data_udp_send_thread , sizeof(wa_data_udp_send_thread) , NORMALPRIO , data_udp_send_thread , NULL); /* i2c MPU9150 */ chThdCreateStatic(waThread_mpu9150_int, sizeof(waThread_mpu9150_int) , NORMALPRIO , Thread_mpu9150_int, NULL); /* SPI ADIS */ //chThdCreateStatic(waThread_adis_dio1, sizeof(waThread_adis_dio1), NORMALPRIO, Thread_adis_dio1, NULL); //chThdCreateStatic(waThread_adis_newdata, sizeof(waThread_adis_newdata), NORMALPRIO, Thread_adis_newdata, NULL); /*! Activates the EXT driver 1. */ extStart(&EXTD1, &extcfg); chEvtRegister(&extdetail_wkup_event, &el0, 0); while (TRUE) { chEvtDispatch(evhndl_main, chEvtWaitOneTimeout((eventmask_t)1, MS2ST(500))); } }