]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/commitdiff
Adapting code for Simulation. Bringing SCI getc and C getc a little bit closer.
authorCarlos Jenkins <carlos@jenkins.co.cr>
Thu, 6 Jun 2013 15:37:12 +0000 (17:37 +0200)
committerCarlos Jenkins <carlos@jenkins.co.cr>
Thu, 6 Jun 2013 15:37:12 +0000 (17:37 +0200)
apps/echo/src/main.c
apps/sdr-log/.cproject
apps/sdr-log/.project
apps/sdr-log/src/main.c
os/6.0.4_posix/include/os/os.h
rpp/include/rpp/sci.h
rpp/src/rpp/sci.c
rpp/src/rpp/sdr.c

index 83c3c84b8ea8530f8426576b2dc76d74c7f09194..7914dfc96025f362de1592bc54d98372bac09cf6 100644 (file)
@@ -18,13 +18,19 @@ void echo(void *p)
     rpp_sci_printf((const char*)"================================\r\n");
     rpp_sci_printf((const char*)"--> ");
 
+    int16_t raw = 0;
     uint8_t input = 0;
     uint8_t buff_index = 0;
     boolean_t flush = FALSE;
     while(TRUE) {
 
         // Get one character from the user
-        input = rpp_sci_getc();
+        raw = rpp_sci_getc();
+        if(raw == FAILURE) {
+            vTaskDelay(100 / portTICK_RATE_MS);
+            continue;
+        }
+        input = (uint8_t)raw;
 
         // Backspace and Delete
         if(input == 8 || input == 127) {
index 83dea347076560ea1cddc0f47bc9397241116bf1..a1528e9bb68c1274c185828001d8e7db19732e1c 100644 (file)
                                                        </tool>
                                                </toolChain>
                                        </folderInfo>
+                                       <fileInfo id="cdt.managedbuild.toolchain.gnu.base.520906199.1983895916" name="rpp_posix.c" rcbsApplicability="disable" resourcePath="lib/rpp/rpp_posix.c" toolsToInvoke="cdt.managedbuild.tool.gnu.c.compiler.base.814685508.1381444926">
+                                               <tool id="cdt.managedbuild.tool.gnu.c.compiler.base.814685508.1381444926" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.base.814685508"/>
+                                       </fileInfo>
                                        <sourceEntries>
                                                <entry excluding="src|lib" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
-                                               <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="lib"/>
+                                               <entry excluding="rpp/rpp_posix.c|os/rpp_support.c" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="lib"/>
                                                <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
                                        </sourceEntries>
                                </configuration>
index 07689d7ec199dd7218413e202640b14d974d6104..e0b5c2120620fa6fe3bb3c69a7e3253d48d10210 100644 (file)
                        <type>1</type>
                        <locationURI>PARENT-2-PROJECT_LOC/rpp/src/rpp/rpp.c</locationURI>
                </link>
+               <link>
+                       <name>lib/rpp/rpp_posix.c</name>
+                       <type>1</type>
+                       <locationURI>PARENT-2-PROJECT_LOC/os/6.0.4_posix/src/rpp/rpp_posix.c</locationURI>
+               </link>
                <link>
                        <name>lib/rpp/sci.c</name>
                        <type>1</type>
index 80724ec8d39a8dbc46d62f92e8a9bdafaf874296..c3614ab81b769c670584633fef0236ac32f99b59 100644 (file)
@@ -1,9 +1,8 @@
 #include "rpp/rpp.h"
 #include <stdlib.h>
 
-#if rppCONFIG_DRV == 0
-#include <stdio.h> // printf()
-#define rpp_sci_printf printf
+#if defined(FREERTOS_POSIX)
+#include "lib/rpp/rpp_posix.c"
 #endif
 
 #define FREQ_MILLIS     3000
index b4976f054290a0e642648e588d04c95566c17be4..8f4810f57abeb900ee67535acf37adb29931a1e0 100644 (file)
@@ -15,6 +15,8 @@
 #define FREERTOS_VERSION_NUMBER_MINOR 0
 #define FREERTOS_VERSION_NUMBER_REV   4
 
+#define FREERTOS_POSIX                1
+
 #include "os/FreeRTOS.h"
 #include "os/task.h"
 #include "os/semphr.h"
index 6f8b06e08a06b68b04245a48648ab3a5ec973982..c1be949d83df7f1aca36221975b3dd330dca6025 100644 (file)
@@ -192,9 +192,14 @@ int8_t rpp_sci_putc(uint8_t byte);
  * This function will wait until a byte is available in the SCI input buffer if
  * it is empty.
  *
- * @return The byte read from the SCI input buffer.
+ * @note The byte is promoted to an int16_t in order to accommodate for EOF/-1
+ * if an error occurs. This is in order to conform with C getc, but should never
+ * happen in current implementation.
+ *
+ * @return [0-255] The byte read from the SCI input buffer.
+ *          [ < 0 ] If and error occurred.
  */
-uint8_t rpp_sci_getc();
+int16_t rpp_sci_getc();
 
 
 
index e8caec94ee41c746c2948d429290333de4dadf6a..346cf98b85cf599ffc4880412f6a3da68bf9398b 100644 (file)
@@ -218,15 +218,17 @@ int8_t rpp_sci_putc(uint8_t byte)
 }
 
 
-uint8_t rpp_sci_getc()
+int16_t rpp_sci_getc()
 {
     uint8_t result = 0;
 
     #if rppCONFIG_DRV == 1
-    drv_sci_receive(1, &result, portMAX_DELAY);
+    if(drv_sci_receive(1, &result, portMAX_DELAY) == FAILURE) {
+        return FAILURE;
+    }
     #endif
 
-    return result;
+    return (int16_t)result;
 }
 
 
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;