static void dyn3_execute(void) { Thread *tp; tprio_t prio = chThdGetPriority(); /* Testing references increase/decrease and final detach.*/ tp = chThdCreateFromHeap(&heap1, WA_SIZE, prio-1, thread, "A"); test_assert(1, tp->p_refs == 1, "wrong initial reference counter"); chThdAddRef(tp); test_assert(2, tp->p_refs == 2, "references increase failure"); chThdRelease(tp); test_assert(3, tp->p_refs == 1, "references decrease failure"); /* Verify the new threads count.*/ test_assert(4, regfind(tp), "thread missing from registry"); test_assert(5, regfind(tp), "thread disappeared"); /* Detach and let the thread execute and terminate.*/ chThdRelease(tp); test_assert(6, tp->p_refs == 0, "detach failure"); test_assert(7, tp->p_state == THD_STATE_READY, "invalid state"); test_assert(8, regfind(tp), "thread disappeared"); test_assert(9, regfind(tp), "thread disappeared"); chThdSleepMilliseconds(50); /* The thread just terminates. */ test_assert(10, tp->p_state == THD_STATE_FINAL, "invalid state"); /* Clearing the zombie by scanning the registry.*/ test_assert(11, regfind(tp), "thread disappeared"); test_assert(12, !regfind(tp), "thread still in registry"); }
/* * Application entry point. */ int main(void) { static const evhandler_t evhndl[] = { InsertHandler, RemoveHandler }; Thread *shelltp = NULL; struct EventListener el0, el1; /* * 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(); /* * Activates the serial driver 2 using the driver default configuration. */ sdStart(&SD2, NULL); /* * Shell manager initialization. */ shellInit(); /* * Initializes the MMC driver to work with SPI2. */ palSetPadMode(IOPORT2, GPIOB_SPI2NSS, PAL_MODE_OUTPUT_PUSHPULL); palSetPad(IOPORT2, GPIOB_SPI2NSS); mmcObjectInit(&MMCD1, &SPID2, &ls_spicfg, &hs_spicfg, mmc_is_protected, mmc_is_inserted); mmcStart(&MMCD1, NULL); /* * Creates the blinker thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); /* * Normal main() thread activity, in this demo it does nothing except * sleeping in a loop and listen for events. */ chEvtRegister(&MMCD1.inserted_event, &el0, 0); chEvtRegister(&MMCD1.removed_event, &el1, 1); while (TRUE) { if (!shelltp) 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, chEvtWaitOne(ALL_EVENTS)); } return 0; }
void senokoShellRestart(void) { /* Recovers memory of the previous shell. */ if (shell_tp && chThdTerminatedX(shell_tp)) chThdRelease(shell_tp); shell_tp = shellCreateStatic(&shellConfig, waShellThread, sizeof(waShellThread), NORMALPRIO); }
/* * 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 main(void) { Thread *shelltp = NULL; halInit(); chSysInit(); palSetPadMode(GPIOA,9,PAL_MODE_STM32_ALTERNATE_PUSHPULL); palSetPadMode(GPIOA,10,PAL_MODE_INPUT); sdStart(&SD1, NULL); shellInit(); palSetPadMode(GPIOA,8,PAL_MODE_OUTPUT_PUSHPULL); chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); Lcd_Init(); Lcd_Clear(); Lcd_Example(); while (TRUE) { if (!shelltp){ shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO);} else if (chThdTerminated(shelltp)) { chThdRelease(shelltp); shelltp = NULL; } chThdSleepMilliseconds(500); } }
/* * Application entry point. */ int main(void) { /* Shell thread */ Thread *shelltp = NULL; /* UART Configuration Structure */ SerialConfig sc; // Dummy ADC Configuration structure ADCConfig adc_conf; /* * 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(); GPIO_Configuration(); //ADC_Configuration(); I2C_Configuration(); /* Start Serial Driver */ sc.sc_speed = 115200; sc.sc_cr1 = 0; sc.sc_cr2 = USART_CR2_STOP1_BITS | USART_CR2_LINEN; sc.sc_cr3 = 0; sdStart(&SD1, &sc); /* Shell manager initialization. */ shellInit(); /* * Creates the example thread. */ chThdCreateStatic(waThread1, sizeof(waI2CThread), NORMALPRIO, I2CThread, NULL); /* * Normal main() thread activity, in this demo it does nothing except * sleeping in a loop and check the button state, when the button is * pressed the test procedure is launched with output on the serial * driver 1. */ while (TRUE) { if(!shelltp) { shelltp = shellCreate( &shell_cfg, THD_WA_SIZE(2048), NORMALPRIO); } else if(chThdTerminated(shelltp)) { // Recovers memory of the previous shell. chThdRelease(shelltp); shelltp = NULL; } } }
int main(void) { thread_t *sh = NULL; PollerData.temp = 0; PollerData.press = 0;/* PollerData.uTime = 0;*/ halInit(); chSysInit(); shellInit(); usbDisconnectBus(serusbcfg.usbp); chThdSleepMilliseconds(1000); usbStart(serusbcfg.usbp, &usbcfg); usbConnectBus(serusbcfg.usbp); sduObjectInit(&SDU1); sduStart(&SDU1, &serusbcfg); // SPI-related pins (for display) palSetPadMode(GPIOB, 11, PAL_MODE_OUTPUT_PUSHPULL); palSetPadMode(GPIOB, 10, PAL_MODE_OUTPUT_PUSHPULL); palSetPadMode(GPIOB, 13, PAL_MODE_ALTERNATE(5)); palSetPadMode(GPIOB, 14, PAL_MODE_OUTPUT_PUSHPULL); palSetPadMode(GPIOB, 15, PAL_MODE_ALTERNATE(5)); spiStart(&SPID1, &spi1cfg); spiStart(&SPID2, &spi2cfg); i2cStart(&I2CD1, &i2cconfig); initGyro(); initAccel(); initMag(); // nunchuk_status = nunchuk_init(); bmp085_status = bmp085_init(); lcd5110Init(); lcd5110SetPosXY(0, 0); lcd5110WriteText("P :: "); lcd5110SetPosXY(0, 1); lcd5110WriteText("T :: "); chThdCreateStatic(waThreadBlink, sizeof(waThreadBlink), NORMALPRIO, ThreadBlink, NULL); chThdCreateStatic(waThreadButton, sizeof(waThreadButton), NORMALPRIO, ThreadButton, NULL); chThdCreateStatic(waPoller, sizeof(waPoller), NORMALPRIO, ThreadPoller, NULL); while (TRUE) { if (!sh) { sh = shellCreate(&shCfg, SHELL_WA_SIZE, NORMALPRIO); } else if (chThdTerminatedX(sh)) { chThdRelease(sh); sh = NULL; } chThdSleepMilliseconds(1000); } return 0; // never returns, lol }
void Shell_Setup(void){ if (!shelltp){ shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO);} /* create shell tread */ else if (chThdTerminated(shelltp)) { chThdRelease(shelltp); /* Recovers memory of the previous shell. */ shelltp = NULL; /* Triggers spawning of a new shell. */ } }
/* * Shell exit event. */ static void ShellHandler(eventid_t id) { (void)id; if (chThdTerminatedX(shelltp)) { chThdRelease(shelltp); shelltp = NULL; } }
int main(void){ halInit(); chSysInit(); Thread *sh = NULL; sdStart(&SD1,&sd1conf); //sdStart(&SD1,NULL); chThdSleepMilliseconds(200); #if USE_I2C_STUFF I2CInit_pns(); #if USE_I2C_POLL_THD /* Create accelerometer thread */ chThdCreateStatic(PollAccelThreadWA, sizeof(PollAccelThreadWA), NORMALPRIO, PollAccelThread, NULL); chThdCreateStatic(PollColorThreadWA, sizeof(PollColorThreadWA), NORMALPRIO, PollColorThread, NULL); #endif #endif chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); #if USE_SER_OUT_THD chThdCreateStatic(waSerOutThr1, sizeof(waSerOutThr1), NORMALPRIO, SerOutThr1, NULL); #endif palSetPadMode(GPIOA, GPIOA_PA2, PAL_MODE_OUTPUT_PUSHPULL); palSetPadMode(GPIOA, 3, PAL_MODE_OUTPUT_PUSHPULL); //TestThread(&SD1); shellInit(); while (TRUE){ //palSetPad(GPIOA, 3); //TestThread(&SD1); //chThdSleepMilliseconds(500); //palClearPad(GPIOA, 3); //chThdSleepMilliseconds(500); if (!sh){ chprintf((BaseSequentialStream *)&SD1,"Starting ChibiOS/RT Shell\n\r"); sh = shellCreate(&shCfg, SHELL_WA_SIZE, NORMALPRIO+1); } else if (chThdTerminated(sh)) { chThdRelease(sh); sh = NULL; } // chThdSleepMilliseconds(1000); } }
/* * Application entry point. */ int main(void) { 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(); /* * Activates the USB driver and then the USB bus pull-up on D+. */ usbDisconnectBus(serusbcfg.usbp); chThdSleepMilliseconds(1000); sduObjectInit(&SDU1); sduStart(&SDU1, &serusbcfg); usbConnectBus(serusbcfg.usbp); palClearPad(GPIOC, GPIOC_USB_DISC); /* * Shell manager initialization. */ shellInit(); /* * Creates the blinker thread. */ chThdCreateStatic(waBurner, sizeof(waBurner), NORMALPRIO, Burner, &SDU1); i2cStart(&I2CD1, &i2cfg1); EepromOpen(&EepromFile); /* tune ports for I2C1*/ palSetPadMode(IOPORT2, 6, PAL_MODE_STM32_ALTERNATE_OPENDRAIN); palSetPadMode(IOPORT2, 7, PAL_MODE_STM32_ALTERNATE_OPENDRAIN); // BKP->DR1 = 0; // BKP->DR2 = 0; // BKP->DR3 = 0; /* * Normal main() thread activity, in this demo it does nothing except * sleeping in a loop and check the button state. */ while (TRUE) { if (!shelltp && (SDU1.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. */ } chThdSleepMilliseconds(1000); } }
/* * Application entry point. */ int main(void) { 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(); /* * Activates the serial driver 1 using the driver default configuration. */ sdStart(&SERIAL_DRIVER, NULL); /* * Initializes the PWM driver. */ pwmStart(&PWM_DRIVER, &pwmcfg); /* * Initializes the GPT driver. */ gptStart(&GPT_DRIVER, &gptcfg); /* * Initializes the EXT driver. */ extStart(&EXT_DRIVER, &extcfg); /* * Shell manager initialization. */ shellInit(); /* * Creates the blinker thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); /* * Normal main() thread activity, in this demo it does nothing except * sleeping in a loop and check the button state. */ while (TRUE) { if (!shelltp) shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); else if (chThdTerminated(shelltp)) { chThdRelease(shelltp); shelltp = NULL; } chprintf(&SERIAL_DRIVER, "M: %6umm T1: %6u T2: %6u\r\n", measure / 2, tmp1, tmp2); chThdSleepMilliseconds(200); } }
void vshellRestart(bool_t active) { if (!shelltp && 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. */ } }
void usbcdc_process(void) { if (!shelltp && (SDU1.config->usbp->state == USB_ACTIVE)) shelltp = shellCreate(&shell_cfg2, SHELLUSB_WA_SIZE, NORMALPRIO); else if (chThdTerminated(shelltp)) { chThdRelease(shelltp); /* Recovers memory of the previous shell. */ shelltp = NULL; /* Triggers spawning of a new shell. */ } }
/* * Application entry point. */ int main(void) { thread_t *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(); #if defined(DEBUG_USB) palSetPadMode(GPIOA, 1, PAL_MODE_ALTERNATIVE_2); palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATIVE_2); sdStart(&SD1, &s0cfg); #endif /* DEBUG_USB */ /* * 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+. * Note, a delay is inserted in order to not have to disconnect the cable * after a reset. */ usbDisconnectBus(serusbcfg.usbp); #if defined(DEBUG_USB) usb_debug_init(); #endif /* DEBUG_USB */ chThdSleepMilliseconds(1000); usbStart(serusbcfg.usbp, &usbcfg); usbConnectBus(serusbcfg.usbp); /* * Shell manager initialization. */ shellInit(); while (!chThdShouldTerminateX()) { if (!shelltp && (serusbcfg.usbp->state == USB_ACTIVE)) shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); else if (chThdTerminatedX(shelltp)) { chThdRelease(shelltp); /* Recovers memory of the previous shell. */ shelltp = NULL; /* Triggers spawning of a new shell. */ } chThdSleepMilliseconds(1000); palTogglePad(GPIOB, GPIOB_LED); } return 0; }
/* * Application entry point. */ int main(void) { 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(); /* * 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+. * 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); chThdSleepMilliseconds(100); /* * Shell manager initialization. */ shellInit(); /* * Initializes the SDIO drivers. */ mmcObjectInit(&MMCD1); mmcStart(&MMCD1, &mmccfg); /* * Normal main() thread activity, in this demo it does nothing except * sleeping in a loop and check the button state. */ while (TRUE) { if (!shelltp && (SDU1.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. */ } chThdSleepMilliseconds(1000); } }
/* * Application entry point. */ int main(void) { 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(); /* * Activates the serial driver 1 using the driver default configuration. */ sdStart(&SD1, NULL); /* * Shell manager initialization. */ shellInit(); /* * Creates the blinker thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); /* * Normal main() thread activity. */ while (TRUE) { if (!shelltp) 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. */ } #if 0 if (SIU.GPDI[GPIO_BUTTON1].B.PDI) { volatile msg_t result; #if 0 MemoryStream report; msObjectInit(&report, report_buffer, sizeof(report_buffer), 0); result = TestThread(&report); #else result = TestThread(&SD1); #endif } #endif chThdSleepMilliseconds(1000); } return 0; }
/* * Application entry point. */ int main(void) { static const evhandler_t evhndl[] = { InsertHandler, RemoveHandler }; Thread *shelltp = NULL; struct EventListener el0, el1; /* * 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(); /* * Activates the serial driver 1 and SDC driver 1 using default * configuration. */ sdStart(&SD1, NULL); sdcStart(&SDCD1, NULL); /* * Shell manager initialization. */ shellInit(); /* * Activates the card insertion monitor. */ tmr_init(&SDCD1); /* * Creates the blinker thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); /* * Normal main() thread activity, in this demo it does nothing except * sleeping in a loop and listen for events. */ chEvtRegister(&inserted_event, &el0, 0); chEvtRegister(&removed_event, &el1, 1); while (TRUE) { if (!shelltp) 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, chEvtWaitOne(ALL_EVENTS)); } }
/* * Application entry point. */ int main(void) { Thread *shelltp0 = NULL; Thread *shelltp2 = NULL; //unsigned int i = 0; /* * 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+. * Note, a delay is inserted in order to not have to disconnect the cable * after a reset. */ usbDisconnectBus(serusbcfg.usbp); chThdSleepMilliseconds(1500); usbStart(serusbcfg.usbp, &usbcfg); usbConnectBus(serusbcfg.usbp); /* added by myself */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); /* added by myself */ /* * Normal main() thread activity, in this demo it just performs * a shell respawn upon its termination. */ while (1) { if (!shelltp0) { if (SDU1.config->usbp->state == USB_ACTIVE) { /* Spawns a new shell.*/ shelltp0 = shellCreate(&shell_cfg0, SHELL_WA_SIZE, NORMALPRIO); } } else { /* If the previous shell exited.*/ if (chThdTerminated(shelltp0)) { /* Recovers memory of the previous shell.*/ chThdRelease(shelltp0); shelltp0 = NULL; } } chThdSleepMilliseconds(1000); } }
/* * Application entry point. */ int main(void) { 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(); /* * Activates the serial driver 1 using the driver default configuration. */ sdStart(&SD1, NULL); /* * Shell manager initialization. */ shellInit(); /* * Starts the LED blinker thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); sduObjectInit(&SDU1); sduStart(&SDU1, &serusbcfg); usbStart(serusbcfg.usbp, &usbcfg); usbDisconnectBus(serusbcfg.usbp); chThdSleepMilliseconds(1000); usbConnectBus(serusbcfg.usbp); /* * Normal main() thread activity, in this demo it does nothing except * sleeping in a loop and listen for events. */ while (TRUE) { /* if (!shelltp) {*/ if (!shelltp && (SDU1.config->usbp->state == USB_ACTIVE)) { /* chprintf((BaseSequentialStream *)&SD1, "USB Active\r\n");*/ 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. */ } chThdSleepMilliseconds(100); } return 0; }
/* * Application entry point. */ int main(void) { /* * Shell thread */ 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(); /* * Activate custom stuff */ // mypwmInit(); // myADCinit(); // mySPIinit(); motorInit(); /* * Activates the USB driver and then the USB bus pull-up on D+. */ // myUSBinit(); /* * Main loop, does nothing except spawn a shell when the old one was terminated */ while (TRUE) { setMotorData(1300,1490); if (!shelltp && isUsbActive()) { 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. */ } chThdSleepMilliseconds(1000); } }
int main(void) { Thread *shelltp = NULL; short timeout = 0; // 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(); // Init the serial port associated with the console vexConsoleInit(); // use digital 10 as safety //if( palReadPad( VEX_DIGIO_10_PORT, VEX_DIGIO_10_PIN) == 1) // init VEX vexCortexInit(); // wait for good spi comms while( vexSpiGetOnlineStatus() == 0 ) { // wait for a while chThdSleepMilliseconds(100); // dump after 5 seconds if(timeout++ == 50) break; } // Shell manager initialization. shellInit(); // spin in loop monitoring the shell while (TRUE) { if (!shelltp) 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. */ } chThdSleepMilliseconds(50); } }
/* * Application entry point. */ int main(void) { thread_t *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(); /* * Shell manager initialization. */ shellInit(); /* * Activates the serial driver 6 using the driver default configuration. */ sdStart(&SD6, NULL); /* * Initializes the SDIO drivers. */ sdcStart(&SDCD1, &sdccfg); /* * Creates the blinker thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); /* * Normal main() thread activity, in this demo it does nothing. */ while (true) { if (!shelltp) shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); else if (chThdTerminatedX(shelltp)) { chThdRelease(shelltp); /* Recovers memory of the previous shell. */ shelltp = NULL; /* Triggers spawning of a new shell. */ } chThdSleepMilliseconds(1000); } }
/* * Application entry point. */ int main(void) { 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(); /* * Activates the USB driver and then the USB bus pull-up on D+. */ sduObjectInit(&SDU1); sduStart(&SDU1, &serusbcfg); usbDisconnectBus(serusbcfg.usbp); chThdSleepMilliseconds(100); usbConnectBus(serusbcfg.usbp); /* * Shell manager initialization. */ shellInit(); /* * Creates the blinker thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); /* * Normal main() thread activity, in this demo it does nothing except * sleeping in a loop and check the button state. */ while (TRUE) { if (!shelltp && (SDU1.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. */ } chThdSleepMilliseconds(1000); } }
/* * Application entry point. */ int main(void) { thread_t* 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(); /* * Activates the serial driver 2 using the driver default configuration. */ sdStart(&SD1, NULL); shellInit(); /* * Creates the blinker thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); /* * Normal main() thread activity, in this demo it does nothing except * sleeping in a loop and check the button state. */ while (true) { if(!shelltp) { shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); } else if(chThdTerminatedX(shelltp)) { chThdRelease(shelltp); shelltp = NULL; } chThdSleepMilliseconds(1000); } }
/** * @brief Returns the thread next to the specified one. * @details The reference counter of the specified thread is decremented and * the reference counter of the returned thread is incremented. * * @param[in] tp pointer to the thread * @return A reference to the next thread. * @retval NULL if there is no next thread. * * @api */ thread_t *chRegNextThread(thread_t *tp) { thread_t *ntp; chSysLock(); ntp = tp->p_newer; if (ntp == (thread_t *)&ch.rlist) ntp = NULL; #if CH_CFG_USE_DYNAMIC else { chDbgAssert(ntp->p_refs < 255, "too many references"); ntp->p_refs++; } #endif chSysUnlock(); #if CH_CFG_USE_DYNAMIC chThdRelease(tp); #endif return ntp; }
/** * @brief Returns the thread next to the specified one. * @details The reference counter of the specified thread is decremented and * the reference counter of the returned thread is incremented. * * @param[in] tp pointer to the thread * @return A reference to the next thread. * @retval NULL if there is no next thread. * * @api */ Thread *chRegNextThread(Thread *tp) { Thread *ntp; chSysLock(); ntp = tp->p_newer; if (ntp == (Thread *)&rlist) ntp = NULL; #if CH_USE_DYNAMIC else { chDbgAssert(ntp->p_refs < 255, "chRegNextThread(), #1", "too many references"); ntp->p_refs++; } #endif chSysUnlock(); #if CH_USE_DYNAMIC chThdRelease(tp); #endif return ntp; }
//----------------------------------------------------------------------------- int main(void) { halInit(); chSysInit(); kuroBoxInit(); chprintf(prnt, "Starting... [%s] \n", BOARD_NAME); kbg_setLCDBacklight(1); memset(&factory_config, 0, sizeof(factory_config)); cmd_read(prnt, 0, NULL); cmd_print(prnt, 0, NULL); Thread * shelltp = NULL; while ( 1 ) { if (!shelltp) { shelltp = shellCreate(&shell_cfg, SHELL_WA_SIZE, NORMALPRIO); } else if (chThdTerminated(shelltp)) { chThdRelease(shelltp); shelltp = NULL; } } //-------------------------------------------------------------------------- // endless loop to say we've finished while(1) { kbg_setLED1(0); kbg_setLED2(0); kbg_setLED3(0); chThdSleepMilliseconds(200); kbg_setLED1(1); kbg_setLED2(1); kbg_setLED3(1); chThdSleepMilliseconds(200); } }
/** * @brief Blocks the execution of the invoking thread until the specified * thread terminates then the exit code is returned. * @details This function waits for the specified thread to terminate then * decrements its reference counter, if the counter reaches zero then * the thread working area is returned to the proper allocator.<br> * The memory used by the exited thread is handled in different ways * depending on the API that spawned the thread: * - If the thread was spawned by @p chThdCreateStatic() or by * @p chThdInit() then nothing happens and the thread working area * is not released or modified in any way. This is the default, * totally static, behavior. * - If the thread was spawned by @p chThdCreateFromHeap() then * the working area is returned to the system heap. * - If the thread was spawned by @p chThdCreateFromMemoryPool() * then the working area is returned to the owning memory pool. * . * @pre The configuration option @p CH_USE_WAITEXIT must be enabled in * order to use this function. * @post Enabling @p chThdWait() requires 2-4 (depending on the * architecture) extra bytes in the @p Thread structure. * @post After invoking @p chThdWait() the thread pointer becomes invalid * and must not be used as parameter for further system calls. * @note If @p CH_USE_DYNAMIC is not specified this function just waits for * the thread termination, no memory allocators are involved. * * @param[in] tp pointer to the thread * @return The exit code from the terminated thread. * * @api */ msg_t chThdWait(Thread *tp) { msg_t msg; chDbgCheck(tp != NULL, "chThdWait"); chSysLock(); chDbgAssert(tp != currp, "chThdWait(), #1", "waiting self"); #if CH_USE_DYNAMIC chDbgAssert(tp->p_refs > 0, "chThdWait(), #2", "not referenced"); #endif if (tp->p_state != THD_STATE_FINAL) { list_insert(currp, &tp->p_waiting); chSchGoSleepS(THD_STATE_WTEXIT); } msg = tp->p_u.exitcode; chSysUnlock(); #if CH_USE_DYNAMIC chThdRelease(tp); #endif return msg; }
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); } }