]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - rpp/src/rpp/lout.c
Created rpp-layer test project adn fixed the RPP layer on library.
[pes-rpp/rpp-lib.git] / rpp / src / rpp / lout.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 : lout.c
20  * Abstract:
21  *     Logic Output RPP API implementation file.
22  *
23  * References:
24  *     lout.h
25  *     RPP API documentation.
26  */
27
28
29 #include "rpp/rpp.h"
30
31 #if rppCONFIG_INCLUDE_LOUT == 1
32
33 #if rppCONFIG_DRV == 1
34 #include "drv/lout.h"
35 #endif
36
37 static boolean_t initialized = FALSE;
38
39 int8_t rpp_lout_init()
40 {
41     if(initialized) {
42         return FAILURE;
43     }
44     initialized = TRUE;
45
46     // FIXME: Implement.
47    return SUCCESS;
48 }
49
50
51 static uint8_t out_cache = 0x0;
52
53 int8_t rpp_lout_set(uint8_t pin, int8_t val)
54 {
55     if((pin < 1) || (pin > 8)) {
56         return -1;
57     }
58     if(val) {
59         bit_set(out_cache, pin - 1);
60     } else {
61         bit_clear(out_cache, pin - 1);
62     }
63     return SUCCESS;
64 }
65
66
67 static uint8_t diag_cache = 0x0;
68
69 int8_t rpp_lout_diag(uint8_t pin)
70 {
71     if((pin < 1) || (pin > 8)) {
72         return -1;
73     }
74
75     if(is_bit_set(diag_cache, pin - 1)) {
76         return HIGH;
77     }
78     return LOW;
79 }
80
81
82 int8_t rpp_lout_update()
83 {
84     #if rppCONFIG_DRV == 1
85     // Update output values
86     lout_set_word(out_cache);
87     // FIXME: Check which SPI transfer statuses could be considered errors
88     lout_spi_transfer();
89
90     // Read back diagnostic values
91     // FIXME: Implement. Dummy assign for now.
92     diag_cache = out_cache;
93
94     if(diag_cache != out_cache) {
95         return FAILURE;
96     }
97     #endif
98
99     return SUCCESS;
100 }
101
102
103 #endif /* rppCONFIG_INCLUDE_LOUT */
104