comparison services/dar/dar_task.c @ 0:75a11d740a02

initial import of gsm-fw from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 09 Jun 2016 00:02:41 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:75a11d740a02
1 /****************************************************************************/
2 /* */
3 /* File Name: dar_task.c */
4 /* */
5 /* Purpose: This function is the main function. It contains the dar_core */
6 /* which waits for messages or function calls. */
7 /* */
8 /* */
9 /* Version 0.1 */
10 /* */
11 /* Date Modification */
12 /* ------------------------------------ */
13 /* 16 October 2001 Create */
14 /* */
15 /* Author Stephanie Gerthoux */
16 /* */
17 /* (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved*/
18 /****************************************************************************/
19
20 #include "../../riviera/rv/rv_defined_swe.h"
21 #ifdef RVM_DAR_SWE
22 #ifndef _WINDOWS
23 #include "../../include/config.h"
24 #endif
25
26 #include <string.h>
27 #include "../../riviera/rvm/rvm_gen.h"
28 #include "../../riviera/rvm/rvm_use_id_list.h"
29 #include "dar_api.h"
30 #include "dar_macro_i.h"
31 #include "dar_handle_message.h"
32 #include "dar_structs_i.h"
33 #include "dar_error_hdlr_i.h"
34 #include "dar_const_i.h"
35
36 #include "../ffs/ffs_api.h"
37
38 /* Variables definitions */
39 T_DAR_RECOVERY_STATUS status=0;
40
41 /**** Global variables ****/
42 /* Define a pointer to the Global Environment Control block */
43 extern T_DAR_ENV_CTRL_BLK *dar_gbl_var_p;
44
45 /* Write buffer*/
46 extern char dar_write_buffer[DAR_MAX_BUFFER_SIZE];
47
48 /* index used in the circular buffer*/
49 extern UINT16 dar_current_index;
50
51 /* DAR previous status : to get the status of the last exception */
52 extern UINT8 dar_previous_exception;
53
54 /* Ram buffer that contains the Debug Unit register */
55 extern UINT32 debug_RAM[DEBUG_UNIT_WORD_SIZE];
56
57 /* X_dump buffer defined in the command file */
58 /* This buffer contains the general register, the PC, the CPSR....*/
59 #ifndef _WINDOWS
60 extern INT32 xdump_buffer;
61 #endif
62
63
64 /***************************************************************************/
65 /* Function dar_core */
66 /* */
67 /* Description Core of the dar task, which scans the dar mailbox and */
68 /* waits for messages. When a message arrives, it sends it*/
69 /* to proper functions */
70 /* */
71 /* */
72 /***************************************************************************/
73
74 T_RV_RET dar_core(void)
75 {
76 /* Declare local variables */
77 /**** Structs ****/
78 /* File descriptor type */
79 T_FFS_FD ffs_fd;
80
81 /* Variables */
82 T_RV_RET error_status = RV_OK;
83 T_RV_HDR *msg_p = NULL;
84 UINT16 received_event = 0x0000;
85 char dar_ffs[20];
86 char dar_dir_ffs[20];
87 char dar_subdir_ffs[20];
88 BOOL dar_ffs_error = FALSE;
89
90 #ifndef _WINDOWS
91 /* Define the Link register and the CPSR */
92 INT32 *link_register_p = &(xdump_buffer) + 14;
93 INT32 *dar_spsr_p = &(xdump_buffer) + 16;
94 UINT16 i;
95 #endif
96
97 /* Dar_ffs file name */
98 strcpy(dar_dir_ffs,"/var");
99 strcpy(dar_subdir_ffs,"/var/dbg");
100
101 #ifndef _WINDOWS
102 strcpy(dar_ffs,"/var/dbg/dar");
103 #else
104 strcpy(dar_ffs,"\var\dbg\dar");
105 #endif
106
107 DAR_SEND_TRACE("DAR_TASK started",RV_TRACE_LEVEL_DEBUG_HIGH);
108
109 /*---------------------------------*/
110 /* FFS */
111 /*---------------------------------*/
112
113 /**** create the dar ffs directories ****/
114 if ((ffs_mkdir(dar_dir_ffs) != EFFS_OK) && (ffs_mkdir(dar_dir_ffs) != EFFS_EXISTS))
115 {
116 DAR_SEND_TRACE("DAR entity can't create the '/var' folder into the flash",RV_TRACE_LEVEL_ERROR);
117 }
118
119 if ((ffs_mkdir(dar_subdir_ffs) != EFFS_OK) && (ffs_mkdir(dar_subdir_ffs) != EFFS_EXISTS))
120 {
121 DAR_SEND_TRACE("DAR entity can't create the '/var/dbg' folder into the flash",RV_TRACE_LEVEL_ERROR);
122 }
123
124
125 /**** create the ffs file ****/
126 ffs_fd = ffs_open(dar_ffs, FFS_O_CREATE | FFS_O_WRONLY | FFS_O_TRUNC | FFS_O_APPEND);
127
128 if (ffs_fd < 0)
129 {
130 DAR_SEND_TRACE("DAR entity has received wrong file name or the flash is not formatted",RV_TRACE_LEVEL_WARNING);
131 dar_ffs_error = TRUE;
132 }
133
134 #ifndef _WINDOWS
135
136 /**** Save the RAM buffer into the FFS ****/
137 /* save the buffer in 2 parts in order to have the information in chronological order */
138 /* save the oldest information : from dar_current_index to the end of the buffer*/
139 if ((ffs_write (ffs_fd,
140 (void *)(&dar_write_buffer + dar_current_index),
141 (DAR_MAX_BUFFER_SIZE - dar_current_index))) < 0 & (dar_ffs_error == FALSE))
142 {
143 DAR_SEND_TRACE("DAR entity can't saved the file in flash",RV_TRACE_LEVEL_WARNING);
144 }
145
146 /* save the rest of information: from the beginning of the buffer to dar_current_index */
147 if ((ffs_write (ffs_fd,
148 (void *)(&dar_write_buffer),
149 (dar_current_index))) < 0 & (dar_ffs_error == FALSE))
150 {
151 DAR_SEND_TRACE("DAR entity can't saved the file in flash",RV_TRACE_LEVEL_WARNING);
152 }
153
154 /* Erase the dar_write_buffer */
155 for (i=0;i<DAR_MAX_BUFFER_SIZE; i++)
156 {
157 dar_write_buffer[i] = 0;
158 }
159
160 /**** Save the X_dump_buffer into the Flash. ****/
161 /* This buffer is defined in the command file */
162 /* And the size of this buffer is defined in the gsm_cs_amd4_lj3_test.cmd */
163 /* its size is 38*32 bits = 38*4 bytes = 152 bytes */
164 if ((ffs_write (ffs_fd,
165 (void *)(&xdump_buffer),
166 (DAR_X_DUMP_BUFFER_SIZE))) < 0 & (dar_ffs_error == FALSE))
167 {
168 DAR_SEND_TRACE("DAR entity can't saved the X_dump_buffer in flash",RV_TRACE_LEVEL_WARNING);
169 }
170
171 /**** Save the Debug Unit Register into the Flash if necessary (Abort or prefetch)****/
172 /* A Prefetch abort exception or a data abort exception is generated */
173 #if ((CHIPSET == 7) || (CHIPSET == 8) || (CHIPSET == 10) || (CHIPSET == 11))
174 if ((dar_previous_exception == DAR_EXCEPTION_PREFETCH_ABORT) ||
175 (dar_previous_exception == DAR_EXCEPTION_DATA_ABORT))
176 {
177 /* Save the Debug Unit into the Flash */
178 if ((ffs_write (ffs_fd,
179 (void *) &debug_RAM,
180 (4*DEBUG_UNIT_WORD_SIZE))) < 0 & (dar_ffs_error == FALSE))
181 {
182 DAR_SEND_TRACE("DAR entity can't saved the DEBUG UNIT in flash",RV_TRACE_LEVEL_WARNING);
183 }
184 }
185 #endif
186
187 #else
188 /* save the buffer in 2 parts in order to have the information in chronological order */
189 /* save the oldest information : from dar_current_index to the end of the buffer*/
190 if ((ffs_write (ffs_fd,
191 (&dar_write_buffer + dar_current_index),
192 (DAR_MAX_BUFFER_SIZE - dar_current_index))) != EFFS_OK)
193 {
194 DAR_SEND_TRACE("DAR entity can't saved the file in flash",RV_TRACE_LEVEL_WARNING);
195 }
196 /* save the rest of information: from the beginning of the buffer to dar_current_index */
197 if ((ffs_write (ffs_fd,
198 (&dar_write_buffer),
199 (dar_current_index))) != EFFS_OK)
200 {
201 DAR_SEND_TRACE("DAR entity can't saved the file in flash",RV_TRACE_LEVEL_WARNING);
202 }
203 /* The X_dump_buffer and the Debug Unit can't be saved on the PC */
204 #endif
205
206 /* Close the ffs file*/
207 #ifndef _WINDOWS
208 if ( ffs_close(ffs_fd) != EFFS_OK & (dar_ffs_error == FALSE))
209 {
210 DAR_SEND_TRACE("DAR entity has not closed the file",RV_TRACE_LEVEL_WARNING);
211 }
212 #else
213 if ( ffs_close(ffs_fd) != EFFS_OK )
214 {
215 dar_error_trace(DAR_ENTITY_FILE_NO_CLOSE);
216 }
217 #endif
218
219 #ifndef _WINDOWS
220 /**** Save the LR and the SPSR when an exception has occured ****/
221 if ((dar_previous_exception == DAR_EXCEPTION_PREFETCH_ABORT)||
222 (dar_previous_exception == DAR_EXCEPTION_DATA_ABORT) ||
223 (dar_previous_exception == DAR_EXCEPTION_UNDEFINED) ||
224 (dar_previous_exception == DAR_EXCEPTION_SWI) ||
225 (dar_previous_exception == DAR_EXCEPTION_RESERVED))
226 {
227 /* Displays the Link register saved on exception */
228 DAR_SEND_TRACE_PARAM("Link register = ", *link_register_p,RV_TRACE_LEVEL_DEBUG_HIGH);
229
230 /* Displays the User mode CPSR saved on exception */
231 DAR_SEND_TRACE_PARAM("User mode SPSR before the exception=", *dar_spsr_p,RV_TRACE_LEVEL_DEBUG_HIGH);
232 }
233
234 /* Displays the status of the last reset of the system */
235 dar_recovery_get_status(&status);
236 #endif
237
238 /* ------------------------------------------- */
239 /* loop to process messages */
240 /* ------------------------------------------- */
241 while (error_status == RV_OK)
242 {
243 /* Wait for all events. */
244 received_event = rvf_wait(DAR_ALL_EVENT_FLAGS, DAR_NOT_TIME_OUT);
245
246 if (received_event & DAR_TASK_MBOX_EVT_MASK)
247 {
248 /* Read the message in the Dar mailbox and handle it. */
249 msg_p = (T_RV_HDR *) rvf_read_mbox(DAR_MBOX);
250 error_status = dar_handle_msg(msg_p);
251 }
252 }
253
254 /* If one of the occured events is unexpected (due to an unassigned */
255 /* mailbox), then report an internal error. */
256 if (received_event & ~(DAR_TASK_MBOX_EVT_MASK ))
257 {
258 DAR_SEND_TRACE(" DAR ERROR (env). One of the occured events is unexpected ",
259 RV_TRACE_LEVEL_ERROR);
260
261 error_status = RV_NOT_SUPPORTED;
262 }
263
264 /* If a memory error happened .. */
265 if (error_status == RV_MEMORY_ERR)
266 {
267 dar_gbl_var_p->callBackFctError("DAR",
268 RVM_MEMORY_ERR,
269 0,
270 " Memory Error : the DAR primitive memory bank is RED ");
271 }
272
273 return RV_OK;
274 } /* dar_core */
275
276 #endif /* #ifdef RVM_DAR_SWE */