-/* -------------------------------- Arctic Core ------------------------------
- * Arctic Core - the open source AUTOSAR platform http://arccore.com
- *
- * Copyright (C) 2009 ArcCore AB <contact@arccore.com>
- *
- * This source code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 as published by the
- * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
- *
- * This program 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 General Public License
- * for more details.
- * -------------------------------- Arctic Core ------------------------------*/
-
-\r
+/* -------------------------------- Arctic Core ------------------------------\r
+ * Arctic Core - the open source AUTOSAR platform http://arccore.com\r
+ *\r
+ * Copyright (C) 2009 ArcCore AB <contact@arccore.com>\r
+ *\r
+ * This source code is free software; you can redistribute it and/or modify it\r
+ * under the terms of the GNU General Public License version 2 as published by the\r
+ * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.\r
+ *\r
+ * This program is distributed in the hope that it will be useful, but\r
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License\r
+ * for more details.\r
+ * -------------------------------- Arctic Core ------------------------------*/\r
+\r
+\r
+#include <unistd.h>\r
#include <sys/stat.h>\r
#include <sys/types.h>\r
#include <errno.h>\r
-#include <stdlib.h>
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <stdio.h>\r
+#include <stddef.h>\r
+#include "Std_Types.h"\r
#include "Ramlog.h"\r
-//#include "clibsupport_gcc.h"\r
-
-#if defined(CFG_ARM)
-#define open _open
-#define exit _exit
-#define fstat _fstat
-#define getpid _getpid
-#define kill _kill
-#define close _close
-#define isatty _isatty
-#define sbrk _sbrk
-#define read _read
-#define write _write
-#define lseek _lseek
-#endif
+\r
+#if defined(CFG_ARM_CM3)\r
+#include "irq_types.h"\r
+#include "stm32f10x.h"\r
+#endif\r
+\r
+#ifdef USE_TTY_TCF_STREAMS\r
+#include "streams.h"\r
+#endif\r
+\r
+\r
+#if defined(CFG_ARM)\r
+#define open _open\r
+#define exit _exit\r
+#define fstat _fstat\r
+#define getpid _getpid\r
+#define kill _kill\r
+#define close _close\r
+#define isatty _isatty\r
+#define sbrk _sbrk\r
+#define read _read\r
+#define write _write\r
+#define lseek _lseek\r
+#endif\r
\r
// Operation on Winidea terminal buffer\r
+\r
+\r
#define TWBUFF_SIZE 0x100\r
#define TRBUFF_SIZE 0x100\r
\r
+\r
#define TBUFF_PTR 2\r
\r
#define TWBUFF_LEN (TWBUFF_SIZE+TBUFF_PTR)\r
#define TWBUFF_INC(n) ((n + 1)&(TWBUFF_SIZE-1))\r
#define TWBUFF_FULL() (TWBUFF_TPTR==((TWBUFF_CPTR-1)&(TWBUFF_SIZE-1)))\r
\r
-#ifdef USE_WINIDEA_TERM\r
+#ifdef USE_TTY_WINIDEA\r
+\r
+#if defined(MC912DG128A)\r
+static volatile unsigned char g_TWBuffer[TWBUFF_LEN];\r
+static volatile unsigned char g_TRBuffer[TRBUFF_LEN];\r
+volatile char g_TConn __attribute__ ((section (".winidea_port")));\r
+\r
+#else\r
static volatile unsigned char g_TWBuffer[TWBUFF_LEN] __attribute__ ((aligned (0x100))); // Transmit to WinIDEA terminal\r
static volatile unsigned char g_TRBuffer[TRBUFF_LEN] __attribute__ ((aligned (0x100)));\r
-static volatile char g_TConn __attribute__ ((section (".winidea_port")));\r
+volatile char g_TConn __attribute__ ((section (".winidea_port")));\r
+\r
+#endif\r
+\r
+#endif\r
+\r
+#ifdef USE_TTY_CODE_COMPOSER\r
+\r
+#define _DTOPEN (0xF0)\r
+#define _DTCLOSE (0xF1)\r
+#define _DTREAD (0xF2)\r
+#define _DTWRITE (0xF3)\r
+#define _DTLSEEK (0xF4)\r
+#define _DTUNLINK (0xF5)\r
+#define _DTGETENV (0xF6)\r
+#define _DTRENAME (0xF7)\r
+#define _DTGETTIME (0xF8)\r
+#define _DTGETCLK (0xF9)\r
+#define _DTSYNC (0xFF)\r
+\r
+#define LOADSHORT(x,y,z) { x[(z)] = (unsigned short) (y); \\r
+ x[(z)+1] = (unsigned short) (y) >> 8; }\r
+\r
+#define UNLOADSHORT(x,z) ((short) ( (short) x[(z)] + \\r
+ ((short) x[(z)+1] << 8)))\r
+\r
+#define PACKCHAR(val, base, byte) ( (base)[(byte)] = (val) )\r
+\r
+#define UNPACKCHAR(base, byte) ( (base)[byte] )\r
+\r
+\r
+static unsigned char parmbuf[8];\r
+#define CC_BUFSIZ 512\r
+#define CC_BUFFER_SIZE ((CC_BUFSIZ)+32)\r
+volatile unsigned int _CIOBUF_[CC_BUFFER_SIZE] __attribute__ ((section (".cio")));\r
+static unsigned char CIOTMPBUF[CC_BUFSIZ];\r
+static uint16 cio_tmp_buf_index = 0;\r
+\r
+/***************************************************************************/\r
+/* */\r
+/* WRITEMSG() - Sends the passed data and parameters on to the host. */\r
+/* */\r
+/***************************************************************************/\r
+void writemsg(unsigned char command,\r
+ register const unsigned char *parm,\r
+ register const char *data,\r
+ unsigned int length)\r
+{\r
+ volatile unsigned char *p = (volatile unsigned char *)(_CIOBUF_+1);\r
+ unsigned int i;\r
+\r
+ /***********************************************************************/\r
+ /* THE LENGTH IS WRITTEN AS A TARGET INT */\r
+ /***********************************************************************/\r
+ _CIOBUF_[0] = length;\r
+\r
+ /***********************************************************************/\r
+ /* THE COMMAND IS WRITTEN AS A TARGET BYTE */\r
+ /***********************************************************************/\r
+ *p++ = command;\r
+\r
+ /***********************************************************************/\r
+ /* PACK THE PARAMETERS AND DATA SO THE HOST READS IT AS BYTE STREAM */\r
+ /***********************************************************************/\r
+ for (i = 0; i < 8; i++) PACKCHAR(*parm++, p, i);\r
+ for (i = 0; i < length; i++) PACKCHAR(*data++, p, i+8);\r
+\r
+ /***********************************************************************/\r
+ /* THE BREAKPOINT THAT SIGNALS THE HOST TO DO DATA TRANSFER */\r
+ /***********************************************************************/\r
+ __asm(" .global C$$IO$$");\r
+ __asm("C$$IO$$: nop");\r
+}\r
+\r
+/***************************************************************************/\r
+/* */\r
+/* READMSG() - Reads the data and parameters passed from the host. */\r
+/* */\r
+/***************************************************************************/\r
+void readmsg(register unsigned char *parm,\r
+ register char *data)\r
+{\r
+ volatile unsigned char *p = (volatile unsigned char *)(_CIOBUF_+1);\r
+ unsigned int i;\r
+ unsigned int length;\r
+\r
+ /***********************************************************************/\r
+ /* THE LENGTH IS READ AS A TARGET INT */\r
+ /***********************************************************************/\r
+ length = _CIOBUF_[0];\r
+\r
+ /***********************************************************************/\r
+ /* UNPACK THE PARAMETERS AND DATA */\r
+ /***********************************************************************/\r
+ for (i = 0; i < 8; i++) *parm++ = UNPACKCHAR(p, i);\r
+ if (data != NULL)\r
+ for (i = 0; i < length; i++) *data++ = UNPACKCHAR(p, i+8);\r
+}\r
+\r
+/****************************************************************************/\r
+/* HOSTWRITE() - Pass the write command and its arguments to the host. */\r
+/****************************************************************************/\r
+int HOSTwrite(int dev_fd, const char *buf, unsigned count)\r
+{\r
+ int result;\r
+\r
+ // WARNING. Can only handle count == 1!\r
+ if (count != 1) _exit(1);\r
+\r
+ if (count > CC_BUFSIZ) count = CC_BUFSIZ;\r
+\r
+ if (cio_tmp_buf_index < CC_BUFSIZ) {\r
+ CIOTMPBUF[cio_tmp_buf_index++] = *buf;\r
+\r
+ if (*buf != 0xA) { // Only flush if newline\r
+ return 0;\r
+ }\r
+ }\r
+\r
+\r
+ LOADSHORT(parmbuf,dev_fd,0);\r
+ LOADSHORT(parmbuf,cio_tmp_buf_index,2);\r
+ writemsg(_DTWRITE,parmbuf,(char *)CIOTMPBUF,cio_tmp_buf_index);\r
+ readmsg(parmbuf,NULL);\r
+\r
+ result = UNLOADSHORT(parmbuf,0);\r
+\r
+ cio_tmp_buf_index = 0;\r
+\r
+ return result;\r
+}\r
+\r
+#endif\r
+\r
+#ifdef USE_TTY_TMS570_KEIL\r
+#include "GLCD.h"\r
+#endif\r
+\r
+#define FILE_RAMLOG 3\r
+\r
+/* Location MUST match NoICE configuration */\r
+#ifdef USE_TTY_NOICE\r
+static volatile char VUART_TX __attribute__ ((section (".noice_port")));\r
+static volatile char VUART_RX __attribute__ ((section (".noice_port")));\r
+volatile unsigned char START_VUART = 0;\r
#endif\r
-
-#define FILE_RAMLOG 3
\r
/*\r
* T32 stuff\r
*/\r
-
+\r
// This must be in un-cached space....\r
+#ifdef USE_TTY_T32\r
static volatile char t32_outport __attribute__ ((section (".t32_outport")));\r
\r
-\r
-int arc_putchar(int c) {\r
- char cc = c;\r
- write( 1,&cc,1);\r
-\r
- return 0;\r
-}\r
-\r
void t32_writebyte(char c)\r
-{
- /* T32 can hang here for several reasons;
+{\r
+ /* T32 can hang here for several reasons;\r
* - term.view e:address.offset(v.address(t32_outport)) e:0\r
*/\r
\r
while (t32_outport != 0 ) ; /* wait until port is free */\r
t32_outport = c; /* send character */\r
}\r
-\r
+#endif\r
/*\r
* clib support\r
*/\r
#undef errno\r
extern int errno;\r
\r
-int execve(char *name, char **argv, char **env){\r
- (void)name;\r
+\r
+int execve(const char *path, char * const argv[], char * const envp[] ) {\r
+//int execve(char *name, char **argv, char **env){\r
+ (void)path;\r
(void)argv;\r
- (void)env;\r
+ (void)envp;\r
errno=ENOMEM;\r
return -1;\r
}\r
\r
-int fork() {\r
+pid_t fork() {\r
errno=EAGAIN;\r
return -1;\r
}\r
(void)flags;\r
(void)mode;\r
\r
+#if defined(USE_RAMLOG)\r
if( strcmp(name,"ramlog") == 0 ) {\r
return FILE_RAMLOG;\r
}\r
+#endif\r
\r
return -1;\r
}\r
\r
-int read( int fd, char *buf, int nbytes )\r
+int read( int fd, void *buf, size_t nbytes )\r
{\r
(void)fd;\r
(void)buf;\r
(void)nbytes;\r
-#ifdef USE_WINIDEA_TERM\r
+#ifdef USE_TTY_WINIDEA\r
(void)g_TRBuffer[0];\r
#endif\r
\r
+#ifdef USE_TTY_NOICE\r
+ // Not tested at all\r
+ int retval;\r
+ while (VUART_RX != 0)\r
+ {\r
+ }\r
+\r
+ retval = VUART_RX;\r
+ VUART_RX = 0;\r
+#endif\r
+\r
/* Only support write for now, return 0 read */\r
return 0;\r
}\r
\r
\r
-int write( int fd, char *buf, int nbytes)\r
+int write( int fd, const void *_buf, size_t nbytes)\r
{\r
//(void)fd; // Normally 0- ?, 1-stdout, 2-stderr,\r
// Added 3-ramlog,\r
\r
- if( fd < 3 ) {\r
-#ifdef USE_WINIDEA_TERM\r
- if (g_TConn)\r
- {\r
- unsigned char nCnt,nLen;\r
- for(nCnt=0; nCnt<nbytes; nCnt++)\r
- {\r
- while(TWBUFF_FULL());\r
- nLen=TWBUFF_TPTR;\r
- g_TWBuffer[nLen]=buf[nCnt];\r
- nLen=TWBUFF_INC(nLen);\r
- TWBUFF_TPTR=nLen;\r
- }\r
- }\r
+\r
+ if( fd <= STDERR_FILENO ) {\r
+#ifdef USE_TTY_NOICE\r
+ char *buf1 = (char *)_buf;\r
+ if (START_VUART)\r
+ {\r
+ for (int i = 0; i < nbytes; i++) {\r
+ char c = buf1[i];\r
+ if (c == '\n')\r
+ {\r
+ while (VUART_TX != 0)\r
+ {\r
+ }\r
+\r
+ VUART_TX = '\r';\r
+ }\r
+\r
+ while (VUART_TX != 0)\r
+ {\r
+ }\r
+\r
+ VUART_TX = c;\r
+ }\r
+ }\r
+#endif\r
+\r
+#ifdef USE_TTY_WINIDEA\r
+ if (g_TConn)\r
+ {\r
+ char *buf = (char *)_buf;\r
+ unsigned char nCnt,nLen;\r
+ for(nCnt=0; nCnt<nbytes; nCnt++)\r
+ {\r
+ while(TWBUFF_FULL()) ;\r
+ nLen=TWBUFF_TPTR;\r
+ g_TWBuffer[nLen]=buf[nCnt];\r
+ nLen=TWBUFF_INC(nLen);\r
+ TWBUFF_TPTR=nLen;\r
+ }\r
+ }\r
#endif\r
\r
-#ifdef USE_T32_TERM\r
- for (int i = 0; i < nbytes; i++) {\r
- if (*(buf + i) == '\n') {\r
- t32_writebyte ('\r');\r
+#ifdef USE_TTY_T32\r
+ char *buf = (char *)_buf;\r
+ for (int i = 0; i < nbytes; i++) {\r
+ if (*(buf + i) == '\n') {\r
+ t32_writebyte ('\r');\r
// t32_writebyte ('\n');\r
- }\r
- t32_writebyte (*(buf + i));\r
- }\r
-#endif
-#ifdef USE_ARM_ITM_TERM
- for (int i = 0; i < nbytes; i++) {
- ITM_SendChar(*(buf + i));
- }
-#endif
-
+ }\r
+ t32_writebyte (*(buf + i));\r
+ }\r
+#endif\r
+\r
+#ifdef USE_TTY_ARM_ITM\r
+ char *buf = (char *)_buf;\r
+ for (int i = 0; i < nbytes; i++) {\r
+ ITM_SendChar(*(buf + i));\r
+ }\r
+#endif\r
+\r
+#ifdef USE_TTY_TCF_STREAMS\r
+ char *buf = (char *)_buf;\r
+ for (int i = 0; i < nbytes; i++) {\r
+ TCF_TTY_SendChar(*(buf + i));\r
+ }\r
+#endif\r
+\r
+#ifdef USE_TTY_CODE_COMPOSER\r
+ HOSTwrite(fd, _buf, nbytes);\r
+#endif\r
+\r
+#ifdef USE_TTY_TMS570_KEIL\r
+ for (int i = 0; i < nbytes; i++) {\r
+ GLCD_PrintChar((char *)(_buf + i));\r
+ }\r
+#endif\r
+\r
+#if defined(USE_RAMLOG)\r
+ {\r
+ char *buf = (char *)_buf;\r
+ for (int i = 0; i < nbytes; i++) {\r
+ ramlog_chr (*(buf + i));\r
+ }\r
+ }\r
+#endif\r
+\r
}\r
else\r
- {
-#if defined(USE_RAMLOG)
+ {\r
+#if defined(USE_RAMLOG)\r
/* RAMLOG support */\r
if(fd == FILE_RAMLOG) {\r
+ char *buf = (char *)_buf;\r
for (int i = 0; i < nbytes; i++) {\r
ramlog_chr (*(buf + i));\r
}\r
- }
+ }\r
#endif\r
}\r
\r
return (nbytes);\r
}\r
\r
+int arc_putchar(int fd, int c) {\r
+ char cc = c;\r
+ write( fd,&cc,1);\r
+\r
+ return 0;\r
+}\r
+\r
/* If we use malloc and it runs out of memory it calls sbrk()\r
*/\r
-#if 1\r
\r
+#if defined(CFG_PPC)\r
+\r
+/* linker symbols */\r
+extern char _heap_start[]; // incomplete array to ensure not placed in small-data\r
+extern char _heap_end[];\r
+\r
+void * sbrk( ptrdiff_t incr )\r
+{\r
+ char *prevEnd;\r
+ static char *nextAvailMemPtr = _heap_start;\r
+\r
+ if( nextAvailMemPtr + incr > _heap_end) {\r
+ write( 2, "Heap overflow!\n", 15 );\r
+ abort();\r
+ }\r
+ prevEnd = nextAvailMemPtr;\r
+ nextAvailMemPtr += incr;\r
+ return prevEnd;\r
+}\r
+#else\r
extern char _end[];\r
\r
//static char *curbrk = _end;\r
-
+\r
#ifndef HEAPSIZE\r
#define HEAPSIZE 16000\r
-#endif
-unsigned char _heap[HEAPSIZE];\r
+#endif\r
+\r
+/*\r
+ * The heap sadly have alignment that depends on the pagesize that\r
+ * you compile malloc newlib with. From what I can tell from the\r
+ * code that is a pagesize of 4096.\r
+ */\r
\r
-caddr_t sbrk( int incr )\r
+unsigned char _heap[HEAPSIZE] __attribute__((aligned (4)));\r
+//__attribute__((section(".heap")));\r
+\r
+void * sbrk( ptrdiff_t incr )\r
{\r
static unsigned char *heap_end;\r
unsigned char *prev_heap_end;\r
\r
/* initialize */\r
- if( heap_end == 0 )\r
+ if( heap_end == 0 ){\r
heap_end = _heap;\r
-\r
- prev_heap_end = heap_end;\r
+ }\r
+ prev_heap_end = heap_end;\r
\r
if( heap_end + incr - _heap > HEAPSIZE ) {\r
/* heap overflow - announce on stderr */\r
\r
return (caddr_t) prev_heap_end;\r
}\r
-#else\r
-void *sbrk(int inc )\r
-{\r
- /* We use our own malloc */\r
- return (void *)(-1);\r
-}\r
#endif\r
\r
int stat( const char *file, struct stat *st ) {\r
}\r
\r
\r
-int getpid() {\r
+pid_t getpid() {\r
return 1;\r
}\r
\r
}\r
\r
\r
+#if defined(__GNUC__)\r
void __init( void )\r
{\r
-\r
}\r
+#endif\r
+\r
#if defined(CFG_ARM)\r
void _exit( int status ) {\r
- while(1);\r
+#ifdef USE_TTY_CODE_COMPOSER\r
+ __asm(" .global C$$EXIT");\r
+ __asm("C$$EXIT: nop");\r
+#endif\r
+ while(1) ;\r
}\r
#endif\r
\r