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 ------------------------------*/
18 #include <sys/types.h>
23 #include "Std_Types.h"
25 //#include "clibsupport_gcc.h"
31 #define getpid _getpid
34 #define isatty _isatty
41 // Operation on Winidea terminal buffer
42 #define TWBUFF_SIZE 0x100
43 #define TRBUFF_SIZE 0x100
47 #define TWBUFF_LEN (TWBUFF_SIZE+TBUFF_PTR)
48 #define TRBUFF_LEN (TRBUFF_SIZE+TBUFF_PTR)
49 #define TWBUFF_TPTR (g_TWBuffer[TWBUFF_SIZE+0])
50 #define TWBUFF_CPTR (g_TWBuffer[TWBUFF_SIZE+1])
51 #define TWBUFF_INC(n) ((n + 1)&(TWBUFF_SIZE-1))
52 #define TWBUFF_FULL() (TWBUFF_TPTR==((TWBUFF_CPTR-1)&(TWBUFF_SIZE-1)))
54 #ifdef USE_WINIDEA_TERM
55 static volatile unsigned char g_TWBuffer[TWBUFF_LEN] __attribute__ ((aligned (0x100))); // Transmit to WinIDEA terminal
56 static volatile unsigned char g_TRBuffer[TRBUFF_LEN] __attribute__ ((aligned (0x100)));
57 static volatile char g_TConn __attribute__ ((section (".winidea_port")));
66 // This must be in un-cached space....
67 static volatile char t32_outport __attribute__ ((section (".t32_outport")));
72 void t32_writebyte(char c)
74 /* T32 can hang here for several reasons;
75 * - term.view e:address.offset(v.address(t32_outport)) e:0
78 while (t32_outport != 0 ) ; /* wait until port is free */
79 t32_outport = c; /* send character */
92 char *__env[1] = { 0 };
93 char **environ = __env;
100 int execve(char *name, char **argv, char **env){
113 #include <sys/stat.h>
114 int fstat(int file, struct stat *st) {
116 st->st_mode = S_IFCHR;
120 /* Returns 1 if connected to a terminal. T32 can be a terminal
130 int fstat( int fd, struct stat *buf )
132 buf->st_mode = S_IFCHR;
139 /* reposition read/write file offset
140 * We can't seek, return error.*/
141 off_t lseek( int fd, off_t offset,int whence)
151 int open(const char *name, int flags, int mode){
156 if( strcmp(name,"ramlog") == 0 ) {
163 int read( int fd, char *buf, int nbytes )
168 #ifdef USE_WINIDEA_TERM
172 /* Only support write for now, return 0 read */
177 int write( int fd, char *buf, int nbytes)
179 //(void)fd; // Normally 0- ?, 1-stdout, 2-stderr,
183 #ifdef USE_WINIDEA_TERM
186 unsigned char nCnt,nLen;
187 for(nCnt=0; nCnt<nbytes; nCnt++)
189 while(TWBUFF_FULL());
191 g_TWBuffer[nLen]=buf[nCnt];
192 nLen=TWBUFF_INC(nLen);
199 for (int i = 0; i < nbytes; i++) {
200 if (*(buf + i) == '\n') {
201 t32_writebyte ('\r');
202 // t32_writebyte ('\n');
204 t32_writebyte (*(buf + i));
207 #ifdef USE_ARM_ITM_TERM
208 for (int i = 0; i < nbytes; i++) {
209 ITM_SendChar(*(buf + i));
216 #if defined(USE_RAMLOG)
218 if(fd == FILE_RAMLOG) {
219 for (int i = 0; i < nbytes; i++) {
220 ramlog_chr (*(buf + i));
229 int arc_putchar(int c) {
236 /* If we use malloc and it runs out of memory it calls sbrk()
242 //static char *curbrk = _end;
245 #define HEAPSIZE 16000
249 * The heap sadly have alignment that depends on the pagesize that
250 * you compile malloc newlib with. From what I can tell from the
251 * code that is a pagesize of 4096.
254 unsigned char _heap[HEAPSIZE] __attribute__((aligned (4)));
255 //__attribute__((section(".heap")));
257 caddr_t sbrk( int incr )
259 static unsigned char *heap_end;
260 unsigned char *prev_heap_end;
266 prev_heap_end = heap_end;
268 if( heap_end + incr - _heap > HEAPSIZE ) {
269 /* heap overflow - announce on stderr */
270 write( 2, "Heap overflow!\n", 15 );
276 return (caddr_t) prev_heap_end;
281 /* We use our own malloc */
286 int stat( const char *file, struct stat *st ) {
287 //int stat(char *file, struct stat *st) {
289 st->st_mode = S_IFCHR;
301 int kill(int pid, int sig){
309 /* Should not really be here, but .. */
322 void _exit( int status ) {