Skip to content

Conversation

@singalsu
Copy link
Collaborator

These macros are useful for decoding bit fields.

Signed-off-by: Seppo Ingalsuo seppo.ingalsuo@linux.intel.com

Copy link
Member

@lgirdwood lgirdwood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@singalsu can you check and see if these are the same naming and usages as Zephyr versions. We should align.

@singalsu
Copy link
Collaborator Author

singalsu commented May 27, 2021

There's in Zephyr e.g. drivers/neural_net/intel_gna.h one with different way than mine. This shifts left and right other bits out of uint32 except requested one. Mine ANDs with bit mask and shift right the result, and works with other world lengths too. The macro params order is different.

#define GNA_GET_BITS(val, b_hi, b_lo)	((((uint32_t)(val)) << (31 - (b_hi))) >> \
		(31 - (b_hi) + (b_lo)))

I could not spot anything similar from https://github.com/zephyrproject-rtos/zephyr with quick grep for BIT and GET.

Edit: one more from drivers/ethernet/eth_smsc911x_priv.h with different way and different macro parameters. This might fail with 64 bit.

#define GET_BITFIELD(val, lsb, msb) \
	(((val) >> (lsb)) & ((1 << ((msb) - (lsb) + 1)) - 1))

@paulstelian97
Copy link
Collaborator

Won't approve until I see the intended use case.

@singalsu singalsu force-pushed the add_get_bit_and_get_bits_macros branch from 132c1df to 35ba93b Compare May 27, 2021 15:15
@singalsu
Copy link
Collaborator Author

singalsu commented May 27, 2021

@paulstelian97 The macros are used in this another PR file https://github.com/thesofproject/sof/blob/8d68ef2832b4fcdfabaccce00f95952a09a6b3a5/src/drivers/intel/dmic/dmic_nhlt.c . It was a proposal by Liam to make a separate PR for this.

Edit: Sorry, not that file but the header it uses https://github.com/thesofproject/sof/blob/8d68ef2832b4fcdfabaccce00f95952a09a6b3a5/src/include/sof/drivers/dmic.h . See e.g. line 161 ->

@lgirdwood
Copy link
Member

lgirdwood commented May 27, 2021

@nashif @andyross we would like to add some macros for getting registers bits, but would obviously like to align with Zephyr. Is there anything similar in Zephyr today and if not, would this be something that would be added later ?

These macros are useful for decoding bit fields.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
@singalsu singalsu force-pushed the add_get_bit_and_get_bits_macros branch from 35ba93b to 799230e Compare June 1, 2021 14:14
Copy link
Collaborator

@paulstelian97 paulstelian97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess they look good now. An extra commit to use MASK in the pre-existing SET_BITS wouldn't be bad but I won't require it.

@lgirdwood lgirdwood merged commit 8c49743 into thesofproject:main Jun 3, 2021
@singalsu singalsu deleted the add_get_bit_and_get_bits_macros branch June 15, 2021 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants