/** * @brief closes sci peripheral of interrupt driven driver * * calls tms570_sci_poll_last_close and disables interrupts * * @param[in] tty Termios control * @param[in] base context of the driver * @param[in] args * @retval false Error occured during initialization * @retval true Driver is open and ready */ static void tms570_sci_interrupt_last_close( rtems_termios_tty *tty, rtems_termios_device_context *base, rtems_libio_open_close_args_t *args ) { tms570_sci_context *ctx = (tms570_sci_context *) base; rtems_interrupt_lock_context lock_context; rtems_interval tw; int32_t baudrate; /* Turn off RX interrupts */ rtems_termios_device_lock_acquire(base, &lock_context); tms570_sci_disable_interrupts(ctx); rtems_termios_device_lock_release(base, &lock_context); tw = rtems_clock_get_ticks_per_second(); baudrate = rtems_termios_baud_to_number(cfgetospeed(&tty->termios)); tw = tw * 10 / baudrate + 1; while ( ( ctx->regs->FLR & TMS570_SCI_FLR_TX_EMPTY ) == 0 ) { rtems_task_wake_after(tw); } /* uninstall ISR */ rtems_interrupt_handler_remove(ctx->irq, tms570_sci_interrupt_handler, tty); tms570_sci_poll_last_close(tty, base, args); }
rtems_task Task_1_through_3( rtems_task_argument argument ) { rtems_id tid; rtems_time_of_day time; rtems_status_code status; status = rtems_task_ident( RTEMS_SELF, RTEMS_SEARCH_ALL_NODES, &tid ); directive_failed( status, "rtems_task_ident of self" ); while ( FOREVER ) { status = rtems_timer_server_fire_after( Timer_id[ argument ], (task_number( tid ) - 1) * 5 * rtems_clock_get_ticks_per_second(), Resume_task, (void *) &tid ); directive_failed( status, "rtems_timer_server_fire_after failed" ); status = rtems_clock_get_tod( &time ); directive_failed( status, "rtems_clock_get_tod failed" ); if ( time.second >= 35 ) { puts( "*** END OF TEST 30 ***" ); rtems_test_exit( 0 ); } put_name( Task_name[ task_number( tid ) - 1 ], FALSE ); print_time( " - rtems_clock_get_tod - ", &time, "\n" ); status = rtems_task_suspend( RTEMS_SELF ); directive_failed( status, "rtems_task_suspend" ); } }
rtems_task Task_1( rtems_task_argument argument ) { rtems_status_code status; rtems_id tid; rtems_time_of_day time; uint32_t task_index; INTEGER_DECLARE; status = rtems_task_ident( RTEMS_SELF, RTEMS_SEARCH_ALL_NODES, &tid ); directive_failed( status, "rtems_task_ident" ); task_index = task_number( tid ); INTEGER_LOAD( INTEGER_factors[ task_index ] ); put_name( Task_name[ task_index ], FALSE ); printf( " - integer base = (0x%" PRIx32 ")\n", INTEGER_factors[ task_index ] ); while( FOREVER ) { status = rtems_clock_get_tod( &time ); directive_failed( status, "rtems_clock_get_tod" ); put_name( Task_name[ task_number( tid ) ], FALSE ); print_time( " - rtems_clock_get_tod - ", &time, "\n" ); INTEGER_CHECK( INTEGER_factors[ task_index ] ); status = rtems_task_wake_after( ( task_number( tid ) ) * 5 * rtems_clock_get_ticks_per_second() ); directive_failed( status, "rtems_task_wake_after" ); } }
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 ); }
rtems_task Test_task( rtems_task_argument unused ) { rtems_id tid; rtems_time_of_day time; uint32_t task_index; rtems_status_code status; status = rtems_task_ident( RTEMS_SELF, RTEMS_SEARCH_ALL_NODES, &tid ); directive_failed( status, "task ident" ); task_index = task_number( tid ); for ( ; ; ) { status = rtems_clock_get_tod( &time ); if ( time.second >= 35 ) { puts( "*** END OF CLOCK TICK TEST ***" ); rtems_test_exit( 0 ); } put_name( Task_name[ task_index ], FALSE ); print_time( " - rtems_clock_get_tod - ", &time, "\n" ); status = rtems_task_wake_after( task_index * 5 * rtems_clock_get_ticks_per_second() ); directive_failed( status, "wake after" ); } }
rtems_task Test_task( rtems_task_argument unused ) { rtems_status_code status; for ( ; ; ) { /* Semaphore not available, ensured to block */ status = rtems_semaphore_obtain( Sem_id, RTEMS_DEFAULT_OPTIONS, RTEMS_NO_TIMEOUT ); if ( status != RTEMS_SUCCESSFUL ) fputs( "Task - obtain did not work\n", stderr ); LED_ON(); status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() ); assert( status == RTEMS_SUCCESSFUL ); /* Transfers semaphore to Init task */ status = rtems_semaphore_release( Sem_id ); if ( status != RTEMS_SUCCESSFUL ) fputs( "Task - release did not work\n", stderr ); } }
rtems_task Task_2( rtems_task_argument argument ) { rtems_status_code status; rtems_time_of_day time; rtems_name name; status = rtems_object_get_classic_name( rtems_task_self(), &name ); directive_failed( status, "rtems_object_get_classic_name" ); while( FOREVER ) { status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() ); directive_failed( status, "rtems_task_wake_after" ); status = rtems_clock_get_tod( &time ); directive_failed( status, "rtems_clock_get_tod" ); if ( time.second >= 17 ) { puts( "*** END OF TEST 3 *** " ); rtems_test_exit( 0 ); } put_name( name, FALSE ); print_time( " ", &time, "\n" ); } }
rtems_task Test_task( rtems_task_argument unused ) { rtems_id tid; rtems_time_of_day time; uint32_t task_index; rtems_status_code status; char name[5]; char *p; /* Get the task name */ p = rtems_object_get_name( RTEMS_SELF, 5, name ); rtems_test_assert( p != NULL ); status = rtems_task_ident( RTEMS_SELF, RTEMS_SEARCH_ALL_NODES, &tid ); rtems_test_assert( status == RTEMS_SUCCESSFUL ); task_index = task_number( tid ); for ( ; ; ) { status = rtems_clock_get_tod( &time ); rtems_test_assert( status == RTEMS_SUCCESSFUL ); if ( time.second >= 35 ) { TEST_END(); rtems_test_exit( 0 ); } PrintTaskInfo( p, &time ); status = rtems_task_wake_after( task_index * 5 * rtems_clock_get_ticks_per_second() ); rtems_test_assert( status == RTEMS_SUCCESSFUL ); } }
void Receive_messages() { rtems_status_code status; uint32_t index; size_t size; char receive_buffer[16]; for ( index=1 ; index <=3 ; index++ ) { puts( "Receiving message ..." ); status = rtems_message_queue_receive( Queue_id[ 1 ], receive_buffer, &size, RTEMS_DEFAULT_OPTIONS, RTEMS_NO_TIMEOUT ); directive_failed( status, "rtems_message_queue_receive" ); puts_nocr( "Received : "); puts( receive_buffer ); } puts( "Receiver delaying for a second" ); status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() ); directive_failed( status, "rtems_task_wake_after" ); }
rtems_task Init( rtems_task_argument argument ) { rtems_status_code status; rtems_id period_id; rtems_interval ticks; uint32_t count; puts( "\n\n*** LED BLINKER -- single period ***" ); LED_INIT(); status = rtems_rate_monotonic_create( rtems_build_name( 'P', 'E', 'R', '1' ), &period_id ); ticks = rtems_clock_get_ticks_per_second(); for (count=0; ; count++) { status = rtems_rate_monotonic_period( period_id, ticks ); if ( (count % 2) == 0 ) LED_OFF(); else LED_ON(); } status = rtems_task_delete( RTEMS_SELF ); }
rtems_status_code rtems_bsd_initialize(void) { rtems_status_code sc = RTEMS_SUCCESSFUL; hz = (int) rtems_clock_get_ticks_per_second(); tick = 1000000 / hz; maxusers = 1; gettimeofday(&boottime, NULL); timeval2bintime(&boottime, &boottimebin); mkdir("/etc", S_IRWXU | S_IRWXG | S_IRWXO); sc = rtems_timer_initiate_server( BSD_TASK_PRIORITY_TIMER, BSD_MINIMUM_TASK_STACK_SIZE, RTEMS_DEFAULT_ATTRIBUTES ); if (sc != RTEMS_SUCCESSFUL) { return RTEMS_UNSATISFIED; } mutex_init(); mi_startup(); return RTEMS_SUCCESSFUL; }
rtems_task Init( rtems_task_argument argument ) { rtems_status_code status; puts( "\n\n*** LED BLINKER -- timer_server ***" ); LED_INIT(); status = rtems_timer_initiate_server( 1, RTEMS_MINIMUM_STACK_SIZE * 2, RTEMS_DEFAULT_ATTRIBUTES ); if ( status != RTEMS_SUCCESSFUL ) fputs( "timer create server failed\n", stderr ); status = rtems_timer_create(rtems_build_name( 'T', 'M', 'R', '1' ), &Timer1); if ( status != RTEMS_SUCCESSFUL ) fputs( "Timer1 create failed\n", stderr ); status = rtems_timer_create(rtems_build_name( 'T', 'M', 'R', '2' ), &Timer2); if ( status != RTEMS_SUCCESSFUL ) fputs( "Timer2 create failed\n", stderr ); Timer_Routine(Timer1, NULL); status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() ); Timer_Routine(Timer2, NULL); status = rtems_task_delete( RTEMS_SELF ); }
rtems_task Test_task( rtems_task_argument arg ) { rtems_time_of_day time; uint32_t task_index; rtems_status_code status; task_index = arg; for ( ; ; ) { status = rtems_clock_get_tod( &time ); directive_failed( status, "get tod" ); if ( time.second >= 15 ) { puts( "*** END OF SP73 (YIELD) TEST ***" ); rtems_test_exit( 0 ); } put_name( Task_name[ task_index ], FALSE ); print_time( " - rtems_clock_get_tod - ", &time, "\n" ); status = rtems_task_wake_after( task_index * 5 * rtems_clock_get_ticks_per_second() ); directive_failed( status, "wake after" ); } }
rtems_task Init( rtems_task_argument argument ) { rtems_status_code status; puts( "\n\n*** LED BLINKER -- timer ***" ); LED_INIT(); status = rtems_timer_create(rtems_build_name( 'T', 'M', 'R', '1' ), &Timer1); if ( status != RTEMS_SUCCESSFUL ) fputs( "Timer1 create failed\n", stderr ); status = rtems_timer_create(rtems_build_name( 'T', 'M', 'R', '2' ), &Timer2); if ( status != RTEMS_SUCCESSFUL ) fputs( "Timer2 create failed\n", stderr ); Timer_Routine(Timer1, NULL); LED_Change_Routine(); status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() ); Timer_Routine(Timer2, NULL); LED_Change_Routine(); while (1) { status = rtems_task_wake_after( 10 ); LED_Change_Routine(); } status = rtems_task_delete( RTEMS_SELF ); }
void Task_2_through_4(void) { ID tid; int tid_index; rtems_time_of_day time; ER status; char name[30]; status = get_tid( &tid ); directive_failed( status, "get_tid"); tid_index = tid - 1; /* account for init tasks */ sprintf(name, "TA%d", tid_index); while( FOREVER ) { status = rtems_clock_get_tod( &time ); directive_failed( status, "rtems_clock_get_tod" ); if ( time.second >= 35 ) { puts( "*** END OF ITRON TASK TEST 1 ***" ); rtems_test_exit( 0 ); } printf(name); print_time( " - rtems_clock_get_tod - ", &time, "\n" ); status = rtems_task_wake_after( tid_index * 5 * rtems_clock_get_ticks_per_second() ); directive_failed( status, "rtems_task_wake_after" ); } }
void Task_2() { rtems_status_code status; puts( "TA2 - rtems_task_wake_after - sleep 1 minute" ); status = rtems_task_wake_after( 60*rtems_clock_get_ticks_per_second() ); directive_failed( status, "rtems_task_wake_after in TA2" ); }
rtems_task gyroscope_task(rtems_task_argument arg) { printf("gyroscope task started\n"); for (;;) { rtems_task_wake_after(5 * rtems_clock_get_ticks_per_second()); } }
/****************************************************************************** ** Function: OS_TicksToUsec ** ** Purpose: Convert a number of Ticks to microseconds ** */ void OS_TicksToUsecs(rtems_interval ticks, uint32 *usecs) { rtems_interval ticks_per_sec = rtems_clock_get_ticks_per_second(); uint32 usecs_per_tick; usecs_per_tick = (1000000)/ticks_per_sec; *usecs = ticks * usecs_per_tick; }
rtems_task Init( rtems_task_argument argument ) { rtems_status_code status; rtems_id task_id; rtems_name task_name; puts( "\n\n*** LED BLINKER -- semaphore ping/pong ***" ); LED_INIT(); status = rtems_semaphore_create( rtems_build_name( 'S', 'E', 'M', ' ' ), 0, /* created locked */ RTEMS_DEFAULT_ATTRIBUTES, 0, &Sem_id ); assert( status == RTEMS_SUCCESSFUL ); task_name = rtems_build_name( 'T', 'A', '1', ' ' ); status = rtems_task_create( task_name, 1, RTEMS_MINIMUM_STACK_SIZE * 2, RTEMS_DEFAULT_MODES, RTEMS_DEFAULT_ATTRIBUTES, &task_id ); assert( status == RTEMS_SUCCESSFUL ); status = rtems_task_start( task_id, Test_task, 1 ); assert( status == RTEMS_SUCCESSFUL ); while (1) { LED_OFF(); status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() ); assert( status == RTEMS_SUCCESSFUL ); /* Transfers semaphore to TA1 */ status = rtems_semaphore_release( Sem_id ); if ( status != RTEMS_SUCCESSFUL ) fputs( "init - release did not work\n", stderr ); /* Semaphore not available, ensured to block */ status = rtems_semaphore_obtain( Sem_id, RTEMS_DEFAULT_OPTIONS, RTEMS_NO_TIMEOUT ); if ( status != RTEMS_SUCCESSFUL ) fputs( "init - obtain did not work\n", stderr ); } status = rtems_task_delete( RTEMS_SELF ); assert( status == RTEMS_SUCCESSFUL ); }
rtems_task Test_task( rtems_task_argument argument ) { rtems_status_code status; rtems_id tid; rtems_time_of_day time; status = rtems_task_ident( RTEMS_SELF, RTEMS_SEARCH_ALL_NODES, &tid ); directive_failed( status, "rtems_task_ident" ); status = rtems_clock_get_tod( &time ); directive_failed( status, "rtems_clock_get_tod" ); put_name( Task_name[ task_number( tid ) ], FALSE ); print_time( " - rtems_clock_get_tod - ", &time, "\n" ); status = rtems_task_wake_after( task_number( tid ) * 1 * rtems_clock_get_ticks_per_second() ); directive_failed( status, "rtems_task_wake_after" ); status = rtems_clock_get_tod( &time ); directive_failed( status, "rtems_clock_get_tod" ); put_name( Task_name[ task_number( tid ) ], FALSE ); print_time( " - rtems_clock_get_tod - ", &time, "\n" ); if ( task_number(tid) == 1 ) { /* TASK 1 */ put_name( Task_name[ 1 ], FALSE ); printf( " - deleting self\n" ); status = rtems_task_delete( RTEMS_SELF ); directive_failed( status, "rtems_task_delete of RTEMS_SELF" ); } else if ( task_number(tid) == 2 ) { /* TASK 2 */ put_name( Task_name[ 2 ], FALSE ); printf( " - waiting to be deleted by " ); put_name( Task_name[ 3 ], TRUE ); while ( FOREVER ); } else { /* TASK 3 */ put_name( Task_name[ 3 ], FALSE ); printf( " - getting TID of " ); put_name( Task_name[ 2 ], TRUE ); do { status = rtems_task_ident( Task_name[ 2 ], RTEMS_SEARCH_ALL_NODES, &tid ); } while ( status != RTEMS_SUCCESSFUL ); directive_failed( status, "rtems_task_ident" ); put_name( Task_name[ 3 ], FALSE ); printf( " - deleting " ); put_name( Task_name[ 2 ], TRUE ); status = rtems_task_delete( tid ); directive_failed( status, "rtems_task_delete of Task 2" ); puts( "*** END OF TEST 1 ***" ); rtems_test_exit(0); } }
void task1 (void) { ticksPerSecond = rtems_clock_get_ticks_per_second(); createTask ('1', &taskId1); createTask ('2', &taskId2); startTask (taskId1, subTask1); startTask (taskId2, subTask2); rtems_task_suspend (RTEMS_SELF); }
void Non_Dormant_task(void) { ER status; while (TRUE) { puts( "NON-DORMANT - Sleep for 2 minutes" ); status = rtems_task_wake_after( 120*rtems_clock_get_ticks_per_second() ); directive_failed( status, "rtems_task_wake_after" ); } }
rtems_task Task_1_through_5( rtems_task_argument argument ) { int i; unsigned int passes = 0; rtems_id tid; rtems_time_of_day time; rtems_status_code status; unsigned char *mem_ptr; int mem_amt; status = rtems_task_ident( RTEMS_SELF, RTEMS_SEARCH_ALL_NODES, &tid ); directive_failed( status, "rtems_task_ident" ); while (TRUE) { bool malloc_walk_ok; if ( passes++ > NUM_PASSES ) { TEST_END(); rtems_test_exit(0); } status = rtems_clock_get_tod( &time ); directive_failed( status, "rtems_clock_get_tod" ); put_name( Task_name[ task_number( tid ) ], FALSE ); print_time( " - rtems_clock_get_tod - ", &time, "\n" ); mem_amt = ((int)((float)rand()*1000.0/(float)RAND_MAX)); while (!(mem_ptr = malloc ( mem_amt))) { printf("out of memory... trying again.\n"); mem_amt = ((int)((float)rand()*1000.0/(float)RAND_MAX)); } printf("mallocing %d bytes\n",mem_amt); memset( mem_ptr, mem_amt, mem_amt ); malloc_report_statistics(); malloc_walk_ok = malloc_walk( 1, false ); rtems_test_assert( malloc_walk_ok ); status = rtems_task_wake_after( task_number( tid ) * 1 * rtems_clock_get_ticks_per_second()/4 ); for (i=0; i < mem_amt; i++) { if ( mem_ptr[i] != (mem_amt & 0xff)) { printf("failed %d, %d, 0x%x, 0x%x\n",i,mem_amt,mem_ptr[i],mem_amt&0xff); rtems_test_exit(1); } } directive_failed( status, "rtems_task_wake_after" ); free( mem_ptr ); } }
rtems_task Init( rtems_task_argument argument ) { rtems_status_code status; puts( "\n\n*** LED BLINKER -- task wake after ***" ); LED_INIT(); while (1) { (void) rtems_task_wake_after( 1 * rtems_clock_get_ticks_per_second() ); LED_OFF(); (void) rtems_task_wake_after( 1 * rtems_clock_get_ticks_per_second() ); LED_ON(); } status = rtems_task_delete( RTEMS_SELF ); }
rtems_task Task_3( rtems_task_argument argument ) { rtems_status_code status; puts( "TA3 - rtems_task_wake_after - sleep 5 seconds" ); status = rtems_task_wake_after( 5*rtems_clock_get_ticks_per_second() ); directive_failed( status, "rtems_task_wake_after in TA3" ); puts( "TA3 - rtems_task_delete - delete self" ); status = rtems_task_delete( RTEMS_SELF ); directive_failed( status, "rtems_task_delete of TA3" ); }
rtems_timer_service_routine Timer_Routine( rtems_id id, void *ignored ) { rtems_status_code status; if ( id == Timer1 ) LED_OFF(); else LED_ON(); status = rtems_timer_server_fire_after( id, 2 * rtems_clock_get_ticks_per_second(), Timer_Routine, NULL ); }
rtems_task Task_3( rtems_task_argument argument ) { rtems_status_code status; puts( "TA3 - rtems_task_suspend - suspend self" ); status = rtems_task_suspend( RTEMS_SELF ); directive_failed( status, "rtems_task_suspend of TA3" ); while( FOREVER ) { puts( "TA3 - rtems_task_wake_after - sleep 1 second" ); status = rtems_task_wake_after( rtems_clock_get_ticks_per_second() ); directive_failed( status, "rtems_task_wake_after of TA3" ); } }
rtems_timer_service_routine Timer_Routine(rtems_id id, void *ignored) { rtems_status_code status; Fired++; timerRan = true; status = rtems_timer_server_fire_after( id, rtems_clock_get_ticks_per_second(), Timer_Routine, NULL ); directive_failed( status, "fire after" ); }
rtems_timer_service_routine Timer_Routine( rtems_id id, void *ignored ) { rtems_status_code status; if ( id == Timer1 ) led_value = 1; else led_value = 2; led_do_print = 1; status = rtems_timer_fire_after( id, 2 * rtems_clock_get_ticks_per_second(), Timer_Routine, NULL ); }
void Task_3() { rtems_status_code status; /* * XXX - Convert Later. */ puts( "TA3 - rtems_task_wake_after - sleep 5 seconds" ); status = rtems_task_wake_after( 5*rtems_clock_get_ticks_per_second() ); directive_failed( status, "rtems_task_wake_after in TA3" ); puts( "TA3 - exd_tsk - exit and delete self" ); exd_tsk(); directive_failed( 0, "exd_tsk" ); }