]> git.sur5r.net Git - freertos/blob - Demo/CORTEX_A2F200_IAR_and_Keil/MicroSemi_Code/CMSIS/startup_gcc/newlib_stubs.c
Create directory structure to hold the (not yet created) Keil and IAR demo projects...
[freertos] / Demo / CORTEX_A2F200_IAR_and_Keil / MicroSemi_Code / CMSIS / startup_gcc / newlib_stubs.c
1 /*******************************************************************************\r
2  * (c) Copyright 2009 Actel Corporation.  All rights reserved.\r
3  * \r
4  * Stubs for Newlib system calls.\r
5  *  \r
6  * SVN $Revision: 2020 $\r
7  * SVN $Date: 2010-01-20 14:51:50 +0000 (Wed, 20 Jan 2010) $\r
8  */\r
9 #include <stdlib.h>\r
10 #include <sys/unistd.h>\r
11 #include <sys/stat.h>\r
12 #include <sys/times.h>\r
13 #include <errno.h>\r
14 #undef errno\r
15 extern int errno;\r
16 \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
24  */\r
25 #ifdef ACTEL_STDIO_THRU_UART\r
26 #include "../../drivers/mss_uart/mss_uart.h"\r
27 \r
28 #ifndef ACTEL_STDIO_BAUD_RATE\r
29 #define ACTEL_STDIO_BAUD_RATE  MSS_UART_57600_BAUD\r
30 #endif\r
31 \r
32 /*------------------------------------------------------------------------------\r
33  * Global flag used to indicate if the UART driver needs to be initialized.\r
34  */\r
35 static int g_stdio_uart_init_done = 0;\r
36 \r
37 #endif  /* ACTEL_STDIO_THRU_UART */\r
38 \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
43  */\r
44 char *__env[1] = { 0 };\r
45 char **environ = __env;\r
46 \r
47 /*==============================================================================\r
48  * Close a file.\r
49  */\r
50 int _close(int file)\r
51 {\r
52     return -1;\r
53 }\r
54 \r
55 /*==============================================================================\r
56  * Transfer control to a new process.\r
57  */\r
58 int _execve(char *name, char **argv, char **env)\r
59 {\r
60     errno = ENOMEM;\r
61     return -1;\r
62 }\r
63 \r
64 /*==============================================================================\r
65  * Exit a program without cleaning up files.\r
66  */\r
67 void _exit( int code )\r
68 {\r
69         /* Should we force a system reset? */\r
70         while( 1 )\r
71         {\r
72                 ;\r
73         }\r
74 }\r
75 \r
76 /*==============================================================================\r
77  * Create a new process.\r
78  */\r
79 int _fork(void)\r
80 {\r
81     errno = EAGAIN;\r
82     return -1;\r
83 }\r
84 \r
85 /*==============================================================================\r
86  * Status of an open file.\r
87  */\r
88 int _fstat(int file, struct stat *st)\r
89 {\r
90     st->st_mode = S_IFCHR;\r
91     return 0;\r
92 }\r
93 \r
94 /*==============================================================================\r
95  * Process-ID\r
96  */\r
97 int _getpid(void)\r
98 {\r
99     return 1;\r
100 }\r
101 \r
102 /*==============================================================================\r
103  * Query whether output stream is a terminal.\r
104  */\r
105 int _isatty(int file)\r
106 {\r
107     return 1;\r
108 }\r
109 \r
110 /*==============================================================================\r
111  * Send a signal.\r
112  */\r
113 int _kill(int pid, int sig)\r
114 {\r
115     errno = EINVAL;\r
116     return -1;\r
117 }\r
118 \r
119 /*==============================================================================\r
120  * Establish a new name for an existing file.\r
121  */\r
122 int _link(char *old, char *new)\r
123 {\r
124     errno = EMLINK;\r
125     return -1;\r
126 }\r
127 \r
128 /*==============================================================================\r
129  * Set position in a file.\r
130  */\r
131 int _lseek(int file, int ptr, int dir)\r
132 {\r
133     return 0;\r
134 }\r
135 \r
136 /*==============================================================================\r
137  * Open a file.\r
138  */\r
139 int _open(const char *name, int flags, int mode)\r
140 {\r
141     return -1;\r
142 }\r
143 \r
144 /*==============================================================================\r
145  * Read from a file.\r
146  */\r
147 int _read(int file, char *ptr, int len)\r
148 {\r
149     return 0;\r
150 }\r
151 \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
156  * GNU linker. \r
157  */\r
158 caddr_t _sbrk(int incr)\r
159 {\r
160     extern char _end;           /* Defined by the linker */\r
161     static char *heap_end;\r
162     char *prev_heap_end;\r
163     char * stack_ptr;\r
164     \r
165     if (heap_end == 0)\r
166     {\r
167       heap_end = &_end;\r
168     }\r
169     \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
173     {\r
174       write (1, "Heap and stack collision\n", 25);\r
175       abort ();\r
176     }\r
177   \r
178     heap_end += incr;\r
179     return (caddr_t) prev_heap_end;\r
180 }\r
181 \r
182 /*==============================================================================\r
183  * Status of a file (by name).\r
184  */\r
185 int _stat(char *file, struct stat *st)\r
186 {\r
187     st->st_mode = S_IFCHR;\r
188     return 0;\r
189 }\r
190 \r
191 /*==============================================================================\r
192  * Timing information for current process.\r
193  */\r
194 int _times(struct tms *buf)\r
195 {\r
196     return -1;\r
197 }\r
198 \r
199 /*==============================================================================\r
200  * Remove a file's directory entry.\r
201  */\r
202 int _unlink(char *name)\r
203 {\r
204     errno = ENOENT;\r
205     return -1;\r
206 }\r
207 \r
208 /*==============================================================================\r
209  * Wait for a child process.\r
210  */\r
211 int _wait(int *status)\r
212 {\r
213     errno = ECHILD;\r
214     return -1;\r
215 }\r
216 \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
222  */\r
223 int _write_r( void * reent, int file, char * ptr, int len )\r
224 {\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
228          * called.\r
229          */\r
230         if ( !g_stdio_uart_init_done )\r
231         {\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
234         }\r
235         \r
236         /*--------------------------------------------------------------------------\r
237          * Output text to the UART.\r
238          */\r
239         MSS_UART_polled_tx( &g_mss_uart0, (uint8_t *)ptr, len );\r
240         \r
241         return len;\r
242 #else   /* ACTEL_STDIO_THRU_UART */\r
243         return 0;\r
244 #endif  /* ACTEL_STDIO_THRU_UART */\r
245 }\r
246 \r
247 \r