/** * com1553 - MIL-1553 Communication Library for Herschel - Interrupt Service Routine * * Filename : \file isr1553.c * * Purposes : \brief [DONE] com1553 - MIL-1553 Communication Library for Herschel - Interrupt Service Routine * * Logical Task : in Spire - TMTC * : in Pacs - TOTH * : in HIFI - TMTC * : \ingroup group_COM1553 * * Author : Scige * * Last Developer : $Author: lorenzo $ * * Revision : $Revision: 1.18 $ * * Checkout Tag : $Name: $ * * Last Modification : $Date: 2009/01/15 16:45:50 $ * * Location : $RCSfile: isr1553.c,v $ * * \version : $Header: /home/local/cvsrep/OBS_FM/1553_Lib/isr1553.c,v 1.18 2009/01/15 16:45:50 lorenzo Exp $ */ /* * Commitments History : * As reported in Main cvs Documentation * ( https://www.cvshome.org/docs/manual/cvs-1.11.18/cvs_12.html#SEC102 ) * The Modification Log has been posted at End Of File. */ // ---------------------------------------------------------------------------// // ---------------------------------------------------------------------------// #include "conf1553.h" #if OBSCODE == HIFI_CODE #include "init1553.h" #elif OBSCODE == SPIRE_CODE #include "init1553.h" #elif OBSCODE == PACS_CODE #include "LT_TMdef.h" #include "MM_21020.h" #include "init1553.h" #endif // ---------------------------------------------------------------------------// #if OBSCODE == HIFI_CODE int Delta_0_SubFrame_Counter; int Delta_1_SubFrame_Counter; unsigned Buf_0_SubFrame_Counter; unsigned Buf_1_SubFrame_Counter; int Counter_Flag = 0; #endif // ---------------------------------------------------------------------------// // -- FUNCTIONS IN THIS MODULE int isr1553 ( int ); static void checkFreeDPRAM ( void ); void readCmndDPRAM ( void ); static void checkCmndDPRAM ( void ); static void force_step_TM_Request ( void ); static void publish_TM_request ( void ); static void publish_TM_pointer ( void ); // ---------------------------------------------------------------------------// // -- EXTERN FUNCT #if OBSCODE == HIFI_CODE extern void prhi_stack_pshC ( STACK_CHAN * ptr_K_ArgsP, int event_number); #elif OBSCODE == SPIRE_CODE extern void prhi_stack_pshC ( STACK_CHAN * ptr_K_ArgsP, int event_number); #elif OBSCODE == PACS_CODE #endif // ---------------------------------------------------------------------------// // -- STATIC VAR /** \brief com1553 - Holder of low level (network level) DDC1553 Message Token. * \ingroup group_COM1553 */ static MsgType msg; /** \brief com1553 - Current content of the SubAddress 10 RX - Telemetry Packet Transfer Confirmation. * \ingroup group_COM1553 */ static int sa10[2] = {0,0}; /** \brief com1553 - Previous content of the SubAddress 10 TX - Telemetry Packet Transfer Request. * \ingroup group_COM1553 */ static int SA10[2] = {0,0}; /** \brief com1553 - Current content of the SubAddress 27 RX - Telemetry Packet Transfer Descriptor. * \ingroup group_COM1553 */ static int sa27[2] = {0,0}; /** \brief com1553 - Previous content of the SubAddress 27 RX - Telemetry Packet Transfer Descriptor. * \ingroup group_COM1553 */ static int SA27[2] = {0,0}; /** \brief com1553 - Current content of the SubAddress 1 TX - Remote Terminal Status and Information * \ingroup group_COM1553 */ static int sa1t[2]; /** \brief com1553 - Transient content of the Lookup pointer for SubAddress [11-27][TX] - Telemetry Packet * \ingroup group_COM1553 */ static int cOffSet[16]; /** \brief com1553 - Transient content of the SubAddress 10 TX - Telemetry Packet Transfer Request. * \ingroup group_COM1553 */ static int tm__req[2]; // ---------------------------------------------------------------------------// // ---------------------------------------------------------------------------// /* used in isr2.s */ extern unsigned int com1553_isr_counter; // ---------------------------------------------------------------------------// /** * \par Internal: * the Activaction flow follows the following order: * 1-- Hardware Interrupt 2 --> irq2 * 2 - irq2 --> isr1553 * 3 - 1sr1553 --> tmtc * 3 - the activation of tmtc occures only if the message read is : * 3 - a sync command and there are packets transactions. * * \ingroup group_COM1553 */ // ---------------------------------------------------------------------------// /** int isr1553 ( int status ); * * \brief Virtuoso's Event Handle - Manage Low Level Messsages, Handshake Network Layer Packet and Activate Interface Manager Task [TMTC/TOTH/TMTC]. * * \param status ignored * * \retval TRUE If there is a TeleCommand to be read or there is a request to upload a Telemetry packet * \retval FALSE Otherwise * * \note This routine is called a Virtuoso Event Handler.\n * \note Its return value has a semantical propagation to the related Event.\n * \note A TRUE return value alloe the event to be reaised and awake any related waiting task.\n * * \par Inter-Process Communication - Low Level : * The lowest level Interrupt Service Routine \ref isr2 is called by the Hardware Interrupt * coming from DDC1553 Chip [ thsi follows a netwide Synchronize Message ], via the Virtuoso * event \ref ISR_1553_EVENT.\n * The lowest level Interrupt Service Routine \ref isr2 also keeps the current Synchronize * Message stack position in \ref Ghost_1553_StackPointer.\n * The Virtuoso Event Daemon activate this routine. * * \par Inter-Process Communication - Mid Level : * If a Telemetry transfer is pending the SubAddress Offset pointer are Updated into * SubAddress Lookup Table, \ref publish_TM_pointer, and in any case a correct Packet Transfer * Request ( even a request to no transfer ) is posted into SubAddress 10TX, \ref publish_TM_request. * In these communication \ref TmReader and related Structures are used as tokenized queue. * * \par Inter-Process Communication - High Level : * If there is Space in the circular Buffers and at least a Telemetry Packet Transfer is Pending * ( condition bypassed by HIFI ), the DDC1553 Listener Task is awaken.\n * If there is a TeleCommand Packet Transfer Pending the DDC1553 Listener Task is awaken.\n * In these communication \ref FreeCmndDPRAM and \ref FreePackDPRAM are used as discrete sempahore. * * \callgraph * \ingroup group_COM1553 */ int isr1553 ( int status ) { int sptr, dataword; sptr = 0x0FF & ( (Ghost_1553_StackPointer & 0xFFFF) - 4); // Ghost_1553_StackPointer points to the location of the ModeCommand in the 1553 stack if ( MilRTReadMsg ( MilRTConf, sptr, &msg) ) return FALSE; // ____/__00/000_/____ Mode Code posible configurations // ____/__11/111_/____ if( ((( msg.j_CmdWord1 ) & 0x03E0)==0x0000)|| ((( msg.j_CmdWord1 ) & 0x03E0)==0x03E0)) { //it is a ModeCommand publish_TM_pointer(); switch (msg.j_CmdWord1&0x01f) { case RT_MODE_SYNCHRONIZE: // Start of Frame { { #if OBSCODE == HIFI_CODE prhi_stack_pshC ( K_ArgsP, TS_EVENT); #elif OBSCODE == SPIRE_CODE prhi_stack_pshC ( K_ArgsP, TS_EVENT); #elif OBSCODE == PACS_CODE MilBlockRead(MilRTConf, //Read data Rx_data_han8->m_AbsAddr, //from sa at current rx (int *) Dpu_time, 4); //into current position MilBlockWrite(MilRTConf, //Read data// nino 22/09/2004 Tx_data_han8->m_AbsAddr, //from rx at current sa (int *) Dpu_time, 4); //into current position Current_time = KS_HighTimerRead(); adicpyMask(Dpu_time,Dpu_time,4); /* Dpu_time[0] &= 0xFFFF; Dpu_time[1] &= 0xFFFF; Dpu_time[2] &= 0xFFFF; Dpu_time[3] &= 0xFFFF;*/ #endif } SubFrame_Counter=0; Current_SubFrame=0; // nino 28/11/2003 for 01/12/2003 // interrupt counters handling at subframe 0 (sync) if ( (com1553_isr_counter > 64) && (com1553_isr_counter - Buf_0_SubFrame_Counter != 64) && Counter_Flag == 0) { Delta_0_SubFrame_Counter = com1553_isr_counter - Buf_0_SubFrame_Counter; Delta_1_SubFrame_Counter = 1; Counter_Flag = 1; } Buf_0_SubFrame_Counter = com1553_isr_counter; Buf_1_SubFrame_Counter = com1553_isr_counter; { // fill in instrument status in SA1T according to PSICD sa1t[0] = SubFrame_Counter; // SubFrame Counter sa1t[1] = MilRTBITRead(MilRTConf); // BIT word MilBlockWrite(MilRTConf, ((Tx_data_han1->m_AbsAddr) + TM_STATUS_OFFSET ), sa1t ,2); } // end SA1T { // nino 28/11/2003 for 01/12/2003 tmreq_reply[0] = 0; tmreq_reply[1] = 0; // nino 27/09/2004 tmreq_reply[2] = 0; // nino 27/09/2004 MilBlockWrite(MilRTConf, ((Tx_data_han1->m_AbsAddr) + TMREQ_REPLY_OFFSET ), tmreq_reply ,3); } // nino 28/11/2003 for 01/12/2003 checkFreeDPRAM(); checkCmndDPRAM(); publish_TM_request(); break; } case RT_MODE_SYNCHRONIZE_DATA: // Start of Subframe { // dataword = *(MilRTConf->pm_MilBaseReg + RtEmod_BCST_SYNC_WITH_DATA); // dataword = MilRTReadEnhMCData(MilRTConf,RtEmod_BCST_SYNC_WITH_DATA); dataword = msg.aj_Data[0]; Current_SubFrame = dataword & 0x003f; RT_TMEnable_prev = RT_TMEnable; RT_TMEnable = (dataword>>11) & 0x1F; SubFrame_Counter++; // interrupt counters handling at subframe >= 1 (non sync) if ( (com1553_isr_counter > 64) && (com1553_isr_counter - Buf_1_SubFrame_Counter != 1) && Counter_Flag == 0) { Delta_0_SubFrame_Counter = 64; Delta_1_SubFrame_Counter = com1553_isr_counter - Buf_1_SubFrame_Counter; Counter_Flag = 1; } Buf_1_SubFrame_Counter = com1553_isr_counter; { // fill in instrument status in SA1T according to PSICD sa1t[0] = SubFrame_Counter; //SubFrame Counter sa1t[1] = MilRTBITRead(MilRTConf); // BIT word MilBlockWrite(MilRTConf, ((Tx_data_han1->m_AbsAddr) + TM_STATUS_OFFSET ), sa1t ,2); } // end SA1T if ( ( Burst_active == 1)&&(RT_TMEnable == RTAddress)) { force_step_TM_Request ( ); } else { checkFreeDPRAM(); } checkCmndDPRAM(); publish_TM_request(); break; } // case RT_MODE_TXS_SHUTDN: break; // case RT_MODE_OVER_TXS_SHUTDN: break; // case RT_MODE_DYN_BUS_CTRL: break; // case RT_MODE_TX_STAT_WORD: break; // case RT_MODE_INIT_SELF_TST: break; // case RT_MODE_INH_TERM_FLAG: break; // case RT_MODE_OVER_INH_TERM_FLAG: break; // case RT_MODE_RESET_REMOTE_TERM: break; // case RT_MODE_TXS_VECTOR_WORD: break; // case RT_MODE_TX_LAST_COMMAND: break; // case RT_MODE_TX_BIT_WORD: break; // case RT_MODE_SEL_TRANS_SHUTDN: break; // case RT_MODE_OVER_SEL_TRANS_SHUTDN: break; default: return FALSE; // /* */ MIL_ERROR_INVALIDMODECODE; }// end switch }// end if // Virtuoso assume the return value (False := unsignaled) for KS_EventTestW // Virtuoso assume the return value (True := signaled ) for KS_EventTestW // True value raise the tasks with KS_EventTestW(ISR_1553_EVENT) statement if ( (FreeCmndDPRAM < MaxCmndDPRAM )|| ( (FreePackDPRAM > 0 ) #if OBSCODE != HIFI_CODE && (Waiting_TM_packet > 0) #endif ) ) { return TRUE; } return FALSE; } //end proc. ISR1553 // ---------------------------------------------------------------------------// // ---------------------------------------------------------------------------// /** void readCmndDPRAM ( void ) * \brief Copy Content of the TeleCommand Packet Transfer Descriptor [SubAddress 27 RX] in SA27.\n * \brief Used as First Initialization. * * \callgraph * \ingroup group_COM1553 */ void readCmndDPRAM ( void ) { MilBlockRead (MilRTConf, Rx_data_han27->m_AbsAddr ,SA27, 2); } // ---------------------------------------------------------------------------// // ---------------------------------------------------------------------------// /** void checkCmndDPRAM ( void ) * \brief Check if a new TeleCommand Packet Transfer Descriptor [SubAddress 27 RX] is arrived. * \brief If TRUE updates \ref FreeCmndDPRAM; * * \callgraph * \ingroup group_COM1553 */ void checkCmndDPRAM ( void ) { int count_prev, count_new; MilBlockRead (MilRTConf, Rx_data_han27->m_AbsAddr ,sa27, 2); sa27[0]&=0xFFFF; sa27[1]&=0xFFFF; count_new = sa27[1] & 0xFF; count_prev = SA27[1] & 0xFF; if (count_prev != count_new) { FreeCmndDPRAM--; SA27[0]=sa27[0]; SA27[1]=sa27[1]; } return; } // ---------------------------------------------------------------------------// // ---------------------------------------------------------------------------// /** void publish_TM_request ( void ) * \brief Updates TeleMetry Packet Transfer Request [SubAddress 10 TX]. * * \callgraph * \ingroup group_COM1553 */ static void publish_TM_request ( void ) { if( TmReader->status == CONTINUE ) // There is a TmRequest { tm__req[0]=TmReader->tmreq; tm__req[1]=TmReader->count; } else // There aren't any TmRequest { FreePackDPRAM = MaxPackDPRAM; tm__req[0] =0x0000; tm__req[1]&=0xE7FF; } MilBlockWrite(MilRTConf,Tx_data_han10->m_AbsAddr,tm__req, 2); SA10[0]=tm__req[0]; SA10[1]=tm__req[1]; } // ---------------------------------------------------------------------------// // ---------------------------------------------------------------------------// /** void publish_TM_pointer ( void ) * \brief Updates TeleMetry Packet Pointers to Circular Buffers [SubAddress 11-27 TX]. * * \callgraph * \ingroup group_COM1553 */ static void publish_TM_pointer ( void ) { int i; if( TmReader->status == CONTINUE ) // There is a TmRequest { for (i = 0; i< 16; i++) { cOffSet[i] = TmReader->offset[i] + (Tx_data_han[i])->m_AbsAddr; } adicpy( (int *)0x8f00016B, cOffSet, 16); adicpy( (int *)0x8f0001EB, cOffSet, 16); } } // ---------------------------------------------------------------------------// // ---------------------------------------------------------------------------// /** void checkFreeDPRAM ( void ) * * \brief Check for TeleMetry Packet Transfer Confirmation [SubAddress 10 RX].\n * \brief If Confirmed Updates PacketTRansfer Request Queue to point to the next request. * * \see \ref TmReader * * \callgraph * \ingroup group_COM1553 */ static void checkFreeDPRAM ( void ) { int pcount, preq; MilBlockRead (MilRTConf, Rx_data_han10->m_AbsAddr, sa10, 2); preq = 0x0000FFFF & sa10[0]; pcount = 0x0000E7FF & sa10[1]; if ( TmReader->status == CONTINUE ) { if (RT_TMEnable_prev==RTAddress) { if (((TmReader->count) != pcount)|| ((TmReader->tmreq) != preq) )//we didn't obtained a TM_confirm { tmreq_reply[0] = preq; tmreq_reply[1] = pcount; // nino 24/09/2004 tmreq_reply[2] = SubFrame_Counter-1; // nino 24/09/2004 MilBlockWrite(MilRTConf, ((Tx_data_han1->m_AbsAddr)+TMREQ_REPLY_OFFSET ), tmreq_reply ,3); } } if (((TmReader->count&0x0000E7FF) == pcount)&& ((TmReader->tmreq) == preq))//we obtained a TM_confirm { TmReader->status = ISFREE; // Free this node TmReader = TmReader->next; // Load the next TmRequest ++FreePackDPRAM; } } return; } // ---------------------------------------------------------------------------// // ---------------------------------------------------------------------------// /** void force_step_TM_Request ( void ) * * \brief Updates TeleMetry Packet Transfer Request Queue to point to the next request. * * \see \ref TmReader * * \callgraph * \ingroup group_COM1553 */ static void force_step_TM_Request ( void ) { if ( TmReader->status == CONTINUE ) { if ( ( TRUE ) ) //|| (((TmReader->count) == pcount)&&((TmReader->tmreq) == preq)))//we obtained a TM_confirm { TmReader->status = ISFREE; // Free this node TmReader = TmReader->next; // Load the next TmRequest ++FreePackDPRAM; } } return; } // ---------------------------------------------------------------------------// // ---------------------------------------------------------------------------// /* * Commitments History : * $Log: isr1553.c,v $ * Revision 1.18 2009/01/15 16:45:50 lorenzo * minor problem solved * * This is obs.5.9 beta * * Revision 1.17 2009/01/15 13:56:54 lorenzo * interrupt counters handling revised * * Revision 1.16 2009/01/15 12:17:09 annadg * interrupt counter added in isr2, counter flag check added in res_check * * Revision 1.15 2008/12/10 10:57:55 lorenzo * - Restoring 1553 of obs5.8.1 * - Removing rc_check_subframe_counter and other OBS handling of the subframe counter. * * Revision 1.13 2007/06/19 10:17:21 lorenzo * 1553 lib updated * * Revision 1.16 2007/03/13 11:10:34 stefano * modifications of 13/3/2007 for PACS * * Revision 1.15 2006/10/16 14:19:53 scige * Some More Comments * * Revision 1.14 2006/06/07 11:44:56 scige * Some More Comment * by Scige John Liu IFSI * * Revision 1.13 2006/04/27 10:21:44 scige * Some more Comment alignement before STRONG COMMENTING * * Revision 1.12 2006/03/23 14:32:11 daniele * Daniele Schito: substituted all memcpy with adicpy and removed some define memcpy. * * Revision 1.8 2006/03/21 15:52:20 daniele * Daniele Schito: Used 1553_consolidated updated * * Revision 1.11 2006/03/21 15:41:08 daniele * Daniele Schito: Fixed some includes order * * Revision 1.10 2006/02/15 14:56:57 scige * Abstract comment reformatted * History log replaced or moved at end of file * * Revision 1.9 2006/02/15 14:34:03 scige * Some more comments restored * * Revision 1.4 2005/09/16 13:09:40 scige * *** empty log message *** * * Revision 1.2 2005/08/26 12:16:19 scige * storage * * Revision 1.1 2005/08/10 12:53:40 scige * Communication Library: 1553 * com1553 * Base Common Version of Spire/Pacs OBS * */