comparison gsm-fw/ccd/ccd_store.c @ 648:970d6199f2c5

gsm-fw/ccd/*.[ch]: initial import from the LoCosto source
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Thu, 04 Sep 2014 05:48:57 +0000
parents
children
comparison
equal deleted inserted replaced
647:a60b375014e3 648:970d6199f2c5
1 /*
2 +-----------------------------------------------------------------------------
3 | Project :
4 | Modul : ccd_store.c
5 +-----------------------------------------------------------------------------
6 | Copyright 2004 Texas Instruments Deutschland, GmbH
7 | All rights reserved.
8 |
9 | This file is confidential and a trade secret of Texas
10 | Instruments Berlin, AG
11 | The receipt of or possession of this file does not convey
12 | any rights to reproduce or disclose its contents or to
13 | manufacture, use, or sell anything it may describe, in
14 | whole, or in part, without the specific written consent of
15 | Texas Instruments Berlin, AG.
16 +-----------------------------------------------------------------------------
17 | Purpose : CCD - Definition of store handling routines
18 +-----------------------------------------------------------------------------
19 */
20
21 #define CCD_STO_C
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <stdarg.h>
26 #include <string.h>
27 #include <setjmp.h>
28
29 /*
30 * Standard definitions like UCHAR, ERROR etc.
31 */
32 #include "typedefs.h"
33 #include "header.h"
34
35 /*
36 * Types and constants used by CCD
37 */
38 #include "ccd_globs.h"
39
40 /*
41 * Type definitions for CCD data tables
42 */
43 #include "ccdtable.h"
44
45 /*
46 * Function prototypes of CCD-CCDDATA interface
47 */
48 #include "ccddata.h"
49
50 /*
51 * Prototypes of ccd internal functions
52 */
53 #include "ccd.h"
54
55
56 extern T_CCD_TASK_TABLE* ccd_task_list[];
57
58 #ifndef RUN_INT_RAM
59 /* Attention for RUN_...: static function */
60 /*
61 +------------------------------------------------------------------------------
62 | Function : ccd_store_alloc
63 +------------------------------------------------------------------------------
64 | Description : This function allocates a the entity's store entry and
65 | set its next pointer to 0.
66 | The members of the entry must not reset with each
67 | coding/decoding action.
68 |
69 | Parameters : -
70 |
71 | Return : pointer to struct of type T_CCD_STORE_LIST
72 +------------------------------------------------------------------------------
73 */
74 static T_CCD_STORE_LIST* ccd_store_alloc ()
75 {
76 T_CCD_STORE_LIST* stoentry;
77 int i;
78 #if defined (CCD_TEST)
79 stoentry = malloc (sizeof(T_CCD_STORE_LIST));
80 #else
81 stoentry = D_ALLOC (sizeof(T_CCD_STORE_LIST));
82 #endif
83 /* for future use to extend register capacity */
84 /* stoentry->next = NULL */
85 if (stoentry)
86 {
87 for (i = 0; i < 3; i++)
88 {
89 stoentry->store[i] = 0;
90 }
91 /* for future use to extend register capacity */
92 /* (*stoentry)->next = NULL */
93 }
94 return stoentry;
95 }
96 #endif /* !RUN_INT_RAM */
97
98 #ifndef RUN_INT_RAM
99 /*
100 +------------------------------------------------------------------------------
101 | Function : ccd_store_init
102 +------------------------------------------------------------------------------
103 | Description : This function initializes the entity's store entry
104 |
105 | Parameters : eentry - pointing to the entity's error entry
106 |
107 | Return : 1 in case of error, 0 otherwise
108 +------------------------------------------------------------------------------
109 */
110 int ccd_store_init (T_CCD_STORE_LIST** stoentry)
111 {
112 if (!*stoentry)
113 {
114 #if defined (CCD_TEST)
115 *stoentry = malloc (sizeof(T_CCD_STORE_LIST));
116 #else
117 *stoentry = D_ALLOC (sizeof(T_CCD_STORE_LIST));
118 #endif
119 }
120 if (*stoentry)
121 {
122 int i;
123 for (i = 0; i < 3; i++)
124 {
125 (*stoentry)->store[i] = 0;
126 }
127 /* for future use to extend register capacity */
128 /* (*stoentry)->next = NULL */
129 return 0;
130 }
131 return 1;
132 }
133 #endif /* !RUN_INT_RAM */
134
135 #ifndef RUN_INT_RAM
136 /*
137 +------------------------------------------------------------------------------
138 | Function : ccd_store_exit
139 +------------------------------------------------------------------------------
140 | Description : This function frees the task related store entry in
141 | ccd_task_list.
142 |
143 | Parameters : -
144 |
145 | Return : -
146 +------------------------------------------------------------------------------
147 */
148 void ccd_store_exit (void)
149 {
150 T_CCD_STORE_LIST** entry;
151 #if defined (CCD_TEST)
152 entry = &ccd_task_list[0]->ccd_store;
153 if (*entry)
154 {
155 /* for future use: This function frees the task related store list in case */
156 /* of extended register capacity */
157 /* ccd_sto_free(*stoentry); */
158 free (*entry);
159 }
160 #else
161 T_HANDLE me = vsi_e_handle (0, NULL);
162 if (me == VSI_ERROR)
163 me = 0;
164 entry = &ccd_task_list[me]->ccd_store;
165 if (*entry)
166 {
167 /* for future use: This function frees the task related store list in case */
168 /* of extended register capacity */
169 /* ccd_sto_free(*stoentry); */
170 D_FREE (*entry);
171 }
172 #endif
173 *entry = 0;
174 }
175 #endif /* !RUN_INT_RAM */
176
177 #ifndef RUN_INT_RAM
178 /*
179 +------------------------------------------------------------------------------
180 | Function : ccd_writeStore
181 +------------------------------------------------------------------------------
182 | Description : This function copies information to the register
183 | retaining its entries after CCD actions are finished.
184 |
185 | Parameters : globs - the current variable set
186 | regNo - to select one of the CCD STORE Registers
187 | value - information to write to CCD STORE Register
188 |
189 | Return : 1 in case of error, 0 otherwise
190 +------------------------------------------------------------------------------
191 */
192
193 UBYTE ccd_writeStore (T_CCD_Globs *globs, ULONG regNo, ULONG value)
194 {
195 T_CCD_STORE_LIST* it;
196 /*
197 #if defined (CCD_TEST)
198 it = ccd_task_list[0]->ccd_store;
199 #else
200 T_HANDLE me = vsi_e_handle (0, NULL);
201 if (me == VSI_ERROR)
202 me = 0;
203 it = ccd_task_list[me]->ccd_store;
204 #endif
205 */
206 it = ccd_task_list[globs->me]->ccd_store;
207
208 #ifdef DEBUG_CCD
209 TRACE_CCD (globs, "Writing %x to STO[%d] ", value, regNo);
210 #endif
211
212 if (regNo < 3)
213 {
214 if (!it)
215 {
216 it = ccd_store_alloc ();
217 }
218
219 if (it)
220 {
221 it->store[regNo] = value;
222 }
223
224 else
225 {
226 /* Memory allocation failed */
227 #ifdef DEBUG_CCD
228 TRACE_CCD (globs, "Memory allocation failed!");
229 #endif
230 return 1;
231 }
232 }
233
234 else
235 {
236 /* for future use: extended register capacity requested */
237 #ifdef DEBUG_CCD
238 TRACE_CCD (globs, "Invalid register number STO[%d] ", regNo);
239 #endif
240 return 1;
241 }
242
243 return 0;
244 }
245 #endif /* !RUN_INT_RAM */
246
247 #ifndef RUN_INT_RAM
248 /*
249 +------------------------------------------------------------------------------
250 | Function : ccd_setStore
251 +------------------------------------------------------------------------------
252 | Description : This function copies information from the user to the CCD
253 | STORE Register. It retains its entries after CCD actions
254 | are finished.
255 |
256 | Parameters : regNo - to select one of the CCD STORE Registers
257 | value - information to write to CCD STORE Register
258 |
259 | Return : 1 in case of error, 0 otherwise
260 +------------------------------------------------------------------------------
261 */
262
263 UBYTE ccd_setStore ( ULONG regNo, ULONG value)
264 {
265 T_CCD_Globs* entry;
266 #if defined (CCD_TEST)
267 entry = ccd_task_list[0]->ccd_globs;
268 #else
269 T_HANDLE me = vsi_e_handle (0, NULL);
270 if (me == VSI_ERROR)
271 me = 0;
272 entry = ccd_task_list[me]->ccd_globs;
273 entry->me = me;
274 #endif
275
276 return ccd_writeStore (entry, regNo, value);
277 }
278 #endif /* !RUN_INT_RAM */
279
280 #ifndef RUN_INT_RAM
281 /*
282 +------------------------------------------------------------------------------
283 | Function : ccd_getStore
284 +------------------------------------------------------------------------------
285 | Description : This function reads information from the CCD STORE Register
286 | and provides it to CCD.
287 | (CCD STORE Register retains its entries after CCD actions
288 | are finished.)
289 |
290 | Parameters : globs - the current variable set
291 | regNo - to select one of the CCD STORE Registers
292 | value - information to write to CCD STORE Register
293 |
294 | Return : 1 in case of error, 0 otherwise
295 +------------------------------------------------------------------------------
296 */
297
298 UBYTE ccd_getStore (T_CCD_Globs *globs, ULONG regNo, ULONG *value)
299 {
300 T_CCD_STORE_LIST* it = ccd_task_list[globs->me]->ccd_store;
301
302 #ifdef DEBUG_CCD
303 TRACE_CCD (globs, "Reading from STO[%d] ", regNo);
304 #endif
305
306 if (regNo < 3)
307 {
308 if (it)
309 {
310 *value = it->store[regNo];
311 }
312 else
313 {
314 #ifdef DEBUG_CCD
315 TRACE_CCD (globs, "No CCD STORE Register persent!");
316 #endif
317 return 1;
318 }
319 }
320
321 else
322 {
323 /* for future use: extended register capacity requested */
324 #ifdef DEBUG_CCD
325 TRACE_CCD (globs, "Invalid register number STO[%d] ", regNo);
326 #endif
327 return 1;
328 }
329
330 return 0;
331 }
332 #endif /* !RUN_INT_RAM */