Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include <stdlib.h>
00038 #include <errno.h>
00039 #include <string.h>
00040 #include <sys/stat.h>
00041 #include <sys/types.h>
00042
00043 #include "uart/uart.h"
00044
00045 int _read_r (struct _reent *r, int file, char * ptr, int len)
00046 {
00047 r = r;
00048 file = file;
00049 ptr = ptr;
00050 len = len;
00051
00052 errno = EINVAL;
00053 return -1;
00054 }
00055
00056
00057
00058 int _lseek_r (struct _reent *r, int file, int ptr, int dir)
00059 {
00060 r = r;
00061 file = file;
00062 ptr = ptr;
00063 dir = dir;
00064
00065 return 0;
00066 }
00067
00068
00069
00070 int _write_r (struct _reent *r, int file, char * ptr, int len)
00071 {
00072 r = r;
00073 file = file;
00074 ptr = ptr;
00075
00076 #if 1
00077 int index;
00078
00079
00080 for(index=0; index<len; index++)
00081 {
00082 if (ptr[index] == '\n')
00083 {
00084 UARTTransmitByte('\r',UART_CH_0);
00085 }
00086
00087 UARTTransmitByte(ptr[index],UART_CH_0);
00088 }
00089 #endif
00090
00091
00092 return len;
00093 }
00094
00095
00096
00097 int _close_r (struct _reent *r, int file)
00098 {
00099 return 0;
00100 }
00101
00102
00103
00104
00105 register char * stack_ptr asm ("sp");
00106
00107 caddr_t _sbrk_r (struct _reent *r, int incr)
00108 {
00109 extern char end asm ("end");
00110 static char * heap_end;
00111 unsigned long n;
00112 char * prev_heap_end;
00113 if (heap_end == NULL)
00114 heap_end = &end;
00115
00116 prev_heap_end = heap_end;
00117
00118 if (heap_end + incr > stack_ptr)
00119 {
00120 uart_puts("\n Heap > stack");
00121
00122
00123 #if 0
00124 extern void DABT_Routine(void);
00125
00126 n = (unsigned long)stack_ptr;
00127
00128 uart_puts("0x");
00129 uart_putc('0' + ((n>>7) & 0xf));
00130 uart_putc('0' + ((n>>6) & 0xf));
00131 uart_putc('0' + ((n>>5) & 0xf));
00132 uart_putc('0' + ((n>>4) & 0xf));
00133 uart_putc('0' + ((n>>3) & 0xf));
00134 uart_putc('0' + ((n>>2) & 0xf));
00135 uart_putc('0' + ((n>>1) & 0xf));
00136 uart_putc('0' + ((n) & 0xf));
00137 uart_putc(' ');
00138
00139 n = (unsigned long)(heap_end);
00140
00141 uart_puts("0x");
00142 uart_putc('0' + ((n>>7) & 0xf));
00143 uart_putc('0' + ((n>>6) & 0xf));
00144 uart_putc('0' + ((n>>5) & 0xf));
00145 uart_putc('0' + ((n>>4) & 0xf));
00146 uart_putc('0' + ((n>>3) & 0xf));
00147 uart_putc('0' + ((n>>2) & 0xf));
00148 uart_putc('0' + ((n>>1) & 0xf));
00149 uart_putc('0' + ((n) & 0xf));
00150 uart_putc(' ');
00151
00152 uart_puts("_sbrk: Heap and stack collision\n");
00153
00154 DABT_Routine ();
00155 #else
00156 errno = ENOMEM;
00157 return (caddr_t) -1;
00158 #endif
00159 }
00160
00161 heap_end += incr;
00162
00163 return (caddr_t) prev_heap_end;
00164 }
00165
00166
00167
00168 int _fstat_r (struct _reent *r, int file, struct stat * st)
00169 {
00170 r = r;
00171 file = file;
00172
00173 memset (st, 0, sizeof (* st));
00174 st->st_mode = S_IFCHR;
00175 return 0;
00176 }
00177
00178
00179
00180 int _isatty_r(struct _reent *r, int fd)
00181 {
00182 r = r;
00183 fd = fd;
00184
00185 return 1;
00186 }
00187
00188
00189
00190