comparison nuc-fw/nucleus/hic.c @ 79:947b1f473960

beginning of nuc-fw
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 11 Aug 2013 07:17:25 +0000
parents
children
comparison
equal deleted inserted replaced
78:2c266d4339ff 79:947b1f473960
1 /*************************************************************************/
2 /* */
3 /* Copyright Mentor Graphics Corporation 2002 */
4 /* All Rights Reserved. */
5 /* */
6 /* THIS WORK CONTAINS TRADE SECRET AND PROPRIETARY INFORMATION WHICH IS */
7 /* THE PROPERTY OF MENTOR GRAPHICS CORPORATION OR ITS LICENSORS AND IS */
8 /* SUBJECT TO LICENSE TERMS. */
9 /* */
10 /*************************************************************************/
11
12 /*************************************************************************/
13 /* */
14 /* FILE NAME VERSION */
15 /* */
16 /* hic.c Nucleus PLUS 1.14 */
17 /* */
18 /* COMPONENT */
19 /* */
20 /* HI - History Management */
21 /* */
22 /* DESCRIPTION */
23 /* */
24 /* This file contains the core routines for the History Management */
25 /* component. */
26 /* */
27 /* DATA STRUCTURES */
28 /* */
29 /* None */
30 /* */
31 /* FUNCTIONS */
32 /* */
33 /* HIC_Disable_History_Saving Disable history saving */
34 /* HIC_Enable_History_Saving Enable history saving */
35 /* HIC_Make_History_Entry_Service Make history entry service */
36 /* HIC_Make_History_Entry Make system history entry */
37 /* HIC_Retrieve_History_Entry Retrieve history entry */
38 /* */
39 /* DEPENDENCIES */
40 /* */
41 /* tc_extr.h Thread Control functions */
42 /* tm_extr.h Timer management functions */
43 /* hi_extr.h History functions */
44 /* */
45 /* HISTORY */
46 /* */
47 /* DATE REMARKS */
48 /* */
49 /* 03-01-1993 Created initial version 1.0 */
50 /* 04-19-1993 Verified version 1.0 */
51 /* 03-01-1994 Replaced void with VOID, */
52 /* modified protection logic, */
53 /* resulting in version 1.1 */
54 /* */
55 /* 03-18-1994 Verified version 1.1 */
56 /* 04-17-1996 updated to version 1.2 */
57 /* 03-24-1998 Released version 1.3. */
58 /* 03-26-1999 Released 1.11m (new release */
59 /* numbering scheme) */
60 /* 04-17-2002 Released version 1.13m */
61 /* 11-07-2002 Released version 1.14 */
62 /*************************************************************************/
63 #define NU_SOURCE_FILE
64
65 #include "in_defs.h" /* Initialization defines */
66 #include "tc_extr.h" /* Thread control functions */
67 #include "tm_extr.h" /* Timer functions */
68 #include "hi_extr.h" /* History functions */
69
70 /* Define external inner-component global data references. */
71
72 extern INT INC_Initialize_State;
73 extern INT HID_History_Enable;
74 extern INT HID_Write_Index;
75 extern INT HID_Read_Index;
76 extern INT HID_Entry_Count;
77 extern TC_PROTECT HID_History_Protect;
78
79
80 /* Define the actual history table. Note that this is defined in this file
81 in order to eliminate this table if none of the run-time history functions
82 are accessed. */
83
84 HI_HISTORY_ENTRY HIC_History_Table[HI_MAX_ENTRIES];
85
86
87 /*************************************************************************/
88 /* */
89 /* FUNCTION */
90 /* */
91 /* HIC_Disable_History_Saving */
92 /* */
93 /* DESCRIPTION */
94 /* */
95 /* This function disables the history saving function. */
96 /* */
97 /* CALLED BY */
98 /* */
99 /* Application */
100 /* */
101 /* CALLS */
102 /* */
103 /* TCT_Protect Protect history structures */
104 /* TCT_Unprotect Release history protection */
105 /* */
106 /* INPUTS */
107 /* */
108 /* None */
109 /* */
110 /* OUTPUTS */
111 /* */
112 /* None */
113 /* */
114 /* HISTORY */
115 /* */
116 /* DATE REMARKS */
117 /* */
118 /* 03-01-1993 Created initial version 1.0 */
119 /* 04-19-1993 Verified version 1.0 */
120 /* 03-01-1994 Replaced void with VOID, */
121 /* resulting in version 1.1 */
122 /* */
123 /* 03-18-1994 Verified version 1.1 */
124 /* */
125 /*************************************************************************/
126 VOID HIC_Disable_History_Saving(VOID)
127 {
128 NU_SUPERV_USER_VARIABLES
129
130 /* Switch to supervisor mode */
131 NU_SUPERVISOR_MODE();
132
133 /* Protect the history data structures. */
134 TCT_Protect(&HID_History_Protect);
135
136 /* Disable history saving by setting the enable flag to false. */
137 HID_History_Enable = NU_FALSE;
138
139 /* Release protection. */
140 TCT_Unprotect();
141
142 /* Return to user mode */
143 NU_USER_MODE();
144 }
145
146
147 /*************************************************************************/
148 /* */
149 /* FUNCTION */
150 /* */
151 /* HIC_Enable_History_Saving */
152 /* */
153 /* DESCRIPTION */
154 /* */
155 /* This function enables the history saving function. */
156 /* */
157 /* CALLED BY */
158 /* */
159 /* Application */
160 /* */
161 /* CALLS */
162 /* */
163 /* TCT_Protect Protect history structures */
164 /* TCT_Unprotect Release history protection */
165 /* */
166 /* INPUTS */
167 /* */
168 /* None */
169 /* */
170 /* OUTPUTS */
171 /* */
172 /* None */
173 /* */
174 /* HISTORY */
175 /* */
176 /* DATE REMARKS */
177 /* */
178 /* 03-01-1993 Created initial version 1.0 */
179 /* 04-19-1993 Verified version 1.0 */
180 /* 03-01-1994 Replaced void with VOID, */
181 /* resulting in version 1.1 */
182 /* */
183 /* 03-18-1994 Verified version 1.1 */
184 /* */
185 /*************************************************************************/
186 VOID HIC_Enable_History_Saving(VOID)
187 {
188 NU_SUPERV_USER_VARIABLES
189
190 /* Switch to supervisor mode */
191 NU_SUPERVISOR_MODE();
192
193 /* Protect the history data structures. */
194 TCT_Protect(&HID_History_Protect);
195
196 /* Enable history saving by setting the enable flag to true. */
197 HID_History_Enable = NU_TRUE;
198
199 /* Release protection. */
200 TCT_Unprotect();
201
202 /* Return to user mode */
203 NU_USER_MODE();
204 }
205
206
207 /*************************************************************************/
208 /* */
209 /* FUNCTION */
210 /* */
211 /* HIC_Make_History_Entry_Service */
212 /* */
213 /* DESCRIPTION */
214 /* */
215 /* This function makes an application entry in the history table. */
216 /* */
217 /* CALLED BY */
218 /* */
219 /* Application */
220 /* */
221 /* CALLS */
222 /* */
223 /* HIC_Make_History_Entry Make a history entry */
224 /* */
225 /* INPUTS */
226 /* */
227 /* param1 First history parameter */
228 /* param2 Second history parameter */
229 /* param3 Third history parameter */
230 /* */
231 /* OUTPUTS */
232 /* */
233 /* None */
234 /* */
235 /* HISTORY */
236 /* */
237 /* DATE REMARKS */
238 /* */
239 /* 03-01-1993 Created initial version 1.0 */
240 /* 04-19-1993 Verified version 1.0 */
241 /* */
242 /*************************************************************************/
243 VOID HIC_Make_History_Entry_Service(UNSIGNED param1,
244 UNSIGNED param2, UNSIGNED param3)
245 {
246 /* Call actual function to make the history entry. */
247 HIC_Make_History_Entry(NU_USER_ID, param1, param2, param3);
248 }
249
250
251
252 /*************************************************************************/
253 /* */
254 /* FUNCTION */
255 /* */
256 /* HIC_Make_History_Entry */
257 /* */
258 /* DESCRIPTION */
259 /* */
260 /* This function makes an entry in the next available location in */
261 /* the history table- if history saving is enabled. */
262 /* */
263 /* CALLED BY */
264 /* */
265 /* Application */
266 /* */
267 /* CALLS */
268 /* */
269 /* TCC_Current_HISR_Pointer Retrieve current HISR pointer*/
270 /* TCC_Current_Task_Pointer Retrieve current task pointer*/
271 /* TCT_Get_Current_Protect Pickup current protection */
272 /* TCT_Protect Protect history structures */
273 /* TCT_Set_Current_Protect Set current protection */
274 /* TCT_Unprotect Release history protection */
275 /* TCT_Unprotect_Specific Release history protection */
276 /* TMT_Retrieve_Clock Retrieve system clock */
277 /* */
278 /* INPUTS */
279 /* */
280 /* param1 First history parameter */
281 /* param2 Second history parameter */
282 /* param3 Third history parameter */
283 /* */
284 /* OUTPUTS */
285 /* */
286 /* None */
287 /* */
288 /* HISTORY */
289 /* */
290 /* DATE REMARKS */
291 /* */
292 /* 03-01-1993 Created initial version 1.0 */
293 /* 04-19-1993 Verified version 1.0 */
294 /* 03-01-1994 Modified protection logic, */
295 /* resulting in version 1.1 */
296 /* */
297 /* 03-18-1994 Verified version 1.1 */
298 /* */
299 /*************************************************************************/
300 VOID HIC_Make_History_Entry(DATA_ELEMENT id, UNSIGNED param1,
301 UNSIGNED param2, UNSIGNED param3)
302 {
303 TC_PROTECT *save_protect; /* Save protect pointer */
304 HI_HISTORY_ENTRY *pointer; /* Quick access pointer */
305 NU_SUPERV_USER_VARIABLES
306
307 /* Switch to supervisor mode */
308 NU_SUPERVISOR_MODE();
309
310 /* If we are not in initialization, get the current protection state */
311 if (INC_Initialize_State == INC_END_INITIALIZE)
312
313 /* Pickup current protection. */
314 save_protect = TCT_Get_Current_Protect();
315
316 else
317 /* we are in initialization, just clear save_protect */
318 save_protect = 0;
319
320 /* Protect the history data structures. */
321 TCT_Protect(&HID_History_Protect);
322
323 /* Determine if history saving is enabled. */
324 if (HID_History_Enable)
325 {
326
327 /* Yes, history saving is enabled. */
328
329 /* Build a pointer to the next location to write to in the table. */
330 pointer = &HIC_History_Table[HID_Write_Index];
331
332 /* Place the necessary information into the history table at the
333 current location. */
334 pointer -> hi_id = id;
335 pointer -> hi_param1 = param1;
336 pointer -> hi_param2 = param2;
337 pointer -> hi_param3 = param3;
338 pointer -> hi_time = TMT_Retrieve_Clock();
339
340 /* Now determine what thread we are currently in. */
341 if ((pointer -> hi_thread =
342 (VOID *) TCC_Current_Task_Pointer()) != NU_NULL)
343
344 /* Task thread. Set the caller flag accordingly. */
345 pointer -> hi_caller = HI_TASK;
346
347 else if ((pointer -> hi_thread =
348 (VOID *) TCC_Current_HISR_Pointer()) != NU_NULL)
349
350 /* HISR thread. Set the caller flag accordingly. */
351 pointer -> hi_caller = HI_HISR;
352
353 else
354
355 /* Neither a task or HISR, it caller must be initialization. */
356 pointer -> hi_caller = HI_INITIALIZE;
357
358 /* Move the write index. */
359 HID_Write_Index++;
360
361 /* Check for a wrap condition on the write index. */
362 if (HID_Write_Index >= HI_MAX_ENTRIES)
363
364 /* Wrap condition present, adjust the write index to the top of the
365 table. */
366 HID_Write_Index = 0;
367
368 /* Increment the entries counter, if the maximum has not yet been
369 reached. */
370 if (HID_Entry_Count < HI_MAX_ENTRIES)
371
372 /* Increment the total entries counter. */
373 HID_Entry_Count++;
374 else
375
376 /* Drag the read index along with the write index. */
377 HID_Read_Index = HID_Write_Index;
378 }
379
380 /* Determine if there was protection in force before call. */
381 if (save_protect)
382 {
383
384 /* Make saved protection the current again. */
385 TCT_Set_Current_Protect(save_protect);
386
387 /* Release the history protection. */
388 TCT_Unprotect_Specific(&HID_History_Protect);
389 }
390 else
391
392 /* Release protection. */
393 TCT_Unprotect();
394
395 /* Return to user mode */
396 NU_USER_MODE();
397 }
398
399
400 /*************************************************************************/
401 /* */
402 /* FUNCTION */
403 /* */
404 /* HIC_Retrieve_History_Entry */
405 /* */
406 /* DESCRIPTION */
407 /* */
408 /* This function retrieves the next oldest entry in the history */
409 /* table. If no more entries are available, an error status is */
410 /* returned. */
411 /* */
412 /* CALLED BY */
413 /* */
414 /* Application */
415 /* */
416 /* CALLS */
417 /* */
418 /* TCT_Protect Protect history structures */
419 /* TCT_Unprotect Release history protection */
420 /* */
421 /* INPUTS */
422 /* */
423 /* id Destination for entry id */
424 /* param1 Destination for parameter 1 */
425 /* param2 Destination for parameter 2 */
426 /* param3 Destination for parameter 3 */
427 /* time Destination for time of entry*/
428 /* task Destination of task pointer */
429 /* hisr Destination of hisr pointer */
430 /* */
431 /* OUTPUTS */
432 /* */
433 /* None */
434 /* */
435 /* HISTORY */
436 /* */
437 /* DATE REMARKS */
438 /* */
439 /* 03-01-1993 Created initial version 1.0 */
440 /* 04-19-1993 Verified version 1.0 */
441 /* */
442 /*************************************************************************/
443 STATUS HIC_Retrieve_History_Entry(DATA_ELEMENT *id, UNSIGNED *param1,
444 UNSIGNED *param2, UNSIGNED *param3,
445 UNSIGNED *time, NU_TASK **task,
446 NU_HISR **hisr)
447 {
448
449 STATUS status; /* Completion status */
450 HI_HISTORY_ENTRY *pointer; /* Quick access pointer */
451 NU_SUPERV_USER_VARIABLES
452
453 /* Switch to supervisor mode */
454 NU_SUPERVISOR_MODE();
455
456 /* Initialize status. */
457 status = NU_SUCCESS;
458
459 /* Protect the history data structures. */
460 TCT_Protect(&HID_History_Protect);
461
462 /* Determine if there is an entry in the history log. */
463 if (HID_Entry_Count)
464 {
465
466 /* Yes, there is at least one entry in the history log. */
467
468 /* Build a pointer to the next location to read from in the table. */
469 pointer = &HIC_History_Table[HID_Read_Index];
470
471 /* Place the necessary information into the history table at the
472 current location. */
473 *id = pointer -> hi_id;
474 *param1 = pointer -> hi_param1;
475 *param2 = pointer -> hi_param2;
476 *param3 = pointer -> hi_param3;
477 *time = pointer -> hi_time;
478
479 /* Now determine what thread the entry was made from. */
480 if (pointer -> hi_caller == HI_TASK)
481 {
482
483 /* Setup the task return parameter. */
484 *task = (NU_TASK *) pointer -> hi_thread;
485 *hisr = NU_NULL;
486 }
487 else
488 {
489
490 /* In either HISR or initialize case place the thread value
491 in the HISR return parameter. */
492 *hisr = (NU_HISR *) pointer -> hi_thread;
493 *task = NU_NULL;
494 }
495
496 /* Move the read index. */
497 HID_Read_Index++;
498
499 /* Check for a wrap condition on the read index. */
500 if (HID_Read_Index >= HI_MAX_ENTRIES)
501
502 /* Wrap condition present, adjust the read index to the top of the
503 table. */
504 HID_Read_Index = 0;
505
506 /* Decrement the entries counter. */
507 HID_Entry_Count--;
508 }
509 else
510
511 /* Return the end of history log status. */
512 status = NU_END_OF_LOG;
513
514 /* Release protection. */
515 TCT_Unprotect();
516
517 /* Return to user mode */
518 NU_USER_MODE();
519
520 /* Return completion status to the caller. */
521 return(status);
522 }
523
524
525
526