1 /*******************************************************************
2 Components for embedded applications builded for
3 laboratory and medical instruments firmware
5 system_stub.c - system stub routines for system-less
6 NEWLIB C library environment
8 Copyright (C) 2001-2003 by Pavel Pisa pisa@cmp.felk.cvut.cz
9 (C) 2001-2003 by PiKRON Ltd. http://www.pikron.com
11 *******************************************************************/
14 #include <system_def.h>
18 /***********************************************************/
19 #include <periph/qsm_rs232.h>
24 while((ch=qsm_rs232_recch())<0)
25 { /* wait for char */ ; }
30 int outbyte(unsigned char ch)
33 while((res=qsm_rs232_sendch(ch))<0)
34 { /* wait for send */ ; }
39 /***********************************************************/
42 * close -- We don't need to do anything, but pretend we did.
50 * fstat -- Since we have no file system, we just return an error.
52 int fstat(int fd,struct stat *buf)
54 buf->st_mode = S_IFCHR; /* Always pretend to be a tty */
60 * getpid -- only one process, so just return 1.
68 * isatty -- returns 1 if connected to a terminal device,
69 * returns 0 if not. Since we're hooked up to a
70 * serial port, we'll say yes _AND return a 1.
78 * kill -- go out via exit...
80 int kill(int pid,int sig)
89 * lseek -- Since a serial port is non-seekable, we return an error.
91 off_t lseek(int fd, off_t offset, int whence)
98 * open -- open a file descriptor. We don't have a filesystem, so
101 int open(const char *buf, int flags, int mode)
108 * print -- do a raw print of a string
110 void print(char *ptr)
118 * putnum -- print a 32 bit number in hex
120 void putnum(unsigned int num)
128 for (cnt = 7 ; cnt >= 0 ; cnt--) {
129 digit = (num >> (cnt * 4)) & 0xf;
132 *ptr++ = (char) ('0' + digit);
134 *ptr++ = (char) ('a' - 10 + digit);
142 * read -- read bytes from the serial port. Ignore fd, since
143 * we only have stdin.
145 int read(int fd,char *buf,int nbytes)
149 for (i = 0; i < nbytes; i++) {
150 *(buf + i) = inbyte();
151 if ((*(buf + i) == '\n') || (*(buf + i) == '\r')) {
152 (*(buf + i + 1)) = 0;
163 * sbrk -- changes heap size size. Get nbytes more
164 * RAM. We just increment a pointer in what's
165 * left of memory on the board.
167 char *sbrk(int nbytes)
173 heap_ptr = (char *)&_end;
174 /* heap_ptr = (char *)0x70000; */ /* !!!!!!!!!!! */
180 /* FIXME: We really want to make sure we don't run out of RAM, but this
181 * isn't very portable.
184 if ((RAMSIZE - heap_ptr - nbytes) >= 0) {
196 * stat -- Since we have no file system, we just return an error.
198 int stat(const char *path, struct stat *buf)
205 * unlink -- since we have no file system,
206 * we just return an error.
208 int unlink(char * path)
215 * write -- write bytes to the serial port. Ignore fd, since
216 * stdout and stderr are the same. Since we have no filesystem,
217 * open will only return an error.
219 int write(int fd, char *buf, int nbytes)
223 for (i = 0; i < nbytes; i++) {
224 if (*(buf + i) == '\n') {
227 outbyte (*(buf + i));