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

📄 can.lst

📁 本程序是针对Infineon公司的XC167CI处理器而编写的CAN网络程序。CAN(控制局域网)协议是一种广泛的应用于汽车电子的网络协议。本程序建立了三个CAN节点
💻 LST
📖 第 1 页 / 共 4 页
字号:
  289  1        ///  - remote monitoring is disabled
  290  1        ///  - transmit interrupt node pointer: TwinCAN SRN 3
  291  1      
  292  1        CAN_MSGCFGL2   =  0x008A;      // load message configuration register low
  293  1        CAN_MSGCFGH2   =  0x0030;      // load message configuration register high
  294  1      
  295  1        ///  - acceptance mask 11-bit: 0x7FF
  296  1        ///  - identifier 11-bit:      0x133
  297  1      
  298  1        CAN_MSGAMRL2   =  0xFFFF;      // load acceptance mask register low
  299  1        CAN_MSGAMRH2   =  0xFFFF;      // load acceptance mask register high
  300  1        CAN_MSGARL2    =  0x0000;      // load arbitration register low
  301  1        CAN_MSGARH2    =  0x04CC;      // load arbitration register high
  302  1        CAN_MSGDRL20   =  0x0000;      // load data register 0 low
  303  1        CAN_MSGDRH20   =  0x0000;      // load data register 0 high
C166 COMPILER V6.04, CAN                                                                   12/10/2006 17:56:47 PAGE 6   

  304  1        CAN_MSGDRL24   =  0x0000;      // load data register 4 low
  305  1        CAN_MSGDRH24   =  0x0000;      // load data register 4 high
  306  1      
  307  1        ///  - functionality of standard message object
  308  1      
  309  1        CAN_MSGFGCRL2  =  0x0000;      // load FIFO/gateway control register low
  310  1        CAN_MSGFGCRH2  =  0x0002;      // load FIFO/gateway control register high
  311  1      
  312  1        CAN_MSGCTRH2   =  0x0000;      // load message control register high
  313  1        CAN_MSGCTRL2   =  0x55A5;      // load message control register low
  314  1      
  315  1        ///  -----------------------------------------------------------------------
  316  1        ///  Configuration of Message Object 3:
  317  1        ///  -----------------------------------------------------------------------
  318  1        ///  - message object 3 is valid
  319  1        ///  - enable receive interrupt; bit INTPND is set after successfull 
  320  1        ///    reception of a frame
  321  1      
  322  1        ///  - message object is used as receive object
  323  1        ///  - standard 11-bit identifier
  324  1        ///  - 8 valid data bytes
  325  1        ///  - this message object works with CAN node B
  326  1        ///  - remote monitoring is disabled
  327  1        ///  - receive interrupt node pointer: TwinCAN SRN 4
  328  1      
  329  1        CAN_MSGCFGL3   =  0x0082;      // load message configuration register low
  330  1        CAN_MSGCFGH3   =  0x0004;      // load message configuration register high
  331  1      
  332  1        ///  - acceptance mask 11-bit: 0x7FD
  333  1        ///  - identifier 11-bit:      0x130
  334  1      
  335  1        CAN_MSGAMRL3   =  0x0000;      // load acceptance mask register low
  336  1        CAN_MSGAMRH3   =  0xFFF4;      // load acceptance mask register high
  337  1        CAN_MSGARL3    =  0x0000;      // load arbitration register low
  338  1        CAN_MSGARH3    =  0x04C0;      // load arbitration register high
  339  1        CAN_MSGDRL30   =  0x0000;      // load data register 0 low
  340  1        CAN_MSGDRH30   =  0x0000;      // load data register 0 high
  341  1        CAN_MSGDRL34   =  0x0000;      // load data register 4 low
  342  1        CAN_MSGDRH34   =  0x0000;      // load data register 4 high
  343  1      
  344  1        ///  - functionality of standard message object
  345  1      
  346  1        CAN_MSGFGCRL3  =  0x0000;      // load FIFO/gateway control register low
  347  1        CAN_MSGFGCRH3  =  0x0003;      // load FIFO/gateway control register high
  348  1      
  349  1        CAN_MSGCTRH3   =  0x0000;      // load message control register high
  350  1        CAN_MSGCTRL3   =  0x5599;      // load message control register low
  351  1      
  352  1      
  353  1        ///  -----------------------------------------------------------------------
  354  1        ///  Configuration of Service Request Nodes 0 - 7:
  355  1        ///  -----------------------------------------------------------------------
  356  1        ///  SRN0 service request node configuration:
  357  1        ///  - SRN0 interrupt priority level (ILVL) = 15
  358  1        ///  - SRN0 interrupt group level (GLVL) = 0
  359  1        ///  - SRN0 group priority extension (GPX) = 0
  360  1      
  361  1        CAN_0IC        =  0x007C;     
  362  1      
  363  1        ///  Use PEC channel 4 for CAN INT 0:
  364  1        ///  - normal interrupt
  365  1        ///  - pointers are not modified
C166 COMPILER V6.04, CAN                                                                   12/10/2006 17:56:47 PAGE 7   

  366  1        ///  - transfer a word
  367  1        ///  - service End of PEC interrrupt by a EOP interrupt node is disabled
  368  1      
  369  1        PECC4          =  0x0000;      // load PECC4 control register
  370  1      
  371  1      
  372  1        ///  SRN1 service request node configuration:
  373  1        ///  - SRN1 interrupt priority level (ILVL) = 14
  374  1        ///  - SRN1 interrupt group level (GLVL) = 1
  375  1        ///  - SRN1 group priority extension (GPX) = 0
  376  1      
  377  1        CAN_1IC        =  0x0079;     
  378  1      
  379  1        ///  Use PEC channel 1 for CAN INT 1:
  380  1        ///  - normal interrupt
  381  1        ///  - pointers are not modified
  382  1        ///  - transfer a word
  383  1        ///  - service End of PEC interrrupt by a EOP interrupt node is disabled
  384  1      
  385  1        PECC1          =  0x0000;      // load PECC1 control register
  386  1      
  387  1      
  388  1        ///  SRN2 service request node configuration:
  389  1        ///  - SRN2 interrupt priority level (ILVL) = 12
  390  1        ///  - SRN2 interrupt group level (GLVL) = 0
  391  1        ///  - SRN2 group priority extension (GPX) = 0
  392  1      
  393  1        CAN_2IC        =  0x0070;     
  394  1      
  395  1        ///  SRN3 service request node configuration:
  396  1        ///  - SRN3 interrupt priority level (ILVL) = 13
  397  1        ///  - SRN3 interrupt group level (GLVL) = 1
  398  1        ///  - SRN3 group priority extension (GPX) = 0
  399  1      
  400  1        CAN_3IC        =  0x0075;     
  401  1      
  402  1        ///  SRN4 service request node configuration:
  403  1        ///  - SRN4 interrupt priority level (ILVL) = 11
  404  1        ///  - SRN4 interrupt group level (GLVL) = 1
  405  1        ///  - SRN4 group priority extension (GPX) = 0
  406  1      
  407  1        CAN_4IC        =  0x006D;     
  408  1      
  409  1      
  410  1      
  411  1        // USER CODE BEGIN (Init,3)
  412  1      
  413  1        // USER CODE END
  414  1      
  415  1      
  416  1        CAN_PISEL      =  0x0008;      // load port input select register
  417  1      
  418  1        //   -----------------------------------------------------------------------
  419  1        //   Start the CAN Nodes:
  420  1        //   -----------------------------------------------------------------------
  421  1      
  422  1        CAN_BCR       &= ~(uword)0x0041; // reset INIT and CCE
  423  1      
  424  1      
  425  1        // USER CODE BEGIN (Init,4)
  426  1      
  427  1        // USER CODE END
C166 COMPILER V6.04, CAN                                                                   12/10/2006 17:56:47 PAGE 8   

  428  1      
  429  1      } //  End of function CAN_vInit
  430         
  431         
  432         //****************************************************************************
  433         // @Function      void CAN_vGetMsgObj(ubyte ubObjNr, TCAN_SWObj *pstObj) 
  434         //
  435         //----------------------------------------------------------------------------
  436         // @Description   This function fills the forwarded SW message object with 
  437         //                the content of the chosen HW message object.
  438         //                
  439         //                The structure of the SW message object is defined in the 
  440         //                header file CAN.H (see TCAN_SWObj).
  441         //
  442         //----------------------------------------------------------------------------
  443         // @Returnvalue   None
  444         //
  445         //----------------------------------------------------------------------------
  446         // @Parameters    ubObjNr: 
  447         //                Number of the message object to be read (0-31)
  448         // @Parameters    *pstObj: 
  449         //                Pointer on a message object to be filled by this function
  450         //
  451         //----------------------------------------------------------------------------
  452         // @Date          2006-12-10
  453         //
  454         //****************************************************************************
  455         
  456         // USER CODE BEGIN (GetMsgObj,1)
  457         
  458         // USER CODE END
  459         
  460         void CAN_vGetMsgObj(ubyte ubObjNr, TCAN_SWObj *pstObj)
  461         {
  462  1        ubyte i;
  463  1      
  464  1        for(i = 0; i < (CAN_HWOBJ[ubObjNr].uwMSGCFG & 0x00f0) >> 4; i++)
  465  1        {
  466  2          pstObj->ubData[i] = CAN_HWOBJ[ubObjNr].ubData[i];
  467  2        }
  468  1      
  469  1        if(CAN_HWOBJ[ubObjNr].uwMSGCFG & 0x04)  // extended identifier
  470  1        {
  471  2          pstObj->ulID   = CAN_HWOBJ[ubObjNr].ulCANAR;
  472  2          pstObj->ulMask = CAN_HWOBJ[ubObjNr].ulCANAMR;
  473  2        }
  474  1        else                                    // standard identifier 
  475  1        {
  476  2          pstObj->ulID   = CAN_HWOBJ[ubObjNr].ulCANAR >> 18;
  477  2          pstObj->ulMask = CAN_HWOBJ[ubObjNr].ulCANAMR >> 18;
  478  2        }
  479  1      
  480  1        pstObj->uwCounter = CAN_HWOBJ[ubObjNr].uwCounter;
  481  1        pstObj->uwMsgCfg  = CAN_HWOBJ[ubObjNr].uwMSGCFG;
  482  1      
  483  1      } //  End of function CAN_vGetMsgObj
  484         
  485         
  486         //****************************************************************************
  487         // @Function      ubyte CAN_ubRequestMsgObj(ubyte ubObjNr) 
  488         //
  489         //----------------------------------------------------------------------------
C166 COMPILER V6.04, CAN                                                                   12/10/2006 17:56:47 PAGE 9   

  490         // @Description   If a TRANSMIT OBJECT is to be reconfigured it must first be 
  491         //                accessed. The access to the transmit object is exclusive. 
  492         //                This function checks whether the choosen message object is 
  493         //                still executing a transmit request, or if the object can be 
  494         //                accessed exclusively.
  495         //                After the message object is reserved, it can be 
  496         //                reconfigured by using the function CAN_vConfigMsgObj or 
  497         //                CAN_vLoadData.
  498         //                Both functions enable access to the object for the CAN 
  499         //                controller. 
  500         //                By calling the function CAN_vTransmit transfering of data 
  501         //                is started.
  502         //
  503         //----------------------------------------------------------------------------
  504         // @Returnvalue   0 message object is busy (a transfer is active), else 1
  505         //
  506         //----------------------------------------------------------------------------
  507         // @Parameters    ubObjNr: 
  508         //                Number of the message object (0-31)
  509         //
  510         //----------------------------------------------------------------------------
  511         // @Date          2006-12-10
  512         //
  513         //****************************************************************************
  514         
  515         // USER CODE BEGIN (RequestMsgObj,1)
  516         
  517         // USER CODE END
  518         
  519         ubyte CAN_ubRequestMsgObj(ubyte ubObjNr)
  520         {
  521  1        ubyte ubReturn;
  522  1      
  523  1        ubReturn = 0;
  524  1        if((CAN_HWOBJ[ubObjNr].uwMSGCTR & 0x3000) == 0x1000)  // if reset TXRQ 
  525  1        {
  526  2          CAN_HWOBJ[ubObjNr].uwMSGCTR = 0xfbff;               // set CPUUPD 
  527  2          ubReturn = 1;
  528  2        }
  529  1        return(ubReturn);
  530  1      
  531  1      } //  End of function CAN_ubRequestMsgObj
  532         
  533         
  534         //****************************************************************************
  535         // @Function      ubyte CAN_ubNewData(ubyte ubObjNr) 
  536         //
  537         //----------------------------------------------------------------------------
  538         // @Description   This function checks whether the selected RECEIVE OBJECT 
  539         //                has received a new message. If so the function returns the 
  540         //                value '1'.
  541         //
  542         //----------------------------------------------------------------------------
  543         // @Returnvalue   1 the message object has received a new message, else 0
  544         //
  545         //----------------------------------------------------------------------------
  546         // @Parameters    ubObjNr: 
  547         //                Number of the message object (0-31)
  548         //
  549         //----------------------------------------------------------------------------
  550         // @Date          2006-12-10
  551         //
C166 COMPILER V6.04, CAN                                                                   12/10/2006 17:56:47 PAGE 10  

  552         //****************************************************************************
  553         
  554         // USER CODE BEGIN (NewData,1)
  555         
  556         // USER CODE END
  557         
  558         ubyte CAN_ubNewData(ubyte ubObjNr)
  559         {
  560  1        ubyte ubReturn;
  561  1      
  562  1        ubReturn = 0;
  563  1        if((CAN_HWOBJ[ubObjNr].uwMSGCTR & 0x0300) == 0x0200)  // if NEWDAT
  564  1        {
  565  2          ubReturn = 1;
  566  2        }
  567  1        return(ubReturn);
  568  1      
  569  1      } //  End of function CAN_ubNewData
  570         
  571         
  572         //****************************************************************************
  573         // @Function      void CAN_vTransmit(ubyte ubObjNr) 
  574         //
  575         //----------------------------------------------------------------------------
  576         // @Description   This function triggers the CAN controller to send the 
  577         //                selected message.
  578         //                If the selected message object is a TRANSMIT OBJECT then 
  579         //                this function triggers the sending of a data frame. If 
  580         //                however the selected message object is a RECEIVE OBJECT 
  581         //                this function triggers the sending of a remote frame.
  582         //
  583         //----------------------------------------------------------------------------

⌨️ 快捷键说明

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