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

📄 can.lst

📁 英飞凌C166之XC164CS双CAN通讯程序
💻 LST
📖 第 1 页 / 共 3 页
字号:
  299  1        CAN_MSGDRH14   =  0x0000;      // load data register 4 high
  300  1      
  301  1        ///  - functionality of standard message object
  302  1      
  303  1        CAN_MSGFGCRL1  =  0x0000;      // load FIFO/gateway control register low
C166 COMPILER V6.04, CAN                                                                   09/08/2007 14:27:20 PAGE 6   

  304  1        CAN_MSGFGCRH1  =  0x0001;      // load FIFO/gateway control register high
  305  1      
  306  1        CAN_MSGCTRH1   =  0x0000;      // load message control register high
  307  1        CAN_MSGCTRL1   =  0x5599;      // load message control register low
  308  1      
  309  1      
  310  1        ///  -----------------------------------------------------------------------
  311  1        ///  Configuration of Service Request Nodes 0 - 7:
  312  1        ///  -----------------------------------------------------------------------
  313  1        ///  SRN0 service request node configuration:
  314  1        ///  - SRN0 interrupt priority level (ILVL) = 12
  315  1        ///  - SRN0 interrupt group level (GLVL) = 0
  316  1        ///  - SRN0 group priority extension (GPX) = 0
  317  1      
  318  1        CAN_0IC        =  0x0070;     
  319  1      
  320  1        ///  SRN1 service request node configuration:
  321  1        ///  - SRN1 interrupt priority level (ILVL) = 11
  322  1        ///  - SRN1 interrupt group level (GLVL) = 1
  323  1        ///  - SRN1 group priority extension (GPX) = 0
  324  1      
  325  1        CAN_1IC        =  0x006D;     
  326  1      
  327  1      
  328  1      
  329  1        // USER CODE BEGIN (Init,3)
  330  1      
  331  1        // USER CODE END
  332  1      
  333  1      
  334  1        CAN_PISEL      =  0x0000;      // load port input select register
  335  1      
  336  1        //   -----------------------------------------------------------------------
  337  1        //   Start the CAN Nodes:
  338  1        //   -----------------------------------------------------------------------
  339  1      
  340  1        CAN_ACR       &= ~(uword)0x0041; // reset INIT and CCE
  341  1        CAN_BCR       &= ~(uword)0x0041; // reset INIT and CCE
  342  1      
  343  1      
  344  1        // USER CODE BEGIN (Init,4)
  345  1      
  346  1        // USER CODE END
  347  1      
  348  1      } //  End of function CAN_vInit
  349         
  350         
  351         //****************************************************************************
  352         // @Function      void CAN_vGetMsgObj(ubyte ubObjNr, TCAN_SWObj *pstObj) 
  353         //
  354         //----------------------------------------------------------------------------
  355         // @Description   This function fills the forwarded SW message object with 
  356         //                the content of the chosen HW message object.
  357         //                
  358         //                The structure of the SW message object is defined in the 
  359         //                header file CAN.H (see TCAN_SWObj).
  360         //
  361         //----------------------------------------------------------------------------
  362         // @Returnvalue   None
  363         //
  364         //----------------------------------------------------------------------------
  365         // @Parameters    ubObjNr: 
C166 COMPILER V6.04, CAN                                                                   09/08/2007 14:27:20 PAGE 7   

  366         //                Number of the message object to be read (0-31)
  367         // @Parameters    *pstObj: 
  368         //                Pointer on a message object to be filled by this function
  369         //
  370         //----------------------------------------------------------------------------
  371         // @Date          2007-5-25
  372         //
  373         //****************************************************************************
  374         
  375         // USER CODE BEGIN (GetMsgObj,1)
  376         
  377         // USER CODE END
  378         
  379         void CAN_vGetMsgObj(ubyte ubObjNr, TCAN_SWObj *pstObj)
  380         {
  381  1        ubyte i;
  382  1      
  383  1        for(i = 0; i < (CAN_HWOBJ[ubObjNr].uwMSGCFG & 0x00f0) >> 4; i++)
  384  1        {
  385  2          pstObj->ubData[i] = CAN_HWOBJ[ubObjNr].ubData[i];
  386  2        }
  387  1      
  388  1        if(CAN_HWOBJ[ubObjNr].uwMSGCFG & 0x04)  // extended identifier
  389  1        {
  390  2          pstObj->ulID   = CAN_HWOBJ[ubObjNr].ulCANAR;
  391  2          pstObj->ulMask = CAN_HWOBJ[ubObjNr].ulCANAMR;
  392  2        }
  393  1        else                                    // standard identifier 
  394  1        {
  395  2          pstObj->ulID   = CAN_HWOBJ[ubObjNr].ulCANAR >> 18;
  396  2          pstObj->ulMask = CAN_HWOBJ[ubObjNr].ulCANAMR >> 18;
  397  2        }
  398  1      
  399  1        pstObj->uwCounter = CAN_HWOBJ[ubObjNr].uwCounter;
  400  1        pstObj->uwMsgCfg  = CAN_HWOBJ[ubObjNr].uwMSGCFG;
  401  1      
  402  1      } //  End of function CAN_vGetMsgObj
  403         
  404         
  405         //****************************************************************************
  406         // @Function      ubyte CAN_ubRequestMsgObj(ubyte ubObjNr) 
  407         //
  408         //----------------------------------------------------------------------------
  409         // @Description   If a TRANSMIT OBJECT is to be reconfigured it must first be 
  410         //                accessed. The access to the transmit object is exclusive. 
  411         //                This function checks whether the choosen message object is 
  412         //                still executing a transmit request, or if the object can be 
  413         //                accessed exclusively.
  414         //                After the message object is reserved, it can be 
  415         //                reconfigured by using the function CAN_vConfigMsgObj or 
  416         //                CAN_vLoadData.
  417         //                Both functions enable access to the object for the CAN 
  418         //                controller. 
  419         //                By calling the function CAN_vTransmit transfering of data 
  420         //                is started.
  421         //
  422         //----------------------------------------------------------------------------
  423         // @Returnvalue   0 message object is busy (a transfer is active), else 1
  424         //
  425         //----------------------------------------------------------------------------
  426         // @Parameters    ubObjNr: 
  427         //                Number of the message object (0-31)
C166 COMPILER V6.04, CAN                                                                   09/08/2007 14:27:20 PAGE 8   

  428         //
  429         //----------------------------------------------------------------------------
  430         // @Date          2007-5-25
  431         //
  432         //****************************************************************************
  433         
  434         // USER CODE BEGIN (RequestMsgObj,1)
  435         
  436         // USER CODE END
  437         
  438         ubyte CAN_ubRequestMsgObj(ubyte ubObjNr)
  439         {
  440  1        ubyte ubReturn;
  441  1      
  442  1        ubReturn = 0;
  443  1        if((CAN_HWOBJ[ubObjNr].uwMSGCTR & 0x3000) == 0x1000)  // if reset TXRQ 
  444  1        {
  445  2          CAN_HWOBJ[ubObjNr].uwMSGCTR = 0xfbff;               // set CPUUPD 
  446  2          ubReturn = 1;
  447  2        }
  448  1        return(ubReturn);
  449  1      
  450  1      } //  End of function CAN_ubRequestMsgObj
  451         
  452         
  453         //****************************************************************************
  454         // @Function      ubyte CAN_ubNewData(ubyte ubObjNr) 
  455         //
  456         //----------------------------------------------------------------------------
  457         // @Description   This function checks whether the selected RECEIVE OBJECT 
  458         //                has received a new message. If so the function returns the 
  459         //                value '1'.
  460         //
  461         //----------------------------------------------------------------------------
  462         // @Returnvalue   1 the message object has received a new message, else 0
  463         //
  464         //----------------------------------------------------------------------------
  465         // @Parameters    ubObjNr: 
  466         //                Number of the message object (0-31)
  467         //
  468         //----------------------------------------------------------------------------
  469         // @Date          2007-5-25
  470         //
  471         //****************************************************************************
  472         
  473         // USER CODE BEGIN (NewData,1)
  474         
  475         // USER CODE END
  476         
  477         ubyte CAN_ubNewData(ubyte ubObjNr)
  478         {
  479  1        ubyte ubReturn;
  480  1      
  481  1        ubReturn = 0;
  482  1        if((CAN_HWOBJ[ubObjNr].uwMSGCTR & 0x0300) == 0x0200)  // if NEWDAT
  483  1        {
  484  2          ubReturn = 1;
  485  2        }
  486  1        return(ubReturn);
  487  1      
  488  1      } //  End of function CAN_ubNewData
  489         
C166 COMPILER V6.04, CAN                                                                   09/08/2007 14:27:20 PAGE 9   

  490         
  491         //****************************************************************************
  492         // @Function      void CAN_vTransmit(ubyte ubObjNr) 
  493         //
  494         //----------------------------------------------------------------------------
  495         // @Description   This function triggers the CAN controller to send the 
  496         //                selected message.
  497         //                If the selected message object is a TRANSMIT OBJECT then 
  498         //                this function triggers the sending of a data frame. If 
  499         //                however the selected message object is a RECEIVE OBJECT 
  500         //                this function triggers the sending of a remote frame.
  501         //
  502         //----------------------------------------------------------------------------
  503         // @Returnvalue   None
  504         //
  505         //----------------------------------------------------------------------------
  506         // @Parameters    ubObjNr: 
  507         //                Number of the message object (0-31)
  508         //
  509         //----------------------------------------------------------------------------
  510         // @Date          2007-5-25
  511         //
  512         //****************************************************************************
  513         
  514         // USER CODE BEGIN (Transmit,1)
  515         
  516         // USER CODE END
  517         
  518         void CAN_vTransmit(ubyte ubObjNr)
  519         {
  520  1        CAN_HWOBJ[ubObjNr].uwMSGCTR = 0xe7ff;  // set TXRQ, reset CPUUPD
  521  1      
  522  1      } //  End of function CAN_vTransmit
  523         
  524         
  525         //****************************************************************************
  526         // @Function      void CAN_vConfigMsgObj(ubyte ubObjNr, TCAN_SWObj *pstObj) 
  527         //
  528         //----------------------------------------------------------------------------
  529         // @Description   This function sets up the message objects. This includes 
  530         //                the 8 data bytes, the identifier (11- or 29-bit), the 
  531         //                acceptance mask (11- or 29-bit), the data number (0-8 
  532         //                bytes), the frame counter value and the XTD-bit (standard 
  533         //                or extended identifier).  The direction bit (DIR), the NODE 
  534         //                bit and the RMM (remote monitoring) bit can not be changed. 
  535         //                The message is not sent; for this the function 
  536         //                CAN_vTransmit must be called.
  537         //                
  538         //                The structure of the SW message object is defined in the 
  539         //                header file CAN.H (see TCAN_SWObj).
  540         //
  541         //----------------------------------------------------------------------------
  542         // @Returnvalue   None
  543         //
  544         //----------------------------------------------------------------------------
  545         // @Parameters    ubObjNr: 
  546         //                Number of the message object to be configured (0-31)
  547         // @Parameters    *pstObj: 
  548         //                Pointer on a message object
  549         //
  550         //----------------------------------------------------------------------------
  551         // @Date          2007-5-25
C166 COMPILER V6.04, CAN                                                                   09/08/2007 14:27:20 PAGE 10  

  552         //
  553         //****************************************************************************
  554         
  555         // USER CODE BEGIN (ConfigMsgObj,1)
  556         
  557         // USER CODE END
  558         
  559         void CAN_vConfigMsgObj(ubyte ubObjNr, TCAN_SWObj *pstObj)
  560         {
  561  1        ubyte i;
  562  1      
  563  1        CAN_HWOBJ[ubObjNr].uwMSGCTR = 0xfb7f;     // set CPUUPD, reset MSGVAL
  564  1      
  565  1        if(pstObj->uwMsgCfg & 0x0004)             // extended identifier
  566  1        {
  567  2          CAN_HWOBJ[ubObjNr].uwMSGCFG |= 0x0004;
  568  2          CAN_HWOBJ[ubObjNr].ulCANAR   = pstObj->ulID ;
  569  2          CAN_HWOBJ[ubObjNr].ulCANAMR  = pstObj->ulMask ;
  570  2        }
  571  1        else                                      // standard identifier
  572  1        {
  573  2          CAN_HWOBJ[ubObjNr].uwMSGCFG &= ~(uword)0x0004;
  574  2          CAN_HWOBJ[ubObjNr].ulCANAR   = pstObj->ulID << 18;
  575  2          CAN_HWOBJ[ubObjNr].ulCANAMR  = pstObj->ulMask << 18;
  576  2        }
  577  1      
  578  1        CAN_HWOBJ[ubObjNr].uwCounter = pstObj->uwCounter;
  579  1      
  580  1        CAN_HWOBJ[ubObjNr].uwMSGCFG  = (CAN_HWOBJ[ubObjNr].uwMSGCFG & 0x000f) | (pstObj->uwMsgCfg & 0x00f0);
  581  1      
  582  1        if(CAN_HWOBJ[ubObjNr].uwMSGCFG & 0x0008)  // if transmit direction
  583  1        {
  584  2          for(i = 0; i < (pstObj->uwMsgCfg & 0x00f0) >> 4; i++)
  585  2          {
  586  3            CAN_HWOBJ[ubObjNr].ubData[i] = pstObj->ubData[i];
  587  3          }
  588  2          CAN_HWOBJ[ubObjNr].uwMSGCTR  = 0xf6bf;  // set NEWDAT, reset CPUUPD, 
  589  2        }                                         // set MSGVAL
  590  1        else                                      // if receive direction
  591  1        {
  592  2          CAN_HWOBJ[ubObjNr].uwMSGCTR  = 0xf7bf;  // reset CPUUPD, set MSGVAL
  593  2        }
  594  1      
  595  1      } //  End of function CAN_vConfigMsgObj
  596         
  597         
  598         //****************************************************************************
  599         // @Function      void CAN_vLoadData(ubyte ubObjNr, ubyte *pubData) 
  600         //
  601         //----------------------------------------------------------------------------
  602         // @Description   If a hardware TRANSMIT OBJECT has to be loaded with data 
  603         //                but not with a new identifier, this function may be used 

⌨️ 快捷键说明

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