]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blobdiff - rpp/src/rpp/sdr.c
Adapting code for Simulation. Bringing SCI getc and C getc a little bit closer.
[pes-rpp/rpp-lib.git] / rpp / src / rpp / sdr.c
index 8f89dceca21639d77cb36d4246574bf6aef39fe5..e8c56938af7909ebfde8bed2c120180134c69934 100644 (file)
 #include "rpp/rpp.h"
 
 #if rppCONFIG_INCLUDE_SDR == 1
-#include <stdio.h>  // vsnprintf() & (printf() & putchar())
+#include <stdio.h>  // vsnprintf()
 #include <ctype.h>  // isprint()
 #include <string.h> // strncmp()
 #include <stdarg.h> // va_start, va_end
 
 #if rppCONFIG_DRV == 1
 #include "drv/drv.h"
-#else
+#elif defined(FREERTOS_POSIX)
 #include <stdlib.h> // malloc()
-#define rpp_sci_putc putchar
-#define rpp_sci_printf printf
+#include "lib/os/rpp_support.c"
 #endif
 
 static const char* prompt  = "--> ";
@@ -123,19 +122,15 @@ void rpp_sdr_cmdproc(void *p)
     while(TRUE) {
 
         // Get one character from the user
-        #if rppCONFIG_DRV == 1
         if(rpp_sci_read_nb(1, &input) != SUCCESS) {
-        #else // FIXME: In POSIX simulation this line doesn't work.
-        if(rpp_sci_read_nb(1, &input) != SUCCESS) {
-        #endif
-            vTaskDelay(10);
+            vTaskDelay(100 / portTICK_RATE_MS);
             continue;
         }
 
         // Stop flushing if one character is received
         if(show_flushing) {
             rpp_sdr_show(FALSE);
-            vTaskDelay(10);
+            vTaskDelay(100 / portTICK_RATE_MS);
             rpp_sci_printf("%s", newline);
             rpp_sci_printf("%s", prompt);
             continue;
@@ -245,7 +240,7 @@ int8_t rpp_sdr_init()
     memory_size    = RPP_SDR_ADDR_END - RPP_SDR_ADDR_START + 1;
     memory_start   = (uint8_t*)RPP_SDR_ADDR_START;
     memory_end     = (uint8_t*)RPP_SDR_ADDR_END;
-    #else
+    #elif defined(FREERTOS_POSIX)
     memory_size    = 1024*1024; // Allocate 1MB for test
     memory_start   = (uint8_t*)malloc(memory_size);
     memory_end     = (uint8_t*)(memory_start + memory_size - 1);
@@ -323,6 +318,11 @@ int32_t rpp_sdr_printf(const char* format, ...)
         return FAILURE;
     }
 
+    // Don't even try if memory is full
+    if(memory_current == memory_end) {
+        return FAILURE;
+    }
+
     /// Format user string
     char str[MAX_BUFFER_LEN];
     int length = -1;