⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 elinmint.h

📁 这个是我在microchip公司的网站下载的PIC18系列单片的一些驱动程序
💻 H
📖 第 1 页 / 共 3 页
字号:
//*********************************************************************
// CRC union, used to define the checksum used by LIN and at the 
// same time to allow the bit by bit access
//*********************************************************************

typedef union ELINMINT_CRC
{
 int CRC;
 BYTE CRCL;
 struct
 {
  unsigned CRC0:1;
  unsigned CRC1:1;
  unsigned CRC2:1;
  unsigned CRC3:1;
  unsigned CRC4:1;
  unsigned CRC5:1;
  unsigned CRC6:1;
  unsigned CRC7:1; 
  unsigned CRC8:1;
  unsigned CRC9:1;
  unsigned CRC10:1;
  unsigned CRC11:1;
  unsigned CRC12:1;
  unsigned CRC13:1;
  unsigned CRC14:1;
  unsigned CRC15:1; 
 }CRCbits;
} ELINMINT_CRC;

//*********************************************************************
// STATUS union, used to define the main status in a way to permit the 
// bit by bit access
//*********************************************************************


#define ELINMINT_IDLEBIT_POSITION       0x08                            // IDLE bit position in status byte, must be kept up to date

typedef union ELINMINT_STATUS
{
 BYTE ELINMIntStatusByte;
 struct
 {
  unsigned TX:1;                                                        // transmitting active flag
  unsigned RX:1;                                                        // reception active flag
  unsigned ERROR:1;                                                     // error flag
  unsigned IDLE:1;                                                      // protocol IDLE flag
  unsigned ERROR_BIT0:1;                                                // error definition nibble
  unsigned ERROR_BIT1:1;  
  unsigned ERROR_BIT2:1;
  unsigned ERROR_BIT3:1;  
 }ELINMINTSTS;
}ELINMINT_STATUS;

//*********************************************************************
// ELINMINT_STATUS1 union, used to define auxiliar status in a way to 
// permit the bit by bit access
//*********************************************************************

typedef union ELINMINT_STATUS1
{
 BYTE ELINMIntStatusByte;
 struct
 {
  unsigned WAKEUP:1;                                                    // wake-up in process flag
  unsigned HEADER:1;                                                    // header in transmission flag
  unsigned FRAME:1;                                                     // frame in transmission flag
  unsigned EXTENDED:1;                                                  // Extended message size flag
  unsigned WAKEUP_RECEIVED:1;                                           // wake-up signal received from slave
  unsigned WAKEUP_SENT:1;                                               // wake-up signal sent to slaves
  unsigned SLEEP_TIMEOUT:1;                                             // bus idle time-out flag
 }ELINMINTSTS;
}ELINMINT_STATUS1;


/*********************************************************************
 * Function:    BYTE _ELINMIntInitialize(void)
 *
 * PreCondition:
 *
 * Input:

 * Output:      0=NO Error
 *              !0=ERROR CODE
 *
 * Side Effects:
 *
 * Stack Requirements:
 *
 * Overview:	This procedure Initializes:
 *                      The Baud Rate
 *                      Reception Interrupt (enabled)
 *                      Protocol Status bytes - > put protocol in IDLE 
 *                      Interbyte timing
 *                      
 ********************************************************************/
BYTE _ELINMIntInitialize(void);

/*********************************************************************
 * Function:    void ELINMIntHandler(void)
 
 *
 * PreCondition:    
 *
 * Input:           
 *
 * Output:          
 *
 * Side Effects:    
 *
 * Stack Requirements: 
 *
 * Overview:	This procedure process LIN interrupt related tasks
 *
 ********************************************************************/
void ELINMIntHandler(void);

/*********************************************************************
 * Function: 	void _ELINMIntSendMessage(BYTE id,char size,unsigned int fmin,unsigned int fmax)
 *
 * PreCondition:mELINMIntInitialize invoked    
 *
 * Input: 	The pointer to the original message to be sent
 *			The ID
 *			The size of the message
 *			The minimum frame time
 *			The maximum frame time
 *					
 *
 * Output:  
 *
 * Side Effects:    
 *
 * Stack Requirements: 
 *
 * Overview:	This function sends a message thru LIN 
 *
 ********************************************************************/
void _ELINMIntSendMessage(BYTE id,char size,unsigned int fmin,unsigned int fmax);

/*********************************************************************
 * Function:    void _ELINMIntResetProtocol(BYTE code)
 *
 * PreCondition:
 *
 * Input:	code - any eventual error code
 *					
 * Output:			
 *
 * Side Effects:
 *
 * Stack Requirements:
 *
 * Overview:	This procedure resets the protocol and if necessary 
 * 		sets the error flags
 *
 ********************************************************************/
void _ELINMIntResetProtocol(BYTE code);

/*********************************************************************
 * Function: 	void _ELINMIntReceiveMessage(BYTE tag,BYTE id,char size);
 *
 * PreCondition:mELINMIntInitialize invoked
 *
 * Input: 	The tag (message identifier)
 *		The ID used in reception
 *		The size of the message
 *
 * Output:  
 *
 * Side Effects:    
 *
 * Stack Requirements: 
 *
 * Overview:	This function receive a message thru LIN 
 *
 ********************************************************************/
void _ELINMIntReceiveMessage(BYTE tag,BYTE id,char size);

/*********************************************************************
 * Function:	BYTE *_ELINMIntGetPointer(char _ELINMInt_tag, BYTE _ELINMInt_position)
 *
 * PreCondition:mELINMIntInitialize invoked
 *		TX Buffer Available (using mELINMIntTXBufferAvailable())
 *
 * Input:
 *              _ELINMInt_tag - The specific message tag 
 *              to be associated with the TX message buffer.
 *              _ELINMInt_position - the position of the buffer to be 
 *              returned. 
 *
 * Output:	A pointer to the TX data buffer to be loaded.
 *
 * Side Effects:
 *
 * Stack Requirements:
 *
 * Overview:    This function takes a tag and associates it with a
 *              TX buffer and returns a BYTE pointer that allows the user
 *              to load the message to be transmitted. The tag lets the
 *              user identifies his(hers) message in case of an error
 *
 * OBS:         This function is not invoked directly by the user but
 *              through a macro (mELINMIntGetTXPointer(tag))
 ********************************************************************/
BYTE *_ELINMIntGetPointer(char _ELINMInt_tag, BYTE _ELINMInt_position);

/*********************************************************************
 * Function:    BYTE _ELINMIntCalcIDParity(ELINMINT_ID ELINM_idtr)
 *
 * PreCondition:
 *
 * Input:	ID 
 *
 * Output:	ID with parity bits set
 *
 * Side Effects:    
 *
 * Stack Requirements:
 *
 * Overview:	This functions calculates the Parity.
 *
 ********************************************************************/
BYTE _ELINMIntCalcIDParity(ELINMINT_ID ELINM_idtr);

/*********************************************************************
 * Macro:       mELINMIntSendMessage(tag,i,s)
 *
 * PreCondition:mELINMIntInitialize() invoked. 
 *              TX Buffer available 
 *
 * Input: 	tag - message tag
 *		i - ID of the message
 *		s  - size in bytes
 *				
 * Output:		
 *
 * Side Effects:        
 *
 * Note:        This macro calculates the frame's maximum and and minimum 
 *              times and passes all this info to the related function. If 
 *              the size of the message is passed to the macro as a constant 
 *              then the calculations are done in compile time, therefore 
 *              saving both time and space, being the recommended method.
 *              It will also work when a variable is passed as a parameter,
 *              but the calculations will be done in real-time.
 *                      	
 ********************************************************************/
#define         mELINMIntSendMessage(tag,i,s)	_ELINMIntSendMessage(i,s,(((((s+3)*10L)+44L)*ELINMINT_CORRECTION_FACTOR)/100L),((((((((s+3)*10L)+44L)+1L)*14L)/10L)*ELINMINT_CORRECTION_FACTOR)/100L))

/*********************************************************************
 * Macro:       mELINMIntTXBufferAvailable()
 *
 * PreCondition:mELINMIntInitialize() invoked.
 *
 * Input:
 *
 * Output:	1 = buffer available for TX
 *		0 = NO buffer available
 *
 * Side Effects:
 *
 * Note:
 *
 ********************************************************************/
#define         mELINMIntTXBufferAvailable()		(_ELINMIntStatus.ELINMINTSTS.IDLE)

/*********************************************************************
 * Macro: 	mELINMIntRXBufferAvailable()
 *
 * PreCondition:mELINMIntInitialize() invoked.                 
 *
 * Input: 		
 *
 * Output:      1 = buffer available for RX
 *		0 = NO buffer available
 *
 * Side Effects:
 *
 * Note:  			
 *
 ********************************************************************/
#define         mELINMIntRXBufferAvailable()		(_ELINMIntStatus.ELINMINTSTS.IDLE)

/*********************************************************************
 * Macro: 	mELINMIntGetMessageTag()
 *
 * PreCondition:mELINMIntInitialize() invoked.                                 
 *
 * Input: 		
 *
 * Output:      Returns the tag of the received message.
 *
 * Side Effects:
 *
 * Note:        			
 *
 ********************************************************************/
#define         mELINMIntGetMessageTag()		(_ELINMIntMessageTag)

/*********************************************************************
 * Macro: 	mELINMIntTXErrorDetected()
 *
 * PreCondition:mELINMIntInitialize() invoked.                                  
 *
 * Input: 		
 *
 * Output:	1 = error in transmission detected!
 *              0 = NO error detected
 *	
 * Side Effects:
 *
 * Note:  			
 *
 ********************************************************************/
#define         mELINMIntTXErrorDetected()		(_ELINMIntStatus.ELINMINTSTS.ERROR)	

/*********************************************************************
 * Macro: 	mELINMIntRXErrorDetected()
 *
 * PreCondition:mELINMIntInitialize() invoked.                                  
 *
 * Input: 		
 *
 * Output:	0 = error in reception detected
 *			
 * Side Effects:
 *
 * Note:  			
 *
 ********************************************************************/
#define         mELINMIntRXErrorDetected()		(_ELINMIntStatus.ELINMINTSTS.ERROR)	

/*********************************************************************
 * Macro:	mELINMIntTXErrorCode(tag)
 *
 * PreCondition:Error been detected by mELINMIntRXErrorDetected()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -