テスト用

Fork of nRF51822 by Nordic Semiconductor

Committer:
Rohit Grover
Date:
Fri Jul 11 13:52:58 2014 +0100
Revision:
43:e1d294ed29c4
Parent:
37:c29c330d942c
Child:
45:3c4df37ed83e
no need to include nrf.h

Who changed what in which revision?

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