We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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 ?
The switch statement can be fast for some processors, that have efficient methods to call a jump table.
JMP @A+DPTR ?
And if the compiler isn't clever enough to translate the switch/case structure this way, there is still the option of writing an assembly function.
This approach also works for more than 8 bits without any further effort, while the lookup table approach will need additional decision steps in such cases.