[En-Nut-Discussion] Do we need something like sbv/sbi to complement sbi/cbi?

Uwe Bonnes bon at elektron.ikp.physik.tu-darmstadt.de
Thu Dec 29 17:11:00 CET 2011


in Ulrich's devnut_m3n, some function used
  sbi( ) and cbi()

Obvious, the stm libraries define register bits with their bit value
#define  TIM_SR_UIF                          ((uint16_t)0x0001)
and not bit positions like
#define  TIM_SR_UIF_BIT                         0

The s/cbi macro expands in devnut_m3n expands like
#define cbi(_reg, _bit)         outr(_reg, inr(_reg) & ~_BV(_bit)) 
and was used like
  cbi( &TIM->SR, TIM_SR_UIF );
and so things got wrong.

The coding style rules say  that direct register access like 
is deprecated. So either explicit writing
outr(_reg, inr(_reg) & _mask)
is needed, or some macros to do so. In my tree I added

#define sbv(_reg, _mask)         outr(_reg, inr(_reg) | _mask)
#define cbv(_reg, _mask)         outr(_reg, inr(_reg) & ~_mask)
#define bv_is_set(_reg, _mask)  ((inr(_reg) & _mask)) != 0)

Are these macros the right thing?

Uwe Bonnes                bon at elektron.ikp.physik.tu-darmstadt.de

Institut fuer Kernphysik  Schlossgartenstrasse 9  64289 Darmstadt
--------- Tel. 06151 162516 -------- Fax. 06151 164321 ----------

More information about the En-Nut-Discussion mailing list