void doit( rtems_timer_service_routine (*TSR)(rtems_id, void *), const char *method ) { rtems_interval start; rtems_interval end; rtems_status_code status; printf( "Init: schedule %s from a TSR\n", method ); TSR_occurred = 0; TSR_status = 0; status = rtems_timer_fire_after( timer_id, 10, TSR, NULL ); rtems_test_assert( !status ); start = rtems_clock_get_ticks_since_boot(); do { end = rtems_clock_get_ticks_since_boot(); } while ( !TSR_occurred && ((end - start) <= 800)); if ( !TSR_occurred ) { printf( "%s did not occur\n", method ); rtems_test_exit(0); } if ( TSR_status != EPROTO ) { printf( "%s returned %s\n", method, strerror(TSR_status) ); rtems_test_exit(0); } printf( "%s - from ISR returns EPROTO - OK\n", method ); }
rtems_task Periodic_Task( rtems_task_argument argument ) { rtems_status_code status; rtems_name period_name = rtems_build_name('P','E','R','a'); rtems_id period_id; rtems_interval start; rtems_interval end; puts( "Periodic - Create Period" ); /* create period */ status = rtems_rate_monotonic_create( period_name, &period_id ); directive_failed(status, "rate_monotonic_create"); partial_loop = 0; while (1) { /* start period with initial value */ status = rtems_rate_monotonic_period( period_id, 25 ); directive_failed(status, "rate_monotonic_period"); partial_loop = 0; start = rtems_clock_get_ticks_since_boot(); end = start + 5; while ( end <= rtems_clock_get_ticks_since_boot() ) ; partial_loop = 1; rtems_task_wake_after( 5 ); } puts( "Periodic - Deleting self" ); rtems_task_delete( RTEMS_SELF ); }
/* * Spin loop to allow tasks to delay without yeilding the * processor. */ static void test_delay(int ticks) { rtems_interval start, stop; start = rtems_clock_get_ticks_since_boot(); do { stop = rtems_clock_get_ticks_since_boot(); } while ( (stop - start) < ticks ); }
/* * Spin until the next clock tick */ void rtems_test_spin_until_next_tick( void ) { rtems_interval start; rtems_interval now; start = rtems_clock_get_ticks_since_boot(); do { now = rtems_clock_get_ticks_since_boot(); } while ( now != start ); }
static rtems_interval sync_with_clock_tick(void) { rtems_interval start = rtems_clock_get_ticks_since_boot(); rtems_interval current; do { current = rtems_clock_get_ticks_since_boot(); } while (current == start); return current; }
/* * Fill the input buffer by polling the device */ static rtems_status_code fillBufferPoll (struct rtems_termios_tty *tty) { int n; if (tty->termios.c_lflag & ICANON) { for (;;) { n = (*tty->device.pollRead)(tty->minor); if (n < 0) { rtems_task_wake_after (1); } else { if (siproc (n, tty)) break; } } } else { rtems_interval then, now; then = rtems_clock_get_ticks_since_boot(); for (;;) { n = (*tty->device.pollRead)(tty->minor); if (n < 0) { if (tty->termios.c_cc[VMIN]) { if (tty->termios.c_cc[VTIME] && tty->ccount) { now = rtems_clock_get_ticks_since_boot(); if ((now - then) > tty->vtimeTicks) { break; } } } else { if (!tty->termios.c_cc[VTIME]) break; now = rtems_clock_get_ticks_since_boot(); if ((now - then) > tty->vtimeTicks) { break; } } rtems_task_wake_after (1); } else { siproc (n, tty); if (tty->ccount >= tty->termios.c_cc[VMIN]) break; if (tty->termios.c_cc[VMIN] && tty->termios.c_cc[VTIME]) then = rtems_clock_get_ticks_since_boot(); } } } return RTEMS_SUCCESSFUL; }
rtems_task Init( rtems_task_argument argument ) { rtems_status_code status; rtems_id timer; rtems_interval start; rtems_interval now; puts( "\n\n*** TEST 38 ***" ); main_task = rtems_task_self(); /* * Timer used in multiple ways */ status = rtems_timer_create( 1, &timer ); directive_failed( status, "rtems_timer_create" ); /* * Get starting time */ start = rtems_clock_get_ticks_since_boot(); status = rtems_signal_catch( signal_handler, RTEMS_DEFAULT_MODES ); directive_failed( status, "rtems_signal_catch" ); puts( "rtems_signal_catch - handler installed" ); /* * Test Signal from ISR */ signal_sent = FALSE; status = rtems_timer_fire_after( timer, 10, test_signal_from_isr, NULL ); directive_failed( status, "timer_fire_after failed" ); while (1) { now = rtems_clock_get_ticks_since_boot(); if ( (now-start) > 100 ) { puts( "Signal from ISR did not get processed\n" ); rtems_test_exit( 0 ); } if ( signal_processed ) break; } puts( "Signal sent from ISR has been processed" ); puts( "*** END OF TEST 38 ***" ); rtems_test_exit( 0 ); }
void Shm_Print_statistics(void) { uint32_t ticks; uint32_t ticks_per_second; uint32_t seconds; int packets_per_second; ticks = rtems_clock_get_ticks_since_boot(); ticks_per_second = rtems_clock_get_ticks_per_second(); seconds = ticks / ticks_per_second; if ( seconds == 0 ) seconds = 1; packets_per_second = Shm_Receive_message_count / seconds; if ( (Shm_Receive_message_count % seconds) >= (seconds / 2) ) packets_per_second++; printk( "\n\nSHMDR STATISTICS (NODE %" PRId32 ")\n", Multiprocessing_configuration.node ); printk( "TICKS SINCE BOOT = %" PRId32 "\n", ticks ); printk( "TICKS PER SECOND = %" PRId32 "\n", ticks_per_second ); printk( "ISRs=%" PRId32 "\n", Shm_Interrupt_count ); printk( "RECV=%" PRId32 "\n", Shm_Receive_message_count ); printk( "NULL=%" PRId32 "\n", Shm_Null_message_count ); printk( "PKTS/SEC=%" PRId32 "\n", packets_per_second ); }
static void preview_update(mtk_event *e, int count) { rtems_interval t; unsigned short *videoframe; int x, y; unsigned int status; t = rtems_clock_get_ticks_since_boot(); if(t >= next_update) { videoframe = (unsigned short *)1; /* invalidate */ ioctl(video_fd, VIDEO_BUFFER_LOCK, &videoframe); if(videoframe != NULL) { for(y=0;y<144;y++) for(x=0;x<180;x++) preview_fb[180*y+x] = videoframe[720*2*y+4*x]; ioctl(video_fd, VIDEO_BUFFER_UNLOCK, videoframe); mtk_cmd(appid, "p_preview.refresh()"); } ioctl(video_fd, VIDEO_GET_SIGNAL, &status); mtk_cmdf(appid, "l_detected.set(-text \"%s\")", fmt_video_signal(status)); next_update = t + UPDATE_PERIOD; } }
void open_videoin_window(void) { if(w_open) return; if(!resmgr_acquire("Video in settings", RESOURCE_VIDEOIN)) return; video_fd = open("/dev/video", O_RDWR); if(video_fd == -1) { perror("Unable to open video device"); resmgr_release(RESOURCE_VIDEOIN); return; } w_open = 1; load_videoin_config(); old_format = format; old_brightness = brightness; old_contrast = contrast; old_hue = hue; next_update = rtems_clock_get_ticks_since_boot() + UPDATE_PERIOD; input_add_callback(preview_update); mtk_cmd(appid, "w.open()"); }
/* * Burn CPU for specified number of ticks */ void rtems_test_spin_for_ticks(int ticks) { rtems_interval start; rtems_interval now; start = rtems_clock_get_ticks_since_boot(); do { now = rtems_clock_get_ticks_since_boot(); /* * Spin for <= ticks so we spin >= number of ticks. * The first tick we spin through is a partial one. * So you sping "ticks" number of ticks plus a partial * one. */ } while ( (now-start) <= ticks ); }
/** * POSIX 1003.1b 4.5.2 - Get Process Times */ clock_t _times( struct tms *ptms ) { rtems_interval ticks, us_per_tick; Thread_Control *executing; if ( !ptms ) rtems_set_errno_and_return_minus_one( EFAULT ); /* * This call does not depend on TOD being initialized and can't fail. */ ticks = rtems_clock_get_ticks_since_boot(); us_per_tick = rtems_configuration_get_microseconds_per_tick(); /* * RTEMS technically has no notion of system versus user time * since there is no separation of OS from application tasks. * But we can at least make a distinction between the number * of ticks since boot and the number of ticks executed by this * this thread. */ { Timestamp_Control per_tick; uint32_t ticks_of_executing; uint32_t fractional_ticks; Per_CPU_Control *cpu_self; _Timestamp_Set( &per_tick, rtems_configuration_get_microseconds_per_tick() / TOD_MICROSECONDS_PER_SECOND, (rtems_configuration_get_nanoseconds_per_tick() % TOD_NANOSECONDS_PER_SECOND) ); cpu_self = _Thread_Dispatch_disable(); executing = _Thread_Executing; _Thread_Update_cpu_time_used( executing, &_Thread_Time_of_last_context_switch ); _Timestamp_Divide( &executing->cpu_time_used, &per_tick, &ticks_of_executing, &fractional_ticks ); _Thread_Dispatch_enable( cpu_self ); ptms->tms_utime = ticks_of_executing * us_per_tick; } ptms->tms_stime = ticks * us_per_tick; ptms->tms_cutime = 0; ptms->tms_cstime = 0; return ticks * us_per_tick; }
clock_t _times( struct tms *ptms ) { rtems_interval ticks; if ( !ptms ) { errno = EFAULT; return -1; } /* * This call does not depend on TOD being initialized and can't fail. */ ticks = rtems_clock_get_ticks_since_boot(); /* * RTEMS technically has no notion of system versus user time * since there is no separation of OS from application tasks. * But we can at least make a distinction between the number * of ticks since boot and the number of ticks executed by this * this thread. */ #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__ { Timestamp_Control per_tick; uint32_t ticks; uint32_t fractional_ticks; _Timestamp_Set( &per_tick, rtems_configuration_get_microseconds_per_tick() / TOD_MICROSECONDS_PER_SECOND, (rtems_configuration_get_nanoseconds_per_tick() % TOD_NANOSECONDS_PER_SECOND) ); _Timestamp_Divide( &_Thread_Executing->cpu_time_used, &per_tick, &ticks, &fractional_ticks ); ptms->tms_utime = ticks; } #else ptms->tms_utime = _Thread_Executing->cpu_time_used; #endif ptms->tms_stime = ticks; ptms->tms_cutime = 0; ptms->tms_cstime = 0; return ticks; }
static void test_clock_tick_functions( void ) { rtems_interrupt_level level; Watchdog_Interval saved_ticks; _Thread_Disable_dispatch(); rtems_interrupt_disable( level ); saved_ticks = _Watchdog_Ticks_since_boot; _Watchdog_Ticks_since_boot = 0xdeadbeef; rtems_test_assert( rtems_clock_get_ticks_since_boot() == 0xdeadbeef ); rtems_test_assert( rtems_clock_tick_later( 0 ) == 0xdeadbeef ); rtems_test_assert( rtems_clock_tick_later( 0x8160311e ) == 0x600df00d ); _Watchdog_Ticks_since_boot = 0; rtems_test_assert( rtems_clock_tick_later_usec( 0 ) == 1 ); rtems_test_assert( rtems_clock_tick_later_usec( 1 ) == 2 ); rtems_test_assert( rtems_clock_tick_later_usec( US_PER_TICK ) == 2 ); rtems_test_assert( rtems_clock_tick_later_usec( US_PER_TICK + 1 ) == 3 ); _Watchdog_Ticks_since_boot = 0; rtems_test_assert( !rtems_clock_tick_before( 0xffffffff ) ); rtems_test_assert( !rtems_clock_tick_before( 0 ) ); rtems_test_assert( rtems_clock_tick_before( 1 ) ); _Watchdog_Ticks_since_boot = 1; rtems_test_assert( !rtems_clock_tick_before( 0 ) ); rtems_test_assert( !rtems_clock_tick_before( 1 ) ); rtems_test_assert( rtems_clock_tick_before( 2 ) ); _Watchdog_Ticks_since_boot = 0x7fffffff; rtems_test_assert( !rtems_clock_tick_before( 0x7ffffffe ) ); rtems_test_assert( !rtems_clock_tick_before( 0x7fffffff ) ); rtems_test_assert( rtems_clock_tick_before( 0x80000000 ) ); _Watchdog_Ticks_since_boot = 0x80000000; rtems_test_assert( !rtems_clock_tick_before( 0x7fffffff ) ); rtems_test_assert( !rtems_clock_tick_before( 0x80000000 ) ); rtems_test_assert( rtems_clock_tick_before( 0x80000001 ) ); _Watchdog_Ticks_since_boot = 0xffffffff; rtems_test_assert( !rtems_clock_tick_before( 0xfffffffe ) ); rtems_test_assert( !rtems_clock_tick_before( 0xffffffff ) ); rtems_test_assert( rtems_clock_tick_before( 0 ) ); _Watchdog_Ticks_since_boot = saved_ticks; rtems_interrupt_enable( level ); _Thread_Enable_dispatch(); }
rtems_task Init( rtems_task_argument argument ) { clock_t start; clock_t end; clock_t now; clock_t sc; clock_t difference; struct tms start_tm; struct tms end_tm; int interval = 5; puts( "\n\n*** TEST TIMES 01 ***" ); puts( "times( NULL ) -- EFAULT" ); sc = times( NULL ); rtems_test_assert( sc == -1 ); rtems_test_assert( errno == EFAULT ); puts( "_times_r( NULL, NULL ) -- EFAULT" ); start = _times_r( NULL, NULL ); rtems_test_assert( sc == -1 ); rtems_test_assert( errno == EFAULT ); while ( rtems_clock_get_ticks_since_boot() == 0 ) ; puts( "_times( &start_tm ) -- OK" ); now = _times( &start_tm ); rtems_test_assert( start != 0 ); rtems_test_assert( now != 0 ); rtems_test_spin_for_ticks( interval ); puts( "_times( &end_tm ) -- OK" ); end = _times( &end_tm ); rtems_test_assert( end != 0 ); puts( "Check various values" ); difference = end - start; rtems_test_assert( difference >= interval ); rtems_test_assert( end_tm.tms_utime - start_tm.tms_utime >= interval ); rtems_test_assert( end_tm.tms_stime - start_tm.tms_stime >= interval ); rtems_test_assert( end_tm.tms_cutime == 0 ); rtems_test_assert( end_tm.tms_cstime == 0 ); puts( "*** END OF TEST TIMES 01 ***" ); rtems_test_exit(0); }
rtems_task Init( rtems_task_argument argument ) { uint32_t i; char ch; uint32_t cpu_num; rtems_id id; rtems_status_code status; TEST_BEGIN(); locked_print_initialize(); for ( killtime=0; killtime<1000000; killtime++ ) ; for ( i=0; i<rtems_get_processor_count() -1; i++ ) { ch = '1' + i; status = rtems_task_create( rtems_build_name( 'T', 'A', ch, ' ' ), 1, RTEMS_MINIMUM_STACK_SIZE, RTEMS_DEFAULT_MODES, RTEMS_DEFAULT_ATTRIBUTES, &id ); directive_failed( status, "task create" ); cpu_num = rtems_get_current_processor(); locked_printf(" CPU %" PRIu32 " start task TA%c\n", cpu_num, ch); status = rtems_task_start( id, Test_task, i+1 ); directive_failed( status, "task start" ); } locked_printf(" kill 10 clock ticks\n" ); while ( rtems_clock_get_ticks_since_boot() < 10 ) ; rtems_cpu_usage_report(); TEST_END(); rtems_test_exit(0); }
rtems_task Init( rtems_task_argument argument ) { int i; char ch; int cpu_num; rtems_id id; rtems_status_code status; locked_print_initialize(); locked_printf( "\n\n*** TEST SMP09 ***\n" ); for ( killtime=0; killtime<1000000; killtime++ ) ; for ( i=0; i<rtems_smp_get_number_of_processors() -1; i++ ) { ch = '1' + i; status = rtems_task_create( rtems_build_name( 'T', 'A', ch, ' ' ), 1, RTEMS_MINIMUM_STACK_SIZE, RTEMS_DEFAULT_MODES, RTEMS_DEFAULT_ATTRIBUTES, &id ); directive_failed( status, "task create" ); cpu_num = bsp_smp_processor_id(); locked_printf(" CPU %d start task TA%c\n", cpu_num, ch); status = rtems_task_start( id, Test_task, i+1 ); directive_failed( status, "task start" ); } locked_printf(" kill 10 clock ticks\n" ); while ( rtems_clock_get_ticks_since_boot() < 10 ) ; rtems_cpu_usage_report(); locked_printf( "*** END OF TEST SMP09 ***" ); rtems_test_exit(0); }
static void test_reset(void) { rtems_status_code sc = RTEMS_SUCCESSFUL; obtain_try = false; obtain_done = false; release_happened = false; interrupt_happened = false; delayed_happened = false; interrupt_triggered_happened = false; server_triggered_happened = false; /* Synchronize with tick */ sc = rtems_task_wake_after(1); directive_failed(sc, "rtems_task_wake_after"); start = rtems_clock_get_ticks_since_boot(); }
/* * Initialization of FIFO/pipe module. */ void rtems_pipe_initialize (void) { if (!rtems_pipe_configured) return; if (rtems_pipe_semaphore) return; rtems_status_code sc; sc = rtems_semaphore_create( rtems_build_name ('P', 'I', 'P', 'E'), 1, RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY, RTEMS_NO_PRIORITY, &rtems_pipe_semaphore); if (sc != RTEMS_SUCCESSFUL) rtems_fatal_error_occurred (sc); rtems_interval now; now = rtems_clock_get_ticks_since_boot(); rtems_pipe_no = now; }
static void test_delay_nanoseconds(test_context *ctx) { int i; for (i = 0; i < N; ++i) { rtems_counter_ticks t0; rtems_counter_ticks t1; rtems_interval tick; tick = sync_with_clock_tick(); t0 = rtems_counter_read(); rtems_counter_delay_nanoseconds(NS_PER_TICK); t1 = rtems_counter_read(); ctx->delay_ns_t[i][0] = t0; ctx->delay_ns_t[i][1] = t1; rtems_test_assert(tick < rtems_clock_get_ticks_since_boot()); } }
static void assert_time(rtems_interval expected) { rtems_test_assert((rtems_clock_get_ticks_since_boot() - start) == expected); }
rtems_task Init( rtems_task_argument argument ) { int cpu_num; rtems_id id; rtems_status_code status; rtems_interval per_second; rtems_interval then; rtems_id Timer; locked_print_initialize(); rtems_test_begin_with_plugin(locked_printf_plugin, NULL); if ( rtems_get_processor_count() == 1 ) { success(); } /* Create/verify semaphore */ status = rtems_semaphore_create( rtems_build_name ('S', 'E', 'M', '1'), 1, RTEMS_LOCAL | RTEMS_SIMPLE_BINARY_SEMAPHORE | RTEMS_PRIORITY, 1, &Semaphore ); directive_failed( status, "rtems_semaphore_create" ); /* Lock semaphore */ status = rtems_semaphore_obtain( Semaphore, RTEMS_WAIT, 0); directive_failed( status,"rtems_semaphore_obtain of SEM1\n"); /* Create and Start test task. */ status = rtems_task_create( rtems_build_name( 'T', 'A', '1', ' ' ), 1, RTEMS_MINIMUM_STACK_SIZE, RTEMS_DEFAULT_MODES, RTEMS_DEFAULT_ATTRIBUTES, &id ); directive_failed( status, "task create" ); cpu_num = rtems_get_current_processor(); locked_printf(" CPU %d start task TA1\n", cpu_num ); status = rtems_task_start( id, Test_task, 1 ); directive_failed( status, "task start" ); /* Create and start TSR */ locked_printf(" CPU %d create and start timer\n", cpu_num ); status = rtems_timer_create( rtems_build_name( 'T', 'M', 'R', '1' ), &Timer); directive_failed( status, "rtems_timer_create" ); per_second = rtems_clock_get_ticks_per_second(); status = rtems_timer_fire_after( Timer, 2 * per_second, TimerMethod, NULL ); directive_failed( status, "rtems_timer_fire_after"); /* * Wait long enough that TSR should have fired. * * Spin so CPU 0 is consumed. This forces task to run on CPU 1. */ then = rtems_clock_get_ticks_since_boot() + 4 * per_second; while (1) { if ( rtems_clock_get_ticks_since_boot() > then ) break; if ( TSRFired && TaskRan ) break; }; /* Validate the timer fired and that the task ran */ if ( !TSRFired ) locked_printf( "*** ERROR TSR DID NOT FIRE ***" ); if ( !TaskRan ) { locked_printf( "*** ERROR TASK DID NOT RUN ***" ); rtems_test_exit(0); } /* End the program */ success(); }
rtems_task Task_Periodic( rtems_task_argument argument ) { rtems_id rmid; rtems_status_code status; time_t approved_budget, exec_time, abs_time, current_budget; int start, stop, now; qres_sid_t server_id, tsid; qres_params_t params, tparams; params.P = Period; params.Q = Execution+1; printf( "Periodic task: Create server and Attach thread\n" ); if ( qres_create_server( ¶ms, &server_id ) ) printf( "ERROR: CREATE SERVER FAILED\n" ); if ( qres_attach_thread( server_id, 0, Task_id ) ) printf( "ERROR: ATTACH THREAD FAILED\n" ); printf( "Periodic task: ID and Get parameters\n" ); if ( qres_get_sid( 0, Task_id, &tsid ) ) printf( "ERROR: GET SERVER ID FAILED\n" ); if ( tsid != server_id ) printf( "ERROR: SERVER ID MISMATCH\n" ); if ( qres_get_params( server_id, &tparams ) ) printf( "ERROR: GET PARAMETERS FAILED\n" ); if ( params.P != tparams.P || params.Q != tparams.Q ) printf( "ERROR: PARAMETERS MISMATCH\n" ); printf( "Periodic task: Detach thread and Destroy server\n" ); if ( qres_detach_thread( server_id, 0, Task_id ) ) printf( "ERROR: DETACH THREAD FAILED\n" ); if ( qres_destroy_server( server_id ) ) printf( "ERROR: DESTROY SERVER FAILED\n" ); if ( qres_create_server( ¶ms, &server_id ) ) printf( "ERROR: CREATE SERVER FAILED\n" ); printf( "Periodic task: Current budget and Execution time\n" ); if ( qres_get_curr_budget( server_id, ¤t_budget ) ) printf( "ERROR: GET REMAINING BUDGET FAILED\n" ); if ( current_budget != params.Q ) printf( "ERROR: REMAINING BUDGET MISMATCH\n" ); if ( qres_get_exec_time( server_id, &exec_time, &abs_time ) ) printf( "ERROR: GET EXECUTION TIME FAILED\n" ); printf( "Periodic task: Set parameters\n" ); if ( qres_attach_thread( server_id, 0, Task_id ) ) printf( "ERROR: ATTACH THREAD FAILED\n" ); params.P = Period * 2; params.Q = Execution * 2 +1; if ( qres_set_params( server_id, ¶ms ) ) printf( "ERROR: SET PARAMS FAILED\n" ); if ( qres_get_params( server_id, &tparams ) ) printf( "ERROR: GET PARAMS FAILED\n" ); if ( params.P != tparams.P || params.Q != tparams.Q ) printf( "ERROR: PARAMS MISMATCH\n" ); params.P = Period; params.Q = Execution+1; if ( qres_set_params( server_id, ¶ms ) ) printf( "ERROR: SET PARAMS FAILED\n" ); if ( qres_get_appr_budget( server_id, &approved_budget ) ) printf( "ERROR: GET APPROVED BUDGET FAILED\n" ); printf( "Periodic task: Approved budget\n" ); if ( approved_budget != params.Q ) printf( "ERROR: APPROVED BUDGET MISMATCH\n" ); status = rtems_rate_monotonic_create( argument, &rmid ); directive_failed( status, "rtems_rate_monotonic_create" ); /* Starting periodic behavior of the task */ printf( "Periodic task: Starting periodic behavior\n" ); status = rtems_task_wake_after( 1 + Phase ); directive_failed( status, "rtems_task_wake_after" ); while ( FOREVER ) { if ( rtems_rate_monotonic_period(rmid, Period) == RTEMS_TIMEOUT ) printf( "P%" PRIdPTR " - Deadline miss\n", argument ); start = rtems_clock_get_ticks_since_boot(); printf( "P%" PRIdPTR "-S ticks:%d\n", argument, start ); if ( start > 4*Period+Phase ) break; /* stop */ /* active computing */ while(FOREVER) { now = rtems_clock_get_ticks_since_boot(); if ( now >= start + Execution ) break; if ( qres_get_exec_time( server_id, &exec_time, &abs_time ) ) printf( "ERROR: GET EXECUTION TIME FAILED\n" ); if ( qres_get_curr_budget( server_id, ¤t_budget) ) printf( "ERROR: GET CURRENT BUDGET FAILED\n" ); if ( (current_budget + exec_time) > (Execution + 1) ) { printf( "ERROR: CURRENT BUDGET AND EXECUTION TIME MISMATCH\n" ); rtems_test_exit( 0 ); } } stop = rtems_clock_get_ticks_since_boot(); printf( "P%" PRIdPTR "-F ticks:%d\n", argument, stop ); } /* delete period and SELF */ status = rtems_rate_monotonic_delete( rmid ); if ( status != RTEMS_SUCCESSFUL ) { printf("rtems_rate_monotonic_delete failed with status of %d.\n", status); rtems_test_exit( 0 ); } if ( qres_cleanup() ) printf( "ERROR: QRES CLEANUP\n" ); fflush(stdout); TEST_END(); rtems_test_exit( 0 ); }
rtems_task Task_Periodic( rtems_task_argument argument ) { rtems_id rmid; rtems_status_code status; time_t approved_budget, exec_time, abs_time, remaining_budget; int start, stop, now; rtems_cbs_server_id server_id = 0, tsid; rtems_cbs_parameters params, tparams; params.deadline = Period; params.budget = Execution+1; /* Taks 1 will be attached to a server, task 2 not. */ if ( argument == 1 ) { printf( "Periodic task: Create server and Attach thread\n" ); if ( rtems_cbs_create_server( ¶ms, NULL, &server_id ) ) printf( "ERROR: CREATE SERVER FAILED\n" ); if ( rtems_cbs_attach_thread( server_id, Task_id ) ) printf( "ERROR: ATTACH THREAD FAILED\n" ); printf( "Periodic task: ID and Get parameters\n" ); if ( rtems_cbs_get_server_id( Task_id, &tsid ) ) printf( "ERROR: GET SERVER ID FAILED\n" ); if ( tsid != server_id ) printf( "ERROR: SERVER ID MISMATCH\n" ); if ( rtems_cbs_get_parameters( server_id, &tparams ) ) printf( "ERROR: GET PARAMETERS FAILED\n" ); if ( params.deadline != tparams.deadline || params.budget != tparams.budget ) printf( "ERROR: PARAMETERS MISMATCH\n" ); printf( "Periodic task: Detach thread and Destroy server\n" ); if ( rtems_cbs_detach_thread( server_id, Task_id ) ) printf( "ERROR: DETACH THREAD FAILED\n" ); if ( rtems_cbs_destroy_server( server_id ) ) printf( "ERROR: DESTROY SERVER FAILED\n" ); if ( rtems_cbs_create_server( ¶ms, NULL, &server_id ) ) printf( "ERROR: CREATE SERVER FAILED\n" ); printf( "Periodic task: Remaining budget and Execution time\n" ); if ( rtems_cbs_get_remaining_budget( server_id, &remaining_budget ) ) printf( "ERROR: GET REMAINING BUDGET FAILED\n" ); if ( remaining_budget != params.budget ) printf( "ERROR: REMAINING BUDGET MISMATCH\n" ); if ( rtems_cbs_get_execution_time( server_id, &exec_time, &abs_time ) ) printf( "ERROR: GET EXECUTION TIME FAILED\n" ); printf( "Periodic task: Set parameters\n" ); if ( rtems_cbs_attach_thread( server_id, Task_id ) ) printf( "ERROR: ATTACH THREAD FAILED\n" ); params.deadline = Period * 2; params.budget = Execution * 2 +1; if ( rtems_cbs_set_parameters( server_id, ¶ms ) ) printf( "ERROR: SET PARAMS FAILED\n" ); if ( rtems_cbs_get_parameters( server_id, &tparams ) ) printf( "ERROR: GET PARAMS FAILED\n" ); if ( params.deadline != tparams.deadline || params.budget != tparams.budget ) printf( "ERROR: PARAMS MISMATCH\n" ); params.deadline = Period; params.budget = Execution+1; if ( rtems_cbs_set_parameters( server_id, ¶ms ) ) printf( "ERROR: SET PARAMS FAILED\n" ); if ( rtems_cbs_get_approved_budget( server_id, &approved_budget ) ) printf( "ERROR: GET APPROVED BUDGET FAILED\n" ); printf( "Periodic task: Approved budget\n" ); if ( approved_budget != params.budget ) printf( "ERROR: APPROVED BUDGET MISMATCH\n" ); } status = rtems_rate_monotonic_create( argument, &rmid ); directive_failed( status, "rtems_rate_monotonic_create" ); /* Starting periodic behavior of the task */ printf( "Periodic task: Starting periodic behavior\n" ); status = rtems_task_wake_after( 1 + Phase ); directive_failed( status, "rtems_task_wake_after" ); while ( FOREVER ) { if ( rtems_rate_monotonic_period(rmid, Period) == RTEMS_TIMEOUT ) printf( "P%" PRIdPTR " - Deadline miss\n", argument ); start = rtems_clock_get_ticks_since_boot(); printf( "P%" PRIdPTR "-S ticks:%d\n", argument, start ); if ( start > 4*Period+Phase ) break; /* stop */ /* active computing */ while(FOREVER) { now = rtems_clock_get_ticks_since_boot(); if ( now >= start + Execution ) break; if ( server_id != 0 ) { if ( rtems_cbs_get_execution_time( server_id, &exec_time, &abs_time ) ) printf( "ERROR: GET EXECUTION TIME FAILED\n" ); if ( rtems_cbs_get_remaining_budget( server_id, &remaining_budget) ) printf( "ERROR: GET REMAINING BUDGET FAILED\n" ); if ( (remaining_budget + exec_time) > (Execution + 1) ) { printf( "ERROR: REMAINING BUDGET AND EXECUTION TIME MISMATCH\n" ); rtems_test_exit( 0 ); } } } stop = rtems_clock_get_ticks_since_boot(); printf( "P%" PRIdPTR "-F ticks:%d\n", argument, stop ); } /* delete period and SELF */ status = rtems_rate_monotonic_delete( rmid ); if ( status != RTEMS_SUCCESSFUL ) { printf("rtems_rate_monotonic_delete failed with status of %d.\n", status); rtems_test_exit( 0 ); } printf( "Periodic task: Deleting self\n" ); status = rtems_task_delete( RTEMS_SELF ); directive_failed( status, "rtems_task_delete of RTEMS_SELF" ); }
void *POSIX_Init( void *argument ) { int status; struct sigaction act; sigset_t mask; sighandler_t oldHandler; sighandler_t newHandler; rtems_interval start, end; puts( "\n\n*** POSIX TEST SIGNAL ***" ); /* set the time of day, and print our buffer in multiple ways */ set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 ); /* get id of this thread */ Init_id = pthread_self(); printf( "Init's ID is 0x%08" PRIxpthread_t "\n", Init_id ); Signal_occurred = 0; Signal_count = 0; act.sa_handler = Handler_1; act.sa_flags = 0; sigaction( SIGUSR1, &act, NULL ); sigaction( SIGFPE, &act, NULL ); sigaction( SIGILL, &act, NULL ); sigaction( SIGSEGV, &act, NULL ); /* * If we have the signal pending with default, we will die. */ puts("Validate signal with SIG_DFL"); signal( SIGUSR1, SIG_DFL ); status = kill( getpid(), SIGUSR1 ); status = sleep( 1 ); puts("Validate signal with SIG_IGN"); signal( SIGUSR1, SIG_IGN ); status = kill( getpid(), SIGUSR1 ); status = sleep( 1 ); /* unblock Signal and see if it happened */ status = sigemptyset( &mask ); rtems_test_assert( !status ); status = sigaddset( &mask, SIGUSR1 ); rtems_test_assert( !status ); status = sigaddset( &mask, SIGFPE ); rtems_test_assert( !status ); status = sigaddset( &mask, SIGILL ); rtems_test_assert( !status ); status = sigaddset( &mask, SIGSEGV ); rtems_test_assert( !status ); puts( "Init: Unblock SIGUSR1 SIGFPE SIGILL SIGSEGV" ); status = sigprocmask( SIG_UNBLOCK, &mask, NULL ); rtems_test_assert( !status ); /* install a signal handler for SIGUSR1 */ Signal_occurred = 0; Signal_count = 0; act.sa_handler = Handler_1; act.sa_flags = 0; sigaction( SIGUSR1, &act, NULL ); Signal_count = 0; Signal_occurred = 0; newHandler = Signal_handler; oldHandler = signal( SIGUSR1, newHandler ); if (oldHandler == Handler_1 ) puts("Init: signal return value verified"); else puts("Init: ERROR==> signal unexpected return value" ); status = sleep( 1 ); puts( "Init: send SIGUSR1 to process" ); status = kill( getpid(), SIGUSR1 ); status = sleep( 5 ); puts( "Init: send SIGFPE to process" ); status = _kill_r( NULL, getpid(), SIGFPE ); status = sleep(5); puts( "Init: send SIGILL to process" ); status = _kill_r( NULL, getpid(), SIGILL ); status = sleep(5); puts( "Init: send SIGSEGV to process" ); status = _kill_r( NULL, getpid(), SIGSEGV ); status = sleep(5); Timer_name[0]= rtems_build_name( 'T', 'M', '1', ' ' ); status = rtems_timer_create( Timer_name[0], &Timer_id[0]); Signal_count = 0; Signal_occurred = 0; puts( "Init: send SIGUSR1 to process from a TSR (interruptible sleep)" ); status = rtems_timer_fire_after( Timer_id[ 0 ], 1, Signal_duringISR_TSR, NULL ); sleep(5); /* signal occurs during interruptible sleep */ /* now schedule another one to fire but do not sleep */ puts( "Init: send SIGUSR1 to process from a TSR (spin)" ); start = rtems_clock_get_ticks_since_boot(); Signal_count = 0; Signal_occurred = 0; status = rtems_timer_fire_after( Timer_id[ 0 ], 10, Signal_duringISR_TSR, NULL ); do { end = rtems_clock_get_ticks_since_boot(); } while ( !Signal_occurred && ((end - start) <= 800)); if ( !Signal_occurred ) { puts( "Signal did not occur" ); rtems_test_exit(0); } /* end of install a signal handler for SIGUSR1 */ Signal_occurred = 0; puts("*** Validate unexpected program termination ***"); puts( "*** END OF POSIX TEST SIGNAL ***" ); _POSIX_signals_Abnormal_termination_handler( SIGUSR1 ); status = sleep( 1 ); puts( "ERROR==> Expected program termination"); rtems_test_exit(0); return NULL; /* just so the compiler thinks we returned something */ }
rtems_task Tasks_Periodic( rtems_task_argument argument ) { rtems_id rmid; rtems_id test_rmid; rtems_status_code status; bool scenario_done = 0; int start, stop, now; rtems_cbs_server_id server_id, tsid; rtems_cbs_parameters params, tparams; params.deadline = Periods[ argument ]; params.budget = Execution[ argument ]+1; if ( argument == 4 ) { if ( rtems_cbs_create_server( ¶ms, &overrun_handler_task_4, &server_id )) printf( "ERROR: CREATE SERVER FAILED\n" ); } else { if ( rtems_cbs_create_server( ¶ms, NULL, &server_id ) ) printf( "ERROR: CREATE SERVER FAILED\n" ); } if ( rtems_cbs_attach_thread( server_id, Task_id[ argument ] ) ) printf( "ERROR: ATTACH THREAD FAILED\n" ); if ( rtems_cbs_get_server_id( Task_id[ argument ], &tsid ) ) printf( "ERROR: GET SERVER ID FAILED\n" ); if ( tsid != server_id ) printf( "ERROR: SERVER ID MISMATCH\n" ); if ( rtems_cbs_get_parameters( server_id, &tparams ) ) printf( "ERROR: GET PARAMETERS FAILED\n" ); if ( params.deadline != tparams.deadline || params.budget != tparams.budget ) printf( "ERROR: PARAMETERS MISMATCH\n" ); status = rtems_rate_monotonic_create( argument, &rmid ); directive_failed( status, "rtems_rate_monotonic_create" ); put_name( Task_name[ argument ], FALSE ); printf( "- rtems_rate_monotonic_create id = 0x%08" PRIxrtems_id "\n", rmid ); status = rtems_rate_monotonic_ident( argument, &test_rmid ); directive_failed( status, "rtems_rate_monotonic_ident" ); put_name( Task_name[ argument ], FALSE ); printf( "- rtems_rate_monotonic_ident id = 0x%08" PRIxrtems_id "\n", test_rmid ); if ( rmid != test_rmid ) { printf( "RMID's DO NOT MATCH (0x%" PRIxrtems_id " and 0x%" PRIxrtems_id ")\n", rmid, test_rmid ); rtems_test_exit( 0 ); } put_name( Task_name[ argument ], FALSE ); printf( "- (0x%08" PRIxrtems_id ") period %" PRIu32 "\n", rmid, Periods[ argument ] ); status = rtems_task_wake_after( 2 + Phases[argument] ); directive_failed( status, "rtems_task_wake_after" ); while (FOREVER) { if (rtems_rate_monotonic_period(rmid, Periods[argument])==RTEMS_TIMEOUT) printf("P%" PRIdPTR " - Deadline miss\n", argument); start = rtems_clock_get_ticks_since_boot(); printf("P%" PRIdPTR "-S ticks:%d\n", argument, start); if ( start >= 2*HP_LENGTH ) break; /* stop */ /* Specific scenario for task 4: tries to exceed announced budget, the task priority has to be pulled down to background. */ now = rtems_clock_get_ticks_since_boot(); if ( !scenario_done && argument == 4 && now >= 200 ) { Violating_task[ argument ] = 1; scenario_done = 1; } /* Specific scenario for task 3: changes scheduling parameters. */ if ( !scenario_done && argument == 3 && now >= 250 ) { Periods[ argument ] = Periods[ argument ] * 2; Execution[ argument ] = Execution[ argument ] * 2; params.deadline = Periods[ argument ]; params.budget = Execution[ argument ]+1; if ( rtems_cbs_set_parameters( server_id, ¶ms) ) printf( "ERROR: SET PARAMETERS FAILED\n" ); if ( rtems_cbs_get_parameters( server_id, &tparams ) ) printf( "ERROR: GET PARAMETERS FAILED\n" ); if ( params.deadline != tparams.deadline || params.budget != tparams.budget ) printf( "ERROR: PARAMETERS MISMATCH\n" ); scenario_done = 1; } /* Specific scenario for task 2: late unblock after being blocked by itself, the task priority has to be pulled down to background. */ if ( !scenario_done && argument == 2 && now >= 500 ) { Violating_task[ argument ] = 1; scenario_done = 1; } if (argument == 2 && Violating_task[ argument ]) rtems_task_wake_after( 10 ); /* active computing */ while(FOREVER) { now = rtems_clock_get_ticks_since_boot(); if ( argument == 4 && !Violating_task[ argument ] && (now >= start + Execution[argument])) break; if ( argument != 4 && (now >= start + Execution[argument]) ) break; } stop = rtems_clock_get_ticks_since_boot(); printf("P%" PRIdPTR "-F ticks:%d\n", argument, stop); } /* delete period and SELF */ status = rtems_rate_monotonic_delete( rmid ); if ( status != RTEMS_SUCCESSFUL ) { printf("rtems_rate_monotonic_delete failed with status of %d.\n",status); rtems_test_exit( 0 ); } if ( rtems_cbs_cleanup() ) printf( "ERROR: CBS CLEANUP\n" ); fflush(stdout); TEST_END(); rtems_test_exit( 0 ); }
/** * Return current system time counter in microseconds */ static u32 get_time(void) { return rtems_clock_get_ticks_since_boot()*MICROSECONDS_PER_TICK; }
rtems_task Init (rtems_task_argument ignored) { int i; rtems_id semrec, semnorec; rtems_status_code sc; rtems_interval then, now; puts( "*** SP29 - SIMPLE SEMAPHORE TEST ***" ); puts( "This test only prints on errors." ); ticksPerSecond = rtems_clock_get_ticks_per_second(); if (ticksPerSecond <= 0) { printf( "Invalid ticks per second: %" PRIdrtems_interval "\n", ticksPerSecond ); exit (1); } sc = rtems_semaphore_create (rtems_build_name ('S', 'M', 'r', 'c'), 1, RTEMS_PRIORITY|RTEMS_BINARY_SEMAPHORE|RTEMS_INHERIT_PRIORITY| \ RTEMS_NO_PRIORITY_CEILING|RTEMS_LOCAL, 0, &semrec ); directive_failed( sc, "create recursive lock" ); sc = rtems_semaphore_create (rtems_build_name ('S', 'M', 'n', 'c'), 1, RTEMS_PRIORITY|RTEMS_SIMPLE_BINARY_SEMAPHORE|RTEMS_NO_INHERIT_PRIORITY| \ RTEMS_NO_PRIORITY_CEILING|RTEMS_LOCAL, 0, &semnorec ); directive_failed( sc, "create non-recursive lock" ); sc = rtems_semaphore_obtain (semrec, RTEMS_NO_WAIT, 0); directive_failed( sc, "obtain recursive lock" ); sc = rtems_semaphore_obtain (semrec, RTEMS_NO_WAIT, 0); directive_failed( sc, "reobtain recursive lock" ); sc = rtems_semaphore_obtain (semnorec, RTEMS_NO_WAIT, 0); directive_failed( sc, "reobtain recursive lock" ); sc = rtems_semaphore_obtain (semnorec, RTEMS_NO_WAIT, 0); if (sc == RTEMS_SUCCESSFUL) { printf( "%d: Reobtain non-recursive-lock semaphore -- and should not have.\n", __LINE__ ); rtems_test_exit(1); } sc = rtems_semaphore_release (semnorec); directive_failed( sc, "release non-recursive lock" ); sc = rtems_semaphore_release (semnorec); directive_failed( sc, "re-release non-recursive lock" ); sc = rtems_semaphore_obtain (semnorec, RTEMS_NO_WAIT, 0); directive_failed( sc, "obtain non-recursive lock" ); sc = rtems_semaphore_obtain (semnorec, RTEMS_NO_WAIT, 0); if (sc == RTEMS_SUCCESSFUL) { printf( "%d: Reobtain non-recursive-lock semaphore -- and should not have.\n", __LINE__ ); } else if (sc != RTEMS_UNSATISFIED) { printf( "%d: Reobtain non-recursive-lock semaphore failed, but error is " "%d (%s), not RTEMS_UNSATISFIED.\n", __LINE__, sc, rtems_status_text (sc) ); } sc = rtems_semaphore_release (semnorec); directive_failed( sc, "release non-recursive lock" ); sc = rtems_semaphore_release (semnorec); directive_failed( sc, "rerelease non-recursive lock" ); sc = rtems_semaphore_obtain (semnorec, RTEMS_NO_WAIT, 0); directive_failed( sc, "obtain non-recursive lock" ); /* * Since this task is holding this, this task will block and timeout. * Then the timeout error will be returned. */ then = rtems_clock_get_ticks_since_boot(); sc = rtems_semaphore_obtain (semnorec, RTEMS_WAIT, 5); now = rtems_clock_get_ticks_since_boot(); if (sc == RTEMS_SUCCESSFUL) { printf( "%d: Reobtain non-recursive-lock semaphore -- and should not have.\n", __LINE__ ); } else if (sc != RTEMS_TIMEOUT) { printf( "%d: Reobtain non-recursive-lock semaphore failed, but error is " "%d (%s), not RTEMS_TIMEOUT.\n", __LINE__, sc, rtems_status_text (sc) ); } if ((then - now) < 4) { printf( "%d: Reobtain non-recursive-lock semaphore failed without timeout.\n", __LINE__ ); } startTask (semnorec); then = rtems_clock_get_ticks_since_boot(); for (i = 0 ; i < 5 ; i++) { rtems_interval diff; sc = rtems_semaphore_obtain( semnorec, RTEMS_WAIT, RTEMS_NO_TIMEOUT ); now = rtems_clock_get_ticks_since_boot(); diff = (now - then); then = now; if (sc != RTEMS_SUCCESSFUL) { printf( "%d: Failed to obtain non-recursive-lock semaphore: %s\n", __LINE__, rtems_status_text (sc) ); } else if (diff < (int) (2 * ticksPerSecond)) { printf( "%d: Obtained obtain non-recursive-lock semaphore too quickly -- %" PRIdrtems_interval " ticks not %" PRIdrtems_interval " ticks\n", __LINE__, diff, (2 * ticksPerSecond) ); } } puts( "*** END OF TEST 29 ***" ); rtems_test_exit (0); }
static portCHAR *http_generate_platform_stats_page( void ) { portCHAR dynamic_text[ 128 ] = { 0 }; portCHAR headerRow[ 128 ]; rtems_interval elapsed_time = rtems_clock_get_ticks_since_boot() / rtems_clock_get_ticks_per_second(); uint32_t hours; uint32_t minutes; uint32_t seconds; hours = elapsed_time / 3600UL; elapsed_time -= hours * 3600UL; minutes = elapsed_time / 60; elapsed_time -= minutes * 60; seconds = elapsed_time; memset( DYNAMIC_PAGE_CONTENT, 0, sizeof( DYNAMIC_PAGE_CONTENT ) ); /* Update the hit count */ nPageHits++; strncat( DYNAMIC_PAGE_CONTENT, PAGE_HEADER_DYNAMIC, sizeof( DYNAMIC_PAGE_CONTENT ) - strlen( DYNAMIC_PAGE_CONTENT ) ); snprintf( dynamic_text, sizeof( dynamic_text ), "Page refresh count %d", (int) nPageHits ); strncat( DYNAMIC_PAGE_CONTENT, dynamic_text, sizeof( DYNAMIC_PAGE_CONTENT ) - strlen( DYNAMIC_PAGE_CONTENT ) ); snprintf( dynamic_text, sizeof( dynamic_text ), "<p>Number of Ethernet Packets (RX: %lu, TX %lu)", stm32f_ethernet_get_num_rx_msg(), stm32f_ethernet_get_num_tx_msg() ); strncat( DYNAMIC_PAGE_CONTENT, dynamic_text, sizeof( DYNAMIC_PAGE_CONTENT ) - strlen( DYNAMIC_PAGE_CONTENT ) ); snprintf( dynamic_text, sizeof( dynamic_text ), "<p>Uptime: %lu hours, %lu minutes, %lu second", hours, minutes, seconds); strncat( DYNAMIC_PAGE_CONTENT, dynamic_text, sizeof( DYNAMIC_PAGE_CONTENT ) - strlen( DYNAMIC_PAGE_CONTENT ) ); #ifdef REPORT_STACK_USAGE static uint32_t last_stack_report = 0; if(last_stack_report != minutes) { rtems_stack_checker_report_usage(); last_stack_report = minutes; } #endif snprintf( headerRow, sizeof( headerRow ), "<pre><br>%4s\t%16s\t%8s\t%10s\t%8s", "Name", "Task State", "Stk Addr", "Stk Sz", "rtems_id" ); strncat( (char *) DYNAMIC_PAGE_CONTENT, headerRow, sizeof( DYNAMIC_PAGE_CONTENT ) - strlen( DYNAMIC_PAGE_CONTENT ) ); strncat( (char *) DYNAMIC_PAGE_CONTENT, "<br>------------------------------------------------------------------------------<br>", sizeof( DYNAMIC_PAGE_CONTENT ) - strlen( DYNAMIC_PAGE_CONTENT ) ); /* The list of tasks and their status */ osThreadList( (unsigned char *) ( DYNAMIC_PAGE_CONTENT + strlen( DYNAMIC_PAGE_CONTENT ) ) ); strncat( (char *) DYNAMIC_PAGE_CONTENT, "<br>--------------------------------------------------------------------------</pre></body></html>", sizeof( DYNAMIC_PAGE_CONTENT ) - strlen( DYNAMIC_PAGE_CONTENT ) ); return (portCHAR *) DYNAMIC_PAGE_CONTENT; }