Hello,
You can use inline assembly function in your C code,
For example the following BSP_GPIO_SetBit(ADDR, Bit) call in your C code will be replaced at compilation by the bset instruction.
//-----------------------------------------------------------------------------------------------------------------------------------//
// Add the following functions in a Header File to use them
//-----------------------------------------------------------------------------------------------------------------------------------//
// Set Bit Bit_P at Address Adr_P
inline asm void BSP_GPIO_SetBit(vuint8 *Adr_P:__A0, int Bit_P:__D0) { bset.b d0,(a0) }
// Clear Bit Bit_P at Address Adr_P
inline asm void BSP_GPIO_ClearBit(vuint8 *Adr_P:__A0, int Bit_P:__D0) { bclr.b d0,(a0) }
// Toggle Bit Bit_P at Address Adr_P
inline asm void BSP_GPIO_ToggleBit(vuint8 *Adr_P:__A0, int Bit_P:__D0) { bchg.b d0,(a0) }
// Read Bit Bit_P at Address Adr_P (Return True/False in D0)
inline asm int BSP_GPIO_ReadBit(vuint8 *Adr_P:__A0, int Bit_P:__D0):__D0 { btst.b d0,(a0); sne.b d0; andi.l #1,d0 }
//-----------------------------------------------------------------------------------------------------------------------------------//
I Hope this helps..
Bye
<< Freescale MCF5234/35 with CodeWarrior 6.4>>
Thanks, I will try this.
Regards
Marcel
No, the CodeWarrior C compiler does not currently use btst, bclr, and bset instructions to manipulate bitfields.
But I'll pass your message along to the compiler team. Your question is a clear case of a user's need for such code generation.
Marc.
Hi,
Can this still be implemented please?!
Currently all write accesses to peripheral register bits do not generate code using the bclr / bset instructions, but generate code which is NOT atomic. It reads the register into a data register, applies the mask and writes the data register back to the peripheral register.
BTW, we are using MCF51QE128 and MCF51JM128 devices with CWDS for Microcontroller 6.2, build 8127.
Thanks
Marcel
Hello
If you wish that to be implemented to need to submit a Change Request and ask for improvement of generated code in that area.
Click here to submit a service request.
Make sure to attach a project producing non-optimal code .
To generate the required information:
- Start CodeWarrior
- Open the project
- Select "Help" -> "Pack and Go" and follow instructions on the screen.
Attach the generated .zip file to the SR.
CrasyCat