]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/blob - include/cmdio_tisci.h
34555d1c7669036635f7445a896d5c127ab41db5
[pes-rpp/rpp-test-sw.git] / include / cmdio_tisci.h
1 /*
2  * cmd_proc_freertos_tms570.h
3  *
4  *  Created on: 1.8.2012
5  *      Author: Michal Horn
6  *
7  *  Header file for cmdProc with FreeRTOS procedures included.
8  */
9
10 #ifndef CMDIO_BUFFER_H_
11 #define CMDIO_BUFFER_H_
12
13 #define MAX_BUFFER_LEN 128
14
15 #include "cmd_proc.h"
16 #include "FreeRTOS.h"
17 #include "os_queue.h"
18 #include "os_semphr.h"
19
20
21 typedef struct {
22         xQueueHandle buf;
23         xSemaphoreHandle mutex;
24         uint8_t initialized;
25 } tBuffer;
26
27
28 /**     Initialize IO Buffers
29 */
30 void initIoBuffer();
31
32 /**     Print string into an output buffer. Let it be blocking or nonblocking in case the buffer is full.
33  * @param[in]   string  String to be printed into buffer
34  * @param[in]   length  number of characters to be printed
35  * @param[in]   ticks   Number of FreeRTOS's ticks to block task, when buffer is full. portMAX_DELAY can be used.
36  * @return      pdPASS when OK; errQUEUE_FULL when buffer is full and ran out of block time.
37  */
38 portBASE_TYPE printToOutputBuffer(const uint8_t * string, uint32_t length, portTickType ticks);
39
40 /**     Print string into an input buffer. Let it be blocking or nonblocking in case the buffer is full.
41  * @param[in]   string  String to be printed into buffer
42  * @param[in]   length  number of characters to be printed
43  * @param[in]   ticks   Number of FreeRTOS's ticks to block task, when buffer is full. portMAX_DELAY can be used.
44  * @return      pdPASS when OK; errQUEUE_FULL when buffer is full and ran out of block time.
45  */
46 portBASE_TYPE printToInputBuffer(const uint8_t * string, uint32_t length, portTickType ticks);
47
48 /**     Read character from an output buffer. Let it be blocking or nonblocking in case the buffer is empty.
49  * @param[out]  ch      Character read from buffer
50  * @param[in]   ticks   Number of FreeRTOS's ticks to block task, when buffer is empty. portMAX_DELAY can be used.
51  * @return      pdPASS when OK; errQUEUE_EMPTY when buffer is empty and ran out of block time.
52  */
53 portBASE_TYPE readFromOutputBuffer(uint8_t * ch, portTickType ticks);
54
55 /**     Read character from an input buffer. Let it be blocking or nonblocking in case the buffer is empty.
56  * @param[out]  ch      Character read from buffer
57  * @param[in]   ticks   Number of FreeRTOS's ticks to block task, when buffer is full. portMAX_DELAY can be used.
58  * @return      pdPASS when OK; errQUEUE_EMPTY when buffer is empty and ran out of block time.
59  */
60 portBASE_TYPE readFromInputBuffer(uint8_t * ch, portTickType ticks);
61
62 /**     Read character from a buffer. Let it be blocking or nonblocking in case the buffer is empty.
63  * @param[in]   buffer  Pointer to buffer from which will be read.
64  * @param[out]  ch      Character read from buffer
65  * @param[in]   ticks   Number of FreeRTOS's ticks to block task, when buffer is empty. portMAX_DELAY can be used.
66  * @return      pdPASS when OK; errQUEUE_EMPTY when buffer is empty and ran out of block time.
67  */
68 portBASE_TYPE read(tBuffer* buffer, uint8_t * ch, portTickType ticks);
69
70 /**     Print string to a buffer. Let it be blocking or nonblocking in case the buffer is full.
71  * @param[in]   buffer  Pointer to buffer from which will be read.
72  * @param[in]   string  String to be printed into buffer
73  * @param[in]   length  number of characters to be printed
74  * @param[in]   ticks   Number of FreeRTOS's ticks to block task, when buffer is full. portMAX_DELAY can be used.
75  * @return      pdPASS when OK; errQUEUE_FULL when buffer is full and ran out of block time.
76  */
77 portBASE_TYPE print(tBuffer* buffer, const uint8_t * string, uint32_t length, portTickType ticks);
78
79 /**     Makes input buffer empty
80  */
81 void clearInputBuffer();
82
83 /**     Makes output buffer empty
84  */
85 void clearOutputBuffer();
86
87 /**     Makes buffer empty
88  * @param[in]   buffer  Buffer to be cleared
89  */
90 void clearBuffer(tBuffer * buffer);
91
92 /**     Puts character into output buffer. Is blocking, when buffer is full.
93  *      @param[in]      cmd_io  IO stack pointer
94  *      @param[in]      ch      Character to be printed
95  *      @return 1 when succes, 0 when fail
96  */
97 int buf_putc(cmd_io_t *cmd_io, int ch);
98
99 /**     Gets character from input buffer, is blocking when buffer is empty.
100  *      @param[in]      cmd_io  IO stack pointer
101  *      @return read character
102  */
103 int buf_getc(cmd_io_t *cmd_io);
104
105 /**     Writes string into output buffer, is blocking when buffer is full.
106  *      @param[in]      cmd_io  IO stack pointer
107  *      @param[in]      buf     String to be written
108  *      @param[in]      count   Number of character to be written
109  *      @return number of written characters
110  */
111 int buf_write(cmd_io_t *cmd_io, const void *buf, int count);
112
113 /**     Reads string from input buffer, is blocking when buffer is empty.
114  *      @param[in]      cmd_io  IO stack pointer
115  *      @param[out]     buf     Buffer into which string be read
116  *      @param[in]      count   Number of character to be read
117  *      @return number of read characters
118  */
119 int buf_read(cmd_io_t *cmd_io, void *buf, int count);
120
121 #endif /* CMDIO_BUFFER_H_ */
122