This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

bit access to eCAN mailboxes F28335

Hi,

 

I need bit access in the MDL and MDH data registers of eCAN mailboxes. I've added a structure in the eCAN header file. When I open CCSv4 to code my MCU, it gives me this bit options

 

Struct MDL_BITS{

Uint16 bit0:1;

Uint16 bit1:1;

.......

 

similarly  for MDH too!!

ECanaMboxes.MBOX10.MDL.bit.bit0 when I use it. However, these are not taking the values I enter. Is this the correct way to achieve bit access to mailboxes?

  • Have you added the union? This kind of bit addressing relies on a union to allow you access either the whole register or just single bits.  At the moment it currently allows byteaddressing:

    Current code:

    union CANMDH_REG {
       Uint32                  all;
       struct CANMDH_WORDS     word;
       struct CANMDH_BYTES     byte;
    };

    and

    struct  CANMDH_BYTES {      // bits   description
       Uint16      BYTE7:8;     // 63:56
       Uint16      BYTE6:8;     // 55:48
       Uint16      BYTE5:8;     // 47:40
       Uint16      BYTE4:8;     // 39:32
    };

    There are two ways to change this to do what you want (I am using MDH but changing it to MDL will be easy)

    1) Change the union only

    union CANMDH_REG {
       Uint32                  all;
      struct MDH_BITS bit;
    };

    2) Change the union and add a byte struct

    struct CANMDH_BYTE_BITS

     {

    Uint16 bit0:1

    ...

    Uint16 bit7:1

     }

    union CANMDH_BYTE_REG

     {

       Uint16 all:8;

       struct CANMDH_BYTE_BITS bit;

     }

    struct  CANMDH_BYTES {      // bits   description
    union CANMDH_BYTE_REG Byte7;

    union CANMDH_BYTE_REG Byte6;

    union CANMDH_BYTE_REG Byte5;

    union CANMDH_BYTE_REG Byte4;

    };

    union CANMDH_REG {
       Uint32                  all;
       struct CANMDH_BYTES     byte;
    };

    This will allow the addressing Reg.byte.Byte7.bit.bit0.

    Look at the header files for more examples of unions.

    Hope this helps,

    Tim

     

     

  • Hi Tim,

     

    Thanks! That helped. I changed the union for bits directly.This is what I've done before too. But for some weird reason, it wouldn't work properly. all I had to do was, retype the whole thing and it works. :)

     

    Thanks,

     

    VY

  • Hi,

    I've another question. Apart from defining the bits, I wanted to define another struct variable in MDL and MDH regs. Here's what I need:

    struct CANMDH_Variable {  //bits description

     

    Uint16 A:8;                                       //32:39

    Uint16    B:16;                                   //55:40

    Uint16    C:8;                                    //63:56

    };

     

    union CANMDH_REG {

       Uint32                  all;

       struct CANMDH_WORDS     word;

       struct CANMDH_BYTES     byte;

       struct CANMDH_BITS   bit;

       struct CANMDH_Variable    variable;

    };

     

     

    Similarly in MDL too. When I compile this code, it gives me the following error:

     

    Severity and Description Path Resource Location Creation Time Id

    run placement fails for object "ECanaMboxesFile", size 0x180 (page 1). Available ranges: ECANA_MBOX   size: 0x100        unused: 0x100        max hole: 0x100 Example_28335_Flash line 0 1304601263380 764

    I do not know what this means. It also gives me a linking error during this:
    Severity and Description Path Resource Location Creation Time Id
    errors encountered during linking; "Example_28335_Flash.out" not built Example_28335_Flash line 0 1304601263382 767
    if I delete the line "struct CANMDH_Variable    variable;" , it works alright again. Can anyone tell me what is wrong here.
    Thanks,
    VY

     

     

  • I guess the bitfield B:16 cannot span a word boundary and as it doesn't fit into what is left in the word that is partially occupied by A:8 the compiler puts B into the next word.

    Thus, sizeof(struct CANMD_Variable) is 3 and not 2 which makes it not fit into the reserved space.

  • johannes said:

    I guess the bitfield B:16 cannot span a word boundary and as it doesn't fit into what is left in the word that is partially occupied by A:8 the compiler puts B into the next word.

    Thus, sizeof(struct CANMD_Variable) is 3 and not 2 which makes it not fit into the reserved space.

    That must be it.  I was trying to think of why it wasn't working but I think you have provided the answer.

    Thanks

    Tim