summaryrefslogtreecommitdiffstats
path: root/classic_api
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2009-08-06 20:25:58 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2009-08-06 20:25:58 +0000
commit3083373e471be76b1624e0583c5a3f2f455d41c1 (patch)
treee7d15e5fdeb23587043f57d57fb0de6f399dbbbc /classic_api
downloadrtems-examples-3083373e471be76b1624e0583c5a3f2f455d41c1.tar.bz2
Initial import of reorganized examples.initialbase
Diffstat (limited to 'classic_api')
-rw-r--r--classic_api/Makefile9
-rw-r--r--classic_api/classic_signal/.cvsignore1
-rw-r--r--classic_api/classic_signal/Makefile27
-rw-r--r--classic_api/classic_signal/test.c110
-rw-r--r--classic_api/triple_period/.cvsignore1
-rw-r--r--classic_api/triple_period/Makefile25
-rw-r--r--classic_api/triple_period/init.c77
-rw-r--r--classic_api/triple_period/system.h136
-rw-r--r--classic_api/triple_period/tasks.c170
9 files changed, 556 insertions, 0 deletions
diff --git a/classic_api/Makefile b/classic_api/Makefile
new file mode 100644
index 0000000..f5e1477
--- /dev/null
+++ b/classic_api/Makefile
@@ -0,0 +1,9 @@
+#
+# $Id$
+#
+
+include $(RTEMS_MAKEFILE_PATH)/Makefile.inc
+include $(RTEMS_CUSTOM)
+include $(RTEMS_ROOT)/make/directory.cfg
+
+SUBDIRS=classic_signal triple_period
diff --git a/classic_api/classic_signal/.cvsignore b/classic_api/classic_signal/.cvsignore
new file mode 100644
index 0000000..fecf58a
--- /dev/null
+++ b/classic_api/classic_signal/.cvsignore
@@ -0,0 +1 @@
+o-optimize
diff --git a/classic_api/classic_signal/Makefile b/classic_api/classic_signal/Makefile
new file mode 100644
index 0000000..9fe9919
--- /dev/null
+++ b/classic_api/classic_signal/Makefile
@@ -0,0 +1,27 @@
+#
+# $Id$
+#
+
+#
+# RTEMS_MAKEFILE_PATH is typically set in an environment variable
+#
+
+PGM=${ARCH}/hello.exe
+
+# optional managers required
+MANAGERS=all
+
+# C source names
+CSRCS = test.c
+COBJS = $(CSRCS:%.c=${ARCH}/%.o)
+
+include $(RTEMS_MAKEFILE_PATH)/Makefile.inc
+include $(RTEMS_CUSTOM)
+include $(PROJECT_ROOT)/make/leaf.cfg
+
+OBJS= $(COBJS) $(CXXOBJS) $(ASOBJS)
+
+all: ${ARCH} $(PGM)
+
+$(PGM): $(OBJS)
+ $(make-exe)
diff --git a/classic_api/classic_signal/test.c b/classic_api/classic_signal/test.c
new file mode 100644
index 0000000..0742a93
--- /dev/null
+++ b/classic_api/classic_signal/test.c
@@ -0,0 +1,110 @@
+/*
+ * Classic API Signal to Task from ISR
+ *
+ * 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$
+ */
+
+#include <bsp.h>
+#include "../../testmacros.h"
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+volatile bool signal_sent;
+volatile bool signal_processed;
+
+rtems_id main_task;
+
+void signal_handler(
+ rtems_signal_set signals
+)
+{
+ signal_processed = TRUE;
+}
+
+rtems_timer_service_routine test_signal_from_isr(
+ rtems_id timer,
+ void *arg
+)
+{
+ rtems_status_code status;
+
+ status = rtems_signal_send( main_task, 0x0a0b0c0d );
+
+ signal_sent = TRUE;
+}
+
+rtems_task Init(
+ rtems_task_argument argument
+)
+{
+ rtems_status_code status;
+ rtems_id timer;
+ rtems_interval start;
+ rtems_interval now;
+
+ puts( "\n\n*** SIGNAL FROM TST TEST ***" );
+
+ main_task = rtems_task_self();
+
+ /*
+ * Timer used in multiple ways
+ */
+ status = rtems_timer_create( 1, &timer );
+ assert( status == RTEMS_SUCCESSFUL );
+
+ /*
+ * Get starting time
+ */
+ status = rtems_clock_get( RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &start );
+ assert( status == RTEMS_SUCCESSFUL );
+
+ status = rtems_signal_catch( signal_handler, RTEMS_DEFAULT_MODES );
+ assert( status == RTEMS_SUCCESSFUL );
+ puts( "rtems_signal_catch - handler installed" );
+
+ /*
+ * Test Signal from ISR
+ */
+ signal_sent = FALSE;
+
+ status = rtems_timer_fire_after( timer, 50, test_signal_from_isr, NULL );
+ assert( status == RTEMS_SUCCESSFUL );
+
+ while (1) {
+ status = rtems_clock_get( RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &now );
+ assert( status == RTEMS_SUCCESSFUL );
+ if ( (now-start) > 100 ) {
+ puts( "Signal from ISR did not get processed\n" );
+ exit( 0 );
+ }
+ if ( signal_processed )
+ break;
+ }
+
+ puts( "Signal sent from ISR has been processed" );
+ puts( "*** END OF SIGNAL FROM TSR TEST ***" );
+ exit( 0 );
+}
+
+/* configuration information */
+
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_MAXIMUM_TASKS 1
+#define CONFIGURE_MAXIMUM_TIMERS 1
+
+#define CONFIGURE_INIT
+
+#include <rtems/confdefs.h>
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
+ }
+}
+