2017-04-13 13:24:16 -07:00
|
|
|
/*
|
|
|
|
Copyright (c) 2011 Arduino. All right reserved.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file syscalls_sam3.c
|
|
|
|
*
|
|
|
|
* Implementation of newlib syscall.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------
|
|
|
|
* Headers
|
|
|
|
*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "syscalls.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#if defined ( __GNUC__ ) /* GCC CS3 */
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "Arduino.h"
|
|
|
|
|
|
|
|
// Helper macro to mark unused parameters and prevent compiler warnings.
|
|
|
|
// Appends _UNUSED to the variable name to prevent accidentally using them.
|
|
|
|
#ifdef __GNUC__
|
2017-05-22 11:54:41 -07:00
|
|
|
#define UNUSED_PARAM(x) x ## _UNUSED __attribute__((__unused__))
|
2017-04-13 13:24:16 -07:00
|
|
|
#else
|
2017-05-22 11:54:41 -07:00
|
|
|
#define UNUSED_PARAM(x) x ## _UNUSED
|
2017-04-13 13:24:16 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------
|
|
|
|
* Exported variables
|
|
|
|
*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#undef errno
|
|
|
|
extern int errno ;
|
|
|
|
extern int _end ;
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------
|
|
|
|
* Exported functions
|
|
|
|
*----------------------------------------------------------------------------*/
|
|
|
|
extern void _exit( int status ) ;
|
|
|
|
extern void _kill( int pid, int sig ) ;
|
|
|
|
extern int _getpid ( void ) ;
|
|
|
|
|
2017-05-13 05:41:58 -07:00
|
|
|
static unsigned char *heap_brk = NULL;
|
|
|
|
static unsigned char *heap_end = NULL;
|
|
|
|
|
2017-05-22 11:54:41 -07:00
|
|
|
void setHeap(unsigned char *start, unsigned char *end) {
|
2017-05-13 05:41:58 -07:00
|
|
|
heap_brk = start;
|
|
|
|
heap_end = end;
|
|
|
|
}
|
|
|
|
|
2017-04-13 13:24:16 -07:00
|
|
|
extern caddr_t _sbrk ( int incr )
|
|
|
|
{
|
2017-05-22 11:54:41 -07:00
|
|
|
caddr_t prev_heap;
|
2017-04-13 13:24:16 -07:00
|
|
|
|
2017-05-13 05:41:58 -07:00
|
|
|
if ( heap_brk == NULL )
|
2017-04-13 13:24:16 -07:00
|
|
|
{
|
2017-05-13 05:41:58 -07:00
|
|
|
heap_brk = (unsigned char *)&_end ;
|
2017-04-13 13:24:16 -07:00
|
|
|
}
|
2017-05-22 11:54:41 -07:00
|
|
|
prev_heap = (caddr_t)heap_brk;
|
2017-04-13 13:24:16 -07:00
|
|
|
|
2017-05-13 23:10:41 -07:00
|
|
|
if (heap_end != NULL && (heap_brk + incr) > heap_end) {
|
2017-05-13 05:41:58 -07:00
|
|
|
return (caddr_t)-1;
|
|
|
|
}
|
2017-05-13 23:10:41 -07:00
|
|
|
|
|
|
|
heap_brk += incr ;
|
2017-04-13 13:24:16 -07:00
|
|
|
|
2017-05-13 05:41:58 -07:00
|
|
|
return prev_heap ;
|
2017-04-13 13:24:16 -07:00
|
|
|
}
|
|
|
|
|
2017-05-22 11:54:41 -07:00
|
|
|
extern int link( UNUSED_PARAM(char *cOld), UNUSED_PARAM(char *cNew) )
|
2017-04-13 13:24:16 -07:00
|
|
|
{
|
|
|
|
return -1 ;
|
|
|
|
}
|
|
|
|
|
2017-05-22 11:54:41 -07:00
|
|
|
extern int _close( UNUSED_PARAM(int file) )
|
2017-04-13 13:24:16 -07:00
|
|
|
{
|
|
|
|
return -1 ;
|
|
|
|
}
|
|
|
|
|
2017-05-22 11:54:41 -07:00
|
|
|
extern int _fstat( UNUSED_PARAM(int file), struct stat *st )
|
2017-04-13 13:24:16 -07:00
|
|
|
{
|
|
|
|
st->st_mode = S_IFCHR ;
|
|
|
|
|
|
|
|
return 0 ;
|
|
|
|
}
|
|
|
|
|
2017-05-22 11:54:41 -07:00
|
|
|
extern int _isatty( UNUSED_PARAM(int file) )
|
2017-04-13 13:24:16 -07:00
|
|
|
{
|
|
|
|
return 1 ;
|
|
|
|
}
|
|
|
|
|
2017-05-22 11:54:41 -07:00
|
|
|
extern int _lseek( UNUSED_PARAM(int file), UNUSED_PARAM(int ptr), UNUSED_PARAM(int dir) )
|
2017-04-13 13:24:16 -07:00
|
|
|
{
|
|
|
|
return 0 ;
|
|
|
|
}
|
|
|
|
|
2017-05-22 11:54:41 -07:00
|
|
|
extern int _read(UNUSED_PARAM(int file), UNUSED_PARAM(char *ptr), UNUSED_PARAM(int len) )
|
2017-04-13 13:24:16 -07:00
|
|
|
{
|
|
|
|
return 0 ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern void _exit( int status )
|
|
|
|
{
|
|
|
|
printf( "Exiting with status %d.\n", status ) ;
|
|
|
|
|
|
|
|
for ( ; ; ) ;
|
|
|
|
}
|
|
|
|
|
2017-05-22 11:54:41 -07:00
|
|
|
extern void _kill( UNUSED_PARAM(int pid), UNUSED_PARAM(int sig) )
|
2017-04-13 13:24:16 -07:00
|
|
|
{
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern int _getpid ( void )
|
|
|
|
{
|
|
|
|
return -1 ;
|
|
|
|
}
|