comparison gsm-fw/services/dar/dar_task.c @ 305:4dccc9d3305f

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