/** * @brief Initializes the statistics module. * * @init */ void _stats_init(void) { ch.kernel_stats.n_irq = 0; ch.kernel_stats.n_ctxswc = 0; chTMObjectInit(&ch.kernel_stats.m_crit_thd); chTMObjectInit(&ch.kernel_stats.m_crit_isr); }
/** * @brief Initializes a thread structure. * @note This is an internal functions, do not use it in application code. * * @param[in] tp pointer to the thread * @param[in] name thread name * @param[in] prio the priority level for the new thread * @return The same thread pointer passed as parameter. * * @notapi */ thread_t *_thread_init(thread_t *tp, const char *name, tprio_t prio) { tp->prio = prio; #if CH_CFG_TIME_QUANTUM > 0 tp->preempt = (tslices_t)CH_CFG_TIME_QUANTUM; #endif #if CH_CFG_USE_MUTEXES == TRUE tp->realprio = prio; tp->mtxlist = NULL; #endif #if CH_CFG_USE_EVENTS == TRUE tp->epending = (eventmask_t)0; #endif #if CH_DBG_THREADS_PROFILING == TRUE tp->time = (systime_t)0; #endif #if CH_CFG_USE_REGISTRY == TRUE tp->name = name; REG_INSERT(tp); #endif #if CH_CFG_USE_WAITEXIT == TRUE list_init(&tp->waiting); #endif #if CH_CFG_USE_MESSAGES == TRUE queue_init(&tp->msgqueue); #endif #if CH_DBG_STATISTICS == TRUE chTMObjectInit(&tp->stats); #endif CH_CFG_THREAD_INIT_HOOK(tp); return tp; }
Navi6dWrapper::Navi6dWrapper(ACSInput &acs_in, gnss::GNSSReceiver &GNSS) : time_overrun_cnt(0), acs_in(acs_in), GNSS(GNSS) { chTMObjectInit(&tmeas); return; }
/** * @brief Initializes the time measurement unit. * * @init */ void _tm_init(void) { time_measurement_t tm; /* Time Measurement subsystem calibration, it does a null measurement and calculates the call overhead which is subtracted to real measurements.*/ ch.tm.offset = 0; chTMObjectInit(&tm); chTMStartMeasurementX(&tm); chTMStopMeasurementX(&tm); ch.tm.offset = tm.last; }
void membench_run(membench_t *dest, const membench_t *src, membench_result_t *result) { time_measurement_t mem_tmu; size_t len; if (src->size < dest->size) len = src->size; else len = dest->size; /* memset */ chTMObjectInit(&mem_tmu); chTMStartMeasurementX(&mem_tmu); memset(dest->start, 0x55, dest->size); chTMStopMeasurementX(&mem_tmu); result->memset = speed_bps(&mem_tmu, dest->size); /* memcpy */ chTMObjectInit(&mem_tmu); chTMStartMeasurementX(&mem_tmu); memcpy(dest->start, src->start, len); chTMStopMeasurementX(&mem_tmu); result->memcpy = speed_bps(&mem_tmu, len); /* memcmp */ chTMObjectInit(&mem_tmu); chTMStartMeasurementX(&mem_tmu); warning_suppressor = memcmp(dest->start, src->start, len); chTMStopMeasurementX(&mem_tmu); result->memcmp = speed_bps(&mem_tmu, len); /* memcpy DMA */ memcpy_dma_start(); chTMObjectInit(&mem_tmu); chTMStartMeasurementX(&mem_tmu); memcpy_dma(dest->start, src->start, len); chTMStopMeasurementX(&mem_tmu); result->memcpy_dma = speed_bps(&mem_tmu, len); memcpy_dma_stop(); }
/** * @brief Initializes a thread structure. * @note This is an internal functions, do not use it in application code. * * @param[in] tp pointer to the thread * @param[in] prio the priority level for the new thread * @return The same thread pointer passed as parameter. * * @notapi */ thread_t *_thread_init(thread_t *tp, tprio_t prio) { tp->p_prio = prio; tp->p_state = CH_STATE_WTSTART; tp->p_flags = CH_FLAG_MODE_STATIC; #if CH_CFG_TIME_QUANTUM > 0 tp->p_preempt = CH_CFG_TIME_QUANTUM; #endif #if CH_CFG_USE_MUTEXES tp->p_realprio = prio; tp->p_mtxlist = NULL; #endif #if CH_CFG_USE_EVENTS tp->p_epending = 0; #endif #if CH_DBG_THREADS_PROFILING tp->p_time = 0; #endif #if CH_CFG_USE_DYNAMIC tp->p_refs = 1; #endif #if CH_CFG_USE_REGISTRY tp->p_name = NULL; REG_INSERT(tp); #endif #if CH_CFG_USE_WAITEXIT list_init(&tp->p_waiting); #endif #if CH_CFG_USE_MESSAGES queue_init(&tp->p_msgqueue); #endif #if CH_DBG_ENABLE_STACK_CHECK tp->p_stklimit = (stkalign_t *)(tp + 1); #endif #if CH_DBG_STATISTICS || defined(__DOXYGEN__) chTMObjectInit(&tp->p_stats); chTMStartMeasurementX(&tp->p_stats); #endif #if defined(CH_CFG_THREAD_INIT_HOOK) CH_CFG_THREAD_INIT_HOOK(tp); #endif return tp; }
/* * Application entry point. */ int main(void) { /* performance counters */ int32_t adc_ints = 0; int32_t spi_ints = 0; int32_t uart_ints = 0; int32_t adc_idle_ints = 0; int32_t spi_idle_ints = 0; int32_t uart_idle_ints = 0; uint32_t background_cnt = 0; systime_t T = 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(); #if STM32_NAND_USE_EXT_INT extStart(&EXTD1, &extcfg); #endif chTMObjectInit(&tmu_driver_start); chTMStartMeasurementX(&tmu_driver_start); #if USE_BAD_MAP nandStart(&NAND, &nandcfg, &badblock_map); #else nandStart(&NAND, &nandcfg, NULL); #endif chTMStopMeasurementX(&tmu_driver_start); chThdSleepMilliseconds(4000); chThdCreateStatic(BackgroundThreadWA, sizeof(BackgroundThreadWA), NORMALPRIO - 20, BackgroundThread, NULL); nand_wp_release(); /* * run NAND test in parallel with DMA load and background thread */ dma_storm_adc_start(); dma_storm_uart_start(); dma_storm_spi_start(); T = chVTGetSystemTimeX(); general_test(&NAND, NAND_TEST_START_BLOCK, NAND_TEST_END_BLOCK, 1); T = chVTGetSystemTimeX() - T; adc_ints = dma_storm_adc_stop(); uart_ints = dma_storm_uart_stop(); spi_ints = dma_storm_spi_stop(); chSysLock(); background_cnt = BackgroundThdCnt; BackgroundThdCnt = 0; chSysUnlock(); /* * run DMA load and background thread _without_ NAND test */ dma_storm_adc_start(); dma_storm_uart_start(); dma_storm_spi_start(); chThdSleep(T); adc_idle_ints = dma_storm_adc_stop(); uart_idle_ints = dma_storm_uart_stop(); spi_idle_ints = dma_storm_spi_stop(); /* * ensure that NAND code have negligible impact on other subsystems */ osalDbgCheck(background_cnt > (BackgroundThdCnt / 4)); osalDbgCheck(abs(adc_ints - adc_idle_ints) < (adc_idle_ints / 20)); osalDbgCheck(abs(uart_ints - uart_idle_ints) < (uart_idle_ints / 20)); osalDbgCheck(abs(spi_ints - spi_idle_ints) < (spi_idle_ints / 10)); /* * perform ECC calculation test */ ecc_test(&NAND, NAND_TEST_END_BLOCK); #if USE_KILL_BLOCK_TEST kill_block(&NAND, NAND_TEST_KILL_BLOCK); #endif nand_wp_assert(); /* * Normal main() thread activity, in this demo it does nothing. */ while (true) { chThdSleepMilliseconds(500); } }
static void general_test (NANDDriver *nandp, size_t first, size_t last, size_t read_rounds){ size_t block, page, round; bool status; uint8_t op_status; uint32_t recc, wecc; red_led_on(); /* initialize time measurement units */ chTMObjectInit(&tmu_erase); chTMObjectInit(&tmu_write_data); chTMObjectInit(&tmu_write_spare); chTMObjectInit(&tmu_read_data); chTMObjectInit(&tmu_read_spare); /* perform basic checks */ for (block=first; block<last; block++){ if (!nandIsBad(nandp, block)){ if (!is_erased(nandp, block)){ op_status = nandErase(nandp, block); osalDbgCheck(0 == (op_status & 1)); /* operation failed */ } } } /* write block with pattern, read it back and compare */ for (block=first; block<last; block++){ if (!nandIsBad(nandp, block)){ for (page=0; page<nandp->config->pages_per_block; page++){ pattern_fill(); chTMStartMeasurementX(&tmu_write_data); op_status = nandWritePageData(nandp, block, page, nand_buf, nandp->config->page_data_size, &wecc); chTMStopMeasurementX(&tmu_write_data); osalDbgCheck(0 == (op_status & 1)); /* operation failed */ chTMStartMeasurementX(&tmu_write_spare); op_status = nandWritePageSpare(nandp, block, page, nand_buf + nandp->config->page_data_size, nandp->config->page_spare_size); chTMStopMeasurementX(&tmu_write_spare); osalDbgCheck(0 == (op_status & 1)); /* operation failed */ /* read back and compare */ for (round=0; round<read_rounds; round++){ memset(nand_buf, 0, NAND_PAGE_SIZE); chTMStartMeasurementX(&tmu_read_data); nandReadPageData(nandp, block, page, nand_buf, nandp->config->page_data_size, &recc); chTMStopMeasurementX(&tmu_read_data); osalDbgCheck(0 == (recc ^ wecc)); /* ECC error detected */ chTMStartMeasurementX(&tmu_read_spare); nandReadPageSpare(nandp, block, page, nand_buf + nandp->config->page_data_size, nandp->config->page_spare_size); chTMStopMeasurementX(&tmu_read_spare); osalDbgCheck(0 == memcmp(ref_buf, nand_buf, NAND_PAGE_SIZE)); /* Read back failed */ } } /* make clean */ chTMStartMeasurementX(&tmu_erase); op_status = nandErase(nandp, block); chTMStopMeasurementX(&tmu_erase); osalDbgCheck(0 == (op_status & 1)); /* operation failed */ status = is_erased(nandp, block); osalDbgCheck(true == status); /* blocks was not erased successfully */ }/* if (!nandIsBad(nandp, block)){ */ } red_led_off(); }