Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
56 | mjames | 1 | /*---------------------------------------------------------------------------- |
2 | * Name: Retarget.c |
||
3 | * Purpose: 'Retarget' layer for target-dependent low level functions |
||
4 | * Note(s): |
||
5 | *---------------------------------------------------------------------------- |
||
6 | * This file is part of the uVision/ARM development tools. |
||
7 | * This software may only be used under the terms of a valid, current, |
||
8 | * end user licence from KEIL for a compatible version of KEIL software |
||
9 | * development tools. Nothing else gives you the right to use this software. |
||
10 | * |
||
11 | * This software is supplied "AS IS" without warranties of any kind. |
||
12 | * |
||
13 | * Copyright (c) 2012 Keil - An ARM Company. All rights reserved. |
||
14 | *----------------------------------------------------------------------------*/ |
||
15 | |||
16 | #include <sys/stat.h> |
||
17 | #include <string.h> |
||
18 | #include <errno.h> |
||
19 | |||
20 | int SER_PutChar (int c) { |
||
21 | |||
22 | return (c); |
||
23 | } |
||
24 | |||
25 | int SER_GetChar (void) { |
||
26 | |||
27 | return (-1); |
||
28 | } |
||
29 | |||
30 | /*-- GCC - Newlib runtime support --------------------------------------------*/ |
||
31 | |||
32 | extern int __HeapBase; |
||
33 | extern int __HeapLimit; |
||
34 | |||
35 | int _open (const char * path, int flags, ...) |
||
36 | { |
||
37 | return (-1); |
||
38 | } |
||
39 | |||
40 | int _close (int fd) |
||
41 | { |
||
42 | return (-1); |
||
43 | } |
||
44 | |||
45 | int _lseek (int fd, int ptr, int dir) |
||
46 | { |
||
47 | return (0); |
||
48 | } |
||
49 | |||
50 | int __attribute__((weak)) _fstat (int fd, struct stat * st) |
||
51 | { |
||
52 | memset (st, 0, sizeof (* st)); |
||
53 | st->st_mode = S_IFCHR; |
||
54 | return (0); |
||
55 | } |
||
56 | |||
57 | int _isatty (int fd) |
||
58 | { |
||
59 | return (1); |
||
60 | } |
||
61 | |||
62 | int _read (int fd, char * ptr, int len) |
||
63 | { |
||
64 | char c; |
||
65 | int i; |
||
66 | |||
67 | for (i = 0; i < len; i++) |
||
68 | { |
||
69 | c = SER_GetChar(); |
||
70 | if (c == 0x0D) break; |
||
71 | *ptr++ = c; |
||
72 | SER_PutChar(c); |
||
73 | } |
||
74 | return (len - i); |
||
75 | } |
||
76 | |||
77 | int _write (int fd, char * ptr, int len) |
||
78 | { |
||
79 | int i; |
||
80 | |||
81 | for (i = 0; i < len; i++) SER_PutChar (*ptr++); |
||
82 | return (i); |
||
83 | } |
||
84 | |||
85 | caddr_t _sbrk (int incr) |
||
86 | { |
||
87 | static char * heap; |
||
88 | char * prev_heap; |
||
89 | |||
90 | if (heap == NULL) |
||
91 | { |
||
92 | heap = (char *)&__HeapBase; |
||
93 | } |
||
94 | |||
95 | prev_heap = heap; |
||
96 | |||
97 | if ((heap + incr) > (char *)&__HeapLimit) |
||
98 | { |
||
99 | errno = ENOMEM; |
||
100 | return (caddr_t) -1; |
||
101 | } |
||
102 | |||
103 | heap += incr; |
||
104 | |||
105 | return (caddr_t) prev_heap; |
||
106 | } |