]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - rpp/src/rpp/irc.c
Modify IRC enable code
[pes-rpp/rpp-lib.git] / rpp / src / rpp / irc.c
1 /* Copyright (C) 2013-2014 Czech Technical University in Prague
2  *
3  * Authors:
4  *     - Karel Kočí
5  *
6  * This document contains proprietary information belonging to Czech
7  * Technical University in Prague. Passing on and copying of this
8  * document, and communication of its contents is not permitted
9  * without prior written authorization.
10  *
11  * File : irc.c
12  * Abstract:
13  *     IRC sensor input driver RPP API implementation file.
14  *
15  * References:
16  *     irc.h
17  *     RPP API documentation.
18  */
19
20 #include "rpp/rpp.h"
21
22 #ifndef FREERTOS_POSIX
23 #include "sys/sys.h"
24 #else
25 #define setMuxForIRC(a, b)
26 #define ircEnable(a)
27 #define ircDisable(a)
28 #endif
29
30 static boolean_t initialized = FALSE;
31
32 static boolean_t rpp_irc_enabled[2] = {FALSE, FALSE};
33
34 int8_t rpp_irc_init()
35 {
36
37         if (initialized)
38                 return FAILURE;
39
40 #ifndef FREERTOS_POSIX
41         het2Init();
42 #endif
43
44         initialized = TRUE;
45         return SUCCESS;
46 }
47
48 int8_t rpp_irc_enable(uint8_t irc)
49 {
50
51         if (!initialized)
52                 return FAILURE;
53
54         if (irc < 1 || irc > 2)
55                 return -RPP_EINVAL;
56
57         rpp_irc_enabled[irc-1] = TRUE;
58
59         setMuxForIRC(irc, TRUE);
60         ircEnable(irc);
61
62         return SUCCESS;
63 }
64
65 int8_t rpp_irc_status(uint8_t irc)
66 {
67
68         if (!initialized)
69                 return FAILURE;
70
71         if (irc < 1 || irc > 2)
72                 return -RPP_EINVAL;
73
74         return rpp_irc_enabled[irc-1];
75 }
76
77 int32_t rpp_irc_get(uint8_t irc)
78 {
79
80         if (!initialized)
81                 return FAILURE;
82
83         if (irc < 1 || irc > 2)
84                 return 0;
85
86         if (rpp_irc_status(irc) != 1)
87                 return FAILURE;
88
89 #ifndef FREERTOS_POSIX
90         return ircGet(irc);
91 #else
92         return 1;
93 #endif
94 }
95
96 int8_t rpp_irc_disable(uint8_t irc)
97 {
98
99         if (!initialized)
100                 return FAILURE;
101
102         if (irc < 1 || irc > 2)
103                 return -RPP_EINVAL;
104
105         if (rpp_irc_status(irc) != 1)
106                 return FAILURE;
107
108         ircDisable(irc);
109         setMuxForIRC(irc, FALSE);
110         rpp_irc_enabled[irc-1] = FALSE;
111         return SUCCESS;
112 }