123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- #include <stdlib.h>
- #include <errno.h>
- #include <string.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include "ch.h"
- #if defined(STDOUT_SD) || defined(STDIN_SD)
- #include "hal.h"
- #endif
- __attribute__((used))
- int _read_r(struct _reent *r, int file, char * ptr, int len)
- {
- (void)r;
- #if defined(STDIN_SD)
- if (!len || (file != 0)) {
- __errno_r(r) = EINVAL;
- return -1;
- }
- len = sdRead(&STDIN_SD, (uint8_t *)ptr, (size_t)len);
- return len;
- #else
- (void)file;
- (void)ptr;
- (void)len;
- __errno_r(r) = EINVAL;
- return -1;
- #endif
- }
- __attribute__((used))
- int _lseek_r(struct _reent *r, int file, int ptr, int dir)
- {
- (void)r;
- (void)file;
- (void)ptr;
- (void)dir;
- return 0;
- }
- __attribute__((used))
- int _write_r(struct _reent *r, int file, char * ptr, int len)
- {
- (void)r;
- (void)file;
- (void)ptr;
- #if defined(STDOUT_SD)
- if (file != 1) {
- __errno_r(r) = EINVAL;
- return -1;
- }
- sdWrite(&STDOUT_SD, (uint8_t *)ptr, (size_t)len);
- #endif
- return len;
- }
- __attribute__((used))
- int _close_r(struct _reent *r, int file)
- {
- (void)r;
- (void)file;
- return 0;
- }
- __attribute__((used))
- caddr_t _sbrk_r(struct _reent *r, int incr)
- {
- #if CH_CFG_USE_MEMCORE
- void *p;
- chDbgCheck(incr >= 0);
- p = chCoreAlloc((size_t)incr);
- if (p == NULL) {
- __errno_r(r) = ENOMEM;
- return (caddr_t)-1;
- }
- return (caddr_t)p;
- #else
- (void)incr;
- __errno_r(r) = ENOMEM;
- return (caddr_t)-1;
- #endif
- }
- __attribute__((used))
- int _fstat_r(struct _reent *r, int file, struct stat * st)
- {
- (void)r;
- (void)file;
- memset(st, 0, sizeof(*st));
- st->st_mode = S_IFCHR;
- return 0;
- }
- __attribute__((used))
- int _isatty_r(struct _reent *r, int fd)
- {
- (void)r;
- (void)fd;
- return 1;
- }
|