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