Nordic stack and drivers for the mbed BLE API

Fork of nRF51822 by Nordic Semiconductor

Committer:
rgrover1
Date:
Thu Apr 30 08:34:37 2015 +0100
Revision:
112:737b08b3b995
Parent:
103:138bdc859cc9
Synchronized with git rev 4ae92f89
Author: Rohit Grover
porting to v8.0 of the SDK

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rgrover1 103:138bdc859cc9 1 /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
rgrover1 103:138bdc859cc9 2 *
rgrover1 103:138bdc859cc9 3 * The information contained herein is property of Nordic Semiconductor ASA.
rgrover1 103:138bdc859cc9 4 * Terms and conditions of usage are described in detail in NORDIC
rgrover1 103:138bdc859cc9 5 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
rgrover1 103:138bdc859cc9 6 *
rgrover1 103:138bdc859cc9 7 * Licensees are granted free, non-transferable use of the information. NO
rgrover1 103:138bdc859cc9 8 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
rgrover1 103:138bdc859cc9 9 * the file.
rgrover1 103:138bdc859cc9 10 *
rgrover1 103:138bdc859cc9 11 */
rgrover1 103:138bdc859cc9 12
rgrover1 103:138bdc859cc9 13 /** @file
rgrover1 103:138bdc859cc9 14 *
rgrover1 103:138bdc859cc9 15 * @defgroup app_gpiote GPIOTE Handler
rgrover1 103:138bdc859cc9 16 * @{
rgrover1 103:138bdc859cc9 17 * @ingroup app_common
rgrover1 103:138bdc859cc9 18 *
rgrover1 103:138bdc859cc9 19 * @brief GPIOTE handler module.
rgrover1 103:138bdc859cc9 20 *
rgrover1 103:138bdc859cc9 21 * @details The GPIOTE handler allows several modules ("users") to share the GPIOTE interrupt,
rgrover1 103:138bdc859cc9 22 * each user defining a set of pins able to generate events to the user.
rgrover1 103:138bdc859cc9 23 * When a GPIOTE interrupt occurs, the GPIOTE interrupt handler will call the event handler
rgrover1 103:138bdc859cc9 24 * of each user for which at least one of the pins generated an event.
rgrover1 103:138bdc859cc9 25 *
rgrover1 103:138bdc859cc9 26 * The GPIOTE users are responsible for configuring all their corresponding pins, except
rgrover1 103:138bdc859cc9 27 * the SENSE field, which should be initialized to GPIO_PIN_CNF_SENSE_Disabled.
rgrover1 103:138bdc859cc9 28 * The SENSE field will be updated by the GPIOTE module when it is enabled or disabled,
rgrover1 103:138bdc859cc9 29 * and also while it is enabled.
rgrover1 103:138bdc859cc9 30 *
rgrover1 103:138bdc859cc9 31 * The module specifies on which pins events should be generated if the pin(s) goes
rgrover1 103:138bdc859cc9 32 * from low->high or high->low or both directions.
rgrover1 103:138bdc859cc9 33 *
rgrover1 103:138bdc859cc9 34 * @note Even if the application is using the @ref app_scheduler, the GPIOTE event handlers will
rgrover1 103:138bdc859cc9 35 * be called directly from the GPIOTE interrupt handler.
rgrover1 103:138bdc859cc9 36 *
rgrover1 103:138bdc859cc9 37 * @warning If multiple users registers for the same pins the behavior for those pins are undefined.
rgrover1 103:138bdc859cc9 38 */
rgrover1 103:138bdc859cc9 39
rgrover1 103:138bdc859cc9 40 #ifndef APP_GPIOTE_H__
rgrover1 103:138bdc859cc9 41 #define APP_GPIOTE_H__
rgrover1 103:138bdc859cc9 42
rgrover1 103:138bdc859cc9 43 #include <stdint.h>
rgrover1 103:138bdc859cc9 44 #include <stdbool.h>
rgrover1 103:138bdc859cc9 45 #include "nrf.h"
rgrover1 103:138bdc859cc9 46 #include "app_error.h"
rgrover1 103:138bdc859cc9 47 #include "app_util.h"
rgrover1 103:138bdc859cc9 48
rgrover1 103:138bdc859cc9 49 #define GPIOTE_USER_NODE_SIZE 20 /**< Size of app_gpiote.gpiote_user_t (only for use inside APP_GPIOTE_BUF_SIZE()). */
rgrover1 103:138bdc859cc9 50 #define NO_OF_PINS 32 /**< Number of GPIO pins on the nRF51 chip. */
rgrover1 103:138bdc859cc9 51
rgrover1 103:138bdc859cc9 52 /**@brief Compute number of bytes required to hold the GPIOTE data structures.
rgrover1 103:138bdc859cc9 53 *
rgrover1 103:138bdc859cc9 54 * @param[in] MAX_USERS Maximum number of GPIOTE users.
rgrover1 103:138bdc859cc9 55 *
rgrover1 112:737b08b3b995 56 * @retval Required buffer size (in bytes).
rgrover1 103:138bdc859cc9 57 */
rgrover1 103:138bdc859cc9 58 #define APP_GPIOTE_BUF_SIZE(MAX_USERS) ((MAX_USERS) * GPIOTE_USER_NODE_SIZE)
rgrover1 103:138bdc859cc9 59
rgrover1 103:138bdc859cc9 60 typedef uint8_t app_gpiote_user_id_t;
rgrover1 103:138bdc859cc9 61
rgrover1 103:138bdc859cc9 62 /**@brief GPIOTE event handler type. */
rgrover1 103:138bdc859cc9 63 typedef void (*app_gpiote_event_handler_t)(uint32_t event_pins_low_to_high,
rgrover1 103:138bdc859cc9 64 uint32_t event_pins_high_to_low);
rgrover1 103:138bdc859cc9 65
rgrover1 103:138bdc859cc9 66 /**@brief GPIOTE input event handler type. */
rgrover1 103:138bdc859cc9 67 typedef void (*app_gpiote_input_event_handler_t)(void);
rgrover1 103:138bdc859cc9 68
rgrover1 103:138bdc859cc9 69 /**@brief Macro for initializing the GPIOTE module.
rgrover1 103:138bdc859cc9 70 *
rgrover1 103:138bdc859cc9 71 * @details It will handle dimensioning and allocation of the memory buffer required by the module,
rgrover1 103:138bdc859cc9 72 * making sure that the buffer is correctly aligned.
rgrover1 103:138bdc859cc9 73 *
rgrover1 103:138bdc859cc9 74 * @param[in] MAX_USERS Maximum number of GPIOTE users.
rgrover1 103:138bdc859cc9 75 *
rgrover1 103:138bdc859cc9 76 * @note Since this macro allocates a buffer, it must only be called once (it is OK to call it
rgrover1 103:138bdc859cc9 77 * several times as long as it is from the same location, e.g. to do a reinitialization).
rgrover1 103:138bdc859cc9 78 */
rgrover1 103:138bdc859cc9 79 /*lint -emacro(506, APP_GPIOTE_INIT) */ /* Suppress "Constant value Boolean */
rgrover1 103:138bdc859cc9 80 #define APP_GPIOTE_INIT(MAX_USERS) \
rgrover1 103:138bdc859cc9 81 do \
rgrover1 103:138bdc859cc9 82 { \
rgrover1 103:138bdc859cc9 83 static uint32_t app_gpiote_buf[CEIL_DIV(APP_GPIOTE_BUF_SIZE(MAX_USERS), sizeof(uint32_t))];\
rgrover1 103:138bdc859cc9 84 uint32_t ERR_CODE = app_gpiote_init((MAX_USERS), app_gpiote_buf); \
rgrover1 103:138bdc859cc9 85 APP_ERROR_CHECK(ERR_CODE); \
rgrover1 103:138bdc859cc9 86 } while (0)
rgrover1 103:138bdc859cc9 87
rgrover1 103:138bdc859cc9 88 /**@brief Function for initializing the GPIOTE module.
rgrover1 103:138bdc859cc9 89 *
rgrover1 103:138bdc859cc9 90 * @note Normally initialization should be done using the APP_GPIOTE_INIT() macro, as that will
rgrover1 103:138bdc859cc9 91 * allocate the buffer needed by the GPIOTE module (including aligning the buffer correctly).
rgrover1 103:138bdc859cc9 92 *
rgrover1 103:138bdc859cc9 93 * @param[in] max_users Maximum number of GPIOTE users.
rgrover1 103:138bdc859cc9 94 * @param[in] p_buffer Pointer to memory buffer for internal use in the app_gpiote
rgrover1 103:138bdc859cc9 95 * module. The size of the buffer can be computed using the
rgrover1 103:138bdc859cc9 96 * APP_GPIOTE_BUF_SIZE() macro. The buffer must be aligned to
rgrover1 103:138bdc859cc9 97 * a 4 byte boundary.
rgrover1 103:138bdc859cc9 98 *
rgrover1 103:138bdc859cc9 99 * @retval NRF_SUCCESS Successful initialization.
rgrover1 103:138bdc859cc9 100 * @retval NRF_ERROR_INVALID_PARAM Invalid parameter (buffer not aligned to a 4 byte
rgrover1 103:138bdc859cc9 101 * boundary).
rgrover1 103:138bdc859cc9 102 */
rgrover1 103:138bdc859cc9 103 uint32_t app_gpiote_init(uint8_t max_users, void * p_buffer);
rgrover1 103:138bdc859cc9 104
rgrover1 103:138bdc859cc9 105 /**@brief Function for registering a GPIOTE user.
rgrover1 103:138bdc859cc9 106 *
rgrover1 103:138bdc859cc9 107 * @param[out] p_user_id Id for the new GPIOTE user.
rgrover1 103:138bdc859cc9 108 * @param[in] pins_low_to_high_mask Mask defining which pins will generate events to this user
rgrover1 103:138bdc859cc9 109 * when state is changed from low->high.
rgrover1 103:138bdc859cc9 110 * @param[in] pins_high_to_low_mask Mask defining which pins will generate events to this user
rgrover1 103:138bdc859cc9 111 * when state is changed from high->low.
rgrover1 103:138bdc859cc9 112 * @param[in] event_handler Pointer to function to be executed when an event occurs.
rgrover1 103:138bdc859cc9 113 *
rgrover1 103:138bdc859cc9 114 * @retval NRF_SUCCESS Successful initialization.
rgrover1 103:138bdc859cc9 115 * @retval NRF_ERROR_INVALID_PARAM Invalid parameter (buffer not aligned to a 4 byte boundary).
rgrover1 103:138bdc859cc9 116 * @retval NRF_ERROR_INALID_STATE If @ref app_gpiote_init has not been called on the GPIOTE
rgrover1 103:138bdc859cc9 117 * module.
rgrover1 103:138bdc859cc9 118 * @retval NRF_ERROR_NO_MEM Returned if the application tries to register more users
rgrover1 103:138bdc859cc9 119 * than defined when the GPIOTE module was initialized in
rgrover1 103:138bdc859cc9 120 * @ref app_gpiote_init.
rgrover1 103:138bdc859cc9 121 */
rgrover1 103:138bdc859cc9 122 uint32_t app_gpiote_user_register(app_gpiote_user_id_t * p_user_id,
rgrover1 103:138bdc859cc9 123 uint32_t pins_low_to_high_mask,
rgrover1 103:138bdc859cc9 124 uint32_t pins_high_to_low_mask,
rgrover1 103:138bdc859cc9 125 app_gpiote_event_handler_t event_handler);
rgrover1 103:138bdc859cc9 126
rgrover1 103:138bdc859cc9 127 /**@brief Function for informing the GPIOTE module that the specified user wants to use the GPIOTE module.
rgrover1 103:138bdc859cc9 128 *
rgrover1 103:138bdc859cc9 129 * @param[in] user_id Id of user to enable.
rgrover1 103:138bdc859cc9 130 *
rgrover1 103:138bdc859cc9 131 * @retval NRF_SUCCESS On success.
rgrover1 103:138bdc859cc9 132 * @retval NRF_ERROR_INVALID_PARAM Invalid user_id provided, No a valid user.
rgrover1 103:138bdc859cc9 133 * @retval NRF_ERROR_INALID_STATE If @ref app_gpiote_init has not been called on the GPIOTE
rgrover1 103:138bdc859cc9 134 * module.
rgrover1 103:138bdc859cc9 135 */
rgrover1 103:138bdc859cc9 136 uint32_t app_gpiote_user_enable(app_gpiote_user_id_t user_id);
rgrover1 103:138bdc859cc9 137
rgrover1 103:138bdc859cc9 138 /**@brief Function for informing the GPIOTE module that the specified user is done using the GPIOTE module.
rgrover1 103:138bdc859cc9 139 *
rgrover1 103:138bdc859cc9 140 * @param[in] user_id Id of user to enable.
rgrover1 103:138bdc859cc9 141 *
rgrover1 112:737b08b3b995 142 * @retval NRF_SUCCESS On success.
rgrover1 103:138bdc859cc9 143 * @retval NRF_ERROR_INVALID_PARAM Invalid user_id provided, No a valid user.
rgrover1 103:138bdc859cc9 144 * @retval NRF_ERROR_INALID_STATE If @ref app_gpiote_init has not been called on the GPIOTE
rgrover1 103:138bdc859cc9 145 * module.
rgrover1 103:138bdc859cc9 146 */
rgrover1 103:138bdc859cc9 147 uint32_t app_gpiote_user_disable(app_gpiote_user_id_t user_id);
rgrover1 103:138bdc859cc9 148
rgrover1 103:138bdc859cc9 149 /**@brief Function for getting the state of the pins which are registered for the specified user.
rgrover1 103:138bdc859cc9 150 *
rgrover1 103:138bdc859cc9 151 * @param[in] user_id Id of user to check.
rgrover1 103:138bdc859cc9 152 * @param[out] p_pins Bit mask corresponding to the pins configured to generate events to
rgrover1 103:138bdc859cc9 153 * the specified user. All bits corresponding to pins in the state
rgrover1 103:138bdc859cc9 154 * 'high' will have value '1', all others will have value '0'.
rgrover1 103:138bdc859cc9 155 *
rgrover1 112:737b08b3b995 156 * @retval NRF_SUCCESS On success.
rgrover1 103:138bdc859cc9 157 * @retval NRF_ERROR_INVALID_PARAM Invalid user_id provided, No a valid user.
rgrover1 103:138bdc859cc9 158 * @retval NRF_ERROR_INALID_STATE If @ref app_gpiote_init has not been called on the GPIOTE
rgrover1 103:138bdc859cc9 159 * module.
rgrover1 103:138bdc859cc9 160 */
rgrover1 103:138bdc859cc9 161 uint32_t app_gpiote_pins_state_get(app_gpiote_user_id_t user_id, uint32_t * p_pins);
rgrover1 103:138bdc859cc9 162
rgrover1 103:138bdc859cc9 163 /**@brief Function for registering event handlers for GPIOTE IN events.
rgrover1 103:138bdc859cc9 164 *
rgrover1 103:138bdc859cc9 165 * @param[in] channel GPIOTE channel [0..3].
rgrover1 103:138bdc859cc9 166 * @param[in] pin Pins associated with GPIOTE channel. Changes on following pins will generate events.
rgrover1 103:138bdc859cc9 167 * @param[in] polarity Specify operation on input that shall trigger IN event.
rgrover1 103:138bdc859cc9 168 * @param[in] event_handler Event handler invoked on the IN event in the GPIOTE interrupt.
rgrover1 103:138bdc859cc9 169 *
rgrover1 112:737b08b3b995 170 * @retval NRF_SUCCESS On success.
rgrover1 103:138bdc859cc9 171 * @retval NRF_ERROR_INVALID_PARAM Invalid channel or pin number.
rgrover1 103:138bdc859cc9 172 * @retval NRF_ERROR_NOT_SUPPORTED Driver doesn't support IN events.
rgrover1 103:138bdc859cc9 173 */
rgrover1 103:138bdc859cc9 174 uint32_t app_gpiote_input_event_handler_register(const uint8_t channel,
rgrover1 103:138bdc859cc9 175 const uint32_t pin,
rgrover1 103:138bdc859cc9 176 const uint32_t polarity,
rgrover1 103:138bdc859cc9 177 app_gpiote_input_event_handler_t event_handler);
rgrover1 103:138bdc859cc9 178
rgrover1 103:138bdc859cc9 179 /**@brief Function for unregistering event handlers for GPIOTE IN events.
rgrover1 103:138bdc859cc9 180 *
rgrover1 112:737b08b3b995 181 * @retval NRF_SUCCESS On success.
rgrover1 103:138bdc859cc9 182 * @retval NRF_ERROR_NOT_SUPPORTED Driver doesn't support IN events.
rgrover1 103:138bdc859cc9 183 */
rgrover1 103:138bdc859cc9 184 uint32_t app_gpiote_input_event_handler_unregister(const uint8_t channel);
rgrover1 103:138bdc859cc9 185
rgrover1 103:138bdc859cc9 186 /**@brief Function for registering event handler invoked at the end of a GPIOTE interrupt.
rgrover1 103:138bdc859cc9 187 *
rgrover1 103:138bdc859cc9 188 * @param[in] event_handler Event handler invoked at the end of the GPIOTE interrupt.
rgrover1 103:138bdc859cc9 189 *
rgrover1 112:737b08b3b995 190 * @retval NRF_SUCCESS On success.
rgrover1 103:138bdc859cc9 191 * @retval NRF_ERROR_NOT_SUPPORTED Driver doesn't support IN events.
rgrover1 103:138bdc859cc9 192 */
rgrover1 103:138bdc859cc9 193 uint32_t app_gpiote_end_irq_event_handler_register(app_gpiote_input_event_handler_t event_handler);
rgrover1 103:138bdc859cc9 194
rgrover1 103:138bdc859cc9 195 /**@brief Function for unregistering event handler invoked at the end of a GPIOTE interrupt.
rgrover1 103:138bdc859cc9 196 *
rgrover1 112:737b08b3b995 197 * @retval NRF_SUCCESS On success.
rgrover1 103:138bdc859cc9 198 * @retval NRF_ERROR_NOT_SUPPORTED Driver doesn't support IN events.
rgrover1 103:138bdc859cc9 199 */
rgrover1 103:138bdc859cc9 200 uint32_t app_gpiote_end_irq_event_handler_unregister(void);
rgrover1 103:138bdc859cc9 201
rgrover1 103:138bdc859cc9 202 /**@brief Function for enabling interrupts in the GPIOTE driver.
rgrover1 103:138bdc859cc9 203 *
rgrover1 112:737b08b3b995 204 * @retval NRF_SUCCESS On success.
rgrover1 103:138bdc859cc9 205 * @retval NRF_ERROR_NOT_SUPPORTED Driver doesn't support.
rgrover1 103:138bdc859cc9 206 */
rgrover1 103:138bdc859cc9 207 uint32_t app_gpiote_enable_interrupts(void);
rgrover1 103:138bdc859cc9 208
rgrover1 103:138bdc859cc9 209 /**@brief Function for disabling interrupts in the GPIOTE driver.
rgrover1 103:138bdc859cc9 210 *
rgrover1 112:737b08b3b995 211 * @retval NRF_SUCCESS On success.
rgrover1 103:138bdc859cc9 212 * @retval NRF_ERROR_NOT_SUPPORTED Driver doesn't support.
rgrover1 103:138bdc859cc9 213 */
rgrover1 103:138bdc859cc9 214 uint32_t app_gpiote_disable_interrupts(void);
rgrover1 103:138bdc859cc9 215
rgrover1 103:138bdc859cc9 216
rgrover1 103:138bdc859cc9 217 #endif // APP_GPIOTE_H__
rgrover1 103:138bdc859cc9 218
rgrover1 103:138bdc859cc9 219 /** @} */