comparison src/cs/services/atp/atp_uart_env.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: atp_uart_env.c */
4 /* */
5 /* Purpose: This file contains the functions used to: */
6 /* - get some information about the ATP-UART */
7 /* interface, such as its name or the memory */
8 /* requirements, */
9 /* - set the memory bank identifier dedicated to the */
10 /* ATP-UART interface, */
11 /* - initialize the ATP-UART interface, */
12 /* - activate the ATP-UART interface, */
13 /* - prepare the termination of the ATP-UART */
14 /* interface, */
15 /* - kill the ATP-UART interface. */
16 /* */
17 /* Note: None. */
18 /* */
19 /* Revision History: */
20 /* 10/04/01 Pascal Pompei */
21 /* - Create. */
22 /* */
23 /* (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved. */
24 /* */
25 /********************************************************************************/
26 #include "atp/atp_uart_i.h"
27 #include "atp/atp_uart_env.h"
28 #include "rvm/rvm_priorities.h"
29 #include "rvm/rvm_use_id_list.h"
30
31
32 /******************** GLOBAL ATP-UART INTERFACE CONTROL BLOCK *******************/
33 /* */
34 /* Define a pointer to the 'Global ATP-UART Interface Control Block'. */
35 T_ATP_UART_CTRL_BLK *gbl_atp_uart_ctrl_blk_p = NULL;
36
37
38 /********************************************************************************/
39 /* */
40 /* Function Name: atp_uart_get_info */
41 /* */
42 /* Purpose: This function gets some information about the ATP-UART */
43 /* interface, such as its name or the required resources. */
44 /* */
45 /* Input Parameters: */
46 /* info_software_entity_p - Points to the structure gathering information */
47 /* about the ATP-UART interface. */
48 /* */
49 /* Output Parameters: None. */
50 /* */
51 /* Global Parameters: None. */
52 /* */
53 /* Note: None. */
54 /* */
55 /* Revision History: */
56 /* 10/04/01 Pascal Pompei */
57 /* - Create. */
58 /* */
59 /********************************************************************************/
60 T_RVM_RETURN atp_uart_get_info (T_RVM_INFO_SWE *info_software_entity_p)
61 {
62
63 /*********************** atp_uart_get_info function begins **********************/
64
65 /* Get some information about the ATP-UART interface, such as its priority */
66 /* or the number of needed memory banks. */
67 info_software_entity_p->swe_type = RVM_SWE_TYPE_4;
68 ((info_software_entity_p->type_info).type4).stack_size = ATP_UART_STACK_SIZE;
69 ((info_software_entity_p->type_info).type4).priority = RVM_ATP_UART_TASK_PRIORITY;
70 ((info_software_entity_p->type_info).type4).nb_mem_bank = 0x01;
71
72 /* Get the name of the ATP-UART interface. */
73 strcpy (((info_software_entity_p->type_info).type4).swe_name,
74 ATP_UART_NAME);
75
76 /* Get the unique entity identifier assigned to the ATP-UART interface. */
77 ((info_software_entity_p->type_info).type4).swe_use_id = ATP_UART_USE_ID;
78
79 /* Get some information about the 'Memory Bank' assigned to the ATP-UART */
80 /* interface, such as its size or the corresponding watermarks. */
81 strcpy ((((info_software_entity_p->type_info).type4).mem_bank[0]).bank_name,
82 "ATP_UART");
83 ((((info_software_entity_p->type_info).type4).mem_bank[0]).initial_params).size = ATP_UART_MB_PRIM_SIZE;
84 ((((info_software_entity_p->type_info).type4).mem_bank[0]).initial_params).watermark = ATP_UART_MB_PRIM_WATERMARK;
85
86 /* Notify the 'Riviera Manager' of the callback functions to be used in */
87 /* order to run the ATP-UART interface. */
88 ((info_software_entity_p->type_info).type4).set_info = atp_uart_set_info;
89 ((info_software_entity_p->type_info).type4).init = atp_uart_init;
90 ((info_software_entity_p->type_info).type4).core = atp_uart_core;
91 ((info_software_entity_p->type_info).type4).stop = atp_uart_stop;
92 ((info_software_entity_p->type_info).type4).kill = atp_uart_kill;
93
94 /* Notify the 'Riviera Manager' of the fact that the ATP-UART interface */
95 /* requires to be layered above the AT Parser. */
96 ((info_software_entity_p->type_info).type4).nb_linked_swe = 0x01;
97 ((info_software_entity_p->type_info).type4).linked_swe_id[0] = ATP_USE_ID;
98 return (RVM_OK);
99
100 } /********************** End of atp_uart_get_info function *********************/
101
102
103 /********************************************************************************/
104 /* */
105 /* Function Name: atp_uart_set_info */
106 /* */
107 /* Purpose: This function sets the memory bank identifiers */
108 /* dedicated to the ATP-UART interface. */
109 /* */
110 /* Input Parameters: */
111 /* addr_id - Contains the unique address identifier assigned */
112 /* to the ATP-UART interface. */
113 /* return_path_p - Points to the information regarding return paths */
114 /* assigned to other linked software entities. */
115 /* mb_id_p - Points to the memory bank identifiers assigned to */
116 /* the ATP-UART interface. */
117 /* error_function_p - Function to be called in order to report any */
118 /* unrecoverable error. */
119 /* */
120 /* Output Parameters: None. */
121 /* */
122 /* Global Parameters: None. */
123 /* */
124 /* Note: None. */
125 /* */
126 /* Revision History: */
127 /* 10/04/01 Pascal Pompei */
128 /* - Create. */
129 /* */
130 /********************************************************************************/
131 T_RVM_RETURN atp_uart_set_info (T_RVF_ADDR_ID addr_id,
132 T_RV_RETURN return_path_p[],
133 T_RVF_MB_ID *mb_id_p,
134 T_RVM_CB_FUNC error_function_p)
135 {
136 /* Declare a local variable. */
137 T_RVF_MB_STATUS mb_status = RVF_GREEN;
138
139 /*********************** atp_uart_set_info function begins **********************/
140
141 /* Allocate memory required to store the 'Global ATP-UART Interface Control */
142 /* Block'. */
143 mb_status = rvf_get_buf (mb_id_p[0],
144 sizeof (T_ATP_UART_CTRL_BLK),
145 (T_RVF_BUFFER **) (&gbl_atp_uart_ctrl_blk_p));
146
147 /* If insufficient resources to properly run the ATP-UART interface, then */
148 /* report an internal memory error and abort. */
149 switch (mb_status)
150 {
151 case RVF_GREEN:
152 {
153
154 /* Initialize the 'Global ATP-UART Interface Control Block'. */
155 memset ((T_RVF_BUFFER *) (gbl_atp_uart_ctrl_blk_p),
156 0x00,
157 sizeof (T_ATP_UART_CTRL_BLK));
158
159 /* Store the memory bank identifier assigned to the ATP-UART */
160 /* interface. */
161 gbl_atp_uart_ctrl_blk_p->mb_id = mb_id_p[0];
162
163 /* Store the unique address identifier assigned to the ATP-UART */
164 /* interface. */
165 gbl_atp_uart_ctrl_blk_p->addr_id = addr_id;
166
167 /* Store the function to be called whenever any unrecoverable */
168 /* error occurs. */
169 gbl_atp_uart_ctrl_blk_p->error_function_p = error_function_p;
170 rvf_send_trace (" ATP-UART (env). 'atp_uart_set_info' succeeded ",
171 48,
172 NULL_PARAM,
173 RV_TRACE_LEVEL_DEBUG_LOW,
174 ATP_USE_ID);
175 break;
176 }
177 case RVF_YELLOW:
178 {
179 (void) rvf_free_buf ((T_RVF_BUFFER *) (gbl_atp_uart_ctrl_blk_p));
180 gbl_atp_uart_ctrl_blk_p = NULL;
181 }
182 default:
183 {
184 rvf_send_trace (" ATP-UART (env). 'atp_uart_set_info' failed ",
185 45,
186 NULL_PARAM,
187 RV_TRACE_LEVEL_WARNING,
188 ATP_USE_ID);
189 return (RVM_MEMORY_ERR);
190 }
191 }
192 return (RVM_OK);
193
194 } /********************** End of atp_uart_set_info function *********************/
195
196
197 /********************************************************************************/
198 /* */
199 /* Function Name: atp_uart_init */
200 /* */
201 /* Purpose: This function initializes the ATP-UART interface. */
202 /* */
203 /* Input Parameters: None. */
204 /* */
205 /* Output Parameters: None. */
206 /* */
207 /* Global Parameters: None. */
208 /* */
209 /* Note: None. */
210 /* */
211 /* Revision History: */
212 /* 10/04/01 Pascal Pompei */
213 /* - Create. */
214 /* */
215 /********************************************************************************/
216 T_RVM_RETURN atp_uart_init (void)
217 {
218
219 /************************* atp_uart_init function begins ************************/
220
221 /* Set the default name and handle assigned to the COM port. Note that the */
222 /* name must be a NULL-terminated string. */
223 (void) strcpy ((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).com_port_name,
224 ATP_UART_DEFAULT_COM_PORT_NAME);
225 (gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).com_port_handle = INVALID_HANDLE_VALUE;
226
227 /* Indicate that no virtual modem port is established with the AT Parser */
228 /* for now. */
229 (gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).virtual_modem_port_established = FALSE;
230 (gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).virtual_modem_port_mode = ATP_PORT_CMD_MODE;
231 (gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).control_signals = ATP_RX_FLOW_OFF;
232 rvf_send_trace (" ATP-UART (env). 'atp_uart_init' succeeded ",
233 44,
234 NULL_PARAM,
235 RV_TRACE_LEVEL_DEBUG_LOW,
236 ATP_USE_ID);
237 return (RVM_OK);
238
239 } /************************ End of atp_uart_init function ***********************/
240
241
242 /********************************************************************************/
243 /* */
244 /* Function Name: atp_uart_core */
245 /* */
246 /* Purpose: This function activates the ATP-UART interface. */
247 /* */
248 /* Input Parameters: None. */
249 /* */
250 /* Output Parameters: None. */
251 /* */
252 /* Global Parameters: None. */
253 /* */
254 /* Note: None. */
255 /* */
256 /* Revision History: */
257 /* 10/04/01 Pascal Pompei */
258 /* - Create. */
259 /* */
260 /********************************************************************************/
261 T_RVM_RETURN atp_uart_core (void)
262 {
263
264 /************************* atp_uart_core function begins ************************/
265
266 return (atp_uart_handle_msg ());
267
268 } /************************ End of atp_uart_core function ***********************/
269
270
271 /********************************************************************************/
272 /* */
273 /* Function Name: atp_uart_stop */
274 /* */
275 /* Purpose: This function prepares the termination of the ATP-UART */
276 /* interface. */
277 /* */
278 /* Input Parameters: None. */
279 /* */
280 /* Output Parameters: None. */
281 /* */
282 /* Global Parameters: None. */
283 /* */
284 /* Note: None. */
285 /* */
286 /* Revision History: */
287 /* 10/04/01 Pascal Pompei */
288 /* - Create. */
289 /* */
290 /********************************************************************************/
291 T_RVM_RETURN atp_uart_stop (void)
292 {
293
294 /************************* atp_uart_stop function begins ************************/
295
296 /* If the virtual modem port is opened with the AT Parser, then deactivate */
297 /* it first. If any error occurred, then call the function used whenever */
298 /* any unrecoverable error occurs and abort. */
299 if (((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).virtual_modem_port_established == TRUE) && \
300 (atp_close_port ((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).atp_id, \
301 ATP_UART_GSM_PORT_NB) != RV_OK))
302 {
303 ATP_UART_UNRECOVERABLE_ERROR (RVM_INTERNAL_ERR,
304 " ATP-UART (env). 'atp_uart_stop' failed ");
305 return (RVM_NOT_READY);
306 }
307
308 /* Then, if needed, deactivate the COM port currently in use. If any */
309 /* error occurred, then call the function used whenever any unrecoverable */
310 /* error occurs and abort. */
311 if (((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).com_port_handle != INVALID_HANDLE_VALUE) && \
312 (atp_uart_remove_com_port () != RV_OK))
313 {
314 ATP_UART_UNRECOVERABLE_ERROR (RVM_INTERNAL_ERR,
315 " ATP-UART (env). 'atp_uart_stop' failed ");
316 return (RVM_NOT_READY);
317 }
318
319 /* At last, withdraw the ATP-UART interface from the AT Parser. If any */
320 /* error occurred, then call the function used whenever any unrecoverable */
321 /* error occurs and abort. */
322 if (atp_dereg ((gbl_atp_uart_ctrl_blk_p->conn_ctrl_blk).atp_id) != RV_OK)
323 {
324 ATP_UART_UNRECOVERABLE_ERROR (RVM_INTERNAL_ERR,
325 " ATP-UART (env). 'atp_uart_stop' failed ");
326 return (RVM_NOT_READY);
327 }
328 rvf_send_trace (" ATP-UART (env). 'atp_uart_stop' succeeded ",
329 44,
330 NULL_PARAM,
331 RV_TRACE_LEVEL_DEBUG_LOW,
332 ATP_USE_ID);
333 return (RVM_OK);
334
335 } /************************ End of atp_uart_stop function ***********************/
336
337
338 /********************************************************************************/
339 /* */
340 /* Function Name: atp_uart_kill */
341 /* */
342 /* Purpose: This function kills the ATP-UART interface. */
343 /* */
344 /* Input Parameters: None. */
345 /* */
346 /* Output Parameters: None. */
347 /* */
348 /* Global Parameters: None. */
349 /* */
350 /* Note: None. */
351 /* */
352 /* Revision History: */
353 /* 10/04/01 Pascal Pompei */
354 /* - Create. */
355 /* */
356 /********************************************************************************/
357 T_RVM_RETURN atp_uart_kill (void)
358 {
359
360 /************************* atp_uart_kill function begins ************************/
361
362 /* Free the previously allocated memory required to store the 'Global */
363 /* ATP-UART Interface Control Block'. */
364 (void) rvf_free_buf ((T_RVF_BUFFER *) (gbl_atp_uart_ctrl_blk_p));
365 gbl_atp_uart_ctrl_blk_p = NULL;
366 rvf_send_trace (" ATP-UART (env). 'atp_uart_kill' succeeded ",
367 44,
368 NULL_PARAM,
369 RV_TRACE_LEVEL_DEBUG_LOW,
370 ATP_USE_ID);
371 return (RVM_OK);
372
373 } /************************ End of atp_uart_kill function ***********************/