Nordic Semiconductor / nrf51-sdk

Dependents:   nRF51822 nRF51822

Committer:
vcoubard
Date:
Mon Apr 11 16:13:57 2016 +0000
Revision:
45:4a80ff6428ab
Parent:
29:286940b7ee5a
Thanks to web-ide, it is not possible to add files to .hgignore.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vcoubard 29:286940b7ee5a 1 /*
vcoubard 29:286940b7ee5a 2 * Copyright (c) Nordic Semiconductor ASA
vcoubard 29:286940b7ee5a 3 * All rights reserved.
vcoubard 29:286940b7ee5a 4 *
vcoubard 29:286940b7ee5a 5 * Redistribution and use in source and binary forms, with or without modification,
vcoubard 29:286940b7ee5a 6 * are permitted provided that the following conditions are met:
vcoubard 29:286940b7ee5a 7 *
vcoubard 29:286940b7ee5a 8 * 1. Redistributions of source code must retain the above copyright notice, this
vcoubard 29:286940b7ee5a 9 * list of conditions and the following disclaimer.
vcoubard 29:286940b7ee5a 10 *
vcoubard 29:286940b7ee5a 11 * 2. Redistributions in binary form must reproduce the above copyright notice, this
vcoubard 29:286940b7ee5a 12 * list of conditions and the following disclaimer in the documentation and/or
vcoubard 29:286940b7ee5a 13 * other materials provided with the distribution.
vcoubard 29:286940b7ee5a 14 *
vcoubard 29:286940b7ee5a 15 * 3. Neither the name of Nordic Semiconductor ASA nor the names of other
vcoubard 29:286940b7ee5a 16 * contributors to this software may be used to endorse or promote products
vcoubard 29:286940b7ee5a 17 * derived from this software without specific prior written permission.
vcoubard 29:286940b7ee5a 18 *
vcoubard 29:286940b7ee5a 19 *
vcoubard 29:286940b7ee5a 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
vcoubard 29:286940b7ee5a 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
vcoubard 29:286940b7ee5a 22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
vcoubard 29:286940b7ee5a 23 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
vcoubard 29:286940b7ee5a 24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
vcoubard 29:286940b7ee5a 25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
vcoubard 29:286940b7ee5a 26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
vcoubard 29:286940b7ee5a 27 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
vcoubard 29:286940b7ee5a 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
vcoubard 29:286940b7ee5a 29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
vcoubard 29:286940b7ee5a 30 *
Vincent Coubard 0:f2542974c862 31 */
Vincent Coubard 0:f2542974c862 32
Vincent Coubard 0:f2542974c862 33 #include "ble_radio_notification.h"
Vincent Coubard 0:f2542974c862 34 #include <stdlib.h>
Vincent Coubard 0:f2542974c862 35
Vincent Coubard 0:f2542974c862 36
Vincent Coubard 0:f2542974c862 37 static bool m_radio_active = false; /**< Current radio state. */
Vincent Coubard 0:f2542974c862 38 static ble_radio_notification_evt_handler_t m_evt_handler = NULL; /**< Application event handler for handling Radio Notification events. */
Vincent Coubard 0:f2542974c862 39
Vincent Coubard 0:f2542974c862 40
Vincent Coubard 0:f2542974c862 41 void SWI1_IRQHandler(void)
Vincent Coubard 0:f2542974c862 42 {
Vincent Coubard 0:f2542974c862 43 m_radio_active = !m_radio_active;
Vincent Coubard 0:f2542974c862 44 if (m_evt_handler != NULL)
Vincent Coubard 0:f2542974c862 45 {
Vincent Coubard 0:f2542974c862 46 m_evt_handler(m_radio_active);
Vincent Coubard 0:f2542974c862 47 }
Vincent Coubard 0:f2542974c862 48 }
Vincent Coubard 0:f2542974c862 49
Vincent Coubard 0:f2542974c862 50
Vincent Coubard 0:f2542974c862 51 uint32_t ble_radio_notification_init(nrf_app_irq_priority_t irq_priority,
Vincent Coubard 0:f2542974c862 52 nrf_radio_notification_distance_t distance,
Vincent Coubard 0:f2542974c862 53 ble_radio_notification_evt_handler_t evt_handler)
Vincent Coubard 0:f2542974c862 54 {
Vincent Coubard 0:f2542974c862 55 uint32_t err_code;
Vincent Coubard 0:f2542974c862 56
Vincent Coubard 0:f2542974c862 57 m_evt_handler = evt_handler;
Vincent Coubard 0:f2542974c862 58
Vincent Coubard 0:f2542974c862 59 // Initialize Radio Notification software interrupt
Vincent Coubard 0:f2542974c862 60 err_code = sd_nvic_ClearPendingIRQ(SWI1_IRQn);
Vincent Coubard 0:f2542974c862 61 if (err_code != NRF_SUCCESS)
Vincent Coubard 0:f2542974c862 62 {
Vincent Coubard 0:f2542974c862 63 return err_code;
Vincent Coubard 0:f2542974c862 64 }
Vincent Coubard 0:f2542974c862 65
Vincent Coubard 0:f2542974c862 66 err_code = sd_nvic_SetPriority(SWI1_IRQn, irq_priority);
Vincent Coubard 0:f2542974c862 67 if (err_code != NRF_SUCCESS)
Vincent Coubard 0:f2542974c862 68 {
Vincent Coubard 0:f2542974c862 69 return err_code;
Vincent Coubard 0:f2542974c862 70 }
Vincent Coubard 0:f2542974c862 71
Vincent Coubard 0:f2542974c862 72 err_code = sd_nvic_EnableIRQ(SWI1_IRQn);
Vincent Coubard 0:f2542974c862 73 if (err_code != NRF_SUCCESS)
Vincent Coubard 0:f2542974c862 74 {
Vincent Coubard 0:f2542974c862 75 return err_code;
Vincent Coubard 0:f2542974c862 76 }
Vincent Coubard 0:f2542974c862 77
Vincent Coubard 0:f2542974c862 78 // Configure the event
Vincent Coubard 0:f2542974c862 79 return sd_radio_notification_cfg_set(NRF_RADIO_NOTIFICATION_TYPE_INT_ON_BOTH, distance);
vcoubard 1:ebc0e0ef0a11 80 }