summaryrefslogtreecommitdiffstats
path: root/file_io
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2009-08-06 21:25:41 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2009-08-06 21:25:41 +0000
commitab7caff0b5dbd89774050c0982c0ccc3198c3f51 (patch)
tree90ed664314a9b56e778f6a6f10e7936978c48e4b /file_io
parent2009-08-06 Joel Sherrill <joel.sherrill@oarcorp.com> (diff)
downloadrtems-examples-ab7caff0b5dbd89774050c0982c0ccc3198c3f51.tar.bz2
2009-08-06 Joel Sherrill <joel.sherrill@oarcorp.com>
* ChangeLog, Makefile, fdopen/.cvsignore, fdopen/Makefile, fdopen/README, fdopen/test.c, filerdback/.cvsignore, filerdback/Makefile, filerdback/README, filerdback/test.c, repeated_opens/.cvsignore, repeated_opens/Makefile, repeated_opens/README, repeated_opens/test.c: New files.
Diffstat (limited to 'file_io')
-rw-r--r--file_io/ChangeLog8
-rw-r--r--file_io/Makefile9
-rw-r--r--file_io/fdopen/.cvsignore1
-rw-r--r--file_io/fdopen/Makefile44
-rw-r--r--file_io/fdopen/README139
-rw-r--r--file_io/fdopen/test.c84
-rw-r--r--file_io/filerdback/.cvsignore1
-rw-r--r--file_io/filerdback/Makefile44
-rw-r--r--file_io/filerdback/README18
-rw-r--r--file_io/filerdback/test.c64
-rw-r--r--file_io/repeated_opens/.cvsignore1
-rw-r--r--file_io/repeated_opens/Makefile44
-rw-r--r--file_io/repeated_opens/README18
-rw-r--r--file_io/repeated_opens/test.c59
14 files changed, 534 insertions, 0 deletions
diff --git a/file_io/ChangeLog b/file_io/ChangeLog
new file mode 100644
index 0000000..4d2fe47
--- /dev/null
+++ b/file_io/ChangeLog
@@ -0,0 +1,8 @@
+2009-08-06 Joel Sherrill <joel.sherrill@oarcorp.com>
+
+ * ChangeLog, Makefile, fdopen/.cvsignore, fdopen/Makefile,
+ fdopen/README, fdopen/test.c, filerdback/.cvsignore,
+ filerdback/Makefile, filerdback/README, filerdback/test.c,
+ repeated_opens/.cvsignore, repeated_opens/Makefile,
+ repeated_opens/README, repeated_opens/test.c: New files.
+
diff --git a/file_io/Makefile b/file_io/Makefile
new file mode 100644
index 0000000..1a3f6ea
--- /dev/null
+++ b/file_io/Makefile
@@ -0,0 +1,9 @@
+#
+# $Id$
+#
+
+include $(RTEMS_MAKEFILE_PATH)/Makefile.inc
+include $(RTEMS_CUSTOM)
+include $(RTEMS_ROOT)/make/directory.cfg
+
+SUBDIRS = fdopen filerdback repeated_opens
diff --git a/file_io/fdopen/.cvsignore b/file_io/fdopen/.cvsignore
new file mode 100644
index 0000000..fecf58a
--- /dev/null
+++ b/file_io/fdopen/.cvsignore
@@ -0,0 +1 @@
+o-optimize
diff --git a/file_io/fdopen/Makefile b/file_io/fdopen/Makefile
new file mode 100644
index 0000000..7643abe
--- /dev/null
+++ b/file_io/fdopen/Makefile
@@ -0,0 +1,44 @@
+#
+# Makefile
+#
+
+#
+# RTEMS_MAKEFILE_PATH is typically set in an environment variable
+#
+
+EXEC=test.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/file_io/fdopen/README b/file_io/fdopen/README
new file mode 100644
index 0000000..dee115d
--- /dev/null
+++ b/file_io/fdopen/README
@@ -0,0 +1,139 @@
+#
+# README for fdopen() test
+#
+
+Resolution: Fixed
+
+This test failed because fcntl() did not yet support the F_GETFL
+control operation. This code was added (along with F_SETFL) and
+the test began to work.
+
+-----------------------
+
+This is the original email that the test came from:
+
+From janovetz@tempest.ece.uiuc.edu Sat Mar 6 10:34:11 1999
+Date: Thu, 4 Mar 1999 19:37:37 -0600
+From: Jake Janovetz <janovetz@tempest.ece.uiuc.edu>
+To: rtems-snapshots@oarcorp.com
+Subject: More on fdopen()
+
+Hello all...
+
+Sorry to beat a dead horse (to me, it's still living), but I
+still can't get the fdopen stuff to work... Since I cannot
+find a reference to fdopen() under the rtems source tree,
+I presume its only incarnation in 'newlib'. The
+newlib-1.8.1 19990302 patch does not seem to have a reference
+to fdopen, so I don't see anything modified there.
+
+I'd like to know where the fdopen fix resides, so I know I
+have it.
+
+Finally, I'm including a simple test for fdopen(). If some
+merciful soul can run this (Eric has already verified that his
+version works -- I'm hoping that maybe a patch didn't make it
+into 0302), I would appreciate it.
+
+ Cheers,
+ Jake
+
+--
+ janovetz@uiuc.edu | Once you have flown, you will walk the earth with
+ University of Illinois | your eyes turned skyward, for there you have been,
+ | there you long to return. -- da Vinci
+ PP-ASEL | http://www.ews.uiuc.edu/~janovetz/index.html
+
+
+
+
+#include <bsp.h>
+#include <fcntl.h>
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+#define CONFIGURE_EXECUTIVE_RAM_SIZE (2048*1024)
+#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 4
+#define CONFIGURE_MAXIMUM_SEMAPHORES 20
+#define CONFIGURE_MAXIMUM_TASKS 20
+#define CONFIGURE_MAXIMUM_TIMERS 20
+#define CONFIGURE_MAXIMUM_PERIODS 1
+#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 10
+#define CONFIGURE_INIT_TASK_STACK_SIZE (32*1024)
+#define CONFIGURE_INIT_TASK_PRIORITY 90
+#define CONFIGURE_INIT_TASK_INITIAL_MODES (RTEMS_PREEMPT | \
+ RTEMS_NO_TIMESLICE | \
+ RTEMS_NO_ASR | \
+ RTEMS_INTERRUPT_LEVEL(0))
+#define CONFIGURE_MICROSECONDS_PER_TICK 10486
+#define CONFIGURE_INIT
+rtems_task Init(rtems_task_argument argument);
+
+#define CONFIGURE_HAS_OWN_DEVICE_DRIVER_TABLE
+rtems_driver_address_table Device_drivers[] = {
+ CONSOLE_DRIVER_TABLE_ENTRY,
+ CLOCK_DRIVER_TABLE_ENTRY,
+};
+
+#include <rtems/confdefs.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <rtems.h>
+#include <rtems/error.h>
+#include <rtems/libio.h>
+#include "m68360.h"
+#include <stdlib.h>
+#include <errno.h>
+
+
+rtems_task
+Init(rtems_task_argument ignored)
+{
+ int fd;
+ FILE *fp;
+ char str[256];
+
+
+ /***********************************************************************
+ * Print the boot-up message.
+ **********************************************************************/
+ printf("\n\n");
+ printf("%s\n", _RTEMS_version);
+
+ printf("Here we go!\n");
+ fp = fopen("test", "w");
+ fprintf(fp, "Hello world!!!\n");
+ fclose(fp);
+
+ fp = fopen("test", "r");
+ fgets(str, 200, fp);
+ printf("read: %s\n", str);
+ fclose(fp);
+
+ fd = open("test", O_RDONLY);
+ if (fd == -1)
+ {
+ printf("Starting on the wrong foot....\n");
+ }
+ fp = fdopen(fd, "r");
+ if (fp == NULL)
+ {
+ printf("Crap, man! Nothing ever goes my way!\n");
+ close(fd);
+ }
+ else
+ {
+ printf("Soon, I will be able to take over the world!\n");
+ fgets(str, 200, fp);
+ printf("%s\n", str);
+ fclose(fp);
+ }
+
+ while (1)
+ {
+ rtems_task_wake_after(100);
+ }
+
+
+ exit(0);
+}
diff --git a/file_io/fdopen/test.c b/file_io/fdopen/test.c
new file mode 100644
index 0000000..c16aa6c
--- /dev/null
+++ b/file_io/fdopen/test.c
@@ -0,0 +1,84 @@
+/*
+ * Simple test program -- demonstrating use of IMFS
+ */
+
+#include <bsp.h>
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+rtems_task Init(
+ rtems_task_argument ignored
+)
+{
+ int fd;
+ FILE *fp;
+ char str[256];
+
+ /*
+ * Print a startup message
+ */
+ printf(
+ "\n\n"
+ "%s\n"
+ "Here we go!\n",
+ _RTEMS_version
+ );
+
+ fp = fopen("test", "w");
+ fprintf(fp, "Hello world!!!\n");
+ fclose(fp);
+
+ fp = fopen("test", "r");
+ fgets(str, 200, fp);
+ printf("read: %s\n", str);
+ fclose(fp);
+
+ fd = open("test", O_WRONLY|O_APPEND);
+ printf( "fcntl flags =0x%x\n", fcntl( fd, F_GETFL ) );
+ close(fd);
+
+ fd = open("test1", O_CREAT);
+ printf( "fcntl flags =0x%x\n", fcntl( fd, F_GETFL ) );
+ close(fd);
+
+ fd = open("test", O_RDONLY);
+ if (fd == -1) {
+ printf("Starting on the wrong foot....\n");
+ exit(-1);
+ }
+
+ printf( "fcntl flags =0x%x\n", fcntl( fd, F_GETFL ) );
+
+ fp = fdopen(fd, "r");
+ if (fp == NULL) {
+ printf("Nothing ever goes my way!\n");
+ close(fd);
+ exit(-1);
+ } else {
+ printf("Soon, I will be able to take over the world!\n");
+ fgets(str, 200, fp);
+ printf("%s\n", str);
+ fclose(fp);
+ }
+
+ exit(0);
+}
+
+/* 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_USE_IMFS_AS_BASE_FILESYSTEM
+#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 6
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+#define CONFIGURE_MAXIMUM_TASKS 1
+
+#define CONFIGURE_INIT
+
+#include <rtems/confdefs.h>
+/* end of file */
diff --git a/file_io/filerdback/.cvsignore b/file_io/filerdback/.cvsignore
new file mode 100644
index 0000000..fecf58a
--- /dev/null
+++ b/file_io/filerdback/.cvsignore
@@ -0,0 +1 @@
+o-optimize
diff --git a/file_io/filerdback/Makefile b/file_io/filerdback/Makefile
new file mode 100644
index 0000000..7643abe
--- /dev/null
+++ b/file_io/filerdback/Makefile
@@ -0,0 +1,44 @@
+#
+# Makefile
+#
+
+#
+# RTEMS_MAKEFILE_PATH is typically set in an environment variable
+#
+
+EXEC=test.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/file_io/filerdback/README b/file_io/filerdback/README
new file mode 100644
index 0000000..e562ba4
--- /dev/null
+++ b/file_io/filerdback/README
@@ -0,0 +1,18 @@
+#
+# README for simple example application
+#
+
+In this directory, you will find a simple RTEMS application and a Makefile.
+It can be built by setting the environment variable "RTEMS_MAKEFILE_PATH"
+and invoking make.
+
+Here are a couple of example ways to do this using the erc32 BSP:
+
+ RTEMS_MAKEFILE_PATH=/home/joel/gnat-3.10p/sparc-rtems/rtems/erc32 gmake
+
+The resulting application end up in o-erc32/test.exe.
+
+An alterative way to do this is to set the environment variable separately:
+
+ export RTEMS_MAKEFILE_PATH=/home/joel/gnat-3.10p/sparc-rtems/rtems/erc32
+ gmake
diff --git a/file_io/filerdback/test.c b/file_io/filerdback/test.c
new file mode 100644
index 0000000..c7226f6
--- /dev/null
+++ b/file_io/filerdback/test.c
@@ -0,0 +1,64 @@
+/*
+ * Simple test program to write and read a file back.
+ */
+
+#include <bsp.h>
+
+#include <string.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <memory.h>
+
+char *bufr = "Happy days are here again. Happy days are here again.1Happy "
+"days are here again.2Happy days are here again.3Happy days are here again."
+"4Happy days are here again.5Happy days are here again.6Happy days are here "
+"again.7Happy days are here again.";
+
+rtems_task Init(
+ rtems_task_argument ignored
+)
+{
+ int fd;
+ int i, n, total;
+ char *bufr2;
+
+ printf( "BUFSIZ = %d\n", BUFSIZ );
+ bufr2 = (char *)malloc(BUFSIZ);
+ fd = creat("tester", S_IRWXU | S_IRWXG | S_IRWXO);
+ for (i=0; i<10; i++) {
+ n=write(fd, bufr, strlen(bufr));
+ printf("Wrote %d\n", n);
+ }
+ close(fd);
+
+ total = 0;
+ fd = open("tester", O_RDONLY);
+ while ((n=read(fd,bufr2,60)) > 0) {
+ bufr2[n-1] = '\0';
+ total += n;
+ printf("Read=%d, total=%d : %s\n", n, total, bufr2);
+ }
+ free(bufr2);
+ close(fd);
+ exit(0);
+}
+
+/* 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_MAXIMUM_TASKS 1
+#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
+#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4
+
+#define CONFIGURE_INIT
+
+#include <rtems/confdefs.h>
+
+/* end of file */
diff --git a/file_io/repeated_opens/.cvsignore b/file_io/repeated_opens/.cvsignore
new file mode 100644
index 0000000..fecf58a
--- /dev/null
+++ b/file_io/repeated_opens/.cvsignore
@@ -0,0 +1 @@
+o-optimize
diff --git a/file_io/repeated_opens/Makefile b/file_io/repeated_opens/Makefile
new file mode 100644
index 0000000..7643abe
--- /dev/null
+++ b/file_io/repeated_opens/Makefile
@@ -0,0 +1,44 @@
+#
+# Makefile
+#
+
+#
+# RTEMS_MAKEFILE_PATH is typically set in an environment variable
+#
+
+EXEC=test.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/file_io/repeated_opens/README b/file_io/repeated_opens/README
new file mode 100644
index 0000000..e562ba4
--- /dev/null
+++ b/file_io/repeated_opens/README
@@ -0,0 +1,18 @@
+#
+# README for simple example application
+#
+
+In this directory, you will find a simple RTEMS application and a Makefile.
+It can be built by setting the environment variable "RTEMS_MAKEFILE_PATH"
+and invoking make.
+
+Here are a couple of example ways to do this using the erc32 BSP:
+
+ RTEMS_MAKEFILE_PATH=/home/joel/gnat-3.10p/sparc-rtems/rtems/erc32 gmake
+
+The resulting application end up in o-erc32/test.exe.
+
+An alterative way to do this is to set the environment variable separately:
+
+ export RTEMS_MAKEFILE_PATH=/home/joel/gnat-3.10p/sparc-rtems/rtems/erc32
+ gmake
diff --git a/file_io/repeated_opens/test.c b/file_io/repeated_opens/test.c
new file mode 100644
index 0000000..5106621
--- /dev/null
+++ b/file_io/repeated_opens/test.c
@@ -0,0 +1,59 @@
+/* Open/close test */
+
+#include <rtems.h>
+#include <rtems/clockdrv.h>
+#include <rtems/console.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <memory.h>
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+rtems_task Init(rtems_task_argument a)
+{
+ int i;
+ int fd;
+ char msg[16];
+ int len;
+ int l;
+
+ printf("Open/close test (%d)\n",(int)a);
+
+ strcpy(msg,"OK!\n");
+ len = strlen(msg);
+
+ for(i = 0; i < 10000; i++){
+ fd = open("/tempfile",O_RDWR|O_CREAT, 0666);
+ if(fd < 0){
+ printf("open failed on %dth try (%s).\n",i, strerror(errno));
+ continue;
+ }
+ l = write(fd,msg,len);
+ if(l != len){
+ printf("write failed on %dth try. (%d)\n",i,l);
+ break;
+ }
+ close(fd);
+ if ( i && (i%100 == 0)) printf("pass %d\n", i);
+
+ }
+ printf("Done.\n");
+ exit(0);
+}
+
+/* NOTICE: the clock driver is explicitly disabled */
+#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+
+#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
+
+#define CONFIGURE_MAXIMUM_TASKS 1
+#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_INIT
+#include <rtems/confdefs.h>
+