1 /***********************************************************************/
3 /* SYSCALLS.C: System Calls */
4 /* most of this is from newlib-lpc and a Keil-demo */
6 /* These are "reentrant functions" as needed by */
7 /* the WinARM-newlib-config, see newlib-manual. */
8 /* Collected and modified by Martin Thomas */
10 /***********************************************************************/
19 static void my_putc(char c)
21 while (!AT91F_US_TxReady((AT91PS_USART)AT91C_BASE_DBGU));
22 AT91F_US_PutChar((AT91PS_USART)AT91C_BASE_DBGU, c);
25 static int my_kbhit( void )
27 if ((AT91F_US_RxReady((AT91PS_USART)AT91C_BASE_DBGU)) == 0) return 0;
31 static char my_getc( void )
33 return AT91F_US_GetChar((AT91PS_USART)AT91C_BASE_DBGU);
46 p = (unsigned char*)ptr;
48 for (i = 0; i < len; i++) {
51 while ( !my_kbhit() ) ;
71 const unsigned char *p;
73 p = (const unsigned char*) ptr;
75 for (i = 0; i < len; i++) {
76 if (*p == '\n' ) my_putc('\r');
98 return (_off_t)0; /* Always indicate we are at file beginning. */
107 /* Always set as character device. */
108 st->st_mode = S_IFCHR;
109 /* assigned to strong type with implicit */
110 /* signed/unsigned conversion. Required by */
117 int isatty(int file); /* avoid warning */
126 static void _exit (int n) {
127 label: goto label; /* endless loop */
132 /* "malloc clue function" from newlib-lpc/Keil-Demo/"generic" */
134 /**** Locally used variables. ****/
135 // mt: "cleaner": extern char* end;
136 extern char end[]; /* end is set in the linker command */
137 /* file and is the end of statically */
138 /* allocated data (thus start of heap). */
140 static char *heap_ptr; /* Points to current end of the heap. */
142 /************************** _sbrk_r *************************************
143 * Support function. Adjusts end of heap to provide more memory to
144 * memory allocator. Simple and dumb with no sanity checks.
146 * struct _reent *r -- re-entrancy structure, used by newlib to
147 * support multiple threads of operation.
148 * ptrdiff_t nbytes -- number of bytes to add.
149 * Returns pointer to start of new heap area.
151 * Note: This implementation is not thread safe (despite taking a
152 * _reent structure as a parameter).
153 * Since _s_r is not used in the current implementation,
154 * the following messages must be suppressed.
160 char *base; /* errno should be set to ENOMEM on error */
162 if (!heap_ptr) { /* Initialize if first time through. */
165 base = heap_ptr; /* Point to end of heap. */
166 heap_ptr += nbytes; /* Increase heap. */
168 return base; /* Return pointer to start of new heap area. */