]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - rpp/src/rpp/mout.c
Change the license from GPL to proprietary
[pes-rpp/rpp-lib.git] / rpp / src / rpp / mout.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 : mout.c
12  * Abstract:
13  *     Power Output (12V, 2A, Push/Pull) RPP API implementation file.
14  *
15  * References:
16  *     mout.h
17  *     RPP API documentation.
18  */
19
20
21 #include "rpp/rpp.h"
22
23 #if rppCONFIG_INCLUDE_MOUT == 1
24
25 #if rppCONFIG_DRV == 1
26 #include "drv/mout.h"
27 #endif
28
29 static boolean_t initialized = FALSE;
30
31 int8_t rpp_mout_init()
32 {
33     if(initialized) {
34         return FAILURE;
35     }
36     initialized = TRUE;
37
38     return SUCCESS;
39 }
40
41
42 static uint8_t cache[] = {
43     LOW, LOW, LOW, LOW, LOW, LOW
44 };
45
46 int8_t rpp_mout_set(uint8_t pin, uint8_t val)
47 {
48     // Check range
49     if((pin < 1) || (pin > 6)) {
50         return -1;
51     }
52
53     // Check val
54     if((val != HIGH) && (val != LOW)) {
55         return -2;
56     }
57
58     uint8_t idx = pin - 1;
59
60     #if rppCONFIG_DRV == 1
61     // Set and store value
62     if(drv_mout_set(idx, val) != SUCCESS) {
63         return -3;
64     }
65     cache[idx] = val;
66
67     // FIXME Wait some time for synchronization
68     // Don't use vTaskDelay() here because the minimum time to wait is one tick,
69     // and depending of the configuration of the user model one tick can overrun
70     // the program.
71     int wait;
72     for(wait = 0; wait < 10; wait++) {
73         asm(" nop");
74     }
75
76     // Get value back and compare
77     if(drv_mout_diag(idx) == FAILURE) {
78         return -4;
79     }
80     #else
81     cache[idx] = val;
82     #endif
83
84     return SUCCESS;
85 }
86
87
88 int8_t rpp_mout_get(uint8_t pin)
89 {
90     // Check range
91     if((pin < 1) || (pin > 6)) {
92         return -1;
93     }
94
95     return cache[pin - 1];
96 }
97
98
99 int8_t rpp_mout_diag(uint8_t pin)
100 {
101     // Check range
102     if((pin < 1) || (pin > 6)) {
103         return -1;
104     }
105
106     #if rppCONFIG_DRV == 1
107     if(drv_mout_diag(pin - 1) == 0) {
108         return FAILURE;
109     }
110     #endif
111     return SUCCESS;
112 }
113
114
115 #endif /* rppCONFIG_INCLUDE_MOUT */
116