comparison gpf/tst_pei/tst_pei.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: tst_pei.c
4 +------------------------------------------------------------------------------
5 | Copyright 2004 Texas Instruments Deutschland, AG
6 | All rights reserved.
7 |
8 | This file is confidential and a trade secret of Texas
9 | Instruments Berlin, AG
10 | The receipt of or possession of this file does not convey
11 | any rights to reproduce or disclose its contents or to
12 | manufacture, use, or sell anything it may describe, in
13 | whole, or in part, without the specific written consent of
14 | Texas Instruments Deutschland, AG.
15 +-----------------------------------------------------------------------------
16 | Purpose : This Modul contains the PEI interface of TST
17 +-----------------------------------------------------------------------------
18 */
19
20 #ifndef __TST_PEI_C__
21 #define __TST_PEI_C__
22 #endif
23
24 #define ENTITY_TST
25
26 /*==== INCLUDES ===================================================*/
27
28 #include <string.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31
32 #include "gpfconf.h"
33 #define _FF_RV_EXIST_ 1
34
35 #ifdef _TOOLS_
36 #include "frame_const.h"
37 #include <stdlib.h>
38 #endif /* _TOOLS_ */
39
40 #ifndef _TARGET_
41 #include "printtofile.h"
42 #endif
43
44 #include "typedefs.h"
45 #include "vsi.h"
46 #include "../frame/frame.h"
47 #include "pei.h"
48 #include "os.h"
49 #include "tools.h"
50 #include "gdi.h"
51 #include "os.h"
52 #include "frm_defs.h"
53 #include "frm_types.h"
54 #include "frm_glob.h"
55 #include "../frame/route.h"
56 #include "drvconf.h"
57 #include "tstdriver.h"
58 #include "tstheader.h"
59 #include "tst_mux.h"
60 #include "pcon.h"
61
62 #ifdef CTB
63 #include "tst_primitives.h"
64 #endif
65
66 #ifdef _PSOS_
67 #include "pna.h"
68 #endif
69
70 #ifdef _FF_RV_EXIST_
71 #include "../../services/ffs/ffs_api.h"
72 #endif
73
74 /*==== TYPES ======================================================*/
75
76 #undef VSI_CALLER
77 #ifdef _TOOLS_
78 #define VSI_CALLER TST_Handle,
79 #else
80 #define VSI_CALLER e_running[os_MyHandle()],
81 #endif
82
83 /*==== CONSTANTS ==================================================*/
84
85 #ifdef _VXWORKS_
86 #define TST_STACKSIZE 8192
87 #define TST_PRIORITY 190 /* priority (1->high, 255->low) */
88 #else
89 #ifdef _TOOLS_
90 #define TST_STACKSIZE 4096
91 #define TST_PRIORITY 15
92 #define TST_SND_PRIORITY 15 /* priority (1->low, 255->high) */
93 #define TST_RCV_PRIORITY 15 /* priority (1->low, 255->high) */
94 #else
95 #define TST_STACKSIZE 1024
96 #define TST_PRIORITY 2
97 #define TST_SND_PRIORITY 6 /* priority (1->low, 255->high) */
98 #define TST_RCV_PRIORITY 7 /* priority (1->low, 255->high) */
99 #endif
100 #endif
101
102 #ifdef _TOOLS_
103 #define TST_TIMERS 2
104 #define GET_STACK_TIME_TIMER_INDEX 0
105 #define GET_STACK_TIME_TIMER_DURATION 60000
106 #define TST_SYNC_TIMER_INDEX 1
107 #define TST_SYNC_TIMER_DURATION 2000
108 #else
109 #define TST_TIMERS 0
110 #endif
111
112 #ifdef _FF_RV_EXIST_
113 #define TRACEMASKFILE "/var/dbg/tracemask"
114 #endif
115
116 #define DRV_CALLBACK_OPC 0
117
118 #ifdef _TOOLS_
119 #define TR_RCV_BUF_SIZE (MAX_PRIM_PARTITION_SIZE)
120 #define TR_MAX_IND (TR_RCV_BUF_SIZE-1)
121 USHORT MaxEntities = MAX_ENTITIES;
122 #endif /* _TOOLS_ */
123
124 /*==== EXTERNALS ==================================================*/
125
126 #ifndef _TOOLS_
127 extern const T_PCON_PROPERTIES *pcon;
128 extern const USHORT TST_SndQueueEntries;
129 extern const USHORT TST_RcvQueueEntries;
130 extern const USHORT TST_SndStacksize;
131 extern const USHORT TST_RcvStacksize;
132 extern UBYTE FrameEnv;
133 #endif
134
135 #ifdef _TOOLS_
136 __declspec (dllimport) UBYTE SuppressOK;
137 #else
138 extern char *str2ind_version;
139 extern UBYTE SuppressOK;
140 #endif
141
142 #ifdef CTB
143 static T_HANDLE hCommIDLE = VSI_ERROR;
144 extern short idle_pei_create (T_PEI_INFO const ** info);
145 #endif
146
147 #ifdef _FF_RV_EXIST_
148 extern char TaskName[];
149 #endif
150
151 /*==== VARIABLES ==================================================*/
152
153 #ifndef RUN_INT_RAM
154
155 T_HANDLE TST_Handle;
156 T_HANDLE RCV_Handle;
157 T_HANDLE TIF_Handle;
158
159 UBYTE TST_DrvState = TST_DRV_DISCONNECTED;
160 static char const *ok_string = "OK";
161 static UBYTE frmenv;
162
163 #ifdef _TOOLS_
164 ULONG TR_RcvBufferSize = TR_RCV_BUF_SIZE;
165 ULONG TR_MaxInd = TR_MAX_IND;
166 int tst_syncronized = 0;
167 int tst_message_received = 0;
168 int tst_sync_timeout_cnt = 0;
169 int tst_max_sync_timeout = 0;
170 int tst_sync_mode = 0;
171 int tst_sync_sucess = 1;
172 int tst_sync_started = 0;
173 int tst_status_received = 0;
174 T_HANDLE tst_sync_req_handle = VSI_ERROR;
175 char sync_req_name[RESOURCE_NAMELEN];
176 char sync_req_time[16];
177
178 #endif /* _TOOLS_ */
179
180 GLOBAL USHORT tst_task_priority = TST_PRIORITY;
181 GLOBAL ULONG tst_task_stack_size = TST_STACKSIZE;
182
183 extern SHORT tst_pei_primitive (void *primitive);
184
185 #endif /* RUN_INT_RAM */
186
187 #ifdef RUN_INT_RAM
188
189 extern T_HANDLE TST_Handle;
190 extern T_HANDLE RCV_Handle;
191 extern T_HANDLE TIF_Handle;
192 extern UBYTE TST_DrvState;
193
194 #endif
195
196 #ifdef CTB
197 static char ctb_rcv[4];
198 static U32 ctb_remaining_tick_time=0;
199 BOOL ctb_tick_enabled = FALSE;
200 BOOL ctb_sent_to_tap = FALSE;
201 T_HANDLE idle_handle;
202 #endif
203
204 /*==== FUNCTIONS ==================================================*/
205
206 #ifndef RUN_FLASH
207 /*
208 +--------------------------------------------------------------------+
209 | PROJECT : GSM-GPF (8415) MODULE : TST_PEI |
210 | STATE : code ROUTINE : pei_primitive |
211 +--------------------------------------------------------------------+
212 */
213
214 SHORT tst_pei_primitive (void *primitive)
215 {
216 T_PRIM_HEADER *prim = (T_PRIM_HEADER*)primitive;
217 #ifndef _TOOLS_
218 T_VOID_STRUCT *prim_ptr = NULL;
219 #endif
220 SHORT ret = PEI_OK;
221
222 #ifdef _TOOLS_
223 if ( ((SAP_NR(prim->opc)==TRACE_SAP) || (prim->opc==TRACE_OPC)) && (P_SHO(prim)!=0) )
224 {
225 prim->opc = SYS_MASK;
226 }
227 #endif
228
229 if ( (SAP_NR(prim->opc)!=TRACE_SAP) && (prim->opc!=TRACE_OPC) && !(prim->opc & SYS_MASK) )
230 {
231 #ifndef _TOOLS_
232 prim_ptr = (T_VOID_STRUCT*)(((T_PRIM_X*)prim)->prim_ptr);
233 #endif
234 VSI_PPM_RCV(prim_ptr);
235 PTRACE_OUT(prim->opc );
236 }
237
238 if ( TST_DrvState == TST_DRV_CONNECTED )
239 {
240 if ( vsi_d_write ( TST_Handle, TIF_Handle, primitive, prim->len ) != VSI_OK )
241 ret = PEI_ERROR;
242 #ifdef _TOOLS_
243 vsi_t_sleep(TST_Handle,10);
244 #endif
245 }
246
247 #ifndef _TOOLS_
248 if ( prim_ptr != NULL )
249 {
250 FREE(P2D(prim_ptr));
251 }
252 #endif
253 vsi_trc_free (0, (T_VOID_STRUCT**)&prim);
254
255 return ( ret );
256 }
257 #endif
258
259 #ifndef RUN_INT_RAM
260 /*
261 +--------------------------------------------------------------------+
262 | PROJECT : GSM-GPF (8415) MODULE : TST_PEI |
263 | STATE : code ROUTINE : pei_init |
264 +--------------------------------------------------------------------+
265 */
266
267 LOCAL SHORT pei_init ( T_HANDLE handle )
268 {
269 #ifdef _TOOLS_
270 T_HANDLE h_pco;
271 #endif
272
273 #ifdef _FF_RV_EXIST_
274 T_HANDLE entityTraceMask;
275 ULONG actual;
276 T_FFS_FD fd;
277 T_RV_RETURN retPath;
278 BOOL gotAll = TRUE;
279 #endif
280
281 TST_Handle = handle;
282 #ifdef _TOOLS_
283 while (vsi_c_open (0, FRM_RCV_NAME) < VSI_OK)
284 {
285 vsi_t_sleep(0,100);
286 }
287 frmenv = (UBYTE) pf_get_frameenv ();
288 if ( os_OpenQueue (0, FRM_PCO_NAME, &h_pco) == OS_OK ||
289 os_create_extq (FRM_PCO_NAME, &h_pco) == OS_OK)
290 {
291 vsi_o_set_htrace (h_pco);
292 #ifdef _DEBUG
293 fprintf (stdout,"TST: %s commH set to %d\n", FRM_PCO_NAME,h_pco);
294 #endif
295 }
296 vsi_t_start ( handle, GET_STACK_TIME_TIMER_INDEX, GET_STACK_TIME_TIMER_DURATION );
297 #else
298 if ( vsi_c_open (TST_Handle, FRM_RCV_NAME) < VSI_OK )
299 return PEI_ERROR;
300 RCV_Handle = vsi_e_handle ( TST_Handle, FRM_RCV_NAME );
301 frmenv = FrameEnv;
302 #endif
303 #ifndef _TARGET_
304 initPrintToFile();
305 #endif
306 if ( vsi_d_init ( TST_Handle ) != VSI_OK )
307 {
308 #ifndef _TARGET_
309 printf("SYSTEM ERROR: Driver initialization failed\n");
310 vsi_o_assert ( TST_Handle, OS_SYST_ERR, __FILE__, __LINE__, "SYSTEM ERROR: Testinterface driver initialization failed" );
311 #else
312 ;
313 #endif
314 }
315 TIF_Handle = vsi_d_open ( TST_Handle, (char*)TIF_NAME );
316 vsi_d_setsignal ( TST_Handle, 0, DRV_SIGTYPE_READ|DRV_SIGTYPE_CONNECT|DRV_SIGTYPE_DISCONNECT);
317 vsi_d_setconfig ( TST_Handle, 0, NULL );
318 vsi_trcsuspend ( TST_Handle, TST_Handle, OS_NO_SUSPEND );
319 SuppressOK = FALSE;
320 tst_mux_init();
321
322 #ifdef _FF_RV_EXIST_
323 fd = ffs_open(TRACEMASKFILE, FFS_O_RDONLY);
324 if (fd < 0)
325 {
326 // could not open nor create /var/dbg/tracemask warning
327 vsi_o_ttrace(NO_TASK, TC_SYSTEM, "pei_init: no trace mask in FFS");
328 }
329 else
330 {
331 InitializeTrace();
332 TraceMask[0] = 0;
333 TraceMask[0] |= TC_SYSTEM|TC_ERROR;
334 for (entityTraceMask = 0; entityTraceMask < (MaxEntities + 1); entityTraceMask++)
335 {
336 actual = TraceMask[entityTraceMask];
337 if (ffs_read(fd, (void*)&TraceMask[entityTraceMask], sizeof(ULONG) ) != sizeof(ULONG) )
338 {
339 gotAll = FALSE;
340 }
341 else
342 {
343 if (entityTraceMask == 0) // first element
344 {
345 TraceMask[0] = 0;
346 TraceMask[0] |= TC_SYSTEM|TC_ERROR;
347 }
348 if (actual != TraceMask[entityTraceMask])
349 {
350 // not the default trace mask, generate warning
351 if ( vsi_e_name ( 0, entityTraceMask, TaskName ) == VSI_OK )
352 {
353 vsi_o_ttrace(NO_TASK, TC_SYSTEM, "pei_init: FFS trace mask gave 0x%08x for %s (default 0x%08x)", TraceMask[entityTraceMask], TaskName, actual);
354 }
355 }
356 }
357 }
358 }
359 ffs_close(fd);
360 if (!gotAll)
361 {
362 vsi_o_ttrace(NO_TASK, TC_SYSTEM, "pei_init: some trace masks can't be read from FFS");
363 }
364 #endif
365
366 return PEI_OK;
367 }
368 #endif
369
370
371
372 #ifndef RUN_INT_RAM
373 /*
374 +--------------------------------------------------------------------+
375 | PROJECT : GSM-GPF (8415) MODULE : TST_PEI |
376 | STATE : code ROUTINE : pei_exit |
377 +--------------------------------------------------------------------+
378 */
379
380 static SHORT pei_exit (void)
381 {
382 #ifdef _TOOLS_
383 T_HANDLE rcvh=vsi_p_handle (0, FRM_RCV_NAME);
384 if (rcvh > VSI_OK)
385 {
386 /* exit RCV process */
387 vsi_p_exit ( TST_Handle, vsi_p_handle (0, FRM_RCV_NAME));
388 }
389 /* exit all drivers */
390 vsi_d_exit ( TST_Handle, 0);
391 #endif /* _TOOLS_ */
392
393 return PEI_OK;
394 }
395 #endif
396
397 #ifndef RUN_INT_RAM
398 #ifdef _TOOLS_
399 /*
400 +--------------------------------------------------------------------+
401 | PROJECT : GSM-GPF (8415) MODULE : TST_PEI |
402 | STATE : code ROUTINE : pei_timeout |
403 +--------------------------------------------------------------------+
404 */
405
406 LOCAL SHORT pei_timeout (USHORT index)
407 {
408
409 switch ( index )
410 {
411 case GET_STACK_TIME_TIMER_INDEX:
412 #if 0
413 if ( tst_message_received == 1 )
414 {
415 tst_drv_write ( NO_TASK, SYS_MASK, FRM_TST_NAME, (char*)SYSPRIM_GET_STACK_TIME );
416 }
417 vsi_t_start ( VSI_CALLER GET_STACK_TIME_TIMER_INDEX, GET_STACK_TIME_TIMER_DURATION );
418 #endif
419 break;
420 case TST_SYNC_TIMER_INDEX:
421 if ( tst_sync_timeout_cnt++ >= tst_max_sync_timeout-1 )
422 {
423 T_HANDLE tif_handle;
424 T_VOID_STRUCT *ptr;
425
426 tst_status_received = 0;
427 tst_sync_timeout_cnt = 0;
428 tst_sync_mode = 0;
429 tst_sync_sucess = 0;
430 tif_handle = vsi_d_open ( TST_Handle, (char*)TIF_NAME );
431 vsi_d_setconfig ( TST_Handle, tif_handle, DISABLE_SYNC_MODE );
432 vsi_t_stop ( TST_Handle, TST_SYNC_TIMER_INDEX );
433 ptr = vsi_c_pnew ( sizeof(T_PRIM_HEADER)+strlen(SYSPRIM_TST_SYNC_REJ), 0x8000 FILE_LINE );
434 strcpy ( (char*)ptr, SYSPRIM_TST_SYNC_REJ );
435 vsi_c_psend ( tst_sync_req_handle, ptr );
436 }
437 else
438 {
439 if ( tst_syncronized == 0 )
440 {
441 T_HANDLE tif_handle;
442 tst_sync_sucess = 1;
443 tst_status_received = 0;
444 tif_handle = vsi_d_open ( TST_Handle, (char*)TIF_NAME );
445 vsi_d_setconfig ( TST_Handle, tif_handle, ENABLE_SYNC_MODE );
446 tst_drv_write ( NO_TASK, SYS_MASK, FRM_RCV_NAME, (char*)"TRACECLASS 0x10" );
447 vsi_t_sleep ( TST_Handle, 100 );
448 tst_drv_write ( NO_TASK, SYS_MASK, FRM_RCV_NAME, (char*)"STATUS TASK" );
449 vsi_t_start ( TST_Handle, TST_SYNC_TIMER_INDEX, TST_SYNC_TIMER_DURATION );
450 vsi_t_sleep ( TST_Handle, 200 );
451 tst_drv_write ( NO_TASK, SYS_MASK, FRM_RCV_NAME, (char*)"ROUTING" );
452 }
453 }
454 break;
455 default:
456 break;
457 }
458 return PEI_OK;
459 }
460 #endif
461 #endif
462
463 #ifndef RUN_INT_RAM
464 /*
465 +--------------------------------------------------------------------+
466 | PROJECT : GSM-GPF (8415) MODULE : TST_PEI |
467 | STATE : code ROUTINE : pei_signal |
468 +--------------------------------------------------------------------+
469 */
470 LOCAL SHORT pei_signal (ULONG SignalType, void *ptr)
471 {
472 /*
473 * the following line of code causes a warning on tms470 compiler, that cannot be avoided
474 * without changing the PEI interface. Warning will not cause a problem
475 */
476 T_VOID_STRUCT *sig_ptr = (T_VOID_STRUCT*)ptr;
477 T_PRIM_HEADER *prim;
478 T_S_HEADER *s_hdr;
479 T_HANDLE DestTaskHandle, DestComHandle;
480 T_HANDLE min, max, i;
481 unsigned int Length;
482 ULONG Suspend, TraceMask, OldTraceMask;
483 unsigned int Offset = 0;
484 char token[81];
485 UBYTE FreePrim = 1;
486 SHORT ret = PEI_OK;
487 USHORT processed = FALSE;
488
489 switch ( SignalType )
490 {
491 case DRV_SIGTYPE_READ:
492 VSI_PPM_RCV(sig_ptr);
493 if ( (prim = ((T_PRIM_X*)sig_ptr)->prim_ptr) != NULL )
494 {
495 VSI_PPM_RCV (prim);
496 s_hdr = (T_S_HEADER*)((ULONG*)prim + prim->sh_offset);
497 DestTaskHandle = vsi_e_handle ( TST_Handle, s_hdr->rcv );
498 if ( DestTaskHandle == VSI_ERROR )
499 {
500 if ( !strcmp ( "IRQ", s_hdr->rcv ) )
501 {
502 DestTaskHandle = 0;
503 OldTraceMask = TC_SYSTEM;
504 TraceMask = 0;
505 }
506 else
507 {
508 if ( !strcmp ( "SYST", s_hdr->rcv ) )
509 {
510 DestTaskHandle = 0;
511 vsi_gettracemask ( DestTaskHandle, 0, &OldTraceMask);
512 TraceMask = TC_SYSTEM;
513 }
514 else
515 {
516 OldTraceMask = 0;
517 TraceMask = 0;
518 }
519 }
520 }
521 else
522 {
523 /* to satisfy LINT */
524 OldTraceMask = 0;
525 TraceMask = 0;
526 }
527 if ( DestTaskHandle != VSI_ERROR )
528 {
529 if ( prim->opc & SYS_MASK )
530 {
531 Length = GetNextToken ((char*)(P2D(prim)), token, " #");
532 Offset = Length+1;
533 if ( frmenv == ENV_STACK )
534 {
535 /* Set Traceclass for non-frame tasks/HISRs */
536 if ( DestTaskHandle == 0 && !strcmp (token, SYSPRIM_TRACECLASS_TOKEN) )
537 {
538 Length = GetNextToken ((char *)(P2D(prim))+Offset, token, " #");
539 TraceMask = ASCIIToHex(token, CHARS_FOR_32BIT);
540 vsi_settracemask ( DestTaskHandle, 0, TraceMask|OldTraceMask); /* it is not allowed to switch of system traces */
541 sprintf ( token, "%s (%s %s)", ok_string, (char*)(P2D(prim)), s_hdr->rcv );
542 tst_drv_write ( NO_TASK, 0, NULL, token );
543 processed = TRUE;
544 }
545 if (!strcmp (token, SYSPRIM_TRC_SUSPEND))
546 {
547 processed = TRUE;
548 /*
549 * set suspend for traces to SUSPEND or NO_SUSPEND
550 */
551 Length = GetNextToken ((char *)(P2D(prim))+Offset, token, " #");
552 Offset += (Length+1);
553
554 if ( !strcmp ( token, "ALL" ) )
555 {
556 min = 1;
557 max = MaxEntities;
558 GetNextToken ((char *)(P2D(prim))+Offset, token, " #");
559 }
560 else
561 {
562 min = DestTaskHandle;
563 max = min;
564 }
565 if ( !strcmp ( token, "YES" ) )
566 Suspend = 0xffffffff;
567 else
568 Suspend = 0;
569
570 for ( i = min; i <= max; i++ )
571 vsi_trcsuspend ( TST_Handle, i, Suspend );
572 sprintf ( token, "%s (%s %s)", ok_string, (char*)(P2D(prim)), s_hdr->rcv );
573 tst_drv_write ( NO_TASK, 0, NULL, token );
574 }
575 else if (!strcmp (token, SYSPRIM_MEMCHECK_TOKEN))
576 {
577 processed = TRUE;
578 /*
579 * Memory Check
580 */
581 for ( i = 1; i <= MaxEntities; i++ )
582 {
583 if ( vsi_object_info (TST_Handle, OS_OBJTASK, (USHORT)i, token, sizeof(token)) != VSI_ERROR )
584 {
585 tst_drv_write ( NO_TASK, 0, NULL, token );
586 }
587 }
588 }
589 #ifdef CTB
590 #ifndef _TOOLS_
591 else if (!strcmp (token, SYSPRIM_TIMER_TICK_REQ))
592 {
593 processed = TRUE;
594 ctb_sent_to_tap = FALSE;
595 if(strlen(ctb_rcv)<3)
596 {
597 strcpy(ctb_rcv, P_SND(prim));
598 }
599 ctb_remaining_tick_time = P_TIME(prim); //The time parameter is sent in the time stap.
600 /*sprintf ( token, "Requesting ticking for %d from %s", ctb_remaining_tick_time, ctb_rcv);
601 tst_drv_write ( NO_TASK, 0, NULL, token );*/
602 PSIGNAL(hCommIDLE, IDLE_REQ, NULL);
603 }
604 else if (!strcmp (token, SYSPRIM_INT_TICK_MODE_REQ))
605 {
606 processed = TRUE;
607 if(ctb_tick_enabled)
608 {
609 vsi_p_delete (TST_Handle,idle_handle);
610 ctb_tick_enabled = FALSE;
611 ctb_sent_to_tap = FALSE;
612 sprintf ( token, "Disabling Common Timer Base");
613 ctb_rcv[0]='\0';
614 os_StartTicking();
615 }
616 else
617 sprintf ( token, "Common Timer Base already disabled");
618 tst_drv_write ( NO_TASK, 0, NULL, token );
619 if(!strcmp(P_SND(prim), "TAP"))
620 {
621 tst_drv_write ( NO_TASK, SYS_MASK, "TAP", "INT_TICK_MODE_CNF");
622 }
623 }
624 else if (!strcmp (token, SYSPRIM_EXT_TICK_MODE_REQ))
625 {
626 processed = TRUE;
627 if(!ctb_tick_enabled)
628 {
629 if ( (idle_handle = vsi_p_create (TST_Handle, idle_pei_create, NULL, 1)) == VSI_ERROR )
630 {
631 vsi_o_assert ( TST_Handle, OS_SYST_ERR, __FILE__, __LINE__, "CTB: Cannot create IDLE task" );
632 }
633 vsi_p_start (TST_Handle, idle_handle);
634 while ( (hCommIDLE = vsi_e_handle ( TST_Handle, "IDLE" ))<VSI_OK)
635 {
636 vsi_t_sleep(0,1000);
637 }
638 os_StopTicking();
639 sprintf ( token, "Enabling Common Timer Base");
640 ctb_tick_enabled = TRUE;
641 }
642 else
643 sprintf ( token, "Common Timer Base already enabled");
644 tst_drv_write ( NO_TASK, 0, NULL, token );
645 if(!strcmp(P_SND(prim), "TAP"))
646 {
647 char send_str[50];
648 char tmp_str[8];
649 //Get process id and put in this syst primitive.
650 strcpy(send_str,"EXT_TICK_MODE_CNF#");
651 _itoa(os_GetProcessId(), tmp_str, 10);
652 strcat(send_str, tmp_str);
653 tst_drv_write ( NO_TASK, SYS_MASK, "TAP", send_str);
654 }
655 }
656 #endif
657 #endif //CTB
658
659 #ifndef _TARGET_
660 else if (!strcmp (token, SYSPRIM_SUPPRESS_OK))
661 {
662 processed = TRUE;
663 SuppressOK = TRUE;
664 }
665 #endif
666 else if (!strcmp (token, SYSPRIM_GET_STACK_TIME))
667 {
668 processed = TRUE;
669 tst_drv_write ( NO_TASK, SYS_MASK, FRM_TST_NAME, (char*)SYSPRIM_IS_STACK_TIME );
670 }
671 else if (!strcmp (token, SYSPRIM_READ_ROUTING))
672 {
673 processed = TRUE;
674 i = 0;
675 while ( rt_RouteRead ( DestTaskHandle, token ) != RT_ERROR )
676 {
677 tst_drv_write ( NO_TASK, 0, NULL, token );
678 i++;
679 }
680 if ( !i )
681 {
682 sprintf ( token, "NO %s ROUTINGS STORED", s_hdr->rcv );
683 tst_drv_write ( NO_TASK, 0, NULL, token );
684 }
685 }
686 #ifndef _TOOLS_
687 else if (!strcmp (token, SYSPRIM_STR2IND_VERSION))
688 {
689 processed = TRUE;
690 tst_drv_write ( NO_TASK, 0, NULL, str2ind_version );
691 }
692 #endif
693 }
694 }
695 }
696 #ifdef _TOOLS_
697 else
698 {
699 /* synchronization with protocol stack */
700 if ( tst_sync_mode == 1 )
701 {
702 char *pos;
703 char task_status;
704 T_VOID_STRUCT *cmd_ptr;
705
706 pos = strstr ( (char*)(P2D(prim)), "Name:" );
707 if ( pos != NULL )
708 {
709 tst_sync_started = 1;
710 GetNextToken ((char *)(P2D(prim))+strlen("Name:"), token, " #");
711 if ( strcmp(token,FRM_RCV_NAME) && strcmp(token,FRM_TST_NAME) && strcmp(token,"EXTR") )
712 {
713 pos = strstr ( (char*)(P2D(prim)), "Stat:" );
714 if ( pos != NULL )
715 {
716 tst_status_received = 1;
717 task_status = atoi(pos+strlen("Stat:"));
718 if ( task_status != 6 )
719 {
720 tst_sync_sucess = 0;
721 }
722 }
723 }
724 }
725 else
726 {
727 if ( tst_sync_started == 1 )
728 {
729 pos = strstr ( (char*)(P2D(prim)), "ROUTING" );
730 if ( pos != NULL )
731 {
732 if ( tst_sync_sucess == 1 && tst_status_received == 1 )
733 {
734 T_HANDLE tif_handle = vsi_d_open ( TST_Handle, (char*)TIF_NAME );
735 vsi_d_setconfig ( TST_Handle, tif_handle, DISABLE_SYNC_MODE );
736 vsi_t_stop ( TST_Handle, TST_SYNC_TIMER_INDEX );
737 cmd_ptr = vsi_c_pnew ( sizeof(T_PRIM_HEADER)+strlen(SYSPRIM_TST_SYNC_CNF), 0x8000 FILE_LINE );
738 strcpy ( (char*)cmd_ptr, SYSPRIM_TST_SYNC_CNF );
739 vsi_o_ttrace ( TST_Handle, TC_TIMER, "SYNC DONE") ;
740 vsi_c_psend ( tst_sync_req_handle, cmd_ptr );
741 tst_sync_mode = 0;
742 tst_sync_timeout_cnt = 0;
743 tst_syncronized = 1;
744 }
745 }
746 }
747 }
748 }
749 }
750 #endif /* _TOOLS_ */
751 if ( processed == FALSE )
752 {
753 if ( ( DestComHandle = vsi_c_open ( TST_Handle, s_hdr->rcv ) ) != VSI_ERROR )
754 {
755 /* free carrier */
756 PFREE(P2D(sig_ptr));
757 FreePrim = 0;
758 vsi_c_psend (DestComHandle, (T_VOID_STRUCT*)P2D(prim) FILE_LINE_MACRO);
759 }
760 else
761 {
762 #ifndef _TOOLS_
763 if ( frmenv == ENV_STACK )
764 {
765 sprintf ( token, "SYSTEM WARNING: Receiver Process '%s' unknown", s_hdr->rcv );
766 tst_drv_write ( NO_TASK, 0, NULL, token );
767 ret = PEI_ERROR;
768 }
769 #endif /* _TOOLS_ */
770 /* free dyn_ptr if unknown receiver */
771 FREE(P2D(prim));
772 }
773 }
774 else
775 {
776 /* free dyn_ptr if processed in TST */
777 FREE(P2D(prim));
778 }
779 }
780
781 if ( FreePrim )
782 {
783 /* free carrier */
784 PFREE(P2D(sig_ptr));
785 }
786 break;
787 case DRV_SIGTYPE_CONNECT:
788 TST_DrvState = TST_DRV_CONNECTED;
789 #ifndef _TOOLS_
790 tst_drv_write ( NO_TASK, SYS_MASK, FRM_TST_NAME, (char*)SYSPRIM_IS_STACK_TIME );
791 tst_drv_write ( NO_TASK, 0, NULL, str2ind_version );
792 #endif
793 break;
794 case DRV_SIGTYPE_DISCONNECT:
795 TST_DrvState = TST_DRV_DISCONNECTED;
796 #ifdef _PSOS_
797 /* for pSOS: send empty message to TST */
798 if ( vsi_d_open ( TST_Handle, "SOCKET" ) != VSI_ERROR )
799 {
800 T_QMSG Message;
801 static T_HANDLE tst_handle = 0;
802
803 if( TST_Handle > 0 )
804 {
805 Message.MsgType = MSG_PRIMITIVE;
806 Message.Msg.Primitive.Prim = NULL;
807 Message.Msg.Primitive.PrimLen = 0;
808 #ifdef MEMORY_SUPERVISION
809 vsi_c_send (TST_Handle, TST_Handle, &Message, __FILE__, __LINE__);
810 #else
811 vsi_c_send (TST_Handle, TST_Handle, &Message);
812 #endif
813 }
814 }
815 #endif
816 break;
817 #ifdef CTB
818 case IDLE_CNF:
819 if(ctb_remaining_tick_time > 0 && ctb_tick_enabled && !ctb_sent_to_tap)
820 {
821 os_Tick();
822 PSIGNAL(hCommIDLE, IDLE_REQ, NULL);
823 ctb_remaining_tick_time = ctb_remaining_tick_time-50;
824 }
825 else
826 {
827 /*sprintf ( token, "Ticking finished - remaining time %d", ctb_remaining_tick_time);
828 tst_drv_write ( NO_TASK, 0, NULL, token );*/
829 if(!strcmp(ctb_rcv, "TAP"))
830 tst_drv_write ( NO_TASK, SYS_MASK, FRM_TST_NAME, SYSPRIM_IS_STACK_TIME ); //Synchronize time with tools
831 tst_drv_write ( NO_TASK, SYS_MASK, ctb_rcv, "TIMER_TICK_CNF");
832 }
833 break;
834 #endif
835 default:
836 sprintf ( token, "Unhandled PSIGNAL");
837 tst_drv_write ( NO_TASK, 0, NULL, token );
838 break;
839 }
840 return ( ret );
841 }
842 #endif
843
844 #ifndef RUN_INT_RAM
845 /*
846 +--------------------------------------------------------------------+
847 | PROJECT : GSM-GPF (8415) MODULE : TST_PEI |
848 | STATE : code ROUTINE : pei_config |
849 +--------------------------------------------------------------------+
850 */
851
852 LOCAL SHORT pei_config (char * inString)
853 {
854 T_HANDLE drv_handle;
855 char token[80];
856 unsigned int length, offset;
857 BOOL select = 0,config = 0;
858 T_TST_DRV_ENTRY *tst_drv_info;
859
860 length = GetNextToken (inString, token, " #");
861 offset = length+1;
862 if ( !strcmp ( token, "DRIVER") )
863 {
864 length = GetNextToken (inString+offset, token, " #");
865 offset += (length+1);
866 if ( !strcmp ( token, "FLUSH") )
867 {
868 vsi_d_flush ( TST_Handle, 0 );
869 }
870 if ( !strcmp ( token, "SELECT") )
871 {
872 select = 1;
873 }
874 if ( !strcmp ( token, "CONFIG") )
875 {
876 config = 1;
877 #ifdef _TOOLS_
878 tst_syncronized = 0;
879 #endif
880 }
881 length = GetNextToken (inString+offset, token, " #");
882 offset += (length+1);
883 if ( select )
884 {
885 #ifdef _TOOLS_
886 if ( !strcmp(NODRV_NAME,token) )
887 {
888 if ( tst_drv_open ( token, &tst_drv_info ) == VSI_ERROR ||
889 vsi_d_create ( TST_Handle, tst_drv_info ) == VSI_ERROR)
890 {
891 return PEI_ERROR;
892 }
893 PrintToFile("TST: all drivers unloaded\n");
894 }
895 else
896 #endif
897 {
898 /* check if driver is already loaded */
899 if ( (drv_handle = vsi_d_open ( TST_Handle, token )) == VSI_ERROR )
900 {
901 if ( tst_drv_open ( token, &tst_drv_info ) == VSI_ERROR ||
902 vsi_d_create ( TST_Handle, tst_drv_info ) == VSI_ERROR )
903 {
904 return PEI_ERROR;
905 }
906 }
907 else
908 {
909 #ifdef _TOOLS_
910 #ifdef _DEBUG
911 PrintToFile("TST: keeping %s loaded\n",token);
912 #endif
913 #endif
914 vsi_d_close( TST_Handle, drv_handle );
915 }
916 }
917 }
918 if ( config )
919 {
920 if ( ( drv_handle = vsi_d_open ( TST_Handle, token ) ) == VSI_ERROR )
921 {
922 return PEI_ERROR;
923 }
924 if (vsi_d_setconfig ( TST_Handle, drv_handle, inString+offset) != VSI_OK)
925 {
926 #ifdef _TOOLS_
927 char text[99];
928 _snprintf(text,98,"TST: Error configuring driver %s with \"%s\" :-(",token, inString+offset);
929 vsi_o_ttrace(NO_TASK, TC_SYSTEM, text);
930 #endif /* _TOOLS_ */
931 }
932 vsi_d_close( TST_Handle, drv_handle );
933 }
934 }
935 else if ( !strcmp ( token, "THIF") )
936 {
937 T_HANDLE tif_handle;
938 tif_handle = vsi_d_open ( TST_Handle, (char*)TIF_NAME );
939 length = GetNextToken (inString+offset, token, " #");
940 offset += (length+1);
941
942 if ( !strcmp ( token, "OPEN") )
943 {
944 vsi_d_setconfig ( TST_Handle, tif_handle, token );
945 }
946 else if ( !strcmp ( token, "CLOSE") )
947 {
948 vsi_d_setconfig ( TST_Handle, tif_handle, token );
949 }
950 }
951 #ifdef _TOOLS_
952 else if ( !strcmp ( token, SYSPRIM_TST_SYNC_REQ) )
953 {
954 T_HANDLE tif_handle;
955 unsigned int len;
956
957 len = GetNextToken (inString+offset, sync_req_name, " #");
958 offset += len;
959 len = GetNextToken (inString+offset, sync_req_time, " #");
960 tst_max_sync_timeout = (atoi(sync_req_time) - 1000)/TST_SYNC_TIMER_DURATION;
961
962 tst_sync_req_handle = vsi_c_open ( TST_Handle, sync_req_name );
963 if ( tst_sync_req_handle != VSI_ERROR )
964 {
965 if ( tst_syncronized == 0 )
966 {
967 tst_sync_started = 0;
968 tst_status_received = 0;
969 tst_sync_mode = 1;
970 tst_sync_sucess = 1;
971 tif_handle = vsi_d_open ( TST_Handle, (char*)TIF_NAME );
972 vsi_d_setconfig ( TST_Handle, tif_handle, ENABLE_SYNC_MODE );
973 tst_drv_write ( NO_TASK, SYS_MASK, FRM_RCV_NAME, (char*)"TRACECLASS 0x10" );
974 vsi_t_sleep ( TST_Handle, 100 );
975 tst_drv_write ( NO_TASK, SYS_MASK, FRM_RCV_NAME, (char*)"STATUS TASK" );
976 vsi_t_start ( TST_Handle, TST_SYNC_TIMER_INDEX, TST_SYNC_TIMER_DURATION );
977 vsi_t_sleep ( TST_Handle, 200 );
978 tst_drv_write ( NO_TASK, SYS_MASK, FRM_RCV_NAME, (char*)"ROUTING" );
979 }
980 }
981 }
982 #endif
983 #ifdef _FF_RV_EXIST_
984 else if ( !strcmp ( token, "TRACEMASK_IN_FFS") )
985 {
986 int amount;
987 T_FFS_FD fd;
988 T_FFS_RET ret;
989 T_FFS_SIZE written;
990 T_FFS_DIR dir;
991 BOOL writeFailed = FALSE;
992 if (vsi_e_handle ( TST_Handle, FRM_RCV_NAME ) == e_running[os_MyHandle()]) // config prim processing only allowed in RCV, not TST!
993 {
994 fd = ffs_open(TRACEMASKFILE, FFS_O_RDWR | FFS_O_CREATE | FFS_O_TRUNC);
995 if (fd < 0)
996 {
997 // could not open nor create /var/dbg/tracemask warning
998 vsi_o_ttrace(NO_TASK, TC_SYSTEM, "pei_config: could not open/create FFS trace mask, reason is 0x%x", fd);
999 }
1000 else
1001 {
1002 TraceMask[0] = 0;
1003 TraceMask[0] |= TC_SYSTEM|TC_ERROR;
1004 amount = sizeof(ULONG) * (MaxEntities + 1);
1005 written = ffs_write(fd, (void*)&TraceMask[0], amount);
1006 if (written != amount)
1007 {
1008 if (written >= 0)
1009 {
1010 amount -= written;
1011 vsi_o_ttrace(NO_TASK, TC_SYSTEM, "pei_config: writing to FFS, second try");
1012 written = ffs_write(fd, (void*)&TraceMask[0], amount);
1013 if (written != amount)
1014 {
1015 writeFailed = TRUE;
1016 }
1017 }
1018 else
1019 {
1020 writeFailed = TRUE;
1021 }
1022 }
1023 if (writeFailed)
1024 {
1025 vsi_o_ttrace(NO_TASK, TC_SYSTEM, "pei_config: ffs_write to FFS failed with 0x%x, did open with", written, fd);
1026 }
1027 else
1028 {
1029 if (ffs_fdatasync(fd) == EFFS_OK)
1030 {
1031 vsi_o_ttrace(NO_TASK, TC_SYSTEM, "pei_config: successfully written trace mask to FFS");
1032 }
1033 else
1034 {
1035 vsi_o_ttrace(NO_TASK, TC_SYSTEM, "pei_config: flushing FFS trace mask failed!");
1036 }
1037 }
1038 ffs_close(fd);
1039 }
1040 }
1041 }
1042 else if ( !strcmp ( token, "NO_TRACEMASK_IN_FFS") )
1043 {
1044 T_FFS_RET ret;
1045
1046 InitializeTrace();
1047 TraceMask[0] = 0;
1048 TraceMask[0] |= TC_SYSTEM|TC_ERROR;
1049 if (vsi_e_handle ( TST_Handle, FRM_RCV_NAME ) == e_running[os_MyHandle()]) // config prim processing only allowed in RCV, not TST!
1050 {
1051 ret = ffs_remove(TRACEMASKFILE);
1052 if (ret != EFFS_OK)
1053 {
1054 vsi_o_ttrace(NO_TASK, TC_SYSTEM, "pei_config: failed to remove FFS trace mask, reason is 0x%x", ret);
1055 }
1056 else
1057 {
1058 vsi_o_ttrace(NO_TASK, TC_SYSTEM, "pei_config: successfully removed FFS trace mask");
1059 }
1060 }
1061 }
1062 #endif
1063 return PEI_OK;
1064 }
1065 #endif
1066
1067 #ifndef RUN_INT_RAM
1068 GLOBAL SHORT tstsnd_pei_create ( T_PEI_INFO ** info)
1069 {
1070 static T_PEI_INFO data =
1071 { "TST",
1072 {
1073 pei_init,
1074 pei_exit,
1075 tst_pei_primitive,
1076 #ifdef _TOOLS_
1077 pei_timeout,
1078 #else
1079 NULL,
1080 #endif
1081 NULL,
1082 NULL,
1083 pei_config,
1084 NULL
1085 },
1086 TST_STACKSIZE,
1087 0,
1088 TST_SND_PRIORITY,
1089 TST_TIMERS,
1090 (PASSIVE_BODY|COPY_BY_REF|SYSTEM_PROCESS|TRC_NO_SUSPEND)
1091 };
1092
1093 #ifdef _TOOLS_
1094 data.QueueEntries = TST_QUEUE_ENTRIES;
1095 #else
1096 data.QueueEntries = TST_SndQueueEntries;
1097 /*
1098 * This way of setting the TST and RCV stacksize is chosen to keep it backwardscompatible,
1099 * i.e. not change the behavior if the stacksizes are not define in the configuration
1100 * file xxxconst.h.
1101 */
1102 if ( TST_SndStacksize > 0 )
1103 {
1104 data.StackSize = TST_SndStacksize;
1105 }
1106 if ( pcon != NULL )
1107 {
1108 data.StackSize += pcon->stack_offset;
1109 }
1110 #endif
1111 *info = &data;
1112 return PEI_OK;
1113 }
1114 #endif
1115
1116 #ifndef RUN_INT_RAM
1117 GLOBAL SHORT tstrcv_pei_create ( T_PEI_INFO ** info)
1118 {
1119 static T_PEI_INFO data =
1120 { "RCV",
1121 {
1122 NULL,
1123 NULL,
1124 NULL,
1125 NULL,
1126 pei_signal,
1127 NULL,
1128 pei_config,
1129 NULL
1130 },
1131 TST_STACKSIZE,
1132 0,
1133 TST_RCV_PRIORITY,
1134 TST_TIMERS,
1135 (PASSIVE_BODY|COPY_BY_REF|SYSTEM_PROCESS|TRC_NO_SUSPEND)
1136 };
1137
1138 #ifdef _TOOLS_
1139 data.QueueEntries = TST_QUEUE_ENTRIES;
1140 #else
1141 data.QueueEntries = TST_RcvQueueEntries;
1142 /*
1143 * This way of setting the TST and RCV stacksize is chosen to keep it backwardscompatible,
1144 * i.e. not change the behavior if the stacksizes are not define in the configuration
1145 * file xxxconst.h.
1146 */
1147 if ( TST_RcvStacksize > 0 )
1148 {
1149 data.StackSize = TST_RcvStacksize;
1150 }
1151 if ( pcon != NULL )
1152 {
1153 data.StackSize += pcon->stack_offset;
1154 }
1155 #endif
1156 *info = &data;
1157 return PEI_OK;
1158 }
1159 #endif
1160