void test_subtract(){ /* * Simple subtraction, number of nanoseconds in timespec2 is less than in * timespec1. */ rtems_timespec_set(timespec1,10, 800); rtems_timespec_set(timespec2,13, 500); rtems_timespec_subtract(timespec1,timespec2,tpointer); rtems_test_assert( (tpointer->tv_sec==2) && (tpointer->tv_nsec==(TOD_NANOSECONDS_PER_SECOND-300)) ); /* * Simple subtraction, number of nanoseconds in timespec2 is greater than in * timespec1. It hits another branch. */ rtems_timespec_set(timespec1,10,200); rtems_timespec_subtract(timespec1,timespec2,tpointer); rtems_test_assert( (tpointer->tv_sec==3) && (tpointer->tv_nsec==300) ); /* * Case when timespec2 (end) is less than timespec1 (start). It produce * negative result. */ rtems_timespec_set(timespec1,13,600); rtems_timespec_subtract(timespec1,timespec2,tpointer); rtems_test_assert( (tpointer->tv_sec==(-1)) && \ (tpointer->tv_nsec==999999900) ); puts(" rtems_timespec_subtract test PASSED"); }
static void rx_irq_handler(void *arg) { static struct rx_state tmp_state; static uint8_t next_channel = 0xff; struct timespec diff, ts; rtems_clock_get_uptime(&ts); rtems_timespec_subtract(&tmp_state.last_update, &ts, &diff); memcpy(&tmp_state, &ts, sizeof(ts)); if ((diff.tv_sec > 0) || (diff.tv_nsec > MAX_PULSE_TIME)) { next_channel = 0; } else if (next_channel < RX_NUM_CHANNELS) { tmp_state.values[next_channel] = diff.tv_nsec; next_channel++; if (next_channel == RX_NUM_CHANNELS) memcpy(¤t_state, &tmp_state, sizeof(current_state)); } volatile lm3s69xx_gpio *portd = LM3S69XX_GPIO(LM3S69XX_PORT_D); portd->icr = 1U << 3; rtems_semaphore_release(rx_sem); }
static void Init(rtems_task_argument arg) { struct timespec real_start; struct timespec mono_start; struct timespec real_end; struct timespec mono_end; struct timespec real_elapsed; struct timespec mono_elapsed; struct timespec min; struct timespec max; int rv; TEST_BEGIN(); rtems_timespec_set(&min, 1, 980000000); rtems_timespec_set(&max, 2, 20000000); rv = clock_gettime(CLOCK_REALTIME, &real_start); rtems_test_assert(rv == 0); rv = clock_gettime(CLOCK_MONOTONIC, &mono_start); rtems_test_assert(rv == 0); rtems_task_wake_after(2 * rtems_clock_get_ticks_per_second()); rv = clock_gettime(CLOCK_REALTIME, &real_end); rtems_test_assert(rv == 0); rv = clock_gettime(CLOCK_MONOTONIC, &mono_end); rtems_test_assert(rv == 0); rtems_timespec_subtract(&real_start, &real_end, &real_elapsed); rtems_timespec_subtract(&mono_start, &mono_end, &mono_elapsed); rtems_test_assert(rtems_timespec_greater_than(&real_elapsed, &min)); rtems_test_assert(rtems_timespec_greater_than(&max, &real_elapsed)); rtems_test_assert(rtems_timespec_greater_than(&mono_elapsed, &min)); rtems_test_assert(rtems_timespec_greater_than(&max, &mono_elapsed)); TEST_END(); rtems_test_exit(0); }