]> rtime.felk.cvut.cz Git - arc.git/blobdiff - common/msl_port.c
Merge with mahi-application
[arc.git] / common / msl_port.c
index fdd8b9dc99ff18b7508388dbd5bb6ca25a487dd8..0c63525cb7ac2e7284ea9f0da34a4d8c7c926cfe 100644 (file)
@@ -9,6 +9,27 @@
 Methods called by MW MSL libraries to perform console IO:\r
 */\r
 \r
+#include "stddef.h"\r
+\r
+#ifdef USE_TTY_WINIDEA\r
+\r
+#define TWBUFF_SIZE 0x100\r
+#define TRBUFF_SIZE 0x100\r
+#define TBUFF_PTR 2\r
+\r
+#define TWBUFF_LEN             (TWBUFF_SIZE+TBUFF_PTR)\r
+#define TRBUFF_LEN             (TRBUFF_SIZE+TBUFF_PTR)\r
+#define TWBUFF_TPTR            (g_TWBuffer[TWBUFF_SIZE+0])\r
+#define TWBUFF_CPTR            (g_TWBuffer[TWBUFF_SIZE+1])\r
+#define TWBUFF_INC(n)  ((n + 1)&(TWBUFF_SIZE-1))\r
+#define TWBUFF_FULL()  (TWBUFF_TPTR==((TWBUFF_CPTR-1)&(TWBUFF_SIZE-1)))\r
+\r
+volatile char g_TConn;\r
+volatile unsigned char g_TWBuffer[TWBUFF_LEN] __attribute__ ((aligned (0x100))); // Transmit to WinIDEA terminal\r
+volatile unsigned char g_TRBuffer[TRBUFF_LEN] __attribute__ ((aligned (0x100)));\r
+\r
+\r
+#endif\r
 \r
 int  InitializeUART(void)\r
 {\r
@@ -17,16 +38,51 @@ int  InitializeUART(void)
 \r
 int ReadUARTN( char* buf, int cnt )\r
 {\r
+#ifdef USE_TTY_WINIDEA\r
+       (void)g_TRBuffer[0];\r
+#endif\r
        (void)buf;\r
        (void)cnt;\r
-       return 0;\r
+       return 0; // No error\r
+}\r
+\r
+int ReadUART1(char* c) {\r
+       return ReadUARTN( c, 1 );\r
 }\r
 \r
 int WriteUARTN( char* buf, int cnt )\r
 {\r
+#ifdef USE_TTY_WINIDEA\r
+       if (g_TConn)\r
+       {\r
+               unsigned char nCnt,nLen;\r
+               for(nCnt = 0; nCnt < cnt; 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
+#if defined(USE_RAMLOG)\r
+               {\r
+                       char *pbuf = buf;\r
+                       for (int i = 0; i < cnt; i++) {\r
+                               ramlog_chr (*(pbuf + i));\r
+                       }\r
+               }\r
+#endif\r
+\r
        (void)buf;\r
        (void)cnt;\r
-       return 0;\r
+       \r
+       return 0; // No error\r
+}\r
+\r
+int WriteUART1(char c) {\r
+       return WriteUARTN( &c, 1 );\r
 }\r
 \r
 \r
@@ -55,9 +111,57 @@ void exit(int exit ) {
 }\r
 \r
 \r
-void *sbrk(int inc )\r
+\r
+extern char _end[];\r
+\r
+//static char *curbrk = _end;\r
+#if 0\r
+\r
+#ifndef HEAPSIZE\r
+#define HEAPSIZE 16000\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
+unsigned char _heap[HEAPSIZE] __attribute__((aligned (4)));\r
+//__attribute__((section(".heap")));\r
+\r
+#else\r
+\r
+/* The linker will allocate a heap for us\r
+ * Importing variables set by the linker is never pretty... */\r
+extern unsigned char _heap_addr[];\r
+extern void _heap_size(void);\r
+\r
+const ptrdiff_t _heap_size_proper = (const ptrdiff_t) &_heap_size; // Casting this to get a proper type\r
+\r
+#define HEAPSIZE       _heap_size_proper\r
+#define _heap          _heap_addr\r
+\r
+#endif\r
+\r
+\r
+void * sbrk( ptrdiff_t incr )\r
 {\r
        (void)inc;\r
-       /* We use our own malloc */\r
-       return (void *)(-1);\r
+    unsigned char *prev_heap_end;\r
+\r
+/* initialize */\r
+    if( heap_end == 0 ){\r
+       heap_end = _heap;\r
+    }\r
+    prev_heap_end = heap_end;\r
+\r
+       if( heap_end + incr - _heap > HEAPSIZE ) {\r
+       /* heap overflow - announce on stderr */\r
+               abort();\r
+       }\r
+\r
+   heap_end += incr;\r
+\r
+   return prev_heap_end;\r
 }\r