bsp/atsam: Add additional PIO helper.

This commit is contained in:
Christian Mauderer
2019-10-23 10:41:34 +02:00
parent d4b92da208
commit d60b6d7c33
2 changed files with 59 additions and 0 deletions
@@ -37,6 +37,8 @@
#include "chip.h"
#include <string.h>
#include <rtems/irq-extension.h>
#include <rtems/sysinit.h>
#include <bsp/fatal.h>
@@ -285,3 +287,47 @@ void PIO_ConfigureIt(const Pin *pPin, void (*handler)(const Pin *, void *arg),
/* Define new source */
TRACE_DEBUG("PIO_ConfigureIt: Defining new source #%d.\n\r", _dwNumSources);
}
/**
* Search for a PIO interrupt and remove it if it is there.
* \param pPin Pointer to a Pin instance.
* \param handler Interrupt handler function pointer.
* \param arg Pointer to interrupt handler argument
* \return RTEMS_SUCCESSFUL if removed.
* \return RTEMS_UNSATISFIED if the handler couldn't be found
*/
rtems_status_code PIO_RemoveIt(const Pin *pPin,
void (*handler)(const Pin *, void *arg), void *arg)
{
InterruptSource *pSource;
rtems_interrupt_level level;
rtems_status_code sc = RTEMS_UNSATISFIED;
uint32_t i;
uint32_t j;
TRACE_DEBUG("PIO_RemoveIt()\n\r");
rtems_interrupt_disable(level);
for(i = 0; i < _dwNumSources; ++i) {
pSource = &(_aIntSources[_dwNumSources]);
if(pSource->pPin == pPin &&
pSource->handler == handler &&
pSource->arg == arg) {
if(i + 1 < _dwNumSources) {
TRACE_DEBUG("PIO_RemoveIt: Remove #%d.\n\r", i);
/* Move remaining sources */
memcpy(pSource,
&(_aIntSources[i+1]),
sizeof(_aIntSources[0])*(_dwNumSources-i-1)
);
}
_dwNumSources--;
sc = RTEMS_SUCCESSFUL;
}
}
rtems_interrupt_enable(level);
return sc;
}
@@ -66,6 +66,7 @@
*/
#include "pio.h"
#include <rtems.h>
#ifdef __cplusplus
extern "C" {
@@ -80,6 +81,8 @@ extern void PIO_InitializeInterrupts(uint32_t dwPriority);
extern void PIO_ConfigureIt(const Pin *pPin,
void (*handler)(const Pin *, void *arg), void *arg);
extern rtems_status_code PIO_RemoveIt(const Pin *pPin,
void (*handler)(const Pin *, void *arg), void *arg);
/**
* Enables the given interrupt source if it has been configured. The status
@@ -103,6 +106,16 @@ static inline void PIO_DisableIt(const Pin *pPin)
pPin->pio->PIO_IDR = pPin->mask;
}
/**
* Check whether a given interrupt source is active.
*
* \param pPin Interrupt source to check.
*/
static inline bool PIO_ItIsActive(const Pin *pPin)
{
return ((pPin->pio->PIO_IMR & pPin->mask) != 0);
}
extern void PIO_IT_InterruptHandler(void);
extern void PioInterruptHandler(uint32_t id, Pio *pPio);