00001
00006 #include "sceptre.h"
00007 #include "device.h"
00008 #include <stdio.h>
00009
00010
00020 _ssize_t _read_r(struct _reent *p_reent, int fd, _PTR p_dst, size_t dst_size)
00021 {
00022 int index;
00023
00024
00025
00026
00027 if (dst_size==0) return dst_size;
00028
00029 switch (fd)
00030 {
00031 case SCEPTRE_STDIN:
00032 {
00033 int i;
00034 char *p_str = (char *)p_dst;
00035 for (i=0; i<dst_size; i++)
00036 {
00037 uint32_t ch;
00038 if (uart0_getc(&ch,0)==false) break;
00039 *p_str++ = ch;
00040 }
00041 return dst_size - i;
00042 }
00043 break;
00044
00045 case SCEPTRE_STDOUT:
00046 case SCEPTRE_STDERR:
00047 break;
00048 }
00049
00050
00051 if ((index=device_find(p_reent,DEVICE_TYPE(fd)))==-1) return -1;
00052
00053
00054 if (device_table_list[index].p_item->read)
00055 {
00056 return device_table_list[index].p_item->read(p_reent,fd,p_dst,dst_size);
00057 }
00058
00059 printf("*** _read_r failed\n");
00060
00061 p_reent->_errno = EBADF;
00062 return -1;
00063 }
00064
00065