]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - rpp/src/rpp/mout.c
Update rpp/gio.* to the new drv/gio interface and remove crap from it
[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 #ifndef FREERTOS_POSIX
24 #include "drv/mout.h"
25 #endif
26
27 static boolean_t initialized = FALSE;
28
29 int8_t rpp_mout_init()
30 {
31         if (initialized)
32                 return FAILURE;
33         initialized = TRUE;
34 #ifndef FREERTOS_POSIX
35         dmmInit();
36         gioInit();
37         hetInit();
38 #endif
39
40         return SUCCESS;
41 }
42
43
44 static uint8_t cache[] = {
45         LOW, LOW, LOW, LOW, LOW, LOW
46 };
47
48 int8_t rpp_mout_set(uint8_t pin, uint8_t val)
49 {
50         // Check range
51         if ((pin < 1) || (pin > 6))
52                 return -1;
53
54         // Check val
55         if ((val != HIGH) && (val != LOW))
56                 return -2;
57
58         uint8_t idx = pin - 1;
59
60 #ifndef FREERTOS_POSIX
61         // Set and store value
62         if (drv_mout_set(idx, val) != SUCCESS)
63                 return -3;
64         cache[idx] = val;
65
66         // FIXME Wait some time for synchronization
67         // Don't use vTaskDelay() here because the minimum time to wait is one tick,
68         // and depending of the configuration of the user model one tick can overrun
69         // the program.
70         int wait;
71         for (wait = 0; wait < 10; wait++) {
72                 asm (" nop");
73         }
74
75         // Get value back and compare
76         if (drv_mout_diag(idx) == FAILURE)
77                 return -4;
78
79 #else
80         cache[idx] = val;
81 #endif
82
83         return SUCCESS;
84 }
85
86
87 int8_t rpp_mout_get(uint8_t pin)
88 {
89         // Check range
90         if ((pin < 1) || (pin > 6))
91                 return -1;
92
93         return cache[pin - 1];
94 }
95
96
97 int8_t rpp_mout_diag(uint8_t pin)
98 {
99         // Check range
100         if ((pin < 1) || (pin > 6))
101                 return -1;
102
103 #ifndef FREERTOS_POSIX
104         if (drv_mout_diag(pin - 1) == 0)
105                 return FAILURE;
106
107 #endif
108         return SUCCESS;
109 }