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

📄 lin_driver.c

📁 LIN_InitNode_C161xx.h preconfiguration for C161xx LIN_InitNode_C164xx.h preconfiguration for C164
💻 C
📖 第 1 页 / 共 5 页
字号:
   stLinIdInfo[ucLocalCounter].ucId  = REC_ID14;
   stLinIdInfo[ucLocalCounter++].ucType = REC_TYPE;
#endif
#ifdef REC_ID15
   stLinIdInfo[ucLocalCounter].ucId  = REC_ID15;
   stLinIdInfo[ucLocalCounter++].ucType = REC_TYPE;
#endif

#ifdef SLAVE
   stLinIdInfo[ucLocalCounter].ucId  = ZERO;
   stLinIdInfo[ucLocalCounter++].ucType = REC_TYPE;
#endif


// monitor-message-buffer
#ifdef MON_ID0
   stLinIdInfo[ucLocalCounter].ucId  = MON_ID0;
   stLinIdInfo[ucLocalCounter++].ucType = MON_TYPE;
#endif
#ifdef MON_ID1
   stLinIdInfo[ucLocalCounter].ucId  = MON_ID1;
   stLinIdInfo[ucLocalCounter++].ucType = MON_TYPE;
#endif
#ifdef MON_ID2
   stLinIdInfo[ucLocalCounter].ucId  = MON_ID2;
   stLinIdInfo[ucLocalCounter++].ucType = MON_TYPE;
#endif
#ifdef MON_ID3
   stLinIdInfo[ucLocalCounter].ucId  = MON_ID3;
   stLinIdInfo[ucLocalCounter++].ucType = MON_TYPE;
#endif
#ifdef MON_ID4
   stLinIdInfo[ucLocalCounter].ucId  = MON_ID4;
   stLinIdInfo[ucLocalCounter++].ucType = MON_TYPE;
#endif
#ifdef MON_ID5
   stLinIdInfo[ucLocalCounter].ucId  = MON_ID5;
   stLinIdInfo[ucLocalCounter++].ucType = MON_TYPE;
#endif
#ifdef MON_ID6
   stLinIdInfo[ucLocalCounter].ucId  = MON_ID6;
   stLinIdInfo[ucLocalCounter++].ucType = MON_TYPE;
#endif
#ifdef MON_ID7
   stLinIdInfo[ucLocalCounter].ucId  = MON_ID7;
   stLinIdInfo[ucLocalCounter++].ucType = MON_TYPE;
#endif
#ifdef MON_ID8
   stLinIdInfo[ucLocalCounter].ucId  = MON_ID8;
   stLinIdInfo[ucLocalCounter++].ucType = MON_TYPE;
#endif
#ifdef MON_ID9
   stLinIdInfo[ucLocalCounter].ucId  = MON_ID9;
   stLinIdInfo[ucLocalCounter++].ucType = MON_TYPE;
#endif
#ifdef MON_ID10
   stLinIdInfo[ucLocalCounter].ucId  = MON_ID10;
   stLinIdInfo[ucLocalCounter++].ucType = MON_TYPE;
#endif
#ifdef MON_ID11
   stLinIdInfo[ucLocalCounter].ucId  = MON_ID11;
   stLinIdInfo[ucLocalCounter++].ucType = MON_TYPE;
#endif
#ifdef MON_ID12
   stLinIdInfo[ucLocalCounter].ucId  = MON_ID12;
   stLinIdInfo[ucLocalCounter++].ucType = MON_TYPE;
#endif
#ifdef MON_ID13
   stLinIdInfo[ucLocalCounter].ucId  = MON_ID13;
   stLinIdInfo[ucLocalCounter++].ucType = MON_TYPE;
#endif
#ifdef MON_ID14
   stLinIdInfo[ucLocalCounter].ucId  = MON_ID14;
   stLinIdInfo[ucLocalCounter++].ucType = MON_TYPE;
#endif
#ifdef MON_ID15
   stLinIdInfo[ucLocalCounter].ucId  = MON_ID15;
   stLinIdInfo[ucLocalCounter].ucType = MON_TYPE;
#endif

}
//****************************************************************************
// USER CODE END: void LIN_vCreateIdInfo()  





//****************************************************************************
// @Function      unsigned char LIN_ucGetID(unsigned char ucLocalReceivedByte)  
//
//----------------------------------------------------------------------------
// @Description   
//                this function separates the ID-number 
//                from the ID-field.
//----------------------------------------------------------------------------
// @Returnvalue   unsigned char: the id-number and lenghtcontrol 
//                without parity bits
//
//----------------------------------------------------------------------------
// @Parameters    unsigned char cLocalReceivedByte:  the idfield
//
//----------------------------------------------------------------------------
// @Date          06/19/2000
//
//****************************************************************************
//----------------------------------------------------------------------------
// @Global Variables
//    none
//----------------------------------------------------------------------------
// @AppNote
//    Example:
//
//    test = LIN_ucGetID(0x80)
//
//    test == 0     rsp.    test == 0x00
//
//****************************************************************************
unsigned char LIN_ucGetID(unsigned char ucLocalReceivedByte)
{
   ucLocalReceivedByte  &= 0x3F;
   return(ucLocalReceivedByte);
}
//****************************************************************************
// USER CODE END: unsigned char LIN_ucGetID(unsigned char ucLocalReceivedByte)






//****************************************************************************
// @Function  unsigned char LIN_ucGetNOD(unsigned char ucLocalReceivedByte)  
//
//----------------------------------------------------------------------------
// @Description   
//                this function separates "Number of Data"  from the ID-field.
//----------------------------------------------------------------------------
// @Returnvalue   unsigned char: the lenghtcontrol without Id-bits and parity 
//                bits
//                possible values: 2,4 or 8
//
//----------------------------------------------------------------------------
// @Parameters    unsigned char ucLocalReceivedByte:  the idfield
//
//----------------------------------------------------------------------------
// @Date          06/19/2000
//
//****************************************************************************
//----------------------------------------------------------------------------
// @Global Variables
//    none
//----------------------------------------------------------------------------
// @AppNote
//    Example:
//
//    test = LIN_ucGetNOD(0x80)
//
//    test == 2
//
//****************************************************************************
unsigned char LIN_ucGetNOD(unsigned char ucLocalReceivedByte)
{
   ucLocalReceivedByte  &= 0x30;
   ucLocalReceivedByte >>= 4;
   // if the result is 0, then NOD is 2 Databytes
   switch(ucLocalReceivedByte)
   {
      case 0:
         ucLocalReceivedByte = 2;  
         break;
      case 1:
         ucLocalReceivedByte = 2;  
         break;
      case 2:
         ucLocalReceivedByte = 4;  
         break;
      case 3:
         ucLocalReceivedByte = 8;  
         break;
      default:
         ucLocalReceivedByte = 2;  
   }
   return(ucLocalReceivedByte);
}
//****************************************************************************
// USER CODE END: uchar LIN_ucGet(unsigned char ucLocalReceivedByte)




//****************************************************************************
// @Function      unsigned char LIN_ucGetMode(unsigned char ucLocalId)  
//
//----------------------------------------------------------------------------
// @Description   
//    this function returns the receive-mode of the node.
//    1) Transmit Data: return-value = 6
//    2) Receive Data : return-value = 7
//    3) Monitor Data : return-value = 8
//    It's recommended to save the Return-Value in the nTRANSCEIVER_STATUS 
//    byte.
//----------------------------------------------------------------------------
// @Returnvalue   unsigned char: the Node-Mode, see above
//----------------------------------------------------------------------------
// @Parameters    uchar: the ID
//----------------------------------------------------------------------------
// @Date          06/19/2000
//
//****************************************************************************
//----------------------------------------------------------------------------
// @Global Variables
//    none
//----------------------------------------------------------------------------
// @AppNote
//    1) For-loop: scan all array-elements from 0 to EOA (End of Array)
//    2) search the array-element with the desired Id
//    3) select between Send-Type an Receive-Type and write the result in
//       the return varible
//       else: the node has monitor-function
//    4) if the Id wasn't found then checksum_ok will be returned
//----------------------------------------------------------------------------
//****************************************************************************
unsigned char LIN_ucGetMode(unsigned char ucLocalId)  
{
   unsigned char ucLocalReturn;
   unsigned char ucLocCoun;
   ucLocalReturn = l_i_am_monitor;
   
   for(ucLocCoun = 0;ucLocCoun <= MAX_LIN_ID;ucLocCoun++)
   {
      if(stLinIdInfo[ucLocCoun].ucId == ucLocalId)
      {
         if(stLinIdInfo[ucLocCoun].ucType == SEND_TYPE)
         {
            ucLocalReturn = l_i_am_transmitter;
         }
         else if(stLinIdInfo[ucLocCoun].ucType == REC_TYPE)
         {
            ucLocalReturn = l_i_am_receiver;
         }
         else
         {
            ucLocalReturn = l_i_am_monitor;
         }
      }
   }
   return(ucLocalReturn);
}
//****************************************************************************
// USER CODE END: unsigned char LIN_ucGetMode(unsigned char ucLocalId)





//****************************************************************************
// @Function  unsigned int LIN_uiCalcTFrameMax(volatile unsigned int uiLocNOD)  
//
//----------------------------------------------------------------------------
// @Description   
//                this function gets the Time-FrameMax and loads the 
//                capture compare register
//
//----------------------------------------------------------------------------
// @Returnvalue   the right maximum Time for the Frame (Time_frame_max)
//
//----------------------------------------------------------------------------
// @Parameters    unsigned int: the Number of Data
//
//----------------------------------------------------------------------------
// @Date          08/02/2000
//
//****************************************************************************
//----------------------------------------------------------------------------
// @Global Variables
//    none
//----------------------------------------------------------------------------
// @AppNote
//****************************************************************************
unsigned int LIN_uiCalcTFrameMax(volatile unsigned int uiLocNOD)  
{
   
   switch(uiLocNOD)
   {
      case 2:
         uiLocNOD = TIME_FRAMEMAX2;
         break;
      case 4:
         uiLocNOD = TIME_FRAMEMAX4;
         break;
      case 8:
         uiLocNOD = TIME_FRAMEMAX8;
         break;
      default:
         uiLocNOD = TIME_FRAMEMAX8;
   }
   return uiLocNOD;
}
//****************************************************************************
// USER CODE END: unsigned int LIN_uiCalcTFrameMax(volatile uint uiLocNOD)  





//****************************************************************************
// @Function      unsigned char LIN_ucChecksum(stLIN_MESSAGE *pstLocalHelp)  
//
//----------------------------------------------------------------------------
// @Description   
//                this function creates the checksum-field. The checksum field
//                will be calculated as a inverted sum over all data-bytes  
//                this is called inverted modulo-256. If the sum is over 0xFF 
//                the carry-bit will be set and must be added to LSB of the  
//                next addition.
//----------------------------------------------------------------------------
// @Returnvalue   unsigned char; the checksum
//----------------------------------------------------------------------------
// @Parameters    stLIN_MESSAGE *pstLocalHelp: pointer on struct, that's
//                the address of the element
//
//----------------------------------------------------------------------------
// @Date          04/26/2000
//
//****************************************************************************
//----------------------------------------------------------------------------
// @Global Variables
//    none
//----------------------------------------------------------------------------
// @AppNote
//    If the additon of two bytes is over 0xFF, in assembler  a carry-flag 
//    would be set but in C-language there is no permission on this flag so 
//    this must be calculated by an algorithm. 
//    Algorithm: If the addition is over 0xFF then a decrease in value of 0xFF 
//    must occur.
//    

⌨️ 快捷键说明

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