]> rtime.felk.cvut.cz Git - frescor/fosa.git/blobdiff - src_rtlinux/fosa_misc.c
Working in the Demo for Brussels
[frescor/fosa.git] / src_rtlinux / fosa_misc.c
diff --git a/src_rtlinux/fosa_misc.c b/src_rtlinux/fosa_misc.c
new file mode 100644 (file)
index 0000000..6c867e0
--- /dev/null
@@ -0,0 +1,182 @@
+// -----------------------------------------------------------------------
+//  Copyright (C) 2006 - 2007 FRESCOR consortium partners:
+//
+//    Universidad de Cantabria,              SPAIN
+//    University of York,                    UK
+//    Scuola Superiore Sant'Anna,            ITALY
+//    Kaiserslautern University,             GERMANY
+//    Univ. Politecnica  Valencia,           SPAIN
+//    Czech Technical University in Prague,  CZECH REPUBLIC
+//    ENEA                                   SWEDEN
+//    Thales Communication S.A.              FRANCE
+//    Visual Tools S.A.                      SPAIN
+//    Rapita Systems Ltd                     UK
+//    Evidence                               ITALY
+//    
+//    See http://www.frescor.org for a link to partners' websites
+//
+//           FRESCOR project (FP6/2005/IST/5-034026) is funded
+//        in part by the European Union Sixth Framework Programme
+//        The European Union is not liable of any use that may be
+//        made of this code.
+//
+//  This file is part of the FRSH implementation
+//
+//  FRSH is free software; you can  redistribute it and/or  modify
+//  it under the terms of  the GNU General Public License as published by
+//  the Free Software Foundation;  either  version 2, or (at  your option)
+//  any later version.
+//
+//  FRSH  is distributed  in  the hope  that  it  will  be useful,  but
+//  WITHOUT  ANY  WARRANTY;     without  even the   implied   warranty  of
+//  MERCHANTABILITY  or  FITNESS FOR  A  PARTICULAR PURPOSE. See  the  GNU
+//  General Public License for more details.
+//
+//  You should have  received a  copy of  the  GNU  General Public License
+//  distributed  with  FRSH;  see file COPYING.   If not,  write to the
+//  Free Software  Foundation,  59 Temple Place  -  Suite 330,  Boston, MA
+//  02111-1307, USA.
+//
+//  As a special exception, if you include this header file into source
+//  files to be compiled, this header file does not by itself cause
+//  the resulting executable to be covered by the GNU General Public
+//  License.  This exception does not however invalidate any other
+//  reasons why the executable file might be covered by the GNU General
+//  Public License.
+// -----------------------------------------------------------------------
+//fosa_misc.h
+//==============================================
+//  ********  ******    ********  **********
+//  **///// /**    **  **//////  /**     /**
+//  **      /**    ** /**        /**     /**
+//  ******* /**    ** /********* /**********
+//  **////  /**    ** ////////** /**//////**
+//  **      /**    **        /** /**     /**
+//  **      /**    **  ********  /**     /**
+//  //       /******/  ////////   //      // 
+//
+// FOSA(Frescor Operating System Adaptation layer)
+//================================================
+
+//#include <fosa.h>
+#include <stdarg.h>
+
+extern int vsprintf(char *str, const char *format, va_list ap);
+extern void rtl_printf(const char *format, ...);
+typedef int size_t;
+
+static char vsprintf_buffer[512];
+
+int vprintf(const char *fmt, va_list ap) {
+  int i=vsprintf(vsprintf_buffer, fmt, ap);
+  rtl_printf(vsprintf_buffer);
+  return i;
+}
+
+int printf(const char *fmt,...) {
+  int i;
+  va_list args;
+
+  va_start(args, fmt);
+  i=vsprintf(vsprintf_buffer, fmt, args);
+  va_end(args);
+  rtl_printf(vsprintf_buffer);
+  return i;
+}
+
+typedef unsigned long FILE;
+
+FILE stdout=2;
+
+int vfprintf(FILE *stream, const char *fmt, va_list ap) {
+  int i=vsprintf(vsprintf_buffer, fmt, ap);
+  rtl_printf(vsprintf_buffer);
+  return i;
+}
+
+static void *memccpy(void *dst, const void *src, int c, int count)
+{
+  char *a = dst;
+  const char *b = src;
+  while (count--)
+  {
+    *a++ = *b;
+    if (*b==c)
+    {
+      return (void *)a;
+    }
+    b++;
+  }
+  return 0;
+}
+
+char *strncpy(char *dest, const char *src, size_t n) {
+  memccpy(dest,src,0,n);
+  return dest;
+}
+
+int strncmp(const char *s1, const char *s2, size_t n) {
+  const unsigned char* a=(const unsigned char*)s1;
+  const unsigned char* b=(const unsigned char*)s2;
+  const unsigned char* fini=a+n;
+  while (a<fini) {
+    int res=*a-*b;
+    if (res) return res;
+    if (!*a) return 0;
+    ++a; ++b;
+  }
+  return 0;
+}
+
+int puts(const char *s) {
+  rtl_printf(s);
+  return 0;
+}
+
+typedef signed long time_t;
+extern long long gethrtime(void);
+time_t time(time_t *t) {
+  time_t sec;
+  long long nsec;
+  
+  nsec=gethrtime();
+  sec=(time_t)(nsec/1000000000LL);
+  if (t)
+    *t=sec;
+  return sec;
+}
+
+#define NSECS 1000000000LL
+struct timespec {
+  time_t tv_sec;        /* seconds */
+  long tv_nsec;         /* nanoseconds */
+};
+
+extern int nanosleep(const struct timespec *req, struct timespec *rem);
+
+unsigned int sleep(unsigned int seg) {
+  struct timespec req={
+    .tv_sec=seg%NSECS,
+    .tv_nsec=seg/NSECS,
+  }, rem;
+  nanosleep(&req, &rem);
+  return rem.tv_sec;
+}
+
+void exit(int val) {
+  struct timespec req={
+    .tv_sec=1000,
+    .tv_nsec=1000000,
+  };
+  rtl_printf ("Application exited with %d\n", val);
+  while(1) {
+    nanosleep(&req, 0);
+  }
+}
+
+void __assert_fail (const char *assertion, const char *file, 
+                   unsigned int line, const char *function) {
+  rtl_printf("Assertion `%s` FILE: %s LINE: %d FUNCTION: %s failed.\n",
+            assertion, file, line, function);
+  exit(-1);
+}