]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/commitdiff
CMDPROC modified for new IO functions and library
authorMichal Horn <michal@michal-laptop.(none)>
Sun, 16 Jun 2013 22:44:41 +0000 (00:44 +0200)
committerMichal Horn <michal@michal-laptop.(none)>
Sun, 16 Jun 2013 22:44:41 +0000 (00:44 +0200)
rpp/lib/cmdproc/include/cmdproc_freertos_tms570.h
rpp/lib/cmdproc/include/cmdproc_io_tisci.h
rpp/lib/cmdproc/include/cmdproc_utils.h
rpp/lib/cmdproc/include/commands/cmd_emac.h
rpp/lib/cmdproc/src/cmdproc.c
rpp/lib/cmdproc/src/cmdproc_freertos_tms570.c
rpp/lib/cmdproc/src/cmdproc_io_tisci.c
rpp/lib/cmdproc/src/cmdproc_run.c
rpp/lib/cmdproc/src/cmdproc_utils.c

index 308b0027aa7bf48617ef109a8ae0d6f6f9c3cfe5..6292d85b35a741a755f85115d3cda4346dfd9b63 100644 (file)
 
 /* Include files */
 #include "string.h"
+#include "os/FreeRTOS.h"
 #include "cmdproc.h"
 #include "cmdproc_io_tisci.h"
-#include "sys/ti_drv_sci.h"
-#include "os/os_task.h"
-#include "os/os_portmacro.h"
+#include "os/task.h"
+#include "os/portmacro.h"
 
 
 /**    Initializes CmdProc library, IO stack and creates task for FreeRTOS.
index 92727423bef32a97a960e791f93e2606489bca38..6eee8c1d6bae08e1e227c2738207c621f1d810b7 100644 (file)
 
 /* Include files */
 #include "cmdproc.h"
-#include "os/FreeRTOS.h"
-#include "os/os_queue.h"
-#include "os/os_semphr.h"
-#include "os/os_task.h"
-#include "sys/ti_drv_sci.h"
-
-/** Maximal length of buffers */
-#define MAX_BUFFER_LEN 128
-/**    Error code when accessing to not initialized buffer     */
-#define errBUFFER_NOT_INITIALIZED -6
-/** Flag for transfer in progress */
-#define BUF_TRANSFER_IN_PROGRESS 1
-
-/** Struct to represent IO buffer for TI SCI */
-typedef struct {
-       xQueueHandle buf;       /**< Ring buffer (FreeRTOS queue) */
-       xSemaphoreHandle mutex; /**< Mutex to allow speaking only one device at time */
-       uint8_t flags;  /**< Flags */
-} tBuffer;
-
-
-/**    Initialize IO Buffers
-*/
-void initIoBuffer();
-
-/**    Print string into an output buffer in a not blocking way.
- * @param[in]  string  String to be printed into output buffer
- * @return     pdPASS when OK; errQUEUE_FULL when buffer is full, errBUFFER_NOT_INITIALIZED when initIoBuffer function was not called before
- */
-portBASE_TYPE print(const uint8_t * string);
-
-/**    Read character from an input buffer in a blocking way
- * @param[out] ch      Character read from buffer
- * @return     pdPASS when OK; errQUEUE_EMPTY when buffer is empty and ran out of block time, errBUFFER_NOT_INITIALIZED when initIoBuffer function was not called before.
- */
-portBASE_TYPE read(uint8_t * ch);
-
-/**    Read character from a buffer. Let it be blocking or nonblocking in case the buffer is empty.
- * @param[in]  buffer  Pointer to buffer from which will be read.
- * @param[out] ch      Character read from buffer
- * @return     pdPASS when OK; errQUEUE_EMPTY when buffer is empty and ran out of block time, errBUFFER_NOT_INITIALIZED when initIoBuffer function was not called before.
- */
-portBASE_TYPE genericRead(tBuffer* buffer, uint8_t * ch);
-
-/**    Print string to a buffer. Let it be blocking or nonblocking in case the buffer is full.
- * @param[in]  buffer  Pointer to buffer from which will be read.
- * @param[in]  string  String to be printed into buffer
- * @return     pdPASS when OK; errQUEUE_FULL when buffer is full and ran out of block time, errBUFFER_NOT_INITIALIZED when initIoBuffer function was not called before.
- */
-portBASE_TYPE genericPrint(tBuffer* buffer, const uint8_t * string);
-
-/**    Makes input buffer empty
- * @return pdPass when success, errBUFFER_NOT_INITIALIZED when initIoBuffer function was not called before
- */
-portBASE_TYPE clearInputBuffer();
-
-/**    Makes output buffer empty
- * @return pdPass when success, errBUFFER_NOT_INITIALIZED when initIoBuffer function was not called before
- */
-portBASE_TYPE clearOutputBuffer();
-
-/**    Makes buffer empty
- * @param[in]  buffer  Buffer to be cleared
- * @return pdPass when success, errBUFFER_NOT_INITIALIZED when initIoBuffer function was not called before
- */
-portBASE_TYPE clearBuffer(tBuffer * buffer);
 
 /**    Puts character into output buffer. Is blocking, when buffer is full.
  *     @param[in]      cmd_io  IO stack pointer
index 942499c00f2506e417f9d726b8edaabcefcf8826..eb84bc3218421c1d874c28a84bfca4ae5316723b 100644 (file)
@@ -1,7 +1,8 @@
 #ifndef _UTILS_DEF_H_
 #define _UTILS_DEF_H_
 
-#include <sys_common.h>
+#include "types.h"
+
 /*masked fields macros*/
 #define __val2mfld(mask,val) (((mask)&~((mask)<<1))*(val)&(mask))
 #define __mfld2val(mask,val) (((val)&(mask))/((mask)&~((mask)<<1)))
index ecd94e3851b975f62af12bc6e9272a2d61178fd1..12cd1c421ba99ed20148d367581992ae4f117c0d 100644 (file)
@@ -2,7 +2,7 @@
 #define _EMAC_TEST_H_
 
 #include "cmdproc.h"
-#include "sys_common.h"
+#include "types.h"
 
 /* ************************************************* */
 /*   Emac frame buffer related stuff                 */
index c277d80839b6a2beba32e5b59712e10ce4c995de..999adc927a19f39b66aeb84c045baa574a796add 100644 (file)
@@ -22,7 +22,6 @@
 #include <ctype.h>
 #include <string.h>
 #include <stdlib.h>
-#include "i2str.h"
 #include "cmdproc.h"
 #include "cmdproc_priv.h"
 
index 3ccbe2fda7d83d4664f26c23a2fc510b871c54e1..8b0ea3d67fa2dc2428be9f7c3783d0b08721ef4a 100644 (file)
@@ -8,6 +8,7 @@
 
 /* Include files */
 #include "cmdproc_freertos_tms570.h"
+#include "rpp/sci.h"
 
 /** cmdProc task handler */
 xTaskHandle processCmdHandler;
@@ -20,7 +21,6 @@ extern cmd_io_t cmd_io_std_line;
 
 
 void initCmdProc(unsigned portBASE_TYPE priority, uint8_t * introText, uint8_t * promptText) {
-       initIoBuffer();
        prompt = NULL;
        if (promptText != NULL) {
                prompt = (uint8_t *)pvPortMalloc(strlen((char*)promptText));
@@ -28,28 +28,22 @@ void initCmdProc(unsigned portBASE_TYPE priority, uint8_t * introText, uint8_t *
        }
        int taskRetVal;
        if ((taskRetVal = xTaskCreate(processCmd, (const signed char *)"processCmd", 300, NULL, priority, processCmdHandler)) != pdPASS) {
-               uint8_t taskCreateError[]="FreeRTOS: Creating task processCmd failed. Error code: ";
-               print(taskCreateError);
-               char buf[20];
-               i2str(buf, taskRetVal, 1, 0);
-               print((uint8_t *)buf);
-               print((uint8_t *)"\r\n");
+               rpp_sci_printf("FreeRTOS: Creating task processCmd failed. Error code: %d", taskRetVal);
                /* An error occurred, block program */
                while(1)
                        ;
        }
        if (introText != NULL)
-               print((uint8_t *)introText);
+               rpp_sci_printf("%s", introText);
        if (prompt != NULL)
-               print((uint8_t *)prompt);
-       sciReceive(sciREG, 1, NULL);
+               rpp_sci_printf("%s", prompt);
 }
 
 void processCmd(void *pvParameters ) {
        for (;;) {
                cmd_processor_run(&cmd_io_std_line, cmd_list_main);
                if (prompt != NULL)
-                       print((uint8_t *)prompt);
+                       rpp_sci_printf("%s", prompt);
        }
 }
 
index 702518f913c5ded45931037a3803106f011ff0ed..0efac348ba8cb3dd8b5acd49deb1af119b764520 100644 (file)
@@ -8,99 +8,30 @@
 
 /* Include files */
 #include "cmdproc_io_tisci.h"
-
-/** Buffer used for sending to sci */
-tBuffer outBuffer;
-/** Buffer used for receiving from sci */
-tBuffer inBuffer;
-
-void initIoBuffer() {
-       outBuffer.buf = xQueueCreate(MAX_BUFFER_LEN, sizeof(uint8_t));
-       outBuffer.mutex = xSemaphoreCreateMutex();
-       outBuffer.flags = 0;
-       inBuffer.buf = xQueueCreate(MAX_BUFFER_LEN, sizeof(uint8_t));
-       inBuffer.mutex = xSemaphoreCreateMutex();
-       outBuffer.flags = 0;
-}
-portBASE_TYPE print(const uint8_t * string) {
-       return genericPrint(&outBuffer, string);
-}
-portBASE_TYPE read(uint8_t * ch) {
-       return genericRead(&inBuffer, ch);
-}
-portBASE_TYPE genericRead(tBuffer* buffer, uint8_t * ch) {
-       if (buffer->buf == NULL) return errBUFFER_NOT_INITIALIZED;
-       portBASE_TYPE ret;
-       ret = xQueueReceive(buffer->buf, ch, portMAX_DELAY);
-       return ret;
-}
-portBASE_TYPE genericPrint(tBuffer* buffer, const uint8_t * string) {
-       if (buffer->buf == NULL) return errBUFFER_NOT_INITIALIZED;
-       portBASE_TYPE ret = pdPASS;
-       xSemaphoreTake(buffer->mutex, portMAX_DELAY);
-       while (*string != '\0') {
-               if (!buffer->flags & BUF_TRANSFER_IN_PROGRESS) {
-                               taskENTER_CRITICAL();
-                               if (!buffer->flags & BUF_TRANSFER_IN_PROGRESS) {
-                                       buffer->flags |= BUF_TRANSFER_IN_PROGRESS;
-                                       sciREG->SETINT = SCI_TX_INT;    // Start new transfer by sending first byte
-                                       sciREG->TD     = *string++;
-                               }
-                               taskEXIT_CRITICAL();
-                               continue;
-               }
-               if ((ret = xQueueSend(buffer->buf, (void*)string++, portMAX_DELAY) )!= pdPASS) {
-                       break; // Some critical error occurred
-               }
-       }
-       xSemaphoreGive(buffer->mutex);
-       return ret ;
-}
-portBASE_TYPE clearInputBuffer() {
-       return clearBuffer(&inBuffer);
-}
-portBASE_TYPE clearOutputBuffer() {
-       return clearBuffer(&outBuffer);
-}
-portBASE_TYPE clearBuffer(tBuffer * buffer) {
-       if (buffer->buf == NULL) return errBUFFER_NOT_INITIALIZED;
-       while ((xQueueReceive(buffer->buf, NULL, 0)) != errQUEUE_EMPTY) // Delete content of queue
-               ;
-       return pdPASS;
-}
+#include "types.h"
+#include "rpp/rpp.h"
 
 int tisci_putc(cmd_io_t *cmd_io, int ch) {
-       uint8_t c[2];
-       c[0] =(uint8_t)ch;
-       c[1] = (uint8_t)'\0';
-       if (print((uint8_t *)&c) != pdPASS) {
-               return 0;
-       }
+       rpp_sci_putc((uint8_t)ch);
     return 1;
 }
 
 int tisci_getc(cmd_io_t *cmd_io) {
-       uint8_t ret = '\0';
-       if (read(&ret) != pdPASS) {
+       int ret = '\0';
+       ret = rpp_sci_getc();
+       if (ret == FAILURE) {
         ret = '\0';
        }
     return ret;
 }
 int tisci_write(cmd_io_t *cmd_io, const void *buf, int count) {
     const char *tmpBuf = buf;
-       if (print((uint8_t *)tmpBuf) != pdPASS)
-               return 0;
-    return count;
+
+       return rpp_sci_printf("%s", tmpBuf);
 }
 int tisci_read(cmd_io_t *cmd_io, void *buf, int count) {
-    char *tmpBuf = buf;
-    int i = 0;
-    while (i < count) {
-       if (read((uint8_t *)&tmpBuf[i]) != pdPASS)
-               break;
-       i++;
-    }
-    return i;
+    uint8_t* tmpBuf = buf;
+       return rpp_sci_read(count, tmpBuf);
 }
 
 /* Setting io stack for cmdProc */
index 84afd66e161dd1ce9b5ac62a6ca365c32d6030d2..72aa81731f670d587e3235aecb9bb055e03a15c3 100644 (file)
@@ -47,7 +47,7 @@ int cmd_processor_run(cmd_io_t *cmd_io, cmd_des_t const **commands)
   }else if(val<0){
     char s[20];
     cmd_io_puts(cmd_io,"ERROR ");
-    i2str(s,-val,0,0);
+    sprintf(s, "%d", -val);
     cmd_io_puts(cmd_io,s);
     cmd_io_putc(cmd_io,'\r');
     cmd_io_putc(cmd_io,'\n');
index f580e2ce3fcbe6aa1375d72b0a35dc05f32793ad..42c6d1675c35052b57a1f0b9010f48e477e3585d 100644 (file)
@@ -15,6 +15,7 @@
 #include <ctype.h>
 #include <stdlib.h>
 #include <cmdproc.h>
+#include "i2str.h"
 
 /* string parse and input routines */