It is simply, there are three 3 tx buffers which shares one space in memory model. Access is driven by CANTBSEL register.
CANTBSEL register has special feature – when we write and read this register, it will find the lowest ordered bit set to “1”, all other bits will be read as “0”. This feature allows simple code for selecting proper buffer.
Datasheet says:
The application software wants to get the next available transmit buffer. It reads the CANTFLG register and writes this value back into the CANTBSEL register. In this example Tx buffers TX1 and TX2 are available. The value read from CANTFLG is therefore 0b0000_0110. When writing this value back to CANTBSEL the Tx buffer TX1 is selected in the CANTXFG because the lowest numbered bit set to “1” is at bit position 1. Reading back this value out of CANTBSEL results in 0b0000_0010, because only the lowest numbered bit position set to “1” is presented. This mechanism eases the application software the selection of the next available Tx buffer.
LDD CANTFLG; value read is 0b0000_0110
STD CANTBSEL; value written is 0b0000_0110
LDD CANTBSEL; value read is 0b0000_0010
So, you can use this code:
CAN0TBSEL = CAN0TFLG; /* Select lowest empty buffer */
txbuffer = CAN0TBSEL; /* Backup selected buffer */
//fill Tx buffer
CAN0TFLG = txbuffer; /* Start transmission */
In attachment you can find simple example code.
Note: example code was created for different S12 MCU, therefore some details doesn’t need to fit, however principle is the same.