]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - rpp/src/rpp/irc.c
96625b7f6712826a2f996a7d0b8da2a08e54b311
[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 boolean_t rpp_irc1_enabled = FALSE;
33 boolean_t rpp_irc2_enabled = FALSE;
34
35 int8_t rpp_irc_init()
36 {
37
38         if (initialized)
39                 return FAILURE;
40
41 #ifndef FREERTOS_POSIX
42         het2Init();
43 #endif
44
45         initialized = TRUE;
46         return SUCCESS;
47 }
48
49 int8_t rpp_irc_enable(uint8_t irc)
50 {
51
52         if (!initialized)
53                 return FAILURE;
54
55         if (irc < 1 || irc > 2)
56                 return -RPP_EINVAL;
57
58         switch (irc) {
59         case 1:
60                 rpp_irc1_enabled = TRUE;
61                 break;
62         case 2:
63                 rpp_irc2_enabled = TRUE;
64                 break;
65         }
66
67         setMuxForIRC(irc, TRUE);
68         ircEnable(irc);
69
70         return SUCCESS;
71 }
72
73 int8_t rpp_irc_status(uint8_t irc)
74 {
75
76         if (!initialized)
77                 return FAILURE;
78
79         if (irc < 1 || irc > 2)
80                 return -RPP_EINVAL;
81
82         switch (irc) {
83         case 1:
84                 return rpp_irc1_enabled ? 1 : 0;
85         case 2:
86                 return rpp_irc2_enabled ? 1 : 0;
87         }
88         return FAILURE;
89 }
90
91 int32_t rpp_irc_get(uint8_t irc)
92 {
93
94         if (!initialized)
95                 return FAILURE;
96
97         if (irc < 1 || irc > 2)
98                 return 0;
99
100         if (rpp_irc_status(irc) != 1)
101                 return FAILURE;
102
103 #ifndef FREERTOS_POSIX
104         return ircGet(irc);
105 #else
106         return 1;
107 #endif
108 }
109
110 int8_t rpp_irc_disable(uint8_t irc)
111 {
112
113         if (!initialized)
114                 return FAILURE;
115
116         if (irc < 1 || irc > 2)
117                 return -RPP_EINVAL;
118
119         if (rpp_irc_status(irc) != 1)
120                 return FAILURE;
121
122         ircDisable(irc);
123         setMuxForIRC(irc, FALSE);
124         switch (irc) {
125         case 1:
126                 rpp_irc1_enabled = FALSE;
127                 break;
128         case 2:
129                 rpp_irc2_enabled = FALSE;
130                 break;
131         }
132         return FAILURE;
133 }