Patched version of nrf51822 FOTA compatible driver, with GPTIO disabled, as it clashed with the mbed definitions...

Fork of nRF51822 by Nordic Semiconductor

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ble_radio_notification.c Source File

ble_radio_notification.c

00001 /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
00002  *
00003  * The information contained herein is property of Nordic Semiconductor ASA.
00004  * Terms and conditions of usage are described in detail in NORDIC
00005  * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
00006  *
00007  * Licensees are granted free, non-transferable use of the information. NO
00008  * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
00009  * the file.
00010  */
00011 
00012 #include "ble_radio_notification.h "
00013 #include <stdlib.h>
00014 
00015 
00016 static bool                                 m_radio_active = false;  /**< Current radio state. */
00017 static ble_radio_notification_evt_handler_t m_evt_handler  = NULL;   /**< Application event handler for handling Radio Notification events. */
00018 
00019 
00020 void SWI1_IRQHandler(void)
00021 {
00022     m_radio_active = !m_radio_active;
00023     if (m_evt_handler != NULL)
00024     {
00025         m_evt_handler(m_radio_active);
00026     }
00027 }
00028 
00029 
00030 uint32_t ble_radio_notification_init(nrf_app_irq_priority_t               irq_priority,
00031                                      nrf_radio_notification_distance_t    distance,
00032                                      ble_radio_notification_evt_handler_t evt_handler)
00033 {
00034     uint32_t err_code;
00035 
00036     m_evt_handler = evt_handler;
00037 
00038     // Initialize Radio Notification software interrupt
00039     err_code = sd_nvic_ClearPendingIRQ(SWI1_IRQn );
00040     if (err_code != NRF_SUCCESS)
00041     {
00042         return err_code;
00043     }
00044 
00045     err_code = sd_nvic_SetPriority(SWI1_IRQn , irq_priority);
00046     if (err_code != NRF_SUCCESS)
00047     {
00048         return err_code;
00049     }
00050 
00051     err_code = sd_nvic_EnableIRQ(SWI1_IRQn );
00052     if (err_code != NRF_SUCCESS)
00053     {
00054         return err_code;
00055     }
00056 
00057     // Configure the event
00058     return sd_radio_notification_cfg_set(NRF_RADIO_NOTIFICATION_TYPE_INT_ON_BOTH, distance);
00059 }