/** * * @brief Checks number of tests and calculate average time * * @return 1 if success and 0 on failure * * @param i Number of tests. * @param t Time in ticks for the whole test. */ int check_result(int i, uint32_t t) { /* * bench_test_end checks tCheck static variable. * bench_test_start modifies it */ if (bench_test_end() != 0) { fprintf(output_file, sz_case_result_fmt, sz_fail); fprintf(output_file, sz_case_details_fmt, "timer tick happened. Results are inaccurate"); fprintf(output_file, sz_case_end_fmt); return 0; } if (i != NUMBER_OF_LOOPS) { fprintf(output_file, sz_case_result_fmt, sz_fail); fprintf(output_file, sz_case_details_fmt, "loop counter = "); fprintf(output_file, "%i !!!", i); fprintf(output_file, sz_case_end_fmt); return 0; } fprintf(output_file, sz_case_result_fmt, sz_success); fprintf(output_file, sz_case_details_fmt, "Average time for 1 iteration: "); fprintf(output_file, sz_case_timing_fmt, SYS_CLOCK_HW_CYCLES_TO_NS_AVG(t, NUMBER_OF_LOOPS)); fprintf(output_file, sz_case_end_fmt); return 1; }
int pipeget(kpipe_t pipe, K_PIPE_OPTION option, int size, int count, unsigned int* time) { int i; unsigned int t; int sizexferd_total = 0; int size2xfer_total = size * count; /* sync with the sender */ task_sem_take_wait(SEM0); t = BENCH_START(); for (i = 0; _1_TO_N == option || (i < count); i++) { int sizexferd = 0; int size2xfer = min(size, size2xfer_total - sizexferd_total); int ret; ret = task_pipe_get_wait(pipe, data_recv, size2xfer, &sizexferd, option); if (RC_OK != ret) { return 1; } if (_ALL_N == option && sizexferd != size2xfer) { return 1; } sizexferd_total += sizexferd; if (size2xfer_total == sizexferd_total) { break; } if (size2xfer_total < sizexferd_total) { return 1; } } t = TIME_STAMP_DELTA_GET(t); *time = SYS_CLOCK_HW_CYCLES_TO_NS_AVG(t, count); if (bench_test_end() < 0) { if (high_timer_overflow()) { PRINT_STRING("| Timer overflow. Results are invalid ", output_file); } else { PRINT_STRING("| Tick occured. Results may be inaccurate ", output_file); } PRINT_STRING(" |\n", output_file); } return 0; }
/** * * @brief The test main function * * @return 0 on success */ int nanoIntLockUnlock(void) { int i; unsigned int mask; PRINT_FORMAT(" 5- Measure average time to lock then unlock interrupts"); bench_test_start(); timestamp = TIME_STAMP_DELTA_GET(0); for (i = 0; i < NTESTS; i++) { mask = irq_lock(); irq_unlock(mask); } timestamp = TIME_STAMP_DELTA_GET(timestamp); if (bench_test_end() == 0) { PRINT_FORMAT(" Average time for lock then unlock " "is %lu tcs = %lu nsec", timestamp / NTESTS, SYS_CLOCK_HW_CYCLES_TO_NS_AVG(timestamp, NTESTS)); } else { errorCount++; PRINT_OVERFLOW_ERROR(); } return 0; }