/** * * @brief Test the k_cpu_idle() routine * * This tests the k_cpu_idle() routine. The first thing it does is align to * a tick boundary. The only source of interrupts while the test is running is * expected to be the tick clock timer which should wake the CPU. Thus after * each call to k_cpu_idle(), the tick count should be one higher. * * @return TC_PASS on success * @return TC_FAIL on failure */ static int test_kernel_cpu_idle(int atomic) { int tms; /* current time in millisecond */ int i; /* loop variable */ /* Align to a "ms boundary". */ tms = k_uptime_get_32(); while (tms == k_uptime_get_32()) { } tms = k_uptime_get_32(); for (i = 0; i < 5; i++) { /* Repeat the test five times */ if (atomic) { unsigned int key = irq_lock(); k_cpu_atomic_idle(key); } else { k_cpu_idle(); } /* calculating milliseconds per tick*/ tms += sys_clock_us_per_tick / USEC_PER_MSEC; if (k_uptime_get_32() < tms) { return TC_FAIL; } } return TC_PASS; }
/** * * @brief Test the k_cpu_idle() routine * * This tests the k_cpu_idle() routine. The first thing it does is align to * a tick boundary. The only source of interrupts while the test is running is * expected to be the tick clock timer which should wake the CPU. Thus after * each call to k_cpu_idle(), the tick count should be one higher. * * @return TC_PASS on success * @return TC_FAIL on failure */ static int test_kernel_cpu_idle(int atomic) { int tms, tms2;; /* current time in millisecond */ int i; /* loop variable */ /* Align to a "ms boundary". */ tms = k_uptime_get_32(); while (tms == k_uptime_get_32()) { } tms = k_uptime_get_32(); for (i = 0; i < 5; i++) { /* Repeat the test five times */ if (atomic) { unsigned int key = irq_lock(); k_cpu_atomic_idle(key); } else { k_cpu_idle(); } /* calculating milliseconds per tick*/ tms += sys_clock_us_per_tick / USEC_PER_MSEC; tms2 = k_uptime_get_32(); if (tms2 < tms) { TC_ERROR("Bad ms per tick value computed, got %d which is less than %d\n", tms2, tms); return TC_FAIL; } } return TC_PASS; }