diff options
Diffstat (limited to 'classic_api/triple_period')
-rw-r--r-- | classic_api/triple_period/.cvsignore | 1 | ||||
-rw-r--r-- | classic_api/triple_period/Makefile | 25 | ||||
-rw-r--r-- | classic_api/triple_period/init.c | 77 | ||||
-rw-r--r-- | classic_api/triple_period/system.h | 136 | ||||
-rw-r--r-- | classic_api/triple_period/tasks.c | 170 |
5 files changed, 409 insertions, 0 deletions
diff --git a/classic_api/triple_period/.cvsignore b/classic_api/triple_period/.cvsignore new file mode 100644 index 0000000..fecf58a --- /dev/null +++ b/classic_api/triple_period/.cvsignore @@ -0,0 +1 @@ +o-optimize diff --git a/classic_api/triple_period/Makefile b/classic_api/triple_period/Makefile new file mode 100644 index 0000000..32f9eef --- /dev/null +++ b/classic_api/triple_period/Makefile @@ -0,0 +1,25 @@ +# +# $Id$ +# + +PGM=${ARCH}/triple_period.exe + +# optional managers required +MANAGERS=all + +# C source names, if any, go here -- minus the .c +CSRCS = init.c tasks.c +COBJS = $(CSRCS:%.c=${ARCH}/%.o) + +H_FILES=system.h + +OBJS=$(COBJS) + +include $(RTEMS_MAKEFILE_PATH)/Makefile.inc +include $(RTEMS_CUSTOM) +include $(RTEMS_ROOT)/make/leaf.cfg + +all: ${ARCH} $(PGM) + +${PGM}: ${OBJS} + $(make-exe) diff --git a/classic_api/triple_period/init.c b/classic_api/triple_period/init.c new file mode 100644 index 0000000..f35494a --- /dev/null +++ b/classic_api/triple_period/init.c @@ -0,0 +1,77 @@ +/* + * COPYRIGHT (c) 1989-2007. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ +/* updated for triple test, 2003/11/06, Erik Adli */ + +#define CONFIGURE_INIT +#include "system.h" +#include <inttypes.h> +#include <stdio.h> + +/* + * Keep the names and IDs in global variables so another task can use them. + */ +rtems_id Task_id[ 4 ]; /* array of task ids */ +rtems_name Task_name[ 4 ]; /* array of task names */ + +rtems_task Init( + rtems_task_argument argument +) +{ + rtems_status_code status; + rtems_time_of_day time; + uint32_t ticks_per_second, ticks_since_boot; + + puts( "\n\n\n*** PERIODIC TASKING TRIPLE TEST ***" ); + puts( "*** This demo shows three different ways of running periodic tasks ***" ); + puts( "*** It also demonstrates the CPU usage and Rate Monotonic statitistics utilities ***" ); + + rtems_clock_get( RTEMS_CLOCK_GET_TICKS_PER_SECOND, &ticks_per_second ); + printf("\nTicks per second in your system: %" PRIu32 "\n", ticks_per_second); + rtems_clock_get( RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &ticks_since_boot ); + printf("Ticks since boot: %" PRIu32 "\n\n", ticks_since_boot); + + time.year = 1988; + time.month = 12; + time.day = 31; + time.hour = 9; + time.minute = 0; + time.second = 0; + time.ticks = 0; + + status = rtems_clock_set( &time ); + + Task_name[ 1 ] = rtems_build_name( 'T', 'A', '1', ' ' ); + Task_name[ 2 ] = rtems_build_name( 'T', 'A', '2', ' ' ); + Task_name[ 3 ] = rtems_build_name( 'T', 'A', '3', ' ' ); + + // prototype: rtems_task_create( name, initial_priority, stack_size, initial_modes, attribute_set, *id ); + status = rtems_task_create( + Task_name[ 1 ], 1, RTEMS_MINIMUM_STACK_SIZE * 2, RTEMS_DEFAULT_MODES, + RTEMS_DEFAULT_ATTRIBUTES, &Task_id[ 1 ] + ); + status = rtems_task_create( + Task_name[ 2 ], 1, RTEMS_MINIMUM_STACK_SIZE * 2, RTEMS_DEFAULT_MODES, + RTEMS_DEFAULT_ATTRIBUTES, &Task_id[ 2 ] + ); + status = rtems_task_create( + Task_name[ 3 ], 1, RTEMS_MINIMUM_STACK_SIZE * 2, RTEMS_DEFAULT_MODES, + RTEMS_DEFAULT_ATTRIBUTES, &Task_id[ 3 ] + ); + + // prototype: rtems_task_start( id, entry_point, argument ); + status = rtems_task_start( Task_id[ 1 ], Task_Absolute_Period, 1 ); + status = rtems_task_start( Task_id[ 2 ], Task_Rate_Monotonic_Period, 2 ); + status = rtems_task_start( Task_id[ 3 ], Task_Relative_Period, 3 ); + + + // delete init task after starting the three working tasks + status = rtems_task_delete( RTEMS_SELF ); +} diff --git a/classic_api/triple_period/system.h b/classic_api/triple_period/system.h new file mode 100644 index 0000000..4538bf8 --- /dev/null +++ b/classic_api/triple_period/system.h @@ -0,0 +1,136 @@ +/* + * + * COPYRIGHT (c) 1989-2007. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ +/* updated for triple test, 20003/11/06, Erik Adli */ + + +#include <inttypes.h> +#include <rtems.h> + +/* functions */ + +rtems_task Init( + rtems_task_argument argument +); + +rtems_task Task_Absolute_Period( + rtems_task_argument argument +); + +rtems_task Task_Rate_Monotonic_Period( + rtems_task_argument argument +); + +rtems_task Task_Relative_Period( + rtems_task_argument argument +); + +/* global variables */ + +/* + * Keep the names and IDs in global variables so another task can use them. + */ +extern rtems_id Task_id[ 4 ]; /* array of task ids */ +extern rtems_name Task_name[ 4 ]; /* array of task names */ + + + +/* configuration information */ + +#include <bsp.h> /* for device driver prototypes */ + +#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER + +#define CONFIGURE_MICROSECONDS_PER_TICK 500 // NB: 10 and lower gives system failure for erc32 simulator + +#define CONFIGURE_MAXIMUM_TASKS 4 + +#define CONFIGURE_EXTRA_TASK_STACKS (6 * RTEMS_MINIMUM_STACK_SIZE) + +// Needed for RM Mangager +#define CONFIGURE_MAXIMUM_PERIODS 1 + +#define CONFIGURE_RTEMS_INIT_TASKS_TABLE + + +/* Needed for erc32 simulator.. */ +/* ..for using "CPU_usage_Dump", since it uses printf("%f") if your processor has floating points) */ +/* If you want to take away FP support (to avoid heavy context switch), you must rewrite CPU_usage_Dump instead */ +#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT + + +#include <rtems/confdefs.h> + +/* + * Handy macros and static inline functions + */ + +/* + * Macro to hide the ugliness of printing the time. + */ + +#define print_time(_s1, _tb, _s2) \ + do { \ + printf( "%s%02" PRIu32 ":%02" PRIu32 ":%02" PRIu32 \ + " %02" PRIu32 "/%02" PRIu32 "/%04" PRIu32 "%s", \ + _s1, (_tb)->hour, (_tb)->minute, (_tb)->second, \ + (_tb)->month, (_tb)->day, (_tb)->year, _s2 ); \ + fflush(stdout); \ + } while ( 0 ) + +/* + * Macro to print an task name that is composed of ASCII characters. + * + */ + +#define put_name( _name, _crlf ) \ + do { \ + uint32_t c0, c1, c2, c3; \ + \ + c0 = ((_name) >> 24) & 0xff; \ + c1 = ((_name) >> 16) & 0xff; \ + c2 = ((_name) >> 8) & 0xff; \ + c3 = (_name) & 0xff; \ + putchar( (char)c0 ); \ + if ( c1 ) putchar( (char)c1 ); \ + if ( c2 ) putchar( (char)c2 ); \ + if ( c3 ) putchar( (char)c3 ); \ + if ( (_crlf) ) \ + putchar( '\n' ); \ + } while (0) + +/* + * static inline routine to make obtaining ticks per second easier. + */ + +static inline uint32_t get_ticks_per_second( void ) +{ + rtems_interval ticks_per_second; + (void) rtems_clock_get( RTEMS_CLOCK_GET_TICKS_PER_SECOND, &ticks_per_second ); return ticks_per_second; +} + + +/* + * This allows us to view the "Test_task" instantiations as a set + * of numbered tasks by eliminating the number of application + * tasks created. + * + * In reality, this is too complex for the purposes of this + * example. It would have been easier to pass a task argument. :) + * But it shows how rtems_id's can sometimes be used. + */ + +#define task_number( tid ) \ + ( rtems_get_index( tid ) - \ + rtems_configuration_get_rtems_api_configuration()->number_of_initialization_tasks ) + +/* end of include file */ diff --git a/classic_api/triple_period/tasks.c b/classic_api/triple_period/tasks.c new file mode 100644 index 0000000..dbf1f6e --- /dev/null +++ b/classic_api/triple_period/tasks.c @@ -0,0 +1,170 @@ +/* + * COPYRIGHT (c) 1989-2007. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ +/* updated for triple test, 20003/11/06, Erik Adli */ + +#include "system.h" +#include <stdio.h> +#include <stdlib.h> + +/* CPU usage and Rate monotonic manger statistics */ +#include "rtems/cpuuse.h" + +// Periods for the various tasks [seconds] +#define PERIOD_TASK_ABSOLUTE 1 +#define PERIOD_TASK_RATE_MONOTONIC 2 +#define PERIOD_TASK_RELATIVE 3 + + + +// TASK 1 +// +// * Absolute timing for task 1 +// * CPU usage statistics +// * Demo end criteria +// +rtems_task Task_Absolute_Period( + rtems_task_argument unused +) +{ + rtems_time_of_day time; + rtems_status_code status; + uint32_t ticks_since_boot; + uint32_t count; + + count = 0; + rtems_cpu_usage_reset(); + + while( 1 ) { + status = rtems_clock_get( RTEMS_CLOCK_GET_TOD, &time ); + count++; + + // sets end criteria for demo application (60 seconds) + if ( time.second >= 60 ) { + puts( "*** END OF PERIODIC TASKING TRIPLE TEST ***" ); + exit( 0 ); + } + + printf( + "\n\nTask 1 - activating every %d second using " + "absolute time (rtems_task_wake_when)\n", + PERIOD_TASK_ABSOLUTE + ); + print_time( " - rtems_clock_get - ", &time, "\n" ); + rtems_clock_get( RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &ticks_since_boot ); + printf(" - Ticks since boot: %" PRIu32 "\n", ticks_since_boot); + + rtems_time_of_day time; + + time.year = 1988; + time.month = 12; + time.day = 31; + time.hour = 9; + time.minute = 0; + time.second = count * PERIOD_TASK_ABSOLUTE; // Every N1 seconds + time.ticks = 0; // NB!! 'ticks' is don't care ( = does not work); rtems_task_wait_when has granularity of 1 second ( "taskwakewhen.c" nullifies time.ticks ) + + status = rtems_task_wake_when( &time ); + + // dump CPU usage every 5th period + if( 0 == (count % 5) ) { + //CPU_usage_Dump( ); // UNCOMMENT ME FOR WORKING CPU_usage_Dump + } + } +}; + + +// TASK 2 +// +// * RM schdeling for task 2 +// * Rate Monotonic usage statistics +// +rtems_task Task_Rate_Monotonic_Period( + rtems_task_argument unused +) +{ + rtems_time_of_day time; + rtems_status_code status; + uint32_t ticks_since_boot; + rtems_name my_period_name; + rtems_id RM_period; + bool is_RM_created = 0; + uint32_t count; + + count = 0; + + while( 1 ) { + status = rtems_clock_get( RTEMS_CLOCK_GET_TOD, &time ); + count++; + + printf( "\n\nTask 2 - activating every %d second using rate monotonic manager to schedule (rtems_rate_monotonic_period)\n", PERIOD_TASK_RATE_MONOTONIC); + print_time( " - rtems_clock_get - ", &time, "\n" ); + rtems_clock_get( RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &ticks_since_boot ); + printf(" - Ticks since boot: %" PRIu32 "\n", ticks_since_boot); + + if( TRUE != is_RM_created ) { + count = 0; + my_period_name = rtems_build_name( 'P', 'E', 'R', '1' ); + status = rtems_rate_monotonic_create( my_period_name, &RM_period ); + if( RTEMS_SUCCESSFUL != status ) { + printf("RM failed with status: %d\n", status); + exit(1); + } + // Initiate RM periode + status = rtems_rate_monotonic_period( RM_period, get_ticks_per_second() * PERIOD_TASK_RATE_MONOTONIC ); // Every N2 seconds + if( RTEMS_SUCCESSFUL != status ) { + printf("RM failed with status: %d\n", status); + exit(1); + } + + is_RM_created = TRUE; + } + // Block until RM period has expired + status = rtems_rate_monotonic_period( RM_period, get_ticks_per_second() * PERIOD_TASK_RATE_MONOTONIC ); // Every N2 seconds + if( RTEMS_SUCCESSFUL != status ) { + if( RTEMS_TIMEOUT != status ) { + printf("RM missed period!\n"); + } + printf("RM failed with status: %d\n", status); + exit(1); + } + + // dump Rate Monotonic usage every 5th period + if( 0 == (count % 5) ) { + ; // rtems_rate_monotonic_report_statistics(); + } + } +} + + +// TASK 3 +// +// * relative delay for task 3 +// +rtems_task Task_Relative_Period( + rtems_task_argument unused +) +{ + rtems_time_of_day time; + rtems_status_code status; + uint32_t ticks_since_boot; + + while( 1 ) { + status = rtems_clock_get( RTEMS_CLOCK_GET_TOD, &time ); + + printf( "\n\nTask 3 - activating after every %d second using relative time (rtems_task_wake_after)\n", PERIOD_TASK_RELATIVE); + print_time( " - rtems_clock_get - ", &time, "\n" ); + rtems_clock_get( RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &ticks_since_boot ); + printf(" - Ticks since boot: %" PRIu32 "\n", ticks_since_boot); // Note how the ticks are drifting with this method + + status = rtems_task_wake_after( get_ticks_per_second() * PERIOD_TASK_RELATIVE ); // Every N3 seconds + } +} + |