bugfix for duplicate symbol

Fork of nRF51822 by Nordic Semiconductor

Files at this revision

API Documentation at this revision

Comitter:
finneyj
Date:
Fri May 15 12:12:21 2015 +0000
Parent:
111:be2a122ed2f7
Commit message:
bug fix - redefined symbol

Changed in this revision

nordic-sdk/components/libraries/gpiote/app_gpiote.c Show diff for this revision Revisions of this file
nordic-sdk/components/libraries/gpiote/app_gpiote.h Show diff for this revision Revisions of this file
--- a/nordic-sdk/components/libraries/gpiote/app_gpiote.c	Wed Apr 15 09:24:27 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,360 +0,0 @@
-/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
- *
- * The information contained herein is property of Nordic Semiconductor ASA.
- * Terms and conditions of usage are described in detail in NORDIC
- * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
- *
- * Licensees are granted free, non-transferable use of the information. NO
- * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
- * the file.
- *
- */
-
-#include "app_gpiote.h"
-#include <stdlib.h>
-#include <string.h>
-#include "app_util.h"
-#include "app_util_platform.h"
-#include "nrf_error.h"
-#include "nrf_gpio.h"
-
-
-/**@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;
-
-STATIC_ASSERT(sizeof(gpiote_user_t) <= GPIOTE_USER_NODE_SIZE);
-STATIC_ASSERT(sizeof(gpiote_user_t) % 4 == 0);
-
-static uint32_t        m_enabled_users_mask;          /**< Mask for tracking which users are enabled. */
-static uint8_t         m_user_array_size;             /**< Size of user array. */
-static uint8_t         m_user_count;                  /**< Number of registered users. */
-static gpiote_user_t * mp_users = NULL;               /**< Array of GPIOTE users. */
-
-
-/**@brief Function for toggling sense level for specified pins.
- *
- * @param[in]   p_user   Pointer to user structure.
- * @param[in]   pins     Bitmask specifying for which pins the sense level is to be toggled.
- */
-static void sense_level_toggle(gpiote_user_t * p_user, uint32_t pins)
-{
-    uint32_t pin_no;
-
-    for (pin_no = 0; pin_no < NO_OF_PINS; pin_no++)
-    {
-        uint32_t pin_mask = (1 << pin_no);
-
-        if ((pins & pin_mask) != 0)
-        {
-            uint32_t sense;
-
-            // Invert sensing.
-            if ((p_user->sense_high_pins & pin_mask) == 0)
-            {
-                sense                    = GPIO_PIN_CNF_SENSE_High << GPIO_PIN_CNF_SENSE_Pos;
-                p_user->sense_high_pins |= pin_mask;
-            }
-            else
-            {
-                sense                    = GPIO_PIN_CNF_SENSE_Low << GPIO_PIN_CNF_SENSE_Pos;
-                p_user->sense_high_pins &= ~pin_mask;
-            }
-
-            NRF_GPIO->PIN_CNF[pin_no] &= ~GPIO_PIN_CNF_SENSE_Msk;
-            NRF_GPIO->PIN_CNF[pin_no] |= sense;
-        }
-    }
-}
-
-
-/**@brief Function for handling the GPIOTE interrupt.
- */
-void GPIOTE_IRQHandler(void)
-{
-    uint8_t  i;
-    uint32_t pins_changed;
-    uint32_t pins_state = NRF_GPIO->IN;
-
-    // Clear event.
-    NRF_GPIOTE->EVENTS_PORT = 0;
-
-    // Check all users.
-    for (i = 0; i < m_user_count; i++)
-    {
-        gpiote_user_t * p_user = &mp_users[i];
-
-        // Check if user is enabled.
-        if (((1 << i) & m_enabled_users_mask) != 0)
-        {
-            uint32_t transition_pins;
-            uint32_t event_low_to_high;
-            uint32_t event_high_to_low;
-
-            // Find set of pins on which there has been a transition.
-            transition_pins = (pins_state ^ ~p_user->sense_high_pins) & p_user->pins_mask;
-
-            // Toggle SENSE level for all pins that have changed state.
-            sense_level_toggle(p_user, transition_pins);
-
-            // Second read after setting sense.
-            // Check if any pins have changed while serving this interrupt.
-            pins_changed = NRF_GPIO->IN ^ pins_state;
-            if (pins_changed)
-            {
-                // Transition pins detected in late stage.
-                uint32_t late_transition_pins;
-
-                pins_state          |= pins_changed;
-
-                // Find set of pins on which there has been a transition.
-                late_transition_pins = (pins_state ^ ~p_user->sense_high_pins) & p_user->pins_mask;
-
-                // Toggle SENSE level for all pins that have changed state in last phase.
-                sense_level_toggle(p_user, late_transition_pins);
-
-                // Update pins that has changed state since the interrupt occurred.
-                transition_pins |= late_transition_pins;
-            }
-
-            // Call user event handler if an event has occurred.
-            event_high_to_low = (~pins_state & p_user->pins_high_to_low_mask) & transition_pins;
-            event_low_to_high = (pins_state & p_user->pins_low_to_high_mask) & transition_pins;
-
-            if ((event_low_to_high | event_high_to_low) != 0)
-            {
-                p_user->event_handler(event_low_to_high, event_high_to_low);
-            }
-        }
-    }
-}
-
-
-/**@brief Function for sense disabling for all pins for specified user.
- *
- * @param[in]  user_id   User id.
- */
-static void pins_sense_disable(app_gpiote_user_id_t user_id)
-{
-    uint32_t pin_no;
-
-    for (pin_no = 0; pin_no < 32; pin_no++)
-    {
-        if ((mp_users[user_id].pins_mask & (1 << pin_no)) != 0)
-        {
-            NRF_GPIO->PIN_CNF[pin_no] &= ~GPIO_PIN_CNF_SENSE_Msk;
-            NRF_GPIO->PIN_CNF[pin_no] |= GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos;
-        }
-    }
-}
-
-
-uint32_t app_gpiote_init(uint8_t max_users, void * p_buffer)
-{
-    if (p_buffer == NULL)
-    {
-        return NRF_ERROR_INVALID_PARAM;
-    }
-
-    // Check that buffer is correctly aligned.
-    if (!is_word_aligned(p_buffer))
-    {
-        return NRF_ERROR_INVALID_PARAM;
-    }
-
-    // Initialize file globals.
-    mp_users             = (gpiote_user_t *)p_buffer;
-    m_user_array_size    = max_users;
-    m_user_count         = 0;
-    m_enabled_users_mask = 0;
-
-    memset(mp_users, 0, m_user_array_size * sizeof(gpiote_user_t));
-
-    // Initialize GPIOTE interrupt (will not be enabled until app_gpiote_user_enable() is called).
-    NRF_GPIOTE->INTENCLR = 0xFFFFFFFF;
-
-    NVIC_ClearPendingIRQ(GPIOTE_IRQn);
-    NVIC_SetPriority(GPIOTE_IRQn, APP_IRQ_PRIORITY_HIGH);
-    NVIC_EnableIRQ(GPIOTE_IRQn);
-
-    return NRF_SUCCESS;
-}
-
-
-uint32_t app_gpiote_user_register(app_gpiote_user_id_t     * p_user_id,
-                                  uint32_t                   pins_low_to_high_mask,
-                                  uint32_t                   pins_high_to_low_mask,
-                                  app_gpiote_event_handler_t event_handler)
-{
-    // Check state and parameters.
-    if (mp_users == NULL)
-    {
-        return NRF_ERROR_INVALID_STATE;
-    }
-    if (event_handler == NULL)
-    {
-        return NRF_ERROR_INVALID_PARAM;
-    }
-    if (m_user_count >= m_user_array_size)
-    {
-        return NRF_ERROR_NO_MEM;
-    }
-
-    // Allocate new user.
-    mp_users[m_user_count].pins_mask             = pins_low_to_high_mask | pins_high_to_low_mask;
-    mp_users[m_user_count].pins_low_to_high_mask = pins_low_to_high_mask;
-    mp_users[m_user_count].pins_high_to_low_mask = pins_high_to_low_mask;
-    mp_users[m_user_count].event_handler         = event_handler;
-
-    *p_user_id = m_user_count++;
-
-    // Make sure SENSE is disabled for all pins.
-    pins_sense_disable(*p_user_id);
-
-    return NRF_SUCCESS;
-}
-
-
-uint32_t app_gpiote_user_enable(app_gpiote_user_id_t user_id)
-{
-    uint32_t pin_no;
-    uint32_t pins_state;
-
-    // Check state and parameters.
-    if (mp_users == NULL)
-    {
-        return NRF_ERROR_INVALID_STATE;
-    }
-    if (user_id >= m_user_count)
-    {
-        return NRF_ERROR_INVALID_PARAM;
-    }
-
-    // Clear any pending event.
-    NRF_GPIOTE->EVENTS_PORT = 0;
-    pins_state              = NRF_GPIO->IN;
-
-    // Enable user.
-    if (m_enabled_users_mask == 0)
-    {
-        NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_PORT_Msk;
-    }
-    m_enabled_users_mask |= (1 << user_id);
-
-    // Enable sensing for all pins for specified user.
-    mp_users[user_id].sense_high_pins = 0;
-    for (pin_no = 0; pin_no < 32; pin_no++)
-    {
-        uint32_t pin_mask = (1 << pin_no);
-
-        if ((mp_users[user_id].pins_mask & pin_mask) != 0)
-        {
-            uint32_t sense;
-
-            if ((pins_state & pin_mask) != 0)
-            {
-                sense = GPIO_PIN_CNF_SENSE_Low << GPIO_PIN_CNF_SENSE_Pos;
-            }
-            else
-            {
-                sense = GPIO_PIN_CNF_SENSE_High << GPIO_PIN_CNF_SENSE_Pos;
-                mp_users[user_id].sense_high_pins |= pin_mask;
-            }
-
-            NRF_GPIO->PIN_CNF[pin_no] &= ~GPIO_PIN_CNF_SENSE_Msk;
-            NRF_GPIO->PIN_CNF[pin_no] |= sense;
-        }
-    }
-
-    return NRF_SUCCESS;
-}
-
-
-uint32_t app_gpiote_user_disable(app_gpiote_user_id_t user_id)
-{
-    // Check state and parameters.
-    if (mp_users == NULL)
-    {
-        return NRF_ERROR_INVALID_STATE;
-    }
-    if (user_id >= m_user_count)
-    {
-        return NRF_ERROR_INVALID_PARAM;
-    }
-
-    // Disable sensing for all pins for specified user.
-    pins_sense_disable(user_id);
-
-    // Disable user.
-    m_enabled_users_mask &= ~(1UL << user_id);
-    if (m_enabled_users_mask == 0)
-    {
-        NRF_GPIOTE->INTENCLR = GPIOTE_INTENSET_PORT_Msk;
-    }
-
-    return NRF_SUCCESS;
-}
-
-
-uint32_t app_gpiote_pins_state_get(app_gpiote_user_id_t user_id, uint32_t * p_pins)
-{
-    gpiote_user_t * p_user;
-
-    // Check state and parameters.
-    if (mp_users == NULL)
-    {
-        return NRF_ERROR_INVALID_STATE;
-    }
-    if (user_id >= m_user_count)
-    {
-        return NRF_ERROR_INVALID_PARAM;
-    }
-
-    // Get pins.
-    p_user  = &mp_users[user_id];
-    *p_pins = NRF_GPIO->IN & p_user->pins_mask;
-
-    return NRF_SUCCESS;
-}
-
-#if defined(SVCALL_AS_NORMAL_FUNCTION) || defined(SER_CONNECTIVITY)
-uint32_t app_gpiote_input_event_handler_register(const uint8_t                    channel,
-                                                 const uint32_t                   pin,
-                                                 const uint32_t                   polarity,
-                                                 app_gpiote_input_event_handler_t event_handler)
-{
-    (void)sense_level_toggle(NULL, pin);
-    return NRF_ERROR_NOT_SUPPORTED;
-}
-
-uint32_t app_gpiote_input_event_handler_unregister(const uint8_t channel)
-{
-    return NRF_ERROR_NOT_SUPPORTED;
-}
-
-uint32_t app_gpiote_end_irq_event_handler_register(app_gpiote_input_event_handler_t event_handler)
-{
-    return NRF_ERROR_NOT_SUPPORTED;
-}
-
-uint32_t app_gpiote_end_irq_event_handler_unregister(void)
-{
-    return NRF_ERROR_NOT_SUPPORTED;
-}
-
-uint32_t app_gpiote_enable_interrupts(void)
-{
-    return NRF_ERROR_NOT_SUPPORTED;
-}
-
-uint32_t app_gpiote_disable_interrupts(void)
-{
-    return NRF_ERROR_NOT_SUPPORTED;
-}
-#endif // SVCALL_AS_NORMAL_FUNCTION || SER_CONNECTIVITY
\ No newline at end of file
--- a/nordic-sdk/components/libraries/gpiote/app_gpiote.h	Wed Apr 15 09:24:27 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,219 +0,0 @@
-/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
- *
- * The information contained herein is property of Nordic Semiconductor ASA.
- * Terms and conditions of usage are described in detail in NORDIC
- * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
- *
- * Licensees are granted free, non-transferable use of the information. NO
- * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
- * the file.
- *
- */
-
-/** @file
- *
- * @defgroup app_gpiote GPIOTE Handler
- * @{
- * @ingroup app_common
- *
- * @brief GPIOTE handler module.
- *
- * @details The GPIOTE handler allows several modules ("users") to share the GPIOTE interrupt,
- *          each user defining a set of pins able to generate events to the user.
- *          When a GPIOTE interrupt occurs, the GPIOTE interrupt handler will call the event handler
- *          of each user for which at least one of the pins generated an event.
- *
- *          The GPIOTE users are responsible for configuring all their corresponding pins, except
- *          the SENSE field, which should be initialized to GPIO_PIN_CNF_SENSE_Disabled.
- *          The SENSE field will be updated by the GPIOTE module when it is enabled or disabled,
- *          and also while it is enabled.
- *
- *          The module specifies on which pins events should be generated if the pin(s) goes
- *          from low->high or high->low or both directions.
- *
- * @note    Even if the application is using the @ref app_scheduler, the GPIOTE event handlers will
- *          be called directly from the GPIOTE interrupt handler.
- *
- * @warning If multiple users registers for the same pins the behavior for those pins are undefined.
- */
-
-#ifndef APP_GPIOTE_H__
-#define APP_GPIOTE_H__
-
-#include <stdint.h>
-#include <stdbool.h>
-#include "nrf.h"
-#include "app_error.h"
-#include "app_util.h"
-
-#define GPIOTE_USER_NODE_SIZE   20          /**< Size of app_gpiote.gpiote_user_t (only for use inside APP_GPIOTE_BUF_SIZE()). */
-#define NO_OF_PINS              32          /**< Number of GPIO pins on the nRF51 chip. */
-
-/**@brief Compute number of bytes required to hold the GPIOTE data structures.
- *
- * @param[in]   MAX_USERS   Maximum number of GPIOTE users.
- *
- * @return      Required buffer size (in bytes).
- */
-#define APP_GPIOTE_BUF_SIZE(MAX_USERS)  ((MAX_USERS) * GPIOTE_USER_NODE_SIZE)
-
-typedef uint8_t app_gpiote_user_id_t;
-
-/**@brief GPIOTE event handler type. */
-typedef void (*app_gpiote_event_handler_t)(uint32_t event_pins_low_to_high,
-                                           uint32_t event_pins_high_to_low);
-
-/**@brief GPIOTE input event handler type. */
-typedef void (*app_gpiote_input_event_handler_t)(void);
-
-/**@brief Macro for initializing the GPIOTE module.
- *
- * @details It will handle dimensioning and allocation of the memory buffer required by the module,
- *          making sure that the buffer is correctly aligned.
- *
- * @param[in]   MAX_USERS   Maximum number of GPIOTE users.
- *
- * @note Since this macro allocates a buffer, it must only be called once (it is OK to call it
- *       several times as long as it is from the same location, e.g. to do a reinitialization).
- */
-/*lint -emacro(506, APP_GPIOTE_INIT) */ /* Suppress "Constant value Boolean */
-#define APP_GPIOTE_INIT(MAX_USERS)                                                                 \
-    do                                                                                             \
-    {                                                                                              \
-        static uint32_t app_gpiote_buf[CEIL_DIV(APP_GPIOTE_BUF_SIZE(MAX_USERS), sizeof(uint32_t))];\
-        uint32_t ERR_CODE = app_gpiote_init((MAX_USERS), app_gpiote_buf);                          \
-        APP_ERROR_CHECK(ERR_CODE);                                                                 \
-    } while (0)
-
-/**@brief Function for initializing the GPIOTE module.
- *
- * @note Normally initialization should be done using the APP_GPIOTE_INIT() macro, as that will
- *       allocate the buffer needed by the GPIOTE module (including aligning the buffer correctly).
- *
- * @param[in]   max_users               Maximum number of GPIOTE users.
- * @param[in]   p_buffer                Pointer to memory buffer for internal use in the app_gpiote
- *                                      module. The size of the buffer can be computed using the
- *                                      APP_GPIOTE_BUF_SIZE() macro. The buffer must be aligned to 
- *                                      a 4 byte boundary.
- *
- * @retval      NRF_SUCCESS             Successful initialization.
- * @retval      NRF_ERROR_INVALID_PARAM Invalid parameter (buffer not aligned to a 4 byte
- *                                      boundary).
- */
-uint32_t app_gpiote_init(uint8_t max_users, void * p_buffer);
-
-/**@brief Function for registering a GPIOTE user.
- *
- * @param[out]  p_user_id               Id for the new GPIOTE user.
- * @param[in]   pins_low_to_high_mask   Mask defining which pins will generate events to this user 
- *                                      when state is changed from low->high.
- * @param[in]   pins_high_to_low_mask   Mask defining which pins will generate events to this user
- *                                      when state is changed from high->low.
- * @param[in]   event_handler           Pointer to function to be executed when an event occurs.
- *
- * @retval      NRF_SUCCESS             Successful initialization.
- * @retval      NRF_ERROR_INVALID_PARAM Invalid parameter (buffer not aligned to a 4 byte boundary).
- * @retval      NRF_ERROR_INALID_STATE  If @ref app_gpiote_init has not been called on the GPIOTE
- *                                      module.
- * @retval      NRF_ERROR_NO_MEM        Returned if the application tries to register more users
- *                                      than defined when the GPIOTE module was initialized in
- *                                      @ref app_gpiote_init.
- */
-uint32_t app_gpiote_user_register(app_gpiote_user_id_t *     p_user_id,
-                                  uint32_t                   pins_low_to_high_mask,
-                                  uint32_t                   pins_high_to_low_mask,
-                                  app_gpiote_event_handler_t event_handler);
-
-/**@brief Function for informing the GPIOTE module that the specified user wants to use the GPIOTE module.
- *
- * @param[in]   user_id                 Id of user to enable.
- *
- * @retval      NRF_SUCCESS             On success.
- * @retval      NRF_ERROR_INVALID_PARAM Invalid user_id provided, No a valid user.
- * @retval      NRF_ERROR_INALID_STATE  If @ref app_gpiote_init has not been called on the GPIOTE
- *                                      module.
- */
-uint32_t app_gpiote_user_enable(app_gpiote_user_id_t user_id);
-
-/**@brief Function for informing the GPIOTE module that the specified user is done using the GPIOTE module.
- *
- * @param[in]   user_id                   Id of user to enable.
- *
- * @return      NRF_SUCCESS               On success.
- * @retval      NRF_ERROR_INVALID_PARAM   Invalid user_id provided, No a valid user.
- * @retval      NRF_ERROR_INALID_STATE    If @ref app_gpiote_init has not been called on the GPIOTE
- *                                        module.
- */
-uint32_t app_gpiote_user_disable(app_gpiote_user_id_t user_id);
-
-/**@brief Function for getting the state of the pins which are registered for the specified user.
- *
- * @param[in]   user_id         Id of user to check.
- * @param[out]  p_pins          Bit mask corresponding to the pins configured to generate events to
- *                              the specified user. All bits corresponding to pins in the state
- *                              'high' will have value '1', all others will have value '0'.
- *
- * @return      NRF_SUCCESS               On success.
- * @retval      NRF_ERROR_INVALID_PARAM   Invalid user_id provided, No a valid user.
- * @retval      NRF_ERROR_INALID_STATE    If @ref app_gpiote_init has not been called on the GPIOTE
- *                                        module.
- */
-uint32_t app_gpiote_pins_state_get(app_gpiote_user_id_t user_id, uint32_t * p_pins);
-
-/**@brief Function for registering event handlers for GPIOTE IN events.
- *
- * @param[in] channel         GPIOTE channel [0..3].
- * @param[in] pin             Pins associated with GPIOTE channel. Changes on following pins will generate events.
- * @param[in] polarity        Specify operation on input that shall trigger IN event.
- * @param[in] event_handler   Event handler invoked on the IN event in the GPIOTE interrupt.
- *
- * @return   NRF_SUCCESS                 On success.
- * @retval   NRF_ERROR_INVALID_PARAM     Invalid channel or pin number.
- * @retval   NRF_ERROR_NOT_SUPPORTED     Driver doesn't support IN events.
- */
-uint32_t app_gpiote_input_event_handler_register(const uint8_t channel,
-                                                 const uint32_t pin,
-                                                 const uint32_t polarity,
-                                                 app_gpiote_input_event_handler_t event_handler);
-
-/**@brief Function for unregistering event handlers for GPIOTE IN events.
- *
- * @return   NRF_SUCCESS                 On success.
- * @retval   NRF_ERROR_NOT_SUPPORTED     Driver doesn't support IN events.
- */
-uint32_t app_gpiote_input_event_handler_unregister(const uint8_t channel);
-
-/**@brief Function for registering event handler invoked at the end of a GPIOTE interrupt.
- *
- * @param[in] event_handler    Event handler invoked at the end of the GPIOTE interrupt.
- *
- * @return   NRF_SUCCESS                 On success.
- * @retval   NRF_ERROR_NOT_SUPPORTED     Driver doesn't support IN events.
- */
-uint32_t app_gpiote_end_irq_event_handler_register(app_gpiote_input_event_handler_t event_handler);
-
-/**@brief Function for unregistering event handler invoked at the end of a GPIOTE interrupt.
- *
- * @return   NRF_SUCCESS                 On success.
- * @retval   NRF_ERROR_NOT_SUPPORTED     Driver doesn't support IN events.
- */
-uint32_t app_gpiote_end_irq_event_handler_unregister(void);
-
-/**@brief Function for enabling interrupts in the GPIOTE driver.
- *
- * @return   NRF_SUCCESS                 On success.
- * @retval   NRF_ERROR_NOT_SUPPORTED     Driver doesn't support.
- */
-uint32_t app_gpiote_enable_interrupts(void);
-
-/**@brief Function for disabling interrupts in the GPIOTE driver.
- *
- * @return   NRF_SUCCESS                 On success.
- * @retval   NRF_ERROR_NOT_SUPPORTED     Driver doesn't support.
- */
-uint32_t app_gpiote_disable_interrupts(void);
-
-
-#endif // APP_GPIOTE_H__
-
-/** @} */
\ No newline at end of file