/** * MIL-STD 1553B Library - Carlo Gavazzi Space * * Filename : \file MilInit.c * * Purposes : \brief MIL-STD 1553B Library - Carlo Gavazzi Space * * Logical Task : N/A * * Author : CGSpace * * Last Developer : $Author: lorenzo $ * * Revision : $Revision: 1.3 * * Checkout Tag : $Name: $ * * Last Modification : $Date: 2006/10/20 09:22:14 $ * * Location : $RCSfile: MilInit.c,v $ * * \version : $Header: /home/local/cvsrep/OBS_FM/1553_Lib/MilInit.c,v 1.10 2006/10/20 09:22:14 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. */ // ---------------------------------------------------------------------------// // ---------------------------------------------------------------------------// /* Milinit.c - */ /* Purpose: The module contains the routine for the dynamic allocation of ACE memory Content: The module contains the following functions: - SUBHEADINGS Project : HSO/FIRST BASIC S/W Component : HSO/FIRST DRIVERS S/W Filename : $RCSfile: MilInit.c,v $ CI Number : Revision : Revision: 1.3 Company : Carlo Gavazzi Space S.P.A. Author : Andrea Bertoli Creation Date : 2000/05/15 Last ChangeDate: $Date: 2006/10/20 09:22:14 $ SEE ALSO: ADD Ref: Inserted here reference with Architectural Design and Detail Document. Other Ref: Notes: */ // ---------------------------------------------------------------------------// // ---------------------------------------------------------------------------// /* include header */ #include "MilDef.h" // ---------------------------------------------------------------------------// /*-------------------------------------------------------------------------- Name Bu1553AModeCd Description Affects both RT and Message Monitor modes. If this bit is programmed to a logic "0" (default), the ACE considers both subadresses 0 and 31 to be mode code subaddresses. In this configuration, the ACE RT recongnizes and responds to all MIL-STD-1553B mode codes, including those with or without, Data Words. In addition, if this bit is logic "0," the ACE will decode for the MIL-STD-1553B "Transmit Status" and "Transmit Last Command" mode codes and will not update its internal RT Status Word Register as a result of these commands, with the exception of setting the Message Error bit if the command is illegalized. If this bit is programmed to logic "1," the ACE RT or Message Monitor considers oly subaddress 0 to be a mode code subaddress. Subaddress 31 is treated as a standard nonmode code subaddress. In this configuration, the ACE will consider valid and respond only to mode code commands containing no Data Words. In this configuration, the ACE RT will consider all mode code commands followed by Data Words to be invalid and will not respond. In addition, if this bit is a logic "1", the ACE will not decode for the MIL-STD-1553B "Transmit Status" and "Transmit Last Command" mode codes. As a result, the internal RT Status Word Register will be updated as a result of these commands. In Sel = ON(1) or OFF(0) see above description Out return = error condition --------------------------------------------------------------------------*/ MilError_t Mil1553AModeCd(MilConf_p pw_MilConf, unsigned char d_Selection) { /* bit 2 Configuration register 3 */ return(MilWriteReg(pw_MilConf, CONFIG_3, (MilReadReg(pw_MilConf, CONFIG_3)&0xfffd)|((d_Selection)?0x0002:0))); } /*-------------------------------------------------------------------------- Name MilWordBoundaries Description Enables or disables word boundaries on stack pointers usually used for backwards compatibility to older products. In Sel = ON enables rollover at word boundaries Out return = error condition --------------------------------------------------------------------------*/ MilError_t MilWordBoundaries(MilConf_p pw_MilConf, unsigned char d_Selection) { /* bit 10 configuration register 2 */ return(MilWriteReg(pw_MilConf, CONFIG_2, (MilReadReg(pw_MilConf, CONFIG_2)&0xfbff)|((d_Selection)?0:0x0400))); } /*-------------------------------------------------------------------------- Name MilRamParityCheck Description Enables ram parity checking on all ram accesses. If ram parity fails the ram parity interrupt request will be generated. In Sel = ON enables ram parity checking Out return = error condition --------------------------------------------------------------------------*/ MilError_t MilRamParityCheck(MilConf_p pw_MilConf, unsigned char d_Selection) { return(MilWriteReg(pw_MilConf, CONFIG_2, (MilReadReg(pw_MilConf, CONFIG_2)&0xbfff)|((d_Selection)?0x4000:0))); } /*-------------------------------------------------------------------------- Name MilClockSel Description Selects a 12 Mhz or 16 Mhz clock source. In Clock = CLOCK_16 selects a 16 Mhz clock CLOCK_12 selects a 12 Mhz clock Out return = error condition --------------------------------------------------------------------------*/ MilError_t MilClockSel(MilConf_p pw_MilConf, unsigned char d_Selection) { return(MilWriteReg(pw_MilConf, CONFIG_5, (MilReadReg(pw_MilConf, CONFIG_5)&0x7fff)|((d_Selection)?0x8000:0))); } /*-------------------------------------------------------------------------- Name MilSamplingSel Description Selects double or single edge signal sampling. In Sel = SINGLE_EDGE selects single edge sampling DOUBLE_EDGE selects double edge sampling Out return = error condition --------------------------------------------------------------------------*/ MilError_t MilSamplingSel(MilConf_p pw_MilConf, unsigned char d_Selection) { return(MilWriteReg(pw_MilConf, CONFIG_5, (MilReadReg(pw_MilConf, CONFIG_5)&0x3fff)|((d_Selection)?0x4000:0))); } /*-------------------------------------------------------------------------- Name MilReadTimeTag Description Reads and returns data from the timetag register. Out return = 'data' read from the time tag clock --------------------------------------------------------------------------*/ unsigned int MilReadTimeTag(MilConf_p pw_MilConf) { return(MilReadReg(pw_MilConf, TIMETAG)); } /*-------------------------------------------------------------------------- Name MilTimeout Description Configures the ACE to define the length of a response timeout. In Value = predefined constant representing a response timeout length Out return = error condition --------------------------------------------------------------------------*/ MilError_t MilTimeout(MilConf_p pw_MilConf, unsigned int j_Value) { return(MilWriteReg(pw_MilConf, CONFIG_5, (MilReadReg(pw_MilConf, CONFIG_5)&0xf9ff)|j_Value)); } /*-------------------------------------------------------------------------- Name MilTimeTagResolution Description Configures the ACE to define the time tag counter resolution. In Value = predefined constant representing the desired resolution Out return = error condition --------------------------------------------------------------------------*/ MilError_t MilTimeTagResolution(MilConf_p pw_MilConf, unsigned int j_Value) { /* write the bits 7,8,9 in the CONFIG_2 register */ return(MilWriteReg( pw_MilConf, CONFIG_2, (MilReadReg(pw_MilConf, CONFIG_2)&0xfc7f)|j_Value)); } /*-------------------------------------------------------------------------- Name MilTimeTagTest Description Increments tt register if timetag test mode is active. Out return = error condition --------------------------------------------------------------------------*/ MilError_t MilTimeTagTest(MilConf_p pw_MilConf) { return(MilWriteReg(pw_MilConf,CONTROL,0x0010)); } /*-------------------------------------------------------------------------- Name MilTimeTagReset Description Resets tt register to 0000h. Out return = error condition --------------------------------------------------------------------------*/ MilError_t MilTimeTagReset(MilConf_p pw_MilConf) { return(MilWriteReg(pw_MilConf, CONTROL,0x0008)); } /*-------------------------------------------------------------------------- Name MilReset Description ACE software reset. Messages are aborted, all registers are reset to 0000h and internal states re-initialized. Out return = error condition --------------------------------------------------------------------------*/ MilError_t MilReset(MilConf_p pw_MilConf) { /* set the bit 0 in the Start/Reset register */ return(MilWriteReg(pw_MilConf, CONTROL,0x0001)); } /*-------------------------------------------------------------------------- Name MilValidMENoData Description When ACE recieves an rx command that has been illigalized, this determines if the ace will store the data words to ram. In Sel = ON will NOT store illegal rx data Out return = error condition --------------------------------------------------------------------------*/ MilError_t MilValidMENoData(MilConf_p pw_MilConf, unsigned int j_Selection) { return(MilWriteReg(pw_MilConf, CONFIG_4, (MilReadReg(pw_MilConf,CONFIG_4)&0xffbf)|((j_Selection)?0x0040:0))); } /*-------------------------------------------------------------------------- Name MilValidBUSYNoData Description When ACE recieves an rx command when asserting the busy bit in the status word, this determines if the ace will store the data words to ram. In Sel = ON will NOT store rx data Out return = error condition --------------------------------------------------------------------------*/ MilError_t MilValidBUSYNoData(MilConf_p pw_MilConf, unsigned int j_Selection) { return(MilWriteReg(pw_MilConf, CONFIG_4, (MilReadReg(pw_MilConf,CONFIG_4)&0xffdf)|(j_Selection?0x0020:0))); } /*-------------------------------------------------------------------------- Name MilCreateCmdWord Description Creates 16 bit 1553 command word from rt, tr bit, subaddress, and word count. Added [01-JUN-1995] In rt = remote terminal number 0..31 tr = 0 rx, 1 tx sa = subadress 0..31 wc = word count/mode code 0..31 (0=32 words) Out return = error condition --------------------------------------------------------------------------*/ unsigned int MilCreateCmdWord(MilConf_p pw_MilConf, unsigned int j_Rt, unsigned int j_Tr, unsigned int j_Sa, unsigned int j_Wc) { /* built the command word */ return((((j_Rt<<11)|((j_Tr!=0)<<10)|(j_Sa<<5)|(j_Wc&0x001f)))); } /*-------------------------------------------------------------------------- Name MilEnhancedMode Description Enables or disables enhanced mode operation including enhanced interrupt features. In Sel = ON selects enhanced mode Out return = error condition --------------------------------------------------------------------------*/ MilError_t MilEnhancedMode(MilConf_p pw_MilConf,unsigned char d_Selection) { if(!pw_MilConf) return(MIL_ERROR_NOTCONFIGURED); if(d_Selection) { /* enable enhanced mode */ MilWriteReg(pw_MilConf, CONFIG_3,MilReadReg(pw_MilConf, CONFIG_3)|0x8000); /* enable enhanced interrupts */ MilWriteReg(pw_MilConf, CONFIG_2,MilReadReg(pw_MilConf, CONFIG_2)|0x8000); } else { /* disable enhanced mode */ MilWriteReg(pw_MilConf, CONFIG_3,MilReadReg(pw_MilConf, CONFIG_3)&0x7fff); /* disable enhanced interrupts */ MilWriteReg(pw_MilConf, CONFIG_2,MilReadReg(pw_MilConf, CONFIG_2)&0x7fff); } return(MIL_SUCCESS); } /*-------------------------------------------------------------------------- Name MilPreset Description Resets the ace then pre-sets to the default states assumed by the ACE software library. Out return = error condition --------------------------------------------------------------------------*/ MilError_t MilPreset(MilConf_p pw_MilConf) { if(!pw_MilConf) return(MIL_ERROR_NOTCONFIGURED); /* reset the chip register */ MilReset(pw_MilConf); /* enable enhanced mode and enhanced interrupt */ MilEnhancedMode(pw_MilConf, ON); /* set the time tag resolution in microsecond in this case is set 2 microsecond*/ MilTimeTagResolution(pw_MilConf, MIL_TIMETAG_2); /* set the interrupt pulse or level*/ MilIrqType(pw_MilConf,pw_MilConf->d_MilIrqType); /* Do not Auto clear the Interrupt status after the read */ MilIrqAutoClear(pw_MilConf, OFF); /* disable the interrupt */ MilIrqDisable(pw_MilConf, 0xffff); return(MIL_SUCCESS); } /*-------------------------------------------------------------------------- Name MilGetMsgType Description Uses message structure to determine the message type. In msg = a pointer to a message for which message type is to be determined In mode = BCmode uses the msg type in bus controller mode MTmode uses the msg type in monitor mode Out return = value indicating the type of message --------------------------------------------------------------------------*/ /* U16BIT __BUDECL BuGetMsgType(BuConf_p BuConf, MsgType*msg,U8BIT Mode) { U16BIT rt,tr,sa,wc;U8BIT type; BuParseCmdWord(BuConf, msg->CmdWord1,&rt,&tr,&sa,&wc); type=tr<<3; type|=((rt==BRDCSTRTADDRVAL)?2:0); if((sa==MODESADDRVAL1)||(sa==MODESADDRVAL2)) { type|=4; type|=((wc&0x10)?1:0); } else { if(Mode==MTmode)type|=((msg->BlockStatus&MT_RTTORT)?1:0); else if(Mode==BCmode)type|=((msg->ControlWord&CW_RTTORT)?1:0); } switch(type) { case BCTORT: case RTTORT: case BRDCST: case BRDCSTRTTORT: case MODENODATA: case MODEDATARX: case BRDCSTMODENODATA: case BRDCSTMODEDATA: case RTTOBC: case MODEDATATX: break; default:type=INVALID;break; } msg->Type=type; return(type); } */ /*-------------------------------------------------------------------------- Name BuGetMsgWordCount Description Returns the length of a decoded message. In msg = a pointer to a message for which number of data words is to be determined Out return = number of data words in the message --------------------------------------------------------------------------*/ /* U16BIT __BUDECL BuGetMsgWordCount(BuConf_p BuConf, MsgType*msg) { U16BIT rt,tr,sa,wc; BuParseCmdWord(BuConf, msg->CmdWord1,&rt,&tr,&sa,&wc); switch(msg->Type) { case BRDCSTMODENODATA: case MODENODATA:return(msg->WordCount=0); case MODEDATARX: case MODEDATATX: case BRDCSTMODEDATA:return(msg->WordCount=1); default:return(msg->WordCount=wc?wc:32); } } */ /*-------------------------------------------------------------------------- Name BuCmdStr Description Converts 1553 command word into string. In value = command word Out return = ptr to string buffer containing command word string --------------------------------------------------------------------------*/ /* char* __BUDECL BuCmdStr(BuConf_p BuConf, U16BIT value) { static char buffer[32]; U16BIT rt,sa,tr,wc; BuParseCmdWord(BuConf, value,&rt,&tr,&sa,&wc); sprintf(buffer,"%02d-%c-%02d-%02d",rt,(tr)?'T':'R',sa,wc); return(buffer); } */ /*-------------------------------------------------------------------------- Name BuMsgTypeStr Description Converts defined message type constant value into string describing message type. In value = message type Out return = ptr to string buffer containing message description --------------------------------------------------------------------------*/ /* static char *MessageType[]=MsgTypeString; char* __BUDECL BuMsgTypeStr(BuConf_p BuConf, U8BIT value) { return(MessageType[value]); } */ /*-------------------------------------------------------------------------- Name MilParseCmdWord Description Receives a command word and calculates the rt address, the subaddress, the transmit or receive bit, and the word count. In cmdword = value of the command word to be parsed Out rt = rt address Out tr = transmit/receive bit Out sa = subaddress Out wc = word count --------------------------------------------------------------------------*/ void MilParseCmdWord(MilConf_p pw_MilConf, unsigned int j_CmdWord, unsigned int *j_Rt, unsigned int *j_Tr, unsigned int *j_Sa, unsigned int *j_Wc) { *j_Rt=(j_CmdWord&0xf800)>>11; *j_Tr=(j_CmdWord&0x0400)>>10; *j_Sa=(j_CmdWord&0x03e0)>>5; *j_Wc=(j_CmdWord&0x001f); } /******************************************************************** * * MilRTSelfTest - Test of ACE chip * * Description * The function performs the ACE chip autotest * * ARGUMENTS * Input Parameters * - pw_MilConf Mil1553 management structure * * Output Parameters * N/A * * Global Variables * * RETURNS: error condition * * SEE ALSO: * * * INTERNAL * This section will not appear in the generated manual entry. * */ MilError_t MilRTSelfTest(MilConf_p pw_MilConf) { return MIL_SUCCESS; } // ---------------------------------------------------------------------------// // ---------------------------------------------------------------------------// /* * modification history * -------------------- * $Log: MilInit.c,v $ * Revision 1.10 2006/10/20 09:22:14 lorenzo * 1553 library updated * * Revision 1.7 2006/06/07 11:44:55 scige * Some More Comment * by Scige John Liu IFSI * * Revision 1.6 2006/02/15 14:56:56 scige * Abstract comment reformatted * History log replaced or moved at end of file * * */