Drexel University's Logo

Clayton McNeil

Texas Instruments F2808 DSP eCAN Guide


Home
About Me
Tutorials
Media Archive
Resources

Part 2: eCAN Programming Conventions

Many of the eCan register can only be accessed 32-bit wide. What this means is that a specific bit cannot just be set without affecting the other bits. To overcome this, registers are represented as a nestled set of structures and unions contained within the ECAN_REGS structure. For instance, the eCAN CANME register is represented by a union called CANME_REG, which is made up of a structure called CANME_BITS and a 32-bit, unsigned integer called ‘all’.

ECAN_REGS structure referred to as the ‘shadow’. The bit is then changed in the copy and the whole thing is assigned back to the original. The net effect is that only the bit changed in the copy is really altered, even though all the bits were technically set. Below is code demonstrating this technique for the MC register:

One other consideration to keep in mind is that some bits are EALLOW protected, which means that the CPU cannot change them without first issuing the EALLOW instruction. This is done in code via the EALLOW macro. Once the changes are made, the EDIS instruction should be issued, via the EDIS macro, to disable writes again.

    ECanaShadow.CANME.all = ECanaRegs.CANME.all;
    ECanaShadow.CANME.bit.ME1 = 1;
    ECanaShadow.CANME.bit.ME2 = 1;
    ECanaShadow.CANME.bit.ME3 = 1;
    ECanaRegs.CANME.all = ECanaShadow.CANME.all;

Note that sometimes, using the shadow is not necessary. The above code enables mailboxes 1-3. Assuming that these were the only mailboxes that should be turned on, an alternative way to accomplishing this would be:

    ECanaRegs.CANME.all = 0x0000000E;

In both case, all 32-bits of the register were set. The only difference with this method is that the previous state of the register was ignored (and the code is considerably shorter).

Continue to Part 3, DSP280x_ECan.c...

Home | About Me | Tutorials | Media Archive | Resources