📄 can.lst
字号:
584 // @Returnvalue None
585 //
586 //----------------------------------------------------------------------------
587 // @Parameters ubObjNr:
588 // Number of the message object (0-31)
589 //
590 //----------------------------------------------------------------------------
591 // @Date 2006-12-10
592 //
593 //****************************************************************************
594
595 // USER CODE BEGIN (Transmit,1)
596
597 // USER CODE END
598
599 void CAN_vTransmit(ubyte ubObjNr)
600 {
601 1 CAN_HWOBJ[ubObjNr].uwMSGCTR = 0xe7ff; // set TXRQ, reset CPUUPD
602 1
603 1 } // End of function CAN_vTransmit
604
605
606 //****************************************************************************
607 // @Function void CAN_vConfigMsgObj(ubyte ubObjNr, TCAN_SWObj *pstObj)
608 //
609 //----------------------------------------------------------------------------
610 // @Description This function sets up the message objects. This includes
611 // the 8 data bytes, the identifier (11- or 29-bit), the
612 // acceptance mask (11- or 29-bit), the data number (0-8
613 // bytes), the frame counter value and the XTD-bit (standard
C166 COMPILER V6.04, CAN 12/10/2006 17:56:47 PAGE 11
614 // or extended identifier). The direction bit (DIR), the NODE
615 // bit and the RMM (remote monitoring) bit can not be changed.
616 // The message is not sent; for this the function
617 // CAN_vTransmit must be called.
618 //
619 // The structure of the SW message object is defined in the
620 // header file CAN.H (see TCAN_SWObj).
621 //
622 //----------------------------------------------------------------------------
623 // @Returnvalue None
624 //
625 //----------------------------------------------------------------------------
626 // @Parameters ubObjNr:
627 // Number of the message object to be configured (0-31)
628 // @Parameters *pstObj:
629 // Pointer on a message object
630 //
631 //----------------------------------------------------------------------------
632 // @Date 2006-12-10
633 //
634 //****************************************************************************
635
636 // USER CODE BEGIN (ConfigMsgObj,1)
637
638 // USER CODE END
639
640 void CAN_vConfigMsgObj(ubyte ubObjNr, TCAN_SWObj *pstObj)
641 {
642 1 ubyte i;
643 1
644 1 CAN_HWOBJ[ubObjNr].uwMSGCTR = 0xfb7f; // set CPUUPD, reset MSGVAL
645 1
646 1 if(pstObj->uwMsgCfg & 0x0004) // extended identifier
647 1 {
648 2 CAN_HWOBJ[ubObjNr].uwMSGCFG |= 0x0004;
649 2 CAN_HWOBJ[ubObjNr].ulCANAR = pstObj->ulID ;
650 2 CAN_HWOBJ[ubObjNr].ulCANAMR = pstObj->ulMask ;
651 2 }
652 1 else // standard identifier
653 1 {
654 2 CAN_HWOBJ[ubObjNr].uwMSGCFG &= ~(uword)0x0004;
655 2 CAN_HWOBJ[ubObjNr].ulCANAR = pstObj->ulID << 18;
656 2 CAN_HWOBJ[ubObjNr].ulCANAMR = pstObj->ulMask << 18;
657 2 }
658 1
659 1 CAN_HWOBJ[ubObjNr].uwCounter = pstObj->uwCounter;
660 1
661 1 CAN_HWOBJ[ubObjNr].uwMSGCFG = (CAN_HWOBJ[ubObjNr].uwMSGCFG & 0x000f) | (pstObj->uwMsgCfg & 0x00f0);
662 1
663 1 if(CAN_HWOBJ[ubObjNr].uwMSGCFG & 0x0008) // if transmit direction
664 1 {
665 2 for(i = 0; i < (pstObj->uwMsgCfg & 0x00f0) >> 4; i++)
666 2 {
667 3 CAN_HWOBJ[ubObjNr].ubData[i] = pstObj->ubData[i];
668 3 }
669 2 CAN_HWOBJ[ubObjNr].uwMSGCTR = 0xf6bf; // set NEWDAT, reset CPUUPD,
670 2 } // set MSGVAL
671 1 else // if receive direction
672 1 {
673 2 CAN_HWOBJ[ubObjNr].uwMSGCTR = 0xf7bf; // reset CPUUPD, set MSGVAL
674 2 }
675 1
C166 COMPILER V6.04, CAN 12/10/2006 17:56:47 PAGE 12
676 1 } // End of function CAN_vConfigMsgObj
677
678
679 //****************************************************************************
680 // @Function void CAN_vLoadData(ubyte ubObjNr, ubyte *pubData)
681 //
682 //----------------------------------------------------------------------------
683 // @Description If a hardware TRANSMIT OBJECT has to be loaded with data
684 // but not with a new identifier, this function may be used
685 // instead of the function CAN_vConfigMsgObj. The message
686 // object should be accessed by calling the function
687 // CAN_ubRequestMsgObj before calling this function. This
688 // prevents the CAN controller from working with invalid data.
689 //
690 //----------------------------------------------------------------------------
691 // @Returnvalue None
692 //
693 //----------------------------------------------------------------------------
694 // @Parameters ubObjNr:
695 // Number of the message object to be configured (0-31)
696 // @Parameters *pubData:
697 // Pointer on a data buffer
698 //
699 //----------------------------------------------------------------------------
700 // @Date 2006-12-10
701 //
702 //****************************************************************************
703
704 // USER CODE BEGIN (LoadData,1)
705
706 // USER CODE END
707
708 void CAN_vLoadData(ubyte ubObjNr, ubyte *pubData)
709 {
710 1 ubyte i;
711 1
712 1 CAN_HWOBJ[ubObjNr].uwMSGCTR = 0xfaff; // set CPUUPD and NEWDAT
713 1
714 1 for(i = 0; i < (CAN_HWOBJ[ubObjNr].uwMSGCFG & 0xf0) >> 4; i++)
715 1 {
716 2 CAN_HWOBJ[ubObjNr].ubData[i] = *(pubData++);
717 2 }
718 1
719 1 CAN_HWOBJ[ubObjNr].uwMSGCTR = 0xf7ff; // reset CPUUPD
720 1
721 1 } // End of function CAN_vLoadData
722
723
724 //****************************************************************************
725 // @Function void CAN_viSRN0(void)
726 //
727 //----------------------------------------------------------------------------
728 // @Description This is the interrupt service routine for the Service
729 // Request Node 0 of the TwinCAN module.
730 //
731 //----------------------------------------------------------------------------
732 // @Returnvalue None
733 //
734 //----------------------------------------------------------------------------
735 // @Parameters None
736 //
737 //----------------------------------------------------------------------------
C166 COMPILER V6.04, CAN 12/10/2006 17:56:47 PAGE 13
738 // @Date 2006-12-10
739 //
740 //****************************************************************************
741
742 // USER CODE BEGIN (SRN0,1)
743
744 // USER CODE END
745
746 void CAN_viSRN0(void) interrupt CAN_SRN0INT
747 {
748 1 uword uwStatusB;
749 1
750 1 // USER CODE BEGIN (SRN0,2)
751 1
752 1 // USER CODE END
753 1
754 1 while((CAN_BSR & 0x0018))
755 1 {
756 2
757 2 // status change interrupt of node B
758 2
759 2 uwStatusB = CAN_BSR;
760 2 if (uwStatusB & 0x0008) // if TXOK
761 2 {
762 3 // Indicates that a message has been transmitted successfully
763 3 // (error free and acknowledged by at least one other node).
764 3
765 3 uwStatusB &= 0xfff7;
766 3 CAN_BSR = uwStatusB; // reset TXOK
767 3
768 3 // USER CODE BEGIN (SRN0_NODEB,3)
769 3
770 3 // USER CODE END
771 3 }
772 2
773 2 if (uwStatusB & 0x0010) // if RXOK
774 2 {
775 3 // Indicates that a message has been received successfully.
776 3
777 3 uwStatusB &= 0xffef;
778 3 CAN_BSR = uwStatusB; // reset RXOK
779 3
780 3 // USER CODE BEGIN (SRN0_NODEB,4)
781 3
782 3 // USER CODE END
783 3 }
784 2
785 2
786 2 // USER CODE BEGIN (SRN0_NODEB,13)
787 2
788 2 // USER CODE END
789 2
790 2
791 2
792 2 // USER CODE BEGIN (SRN0,3)
793 2
794 2 // USER CODE END
795 2
796 2
797 2 } // End of while()
798 1
799 1 // USER CODE BEGIN (SRN0,7)
C166 COMPILER V6.04, CAN 12/10/2006 17:56:47 PAGE 14
800 1
801 1 // USER CODE END
802 1
803 1 } // End of function CAN_viSRN0
804
805
806 //****************************************************************************
807 // @Function void CAN_viSRN1(void)
808 //
809 //----------------------------------------------------------------------------
810 // @Description This is the interrupt service routine for the Service
811 // Request Node 1 of the TwinCAN module.
812 //
813 //----------------------------------------------------------------------------
814 // @Returnvalue None
815 //
816 //----------------------------------------------------------------------------
817 // @Parameters None
818 //
819 //----------------------------------------------------------------------------
820 // @Date 2006-12-10
821 //
822 //****************************************************************************
823
824 // USER CODE BEGIN (SRN1,1)
825
826 // USER CODE END
827
828 void CAN_viSRN1(void) interrupt CAN_SRN1INT
829 {
830 1
831 1 // USER CODE BEGIN (SRN1,2)
832 1
833 1 // USER CODE END
834 1
835 1 while((( ((ulong)CAN_RXIPNDH << 16) + CAN_RXIPNDL) & 0x00000001))
836 1 {
837 2
838 2 // message object 0 interrupt
839 2
840 2 if((CAN_HWOBJ[0].uwMSGCTR & 0x0003) == 0x0002) // if INTPND
841 2 {
842 3 if(CAN_RXIPNDL & CAN_RXIPNDL_RXIPND0) // message object 0 receive interrupt
843 3 {
844 4
845 4 if((CAN_HWOBJ[0].uwMSGCTR & 0x0300) == 0x0200) // if NEWDAT is set
846 4 {
847 5
848 5 if ((CAN_HWOBJ[0].uwMSGCTR & 0x0c00) == 0x0800) // if MSGLST is set
849 5 {
850 6 // Indicates that the CAN controller has stored a new
851 6 // message into this object, while NEWDAT was still set,
852 6 // ie. the previously stored message is lost.
853 6
854 6 CAN_HWOBJ[0].uwMSGCTR = 0xf7ff; // reset MSGLST
855 6
856 6 // USER CODE BEGIN (SRN1_OBJ0,1)
857 6
858 6 // USER CODE END
859 6 }
860 5 else
861 5 {
C166 COMPILER V6.04, CAN 12/10/2006 17:56:47 PAGE 15
862 6 // The CAN controller has stored a new message
863 6 // into this object.
864 6
865 6 // USER CODE BEGIN (SRN1_OBJ0,2)
866 6 P1L=0xfe;
867 6 delayms(1);
*** WARNING C140 IN LINE 867 OF CAN.C: 'delayms' undefined; assuming 'extern int delayms()'
868 6 P1L=0xff;
869 6 // USER CODE END
870 6 }
871 5
872 5 CAN_HWOBJ[0].uwMSGCTR = 0xfdff; // reset NEWDAT
873 5 }
874 4
875 4 } // End of RXIPND0
876 3
877 3
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -