]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - rpp/src/rpp/sci.c
Added a CCS project that compiles the whole RPP library, not just the RPP layer,...
[pes-rpp/rpp-lib.git] / rpp / src / rpp / sci.c
1 /* Copyright (C) 2013 Czech Technical University in Prague
2  *
3  * Authors:
4  *     - Carlos Jenkins <carlos@jenkins.co.cr>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  * File : sci.c
20  * Abstract:
21  *     Serial Communication Interface RPP API implementation file.
22  *
23  * References:
24  *     sci.h
25  *     RPP API documentation.
26  */
27
28
29 #include "rpp/rpp.h"
30
31 #if rppCONFIG_INCLUDE_SCI == 1
32 #include <stdio.h>
33
34 #if rppCONFIG_DRV == 1
35 #include "drv/drv.h"
36 #endif
37
38 static boolean_t initialized = FALSE;
39
40 int8_t rpp_sci_init()
41 {
42     if(initialized) {
43         return FAILURE;
44     }
45     initialized = TRUE;
46
47     #if rppCONFIG_DRV == 1
48     drv_sci_init();
49     #endif
50
51    return SUCCESS;
52 }
53
54 int rpp_sci_printf(const char *format, ...)
55 {
56     char str[128];
57     int length = -1;
58
59     va_list argList;
60     va_start(argList, format);
61
62     length = vsnprintf(str, sizeof(str), format, argList);
63
64     va_end(argList);
65
66     if(length > 0) {
67         #if rppCONFIG_DRV == 1
68         drv_sci_send((uint32_t)length, (uint8_t*)str);
69         #endif
70     }
71
72     return length;
73 }
74
75
76 #endif /* rppCONFIG_INCLUDE_SCI */
77