1 /* -------------------------------- Arctic Core ------------------------------
2 * Arctic Core - the open source AUTOSAR platform http://arccore.com
4 * Copyright (C) 2009 ArcCore AB <contact@arccore.com>
6 * This source code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by the
8 * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * -------------------------------- Arctic Core ------------------------------*/
17 #include <sys/stat.h>
\r
18 #include <sys/types.h>
\r
21 //#include "clibsupport_gcc.h"
\r
27 #define getpid _getpid
30 #define isatty _isatty
37 // Operation on Winidea terminal buffer
\r
38 #define TWBUFF_SIZE 0x100
\r
39 #define TRBUFF_SIZE 0x100
\r
43 #define TWBUFF_LEN (TWBUFF_SIZE+TBUFF_PTR)
\r
44 #define TRBUFF_LEN (TRBUFF_SIZE+TBUFF_PTR)
\r
45 #define TWBUFF_TPTR (g_TWBuffer[TWBUFF_SIZE+0])
\r
46 #define TWBUFF_CPTR (g_TWBuffer[TWBUFF_SIZE+1])
\r
47 #define TWBUFF_INC(n) ((n + 1)&(TWBUFF_SIZE-1))
\r
48 #define TWBUFF_FULL() (TWBUFF_TPTR==((TWBUFF_CPTR-1)&(TWBUFF_SIZE-1)))
\r
50 #ifdef USE_WINIDEA_TERM
\r
51 static volatile unsigned char g_TWBuffer[TWBUFF_LEN] __attribute__ ((aligned (0x100))); // Transmit to WinIDEA terminal
\r
52 static volatile unsigned char g_TRBuffer[TRBUFF_LEN] __attribute__ ((aligned (0x100)));
\r
53 static volatile char g_TConn __attribute__ ((section (".winidea_port")));
\r
62 // This must be in un-cached space....
\r
63 static volatile char t32_outport __attribute__ ((section (".t32_outport")));
\r
66 int arc_putchar(int c) {
\r
73 void t32_writebyte(char c)
\r
75 /* T32 can hang here for several reasons;
76 * - term.view e:address.offset(v.address(t32_outport)) e:0
\r
79 while (t32_outport != 0 ) ; /* wait until port is free */
\r
80 t32_outport = c; /* send character */
\r
88 int close( int fd ) {
\r
93 char *__env[1] = { 0 };
\r
94 char **environ = __env;
\r
101 int execve(char *name, char **argv, char **env){
\r
114 #include <sys/stat.h>
\r
115 int fstat(int file, struct stat *st) {
\r
117 st->st_mode = S_IFCHR;
\r
121 /* Returns 1 if connected to a terminal. T32 can be a terminal
\r
124 int isatty( int fd )
\r
131 int fstat( int fd, struct stat *buf )
\r
133 buf->st_mode = S_IFCHR;
\r
134 buf->st_blksize = 0;
\r
140 /* reposition read/write file offset
\r
141 * We can't seek, return error.*/
\r
142 off_t lseek( int fd, off_t offset,int whence)
\r
149 return ((off_t)-1);
\r
152 int open(const char *name, int flags, int mode){
\r
157 if( strcmp(name,"ramlog") == 0 ) {
\r
158 return FILE_RAMLOG;
\r
164 int read( int fd, char *buf, int nbytes )
\r
169 #ifdef USE_WINIDEA_TERM
\r
170 (void)g_TRBuffer[0];
\r
173 /* Only support write for now, return 0 read */
\r
178 int write( int fd, char *buf, int nbytes)
\r
180 //(void)fd; // Normally 0- ?, 1-stdout, 2-stderr,
\r
184 #ifdef USE_WINIDEA_TERM
\r
187 unsigned char nCnt,nLen;
\r
188 for(nCnt=0; nCnt<nbytes; nCnt++)
\r
190 while(TWBUFF_FULL());
\r
192 g_TWBuffer[nLen]=buf[nCnt];
\r
193 nLen=TWBUFF_INC(nLen);
\r
199 #ifdef USE_T32_TERM
\r
200 for (int i = 0; i < nbytes; i++) {
\r
201 if (*(buf + i) == '\n') {
\r
202 t32_writebyte ('\r');
\r
203 // t32_writebyte ('\n');
\r
205 t32_writebyte (*(buf + i));
\r
208 #ifdef USE_ARM_ITM_TERM
209 for (int i = 0; i < nbytes; i++) {
210 ITM_SendChar(*(buf + i));
217 /* RAMLOG support */
\r
218 if(fd == FILE_RAMLOG) {
\r
219 for (int i = 0; i < nbytes; i++) {
\r
220 ramlog_chr (*(buf + i));
\r
228 /* If we use malloc and it runs out of memory it calls sbrk()
\r
232 extern char _end[];
\r
234 //static char *curbrk = _end;
\r
236 #define HEAPSIZE 16000
\r
237 unsigned char _heap[HEAPSIZE];
\r
239 caddr_t sbrk( int incr )
\r
241 static unsigned char *heap_end;
\r
242 unsigned char *prev_heap_end;
\r
245 if( heap_end == 0 )
\r
248 prev_heap_end = heap_end;
\r
250 if( heap_end + incr - _heap > HEAPSIZE ) {
\r
251 /* heap overflow - announce on stderr */
\r
252 write( 2, "Heap overflow!\n", 15 );
\r
258 return (caddr_t) prev_heap_end;
\r
261 void *sbrk(int inc )
\r
263 /* We use our own malloc */
\r
264 return (void *)(-1);
\r
268 int stat( const char *file, struct stat *st ) {
\r
269 //int stat(char *file, struct stat *st) {
\r
271 st->st_mode = S_IFCHR;
\r
283 int kill(int pid, int sig){
\r
291 /* Should not really be here, but .. */
\r
299 void __init( void )
\r
303 #if defined(CFG_ARM)
\r
304 void _exit( int status ) {
\r