b553401dd9f646e0e75fe006d1f19d714f0b405b
1 /***********************************************************************/
3 /* SYSCALLS.C: System Calls for the newlib */
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 /***********************************************************************/
26 while ( AT91F_US_RxReady((AT91PS_USART)AT91C_BASE_DBGU) == 0 ) {
32 *p= AT91F_US_GetChar((AT91PS_USART)AT91C_BASE_DBGU);
46 const unsigned char *p;
51 for( ; todo != 0; todo--) {
53 while (!AT91F_US_TxReady((AT91PS_USART)AT91C_BASE_DBGU)) {
56 AT91F_US_PutChar((AT91PS_USART)AT91C_BASE_DBGU, '\r');
58 while (!AT91F_US_TxReady((AT91PS_USART)AT91C_BASE_DBGU)) {
61 AT91F_US_PutChar((AT91PS_USART)AT91C_BASE_DBGU, *p++);
64 return (_ssize_t
)len
; // Number of bytes written.
82 return (_off_t
)0; /* Always indicate we are at file beginning. */
91 /* Always set as character device. */
92 st
->st_mode
= S_IFCHR
;
93 /* assigned to strong type with implicit */
94 /* signed/unsigned conversion. Required by */
101 int _isatty(int file
); /* avoid warning */
103 int _isatty(int file
)
114 static void _exit (int n
) {
115 label
: goto label
; /* endless loop */
122 void * _sbrk_r(struct _reent
*r
, int incr
)
127 chDbgCheck(incr
> 0, "_sbrk_r");
130 p
= chCoreAlloc((size_t)incr
);
132 __errno_r(r
) = ENOMEM
;
137 __errno_r(r
) = ENOMEM
;
144 /**** Locally used variables. ****/
145 // mt: "cleaner": extern char* end;
146 extern char end
[]; /* end is set in the linker command */
147 /* file and is the end of statically */
148 /* allocated data (thus start of heap). */
150 static char *heap_ptr
; /* Points to current end of the heap. */
152 /************************** _sbrk_r *************************************
153 * Support function. Adjusts end of heap to provide more memory to
154 * memory allocator. Simple and dumb with no sanity checks.
156 * struct _reent *r -- re-entrancy structure, used by newlib to
157 * support multiple threads of operation.
158 * ptrdiff_t nbytes -- number of bytes to add.
159 * Returns pointer to start of new heap area.
161 * Note: This implementation is not thread safe (despite taking a
162 * _reent structure as a parameter).
163 * Since _s_r is not used in the current implementation,
164 * the following messages must be suppressed.
170 char *base
; /* errno should be set to ENOMEM on error */
172 if (!heap_ptr
) { /* Initialize if first time through. */
175 base
= heap_ptr
; /* Point to end of heap. */
176 heap_ptr
+= nbytes
; /* Increase heap. */
178 return base
; /* Return pointer to start of new heap area. */