Untitled diff

Creato Il diff non scade mai
12 rimozioni
523 linee
103 aggiunte
613 linee
/* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
/* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
*
*
* The information contained herein is property of Nordic Semiconductor ASA.
* The information contained herein is property of Nordic Semiconductor ASA.
* Terms and conditions of usage are described in detail in NORDIC
* Terms and conditions of usage are described in detail in NORDIC
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
*
*
* Licensees are granted free, non-transferable use of the information. NO
* Licensees are granted free, non-transferable use of the information. NO
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
* the file.
* the file.
*
*
*/
*/


#include "nrf_drv_gpiote.h"
#include "nrf_drv_gpiote.h"
#include "nrf_drv_common.h"
#include "nrf_drv_common.h"
#include "nrf_drv_config.h"
#include "nrf_drv_config.h"
#include "app_util_platform.h"
#include "app_util_platform.h"
#include "nrf_assert.h"
#include "nrf_assert.h"


#define FORBIDDEN_HANDLER_ADDRESS ((nrf_drv_gpiote_evt_handler_t)UINT32_MAX)
#define FORBIDDEN_HANDLER_ADDRESS ((nrf_drv_gpiote_evt_handler_t)UINT32_MAX)
#define PIN_NOT_USED (-1)
#define PIN_NOT_USED (-1)
#define PIN_USED (-2)
#define PIN_USED (-2)
#define NO_CHANNELS (-1)
#define NO_CHANNELS (-1)
#define SENSE_FIELD_POS (6)
#define SENSE_FIELD_POS (6)
#define SENSE_FIELD_MASK (0xC0)
#define SENSE_FIELD_MASK (0xC0)


//lint -save -e661
//lint -save -e661
typedef struct
typedef struct
{
{
nrf_drv_state_t state;
nrf_drv_state_t state;
nrf_drv_gpiote_evt_handler_t handlers[NUMBER_OF_GPIO_TE+GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS];
nrf_drv_gpiote_evt_handler_t handlers[NUMBER_OF_GPIO_TE+GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS];
int8_t pin_assignments[NUMBER_OF_PINS];
int8_t pin_assignments[NUMBER_OF_PINS];
int8_t handlers_to_pins[GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS];
int8_t handlers_to_pins[GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS];
} control_block_t;
} control_block_t;


static control_block_t m_cb;
static control_block_t m_cb;


typedef void (*app_gpiote_event_handler_t)(uint32_t event_pins_low_to_high,
uint32_t event_pins_high_to_low);

/**@brief GPIOTE user type. */
typedef struct
{
uint32_t pins_mask; /**< Mask defining which pins user wants to monitor. */
uint32_t pins_low_to_high_mask; /**< Mask defining which pins will generate events to this user when toggling low->high. */
uint32_t pins_high_to_low_mask; /**< Mask defining which pins will generate events to this user when toggling high->low. */
uint32_t sense_high_pins; /**< Mask defining which pins are configured to generate GPIOTE interrupt on transition to high level. */
app_gpiote_event_handler_t event_handler; /**< Pointer to function to be executed when an event occurs. */
} gpiote_user_t;

extern uint32_t m_enabled_users_mask; /**< Mask for tracking which users are enabled. */
extern uint8_t m_user_array_size; /**< Size of user array. */
extern uint8_t m_user_count; /**< Number of registered users. */
extern gpiote_user_t * mp_users; /**< Array of GPIOTE users. */

__STATIC_INLINE bool pin_in_use(uint32_t pin)
__STATIC_INLINE bool pin_in_use(uint32_t pin)
{
{
return (m_cb.pin_assignments[pin] != PIN_NOT_USED) ? true : false;
return (m_cb.pin_assignments[pin] != PIN_NOT_USED) ? true : false;
}
}


__STATIC_INLINE bool pin_in_use_as_non_task_out(uint32_t pin)
__STATIC_INLINE bool pin_in_use_as_non_task_out(uint32_t pin)
{
{
return (m_cb.pin_assignments[pin] == PIN_USED) ? true : false;
return (m_cb.pin_assignments[pin] == PIN_USED) ? true : false;
}
}


__STATIC_INLINE bool pin_in_use_by_te(uint32_t pin)
__STATIC_INLINE bool pin_in_use_by_te(uint32_t pin)
{
{
return (m_cb.pin_assignments[pin] >= 0 && m_cb.pin_assignments[pin] < NUMBER_OF_GPIO_TE) ? true : false;
return (m_cb.pin_assignments[pin] >= 0 && m_cb.pin_assignments[pin] < NUMBER_OF_GPIO_TE) ? true : false;
}
}


__STATIC_INLINE bool pin_in_use_by_port(uint32_t pin)
__STATIC_INLINE bool pin_in_use_by_port(uint32_t pin)
{
{
return (m_cb.pin_assignments[pin] >= NUMBER_OF_GPIO_TE) ? true : false;
return (m_cb.pin_assignments[pin] >= NUMBER_OF_GPIO_TE) ? true : false;
}
}


__STATIC_INLINE bool pin_in_use_by_gpiote(uint32_t pin)
__STATIC_INLINE bool pin_in_use_by_gpiote(uint32_t pin)
{
{
return (m_cb.pin_assignments[pin] >= 0) ? true : false;
return (m_cb.pin_assignments[pin] >= 0) ? true : false;
}
}


__STATIC_INLINE void pin_in_use_by_te_set(uint32_t pin,
__STATIC_INLINE void pin_in_use_by_te_set(uint32_t pin,
uint32_t channel_id,
uint32_t channel_id,
nrf_drv_gpiote_evt_handler_t handler,
nrf_drv_gpiote_evt_handler_t handler,
bool is_channel)
bool is_channel)
{
{
m_cb.pin_assignments[pin] = channel_id;
m_cb.pin_assignments[pin] = channel_id;
m_cb.handlers[channel_id] = handler;
m_cb.handlers[channel_id] = handler;
if (!is_channel)
if (!is_channel)
{
{
m_cb.handlers_to_pins[channel_id-NUMBER_OF_GPIO_TE] = (int8_t)pin;
m_cb.handlers_to_pins[channel_id-NUMBER_OF_GPIO_TE] = (int8_t)pin;
}
}
}
}


__STATIC_INLINE void pin_in_use_set(uint32_t pin)
__STATIC_INLINE void pin_in_use_set(uint32_t pin)
{
{
m_cb.pin_assignments[pin] = PIN_USED;
m_cb.pin_assignments[pin] = PIN_USED;
}
}


__STATIC_INLINE void pin_in_use_clear(uint32_t pin)
__STATIC_INLINE void pin_in_use_clear(uint32_t pin)
{
{
m_cb.pin_assignments[pin] = PIN_NOT_USED;
m_cb.pin_assignments[pin] = PIN_NOT_USED;