bset/bclr/btst from C compiler

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

bset/bclr/btst from C compiler

5,390 Views
dferbas
Contributor I
Hi,

does anyone know how to force compilation for bit field access to be done with btst/bclr/bset instructions. We are using MCF5272.

The code size (originally generated for MC68EN302 with Microtek C compiler) really increased when and/or with patterns are generated.

Is this supported by MW Coldfire suite ?

Dusan
Labels (1)
0 Kudos
5 Replies

1,074 Views
Arev
Contributor III

 

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>>

 

0 Kudos

1,074 Views
Marcel
Contributor II

Thanks, I will try this.

 

Regards

Marcel

0 Kudos

1,074 Views
marc_paquette
Contributor V

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.

0 Kudos

1,074 Views
Marcel
Contributor II

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

0 Kudos

1,074 Views
CrasyCat
Specialist III

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

0 Kudos