]> git.sur5r.net Git - freertos/blob - Demo/MCF5235_GCC/system/newlib.c
Update to V4.6.1 - including PIC32MX port.
[freertos] / Demo / MCF5235_GCC / system / newlib.c
1 /*\r
2     FreeRTOS MCF5235 port - Copyright (C) 2006 Christian Walter.\r
3 \r
4     This file is part of the FreeRTOS distribution.\r
5 \r
6     FreeRTOS is free software; you can redistribute it and/or modify\r
7     it under the terms of the GNU General Public License as published by\r
8     the Free Software Foundation; either version 2 of the License, or\r
9     (at your option) any later version.\r
10 \r
11     FreeRTOS is distributed in the hope that it will be useful,\r
12     but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14     GNU General Public License for more details.\r
15 \r
16     You should have received a copy of the GNU General Public License\r
17     along with FreeRTOS; if not, write to the Free Software\r
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
19 \r
20     A special exception to the GPL can be applied should you wish to distribute\r
21     a combined work that includes FreeRTOS, without being obliged to provide\r
22     the source code for any proprietary components.  See the licensing section\r
23     of http://www.FreeRTOS.org for full details of how and when the exception\r
24     can be applied.\r
25 \r
26     ***************************************************************************\r
27     See http://www.FreeRTOS.org for documentation, latest information, license\r
28     and contact details.  Please ensure to read the configuration and relevant\r
29     port sections of the online documentation.\r
30 \r
31         Also see http://www.SafeRTOS.com a version that has been certified for use\r
32         in safety critical systems, plus commercial licensing, development and\r
33         support options.\r
34     ***************************************************************************\r
35 */\r
36 \r
37 /* ------------------------ System includes ------------------------------- */\r
38 #include <sys/types.h>\r
39 #include <sys/stat.h>\r
40 #include <unistd.h>\r
41 #include <errno.h>\r
42 \r
43 /* ------------------------ FreeRTOS includes ----------------------------- */\r
44 #include <FreeRTOS.h>\r
45 #include <serial.h>\r
46 \r
47 /* ------------------------ Prototypes ------------------------------------ */\r
48 void vSerialPutStringNOISR( xComPortHandle pxPort,\r
49                             const signed portCHAR * const pcString,\r
50                             unsigned portSHORT usStringLength );\r
51 \r
52 /* ------------------------ Start implementation -------------------------- */\r
53 void\r
54 _exit( int status )\r
55 {\r
56     asm volatile    ( "halt" );\r
57 \r
58     for( ;; );\r
59 }\r
60 \r
61 pid_t\r
62 getpid( void )\r
63 {\r
64     return 0;\r
65 }\r
66 \r
67 int\r
68 kill( pid_t pid, int sig )\r
69 {\r
70     _exit( 0 );\r
71 }\r
72 \r
73 int\r
74 close( int fd )\r
75 {\r
76     return 0;\r
77 }\r
78 \r
79 int\r
80 fstat( int fd, struct stat *buf )\r
81 {\r
82     buf->st_mode = S_IFCHR;\r
83     buf->st_blksize = 0;\r
84     return 0;\r
85 }\r
86 \r
87 ssize_t\r
88 write( int fd, const void *buf, size_t nbytes )\r
89 {\r
90     ssize_t res = nbytes;\r
91     extern xComPortHandle xSTDComPort;\r
92     switch ( fd )\r
93     {\r
94         case STDERR_FILENO:\r
95             vSerialPutStringNOISR( xSTDComPort,\r
96                                    ( const signed portCHAR * const )buf,\r
97                                    ( unsigned portSHORT )nbytes );\r
98             break;\r
99         case STDOUT_FILENO:\r
100             vSerialPutString( xSTDComPort,\r
101                               ( const signed portCHAR * const)buf,\r
102                               ( unsigned portSHORT )nbytes );\r
103             break;\r
104         default:\r
105             errno = EIO;\r
106             res = -1;\r
107             break;\r
108     }\r
109     return res;\r
110 }\r
111 \r
112 int\r
113 read( int fd, void *buf, size_t nbytes )\r
114 {\r
115     switch ( fd )\r
116     {\r
117         default:\r
118             errno = EIO;\r
119             return -1;\r
120     }\r
121 }\r
122 \r
123 int\r
124 isatty( int fd )\r
125 {\r
126     return 0;\r
127 }\r
128 \r
129 off_t\r
130 lseek( int fd, off_t offset, int whence )\r
131 {\r
132     errno = EIO;\r
133     return ( off_t ) - 1;\r
134 }\r
135 \r
136 extern char     _end[];\r
137 char           *heap_ptr;\r
138 \r
139 void           *\r
140 sbrk( ptrdiff_t nbytes )\r
141 {\r
142     char           *base;\r
143 \r
144     if( !heap_ptr )\r
145         heap_ptr = ( char * )&_end;\r
146     base = heap_ptr;\r
147     heap_ptr += nbytes;\r
148 \r
149     return base;\r
150 }\r