/* * Application entry point. */ 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(); palSetPadMode(GPIOF, GPIOF_LED_RED, PAL_MODE_OUTPUT_PUSHPULL); /* * Start the gpt drivers with the custom configurations. */ gptStart(&GPTD1, &gpt1cfg); gptStart(&GPTD7, &gpt7cfg); /* * Normal main() thread activity */ while (TRUE) { gptStartContinuous(&GPTD7, 5000); chThdSleepMilliseconds(5000); gptStopTimer(&GPTD7); gptStartContinuous(&GPTD7, 2500); chThdSleepMilliseconds(5000); gptStopTimer(&GPTD7); } return 0; }
/* * Application entry point. */ 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 the GPT drivers 2 and 3. */ gptStart(&GPTD2, &gpt2cfg); gptPolledDelay(&GPTD2, 10); /* Small delay.*/ gptStart(&GPTD3, &gpt3cfg); gptPolledDelay(&GPTD3, 10); /* Small delay.*/ /* * Normal main() thread activity, it changes the GPT1 period every * five seconds. */ while (TRUE) { palSetPad(GPIOD, GPIOD_LED4); gptStartContinuous(&GPTD2, 5000); chThdSleepMilliseconds(5000); gptStopTimer(&GPTD2); palClearPad(GPIOD, GPIOD_LED4); gptStartContinuous(&GPTD2, 2500); chThdSleepMilliseconds(5000); gptStopTimer(&GPTD2); } }
/* Private functions ---------------------------------------------------------*/ void dcf_init(void) { palSetPadMode(DCF_PORT, DCF_PIN, PAL_MODE_INPUT); DBGMCU->CR |= DBGMCU_CR_DBG_TIM3_STOP; shFillStruct(&del, dcf_task, NULL, MS2ST(100), PERIODIC); gptStart(timer, &gpt); gptStart(secs , &sec_gpt); gptStartContinuous(secs,10000); }
void timer_init(void) { // start system tick timer gptStart (&GPTD3, &gpt3cfg); gptStartContinuous (&GPTD3, TICK_TIME_MS * 1000); // start stepper timer timer1_interval = 50000; // nominal rate gptStart (&GPTD1, &gpt1cfg); //gptStartOneShot (&GPTD1, timer1_interval); }
void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat) { if (!audio_initialized) { audio_init(); } if (audio_config.enable) { // Cancel note if a note is playing if (playing_note) { stop_all_notes(); } playing_notes = true; notes_pointer = np; notes_count = n_count; notes_repeat = n_repeat; place = 0; current_note = 0; note_frequency = (*notes_pointer)[current_note][0]; note_length = ((*notes_pointer)[current_note][1] / 4) * (((float)note_tempo) / 100); note_position = 0; gptStart(&GPTD8, &gpt8cfg1); gptStartContinuous(&GPTD8, 2U); RESTART_CHANNEL_1(); RESTART_CHANNEL_2(); } }
void play_note(float freq, int vol) { dprintf("audio play note freq=%d vol=%d", (int)freq, vol); if (!audio_initialized) { audio_init(); } if (audio_config.enable && voices < 8) { // Cancel notes if notes are playing if (playing_notes) { stop_all_notes(); } playing_note = true; envelope_index = 0; if (freq > 0) { frequencies[voices] = freq; volumes[voices] = vol; voices++; } gptStart(&GPTD8, &gpt8cfg1); gptStartContinuous(&GPTD8, 2U); RESTART_CHANNEL_1(); RESTART_CHANNEL_2(); } }
int main(void) { // performs all the init required to use various peripherals halInit(); // gets the operating system code up and running // one of the timer unit is init to generate interrupts at a spec rate chSysInit(); // configure the I/O pin palSetPadMode(GPIOD, GPIOD_LED6, PAL_MODE_OUTPUT_PUSHPULL); palSetPadMode(GPIOD, GPIOD_LED5, PAL_MODE_OUTPUT_PUSHPULL); // configure the GPT Timer gptStart(&GPTD2, &gptcfg); // start timer in continuous mode gptStartContinuous(&GPTD2, 10); // 70KHz while (TRUE) { // sets a pin high palSetPad(GPIOD, GPIOD_LED5); // generates a 500ms delay // OS immediately shutsdown processor core & switches to low power mode chThdSleepMilliseconds(500); // sets a pin low palClearPad(GPIOD, GPIOD_LED5); chThdSleepMilliseconds(500); } }
/* * Application entry point. */ 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(); palSetPadMode(IOPORT2, 7, PAL_MODE_OUTPUT_PUSHPULL); sdStart(&SD1, NULL); gptStart(&GPTD1, &gpt2cfg); gptStartContinuous(&GPTD1, 500); while (1) { chprintf(&SD1, "OCR1A: %d, TCCR1B: %x, period: %d, counter: %d , TCNT1: %d\r\n", OCR1A, TCCR1B, GPTD1.period, GPTD1.counter, TCNT1); chThdSleepMilliseconds(100); } }
static msg_t VexSonarTask( void *arg ) { tVexSonarChannel c; (void)arg; chRegSetThreadName("sonar"); gptStart( sonarGpt, &vexSonarGpt ); while(!chThdShouldTerminate()) { if( vexSonars[nextSonar].flags == (SONAR_INSTALLED | SONAR_ENABLED) ) { // ping sonar vexSonarPing(nextSonar); // wait for next time slot // the timer is set to timeout in 40mS but we need a 10mS gap before any more // pings can be sent chThdSleepUntil(chTimeNow() + 50); // calculate echo time vexSonars[nextSonar].time = vexSonars[nextSonar].time_f - vexSonars[nextSonar].time_r; // was the time too great ? if( vexSonars[nextSonar].time > 35000 ) vexSonars[nextSonar].time = -1; // if we have a valid time calculate real distance if( vexSonars[nextSonar].time != -1 ) { vexSonars[nextSonar].distance_cm = vexSonars[nextSonar].time / 58; vexSonars[nextSonar].distance_inch = vexSonars[nextSonar].time / 148; } else { vexSonars[nextSonar].distance_cm = -1; vexSonars[nextSonar].distance_inch = -1; } // look for next sonar for(c=kVexSonar_1;c<kVexSonar_Num;c++) { if( ++nextSonar == kVexSonar_Num ) nextSonar = kVexSonar_1; // we need sonar to be installed and enabled if( vexSonars[nextSonar].flags == (SONAR_INSTALLED | SONAR_ENABLED) ) break; } } else // Nothing enabled, just wait chThdSleepMilliseconds(25); } return (msg_t)0; }
/* * Application entry point. */ 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 the GPT driver 1. */ gptStart(&GPTD1, &gpt1cfg); #if !POLLED_TEST gptStartContinuous(&GPTD1, 2); #endif while (1) { #if POLLED_TEST gpt_lld_polled_delay(&GPTD1, 1) ; palTogglePad(GPIOB, GPIOB_LED); #else chThdSleepMilliseconds(500); #endif } }
/* * 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); } }
static void timer_config(){ static GPTConfig const timer_config = { (FRDMSlave::sample_rate * 1000) / FRDMSlave::samples_per_transfer, (gptcallback_t) timer_cb }; gptObjectInit(timer_driver); gptStart(timer_driver, &timer_config); }
BOOL xMBPortTimersInit( USHORT usTim1Timerout50us ) { timerout = usTim1Timerout50us*((500*1000)/gptcfg.frequency); gptStart(&GPTDRIVER, &gptcfg); #ifdef DEBUG_MB tmObjectInit (&tm); #endif return TRUE; }
/* * Application entry point. */ 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(); /* * Activates the serial driver 1 using the driver default configuration. */ sdStart(&SD1, NULL); /* * Starting GPT4 driver, it is used for triggering the ADC. */ gptStart(&GPTD4, &gpt4cfg1); /* * Fixed an errata on the STM32F7xx, the DAC clock is required for ADC * triggering. */ rccEnableDAC1(false); /* * Activates the ADC1 driver and the temperature sensor. */ adcStart(&ADCD1, NULL); adcSTM32EnableTSVREFE(); /* * Starts an ADC continuous conversion triggered with a period of * 1/10000 second. */ adcStartConversion(&ADCD1, &adcgrpcfg1, samples1, ADC_GRP1_BUF_DEPTH); gptStartContinuous(&GPTD4, 100); /* * Creates the example thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); /* * Normal main() thread activity, in this demo it does nothing. */ while (true) { chThdSleepMilliseconds(500); } }
void TimeKeeper::start(void) { unix_usec = rtc_get_time_unix_usec(); gptStart(&RTC_GPTD, &gptcfg); gptStartContinuous(&RTC_GPTD, RTC_TIMER_STEP); worker = chThdCreateStatic(TimekeeperThreadWA, sizeof(TimekeeperThreadWA), TIMEKEEPERPRIO, TimekeeperThread, this); osalDbgCheck(nullptr != worker); // Can not allocate memory Exti.pps(true); ready = true; }
void initMicrosecondTimer(void) { gptStart(&GPTDEVICE, &gpt5cfg); lastSetTimerTimeNt = getTimeNowNt(); #if EFI_EMULATE_POSITION_SENSORS chThdCreateStatic(mwThreadStack, sizeof(mwThreadStack), NORMALPRIO, (tfunc_t) mwThread, NULL); #endif /* EFI_ENGINE_EMULATOR */ // // test code // chSysLock() // ; // setHardwareUsTimer(300); // chSysUnlock() // ; }
/* * Application entry point. */ 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(); /* * Starting DAC1 driver, setting up the output pins as analog as suggested * by the Reference Manual. */ palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_ANALOG); palSetPadMode(GPIOA, 5, PAL_MODE_INPUT_ANALOG); dacStart(&DACD1, &dac1cfg1); /* * Starting GPT6 driver, it is used for triggering the DAC. */ gptStart(&GPTD6, &gpt6cfg1); /* * Starting a continuous conversion. * Note, the buffer size is divided by two because two elements are fetched * for each transfer. */ dacStartConversion(&DACD1, &dacgrpcfg1, (dacsample_t *)dac_buffer, DAC_BUFFER_SIZE / 2U); gptStartContinuous(&GPTD6, 2U); /* * Normal main() thread activity, if the button is pressed then the DAC * transfer is stopped. */ while (true) { if (palReadPad(GPIOA, GPIOA_BUTTON)) { gptStopTimer(&GPTD6); dacStopConversion(&DACD1); } chThdSleepMilliseconds(500); } return 0; }
void initMicrosecondTimer(void) { gptStart(&GPTDEVICE, &gpt5cfg); efiAssertVoid(CUSTOM_ERR_TIMER_STATE, GPTDEVICE.state == GPT_READY, "hw state"); lastSetTimerTimeNt = getTimeNowNt(); #if EFI_EMULATE_POSITION_SENSORS watchdogControllerInstance.Start(); #endif /* EFI_ENGINE_EMULATOR */ // // test code // chSysLock() // ; // setHardwareUsTimer(300); // chSysUnlock() // ; }
void vexSpiInit() { uint16_t i; // initialize the tx data for(i=0;i<32;i++) vexSpiData.txdata.data[i] = txInitData[i]; vexSpiData.online = 0; // Initializes the SPI driver 1. spiStart(&SPID1, &spicfg); // start timer gptStart( spiGpt, &vexSpiGpt ); }
static void adctodac(void *arg) { uint16_t temp = 0; adcStart(&ADCD1, &adccfg); dacStart(&DACD1, &dac1cfg1); gptStart(&GPTD6, &gpt6cfg1); while(!0) { adcStartConversion(&ADCD1, &adccg, samples_buf, ADC_BUF_DEPTH); temp = samples_buf[0]; //dacPutChannelX(&DACD1, 1U, temp); dacStartConversion(&DACD1, &dacgrpcfg1, samples_buf, ADC_BUF_DEPTH); gptStartContinuous(&GPTD6, 2U); chThdSleepMilliseconds(1); } }
msg_t app_thread(void *arg) { uint32_t cnt; (void) arg; cnt = 0; print("Hello from APP1\r\n"); gptStart(&GPTD3, &gpt3cfg); gptStartContinuous(&GPTD3, 500); print("GPTD3 started\r\n"); while (TRUE) { cnt++; /*test(cnt);*/ chThdSleepMilliseconds(5000); } return 0; }
//----------------------------------------------------------------------------- int kuroBoxInit(void) { kbg_setLED1(1); kbg_setLED2(1); kbg_setLED3(1); // Serial sdStart(&SD1, &serial1_cfg); sdStart(&SD2, &serial2_cfg); // start the SPI bus, just use the LCD's SPI config since // it's shared with the eeprom spiStart(&SPID1, &lcd_cfg.spicfg); memset(lcd_buffer, 0, sizeof(lcd_buffer)); st7565Start(&ST7565D1, &lcd_cfg, &SPID1, lcd_buffer); // EEPROM spiEepromStart(&spiEepromD1, &eeprom_cfg, &SPID1); // this turns on Layer 1 power, this turns on the mosfets controlling the // VCC rail. After this, we can start GPS, VectorNav and altimeter kbg_setL1PowerOn(); // wait for it to stabilise, poweron devices, and let them start before continuing chThdSleepMilliseconds(500); // set initial button state. kuroBoxButtonsInit(); gptStart(&GPTD2, &one_sec_cfg); // indicate we're ready chThdSleepMilliseconds(100); kbg_setLED1(0); kbg_setLED2(0); kbg_setLED3(0); // all external interrupts, all the system should now be ready for it extStart(&EXTD1, &extcfg); return KB_OK; }
/* * Application entry point. */ 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(); static GPTConfig gpt2cfg = { 2000, /* timer clock.*/ gpt2cb /* Timer callback.*/ }; DDRB |= _BV(DDB7); sdStart(&SD1, NULL); gptStart(&GPTD1,&gpt2cfg); gptStartContinuous(&GPTD1, 500); while(1){ chprintf(&SD1,"OCR1A: %d, TCCR1B, %x, period %d, counter: %d , TCNT1 %d\n",OCR1A,TCCR1B,GPTD1.period,GPTD1.counter,TCNT1); chThdSleepMilliseconds(100); } }
/* * Application entry point. */ int main(void) { halInit(); chSysInit(); /* * Set PA3 - PA1 to Analog (DAC1_CH1, OPAMP1_INP) * You will have to connect these with a jumper wire */ palSetPadMode(GPIOA, 3, PAL_MODE_INPUT_ANALOG); palSetPadMode(GPIOA, 1, PAL_MODE_INPUT_ANALOG); /* * Start peripherals */ dacStart(&DACD1, &dac1cfg1); opampStart(&OPAMPD1, &opamp1_conf); gptStart(&GPTD6, &gpt6cfg1); /* * Starting a continuous conversion. */ dacStartConversion(&DACD1, &dacgrpcfg1, dac_buffer, DAC_BUFFER_SIZE); gptStartContinuous(&GPTD6, 2U); opampEnable(&OPAMPD1); opampCalibrate(); /* * Normal main() thread activity. */ while (true) { chThdSleepMilliseconds(250); palToggleLine(LINE_LED3_RED); } return 0; }
//----------------------------------------------------------------------------- int kuroBoxVectorNavInit(VectorNavDriver * nvp, const VectorNavConfig * cfg) { if ( cfg ) nvp->cfgp = cfg; else nvp->cfgp = &default_vectornav_config; spiStart(nvp->spip, &nvp->cfgp->spicfg); gptStart(nvp->gpdp, &nvp->cfgp->gptcfg); uint8_t header_data[VN100_REG_USER_TAG_SIZE+ VN100_REG_MODEL_SIZE+ VN100_REG_HWREV_SIZE+ VN100_REG_SN_SIZE+ VN100_REG_FWVER_SIZE]; uint8_t * header_data_ptr = header_data; kbv_readRegister(nvp, VN100_REG_USER_TAG, VN100_REG_USER_TAG_SIZE, header_data_ptr); header_data_ptr += VN100_REG_USER_TAG_SIZE; kbv_readRegister(nvp, VN100_REG_MODEL, VN100_REG_MODEL_SIZE, header_data_ptr); header_data_ptr += VN100_REG_MODEL_SIZE; kbv_readRegister(nvp, VN100_REG_HWREV, VN100_REG_HWREV_SIZE, header_data_ptr); header_data_ptr += VN100_REG_HWREV_SIZE; kbv_readRegister(nvp, VN100_REG_SN, VN100_REG_SN_SIZE, header_data_ptr); header_data_ptr += VN100_REG_SN_SIZE; kbv_readRegister(nvp, VN100_REG_FWVER, VN100_REG_FWVER_SIZE, header_data_ptr); header_data_ptr += VN100_REG_FWVER_SIZE; kbwh_setVNav(header_data, header_data_ptr-header_data); return KB_OK; }
/* * 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 2 using the driver default configuration. */ initSerialHw(); /* * Initialize GPT driver 3 */ gptStart(&GPT_DRIVER, &gpt3cfg); /* * Initialize the MMC over SPI hardware */ chprintf((BaseSequentialStream *)&SERIAL_DRIVER, "Initializing MMC Hardware...\r\n"); initMMCSpiHw(); chprintf((BaseSequentialStream *)&SERIAL_DRIVER, "Mounting filesystem ...\r\n"); /* Do an initial ls */ if (mountFS()) { chprintf((BaseSequentialStream *)&SERIAL_DRIVER, "Listing files on the SD card ...\r\n"); scan_files((BaseSequentialStream *)&SERIAL_DRIVER, rootpath); } /* Initialize I2C1 */ initI2CHw(); /* Initalize CC3000 Hardware */ chprintf((BaseSequentialStream *)&SERIAL_DRIVER,"Initializing CC3000 SPI hardware ..."); initCC3000SpiHw(); chprintf((BaseSequentialStream *)&SERIAL_DRIVER,"done!\r\n"); chprintf((BaseSequentialStream *)&SERIAL_DRIVER,"Initializing CC3000 ...\r\n"); initCC3000Hw(); /* * Creates the blinker thread. */ chThdCreateStatic(waThread2, sizeof(waThread2), NORMALPRIO, Thread2, NULL); /* * Shell manager initialization. */ shellInit(); /* * Normal main() thread activity, in this demo it does nothing except * sleeping in a loop and listen for events. */ while (TRUE) { if (!shelltp) shelltp = shellCreate(&shell_cfg, 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(500); } }
//Use this to turn on the timer static void prepareTimer(void){ gptStart(&GPTD3, &gpt3cfg); return; }
/** * @brief IRQ storm execution. * * @param[in] cfg pointer to the test configuration structure * * @api */ void irq_storm_execute(const irq_storm_config_t *cfg) { unsigned i; gptcnt_t interval, threshold, worst; /* Global configuration pointer.*/ config = cfg; /* Starting timers using the stored configurations.*/ gptStart(cfg->gpt1p, cfg->gptcfg1p); gptStart(cfg->gpt2p, cfg->gptcfg2p); /* * Initializes the mailboxes and creates the worker threads. */ for (i = 0; i < IRQ_STORM_CFG_NUM_THREADS; i++) { chMBObjectInit(&mb[i], b[i], IRQ_STORM_CFG_MAILBOX_SIZE); threads[i] = chThdCreateStatic(irq_storm_thread_wa[i], sizeof irq_storm_thread_wa[i], IRQ_STORM_CFG_THREADS_PRIORITY, irq_storm_thread, (void *)i); } /* Printing environment information.*/ chprintf(cfg->out, ""); chprintf(cfg->out, "\r\n*** ChibiOS/RT IRQ-STORM long duration test\r\n***\r\n"); chprintf(cfg->out, "*** Kernel: %s\r\n", CH_KERNEL_VERSION); chprintf(cfg->out, "*** Compiled: %s\r\n", __DATE__ " - " __TIME__); #ifdef PORT_COMPILER_NAME chprintf(cfg->out, "*** Compiler: %s\r\n", PORT_COMPILER_NAME); #endif chprintf(cfg->out, "*** Architecture: %s\r\n", PORT_ARCHITECTURE_NAME); #ifdef PORT_CORE_VARIANT_NAME chprintf(cfg->out, "*** Core Variant: %s\r\n", PORT_CORE_VARIANT_NAME); #endif chprintf(cfg->out, "*** System Clock: %d\r\n", cfg->sysclk); #ifdef PORT_INFO chprintf(cfg->out, "*** Port Info: %s\r\n", PORT_INFO); #endif #ifdef PLATFORM_NAME chprintf(cfg->out, "*** Platform: %s\r\n", PLATFORM_NAME); #endif #ifdef BOARD_NAME chprintf(cfg->out, "*** Test Board: %s\r\n", BOARD_NAME); #endif chprintf(cfg->out, "***\r\n"); chprintf(cfg->out, "*** Iterations: %d\r\n", IRQ_STORM_CFG_ITERATIONS); chprintf(cfg->out, "*** Randomize: %d\r\n", IRQ_STORM_CFG_RANDOMIZE); chprintf(cfg->out, "*** Threads: %d\r\n", IRQ_STORM_CFG_NUM_THREADS); chprintf(cfg->out, "*** Mailbox size: %d\r\n\r\n", IRQ_STORM_CFG_MAILBOX_SIZE); /* Test loop.*/ worst = 0; for (i = 1; i <= IRQ_STORM_CFG_ITERATIONS; i++){ chprintf(cfg->out, "Iteration %d\r\n", i); saturated = false; threshold = 0; /* Timer intervals starting at 2mS then decreased by 10% after each cycle.*/ for (interval = 2000; interval >= 2; interval -= (interval + 9) / 10) { /* Timers programmed slightly out of phase each other.*/ gptStartContinuous(cfg->gpt1p, interval - 1); /* Slightly out of phase.*/ gptStartContinuous(cfg->gpt2p, interval + 1); /* Slightly out of phase.*/ /* Storming for one second.*/ chThdSleepMilliseconds(1000); /* Timers stopped.*/ gptStopTimer(cfg->gpt1p); gptStopTimer(cfg->gpt2p); /* Did the storm saturate the threads chain?*/ if (!saturated) chprintf(cfg->out, "."); else { chprintf(cfg->out, "#"); if (threshold == 0) threshold = interval; break; } } /* Gives threads a chance to empty the mailboxes before next cycle.*/ chThdSleepMilliseconds(20); chprintf(cfg->out, "\r\nSaturated at %d uS\r\n\r\n", threshold); if (threshold > worst) worst = threshold; } gptStopTimer(cfg->gpt1p); gptStopTimer(cfg->gpt2p); chprintf(cfg->out, "Worst case at %d uS\r\n", worst); chprintf(cfg->out, "\r\nTest Complete\r\n"); /* Terminating threads and cleaning up.*/ for (i = 0; i < IRQ_STORM_CFG_NUM_THREADS; i++) { chThdTerminate(threads[i]); chThdWait(threads[i]); threads[i] = NULL; } }
/* * Application entry point. */ int main(void) { unsigned i; gptcnt_t interval, threshold, worst; /* * 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(); /* * Prepares the Serial driver 2 and GPT drivers 1 and 2. */ sdStart(&SD1, NULL); /* Default is 38400-8-N-1.*/ gptStart(&GPTD1, &gpt1cfg); gptStart(&GPTD2, &gpt2cfg); /* * Initializes the mailboxes and creates the worker threads. */ for (i = 0; i < NUM_THREADS; i++) { chMBInit(&mb[i], b[i], MAILBOX_SIZE); chThdCreateStatic(waWorkerThread[i], sizeof waWorkerThread[i], NORMALPRIO - 20, WorkerThread, (void *)i); } /* * Test procedure. */ println(""); println("*** ChibiOS/RT IRQ-STORM long duration test"); println("***"); print("*** Kernel: "); println(CH_KERNEL_VERSION); #ifdef CH_COMPILER_NAME print("*** Compiler: "); println(CH_COMPILER_NAME); #endif print("*** Architecture: "); println(CH_ARCHITECTURE_NAME); #ifdef CH_CORE_VARIANT_NAME print("*** Core Variant: "); println(CH_CORE_VARIANT_NAME); #endif #ifdef CH_PORT_INFO print("*** Port Info: "); println(CH_PORT_INFO); #endif #ifdef PLATFORM_NAME print("*** Platform: "); println(PLATFORM_NAME); #endif #ifdef BOARD_NAME print("*** Test Board: "); println(BOARD_NAME); #endif println("***"); print("*** System Clock: "); printn(LPC13xx_SYSCLK); println(""); print("*** Iterations: "); printn(ITERATIONS); println(""); print("*** Randomize: "); printn(RANDOMIZE); println(""); print("*** Threads: "); printn(NUM_THREADS); println(""); print("*** Mailbox size: "); printn(MAILBOX_SIZE); println(""); println(""); worst = 0; for (i = 1; i <= ITERATIONS; i++){ print("Iteration "); printn(i); println(""); saturated = FALSE; threshold = 0; for (interval = 2000; interval >= 20; interval -= interval / 10) { gptStartContinuous(&GPTD1, interval - 1); /* Slightly out of phase.*/ gptStartContinuous(&GPTD2, interval + 1); /* Slightly out of phase.*/ chThdSleepMilliseconds(1000); gptStopTimer(&GPTD1); gptStopTimer(&GPTD2); if (!saturated) print("."); else { print("#"); if (threshold == 0) threshold = interval; } } /* Gives the worker threads a chance to empty the mailboxes before next cycle.*/ chThdSleepMilliseconds(20); println(""); print("Saturated at "); printn(threshold); println(" uS"); println(""); if (threshold > worst) worst = threshold; } gptStopTimer(&GPTD1); gptStopTimer(&GPTD2); print("Worst case at "); printn(worst); println(" uS"); println(""); println("Test Complete"); /* * Normal main() thread activity, nothing in this test. */ while (TRUE) { chThdSleepMilliseconds(5000); } return 0; }
/* * Application entry point. */ int main(void) { unsigned i; gptcnt_t interval, threshold, worst; /* Enables FPU exceptions.*/ nvicEnableVector(FPU_IRQn, 1); /* * 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(); /* * Prepares the Serial driver 2 and GPT drivers 4 and 3. */ sdStart(&SD2, NULL); /* Default is 38400-8-N-1.*/ palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7)); palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7)); gptStart(&GPTD4, &gpt4cfg); gptStart(&GPTD3, &gpt3cfg); /* * Enabling TIM1 as a fast interrupts source. */ rccEnableTIM1(false); nvicEnableVector(STM32_TIM1_UP_NUMBER, 0); TIM1->ARR = 10000; TIM1->PSC = 0; TIM1->CNT = 0; TIM1->DIER = TIM_DIER_UIE; TIM1->CR1 = TIM_CR1_CEN; /* * Initializes the worker threads. */ chThdCreateStatic(waWorkerThread, sizeof waWorkerThread, NORMALPRIO - 20, WorkerThread, NULL); chThdCreateStatic(waPeriodicThread, sizeof waPeriodicThread, NORMALPRIO - 10, PeriodicThread, NULL); /* * Test procedure. */ println(""); println("*** ChibiOS/RT IRQ-STORM-FPU long duration test"); println("***"); print("*** Kernel: "); println(CH_KERNEL_VERSION); print("*** Compiled: "); println(__DATE__ " - " __TIME__); #ifdef PORT_COMPILER_NAME print("*** Compiler: "); println(PORT_COMPILER_NAME); #endif print("*** Architecture: "); println(PORT_ARCHITECTURE_NAME); #ifdef PORT_CORE_VARIANT_NAME print("*** Core Variant: "); println(PORT_CORE_VARIANT_NAME); #endif #ifdef PORT_INFO print("*** Port Info: "); println(PORT_INFO); #endif #ifdef PLATFORM_NAME print("*** Platform: "); println(PLATFORM_NAME); #endif #ifdef BOARD_NAME print("*** Test Board: "); println(BOARD_NAME); #endif println("***"); print("*** System Clock: "); printn(STM32_SYSCLK); println(""); print("*** Iterations: "); printn(ITERATIONS); println(""); print("*** Randomize: "); printn(RANDOMIZE); println(""); println(""); worst = 0; for (i = 1; i <= ITERATIONS; i++){ print("Iteration "); printn(i); println(""); saturated = FALSE; threshold = 0; for (interval = 2000; interval >= 10; interval -= interval / 10) { gptStartContinuous(&GPTD4, interval - 1); /* Slightly out of phase.*/ gptStartContinuous(&GPTD3, interval + 1); /* Slightly out of phase.*/ chThdSleepMilliseconds(1000); gptStopTimer(&GPTD4); gptStopTimer(&GPTD3); if (!saturated) print("."); else { print("#"); if (threshold == 0) threshold = interval; } } /* Gives the worker threads a chance to empty the mailboxes before next cycle.*/ chThdSleepMilliseconds(20); println(""); print("Saturated at "); printn(threshold); println(" uS"); println(""); if (threshold > worst) worst = threshold; } gptStopTimer(&GPTD4); gptStopTimer(&GPTD3); print("Worst case at "); printn(worst); println(" uS"); println(""); println("Test Complete"); /* * Normal main() thread activity, nothing in this test. */ while (true) { chThdSleepMilliseconds(5000); } }