FreeCalypso > hg > fc-selenite
comparison src/cs/drivers/drv_app/spi/spi_api.c @ 0:b6a5e36de839
src/cs: initial import from Magnetite
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 15 Jul 2018 04:39:26 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:b6a5e36de839 |
---|---|
1 /********************************************************************************* | |
2 * | |
3 * File Name: spi_api.c | |
4 * | |
5 * Bridge functions used to send events to the SPI task | |
6 * | |
7 * (C) Texas Instruments, all rights reserved | |
8 * | |
9 * Version number: 0.1 Date: 25-September-2000 | |
10 * | |
11 * History: 0.1 - Created by Candice Bazanegue | |
12 * | |
13 * Author: | |
14 * | |
15 *********************************************************************************/ | |
16 | |
17 #include "rvf/rvf_api.h" | |
18 #include "spi/spi_api.h" | |
19 #include "spi/spi_env.h" | |
20 #include "spi/spi_process.h" | |
21 #include "rvm/rvm_use_id_list.h" | |
22 | |
23 | |
24 | |
25 /********************************************************************************/ | |
26 /* */ | |
27 /* Function Name: spi_abb_read */ | |
28 /* */ | |
29 /********************************************************************************/ | |
30 T_RV_RET spi_abb_read(UINT16 page, UINT16 address, CALLBACK_FUNC_U16 CallBack) | |
31 { | |
32 T_SPI_READ *msgPtr; | |
33 | |
34 /* check if the driver has been started */ | |
35 if (SPI_GBL_INFO_PTR == NULL) | |
36 { | |
37 rvf_send_trace("ABB read not possible. Reason: SPI task not started",51, NULL_PARAM, | |
38 RV_TRACE_LEVEL_WARNING, SPI_USE_ID); | |
39 return (RVM_NOT_READY); | |
40 } | |
41 | |
42 if(SPI_GBL_INFO_PTR->SpiTaskReady == FALSE) | |
43 { | |
44 rvf_send_trace("ABB read not possible. Reason: SPI Task not ready",49, NULL_PARAM, | |
45 RV_TRACE_LEVEL_WARNING, SPI_USE_ID); | |
46 return (RVM_NOT_READY); | |
47 } | |
48 | |
49 rvf_send_trace("SPI_ABB_READ",12, NULL_PARAM, | |
50 RV_TRACE_LEVEL_WARNING, SPI_USE_ID); | |
51 | |
52 if (rvf_get_buf (SPI_GBL_INFO_PTR->prim_id, sizeof (T_SPI_READ),(void **) &msgPtr) == RVF_RED) | |
53 { | |
54 rvf_send_trace ("SPI ERROR: ABB read not possible. Reason: Not enough memory", | |
55 59, | |
56 NULL_PARAM, | |
57 RV_TRACE_LEVEL_ERROR, | |
58 SPI_USE_ID); | |
59 | |
60 return (RV_MEMORY_ERR); | |
61 } | |
62 | |
63 (msgPtr->os_hdr).msg_id = SPI_ABB_READ_EVT; | |
64 (msgPtr->os_hdr).dest_addr_id = SPI_GBL_INFO_PTR->addr_id; | |
65 (msgPtr->os_hdr).callback_func = (CALLBACK_FUNC) CallBack; | |
66 msgPtr->page = page; | |
67 msgPtr->address = address; | |
68 | |
69 rvf_send_msg (SPI_GBL_INFO_PTR->addr_id, | |
70 msgPtr); | |
71 | |
72 return (RV_OK); | |
73 } | |
74 | |
75 | |
76 | |
77 | |
78 /********************************************************************************/ | |
79 /* */ | |
80 /* Function Name: spi_abb_write */ | |
81 /* */ | |
82 /********************************************************************************/ | |
83 T_RV_RET spi_abb_write(UINT16 page, UINT16 address, UINT16 data) | |
84 { | |
85 T_SPI_WRITE *msgPtr; | |
86 | |
87 /* check if the driver has been started */ | |
88 if (SPI_GBL_INFO_PTR == NULL) | |
89 { | |
90 rvf_send_trace("ABB write not possible. Reason: SPI task not started",52, NULL_PARAM, | |
91 RV_TRACE_LEVEL_WARNING, SPI_USE_ID); | |
92 return (RVM_NOT_READY); | |
93 } | |
94 | |
95 if(SPI_GBL_INFO_PTR->SpiTaskReady == FALSE) | |
96 { | |
97 rvf_send_trace("ABB write not possible. Reason: SPI Task not ready",50, NULL_PARAM, | |
98 RV_TRACE_LEVEL_WARNING, SPI_USE_ID); | |
99 return (RVM_NOT_READY); | |
100 } | |
101 | |
102 if (rvf_get_buf (SPI_GBL_INFO_PTR->prim_id, sizeof (T_SPI_WRITE),(void **) &msgPtr) == RVF_RED) | |
103 { | |
104 rvf_send_trace ("SPI ERROR: ABB write not possible. Reason: Not enough memory", | |
105 60, | |
106 NULL_PARAM, | |
107 RV_TRACE_LEVEL_ERROR, | |
108 SPI_USE_ID); | |
109 | |
110 return (RV_MEMORY_ERR); | |
111 } | |
112 | |
113 (msgPtr->os_hdr).msg_id = SPI_ABB_WRITE_EVT; | |
114 (msgPtr->os_hdr).dest_addr_id = SPI_GBL_INFO_PTR->addr_id; | |
115 (msgPtr->os_hdr).callback_func = NULL; | |
116 msgPtr->page = page; | |
117 msgPtr->address = address; | |
118 msgPtr->data = data; | |
119 | |
120 rvf_send_msg (SPI_GBL_INFO_PTR->addr_id, msgPtr); | |
121 | |
122 return (RV_OK); | |
123 } | |
124 | |
125 | |
126 | |
127 | |
128 /********************************************************************************/ | |
129 /* */ | |
130 /* Function Name: spi_abb_conf_ADC */ | |
131 /* */ | |
132 /********************************************************************************/ | |
133 T_RV_RET spi_abb_conf_ADC(UINT16 channels, UINT16 itval) | |
134 { | |
135 T_SPI_ABB_CONF_ADC *msgPtr; | |
136 | |
137 /* check if the driver has been started */ | |
138 if (SPI_GBL_INFO_PTR == NULL) | |
139 { | |
140 rvf_send_trace("ABB conf ADC not possible. Reason: SPI task not started",55, NULL_PARAM, | |
141 RV_TRACE_LEVEL_WARNING, SPI_USE_ID); | |
142 return (RVM_NOT_READY); | |
143 } | |
144 | |
145 if(SPI_GBL_INFO_PTR->SpiTaskReady == FALSE) | |
146 { | |
147 rvf_send_trace("ABB conf ADC not possible. Reason: SPI Task not ready",53, NULL_PARAM, | |
148 RV_TRACE_LEVEL_WARNING, SPI_USE_ID); | |
149 return (RVM_NOT_READY); | |
150 } | |
151 | |
152 rvf_send_trace("SPI_ABB_CONF_ADC",16, NULL_PARAM, | |
153 RV_TRACE_LEVEL_WARNING, SPI_USE_ID); | |
154 | |
155 if (rvf_get_buf (SPI_GBL_INFO_PTR->prim_id, sizeof (T_SPI_ABB_CONF_ADC),(void **) &msgPtr) == RVF_RED) | |
156 { | |
157 rvf_send_trace ("SPI ERROR: ABB conf ADC not possible. Reason: Not enough memory", | |
158 63, | |
159 NULL_PARAM, | |
160 RV_TRACE_LEVEL_ERROR, | |
161 SPI_USE_ID); | |
162 | |
163 return (RV_MEMORY_ERR); | |
164 } | |
165 | |
166 (msgPtr->os_hdr).msg_id = SPI_ABB_CONF_ADC_EVT; | |
167 (msgPtr->os_hdr).dest_addr_id = SPI_GBL_INFO_PTR->addr_id; | |
168 (msgPtr->os_hdr).callback_func = NULL; | |
169 msgPtr->channels = channels; | |
170 msgPtr->itval = itval; | |
171 | |
172 rvf_send_msg (SPI_GBL_INFO_PTR->addr_id, msgPtr); | |
173 | |
174 return (RV_OK); | |
175 } | |
176 | |
177 | |
178 | |
179 /********************************************************************************/ | |
180 /* */ | |
181 /* Function Name: spi_abb_read_ADC */ | |
182 /* */ | |
183 /********************************************************************************/ | |
184 T_RV_RET spi_abb_read_ADC(UINT16 *Buff, CALLBACK_FUNC_NO_PARAM CallBack) | |
185 { | |
186 T_SPI_ABB_READ_ADC *msgPtr; | |
187 | |
188 /* check if the driver has been started */ | |
189 if (SPI_GBL_INFO_PTR == NULL) | |
190 { | |
191 rvf_send_trace("ABB read ADC not possible. Reason: SPI task not started",55, NULL_PARAM, | |
192 RV_TRACE_LEVEL_WARNING, SPI_USE_ID); | |
193 return (RVM_NOT_READY); | |
194 } | |
195 | |
196 if(SPI_GBL_INFO_PTR->SpiTaskReady == FALSE) | |
197 { | |
198 rvf_send_trace("ABB conf ADC not possible. Reason: SPI Task not ready",53, NULL_PARAM, | |
199 RV_TRACE_LEVEL_WARNING, SPI_USE_ID); | |
200 return (RVM_NOT_READY); | |
201 } | |
202 | |
203 rvf_send_trace("SPI_ABB_READ_ADC",16, NULL_PARAM, | |
204 RV_TRACE_LEVEL_WARNING, SPI_USE_ID); | |
205 | |
206 if (rvf_get_buf (SPI_GBL_INFO_PTR->prim_id, sizeof (T_SPI_ABB_READ_ADC),(void **) &msgPtr) == RVF_RED) | |
207 { | |
208 rvf_send_trace ("SPI ERROR: ABB read ADC not possible. Reason: Not enough memory", | |
209 63, | |
210 NULL_PARAM, | |
211 RV_TRACE_LEVEL_ERROR, | |
212 SPI_USE_ID); | |
213 | |
214 return (RV_MEMORY_ERR); | |
215 } | |
216 | |
217 (msgPtr->os_hdr).msg_id = SPI_ABB_READ_ADC_EVT; | |
218 (msgPtr->os_hdr).dest_addr_id = SPI_GBL_INFO_PTR->addr_id; | |
219 (msgPtr->os_hdr).callback_func = NULL; | |
220 msgPtr->Buff = Buff; | |
221 msgPtr->callback_func = CallBack; | |
222 | |
223 rvf_send_msg (SPI_GBL_INFO_PTR->addr_id, msgPtr); | |
224 | |
225 return (RV_OK); | |
226 } | |
227 |