XMEGA ASF driver bug ? and suggestions

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Not sure if this is the best place to post this, but I think I found a bug in a driver file:

ac_driver.c, line 182:
((scaleFactor << AC_SCALEFAC_bp) & AC_SCALEFAC_gm);

should be:
((scaleFactor << AC_SCALEFAC0_bp) & AC_SCALEFAC_gm);

Also, I think the ADC driver is not easy to use, it has too many dependencies on other files, unlike the other drivers, for example, why use

irqflags_t flags = cpu_irq_save();
...
cpu_irq_restore(flags);

and not the macros in the avr_compiler.h?

/*! \brief This macro will protect the following code from interrupts. */
#define AVR_ENTER_CRITICAL_REGION( ) uint8_t volatile saved_sreg = SREG; \
cli();
#define AVR_LEAVE_CRITICAL_REGION( ) SREG = saved_sreg;

And, I think there are some inconsistencies, why is there an ioport.c in the ASF, but a port_driver.c in the XMEGA app notes?

maybe I'm just being a newbie...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for your findings.

1) AC_SCALEFAC_bp == AC_SCALEFAC0_bp, so it doesn't matter which on you use. the latter that ends with 0 explicit relates to the first bit, while the former refers to the bitmask. Aha... the former should have been _gp, not _bp :/

And, ac_driver.c? The AC driver is named ac.c in ASF, which framework are you referring to?

2) The ADC driver must save and restore interrupts to be absolutely sure the function is atomic. There is no way to work around that. The AVR Software Framework supplies an interrupt.h header file which are there to fiddle with interrupts. It is also both cross-platform and cross-toolchain. The avr_compiler.h is 8-bit specific.

The AVR_ENTER_CRITICAL_REGION and AVR_LEAVE_CRITICAL_REGION macros are horrible, as they hide a variable definition, hence it can only be used at the start of a function given the ASF code style. It is also not good practice to make a "hidden" variable, and magically assume this is available later. Likewise that it is defined as volatile, that is just plain wrong.

There will be a tool available shortly to sort out the driver dependencies, also help you generate a project based upon ASF, and change it on the fly during development.

3) ASF is not an XMEGA appnote, hence the driver is named after the names in the datasheet.

Hans-Christian