/[PAMELA software]/quicklook/dataToXML/Data/compilationInfo/src/BasicSW/Bus1553B/BI_Bus1553B_int.c
ViewVC logotype

Annotation of /quicklook/dataToXML/Data/compilationInfo/src/BasicSW/Bus1553B/BI_Bus1553B_int.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download)
Tue Apr 25 09:00:20 2006 UTC (19 years, 2 months ago) by kusanagi
Branch point for: MAIN
File MIME type: text/plain
Initial revision

1 kusanagi 1.1 /****************************************************************************
2     /* F i l e D a t a
3     /*
4     /* Module : BasicSW
5     /* C.I. No. :
6     /* $Revision: 1.12 $
7     /* $Date: 2005/03/06 14:51:24 $
8     /* Belonging to :
9     /* :
10     /* $RCSfile: BI_Bus1553B_int.c,v $
11     /* Program Type :
12     /* Sub-modules :
13     /*
14     /****************************************************************************
15     /* S W D e v e l o p m e n t E n v i r o n m e n t
16     /*
17     /* Host system :
18     /* SW Compiler :
19     /* $Author: sebastiani $
20     /* :
21     /****************************************************************************
22     /* U p d a t i n g
23     /*
24     /* $Log: BI_Bus1553B_int.c,v $
25     /* Revision 1.12 2005/03/06 14:51:24 sebastiani
26     /* *** empty log message ***
27     /*
28     /* Revision 1.11 2004/12/03 10:05:54 faber
29     /* GAS SYSTEM: this must be zero as agreed in document protocol PAM. R1d1-346bis-04 (russian)
30     /*
31     /* Revision 1.10 2004/12/02 09:53:58 faber
32     /* GAS System Bit in CCA zeroed as agreed in russian document PAM. R1d1-346bis-04
33     /*
34     /* Revision 1.9 2004/11/10 16:59:55 sebastiani
35     /* - GS_COMPILE directive introduced and be undef by default
36     /* - automatic flush mechanism by run manager mailbox timeout
37     /*
38     /* Revision 1.8 2004/07/27 17:30:17 faber
39     /* OBT can be now in second or milliseconds, depending of the situazion.
40     /* OBT_s is used for FM compatibility, OBT_ms basically for MM infos
41     /*
42     /* Revision 1.7 2004/02/05 11:16:07 sebastiani
43     /* file size in CCA is now in MByte
44     /*
45     /* Revision 1.6 2003/12/11 11:35:47 sebastiani
46     /* IPM error bit managerment
47     /*
48     /* Revision 1.5 2003/12/11 10:53:36 alfarano
49     /* update
50     /*
51     /* Revision 1.4 2003/12/01 09:27:16 sebastiani
52     /* CCA info for Gas Module and first implementation of IPM infos.
53     /*
54     /* Revision 1.3 2003/11/18 09:01:14 alfarano
55     /* laben patch fixes some problems
56     /*
57     /* Revision 1.2 2003/09/10 13:47:47 laben
58     /* delete reference to file2
59     /* need to fix the format CCA.
60     /*
61     /* Revision 1.1.1.1 2003/08/04 09:40:21 sebastiani
62     /* Imported sources laben rel. 19.06.2003 integrated with pam2
63     /*
64     /* Revision 1.12 2003/02/26 17:21:33 aurora
65     /* fixed remap descriptor block for mode codes (brd)
66     /*
67     /* Revision 1.11 2003/02/26 16:23:42 zulia
68     /* fixed remap descriptor block for mode codes
69     /*
70     /* Revision 1.10 2002/11/06 15:48:00 zulia
71     /* Correct 1553 ack bug
72     /*
73     /* Revision 1.9 2002/08/01 08:12:12 aurora
74     /* Check on TT MAX length added
75     /*
76     /* Revision 1.8 2002/05/15 13:55:53 zulia
77     /* Modified to return MCMD ID and
78     /* Source Sequence Counter in case of MCMD validation error
79     /*
80     /* Revision 1.7 2002/05/15 13:13:09 aurora
81     /* Modified to return MCMD ID and
82     /* Source Sequence Counter in case of MCMD validation error
83     /*
84     /* Revision 1.6 2002/05/09 08:16:33 zulia
85     /* * acceptance release
86     /*
87     /*
88     /*****************************************************************************/
89    
90     #include <src/BasicSW/Bus1553B/BI_Bus1553B_int.h>
91     #include <src/MCMDManager/MCMDArea/MA_MCMDArea_p.h>
92     #include <src/MCMDManager/TTManager/MT_TTManager_p.h>
93     #include <src/HKManager/HistoryArea/HA_HistoryArea_p.h>
94     #include <src/MCMDManager/MCMDDispatcher/MD_MCMDDispatcher_p.h>
95     #include <src/HKManager/ReportGenerator/RG_ReportGenerator_p.h>
96     #include <src/FileManager/FileSystem/FS_FileSystem_p.h>
97    
98     #include <src/BasicSW/TimingInfo/TI_TimingInfo_p.h>
99    
100     #include <src/INFN/GS_Gas_INFN.h>
101     #include <src/INFN/PWR_PowerHandler_INFN.h>
102    
103    
104     /*============================== Local Variables ============================*/
105     /*****************************************************************************/
106     /* @Variable: legalTable */
107     /* @Purpose : */
108     /* LEGAL_DATA type */
109     /* Array of structures to store informations for opened descriptors */
110     /* @@ */
111     /*****************************************************************************/
112     LEGAL_DATA legalTable [NUM_OF_DESC_BLK_ID];
113    
114     /*****************************************************************************/
115     /* @Variable: sumRtDescrPointerReg */
116     /* @Purpose : */
117     /* unsigned int* type */
118     /* Pointer to the SuMMIT Descriptor Pointer Register */
119     /* @@ */
120     /*****************************************************************************/
121     static unsigned int* sumRtDescrPointerReg = (unsigned int*)SUM_RTDPR_ADRS;
122    
123     /*****************************************************************************/
124     /* @Variable: sumIllegalizationReg */
125     /* @Purpose : */
126     /* unsigned int* type */
127     /* Pointer to the SuMMIT Illegalization Register */
128     /* @@ */
129     /*****************************************************************************/
130     static unsigned int* sumIllegalizationReg = (unsigned int*)SUM_ILLGR_ADRS;
131    
132     /*****************************************************************************/
133     /* @Variable: exgMemoryAreaAdrs */
134     /* @Purpose : */
135     /* unsigned int* type */
136     /* Pointer to the SuMMIT Exchange Memory Area (Area 0) */
137     /* @@ */
138     /*****************************************************************************/
139     static unsigned int* exgMemoryAreaAdrs = (unsigned int*)EXG_MEM_ADRS_AREA0;
140    
141     /*****************************************************************************/
142     /*===== I N T E R N A L F U N C T I O N S =====*/
143     /*****************************************************************************/
144    
145     /*****************************************************************************/
146     /* @Function: BI_ifSuMMITRTDrv */
147     /* @Purpose : */
148     /* The function initialize SuMMIT as SRT device driver and sets */
149     /* */
150     /* @@ */
151     /* @Parameter Name @Mode @Description */
152     /* rtAdrs IN Value of the Remote Terminal Address */
153     /* status_1553 OUT Return code */
154     /* @@ */
155     /*****************************************************************************/
156    
157     status_1553 BI_ifSuMMITRTDrv(unsigned int rtAdrs )
158     {
159     int i, j;
160     status_1553 ret_code = BI_OK;
161    
162     if (rtAdrs < NUM_OF_RT_ADRS)
163     {
164     /* Control Register */
165     /* set enhanced mode number 1 */
166     /* interrupt log list enable */
167     /* channel A (bus A) and channel B (bus B) enable */
168     /* transmit status word */
169     /* register value: 0x9993 */
170     *(unsigned int*)SUM_CTRLR_ADRS = START_EXEC_BIT |
171     SRT_EN_MODE_2 |
172     INT_LOG_LIST_ENABLE|
173     CHAN_A_ENABLE |
174     CHAN_B_ENABLE |
175     BROADCAST_ENABLE |
176     TX_STATUS_WORD_ENABLE;
177    
178     /*Operational Status Register */
179     /* set remote terminal mode of operation */
180     /* set remote terminal address */
181     /* remote terminal address parity bit enable */
182     // no RT_PARITY_BIT_ENABLE;
183     *(unsigned int*)SUM_OPSTR_ADRS = SRT_OP_MODE | (rtAdrs << 11);
184    
185     /* Interrupt Mask Register */
186     *(unsigned int*)SUM_INTMR_ADRS = REG_IRQ_MASK_VALUE;
187    
188     /* Interrupt Log List Pointer Register */
189     /* set location of the Interrupt Log List within */
190     /* a 64k memory space */
191     *(unsigned int*)SUM_ILLPR_ADRS = REG_IRQ_LOG_LIST_PTR_VALUE;
192    
193     /* RT Descriptor Pointer Register */
194     /* set location to start the Descriptor Table within */
195     /* a 64k memory space */
196     /* Interrupt Log List resides in a 32-word ring buffer */
197     *sumRtDescrPointerReg = NUM_OF_ILL_WORDS;//=32 subaddrs;
198    
199     /* Status Word Bits Register */
200     /* immediate clear function enable */
201     *(unsigned int*)SUM_STWBR_ADRS = IMCLRF_ENABLE;
202    
203     /* Illegalization Registers */
204     /* illegalization of all subaddress/mode code */
205     /* (logical 1 = illegal in illegalization registers) */
206     for (i = 0; i < 16; i++)
207     {
208     *(sumIllegalizationReg + i) = 0xFFFF;
209     }
210    
211     /* initialize legalization table to use in BI_ifSuMMITRTDbLegalize() */
212     for (i = 0; i < NUM_OF_DESC_BLK_ID; i += 32)
213     {
214     for (j = 0; j < 32; j++)
215     {
216     legalTable[i+j].blkType = i/32;
217     legalTable[i+j].subAdrs = j;
218     }
219     }
220     }
221     else
222     {
223     ret_code = BI_RT_ADRS_ERROR;
224     }
225    
226     return ret_code;
227     }
228    
229    
230     /*****************************************************************************/
231     /* @Function: BI_ifSuMMITRTDbLegalize */
232     /* @Purpose : */
233     /* This routine legalizes subaddress/mode code of a specified block */
234     /* */
235     /* @@ */
236     /* @Parameter Name @Mode @Description */
237     /* blkType IN Receive or Transmit type block */
238     /* subAdrs IN subaddress */
239     /* int OUT Block descriptor index */
240     /* @@ */
241     /*****************************************************************************/
242    
243     int BI_ifSuMMITRTDbLegalize(unsigned int blkType, unsigned int subAdrs)
244     {
245     int i, block_idx = 0;
246    
247     /* Set the correct legalization bit for the specified subaddress */
248     if ((subAdrs >= 0) && (subAdrs <= 15))
249     {
250     *(unsigned int *)((unsigned int)sumIllegalizationReg + blkType * BLK_SIZE) &=
251     ~(1 << subAdrs);
252     }
253     else if ((subAdrs >= 16) && (subAdrs <= 31))
254     {
255     *(unsigned int *)((unsigned int)sumIllegalizationReg + blkType * BLK_SIZE +
256     BLK_SIZE / 2) &= ~(1 << (subAdrs - 16));
257     }
258     /* Evaluate the subuddress descriptor block index */
259     for (i = 0; i < NUM_OF_DESC_BLK_ID; i++)
260     {
261     if ((legalTable[i].blkType == blkType) && (legalTable[i].subAdrs == subAdrs))
262     {
263     /* If a broadcast subaddress/modecode is specified, remap it to the */
264     /* same non-broadcast desctiptor block index */
265     if(i < BI_RXTX_END_BLOCK)
266     {
267     block_idx = i;
268     }
269     else if(i < BI_BDC_RXTX_END_BLOCK)
270     /* Subaddress is broadcast tx/rx */
271     {
272     block_idx = i - BI_BDC_RXTX_OFS;
273     }
274     else if(i < BI_MC_TXRX_END_BLOCK)
275     /* Subaddress is Mode code tx/rx */
276     {
277     block_idx = i;
278     }
279     else
280     {
281     block_idx = i - BI_BRMC_TXRX_OFS;
282     }
283     }
284     }
285    
286     return block_idx;
287     }
288    
289    
290     /*****************************************************************************/
291     /* @Function: BI_ifSuMMITRTDbGet */
292     /* @Purpose : */
293     /* This routine retrieves the descriptor block related to the specified */
294     /* subaddress identifier */
295     /* */
296     /* @@ */
297     /* @Parameter Name @Mode @Description */
298     /* descblkId IN Identifier of the descriptor block (0..255) */
299     /* db OUT descriptor block structure */
300     /* @@ */
301     /*****************************************************************************/
302    
303     unsigned int* BI_ifSuMMITRTDbGet( unsigned int descblkId, DESC_BLK* db )
304     {
305     unsigned int* pexg = (unsigned int*)0;
306    
307     if( descblkId < NUM_OF_DESC_BLK_ID )
308     {
309     // computes the address of the specified descriptor
310     pexg = exgMemoryAreaAdrs + (*sumRtDescrPointerReg>>16) + descblkId*4;
311     db->ctrlWord = pexg[0] >> 16;
312     db->topAdrs = pexg[1] >> 16;
313     db->currentAdrs = pexg[2] >> 16;
314     db->mib = pexg[3] >> 16;
315     }
316    
317     return pexg;
318     }
319    
320    
321     /*****************************************************************************/
322     /* @Function: BI_ifSuMMITRTGetDataAddress */
323     /* @Purpose : */
324     /* This routine retrieves the pointer of the descriptor block related to */
325     /* the specified subaddress identifier */
326     /* */
327     /* @@ */
328     /* @Parameter Name @Mode @Description */
329     /* descblkId IN Identifier of the descriptor block (0..255) */
330     /* @@ */
331     /*****************************************************************************/
332     unsigned int* BI_ifSuMMITRTGetDataAddress(unsigned int descblkId)
333     {
334     unsigned int* pexg = (unsigned int*)0;
335    
336     if( descblkId < NUM_OF_DESC_BLK_ID )
337     {
338     /* computes the address of the specified descriptor */
339     pexg = exgMemoryAreaAdrs + (*sumRtDescrPointerReg>>16) + descblkId*4;
340     pexg = exgMemoryAreaAdrs + (pexg[1] >> 16);
341     }
342    
343     return pexg;
344     }
345    
346    
347     /*****************************************************************************/
348     /* @Function: BI_ifSuMMITRTDbWrite */
349     /* @Purpose : */
350     /* This routine writes a descriptor block related to the specified */
351     /* subaddress identifier */
352     /* */
353     /* @@ */
354     /* @Parameter Name @Mode @Description */
355     /* descblkId IN Identifier of the descriptor block (0..255) */
356     /* db IN descriptor block structure */
357     /* DESC_BLK* OUT returns the descriptor block memory address */
358     /* @@ */
359     /*****************************************************************************/
360    
361     DESC_BLK* BI_ifSuMMITRTDbWrite(unsigned int descblkId, DESC_BLK db)
362     {
363     DESC_BLK* pdb = (DESC_BLK*)0;
364    
365     if( descblkId < NUM_OF_DESC_BLK_ID )
366     {
367     /* computes the address of the specified descriptor */
368     pdb = (DESC_BLK*)(exgMemoryAreaAdrs + (*sumRtDescrPointerReg>>16) + descblkId*4);
369     pdb->ctrlWord = db.ctrlWord;
370     pdb->topAdrs = db.topAdrs;
371     pdb->currentAdrs = db.currentAdrs;
372     pdb->mib = db.mib;
373     }
374    
375     return pdb;
376     }
377    
378    
379     /*****************************************************************************/
380     /* @Function: BI_ifSuMMITRTPacketRead */
381     /* @Purpose : */
382     /* This routine copies a number of 16 bit words from 1553 exchange memory */
383     /* (at the address of the corrispondent descriptor block) to RAM memory. */
384     /* */
385     /* @@ */
386     /* @Parameter Name @Mode @Description */
387     /* descblkId IN Identifier of the descriptor block (0..255) */
388     /* memRAM IN pointer to the RAM memory to be copied */
389     /* numWords16 IN number of 16 bit words to be copied */
390     /* status_1553 OUT return code */
391     /* @@ */
392     /*****************************************************************************/
393     status_1553 BI_ifSuMMITRTPacketRead( unsigned int descblkId, unsigned short* memRAM, unsigned int numWords16 )
394     {
395     status_1553 status = BI_OK;
396     unsigned int* memExg;
397     DESC_BLK DescBlk;
398    
399    
400     if ( descblkId >= NUM_OF_DESC_BLK_ID )
401     {
402     status = BI_DESC_BLK_ID_ERROR;
403     }
404     else
405     {
406     memExg = BI_ifSuMMITRTGetDataAddress(descblkId); // gets the address of data of the i-th descriptor
407    
408     if( memExg )
409     {
410     while( numWords16 ) // copies the data into RAM
411     {
412     *memRAM = (unsigned short int)(*memExg >> 16); // only 16MSB are significative
413     memRAM++;
414     memExg++;
415     numWords16--;
416     }
417     }
418     else
419     {
420     status = BI_DATA_BOUNDARY_ERROR;
421     }
422     }
423    
424     return status;
425     }
426    
427    
428     /*****************************************************************************/
429     /* @Function: BI_ifSuMMITRTRegRead */
430     /* @Purpose : */
431     /* This routine reads a SuMMIT register */
432     /* */
433     /* @@ */
434     /* @Parameter Name @Mode @Description */
435     /* regId IN offset of the register (0..31) */
436     /* reg OUT register */
437     /* status_1553 OUT return code */
438     /* @@ */
439     /*****************************************************************************/
440    
441     status_1553 BI_ifSuMMITRTRegRead(unsigned int regId, unsigned int *reg )
442     {
443     status_1553 ret_code = BI_OK;
444    
445     /* check register offset */
446     if (regId >= NUM_OF_SUMMIT_REG)
447     {
448     ret_code = BI_OFFSET_ERROR;
449     }
450     else
451     {
452     *reg = *((unsigned int*)SUM_REG_ADRS + regId) >> 16;
453     }
454     return ret_code;
455     }
456    
457     /*****************************************************************************/
458     /* @Function: BI_if1553BLoadMCMD */
459     /* @Purpose : */
460     /* This routine loads a Macrocommand performing the low level check of the */
461     /* MCMD Identifier, MCMD length, MCMD checksum */
462     /* */
463     /* @@ */
464     /* @Parameter Name @Mode @Description */
465     /* subaddId IN Identifier of the descriptor block (0..255) */
466     /* BI_1553MCMDBuffer OUT Buffer of the MCMD */
467     /* BI_1553MCMDACKWord OUT Buffer of the Acknowledge word */
468     /* status_1553 OUT return code */
469     /* @@ */
470     /*****************************************************************************/
471     status_code BI_if1553BLoadMCMD( unsigned int subaddId,
472     unsigned short int* BI_1553MCMDBuffer,
473     unsigned short int* BI_1553MCMDACKWord )
474     {
475     status_code status;
476     unsigned int nwords16, nwords16exg, ttFlag;
477     DESC_BLK db;
478     unsigned int checksum, i;
479     unsigned int mcmdType,
480     mcmdId;
481     unsigned char* pbyte;
482     MsgTsk sndMsg;
483     MA_HEADER_MCMD mcmdHeader;
484     int mcmdttag_direct;
485     TI_TIME obtime;
486     unsigned int* pexg;
487    
488    
489     status = SUCCESSFUL;
490    
491     BI_ifSuMMITRTDbGet( subaddId, &db );
492    
493     pexg = BI_ifSuMMITRTGetDataAddress( subaddId ); /* pexg points to the data area of RSA20 */
494    
495     nwords16 = nwords16exg = 0;
496    
497     if( db.currentAdrs > db.topAdrs )
498     {
499     nwords16 = db.currentAdrs - db.topAdrs;
500     nwords16exg =(pexg[2]>>16) & 0x0FFF;
501     ttFlag =(pexg[1]>>31);
502    
503     /* checks the Identifier RS2-040 */
504     mcmdId = (pexg[1]>>16) & 0xFF;
505    
506     MA_piGetMCMDType(mcmdId, &mcmdType);
507    
508     /* Verify MCMD identifier */
509     if( mcmdType == NULL_MCMD )
510     {
511     status = UNSATISFIED;
512     BI_1553MCMDACKWord[0] |= BI_MCMD_NOT_OK | BI_MCMD_WRONG_IDENTIFIER;
513     }
514     else
515     {
516     /* verifies the words loaded */
517     if ( nwords16 != nwords16exg ||
518     nwords16 > BI_MAX_MCMD_LENGTH ||
519     (ttFlag && nwords16 > BI_MAX_TT_MCMD_LENGTH) ||
520     MA_piGetMCMDLenght(mcmdType,nwords16) != SUCCESSFUL)
521     {
522     status = UNSATISFIED;
523     BI_1553MCMDACKWord[0] |= BI_MCMD_NOT_OK | BI_MCMD_WRONG_WORD_NUMBER;
524     }
525     else
526     {
527     BI_ifSuMMITRTPacketRead(subaddId, BI_1553MCMDBuffer, nwords16);
528     if( BI_1553MCMDBuffer[1] & BI_MCMD_TT_MASK )
529     {
530     BI_1553MCMDACKWord[0] |= BI_MCMD_IS_TIMETAGGED;
531     }
532     mcmdHeader.Type = mcmdType;
533    
534     // verifies the checksum
535     checksum = 0;
536     for (i=0, pbyte = (unsigned char*)BI_1553MCMDBuffer; i<2*(nwords16-1); pbyte++, i++)
537     {
538     checksum += *pbyte;
539     }
540    
541     if( (checksum & 0xFF) != (BI_1553MCMDBuffer[nwords16-1] & 0xFF) )
542     {
543     status = UNSATISFIED;
544     BI_1553MCMDACKWord[0] |= BI_MCMD_NOT_OK | BI_MCMD_CHECKSUM_ERROR;
545     }
546     }
547     }
548    
549     }
550     else
551     {
552     status = UNSATISFIED;
553     BI_1553MCMDACKWord[0] |= BI_MCMD_NOT_OK | BI_MCMD_WRONG_WORD_NUMBER;
554     }
555    
556     if( !(BI_1553MCMDACKWord[0] & BI_MCMD_NOT_OK) )
557     {
558     if( BI_1553MCMDBuffer[1] & BI_MCMD_TT_MASK )
559     {
560     mcmdHeader.TimeTag = BI_1553MCMDBuffer[3]<<16 | BI_1553MCMDBuffer[4];
561     mcmdttag_direct = TIMETAG_MCMD;
562     sndMsg.Code = MT_STORE_TIMETAG_MCMD;
563     }
564     else
565     {
566     mcmdHeader.TimeTag = 0;
567     mcmdttag_direct = IMMEDIATE_MCMD;
568     sndMsg.Code = MD_MCMD_EXEC;
569     }
570    
571     mcmdHeader.Length = BI_1553MCMDBuffer[2] & 0x0FFF;
572    
573     //INFN_PATCH if( MA_piGetBufferMCMD(&mcmdHeader.PtrMCMD, mcmdttag_direct, WAIT, NO_TIMEOUT)
574     if( MA_piGetBufferMCMD(&mcmdHeader.PtrMCMD, mcmdttag_direct)
575     != SUCCESSFUL )
576     {
577     /* internal error: reject the MCMD */
578     status = UNSATISFIED;
579     }
580     else
581     {
582     memcpy((unsigned short int*)mcmdHeader.PtrMCMD, BI_1553MCMDBuffer, 2*mcmdHeader.Length);
583     *(MA_HEADER_MCMD*)sndMsg.Info = mcmdHeader;
584     sndMsg.LlInfo = sizeof(MA_HEADER_MCMD);
585     if( mcmdttag_direct == TIMETAG_MCMD )
586     {
587     status = MT_piSndMsgTTManager(&sndMsg);
588    
589     if( status == HA_E1_TIMETAG_NOT_ALLOWED)
590     {
591     BI_1553MCMDACKWord[0] |= BI_MCMD_NOT_OK | BI_MCMD_WRONG_TIMETAG;
592     *(unsigned short int*)&sndMsg.Info[6] = status;
593     /* Extract parameters and delete MCMD from partition */
594     //INFN_PATCH MA_piDelBufferMCMD(mcmdHeader.PtrMCMD,TIMETAG_MCMD,WAIT,NO_TIMEOUT);
595     MA_piDelBufferMCMD(mcmdHeader.PtrMCMD,TIMETAG_MCMD);
596     }
597     else if(status == HA_E1_MCMD_QUEUE_FULL )
598     {
599     BI_1553MCMDACKWord[0] |= BI_MCMD_NOT_OK | BI_MCMD_TTQUEUE_FULL;
600     *(unsigned short int*)&sndMsg.Info[6] = status;
601     /* Extract parameters and delete MCMD from partition */
602     //INFN_PATCH MA_piDelBufferMCMD(mcmdHeader.PtrMCMD,TIMETAG_MCMD,WAIT,NO_TIMEOUT);
603     MA_piDelBufferMCMD(mcmdHeader.PtrMCMD,TIMETAG_MCMD);
604     }
605     }
606     else
607     {
608     status = MD_piSndMsgMCMDDispatcher(&sndMsg);
609     }
610     }
611     }
612    
613     if( BI_1553MCMDACKWord[0] & BI_MCMD_NOT_OK )
614     {
615    
616     #warning do we want OBT in s or in ms ? if ms, russian must be warned ? TM was in s
617     TI_piGetTimeInfo_s(&obtime);
618     *(unsigned short int*)&sndMsg.Info[0] = HA_HEADER_E1 | mcmdId;
619     *(unsigned short int*)&sndMsg.Info[2] = obtime >> 16;
620     *(unsigned short int*)&sndMsg.Info[4] = obtime;
621     sndMsg.Code = HA_TRACEVENT;
622     sndMsg.LlInfo = HA_SIZEW_E1;
623    
624     if( BI_1553MCMDACKWord[0] & BI_MCMD_WRONG_IDENTIFIER )
625     {
626     *(unsigned short int*)&sndMsg.Info[6] = HA_E1_MCMD_ID_NOT_ALLOWED;
627     }
628     else if( BI_1553MCMDACKWord[0] & BI_MCMD_WRONG_WORD_NUMBER )
629     {
630     *(unsigned short int*)&sndMsg.Info[6] = HA_E1_MCMD_LENGHT_ERROR;
631     }
632     else if( BI_1553MCMDACKWord[0] & BI_MCMD_CHECKSUM_ERROR )
633     {
634     *(unsigned short int*)&sndMsg.Info[6] = HA_E1_MCMD_CHECKSUM_ERROR;
635     }
636     else if( BI_1553MCMDACKWord[0] & BI_MCMD_TTQUEUE_FULL )
637     {
638     *(unsigned short int*)&sndMsg.Info[6] = HA_E1_MCMD_QUEUE_FULL;
639     }
640     else /* ( BI_1553MCMDACKWord[0] & BI_MCMD_WRONG_TIMETAG ) */
641     {
642     *(unsigned short int*)&sndMsg.Info[6] = HA_E1_TIMETAG_NOT_ALLOWED;
643     }
644     HA_piSndMsgHistoryArea(&sndMsg);
645     }
646    
647     return status;
648     }
649    
650    
651     /*****************************************************************************/
652     /* @Function: BI_if1553BWriteAck */
653     /* @Purpose : */
654     /* This routine writes the acknowledge word to perform the MCMD protocol */
655     /* */
656     /* @@ */
657     /* @Parameter Name @Mode @Description */
658     /* subaddId IN subaddress of the ACK word (TSA01) */
659     /* BI_1553MCMDACKWord OUT Buffer of the Acknowledge word */
660     /* subaddIdMCMD OUT MCMD subaddress */
661     /* status_1553 OUT return code */
662     /* @@ */
663     /*****************************************************************************/
664     status_code BI_if1553BWriteAck( unsigned int subaddId,unsigned int subaddIdMCMD,
665     unsigned short int* BI_1553MCMDACKWord)
666     {
667     status_code status;
668     unsigned int* pexg;
669     unsigned int* pexgMCMD;
670    
671     status = SUCCESSFUL;
672     pexg = BI_ifSuMMITRTGetDataAddress(subaddId);
673     pexgMCMD = BI_ifSuMMITRTGetDataAddress(subaddIdMCMD);
674    
675     if ( pexg == (unsigned int*)0 )
676     {
677     status = UNSATISFIED;
678     }
679     else
680     {
681     BI_1553MCMDACKWord[0] |= pexgMCMD[1] << 8;
682     BI_1553MCMDACKWord[1] = pexgMCMD[0];
683     pexg[0] = BI_1553MCMDACKWord[0];
684     pexg[1] = BI_1553MCMDACKWord[1];
685    
686     }
687    
688     return (status);
689     }
690    
691    
692     /*****************************************************************************/
693     /* @Function: BI_if1553BWriteCCA */
694     /* @Purpose : */
695     /* This routine writes the communication control word */
696     /* */
697     /* @@ */
698     /* @Parameter Name @Mode @Description */
699     /* subaddId IN subaddress of the CCA (TSA03) */
700     /* BI_1553CCABuffer OUT Buffer of the CCA structure */
701     /* BI_1553MCMDACKWord OUT Buffer of the Acknowledge word */
702     /* status_1553 OUT return code */
703     /* @@ */
704     /*****************************************************************************/
705     status_code BI_if1553BWriteCCA( unsigned int subaddId,
706     unsigned short int* BI_1553CCABuffer,
707     unsigned short int* BI_1553MCMDACKWord )
708     {
709     status_code status;
710     unsigned int *pexg, i;
711     TI_TIME obt;
712     unsigned int ssw;
713     FS_FILE_DESCR fileInfo;
714     unsigned short size;
715     UINT16 IPMStatus;
716    
717     status = SUCCESSFUL;
718     pexg = BI_ifSuMMITRTGetDataAddress(subaddId);
719    
720     if ( pexg == (unsigned int*)0 )
721     {
722     status = UNSATISFIED;
723     }
724     else
725     {
726     /* Get OBT */
727    
728     // TI_piGetTimeInfo(&obt);
729     TI_piGetCurrentMoscowTime_s(&obt);
730    
731     /* Get Status Word */
732     RG_piGetSubStatusWord(&ssw);
733    
734     /* Get IPM Status */
735     PWR_GetIPMStatus(&IPMStatus);
736    
737    
738     /* File size resolution is 1 bit 8Mb */
739     /* (FileInfo.Size is 1 bit 4 bytes) */
740     // FS_piGetFileInfo(FS_FILE1,&fileInfo);
741     // size =(unsigned short)(((fileInfo.Size>>21)<<8) & 0x0000FF00);
742     // FS_piGetFileInfo(FS_FILE2,&fileInfo);
743     // size |=(unsigned short)((fileInfo.Size>>21) & 0x000000FF);
744    
745     FS_piGetFileInfo(FS_FILE1,&fileInfo);
746    
747     // size =(unsigned short)(((fileInfo.Size>>21)) & 0x000000FF);
748     // size |= (unsigned short)(((fileInfo.Size>>21)<<8) & 0x0000FF00);
749     // Size in Megabyte
750     size =(unsigned short)(((fileInfo.Size>>18)) & 0x0000FFFF);
751    
752     /* Get INFN information */
753     /* Function TBD */
754    
755     BI_1553CCABuffer[0] =(unsigned short)(obt >> 16);
756     BI_1553CCABuffer[1] =(unsigned short)(obt & 0xffff);
757     BI_1553CCABuffer[2] =(unsigned short)(ssw & 0xffff);
758     BI_1553CCABuffer[3] =BI_1553MCMDACKWord[0];
759     BI_1553CCABuffer[4] =BI_1553MCMDACKWord[1];
760     BI_1553CCABuffer[5] =size;
761    
762     BI_1553CCABuffer[6] = IPMStatus; // IPM STATUS
763     BI_1553CCABuffer[7] = 0; // GSStatus; // GAS SYSTEM: this must be zero as agreed in document protocol PAM. R1d1-346bis-04 (russian)
764     BI_1553CCABuffer[8] = 0;
765     BI_1553CCABuffer[9] = 0;
766     BI_1553CCABuffer[10] = 0;
767     BI_1553CCABuffer[11] = 0;
768    
769    
770     /* Copy CCA words into 1553B area */
771     for (i=0; i<BI_MAX_CCA_VORDS; i++)
772     {
773     *pexg++ = BI_1553CCABuffer[i];
774     }
775     }
776    
777     return status;
778     }
779    
780    
781    
782     /*****************************************************************************/
783     /* @Function: BI_if1553BWriteSSW */
784     /* @Purpose : */
785     /* This routine writes the status word */
786     /* */
787     /* @@ */
788     /* @Parameter Name @Mode @Description */
789     /* subaddId IN subaddress of the SSW (TSA02) */
790     /* status_1553 OUT return code */
791     /* @@ */
792     /*****************************************************************************/
793     status_code BI_if1553BWriteSSW( unsigned int subaddId )
794     {
795     status_code status = SUCCESSFUL;
796     unsigned int* pexg;
797     unsigned int ssw;
798    
799     pexg = BI_ifSuMMITRTGetDataAddress(subaddId);
800    
801     if ( pexg == (unsigned int*)0 )
802     {
803     status = UNSATISFIED;
804     }
805     else
806     {
807     RG_piGetSubStatusWord(&ssw);
808     *pexg = ssw;
809     }
810    
811     return status;
812     }

  ViewVC Help
Powered by ViewVC 1.1.23