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

📄 can.c

📁 开发环境为keil166
💻 C
📖 第 1 页 / 共 2 页
字号:
//                the content of the chosen HW message object.
//                
//                The structure of the SW message object is defined in the 
//                header file CAN.H (see TCAN_SWObj).
//
//----------------------------------------------------------------------------
// @Returnvalue   None
//
//----------------------------------------------------------------------------
// @Parameters    ubObjNr: 
//                Number of the message object to be read (0-31)
// @Parameters    *pstObj: 
//                Pointer on a message object to be filled by this function
//
//----------------------------------------------------------------------------
// @Date          2009-4-4
//
//****************************************************************************

// USER CODE BEGIN (GetMsgObj,1)

// USER CODE END

void CAN_vGetMsgObj(ubyte ubObjNr, TCAN_SWObj *pstObj)
{
  ubyte i;

  for(i = 0; i < (CAN_HWOBJ[ubObjNr].uwMSGCFG & 0x00f0) >> 4; i++)
  {
    pstObj->ubData[i] = CAN_HWOBJ[ubObjNr].ubData[i];
  }

  if(CAN_HWOBJ[ubObjNr].uwMSGCFG & 0x04)  // extended identifier
  {
    pstObj->ulID   = CAN_HWOBJ[ubObjNr].ulCANAR;
    pstObj->ulMask = CAN_HWOBJ[ubObjNr].ulCANAMR;
  }
  else                                    // standard identifier 
  {
    pstObj->ulID   = CAN_HWOBJ[ubObjNr].ulCANAR >> 18;
    pstObj->ulMask = CAN_HWOBJ[ubObjNr].ulCANAMR >> 18;
  }

  pstObj->uwCounter = CAN_HWOBJ[ubObjNr].uwCounter;
  pstObj->uwMsgCfg  = CAN_HWOBJ[ubObjNr].uwMSGCFG;

} //  End of function CAN_vGetMsgObj


//****************************************************************************
// @Function      void CAN_vTransmit(ubyte ubObjNr) 
//
//----------------------------------------------------------------------------
// @Description   This function triggers the CAN controller to send the 
//                selected message.
//                If the selected message object is a TRANSMIT OBJECT then 
//                this function triggers the sending of a data frame. If 
//                however the selected message object is a RECEIVE OBJECT 
//                this function triggers the sending of a remote frame.
//
//----------------------------------------------------------------------------
// @Returnvalue   None
//
//----------------------------------------------------------------------------
// @Parameters    ubObjNr: 
//                Number of the message object (0-31)
//
//----------------------------------------------------------------------------
// @Date          2009-4-4
//
//****************************************************************************

// USER CODE BEGIN (Transmit,1)

// USER CODE END

void CAN_vTransmit(ubyte ubObjNr)
{
  CAN_HWOBJ[ubObjNr].uwMSGCTR = 0xe7ff;  // set TXRQ, reset CPUUPD

} //  End of function CAN_vTransmit


//****************************************************************************
// @Function      void CAN_viSRN0(void) 
//
//----------------------------------------------------------------------------
// @Description   This is the interrupt service routine for the Service 
//                Request Node 0 of the TwinCAN module.
//
//----------------------------------------------------------------------------
// @Returnvalue   None
//
//----------------------------------------------------------------------------
// @Parameters    None
//
//----------------------------------------------------------------------------
// @Date          2009-4-4
//
//****************************************************************************

// USER CODE BEGIN (SRN0,1)

// USER CODE END

void CAN_viSRN0(void) interrupt CAN_SRN0INT
{
  uword uwStatusA;

  // USER CODE BEGIN (SRN0,2)
  unsigned char i=0;
  // USER CODE END

  while((( ((ulong)CAN_RXIPNDH << 16) + CAN_RXIPNDL) & 0x00000001) || (CAN_ASR & 0x0018))
  {

    // status change interrupt of node A

    uwStatusA = CAN_ASR;
    if (uwStatusA & 0x0008)  // if TXOK
    {
      // Indicates that a message has been transmitted successfully
      // (error free and acknowledged by at least one other node).

      uwStatusA &= 0xfff7;
      CAN_ASR    = uwStatusA;    // reset TXOK

      // USER CODE BEGIN (SRN0_NODEA,3)

      // USER CODE END
    }

    if (uwStatusA & 0x0010)  // if RXOK
    {
      // Indicates that a message has been received successfully.

      uwStatusA &= 0xffef;
      CAN_ASR    = uwStatusA;    // reset RXOK

      // USER CODE BEGIN (SRN0_NODEA,4)

      // USER CODE END
    }


    // USER CODE BEGIN (SRN0_NODEA,13)

    // USER CODE END



    // message object 0 interrupt

    if((CAN_HWOBJ[0].uwMSGCTR & 0x0003) == 0x0002)         // if INTPND 
    {
      if(CAN_RXIPNDL & CAN_RXIPNDL_RXIPND0)   // message object 0 receive interrupt
      {

        if((CAN_HWOBJ[0].uwMSGCTR & 0x0300) == 0x0200)     // if NEWDAT is set
        {

          if ((CAN_HWOBJ[0].uwMSGCTR & 0x0c00) == 0x0800)  // if MSGLST is set
          {
            // Indicates that the CAN controller has stored a new 
            // message into this object, while NEWDAT was still set,
            // ie. the previously stored message is lost.

            CAN_HWOBJ[0].uwMSGCTR = 0xf7ff;  // reset MSGLST

            // USER CODE BEGIN (SRN0_OBJ0,1)

            // USER CODE END
          }
          else
          {
            // The CAN controller has stored a new message
            // into this object.

            // USER CODE BEGIN (SRN0_OBJ0,2)
			// CAN接收串口发送暂时关闭
			can_data[0]=CAN_HWOBJ[0].ulCANAR>>26;
			can_data[1]=CAN_HWOBJ[0].ulCANAR>>18;
			if (can_data[1] == 0x20)
				{
			 		for(i = 0; i < (CAN_HWOBJ[0].uwMSGCFG & 0x00f0) >> 4; i++)
  					{
    					can_data1[i+2] = CAN_HWOBJ[0].ubData[i];
  					}	
				}
					else if (can_data[1] == 0x21)
					{
					 	for(i = 0; i < (CAN_HWOBJ[0].uwMSGCFG & 0x00f0) >> 4; i++)
  						{
    					can_data2[i+2] = CAN_HWOBJ[0].ubData[i];
  						}
					}
						else if (can_data[1] == 0x30)
						{
						 	for(i = 0; i < (CAN_HWOBJ[0].uwMSGCFG & 0x00f0) >> 4; i++)
  							{
    						can_data3[i+2] = CAN_HWOBJ[0].ubData[i];
  							}
						}
							else if (can_data[1] == 0x90)
							{
							 for(i = 0; i < (CAN_HWOBJ[0].uwMSGCFG & 0x00f0) >> 4; i++)
  								{
    								can_data4[i+2] = CAN_HWOBJ[0].ubData[i];
  								}
							}
								else if (can_data[1] == 0x91)
								{
								  for(i = 0; i < (CAN_HWOBJ[0].uwMSGCFG & 0x00f0) >> 4; i++)
  									{			
    									can_data5[i+2] = CAN_HWOBJ[0].ubData[i];
  									}
								}
									else if (can_data[1] == 0x92)
									{
									 	for(i = 0; i < (CAN_HWOBJ[0].uwMSGCFG & 0x00f0) >> 4; i++)
  										{			
    									can_data6[i+2] = CAN_HWOBJ[0].ubData[i];
  										}
									}
										else if (can_data[1] == 0x93)
										{
										 	for(i = 0; i < (CAN_HWOBJ[0].uwMSGCFG & 0x00f0) >> 4; i++)
  											{			
    										can_data7[i+2] = CAN_HWOBJ[0].ubData[i];
  											}
										}
											else if (can_data[1] == 0x94)
											{
												 for(i = 0; i < (CAN_HWOBJ[0].uwMSGCFG & 0x00f0) >> 4; i++)
  												{			
    												can_data8[i+2] = CAN_HWOBJ[0].ubData[i];
  												}
											}
												else if (can_data[1] == 0x95)
												{
												  for(i = 0; i < (CAN_HWOBJ[0].uwMSGCFG & 0x00f0) >> 4; i++)
  													{			
    													can_data9[i+2] = CAN_HWOBJ[0].ubData[i];
  													}
												}
													else if (can_data[1] == 0xb0)
													{
														 for(i = 0; i < (CAN_HWOBJ[0].uwMSGCFG & 0x00f0) >> 4; i++)
  															{			
    															can_data10[i+2] = CAN_HWOBJ[0].ubData[i];
  															}
													}
														else if (can_data[1] == 0xb1)
														{
															 for(i = 0; i < (CAN_HWOBJ[0].uwMSGCFG & 0x00f0) >> 4; i++)
  																{			
    																can_data11[i+2] = CAN_HWOBJ[0].ubData[i];
  																}
														}
															else if (can_data[1] == 0xb2)
															{
																for(i = 0; i < (CAN_HWOBJ[0].uwMSGCFG & 0x00f0) >> 4; i++)
  																	{			
    																	can_data12[i+2] = CAN_HWOBJ[0].ubData[i];
  																	}
															}
															   else if (can_data[1] == 0xc0)
															   {
															  	 	for(i = 0; i < (CAN_HWOBJ[0].uwMSGCFG & 0x00f0) >> 4; i++)
  																	{			
    																	can_data13[i+2] = CAN_HWOBJ[0].ubData[i];
  																	}
															   }

            // USER CODE END
          }

          CAN_HWOBJ[0].uwMSGCTR = 0xfdff;    // reset NEWDAT
        }

      }  // End of RXIPND0


      CAN_HWOBJ[0].uwMSGCTR = 0xfffd;        // reset INTPND

      // USER CODE BEGIN (SRN0_OBJ0,6)

      // USER CODE END

    }


    // USER CODE BEGIN (SRN0,3)

    // USER CODE END


  }  // End of while()

  // USER CODE BEGIN (SRN0,7)

  // USER CODE END

} //  End of function CAN_viSRN0



// USER CODE BEGIN (CAN_General,10)

// USER CODE END

⌨️ 快捷键说明

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