This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to program sbits which can be indexed ?

I would like to to use the bit addressable memory range (bdata) with an index variable as in the following example:

#define SETBIT(I) WAIT_4_MUTEX; flags^I=1; FREE_MUTEX;

unsigned char bdata flags;

func () {
unsigned char i;
  for (i=0; i < MAX_CELL; i++) {
    // do interesting stuff
    SETBIT(i);
  }
}

This construction of coarse gives a lval error on the use of the SETBIT macro.

My current fall back are the macro's:

#define SETBIT(I) base |= ((unsigned char) (1 << I))
#define CLEARBIT(I) base &= ~((unsigned char) (1 << I))

But still have the feeling that I am wasting cycles on the shift operators in these two macro's and because this is within a mutex region the timing might become an issue.

Is there a better way to set/reset the i-th bit of a bit addressable variable ?

Parents
  • Well, there is a suggestion, here is the listing for setting the second bit of the Hs_st1 bitfield:

    C:0x2D4F    122FB9   LCALL    OS_WAIT(C:2FB9)
    C:0x2D52    432202   ORL      Hs_st1(0x22),#0x02
    C:0x2D55    7F09     MOV      R7,#0x09
    C:0x2D57    123A72   LCALL    OS_SEND_TOKEN(C:3A72)
    

    The shifts apparently have been taken care of outside the critical region, probably even in the preproc's macro expansion. Although for that, in hindsight slightly embarrassing reason, this is what I wanted.

    Thanks everybody for the contributions,

    "In peace my mind withdraws"

Reply
  • Well, there is a suggestion, here is the listing for setting the second bit of the Hs_st1 bitfield:

    C:0x2D4F    122FB9   LCALL    OS_WAIT(C:2FB9)
    C:0x2D52    432202   ORL      Hs_st1(0x22),#0x02
    C:0x2D55    7F09     MOV      R7,#0x09
    C:0x2D57    123A72   LCALL    OS_SEND_TOKEN(C:3A72)
    

    The shifts apparently have been taken care of outside the critical region, probably even in the preproc's macro expansion. Although for that, in hindsight slightly embarrassing reason, this is what I wanted.

    Thanks everybody for the contributions,

    "In peace my mind withdraws"

Children
No data