]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - rpp/src/rpp/lout.c
Reformated by uncrustify
[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         initialized = TRUE;
34 #ifndef FREERTOS_POSIX
35         spi_tms570_init();
36 #endif
37
38         // FIXME: Implement.
39         return SUCCESS;
40 }
41
42
43 static uint8_t out_cache = 0x0;
44
45 int8_t rpp_lout_set(uint8_t pin, uint8_t val)
46 {
47         if ((pin < 1) || (pin > 8))
48                 return -1;
49
50         uint8_t index = pin - 1;
51         if (val)
52                 bit_set(out_cache, index);
53         else
54                 bit_clear(out_cache, index);
55         return SUCCESS;
56 }
57
58
59 static uint8_t diag_cache = 0x0;
60
61 int8_t rpp_lout_diag(uint8_t pin)
62 {
63         if ((pin < 1) || (pin > 8))
64                 return -1;
65
66         if (is_bit_set(diag_cache, pin - 1))
67                 return HIGH;
68         return LOW;
69 }
70
71
72 int8_t rpp_lout_update()
73 {
74 #ifndef FREERTOS_POSIX
75         // Update output values
76         lout_set_word(out_cache);
77         // FIXME: Check which SPI transfer statuses could be considered errors
78         lout_spi_transfer();
79
80         // Read back diagnostic values
81         // FIXME: Implement. Dummy assign for now.
82         diag_cache = out_cache;
83
84         if (diag_cache != out_cache)
85                 return FAILURE;
86
87 #endif
88
89         return SUCCESS;
90 }