/** * com1553 - MIL-1553 Communication Library for Herschel - Low Level Interface Management * * Filename : \file util1553.c * * Purposes : \brief [DONE] com1553 - MIL-1553 Communication Library for Herschel - Low Level Interface Management * * Logical Task : in Spire - TMTC * : in Pacs - TOTH * : in HIFI - TMTC * : \ingroup group_COM1553 * * Author : Scige * * Last Developer : $Author: lorenzo $ * * Revision : $Revision: 1.16 $ * * Checkout Tag : $Name: $ * * Last Modification : $Date: 2007/02/09 10:44:32 $ * * Location : $RCSfile: util1553.c,v $ * * \version : $Header: /home/local/cvsrep/OBS_FM/1553_Lib/util1553.c,v 1.16 2007/02/09 10:44:32 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 #include "conf1553.h" #if OBSCODE == HIFI_CODE #elif OBSCODE == SPIRE_CODE #elif OBSCODE == PACS_CODE #include "MM_21020.h" //Necessary for adicpy #include "LT_TMdef.h" //must be before init1553.h #endif #include "init1553.h" #include "MilConf.h" #include "MilInit.h" // ---------------------------------------------------------------------------// // ---------------------------------------------------------------------------// // -- Functions in this module void UpLoad_Packet ( int * cBuffer ); static void TmRequestGenerator ( int n); void DownLoad_Packet( TC_packet *); inline void align_ptr_counter ( void ); inline void force_1553_reset ( void ); void miaMilSaWrite( MilConf_p pw_MilConf, MemBlockHandle pw_BlockHdl, unsigned int *j_Offset, unsigned int *pj_Ptr, unsigned int j_Length); // ---------------------------------------------------------------------------// // ---------------------------------------------------------------------------// /** void UpLoad_Packet ( int * cBuffer ) * * \brief Writes a Telemetry Packet into DPRAM. * \brief It presumes that there's place on DDC1553 Memory. * \brief Check done by calling \ref checkFreeDPRAM(). * * \par cBuffer Raw Packet Data \b Already \b Formatted and \b Aligned in memory. * * \callgraph * \ingroup group_COM1553 */ void UpLoad_Packet ( int * cBuffer ) { unsigned int i, j, k; int pktlength; int SAddr; int crc; struct TM_request * TmWriter_next; SAddr=0; pktlength = (cBuffer[2]+7) >> 1; //number of word of this msg w/crc //(((totale-1)+1)+6)/2 j = pktlength >> 5; //number of completed SubAddress' i = pktlength & 0x001F; //number of word in the last Sa k = pktlength - 1; crc = memcrc16 (cBuffer, k, 0xFFFF); #if OBSCODE == HIFI_CODE #elif OBSCODE == SPIRE_CODE /* * * Packet level retry test. * Sergio */ if (force_wrong_crc == TRUE) { crc++; force_wrong_crc = FALSE; } #elif OBSCODE == PACS_CODE #endif cBuffer[k] = crc; TmWriter_next = TmWriter->next; adicpy( TmWriter_next->offset, TmWriter->offset, 16); /* * * Start writing packet into DPRAM */ for (SAddr=0; SAddr < j; SAddr++) { miaMilSaWrite( MilRTConf, Tx_data_han[SAddr], &(TmWriter_next->offset[SAddr]), cBuffer+(SAddr<<5), 32); } if (i!=0) { miaMilSaWrite( MilRTConf, Tx_data_han[SAddr], &(TmWriter_next->offset[SAddr]), cBuffer+(SAddr<<5), i); } /* * * Writing end */ TmRequestGenerator ( pktlength ); return; } // ---------------------------------------------------------------------------// // ---------------------------------------------------------------------------// /** static void TmRequestGenerator ( int n) * * \brief Enqueue in Telemetry Packet Transfer Request Que a new Token then step the Writer accesso to the next token, ready to be written. * * \param n Packet Length in 16 Bit word base. * * \callgraph * \ingroup group_COM1553 */ static void TmRequestGenerator ( int n) { // n is the number of words in this packet // ret = (n&0x01f)==0 ? (n&0x03e0)<<3:(((n&0x03e0)+0x020)<<3)+(n&0x01f); TmWriter->status = ISFREE; TmWriter->tmreq = (((n + 0x001F)<<3) & 0x1F00) + (n&0x001F); TmWriter->count = TM_pkt_ctr | 0x0800 | ( Burst_active * 0x2000) ; FreePackDPRAM--; #if OBSCODE != HIFI_CODE Waiting_TM_packet--; #endif if (TM_pkt_ctr==0x00FF) TM_pkt_ctr=1; else TM_pkt_ctr++; TmWriter->next->status = ISFREE; TmWriter->status = CONTINUE; TmWriter = TmWriter->next; return; } // ---------------------------------------------------------------------------// // ---------------------------------------------------------------------------// /** void DownLoad_Packet( TC_packet * tpacket ) * * \brief Read a TeleCommand packet. * * \param tpacket Pointer to a memory area dedicated to host a TeleCommand Packet * * \note In some Implementation colud be NULL. Check \ref OBSCODE Value. * * \callgraph * \ingroup group_COM1553 */ void DownLoad_Packet( TC_packet * tpacket ) { int TC_Req_Conf[2]; int i, j; int SAddr=0; TC_packet * packet; #if OBSCODE == HIFI_CODE TC_MSG currTC_MSG; TC_BUF_HDL Tc_hdl; // Telecommand buffer handler #elif OBSCODE == SPIRE_CODE TC_MSG currTC_MSG; void DownLoadPacket_get_post ( TC_packet * packet, TC_MSG * currTC_MSG); void DownLoadPacket_get_tc_seq_err ( int TC_pkt_ctr_prev, int TC_pkt_ctr ); #elif OBSCODE == PACS_CODE unsigned int pointer_to_struct; #endif #if OBSCODE == HIFI_CODE extern int get_block (K_BLOCK *, K_POOL, int); if(get_block(&(Tc_hdl.block), TC_POOL, TC_BLOCK_LEN_BYTES) != RC_OK) return; Tc_hdl.offset = 0; Tc_hdl.free = TC_BLOCK_MSG; #elif OBSCODE == SPIRE_CODE if(get_block(&(Tc_hdl.block), TC_POOL, TC_BLOCK_LEN_MAX_BYTE) != RC_OK) return; Tc_hdl.offset = 0; Tc_hdl.freespace = TC_BLOCK_MSG; #elif OBSCODE == PACS_CODE #endif MilBlockRead(MilRTConf, Rx_data_han27->m_AbsAddr , TC_Req_Conf ,2); TC_Req_Conf[0] &= 0xFFFF; TC_Req_Conf[1] &= 0xFFFF; #if OBSCODE == SPIRE_CODE TC_pkt_ctr_prev = TC_pkt_ctr; TC_pkt_ctr = TC_Req_Conf[1] & 0xFF; if ( ( ( TC_pkt_ctr_prev == 0xFF ) && ( TC_pkt_ctr != 0x01 ) ) || ( ( TC_pkt_ctr_prev + 1 ) != TC_pkt_ctr ) ) { DownLoadPacket_get_tc_seq_err ( TC_pkt_ctr_prev, TC_pkt_ctr ); } #endif // -- i = 0x001f & TC_Req_Conf[0]; j = 0x001f & ( ( i==0 )? (TC_Req_Conf[0]>>8): (TC_Req_Conf[0]>>8)-1 ); // 0x001F BIT masking to prevent reading over subaddresses // -- #if OBSCODE == HIFI_CODE packet = (TC_packet*)(Tc_hdl.block.pointer_to_data);// + Tc_hdl.offset); #elif OBSCODE == SPIRE_CODE packet = (struct TC_packet_str*)(Tc_hdl.block.pointer_to_data);// + Tc_hdl.offset); #elif OBSCODE == PACS_CODE packet = tpacket; pointer_to_struct = (unsigned int)tpacket; #endif for (SAddr=0; SAddrm_AbsAddr, //from rx at current sa ((int*)packet)+(SAddr<<5),32); //into current position if (i!=0) MilBlockRead(MilRTConf, //write data Rx_data_han[SAddr]->m_AbsAddr, //into tx at current sa ((int*)packet)+(SAddr<<5), i); //remaining words #if OBSCODE == HIFI_CODE // packet->chk_len = (SAddr<<5)+i; //copy the msg length = SAddr*32+i #define M16 0x0000FFFF andmask ((unsigned int *)packet, ((SAddr<<5)+i), M16); #elif OBSCODE == SPIRE_CODE // packet->chk_len = (SAddr<<5)+i; //copy the msg length = SAddr*32+i #define M16 0x0000FFFF andmask ((unsigned int *)packet, ((SAddr<<5)+i), M16); #elif OBSCODE == PACS_CODE #endif packet->error_ctrl = (unsigned int) (((int*)packet)[(j<<5)+i-1]); //copy the crc into crc tag packet->chk_len = (SAddr<<5)+i; //copy the msg length = SAddr*32+i FreeCmndDPRAM++; #if OBSCODE == SPIRE_CODE TCRecId = packet->id; TCRecSeq= packet->seqctrl; TCRecN = TCRecSeq & 0x3fff; TCRecV++; #endif MilBlockWrite(MilRTConf, Tx_data_han27->m_AbsAddr , TC_Req_Conf ,2); #if OBSCODE == HIFI_CODE currTC_MSG.block = Tc_hdl.block; currTC_MSG.offset = Tc_hdl.offset; currTC_MSG.length = (SAddr<<5)+i; currTC_MSG.count = 0 ;// --Tc_hdl.free; KS_FIFOPut(TC_QUEUE, &currTC_MSG); #elif OBSCODE == SPIRE_CODE currTC_MSG.block =Tc_hdl.block; //currTC_MSG.offset =Tc_hdl.offset; //currTC_MSG.length =(SAddr<<5)+i; //currTC_MSG.count = 0 ; DownLoadPacket_get_post ( packet, & currTC_MSG); #elif OBSCODE == PACS_CODE KS_FIFOPut(TC_QUEUE,&pointer_to_struct); #endif return; } // ---------------------------------------------------------------------------// // ---------------------------------------------------------------------------// /** \def M1553_SA10_AREA_A_OFFSET * \brief Offset in DDC1553 Dual Port Ram of the A Memory Area Sub Address Data Lookup Table * \ingroup group_COM1553 */ #define M1553_SA10_AREA_A_OFFSET 0x14A /** \def M1553_SA10_AREA_B_OFFSET * \brief Offset in DDC1553 Dual Port Ram of the B Memory Area Sub Address Data Lookup Table * \ingroup group_COM1553 */ #define M1553_SA10_AREA_B_OFFSET 0x1CA /** \def M1553_CONF_1__CURRENT_AREA * \brief Bit Placement in DDC1553 Configuration Word for A/B Memory Area Selection * \ingroup group_COM1553 */ #define M1553_CONF_1__CURRENT_AREA 0x2000 // ---------------------------------------------------------------------------// // ---------------------------------------------------------------------------// /** inline void align_ptr_counter ( void ) * * \brief Read Last Telemetry Packet Transfer Request Sent, and align local Telemetry Packet Request Counter. * * \par Effect on: * \ref TM_pkt_ctr - Telemetry Packet Request Counter. * * \par Architectural Definition (Hardware Related): * \ref BS_AD_MIL_1553_DPRAM * \ref M1553_SA10_AREA_A_OFFSET * \ref M1553_SA10_AREA_B_OFFSET * * \callgraph * \ingroup group_COM1553 */ inline void align_ptr_counter ( void ) { // Nino 07/02/2007 got problem with polinomial CONSTANT DEFINITION, adding parenthesis. // Nino 07/02/2007 got problem unconnected bus routes, adding AND masking. // Nino 07/02/2007 got problem with addressing, the counter is in the second word. // Nino 11/06/2003 in order to mantain correct packet numbering int * mem_1553_pointer; if ( ((*(int*)(ACE_CONF_1_RW_REG) ) & M1553_CONF_1__CURRENT_AREA) == 0 ) { // AREA A mem_1553_pointer = (int *) (0x3FFF & (*(int *)(BS_AD_MIL_1553_DPRAM + M1553_SA10_AREA_A_OFFSET) ) ); } else { // AREA B mem_1553_pointer = (int *) (0x3FFF & (*(int *)(BS_AD_MIL_1553_DPRAM + M1553_SA10_AREA_B_OFFSET) ) ); } TM_pkt_ctr = (*(BS_AD_MIL_1553_DPRAM + mem_1553_pointer + 1) & 0xFF) + 1; TM_pkt_ctr = (TM_pkt_ctr==0x100)?1:TM_pkt_ctr; } // ---------------------------------------------------------------------------// // ---------------------------------------------------------------------------// /** inline void force_1553_reset ( void ) * \brief Hardware Reset of DDC1553 Chip. * * \callgraph * \ingroup group_COM1553 */ inline void force_1553_reset ( void ) { // ----- nino : Renato's Ordered PATCH ---- 1553 HW RESET *(int*)(0x8d000000) = 0x00000100; *(int*)(0x8d000000) = 0x00000000; // ----- nino : Renato's Ordered PATCH ---- 1553 HW RESET } // ---------------------------------------------------------------------------// // ---------------------------------------------------------------------------// /** void miaMilSaWrite ( MilConf_p pw_MilConf, MemBlockHandle pw_BlockHdl, unsigned int *j_Offset, unsigned int *pj_Ptr, unsigned int j_Length ) * * \brief Copy data to a DDC1553 SubAddress. If SubAddress is Circular Buffered copy data circularly. * * \param pw_MilConf DDC1553 Hardware Configuration Descriptor. * \param pw_BlockHdl DDC1553 SubAddress Memory Map Descriptor. * \param j_Offset Offset in SubAddres. * \param pj_Ptr Pointer to data. * \param j_Length Number of word to copy. * * \callgraph * \ingroup group_COM1553 */ void miaMilSaWrite ( MilConf_p pw_MilConf, MemBlockHandle pw_BlockHdl, unsigned int *j_Offset, unsigned int *pj_Ptr, unsigned int j_Length ) { if ((*j_Offset + j_Length) > pw_BlockHdl->j_Size) { int after_roll, before_roll; before_roll = pw_BlockHdl->j_Size - *j_Offset; after_roll = j_Length - before_roll; /* Higher Boundary of circular buffer */ MilBlockWrite(pw_MilConf, pw_BlockHdl->m_AbsAddr + *j_Offset, pj_Ptr, before_roll); /* Lower Boundary of circular buffer */ MilBlockWrite(pw_MilConf, pw_BlockHdl->m_AbsAddr, pj_Ptr + before_roll, after_roll); } else { /* Single Message Mode or No Buffer Rollover */ MilBlockWrite(pw_MilConf, pw_BlockHdl->m_AbsAddr + *j_Offset, pj_Ptr, j_Length); } *j_Offset += j_Length; *j_Offset &= (pw_BlockHdl->j_Size-1); return; } // ---------------------------------------------------------------------------// // ---------------------------------------------------------------------------// /* * Commitments History : * $Log: util1553.c,v $ * Revision 1.16 2007/02/09 10:44:32 lorenzo * libraries updated * avm2 restored * * Revision 1.26 2007/02/07 16:39:02 scige * Addressing Error in Packet Transfer Request, * Addressing Descriptor instead of Counter. * now Fixed. * * Revision 1.25 2007/02/07 13:39:26 scige * Error interpreting Polinomial Define as pointer. * Error with pending bus routes, fixed with masking. * Tested. * * Revision 1.24 2006/10/20 09:27:43 lorenzo * function get_block changed. The modification affects only HIFI code. * * Revision 1.15 2006/10/20 09:22:15 lorenzo * 1553 library updated * * Revision 1.23 2006/10/16 14:19:53 scige * Some More Comments * * Revision 1.22 2006/06/23 10:27:47 lorenzo * parameters of function get_block were changed * * change affects only the HIFI_code * * Revision 1.12.2.2 2006/06/23 09:46:30 lorenzo * pool handling improved * * Revision 1.12.2.1 2006/06/22 13:07:37 lorenzo * util1553 updated * * ifsimod implemented * * Revision 1.21 2006/06/19 13:24:24 scige * preventive coding - 0x001F BIT masking to prevent reding over subaddresses * * Revision 1.20 2006/06/07 11:44:56 scige * Some More Comment * by Scige John Liu IFSI * * Revision 1.19 2006/04/27 10:21:44 scige * Some more Comment alignement before STRONG COMMENTING * * Revision 1.18 2006/03/23 14:32:11 daniele * Daniele Schito: substituted all memcpy with adicpy and removed some define memcpy. * * Revision 1.17 2006/03/21 16:24:33 daniele * Daniele Schito: Fixed some includes * * Revision 1.16 2006/03/21 15:50:49 daniele * Daniele Schito: Fixed some includes * * Revision 1.15 2006/03/21 15:41:08 daniele * Daniele Schito: Fixed some includes order * * Revision 1.14 2006/03/10 14:28:42 lorenzo * redefinition of memcpy for HIFI eliminated (should be useless) * * Revision 1.13 2006/03/08 17:23:24 daniele * changed include scheme and added some comments * * Revision 1.12 2006/02/17 16:21:10 lorenzo * Some bugs in the HIFI part were fixed * * Revision 1.6.2.1 2006/02/17 15:53:30 lorenzo * 1553_consolidated library updated * * Revision 1.11 2006/02/15 18:24:42 scige * eliminating unused files in TC queue structures * * 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.6 2005/09/16 13:09:40 scige * *** empty log message *** * * Revision 1.4 2005/08/26 13:44:13 scige * call stubs for new error management//handling * * Revision 1.3 2005/08/26 12:49:35 scige * ok S_P_H * * 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 * */