]> rtime.felk.cvut.cz Git - arc.git/blobdiff - common/newlib_port.c
Fixed warning in Code Composer terminal code.
[arc.git] / common / newlib_port.c
index 913e1077046c7fa29191a9b1bd0fd2ea052fcfaf..0a9ca794057f8ee7c5921bf5824e8bed11f3862e 100644 (file)
@@ -21,6 +21,7 @@
 #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
 \r
@@ -106,9 +107,11 @@ volatile char g_TConn __attribute__ ((section (".winidea_port")));
 \r
 \r
 static unsigned char parmbuf[8];\r
-#define BUFSIZ 512\r
-#define CC_BUFFER_SIZE ((BUFSIZ)+32)\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
@@ -178,15 +181,29 @@ int HOSTwrite(int dev_fd, const char *buf, unsigned count)
 {\r
    int result;\r
 \r
-   if (count > BUFSIZ) count = BUFSIZ;\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,count,2);\r
-   writemsg(_DTWRITE,parmbuf,(char *)buf,count);\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
@@ -251,7 +268,7 @@ int execve(const char *path, char * const argv[], char * const envp[] ) {
        return -1;\r
 }\r
 \r
-int fork() {\r
+pid_t fork() {\r
   errno=EAGAIN;\r
   return -1;\r
 }\r
@@ -371,7 +388,7 @@ int write(  int fd, const void *_buf, size_t nbytes)
                  unsigned char nCnt,nLen;\r
                  for(nCnt=0; nCnt<nbytes; nCnt++)\r
                        {\r
-                       while(TWBUFF_FULL());\r
+                       while(TWBUFF_FULL()) ;\r
                        nLen=TWBUFF_TPTR;\r
                        g_TWBuffer[nLen]=buf[nCnt];\r
                        nLen=TWBUFF_INC(nLen);\r
@@ -411,7 +428,7 @@ int write(  int fd, const void *_buf, size_t nbytes)
 \r
 #ifdef USE_TTY_TMS570_KEIL\r
        for (int i = 0; i < nbytes; i++) {\r
-               GLCD_PrintChar((_buf + i));\r
+               GLCD_PrintChar((char *)(_buf + i));\r
        }\r
 #endif\r
 \r
@@ -451,18 +468,18 @@ int arc_putchar(int fd, int c) {
 /* If we use malloc and it runs out of memory it calls sbrk()\r
  */\r
 \r
-#if defined(PPC)\r
+#if defined(CFG_PPC)\r
 \r
 /* linker symbols */\r
-extern char _heap_start;\r
-extern char _heap_end;         // same as _end?\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 = (char *)&_heap_start;\r
+    static char *nextAvailMemPtr = _heap_start;\r
 \r
-    if( nextAvailMemPtr + incr >  (char*)&_heap_end) {\r
+    if( nextAvailMemPtr + incr >  _heap_end) {\r
                write( 2, "Heap overflow!\n", 15 );\r
                abort();\r
        }\r
@@ -519,7 +536,7 @@ int stat( const char *file, struct stat *st ) {
 }\r
 \r
 \r
-int getpid() {\r
+pid_t getpid() {\r
   return 1;\r
 }\r
 \r
@@ -542,17 +559,19 @@ void _fini( void )
 }\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
 #ifdef USE_TTY_CODE_COMPOSER\r
        __asm("        .global C$$EXIT");\r
        __asm("C$$EXIT: nop");\r
 #endif\r
-       while(1);\r
+       while(1) ;\r
 }\r
 #endif\r
 \r