42 #include <sys/reent.h>
43 #include <sys/times.h>
60 char *__env[1] = { 0 };
61 char **environ = __env;
65 static lock_t sbrk_lock = 0;
68 #define DYNAMIC_MEMORY_ALIGN 4
87 _fork_r(
struct _reent *r) {
94 _execve_r(
struct _reent *r,
const char *name,
char *
const *argv,
char *
const *env) {
105 _kill_r(
struct _reent *r,
int pid,
int sig) {
122 _times_r(
struct _reent *r,
struct tms *buf)
132 _wait_r(
struct _reent *r,
int *status)
145 static int get_next_dev_fd(
void);
148 static int get_next_dev_fd(
void) {
151 if (devoptab_list[fd] ==
NULL) {
159 _open_r(
struct _reent *r,
const char *name,
int flags,
int mode) {
164 for (i = 0; i < devoptab_name_list.len; ++i) {
165 if (strcmp(devoptab_name_list.data[i].name, name) == 0) {
167 fd = get_next_dev_fd();
176 devoptab_list[fd] = devoptab_name_list.data[i].devoptab;
178 devoptab_list[fd]->open_r(r, name, flags, mode);
184 if (flags & O_APPEND) {
187 if (flags & O_RDWR) {
190 if (flags & O_RDONLY) {
193 if (flags & O_WRONLY) {
207 _close_r(
struct _reent *r,
int fd) {
216 if (fd >= MAX_OPEN_DEVICES) {
222 if (devoptab_list[fd] ==
NULL) {
227 if (devoptab_list[fd]->close_r ==
NULL) {
233 ret = devoptab_list[fd]->close_r(r, fd);
237 devoptab_list[fd] =
NULL;
243 _read_r(
struct _reent *r,
int fd,
void *ptr,
size_t len) {
251 if (fd >= MAX_OPEN_DEVICES) {
256 ret = cfs_read(fd, ptr, len);
262 if (devoptab_list[fd] ==
NULL) {
267 if (devoptab_list[fd]->read_r ==
NULL) {
273 return devoptab_list[fd]->read_r(r, fd, ptr, len);
277 _write_r(
struct _reent *r,
int fd,
const void *ptr,
size_t len) {
285 if (fd >= MAX_OPEN_DEVICES) {
290 ret = cfs_write(fd, (
const char *)ptr, len);
296 if (devoptab_list[fd] ==
NULL) {
301 if (devoptab_list[fd]->write_r ==
NULL) {
307 return devoptab_list[fd]->write_r(r, fd, ptr, len);
311 _lseek_r(
struct _reent *r,
int fd, off_t offset,
int whence) {
319 if (fd >= MAX_OPEN_DEVICES) {
332 if (devoptab_list[fd] ==
NULL) {
337 if (devoptab_list[fd]->lseek_r ==
NULL) {
343 return devoptab_list[fd]->lseek_r(r, fd, offset, whence);
347 _fstat_r(
struct _reent *r,
int fd,
struct stat *st) {
355 if (fd >= MAX_OPEN_DEVICES) {
357 st->st_mode = S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO;
364 if (devoptab_list[fd] !=
NULL) {
366 st->st_mode = devoptab_list[fd]->st_mode;
376 _isatty_r(
struct _reent *r,
int fd) {
384 if (fd >= MAX_OPEN_DEVICES) {
389 if (devoptab_list[fd] !=
NULL) {
391 if (devoptab_list[fd]->isatty == 0) {
394 return devoptab_list[fd]->isatty;
407 return _isatty_r (_REENT, fd);
415 _stat_r(
struct _reent *r,
const char *file,
struct stat *st) {
424 _link_r(
struct _reent *r,
const char *old,
const char *
new)
434 _unlink_r(
struct _reent *r,
const char *name)
448 extern int _heap_start;
450 extern int _heap_end;
452 static void* current_break = (
void *)(&_heap_start);
461 void*
_sbrk_r(
struct _reent *r, ptrdiff_t increment) {
466 if (increment % DYNAMIC_MEMORY_ALIGN)
468 increment += DYNAMIC_MEMORY_ALIGN - (increment % DYNAMIC_MEMORY_ALIGN);
470 if ((current_break + increment) < ((
void *)(&_heap_end)))
473 current_break += increment;
File-like I/O device operations table.
__STATIC_INLINE void NVIC_SystemReset(void)
System Reset.
int cfs_open(const char *name, int flags)
Open a file.
Device I/O mappings for the Mulle platform.
cfs_offset_t cfs_seek(int fd, cfs_offset_t offset, int whence)
Seek to a specified position in an open file.
#define CFS_WRITE
Specify that cfs_open() should open a file for writing.
#define NULL
The null pointer.
void * _sbrk_r(struct _reent *r, ptrdiff_t increment)
Move the program break.
#define CFS_READ
Specify that cfs_open() should open a file for reading.
K60 hardware register header wrapper.
#define DEBUGGER_BREAK(sig)
Make the CPU signal to the debugger and break execution by issuing a bkpt instruction.
void lock_release(lock_t *Lock_Variable)
Release a lock after having acquired it using lock_acquire or lock_try_acquire.
#define CFS_APPEND
Specify that cfs_open() should append written data to the file rather than overwriting it...
void lock_acquire(lock_t *Lock_Variable)
Blocking access to lock variable.
volatile uint8_t lock_t
Lock variable typedef.
Synchronization primitives for Cortex-M3/M4 processors.
int _fstat_r(struct _reent *r, int fd, struct stat *st)
#define MAX_OPEN_DEVICES
Maximum number of file descriptors allocated to hardware devices.
void cfs_close(int fd)
Close an open file.