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

📄 main.c

📁 汽车电子上现在最火热的总线之一lin2.0总线的单片机实现。
💻 C
📖 第 1 页 / 共 2 页
字号:
               main_gucErrorIncIgnCycle &= (uint8_t)RES_ERR_IG_CYCLE_BUS_NOT_INCR;
            }
         }

         COPCTL = (uint8_t)0; /* reset COP counter */         

         /* update the signals */
         l_u8_wr_ERR_COU_INTL_SEAT_OCCU_PS_LIN  ( 
               EEE_ucReadErrorCounter( ERROR_COUNTER_INTERN_ADDRESS ) );
         l_u8_wr_ERR_COU_BUS_SEAT_OCCU_PS_LIN   ( 
               EEE_ucReadErrorCounter( ERROR_COUNTER_COM_ADDRESS )    );
         l_u8_wr_ERR_COU_OPC_SEAT_OCCU_PS_LIN   ( 
               EEE_ucReadErrorCounter( ERROR_COUNTER_OPEN_ADDRESS )   );
         l_u8_wr_ERR_COU_SC_SEAT_OCCU_PS_LIN    ( 
               EEE_ucReadErrorCounter( ERROR_COUNTER_SHORT_ADDRESS )  );  

      }


      COPCTL = (uint8_t)0; /* reset COP counter */
      
      /* is the LIN bus com layer still receiving/sending resp. is the time
         since the last frame was received too long? */
      if( gusTimeSinceLastSynchBreak > MAX_TIME_SINCE_SYNCH_BREAK )
      {
         /* wait for the next break, maybe the ISR stucks in another state */
         l_voWaitForNextBreak();
         gusTimeSinceLastSynchBreak = (uint16_t)0;
      }
      
      
      COPCTL = (uint8_t)0; /* reset COP counter */

      /* time to increment the OP hour counter? */
      if( (gucTimerFlag & (uint8_t)MASK_SET_OP_HOUR_FLAG) > (uint8_t)0 )
      {
         /* reset the flag */
         gucTimerFlag &= (uint8_t)MASK_RESET_OP_HOUR_FLAG;
         
         /* initiate the incrementation */
         EEE_voIncOperationHourCounter();
         EnableInterrupts; /* flash write routine disables interrupts! */

         /* update the frame signal */
         l_u16_wr_INFO_OPET_SEAT_OCCU_PS_LIN(EEE_ucReadOperationHourCounter());
      
      }

      COPCTL = (uint8_t)0; /* reset COP counter */
	

   }

   /* after leaving the "normal modus" main loop, disable the COP.
      This is not needed for QC Mode. */ 
   voDisableCOPCounter();
   
   /* as long we are in QC Mode - (only the reply-flag is allowed to be set) */
   while( (gucQCModeDisabled & ~QC_MODE_WAIT_FOR_2ND_STEP) == 0 )
   {
                  

      /* write memory */
      if( (gucQCModeFlags & QC_MODE_WRITE_MEMORY_FLAG) 
            == QC_MODE_WRITE_MEMORY_FLAG )
      {
         
         /* get address high byte to write */
         main_gucTemp  = l_u8_rd_QC_MODUS_BYTE_02();
         main_gusTemp  = (uint16_t)main_gucTemp;
         main_gusTemp  = (uint16_t)(main_gusTemp << 8);
		 
         main_gusTemp &= (uint16_t)0xFF00;

         
         /* get address low byte to write */
         main_gucTemp = l_u8_rd_QC_MODUS_BYTE_03();
         main_gusTemp |= (uint16_t)main_gucTemp;
         
         /* get the data to write */
         main_gucTemp = l_u8_rd_QC_MODUS_BYTE_04();
         
         /* only if the address is in the calibrateable range */ 
         if(   ( main_gusTemp > (CALIBRATION_DATA_ADDRESS - 1))
            && ( main_gusTemp < (CALIBRATION_DATA_ADDRESS+PAGE_SIZE)) )
         {
            /* write the data */
            EEE_voWriteMemory( main_gusTemp, main_gucTemp );
            EnableInterrupts; /* flash write routine disables interrupts! */
         }
         
         /* reset the flag */
         gucQCModeFlags &= ~QC_MODE_WRITE_MEMORY_FLAG;      
      }



      /* read memory */
      if( (gucQCModeFlags & QC_MODE_READ_MEMORY_FLAG) 
            == QC_MODE_READ_MEMORY_FLAG )
      {

         /* get address high byte to read */
         main_gucTemp = l_u8_rd_QC_MODUS_BYTE_02();
         main_gusTemp = (uint16_t)main_gucTemp;
         main_gusTemp  = (uint16_t)(main_gusTemp << 8);
         main_gusTemp &= (uint16_t)0xFF00;
         
         /* get address low byte to read */
         main_gucTemp = l_u8_rd_QC_MODUS_BYTE_03();
         main_gusTemp |= (uint16_t)main_gucTemp;

         /* read the data */
         main_gucTemp = EEE_ucReadMemory( main_gusTemp );
         EnableInterrupts; /* flash write routine disables interrupts! */

         /* and put it into the telegram buffer (as well the not used bytes) */
         l_u8_wr_QC_MODUS_BYTE_01( main_gucTemp );
         l_u8_wr_QC_MODUS_BYTE_02( 0xFF );
         l_u8_wr_QC_MODUS_BYTE_03( 0xFF );
         l_u8_wr_QC_MODUS_BYTE_04( 0xFF );
         l_u8_wr_QC_MODUS_BYTE_05( 0xFF );
         l_u8_wr_QC_MODUS_BYTE_06( 0xFF );
         l_u8_wr_QC_MODUS_BYTE_07( 0xFF );
         l_u8_wr_QC_MODUS_BYTE_08( 0xFF );
         

         /* reset the flag */
         gucQCModeFlags &= ~QC_MODE_READ_MEMORY_FLAG;      
      }



      /* clear operation hour counter */
      if( (gucQCModeFlags & QC_MODE_CLEAR_OP_HR_CNT_FLAG) 
            == QC_MODE_CLEAR_OP_HR_CNT_FLAG )
      {
         /* run clear function */
         EEE_voClearOperationHourCounter();
         EnableInterrupts; /* flash write routine disables interrupts! */
         
         /* reset the flag */
         gucQCModeFlags &= ~QC_MODE_CLEAR_OP_HR_CNT_FLAG;      
      }



      /* clear error counter */
      if( (gucQCModeFlags & QC_MODE_CLEAR_ERROR_CNT_FLAG) 
            == QC_MODE_CLEAR_ERROR_CNT_FLAG )
      {
         /* run clear function */
         EEE_voClearErrorCounter();
         EnableInterrupts; /* flash write routine disables interrupts! */
         
         /* reset the flag */
         gucQCModeFlags &= ~QC_MODE_CLEAR_ERROR_CNT_FLAG;      
      }



      /* clear calibration data */
      if( (gucQCModeFlags & QC_MODE_CLEAR_CAL_DATA_FLAG) 
            == QC_MODE_CLEAR_CAL_DATA_FLAG )
      {
         /* run clear function */
         EEE_voClearCalData();
         EnableInterrupts; /* flash write routine disables interrupts! */

         /* reset the flag */
         gucQCModeFlags &= ~QC_MODE_CLEAR_CAL_DATA_FLAG;      
      }



      /* get raw data */
      if( (gucQCModeFlags & QC_MODE_GET_RAW_DATA_FLAG) 
            == QC_MODE_GET_RAW_DATA_FLAG )
      {

         /* get the raw data for all 7 measurements */
         l_u8_wr_QC_MODUS_BYTE_01( PPD_ucSBR_Right_Meas  ( 1 ) );
         l_u8_wr_QC_MODUS_BYTE_02( PPD_ucShort_PPD_Meas  ( 1 ) );
         l_u8_wr_QC_MODUS_BYTE_03( PPD_ucPPD_Meas        ( 1 ) );
         l_u8_wr_QC_MODUS_BYTE_04( PPD_ucSBR_Left_Meas   ( 1 ) );
         l_u8_wr_QC_MODUS_BYTE_05( PPD_ucBreak_SBR_Meas  ( 1 ) );
         l_u8_wr_QC_MODUS_BYTE_06( PPD_ucShort_SBR_Meas  ( 1 ) );
         l_u8_wr_QC_MODUS_BYTE_07( PPD_ucBreak_PPD_Meas  ( 1 ) );
         l_u8_wr_QC_MODUS_BYTE_08( PPD_ucBreak_R1_Meas   ( 1 ) );

         /* reset the flag */
         gucQCModeFlags &= ~QC_MODE_GET_RAW_DATA_FLAG;      
      }



      /* get remote electronics version */
      if( (gucQCModeFlags & QC_MODE_GET_VERSION_FLAG) 
            == QC_MODE_GET_VERSION_FLAG )
      {

         /* take over the nneded information from the NCF file */
         l_voPrepare_GetRemoteElectronicsVersion();
         
         /* reset the flag */
         gucQCModeFlags &= ~QC_MODE_GET_VERSION_FLAG;      

      }
      


      /* check the CRCs */
      if( (gucQCModeFlags & QC_MODE_CHECK_CRC_FLAG) == QC_MODE_CHECK_CRC_FLAG )
      {

         /* init the measurement results with "in process" */
         l_u8_wr_QC_MODUS_BYTE_01( 0x02 );
         l_u8_wr_QC_MODUS_BYTE_02( 0x02 );

         /* check code and calibration array CRC */
         l_u8_wr_QC_MODUS_BYTE_01( DIAG_ucCheckCodeArrayCRCComplete() );
         l_u8_wr_QC_MODUS_BYTE_02( DIAG_ucCheckCalibrationArrayCRC() );
         l_u8_wr_QC_MODUS_BYTE_03( 0xFF );
         l_u8_wr_QC_MODUS_BYTE_04( 0xFF );
         l_u8_wr_QC_MODUS_BYTE_05( 0xFF );
         l_u8_wr_QC_MODUS_BYTE_06( 0xFF );
         l_u8_wr_QC_MODUS_BYTE_07( 0xFF );
         l_u8_wr_QC_MODUS_BYTE_08( 0xFF );
         
         
         /* reset the flag */
         gucQCModeFlags &= ~QC_MODE_CHECK_CRC_FLAG;  

      }
          
      
   }
 
}


/******************************************************************************/
/*! \fn void voInit_uC() 
 *  \brief Initialization of the uC
 *  \param ---
 *  \return ---
 */
void voInit_uC()
{
   
   /* Disable all interrupts */
   DisableInterrupts;
   
   
   /* Configuration Register 2                                          */
   /* bit 7:      0:       internal pullup (IRQ) is connected(0)        */
   /* bit 6:      0:       IRQ function is inactive                     */
   /* bit 5,4,3:  0,0,0:   not used                                     */
   /* bit 2:      1:       use internal bus clock for ESCI              */
   /* bit 1:      0:       oscillator disabled during stop mode         */
   /* bit 0:      1:       reset function active in pin                 */   
   CONFIG2 = (uint8_t)0x05;

   /* Configuration Register 1                                          */
   /* bit 7:   0: COP (computer operating properly) reset long cycle    */
   /* bit 6:   0: LVI (low voltage inhibit) disabled during stop mode   */
   /* bit 5:   0: LVI (low voltage inhibit) module resets enabled       */
   /* bit 4:   0: LVI (low voltage inhibit) module power enabled        */
   /* bit 3:   1: LVI (low voltage inhibit) operates in 5V mode         */
   /* bit 2:   0: short stop recovery bit                               */
   /* bit 1:   0: STOP instruction treated as illegal opcode            */
   /* bit 0:   1: COP (computer operating properly) is disabled         */
   CONFIG1 = (uint8_t)0x09; 
   COPCTL  = (uint8_t)0;                       /* reset the COP counter */
   

   /* Oscillator Status and Control Register: OSCSC                     */
   /* bit 7..6:   0,0: use internal oscillator                          */
   /* bit 5..4:   1,0: set frequency to f = 12.8MHz +/- 25%             */
   /* bit 3..2:   x,x: don't care, to set the EXTERNAL frequency        */
   /* bit 1:      x:   don't care, to put external cloxk on a port pin  */
   /* bit 0:      x:   don't care, read only                            */
   OSCSC = (uint8_t)0x20;
   
   
   /* Trim the internal oscillator:                                     */
   /* increase the value by 1 --> increases the clock period by 0.2%    */
   /* decrease the value by 1 --> decreases the clock period by 0.2%    */
   /* --> 0.2% * 127 = 25.4% !!! (here are the 25%)                     */
   /* IMPORTANT NOTE: at @0xFFC0, there is a preprogrammed Trim Value   */
   /* that had delivered a 5% precision in production !                 */
   LOAD_OSCTRIM();

}

/******************************************************************************/
/*! \fn void voEnableCOPCounter() 
 *  \brief to start and refresh COP
 *  \param ---
 *  \return ---
 */
void voEnableCOPCounter()
{
   /* note that the COP is always disabled when debugging with inDART ONE */

   COPCTL         = (uint8_t)0;     /* reset the COP counter */
   CONFIG1_COPD   = (uint8_t)0;     /* enable the COP counter */
   COPCTL         = (uint8_t)0;     /* reset the COP counter */
}

/******************************************************************************/
/*! \fn void voDisableCOPCounter() 
 *  \brief to stop COP after entering QC Mode
 *  \param ---
 *  \return ---
 */
void voDisableCOPCounter()
{
   /* note that the COP is always disabled when debugging with inDART ONE */
   COPCTL         = (uint8_t)0;     /* reset the COP counter */
   CONFIG1_COPD   = (uint8_t)1;     /* disable the COP counter */
   COPCTL         = (uint8_t)0;     /* reset the COP counter */
}




⌨️ 快捷键说明

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