Author Topic: ?? bug in samd51 EIC header file  (Read 1485 times)

0 Members and 1 Guest are viewing this topic.

Offline snarkysparkyTopic starter

  • Frequent Contributor
  • **
  • Posts: 441
  • Country: us
?? bug in samd51 EIC header file
« on: November 09, 2023, 02:26:16 pm »
I doubt its a bug really but i just don't understand.


I am trying to enable EXTINT11.  The bitfields in the header file

#define EIC_INTENSET_EXTINT_Pos     0            /**< \brief (EIC_INTENSET) External Interrupt Enable */
#define EIC_INTENSET_EXTINT_Msk     (_U_(0xFFFF) << EIC_INTENSET_EXTINT_Pos)
#define EIC_INTENSET_EXTINT(value)  (EIC_INTENSET_EXTINT_Msk & ((value) << EIC_INTENSET_EXTINT_Pos))
#define EIC_INTENSET_MASK           _U_(0x0000FFFF) /**< \brief (EIC_INTENSET) MASK Register */

so

REG_EIC_INTENSET = EIC_INTENSET_EXTINT(11);      //  write 11 into register ?  not correct according to data sheet.  To enable EXTINT11  need to write   1 << 11  into register

datasheet ->
Bits 15:0 – EXTINT[15:0] External Interrupt Enable
The bit x of EXTINT enables the interrupt associated with the EXTINTx pin.
Writing a '0' to bit x has no effect.
Writing a '1' to bit x will set the External Interrupt Enable bit x, which enables the external interrupt EXTINTx.

so I need to do

REG_EIC_INTENSET |= 1 << 11;

AMI wrong ???

Thanks






 

Offline eutectique

  • Frequent Contributor
  • **
  • Posts: 638
  • Country: be
Re: ?? bug in samd51 EIC header file
« Reply #1 on: November 09, 2023, 02:36:14 pm »
Without a specific macro for EXTINT11:

REG_EIC_INTENSET |= EIC_INTENSET_EXTINT(1u<<11);
 

Offline cv007

  • Super Contributor
  • ***
  • Posts: 1071
Re: ?? bug in samd51 EIC header file
« Reply #2 on: November 09, 2023, 09:13:41 pm »
With these header monsters, everything is a define so you have to keep to their system of define/macro usage-

This would be an example of the part you are missing, in the device header which specifies its pins-
Code: [Select]
#define PIN_PA11A_EIC_EXTINT11         _L_(11) /**< \brief EIC signal: EXTINT11 on PA11 mux A */
#define MUX_PA11A_EIC_EXTINT11          _L_(0)
#define PINMUX_PA11A_EIC_EXTINT11  ((PIN_PA11A_EIC_EXTINT11 << 16) | MUX_PA11A_EIC_EXTINT11)
#define PORT_PA11A_EIC_EXTINT11  (_UL_(1) << 11)
#define PIN_PA11A_EIC_EXTINT_NUM       _L_(11) /**< \brief EIC signal: PIN_PA11 External Interrupt Line */
#define PIN_PA27A_EIC_EXTINT11         _L_(27) /**< \brief EIC signal: EXTINT11 on PA27 mux A */
#define MUX_PA27A_EIC_EXTINT11          _L_(0)
#define PINMUX_PA27A_EIC_EXTINT11  ((PIN_PA27A_EIC_EXTINT11 << 16) | MUX_PA27A_EIC_EXTINT11)
#define PORT_PA27A_EIC_EXTINT11  (_UL_(1) << 27)
#define PIN_PA27A_EIC_EXTINT_NUM       _L_(11) /**< \brief EIC signal: PIN_PA27 External Interrupt Line */
#define PIN_PB11A_EIC_EXTINT11         _L_(43) /**< \brief EIC signal: EXTINT11 on PB11 mux A */
#define MUX_PB11A_EIC_EXTINT11          _L_(0)
#define PINMUX_PB11A_EIC_EXTINT11  ((PIN_PB11A_EIC_EXTINT11 << 16) | MUX_PB11A_EIC_EXTINT11)
#define PORT_PB11A_EIC_EXTINT11  (_UL_(1) << 11)

So now you code becomes-
REG_EIC_INTENSET = EIC_INTENSET_EXTINT(PORT_PB11A_EIC_EXTINT11); //or whatever EXT11 pin you wanted

The EIC_INTENSET_EXTINT_Pos define simply specifies the location of all these bits in the register (0). The macro will mask off the relevant bits and shift your BITMASK value into the relevant bit position (0).


Quote
so I need to do

REG_EIC_INTENSET |= 1 << 11;
That would be wrong also. You do not want |= on these type of registers (you want just =). Whether it actually matters or not in this case (I do not know), the purpose of these set/clr registers is to get an atomic write. With |=, you lose that and may potentially mess with other bits due to the read (using the read values to write, instead of just dealing with only the bit(s) you wanted to set).
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 12516
  • Country: us
    • Personal site
Re: ?? bug in samd51 EIC header file
« Reply #3 on: November 09, 2023, 09:46:34 pm »
This is not really a bug. Those files are auto-generated and the generator does not know the type of the field, so the macros universally take the value you want to write. If this value needs to be a shifted bit, then it it on you to shift it. This also lets you set multiple bits at the same time.

And this is not specific to EIC, it applies to all the peripherals.

This also means that there will be macros generated that make no logical sense too.
Alex
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 17876
  • Country: fr
Re: ?? bug in samd51 EIC header file
« Reply #4 on: November 10, 2023, 01:34:32 am »
Yes, they are all built on the same principle and it is quite simple. They encode bit fields with masks and bit positions. (Others prefer using real bit fields in structs, although they are known not to be quite portable - but it usually doesn't matter in practice.) So, as ataradov said, these macros don't do anyting else than this. They don't further encode bit fields (although there may be some other macros that do this, you'll have to look, SAMD header files are quite long.)
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->