Explain CAN receive function from disassembly

MC9S12 based Microcontrollers
Post Reply
Go4IT
Pro
Posts: 764
Joined: 08 Feb 2019, 12:25

Explain CAN receive function from disassembly

Post by Go4IT »

I've extracted this ISR from the rvc-module dump and kindly ask if somebody can explain how the code works. I only had a wague idea of it... somehow the code must filter on which messages it should react and if, i guess it will put something into memory where another routine act on, as ISRs should keep as short as possible...

Code: Select all

ROM_HI:C34D _CAN0_receive:                          ; DATA XREF: USER_VEC:FFB2↓o
ROM_HI:C34D                 leas    -3,sp           ; Load effective address into SP
ROM_HI:C34F                 brset   byte_FSR_3161,#0x10,loc_ROM_HI_C386 ; Ignore remote frames (RTR Bit set)
ROM_HI:C354                 ldab    CAN0IDAC        ; Load B
ROM_HI:C357                 andb    #7              ; AND B with memory
ROM_HI:C359                 stab    2,sp            ; Store B
ROM_HI:C35B                 ldd     #3              ; Load D
ROM_HI:C35E                 std     0,sp            ; Store D
ROM_HI:C360
ROM_HI:C360 loc_ROM_HI_C360:                        ; CODE XREF: _CAN0_receive+28↓j
ROM_HI:C360                 ldd     0,sp            ; Load D
ROM_HI:C362                 lsld                    ; Logic shift left D
ROM_HI:C363                 tfr     d,y             ; Transfer register to register
ROM_HI:C365                 ldd     CAN0RXFG        ; Load D
ROM_HI:C368                 andb    #0xF8           ; AND B with memory
ROM_HI:C36A                 cpd     -0x3B7,y        ; Compare D to memory (16-bit)
ROM_HI:C36E                 beq     loc_ROM_HI_C377 ; Branch if equal
ROM_HI:C370                 ldy     0,sp            ; Load Y
ROM_HI:C372                 dey                     ; Decrement Y
ROM_HI:C373                 sty     0,sp            ; Store Y
ROM_HI:C375                 bge     loc_ROM_HI_C360 ; Branch if greater than or equal
ROM_HI:C377
ROM_HI:C377 loc_ROM_HI_C377:                        ; CODE XREF: _CAN0_receive+21↑j
ROM_HI:C377                 ldy     0,sp            ; Load Y
ROM_HI:C379                 blt     loc_ROM_HI_C386 ; Branch if less than
ROM_HI:C37B                 ldab    -0x3AF,y        ; Load B
ROM_HI:C37F                 clra                    ; Clear A
ROM_HI:C380                 std     0,sp            ; Store D
ROM_HI:C382                 call    sub_ROM_HI_C38E,#3 ; Call subroutine in expanded memory
ROM_HI:C386
ROM_HI:C386 loc_ROM_HI_C386:                        ; CODE XREF: _CAN0_receive+2↑j
ROM_HI:C386                                         ; _CAN0_receive+2C↑j
ROM_HI:C386                 ldab    #1              ; Load B
ROM_HI:C388                 stab    CAN0RFLG        ; ACK received CAN-Message (load next from buffer)
ROM_HI:C38B                 leas    3,sp            ; restore stack
ROM_HI:C38D                 rti                     ; Return from interrupt
ROM_HI:C38D ; End of function _CAN0_receive
The CAN-Module of the MC9S12DG has a so called "foreground receiver". Incomming CAN-messages first goes into a internal buffer, which can take up to 15 messages. Is soon as a message is received a RX-flag is set and the first message is moved to the foreground receiver location where it can easily be handled. As soon as the code has processed the message it clears the RX flag and this will move the next message from buffer into foreground.

I'm especially interested in what kind of messages/IDs the receiver processes.
Post Reply