summaryrefslogtreecommitdiff
path: root/posix_api
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2009-08-06 21:26:29 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2009-08-06 21:26:29 +0000
commit1324bafd0d2d8856e106bc8d929e2d36b47b2273 (patch)
tree74518252efea6b4613ec1ca25da65a82f074f221 /posix_api
parent9c54f28b70f0fd5919c22920cf8546e65d4632fa (diff)
2009-08-06 Joel Sherrill <joel.sherrill@oarcorp.com>
* ChangeLog, Makefile, psx_example_1/Makefile, psx_example_1/test1.c, psx_example_2/Makefile, psx_example_2/test2.c, psx_example_3/Makefile, psx_example_3/test3.c, psx_sched_report/Makefile, psx_sched_report/README, psx_sched_report/test.c: New files.
Diffstat (limited to 'posix_api')
-rw-r--r--posix_api/ChangeLog13
-rw-r--r--posix_api/Makefile12
-rw-r--r--posix_api/psx_example_1/Makefile29
-rw-r--r--posix_api/psx_example_1/test1.c46
-rw-r--r--posix_api/psx_example_2/Makefile29
-rw-r--r--posix_api/psx_example_2/test2.c51
-rw-r--r--posix_api/psx_example_3/Makefile29
-rw-r--r--posix_api/psx_example_3/test3.c89
-rw-r--r--posix_api/psx_sched_report/Makefile44
-rw-r--r--posix_api/psx_sched_report/README6
-rw-r--r--posix_api/psx_sched_report/test.c68
11 files changed, 416 insertions, 0 deletions
diff --git a/posix_api/ChangeLog b/posix_api/ChangeLog
new file mode 100644
index 0000000..466b983
--- /dev/null
+++ b/posix_api/ChangeLog
@@ -0,0 +1,13 @@
+2009-08-06 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * ChangeLog, Makefile, psx_example_1/Makefile, psx_example_1/test1.c,
+ psx_example_2/Makefile, psx_example_2/test2.c,
+ psx_example_3/Makefile, psx_example_3/test3.c,
+ psx_sched_report/Makefile, psx_sched_report/README,
+ psx_sched_report/test.c: New files.
+
+2009-08-06 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * ChangeLog, Makefile, psx_sched_report/Makefile,
+ psx_sched_report/README, psx_sched_report/test.c: New files.
+
diff --git a/posix_api/Makefile b/posix_api/Makefile
new file mode 100644
index 0000000..c247972
--- /dev/null
+++ b/posix_api/Makefile
@@ -0,0 +1,12 @@
+#
+# $Id$
+#
+
+include $(RTEMS_MAKEFILE_PATH)/Makefile.inc
+include $(RTEMS_CUSTOM)
+include $(RTEMS_ROOT)/make/directory.cfg
+
+# If the POSIX API isn't enabled, we can't build these
+ifeq ($(RTEMS_HAS_POSIX_API),yes)
+ SUBDIRS = psx_example_1 psx_example_2 psx_example_3 psx_sched_report
+endif
diff --git a/posix_api/psx_example_1/Makefile b/posix_api/psx_example_1/Makefile
new file mode 100644
index 0000000..cbe498f
--- /dev/null
+++ b/posix_api/psx_example_1/Makefile
@@ -0,0 +1,29 @@
+#
+# Makefile
+#
+
+#
+# RTEMS_MAKEFILE_PATH is typically set in an environment variable
+#
+
+PGM=${ARCH}/psx_example_1.exe
+
+# optional managers required
+MANAGERS=all
+
+# C source names
+CSRCS = test1.c
+COBJS_ = $(CSRCS:.c=.o)
+COBJS = $(COBJS_:%=${ARCH}/%)
+
+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/posix_api/psx_example_1/test1.c b/posix_api/psx_example_1/test1.c
new file mode 100644
index 0000000..4c26bbc
--- /dev/null
+++ b/posix_api/psx_example_1/test1.c
@@ -0,0 +1,46 @@
+/*
+ * $Id$
+ */
+
+#include <sched.h>
+#include <bsp.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <pthread.h>
+
+void * print_hello(void * arg)
+{
+ sleep(1);
+ printf("<child>: Hello World!\n");
+ return NULL;
+}
+
+void *POSIX_Init()
+{
+ pthread_t child1;
+ pthread_t child2;
+ int status;
+
+ status = pthread_create( &child1, NULL, print_hello, NULL );
+ if ( status ) perror("Error on create child 1");
+
+ status = pthread_create( &child2, NULL, print_hello, NULL );
+ if ( status ) perror("Error on create child 1");
+
+ printf("<main>: Wait for child2 thread...\n");
+
+ status = pthread_join( child1, NULL );
+ if ( status ) perror ("Error on join");
+ printf("<main>: Successfully joined with child1\n" );
+ exit(0);
+}
+
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+
+#define CONFIGURE_MAXIMUM_POSIX_THREADS 10
+#define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES 10
+#define CONFIGURE_MAXIMUM_POSIX_MUTEXES 10
+#define CONFIGURE_POSIX_INIT_THREAD_TABLE
+#define CONFIGURE_INIT
+#include <rtems/confdefs.h>
diff --git a/posix_api/psx_example_2/Makefile b/posix_api/psx_example_2/Makefile
new file mode 100644
index 0000000..689b1e1
--- /dev/null
+++ b/posix_api/psx_example_2/Makefile
@@ -0,0 +1,29 @@
+#
+# Makefile
+#
+
+#
+# RTEMS_MAKEFILE_PATH is typically set in an environment variable
+#
+
+PGM=${ARCH}/psx_example_2.exe
+
+# optional managers required
+MANAGERS=all
+
+# C source names
+CSRCS = test2.c
+COBJS_ = $(CSRCS:.c=.o)
+COBJS = $(COBJS_:%=${ARCH}/%)
+
+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/posix_api/psx_example_2/test2.c b/posix_api/psx_example_2/test2.c
new file mode 100644
index 0000000..61d5795
--- /dev/null
+++ b/posix_api/psx_example_2/test2.c
@@ -0,0 +1,51 @@
+/*
+ * $Id$
+ */
+
+#include <bsp.h>
+#include <pthread.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <sched.h>
+
+pthread_mutex_t mutex;
+pthread_cond_t cond;
+
+void * print_hello(void * arg)
+{
+ struct timeval time;
+ struct timespec timeout;
+
+ gettimeofday(&time, NULL);
+ timeout.tv_sec = time.tv_sec + 2;
+ timeout.tv_nsec = time.tv_usec * 1000;
+ printf("<child>: Hello World coming to wait!\n");
+
+ if (pthread_cond_timedwait(&cond, &mutex, &timeout))
+ perror ("Error on pthread_cond_timedwait");
+
+ printf("<child>: Hello World exit to wait!\n");
+ return NULL;
+}
+
+int *POSIX_Init()
+{
+ pthread_t child;
+ if ( pthread_create( &child, NULL, print_hello, NULL ))
+ perror("Error on pthread_create");
+ printf("<main>: Wait for child thread...\n");
+ if ( pthread_join( child, NULL ))
+ perror("Error on pthread_join");
+ return 0;
+}
+
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+
+#define CONFIGURE_MAXIMUM_POSIX_THREADS 10
+#define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES 10
+#define CONFIGURE_MAXIMUM_POSIX_MUTEXES 10
+#define CONFIGURE_POSIX_INIT_THREAD_TABLE
+
+#define CONFIGURE_INIT
+#include <rtems/confdefs.h>
diff --git a/posix_api/psx_example_3/Makefile b/posix_api/psx_example_3/Makefile
new file mode 100644
index 0000000..2f2d4b3
--- /dev/null
+++ b/posix_api/psx_example_3/Makefile
@@ -0,0 +1,29 @@
+#
+# Makefile
+#
+
+#
+# RTEMS_MAKEFILE_PATH is typically set in an environment variable
+#
+
+PGM=${ARCH}/psx_example_3.exe
+
+# optional managers required
+MANAGERS=all
+
+# C source names
+CSRCS = test3.c
+COBJS_ = $(CSRCS:.c=.o)
+COBJS = $(COBJS_:%=${ARCH}/%)
+
+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/posix_api/psx_example_3/test3.c b/posix_api/psx_example_3/test3.c
new file mode 100644
index 0000000..7d5e9ac
--- /dev/null
+++ b/posix_api/psx_example_3/test3.c
@@ -0,0 +1,89 @@
+/*
+ * $Id$
+ */
+#include <sched.h>
+#include <bsp.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <pthread.h>
+
+ pthread_mutex_t mutex;
+ pthread_cond_t cond;
+ struct timespec timeout;
+ struct sched_param param;
+ pthread_attr_t attr;
+
+void * print_hello(void * arg)
+{
+ printf("<child>: Hello World! task with max priority \n");
+ clock_gettime( CLOCK_REALTIME, &timeout );
+ timeout.tv_sec += 3;
+ timeout.tv_nsec = 0;
+ printf("The task is coming to enter in a timed wait\n");
+ pthread_cond_timedwait(&cond, &mutex, &timeout);
+ printf("The task is coming out from the timed wait \n");
+ return NULL;
+}
+
+void * print_hello_a(void * arg)
+{
+ printf(" <child>: Hello World! Task with lowest priority ");
+ return NULL;
+}
+
+
+void *POSIX_Init()
+{
+ pthread_t child1;
+ pthread_t child2;
+
+ pthread_attr_init(&attr);
+ pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
+ pthread_mutex_init( &mutex, NULL );
+ pthread_cond_init( &cond, NULL );
+
+ printf("<main> Enter in the main \n");
+
+ printf("Creating first task \n");
+ param.sched_priority = sched_get_priority_max(SCHED_FIFO);
+ pthread_attr_setschedparam(&attr, &param);
+ if ( pthread_create( &child1, &attr, print_hello, NULL) ||
+ pthread_setschedparam(child1, SCHED_FIFO, &param) ) {
+ printf(
+ "Thread cannot be created or you have not enough privileges \n"
+ " to set priority!!!!\n");
+ exit(1);
+ }
+
+ printf("First Task created \n");
+ printf("Creating second task \n");
+ param.sched_priority = sched_get_priority_max(SCHED_FIFO) - 1;
+ pthread_attr_setschedparam(&attr, &param);
+ if ( pthread_create( &child2, &attr, print_hello_a, NULL) ||
+ pthread_setschedparam(child2, SCHED_FIFO, &param) ) {
+ printf(
+ "Thread cannot be created or you have not enough privileges \n"
+ " to set priority!!!!\n");
+ exit(1);
+ }
+ printf("Second task created \n");
+
+ printf("<main> Out of the main\n");
+ pthread_join( child1, NULL );
+ pthread_join( child2, NULL );
+
+ exit(0);
+}
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+
+#define CONFIGURE_MAXIMUM_POSIX_THREADS 10
+#define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES 10
+#define CONFIGURE_MAXIMUM_POSIX_MUTEXES 10
+#define CONFIGURE_POSIX_INIT_THREAD_TABLE
+
+#define CONFIGURE_INIT
+#include <rtems/confdefs.h>
+
+
+
diff --git a/posix_api/psx_sched_report/Makefile b/posix_api/psx_sched_report/Makefile
new file mode 100644
index 0000000..96dd47f
--- /dev/null
+++ b/posix_api/psx_sched_report/Makefile
@@ -0,0 +1,44 @@
+#
+# Makefile
+#
+
+#
+# RTEMS_MAKEFILE_PATH is typically set in an environment variable
+#
+
+EXEC=psx_sched_report.exe
+PGM=${ARCH}/$(EXEC)
+
+# optional managers required
+MANAGERS=all
+
+# C source names
+CSRCS = test.c
+COBJS_ = $(CSRCS:.c=.o)
+COBJS = $(COBJS_:%=${ARCH}/%)
+
+# C++ source names
+CXXSRCS =
+CXXOBJS_ = $(CXXSRCS:.cc=.o)
+CXXOBJS = $(CXXOBJS_:%=${ARCH}/%)
+
+# AS source names
+ASSRCS =
+ASOBJS_ = $(ASSRCS:.s=.o)
+ASOBJS = $(ASOBJS_:%=${ARCH}/%)
+
+# Libraries
+LIBS = -lrtemsall -lc
+
+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/posix_api/psx_sched_report/README b/posix_api/psx_sched_report/README
new file mode 100644
index 0000000..381066a
--- /dev/null
+++ b/posix_api/psx_sched_report/README
@@ -0,0 +1,6 @@
+#
+# README for POSIX Scheduling information test
+#
+
+Prints some POSIX scheduling information and reports compliancy on
+some issues.
diff --git a/posix_api/psx_sched_report/test.c b/posix_api/psx_sched_report/test.c
new file mode 100644
index 0000000..8d0b9b3
--- /dev/null
+++ b/posix_api/psx_sched_report/test.c
@@ -0,0 +1,68 @@
+/*
+ * Simple test program -- simplified version of sample test hello.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <sched.h>
+#include <stdlib.h>
+
+void print_sched_info(
+ char *s,
+ int policy
+)
+{
+ int min, max, levels;
+ struct timespec t;
+
+ printf( "Information on %s\n", s );
+ min = sched_get_priority_min( policy );
+ max = sched_get_priority_max( policy );
+ (void) sched_rr_get_interval( 1, &t );
+ levels = max - min;
+ printf( "\tSupports %d priority levels (%d - %d)\n", levels, min, max );
+ if ( levels >= 32 )
+ printf( "\tImplementation is compliant on priority levels\n");
+ else
+ printf( "\tImplementation is NOT compliant on priority levels\n" );
+
+ printf( "\tScheduling quantum is %ld seconds and %ld nanoseconds\n",
+ (long)t.tv_sec, (long)t.tv_nsec );
+}
+
+
+#if defined(__rtems__)
+ #include <bsp.h>
+
+rtems_task Init(
+ rtems_task_argument ignored
+)
+#else
+int main()
+#endif
+{
+ print_sched_info( "SCHED_OTHER", SCHED_OTHER );
+ print_sched_info( "SCHED_FIFO", SCHED_FIFO );
+ print_sched_info( "SCHED_RR", SCHED_RR );
+
+ exit( 0 );
+}
+
+#if defined(__rtems__)
+/* configuration information */
+
+/* NOTICE: the clock driver is explicitly disabled */
+#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+#define CONFIGURE_MICROSECONDS_PER_TICK 1000
+#define CONFIGURE_TICKS_PER_TIMESLICE 1
+#define CONFIGURE_MAXIMUM_TASKS 1
+
+#define CONFIGURE_INIT
+
+#include <rtems/confdefs.h>
+#endif
+
+/* end of file */