diff syscalls.c @ 3:74e9b3baac1e

Jumbo commit to make things work. Note I have t
author Daniel O'Connor <darius@dons.net.au>
date Sun, 01 Jan 2012 11:01:13 +1030
parents c59513fd84fb
children 2bce4dbf52b8
line wrap: on
line diff
--- a/syscalls.c	Sat Oct 08 20:35:34 2011 +1030
+++ b/syscalls.c	Sun Jan 01 11:01:13 2012 +1030
@@ -5,14 +5,13 @@
  *      Author: Martin Thomas, 3BSD license
  */
 
-//#define SBRK_VERBOSE 1
-
 #include <stdio.h>
 #include <reent.h>
 #include <errno.h>
 #include <stdlib.h> /* abort */
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/time.h>
 
 #include "comm.h"
 #include "stm32f10x.h" /* for _get_PSP() from core_cm3.h*/
@@ -27,7 +26,8 @@
     return -1;
 }
 
-void _exit(int status) {
+void
+_exit(int status) {
     printf("_exit called with parameter %d\n", status);
     while(1)
 	;
@@ -38,7 +38,6 @@
     return 1;
 }
 
-
 extern char _end; /* Defined by the linker */
 static char *heap_end;
 
@@ -49,26 +48,24 @@
 
 char *
 get_stack_top(void) {
+    /* Use MSP (vs PSP) - the processor is in Thread mode out of reset */
     return (char*) __get_MSP();
-    //return (char*) __get_PSP();
 }
 
 caddr_t
 _sbrk(int incr) {
     char *prev_heap_end;
-#if SBRK_VERBOSE
-    printf("_sbrk called with incr %d\n", incr);
-#endif
+
     if (heap_end == 0) {
 	heap_end = &_end;
     }
     prev_heap_end = heap_end;
-#if 1
+
     if (heap_end + incr > get_stack_top()) {
 	printf("Heap and stack collision\n");
 	abort();
     }
-#endif
+
     heap_end += incr;
     return (caddr_t) prev_heap_end;
 }
@@ -118,3 +115,49 @@
     }
     return len;
 }
+
+int
+_gettimeofday_r(struct _reent *reent __attribute__((unused)), struct timeval *tp, void *tzp __attribute__((unused))) {
+    tp->tv_sec = RTC_GetCounter();
+    tp->tv_usec = 0;
+
+    return 0;
+}
+
+int
+settimeofday(const struct timeval *tp, const struct timezone *tzp __attribute__((unused))) {
+    RTC_SetCounter(tp->tv_sec);
+
+    return 0;
+}
+
+clock_t 
+_clock (void) {
+    return RTC_GetCounter();
+}
+
+void
+__tz_lock (void) {
+}
+
+
+void
+__tz_unlock (void) {
+}
+
+static __tzinfo_type tzinfo = {1, 0,
+    { {'J', 0, 0, 0, 0, (time_t)0, 0L },
+      {'J', 0, 0, 0, 0, (time_t)0, 0L } 
+    } 
+};
+
+__tzinfo_type *
+__gettzinfo (void) {
+  return &tzinfo;
+}
+
+/* Stub, required for strftime?! */
+int
+_open(const char *name __attribute__((unused)), int mode __attribute__((unused)), ...) {
+    return -1;
+}