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

📄 lin_driver.c

📁 LIN_InitNode_C161xx.h preconfiguration for C161xx LIN_InitNode_C164xx.h preconfiguration for C164
💻 C
📖 第 1 页 / 共 5 页
字号:
// @AppNote
//    
//----------------------------------------------------------------------------
//****************************************************************************
void LIN_vWakeUpProcedure(void)  
{
   static unsigned char ucLocalCounter;
   if(ucLocalCounter < 3)
   {
      ucLocalCounter++;
      nNODE_STATUS = l_sleep;
      LIN_vSendWakeUp();
   }
   else if(ucLocalCounter == 3)
   {
      ucLocalCounter = 0;
      nNODE_STATUS = l_sleep;
      // Loads CapCom and Timer Register and starts Timer and IRQ
      LIN_vHandleCapCom(T_T3BRK, ZERO);  
   }
}
//****************************************************************************
// USER CODE END: void LIN_vWakeUpProcedure(void)  



//****************************************************************************
// @Function   void LIN_vReceiveSynch0x00(unsigned char *pucLocalHelpS1RBUF)  
//
//----------------------------------------------------------------------------
// @Description   
//                this function handles the receiveing of the synchbreakfield
//                by detecting 0x00 in slower baudrate
//----------------------------------------------------------------------------
// @Returnvalue   none
//----------------------------------------------------------------------------
// @Parameters    pointer uchar: pointer at the received byte
//----------------------------------------------------------------------------
// @Date          07/21/2000
//
//****************************************************************************
//----------------------------------------------------------------------------
// @Global Variables
//    nTRANSCEIVER_STATUS
//    nERROR_STATUS
//----------------------------------------------------------------------------
// @AppNote
//    STATE: TS2
//    This function was separated from the Rxd-Interrupt-function to get
//    a better overview there.
//----------------------------------------------------------------------------
//****************************************************************************
#ifdef MASTER
void LIN_vReceiveSynch0x00(unsigned char *pucLocalHelpS1RBUF)  
{
   if(*pucLocalHelpS1RBUF == LIN_SYNCHBREAK)
   {
   ASC_BAUDRATE_REGISTER = BAUDRATE_ASC;
//      LIN_vEnableRXD();    // enable Rxd 

      if(nPENDING_STATUS == l_wakeup_pending)
      {
         nPENDING_STATUS = l_default_pending;
      }

      ucMessageSent = 0; 
      // next state
      //////////////////////////////////////////////////////////////////////// 
      nTRANSCEIVER_STATUS = l_synchbreak_done; // STATE: =TS3
      //////////////////////////////////////////////////////////////////////// 
      // send synchfield 0x55
    	ASC_TRANSMIT_BUFFER_REGISTER = LIN_SYNCHFIELD; 
   }
   else
   {
      nERROR_STATUS |= l_bit_error; // error-handling: 
      LIN_vDefaultCondition(); // set default values

   }
}
#endif
//****************************************************************************
// USER CODE END:void LIN_vReceiveSynch0x00(unsigned char *pucLocalHelpS1RBUF)  





//****************************************************************************
// @Function      void LIN_vReceiveSynchBreak(uchar *pucLocalHelpS1RBUF)  
//
//----------------------------------------------------------------------------
// @Description   
//                this function handles the receiveing of the synchbreakfield
//----------------------------------------------------------------------------
// @Returnvalue   none
//----------------------------------------------------------------------------
// @Parameters    pointer uchar: pointer at the received byte
//----------------------------------------------------------------------------
// @Date          06/05/2000
//
//****************************************************************************
//----------------------------------------------------------------------------
// @Global Variables
//    nNODE_STATUS
//    nTRANSCEIVER_STATUS
//    nERROR_STATUS
//----------------------------------------------------------------------------
// @AppNote
//    STATE: TS1
//    This function was separated from the Rxd-Interrupt-function to get
//    a better overview there.
//----------------------------------------------------------------------------
//****************************************************************************
#ifdef SLAVE
void LIN_vReceiveSynchBreak(unsigned char *pucLocalHelpS1RBUF)  
{
   if(*pucLocalHelpS1RBUF == LIN_SYNCHBREAK)
   {
      // Loads CapCom and Timer Register and starts Timer and IRQ
      // TIME_FRAMEMAX8 is default and will be corrected if the NOD is known
      // for this the ID-field must be evaluated.
      LIN_vHandleCapCom(TIME_FRAMEMAX8, ZERO);
      nNODE_STATUS = l_not_ready_for_synchbreak;
      
      //////////////////////////////////////////////////////////////////////// 
      nTRANSCEIVER_STATUS = l_synchbreak_done; /// STATE: =TS4
      //////////////////////////////////////////////////////////////////////// 
      
      // reset flag, The user should have been read this flag before
      ucMessageSent = 0; 

      // now the master-task has answered, reset the wake-up pending
      if(nPENDING_STATUS == l_wakeup_pending)
      {
         nPENDING_STATUS = l_default_pending;
      }
   }
   else
   {
      nERROR_STATUS |= l_bit_error; // error-handling: 
      LIN_vDefaultCondition(); // set default values
   }
}
#endif
//****************************************************************************
// USER CODE END: void LIN_vReceiveSynchBreak(uchar *pucLocalHelpS1RBUF)  




//****************************************************************************
// @Function      void LIN_vReceiveSynchField(*pucLocalHelpS1RBUF)  
//
//----------------------------------------------------------------------------
// @Description   
//                this function handles the receiveing of the synchfield
//----------------------------------------------------------------------------
// @Returnvalue   none
//----------------------------------------------------------------------------
// @Parameters    uchar pointer at the received byte
//----------------------------------------------------------------------------
// @Date          06/19/2000
//
//****************************************************************************
//----------------------------------------------------------------------------
// @Global Variables
//    nTRANSCEIVER_STATUS
//    nERROR_STATUS
//    stLinTransceiveBuffer[] : The LIN-Transceive-Buffer, this buffer is
//    used by the LIN-Functions to send and receive messages. If a message 
//    should be sent then all data and Id must be saved in this buffer first.
//    And if a message has been received, the ID and the data will be saved
//    in this buffer, too. 
//----------------------------------------------------------------------------
// @AppNote
//    STATE: TS4
//    This function was separated from the Rxd-Interrupt-function to get
//    a better overview there.
//----------------------------------------------------------------------------
//****************************************************************************
void LIN_vReceiveSynchField(unsigned char *pucLocalHelpS1RBUF)  
{
   // synchbreak done, next byte must be 0x55
   // if received byte is the synch-field 
   if(*pucLocalHelpS1RBUF == LIN_SYNCHFIELD)
   {  
      // set bit-flag that 0x55 has been received
      //////////////////////////////////////////////////////////////////////// 
      nTRANSCEIVER_STATUS = l_synchfield_received; // STATE: =TS5
      //////////////////////////////////////////////////////////////////////// 

      #ifdef MASTER
         // the master-node set the wake-up pending 
         // now, the master-task has received the synchfield itself
         // reset the wake-up pending, the bus should be awake
         if(nPENDING_STATUS == l_wakeup_pending)
         {
            nPENDING_STATUS = l_default_pending;
         }
         // create the ID-field and send it to the bus
         ASC_TRANSMIT_BUFFER_REGISTER = \
         LIN_ucCreateID(stLinTransceiveBuffer[BUFFER_1].ucId); 
      #endif
   }
   else           // if received byte is not the synchfield then 
   {              
      nERROR_STATUS |= l_inconsistent_synch_field_error; // set error flag
      LIN_vDefaultCondition(); // set default-condition
   }
}
//****************************************************************************
// USER CODE END: void LIN_vReceiveSynchField(*pucLocalHelpS1RBUF)  




//****************************************************************************
// @Function      void LIN_vReceiveIdField(*pucLocalHelpS1RBUF)  
//
//----------------------------------------------------------------------------
// @Description   
//                this function handles the receiveing of the ID-field
//----------------------------------------------------------------------------
// @Returnvalue   none
//----------------------------------------------------------------------------
// @Parameters    uchar pointer at the received byte
//----------------------------------------------------------------------------
// @Date          06/19/2000
//
//****************************************************************************
//----------------------------------------------------------------------------
// @Global Variables
//    nTRANSCEIVER_STATUS
//    nERROR_STATUS
//    stLinTransceiveBuffer[] : The LIN-Transceive-Buffer, this buffer is
//    used by the LIN-Functions to send and receive messages. If a message 
//    should be sent then all data and Id must be saved in this buffer first.
//    And if a message has been received, the ID and the data will be saved
//    in this buffer, too. 
//----------------------------------------------------------------------------
// @AppNote
//    STATE: TS5
//    This function was separated from the Rxd-Interrupt-function to get
//    a better overview there.
//----------------------------------------------------------------------------
//****************************************************************************
void LIN_vReceiveIdField(unsigned char *pucLocalHelpS1RBUF)  
{
   unsigned int uiLocHelp;
   // get and save Number of Data
   stLinTransceiveBuffer[BUFFER_1].ucNOD = LIN_ucGetNOD(*pucLocalHelpS1RBUF);

   // Correction calculation of Time_FrameMax
   uiLocHelp = stLinTransceiveBuffer[BUFFER_1].ucNOD;
   // Time_FrameMax= (10*Ndata+45)*1,4
   // the 1.018 is a correction because the normal bittime
   // should be 52,08us but the real bittime is 51,2 us.
   CC_REGISTER = LIN_uiCalcTFrameMax(uiLocHelp); // correct compare_register
   // save Id from received idfield in the LIN-transceive-buffer
   stLinTransceiveBuffer[BUFFER_1].ucId = LIN_ucGetID(*pucLocalHelpS1RBUF);   

   // create the IDfield and compare it with the received one (parity ok?)
   if(LIN_ucCreateID(stLinTransceiveBuffer[BUFFER_1].ucId) \
      == *pucLocalHelpS1RBUF)
   {                             
      // get Node-Mode of the received id (checks all defined IDs)

      //////////////////////////////////////////////////////////////////////// 
      nTRANSCEIVER_STATUS = \
         LIN_ucGetMode(stLinTransceiveBuffer[BUFFER_1].ucId);
      //////////////////////////////////////////////////////////////////////// 
      // now the status in the Transceiver_status-byte is set.
      // eihter: TS6, TS7 or TS8

      if(nTRANSCEIVER_STATUS == l_i_am_transmitter) // == TS6 ?
      {
         // Set flag that a message is sending. To check if this message 
         // will be sent correct the User-Application 
         // should read this flag after the flag "ready_for_synchbreak"
         // is set beyond this transfer. Is the User-Application is not 
         // waiting for the "ready_for_synchbreak" it could be that
         // the message transfer is still going on and a wrong
         // error-status will be read.
         ucMessageSent = 1; 

         // SxR = 1 enable baudrate generator
         ASC_CONTROL_REGISTER |= ASC_BAUDRATE_GENERATOR_RUN_BIT;   
         // send first byte
         // User Call Back Function will be invoked because it's up to 
         // the user to process/send the requested data. Normally, the  
         // user should use the provided LIN-Function: 
         // LIN_ucSendData(uchar* ucLocalData)
         // then the data (with startaddress = parameter) and the 
         // checksum will be sent as simple as possible for the user.
         (*pvfUcbTxdId)(stLinTransceiveBuffer[BUFFER_1].ucId);  
      } 
   }
   else
   {
      nERROR_STATUS |= l_id_parity_error; // set error-flag
      LIN_vDefaultCondition(); // set default-condition 
   }

}
//****************************************************************************
// USER CODE END: void LIN_vReceiveIdField(*pucLocalHelpS1RBUF)  










//****************************************************************************
// @Function      void LIN_vIAmTransmitter(*pucLocalHelpS1RBUF)  
//
//----------------------------------------------------------------------------
// @Description   
//    this function handles the transmitter status, if the ID (sent by the
//    header) was detected as a "I am transmitter"-status ID in this node then 
//    sent the data-bytes (using the LIN transceive-buffer)
//----------------------------------------------------------------------------
// @Returnvalue   none
//----------------------------------------------------------------------------
// @Parameters    uchar pointer at the received byte

//----------------------------------------------------------------------------
// @Date          06/05/2000
//
//****************************************************************************
//-----------------------------

⌨️ 快捷键说明

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