1 | /*
|
---|
2 | Copyright (c) 2014 Arduino. All right reserved.
|
---|
3 |
|
---|
4 | This library is free software; you can redistribute it and/or
|
---|
5 | modify it under the terms of the GNU Lesser General Public
|
---|
6 | License as published by the Free Software Foundation; either
|
---|
7 | version 2.1 of the License, or (at your option) any later version.
|
---|
8 |
|
---|
9 | This library is distributed in the hope that it will be useful,
|
---|
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
---|
12 | See the GNU Lesser General Public License for more details.
|
---|
13 |
|
---|
14 | You should have received a copy of the GNU Lesser General Public
|
---|
15 | License along with this library; if not, write to the Free Software
|
---|
16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
---|
17 | */
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Implementation of newlib syscall.
|
---|
21 | *
|
---|
22 | */
|
---|
23 |
|
---|
24 | #include <errno.h>
|
---|
25 |
|
---|
26 | #include "syscalls.h"
|
---|
27 | #include "sam.h"
|
---|
28 |
|
---|
29 | #ifdef __cplusplus
|
---|
30 | extern "C" {
|
---|
31 | #endif
|
---|
32 |
|
---|
33 | #undef errno
|
---|
34 | extern int errno ;
|
---|
35 | extern int __end__ ;
|
---|
36 | extern int __ram_end__ ;
|
---|
37 |
|
---|
38 | extern caddr_t _sbrk( int incr )
|
---|
39 | {
|
---|
40 | static unsigned char *heap = NULL ;
|
---|
41 | unsigned char *prev_heap ;
|
---|
42 | int ramend = (int)&__ram_end__ ;
|
---|
43 |
|
---|
44 | if ( heap == NULL )
|
---|
45 | {
|
---|
46 | heap = (unsigned char *)&__end__ ;
|
---|
47 | }
|
---|
48 | prev_heap = heap ;
|
---|
49 |
|
---|
50 | if ( ((int)prev_heap + incr) > ramend )
|
---|
51 | {
|
---|
52 | return (caddr_t) -1 ;
|
---|
53 | }
|
---|
54 |
|
---|
55 | heap += incr ;
|
---|
56 |
|
---|
57 | return (caddr_t) prev_heap ;
|
---|
58 | }
|
---|
59 |
|
---|
60 | extern int link( char *cOld, char *cNew )
|
---|
61 | {
|
---|
62 | return -1 ;
|
---|
63 | }
|
---|
64 |
|
---|
65 | extern int _close( int file )
|
---|
66 | {
|
---|
67 | return -1 ;
|
---|
68 | }
|
---|
69 |
|
---|
70 | extern int _fstat( int file, struct stat *st )
|
---|
71 | {
|
---|
72 | st->st_mode = S_IFCHR ;
|
---|
73 |
|
---|
74 | return 0 ;
|
---|
75 | }
|
---|
76 |
|
---|
77 | extern int _isatty( int file )
|
---|
78 | {
|
---|
79 | return 1 ;
|
---|
80 | }
|
---|
81 |
|
---|
82 | extern int _lseek( int file, int ptr, int dir )
|
---|
83 | {
|
---|
84 | return 0 ;
|
---|
85 | }
|
---|
86 |
|
---|
87 | extern int _read(int file, char *ptr, int len)
|
---|
88 | {
|
---|
89 | return 0 ;
|
---|
90 | }
|
---|
91 |
|
---|
92 | extern int _write( int file, char *ptr, int len )
|
---|
93 | {
|
---|
94 | int iIndex=0 ;
|
---|
95 |
|
---|
96 | switch ( file )
|
---|
97 | {
|
---|
98 | case 1 /*STDOUT_FILENO*/:
|
---|
99 | for ( ; len >= 0 ; len--, ptr++, iIndex++ )
|
---|
100 | {
|
---|
101 | // Check if the transmitter is ready
|
---|
102 | // while ((UART->UART_SR & UART_SR_TXRDY) != UART_SR_TXRDY)
|
---|
103 | {
|
---|
104 | }
|
---|
105 |
|
---|
106 | // Send character
|
---|
107 | // UART->UART_THR = *ptr;
|
---|
108 | }
|
---|
109 | break;
|
---|
110 |
|
---|
111 | default:
|
---|
112 | errno = EBADF ;
|
---|
113 | iIndex = -1 ;
|
---|
114 | break;
|
---|
115 | }
|
---|
116 |
|
---|
117 | return iIndex ;
|
---|
118 | }
|
---|
119 |
|
---|
120 | extern void _exit( int status )
|
---|
121 | {
|
---|
122 | printf( "Exiting with status %d.\n", status ) ;
|
---|
123 |
|
---|
124 | for ( ; ; ) ;
|
---|
125 | }
|
---|
126 |
|
---|
127 | extern void _kill( int pid, int sig )
|
---|
128 | {
|
---|
129 | return ;
|
---|
130 | }
|
---|
131 |
|
---|
132 | extern int _getpid ( void )
|
---|
133 | {
|
---|
134 | return -1 ;
|
---|
135 | }
|
---|
136 |
|
---|
137 | #ifdef __cplusplus
|
---|
138 | }
|
---|
139 | #endif
|
---|