1 /*******************************************************************************
\r
2 * (c) Copyright 2009 Actel Corporation. All rights reserved.
\r
4 * Stubs for Newlib system calls.
\r
6 * SVN $Revision: 2020 $
\r
7 * SVN $Date: 2010-01-20 14:51:50 +0000 (Wed, 20 Jan 2010) $
\r
10 #include <sys/unistd.h>
\r
11 #include <sys/stat.h>
\r
12 #include <sys/times.h>
\r
17 /*==============================================================================
\r
18 * Redirection of standard output to a SmartFusion MSS UART.
\r
19 *------------------------------------------------------------------------------
\r
20 * A default implementation for the redirection of the output of printf() to a
\r
21 * UART is provided as the bottom of this file. This redirection is enabled by
\r
22 * adding the symbol/define ACTEL_STDIO_THRU_UART to your project and
\r
23 * specifying the baud rate using the ACTEL_STDIO_BAUD_RATE define.
\r
25 #ifdef ACTEL_STDIO_THRU_UART
\r
26 #include "../../drivers/mss_uart/mss_uart.h"
\r
28 #ifndef ACTEL_STDIO_BAUD_RATE
\r
29 #define ACTEL_STDIO_BAUD_RATE MSS_UART_57600_BAUD
\r
32 /*------------------------------------------------------------------------------
\r
33 * Global flag used to indicate if the UART driver needs to be initialized.
\r
35 static int g_stdio_uart_init_done = 0;
\r
37 #endif /* ACTEL_STDIO_THRU_UART */
\r
39 /*==============================================================================
\r
40 * Environment variables.
\r
41 * A pointer to a list of environment variables and their values. For a minimal
\r
42 * environment, this empty list is adequate:
\r
44 char *__env[1] = { 0 };
\r
45 char **environ = __env;
\r
47 /*==============================================================================
\r
50 int _close(int file)
\r
55 /*==============================================================================
\r
56 * Transfer control to a new process.
\r
58 int _execve(char *name, char **argv, char **env)
\r
64 /*==============================================================================
\r
65 * Exit a program without cleaning up files.
\r
67 void _exit( int code )
\r
69 /* Should we force a system reset? */
\r
76 /*==============================================================================
\r
77 * Create a new process.
\r
85 /*==============================================================================
\r
86 * Status of an open file.
\r
88 int _fstat(int file, struct stat *st)
\r
90 st->st_mode = S_IFCHR;
\r
94 /*==============================================================================
\r
102 /*==============================================================================
\r
103 * Query whether output stream is a terminal.
\r
105 int _isatty(int file)
\r
110 /*==============================================================================
\r
113 int _kill(int pid, int sig)
\r
119 /*==============================================================================
\r
120 * Establish a new name for an existing file.
\r
122 int _link(char *old, char *new)
\r
128 /*==============================================================================
\r
129 * Set position in a file.
\r
131 int _lseek(int file, int ptr, int dir)
\r
136 /*==============================================================================
\r
139 int _open(const char *name, int flags, int mode)
\r
144 /*==============================================================================
\r
145 * Read from a file.
\r
147 int _read(int file, char *ptr, int len)
\r
152 /*==============================================================================
\r
153 * Increase program data space. As malloc and related functions depend on this,
\r
154 * it is useful to have a working implementation. The following suffices for a
\r
155 * standalone system; it exploits the symbol _end automatically defined by the
\r
158 caddr_t _sbrk(int incr)
\r
160 extern char _end; /* Defined by the linker */
\r
161 static char *heap_end;
\r
162 char *prev_heap_end;
\r
170 prev_heap_end = heap_end;
\r
171 asm volatile ("MRS %0, msp" : "=r" (stack_ptr) );
\r
172 if (heap_end + incr > stack_ptr)
\r
174 write (1, "Heap and stack collision\n", 25);
\r
179 return (caddr_t) prev_heap_end;
\r
182 /*==============================================================================
\r
183 * Status of a file (by name).
\r
185 int _stat(char *file, struct stat *st)
\r
187 st->st_mode = S_IFCHR;
\r
191 /*==============================================================================
\r
192 * Timing information for current process.
\r
194 int _times(struct tms *buf)
\r
199 /*==============================================================================
\r
200 * Remove a file's directory entry.
\r
202 int _unlink(char *name)
\r
208 /*==============================================================================
\r
209 * Wait for a child process.
\r
211 int _wait(int *status)
\r
217 /*==============================================================================
\r
218 * Write to a file. libc subroutines will use this system routine for output to
\r
219 * all files, including stdout
\97so if you need to generate any output, for
\r
220 * example to a serial port for debugging, you should make your minimal write
\r
221 * capable of doing this.
\r
223 int _write_r( void * reent, int file, char * ptr, int len )
\r
225 #ifdef ACTEL_STDIO_THRU_UART
\r
226 /*--------------------------------------------------------------------------
\r
227 * Initialize the UART driver if it is the first time this function is
\r
230 if ( !g_stdio_uart_init_done )
\r
232 MSS_UART_init( &g_mss_uart0, ACTEL_STDIO_BAUD_RATE, (MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY));
\r
233 g_stdio_uart_init_done = 1;
\r
236 /*--------------------------------------------------------------------------
\r
237 * Output text to the UART.
\r
239 MSS_UART_polled_tx( &g_mss_uart0, (uint8_t *)ptr, len );
\r
242 #else /* ACTEL_STDIO_THRU_UART */
\r
244 #endif /* ACTEL_STDIO_THRU_UART */
\r