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

📄 lin_driver.c

📁 LIN_InitNode_C161xx.h preconfiguration for C161xx LIN_InitNode_C164xx.h preconfiguration for C164
💻 C
📖 第 1 页 / 共 5 页
字号:
// This variable stores the timer-value
// on start of receiving/transmitting- procedures if the LIN handles without
// an error then the timer can start by zero otherwise the timer will be
// loaded by the value stored in this variable. (Its for bus-Idle Time-Out
// detection)
//
// nTRANSCEIVER_STATUS:
// the transmission/receiving of a LIN message
// will be handled in a state-machine therefor
// this status byte is used to set the actually state
// of transmission or receiving a message.
//
// nNODE_STATUS
// the node can be in 3 different states
//----------------------------------------------------------------------------
// @AppNote
//----------------------------------------------------------------------------
//
//****************************************************************************
void LIN_vDefaultCondition(void)
{
   if(nPENDING_STATUS == l_wakeup_pending)
   {
      LIN_vHandleCapCom(T_T0BRK, 0x0000);// set and load timer  
   }
   else
   {
      if(nTRANSCEIVER_STATUS != l_checksum_ok) // if TS==9
      {
      // the transmission wasn't ok, reload the timer-register with the timer
      // value saved before. (for No_bus_activity_error)
         CC_TIMER_REGISTER = uiBusIdleTimeOutBuffer;
      }
      else
      {
         CC_TIMER_REGISTER = ZERO;// start timer from the beginning
      }
      // CapCom-Register:   Bus-Idle-Time
      CC_REGISTER = TIME_OUT;       // set compare_register time
      nNODE_STATUS = l_ready_for_synchbreak; // set NS2
   }
   /////////////////////////////////////////////////////////////////////////// 
   nTRANSCEIVER_STATUS = l_default_status; // set default-STATE =TS1
   /////////////////////////////////////////////////////////////////////////// 

   ASC_BAUDRATE_REGISTER = BAUDRATE_ASC;
}
//****************************************************************************
// USER CODE END: void LIN_vDefaultCondition(void)







//****************************************************************************
// @Function   void LIN_vHandleCapCom(unsigned int uiLocalCCReg, \
//                                    unsigned int uiLocalCCTimerReg)
//
//----------------------------------------------------------------------------
// @Description   
//                this function sets the CapCom Register, loads the 
//                CapCom Timer Register and activates the Interrupt
//                and starts the timer
//----------------------------------------------------------------------------
// @Returnvalue   void
//
//----------------------------------------------------------------------------
// @Parameters    uiLocalCCReg: The CapCom Register Value
//                uiLocalCCTimerReg: The CapCom Timer Register Value
//----------------------------------------------------------------------------
// @Date          06/07/2000
//
//****************************************************************************
//----------------------------------------------------------------------------
// @Global Variables
//
//----------------------------------------------------------------------------
// @AppNote
//----------------------------------------------------------------------------
//
//****************************************************************************
void LIN_vHandleCapCom(volatile unsigned int uiLocalCCReg, \
                       volatile unsigned int uiLocalCCTimerReg)
{
   // CapCom-Register:
   CC_REGISTER = uiLocalCCReg; // set compare_register
   CC_IRQ_CONTROL_REGISTER |= CC_INTERRUPT_ENABLE_BIT;
   CC_TIMER_REGISTER = uiLocalCCTimerReg; // timer value
   CC_TIMER_CONTROL_REGISTER |= CC_TIMER_RUN_BIT; // start timer
}
//****************************************************************************
// USER CODE END: void LIN_vHandleCapCom(unsigned int uiLocalCCReg, \
//                                       unsigned int uiLocalCCTimerReg)




//****************************************************************************
// @Function      void LIN_vInitNode(void)
//
//----------------------------------------------------------------------------
// @Description   
//                this function initializes the node 
//----------------------------------------------------------------------------
// @Returnvalue   void
//
//----------------------------------------------------------------------------
// @Parameters    void
//
//----------------------------------------------------------------------------
// @Date          04/05/2000
//
//****************************************************************************
//----------------------------------------------------------------------------
// @Global Variables
//
// uiBusIdleTimeOutBuffer: 
// This variable stores the timer-value
// on start of receiving/transmitting- procedures if the LIN handles without
// an error then the timer can start by zero otherwise the timer will be
// loaded by the value stored in this variable. (Its for bus-Idle Time-Out
// detection)
//
// nTRANSCEIVER_STATUS:
// the transmission/receiving of a LIN message
// will be handled in a state-machine therefor
// this status byte is used to set the actually state
// of transmission or receiving a message.
//
// nNODE_STATUS
// the node can be in 3 different states
// 1) sleep-mode
// 2) ready_for_synchbreak-mode
// 3) not_ready_for_synchbreak-mode
// 4) disconnect
//
// nPENDING_STATUS
// 1) default_pending: no pending
// 2) wakeup-pending
// 3) sleep-pending
// 
// nERROR_STATUS
// the LIN-Protocol Specification supports 6
// different kind of errors, which are flagged
// in this error status byte
//----------------------------------------------------------------------------
// @AppNote
//----------------------------------------------------------------------------
//    Important: first initiate the timer and Capcom and later initiate ASC
//
//****************************************************************************
void LIN_vInitNode(void)
{
   // init. the CapCom Registers
   LIN_vInitCapCom();    

  // Timer 0
   LIN_vInitTimer();          // init timer 0  

   // ASC1 init
   LIN_vInitASC();            // init the UART
  
   //Interrupt
   //GLOBAL_INTERRUPT = ON;

   //Create Buffer
   LIN_vCreateIdInfo();
  
   // Bytes and buffers
   uiBusIdleTimeOutBuffer = ZERO;
   LIN_vDefaultCondition();
   // Status-Register
   nERROR_STATUS       = 0x0000; // set error-status-byte 
   nNODE_STATUS        = l_disconnect; // set node-status-byte =NS1
   nPENDING_STATUS     = l_default_pending; // set pending-status-byte =PS1
   GLOBAL_INTERRUPT = ON;
   // enable UART
   ASC_CONTROL_REGISTER |= ASC_BAUDRATE_GENERATOR_RUN_BIT;
}
//****************************************************************************
// USER CODE END: void LIN_vInitNode(void)







//****************************************************************************
// @Function      unsigned char LIN_ucCreateID(unsigned char ucLocalId)  
//
//----------------------------------------------------------------------------
// @Description   
//                this function creates the ID-field.
//----------------------------------------------------------------------------
// @Returnvalue   unsigned char, the created idfield
//
//----------------------------------------------------------------------------
// @Parameters    unsigned char ucLocalId:    
//                The ID (incl. the Number of Data) of the send-message 
//                
//----------------------------------------------------------------------------
// @Date          06/19/2000
//
//****************************************************************************
//----------------------------------------------------------------------------
// @Global Variables
//    bucIdField      Bitaddressable unsigned char     MODULE: LIN_functions
//----------------------------------------------------------------------------
// @AppNote
//----------------------------------------------------------------------------
//****************************************************************************
unsigned char LIN_ucCreateID(unsigned char ucLocalId)  
{
   bucIdField=0;                    // set bitaddressable variable to 0

   bucIdField |= ucLocalId ;       // join the id together with the idfield 
   
   fb_p0 = fb_id0 ^ fb_id1 ^ fb_id2 ^ fb_id4;      //create parity p0
   fb_p1 = ~(fb_id1 ^ fb_id3 ^ fb_id4 ^ fb_id5);   //create parity -p1

   return(bucIdField);                  // return the idfield
}
//****************************************************************************
// USER CODE END: unsigned char LIN_ucCreateID(unsigned char ucLocalId)  




//****************************************************************************
// @Function      void LIN_vSetSleepMode(void)  
//
//----------------------------------------------------------------------------
// @Description   
//                this function sets the controller in sleep-mode
//----------------------------------------------------------------------------
// @Returnvalue   none
//----------------------------------------------------------------------------
// @Parameters    none
//----------------------------------------------------------------------------
// @Date          05/29/2000
//
//****************************************************************************
//----------------------------------------------------------------------------
// @Global Variables
//
// nNODE_STATUS
// the node can be in 3 different states
//----------------------------------------------------------------------------
// @AppNote
//    
//----------------------------------------------------------------------------
//****************************************************************************
void LIN_vSetSleepMode(void)  
{
if(!LIN_ucReadFlag_Disconnect())
{
   CC_IRQ_CONTROL_REGISTER &= ~CC_INTERRUPT_ENABLE_BIT; //disable Compare-IRQ
   // go in sleep-mode
   //SYSCON1 = 0x01;
   nPENDING_STATUS = l_default_pending;
   nNODE_STATUS = l_sleep;              
   SET_SLEEP_MODE;
}
}
//****************************************************************************
// USER CODE END: void LIN_vSetSleepMode(void)  




//****************************************************************************
// @Function      void LIN_vSendWakeUp(void)  
//
//----------------------------------------------------------------------------
// @Description   
//                this function sends a wakeup signal on the bus
//----------------------------------------------------------------------------
// @Returnvalue   none
//----------------------------------------------------------------------------
// @Parameters    none
//----------------------------------------------------------------------------
// @Date          05/11/2000
//
//****************************************************************************
//----------------------------------------------------------------------------
// @Global Variables
//----------------------------------------------------------------------------
// @AppNote
//    
//    This sign can only be sent if the node is really in sleep-mode
//----------------------------------------------------------------------------
//****************************************************************************
void LIN_vSendWakeUp(void)  
{
if(!LIN_ucReadFlag_Disconnect()) // if node is connected
{
   if(LIN_ucReadFlag_Sleep())
   {
//      LIN_vEnableRXD();    // enable Rxd
      nPENDING_STATUS = l_wakeup_pending; // set status for wakeup pending
      ASC_TRANSMIT_BUFFER_REGISTER = LIN_WAKEUP_CHAR; //send wake-up-signal
      CC_IRQ_CONTROL_REGISTER |= CC_INTERRUPT_ENABLE_BIT; //enable Compare-IRQ
      LIN_vHandleCapCom(T_T0BRK, 0x0000);  // set and load timer  
   }
}
}

//****************************************************************************
// USER CODE END: void LIN_vSendWakeUp(void)  






//****************************************************************************
// @Function      void LIN_vWakeUpProcedure(void)  
//
//----------------------------------------------------------------------------
// @Description   
//                this function handles the wake up procedure 
//                !!! ONLY IN SLAVE MODE !!!
//----------------------------------------------------------------------------
// @Returnvalue   none
//----------------------------------------------------------------------------
// @Parameters    none
//----------------------------------------------------------------------------
// @Date          05/31/2000
//
//****************************************************************************
//----------------------------------------------------------------------------
// @Global Variables
//    none
//----------------------------------------------------------------------------

⌨️ 快捷键说明

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