]> rtime.felk.cvut.cz Git - rpp-test-sw.git/blob - rpp-test-sw/cmdproc/src/cmdproc_io_tisci.c
cmd: Add echoserver functionality and command
[rpp-test-sw.git] / rpp-test-sw / cmdproc / src / cmdproc_io_tisci.c
1 /*******************************************************************
2    Components for embedded applications builded for
3    laboratory and medical instruments firmware
4
5    cmd_proc_io_tisci.c - IO layer functions for SCI on TMS570 and FreeRTOS
6
7    Copyright (C) 2001-2009 by Pavel Pisa pisa@cmp.felk.cvut.cz
8             (C) 2002-2009 by PiKRON Ltd. http://www.pikron.com
9             (C) 2007 by Michal Sojka <sojkam1@fel.cvut.cz>
10             (C) 2012 by Michal Horn <hornmich@fel.cvut.cz>
11
12    This file can be used and copied according to next
13    license alternatives
14    - MPL - Mozilla Public License
15    - GPL - GNU Public License
16    - other license provided by project originators
17 *******************************************************************/
18
19
20 /* Include files */
21 #include "cmdproc_io_tisci.h"
22 #include "types.h"
23 #include "rpp/rpp.h"
24
25 /**
26  * @brief Print character on SCI
27  * @param cmd_io cmd_io structure
28  * @param ch character to be printed
29  * @return always 1
30  *
31  */
32 int tisci_putc(cmd_io_t *cmd_io, int ch)
33 {
34         rpp_sci_putc((uint8_t)ch);
35         return 1;
36 }
37
38 /**
39  * @brief Read character from SCI
40  * @param cmd_io cmd_io structure
41  * @return character ASCII code
42  *
43  */
44 int tisci_getc(cmd_io_t *cmd_io)
45 {
46         int ret = '\0';
47
48         ret = rpp_sci_getc();
49         if (ret == FAILURE)
50                 ret = '\0';
51         return ret;
52 }
53
54 int tisci_getc_nb(cmd_io_t *cmd_io)
55 {
56         uint8_t ch;
57
58         if (rpp_sci_read_nb(1, &ch) == FAILURE)
59                 return -1;
60         else
61                 return ch;
62 }
63
64 /**
65  * @brief Print string on SCI
66  * @param cmd_io cmd_io structure
67  * @param buf String buffer to be printed
68  * @param count maximum character number to be printed
69  * @return number of printed characters
70  *
71  */
72 int tisci_write(cmd_io_t *cmd_io, const void *buf, int count)
73 {
74         const char *tmpBuf = buf;
75
76         return rpp_sci_printf("%s", tmpBuf);
77 }
78
79 /**
80  * @brief Read string from SCI
81  * @param cmd_io cmd_io structure
82  * @param buf String buffer
83  * @param count maximum character number to be read
84  * @return SUCCESS
85  */
86 int tisci_read(cmd_io_t *cmd_io, void *buf, int count)
87 {
88         uint8_t *tmpBuf = buf;
89
90         return rpp_sci_read(count, tmpBuf);
91 }
92
93 /**
94  *  IO stack for cmdProc
95  */
96 cmd_io_t cmd_io_tisci = {
97         tisci_putc,
98         tisci_getc,
99         tisci_write,
100         tisci_read
101 };