bset/bclr/btst from C compiler

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

bset/bclr/btst from C compiler

6,721件の閲覧回数
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
ラベル(1)
タグ(1)
0 件の賞賛
返信
5 返答(返信)

2,405件の閲覧回数
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 件の賞賛
返信

2,405件の閲覧回数
Marcel
Contributor II

Thanks, I will try this.

 

Regards

Marcel

0 件の賞賛
返信

2,405件の閲覧回数
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 件の賞賛
返信

2,405件の閲覧回数
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 件の賞賛
返信

2,405件の閲覧回数
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 件の賞賛
返信