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