/* 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.
/* 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
#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)))
#define _EMAC_TEST_H_
#include "cmdproc.h"
-#include "sys_common.h"
+#include "types.h"
/* ************************************************* */
/* Emac frame buffer related stuff */
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
-#include "i2str.h"
#include "cmdproc.h"
#include "cmdproc_priv.h"
/* Include files */
#include "cmdproc_freertos_tms570.h"
+#include "rpp/sci.h"
/** cmdProc task handler */
xTaskHandle processCmdHandler;
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));
}
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);
}
}
/* 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 */
}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');
#include <ctype.h>
#include <stdlib.h>
#include <cmdproc.h>
+#include "i2str.h"
/* string parse and input routines */