view syscalls.c @ 59:488085e0c7e1

Don't print extra newlines when cat'ing a file.
author Daniel O'Connor <darius@dons.net.au>
date Mon, 08 Apr 2013 23:10:47 +0930
parents 0e7d687a2322
children
line wrap: on
line source

/*
 * syscalls.c
 *
 *  Created on: 03.12.2009
 *      Author: Martin Thomas, 3BSD license
 */

#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 "rtc.h"
#include "stm32f10x.h" /* for _get_PSP() from core_cm3.h*/

int *
__errno(void) {
    static int _errno;
    
    return(&errno);
}

int
_kill(int pid, int sig) {
    pid = pid; sig = sig; /* avoid warnings */
    errno = EINVAL;
    return -1;
}

void
_exit(int status) {
    printf("_exit called with parameter %d\r\n", status);
    __disable_irq();
    while(1)
	;
}

int
_getpid(void) {
    return 1;
}

extern char _end; /* Defined by the linker */
static char *heap_end;

char *
get_heap_end(void) {
    return (char*) heap_end;
}

char *
get_stack_top(void) {
    /* Use MSP (vs PSP) - the processor is in Thread mode out of reset */
    return (char*) __get_MSP();
}

caddr_t
_sbrk(int incr) {
    char *prev_heap_end;

    if (heap_end == 0) {
	heap_end = &_end;
    }
    prev_heap_end = heap_end;

    if (heap_end + incr > get_stack_top()) {
	printf("Heap and stack collision\r\n");
	abort();
    }

    heap_end += incr;
    return (caddr_t) prev_heap_end;
}

int
_close(int file) {
    file = file; /* avoid warning */
    return -1;
}

int
_fstat(int file, struct stat *st) {
    file = file; /* avoid warning */
    st->st_mode = S_IFCHR;
    return 0;
}

int
_isatty(int file) {
    file = file; /* avoid warning */
    return 1;
}

int
_lseek(int file, int ptr, int dir) {
    file = file; /* avoid warning */
    ptr = ptr; /* avoid warning */
    dir = dir; /* avoid warning */
    return 0;
}

int
_read(int file, char *ptr, int len) {
    file = file; /* avoid warning */
    ptr = ptr; /* avoid warning */
    len = len; /* avoid warning */
    return 0;
}

int
_write(int file, char *ptr, int len) {
    int todo;
    
    for (todo = 0; todo < len; todo++) {
	if (file == 1 || file == 2)
	    if (*ptr == '\n')
		comm_put('\r');
	comm_put(*ptr);
	ptr++;
    }
    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 = RTC_PS2USEC(RTC_GetDivider());
    
    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) {
}

/* Set tzinfo directly so we don't need tzset() which requires getenv() */
#ifdef USE_UTC
static __tzinfo_type tzinfo = {1, 0,
    { {'J', 0, 0, 0, 0, (time_t)0, 0L },
      {'J', 0, 0, 0, 0, (time_t)0, 0L } 
    } 
};
#else
/* ACST (south)
 * Switch from DST 3am 1st Sunday of April:  -9.5 hours to UTC
 * Switch  to  DST 2am 1st Sunday October:  -10.5 hours to UTC
 *
 * Copied from http://www.sourceware.org/ml/newlib/2008/msg00311.html
 */
static __tzinfo_type tzinfo = {0, 0, {
	{'M',  4, 5, 0, 10800, (time_t)0, -34200L },
	{'M', 10, 5, 0,  7200, (time_t)0, -37800L } 
    }
};
#endif

__tzinfo_type *
__gettzinfo (void) {
  return &tzinfo;
}

/* Stub, required for strftime?! */
int
_open(const char *name __attribute__((unused)), int mode __attribute__((unused)), ...) {
    return -1;
}