test
Fork of nrf51-sdk by
Embed:
(wiki syntax)
Show/hide line numbers
ble_radio_notification.c
00001 /* 00002 * Copyright (c) Nordic Semiconductor ASA 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without modification, 00006 * are permitted provided that the following conditions are met: 00007 * 00008 * 1. Redistributions of source code must retain the above copyright notice, this 00009 * list of conditions and the following disclaimer. 00010 * 00011 * 2. Redistributions in binary form must reproduce the above copyright notice, this 00012 * list of conditions and the following disclaimer in the documentation and/or 00013 * other materials provided with the distribution. 00014 * 00015 * 3. Neither the name of Nordic Semiconductor ASA nor the names of other 00016 * contributors to this software may be used to endorse or promote products 00017 * derived from this software without specific prior written permission. 00018 * 00019 * 00020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00021 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00022 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00023 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 00024 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00025 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00026 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 00027 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00028 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00029 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 * 00031 */ 00032 00033 #include "ble_radio_notification.h " 00034 #include <stdlib.h> 00035 00036 00037 static bool m_radio_active = false; /**< Current radio state. */ 00038 static ble_radio_notification_evt_handler_t m_evt_handler = NULL; /**< Application event handler for handling Radio Notification events. */ 00039 00040 00041 void SWI1_IRQHandler(void) 00042 { 00043 m_radio_active = !m_radio_active; 00044 if (m_evt_handler != NULL) 00045 { 00046 m_evt_handler(m_radio_active); 00047 } 00048 } 00049 00050 00051 uint32_t ble_radio_notification_init(nrf_app_irq_priority_t irq_priority, 00052 nrf_radio_notification_distance_t distance, 00053 ble_radio_notification_evt_handler_t evt_handler) 00054 { 00055 uint32_t err_code; 00056 00057 m_evt_handler = evt_handler; 00058 00059 // Initialize Radio Notification software interrupt 00060 err_code = sd_nvic_ClearPendingIRQ(SWI1_IRQn); 00061 if (err_code != NRF_SUCCESS) 00062 { 00063 return err_code; 00064 } 00065 00066 err_code = sd_nvic_SetPriority(SWI1_IRQn, irq_priority); 00067 if (err_code != NRF_SUCCESS) 00068 { 00069 return err_code; 00070 } 00071 00072 err_code = sd_nvic_EnableIRQ(SWI1_IRQn); 00073 if (err_code != NRF_SUCCESS) 00074 { 00075 return err_code; 00076 } 00077 00078 // Configure the event 00079 return sd_radio_notification_cfg_set(NRF_RADIO_NOTIFICATION_TYPE_INT_ON_BOTH, distance); 00080 }
Generated on Tue Jul 12 2022 15:51:26 by 1.7.2