Page 2 of 2

Re: HAL vs ATMega328p (Arduino) Pin Change Interrupt

Posted: Sat Aug 29, 2015 9:14 am
by igor
Hi,

Giovanni wrote:That kind of macros are found in a dedicated section of all low level drivers (the default) AND in mcuconf.h (the actual setting). You can find lots of examples in existing LLDs.


thanks, the reason why I was convinced it was not the right place is that other macros start with "AVR_something", while this one starts with "PLATFORM_something", which made me think more of a board-like location, although the INTx is indeed an MCU-level feature.

Btw, could you please explain me the reasoning behind having one macro to enable the feature in he HAL file (HAL_USE_EXT) and one for the low level driver (PLATFORM_EXT_USE_EXT1)?
Is it intended to support multiple instances of the same HW block?

thanks, igor

Re: HAL vs ATMega328p (Arduino) Pin Change Interrupt

Posted: Sat Aug 29, 2015 10:56 am
by Giovanni
PLATFORM_ comes from the templates, you usually search "PLATFORM_" and replace with your platform prefix, for example AVR_.

Giovanni

Re: HAL vs ATMega328p (Arduino) Pin Change Interrupt

Posted: Sat Aug 29, 2015 12:32 pm
by utzig
igor wrote:Btw, could you please explain me the reasoning behind having one macro to enable the feature in he HAL file (HAL_USE_EXT) and one for the low level driver (PLATFORM_EXT_USE_EXT1)?


You need the PLATFORM_*USE* to configure/support your HW specific options and you need the HAL macro because you want to build support for the subsystem without having to go into low-level device drivers (e.g. looking for PLATFORM macros) which would break the purpose of a hardware abstraction layer.

Re: HAL vs ATMega328p (Arduino) Pin Change Interrupt

Posted: Sat Aug 29, 2015 1:32 pm
by igor
utzig wrote:
igor wrote:Btw, could you please explain me the reasoning behind having one macro to enable the feature in he HAL file (HAL_USE_EXT) and one for the low level driver (PLATFORM_EXT_USE_EXT1)?


You need the PLATFORM_*USE* to configure/support your HW specific options and you need the HAL macro because you want to build support for the subsystem without having to go into low-level device drivers (e.g. looking for PLATFORM macros) which would break the purpose of a hardware abstraction layer.


Ok on that. Where does the "1" in PLATFORM_EXT_USE_EXT1 come from?
Btw, that would become, according to Giovanni's post AVR_EXT_USE_EXT1, right?

Is that number used to identify similar but independent HW blocks?

The ATMega328p has INT0 and INT1 as direct external sources of events, but they are both handled in the same registers and I would handle them through #define EXT_MAX_CHANNELS 2
rather than having AVR_EXT_USE_EXT2

thanks, igor

Re: HAL vs ATMega328p (Arduino) Pin Change Interrupt

Posted: Sun Aug 30, 2015 2:13 pm
by igor
igor wrote:Where does the "1" in PLATFORM_EXT_USE_EXT1 come from?
Btw, that would become, according to Giovanni's post AVR_EXT_USE_EXT1, right?

Is that number used to identify similar but independent HW blocks?

The ATMega328p has INT0 and INT1 as direct external sources of events, but they are both handled in the same registers and I would handle them through #define EXT_MAX_CHANNELS 2
rather than having AVR_EXT_USE_EXT2


Answering to myself, after further reading.
So yes, what i wrote seems to be the case.

But I have one new doubt now:

the ext.h file states:

Code: Select all

/*===========================================================================*/
/* Driver constants.                                                         */
/*===========================================================================*/

/**
 * @name    EXT channel modes
 * @{
 */
#define EXT_CH_MODE_EDGES_MASK      3U  /**< @brief Mask of edges field.    */
#define EXT_CH_MODE_DISABLED        0U  /**< @brief Channel disabled.       */
#define EXT_CH_MODE_RISING_EDGE     1U  /**< @brief Rising edge callback.   */
#define EXT_CH_MODE_FALLING_EDGE    2U  /**< @brief Falling edge callback.  */
#define EXT_CH_MODE_BOTH_EDGES      3U  /**< @brief Both edges callback.    */

#define EXT_CH_MODE_AUTOSTART       4U  /**< @brief Channel started
                                             automatically on driver start. */
/** @} */


However the AVR has slightly different modes:

0: _low level_ triggers an interrupt -> ????
1: any change triggers and interrupt -> EXT_CH_MODE_BOTH_EDGES
2: falling edge triggers an interrupt -> EXT_CH_MODE_RISING_EDGE
3: rising edge triggers and interrupt -> EXT_CH_MODE_FALLING_EDGE

Quoting the TRM http://www.atmel.com/images/Atmel-8271-8-bit-AVR-Microcontroller-ATmega48A-48PA-88A-88PA-168A-168PA-328-328P_datasheet_Complete.pdf
@ 13.2.1 EICRA – External Interrupt Control Register A
• Bit 3, 2 – ISC11, ISC10: Interrupt Sense Control 1 Bit 1 and Bit 0 :
If edge or toggle interrupt is selected, pulses that
last longer than one clock period will generate an interrupt. Shorter pulses are not guaranteed to generate an
interrupt. If low level interrupt is selected, the low level must be held until the completion of the currently
executing instruction to generate an interrupt.


So the current driver doesn't seem to support level-driven IRQs.

If my analysis is correct, I would propose to extend it in a generic way (the translation to real register values can still happen in the ext_lld.c file).

The current solution uses only bits [2..0] of the mode field.

So I would propose to turn the modes section into the following (should be 100% compatible with the current version):

Code: Select all

/**
 * @name    EXT channel modes
 * @{
 */
#define EXT_CH_MODE_DISABLED        0U  /**< @brief Channel disabled.       */
#define EXT_CH_MODE_EDGES_MASK      3U  /**< @brief Mask of edges field.    */
#define EXT_CH_MODE_LEVELS_MASK    24U  /**< @brief Mask of levels field.    */
#define EXT_CH_MODE_AUTOSTART       4U  /**< @brief Channel started
                                              automatically on driver start. */

#define EXT_CH_MODE_RISING_EDGE     1U  /**< @brief Rising edge callback.   */
#define EXT_CH_MODE_FALLING_EDGE    2U  /**< @brief Falling edge callback.  */
#define EXT_CH_MODE_BOTH_EDGES      3U  /**< @brief Both edges callback.    */

#define EXT_CH_MODE_HIGH_LEVEL      8U  /**< @brief High Level callback.   */
#define EXT_CH_MODE_LOW_LEVEL      16U  /**< @brief Low Level callback.  */
#define EXT_CH_MODE_BOTH_LEVELS    24U  /**< @brief Both Levels callback.    */

/** @} */


I can create a separate patch for this.

Comments?

thanks, igor

Re: HAL vs ATMega328p (Arduino) Pin Change Interrupt

Posted: Wed Nov 11, 2015 8:05 pm
by AloinJen
May i know something more about your hardware?
What are full specifications of the hardware you are using?
Can you please post you all project details here including the firmware and the schematic details?
I am new in this field and want to learn more and more.

Re: HAL vs ATMega328p (Arduino) Pin Change Interrupt

Posted: Wed Nov 11, 2015 8:36 pm
by igor
AloinJen wrote:May i know something more about your hardware?
What are full specifications of the hardware you are using?
Can you please post you all project details here including the firmware and the schematic details?
I am new in this field and want to learn more and more.


Please do not hijack the thread.
As stated in the topic, the HW is an Arduino with ATMega328p microcontroller.

You just need to google for it.
There's plenty of documentations to get started.

But this topic doesn't seem the best way to have a smooth start.