/* * Application entry point. */ int main(void) { // thread representing the shell Thread *shelltp = NULL; /* * 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(); USBInit(); // main activity - shell respawn upon its termination. while (TRUE) { if (!shelltp && isUSBActive()) { // Checks if shell doesnt exist and USB is active /* Spawns a new shell.*/ shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); } else { /* If the previous shell exited.*/ if (chThdTerminated(shelltp)) { /* Recovers memory of the previous shell.*/ chThdRelease(shelltp); shelltp = NULL; } } chThdSleepMilliseconds(500); } }
int spawnShell(void) { const int ONE_THOUSAND_MILLISECONDS = 1000; const int THREAD_WORKING_AREA_SIZE = 2048; Thread *shellThread = NULL; while (TRUE) { // If we don't have a shell but a living USB connection, create a new thread with the shell. if (!shellThread && isUSBActive()) { shellThread = shellCreate(&shellConfiguration, THD_WA_SIZE(THREAD_WORKING_AREA_SIZE), NORMALPRIO); } else if (chThdTerminated(shellThread)) { // Recover memory of the previous shell. chThdRelease(shellThread); // Trigger spawning of a new shell. shellThread = NULL; } chThdSleepMilliseconds(ONE_THOUSAND_MILLISECONDS); } }
int main(void) { /* * 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(); /* * * Initializes a serial-over-USB CDC driver. * */ sduObjectInit(&SDU1); sduStart(&SDU1, &serusbcfg); /* * * Activates the USB driver and then the USB bus pull-up on D+. * */ usbDisconnectBus(serusbcfg.usbp); chThdSleepMilliseconds(500); usbStart(serusbcfg.usbp, &usbcfg); usbConnectBus(serusbcfg.usbp); /* * * Start I2C and set up sensors * */ i2cStart(&I2CD2, &i2cfg2); /* Initialize Accelerometer and Gyroscope */ if (MPU6050Init(&mpu6050cfg) != MSG_OK) panic("MPU6050 init failed"); /* Initialization failed */ /* Initialize Magnetometer */ if (HMC5983Init(&hmc5983cfg) != MSG_OK) panic("HMC5983 init failed"); /* Initialization failed */ /* Initialize Barometer */ /* TODO: Add barometer code */ /* Initialize sensor readout */ if (SensorReadInit(&mpu6050cfg, &hmc5983cfg, &mpu6050cal, &hmc5983cal) != MSG_OK) panic("Sensor Read init failed"); /* Initialization failed */ /* * * Start the external interrupts * */ extStart(&EXTD1, &extcfg); /* * * Initialize the RC Outputs * */ if (RCOutputInit(&rcoutputcfg) != MSG_OK) panic("RC output init failed"); /* Initialization failed */ /* * * Start RC Inputs * */ eicuInit(); eicuStart(&EICUD9, &rcinputcfg); eicuEnable(&EICUD9); /* * * Start test thread * */ chThdCreateStatic( waThreadTestEvents, sizeof(waThreadTestEvents), HIGHPRIO, ThreadTestEvents, NULL); while(1) { chThdSleepMilliseconds(100); if (isUSBActive() == true) chprintf((BaseSequentialStream *)&SDU1, "Input width: %u\r\n", ic_test); } }