Help save net neutrality! Learn more.
Close

Keil bdata equivilent

Anonymous
2003-03-04
2003-07-18
  • Anonymous - 2003-03-04

    I am trying to compile some code that was written for the Keil compiler

    The code looks like this....

    bdata Uchar conf;
    Sbit( msk_ide, conf, 7);  /* just for TX      */
    Sbit( msk_rtr, conf, 6);  /* just for RX      */
    Sbit( rtr    , conf, 5);  /* commun Rx and TX */
    Sbit( ide    , conf, 4);  /* commun RX and TX */
    Sbit( buffer , conf, 0);  /* just for TX      */

    SDCC doesn't seem to know what to do with the bdata keyword (in Keil makes Uchar conf bit addressable)

    If anyone has any ideas how I can change this code so that it will compile they would be very greatfully received.

    Many thanks

    Simon Hodgson

     
    • Bernhard Held

      Bernhard Held - 2003-03-04

      There's no equivalent for bdata in SDCC. But you can replace it by "manually" placing "conf" and the bits in the bit addressable area 0x20...0x2f:

      data at 0x20 unsigned char conf;
      bit at 7 msk_ide;
      bit at 6 msk_rtr;
      ...

      SDCC knows nothing about the relationship of "conf" and the bits. You've to calculate the correct offsets, and you might need the modifier "volatile".

       
      • J-C Lallemand

        J-C Lallemand - 2003-07-13

        Hi all,

        If I refer to the SDCC documentation, the absolute addressing does not allocate memory.

        What would be the best way then to allocate the memory and the play the trick you describe for bit assignment? Do I have to allocate the memory in an assembly file?

        Thanks in advance...

         
    • Jesus Calvino-Fraga

      You can define a byte at the very begining or the bit data segment that contains the bits, and then instruct the linker to put the bits higher in memory.  This will work only with a version of sdcc built on July 15th 2003 or later since I fixed a problem with the linker that was preventing it to work:

      sdcc -Wl-bBSEG=0x08 bits.c

      ----begin bits.c----
      unsigned char at 0x20 mybyte;
      bit at 0x00 bit0; //bit 0 of mybyte
      bit at 0x01 bit1; //bit 1 of mybyte
      bit at 0x02 bit2; //bit 2 of mybyte
      bit at 0x03 bit3; //bit 3 of mybyte
      bit at 0x04 bit4; //bit 4 of mybyte
      bit at 0x05 bit5; //bit 5 of mybyte
      bit at 0x06 bit6; //bit 6 of mybyte
      bit at 0x07 bit7; //bit 7 of mybyte

      volatile unsigned char j; //just to check for no clash

      void main (void)
      {
        for(j=0; j<20; j++)
        {
           mybyte=j;
        }
        bit0=0;
        bit1=1;
      }
      ----bits.c end---

       
    • Anonymous - 2003-07-18

      I've actually been trying to do the exact same thing.  I see how this can be done if you need only one byte.  But say I want to use 2 bit fields?  Here is what it would look like:

      // bit field 1
      bdata Uchar conf;
      Sbit( msk_ide, conf, 7); /* just for TX */
      Sbit( msk_rtr, conf, 6); /* just for RX */
      Sbit( rtr , conf, 5); /* commun Rx and TX */
      Sbit( ide , conf, 4); /* commun RX and TX */
      Sbit( buffer , conf, 0); /* just for TX */

      //bit field 2
      bdata Uchar bvar
      Sbit(bvar7, bvar, 7);
      Sbit(bvar6, bvar, 6);
      Sbit(bvar5, bvar, 5);
      Sbit(bvar4, bvar, 4);
      Sbit(bvar3, bvar, 3);
      Sbit(bvar2, bvar, 2);
      Sbit(bvar1, bvar, 1);
      Sbit(bvar0, bvar, 0);

      Or maybe even a third bit field.  I've spent days on the problem.  Still trying to understand how to use the bit addressable memory.

      Thanks
      Jon

       

Log in to post a comment.