diff --git a/module.json b/module.json index 8765bd6..25a15e8 100644 --- a/module.json +++ b/module.json @@ -22,24 +22,27 @@ } }, "extraIncludes": [ - "source/nordic_sdk/components", - "source/nordic_sdk/components/libraries/util", - "source/nordic_sdk/components/libraries/hci", - "source/nordic_sdk/components/libraries/bootloader_dfu", - "source/nordic_sdk/components/libraries/bootloader_dfu/hci_transport", - "source/nordic_sdk/components/libraries/bootloader_dfu/experimental", - "source/nordic_sdk/components/libraries/scheduler", - "source/nordic_sdk/components/libraries/crc16", - "source/nordic_sdk/components/softdevice/s130/include", - "source/nordic_sdk/components/softdevice/common/softdevice_handler", - "source/nordic_sdk/components/drivers_nrf/hal", - "source/nordic_sdk/components/drivers_nrf/ble_flash", - "source/nordic_sdk/components/drivers_nrf/pstorage", - "source/nordic_sdk/components/drivers_nrf/pstorage/config", "source/nordic_sdk/components/ble/ble_radio_notification", "source/nordic_sdk/components/ble/ble_services/ble_dfu", "source/nordic_sdk/components/ble/common", "source/nordic_sdk/components/ble/device_manager", - "source/nordic_sdk/components/ble/device_manager/config" + "source/nordic_sdk/components/ble/device_manager/config", + "source/nordic_sdk/components/device", + "source/nordic_sdk/components/drivers_nrf/ble_flash", + "source/nordic_sdk/components/drivers_nrf/hal", + "source/nordic_sdk/components/drivers_nrf/pstorage", + "source/nordic_sdk/components/drivers_nrf/pstorage/config", + "source/nordic_sdk/components/libraries/bootloader_dfu", + "source/nordic_sdk/components/libraries/bootloader_dfu/hci_transport", + "source/nordic_sdk/components/libraries/crc16", + "source/nordic_sdk/components/libraries/hci", + "source/nordic_sdk/components/libraries/scheduler", + "source/nordic_sdk/components/libraries/timer", + "source/nordic_sdk/components/libraries/trace", + "source/nordic_sdk/components/libraries/util", + "source/nordic_sdk/components/softdevice/common/softdevice_handler", + "source/nordic_sdk/components/softdevice/s130/headers", + "source/nordic_sdk/components/toolchain", + "source/nordic_sdk/components/toolchain/gcc" ] } diff --git a/source/nordic_sdk/components/ble/ble_radio_notification/ble_radio_notification.c b/source/nordic_sdk/components/ble/ble_radio_notification/ble_radio_notification.c index 372de3d..014c6f2 100644 --- a/source/nordic_sdk/components/ble/ble_radio_notification/ble_radio_notification.c +++ b/source/nordic_sdk/components/ble/ble_radio_notification/ble_radio_notification.c @@ -1,80 +1,59 @@ -/* - * Copyright (c) Nordic Semiconductor ASA - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this - * list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of other - * contributors to this software may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "ble_radio_notification.h" -#include - - -static bool m_radio_active = false; /**< Current radio state. */ -static ble_radio_notification_evt_handler_t m_evt_handler = NULL; /**< Application event handler for handling Radio Notification events. */ - - -void SWI1_IRQHandler(void) -{ - m_radio_active = !m_radio_active; - if (m_evt_handler != NULL) - { - m_evt_handler(m_radio_active); - } -} - - -uint32_t ble_radio_notification_init(nrf_app_irq_priority_t irq_priority, - nrf_radio_notification_distance_t distance, - ble_radio_notification_evt_handler_t evt_handler) -{ - uint32_t err_code; - - m_evt_handler = evt_handler; - - // Initialize Radio Notification software interrupt - err_code = sd_nvic_ClearPendingIRQ(SWI1_IRQn); - if (err_code != NRF_SUCCESS) - { - return err_code; - } - - err_code = sd_nvic_SetPriority(SWI1_IRQn, irq_priority); - if (err_code != NRF_SUCCESS) - { - return err_code; - } - - err_code = sd_nvic_EnableIRQ(SWI1_IRQn); - if (err_code != NRF_SUCCESS) - { - return err_code; - } - - // Configure the event - return sd_radio_notification_cfg_set(NRF_RADIO_NOTIFICATION_TYPE_INT_ON_BOTH, distance); -} +/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. + * + * The information contained herein is property of Nordic Semiconductor ASA. + * Terms and conditions of usage are described in detail in NORDIC + * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. + * + * Licensees are granted free, non-transferable use of the information. NO + * WARRANTY of ANY KIND is provided. This heading must NOT be removed from + * the file. + */ + +#include "ble_radio_notification.h" +#include + + +static bool m_radio_active = false; /**< Current radio state. */ +static ble_radio_notification_evt_handler_t m_evt_handler = NULL; /**< Application event handler for handling Radio Notification events. */ + + +void SWI1_IRQHandler(void) +{ + m_radio_active = !m_radio_active; + if (m_evt_handler != NULL) + { + m_evt_handler(m_radio_active); + } +} + + +uint32_t ble_radio_notification_init(nrf_app_irq_priority_t irq_priority, + nrf_radio_notification_distance_t distance, + ble_radio_notification_evt_handler_t evt_handler) +{ + uint32_t err_code; + + m_evt_handler = evt_handler; + + // Initialize Radio Notification software interrupt + err_code = sd_nvic_ClearPendingIRQ(SWI1_IRQn); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + + err_code = sd_nvic_SetPriority(SWI1_IRQn, irq_priority); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + + err_code = sd_nvic_EnableIRQ(SWI1_IRQn); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + + // Configure the event + return sd_radio_notification_cfg_set(NRF_RADIO_NOTIFICATION_TYPE_INT_ON_BOTH, distance); +} diff --git a/source/nordic_sdk/components/ble/ble_radio_notification/ble_radio_notification.h b/source/nordic_sdk/components/ble/ble_radio_notification/ble_radio_notification.h index 2117432..2b11ada 100644 --- a/source/nordic_sdk/components/ble/ble_radio_notification/ble_radio_notification.h +++ b/source/nordic_sdk/components/ble/ble_radio_notification/ble_radio_notification.h @@ -1,74 +1,45 @@ -/* - * Copyright (c) Nordic Semiconductor ASA - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this - * list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of other - * contributors to this software may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -/** @file - * - * @defgroup ble_radio_notification Radio Notification Event Handler - * @{ - * @ingroup ble_sdk_lib - * @brief Module for propagating Radio Notification events to the application. - */ - -#ifndef BLE_RADIO_NOTIFICATION_H__ -#define BLE_RADIO_NOTIFICATION_H__ - -#include -#include -#include "nrf_soc.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/**@brief Application radio notification event handler type. */ -typedef void (*ble_radio_notification_evt_handler_t) (bool radio_active); - -/**@brief Function for initializing the Radio Notification module. - * - * @param[in] irq_priority Interrupt priority for the Radio Notification interrupt handler. - * @param[in] distance The time from an Active event until the radio is activated. - * @param[in] evt_handler Handler to be executed when a radio notification event has been - * received. - * - * @return NRF_SUCCESS on successful initialization, otherwise an error code. - */ -uint32_t ble_radio_notification_init(nrf_app_irq_priority_t irq_priority, - nrf_radio_notification_distance_t distance, - ble_radio_notification_evt_handler_t evt_handler); - -#ifdef __cplusplus -} -#endif - -#endif // BLE_RADIO_NOTIFICATION_H__ - -/** @} */ +/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. + * + * The information contained herein is property of Nordic Semiconductor ASA. + * Terms and conditions of usage are described in detail in NORDIC + * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. + * + * Licensees are granted free, non-transferable use of the information. NO + * WARRANTY of ANY KIND is provided. This heading must NOT be removed from + * the file. + */ + +/** @file + * + * @defgroup ble_radio_notification Radio Notification Event Handler + * @{ + * @ingroup ble_sdk_lib + * @brief Module for propagating Radio Notification events to the application. + */ + +#ifndef BLE_RADIO_NOTIFICATION_H__ +#define BLE_RADIO_NOTIFICATION_H__ + +#include +#include +#include "nrf_soc.h" + +/**@brief Application radio notification event handler type. */ +typedef void (*ble_radio_notification_evt_handler_t) (bool radio_active); + +/**@brief Function for initializing the Radio Notification module. + * + * @param[in] irq_priority Interrupt priority for the Radio Notification interrupt handler. + * @param[in] distance The time from an Active event until the radio is activated. + * @param[in] evt_handler Handler to be executed when a radio notification event has been + * received. + * + * @return NRF_SUCCESS on successful initialization, otherwise an error code. + */ +uint32_t ble_radio_notification_init(nrf_app_irq_priority_t irq_priority, + nrf_radio_notification_distance_t distance, + ble_radio_notification_evt_handler_t evt_handler); + +#endif // BLE_RADIO_NOTIFICATION_H__ + +/** @} */ diff --git a/source/nordic_sdk/components/ble/ble_services/ble_dfu/ble_dfu.c b/source/nordic_sdk/components/ble/ble_services/ble_dfu/ble_dfu.c index 409bce0..b2ea43a 100644 --- a/source/nordic_sdk/components/ble/ble_services/ble_dfu/ble_dfu.c +++ b/source/nordic_sdk/components/ble/ble_services/ble_dfu/ble_dfu.c @@ -1,686 +1,666 @@ -/* - * Copyright (c) Nordic Semiconductor ASA - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this - * list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of other - * contributors to this software may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "ble_dfu.h" -#include "nrf_error.h" -#include "ble_types.h" -#include "ble_gatts.h" -#include "app_util.h" -#include "ble_srv_common.h" -#include "nordic_common.h" -#include -#include -#include - -#define MAX_DFU_PKT_LEN 20 /**< Maximum length (in bytes) of the DFU Packet characteristic. */ -#define PKT_START_DFU_PARAM_LEN 2 /**< Length (in bytes) of the parameters for Packet Start DFU Request. */ -#define PKT_INIT_DFU_PARAM_LEN 2 /**< Length (in bytes) of the parameters for Packet Init DFU Request. */ -#define PKT_RCPT_NOTIF_REQ_LEN 3 /**< Length (in bytes) of the Packet Receipt Notification Request. */ -#define MAX_PKTS_RCPT_NOTIF_LEN 6 /**< Maximum length (in bytes) of the Packets Receipt Notification. */ -#define MAX_RESPONSE_LEN 7 /**< Maximum length (in bytes) of the response to a Control Point command. */ -#define MAX_NOTIF_BUFFER_LEN MAX(MAX_PKTS_RCPT_NOTIF_LEN, MAX_RESPONSE_LEN) /**< Maximum length (in bytes) of the buffer needed by DFU Service while sending notifications to peer. */ - -enum -{ - OP_CODE_START_DFU = 1, /**< Value of the Op code field for 'Start DFU' command.*/ - OP_CODE_RECEIVE_INIT = 2, /**< Value of the Op code field for 'Initialize DFU parameters' command.*/ - OP_CODE_RECEIVE_FW = 3, /**< Value of the Op code field for 'Receive firmware image' command.*/ - OP_CODE_VALIDATE = 4, /**< Value of the Op code field for 'Validate firmware' command.*/ - OP_CODE_ACTIVATE_N_RESET = 5, /**< Value of the Op code field for 'Activate & Reset' command.*/ - OP_CODE_SYS_RESET = 6, /**< Value of the Op code field for 'Reset System' command.*/ - OP_CODE_IMAGE_SIZE_REQ = 7, /**< Value of the Op code field for 'Report received image size' command.*/ - OP_CODE_PKT_RCPT_NOTIF_REQ = 8, /**< Value of the Op code field for 'Request packet receipt notification.*/ - OP_CODE_RESPONSE = 16, /**< Value of the Op code field for 'Response.*/ - OP_CODE_PKT_RCPT_NOTIF = 17 /**< Value of the Op code field for 'Packets Receipt Notification'.*/ -}; - -static bool m_is_dfu_service_initialized = false; /**< Variable to check if the DFU service was initialized by the application.*/ -static uint8_t m_notif_buffer[MAX_NOTIF_BUFFER_LEN]; /**< Buffer used for sending notifications to peer. */ - -/**@brief Function for adding DFU Packet characteristic to the BLE Stack. - * - * @param[in] p_dfu DFU Service structure. - * - * @return NRF_SUCCESS on success. Otherwise an error code. - */ -static uint32_t dfu_pkt_char_add(ble_dfu_t * const p_dfu) -{ - ble_gatts_char_md_t char_md; - ble_gatts_attr_t attr_char_value; - ble_uuid_t char_uuid; - ble_gatts_attr_md_t attr_md; - - memset(&char_md, 0, sizeof(char_md)); - - char_md.char_props.write_wo_resp = 1; - char_md.p_char_user_desc = NULL; - char_md.p_char_pf = NULL; - char_md.p_user_desc_md = NULL; - char_md.p_cccd_md = NULL; - char_md.p_sccd_md = NULL; - - char_uuid.type = p_dfu->uuid_type; - char_uuid.uuid = BLE_DFU_PKT_CHAR_UUID; - - memset(&attr_md, 0, sizeof(attr_md)); - - BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&attr_md.read_perm); - BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm); - - attr_md.vloc = BLE_GATTS_VLOC_STACK; - attr_md.rd_auth = 0; - attr_md.wr_auth = 0; - attr_md.vlen = 1; - - memset(&attr_char_value, 0, sizeof(attr_char_value)); - - attr_char_value.p_uuid = &char_uuid; - attr_char_value.p_attr_md = &attr_md; - attr_char_value.init_len = 0; - attr_char_value.init_offs = 0; - attr_char_value.max_len = MAX_DFU_PKT_LEN; - attr_char_value.p_value = NULL; - - return sd_ble_gatts_characteristic_add(p_dfu->service_handle, - &char_md, - &attr_char_value, - &p_dfu->dfu_pkt_handles); -} - - -/**@brief Function for adding DFU Revision characteristic to the BLE Stack. - * - * @param[in] p_dfu DFU Service structure. - * - * @return NRF_SUCCESS on success. Otherwise an error code. - */ -static uint32_t dfu_rev_char_add(ble_dfu_t * const p_dfu, ble_dfu_init_t const * const p_dfu_init) -{ - ble_gatts_char_md_t char_md; - ble_gatts_attr_t attr_char_value; - ble_uuid_t char_uuid; - ble_gatts_attr_md_t attr_md; - - memset(&char_md, 0, sizeof(char_md)); - - char_md.char_props.read = 1; - char_md.p_char_user_desc = NULL; - char_md.p_char_pf = NULL; - char_md.p_user_desc_md = NULL; - char_md.p_cccd_md = NULL; - char_md.p_sccd_md = NULL; - - char_uuid.type = p_dfu->uuid_type; - char_uuid.uuid = BLE_DFU_REV_CHAR_UUID; - - memset(&attr_md, 0, sizeof(attr_md)); - - BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm); - BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&attr_md.write_perm); - - attr_md.vloc = BLE_GATTS_VLOC_STACK; - attr_md.rd_auth = 0; - attr_md.wr_auth = 0; - attr_md.vlen = 1; - - memset(&attr_char_value, 0, sizeof(attr_char_value)); - - attr_char_value.p_uuid = &char_uuid; - attr_char_value.p_attr_md = &attr_md; - attr_char_value.init_len = sizeof(uint16_t); - attr_char_value.init_offs = 0; - attr_char_value.max_len = sizeof(uint16_t); - attr_char_value.p_value = (uint8_t *)&p_dfu_init->revision; - - return sd_ble_gatts_characteristic_add(p_dfu->service_handle, - &char_md, - &attr_char_value, - &p_dfu->dfu_rev_handles); -} - - -/**@brief Function for adding DFU Control Point characteristic to the BLE Stack. - * - * @param[in] p_dfu DFU Service structure. - * - * @return NRF_SUCCESS on success. Otherwise an error code. - */ -static uint32_t dfu_ctrl_pt_add(ble_dfu_t * const p_dfu) -{ - ble_gatts_char_md_t char_md; - ble_gatts_attr_t attr_char_value; - ble_uuid_t char_uuid; - ble_gatts_attr_md_t attr_md; - - memset(&char_md, 0, sizeof(char_md)); - - char_md.char_props.write = 1; - char_md.char_props.notify = 1; - char_md.p_char_user_desc = NULL; - char_md.p_char_pf = NULL; - char_md.p_user_desc_md = NULL; - char_md.p_cccd_md = NULL; - char_md.p_sccd_md = NULL; - - char_uuid.type = p_dfu->uuid_type; - char_uuid.uuid = BLE_DFU_CTRL_PT_UUID; - - memset(&attr_md, 0, sizeof(attr_md)); - - BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&attr_md.read_perm); - BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm); - - attr_md.vloc = BLE_GATTS_VLOC_STACK; - attr_md.rd_auth = 0; - attr_md.wr_auth = 1; - attr_md.vlen = 1; - - memset(&attr_char_value, 0, sizeof(attr_char_value)); - - attr_char_value.p_uuid = &char_uuid; - attr_char_value.p_attr_md = &attr_md; - attr_char_value.init_len = 0; - attr_char_value.init_offs = 0; - attr_char_value.max_len = BLE_L2CAP_MTU_DEF; - attr_char_value.p_value = NULL; - - return sd_ble_gatts_characteristic_add(p_dfu->service_handle, - &char_md, - &attr_char_value, - &p_dfu->dfu_ctrl_pt_handles); -} - - -/**@brief Function for handling the @ref BLE_GAP_EVT_CONNECTED event from the S110 SoftDevice. - * - * @param[in] p_dfu DFU Service Structure. - * @param[in] p_ble_evt Pointer to the event received from BLE stack. - */ -static void on_connect(ble_dfu_t * p_dfu, ble_evt_t * p_ble_evt) -{ - p_dfu->conn_handle = p_ble_evt->evt.gap_evt.conn_handle; -} - - -/**@brief Function for checking if the CCCD of DFU Control point is configured for Notification. - * - * @details This function checks if the CCCD of DFU Control Point characteristic is configured - * for Notification by the DFU Controller. - * - * @param[in] p_dfu DFU Service structure. - * - * @return True if the CCCD of DFU Control Point characteristic is configured for Notification. - * False otherwise. - */ -static bool is_cccd_configured(ble_dfu_t * p_dfu) -{ - // Check if the CCCDs are configured. - uint8_t cccd_val_buf[BLE_CCCD_VALUE_LEN]; - ble_gatts_value_t gatts_value; - - // Initialize value struct. - memset(&gatts_value, 0, sizeof(gatts_value)); - - gatts_value.len = BLE_CCCD_VALUE_LEN; - gatts_value.offset = 0; - gatts_value.p_value = cccd_val_buf; - - // Check the CCCD Value of DFU Control Point. - uint32_t err_code = sd_ble_gatts_value_get(p_dfu->conn_handle, - p_dfu->dfu_ctrl_pt_handles.cccd_handle, - &gatts_value); - if (err_code != NRF_SUCCESS) - { - if (p_dfu->error_handler != NULL) - { - p_dfu->error_handler(err_code); - } - return false; - } - - return ble_srv_is_notification_enabled(cccd_val_buf); -} - - -/**@brief Function for handling a Write event on the Control Point characteristic. - * - * @param[in] p_dfu DFU Service Structure. - * @param[in] p_ble_write_evt Pointer to the write event received from BLE stack. - * - * @return NRF_SUCCESS on successful processing of control point write. Otherwise an error code. - */ -static uint32_t on_ctrl_pt_write(ble_dfu_t * p_dfu, ble_gatts_evt_write_t * p_ble_write_evt) -{ - ble_gatts_rw_authorize_reply_params_t write_authorize_reply; - - write_authorize_reply.type = BLE_GATTS_AUTHORIZE_TYPE_WRITE; - - if (!is_cccd_configured(p_dfu)) - { - // Send an error response to the peer indicating that the CCCD is improperly configured. - write_authorize_reply.params.write.gatt_status = - BLE_GATT_STATUS_ATTERR_CPS_CCCD_CONFIG_ERROR; - - return (sd_ble_gatts_rw_authorize_reply(p_dfu->conn_handle, &write_authorize_reply)); - - } - else - { - uint32_t err_code; - - write_authorize_reply.params.write.gatt_status = BLE_GATT_STATUS_SUCCESS; - - err_code = (sd_ble_gatts_rw_authorize_reply(p_dfu->conn_handle, &write_authorize_reply)); - - if (err_code != NRF_SUCCESS) - { - return err_code; - } - } - - ble_dfu_evt_t ble_dfu_evt; - - switch (p_ble_write_evt->data[0]) - { - case OP_CODE_START_DFU: - ble_dfu_evt.ble_dfu_evt_type = BLE_DFU_START; - - if (p_ble_write_evt->len < PKT_START_DFU_PARAM_LEN) - { - return ble_dfu_response_send(p_dfu, - (ble_dfu_procedure_t) p_ble_write_evt->data[0], - BLE_DFU_RESP_VAL_OPER_FAILED); - } - - ble_dfu_evt.evt.ble_dfu_pkt_write.len = 1; - ble_dfu_evt.evt.ble_dfu_pkt_write.p_data = &(p_ble_write_evt->data[1]); - - p_dfu->evt_handler(p_dfu, &ble_dfu_evt); - break; - - case OP_CODE_RECEIVE_INIT: - ble_dfu_evt.ble_dfu_evt_type = BLE_DFU_RECEIVE_INIT_DATA; - - if (p_ble_write_evt->len < PKT_INIT_DFU_PARAM_LEN) - { - return ble_dfu_response_send(p_dfu, - (ble_dfu_procedure_t) p_ble_write_evt->data[0], - BLE_DFU_RESP_VAL_OPER_FAILED); - } - - ble_dfu_evt.evt.ble_dfu_pkt_write.len = 1; - ble_dfu_evt.evt.ble_dfu_pkt_write.p_data = &(p_ble_write_evt->data[1]); - - p_dfu->evt_handler(p_dfu, &ble_dfu_evt); - break; - - case OP_CODE_RECEIVE_FW: - ble_dfu_evt.ble_dfu_evt_type = BLE_DFU_RECEIVE_APP_DATA; - - p_dfu->evt_handler(p_dfu, &ble_dfu_evt); - break; - - case OP_CODE_VALIDATE: - ble_dfu_evt.ble_dfu_evt_type = BLE_DFU_VALIDATE; - - p_dfu->evt_handler(p_dfu, &ble_dfu_evt); - break; - - case OP_CODE_ACTIVATE_N_RESET: - ble_dfu_evt.ble_dfu_evt_type = BLE_DFU_ACTIVATE_N_RESET; - - p_dfu->evt_handler(p_dfu, &ble_dfu_evt); - break; - - case OP_CODE_SYS_RESET: - ble_dfu_evt.ble_dfu_evt_type = BLE_DFU_SYS_RESET; - - p_dfu->evt_handler(p_dfu, &ble_dfu_evt); - break; - - case OP_CODE_PKT_RCPT_NOTIF_REQ: - if (p_ble_write_evt->len < PKT_RCPT_NOTIF_REQ_LEN) - { - return (ble_dfu_response_send(p_dfu, - BLE_DFU_PKT_RCPT_REQ_PROCEDURE, - BLE_DFU_RESP_VAL_NOT_SUPPORTED)); - } - - ble_dfu_evt.evt.pkt_rcpt_notif_req.num_of_pkts = - uint16_decode(&(p_ble_write_evt->data[1])); - - if (ble_dfu_evt.evt.pkt_rcpt_notif_req.num_of_pkts == 0) - { - ble_dfu_evt.ble_dfu_evt_type = BLE_DFU_PKT_RCPT_NOTIF_DISABLED; - } - else - { - ble_dfu_evt.ble_dfu_evt_type = BLE_DFU_PKT_RCPT_NOTIF_ENABLED; - } - - p_dfu->evt_handler(p_dfu, &ble_dfu_evt); - - break; - - case OP_CODE_IMAGE_SIZE_REQ: - ble_dfu_evt.ble_dfu_evt_type = BLE_DFU_BYTES_RECEIVED_SEND; - - p_dfu->evt_handler(p_dfu, &ble_dfu_evt); - break; - - default: - // Unsupported op code. - return ble_dfu_response_send(p_dfu, - (ble_dfu_procedure_t) p_ble_write_evt->data[0], - BLE_DFU_RESP_VAL_NOT_SUPPORTED); - } - return NRF_SUCCESS; -} - - -/**@brief Function for handling the @ref BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST event from the S110 - * Stack. - * - * @param[in] p_dfu DFU Service Structure. - * @param[in] p_ble_evt Pointer to the event received from BLE stack. - */ -static void on_rw_authorize_req(ble_dfu_t * p_dfu, ble_evt_t * p_ble_evt) -{ - ble_gatts_evt_rw_authorize_request_t * p_authorize_request; - - p_authorize_request = &(p_ble_evt->evt.gatts_evt.params.authorize_request); - - if ( - (p_authorize_request->type == BLE_GATTS_AUTHORIZE_TYPE_WRITE) - && - (p_authorize_request->request.write.handle == p_dfu->dfu_ctrl_pt_handles.value_handle) - && - (p_ble_evt->evt.gatts_evt.params.authorize_request.request.write.op != BLE_GATTS_OP_PREP_WRITE_REQ) - && - (p_ble_evt->evt.gatts_evt.params.authorize_request.request.write.op != BLE_GATTS_OP_EXEC_WRITE_REQ_NOW) - && - (p_ble_evt->evt.gatts_evt.params.authorize_request.request.write.op != BLE_GATTS_OP_EXEC_WRITE_REQ_CANCEL) - ) - { - uint32_t err_code; - - err_code = on_ctrl_pt_write(p_dfu, &(p_authorize_request->request.write)); - - if (err_code != NRF_SUCCESS && p_dfu->error_handler != NULL) - { - p_dfu->error_handler(err_code); - } - } -} - - -/**@brief Function for handling the @ref BLE_GATTS_EVT_WRITE event from the S110 SoftDevice. - * - * @param[in] p_dfu DFU Service Structure. - * @param[in] p_ble_evt Pointer to the event received from BLE stack. - */ -static void on_write(ble_dfu_t * p_dfu, ble_evt_t * p_ble_evt) -{ - if (p_ble_evt->evt.gatts_evt.params.write.handle == p_dfu->dfu_pkt_handles.value_handle) - { - // DFU Packet written - - ble_dfu_evt_t ble_dfu_evt; - - ble_dfu_evt.ble_dfu_evt_type = BLE_DFU_PACKET_WRITE; - ble_dfu_evt.evt.ble_dfu_pkt_write.len = p_ble_evt->evt.gatts_evt.params.write.len; - ble_dfu_evt.evt.ble_dfu_pkt_write.p_data = p_ble_evt->evt.gatts_evt.params.write.data; - - p_dfu->evt_handler(p_dfu, &ble_dfu_evt); - } -} - - -/**@brief Function for handling the BLE_GAP_EVT_DISCONNECTED event from the S110 SoftDevice. - * - * @param[in] p_dfu DFU Service Structure. - * @param[in] p_ble_evt Pointer to the event received from BLE stack. - */ -static void on_disconnect(ble_dfu_t * p_dfu, ble_evt_t * p_ble_evt) -{ - p_dfu->conn_handle = BLE_CONN_HANDLE_INVALID; -} - - -uint32_t ble_dfu_init(ble_dfu_t * p_dfu, ble_dfu_init_t * p_dfu_init) -{ - if ((p_dfu == NULL) || (p_dfu_init == NULL) || (p_dfu_init->evt_handler == NULL)) - { - return NRF_ERROR_NULL; - } - - p_dfu->conn_handle = BLE_CONN_HANDLE_INVALID; - - ble_uuid_t service_uuid; - uint32_t err_code; - - const ble_uuid128_t base_uuid128 = - { - { - 0x23, 0xD1, 0xBC, 0xEA, 0x5F, 0x78, 0x23, 0x15, - 0xDE, 0xEF, 0x12, 0x12, 0x00, 0x00, 0x00, 0x00 - } - }; - - service_uuid.uuid = BLE_DFU_SERVICE_UUID; - - err_code = sd_ble_uuid_vs_add(&base_uuid128, &(service_uuid.type)); - if (err_code != NRF_SUCCESS) - { - return err_code; - } - - err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, - &service_uuid, - &(p_dfu->service_handle)); - if (err_code != NRF_SUCCESS) - { - return err_code; - } - - p_dfu->uuid_type = service_uuid.type; - - err_code = dfu_pkt_char_add(p_dfu); - if (err_code != NRF_SUCCESS) - { - return err_code; - } - - err_code = dfu_ctrl_pt_add(p_dfu); - if (err_code != NRF_SUCCESS) - { - return err_code; - } - - err_code = dfu_rev_char_add(p_dfu, p_dfu_init); - if (err_code != NRF_SUCCESS) - { - return err_code; - } - - p_dfu->evt_handler = p_dfu_init->evt_handler; - - if (p_dfu_init->error_handler != NULL) - { - p_dfu->error_handler = p_dfu_init->error_handler; - } - - m_is_dfu_service_initialized = true; - - return NRF_SUCCESS; -} - - -void ble_dfu_on_ble_evt(ble_dfu_t * p_dfu, ble_evt_t * p_ble_evt) -{ - if ((p_dfu == NULL) || (p_ble_evt == NULL)) - { - return; - } - - if (p_dfu->evt_handler != NULL) - { - switch (p_ble_evt->header.evt_id) - { - case BLE_GAP_EVT_CONNECTED: - on_connect(p_dfu, p_ble_evt); - break; - - case BLE_GATTS_EVT_WRITE: - on_write(p_dfu, p_ble_evt); - break; - - case BLE_GAP_EVT_DISCONNECTED: - on_disconnect(p_dfu, p_ble_evt); - break; - - case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST: - on_rw_authorize_req(p_dfu, p_ble_evt); - break; - - default: - // No implementation needed. - break; - } - } -} - - -uint32_t ble_dfu_bytes_rcvd_report(ble_dfu_t * p_dfu, uint32_t num_of_firmware_bytes_rcvd) -{ - if (p_dfu == NULL) - { - return NRF_ERROR_NULL; - } - - if ((p_dfu->conn_handle == BLE_CONN_HANDLE_INVALID) || !m_is_dfu_service_initialized) - { - return NRF_ERROR_INVALID_STATE; - } - - ble_gatts_hvx_params_t hvx_params; - uint16_t index = 0; - - // Encode the Op Code. - m_notif_buffer[index++] = OP_CODE_RESPONSE; - - // Encode the Reqest Op Code. - m_notif_buffer[index++] = OP_CODE_IMAGE_SIZE_REQ; - - // Encode the Response Value. - m_notif_buffer[index++] = (uint8_t)BLE_DFU_RESP_VAL_SUCCESS; - - index += uint32_encode(num_of_firmware_bytes_rcvd, &m_notif_buffer[index]); - - memset(&hvx_params, 0, sizeof(hvx_params)); - - hvx_params.handle = p_dfu->dfu_ctrl_pt_handles.value_handle; - hvx_params.type = BLE_GATT_HVX_NOTIFICATION; - hvx_params.offset = 0; - hvx_params.p_len = &index; - hvx_params.p_data = m_notif_buffer; - - return sd_ble_gatts_hvx(p_dfu->conn_handle, &hvx_params); -} - - -uint32_t ble_dfu_pkts_rcpt_notify(ble_dfu_t * p_dfu, uint32_t num_of_firmware_bytes_rcvd) -{ - if (p_dfu == NULL) - { - return NRF_ERROR_NULL; - } - - if ((p_dfu->conn_handle == BLE_CONN_HANDLE_INVALID) || !m_is_dfu_service_initialized) - { - return NRF_ERROR_INVALID_STATE; - } - - ble_gatts_hvx_params_t hvx_params; - uint16_t index = 0; - - m_notif_buffer[index++] = OP_CODE_PKT_RCPT_NOTIF; - - index += uint32_encode(num_of_firmware_bytes_rcvd, &m_notif_buffer[index]); - - memset(&hvx_params, 0, sizeof(hvx_params)); - - hvx_params.handle = p_dfu->dfu_ctrl_pt_handles.value_handle; - hvx_params.type = BLE_GATT_HVX_NOTIFICATION; - hvx_params.offset = 0; - hvx_params.p_len = &index; - hvx_params.p_data = m_notif_buffer; - - return sd_ble_gatts_hvx(p_dfu->conn_handle, &hvx_params); -} - - -uint32_t ble_dfu_response_send(ble_dfu_t * p_dfu, - ble_dfu_procedure_t dfu_proc, - ble_dfu_resp_val_t resp_val) -{ - if (p_dfu == NULL) - { - return NRF_ERROR_NULL; - } - - if ((p_dfu->conn_handle == BLE_CONN_HANDLE_INVALID) || !m_is_dfu_service_initialized) - { - return NRF_ERROR_INVALID_STATE; - } - - ble_gatts_hvx_params_t hvx_params; - uint16_t index = 0; - - m_notif_buffer[index++] = OP_CODE_RESPONSE; - - // Encode the Request Op code - m_notif_buffer[index++] = (uint8_t)dfu_proc; - - // Encode the Response Value. - m_notif_buffer[index++] = (uint8_t)resp_val; - - memset(&hvx_params, 0, sizeof(hvx_params)); - - hvx_params.handle = p_dfu->dfu_ctrl_pt_handles.value_handle; - hvx_params.type = BLE_GATT_HVX_NOTIFICATION; - hvx_params.offset = 0; - hvx_params.p_len = &index; - hvx_params.p_data = m_notif_buffer; - - return sd_ble_gatts_hvx(p_dfu->conn_handle, &hvx_params); -} +/* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved. + * + * The information contained herein is property of Nordic Semiconductor ASA. + * Terms and conditions of usage are described in detail in NORDIC + * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. + * + * Licensees are granted free, non-transferable use of the information. NO + * WARRANTY of ANY KIND is provided. This heading must NOT be removed from + * the file. + * + */ + +#include "ble_dfu.h" +#include "nrf_error.h" +#include "ble_types.h" +#include "ble_gatts.h" +#include "app_util.h" +#include "ble_srv_common.h" +#include "nordic_common.h" +#include +#include +#include + +#define MAX_DFU_PKT_LEN 20 /**< Maximum length (in bytes) of the DFU Packet characteristic. */ +#define PKT_START_DFU_PARAM_LEN 2 /**< Length (in bytes) of the parameters for Packet Start DFU Request. */ +#define PKT_INIT_DFU_PARAM_LEN 2 /**< Length (in bytes) of the parameters for Packet Init DFU Request. */ +#define PKT_RCPT_NOTIF_REQ_LEN 3 /**< Length (in bytes) of the Packet Receipt Notification Request. */ +#define MAX_PKTS_RCPT_NOTIF_LEN 6 /**< Maximum length (in bytes) of the Packets Receipt Notification. */ +#define MAX_RESPONSE_LEN 7 /**< Maximum length (in bytes) of the response to a Control Point command. */ +#define MAX_NOTIF_BUFFER_LEN MAX(MAX_PKTS_RCPT_NOTIF_LEN, MAX_RESPONSE_LEN) /**< Maximum length (in bytes) of the buffer needed by DFU Service while sending notifications to peer. */ + +enum +{ + OP_CODE_START_DFU = 1, /**< Value of the Op code field for 'Start DFU' command.*/ + OP_CODE_RECEIVE_INIT = 2, /**< Value of the Op code field for 'Initialize DFU parameters' command.*/ + OP_CODE_RECEIVE_FW = 3, /**< Value of the Op code field for 'Receive firmware image' command.*/ + OP_CODE_VALIDATE = 4, /**< Value of the Op code field for 'Validate firmware' command.*/ + OP_CODE_ACTIVATE_N_RESET = 5, /**< Value of the Op code field for 'Activate & Reset' command.*/ + OP_CODE_SYS_RESET = 6, /**< Value of the Op code field for 'Reset System' command.*/ + OP_CODE_IMAGE_SIZE_REQ = 7, /**< Value of the Op code field for 'Report received image size' command.*/ + OP_CODE_PKT_RCPT_NOTIF_REQ = 8, /**< Value of the Op code field for 'Request packet receipt notification.*/ + OP_CODE_RESPONSE = 16, /**< Value of the Op code field for 'Response.*/ + OP_CODE_PKT_RCPT_NOTIF = 17 /**< Value of the Op code field for 'Packets Receipt Notification'.*/ +}; + +static bool m_is_dfu_service_initialized = false; /**< Variable to check if the DFU service was initialized by the application.*/ +static uint8_t m_notif_buffer[MAX_NOTIF_BUFFER_LEN]; /**< Buffer used for sending notifications to peer. */ + +/**@brief Function for adding DFU Packet characteristic to the BLE Stack. + * + * @param[in] p_dfu DFU Service structure. + * + * @return NRF_SUCCESS on success. Otherwise an error code. + */ +static uint32_t dfu_pkt_char_add(ble_dfu_t * const p_dfu) +{ + ble_gatts_char_md_t char_md; + ble_gatts_attr_t attr_char_value; + ble_uuid_t char_uuid; + ble_gatts_attr_md_t attr_md; + + memset(&char_md, 0, sizeof(char_md)); + + char_md.char_props.write_wo_resp = 1; + char_md.p_char_user_desc = NULL; + char_md.p_char_pf = NULL; + char_md.p_user_desc_md = NULL; + char_md.p_cccd_md = NULL; + char_md.p_sccd_md = NULL; + + char_uuid.type = p_dfu->uuid_type; + char_uuid.uuid = BLE_DFU_PKT_CHAR_UUID; + + memset(&attr_md, 0, sizeof(attr_md)); + + BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&attr_md.read_perm); + BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm); + + attr_md.vloc = BLE_GATTS_VLOC_STACK; + attr_md.rd_auth = 0; + attr_md.wr_auth = 0; + attr_md.vlen = 1; + + memset(&attr_char_value, 0, sizeof(attr_char_value)); + + attr_char_value.p_uuid = &char_uuid; + attr_char_value.p_attr_md = &attr_md; + attr_char_value.init_len = 0; + attr_char_value.init_offs = 0; + attr_char_value.max_len = MAX_DFU_PKT_LEN; + attr_char_value.p_value = NULL; + + return sd_ble_gatts_characteristic_add(p_dfu->service_handle, + &char_md, + &attr_char_value, + &p_dfu->dfu_pkt_handles); +} + + +/**@brief Function for adding DFU Revision characteristic to the BLE Stack. + * + * @param[in] p_dfu DFU Service structure. + * + * @return NRF_SUCCESS on success. Otherwise an error code. + */ +static uint32_t dfu_rev_char_add(ble_dfu_t * const p_dfu, ble_dfu_init_t const * const p_dfu_init) +{ + ble_gatts_char_md_t char_md; + ble_gatts_attr_t attr_char_value; + ble_uuid_t char_uuid; + ble_gatts_attr_md_t attr_md; + + memset(&char_md, 0, sizeof(char_md)); + + char_md.char_props.read = 1; + char_md.p_char_user_desc = NULL; + char_md.p_char_pf = NULL; + char_md.p_user_desc_md = NULL; + char_md.p_cccd_md = NULL; + char_md.p_sccd_md = NULL; + + char_uuid.type = p_dfu->uuid_type; + char_uuid.uuid = BLE_DFU_REV_CHAR_UUID; + + memset(&attr_md, 0, sizeof(attr_md)); + + BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm); + BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&attr_md.write_perm); + + attr_md.vloc = BLE_GATTS_VLOC_STACK; + attr_md.rd_auth = 0; + attr_md.wr_auth = 0; + attr_md.vlen = 1; + + memset(&attr_char_value, 0, sizeof(attr_char_value)); + + attr_char_value.p_uuid = &char_uuid; + attr_char_value.p_attr_md = &attr_md; + attr_char_value.init_len = sizeof(uint16_t); + attr_char_value.init_offs = 0; + attr_char_value.max_len = sizeof(uint16_t); + attr_char_value.p_value = (uint8_t *)&p_dfu_init->revision; + + return sd_ble_gatts_characteristic_add(p_dfu->service_handle, + &char_md, + &attr_char_value, + &p_dfu->dfu_rev_handles); +} + + +/**@brief Function for adding DFU Control Point characteristic to the BLE Stack. + * + * @param[in] p_dfu DFU Service structure. + * + * @return NRF_SUCCESS on success. Otherwise an error code. + */ +static uint32_t dfu_ctrl_pt_add(ble_dfu_t * const p_dfu) +{ + ble_gatts_char_md_t char_md; + ble_gatts_attr_t attr_char_value; + ble_uuid_t char_uuid; + ble_gatts_attr_md_t attr_md; + + memset(&char_md, 0, sizeof(char_md)); + + char_md.char_props.write = 1; + char_md.char_props.notify = 1; + char_md.p_char_user_desc = NULL; + char_md.p_char_pf = NULL; + char_md.p_user_desc_md = NULL; + char_md.p_cccd_md = NULL; + char_md.p_sccd_md = NULL; + + char_uuid.type = p_dfu->uuid_type; + char_uuid.uuid = BLE_DFU_CTRL_PT_UUID; + + memset(&attr_md, 0, sizeof(attr_md)); + + BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&attr_md.read_perm); + BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm); + + attr_md.vloc = BLE_GATTS_VLOC_STACK; + attr_md.rd_auth = 0; + attr_md.wr_auth = 1; + attr_md.vlen = 1; + + memset(&attr_char_value, 0, sizeof(attr_char_value)); + + attr_char_value.p_uuid = &char_uuid; + attr_char_value.p_attr_md = &attr_md; + attr_char_value.init_len = 0; + attr_char_value.init_offs = 0; + attr_char_value.max_len = BLE_L2CAP_MTU_DEF; + attr_char_value.p_value = NULL; + + return sd_ble_gatts_characteristic_add(p_dfu->service_handle, + &char_md, + &attr_char_value, + &p_dfu->dfu_ctrl_pt_handles); +} + + +/**@brief Function for handling the @ref BLE_GAP_EVT_CONNECTED event from the S110 SoftDevice. + * + * @param[in] p_dfu DFU Service Structure. + * @param[in] p_ble_evt Pointer to the event received from BLE stack. + */ +static void on_connect(ble_dfu_t * p_dfu, ble_evt_t * p_ble_evt) +{ + p_dfu->conn_handle = p_ble_evt->evt.gap_evt.conn_handle; +} + + +/**@brief Function for checking if the CCCD of DFU Control point is configured for Notification. + * + * @details This function checks if the CCCD of DFU Control Point characteristic is configured + * for Notification by the DFU Controller. + * + * @param[in] p_dfu DFU Service structure. + * + * @return True if the CCCD of DFU Control Point characteristic is configured for Notification. + * False otherwise. + */ +static bool is_cccd_configured(ble_dfu_t * p_dfu) +{ + // Check if the CCCDs are configured. + uint8_t cccd_val_buf[BLE_CCCD_VALUE_LEN]; + ble_gatts_value_t gatts_value; + + // Initialize value struct. + memset(&gatts_value, 0, sizeof(gatts_value)); + + gatts_value.len = BLE_CCCD_VALUE_LEN; + gatts_value.offset = 0; + gatts_value.p_value = cccd_val_buf; + + // Check the CCCD Value of DFU Control Point. + uint32_t err_code = sd_ble_gatts_value_get(p_dfu->conn_handle, + p_dfu->dfu_ctrl_pt_handles.cccd_handle, + &gatts_value); + if (err_code != NRF_SUCCESS) + { + if (p_dfu->error_handler != NULL) + { + p_dfu->error_handler(err_code); + } + return false; + } + + return ble_srv_is_notification_enabled(cccd_val_buf); +} + + +/**@brief Function for handling a Write event on the Control Point characteristic. + * + * @param[in] p_dfu DFU Service Structure. + * @param[in] p_ble_write_evt Pointer to the write event received from BLE stack. + * + * @return NRF_SUCCESS on successful processing of control point write. Otherwise an error code. + */ +static uint32_t on_ctrl_pt_write(ble_dfu_t * p_dfu, ble_gatts_evt_write_t * p_ble_write_evt) +{ + ble_gatts_rw_authorize_reply_params_t write_authorize_reply; + + write_authorize_reply.type = BLE_GATTS_AUTHORIZE_TYPE_WRITE; + + if (!is_cccd_configured(p_dfu)) + { + // Send an error response to the peer indicating that the CCCD is improperly configured. + write_authorize_reply.params.write.gatt_status = + BLE_GATT_STATUS_ATTERR_CPS_CCCD_CONFIG_ERROR; + + return (sd_ble_gatts_rw_authorize_reply(p_dfu->conn_handle, &write_authorize_reply)); + + } + else + { + uint32_t err_code; + + write_authorize_reply.params.write.gatt_status = BLE_GATT_STATUS_SUCCESS; + + err_code = (sd_ble_gatts_rw_authorize_reply(p_dfu->conn_handle, &write_authorize_reply)); + + if (err_code != NRF_SUCCESS) + { + return err_code; + } + } + + ble_dfu_evt_t ble_dfu_evt; + + switch (p_ble_write_evt->data[0]) + { + case OP_CODE_START_DFU: + ble_dfu_evt.ble_dfu_evt_type = BLE_DFU_START; + + if (p_ble_write_evt->len < PKT_START_DFU_PARAM_LEN) + { + return ble_dfu_response_send(p_dfu, + (ble_dfu_procedure_t) p_ble_write_evt->data[0], + BLE_DFU_RESP_VAL_OPER_FAILED); + } + + ble_dfu_evt.evt.ble_dfu_pkt_write.len = 1; + ble_dfu_evt.evt.ble_dfu_pkt_write.p_data = &(p_ble_write_evt->data[1]); + + p_dfu->evt_handler(p_dfu, &ble_dfu_evt); + break; + + case OP_CODE_RECEIVE_INIT: + ble_dfu_evt.ble_dfu_evt_type = BLE_DFU_RECEIVE_INIT_DATA; + + if (p_ble_write_evt->len < PKT_INIT_DFU_PARAM_LEN) + { + return ble_dfu_response_send(p_dfu, + (ble_dfu_procedure_t) p_ble_write_evt->data[0], + BLE_DFU_RESP_VAL_OPER_FAILED); + } + + ble_dfu_evt.evt.ble_dfu_pkt_write.len = 1; + ble_dfu_evt.evt.ble_dfu_pkt_write.p_data = &(p_ble_write_evt->data[1]); + + p_dfu->evt_handler(p_dfu, &ble_dfu_evt); + break; + + case OP_CODE_RECEIVE_FW: + ble_dfu_evt.ble_dfu_evt_type = BLE_DFU_RECEIVE_APP_DATA; + + p_dfu->evt_handler(p_dfu, &ble_dfu_evt); + break; + + case OP_CODE_VALIDATE: + ble_dfu_evt.ble_dfu_evt_type = BLE_DFU_VALIDATE; + + p_dfu->evt_handler(p_dfu, &ble_dfu_evt); + break; + + case OP_CODE_ACTIVATE_N_RESET: + ble_dfu_evt.ble_dfu_evt_type = BLE_DFU_ACTIVATE_N_RESET; + + p_dfu->evt_handler(p_dfu, &ble_dfu_evt); + break; + + case OP_CODE_SYS_RESET: + ble_dfu_evt.ble_dfu_evt_type = BLE_DFU_SYS_RESET; + + p_dfu->evt_handler(p_dfu, &ble_dfu_evt); + break; + + case OP_CODE_PKT_RCPT_NOTIF_REQ: + if (p_ble_write_evt->len < PKT_RCPT_NOTIF_REQ_LEN) + { + return (ble_dfu_response_send(p_dfu, + BLE_DFU_PKT_RCPT_REQ_PROCEDURE, + BLE_DFU_RESP_VAL_NOT_SUPPORTED)); + } + + ble_dfu_evt.evt.pkt_rcpt_notif_req.num_of_pkts = + uint16_decode(&(p_ble_write_evt->data[1])); + + if (ble_dfu_evt.evt.pkt_rcpt_notif_req.num_of_pkts == 0) + { + ble_dfu_evt.ble_dfu_evt_type = BLE_DFU_PKT_RCPT_NOTIF_DISABLED; + } + else + { + ble_dfu_evt.ble_dfu_evt_type = BLE_DFU_PKT_RCPT_NOTIF_ENABLED; + } + + p_dfu->evt_handler(p_dfu, &ble_dfu_evt); + + break; + + case OP_CODE_IMAGE_SIZE_REQ: + ble_dfu_evt.ble_dfu_evt_type = BLE_DFU_BYTES_RECEIVED_SEND; + + p_dfu->evt_handler(p_dfu, &ble_dfu_evt); + break; + + default: + // Unsupported op code. + return ble_dfu_response_send(p_dfu, + (ble_dfu_procedure_t) p_ble_write_evt->data[0], + BLE_DFU_RESP_VAL_NOT_SUPPORTED); + } + return NRF_SUCCESS; +} + + +/**@brief Function for handling the @ref BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST event from the S110 + * Stack. + * + * @param[in] p_dfu DFU Service Structure. + * @param[in] p_ble_evt Pointer to the event received from BLE stack. + */ +static void on_rw_authorize_req(ble_dfu_t * p_dfu, ble_evt_t * p_ble_evt) +{ + ble_gatts_evt_rw_authorize_request_t * p_authorize_request; + + p_authorize_request = &(p_ble_evt->evt.gatts_evt.params.authorize_request); + + if ( + (p_authorize_request->type == BLE_GATTS_AUTHORIZE_TYPE_WRITE) + && + (p_authorize_request->request.write.handle == p_dfu->dfu_ctrl_pt_handles.value_handle) + && + (p_ble_evt->evt.gatts_evt.params.authorize_request.request.write.op != BLE_GATTS_OP_PREP_WRITE_REQ) + && + (p_ble_evt->evt.gatts_evt.params.authorize_request.request.write.op != BLE_GATTS_OP_EXEC_WRITE_REQ_NOW) + && + (p_ble_evt->evt.gatts_evt.params.authorize_request.request.write.op != BLE_GATTS_OP_EXEC_WRITE_REQ_CANCEL) + ) + { + uint32_t err_code; + + err_code = on_ctrl_pt_write(p_dfu, &(p_authorize_request->request.write)); + + if (err_code != NRF_SUCCESS && p_dfu->error_handler != NULL) + { + p_dfu->error_handler(err_code); + } + } +} + + +/**@brief Function for handling the @ref BLE_GATTS_EVT_WRITE event from the S110 SoftDevice. + * + * @param[in] p_dfu DFU Service Structure. + * @param[in] p_ble_evt Pointer to the event received from BLE stack. + */ +static void on_write(ble_dfu_t * p_dfu, ble_evt_t * p_ble_evt) +{ + if (p_ble_evt->evt.gatts_evt.params.write.handle == p_dfu->dfu_pkt_handles.value_handle) + { + // DFU Packet written + + ble_dfu_evt_t ble_dfu_evt; + + ble_dfu_evt.ble_dfu_evt_type = BLE_DFU_PACKET_WRITE; + ble_dfu_evt.evt.ble_dfu_pkt_write.len = p_ble_evt->evt.gatts_evt.params.write.len; + ble_dfu_evt.evt.ble_dfu_pkt_write.p_data = p_ble_evt->evt.gatts_evt.params.write.data; + + p_dfu->evt_handler(p_dfu, &ble_dfu_evt); + } +} + + +/**@brief Function for handling the BLE_GAP_EVT_DISCONNECTED event from the S110 SoftDevice. + * + * @param[in] p_dfu DFU Service Structure. + * @param[in] p_ble_evt Pointer to the event received from BLE stack. + */ +static void on_disconnect(ble_dfu_t * p_dfu, ble_evt_t * p_ble_evt) +{ + p_dfu->conn_handle = BLE_CONN_HANDLE_INVALID; +} + + +uint32_t ble_dfu_init(ble_dfu_t * p_dfu, ble_dfu_init_t * p_dfu_init) +{ + if ((p_dfu == NULL) || (p_dfu_init == NULL) || (p_dfu_init->evt_handler == NULL)) + { + return NRF_ERROR_NULL; + } + + p_dfu->conn_handle = BLE_CONN_HANDLE_INVALID; + + ble_uuid_t service_uuid; + uint32_t err_code; + + const ble_uuid128_t base_uuid128 = + { + { + 0x23, 0xD1, 0xBC, 0xEA, 0x5F, 0x78, 0x23, 0x15, + 0xDE, 0xEF, 0x12, 0x12, 0x00, 0x00, 0x00, 0x00 + } + }; + + service_uuid.uuid = BLE_DFU_SERVICE_UUID; + + err_code = sd_ble_uuid_vs_add(&base_uuid128, &(service_uuid.type)); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + + err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, + &service_uuid, + &(p_dfu->service_handle)); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + + p_dfu->uuid_type = service_uuid.type; + + err_code = dfu_pkt_char_add(p_dfu); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + + err_code = dfu_ctrl_pt_add(p_dfu); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + + err_code = dfu_rev_char_add(p_dfu, p_dfu_init); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + + p_dfu->evt_handler = p_dfu_init->evt_handler; + + if (p_dfu_init->error_handler != NULL) + { + p_dfu->error_handler = p_dfu_init->error_handler; + } + + m_is_dfu_service_initialized = true; + + return NRF_SUCCESS; +} + + +void ble_dfu_on_ble_evt(ble_dfu_t * p_dfu, ble_evt_t * p_ble_evt) +{ + if ((p_dfu == NULL) || (p_ble_evt == NULL)) + { + return; + } + + if (p_dfu->evt_handler != NULL) + { + switch (p_ble_evt->header.evt_id) + { + case BLE_GAP_EVT_CONNECTED: + on_connect(p_dfu, p_ble_evt); + break; + + case BLE_GATTS_EVT_WRITE: + on_write(p_dfu, p_ble_evt); + break; + + case BLE_GAP_EVT_DISCONNECTED: + on_disconnect(p_dfu, p_ble_evt); + break; + + case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST: + on_rw_authorize_req(p_dfu, p_ble_evt); + break; + + default: + // No implementation needed. + break; + } + } +} + + +uint32_t ble_dfu_bytes_rcvd_report(ble_dfu_t * p_dfu, uint32_t num_of_firmware_bytes_rcvd) +{ + if (p_dfu == NULL) + { + return NRF_ERROR_NULL; + } + + if ((p_dfu->conn_handle == BLE_CONN_HANDLE_INVALID) || !m_is_dfu_service_initialized) + { + return NRF_ERROR_INVALID_STATE; + } + + ble_gatts_hvx_params_t hvx_params; + uint16_t index = 0; + + // Encode the Op Code. + m_notif_buffer[index++] = OP_CODE_RESPONSE; + + // Encode the Reqest Op Code. + m_notif_buffer[index++] = OP_CODE_IMAGE_SIZE_REQ; + + // Encode the Response Value. + m_notif_buffer[index++] = (uint8_t)BLE_DFU_RESP_VAL_SUCCESS; + + index += uint32_encode(num_of_firmware_bytes_rcvd, &m_notif_buffer[index]); + + memset(&hvx_params, 0, sizeof(hvx_params)); + + hvx_params.handle = p_dfu->dfu_ctrl_pt_handles.value_handle; + hvx_params.type = BLE_GATT_HVX_NOTIFICATION; + hvx_params.offset = 0; + hvx_params.p_len = &index; + hvx_params.p_data = m_notif_buffer; + + return sd_ble_gatts_hvx(p_dfu->conn_handle, &hvx_params); +} + + +uint32_t ble_dfu_pkts_rcpt_notify(ble_dfu_t * p_dfu, uint32_t num_of_firmware_bytes_rcvd) +{ + if (p_dfu == NULL) + { + return NRF_ERROR_NULL; + } + + if ((p_dfu->conn_handle == BLE_CONN_HANDLE_INVALID) || !m_is_dfu_service_initialized) + { + return NRF_ERROR_INVALID_STATE; + } + + ble_gatts_hvx_params_t hvx_params; + uint16_t index = 0; + + m_notif_buffer[index++] = OP_CODE_PKT_RCPT_NOTIF; + + index += uint32_encode(num_of_firmware_bytes_rcvd, &m_notif_buffer[index]); + + memset(&hvx_params, 0, sizeof(hvx_params)); + + hvx_params.handle = p_dfu->dfu_ctrl_pt_handles.value_handle; + hvx_params.type = BLE_GATT_HVX_NOTIFICATION; + hvx_params.offset = 0; + hvx_params.p_len = &index; + hvx_params.p_data = m_notif_buffer; + + return sd_ble_gatts_hvx(p_dfu->conn_handle, &hvx_params); +} + + +uint32_t ble_dfu_response_send(ble_dfu_t * p_dfu, + ble_dfu_procedure_t dfu_proc, + ble_dfu_resp_val_t resp_val) +{ + if (p_dfu == NULL) + { + return NRF_ERROR_NULL; + } + + if ((p_dfu->conn_handle == BLE_CONN_HANDLE_INVALID) || !m_is_dfu_service_initialized) + { + return NRF_ERROR_INVALID_STATE; + } + + ble_gatts_hvx_params_t hvx_params; + uint16_t index = 0; + + m_notif_buffer[index++] = OP_CODE_RESPONSE; + + // Encode the Request Op code + m_notif_buffer[index++] = (uint8_t)dfu_proc; + + // Encode the Response Value. + m_notif_buffer[index++] = (uint8_t)resp_val; + + memset(&hvx_params, 0, sizeof(hvx_params)); + + hvx_params.handle = p_dfu->dfu_ctrl_pt_handles.value_handle; + hvx_params.type = BLE_GATT_HVX_NOTIFICATION; + hvx_params.offset = 0; + hvx_params.p_len = &index; + hvx_params.p_data = m_notif_buffer; + + return sd_ble_gatts_hvx(p_dfu->conn_handle, &hvx_params); +} diff --git a/source/nordic_sdk/components/ble/ble_services/ble_dfu/ble_dfu.h b/source/nordic_sdk/components/ble/ble_services/ble_dfu/ble_dfu.h index fa20f96..7596c72 100644 --- a/source/nordic_sdk/components/ble/ble_services/ble_dfu/ble_dfu.h +++ b/source/nordic_sdk/components/ble/ble_services/ble_dfu/ble_dfu.h @@ -1,259 +1,239 @@ -/* - * Copyright (c) Nordic Semiconductor ASA - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this - * list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of other - * contributors to this software may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -/**@file - * - * @defgroup ble_sdk_srv_dfu Device Firmware Update Service - * @{ - * @ingroup ble_sdk_srv - * @brief Device Firmware Update Service - * - * @details The Device Firmware Update (DFU) service is a GATT based service that can be used for - * performing firmware updates over BLE. Note that this implementation uses vendor - * specific UUIDs for service and characteristics and is intended to demonstrate the - * firmware updates over BLE. Refer @ref ota_spec_sec and @ref - * ota_profile_section for more information on the service and profile respectively. - */ - -#ifndef BLE_DFU_H__ -#define BLE_DFU_H__ - -#include -#include "ble_gatts.h" -#include "ble_gap.h" -#include "ble.h" -#include "ble_srv_common.h" - -#define BLE_DFU_SERVICE_UUID 0x1530 /**< The UUID of the DFU Service. */ -#define BLE_DFU_PKT_CHAR_UUID 0x1532 /**< The UUID of the DFU Packet Characteristic. */ -#define BLE_DFU_CTRL_PT_UUID 0x1531 /**< The UUID of the DFU Control Point. */ -#define BLE_DFU_STATUS_REP_UUID 0x1533 /**< The UUID of the DFU Status Report Characteristic. */ -#define BLE_DFU_REV_CHAR_UUID 0x1534 /**< The UUID of the DFU Revision Characteristic. */ - -/**@brief DFU Event type. - * - * @details This enumeration contains the types of events that will be received from the DFU Service. - */ -typedef enum -{ - BLE_DFU_START, /**< The event indicating that the peer wants the application to prepare for a new firmware update. */ - BLE_DFU_RECEIVE_INIT_DATA, /**< The event indicating that the peer wants the application to prepare to receive init parameters. */ - BLE_DFU_RECEIVE_APP_DATA, /**< The event indicating that the peer wants the application to prepare to receive the new firmware image. */ - BLE_DFU_VALIDATE, /**< The event indicating that the peer wants the application to validate the newly received firmware image. */ - BLE_DFU_ACTIVATE_N_RESET, /**< The event indicating that the peer wants the application to undergo activate new firmware and restart with new valid application */ - BLE_DFU_SYS_RESET, /**< The event indicating that the peer wants the application to undergo a reset and start the currently valid application image.*/ - BLE_DFU_PKT_RCPT_NOTIF_ENABLED, /**< The event indicating that the peer has enabled packet receipt notifications. It is the responsibility of the application to call @ref ble_dfu_pkts_rcpt_notify each time the number of packets indicated by num_of_pkts field in @ref ble_dfu_evt_t is received.*/ - BLE_DFU_PKT_RCPT_NOTIF_DISABLED, /**< The event indicating that the peer has disabled the packet receipt notifications.*/ - BLE_DFU_PACKET_WRITE, /**< The event indicating that the peer has written a value to the 'DFU Packet' characteristic. The data received from the peer will be present in the @ref BLE_DFU_PACKET_WRITE element contained within @ref ble_dfu_evt_t.*/ - BLE_DFU_BYTES_RECEIVED_SEND /**< The event indicating that the peer is requesting for the number of bytes of firmware data last received by the application. It is the responsibility of the application to call @ref ble_dfu_pkts_rcpt_notify in response to this event. */ -} ble_dfu_evt_type_t; - -/**@brief DFU Procedure type. - * - * @details This enumeration contains the types of DFU procedures. - */ -typedef enum -{ - BLE_DFU_START_PROCEDURE = 1, /**< DFU Start procedure.*/ - BLE_DFU_INIT_PROCEDURE = 2, /**< DFU Initialization procedure.*/ - BLE_DFU_RECEIVE_APP_PROCEDURE = 3, /**< Firmware receiving procedure.*/ - BLE_DFU_VALIDATE_PROCEDURE = 4, /**< Firmware image validation procedure .*/ - BLE_DFU_PKT_RCPT_REQ_PROCEDURE = 8 /**< Packet receipt notification request procedure. */ -} ble_dfu_procedure_t; - -/**@brief DFU Response value type. - */ -typedef enum -{ - BLE_DFU_RESP_VAL_SUCCESS = 1, /**< Success.*/ - BLE_DFU_RESP_VAL_INVALID_STATE, /**< Invalid state.*/ - BLE_DFU_RESP_VAL_NOT_SUPPORTED, /**< Operation not supported.*/ - BLE_DFU_RESP_VAL_DATA_SIZE, /**< Data size exceeds limit.*/ - BLE_DFU_RESP_VAL_CRC_ERROR, /**< CRC Error.*/ - BLE_DFU_RESP_VAL_OPER_FAILED /**< Operation failed.*/ -} ble_dfu_resp_val_t; - - -/**@brief DFU Packet structure. - * - * @details This structure contains the value of the DFU Packet characteristic as written by the - * peer and the length of the value written. It will be filled by the DFU Service when the - * peer writes to the DFU Packet characteristic. - */ -typedef struct -{ - uint8_t len; /**< Length of the packet received. */ - uint8_t * p_data; /**< Pointer to the received packet. This will point to a word aligned memory location.*/ -} ble_dfu_pkt_write_t; - -/**@brief Packet receipt notification request structure. - * - * @details This structure contains the contents of the packet receipt notification request - * sent by the DFU Controller. - */ -typedef struct -{ - uint16_t num_of_pkts; /**< The number of packets of firmware data to be received by application before sending the next Packet Receipt Notification to the peer. */ -} ble_pkt_rcpt_notif_req_t; - -/**@brief DFU Event structure. - * - * @details This structure contains the event generated by the DFU Service based on the data - * received from the peer. - */ -typedef struct -{ - ble_dfu_evt_type_t ble_dfu_evt_type; /**< Type of the event.*/ - union - { - ble_dfu_pkt_write_t ble_dfu_pkt_write; /**< The DFU packet received. This field is when the @ref ble_dfu_evt_type field is set to @ref BLE_DFU_PACKET_WRITE.*/ - ble_pkt_rcpt_notif_req_t pkt_rcpt_notif_req; /**< Packet receipt notification request. This field is when the @ref ble_dfu_evt_type field is set to @ref BLE_DFU_PKT_RCPT_NOTIF_ENABLED.*/ - } evt; -} ble_dfu_evt_t; - -// Forward declaration of the ble_dfu_t type. -typedef struct ble_dfu_s ble_dfu_t; - -/**@brief DFU Service event handler type. */ -typedef void (*ble_dfu_evt_handler_t) (ble_dfu_t * p_dfu, ble_dfu_evt_t * p_evt); - -/**@brief DFU service structure. - * - * @details This structure contains status information related to the service. - */ -struct ble_dfu_s -{ - uint16_t conn_handle; /**< Handle of the current connection (as provided by the S110 SoftDevice). This will be BLE_CONN_HANDLE_INVALID when not in a connection. */ - uint16_t revision; /**< Handle of DFU Service (as provided by the S110 SoftDevice). */ - uint16_t service_handle; /**< Handle of DFU Service (as provided by the S110 SoftDevice). */ - uint8_t uuid_type; /**< UUID type assigned for DFU Service by the S110 SoftDevice. */ - ble_gatts_char_handles_t dfu_pkt_handles; /**< Handles related to the DFU Packet characteristic. */ - ble_gatts_char_handles_t dfu_ctrl_pt_handles; /**< Handles related to the DFU Control Point characteristic. */ - ble_gatts_char_handles_t dfu_status_rep_handles; /**< Handles related to the DFU Status Report characteristic. */ - ble_gatts_char_handles_t dfu_rev_handles; /**< Handles related to the DFU Revision characteristic. */ - ble_dfu_evt_handler_t evt_handler; /**< The event handler to be called when an event is to be sent to the application.*/ - ble_srv_error_handler_t error_handler; /**< Function to be called in case of an error. */ -}; - -/**@brief DFU service initialization structure. - * - * @details This structure contains the initialization information for the DFU Service. The - * application needs to fill this structure and pass it to the DFU Service using the - * @ref ble_dfu_init function. - */ -typedef struct -{ - uint16_t revision; /**< Revision number to be exposed by the DFU service. */ - ble_dfu_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Device Firmware Update Service. */ - ble_srv_error_handler_t error_handler; /**< Function to be called in case of an error. */ -} ble_dfu_init_t; - -/**@brief Function for handling a BLE event. - * - * @details The DFU service expects the application to call this function each time an event - * is received from the S110 SoftDevice. This function processes the event, if it is - * relevant for the DFU service and calls the DFU event handler of the application if - * necessary. - * - * @param[in] p_dfu Pointer to the DFU service structure. - * @param[in] p_ble_evt Pointer to the event received from S110 SoftDevice. - */ -void ble_dfu_on_ble_evt(ble_dfu_t * p_dfu, ble_evt_t * p_ble_evt); - -/**@brief Function for initializing the DFU service. - * - * @param[out] p_dfu Device Firmware Update service structure. This structure will have to be - * supplied by the application. It will be initialized by this function, - * and will later be used to identify the service instance. - * @param[in] p_dfu_init Information needed to initialize the service. - * - * @return NRF_SUCCESS if the DFU service and its characteristics were successfully added to the - * S110 SoftDevice. Otherwise an error code. - * This function returns NRF_ERROR_NULL if the value of evt_handler in p_dfu_init - * structure provided is NULL or if the pointers supplied as input are NULL. - */ -uint32_t ble_dfu_init(ble_dfu_t * p_dfu, ble_dfu_init_t * p_dfu_init); - -/**@brief Function for sending response to a control point command. - * - * @details This function will encode a DFU Control Point response using the given input - * parameters and will send a notification of the same to the peer. - * - * @param[in] p_dfu Pointer to the DFU service structure. - * @param[in] dfu_proc Procedure for which this response is to be sent. - * @param[in] resp_val Response value. - * - * @return NRF_SUCCESS if the DFU Service has successfully requested the S110 SoftDevice to - * send the notification. Otherwise an error code. - * This function returns NRF_ERROR_INVALID_STATE if the device is not connected to a - * peer or if the DFU service is not initialized or if the notification of the DFU - * Status Report characteristic was not enabled by the peer. It returns NRF_ERROR_NULL - * if the pointer p_dfu is NULL. - */ -uint32_t ble_dfu_response_send(ble_dfu_t * p_dfu, - ble_dfu_procedure_t dfu_proc, - ble_dfu_resp_val_t resp_val); - -/**@brief Function for notifying the peer about the number of bytes of firmware data received. - * - * @param[in] p_dfu Pointer to the DFU service structure. - * @param[in] num_of_firmware_bytes_rcvd Number of bytes. - * - * @return NRF_SUCCESS if the DFU Service has successfully requested the S110 SoftDevice to send - * the notification. Otherwise an error code. - * This function returns NRF_ERROR_INVALID_STATE if the device is not connected to a - * peer or if the DFU service is not initialized or if the notification of the DFU - * Status Report characteristic was not enabled by the peer. It returns NRF_ERROR_NULL - * if the pointer p_dfu is NULL. - */ -uint32_t ble_dfu_bytes_rcvd_report(ble_dfu_t * p_dfu, uint32_t num_of_firmware_bytes_rcvd); - -/**@brief Function for sending Packet Receipt Notification to the peer. - * - * This function will encode the number of bytes received as input parameter into a - * notification of the control point characteristic and send it to the peer. - * - * @param[in] p_dfu Pointer to the DFU service structure. - * @param[in] num_of_firmware_bytes_rcvd Number of bytes of firmware image received. - * - * @return NRF_SUCCESS if the DFU Service has successfully requested the S110 SoftDevice to send - * the notification. Otherwise an error code. - * This function returns NRF_ERROR_INVALID_STATE if the device is not connected to a - * peer or if the DFU service is not initialized or if the notification of the DFU - * Status Report characteristic was not enabled by the peer. It returns NRF_ERROR_NULL - * if the pointer p_dfu is NULL. - */ -uint32_t ble_dfu_pkts_rcpt_notify(ble_dfu_t * p_dfu, uint32_t num_of_firmware_bytes_rcvd); - -#endif // BLE_DFU_H__ - -/** @} */ +/* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved. + * + * The information contained herein is property of Nordic Semiconductor ASA. + * Terms and conditions of usage are described in detail in NORDIC + * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. + * + * Licensees are granted free, non-transferable use of the information. NO + * WARRANTY of ANY KIND is provided. This heading must NOT be removed from + * the file. + * + */ + +/**@file + * + * @defgroup ble_sdk_srv_dfu Device Firmware Update Service + * @{ + * @ingroup ble_sdk_srv + * @brief Device Firmware Update Service + * + * @details The Device Firmware Update (DFU) service is a GATT based service that can be used for + * performing firmware updates over BLE. Note that this implementation uses vendor + * specific UUIDs for service and characteristics and is intended to demonstrate the + * firmware updates over BLE. Refer @ref bledfu_transport_bleservice and @ref + * bledfu_transport_bleprofile for more information on the service and profile respectively. + */ + +#ifndef BLE_DFU_H__ +#define BLE_DFU_H__ + +#include +#include "ble_gatts.h" +#include "ble_gap.h" +#include "ble.h" +#include "ble_srv_common.h" + +#define BLE_DFU_SERVICE_UUID 0x1530 /**< The UUID of the DFU Service. */ +#define BLE_DFU_PKT_CHAR_UUID 0x1532 /**< The UUID of the DFU Packet Characteristic. */ +#define BLE_DFU_CTRL_PT_UUID 0x1531 /**< The UUID of the DFU Control Point. */ +#define BLE_DFU_STATUS_REP_UUID 0x1533 /**< The UUID of the DFU Status Report Characteristic. */ +#define BLE_DFU_REV_CHAR_UUID 0x1534 /**< The UUID of the DFU Revision Characteristic. */ + +/**@brief DFU Event type. + * + * @details This enumeration contains the types of events that will be received from the DFU Service. + */ +typedef enum +{ + BLE_DFU_START, /**< The event indicating that the peer wants the application to prepare for a new firmware update. */ + BLE_DFU_RECEIVE_INIT_DATA, /**< The event indicating that the peer wants the application to prepare to receive init parameters. */ + BLE_DFU_RECEIVE_APP_DATA, /**< The event indicating that the peer wants the application to prepare to receive the new firmware image. */ + BLE_DFU_VALIDATE, /**< The event indicating that the peer wants the application to validate the newly received firmware image. */ + BLE_DFU_ACTIVATE_N_RESET, /**< The event indicating that the peer wants the application to undergo activate new firmware and restart with new valid application */ + BLE_DFU_SYS_RESET, /**< The event indicating that the peer wants the application to undergo a reset and start the currently valid application image.*/ + BLE_DFU_PKT_RCPT_NOTIF_ENABLED, /**< The event indicating that the peer has enabled packet receipt notifications. It is the responsibility of the application to call @ref ble_dfu_pkts_rcpt_notify each time the number of packets indicated by num_of_pkts field in @ref ble_dfu_evt_t is received.*/ + BLE_DFU_PKT_RCPT_NOTIF_DISABLED, /**< The event indicating that the peer has disabled the packet receipt notifications.*/ + BLE_DFU_PACKET_WRITE, /**< The event indicating that the peer has written a value to the 'DFU Packet' characteristic. The data received from the peer will be present in the @ref BLE_DFU_PACKET_WRITE element contained within @ref ble_dfu_evt_t.*/ + BLE_DFU_BYTES_RECEIVED_SEND /**< The event indicating that the peer is requesting for the number of bytes of firmware data last received by the application. It is the responsibility of the application to call @ref ble_dfu_pkts_rcpt_notify in response to this event. */ +} ble_dfu_evt_type_t; + +/**@brief DFU Procedure type. + * + * @details This enumeration contains the types of DFU procedures. + */ +typedef enum +{ + BLE_DFU_START_PROCEDURE = 1, /**< DFU Start procedure.*/ + BLE_DFU_INIT_PROCEDURE = 2, /**< DFU Initialization procedure.*/ + BLE_DFU_RECEIVE_APP_PROCEDURE = 3, /**< Firmware receiving procedure.*/ + BLE_DFU_VALIDATE_PROCEDURE = 4, /**< Firmware image validation procedure .*/ + BLE_DFU_PKT_RCPT_REQ_PROCEDURE = 8 /**< Packet receipt notification request procedure. */ +} ble_dfu_procedure_t; + +/**@brief DFU Response value type. + */ +typedef enum +{ + BLE_DFU_RESP_VAL_SUCCESS = 1, /**< Success.*/ + BLE_DFU_RESP_VAL_INVALID_STATE, /**< Invalid state.*/ + BLE_DFU_RESP_VAL_NOT_SUPPORTED, /**< Operation not supported.*/ + BLE_DFU_RESP_VAL_DATA_SIZE, /**< Data size exceeds limit.*/ + BLE_DFU_RESP_VAL_CRC_ERROR, /**< CRC Error.*/ + BLE_DFU_RESP_VAL_OPER_FAILED /**< Operation failed.*/ +} ble_dfu_resp_val_t; + + +/**@brief DFU Packet structure. + * + * @details This structure contains the value of the DFU Packet characteristic as written by the + * peer and the length of the value written. It will be filled by the DFU Service when the + * peer writes to the DFU Packet characteristic. + */ +typedef struct +{ + uint8_t len; /**< Length of the packet received. */ + uint8_t * p_data; /**< Pointer to the received packet. This will point to a word aligned memory location.*/ +} ble_dfu_pkt_write_t; + +/**@brief Packet receipt notification request structure. + * + * @details This structure contains the contents of the packet receipt notification request + * sent by the DFU Controller. + */ +typedef struct +{ + uint16_t num_of_pkts; /**< The number of packets of firmware data to be received by application before sending the next Packet Receipt Notification to the peer. */ +} ble_pkt_rcpt_notif_req_t; + +/**@brief DFU Event structure. + * + * @details This structure contains the event generated by the DFU Service based on the data + * received from the peer. + */ +typedef struct +{ + ble_dfu_evt_type_t ble_dfu_evt_type; /**< Type of the event.*/ + union + { + ble_dfu_pkt_write_t ble_dfu_pkt_write; /**< The DFU packet received. This field is when the @ref ble_dfu_evt_type field is set to @ref BLE_DFU_PACKET_WRITE.*/ + ble_pkt_rcpt_notif_req_t pkt_rcpt_notif_req; /**< Packet receipt notification request. This field is when the @ref ble_dfu_evt_type field is set to @ref BLE_DFU_PKT_RCPT_NOTIF_ENABLED.*/ + } evt; +} ble_dfu_evt_t; + +// Forward declaration of the ble_dfu_t type. +typedef struct ble_dfu_s ble_dfu_t; + +/**@brief DFU Service event handler type. */ +typedef void (*ble_dfu_evt_handler_t) (ble_dfu_t * p_dfu, ble_dfu_evt_t * p_evt); + +/**@brief DFU service structure. + * + * @details This structure contains status information related to the service. + */ +struct ble_dfu_s +{ + uint16_t conn_handle; /**< Handle of the current connection (as provided by the S110 SoftDevice). This will be BLE_CONN_HANDLE_INVALID when not in a connection. */ + uint16_t revision; /**< Handle of DFU Service (as provided by the S110 SoftDevice). */ + uint16_t service_handle; /**< Handle of DFU Service (as provided by the S110 SoftDevice). */ + uint8_t uuid_type; /**< UUID type assigned for DFU Service by the S110 SoftDevice. */ + ble_gatts_char_handles_t dfu_pkt_handles; /**< Handles related to the DFU Packet characteristic. */ + ble_gatts_char_handles_t dfu_ctrl_pt_handles; /**< Handles related to the DFU Control Point characteristic. */ + ble_gatts_char_handles_t dfu_status_rep_handles; /**< Handles related to the DFU Status Report characteristic. */ + ble_gatts_char_handles_t dfu_rev_handles; /**< Handles related to the DFU Revision characteristic. */ + ble_dfu_evt_handler_t evt_handler; /**< The event handler to be called when an event is to be sent to the application.*/ + ble_srv_error_handler_t error_handler; /**< Function to be called in case of an error. */ +}; + +/**@brief DFU service initialization structure. + * + * @details This structure contains the initialization information for the DFU Service. The + * application needs to fill this structure and pass it to the DFU Service using the + * @ref ble_dfu_init function. + */ +typedef struct +{ + uint16_t revision; /**< Revision number to be exposed by the DFU service. */ + ble_dfu_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Device Firmware Update Service. */ + ble_srv_error_handler_t error_handler; /**< Function to be called in case of an error. */ +} ble_dfu_init_t; + +/**@brief Function for handling a BLE event. + * + * @details The DFU service expects the application to call this function each time an event + * is received from the S110 SoftDevice. This function processes the event, if it is + * relevant for the DFU service and calls the DFU event handler of the application if + * necessary. + * + * @param[in] p_dfu Pointer to the DFU service structure. + * @param[in] p_ble_evt Pointer to the event received from S110 SoftDevice. + */ +void ble_dfu_on_ble_evt(ble_dfu_t * p_dfu, ble_evt_t * p_ble_evt); + +/**@brief Function for initializing the DFU service. + * + * @param[out] p_dfu Device Firmware Update service structure. This structure will have to be + * supplied by the application. It will be initialized by this function, + * and will later be used to identify the service instance. + * @param[in] p_dfu_init Information needed to initialize the service. + * + * @return NRF_SUCCESS if the DFU service and its characteristics were successfully added to the + * S110 SoftDevice. Otherwise an error code. + * This function returns NRF_ERROR_NULL if the value of evt_handler in p_dfu_init + * structure provided is NULL or if the pointers supplied as input are NULL. + */ +uint32_t ble_dfu_init(ble_dfu_t * p_dfu, ble_dfu_init_t * p_dfu_init); + +/**@brief Function for sending response to a control point command. + * + * @details This function will encode a DFU Control Point response using the given input + * parameters and will send a notification of the same to the peer. + * + * @param[in] p_dfu Pointer to the DFU service structure. + * @param[in] dfu_proc Procedure for which this response is to be sent. + * @param[in] resp_val Response value. + * + * @return NRF_SUCCESS if the DFU Service has successfully requested the S110 SoftDevice to + * send the notification. Otherwise an error code. + * This function returns NRF_ERROR_INVALID_STATE if the device is not connected to a + * peer or if the DFU service is not initialized or if the notification of the DFU + * Status Report characteristic was not enabled by the peer. It returns NRF_ERROR_NULL + * if the pointer p_dfu is NULL. + */ +uint32_t ble_dfu_response_send(ble_dfu_t * p_dfu, + ble_dfu_procedure_t dfu_proc, + ble_dfu_resp_val_t resp_val); + +/**@brief Function for notifying the peer about the number of bytes of firmware data received. + * + * @param[in] p_dfu Pointer to the DFU service structure. + * @param[in] num_of_firmware_bytes_rcvd Number of bytes. + * + * @return NRF_SUCCESS if the DFU Service has successfully requested the S110 SoftDevice to send + * the notification. Otherwise an error code. + * This function returns NRF_ERROR_INVALID_STATE if the device is not connected to a + * peer or if the DFU service is not initialized or if the notification of the DFU + * Status Report characteristic was not enabled by the peer. It returns NRF_ERROR_NULL + * if the pointer p_dfu is NULL. + */ +uint32_t ble_dfu_bytes_rcvd_report(ble_dfu_t * p_dfu, uint32_t num_of_firmware_bytes_rcvd); + +/**@brief Function for sending Packet Receipt Notification to the peer. + * + * This function will encode the number of bytes received as input parameter into a + * notification of the control point characteristic and send it to the peer. + * + * @param[in] p_dfu Pointer to the DFU service structure. + * @param[in] num_of_firmware_bytes_rcvd Number of bytes of firmware image received. + * + * @return NRF_SUCCESS if the DFU Service has successfully requested the S110 SoftDevice to send + * the notification. Otherwise an error code. + * This function returns NRF_ERROR_INVALID_STATE if the device is not connected to a + * peer or if the DFU service is not initialized or if the notification of the DFU + * Status Report characteristic was not enabled by the peer. It returns NRF_ERROR_NULL + * if the pointer p_dfu is NULL. + */ +uint32_t ble_dfu_pkts_rcpt_notify(ble_dfu_t * p_dfu, uint32_t num_of_firmware_bytes_rcvd); + +#endif // BLE_DFU_H__ + +/** @} */ diff --git a/source/nordic_sdk/components/ble/common/ble_advdata.c b/source/nordic_sdk/components/ble/common/ble_advdata.c index 041f9fb..d73ec50 100644 --- a/source/nordic_sdk/components/ble/common/ble_advdata.c +++ b/source/nordic_sdk/components/ble/common/ble_advdata.c @@ -1,609 +1,589 @@ -/* - * Copyright (c) Nordic Semiconductor ASA - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this - * list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of other - * contributors to this software may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "ble_advdata.h" -#include "nordic_common.h" -#include "nrf_error.h" -#include "ble_gap.h" -#include "ble_srv_common.h" -#include "app_util.h" - - -// Offset from where advertisement data other than flags information can start. -#define ADV_FLAG_OFFSET 2 - -// Offset for Advertising Data. -// Offset is 2 as each Advertising Data contain 1 octet of Adveritising Data Type and -// one octet Advertising Data Length. -#define ADV_DATA_OFFSET 2 - -// NOTE: For now, Security Manager TK Value and Security Manager Out of Band Flags (OOB) are omitted -// from the advertising data. - - -static uint32_t name_encode(const ble_advdata_t * p_advdata, - uint8_t * p_encoded_data, - uint8_t * p_len) -{ - uint32_t err_code; - uint16_t rem_adv_data_len; - uint16_t actual_length; - uint8_t adv_data_format; - uint8_t adv_offset; - - adv_offset = *p_len; - - - // Check for buffer overflow. - if ((adv_offset + ADV_DATA_OFFSET > BLE_GAP_ADV_MAX_SIZE) || - ((p_advdata->short_name_len + ADV_DATA_OFFSET) > BLE_GAP_ADV_MAX_SIZE)) - { - return NRF_ERROR_DATA_SIZE; - } - actual_length = rem_adv_data_len = (BLE_GAP_ADV_MAX_SIZE - adv_offset - ADV_FLAG_OFFSET); - - // Get GAP device name and length - err_code = sd_ble_gap_device_name_get(&p_encoded_data[adv_offset + ADV_DATA_OFFSET], - &actual_length); - if (err_code != NRF_SUCCESS) - { - return err_code; - } - - // Check if device internd to use short name and it can fit available data size. - if ((p_advdata->name_type == BLE_ADVDATA_FULL_NAME) && (actual_length <= rem_adv_data_len)) - { - // Complete device name can fit, setting Complete Name in Adv Data. - adv_data_format = BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME; - rem_adv_data_len = actual_length; - } - else - { - // Else short name needs to be used. Or application has requested use of short name. - adv_data_format = BLE_GAP_AD_TYPE_SHORT_LOCAL_NAME; - - // If application has set a preference on the short name size, it needs to be considered, - // else fit what can be fit. - if ((p_advdata->short_name_len != 0) && (p_advdata->short_name_len <= rem_adv_data_len)) - { - // Short name fits available size. - rem_adv_data_len = p_advdata->short_name_len; - } - // Else whatever can fit the data buffer will be packed. - else - { - rem_adv_data_len = actual_length; - } - } - - // Complete name field in encoded data. - p_encoded_data[adv_offset++] = rem_adv_data_len + 1; - p_encoded_data[adv_offset++] = adv_data_format; - (*p_len) += (rem_adv_data_len + ADV_DATA_OFFSET); - - return NRF_SUCCESS; -} - - -static uint32_t appearance_encode(uint8_t * p_encoded_data, uint8_t * p_len) -{ - uint32_t err_code; - uint16_t appearance; - - // Check for buffer overflow. - if ((*p_len) + 4 > BLE_GAP_ADV_MAX_SIZE) - { - return NRF_ERROR_DATA_SIZE; - } - - // Get GAP appearance field. - err_code = sd_ble_gap_appearance_get(&appearance); - if (err_code != NRF_SUCCESS) - { - return err_code; - } - - // Encode Length, AD Type and Appearance. - p_encoded_data[(*p_len)++] = 3; - p_encoded_data[(*p_len)++] = BLE_GAP_AD_TYPE_APPEARANCE; - - (*p_len) += uint16_encode(appearance, &p_encoded_data[*p_len]); - - return NRF_SUCCESS; -} - - -static uint32_t tx_power_level_encode(int8_t tx_power_level, - uint8_t * p_encoded_data, - uint8_t * p_len) -{ - // Check for buffer overflow. - if ((*p_len) + 3 > BLE_GAP_ADV_MAX_SIZE) - { - return NRF_ERROR_DATA_SIZE; - } - - // Encode TX Power Level. - p_encoded_data[(*p_len)++] = 2; - p_encoded_data[(*p_len)++] = BLE_GAP_AD_TYPE_TX_POWER_LEVEL; - p_encoded_data[(*p_len)++] = (uint8_t)tx_power_level; - - return NRF_SUCCESS; -} - - -static uint32_t uuid_list_sized_encode(const ble_advdata_uuid_list_t * p_uuid_list, - uint8_t adv_type, - uint8_t uuid_size, - uint8_t * p_encoded_data, - uint8_t * p_len) -{ - int i; - bool is_heading_written = false; - uint8_t start_pos = *p_len; - - for (i = 0; i < p_uuid_list->uuid_cnt; i++) - { - uint32_t err_code; - uint8_t encoded_size; - ble_uuid_t uuid = p_uuid_list->p_uuids[i]; - - // Find encoded uuid size. - err_code = sd_ble_uuid_encode(&uuid, &encoded_size, NULL); - if (err_code != NRF_SUCCESS) - { - return err_code; - } - - // Check size. - if (encoded_size == uuid_size) - { - uint8_t heading_bytes = (is_heading_written) ? 0 : 2; - - // Check for buffer overflow - if (*p_len + encoded_size + heading_bytes > BLE_GAP_ADV_MAX_SIZE) - { - return NRF_ERROR_DATA_SIZE; - } - - if (!is_heading_written) - { - // Write AD structure heading. - (*p_len)++; - p_encoded_data[(*p_len)++] = adv_type; - is_heading_written = true; - } - - // Write UUID. - err_code = sd_ble_uuid_encode(&uuid, &encoded_size, &p_encoded_data[*p_len]); - if (err_code != NRF_SUCCESS) - { - return err_code; - } - (*p_len) += encoded_size; - } - } - - if (is_heading_written) - { - // Write length. - p_encoded_data[start_pos] = (*p_len) - (start_pos + 1); - } - - return NRF_SUCCESS; -} - - -static uint32_t uuid_list_encode(const ble_advdata_uuid_list_t * p_uuid_list, - uint8_t adv_type_16, - uint8_t adv_type_128, - uint8_t * p_encoded_data, - uint8_t * p_len) -{ - uint32_t err_code; - - // Encode 16 bit UUIDs. - err_code = uuid_list_sized_encode(p_uuid_list, - adv_type_16, - sizeof(uint16_le_t), - p_encoded_data, - p_len); - if (err_code != NRF_SUCCESS) - { - return err_code; - } - - // Encode 128 bit UUIDs. - err_code = uuid_list_sized_encode(p_uuid_list, - adv_type_128, - sizeof(ble_uuid128_t), - p_encoded_data, - p_len); - if (err_code != NRF_SUCCESS) - { - return err_code; - } - - return NRF_SUCCESS; -} - - -static uint32_t conn_int_check(const ble_advdata_conn_int_t *p_conn_int) -{ - // Check Minimum Connection Interval. - if ((p_conn_int->min_conn_interval < 0x0006) || - ( - (p_conn_int->min_conn_interval > 0x0c80) && - (p_conn_int->min_conn_interval != 0xffff) - ) - ) - { - return NRF_ERROR_INVALID_PARAM; - } - - // Check Maximum Connection Interval. - if ((p_conn_int->max_conn_interval < 0x0006) || - ( - (p_conn_int->max_conn_interval > 0x0c80) && - (p_conn_int->max_conn_interval != 0xffff) - ) - ) - { - return NRF_ERROR_INVALID_PARAM; - } - - // Make sure Minimum Connection Interval is not bigger than Maximum Connection Interval. - if ((p_conn_int->min_conn_interval != 0xffff) && - (p_conn_int->max_conn_interval != 0xffff) && - (p_conn_int->min_conn_interval > p_conn_int->max_conn_interval) - ) - { - return NRF_ERROR_INVALID_PARAM; - } - - return NRF_SUCCESS; -} - - -static uint32_t conn_int_encode(const ble_advdata_conn_int_t * p_conn_int, - uint8_t * p_encoded_data, - uint8_t * p_len) -{ - uint32_t err_code; - - // Check for buffer overflow. - if ((*p_len) + ADV_DATA_OFFSET + 2 * sizeof(uint16_le_t) > BLE_GAP_ADV_MAX_SIZE) - { - return NRF_ERROR_DATA_SIZE; - } - - // Check parameters. - err_code = conn_int_check(p_conn_int); - if (err_code != NRF_SUCCESS) - { - return err_code; - } - - // Encode Length and AD Type. - p_encoded_data[(*p_len)++] = 1 + 2 * sizeof(uint16_le_t); - p_encoded_data[(*p_len)++] = BLE_GAP_AD_TYPE_SLAVE_CONNECTION_INTERVAL_RANGE; - - // Encode Minimum and Maximum Connection Intervals. - (*p_len) += uint16_encode(p_conn_int->min_conn_interval, &p_encoded_data[*p_len]); - (*p_len) += uint16_encode(p_conn_int->max_conn_interval, &p_encoded_data[*p_len]); - - return NRF_SUCCESS; -} - - -static uint32_t manuf_specific_data_encode(const ble_advdata_manuf_data_t * p_manuf_sp_data, - uint8_t * p_encoded_data, - uint8_t * p_len) -{ - uint8_t data_size = sizeof(uint16_le_t) + p_manuf_sp_data->data.size; - - // Check for buffer overflow. - if ((*p_len) + ADV_DATA_OFFSET + data_size > BLE_GAP_ADV_MAX_SIZE) - { - return NRF_ERROR_DATA_SIZE; - } - - // Encode Length and AD Type. - p_encoded_data[(*p_len)++] = 1 + data_size; - p_encoded_data[(*p_len)++] = BLE_GAP_AD_TYPE_MANUFACTURER_SPECIFIC_DATA; - - // Encode Company Identifier. - (*p_len) += uint16_encode(p_manuf_sp_data->company_identifier, &p_encoded_data[*p_len]); - - // Encode additional manufacturer specific data. - if (p_manuf_sp_data->data.size > 0) - { - if (p_manuf_sp_data->data.p_data == NULL) - { - return NRF_ERROR_INVALID_PARAM; - } - memcpy(&p_encoded_data[*p_len], p_manuf_sp_data->data.p_data, p_manuf_sp_data->data.size); - (*p_len) += p_manuf_sp_data->data.size; - } - - return NRF_SUCCESS; -} - - -static uint32_t service_data_encode(const ble_advdata_t * p_advdata, - uint8_t * p_encoded_data, - uint8_t * p_len) -{ - uint8_t i; - - // Check parameter consistency. - if (p_advdata->p_service_data_array == NULL) - { - return NRF_ERROR_INVALID_PARAM; - } - - for (i = 0; i < p_advdata->service_data_count; i++) - { - ble_advdata_service_data_t * p_service_data; - uint8_t data_size; - - p_service_data = &p_advdata->p_service_data_array[i]; - data_size = sizeof(uint16_le_t) + p_service_data->data.size; - - // Encode Length and AD Type. - p_encoded_data[(*p_len)++] = 1 + data_size; - p_encoded_data[(*p_len)++] = BLE_GAP_AD_TYPE_SERVICE_DATA; - - // Encode service UUID. - (*p_len) += uint16_encode(p_service_data->service_uuid, &p_encoded_data[*p_len]); - - // Encode additional service data. - if (p_service_data->data.size > 0) - { - if (p_service_data->data.p_data == NULL) - { - return NRF_ERROR_INVALID_PARAM; - } - memcpy(&p_encoded_data[*p_len], p_service_data->data.p_data, p_service_data->data.size); - (*p_len) += p_service_data->data.size; - } - } - - return NRF_SUCCESS; -} - - -static uint32_t adv_data_encode(const ble_advdata_t * p_advdata, - uint8_t * p_encoded_data, - uint8_t * p_len) -{ - uint32_t err_code = NRF_SUCCESS; - - *p_len = 0; - - // Encode name. - if (p_advdata->name_type != BLE_ADVDATA_NO_NAME) - { - err_code = name_encode(p_advdata, p_encoded_data, p_len); - if (err_code != NRF_SUCCESS) - { - return err_code; - } - } - - // Encode appearance. - if (p_advdata->include_appearance) - { - err_code = appearance_encode(p_encoded_data, p_len); - if (err_code != NRF_SUCCESS) - { - return err_code; - } - } - - if(p_advdata->flags != 0 ) - { - // Encode flags. - p_encoded_data[(*p_len)++] = 1 + sizeof(uint8_t); - p_encoded_data[(*p_len)++] = BLE_GAP_AD_TYPE_FLAGS; - p_encoded_data[(*p_len)++] = p_advdata->flags; - } - - // Encode TX power level. - if (p_advdata->p_tx_power_level != NULL) - { - err_code = tx_power_level_encode(*p_advdata->p_tx_power_level, p_encoded_data, p_len); - if (err_code != NRF_SUCCESS) - { - return err_code; - } - } - - // Encode 'more available' uuid list. - if (p_advdata->uuids_more_available.uuid_cnt > 0) - { - err_code = uuid_list_encode(&p_advdata->uuids_more_available, - BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_MORE_AVAILABLE, - BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_MORE_AVAILABLE, - p_encoded_data, - p_len); - if (err_code != NRF_SUCCESS) - { - return err_code; - } - } - - // Encode 'complete' uuid list. - if (p_advdata->uuids_complete.uuid_cnt > 0) - { - err_code = uuid_list_encode(&p_advdata->uuids_complete, - BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_COMPLETE, - BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_COMPLETE, - p_encoded_data, - p_len); - if (err_code != NRF_SUCCESS) - { - return err_code; - } - } - - // Encode 'solicited service' uuid list. - if (p_advdata->uuids_solicited.uuid_cnt > 0) - { - err_code = uuid_list_encode(&p_advdata->uuids_solicited, - BLE_GAP_AD_TYPE_SOLICITED_SERVICE_UUIDS_16BIT, - BLE_GAP_AD_TYPE_SOLICITED_SERVICE_UUIDS_128BIT, - p_encoded_data, - p_len); - if (err_code != NRF_SUCCESS) - { - return err_code; - } - } - - // Encode Slave Connection Interval Range. - if (p_advdata->p_slave_conn_int != NULL) - { - err_code = conn_int_encode(p_advdata->p_slave_conn_int, p_encoded_data, p_len); - if (err_code != NRF_SUCCESS) - { - return err_code; - } - } - - // Encode Manufacturer Specific Data. - if (p_advdata->p_manuf_specific_data != NULL) - { - err_code = manuf_specific_data_encode(p_advdata->p_manuf_specific_data, - p_encoded_data, - p_len); - if (err_code != NRF_SUCCESS) - { - return err_code; - } - } - - // Encode Service Data. - if (p_advdata->service_data_count > 0) - { - err_code = service_data_encode(p_advdata, p_encoded_data, p_len); - if (err_code != NRF_SUCCESS) - { - return err_code; - } - } - - return err_code; -} - - -static uint32_t advdata_check(const ble_advdata_t * p_advdata) -{ - // Flags must be included in advertising data, and the BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED flag must be set. - if ( - ((p_advdata->flags & BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED) == 0) - ) - { - return NRF_ERROR_INVALID_PARAM; - } - - return NRF_SUCCESS; -} - - -static uint32_t srdata_check(const ble_advdata_t * p_srdata) -{ - // Flags shall not be included in the scan response data. - if (p_srdata->flags) - { - return NRF_ERROR_INVALID_PARAM; - } - - return NRF_SUCCESS; -} - - -uint32_t ble_advdata_set(const ble_advdata_t * p_advdata, const ble_advdata_t * p_srdata) -{ - uint32_t err_code; - uint8_t len_advdata = 0; - uint8_t len_srdata = 0; - uint8_t encoded_advdata[BLE_GAP_ADV_MAX_SIZE]; - uint8_t encoded_srdata[BLE_GAP_ADV_MAX_SIZE]; - uint8_t * p_encoded_advdata; - uint8_t * p_encoded_srdata; - - // Encode advertising data (if supplied). - if (p_advdata != NULL) - { - err_code = advdata_check(p_advdata); - if (err_code != NRF_SUCCESS) - { - return err_code; - } - - err_code = adv_data_encode(p_advdata, encoded_advdata, &len_advdata); - if (err_code != NRF_SUCCESS) - { - return err_code; - } - p_encoded_advdata = encoded_advdata; - } - else - { - p_encoded_advdata = NULL; - } - - // Encode scan response data (if supplied). - if (p_srdata != NULL) - { - err_code = srdata_check(p_srdata); - if (err_code != NRF_SUCCESS) - { - return err_code; - } - - err_code = adv_data_encode(p_srdata, encoded_srdata, &len_srdata); - if (err_code != NRF_SUCCESS) - { - return err_code; - } - p_encoded_srdata = encoded_srdata; - } - else - { - p_encoded_srdata = NULL; - } - - // Pass encoded advertising data and/or scan response data to the stack. - return sd_ble_gap_adv_data_set(p_encoded_advdata, len_advdata, p_encoded_srdata, len_srdata); -} +/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. + * + * The information contained herein is property of Nordic Semiconductor ASA. + * Terms and conditions of usage are described in detail in NORDIC + * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. + * + * Licensees are granted free, non-transferable use of the information. NO + * WARRANTY of ANY KIND is provided. This heading must NOT be removed from + * the file. + * + */ + +#include "ble_advdata.h" +#include "nordic_common.h" +#include "nrf_error.h" +#include "ble_gap.h" +#include "ble_srv_common.h" +#include "app_util.h" + + +// Offset from where advertisement data other than flags information can start. +#define ADV_FLAG_OFFSET 2 + +// Offset for Advertising Data. +// Offset is 2 as each Advertising Data contain 1 octet of Adveritising Data Type and +// one octet Advertising Data Length. +#define ADV_DATA_OFFSET 2 + +// NOTE: For now, Security Manager TK Value and Security Manager Out of Band Flags (OOB) are omitted +// from the advertising data. + + +static uint32_t name_encode(const ble_advdata_t * p_advdata, + uint8_t * p_encoded_data, + uint8_t * p_len) +{ + uint32_t err_code; + uint16_t rem_adv_data_len; + uint16_t actual_length; + uint8_t adv_data_format; + uint8_t adv_offset; + + adv_offset = *p_len; + + + // Check for buffer overflow. + if ((adv_offset + ADV_DATA_OFFSET > BLE_GAP_ADV_MAX_SIZE) || + ((p_advdata->short_name_len + ADV_DATA_OFFSET) > BLE_GAP_ADV_MAX_SIZE)) + { + return NRF_ERROR_DATA_SIZE; + } + actual_length = rem_adv_data_len = (BLE_GAP_ADV_MAX_SIZE - adv_offset - ADV_FLAG_OFFSET); + + // Get GAP device name and length + err_code = sd_ble_gap_device_name_get(&p_encoded_data[adv_offset + ADV_DATA_OFFSET], + &actual_length); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + + // Check if device internd to use short name and it can fit available data size. + if ((p_advdata->name_type == BLE_ADVDATA_FULL_NAME) && (actual_length <= rem_adv_data_len)) + { + // Complete device name can fit, setting Complete Name in Adv Data. + adv_data_format = BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME; + rem_adv_data_len = actual_length; + } + else + { + // Else short name needs to be used. Or application has requested use of short name. + adv_data_format = BLE_GAP_AD_TYPE_SHORT_LOCAL_NAME; + + // If application has set a preference on the short name size, it needs to be considered, + // else fit what can be fit. + if ((p_advdata->short_name_len != 0) && (p_advdata->short_name_len <= rem_adv_data_len)) + { + // Short name fits available size. + rem_adv_data_len = p_advdata->short_name_len; + } + // Else whatever can fit the data buffer will be packed. + else + { + rem_adv_data_len = actual_length; + } + } + + // Complete name field in encoded data. + p_encoded_data[adv_offset++] = rem_adv_data_len + 1; + p_encoded_data[adv_offset++] = adv_data_format; + (*p_len) += (rem_adv_data_len + ADV_DATA_OFFSET); + + return NRF_SUCCESS; +} + + +static uint32_t appearance_encode(uint8_t * p_encoded_data, uint8_t * p_len) +{ + uint32_t err_code; + uint16_t appearance; + + // Check for buffer overflow. + if ((*p_len) + 4 > BLE_GAP_ADV_MAX_SIZE) + { + return NRF_ERROR_DATA_SIZE; + } + + // Get GAP appearance field. + err_code = sd_ble_gap_appearance_get(&appearance); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + + // Encode Length, AD Type and Appearance. + p_encoded_data[(*p_len)++] = 3; + p_encoded_data[(*p_len)++] = BLE_GAP_AD_TYPE_APPEARANCE; + + (*p_len) += uint16_encode(appearance, &p_encoded_data[*p_len]); + + return NRF_SUCCESS; +} + + +static uint32_t tx_power_level_encode(int8_t tx_power_level, + uint8_t * p_encoded_data, + uint8_t * p_len) +{ + // Check for buffer overflow. + if ((*p_len) + 3 > BLE_GAP_ADV_MAX_SIZE) + { + return NRF_ERROR_DATA_SIZE; + } + + // Encode TX Power Level. + p_encoded_data[(*p_len)++] = 2; + p_encoded_data[(*p_len)++] = BLE_GAP_AD_TYPE_TX_POWER_LEVEL; + p_encoded_data[(*p_len)++] = (uint8_t)tx_power_level; + + return NRF_SUCCESS; +} + + +static uint32_t uuid_list_sized_encode(const ble_advdata_uuid_list_t * p_uuid_list, + uint8_t adv_type, + uint8_t uuid_size, + uint8_t * p_encoded_data, + uint8_t * p_len) +{ + int i; + bool is_heading_written = false; + uint8_t start_pos = *p_len; + + for (i = 0; i < p_uuid_list->uuid_cnt; i++) + { + uint32_t err_code; + uint8_t encoded_size; + ble_uuid_t uuid = p_uuid_list->p_uuids[i]; + + // Find encoded uuid size. + err_code = sd_ble_uuid_encode(&uuid, &encoded_size, NULL); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + + // Check size. + if (encoded_size == uuid_size) + { + uint8_t heading_bytes = (is_heading_written) ? 0 : 2; + + // Check for buffer overflow + if (*p_len + encoded_size + heading_bytes > BLE_GAP_ADV_MAX_SIZE) + { + return NRF_ERROR_DATA_SIZE; + } + + if (!is_heading_written) + { + // Write AD structure heading. + (*p_len)++; + p_encoded_data[(*p_len)++] = adv_type; + is_heading_written = true; + } + + // Write UUID. + err_code = sd_ble_uuid_encode(&uuid, &encoded_size, &p_encoded_data[*p_len]); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + (*p_len) += encoded_size; + } + } + + if (is_heading_written) + { + // Write length. + p_encoded_data[start_pos] = (*p_len) - (start_pos + 1); + } + + return NRF_SUCCESS; +} + + +static uint32_t uuid_list_encode(const ble_advdata_uuid_list_t * p_uuid_list, + uint8_t adv_type_16, + uint8_t adv_type_128, + uint8_t * p_encoded_data, + uint8_t * p_len) +{ + uint32_t err_code; + + // Encode 16 bit UUIDs. + err_code = uuid_list_sized_encode(p_uuid_list, + adv_type_16, + sizeof(uint16_le_t), + p_encoded_data, + p_len); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + + // Encode 128 bit UUIDs. + err_code = uuid_list_sized_encode(p_uuid_list, + adv_type_128, + sizeof(ble_uuid128_t), + p_encoded_data, + p_len); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + + return NRF_SUCCESS; +} + + +static uint32_t conn_int_check(const ble_advdata_conn_int_t *p_conn_int) +{ + // Check Minimum Connection Interval. + if ((p_conn_int->min_conn_interval < 0x0006) || + ( + (p_conn_int->min_conn_interval > 0x0c80) && + (p_conn_int->min_conn_interval != 0xffff) + ) + ) + { + return NRF_ERROR_INVALID_PARAM; + } + + // Check Maximum Connection Interval. + if ((p_conn_int->max_conn_interval < 0x0006) || + ( + (p_conn_int->max_conn_interval > 0x0c80) && + (p_conn_int->max_conn_interval != 0xffff) + ) + ) + { + return NRF_ERROR_INVALID_PARAM; + } + + // Make sure Minimum Connection Interval is not bigger than Maximum Connection Interval. + if ((p_conn_int->min_conn_interval != 0xffff) && + (p_conn_int->max_conn_interval != 0xffff) && + (p_conn_int->min_conn_interval > p_conn_int->max_conn_interval) + ) + { + return NRF_ERROR_INVALID_PARAM; + } + + return NRF_SUCCESS; +} + + +static uint32_t conn_int_encode(const ble_advdata_conn_int_t * p_conn_int, + uint8_t * p_encoded_data, + uint8_t * p_len) +{ + uint32_t err_code; + + // Check for buffer overflow. + if ((*p_len) + ADV_DATA_OFFSET + 2 * sizeof(uint16_le_t) > BLE_GAP_ADV_MAX_SIZE) + { + return NRF_ERROR_DATA_SIZE; + } + + // Check parameters. + err_code = conn_int_check(p_conn_int); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + + // Encode Length and AD Type. + p_encoded_data[(*p_len)++] = 1 + 2 * sizeof(uint16_le_t); + p_encoded_data[(*p_len)++] = BLE_GAP_AD_TYPE_SLAVE_CONNECTION_INTERVAL_RANGE; + + // Encode Minimum and Maximum Connection Intervals. + (*p_len) += uint16_encode(p_conn_int->min_conn_interval, &p_encoded_data[*p_len]); + (*p_len) += uint16_encode(p_conn_int->max_conn_interval, &p_encoded_data[*p_len]); + + return NRF_SUCCESS; +} + + +static uint32_t manuf_specific_data_encode(const ble_advdata_manuf_data_t * p_manuf_sp_data, + uint8_t * p_encoded_data, + uint8_t * p_len) +{ + uint8_t data_size = sizeof(uint16_le_t) + p_manuf_sp_data->data.size; + + // Check for buffer overflow. + if ((*p_len) + ADV_DATA_OFFSET + data_size > BLE_GAP_ADV_MAX_SIZE) + { + return NRF_ERROR_DATA_SIZE; + } + + // Encode Length and AD Type. + p_encoded_data[(*p_len)++] = 1 + data_size; + p_encoded_data[(*p_len)++] = BLE_GAP_AD_TYPE_MANUFACTURER_SPECIFIC_DATA; + + // Encode Company Identifier. + (*p_len) += uint16_encode(p_manuf_sp_data->company_identifier, &p_encoded_data[*p_len]); + + // Encode additional manufacturer specific data. + if (p_manuf_sp_data->data.size > 0) + { + if (p_manuf_sp_data->data.p_data == NULL) + { + return NRF_ERROR_INVALID_PARAM; + } + memcpy(&p_encoded_data[*p_len], p_manuf_sp_data->data.p_data, p_manuf_sp_data->data.size); + (*p_len) += p_manuf_sp_data->data.size; + } + + return NRF_SUCCESS; +} + + +static uint32_t service_data_encode(const ble_advdata_t * p_advdata, + uint8_t * p_encoded_data, + uint8_t * p_len) +{ + uint8_t i; + + // Check parameter consistency. + if (p_advdata->p_service_data_array == NULL) + { + return NRF_ERROR_INVALID_PARAM; + } + + for (i = 0; i < p_advdata->service_data_count; i++) + { + ble_advdata_service_data_t * p_service_data; + uint8_t data_size; + + p_service_data = &p_advdata->p_service_data_array[i]; + data_size = sizeof(uint16_le_t) + p_service_data->data.size; + + // Encode Length and AD Type. + p_encoded_data[(*p_len)++] = 1 + data_size; + p_encoded_data[(*p_len)++] = BLE_GAP_AD_TYPE_SERVICE_DATA; + + // Encode service UUID. + (*p_len) += uint16_encode(p_service_data->service_uuid, &p_encoded_data[*p_len]); + + // Encode additional service data. + if (p_service_data->data.size > 0) + { + if (p_service_data->data.p_data == NULL) + { + return NRF_ERROR_INVALID_PARAM; + } + memcpy(&p_encoded_data[*p_len], p_service_data->data.p_data, p_service_data->data.size); + (*p_len) += p_service_data->data.size; + } + } + + return NRF_SUCCESS; +} + + +static uint32_t adv_data_encode(const ble_advdata_t * p_advdata, + uint8_t * p_encoded_data, + uint8_t * p_len) +{ + uint32_t err_code = NRF_SUCCESS; + + *p_len = 0; + + // Encode name. + if (p_advdata->name_type != BLE_ADVDATA_NO_NAME) + { + err_code = name_encode(p_advdata, p_encoded_data, p_len); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + } + + // Encode appearance. + if (p_advdata->include_appearance) + { + err_code = appearance_encode(p_encoded_data, p_len); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + } + + if(p_advdata->flags != 0 ) + { + // Encode flags. + p_encoded_data[(*p_len)++] = 1 + sizeof(uint8_t); + p_encoded_data[(*p_len)++] = BLE_GAP_AD_TYPE_FLAGS; + p_encoded_data[(*p_len)++] = p_advdata->flags; + } + + // Encode TX power level. + if (p_advdata->p_tx_power_level != NULL) + { + err_code = tx_power_level_encode(*p_advdata->p_tx_power_level, p_encoded_data, p_len); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + } + + // Encode 'more available' uuid list. + if (p_advdata->uuids_more_available.uuid_cnt > 0) + { + err_code = uuid_list_encode(&p_advdata->uuids_more_available, + BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_MORE_AVAILABLE, + BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_MORE_AVAILABLE, + p_encoded_data, + p_len); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + } + + // Encode 'complete' uuid list. + if (p_advdata->uuids_complete.uuid_cnt > 0) + { + err_code = uuid_list_encode(&p_advdata->uuids_complete, + BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_COMPLETE, + BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_COMPLETE, + p_encoded_data, + p_len); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + } + + // Encode 'solicited service' uuid list. + if (p_advdata->uuids_solicited.uuid_cnt > 0) + { + err_code = uuid_list_encode(&p_advdata->uuids_solicited, + BLE_GAP_AD_TYPE_SOLICITED_SERVICE_UUIDS_16BIT, + BLE_GAP_AD_TYPE_SOLICITED_SERVICE_UUIDS_128BIT, + p_encoded_data, + p_len); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + } + + // Encode Slave Connection Interval Range. + if (p_advdata->p_slave_conn_int != NULL) + { + err_code = conn_int_encode(p_advdata->p_slave_conn_int, p_encoded_data, p_len); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + } + + // Encode Manufacturer Specific Data. + if (p_advdata->p_manuf_specific_data != NULL) + { + err_code = manuf_specific_data_encode(p_advdata->p_manuf_specific_data, + p_encoded_data, + p_len); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + } + + // Encode Service Data. + if (p_advdata->service_data_count > 0) + { + err_code = service_data_encode(p_advdata, p_encoded_data, p_len); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + } + + return err_code; +} + + +static uint32_t advdata_check(const ble_advdata_t * p_advdata) +{ + // Flags must be included in advertising data, and the BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED flag must be set. + if ( + ((p_advdata->flags & BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED) == 0) + ) + { + return NRF_ERROR_INVALID_PARAM; + } + + return NRF_SUCCESS; +} + + +static uint32_t srdata_check(const ble_advdata_t * p_srdata) +{ + // Flags shall not be included in the scan response data. + if (p_srdata->flags) + { + return NRF_ERROR_INVALID_PARAM; + } + + return NRF_SUCCESS; +} + + +uint32_t ble_advdata_set(const ble_advdata_t * p_advdata, const ble_advdata_t * p_srdata) +{ + uint32_t err_code; + uint8_t len_advdata = 0; + uint8_t len_srdata = 0; + uint8_t encoded_advdata[BLE_GAP_ADV_MAX_SIZE]; + uint8_t encoded_srdata[BLE_GAP_ADV_MAX_SIZE]; + uint8_t * p_encoded_advdata; + uint8_t * p_encoded_srdata; + + // Encode advertising data (if supplied). + if (p_advdata != NULL) + { + err_code = advdata_check(p_advdata); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + + err_code = adv_data_encode(p_advdata, encoded_advdata, &len_advdata); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + p_encoded_advdata = encoded_advdata; + } + else + { + p_encoded_advdata = NULL; + } + + // Encode scan response data (if supplied). + if (p_srdata != NULL) + { + err_code = srdata_check(p_srdata); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + + err_code = adv_data_encode(p_srdata, encoded_srdata, &len_srdata); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + p_encoded_srdata = encoded_srdata; + } + else + { + p_encoded_srdata = NULL; + } + + // Pass encoded advertising data and/or scan response data to the stack. + return sd_ble_gap_adv_data_set(p_encoded_advdata, len_advdata, p_encoded_srdata, len_srdata); +} diff --git a/source/nordic_sdk/components/ble/common/ble_advdata.h b/source/nordic_sdk/components/ble/common/ble_advdata.h old mode 100755 new mode 100644 index f8ae3e3..0dabb0e --- a/source/nordic_sdk/components/ble/common/ble_advdata.h +++ b/source/nordic_sdk/components/ble/common/ble_advdata.h @@ -1,133 +1,113 @@ -/* - * Copyright (c) Nordic Semiconductor ASA - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this - * list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of other - * contributors to this software may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -/** @file - * - * @defgroup ble_sdk_lib_advdata Advertising Data Encoder - * @{ - * @ingroup ble_sdk_lib - * @brief Function for encoding the advertising data and/or scan response data, and passing them to - * the stack. - */ - -#ifndef BLE_ADVDATA_H__ -#define BLE_ADVDATA_H__ - -#include -#include -#include -#include "ble.h" -#include "app_util.h" - -/**@brief Advertising data name type. This contains the options available for the device name inside - * the advertising data. */ -typedef enum -{ - BLE_ADVDATA_NO_NAME, /**< Include no device name in advertising data. */ - BLE_ADVDATA_SHORT_NAME, /**< Include short device name in advertising data. */ - BLE_ADVDATA_FULL_NAME /**< Include full device name in advertising data. */ -} ble_advdata_name_type_t; - -/**@brief UUID list type. */ -typedef struct -{ - uint16_t uuid_cnt; /**< Number of UUID entries. */ - ble_uuid_t * p_uuids; /**< Pointer to UUID array entries. */ -} ble_advdata_uuid_list_t; - -/**@brief Connection interval range structure. */ -typedef struct -{ - uint16_t min_conn_interval; /**< Minimum Connection Interval, in units of 1.25ms, range 6 to 3200 (i.e. 7.5ms to 4s). */ - uint16_t max_conn_interval; /**< Maximum Connection Interval, in units of 1.25ms, range 6 to 3200 (i.e. 7.5ms to 4s). Value of 0xFFFF indicates no specific maximum. */ -} ble_advdata_conn_int_t; - -/**@brief Manufacturer specific data structure. */ -typedef struct -{ - uint16_t company_identifier; /**< Company Identifier Code. */ - uint8_array_t data; /**< Additional manufacturer specific data. */ -} ble_advdata_manuf_data_t; - -/**@brief Service data structure. */ -typedef struct -{ - uint16_t service_uuid; /**< Service UUID. */ - uint8_array_t data; /**< Additional service data. */ -} ble_advdata_service_data_t; - -/**@brief Advertising data structure. This contains all options and data needed for encoding and - * setting the advertising data. */ -typedef struct -{ - ble_advdata_name_type_t name_type; /**< Type of device name. */ - uint8_t short_name_len; /**< Length of short device name (if short type is specified). */ - bool include_appearance; /**< Determines if Appearance shall be included. */ - uint8_t flags; /**< Advertising data Flags field. */ - int8_t * p_tx_power_level; /**< TX Power Level field. */ - ble_advdata_uuid_list_t uuids_more_available; /**< List of UUIDs in the 'More Available' list. */ - ble_advdata_uuid_list_t uuids_complete; /**< List of UUIDs in the 'Complete' list. */ - ble_advdata_uuid_list_t uuids_solicited; /**< List of solcited UUIDs. */ - ble_advdata_conn_int_t * p_slave_conn_int; /**< Slave Connection Interval Range. */ - ble_advdata_manuf_data_t * p_manuf_specific_data; /**< Manufacturer specific data. */ - ble_advdata_service_data_t * p_service_data_array; /**< Array of Service data structures. */ - uint8_t service_data_count; /**< Number of Service data structures. */ -} ble_advdata_t; - -/**@brief Function for encoding and setting the advertising data and/or scan response data. - * - * @details This function encodes advertising data and/or scan response data based on the selections - * in the supplied structures, and passes the encoded data to the stack. - * - * @param[in] p_advdata Structure for specifying the content of the advertising data. - * Set to NULL if advertising data is not to be set. - * @param[in] p_srdata Structure for specifying the content of the scan response data. - * Set to NULL if scan response data is not to be set. - * - * @return NRF_SUCCESS on success, NRF_ERROR_DATA_SIZE if not all the requested data could fit - * into the advertising packet. The maximum size of the advertisement packet is @ref - * BLE_GAP_ADV_MAX_SIZE. - * - * @warning This API may override application's request to use the long name and use a short name - * instead. This truncation will occur in case the long name does not fit advertisement data size. - * Application is permitted to specify a preferred short name length in case truncation is required. - * For example, if the complete device name is ABCD_HRMonitor, application can specify short name - * length to 8 such that short device name appears as ABCD_HRM instead of ABCD_HRMo or ABCD_HRMoni - * etc if available size for short name is 9 or 12 respectively to have more apporpriate short name. - * However, it should be noted that this is just a preference that application can specify and - * if the preference too large to fit in Advertisement Data, this can be further truncated. - */ -uint32_t ble_advdata_set(const ble_advdata_t * p_advdata, const ble_advdata_t * p_srdata); - -#endif // BLE_ADVDATA_H__ - -/** @} */ +/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. + * + * The information contained herein is property of Nordic Semiconductor ASA. + * Terms and conditions of usage are described in detail in NORDIC + * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. + * + * Licensees are granted free, non-transferable use of the information. NO + * WARRANTY of ANY KIND is provided. This heading must NOT be removed from + * the file. + * + */ + +/** @file + * + * @defgroup ble_sdk_lib_advdata Advertising Data Encoder + * @{ + * @ingroup ble_sdk_lib + * @brief Function for encoding the advertising data and/or scan response data, and passing them to + * the stack. + */ + +#ifndef BLE_ADVDATA_H__ +#define BLE_ADVDATA_H__ + +#include +#include +#include +#include "ble.h" +#include "app_util.h" + +/**@brief Advertising data name type. This contains the options available for the device name inside + * the advertising data. */ +typedef enum +{ + BLE_ADVDATA_NO_NAME, /**< Include no device name in advertising data. */ + BLE_ADVDATA_SHORT_NAME, /**< Include short device name in advertising data. */ + BLE_ADVDATA_FULL_NAME /**< Include full device name in advertising data. */ +} ble_advdata_name_type_t; + +/**@brief UUID list type. */ +typedef struct +{ + uint16_t uuid_cnt; /**< Number of UUID entries. */ + ble_uuid_t * p_uuids; /**< Pointer to UUID array entries. */ +} ble_advdata_uuid_list_t; + +/**@brief Connection interval range structure. */ +typedef struct +{ + uint16_t min_conn_interval; /**< Minimum Connection Interval, in units of 1.25ms, range 6 to 3200 (i.e. 7.5ms to 4s). */ + uint16_t max_conn_interval; /**< Maximum Connection Interval, in units of 1.25ms, range 6 to 3200 (i.e. 7.5ms to 4s). Value of 0xFFFF indicates no specific maximum. */ +} ble_advdata_conn_int_t; + +/**@brief Manufacturer specific data structure. */ +typedef struct +{ + uint16_t company_identifier; /**< Company Identifier Code. */ + uint8_array_t data; /**< Additional manufacturer specific data. */ +} ble_advdata_manuf_data_t; + +/**@brief Service data structure. */ +typedef struct +{ + uint16_t service_uuid; /**< Service UUID. */ + uint8_array_t data; /**< Additional service data. */ +} ble_advdata_service_data_t; + +/**@brief Advertising data structure. This contains all options and data needed for encoding and + * setting the advertising data. */ +typedef struct +{ + ble_advdata_name_type_t name_type; /**< Type of device name. */ + uint8_t short_name_len; /**< Length of short device name (if short type is specified). */ + bool include_appearance; /**< Determines if Appearance shall be included. */ + uint8_t flags; /**< Advertising data Flags field. */ + int8_t * p_tx_power_level; /**< TX Power Level field. */ + ble_advdata_uuid_list_t uuids_more_available; /**< List of UUIDs in the 'More Available' list. */ + ble_advdata_uuid_list_t uuids_complete; /**< List of UUIDs in the 'Complete' list. */ + ble_advdata_uuid_list_t uuids_solicited; /**< List of solcited UUIDs. */ + ble_advdata_conn_int_t * p_slave_conn_int; /**< Slave Connection Interval Range. */ + ble_advdata_manuf_data_t * p_manuf_specific_data; /**< Manufacturer specific data. */ + ble_advdata_service_data_t * p_service_data_array; /**< Array of Service data structures. */ + uint8_t service_data_count; /**< Number of Service data structures. */ +} ble_advdata_t; + +/**@brief Function for encoding and setting the advertising data and/or scan response data. + * + * @details This function encodes advertising data and/or scan response data based on the selections + * in the supplied structures, and passes the encoded data to the stack. + * + * @param[in] p_advdata Structure for specifying the content of the advertising data. + * Set to NULL if advertising data is not to be set. + * @param[in] p_srdata Structure for specifying the content of the scan response data. + * Set to NULL if scan response data is not to be set. + * + * @return NRF_SUCCESS on success, NRF_ERROR_DATA_SIZE if not all the requested data could fit + * into the advertising packet. The maximum size of the advertisement packet is @ref + * BLE_GAP_ADV_MAX_SIZE. + * + * @warning This API may override application's request to use the long name and use a short name + * instead. This truncation will occur in case the long name does not fit advertisement data size. + * Application is permitted to specify a preferred short name length in case truncation is required. + * For example, if the complete device name is ABCD_HRMonitor, application can specify short name + * length to 8 such that short device name appears as ABCD_HRM instead of ABCD_HRMo or ABCD_HRMoni + * etc if available size for short name is 9 or 12 respectively to have more apporpriate short name. + * However, it should be noted that this is just a preference that application can specify and + * if the preference too large to fit in Advertisement Data, this can be further truncated. + */ +uint32_t ble_advdata_set(const ble_advdata_t * p_advdata, const ble_advdata_t * p_srdata); + +#endif // BLE_ADVDATA_H__ + +/** @} */ diff --git a/source/nordic_sdk/components/ble/common/ble_advdata_parser.c b/source/nordic_sdk/components/ble/common/ble_advdata_parser.c index fcbac06..9b9f7df 100644 --- a/source/nordic_sdk/components/ble/common/ble_advdata_parser.c +++ b/source/nordic_sdk/components/ble/common/ble_advdata_parser.c @@ -1,56 +1,24 @@ -/* - * Copyright (c) Nordic Semiconductor ASA - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this - * list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of other - * contributors to this software may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "ble_advdata_parser.h" - -uint32_t ble_advdata_parser_field_find(uint8_t type, - uint8_t * p_advdata, - uint8_t * len, - uint8_t ** pp_field_data) -{ - uint32_t index = 0; - - while (index < *len) - { - uint8_t field_length = p_advdata[index]; - uint8_t field_type = p_advdata[index + 1]; - - if (field_type == type) - { - *pp_field_data = &p_advdata[index + 2]; - *len = field_length - 1; - return NRF_SUCCESS; - } - index += field_length + 1; - } - return NRF_ERROR_NOT_FOUND; -} +#include "ble_advdata_parser.h" + +uint32_t ble_advdata_parser_field_find(uint8_t type, + uint8_t * p_advdata, + uint8_t * len, + uint8_t ** pp_field_data) +{ + uint32_t index = 0; + + while (index < *len) + { + uint8_t field_length = p_advdata[index]; + uint8_t field_type = p_advdata[index + 1]; + + if (field_type == type) + { + *pp_field_data = &p_advdata[index + 2]; + *len = field_length - 1; + return NRF_SUCCESS; + } + index += field_length + 1; + } + return NRF_ERROR_NOT_FOUND; +} diff --git a/source/nordic_sdk/components/ble/common/ble_advdata_parser.h b/source/nordic_sdk/components/ble/common/ble_advdata_parser.h old mode 100755 new mode 100644 index f15a0c5..7117c36 --- a/source/nordic_sdk/components/ble/common/ble_advdata_parser.h +++ b/source/nordic_sdk/components/ble/common/ble_advdata_parser.h @@ -1,41 +1,9 @@ -/* - * Copyright (c) Nordic Semiconductor ASA - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this - * list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of other - * contributors to this software may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef BLE_ADVDATA_PARSER_H_ -#define BLE_ADVDATA_PARSER_H_ - -#include "ble_advdata.h" - -uint32_t ble_advdata_parse(uint8_t * p_data, uint8_t len, ble_advdata_t * advdata); -uint32_t ble_advdata_parser_field_find(uint8_t type, uint8_t * p_advdata, uint8_t * len, uint8_t ** pp_field_data); - -#endif +#ifndef BLE_ADVDATA_PARSER_H_ +#define BLE_ADVDATA_PARSER_H_ + +#include "ble_advdata.h" + +uint32_t ble_advdata_parse(uint8_t * p_data, uint8_t len, ble_advdata_t * advdata); +uint32_t ble_advdata_parser_field_find(uint8_t type, uint8_t * p_advdata, uint8_t * len, uint8_t ** pp_field_data); + +#endif diff --git a/source/nordic_sdk/components/ble/common/ble_conn_params.cpp b/source/nordic_sdk/components/ble/common/ble_conn_params.c similarity index 78% rename from source/nordic_sdk/components/ble/common/ble_conn_params.cpp rename to source/nordic_sdk/components/ble/common/ble_conn_params.c index 6c62171..df50894 100644 --- a/source/nordic_sdk/components/ble/common/ble_conn_params.cpp +++ b/source/nordic_sdk/components/ble/common/ble_conn_params.c @@ -1,381 +1,323 @@ -/* - * Copyright (c) Nordic Semiconductor ASA - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this - * list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of other - * contributors to this software may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "ble_conn_params.h" -#include -#include "nordic_common.h" -#include "ble_hci.h" -#include "ble_srv_common.h" -#include "app_util.h" - -#ifdef USE_APP_TIMER -#include "app_timer.h" -#else -#include "mbed.h" -#endif - -static ble_conn_params_init_t m_conn_params_config; /**< Configuration as specified by the application. */ -static ble_gap_conn_params_t m_preferred_conn_params; /**< Connection parameters preferred by the application. */ -static uint8_t m_update_count; /**< Number of Connection Parameter Update messages that has currently been sent. */ -static uint16_t m_conn_handle; /**< Current connection handle. */ -static ble_gap_conn_params_t m_current_conn_params; /**< Connection parameters received in the most recent Connect event. */ -#ifdef USE_APP_TIMER -static app_timer_id_t m_conn_params_timer_id; /**< Connection parameters timer. */ -#else -static Ticker m_conn_params_timer; -#endif - -static bool m_change_param = false; - -static bool is_conn_params_ok(ble_gap_conn_params_t * p_conn_params) -{ - // Check if interval is within the acceptable range. - // NOTE: Using max_conn_interval in the received event data because this contains - // the client's connection interval. - if ( - (p_conn_params->max_conn_interval >= m_preferred_conn_params.min_conn_interval) - && - (p_conn_params->max_conn_interval <= m_preferred_conn_params.max_conn_interval) - ) - { - return true; - } - else - { - return false; - } -} - - -#ifdef USE_APP_TIMER -static void update_timeout_handler(void * p_context) -{ - UNUSED_PARAMETER(p_context); - -#else /* #if !USE_APP_TIMER */ -static void update_timeout_handler(void) -{ - m_conn_params_timer.detach(); /* this is supposed to be a single-shot timer callback */ -#endif /* #if !USE_APP_TIMER */ - if (m_conn_handle != BLE_CONN_HANDLE_INVALID) - { - // Check if we have reached the maximum number of attempts - m_update_count++; - if (m_update_count <= m_conn_params_config.max_conn_params_update_count) - { - uint32_t err_code; - - // Parameters are not ok, send connection parameters update request. - err_code = sd_ble_gap_conn_param_update(m_conn_handle, &m_preferred_conn_params); - if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL)) - { - m_conn_params_config.error_handler(err_code); - } - } - else - { - m_update_count = 0; - - // Negotiation failed, disconnect automatically if this has been configured - if (m_conn_params_config.disconnect_on_fail) - { - uint32_t err_code; - - err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_CONN_INTERVAL_UNACCEPTABLE); - if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL)) - { - m_conn_params_config.error_handler(err_code); - } - } - - // Notify the application that the procedure has failed - if (m_conn_params_config.evt_handler != NULL) - { - ble_conn_params_evt_t evt; - - evt.evt_type = BLE_CONN_PARAMS_EVT_FAILED; - m_conn_params_config.evt_handler(&evt); - } - } - } -} - - -uint32_t ble_conn_params_init(const ble_conn_params_init_t * p_init) -{ - uint32_t err_code; - - m_conn_params_config = *p_init; - m_change_param = false; - if (p_init->p_conn_params != NULL) - { - m_preferred_conn_params = *p_init->p_conn_params; - - // Set the connection params in stack - err_code = sd_ble_gap_ppcp_set(&m_preferred_conn_params); - if (err_code != NRF_SUCCESS) - { - return err_code; - } - } - else - { - // Fetch the connection params from stack - err_code = sd_ble_gap_ppcp_get(&m_preferred_conn_params); - if (err_code != NRF_SUCCESS) - { - return err_code; - } - } - - m_conn_handle = BLE_CONN_HANDLE_INVALID; - m_update_count = 0; - -#ifdef USE_APP_TIMER - return app_timer_create(&m_conn_params_timer_id, - APP_TIMER_MODE_SINGLE_SHOT, - update_timeout_handler); -#else - return NRF_SUCCESS; -#endif -} - - -uint32_t ble_conn_params_stop(void) -{ -#ifdef USE_APP_TIMER - return app_timer_stop(m_conn_params_timer_id); -#else /* #if !USE_APP_TIMER */ - m_conn_params_timer.detach(); - return NRF_SUCCESS; -#endif /* #if !USE_APP_TIMER */ -} - - -static void conn_params_negotiation(void) -{ - // Start negotiation if the received connection parameters are not acceptable - if (!is_conn_params_ok(&m_current_conn_params)) - { -#ifdef USE_APP_TIMER - uint32_t err_code; -#endif - uint32_t timeout_ticks; - - if (m_change_param) - { - // Notify the application that the procedure has failed - if (m_conn_params_config.evt_handler != NULL) - { - ble_conn_params_evt_t evt; - - evt.evt_type = BLE_CONN_PARAMS_EVT_FAILED; - m_conn_params_config.evt_handler(&evt); - } - } - else - { - if (m_update_count == 0) - { - // First connection parameter update - timeout_ticks = m_conn_params_config.first_conn_params_update_delay; - } - else - { - timeout_ticks = m_conn_params_config.next_conn_params_update_delay; - } - -#ifdef USE_APP_TIMER - err_code = app_timer_start(m_conn_params_timer_id, timeout_ticks, NULL); - if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL)) - { - m_conn_params_config.error_handler(err_code); - } -#else - m_conn_params_timer.attach(update_timeout_handler, timeout_ticks / 32768); -#endif - } - } - else - { - // Notify the application that the procedure has succeded - if (m_conn_params_config.evt_handler != NULL) - { - ble_conn_params_evt_t evt; - - evt.evt_type = BLE_CONN_PARAMS_EVT_SUCCEEDED; - m_conn_params_config.evt_handler(&evt); - } - } - m_change_param = false; -} - - -static void on_connect(ble_evt_t * p_ble_evt) -{ - // Save connection parameters - m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle; - m_current_conn_params = p_ble_evt->evt.gap_evt.params.connected.conn_params; - m_update_count = 0; // Connection parameter negotiation should re-start every connection - - // Check if we shall handle negotiation on connect - if (m_conn_params_config.start_on_notify_cccd_handle == BLE_GATT_HANDLE_INVALID) - { - conn_params_negotiation(); - } -} - - -static void on_disconnect(ble_evt_t * p_ble_evt) -{ -#ifdef USE_APP_TIMER - uint32_t err_code; -#endif - - m_conn_handle = BLE_CONN_HANDLE_INVALID; - - // Stop timer if running - m_update_count = 0; // Connection parameters updates should happen during every connection - -#ifdef USE_APP_TIMER - err_code = app_timer_stop(m_conn_params_timer_id); - if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL)) - { - m_conn_params_config.error_handler(err_code); - } -#else - m_conn_params_timer.detach(); -#endif -} - - -static void on_write(ble_evt_t * p_ble_evt) -{ - ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write; - - // Check if this the correct CCCD - if ( - (p_evt_write->handle == m_conn_params_config.start_on_notify_cccd_handle) - && - (p_evt_write->len == 2) - ) - { - // Check if this is a 'start notification' - if (ble_srv_is_notification_enabled(p_evt_write->data)) - { - // Do connection parameter negotiation if necessary - conn_params_negotiation(); - } - else - { -#ifdef USE_APP_TIMER - uint32_t err_code; - - // Stop timer if running - err_code = app_timer_stop(m_conn_params_timer_id); - if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL)) - { - m_conn_params_config.error_handler(err_code); - } -#else /* #if !USE_APP_TIMER */ - m_conn_params_timer.detach(); -#endif /* #if !USE_APP_TIMER */ - } - } -} - - -static void on_conn_params_update(ble_evt_t * p_ble_evt) -{ - // Copy the parameters - m_current_conn_params = p_ble_evt->evt.gap_evt.params.conn_param_update.conn_params; - - conn_params_negotiation(); -} - - -void ble_conn_params_on_ble_evt(ble_evt_t * p_ble_evt) -{ - switch (p_ble_evt->header.evt_id) - { - case BLE_GAP_EVT_CONNECTED: - on_connect(p_ble_evt); - break; - - case BLE_GAP_EVT_DISCONNECTED: - on_disconnect(p_ble_evt); - break; - - case BLE_GATTS_EVT_WRITE: - on_write(p_ble_evt); - break; - - case BLE_GAP_EVT_CONN_PARAM_UPDATE: - on_conn_params_update(p_ble_evt); - break; - - default: - // No implementation needed. - break; - } -} - -uint32_t ble_conn_params_change_conn_params(ble_gap_conn_params_t *new_params) -{ - uint32_t err_code; - - m_preferred_conn_params = *new_params; - // Set the connection params in stack - err_code = sd_ble_gap_ppcp_set(&m_preferred_conn_params); - if (err_code == NRF_SUCCESS) - { - if (!is_conn_params_ok(&m_current_conn_params)) - { - m_change_param = true; - err_code = sd_ble_gap_conn_param_update(m_conn_handle, &m_preferred_conn_params); - m_update_count = 1; - } - else - { - // Notify the application that the procedure has succeded - if (m_conn_params_config.evt_handler != NULL) - { - ble_conn_params_evt_t evt; - - evt.evt_type = BLE_CONN_PARAMS_EVT_SUCCEEDED; - m_conn_params_config.evt_handler(&evt); - } - err_code = NRF_SUCCESS; - } - } - return err_code; -} +/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. + * + * The information contained herein is property of Nordic Semiconductor ASA. + * Terms and conditions of usage are described in detail in NORDIC + * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. + * + * Licensees are granted free, non-transferable use of the information. NO + * WARRANTY of ANY KIND is provided. This heading must NOT be removed from + * the file. + * + */ + +#include "ble_conn_params.h" +#include +#include "nordic_common.h" +#include "ble_hci.h" +#include "app_timer.h" +#include "ble_srv_common.h" +#include "app_util.h" + + +static ble_conn_params_init_t m_conn_params_config; /**< Configuration as specified by the application. */ +static ble_gap_conn_params_t m_preferred_conn_params; /**< Connection parameters preferred by the application. */ +static uint8_t m_update_count; /**< Number of Connection Parameter Update messages that has currently been sent. */ +static uint16_t m_conn_handle; /**< Current connection handle. */ +static ble_gap_conn_params_t m_current_conn_params; /**< Connection parameters received in the most recent Connect event. */ +static app_timer_id_t m_conn_params_timer_id; /**< Connection parameters timer. */ + +static bool m_change_param = false; + +static bool is_conn_params_ok(ble_gap_conn_params_t * p_conn_params) +{ + // Check if interval is within the acceptable range. + // NOTE: Using max_conn_interval in the received event data because this contains + // the client's connection interval. + if ( + (p_conn_params->max_conn_interval >= m_preferred_conn_params.min_conn_interval) + && + (p_conn_params->max_conn_interval <= m_preferred_conn_params.max_conn_interval) + ) + { + return true; + } + else + { + return false; + } +} + + +static void update_timeout_handler(void * p_context) +{ + UNUSED_PARAMETER(p_context); + + if (m_conn_handle != BLE_CONN_HANDLE_INVALID) + { + // Check if we have reached the maximum number of attempts + m_update_count++; + if (m_update_count <= m_conn_params_config.max_conn_params_update_count) + { + uint32_t err_code; + + // Parameters are not ok, send connection parameters update request. + err_code = sd_ble_gap_conn_param_update(m_conn_handle, &m_preferred_conn_params); + if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL)) + { + m_conn_params_config.error_handler(err_code); + } + } + else + { + m_update_count = 0; + + // Negotiation failed, disconnect automatically if this has been configured + if (m_conn_params_config.disconnect_on_fail) + { + uint32_t err_code; + + err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_CONN_INTERVAL_UNACCEPTABLE); + if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL)) + { + m_conn_params_config.error_handler(err_code); + } + } + + // Notify the application that the procedure has failed + if (m_conn_params_config.evt_handler != NULL) + { + ble_conn_params_evt_t evt; + + evt.evt_type = BLE_CONN_PARAMS_EVT_FAILED; + m_conn_params_config.evt_handler(&evt); + } + } + } +} + + +uint32_t ble_conn_params_init(const ble_conn_params_init_t * p_init) +{ + uint32_t err_code; + + m_conn_params_config = *p_init; + m_change_param = false; + if (p_init->p_conn_params != NULL) + { + m_preferred_conn_params = *p_init->p_conn_params; + + // Set the connection params in stack + err_code = sd_ble_gap_ppcp_set(&m_preferred_conn_params); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + } + else + { + // Fetch the connection params from stack + err_code = sd_ble_gap_ppcp_get(&m_preferred_conn_params); + if (err_code != NRF_SUCCESS) + { + return err_code; + } + } + + m_conn_handle = BLE_CONN_HANDLE_INVALID; + m_update_count = 0; + + return app_timer_create(&m_conn_params_timer_id, + APP_TIMER_MODE_SINGLE_SHOT, + update_timeout_handler); +} + + +uint32_t ble_conn_params_stop(void) +{ + return app_timer_stop(m_conn_params_timer_id); +} + + +static void conn_params_negotiation(void) +{ + // Start negotiation if the received connection parameters are not acceptable + if (!is_conn_params_ok(&m_current_conn_params)) + { + uint32_t err_code; + uint32_t timeout_ticks; + + if (m_change_param) + { + // Notify the application that the procedure has failed + if (m_conn_params_config.evt_handler != NULL) + { + ble_conn_params_evt_t evt; + + evt.evt_type = BLE_CONN_PARAMS_EVT_FAILED; + m_conn_params_config.evt_handler(&evt); + } + } + else + { + if (m_update_count == 0) + { + // First connection parameter update + timeout_ticks = m_conn_params_config.first_conn_params_update_delay; + } + else + { + timeout_ticks = m_conn_params_config.next_conn_params_update_delay; + } + + err_code = app_timer_start(m_conn_params_timer_id, timeout_ticks, NULL); + if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL)) + { + m_conn_params_config.error_handler(err_code); + } + } + } + else + { + // Notify the application that the procedure has succeded + if (m_conn_params_config.evt_handler != NULL) + { + ble_conn_params_evt_t evt; + + evt.evt_type = BLE_CONN_PARAMS_EVT_SUCCEEDED; + m_conn_params_config.evt_handler(&evt); + } + } + m_change_param = false; +} + + +static void on_connect(ble_evt_t * p_ble_evt) +{ + // Save connection parameters + m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle; + m_current_conn_params = p_ble_evt->evt.gap_evt.params.connected.conn_params; + m_update_count = 0; // Connection parameter negotiation should re-start every connection + + // Check if we shall handle negotiation on connect + if (m_conn_params_config.start_on_notify_cccd_handle == BLE_GATT_HANDLE_INVALID) + { + conn_params_negotiation(); + } +} + + +static void on_disconnect(ble_evt_t * p_ble_evt) +{ + uint32_t err_code; + + m_conn_handle = BLE_CONN_HANDLE_INVALID; + + // Stop timer if running + m_update_count = 0; // Connection parameters updates should happen during every connection + + err_code = app_timer_stop(m_conn_params_timer_id); + if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL)) + { + m_conn_params_config.error_handler(err_code); + } +} + + +static void on_write(ble_evt_t * p_ble_evt) +{ + ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write; + + // Check if this the correct CCCD + if ( + (p_evt_write->handle == m_conn_params_config.start_on_notify_cccd_handle) + && + (p_evt_write->len == 2) + ) + { + // Check if this is a 'start notification' + if (ble_srv_is_notification_enabled(p_evt_write->data)) + { + // Do connection parameter negotiation if necessary + conn_params_negotiation(); + } + else + { + uint32_t err_code; + + // Stop timer if running + err_code = app_timer_stop(m_conn_params_timer_id); + if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL)) + { + m_conn_params_config.error_handler(err_code); + } + } + } +} + + +static void on_conn_params_update(ble_evt_t * p_ble_evt) +{ + // Copy the parameters + m_current_conn_params = p_ble_evt->evt.gap_evt.params.conn_param_update.conn_params; + + conn_params_negotiation(); +} + + +void ble_conn_params_on_ble_evt(ble_evt_t * p_ble_evt) +{ + switch (p_ble_evt->header.evt_id) + { + case BLE_GAP_EVT_CONNECTED: + on_connect(p_ble_evt); + break; + + case BLE_GAP_EVT_DISCONNECTED: + on_disconnect(p_ble_evt); + break; + + case BLE_GATTS_EVT_WRITE: + on_write(p_ble_evt); + break; + + case BLE_GAP_EVT_CONN_PARAM_UPDATE: + on_conn_params_update(p_ble_evt); + break; + + default: + // No implementation needed. + break; + } +} + + +uint32_t ble_conn_params_change_conn_params(ble_gap_conn_params_t * new_params) +{ + uint32_t err_code; + + m_preferred_conn_params = *new_params; + // Set the connection params in stack + err_code = sd_ble_gap_ppcp_set(&m_preferred_conn_params); + if (err_code == NRF_SUCCESS) + { + if (!is_conn_params_ok(&m_current_conn_params)) + { + m_change_param = true; + err_code = sd_ble_gap_conn_param_update(m_conn_handle, &m_preferred_conn_params); + m_update_count = 1; + } + else + { + // Notify the application that the procedure has succeded + if (m_conn_params_config.evt_handler != NULL) + { + ble_conn_params_evt_t evt; + + evt.evt_type = BLE_CONN_PARAMS_EVT_SUCCEEDED; + m_conn_params_config.evt_handler(&evt); + } + err_code = NRF_SUCCESS; + } + } + return err_code; +} diff --git a/source/nordic_sdk/components/ble/common/ble_conn_params.h b/source/nordic_sdk/components/ble/common/ble_conn_params.h old mode 100755 new mode 100644 index b852f86..2659443 --- a/source/nordic_sdk/components/ble/common/ble_conn_params.h +++ b/source/nordic_sdk/components/ble/common/ble_conn_params.h @@ -1,139 +1,111 @@ -/* - * Copyright (c) Nordic Semiconductor ASA - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this - * list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of other - * contributors to this software may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -/** @file - * - * @defgroup ble_sdk_lib_conn_params Connection Parameters Negotiation - * @{ - * @ingroup ble_sdk_lib - * @brief Module for initiating and executing a connection parameters negotiation procedure. - */ - -#ifndef BLE_CONN_PARAMS_H__ -#define BLE_CONN_PARAMS_H__ - -#include -#include "ble.h" -#include "ble_srv_common.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/**@brief Connection Parameters Module event type. */ -typedef enum -{ - BLE_CONN_PARAMS_EVT_FAILED , /**< Negotiation procedure failed. */ - BLE_CONN_PARAMS_EVT_SUCCEEDED /**< Negotiation procedure succeeded. */ -} ble_conn_params_evt_type_t; - -/**@brief Connection Parameters Module event. */ -typedef struct -{ - ble_conn_params_evt_type_t evt_type; /**< Type of event. */ -} ble_conn_params_evt_t; - -/**@brief Connection Parameters Module event handler type. */ -typedef void (*ble_conn_params_evt_handler_t) (ble_conn_params_evt_t * p_evt); - -/**@brief Connection Parameters Module init structure. This contains all options and data needed for - * initialization of the connection parameters negotiation module. */ -typedef struct -{ - ble_gap_conn_params_t * p_conn_params; /**< Pointer to the connection parameters desired by the application. When calling ble_conn_params_init, if this parameter is set to NULL, the connection parameters will be fetched from host. */ - uint32_t first_conn_params_update_delay; /**< Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (in number of timer ticks). */ - uint32_t next_conn_params_update_delay; /**< Time between each call to sd_ble_gap_conn_param_update after the first (in number of timer ticks). Recommended value 30 seconds as per BLUETOOTH SPECIFICATION Version 4.0. */ - uint8_t max_conn_params_update_count; /**< Number of attempts before giving up the negotiation. */ - uint16_t start_on_notify_cccd_handle; /**< If procedure is to be started when notification is started, set this to the handle of the corresponding CCCD. Set to BLE_GATT_HANDLE_INVALID if procedure is to be started on connect event. */ - bool disconnect_on_fail; /**< Set to TRUE if a failed connection parameters update shall cause an automatic disconnection, set to FALSE otherwise. */ - ble_conn_params_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Connection Parameters. */ - ble_srv_error_handler_t error_handler; /**< Function to be called in case of an error. */ -} ble_conn_params_init_t; - - -/**@brief Function for initializing the Connection Parameters module. - * - * @note If the negotiation procedure should be triggered when notification/indication of - * any characteristic is enabled by the peer, then this function must be called after - * having initialized the services. - * - * @param[in] p_init This contains information needed to initialize this module. - * - * @return NRF_SUCCESS on successful initialization, otherwise an error code. - */ -uint32_t ble_conn_params_init(const ble_conn_params_init_t * p_init); - -/**@brief Function for stopping the Connection Parameters module. - * - * @details This function is intended to be used by the application to clean up the connection - * parameters update module. This will stop the connection parameters update timer if - * running, thereby preventing any impending connection parameters update procedure. This - * function must be called by the application when it needs to clean itself up (for - * example, before disabling the bluetooth SoftDevice) so that an unwanted timer expiry - * event can be avoided. - * - * @return NRF_SUCCESS on successful initialization, otherwise an error code. - */ -uint32_t ble_conn_params_stop(void); - -/**@brief Function for changing the current connection parameters to a new set. - * - * @details Use this function to change the connection parameters to a new set of parameter - * (ie different from the ones given at init of the module). - * This function is usefull for scenario where most of the time the application - * needs a relatively big connection interval, and just sometimes, for a temporary - * period requires shorter connection interval, for example to transfer a higher - * amount of data. - * If the given parameters does not match the current connection's parameters - * this function initiates a new negotiation. - * - * @param[in] new_params This contains the new connections parameters to setup. - * - * @return NRF_SUCCESS on successful initialization, otherwise an error code. - */ -uint32_t ble_conn_params_change_conn_params(ble_gap_conn_params_t *new_params); - -/**@brief Function for handling the Application's BLE Stack events. - * - * @details Handles all events from the BLE stack that are of interest to this module. - * - * @param[in] p_ble_evt The event received from the BLE stack. - */ -void ble_conn_params_on_ble_evt(ble_evt_t * p_ble_evt); - -#ifdef __cplusplus -} -#endif - -#endif // BLE_CONN_PARAMS_H__ - -/** @} */ +/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. + * + * The information contained herein is property of Nordic Semiconductor ASA. + * Terms and conditions of usage are described in detail in NORDIC + * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. + * + * Licensees are granted free, non-transferable use of the information. NO + * WARRANTY of ANY KIND is provided. This heading must NOT be removed from + * the file. + * + */ + +/** @file + * + * @defgroup ble_sdk_lib_conn_params Connection Parameters Negotiation + * @{ + * @ingroup ble_sdk_lib + * @brief Module for initiating and executing a connection parameters negotiation procedure. + */ + +#ifndef BLE_CONN_PARAMS_H__ +#define BLE_CONN_PARAMS_H__ + +#include +#include "ble.h" +#include "ble_srv_common.h" + +/**@brief Connection Parameters Module event type. */ +typedef enum +{ + BLE_CONN_PARAMS_EVT_FAILED , /**< Negotiation procedure failed. */ + BLE_CONN_PARAMS_EVT_SUCCEEDED /**< Negotiation procedure succeeded. */ +} ble_conn_params_evt_type_t; + +/**@brief Connection Parameters Module event. */ +typedef struct +{ + ble_conn_params_evt_type_t evt_type; /**< Type of event. */ +} ble_conn_params_evt_t; + +/**@brief Connection Parameters Module event handler type. */ +typedef void (*ble_conn_params_evt_handler_t) (ble_conn_params_evt_t * p_evt); + +/**@brief Connection Parameters Module init structure. This contains all options and data needed for + * initialization of the connection parameters negotiation module. */ +typedef struct +{ + ble_gap_conn_params_t * p_conn_params; /**< Pointer to the connection parameters desired by the application. When calling ble_conn_params_init, if this parameter is set to NULL, the connection parameters will be fetched from host. */ + uint32_t first_conn_params_update_delay; /**< Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (in number of timer ticks). */ + uint32_t next_conn_params_update_delay; /**< Time between each call to sd_ble_gap_conn_param_update after the first (in number of timer ticks). Recommended value 30 seconds as per BLUETOOTH SPECIFICATION Version 4.0. */ + uint8_t max_conn_params_update_count; /**< Number of attempts before giving up the negotiation. */ + uint16_t start_on_notify_cccd_handle; /**< If procedure is to be started when notification is started, set this to the handle of the corresponding CCCD. Set to BLE_GATT_HANDLE_INVALID if procedure is to be started on connect event. */ + bool disconnect_on_fail; /**< Set to TRUE if a failed connection parameters update shall cause an automatic disconnection, set to FALSE otherwise. */ + ble_conn_params_evt_handler_t evt_handler; /**< Event handler to be called for handling events in the Connection Parameters. */ + ble_srv_error_handler_t error_handler; /**< Function to be called in case of an error. */ +} ble_conn_params_init_t; + + +/**@brief Function for initializing the Connection Parameters module. + * + * @note If the negotiation procedure should be triggered when notification/indication of + * any characteristic is enabled by the peer, then this function must be called after + * having initialized the services. + * + * @param[in] p_init This contains information needed to initialize this module. + * + * @return NRF_SUCCESS on successful initialization, otherwise an error code. + */ +uint32_t ble_conn_params_init(const ble_conn_params_init_t * p_init); + +/**@brief Function for stopping the Connection Parameters module. + * + * @details This function is intended to be used by the application to clean up the connection + * parameters update module. This will stop the connection parameters update timer if + * running, thereby preventing any impending connection parameters update procedure. This + * function must be called by the application when it needs to clean itself up (for + * example, before disabling the bluetooth SoftDevice) so that an unwanted timer expiry + * event can be avoided. + * + * @return NRF_SUCCESS on successful initialization, otherwise an error code. + */ +uint32_t ble_conn_params_stop(void); + +/**@brief Function for changing the current connection parameters to a new set. + * + * @details Use this function to change the connection parameters to a new set of parameter + * (ie different from the ones given at init of the module). + * This function is usefull for scenario where most of the time the application + * needs a relatively big connection interval, and just sometimes, for a temporary + * period requires shorter connection interval, for example to transfer a higher + * amount of data. + * If the given parameters does not match the current connection's parameters + * this function initiates a new negotiation. + * + * @param[in] new_params This contains the new connections parameters to setup. + * + * @return NRF_SUCCESS on successful initialization, otherwise an error code. + */ +uint32_t ble_conn_params_change_conn_params(ble_gap_conn_params_t *new_params); + +/**@brief Function for handling the Application's BLE Stack events. + * + * @details Handles all events from the BLE stack that are of interest to this module. + * + * @param[in] p_ble_evt The event received from the BLE stack. + */ +void ble_conn_params_on_ble_evt(ble_evt_t * p_ble_evt); + +#endif // BLE_CONN_PARAMS_H__ + +/** @} */ diff --git a/source/nordic_sdk/components/ble/common/ble_date_time.h b/source/nordic_sdk/components/ble/common/ble_date_time.h old mode 100755 new mode 100644 index 39a68e6..5c3b092 --- a/source/nordic_sdk/components/ble/common/ble_date_time.h +++ b/source/nordic_sdk/components/ble/common/ble_date_time.h @@ -1,97 +1,76 @@ -/* - * Copyright (c) Nordic Semiconductor ASA - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this - * list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of other - * contributors to this software may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -/* Attention! -* To maintain compliance with Nordic Semiconductor ASA’s Bluetooth profile -* qualification listings, this section of source code must not be modified. -*/ - -/** @file - * @brief Contains definition of ble_date_time structure. - */ - -/** @file - * - * @defgroup ble_sdk_srv_date_time BLE Date Time characteristic type - * @{ - * @ingroup ble_sdk_lib - * @brief Definition of ble_date_time_t type. - */ - -#ifndef BLE_DATE_TIME_H__ -#define BLE_DATE_TIME_H__ - -#include - -/**@brief Date and Time structure. */ -typedef struct -{ - uint16_t year; - uint8_t month; - uint8_t day; - uint8_t hours; - uint8_t minutes; - uint8_t seconds; -} ble_date_time_t; - -static __INLINE uint8_t ble_date_time_encode(const ble_date_time_t * p_date_time, - uint8_t * p_encoded_data) -{ - uint8_t len = uint16_encode(p_date_time->year, p_encoded_data); - - p_encoded_data[len++] = p_date_time->month; - p_encoded_data[len++] = p_date_time->day; - p_encoded_data[len++] = p_date_time->hours; - p_encoded_data[len++] = p_date_time->minutes; - p_encoded_data[len++] = p_date_time->seconds; - - return len; -} - -static __INLINE uint8_t ble_date_time_decode(ble_date_time_t * p_date_time, - const uint8_t * p_encoded_data) -{ - uint8_t len = sizeof(uint16_t); - - p_date_time->year = uint16_decode(p_encoded_data); - p_date_time->month = p_encoded_data[len++]; - p_date_time->day = p_encoded_data[len++]; - p_date_time->hours = p_encoded_data[len++]; - p_date_time->minutes = p_encoded_data[len++]; - p_date_time->seconds = p_encoded_data[len++]; - - return len; -} - -#endif // BLE_DATE_TIME_H__ - -/** @} */ +/* Copyright (c) 2011 Nordic Semiconductor. All Rights Reserved. +* +* The information contained herein is property of Nordic Semiconductor ASA. +* Terms and conditions of usage are described in detail in NORDIC +* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. +* +* Licensees are granted free, non-transferable use of the information. NO +* WARRANTY of ANY KIND is provided. This heading must NOT be removed from +* the file. +*/ + +/* Attention! +* To maintain compliance with Nordic Semiconductor ASA’s Bluetooth profile +* qualification listings, this section of source code must not be modified. +*/ + +/** @file + * @brief Contains definition of ble_date_time structure. + */ + +/** @file + * + * @defgroup ble_sdk_srv_date_time BLE Date Time characteristic type + * @{ + * @ingroup ble_sdk_lib + * @brief Definition of ble_date_time_t type. + */ + +#ifndef BLE_DATE_TIME_H__ +#define BLE_DATE_TIME_H__ + +#include + +/**@brief Date and Time structure. */ +typedef struct +{ + uint16_t year; + uint8_t month; + uint8_t day; + uint8_t hours; + uint8_t minutes; + uint8_t seconds; +} ble_date_time_t; + +static __INLINE uint8_t ble_date_time_encode(const ble_date_time_t * p_date_time, + uint8_t * p_encoded_data) +{ + uint8_t len = uint16_encode(p_date_time->year, p_encoded_data); + + p_encoded_data[len++] = p_date_time->month; + p_encoded_data[len++] = p_date_time->day; + p_encoded_data[len++] = p_date_time->hours; + p_encoded_data[len++] = p_date_time->minutes; + p_encoded_data[len++] = p_date_time->seconds; + + return len; +} + +static __INLINE uint8_t ble_date_time_decode(ble_date_time_t * p_date_time, + const uint8_t * p_encoded_data) +{ + uint8_t len = sizeof(uint16_t); + + p_date_time->year = uint16_decode(p_encoded_data); + p_date_time->month = p_encoded_data[len++]; + p_date_time->day = p_encoded_data[len++]; + p_date_time->hours = p_encoded_data[len++]; + p_date_time->minutes = p_encoded_data[len++]; + p_date_time->seconds = p_encoded_data[len++]; + + return len; +} + +#endif // BLE_DATE_TIME_H__ + +/** @} */ diff --git a/source/nordic_sdk/components/ble/common/ble_sensor_location.h b/source/nordic_sdk/components/ble/common/ble_sensor_location.h index efe9026..6822d44 100644 --- a/source/nordic_sdk/components/ble/common/ble_sensor_location.h +++ b/source/nordic_sdk/components/ble/common/ble_sensor_location.h @@ -1,61 +1,40 @@ -/* - * Copyright (c) Nordic Semiconductor ASA - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this - * list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of other - * contributors to this software may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - - - /* Attention! -* To maintain compliance with Nordic Semiconductor ASA’s Bluetooth profile -* qualification listings, this section of source code must not be modified. -*/ - -#ifndef BLE_SENSOR_LOCATION_H__ -#define BLE_SENSOR_LOCATION_H__ - -typedef enum { - BLE_SENSOR_LOCATION_OTHER = 0 , /**<-- Other */ - BLE_SENSOR_LOCATION_TOP_OF_SHOE = 1 , /**<-- Top of shoe */ - BLE_SENSOR_LOCATION_IN_SHOE = 2 , /**<-- In shoe */ - BLE_SENSOR_LOCATION_HIP = 3 , /**<-- Hip */ - BLE_SENSOR_LOCATION_FRONT_WHEEL = 4 , /**<-- Front Wheel */ - BLE_SENSOR_LOCATION_LEFT_CRANK = 5 , /**<-- Left Crank */ - BLE_SENSOR_LOCATION_RIGHT_CRANK = 6 , /**<-- Right Crank */ - BLE_SENSOR_LOCATION_LEFT_PEDAL = 7 , /**<-- Left Pedal */ - BLE_SENSOR_LOCATION_RIGHT_PEDAL = 8 , /**<-- Right Pedal */ - BLE_SENSOR_LOCATION_FRONT_HUB = 9 , /**<-- Front Hub */ - BLE_SENSOR_LOCATION_REAR_DROPOUT = 10, /**<-- Rear Dropout */ - BLE_SENSOR_LOCATION_CHAINSTAY = 11, /**<-- Chainstay */ - BLE_SENSOR_LOCATION_REAR_WHEEL = 12, /**<-- Rear Wheel */ - BLE_SENSOR_LOCATION_REAR_HUB = 13, /**<-- Rear Hub */ -}ble_sensor_location_t; - -#define BLE_NB_MAX_SENSOR_LOCATIONS 14 - -#endif // BLE_SENSOR_LOCATION_H__ +/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. + * + * The information contained herein is property of Nordic Semiconductor ASA. + * Terms and conditions of usage are described in detail in NORDIC + * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. + * + * Licensees are granted free, non-transferable use of the information. NO + * WARRANTY of ANY KIND is provided. This heading must NOT be removed from + * the file. + * + */ + + /* Attention! +* To maintain compliance with Nordic Semiconductor ASA’s Bluetooth profile +* qualification listings, this section of source code must not be modified. +*/ + +#ifndef BLE_SENSOR_LOCATION_H__ +#define BLE_SENSOR_LOCATION_H__ + +typedef enum { + BLE_SENSOR_LOCATION_OTHER = 0 , /**<-- Other */ + BLE_SENSOR_LOCATION_TOP_OF_SHOE = 1 , /**<-- Top of shoe */ + BLE_SENSOR_LOCATION_IN_SHOE = 2 , /**<-- In shoe */ + BLE_SENSOR_LOCATION_HIP = 3 , /**<-- Hip */ + BLE_SENSOR_LOCATION_FRONT_WHEEL = 4 , /**<-- Front Wheel */ + BLE_SENSOR_LOCATION_LEFT_CRANK = 5 , /**<-- Left Crank */ + BLE_SENSOR_LOCATION_RIGHT_CRANK = 6 , /**<-- Right Crank */ + BLE_SENSOR_LOCATION_LEFT_PEDAL = 7 , /**<-- Left Pedal */ + BLE_SENSOR_LOCATION_RIGHT_PEDAL = 8 , /**<-- Right Pedal */ + BLE_SENSOR_LOCATION_FRONT_HUB = 9 , /**<-- Front Hub */ + BLE_SENSOR_LOCATION_REAR_DROPOUT = 10, /**<-- Rear Dropout */ + BLE_SENSOR_LOCATION_CHAINSTAY = 11, /**<-- Chainstay */ + BLE_SENSOR_LOCATION_REAR_WHEEL = 12, /**<-- Rear Wheel */ + BLE_SENSOR_LOCATION_REAR_HUB = 13, /**<-- Rear Hub */ +}ble_sensor_location_t; + +#define BLE_NB_MAX_SENSOR_LOCATIONS 14 + +#endif // BLE_SENSOR_LOCATION_H__ diff --git a/source/nordic_sdk/components/ble/common/ble_srv_common.c b/source/nordic_sdk/components/ble/common/ble_srv_common.c index 74992a9..700eb82 100644 --- a/source/nordic_sdk/components/ble/common/ble_srv_common.c +++ b/source/nordic_sdk/components/ble/common/ble_srv_common.c @@ -1,61 +1,41 @@ -/* - * Copyright (c) Nordic Semiconductor ASA - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this - * list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of other - * contributors to this software may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -/* Attention! -* To maintain compliance with Nordic Semiconductor ASA’s Bluetooth profile -* qualification listings, this section of source code must not be modified. -*/ - -#include "ble_srv_common.h" -#include -#include "nordic_common.h" -#include "app_error.h" - - -uint8_t ble_srv_report_ref_encode(uint8_t * p_encoded_buffer, - const ble_srv_report_ref_t * p_report_ref) -{ - uint8_t len = 0; - - p_encoded_buffer[len++] = p_report_ref->report_id; - p_encoded_buffer[len++] = p_report_ref->report_type; - - APP_ERROR_CHECK_BOOL(len == BLE_SRV_ENCODED_REPORT_REF_LEN); - return len; -} - - -void ble_srv_ascii_to_utf8(ble_srv_utf8_str_t * p_utf8, char * p_ascii) -{ - p_utf8->length = (uint16_t)strlen(p_ascii); - p_utf8->p_str = (uint8_t *)p_ascii; -} +/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. + * + * The information contained herein is property of Nordic Semiconductor ASA. + * Terms and conditions of usage are described in detail in NORDIC + * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. + * + * Licensees are granted free, non-transferable use of the information. NO + * WARRANTY of ANY KIND is provided. This heading must NOT be removed from + * the file. + * + */ + +/* Attention! +* To maintain compliance with Nordic Semiconductor ASA’s Bluetooth profile +* qualification listings, this section of source code must not be modified. +*/ + +#include "ble_srv_common.h" +#include +#include "nordic_common.h" +#include "app_error.h" + + +uint8_t ble_srv_report_ref_encode(uint8_t * p_encoded_buffer, + const ble_srv_report_ref_t * p_report_ref) +{ + uint8_t len = 0; + + p_encoded_buffer[len++] = p_report_ref->report_id; + p_encoded_buffer[len++] = p_report_ref->report_type; + + APP_ERROR_CHECK_BOOL(len == BLE_SRV_ENCODED_REPORT_REF_LEN); + return len; +} + + +void ble_srv_ascii_to_utf8(ble_srv_utf8_str_t * p_utf8, char * p_ascii) +{ + p_utf8->length = (uint16_t)strlen(p_ascii); + p_utf8->p_str = (uint8_t *)p_ascii; +} diff --git a/source/nordic_sdk/components/ble/common/ble_srv_common.h b/source/nordic_sdk/components/ble/common/ble_srv_common.h index 87d4da9..4c968f9 100644 --- a/source/nordic_sdk/components/ble/common/ble_srv_common.h +++ b/source/nordic_sdk/components/ble/common/ble_srv_common.h @@ -1,250 +1,232 @@ -/* - * Copyright (c) Nordic Semiconductor ASA - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this - * list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of other - * contributors to this software may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -/** @file - * - * @defgroup ble_sdk_srv_common Common service definitions - * @{ - * @ingroup ble_sdk_srv - * @brief Constants, type definitions and functions that are common to all services. - */ - -#ifndef BLE_SRV_COMMON_H__ -#define BLE_SRV_COMMON_H__ - -#include -#include -#include "ble_types.h" -#include "app_util.h" -#include "ble_gap.h" -#include "ble_gatt.h" - -/** @defgroup UUID_SERVICES Service UUID definitions - * @{ */ -#define BLE_UUID_ALERT_NOTIFICATION_SERVICE 0x1811 /**< Alert Notification service UUID. */ -#define BLE_UUID_BATTERY_SERVICE 0x180F /**< Battery service UUID. */ -#define BLE_UUID_BLOOD_PRESSURE_SERVICE 0x1810 /**< Blood Pressure service UUID. */ -#define BLE_UUID_CURRENT_TIME_SERVICE 0x1805 /**< Current Time service UUID. */ -#define BLE_UUID_CYCLING_SPEED_AND_CADENCE 0x1816 /**< Cycling Speed and Cadence service UUID. */ -#define BLE_UUID_DEVICE_INFORMATION_SERVICE 0x180A /**< Device Information service UUID. */ -#define BLE_UUID_GLUCOSE_SERVICE 0x1808 /**< Glucose service UUID. */ -#define BLE_UUID_HEALTH_THERMOMETER_SERVICE 0x1809 /**< Health Thermometer service UUID. */ -#define BLE_UUID_HEART_RATE_SERVICE 0x180D /**< Heart Rate service UUID. */ -#define BLE_UUID_HUMAN_INTERFACE_DEVICE_SERVICE 0x1812 /**< Human Interface Device service UUID. */ -#define BLE_UUID_IMMEDIATE_ALERT_SERVICE 0x1802 /**< Immediate Alert service UUID. */ -#define BLE_UUID_LINK_LOSS_SERVICE 0x1803 /**< Link Loss service UUID. */ -#define BLE_UUID_NEXT_DST_CHANGE_SERVICE 0x1807 /**< Next Dst Change service UUID. */ -#define BLE_UUID_PHONE_ALERT_STATUS_SERVICE 0x180E /**< Phone Alert Status service UUID. */ -#define BLE_UUID_REFERENCE_TIME_UPDATE_SERVICE 0x1806 /**< Reference Time Update service UUID. */ -#define BLE_UUID_RUNNING_SPEED_AND_CADENCE 0x1814 /**< Running Speed and Cadence service UUID. */ -#define BLE_UUID_SCAN_PARAMETERS_SERVICE 0x1813 /**< Scan Parameters service UUID. */ -#define BLE_UUID_TX_POWER_SERVICE 0x1804 /**< TX Power service UUID. */ -/** @} */ - -/** @defgroup UUID_CHARACTERISTICS Characteristic UUID definitions - * @{ */ -#define BLE_UUID_BATTERY_LEVEL_STATE_CHAR 0x2A1B /**< Battery Level State characteristic UUID. */ -#define BLE_UUID_BATTERY_POWER_STATE_CHAR 0x2A1A /**< Battery Power State characteristic UUID. */ -#define BLE_UUID_REMOVABLE_CHAR 0x2A3A /**< Removable characteristic UUID. */ -#define BLE_UUID_SERVICE_REQUIRED_CHAR 0x2A3B /**< Service Required characteristic UUID. */ -#define BLE_UUID_ALERT_CATEGORY_ID_CHAR 0x2A43 /**< Alert Category Id characteristic UUID. */ -#define BLE_UUID_ALERT_CATEGORY_ID_BIT_MASK_CHAR 0x2A42 /**< Alert Category Id Bit Mask characteristic UUID. */ -#define BLE_UUID_ALERT_LEVEL_CHAR 0x2A06 /**< Alert Level characteristic UUID. */ -#define BLE_UUID_ALERT_NOTIFICATION_CONTROL_POINT_CHAR 0x2A44 /**< Alert Notification Control Point characteristic UUID. */ -#define BLE_UUID_ALERT_STATUS_CHAR 0x2A3F /**< Alert Status characteristic UUID. */ -#define BLE_UUID_BATTERY_LEVEL_CHAR 0x2A19 /**< Battery Level characteristic UUID. */ -#define BLE_UUID_BLOOD_PRESSURE_FEATURE_CHAR 0x2A49 /**< Blood Pressure Feature characteristic UUID. */ -#define BLE_UUID_BLOOD_PRESSURE_MEASUREMENT_CHAR 0x2A35 /**< Blood Pressure Measurement characteristic UUID. */ -#define BLE_UUID_BODY_SENSOR_LOCATION_CHAR 0x2A38 /**< Body Sensor Location characteristic UUID. */ -#define BLE_UUID_BOOT_KEYBOARD_INPUT_REPORT_CHAR 0x2A22 /**< Boot Keyboard Input Report characteristic UUID. */ -#define BLE_UUID_BOOT_KEYBOARD_OUTPUT_REPORT_CHAR 0x2A32 /**< Boot Keyboard Output Report characteristic UUID. */ -#define BLE_UUID_BOOT_MOUSE_INPUT_REPORT_CHAR 0x2A33 /**< Boot Mouse Input Report characteristic UUID. */ -#define BLE_UUID_CURRENT_TIME_CHAR 0x2A2B /**< Current Time characteristic UUID. */ -#define BLE_UUID_DATE_TIME_CHAR 0x2A08 /**< Date Time characteristic UUID. */ -#define BLE_UUID_DAY_DATE_TIME_CHAR 0x2A0A /**< Day Date Time characteristic UUID. */ -#define BLE_UUID_DAY_OF_WEEK_CHAR 0x2A09 /**< Day Of Week characteristic UUID. */ -#define BLE_UUID_DST_OFFSET_CHAR 0x2A0D /**< Dst Offset characteristic UUID. */ -#define BLE_UUID_EXACT_TIME_256_CHAR 0x2A0C /**< Exact Time 256 characteristic UUID. */ -#define BLE_UUID_FIRMWARE_REVISION_STRING_CHAR 0x2A26 /**< Firmware Revision String characteristic UUID. */ -#define BLE_UUID_GLUCOSE_FEATURE_CHAR 0x2A51 /**< Glucose Feature characteristic UUID. */ -#define BLE_UUID_GLUCOSE_MEASUREMENT_CHAR 0x2A18 /**< Glucose Measurement characteristic UUID. */ -#define BLE_UUID_GLUCOSE_MEASUREMENT_CONTEXT_CHAR 0x2A34 /**< Glucose Measurement Context characteristic UUID. */ -#define BLE_UUID_HARDWARE_REVISION_STRING_CHAR 0x2A27 /**< Hardware Revision String characteristic UUID. */ -#define BLE_UUID_HEART_RATE_CONTROL_POINT_CHAR 0x2A39 /**< Heart Rate Control Point characteristic UUID. */ -#define BLE_UUID_HEART_RATE_MEASUREMENT_CHAR 0x2A37 /**< Heart Rate Measurement characteristic UUID. */ -#define BLE_UUID_HID_CONTROL_POINT_CHAR 0x2A4C /**< Hid Control Point characteristic UUID. */ -#define BLE_UUID_HID_INFORMATION_CHAR 0x2A4A /**< Hid Information characteristic UUID. */ -#define BLE_UUID_IEEE_REGULATORY_CERTIFICATION_DATA_LIST_CHAR 0x2A2A /**< IEEE Regulatory Certification Data List characteristic UUID. */ -#define BLE_UUID_INTERMEDIATE_CUFF_PRESSURE_CHAR 0x2A36 /**< Intermediate Cuff Pressure characteristic UUID. */ -#define BLE_UUID_INTERMEDIATE_TEMPERATURE_CHAR 0x2A1E /**< Intermediate Temperature characteristic UUID. */ -#define BLE_UUID_LOCAL_TIME_INFORMATION_CHAR 0x2A0F /**< Local Time Information characteristic UUID. */ -#define BLE_UUID_MANUFACTURER_NAME_STRING_CHAR 0x2A29 /**< Manufacturer Name String characteristic UUID. */ -#define BLE_UUID_MEASUREMENT_INTERVAL_CHAR 0x2A21 /**< Measurement Interval characteristic UUID. */ -#define BLE_UUID_MODEL_NUMBER_STRING_CHAR 0x2A24 /**< Model Number String characteristic UUID. */ -#define BLE_UUID_UNREAD_ALERT_CHAR 0x2A45 /**< Unread Alert characteristic UUID. */ -#define BLE_UUID_NEW_ALERT_CHAR 0x2A46 /**< New Alert characteristic UUID. */ -#define BLE_UUID_PNP_ID_CHAR 0x2A50 /**< PNP Id characteristic UUID. */ -#define BLE_UUID_PROTOCOL_MODE_CHAR 0x2A4E /**< Protocol Mode characteristic UUID. */ -#define BLE_UUID_RECORD_ACCESS_CONTROL_POINT_CHAR 0x2A52 /**< Record Access Control Point characteristic UUID. */ -#define BLE_UUID_REFERENCE_TIME_INFORMATION_CHAR 0x2A14 /**< Reference Time Information characteristic UUID. */ -#define BLE_UUID_REPORT_CHAR 0x2A4D /**< Report characteristic UUID. */ -#define BLE_UUID_REPORT_MAP_CHAR 0x2A4B /**< Report Map characteristic UUID. */ -#define BLE_UUID_RINGER_CONTROL_POINT_CHAR 0x2A40 /**< Ringer Control Point characteristic UUID. */ -#define BLE_UUID_RINGER_SETTING_CHAR 0x2A41 /**< Ringer Setting characteristic UUID. */ -#define BLE_UUID_SCAN_INTERVAL_WINDOW_CHAR 0x2A4F /**< Scan Interval Window characteristic UUID. */ -#define BLE_UUID_SCAN_REFRESH_CHAR 0x2A31 /**< Scan Refresh characteristic UUID. */ -#define BLE_UUID_SERIAL_NUMBER_STRING_CHAR 0x2A25 /**< Serial Number String characteristic UUID. */ -#define BLE_UUID_SOFTWARE_REVISION_STRING_CHAR 0x2A28 /**< Software Revision String characteristic UUID. */ -#define BLE_UUID_SUPPORTED_NEW_ALERT_CATEGORY_CHAR 0x2A47 /**< Supported New Alert Category characteristic UUID. */ -#define BLE_UUID_SUPPORTED_UNREAD_ALERT_CATEGORY_CHAR 0x2A48 /**< Supported Unread Alert Category characteristic UUID. */ -#define BLE_UUID_SYSTEM_ID_CHAR 0x2A23 /**< System Id characteristic UUID. */ -#define BLE_UUID_TEMPERATURE_MEASUREMENT_CHAR 0x2A1C /**< Temperature Measurement characteristic UUID. */ -#define BLE_UUID_TEMPERATURE_TYPE_CHAR 0x2A1D /**< Temperature Type characteristic UUID. */ -#define BLE_UUID_TIME_ACCURACY_CHAR 0x2A12 /**< Time Accuracy characteristic UUID. */ -#define BLE_UUID_TIME_SOURCE_CHAR 0x2A13 /**< Time Source characteristic UUID. */ -#define BLE_UUID_TIME_UPDATE_CONTROL_POINT_CHAR 0x2A16 /**< Time Update Control Point characteristic UUID. */ -#define BLE_UUID_TIME_UPDATE_STATE_CHAR 0x2A17 /**< Time Update State characteristic UUID. */ -#define BLE_UUID_TIME_WITH_DST_CHAR 0x2A11 /**< Time With Dst characteristic UUID. */ -#define BLE_UUID_TIME_ZONE_CHAR 0x2A0E /**< Time Zone characteristic UUID. */ -#define BLE_UUID_TX_POWER_LEVEL_CHAR 0x2A07 /**< TX Power Level characteristic UUID. */ -#define BLE_UUID_CSC_FEATURE_CHAR 0x2A5C /**< Cycling Speed and Cadence Feature characteristic UUID. */ -#define BLE_UUID_CSC_MEASUREMENT_CHAR 0x2A5B /**< Cycling Speed and Cadence Measurement characteristic UUID. */ -#define BLE_UUID_RSC_FEATURE_CHAR 0x2A54 /**< Running Speed and Cadence Feature characteristic UUID. */ -#define BLE_UUID_SC_CTRLPT_CHAR 0x2A55 /**< Speed and Cadence Control Point UUID. */ -#define BLE_UUID_RSC_MEASUREMENT_CHAR 0x2A53 /**< Running Speed and Cadence Measurement characteristic UUID. */ -#define BLE_UUID_SENSOR_LOCATION_CHAR 0x2A5D /**< Sensor Location characteristic UUID. */ -#define BLE_UUID_EXTERNAL_REPORT_REF_DESCR 0x2907 /**< External Report Reference descriptor UUID. */ -#define BLE_UUID_REPORT_REF_DESCR 0x2908 /**< Report Reference descriptor UUID. */ -/** @} */ - -/** @defgroup ALERT_LEVEL_VALUES Definitions for the Alert Level characteristic values - * @{ */ -#define BLE_CHAR_ALERT_LEVEL_NO_ALERT 0x00 /**< No Alert. */ -#define BLE_CHAR_ALERT_LEVEL_MILD_ALERT 0x01 /**< Mild Alert. */ -#define BLE_CHAR_ALERT_LEVEL_HIGH_ALERT 0x02 /**< High Alert. */ -/** @} */ - -#define BLE_SRV_ENCODED_REPORT_REF_LEN 2 /**< The length of an encoded Report Reference Descriptor. */ -#define BLE_CCCD_VALUE_LEN 2 /**< The length of a CCCD value. */ - -/**@brief Type definition for error handler function which will be called in case of an error in - * a service or a service library module. */ -typedef void (*ble_srv_error_handler_t) (uint32_t nrf_error); - -/**@brief Value of a Report Reference descriptor. - * - * @details This is mapping information which maps the parent characteristic to the Report ID(s) and - * Report Type(s) defined within a Report Map characteristic. - */ -typedef struct -{ - uint8_t report_id; /**< Non-zero value if these is more than one instance of the same Report Type */ - uint8_t report_type; /**< Type of Report characteristic @if (SD_S110) (see @ref BLE_HIDS_REPORT_TYPE) @endif */ -} ble_srv_report_ref_t; - -/**@brief UTF-8 string data type. - * - * @note The type can only hold a pointer to the string data (i.e. not the actual data). - */ -typedef struct -{ - uint16_t length; /**< String length. */ - uint8_t * p_str; /**< String data. */ -} ble_srv_utf8_str_t; - -/**@brief Security settings structure. - * @details This structure contains the security options needed during initialization of the - * service. - */ -typedef struct -{ - ble_gap_conn_sec_mode_t read_perm; /**< Read permissions. */ - ble_gap_conn_sec_mode_t write_perm; /**< Write permissions. */ -} ble_srv_security_mode_t; - -/**@brief Security settings structure. - * @details This structure contains the security options needed during initialization of the - * service. It can be used when the charecteristics contains cccd. - */ -typedef struct -{ - ble_gap_conn_sec_mode_t cccd_write_perm; - ble_gap_conn_sec_mode_t read_perm; /**< Read permissions. */ - ble_gap_conn_sec_mode_t write_perm; /**< Write permissions. */ -} ble_srv_cccd_security_mode_t; - -/**@brief Function for decoding a CCCD value, and then testing if notification is - * enabled. - * - * @param[in] p_encoded_data Buffer where the encoded CCCD is stored. - * - * @return TRUE if notification is enabled, FALSE otherwise. - */ -static __INLINE bool ble_srv_is_notification_enabled(uint8_t * p_encoded_data) -{ - uint16_t cccd_value = uint16_decode(p_encoded_data); - return ((cccd_value & BLE_GATT_HVX_NOTIFICATION) != 0); -} - -/**@brief Function for decoding a CCCD value, and then testing if indication is - * enabled. - * - * @param[in] p_encoded_data Buffer where the encoded CCCD is stored. - * - * @return TRUE if indication is enabled, FALSE otherwise. - */ -static __INLINE bool ble_srv_is_indication_enabled(uint8_t * p_encoded_data) -{ - uint16_t cccd_value = uint16_decode(p_encoded_data); - return ((cccd_value & BLE_GATT_HVX_INDICATION) != 0); -} - -/**@brief Function for encoding a Report Reference Descriptor. - * - * @param[in] p_encoded_buffer The buffer of the encoded data. - * @param[in] p_report_ref Report Reference value to be encoded. - * - * @return Length of the encoded data. - */ -uint8_t ble_srv_report_ref_encode(uint8_t * p_encoded_buffer, - const ble_srv_report_ref_t * p_report_ref); - -/**@brief Function for making UTF-8 structure refer to an ASCII string. - * - * @param[out] p_utf8 UTF-8 structure to be set. - * @param[in] p_ascii ASCII string to be referred to. - */ -void ble_srv_ascii_to_utf8(ble_srv_utf8_str_t * p_utf8, char * p_ascii); - -#endif // BLE_SRV_COMMON_H__ - -/** @} */ +/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. + * + * The information contained herein is property of Nordic Semiconductor ASA. + * Terms and conditions of usage are described in detail in NORDIC + * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. + * + * Licensees are granted free, non-transferable use of the information. NO + * WARRANTY of ANY KIND is provided. This heading must NOT be removed from + * the file. + * + */ + +/** @file + * + * @defgroup ble_sdk_srv_common Common service definitions + * @{ + * @ingroup ble_sdk_srv + * @brief Constants, type definitions and functions that are common to all services. + */ + +#ifndef BLE_SRV_COMMON_H__ +#define BLE_SRV_COMMON_H__ + +#include +#include +#include "ble_types.h" +#include "app_util.h" +#include "ble_gap.h" +#include "ble_gatt.h" + +/** @defgroup UUID_SERVICES Service UUID definitions + * @{ */ +#define BLE_UUID_ALERT_NOTIFICATION_SERVICE 0x1811 /**< Alert Notification service UUID. */ +#define BLE_UUID_BATTERY_SERVICE 0x180F /**< Battery service UUID. */ +#define BLE_UUID_BLOOD_PRESSURE_SERVICE 0x1810 /**< Blood Pressure service UUID. */ +#define BLE_UUID_CURRENT_TIME_SERVICE 0x1805 /**< Current Time service UUID. */ +#define BLE_UUID_CYCLING_SPEED_AND_CADENCE 0x1816 /**< Cycling Speed and Cadence service UUID. */ +#define BLE_UUID_DEVICE_INFORMATION_SERVICE 0x180A /**< Device Information service UUID. */ +#define BLE_UUID_GLUCOSE_SERVICE 0x1808 /**< Glucose service UUID. */ +#define BLE_UUID_HEALTH_THERMOMETER_SERVICE 0x1809 /**< Health Thermometer service UUID. */ +#define BLE_UUID_HEART_RATE_SERVICE 0x180D /**< Heart Rate service UUID. */ +#define BLE_UUID_HUMAN_INTERFACE_DEVICE_SERVICE 0x1812 /**< Human Interface Device service UUID. */ +#define BLE_UUID_IMMEDIATE_ALERT_SERVICE 0x1802 /**< Immediate Alert service UUID. */ +#define BLE_UUID_LINK_LOSS_SERVICE 0x1803 /**< Link Loss service UUID. */ +#define BLE_UUID_NEXT_DST_CHANGE_SERVICE 0x1807 /**< Next Dst Change service UUID. */ +#define BLE_UUID_PHONE_ALERT_STATUS_SERVICE 0x180E /**< Phone Alert Status service UUID. */ +#define BLE_UUID_REFERENCE_TIME_UPDATE_SERVICE 0x1806 /**< Reference Time Update service UUID. */ +#define BLE_UUID_RUNNING_SPEED_AND_CADENCE 0x1814 /**< Running Speed and Cadence service UUID. */ +#define BLE_UUID_SCAN_PARAMETERS_SERVICE 0x1813 /**< Scan Parameters service UUID. */ +#define BLE_UUID_TX_POWER_SERVICE 0x1804 /**< TX Power service UUID. */ +#define BLE_UUID_IPSP_SERVICE 0x1820 /**< Internet Protocol Support service UUID. */ + +/** @} */ + +/** @defgroup UUID_CHARACTERISTICS Characteristic UUID definitions + * @{ */ +#define BLE_UUID_BATTERY_LEVEL_STATE_CHAR 0x2A1B /**< Battery Level State characteristic UUID. */ +#define BLE_UUID_BATTERY_POWER_STATE_CHAR 0x2A1A /**< Battery Power State characteristic UUID. */ +#define BLE_UUID_REMOVABLE_CHAR 0x2A3A /**< Removable characteristic UUID. */ +#define BLE_UUID_SERVICE_REQUIRED_CHAR 0x2A3B /**< Service Required characteristic UUID. */ +#define BLE_UUID_ALERT_CATEGORY_ID_CHAR 0x2A43 /**< Alert Category Id characteristic UUID. */ +#define BLE_UUID_ALERT_CATEGORY_ID_BIT_MASK_CHAR 0x2A42 /**< Alert Category Id Bit Mask characteristic UUID. */ +#define BLE_UUID_ALERT_LEVEL_CHAR 0x2A06 /**< Alert Level characteristic UUID. */ +#define BLE_UUID_ALERT_NOTIFICATION_CONTROL_POINT_CHAR 0x2A44 /**< Alert Notification Control Point characteristic UUID. */ +#define BLE_UUID_ALERT_STATUS_CHAR 0x2A3F /**< Alert Status characteristic UUID. */ +#define BLE_UUID_BATTERY_LEVEL_CHAR 0x2A19 /**< Battery Level characteristic UUID. */ +#define BLE_UUID_BLOOD_PRESSURE_FEATURE_CHAR 0x2A49 /**< Blood Pressure Feature characteristic UUID. */ +#define BLE_UUID_BLOOD_PRESSURE_MEASUREMENT_CHAR 0x2A35 /**< Blood Pressure Measurement characteristic UUID. */ +#define BLE_UUID_BODY_SENSOR_LOCATION_CHAR 0x2A38 /**< Body Sensor Location characteristic UUID. */ +#define BLE_UUID_BOOT_KEYBOARD_INPUT_REPORT_CHAR 0x2A22 /**< Boot Keyboard Input Report characteristic UUID. */ +#define BLE_UUID_BOOT_KEYBOARD_OUTPUT_REPORT_CHAR 0x2A32 /**< Boot Keyboard Output Report characteristic UUID. */ +#define BLE_UUID_BOOT_MOUSE_INPUT_REPORT_CHAR 0x2A33 /**< Boot Mouse Input Report characteristic UUID. */ +#define BLE_UUID_CURRENT_TIME_CHAR 0x2A2B /**< Current Time characteristic UUID. */ +#define BLE_UUID_DATE_TIME_CHAR 0x2A08 /**< Date Time characteristic UUID. */ +#define BLE_UUID_DAY_DATE_TIME_CHAR 0x2A0A /**< Day Date Time characteristic UUID. */ +#define BLE_UUID_DAY_OF_WEEK_CHAR 0x2A09 /**< Day Of Week characteristic UUID. */ +#define BLE_UUID_DST_OFFSET_CHAR 0x2A0D /**< Dst Offset characteristic UUID. */ +#define BLE_UUID_EXACT_TIME_256_CHAR 0x2A0C /**< Exact Time 256 characteristic UUID. */ +#define BLE_UUID_FIRMWARE_REVISION_STRING_CHAR 0x2A26 /**< Firmware Revision String characteristic UUID. */ +#define BLE_UUID_GLUCOSE_FEATURE_CHAR 0x2A51 /**< Glucose Feature characteristic UUID. */ +#define BLE_UUID_GLUCOSE_MEASUREMENT_CHAR 0x2A18 /**< Glucose Measurement characteristic UUID. */ +#define BLE_UUID_GLUCOSE_MEASUREMENT_CONTEXT_CHAR 0x2A34 /**< Glucose Measurement Context characteristic UUID. */ +#define BLE_UUID_HARDWARE_REVISION_STRING_CHAR 0x2A27 /**< Hardware Revision String characteristic UUID. */ +#define BLE_UUID_HEART_RATE_CONTROL_POINT_CHAR 0x2A39 /**< Heart Rate Control Point characteristic UUID. */ +#define BLE_UUID_HEART_RATE_MEASUREMENT_CHAR 0x2A37 /**< Heart Rate Measurement characteristic UUID. */ +#define BLE_UUID_HID_CONTROL_POINT_CHAR 0x2A4C /**< Hid Control Point characteristic UUID. */ +#define BLE_UUID_HID_INFORMATION_CHAR 0x2A4A /**< Hid Information characteristic UUID. */ +#define BLE_UUID_IEEE_REGULATORY_CERTIFICATION_DATA_LIST_CHAR 0x2A2A /**< IEEE Regulatory Certification Data List characteristic UUID. */ +#define BLE_UUID_INTERMEDIATE_CUFF_PRESSURE_CHAR 0x2A36 /**< Intermediate Cuff Pressure characteristic UUID. */ +#define BLE_UUID_INTERMEDIATE_TEMPERATURE_CHAR 0x2A1E /**< Intermediate Temperature characteristic UUID. */ +#define BLE_UUID_LOCAL_TIME_INFORMATION_CHAR 0x2A0F /**< Local Time Information characteristic UUID. */ +#define BLE_UUID_MANUFACTURER_NAME_STRING_CHAR 0x2A29 /**< Manufacturer Name String characteristic UUID. */ +#define BLE_UUID_MEASUREMENT_INTERVAL_CHAR 0x2A21 /**< Measurement Interval characteristic UUID. */ +#define BLE_UUID_MODEL_NUMBER_STRING_CHAR 0x2A24 /**< Model Number String characteristic UUID. */ +#define BLE_UUID_UNREAD_ALERT_CHAR 0x2A45 /**< Unread Alert characteristic UUID. */ +#define BLE_UUID_NEW_ALERT_CHAR 0x2A46 /**< New Alert characteristic UUID. */ +#define BLE_UUID_PNP_ID_CHAR 0x2A50 /**< PNP Id characteristic UUID. */ +#define BLE_UUID_PROTOCOL_MODE_CHAR 0x2A4E /**< Protocol Mode characteristic UUID. */ +#define BLE_UUID_RECORD_ACCESS_CONTROL_POINT_CHAR 0x2A52 /**< Record Access Control Point characteristic UUID. */ +#define BLE_UUID_REFERENCE_TIME_INFORMATION_CHAR 0x2A14 /**< Reference Time Information characteristic UUID. */ +#define BLE_UUID_REPORT_CHAR 0x2A4D /**< Report characteristic UUID. */ +#define BLE_UUID_REPORT_MAP_CHAR 0x2A4B /**< Report Map characteristic UUID. */ +#define BLE_UUID_RINGER_CONTROL_POINT_CHAR 0x2A40 /**< Ringer Control Point characteristic UUID. */ +#define BLE_UUID_RINGER_SETTING_CHAR 0x2A41 /**< Ringer Setting characteristic UUID. */ +#define BLE_UUID_SCAN_INTERVAL_WINDOW_CHAR 0x2A4F /**< Scan Interval Window characteristic UUID. */ +#define BLE_UUID_SCAN_REFRESH_CHAR 0x2A31 /**< Scan Refresh characteristic UUID. */ +#define BLE_UUID_SERIAL_NUMBER_STRING_CHAR 0x2A25 /**< Serial Number String characteristic UUID. */ +#define BLE_UUID_SOFTWARE_REVISION_STRING_CHAR 0x2A28 /**< Software Revision String characteristic UUID. */ +#define BLE_UUID_SUPPORTED_NEW_ALERT_CATEGORY_CHAR 0x2A47 /**< Supported New Alert Category characteristic UUID. */ +#define BLE_UUID_SUPPORTED_UNREAD_ALERT_CATEGORY_CHAR 0x2A48 /**< Supported Unread Alert Category characteristic UUID. */ +#define BLE_UUID_SYSTEM_ID_CHAR 0x2A23 /**< System Id characteristic UUID. */ +#define BLE_UUID_TEMPERATURE_MEASUREMENT_CHAR 0x2A1C /**< Temperature Measurement characteristic UUID. */ +#define BLE_UUID_TEMPERATURE_TYPE_CHAR 0x2A1D /**< Temperature Type characteristic UUID. */ +#define BLE_UUID_TIME_ACCURACY_CHAR 0x2A12 /**< Time Accuracy characteristic UUID. */ +#define BLE_UUID_TIME_SOURCE_CHAR 0x2A13 /**< Time Source characteristic UUID. */ +#define BLE_UUID_TIME_UPDATE_CONTROL_POINT_CHAR 0x2A16 /**< Time Update Control Point characteristic UUID. */ +#define BLE_UUID_TIME_UPDATE_STATE_CHAR 0x2A17 /**< Time Update State characteristic UUID. */ +#define BLE_UUID_TIME_WITH_DST_CHAR 0x2A11 /**< Time With Dst characteristic UUID. */ +#define BLE_UUID_TIME_ZONE_CHAR 0x2A0E /**< Time Zone characteristic UUID. */ +#define BLE_UUID_TX_POWER_LEVEL_CHAR 0x2A07 /**< TX Power Level characteristic UUID. */ +#define BLE_UUID_CSC_FEATURE_CHAR 0x2A5C /**< Cycling Speed and Cadence Feature characteristic UUID. */ +#define BLE_UUID_CSC_MEASUREMENT_CHAR 0x2A5B /**< Cycling Speed and Cadence Measurement characteristic UUID. */ +#define BLE_UUID_RSC_FEATURE_CHAR 0x2A54 /**< Running Speed and Cadence Feature characteristic UUID. */ +#define BLE_UUID_SC_CTRLPT_CHAR 0x2A55 /**< Speed and Cadence Control Point UUID. */ +#define BLE_UUID_RSC_MEASUREMENT_CHAR 0x2A53 /**< Running Speed and Cadence Measurement characteristic UUID. */ +#define BLE_UUID_SENSOR_LOCATION_CHAR 0x2A5D /**< Sensor Location characteristic UUID. */ +#define BLE_UUID_EXTERNAL_REPORT_REF_DESCR 0x2907 /**< External Report Reference descriptor UUID. */ +#define BLE_UUID_REPORT_REF_DESCR 0x2908 /**< Report Reference descriptor UUID. */ +/** @} */ + +/** @defgroup ALERT_LEVEL_VALUES Definitions for the Alert Level characteristic values + * @{ */ +#define BLE_CHAR_ALERT_LEVEL_NO_ALERT 0x00 /**< No Alert. */ +#define BLE_CHAR_ALERT_LEVEL_MILD_ALERT 0x01 /**< Mild Alert. */ +#define BLE_CHAR_ALERT_LEVEL_HIGH_ALERT 0x02 /**< High Alert. */ +/** @} */ + +#define BLE_SRV_ENCODED_REPORT_REF_LEN 2 /**< The length of an encoded Report Reference Descriptor. */ +#define BLE_CCCD_VALUE_LEN 2 /**< The length of a CCCD value. */ + +/**@brief Type definition for error handler function which will be called in case of an error in + * a service or a service library module. */ +typedef void (*ble_srv_error_handler_t) (uint32_t nrf_error); + +/**@brief Value of a Report Reference descriptor. + * + * @details This is mapping information which maps the parent characteristic to the Report ID(s) and + * Report Type(s) defined within a Report Map characteristic. + */ +typedef struct +{ + uint8_t report_id; /**< Non-zero value if these is more than one instance of the same Report Type */ + uint8_t report_type; /**< Type of Report characteristic @if (SD_S110) (see @ref BLE_HIDS_REPORT_TYPE) @endif */ +} ble_srv_report_ref_t; + +/**@brief UTF-8 string data type. + * + * @note The type can only hold a pointer to the string data (i.e. not the actual data). + */ +typedef struct +{ + uint16_t length; /**< String length. */ + uint8_t * p_str; /**< String data. */ +} ble_srv_utf8_str_t; + +/**@brief Security settings structure. + * @details This structure contains the security options needed during initialization of the + * service. + */ +typedef struct +{ + ble_gap_conn_sec_mode_t read_perm; /**< Read permissions. */ + ble_gap_conn_sec_mode_t write_perm; /**< Write permissions. */ +} ble_srv_security_mode_t; + +/**@brief Security settings structure. + * @details This structure contains the security options needed during initialization of the + * service. It can be used when the charecteristics contains cccd. + */ +typedef struct +{ + ble_gap_conn_sec_mode_t cccd_write_perm; + ble_gap_conn_sec_mode_t read_perm; /**< Read permissions. */ + ble_gap_conn_sec_mode_t write_perm; /**< Write permissions. */ +} ble_srv_cccd_security_mode_t; + +/**@brief Function for decoding a CCCD value, and then testing if notification is + * enabled. + * + * @param[in] p_encoded_data Buffer where the encoded CCCD is stored. + * + * @return TRUE if notification is enabled, FALSE otherwise. + */ +static __INLINE bool ble_srv_is_notification_enabled(uint8_t * p_encoded_data) +{ + uint16_t cccd_value = uint16_decode(p_encoded_data); + return ((cccd_value & BLE_GATT_HVX_NOTIFICATION) != 0); +} + +/**@brief Function for decoding a CCCD value, and then testing if indication is + * enabled. + * + * @param[in] p_encoded_data Buffer where the encoded CCCD is stored. + * + * @return TRUE if indication is enabled, FALSE otherwise. + */ +static __INLINE bool ble_srv_is_indication_enabled(uint8_t * p_encoded_data) +{ + uint16_t cccd_value = uint16_decode(p_encoded_data); + return ((cccd_value & BLE_GATT_HVX_INDICATION) != 0); +} + +/**@brief Function for encoding a Report Reference Descriptor. + * + * @param[in] p_encoded_buffer The buffer of the encoded data. + * @param[in] p_report_ref Report Reference value to be encoded. + * + * @return Length of the encoded data. + */ +uint8_t ble_srv_report_ref_encode(uint8_t * p_encoded_buffer, + const ble_srv_report_ref_t * p_report_ref); + +/**@brief Function for making UTF-8 structure refer to an ASCII string. + * + * @param[out] p_utf8 UTF-8 structure to be set. + * @param[in] p_ascii ASCII string to be referred to. + */ +void ble_srv_ascii_to_utf8(ble_srv_utf8_str_t * p_utf8, char * p_ascii); + +#endif // BLE_SRV_COMMON_H__ + +/** @} */ diff --git a/source/nordic_sdk/components/ble/device_manager/config/device_manager_cnfg.h b/source/nordic_sdk/components/ble/device_manager/config/device_manager_cnfg.h index 5189db2..47db10b 100644 --- a/source/nordic_sdk/components/ble/device_manager/config/device_manager_cnfg.h +++ b/source/nordic_sdk/components/ble/device_manager/config/device_manager_cnfg.h @@ -1,119 +1,98 @@ -/* - * Copyright (c) Nordic Semiconductor ASA - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this - * list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of other - * contributors to this software may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - - /** - * @file device_manager_cnfg.h - * - * @cond - * @defgroup device_manager_cnfg Device Manager Configuration - * @ingroup device_manager - * @{ - * - * @brief Defines application specific configuration for Device Manager. - * - * @details All configurations that are specific to application have been defined - * here. Application should configuration that best suits its requirements. - */ - -#ifndef DEVICE_MANAGER_CNFG_H__ -#define DEVICE_MANAGER_CNFG_H__ - -/** - * @defgroup device_manager_inst Device Manager Instances - * @{ - */ -/** - * @brief Maximum applications that Device Manager can support. - * - * @details Maximum application that the Device Manager can support. - * Currently only one application can be supported. - * Minimum value : 1 - * Maximum value : 1 - * Dependencies : None. - */ -#define DEVICE_MANAGER_MAX_APPLICATIONS 1 - -/** - * @brief Maximum connections that Device Manager should simultaneously manage. - * - * @details Maximum connections that Device Manager should simultaneously manage. - * Minimum value : 1 - * Maximum value : Maximum links supported by SoftDevice. - * Dependencies : None. - */ -#define DEVICE_MANAGER_MAX_CONNECTIONS 1 - - -/** - * @brief Maximum bonds that Device Manager should manage. - * - * @details Maximum bonds that Device Manager should manage. - * Minimum value : 1 - * Maximum value : 254. - * Dependencies : None. - * @note In case of GAP Peripheral role, the Device Manager will accept bonding procedure - * requests from peers even if this limit is reached, but bonding information will not - * be stored. In such cases, application will be notified with DM_DEVICE_CONTEXT_FULL - * as event result at the completion of the security procedure. - */ -#define DEVICE_MANAGER_MAX_BONDS 2 - - -/** - * @brief Maximum Characteristic Client Descriptors used for GATT Server. - * - * @details Maximum Characteristic Client Descriptors used for GATT Server. - * Minimum value : 1 - * Maximum value : 254. - * Dependencies : None. - */ -#define DM_GATT_CCCD_COUNT 2 - - -/** - * @brief Size of application context. - * - * @details Size of application context that Device Manager should manage for each bonded device. - * Size had to be a multiple of word size. - * Minimum value : 4. - * Maximum value : 256. - * Dependencies : Needed only if Application Context saving is used by the application. - * @note If set to zero, its an indication that application context is not required to be managed - * by the module. - */ -#define DEVICE_MANAGER_APP_CONTEXT_SIZE 0 - -/* @} */ -/* @} */ -/** @endcond */ -#endif // DEVICE_MANAGER_CNFG_H__ - +/* Copyright (C) 2013 Nordic Semiconductor. All Rights Reserved. + * + * The information contained herein is property of Nordic Semiconductor ASA. + * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. + * + * Licensees are granted free, non-transferable use of the information. NO + * WARRANTY of ANY KIND is provided. This heading must NOT be removed from + * the file. + * + */ + + /** + * @file device_manager_cnfg.h + * + * @cond + * @defgroup device_manager_cnfg Device Manager Configuration + * @ingroup device_manager + * @{ + * + * @brief Defines application specific configuration for Device Manager. + * + * @details All configurations that are specific to application have been defined + * here. Application should configuration that best suits its requirements. + */ + +#ifndef DEVICE_MANAGER_CNFG_H__ +#define DEVICE_MANAGER_CNFG_H__ + +/** + * @defgroup device_manager_inst Device Manager Instances + * @{ + */ +/** + * @brief Maximum applications that Device Manager can support. + * + * @details Maximum application that the Device Manager can support. + * Currently only one application can be supported. + * Minimum value : 1 + * Maximum value : 1 + * Dependencies : None. + */ +#define DEVICE_MANAGER_MAX_APPLICATIONS 1 + +/** + * @brief Maximum connections that Device Manager should simultaneously manage. + * + * @details Maximum connections that Device Manager should simultaneously manage. + * Minimum value : 1 + * Maximum value : Maximum links supported by SoftDevice. + * Dependencies : None. + */ +#define DEVICE_MANAGER_MAX_CONNECTIONS 1 + + +/** + * @brief Maximum bonds that Device Manager should manage. + * + * @details Maximum bonds that Device Manager should manage. + * Minimum value : 1 + * Maximum value : 254. + * Dependencies : None. + * @note In case of GAP Peripheral role, the Device Manager will accept bonding procedure + * requests from peers even if this limit is reached, but bonding information will not + * be stored. In such cases, application will be notified with DM_DEVICE_CONTEXT_FULL + * as event result at the completion of the security procedure. + */ +#define DEVICE_MANAGER_MAX_BONDS 7 + + +/** + * @brief Maximum Characteristic Client Descriptors used for GATT Server. + * + * @details Maximum Characteristic Client Descriptors used for GATT Server. + * Minimum value : 1 + * Maximum value : 254. + * Dependencies : None. + */ +#define DM_GATT_CCCD_COUNT 2 + + +/** + * @brief Size of application context. + * + * @details Size of application context that Device Manager should manage for each bonded device. + * Size had to be a multiple of word size. + * Minimum value : 4. + * Maximum value : 256. + * Dependencies : Needed only if Application Context saving is used by the application. + * @note If set to zero, its an indication that application context is not required to be managed + * by the module. + */ +#define DEVICE_MANAGER_APP_CONTEXT_SIZE 0 + +/* @} */ +/* @} */ +/** @endcond */ +#endif // DEVICE_MANAGER_CNFG_H__ + diff --git a/source/nordic_sdk/components/ble/device_manager/device_manager.h b/source/nordic_sdk/components/ble/device_manager/device_manager.h index 7e4e683..5e7acbc 100644 --- a/source/nordic_sdk/components/ble/device_manager/device_manager.h +++ b/source/nordic_sdk/components/ble/device_manager/device_manager.h @@ -1,917 +1,888 @@ -/* - * Copyright (c) Nordic Semiconductor ASA - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this - * list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of other - * contributors to this software may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -/** - * @file device_manager.h - * - * @defgroup device_manager Device Manager - * @ingroup ble_sdk_lib - * @{ - * @brief Device Manager Application Interface Abstraction. - * - * @details The Device Manager module manages Active and Bonded Peers. Management of peer includes - * book keeping of contextual information like the Security Keys, GATT - * configuration and any application specific information. - * - * Active Peers are devices which are connected, and may or may not be bonded. - * Bonded Peers are devices which are bonded, and may or may not be Active (Connected). - * Active Bonded Peer refers to a device which is connected and bonded. - * - * Paired Devices refers to peer devices that are connected and have necessary context - * establishment/exchange for the current connection session. On disconnect, - * all contextual information is flushed. For example, SMP Information Exchanged during - * pairing and GATT Configuration is not retained on disconnection. - * - * Note that this module allows management of contextual information but - * does not provide an interface for connection management. Therefore, entering connectible - * mode, connection establishment, or disconnection of a link with peer is not in scope - * of this module. - * - * For bonded peers, the contextual information is required to be retained on disconnection - * and power cycling. Persistent storage of contextual information is handled by the - * module. This module categorizes the contextual information into 3 categories: - * - Bonding Information - * Bond information is the information exchanged between local and peer device to - * establish a bond. It also includes peer identification information, - * like the peer address or the IRK or both. From here on this category of information - * is referred to as Device Context. - * - Service/Protocol Information - * Service/Protocol information is the information retained for the peer to save on one-time - * procedures like the GATT Service Discovery procedures and Service Configurations. - * It allows devices to resume data exchange on subsequent reconnection without having - * to perform initial set-up procedures each time. From here on this category is - * referred to as Service Context. - * - Application Information - * Application information is the context that the application would like to associate with - * each of the bonded device. For example, if the application chooses to rank its peers - * in order to manage them better, the rank information could be treated as - * Application Information. This storage space is provided to save the application from - * maintaining a mapping table with each Device Instance and Application Information. - * However, if the application have no use for this, it is possible to not - * use or employ this at compile time. From here on this category of information is - * referred to as Application Context. - */ - - -#ifndef DEVICE_MANAGER_H__ -#define DEVICE_MANAGER_H__ - -#include -#include -#include "sdk_common.h" -#include "ble.h" -#include "ble_gap.h" -#include "device_manager_cnfg.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup dm_service_cntext_types Service/Protocol Types - * - * @brief Describes the possible types of Service/Protocol Contexts for a bonded/peer device. - * - * @details Possible Service/Protocol context per peer device. The Device Manager provides the - * functionality of persistently storing the Service/Protocol context and can automatically - * load them when needed. - * For example system attributes for a GATT Server. Based on the nature of the application, - * not all service types may be needed. The application can specify - * only the service/protocol context it wants to use at the time of registration. - * @{ - */ -#define DM_PROTOCOL_CNTXT_NONE 0x00 /**< No Service Context, this implies the application does not want to associate any service/protocol context with the peer device */ -#define DM_PROTOCOL_CNTXT_GATT_SRVR_ID 0x01 /**< GATT Server Service Context, this implies the application does associate GATT Server with the peer device and this information will be loaded when needed for a bonded device */ -#define DM_PROTOCOL_CNTXT_GATT_CLI_ID 0x02 /**< GATT Client Service Context, this implies the application does associate GATT Client with the peer device and this information will be loaded when needed for a bonded device */ -#define DM_PROTOCOL_CNTXT_ALL \ - (DM_PROTOCOL_CNTXT_GATT_SRVR_ID | DM_PROTOCOL_CNTXT_GATT_CLI_ID) /**< All Service/Protocol Context, this implies that the application wants to associate all Service/Protocol Information with the bonded device. This is configurable based on system requirements. If the application has only one type of service, this define could be altered to reflect the same. */ -/** @} */ - - -/** - * @defgroup dm_events Device Manager Events - * - * @brief This section describes the device manager events that are notified to the application. - * - * @details The Device Manager notifies the application of various asynchronous events using the - * asynchronous event notification callback. All events has been categorized into: - * a. General. - * b. Link Status. - * c. Context Management. - * - * In the callback, these events are notified along with handle that uniquely identifies: - * application instance, active instance (if applicable), device instance - * bonding instance, (if applicable) and service instance. - * Not all events are pertaining to an active connection, for example a context deletion event could occur even if the peer - * is not connected. Also, general category of events may not be pertaining to any specific peer. - * See also \ref dm_event_cb_t and \ref dm_register. - * @{ - */ -/** - * @defgroup general_events General Events - * - * @brief General or miscellaneous events. - * - * @details This category of events are general events not pertaining to a peer or context. - * - * @{ - */ -#define DM_EVT_RFU 0x00 /**< Reserved for future use, is never notified. */ -#define DM_EVT_ERROR 0x01 /**< Device Manager Event Error. */ -/** @} */ - -/** - * @defgroup link_status_events Link Status Events - * - * @brief Link Status Events. - * - * @details This category of events notify the application of the link status. Event result associated - * with the event is provided along with the event in the callback to provide more details of - * whether a procedure succeeded or failed and assist the application in decision making of - * how to proceed. For example if a DM_DEVICE_CONNECT_IND is indicated with NRF_SUCCESS - * result, the application may want to proceed with discovering and association with - * service of the peer. However, if indicated with a failure result, the application may - * want to take an alternate action such as reattempting to connect or go into a - * sleep mode. - * - * @{ - */ -#define DM_EVT_CONNECTION 0x11 /**< Indicates that link with the peer is established. */ -#define DM_EVT_DISCONNECTION 0x12 /**< Indicates that link with peer is torn down. */ -#define DM_EVT_SECURITY_SETUP 0x13 /**< Security procedure for link started indication */ -#define DM_EVT_SECURITY_SETUP_COMPLETE 0x14 /**< Security procedure for link completion indication. */ -#define DM_EVT_LINK_SECURED 0x15 /**< Indicates that link with the peer is secured. For bonded devices, subsequent reconnections with bonded peer will result only in this event when the link is secured and setup procedures will not occur unless the bonding information is either lost or deleted on either or both sides. */ -#define DM_EVT_SECURITY_SETUP_REFRESH 0x16 /**< Indicates that the security on the link was re-established. */ -/** @} */ - -/** - * @defgroup context_mgmt_events Context Management Events - * - * @brief Context Management Events. - * - * @details These events notify the application of the status of context loading and storing. - * - * @{ - */ -#define DM_EVT_DEVICE_CONTEXT_LOADED 0x21 /**< Indicates that device context for a peer is loaded. */ -#define DM_EVT_DEVICE_CONTEXT_STORED 0x22 /**< Indicates that device context is stored persistently. */ -#define DM_EVT_DEVICE_CONTEXT_DELETED 0x23 /**< Indicates that device context is deleted. */ -#define DM_EVT_SERVICE_CONTEXT_LOADED 0x31 /**< Indicates that service context for a peer is loaded. */ -#define DM_EVT_SERVICE_CONTEXT_STORED 0x32 /**< Indicates that service context is stored persistently. */ -#define DM_EVT_SERVICE_CONTEXT_DELETED 0x33 /**< Indicates that service context is deleted. */ -#define DM_EVT_APPL_CONTEXT_LOADED 0x41 /**< Indicates that application context for a peer is loaded. */ -#define DM_EVT_APPL_CONTEXT_STORED 0x42 /**< Indicates that application context is stored persistently. */ -#define DM_EVT_APPL_CONTEXT_DELETED 0x43 /**< Indicates that application context is deleted. */ -/** @} */ -/** @} */ - -#define DM_INVALID_ID 0xFF /**< Invalid instance idenitifer. */ - -/** - * @defgroup dm_data_structure Device Manager Data Types - * - * @brief This section describes all the data types exposed by the module to the application. - * @{ - */ - -/** - * @brief Application Instance. - * - * @details Application instance uniquely identifies an application. The identifier is allocated by - * the device manager when application registers with the module. The application is - * expected to identify itself with this instance identifier when initiating subsequent - * requests. Application should use the utility API \ref dm_application_instance_set in - * order to set its application instance in dm_handle_t needed for all subsequent APIs. - * See also \ref dm_register. - */ -typedef uint8_t dm_application_instance_t; - -/** - * @brief Connection Instance. - * - * @details Identifies connection instance for an active device. This instance is allocated by the - * device manager when a connection is established and is notified with DM_EVT_CONNECTION - * with the event result NRF_SUCCESS. - */ -typedef uint8_t dm_connection_instance_t; - -/** - * @brief Device Instance. - * - * @details Uniquely identifies a bonded peer device. The peer device may or may not be connected. - * In case of the central: The bonded device instance to identify the peer is allocated when bonding procedure is initiated by the central using dm_security_setup_req. - * In case of the peripheral: When the bonding procedure is successful, the DM_EVT_SECURITY_SETUP_COMPLETE event with success event result, is received. - * In case the module cannot add more bonded devices, no instance is allocated, this is indicated by an appropriate error code for the API/event as the case may be. Application can choose to disconnect the link. - */ -typedef uint8_t dm_device_instance_t; - -/** - * @brief Service Instance. - * - * @details Uniquely identifies a peer device. The peer device may or may not be connected. This - * instance is allocated by the device manager when a device is bonded and is notified - * when security procedures have been initiated. - * Security Procedures initiation is notified with DM_SECURITY_SETUP_IND with - * success event result. In case the event result indicates that the module cannot add more - * bonded devices, no instance is allocated. Application can chose to disconnect the link. - */ -typedef uint8_t dm_service_instance_t; - -/** - * @brief Service/Protocol Type Identifier. - * - * @details Uniquely identifies a service or a protocol type. Service/Protocol Type identification - * is needed as each service/protocol can have its own contextual data. - * This allows the peer to access more than one service at a time. \ref dm_service_cntext_types describes the - * list of services/protocols supported. - */ -typedef uint8_t service_type_t; - -/**@brief Device Manager Master identification and encryption information. */ -typedef struct dm_enc_key -{ - ble_gap_enc_info_t enc_info; /**< GAP encryption information. */ - ble_gap_master_id_t master_id; /**< Master identification. */ -} dm_enc_key_t; - -/** @brief Device Manager identity and address information. */ -typedef struct dm_id_key -{ - ble_gap_irk_t id_info; /**< Identity information. */ - ble_gap_addr_t id_addr_info; /**< Identity address information. */ -} dm_id_key_t; - -/** @brief Device Manager signing information. */ -typedef struct dm_sign_key -{ - ble_gap_sign_info_t sign_key; /**< GAP signing information. */ -} dm_sign_key_t; - -/** @brief Security keys. */ -typedef struct dm_sec_keyset -{ - union - { - dm_enc_key_t * p_enc_key; /**< Pointer to Device Manager encryption information structure. */ - } enc_key; - dm_id_key_t * p_id_key; /**< Identity key, or NULL. */ - dm_sign_key_t * p_sign_key; /**< Signing key, or NULL. */ -} dm_sec_keys_t; - -/** @brief Device Manager security key set. */ -typedef struct -{ - dm_sec_keys_t keys_periph; /**< Keys distributed by the device in the Peripheral role. */ - dm_sec_keys_t keys_central; /**< Keys distributed by the device in the Central role. */ -} dm_sec_keyset_t; - -/** - * @brief Device Handle used for unique identification of each peer. - * - * @details This data type is used to uniquely identify each peer device. A peer device could be - * active and/or bonded. Therefore an instance for active and bonded is provided. - * However, the application is expected to treat this is an opaque structure and use this for - * all API interactions once stored on appropriate events. - * See \ref dm_events. - */ -typedef struct device_handle -{ - dm_application_instance_t appl_id; /**< Identifies the application instances for the device that is being managed. */ - dm_connection_instance_t connection_id; /**< Identifies the active connection instance. */ - dm_device_instance_t device_id; /**< Identifies peer instance in the data base. */ - dm_service_instance_t service_id; /**< Service instance identifier. */ -} dm_handle_t; - -/** - * @brief Definition of Data Context. - * - * @details Defines contextual data format, it consists of context data length and pointer to data. - */ -typedef struct -{ - uint32_t flags; /**< Additional flags identifying data. */ - uint32_t len; /**< Length of data. */ - uint8_t * p_data; /**< Pointer to contextual data, a copy is made of the data. */ -} dm_context_t; - - -/** - * @brief Device Context. - * - * @details Defines "device context" type for a device managed by device manager. - */ -typedef dm_context_t dm_device_context_t; - -/** - * @brief Service Context. - * - * @details Service context data for a service identified by the 'service_type' field. - */ -typedef struct -{ - service_type_t service_type; /**< Identifies the service/protocol to which the context data is related. */ - dm_context_t context_data; /**< Contains length and pointer to context data */ -} dm_service_context_t; - -/** - * @brief Application context. - * - * @details The application context can be used by the application to map any application level - * information that is to be mapped with a particular peer. - * For bonded peers, this information will be stored by the bond manager persistently. - * Note that the device manager treats this information as an - * opaque block of bytes. - * Necessary APIs to get and set this context for a peer have been provided. - */ -typedef dm_context_t dm_application_context_t; - -/** - * @brief Event parameters. - * - * @details Defines event parameters for each of the events notified by the module. - */ -typedef union -{ - ble_gap_evt_t * p_gap_param; /**< All events that are triggered in device manager as a result of GAP events, like connection, disconnection and security procedures are accompanied with GAP parameters. */ - dm_application_context_t * p_app_context; /**< All events that are associated with application context procedures of store, load, and deletion have this as event parameter. */ - dm_service_context_t * p_service_context; /**< All events that are associated with service context procedures of store, load and deletion have this as event parameter. */ - dm_device_context_t * p_device_context; /**< All events that are associated with device context procedures of store, load and deletion have this as event parameter. */ -} dm_event_param_t; - -/** - * @brief Asynchronous events details notified to the application by the module. - * - * @details Defines event type along with event parameters notified to the application by the - * module. - */ -typedef struct -{ - uint8_t event_id; /**< Identifies the event. See \ref dm_events for details on event types and their significance. */ - dm_event_param_t event_param; /**< Event parameters. Can be NULL if the event does not have any parameters. */ - uint16_t event_paramlen; /**< Length of the event parameters, is zero if the event does not have any parameters. */ -} dm_event_t; - -/** - * @brief Event notification callback registered by application with the module. - * - * @details Event notification callback registered by application with the module when registering - * the module using \ref dm_register API. - * - * @param[in] p_handle Identifies the peer for which the event is being notified. - * @param[in] p_event Identifies the event, any associated parameters and parameter length. - * See \ref dm_events for details on event types and their significance. - * @param[in,out] event_result Provide additional information on the event. - * In addition to SDK error codes there is also a return value - * indicating if maximum number of connections has been reached when connecting or bonding. - * - * @retval NRF_SUCCESS on success, or a failure to indicate if it could handle the event - * successfully. There is no action taken in case application returns a failure. - */ -typedef ret_code_t (*dm_event_cb_t)(dm_handle_t const * p_handle, - dm_event_t const * p_event, - ret_code_t event_result); - -/** - * @brief Initialization Parameters. - * - * @details Indicates the application parameters. Currently this only encompasses clearing - * all persistent data. - */ -typedef struct -{ - bool clear_persistent_data; /**< Set to true in case the module should clear all persistent data. */ -} dm_init_param_t; - -/** - * @brief Application Registration Parameters. - * - * @details Parameters needed by the module when registering with it. - */ -typedef struct -{ - dm_event_cb_t evt_handler; /**< Event Handler to be registered. It will receive asynchronous notification from the module, see \ref dm_events for asynchronous events. */ - uint8_t service_type; /**< Bit mask identifying services that the application intends to support for all peers. */ - ble_gap_sec_params_t sec_param; /**< Security parameters to be used for the application. */ -} dm_application_param_t; - -/** - * @brief Defines possible security status/states. - * - * @details Defines possible security status/states of a link when requested by application using - * the \ref dm_security_status_req. - */ -typedef enum -{ - NOT_ENCRYPTED, /**< The link is not secured. */ - ENCRYPTION_IN_PROGRESS, /**< Link security is being established.*/ - ENCRYPTED /**< The link is secure.*/ -} dm_security_status_t; -/** @} */ - -/** - * @defgroup dm_api Device Module APIs - * - * @brief This section describes APIs exposed by the module. - * - * @details This section describes APIs exposed by the module. The APIs have been categorized to provide - * better and specific look up for developers. Categories are: - * - Set up APIs. - * - Context Management APIs. - * - Utility APIs. - * - * MSCs describe usage of these APIs. - * See @ref dm_msc. - * @{ - */ -/** - * @defgroup dm_setup_api Device Module Set-up APIs - * - * @brief Initialization & registration APIs that are pre-requisite for all other module procedures. - * @details This section describes the Module Initialization and Registration APIs needed to be set up by - * the application before device manager can start managing devices and device contexts - * for the application. - * - * @{ - */ - -/** - * @brief Module Initialization Routine. - * - * @details Function for initializing the module. Must called before any other APIs of the module are used. - * - * @param[in] p_init_param Initialization parameters. - * - * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. - * - * @note It is mandatory that pstorage is initialized before initializing this module. - */ -ret_code_t dm_init(dm_init_param_t const * p_init_param); - -/** - * @brief Function for registering the application. - * - * @details This routine is used by the application to register for asynchronous events with the - * device manager. During registration the application also indicates the services that it - * intends to support on this instance. It is possible to register multiple times with the - * device manager. At least one instance shall be registered with the device manager after - * the module has been initialized. - * Maximum number of application instances device manager can support is determined - * by DM_MAX_APPLICATIONS. - * - * All applications must be registered before initiating or accepting connections from the peer. - * - * @param[in] p_appl_param Application parameters. - * @param[out] p_appl_instance Application Instance Identifier in case registration is successful. - * - * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. - * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization. - * @retval NRF_ERROR_NO_MEM If module cannot support more applications. - * - * @note Currently only one application instance is supported by the module. - */ -ret_code_t dm_register(dm_application_instance_t * p_appl_instance, - dm_application_param_t const * p_appl_param); - -/** - * @brief Function for handling BLE events. - * - * @details BLE Event Handler for the module. This routine should be called from BLE stack event - * dispatcher for the module to work as expected. - * - * @param[in] p_ble_evt BLE stack event being dispatched to the function. - * - */ -void dm_ble_evt_handler(ble_evt_t * p_ble_evt); - -/** @} */ - - -/** - * @defgroup dm_security_api APIs to set up or read status of security on a link. - * - * @brief This section describes APIs to set up Security. These APIs require that the peer is - * connected before the procedures can be requested. - * - * @details This group allows application to request security procedures - * or get the status of the security on a link. - * @{ - */ -/** - * @brief Function for requesting setting up security on a link. - * - * @details This API initiates security procedures with a peer device. - * @note For the GAP Central role, in case peer is not bonded, request to bond/pair is - * initiated. If it is bonded, the link is re-encrypted using the existing bond information. - * For the GAP peripheral role, a Slave security request is sent. - * @details If a pairing procedure is initiated successfully, application is notified of - * @ref DM_EVT_SECURITY_SETUP_COMPLETE. A result indicating success or failure is notified along with the event. - * In case the link is re-encrypted using existing bond information, @ref DM_EVT_LINK_SECURED is - * notified to the application. - * - * @param[in] p_handle Identifies the link on which security is desired. - * - * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. - * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or - * application registration. - * @retval NRF_ERROR_NULL If p_handle is NULL. - * @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application - * or if the peer is not connected when this procedure is requested. - */ -ret_code_t dm_security_setup_req(dm_handle_t * p_handle); - -/** - * @brief Function for reading the status of the security on a link. - * - * @details This API allows application to query status of security on a link. - * - * @param[in] p_handle Identifies the link on which security is desired. - * @param[out] p_status Pointer where security status is provided to the application. - * See \ref dm_security_status_t for possible statuses that can be expected. - * - * @retval NRF_SUCCESS Or appropriate error code indicating reason for failure. - * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or - * application registration. - * @retval NRF_ERROR_NULL If p_handle or p_status is NULL. - * @retval NRF_ERROR_INVALID_ADDR If peer is not identified by the handle provided by the application - * or if peer is not connected when this procedure is requested. - */ -ret_code_t dm_security_status_req(dm_handle_t const * p_handle, dm_security_status_t * p_status); - -/** - * @brief Function for creating the whitelist. - * - * @details This API allows application to create whitelist based on bonded peer devices in module - * data base. - * - * @param[in] p_handle Identifies the application requesting whitelist creation. - * @param[in,out] p_whitelist Pointer where created whitelist is provided to the application. - * - * @note 'addr_count' and 'irk_count' fields of the structure should be populated with the maximum - * number of devices that the application wishes to request in the whitelist. - * If the number of bonded devices is less than requested, the fields are updated with that number of devices. - * If the number of devices are more than requested, the module will populate the list - * with devices in the order the bond was established with the peer devices. Also, if this routine is - * called when a connection exists with one or more peer devices, - * those connected devices are not added to the whitelist. - * - * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. - * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or - * application registration. - * @retval NRF_ERROR_NULL If p_handle or p_whitelist is NULL. - */ -ret_code_t dm_whitelist_create(dm_application_instance_t const * p_handle, - ble_gap_whitelist_t * p_whitelist); - -/** @} */ - - -/** - * @defgroup dm_cntxt_mgmt_api Context Management APIs - * - * @brief Utility APIs offered by the device manager to get information about the peer if and - * when needed. - * - * @details This group of API allow the application to access information that is not required to be - * maintained by the application but may be needed. Hence it is possible to get the - * information from the module instead of mapping all the information with a device - * context. - * @{ - */ - -ret_code_t dm_device_add(dm_handle_t * p_handle, - dm_device_context_t const * p_context); - -/** - * @brief Function for deleting a peer device context and all related information from the database. - * - * @details Delete peer device context and all related information from database. If - * this API returns NRF_SUCCESS, DM_EVT_DEVICE_CONTEXT_DELETED event is notified to the - * application. Event result notified along with the event indicates success or failure - * of this procedure. - * - * @param[in] p_handle Identifies the peer device to be deleted. - * - * @retval NRF_SUCCESS on success, else an error code indicating reason for failure. - * @retval NRF_ERROR_INVALID_STATE In the API is called without module initialization and/or - * application registration. - * @retval NRF_ERROR_NULL If p_handle is NULL. - * @retval NRF_ERROR_INVALID_ADDR If peer is not identified the handle provided by the application. - * - * @note Deleting device context results in deleting service and application context for the - * bonded device. The respective events DM_EVT_SERVICE_CONTEXT_DELETED and - * DM_EVT_APPL_CONTEXT_DELETED are not notified to the application. - */ -ret_code_t dm_device_delete(dm_handle_t const * p_handle); - -/** - * @brief Function for deleting all peer device context and all related information from the database. - * - * @details Delete peer device context and all related information from database. If - * this API returns NRF_SUCCESS, DM_EVT_DEVICE_CONTEXT_DELETED event is notified to the - * application for each device that is deleted from the data base. Event result - * notified along with the event indicates success or failure of this procedure. - * - * @param[in] p_handle Identifies application instance that is requesting - * the deletion of all bonded devices. - * - * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. - * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or - * application registration. - * @retval NRF_ERROR_NULL If p_handle is NULL. - * @retval NRF_ERROR_INVALID_ADDR If peer is not identified the handle provided by the application. - * - * @note Deleting device context results in deleting both service and application context for the - * bonded device. The respective events DM_EVT_SERVICE_CONTEXT_DELETED and - * DM_EVT_APPL_CONTEXT_DELETED are not notified to the application. - */ -ret_code_t dm_device_delete_all(dm_application_instance_t const * p_handle); - -/** - * @brief Function for setting Service Context for a peer device identified by 'p_handle' parameter. - * - * @details This API allows application to Set Service Context for a peer device identified by the - * 'p_handle' parameter. This API is useful when the Service Context cannot be requested - * from the SoftDevice, but needs to be assembled by the application or an another module. - * (or when service context is exchanged in an out of band way.) - * This API could also be used to trigger a storing of service context into persistent - * memory. If this is desired, a NULL pointer could be passed to the p_context. - * - * @param[in] p_handle Identifies peer device for which the procedure is requested. - * @param[in] p_context Service context being set. The context information includes length of - * data and pointer to the contextual data being set. The memory pointed to by - * the pointer to data is assumed to be resident when API is being called and - * can be freed or reused once the set procedure is complete. Set procedure - * completion is indicated by the event \ref DM_EVT_SERVICE_CONTEXT_STORED. - * The Event result is notified along with the event and indicates success or failure of - * this procedure. - * - * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. - * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or - * application registration. - * @retval NRF_ERROR_NULL If p_handle is NULL. - * @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application. - */ -ret_code_t dm_service_context_set(dm_handle_t const * p_handle, - dm_service_context_t const * p_context); - -/** - * @brief Function for getting Service Context for a peer device identified by 'p_handle' parameter. - * - * @details Get Service Context for a peer device identified by the 'p_handle' parameter. If - * this API returns NRF_SUCCESS, DM_EVT_SERVICE_CONTEXT_LOADED event is notified to the - * application. The event result is notified along with the event indicates success or failure - * of this procedure. - * - * @param[in] p_handle Identifies peer device for which procedure is requested. - * @param[in] p_context Application context being requested. The context information includes length - * of the data and a pointer to the data. Note that requesting a 'get' - * of application does not need to provide memory, the pointer to data will be - * pointing to service data and hence no data movement is involved. - * - * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. - * @retval NRF_ERROR_INVALID_STATE In case API is called without module initialization and/or - * application registration. - * @retval NRF_ERROR_NULL If p_handle is NULL. - * @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application. - */ -ret_code_t dm_service_context_get(dm_handle_t const * p_handle, - dm_service_context_t * p_context); - -/** - * @brief Function for deleting a Service Context for a peer device identified by the 'p_handle' parameter. - * - * @details This API allows application to delete a Service Context identified for a peer device - * identified by the 'p_handle' parameter. If this API returns NRF_SUCCESS, - * DM_EVT_SERVICE_CONTEXT_DELETED event is notified to the application. - * Event result is notified along with the event and indicates success or failure of this - * procedure. - * - * @param[in] p_handle Identifies peer device for which procedure is requested. - * - * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. - * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or - * application registration. - * @retval NRF_ERROR_NULL If p_handle is NULL. - * @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application. - */ -ret_code_t dm_service_context_delete(dm_handle_t const * p_handle); - -/** - * @brief Function for setting Application Context for a peer device identified by the 'p_handle' parameter. - * - * @details This application allows the setting of the application context for the peer device identified by - * the 'p_handle'. Application context is stored persistently by the module and can be - * requested by the application at any time using the \ref dm_application_context_get - * API. Note that this procedure is permitted only for bonded devices. If the - * device is not bonded, application context cannot be set. However, it is not mandatory - * that the bonded device is connected when requesting this procedure. - * - * @param[in] p_handle Identifies peer device for which procedure is requested. - * - * @param[in] p_context Application context being set. The context information includes length of the - * data and pointer to the contextual data being set. The memory pointed to by - * the data pointer is assumed to be resident when API is being called and - * can be freed or reused once the set procedure is complete. Set procedure - * completion is notified by the event \ref DM_EVT_APPL_CONTEXT_STORED. - * The event result is notified along with the event and indicates success or - * failure of this procedure. - * - * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. - * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or - * application registration. - * @retval NRF_ERROR_NULL If p_handle and/or p_context is NULL. - * @retval NRF_ERROR_INVALID_ADDR If peer is not identified the handle provided by the application. - * - * @note The API returns FEATURE_NOT_ENABLED in case DEVICE_MANAGER_APP_CONTEXT_SIZE is set to zero. - */ -ret_code_t dm_application_context_set(dm_handle_t const * p_handle, - dm_application_context_t const * p_context); - -/** - * @brief Function for getting Application Context for a peer device identified by the 'p_handle' parameter. - * - * @details Get Application Context for a peer device identified by the 'p_handle' parameter. If - * this API returns NRF_SUCCESS, DM_EVT_APPL_CONTEXT_LOADED event is notified to the - * application. Event result notified along with the event indicates success or failure - * of this procedure. - * - * @param[in] p_handle Identifies peer device for which procedure is requested. - * @param[in] p_context Application context being requested. The context information includes - * length of data and pointer to the contextual data is provided. - * - * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. - * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or - * application registration. - * @retval NRF_ERROR_NULL If p_handle and/or p_context is NULL. - * @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application. - * @retval DM_NO_APP_CONTEXT If no application context was set that can be fetched. - * - * @note The API returns FEATURE_NOT_ENABLED in case DEVICE_MANAGER_APP_CONTEXT_SIZE is set to - * zero. - */ -ret_code_t dm_application_context_get(dm_handle_t const * p_handle, - dm_application_context_t * p_context); - -/** - * @brief Function for deleting Application Context for a peer device identified by the 'p_handle' parameter. - * - * @details Delete Application Context for a peer device identified by the 'p_handle' parameter. If - * this API returns NRF_SUCCESS, DM_EVT_APPL_CONTEXT_DELETED event is notified to the - * application. The event result notified along with the event and indicates success or failure - * of this procedure. - * - * @param[in] p_handle Identifies peer device for which procedure is requested. - * - * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. - * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or - * application registration. - * @retval NRF_ERROR_NULL If the p_handle is NULL. - * @retval NRF_ERROR_INVALID_ADDR If peer is not identified the handle provided by the application. - * @retval DM_NO_APP_CONTEXT If no application context was set that can be deleted. - * - * @note The API returns FEATURE_NOT_ENABLED if the DEVICE_MANAGER_APP_CONTEXT_SIZE is set to zero. - */ -ret_code_t dm_application_context_delete(dm_handle_t const * p_handle); - -/** @} */ - - -/** - * @defgroup utility_api Utility APIs - * @{ - * @brief This section describes the utility APIs offered by the module. - * - * @details APIs defined in this section are utility or assisting/helper APIs. - */ -/** - * @brief Function for Setting/Copying Application instance to Device Manager handle. - * - * @param[in] p_appl_instance Application instance to be set. - * @param[out] p_handle Device Manager handle for which the instance is to be copied. - * - * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. - * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or - * application registration. - * @retval NRF_ERROR_NULL If p_handle and/or p_addr is NULL. - */ -ret_code_t dm_application_instance_set(dm_application_instance_t const * p_appl_instance, - dm_handle_t * p_handle); - -/** - * @brief Function for getting a peer's device address. - * - * @param[in] p_handle Identifies the peer device whose address is requested. Can not be NULL. - * @param[out] p_addr Pointer where address is to be copied. Can not be NULL. - * - * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. - * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or - * application registration. - * @retval NRF_ERROR_NULL If p_handle and/or p_addr is NULL. - * @retval NRF_ERROR_NOT_FOUND If the peer could not be identified. - */ -ret_code_t dm_peer_addr_get(dm_handle_t const * p_handle, - ble_gap_addr_t * p_addr); - -/** - * @brief Function for setting/updating a peer's device address. - * - * @param[in] p_handle Identifies the peer device whose address is requested to be set/updated. - * @param[out] p_addr Address to be set/updated. - * - * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. - * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or - * application registration. - * @retval NRF_ERROR_NULL If p_handle and/or p_addr is NULL. - * @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application. - * @retval NRF_ERROR_INVALID_PARAM If this procedure is requested while connected to the peer or if the address - * type was set to BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE. - * - * @note Setting or updating a peer's device address is permitted - * only for a peer that is bonded and disconnected. - * @note Updated address is reflected only after DM_EVT_DEVICE_CONTEXT_STORED is notified to the - * application for this bonded device instance. In order to avoid abnormal behaviour, it is - * recommended to not invite/initiate connections on the updated address unless this event - * has been notified. - */ -ret_code_t dm_peer_addr_set(dm_handle_t const * p_handle, - ble_gap_addr_t const * p_addr); - -/** - * @brief Function for initializing Device Manager handle. - * - * @param[in] p_handle Device Manager handle to be initialized. - * - * @retval NRF_SUCCESS On success. - * @retval NRF_ERROR_NULL If p_handle is NULL. - * - * @note This routine is permitted before initialization of the module. - */ -ret_code_t dm_handle_initialize(dm_handle_t * p_handle); - -/** - * @brief Function for getting distributed keys for a device. - * - * @param[in] p_handle Device Manager handle identifying the peer. - * @param[out] p_key_dist Pointer to distributed keys. - * - * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. - * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or - * application registration. - * @retval NRF_ERROR_NULL If the p_handle and/or p_key_dist pointer is NULL. - * @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application. - */ -ret_code_t dm_distributed_keys_get(dm_handle_t const * p_handle, - dm_sec_keyset_t * p_key_dist); - -/** - * @brief Function for getting the corresponding dm_handle_t based on the connection handle. - * - * @param[in] conn_handle Connection handle as provided by the SoftDevice. - * @param[in,out] p_handle Pointer to the p_handle containg the application instance for the - * registered application. If the application instance is valid then - * the p_handle will be filled with requested data. - * - * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. - * @retval NRF_ERROR_NULL If the p_handle pointer is NULL. - * @retval NRF_ERROR_NOT_FOUND If no p_handle is found for the provided connection handle. - */ -ret_code_t dm_handle_get(uint16_t conn_handle, dm_handle_t * p_handle); - -#ifdef __cplusplus -} -#endif - -/** @} */ -/** @} */ -/** @} */ -#endif // DEVICE_MANAGER_H__ - +/* Copyright (C) 2013 Nordic Semiconductor. All Rights Reserved. + * + * The information contained herein is property of Nordic Semiconductor ASA. + * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. + * + * Licensees are granted free, non-transferable use of the information. NO + * WARRANTY of ANY KIND is provided. This heading must NOT be removed from + * the file. + * + */ + +/** + * @file device_manager.h + * + * @defgroup device_manager Device Manager + * @ingroup ble_sdk_lib + * @{ + * @brief Device Manager Application Interface Abstraction. + * + * @details The Device Manager module manages Active and Bonded Peers. Management of peer includes + * book keeping of contextual information like the Security Keys, GATT + * configuration and any application specific information. + * + * Active Peers are devices which are connected, and may or may not be bonded. + * Bonded Peers are devices which are bonded, and may or may not be Active (Connected). + * Active Bonded Peer refers to a device which is connected and bonded. + * + * Paired Devices refers to peer devices that are connected and have necessary context + * establishment/exchange for the current connection session. On disconnect, + * all contextual information is flushed. For example, SMP Information Exchanged during + * pairing and GATT Configuration is not retained on disconnection. + * + * Note that this module allows management of contextual information but + * does not provide an interface for connection management. Therefore, entering connectible + * mode, connection establishment, or disconnection of a link with peer is not in scope + * of this module. + * + * For bonded peers, the contextual information is required to be retained on disconnection + * and power cycling. Persistent storage of contextual information is handled by the + * module. This module categorizes the contextual information into 3 categories: + * - Bonding Information + * Bond information is the information exchanged between local and peer device to + * establish a bond. It also includes peer identification information, + * like the peer address or the IRK or both. From here on this category of information + * is referred to as Device Context. + * - Service/Protocol Information + * Service/Protocol information is the information retained for the peer to save on one-time + * procedures like the GATT Service Discovery procedures and Service Configurations. + * It allows devices to resume data exchange on subsequent reconnection without having + * to perform initial set-up procedures each time. From here on this category is + * referred to as Service Context. + * - Application Information + * Application information is the context that the application would like to associate with + * each of the bonded device. For example, if the application chooses to rank its peers + * in order to manage them better, the rank information could be treated as + * Application Information. This storage space is provided to save the application from + * maintaining a mapping table with each Device Instance and Application Information. + * However, if the application have no use for this, it is possible to not + * use or employ this at compile time. From here on this category of information is + * referred to as Application Context. + */ + + +#ifndef DEVICE_MANAGER_H__ +#define DEVICE_MANAGER_H__ + +#include +#include +#include "sdk_common.h" +#include "ble.h" +#include "ble_gap.h" +#include "device_manager_cnfg.h" + +/** + * @defgroup dm_service_cntext_types Service/Protocol Types + * + * @brief Describes the possible types of Service/Protocol Contexts for a bonded/peer device. + * + * @details Possible Service/Protocol context per peer device. The Device Manager provides the + * functionality of persistently storing the Service/Protocol context and can automatically + * load them when needed. + * For example system attributes for a GATT Server. Based on the nature of the application, + * not all service types may be needed. The application can specify + * only the service/protocol context it wants to use at the time of registration. + * @{ + */ +#define DM_PROTOCOL_CNTXT_NONE 0x00 /**< No Service Context, this implies the application does not want to associate any service/protocol context with the peer device */ +#define DM_PROTOCOL_CNTXT_GATT_SRVR_ID 0x01 /**< GATT Server Service Context, this implies the application does associate GATT Server with the peer device and this information will be loaded when needed for a bonded device */ +#define DM_PROTOCOL_CNTXT_GATT_CLI_ID 0x02 /**< GATT Client Service Context, this implies the application does associate GATT Client with the peer device and this information will be loaded when needed for a bonded device */ +#define DM_PROTOCOL_CNTXT_ALL \ + (DM_PROTOCOL_CNTXT_GATT_SRVR_ID | DM_PROTOCOL_CNTXT_GATT_CLI_ID) /**< All Service/Protocol Context, this implies that the application wants to associate all Service/Protocol Information with the bonded device. This is configurable based on system requirements. If the application has only one type of service, this define could be altered to reflect the same. */ +/** @} */ + + +/** + * @defgroup dm_events Device Manager Events + * + * @brief This section describes the device manager events that are notified to the application. + * + * @details The Device Manager notifies the application of various asynchronous events using the + * asynchronous event notification callback. All events has been categorized into: + * a. General. + * b. Link Status. + * c. Context Management. + * + * In the callback, these events are notified along with handle that uniquely identifies: + * application instance, active instance (if applicable), device instance + * bonding instance, (if applicable) and service instance. + * Not all events are pertaining to an active connection, for example a context deletion event could occur even if the peer + * is not connected. Also, general category of events may not be pertaining to any specific peer. + * See also \ref dm_event_cb_t and \ref dm_register. + * @{ + */ +/** + * @defgroup general_events General Events + * + * @brief General or miscellaneous events. + * + * @details This category of events are general events not pertaining to a peer or context. + * + * @{ + */ +#define DM_EVT_RFU 0x00 /**< Reserved for future use, is never notified. */ +#define DM_EVT_ERROR 0x01 /**< Device Manager Event Error. */ +/** @} */ + +/** + * @defgroup link_status_events Link Status Events + * + * @brief Link Status Events. + * + * @details This category of events notify the application of the link status. Event result associated + * with the event is provided along with the event in the callback to provide more details of + * whether a procedure succeeded or failed and assist the application in decision making of + * how to proceed. For example if a DM_DEVICE_CONNECT_IND is indicated with NRF_SUCCESS + * result, the application may want to proceed with discovering and association with + * service of the peer. However, if indicated with a failure result, the application may + * want to take an alternate action such as reattempting to connect or go into a + * sleep mode. + * + * @{ + */ +#define DM_EVT_CONNECTION 0x11 /**< Indicates that link with the peer is established. */ +#define DM_EVT_DISCONNECTION 0x12 /**< Indicates that link with peer is torn down. */ +#define DM_EVT_SECURITY_SETUP 0x13 /**< Security procedure for link started indication */ +#define DM_EVT_SECURITY_SETUP_COMPLETE 0x14 /**< Security procedure for link completion indication. */ +#define DM_EVT_LINK_SECURED 0x15 /**< Indicates that link with the peer is secured. For bonded devices, subsequent reconnections with bonded peer will result only in this event when the link is secured and setup procedures will not occur unless the bonding information is either lost or deleted on either or both sides. */ +#define DM_EVT_SECURITY_SETUP_REFRESH 0x16 /**< Indicates that the security on the link was re-established. */ +/** @} */ + +/** + * @defgroup context_mgmt_events Context Management Events + * + * @brief Context Management Events. + * + * @details These events notify the application of the status of context loading and storing. + * + * @{ + */ +#define DM_EVT_DEVICE_CONTEXT_LOADED 0x21 /**< Indicates that device context for a peer is loaded. */ +#define DM_EVT_DEVICE_CONTEXT_STORED 0x22 /**< Indicates that device context is stored persistently. */ +#define DM_EVT_DEVICE_CONTEXT_DELETED 0x23 /**< Indicates that device context is deleted. */ +#define DM_EVT_SERVICE_CONTEXT_LOADED 0x31 /**< Indicates that service context for a peer is loaded. */ +#define DM_EVT_SERVICE_CONTEXT_STORED 0x32 /**< Indicates that service context is stored persistently. */ +#define DM_EVT_SERVICE_CONTEXT_DELETED 0x33 /**< Indicates that service context is deleted. */ +#define DM_EVT_APPL_CONTEXT_LOADED 0x41 /**< Indicates that application context for a peer is loaded. */ +#define DM_EVT_APPL_CONTEXT_STORED 0x42 /**< Indicates that application context is stored persistently. */ +#define DM_EVT_APPL_CONTEXT_DELETED 0x43 /**< Indicates that application context is deleted. */ +/** @} */ +/** @} */ + +#define DM_INVALID_ID 0xFF /**< Invalid instance idenitifer. */ + +/** + * @defgroup dm_data_structure Device Manager Data Types + * + * @brief This section describes all the data types exposed by the module to the application. + * @{ + */ + +/** + * @brief Application Instance. + * + * @details Application instance uniquely identifies an application. The identifier is allocated by + * the device manager when application registers with the module. The application is + * expected to identify itself with this instance identifier when initiating subsequent + * requests. Application should use the utility API \ref dm_application_instance_set in + * order to set its application instance in dm_handle_t needed for all subsequent APIs. + * See also \ref dm_register. + */ +typedef uint8_t dm_application_instance_t; + +/** + * @brief Connection Instance. + * + * @details Identifies connection instance for an active device. This instance is allocated by the + * device manager when a connection is established and is notified with DM_EVT_CONNECTION + * with the event result NRF_SUCCESS. + */ +typedef uint8_t dm_connection_instance_t; + +/** + * @brief Device Instance. + * + * @details Uniquely identifies a bonded peer device. The peer device may or may not be connected. + * In case of the central: The bonded device instance to identify the peer is allocated when bonding procedure is initiated by the central using dm_security_setup_req. + * In case of the peripheral: When the bonding procedure is successful, the DM_EVT_SECURITY_SETUP_COMPLETE event with success event result, is received. + * In case the module cannot add more bonded devices, no instance is allocated, this is indicated by an appropriate error code for the API/event as the case may be. Application can choose to disconnect the link. + */ +typedef uint8_t dm_device_instance_t; + +/** + * @brief Service Instance. + * + * @details Uniquely identifies a peer device. The peer device may or may not be connected. This + * instance is allocated by the device manager when a device is bonded and is notified + * when security procedures have been initiated. + * Security Procedures initiation is notified with DM_SECURITY_SETUP_IND with + * success event result. In case the event result indicates that the module cannot add more + * bonded devices, no instance is allocated. Application can chose to disconnect the link. + */ +typedef uint8_t dm_service_instance_t; + +/** + * @brief Service/Protocol Type Identifier. + * + * @details Uniquely identifies a service or a protocol type. Service/Protocol Type identification + * is needed as each service/protocol can have its own contextual data. + * This allows the peer to access more than one service at a time. \ref dm_service_cntext_types describes the + * list of services/protocols supported. + */ +typedef uint8_t service_type_t; + +/**@brief Device Manager Master identification and encryption information. */ +typedef struct dm_enc_key +{ + ble_gap_enc_info_t enc_info; /**< GAP encryption information. */ + ble_gap_master_id_t master_id; /**< Master identification. */ +} dm_enc_key_t; + +/** @brief Device Manager identity and address information. */ +typedef struct dm_id_key +{ + ble_gap_irk_t id_info; /**< Identity information. */ + ble_gap_addr_t id_addr_info; /**< Identity address information. */ +} dm_id_key_t; + +/** @brief Device Manager signing information. */ +typedef struct dm_sign_key +{ + ble_gap_sign_info_t sign_key; /**< GAP signing information. */ +} dm_sign_key_t; + +/** @brief Security keys. */ +typedef struct dm_sec_keyset +{ + union + { + dm_enc_key_t * p_enc_key; /**< Pointer to Device Manager encryption information structure. */ + } enc_key; + dm_id_key_t * p_id_key; /**< Identity key, or NULL. */ + dm_sign_key_t * p_sign_key; /**< Signing key, or NULL. */ +} dm_sec_keys_t; + +/** @brief Device Manager security key set. */ +typedef struct +{ + dm_sec_keys_t keys_periph; /**< Keys distributed by the device in the Peripheral role. */ + dm_sec_keys_t keys_central; /**< Keys distributed by the device in the Central role. */ +} dm_sec_keyset_t; + +/** + * @brief Device Handle used for unique identification of each peer. + * + * @details This data type is used to uniquely identify each peer device. A peer device could be + * active and/or bonded. Therefore an instance for active and bonded is provided. + * However, the application is expected to treat this is an opaque structure and use this for + * all API interactions once stored on appropriate events. + * See \ref dm_events. + */ +typedef struct device_handle +{ + dm_application_instance_t appl_id; /**< Identifies the application instances for the device that is being managed. */ + dm_connection_instance_t connection_id; /**< Identifies the active connection instance. */ + dm_device_instance_t device_id; /**< Identifies peer instance in the data base. */ + dm_service_instance_t service_id; /**< Service instance identifier. */ +} dm_handle_t; + +/** + * @brief Definition of Data Context. + * + * @details Defines contextual data format, it consists of context data length and pointer to data. + */ +typedef struct +{ + uint32_t flags; /**< Additional flags identifying data. */ + uint32_t len; /**< Length of data. */ + uint8_t * p_data; /**< Pointer to contextual data, a copy is made of the data. */ +} dm_context_t; + + +/** + * @brief Device Context. + * + * @details Defines "device context" type for a device managed by device manager. + */ +typedef dm_context_t dm_device_context_t; + +/** + * @brief Service Context. + * + * @details Service context data for a service identified by the 'service_type' field. + */ +typedef struct +{ + service_type_t service_type; /**< Identifies the service/protocol to which the context data is related. */ + dm_context_t context_data; /**< Contains length and pointer to context data */ +} dm_service_context_t; + +/** + * @brief Application context. + * + * @details The application context can be used by the application to map any application level + * information that is to be mapped with a particular peer. + * For bonded peers, this information will be stored by the bond manager persistently. + * Note that the device manager treats this information as an + * opaque block of bytes. + * Necessary APIs to get and set this context for a peer have been provided. + */ +typedef dm_context_t dm_application_context_t; + +/** + * @brief Event parameters. + * + * @details Defines event parameters for each of the events notified by the module. + */ +typedef union +{ + ble_gap_evt_t * p_gap_param; /**< All events that are triggered in device manager as a result of GAP events, like connection, disconnection and security procedures are accompanied with GAP parameters. */ + dm_application_context_t * p_app_context; /**< All events that are associated with application context procedures of store, load, and deletion have this as event parameter. */ + dm_service_context_t * p_service_context; /**< All events that are associated with service context procedures of store, load and deletion have this as event parameter. */ + dm_device_context_t * p_device_context; /**< All events that are associated with device context procedures of store, load and deletion have this as event parameter. */ +} dm_event_param_t; + +/** + * @brief Asynchronous events details notified to the application by the module. + * + * @details Defines event type along with event parameters notified to the application by the + * module. + */ +typedef struct +{ + uint8_t event_id; /**< Identifies the event. See \ref dm_events for details on event types and their significance. */ + dm_event_param_t event_param; /**< Event parameters. Can be NULL if the event does not have any parameters. */ + uint16_t event_paramlen; /**< Length of the event parameters, is zero if the event does not have any parameters. */ +} dm_event_t; + +/** + * @brief Event notification callback registered by application with the module. + * + * @details Event notification callback registered by application with the module when registering + * the module using \ref dm_register API. + * + * @param[in] p_handle Identifies the peer for which the event is being notified. + * @param[in] p_event Identifies the event, any associated parameters and parameter length. + * See \ref dm_events for details on event types and their significance. + * @param[in,out] event_result Provide additional information on the event. + * In addition to SDK error codes there is also a return value + * indicating if maximum number of connections has been reached when connecting or bonding. + * + * @retval NRF_SUCCESS on success, or a failure to indicate if it could handle the event + * successfully. There is no action taken in case application returns a failure. + */ +typedef ret_code_t (*dm_event_cb_t)(dm_handle_t const * p_handle, + dm_event_t const * p_event, + ret_code_t event_result); + +/** + * @brief Initialization Parameters. + * + * @details Indicates the application parameters. Currently this only encompasses clearing + * all persistent data. + */ +typedef struct +{ + bool clear_persistent_data; /**< Set to true in case the module should clear all persistent data. */ +} dm_init_param_t; + +/** + * @brief Application Registration Parameters. + * + * @details Parameters needed by the module when registering with it. + */ +typedef struct +{ + dm_event_cb_t evt_handler; /**< Event Handler to be registered. It will receive asynchronous notification from the module, see \ref dm_events for asynchronous events. */ + uint8_t service_type; /**< Bit mask identifying services that the application intends to support for all peers. */ + ble_gap_sec_params_t sec_param; /**< Security parameters to be used for the application. */ +} dm_application_param_t; + +/** + * @brief Defines possible security status/states. + * + * @details Defines possible security status/states of a link when requested by application using + * the \ref dm_security_status_req. + */ +typedef enum +{ + NOT_ENCRYPTED, /**< The link is not secured. */ + ENCRYPTION_IN_PROGRESS, /**< Link security is being established.*/ + ENCRYPTED /**< The link is secure.*/ +} dm_security_status_t; +/** @} */ + +/** + * @defgroup dm_api Device Module APIs + * + * @brief This section describes APIs exposed by the module. + * + * @details This section describes APIs exposed by the module. The APIs have been categorized to provide + * better and specific look up for developers. Categories are: + * - Set up APIs. + * - Context Management APIs. + * - Utility APIs. + * + * MSCs describe usage of these APIs. + * See @ref dm_msc. + * @{ + */ +/** + * @defgroup dm_setup_api Device Module Set-up APIs + * + * @brief Initialization & registration APIs that are pre-requisite for all other module procedures. + * @details This section describes the Module Initialization and Registration APIs needed to be set up by + * the application before device manager can start managing devices and device contexts + * for the application. + * + * @{ + */ + +/** + * @brief Module Initialization Routine. + * + * @details Function for initializing the module. Must called before any other APIs of the module are used. + * + * @param[in] p_init_param Initialization parameters. + * + * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. + * + * @note It is mandatory that pstorage is initialized before initializing this module. + */ +ret_code_t dm_init(dm_init_param_t const * p_init_param); + +/** + * @brief Function for registering the application. + * + * @details This routine is used by the application to register for asynchronous events with the + * device manager. During registration the application also indicates the services that it + * intends to support on this instance. It is possible to register multiple times with the + * device manager. At least one instance shall be registered with the device manager after + * the module has been initialized. + * Maximum number of application instances device manager can support is determined + * by DM_MAX_APPLICATIONS. + * + * All applications must be registered before initiating or accepting connections from the peer. + * + * @param[in] p_appl_param Application parameters. + * @param[out] p_appl_instance Application Instance Identifier in case registration is successful. + * + * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. + * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization. + * @retval NRF_ERROR_NO_MEM If module cannot support more applications. + * + * @note Currently only one application instance is supported by the module. + */ +ret_code_t dm_register(dm_application_instance_t * p_appl_instance, + dm_application_param_t const * p_appl_param); + +/** + * @brief Function for handling BLE events. + * + * @details BLE Event Handler for the module. This routine should be called from BLE stack event + * dispatcher for the module to work as expected. + * + * @param[in] p_ble_evt BLE stack event being dispatched to the function. + * + */ +void dm_ble_evt_handler(ble_evt_t * p_ble_evt); + +/** @} */ + + +/** + * @defgroup dm_security_api APIs to set up or read status of security on a link. + * + * @brief This section describes APIs to set up Security. These APIs require that the peer is + * connected before the procedures can be requested. + * + * @details This group allows application to request security procedures + * or get the status of the security on a link. + * @{ + */ +/** + * @brief Function for requesting setting up security on a link. + * + * @details This API initiates security procedures with a peer device. + * @note For the GAP Central role, in case peer is not bonded, request to bond/pair is + * initiated. If it is bonded, the link is re-encrypted using the existing bond information. + * For the GAP peripheral role, a Slave security request is sent. + * @details If a pairing procedure is initiated successfully, application is notified of + * @ref DM_EVT_SECURITY_SETUP_COMPLETE. A result indicating success or failure is notified along with the event. + * In case the link is re-encrypted using existing bond information, @ref DM_EVT_LINK_SECURED is + * notified to the application. + * + * @param[in] p_handle Identifies the link on which security is desired. + * + * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. + * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or + * application registration. + * @retval NRF_ERROR_NULL If p_handle is NULL. + * @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application + * or if the peer is not connected when this procedure is requested. + */ +ret_code_t dm_security_setup_req(dm_handle_t * p_handle); + +/** + * @brief Function for reading the status of the security on a link. + * + * @details This API allows application to query status of security on a link. + * + * @param[in] p_handle Identifies the link on which security is desired. + * @param[out] p_status Pointer where security status is provided to the application. + * See \ref dm_security_status_t for possible statuses that can be expected. + * + * @retval NRF_SUCCESS Or appropriate error code indicating reason for failure. + * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or + * application registration. + * @retval NRF_ERROR_NULL If p_handle or p_status is NULL. + * @retval NRF_ERROR_INVALID_ADDR If peer is not identified by the handle provided by the application + * or if peer is not connected when this procedure is requested. + */ +ret_code_t dm_security_status_req(dm_handle_t const * p_handle, dm_security_status_t * p_status); + +/** + * @brief Function for creating the whitelist. + * + * @details This API allows application to create whitelist based on bonded peer devices in module + * data base. + * + * @param[in] p_handle Identifies the application requesting whitelist creation. + * @param[in,out] p_whitelist Pointer where created whitelist is provided to the application. + * + * @note 'addr_count' and 'irk_count' fields of the structure should be populated with the maximum + * number of devices that the application wishes to request in the whitelist. + * If the number of bonded devices is less than requested, the fields are updated with that number of devices. + * If the number of devices are more than requested, the module will populate the list + * with devices in the order the bond was established with the peer devices. Also, if this routine is + * called when a connection exists with one or more peer devices, + * those connected devices are not added to the whitelist. + * + * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. + * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or + * application registration. + * @retval NRF_ERROR_NULL If p_handle or p_whitelist is NULL. + */ +ret_code_t dm_whitelist_create(dm_application_instance_t const * p_handle, + ble_gap_whitelist_t * p_whitelist); + +/** @} */ + + +/** + * @defgroup dm_cntxt_mgmt_api Context Management APIs + * + * @brief Utility APIs offered by the device manager to get information about the peer if and + * when needed. + * + * @details This group of API allow the application to access information that is not required to be + * maintained by the application but may be needed. Hence it is possible to get the + * information from the module instead of mapping all the information with a device + * context. + * @{ + */ + +ret_code_t dm_device_add(dm_handle_t * p_handle, + dm_device_context_t const * p_context); + +/** + * @brief Function for deleting a peer device context and all related information from the database. + * + * @details Delete peer device context and all related information from database. If + * this API returns NRF_SUCCESS, DM_EVT_DEVICE_CONTEXT_DELETED event is notified to the + * application. Event result notified along with the event indicates success or failure + * of this procedure. + * + * @param[in] p_handle Identifies the peer device to be deleted. + * + * @retval NRF_SUCCESS on success, else an error code indicating reason for failure. + * @retval NRF_ERROR_INVALID_STATE In the API is called without module initialization and/or + * application registration. + * @retval NRF_ERROR_NULL If p_handle is NULL. + * @retval NRF_ERROR_INVALID_ADDR If peer is not identified the handle provided by the application. + * + * @note Deleting device context results in deleting service and application context for the + * bonded device. The respective events DM_EVT_SERVICE_CONTEXT_DELETED and + * DM_EVT_APPL_CONTEXT_DELETED are not notified to the application. + */ +ret_code_t dm_device_delete(dm_handle_t const * p_handle); + +/** + * @brief Function for deleting all peer device context and all related information from the database. + * + * @details Delete peer device context and all related information from database. If + * this API returns NRF_SUCCESS, DM_EVT_DEVICE_CONTEXT_DELETED event is notified to the + * application for each device that is deleted from the data base. Event result + * notified along with the event indicates success or failure of this procedure. + * + * @param[in] p_handle Identifies application instance that is requesting + * the deletion of all bonded devices. + * + * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. + * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or + * application registration. + * @retval NRF_ERROR_NULL If p_handle is NULL. + * @retval NRF_ERROR_INVALID_ADDR If peer is not identified the handle provided by the application. + * + * @note Deleting device context results in deleting both service and application context for the + * bonded device. The respective events DM_EVT_SERVICE_CONTEXT_DELETED and + * DM_EVT_APPL_CONTEXT_DELETED are not notified to the application. + */ +ret_code_t dm_device_delete_all(dm_application_instance_t const * p_handle); + +/** + * @brief Function for setting Service Context for a peer device identified by 'p_handle' parameter. + * + * @details This API allows application to Set Service Context for a peer device identified by the + * 'p_handle' parameter. This API is useful when the Service Context cannot be requested + * from the SoftDevice, but needs to be assembled by the application or an another module. + * (or when service context is exchanged in an out of band way.) + * This API could also be used to trigger a storing of service context into persistent + * memory. If this is desired, a NULL pointer could be passed to the p_context. + * + * @param[in] p_handle Identifies peer device for which the procedure is requested. + * @param[in] p_context Service context being set. The context information includes length of + * data and pointer to the contextual data being set. The memory pointed to by + * the pointer to data is assumed to be resident when API is being called and + * can be freed or reused once the set procedure is complete. Set procedure + * completion is indicated by the event \ref DM_EVT_SERVICE_CONTEXT_STORED. + * The Event result is notified along with the event and indicates success or failure of + * this procedure. + * + * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. + * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or + * application registration. + * @retval NRF_ERROR_NULL If p_handle is NULL. + * @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application. + */ +ret_code_t dm_service_context_set(dm_handle_t const * p_handle, + dm_service_context_t const * p_context); + +/** + * @brief Function for getting Service Context for a peer device identified by 'p_handle' parameter. + * + * @details Get Service Context for a peer device identified by the 'p_handle' parameter. If + * this API returns NRF_SUCCESS, DM_EVT_SERVICE_CONTEXT_LOADED event is notified to the + * application. The event result is notified along with the event indicates success or failure + * of this procedure. + * + * @param[in] p_handle Identifies peer device for which procedure is requested. + * @param[in] p_context Application context being requested. The context information includes length + * of the data and a pointer to the data. Note that requesting a 'get' + * of application does not need to provide memory, the pointer to data will be + * pointing to service data and hence no data movement is involved. + * + * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. + * @retval NRF_ERROR_INVALID_STATE In case API is called without module initialization and/or + * application registration. + * @retval NRF_ERROR_NULL If p_handle is NULL. + * @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application. + */ +ret_code_t dm_service_context_get(dm_handle_t const * p_handle, + dm_service_context_t * p_context); + +/** + * @brief Function for deleting a Service Context for a peer device identified by the 'p_handle' parameter. + * + * @details This API allows application to delete a Service Context identified for a peer device + * identified by the 'p_handle' parameter. If this API returns NRF_SUCCESS, + * DM_EVT_SERVICE_CONTEXT_DELETED event is notified to the application. + * Event result is notified along with the event and indicates success or failure of this + * procedure. + * + * @param[in] p_handle Identifies peer device for which procedure is requested. + * + * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. + * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or + * application registration. + * @retval NRF_ERROR_NULL If p_handle is NULL. + * @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application. + */ +ret_code_t dm_service_context_delete(dm_handle_t const * p_handle); + +/** + * @brief Function for setting Application Context for a peer device identified by the 'p_handle' parameter. + * + * @details This application allows the setting of the application context for the peer device identified by + * the 'p_handle'. Application context is stored persistently by the module and can be + * requested by the application at any time using the \ref dm_application_context_get + * API. Note that this procedure is permitted only for bonded devices. If the + * device is not bonded, application context cannot be set. However, it is not mandatory + * that the bonded device is connected when requesting this procedure. + * + * @param[in] p_handle Identifies peer device for which procedure is requested. + * + * @param[in] p_context Application context being set. The context information includes length of the + * data and pointer to the contextual data being set. The memory pointed to by + * the data pointer is assumed to be resident when API is being called and + * can be freed or reused once the set procedure is complete. Set procedure + * completion is notified by the event \ref DM_EVT_APPL_CONTEXT_STORED. + * The event result is notified along with the event and indicates success or + * failure of this procedure. + * + * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. + * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or + * application registration. + * @retval NRF_ERROR_NULL If p_handle and/or p_context is NULL. + * @retval NRF_ERROR_INVALID_ADDR If peer is not identified the handle provided by the application. + * + * @note The API returns FEATURE_NOT_ENABLED in case DEVICE_MANAGER_APP_CONTEXT_SIZE is set to zero. + */ +ret_code_t dm_application_context_set(dm_handle_t const * p_handle, + dm_application_context_t const * p_context); + +/** + * @brief Function for getting Application Context for a peer device identified by the 'p_handle' parameter. + * + * @details Get Application Context for a peer device identified by the 'p_handle' parameter. If + * this API returns NRF_SUCCESS, DM_EVT_APPL_CONTEXT_LOADED event is notified to the + * application. Event result notified along with the event indicates success or failure + * of this procedure. + * + * @param[in] p_handle Identifies peer device for which procedure is requested. + * @param[in] p_context Application context being requested. The context information includes + * length of data and pointer to the contextual data is provided. + * + * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. + * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or + * application registration. + * @retval NRF_ERROR_NULL If p_handle and/or p_context is NULL. + * @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application. + * @retval DM_NO_APP_CONTEXT If no application context was set that can be fetched. + * + * @note The API returns FEATURE_NOT_ENABLED in case DEVICE_MANAGER_APP_CONTEXT_SIZE is set to + * zero. + */ +ret_code_t dm_application_context_get(dm_handle_t const * p_handle, + dm_application_context_t * p_context); + +/** + * @brief Function for deleting Application Context for a peer device identified by the 'p_handle' parameter. + * + * @details Delete Application Context for a peer device identified by the 'p_handle' parameter. If + * this API returns NRF_SUCCESS, DM_EVT_APPL_CONTEXT_DELETED event is notified to the + * application. The event result notified along with the event and indicates success or failure + * of this procedure. + * + * @param[in] p_handle Identifies peer device for which procedure is requested. + * + * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. + * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or + * application registration. + * @retval NRF_ERROR_NULL If the p_handle is NULL. + * @retval NRF_ERROR_INVALID_ADDR If peer is not identified the handle provided by the application. + * @retval DM_NO_APP_CONTEXT If no application context was set that can be deleted. + * + * @note The API returns FEATURE_NOT_ENABLED if the DEVICE_MANAGER_APP_CONTEXT_SIZE is set to zero. + */ +ret_code_t dm_application_context_delete(dm_handle_t const * p_handle); + +/** @} */ + + +/** + * @defgroup utility_api Utility APIs + * @{ + * @brief This section describes the utility APIs offered by the module. + * + * @details APIs defined in this section are utility or assisting/helper APIs. + */ +/** + * @brief Function for Setting/Copying Application instance to Device Manager handle. + * + * @param[in] p_appl_instance Application instance to be set. + * @param[out] p_handle Device Manager handle for which the instance is to be copied. + * + * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. + * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or + * application registration. + * @retval NRF_ERROR_NULL If p_handle and/or p_addr is NULL. + */ +ret_code_t dm_application_instance_set(dm_application_instance_t const * p_appl_instance, + dm_handle_t * p_handle); + +/** + * @brief Function for getting a peer's device address. + * + * @param[in] p_handle Identifies the peer device whose address is requested. Can not be NULL. + * @param[out] p_addr Pointer where address is to be copied. Can not be NULL. + * + * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. + * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or + * application registration. + * @retval NRF_ERROR_NULL If p_handle and/or p_addr is NULL. + * @retval NRF_ERROR_NOT_FOUND If the peer could not be identified. + */ +ret_code_t dm_peer_addr_get(dm_handle_t const * p_handle, + ble_gap_addr_t * p_addr); + +/** + * @brief Function for setting/updating a peer's device address. + * + * @param[in] p_handle Identifies the peer device whose address is requested to be set/updated. + * @param[out] p_addr Address to be set/updated. + * + * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. + * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or + * application registration. + * @retval NRF_ERROR_NULL If p_handle and/or p_addr is NULL. + * @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application. + * @retval NRF_ERROR_INVALID_PARAM If this procedure is requested while connected to the peer or if the address + * type was set to BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE. + * + * @note Setting or updating a peer's device address is permitted + * only for a peer that is bonded and disconnected. + * @note Updated address is reflected only after DM_EVT_DEVICE_CONTEXT_STORED is notified to the + * application for this bonded device instance. In order to avoid abnormal behaviour, it is + * recommended to not invite/initiate connections on the updated address unless this event + * has been notified. + */ +ret_code_t dm_peer_addr_set(dm_handle_t const * p_handle, + ble_gap_addr_t const * p_addr); + +/** + * @brief Function for initializing Device Manager handle. + * + * @param[in] p_handle Device Manager handle to be initialized. + * + * @retval NRF_SUCCESS On success. + * @retval NRF_ERROR_NULL If p_handle is NULL. + * + * @note This routine is permitted before initialization of the module. + */ +ret_code_t dm_handle_initialize(dm_handle_t * p_handle); + +/** + * @brief Function for getting distributed keys for a device. + * + * @param[in] p_handle Device Manager handle identifying the peer. + * @param[out] p_key_dist Pointer to distributed keys. + * + * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. + * @retval NRF_ERROR_INVALID_STATE If the API is called without module initialization and/or + * application registration. + * @retval NRF_ERROR_NULL If the p_handle and/or p_key_dist pointer is NULL. + * @retval NRF_ERROR_INVALID_ADDR If the peer is not identified by the handle provided by the application. + */ +ret_code_t dm_distributed_keys_get(dm_handle_t const * p_handle, + dm_sec_keyset_t * p_key_dist); + +/** + * @brief Function for getting the corresponding dm_handle_t based on the connection handle. + * + * @param[in] conn_handle Connection handle as provided by the SoftDevice. + * @param[in,out] p_handle Pointer to the p_handle containg the application instance for the + * registered application. If the application instance is valid then + * the p_handle will be filled with requested data. + * + * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. + * @retval NRF_ERROR_NULL If the p_handle pointer is NULL. + * @retval NRF_ERROR_NOT_FOUND If no p_handle is found for the provided connection handle. + */ +ret_code_t dm_handle_get(uint16_t conn_handle, dm_handle_t * p_handle); + +/** @} */ +/** @} */ +/** @} */ +#endif // DEVICE_MANAGER_H__ + diff --git a/source/nordic_sdk/components/ble/device_manager/device_manager_peripheral.c b/source/nordic_sdk/components/ble/device_manager/device_manager_peripheral.c index 5748da4..968f271 100644 --- a/source/nordic_sdk/components/ble/device_manager/device_manager_peripheral.c +++ b/source/nordic_sdk/components/ble/device_manager/device_manager_peripheral.c @@ -1,2932 +1,2914 @@ -/* - * Copyright (c) Nordic Semiconductor ASA - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this - * list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of other - * contributors to this software may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include "device_manager.h" -// #include "app_trace.h" -#include "pstorage.h" -#include "ble_hci.h" -#include "app_error.h" - -#if defined ( __CC_ARM ) - #ifndef __ALIGN - #define __ALIGN(x) __align(x) /**< Forced aligment keyword for ARM Compiler */ - #endif -#elif defined ( __ICCARM__ ) - #ifndef __ALIGN - #define __ALIGN(x) /**< Forced aligment keyword for IAR Compiler */ - #endif -#elif defined ( __GNUC__ ) - #ifndef __ALIGN - #define __ALIGN(x) __attribute__((aligned(x))) /**< Forced aligment keyword for GNU Compiler */ - #endif -#endif - -#define INVALID_ADDR_TYPE 0xFF /**< Identifier for an invalid address type. */ -#define EDIV_INIT_VAL 0xFFFF /**< Initial value for diversifier. */ - -/** - * @defgroup device_manager_app_states Connection Manager Application States - * @{ - */ -#define STATE_CONTROL_PROCEDURE_IN_PROGRESS 0x01 /**< State where a security procedure is ongoing. */ -#define STATE_QUEUED_CONTROL_REQUEST 0x02 /**< State where it is known if there is any queued security request or not. */ -/** @} */ - -/** - * @defgroup device_manager_conn_inst_states Connection Manager Connection Instances States. - * @{ - */ -#define STATE_IDLE 0x01 /**< State where connection instance is free. */ -#define STATE_CONNECTED 0x02 /**< State where connection is successfully established. */ -#define STATE_PAIRING 0x04 /**< State where pairing procedure is in progress. This state is used for pairing and bonding, as pairing is needed for both. */ -#define STATE_BONDED 0x08 /**< State where device is bonded. */ -#define STATE_DISCONNECTING 0x10 /**< State where disconnection is in progress, application will be notified first, but no further active procedures on the link. */ -#define STATE_PAIRING_PENDING 0x20 /**< State where pairing request is pending on the link. */ -#define STATE_BOND_INFO_UPDATE 0x40 /**< State where information has been updated, update the flash. */ -#define STATE_LINK_ENCRYPTED 0x80 /**< State where link is encrypted. */ -/** @} */ - -/** - * @defgroup device_manager_peer_id_defines Peer Identification Information Defines. - * - * @brief These defines are used to know which of the peer identification is applicable for a peer. - * - * @details These defines are used for peer identification. Here, bit map is used because it is - * possible that the application has both IRK and address for identification. - * @{ - */ -#define UNASSIGNED 0xFF /**< Peer instance is unassigned/unused. */ -#define IRK_ENTRY 0x01 /**< Peer instance has IRK as identification information. */ -#define ADDR_ENTRY 0x02 /**< Peer instance has address as identification information. */ -#define SERVICE_CONTEXT_ENTRY 0x04 /**< Peer instance has service context set. */ -#define APP_CONTEXT_ENTRY 0x08 /**< Peer instance has an application context set. */ -/** @} */ - -/**@brief Device store state identifiers. */ -typedef enum -{ - STORE_ALL_CONTEXT, /**< Store all context. */ - FIRST_BOND_STORE, /**< Store bond. */ - UPDATE_PEER_ADDR /**< Update peer address. */ -} device_store_state_t; - -/** - * @defgroup device_manager_context_offsets Context Offsets - * @{ - * - * @brief Context offsets each of the context information in persistent memory. - * - * @details Below is a layout showing how each how the context information is stored in persistent - * memory. - * - * All Device context is stored in the flash as follows: - * +---------+---------+---------+------------------+----------------+--------------------+ - * | Block / Device ID + Layout of stored information in storage block | - * +---------+---------+---------+------------------+----------------+--------------------+ - * | Block 0 | Device 0| Peer Id | Bond Information | Service Context| Application Context| - * +---------+---------+---------+------------------+----------------+--------------------+ - * | Block 1 | Device 1| Peer Id | Bond Information | Service Context| Application Context| - * +---------+---------+---------+------------------+----------------+--------------------+ - * | ... | .... | - * +---------+---------+---------+------------------+----------------+--------------------+ - * | Block N | Device N| Peer Id | Bond Information | Service Context| Application Context| - * +---------+---------+---------+------------------+----------------+--------------------+ - * - * The following defines are used to get offset of each of the components within a block. - */ - -#define PEER_ID_STORAGE_OFFSET 0 /**< Offset at which peer id is stored in the block. */ -#define BOND_STORAGE_OFFSET PEER_ID_SIZE /**< Offset at which bond information is stored in the block. */ -#define SERVICE_STORAGE_OFFSET (BOND_STORAGE_OFFSET + BOND_SIZE) /**< Offset at which service context is stored in the block. */ -#define APP_CONTEXT_STORAGE_OFFSET (SERVICE_STORAGE_OFFSET + SERVICE_CONTEXT_SIZE) /**< Offset at which application context is stored in the block. */ -/** @} */ - -/** - * @defgroup device_manager_context_size Context size. - * @{ - * - * @brief This group defines the size of each of the context information. - */ -#define PEER_ID_SIZE (sizeof(peer_id_t)) /**< Size of peer identification information. */ -#define BOND_SIZE (sizeof(bond_context_t)) /**< Size of bond information. */ -#define DEVICE_CONTEXT_SIZE (PEER_ID_SIZE + BOND_SIZE) /**< Size of Device context, include peer identification and bond information. */ -#define GATTS_SERVICE_CONTEXT_SIZE (sizeof(dm_gatts_context_t)) /**< Size of GATTS service context. */ -#define GATTC_SERVICE_CONTEXT_SIZE (sizeof(dm_gatt_client_context_t)) /**< Size of GATTC service context. */ -#define SERVICE_CONTEXT_SIZE (GATTS_SERVICE_CONTEXT_SIZE + GATTC_SERVICE_CONTEXT_SIZE) /**< Combined size of GATTS and GATTC service contexts. */ -#define APP_CONTEXT_MIN_SIZE 4 /**< Minimum size for application context data. */ -#if (DEVICE_MANAGER_APP_CONTEXT_SIZE != 0) -#define APP_CONTEXT_SIZE (sizeof(uint32_t) + DEVICE_MANAGER_APP_CONTEXT_SIZE) /**< Size of application context including length field. */ -#else //DEVICE_MANAGER_APP_CONTEXT_SIZE -#define APP_CONTEXT_SIZE 0 /**< Size of application context. */ -#endif // DEVICE_MANAGER_APP_CONTEXT_SIZE -#define ALL_CONTEXT_SIZE (DEVICE_CONTEXT_SIZE + SERVICE_CONTEXT_SIZE + APP_CONTEXT_SIZE) /**< Size of all contexts. */ -/** @} */ - - -/** - * @defgroup device_manager_log Module's Log Macros - * - * @details Macros used for creating module logs which can be useful in understanding handling - * of events or actions on API requests. These are intended for debugging purposes and - * can be disabled by defining the DM_DISABLE_LOGS. - * - * @note That if ENABLE_DEBUG_LOG_SUPPORT is disabled, having DM_DISABLE_LOGS has no effect. - * @{ - */ -#define DM_DISABLE_LOGS /**< Enable this macro to disable any logs from this module. */ - -#ifndef DM_DISABLE_LOGS -#define DM_LOG app_trace_log /**< Used for logging details. */ -#define DM_ERR app_trace_log /**< Used for logging errors in the module. */ -#define DM_TRC app_trace_log /**< Used for getting trace of execution in the module. */ -#define DM_DUMP app_trace_dump /**< Used for dumping octet information to get details of bond information etc. */ -#else //DM_DISABLE_LOGS -#define DM_DUMP(...) /**< Disables dumping of octet streams. */ -#define DM_LOG(...) /**< Disables detailed logs. */ -#define DM_ERR(...) /**< Disables error logs. */ -#define DM_TRC(...) /**< Disables traces. */ -#endif //DM_DISABLE_LOGS -/** @} */ - -/** - * @defgroup device_manager_mutex_lock_unlock Module's Mutex Lock/Unlock Macros. - * - * @details Macros used to lock and unlock modules. Currently the SDK does not use mutexes but - * framework is provided in case need arises to use an alternative architecture. - * @{ - */ -#define DM_MUTEX_LOCK() SDK_MUTEX_LOCK(m_dm_mutex) /**< Lock module using mutex. */ -#define DM_MUTEX_UNLOCK() SDK_MUTEX_UNLOCK(m_dm_mutex) /**< Unlock module using mutex. */ -/** @} */ - - -/** - * @defgroup device_manager_misc_defines Miscellaneous defines used across the module. - * @{ - */ -#define DM_GATT_ATTR_SIZE 6 /**< Size of each GATT attribute to be stored persistently. */ -#define DM_GATT_SERVER_ATTR_MAX_SIZE ((DM_GATT_ATTR_SIZE * DM_GATT_CCCD_COUNT) + 2) /**< Maximum size of GATT attributes to be stored.*/ -#define DM_SERVICE_CONTEXT_COUNT (DM_PROTOCOL_CNTXT_ALL + 1) /**< Maximum number of service contexts. */ -#define DM_EVT_DEVICE_CONTEXT_BASE 0x20 /**< Base for device context base. */ -#define DM_EVT_SERVICE_CONTEXT_BASE 0x30 /**< Base for service context base. */ -#define DM_EVT_APP_CONTEXT_BASE 0x40 /**< Base for application context base. */ -#define DM_LOAD_OPERATION_ID 0x01 /**< Load operation identifier. */ -#define DM_STORE_OPERATION_ID 0x02 /**< Store operation identifier. */ -#define DM_CLEAR_OPERATION_ID 0x03 /**< Clear operation identifier. */ -/** @} */ - -#define DM_GATTS_INVALID_SIZE 0xFFFFFFFF /**< Identifer for GATTS invalid size. */ - -/** - * @defgroup api_param_check API Parameters check macros. - * - * @details Macros for verifying parameters passed to the module in the APIs. These macros - * could be mapped to nothing in the final version of the code in order to save execution - * time and program size. - * @{ - */ - -//#define DM_DISABLE_API_PARAM_CHECK /**< Macro to disable API parameters check. */ - -#ifndef DM_DISABLE_API_PARAM_CHECK - -/**@brief Macro for verifying NULL parameters are not passed to API. - * - * @param[in] PARAM Parameter checked for NULL. - * - * @retval (NRF_ERROR_NULL | DEVICE_MANAGER_ERR_BASE) when @ref PARAM is NULL. - */ -#define NULL_PARAM_CHECK(PARAM) \ - if ((PARAM) == NULL) \ - { \ - return (NRF_ERROR_NULL | DEVICE_MANAGER_ERR_BASE); \ - } -/**@} */ - - -/**@brief Macro for verifying module's initialization status. - * - * @retval (NRF_ERROR_INVALID_STATE | DEVICE_MANAGER_ERR_BASE) when module is not initialized. - */ -#define VERIFY_MODULE_INITIALIZED() \ - do \ - { \ - if (!m_module_initialized) \ - { \ - return (NRF_ERROR_INVALID_STATE | DEVICE_MANAGER_ERR_BASE); \ - } \ - } while (0) - - -/**@brief Macro for verifying module's initialization status. Returns in case it is not initialized. - */ -#define VERIFY_MODULE_INITIALIZED_VOID() \ - do \ - { \ - if (!m_module_initialized) \ - { \ - return; \ - } \ - } while (0) - - -/**@brief Macro for verifying that the application is registered. - * - * @param[in] X Application instance identifier. - * - * @retval (NRF_ERROR_INVALID_STATE | DEVICE_MANAGER_ERR_BASE) when module API is called without - * registering an application with the module. - */ -#define VERIFY_APP_REGISTERED(X) \ - do \ - { \ - if (((X) >= DEVICE_MANAGER_MAX_APPLICATIONS) || \ - (m_application_table[(X)].ntf_cb == NULL)) \ - { \ - return (NRF_ERROR_INVALID_STATE | DEVICE_MANAGER_ERR_BASE); \ - } \ - } while (0) - - -/**@brief Macro for verifying that the application is registered. Returns in case it is not - * registered. - * - * @param[in] X Application instance identifier. - */ -#define VERIFY_APP_REGISTERED_VOID(X) \ - do \ - { \ - if (((X) >= DEVICE_MANAGER_MAX_APPLICATIONS) || \ - (m_application_table[(X)].ntf_cb == NULL)) \ - { \ - return; \ - } \ - } while (0) - - -/**@brief Macro for verifying connection instance is allocated. - * - * @param[in] X Connection instance identifier. - * - * @retval (NRF_ERROR_INVALID_ADDR | DEVICE_MANAGER_ERR_BASE) when connection instance is not - * allocated. - */ -#define VERIFY_CONNECTION_INSTANCE(X) \ - do \ - { \ - if (((X) >= DEVICE_MANAGER_MAX_CONNECTIONS) || \ - (m_connection_table[(X)].state == STATE_IDLE)) \ - { \ - return (NRF_ERROR_INVALID_ADDR | DEVICE_MANAGER_ERR_BASE); \ - } \ - } while (0) - - -/**@brief Macro for verifying if device instance is allocated. - * - * @param[in] X Device instance identifier. - * - * @retval (NRF_ERROR_INVALID_ADDR | DEVICE_MANAGER_ERR_BASE) when device instance is not allocated. - */ -#define VERIFY_DEVICE_INSTANCE(X) \ - do \ - { \ - if (((X) >= DEVICE_MANAGER_MAX_BONDS) || \ - (m_peer_table[(X)].id_bitmap == UNASSIGNED)) \ - { \ - return (NRF_ERROR_INVALID_ADDR | DEVICE_MANAGER_ERR_BASE); \ - } \ - } while (0) - -/**@brief Macro for verifying if device is bonded and thus can store data persistantly. - * - * @param[in] X Connection instance identifier. - * - * @retval (NRF_ERROR_INVALID_STATE | DEVICE_MANAGER_ERR_BASE) when device is not bonded. - */ -#define VERIFY_DEVICE_BOND(X) \ - do \ - { \ - if ((m_connection_table[(X)].state & STATE_BONDED) != STATE_BONDED)\ - { \ - return (NRF_ERROR_INVALID_STATE | DEVICE_MANAGER_ERR_BASE); \ - } \ - } while (0) -#else -#define NULL_PARAM_CHECK(X) -#define VERIFY_MODULE_INITIALIZED() -#define VERIFY_MODULE_INITIALIZED_VOID() -#define VERIFY_APP_REGISTERED(X) -#define VERIFY_APP_REGISTERED_VOID(X) -#define VERIFY_CONNECTION_INSTANCE(X) -#define VERIFY_DEVICE_INSTANCE(X) -#endif //DM_DISABLE_API_PARAM_CHECK -/** @} */ - -#define INVALID_CONTEXT_LEN 0xFFFFFFFF /**< Identifier for invalid context length. */ -/**@brief Macro for checking that application context size is greater that minimal size. - * - * @param[in] X Size of application context. - * - * @retval (NRF_ERROR_INVALID_PARAM) when size is smaller than minimun required size. - */ -#define SIZE_CHECK_APP_CONTEXT(X) \ - if ((X) < (APP_CONTEXT_MIN_SIZE)) \ - { \ - return NRF_ERROR_INVALID_PARAM; \ - } - - -/** - * @defgroup dm_data_types Module's internal data types. - * - * @brief This section describes a module's internal data structures. - * @{ - */ -/**@brief Peer identification information. - */ -typedef struct -{ - ble_gap_id_key_t peer_id; /**< IRK and/or address of peer. */ - uint16_t ediv; /**< Peer's encrypted diversifier. */ - uint8_t id_bitmap; /**< Contains information if above field is valid. */ -} peer_id_t; - -STATIC_ASSERT(sizeof(peer_id_t) % 4 == 0); /**< Check to ensure Peer identification information is a multiple of 4. */ - -/**@brief Portion of bonding information exchanged by a device during bond creation that needs to - * be stored persistently. - * - * @note An entry is not made in this table unless device is bonded. - */ -typedef struct -{ - ble_gap_enc_key_t peer_enc_key; /**< Local LTK info, central IRK and address */ -} bond_context_t; - -STATIC_ASSERT(sizeof(bond_context_t) % 4 == 0); /**< Check to ensure bond information is a multiple of 4. */ - -/**@brief GATT Server Attributes size and data. - */ -typedef struct -{ - uint32_t flags; /**< Flags identifying the stored attributes. */ - uint32_t size; /**< Size of stored attributes. */ - uint8_t attributes[DM_GATT_SERVER_ATTR_MAX_SIZE]; /**< Array to hold the server attributes. */ -} dm_gatts_context_t; - -STATIC_ASSERT(sizeof(dm_gatts_context_t) % 4 == 0); /**< Check to ensure GATT Server Attributes size and data information is a multiple of 4. */ - -/**@brief GATT Client context information. Placeholder for now. - */ -typedef struct -{ - void * p_dummy; /**< Placeholder, currently unused. */ -} dm_gatt_client_context_t; - -STATIC_ASSERT(sizeof(dm_gatt_client_context_t) % 4 == 0); /**< Check to ensure GATT Client context information is a multiple of 4. */ -STATIC_ASSERT((DEVICE_MANAGER_APP_CONTEXT_SIZE % 4) == 0); /**< Check to ensure device manager application context information is a multiple of 4. */ - -/**@brief Connection instance definition. Maintains information with respect to an active peer. - */ -typedef struct -{ - ble_gap_addr_t peer_addr; /**< Peer identification information. This information is retained as long as the connection session exists, once disconnected, for non-bonded devices this information is not stored persistently. */ - uint16_t conn_handle; /**< Connection handle for the device. */ - uint8_t state; /**< Link state. */ - uint8_t bonded_dev_id; /**< In case the device is bonded, this points to the corresponding bonded device. This index can be used to index service and bond context as well. */ -} connection_instance_t; - -/**@brief Application instance definition. Maintains information with respect to a registered - * application. - */ -typedef struct -{ - dm_event_cb_t ntf_cb; /**< Callback registered with the application. */ - ble_gap_sec_params_t sec_param; /**< Local security parameters registered by the application. */ - uint8_t state; /**< Application state. Currently this is used only for knowing if any security procedure is in progress and/or a security procedure is pending to be requested. */ - uint8_t service; /**< Service registered by the application. */ -} application_instance_t; - -/**@brief Function for performing necessary action of storing each of the service context as - * registered by the application. - * - * @param[in] p_block_handle Storage block identifier. - * @param[in] p_handle Device handle identifying device that is stored. - * - * @retval Operation result code. - */ -typedef ret_code_t (* service_context_access_t)(pstorage_handle_t const * p_block_handle, - dm_handle_t const * p_handle); - -/**@brief Function for performing necessary action of applying the context information. - * - * @param[in] p_handle Device handle identifying device that is stored. - * - * @retval Operation result code. - */ -typedef ret_code_t (* service_context_apply_t)(dm_handle_t * p_handle); - -/**@brief Function for performing necessary functions of storing or updating. - * - * @param[in] p_dest Destination address where data is stored persistently. - * @param[in] p_src Source address containing data to be stored. - * @param[in] size Size of data to be stored expressed in bytes. Must be word aligned. - * @param[in] offset Offset in bytes to be applied when writing to the block. - * - * @retval Operation result code. - */ -typedef uint32_t (* storage_operation)(pstorage_handle_t * p_dest, - uint8_t * p_src, - pstorage_size_t size, - pstorage_size_t offset); -/** @} */ - -/** - * @defgroup dm_tables Module's internal tables. - * - * @brief This section describes the module's internal tables and the static global variables - * needed for its functionality. - * @{ - */ -#if (DEVICE_MANAGER_APP_CONTEXT_SIZE != 0) -static uint8_t * m_app_context_table[DEVICE_MANAGER_MAX_BONDS]; /**< Table to remember application contexts of bonded devices. */ -#endif //DEVICE_MANAGER_APP_CONTEXT_SIZE -__ALIGN(sizeof(uint32_t)) -static peer_id_t m_peer_table[DEVICE_MANAGER_MAX_BONDS] ; /**< Table to maintain bonded devices' identification information, an instance is allocated in the table when a device is bonded and freed when bond information is deleted. */ -__ALIGN(sizeof(uint32_t)) -static bond_context_t m_bond_table[DEVICE_MANAGER_MAX_CONNECTIONS]; /**< Table to maintain bond information for active peers. */ -static dm_gatts_context_t m_gatts_table[DEVICE_MANAGER_MAX_CONNECTIONS]; /**< Table for service information for active connection instances. */ -static connection_instance_t m_connection_table[DEVICE_MANAGER_MAX_CONNECTIONS]; /**< Table to maintain active peer information. An instance is allocated in the table when a new connection is established and freed on disconnection. */ -static application_instance_t m_application_table[DEVICE_MANAGER_MAX_APPLICATIONS]; /**< Table to maintain application instances. */ -static pstorage_handle_t m_storage_handle; /**< Persistent storage handle for blocks requested by the module. */ -static uint32_t m_peer_addr_update; /**< 32-bit bitmap to remember peer device address update. */ -static ble_gap_id_key_t m_local_id_info; /**< ID information of central in case resolvable address is used. */ -static bool m_module_initialized = false; /**< State indicating if module is initialized or not. */ -static uint8_t m_irk_index_table[DEVICE_MANAGER_MAX_BONDS]; /**< List maintaining IRK index list. */ - -SDK_MUTEX_DEFINE(m_dm_mutex) /**< Mutex variable. Currently unused, this declaration does not occupy any space in RAM. */ -/** @} */ - -static __INLINE ret_code_t no_service_context_store(pstorage_handle_t const * p_block_handle, - dm_handle_t const * p_handle); - -static __INLINE ret_code_t gatts_context_store(pstorage_handle_t const * p_block_handle, - dm_handle_t const * p_handle); - -static __INLINE ret_code_t gattc_context_store(pstorage_handle_t const * p_block_handle, - dm_handle_t const * p_handle); - -static __INLINE ret_code_t gattsc_context_store(pstorage_handle_t const * p_block_handle, - dm_handle_t const * p_handle); - -static __INLINE ret_code_t no_service_context_load(pstorage_handle_t const * p_block_handle, - dm_handle_t const * p_handle); - -static __INLINE ret_code_t gatts_context_load(pstorage_handle_t const * p_block_handle, - dm_handle_t const * p_handle); - -static __INLINE ret_code_t gattc_context_load(pstorage_handle_t const * p_block_handle, - dm_handle_t const * p_handle); - -static __INLINE ret_code_t gattsc_context_load(pstorage_handle_t const * p_block_handle, - dm_handle_t const * p_handle); - -static __INLINE ret_code_t no_service_context_apply(dm_handle_t * p_handle); - -static __INLINE ret_code_t gatts_context_apply(dm_handle_t * p_handle); - -static __INLINE ret_code_t gattc_context_apply(dm_handle_t * p_handle); - -static __INLINE ret_code_t gattsc_context_apply(dm_handle_t * p_handle); - - -/**< Array of function pointers based on the types of service registered. */ -const service_context_access_t m_service_context_store[DM_SERVICE_CONTEXT_COUNT] = -{ - no_service_context_store, /**< Dummy function, when there is no service context registered. */ - gatts_context_store, /**< GATT Server context store function. */ - gattc_context_store, /**< GATT Client context store function. */ - gattsc_context_store /**< GATT Server & Client context store function. */ -}; - - -/**< Array of function pointers based on the types of service registered. */ -const service_context_access_t m_service_context_load[DM_SERVICE_CONTEXT_COUNT] = -{ - no_service_context_load, /**< Dummy function, when there is no service context registered. */ - gatts_context_load, /**< GATT Server context load function. */ - gattc_context_load, /**< GATT Client context load function. */ - gattsc_context_load /**< GATT Server & Client context load function. */ -}; - - -/**< Array of function pointers based on the types of service registered. */ -const service_context_apply_t m_service_context_apply[DM_SERVICE_CONTEXT_COUNT] = -{ - no_service_context_apply, /**< Dummy function, when there is no service context registered. */ - gatts_context_apply, /**< GATT Server context apply function. */ - gattc_context_apply, /**< GATT Client context apply function. */ - gattsc_context_apply /**< GATT Server & Client context apply function. */ -}; - - -const uint32_t m_context_init_len = 0xFFFFFFFF; /**< Constant used to update the initial value for context in the flash. */ - -/**@brief Function for setting update status for the device identified by 'index'. - * - * @param[in] index Device identifier. - */ -static __INLINE void update_status_bit_set(uint32_t index) -{ - m_peer_addr_update |= (BIT_0 << index); -} - - -/**@brief Function for resetting update status for device identified by 'index'. - * - * @param[in] index Device identifier. - */ -static __INLINE void update_status_bit_reset(uint32_t index) -{ - m_peer_addr_update &= (~((uint32_t)BIT_0 << index)); -} - - -/**@brief Function for providing update status for the device identified by 'index'. - * - * @param[in] index Device identifier. - * - * @retval true if the bit is set, false otherwise. - */ -static __INLINE bool update_status_bit_is_set(uint32_t index) -{ - return ((m_peer_addr_update & (BIT_0 << index)) ? true : false); -} - - -/**@brief Function for initialiasing the application instance identified by 'index'. - * - * @param[in] index Device identifier. - */ -static __INLINE void application_instance_init(uint32_t index) -{ - DM_TRC("[DM]: Initializing Application Instance 0x%08X.\r\n", index); - - m_application_table[index].ntf_cb = NULL; - m_application_table[index].state = 0x00; - m_application_table[index].service = 0x00; -} - - -/**@brief Function for initialiasing the connection instance identified by 'index'. - * - * @param[in] index Device identifier. - */ -static __INLINE void connection_instance_init(uint32_t index) -{ - DM_TRC("[DM]: Initializing Connection Instance 0x%08X.\r\n", index); - - m_connection_table[index].state = STATE_IDLE; - m_connection_table[index].conn_handle = BLE_CONN_HANDLE_INVALID; - m_connection_table[index].bonded_dev_id = DM_INVALID_ID; - - memset(&m_connection_table[index].peer_addr, 0, sizeof (ble_gap_addr_t)); -} - - -/**@brief Function for initialiasing the peer device instance identified by 'index'. - * - * @param[in] index Device identifier. - */ -static __INLINE void peer_instance_init(uint32_t index) -{ - DM_TRC("[DM]: Initializing Peer Instance 0x%08X.\r\n", index); - - memset(m_peer_table[index].peer_id.id_addr_info.addr, 0, BLE_GAP_ADDR_LEN); - memset(m_peer_table[index].peer_id.id_info.irk, 0, BLE_GAP_SEC_KEY_LEN); - - //Initialize the address type to invalid. - m_peer_table[index].peer_id.id_addr_info.addr_type = INVALID_ADDR_TYPE; - - //Initialize the identification bit map to unassigned. - m_peer_table[index].id_bitmap = UNASSIGNED; - - // Initialize diversifier. - m_peer_table[index].ediv = EDIV_INIT_VAL; - - - //Reset the status bit. - update_status_bit_reset(index); - -#if (DEVICE_MANAGER_APP_CONTEXT_SIZE != 0) - //Initialize the application context for bond device. - m_app_context_table[index] = NULL; -#endif //DEVICE_MANAGER_APP_CONTEXT_SIZE -} - - -/**@brief Function for searching connection instance matching the connection handle and the state - * requested. - * - * @details Connection handle and state information is used to get a connection instance, it - * is possible to ignore the connection handle by using BLE_CONN_HANDLE_INVALID. - * - * @param[in] conn_handle Connection handle. - * @param[in] state Connection instance state. - * @param[out] p_instance Connection instance. - * - * @retval NRF_SUCCESS Operation success. - * @retval NRF_ERROR_INVALID_STATE Operation failure. Invalid state - * @retval NRF_ERROR_NOT_FOUND Operation failure. Not found - */ -static ret_code_t connection_instance_find(uint16_t conn_handle, - uint8_t state, - uint32_t * p_instance) -{ - ret_code_t err_code; - uint32_t index; - - err_code = NRF_ERROR_INVALID_STATE; - - for (index = 0; index < DEVICE_MANAGER_MAX_CONNECTIONS; index++) - { - //Search only based on the state. - if (state & m_connection_table[index].state) - { - //Ignore the connection handle. - if ((conn_handle == BLE_CONN_HANDLE_INVALID) || - (conn_handle == m_connection_table[index].conn_handle)) - { - //Search for matching connection handle. - (*p_instance) = index; - err_code = NRF_SUCCESS; - - break; - } - else - { - err_code = NRF_ERROR_NOT_FOUND; - } - } - } - - return err_code; -} - - -/**@brief Function for allocating device instance for a bonded device. - * - * @param[out] p_device_index Device index. - * @param[in] p_addr Peer identification information. - * - * @retval NRF_SUCCESS Operation success. - * @retval DM_DEVICE_CONTEXT_FULL Operation failure. - */ -static __INLINE ret_code_t device_instance_allocate(uint8_t * p_device_index, - ble_gap_addr_t const * p_addr) -{ - ret_code_t err_code; - uint32_t index; - - err_code = DM_DEVICE_CONTEXT_FULL; - - for (index = 0; index < DEVICE_MANAGER_MAX_BONDS; index++) - { - DM_TRC("[DM]:[DI 0x%02X]: Device type 0x%02X.\r\n", - index, m_peer_table[index].peer_id.id_addr_info.addr_type); - DM_TRC("[DM]: Device Addr 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X.\r\n", - m_peer_table[index].peer_id.id_addr_info.addr[0], - m_peer_table[index].peer_id.id_addr_info.addr[1], - m_peer_table[index].peer_id.id_addr_info.addr[2], - m_peer_table[index].peer_id.id_addr_info.addr[3], - m_peer_table[index].peer_id.id_addr_info.addr[4], - m_peer_table[index].peer_id.id_addr_info.addr[5]); - - if (m_peer_table[index].id_bitmap == UNASSIGNED) - { - if (p_addr->addr_type != BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE) - { - m_peer_table[index].id_bitmap &= (~ADDR_ENTRY); - m_peer_table[index].peer_id.id_addr_info = (*p_addr); - } - else - { - m_peer_table[index].id_bitmap &= (~IRK_ENTRY); - } - - (*p_device_index) = index; - err_code = NRF_SUCCESS; - - DM_LOG("[DM]: Allocated device instance 0x%02X\r\n", index); - - break; - } - } - - return err_code; -} - - -/**@brief Function for freeing a device instance allocated for bonded device. - * - * @param[in] device_index Device index. - * - * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. - */ -static __INLINE ret_code_t device_instance_free(uint32_t device_index) -{ - ret_code_t err_code; - pstorage_handle_t block_handle; - - //Get the block handle. - err_code = pstorage_block_identifier_get(&m_storage_handle, device_index, &block_handle); - - if (err_code == NRF_SUCCESS) - { - DM_TRC("[DM]:[DI 0x%02X]: Freeing Instance.\r\n", device_index); - - //Request clearing of the block. - err_code = pstorage_clear(&block_handle, ALL_CONTEXT_SIZE); - - if (err_code == NRF_SUCCESS) - { - peer_instance_init(device_index); - } - } - - return err_code; -} - - -/**@brief Function for searching for the device in the bonded device list. - * - * @param[in] p_addr Peer identification information. - * @param[out] p_device_index Device index. - * - * @retval NRF_SUCCESS Operation success. - * @retval NRF_ERROR_NOT_FOUND Operation failure. - */ -static ret_code_t device_instance_find(ble_gap_addr_t const * p_addr, uint32_t * p_device_index, uint16_t ediv) -{ - ret_code_t err_code; - uint32_t index; - - err_code = NRF_ERROR_NOT_FOUND; - - DM_TRC("[DM]: Searching for device 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X.\r\n", - p_addr->addr[0], - p_addr->addr[1], - p_addr->addr[2], - p_addr->addr[3], - p_addr->addr[4], - p_addr->addr[5]); - - for (index = 0; index < DEVICE_MANAGER_MAX_BONDS; index++) - { - DM_TRC("[DM]:[DI 0x%02X]: Device type 0x%02X.\r\n", - index, m_peer_table[index].peer_id.id_addr_info.addr_type); - DM_TRC("[DM]: Device Addr 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X.\r\n", - m_peer_table[index].peer_id.id_addr_info.addr[0], - m_peer_table[index].peer_id.id_addr_info.addr[1], - m_peer_table[index].peer_id.id_addr_info.addr[2], - m_peer_table[index].peer_id.id_addr_info.addr[3], - m_peer_table[index].peer_id.id_addr_info.addr[4], - m_peer_table[index].peer_id.id_addr_info.addr[5]); - - if (((NULL == p_addr) && (ediv == m_peer_table[index].ediv)) || - ((NULL != p_addr) && (memcmp(&m_peer_table[index].peer_id.id_addr_info, p_addr, sizeof(ble_gap_addr_t)) == 0))) - { - DM_LOG("[DM]: Found device at instance 0x%02X\r\n", index); - - (*p_device_index) = index; - err_code = NRF_SUCCESS; - - break; - } - } - - return err_code; -} - - -/**@brief Function for notifying connection manager event to the application. - * - * @param[in] p_handle Device handle identifying device. - * @param[in] p_event Connection manager event details. - * @param[in] event_result Event result code. - */ -static __INLINE void app_evt_notify(dm_handle_t const * const p_handle, - dm_event_t const * const p_event, - uint32_t event_result) -{ - dm_event_cb_t app_cb = m_application_table[0].ntf_cb; - - DM_MUTEX_UNLOCK(); - - DM_TRC("[DM]: Notifying application of event 0x%02X\r\n", p_event->event_id); - - //No need to do any kind of return value processing thus can be supressed. - UNUSED_VARIABLE(app_cb(p_handle, p_event, event_result)); - - DM_MUTEX_LOCK(); -} - - -/**@brief Function for allocating instance. - * - * @details The instance identifier is provided in the 'p_instance' parameter if the routine - * succeeds. - * - * @param[out] p_instance Connection instance. - * - * @retval NRF_SUCCESS Operation success. - * @retval NRF_ERROR_NO_MEM Operation failure. No memory. - */ -static __INLINE uint32_t connection_instance_allocate(uint32_t * p_instance) -{ - uint32_t err_code; - - DM_TRC("[DM]: Request to allocation connection instance\r\n"); - - err_code = connection_instance_find(BLE_CONN_HANDLE_INVALID, STATE_IDLE, p_instance); - - if (err_code == NRF_SUCCESS) - { - DM_LOG("[DM]:[%02X]: Connection Instance Allocated.\r\n", (*p_instance)); - m_connection_table[*p_instance].state = STATE_CONNECTED; - } - else - { - DM_LOG("[DM]: No free connection instances available\r\n"); - err_code = NRF_ERROR_NO_MEM; - } - - return err_code; -} - - -/**@brief Function for freeing instance. Instance identifier is provided in the parameter - * 'p_instance' in case the routine succeeds. - * - * @param[in] p_instance Connection instance. - */ -static __INLINE void connection_instance_free(uint32_t const * p_instance) -{ - DM_TRC("[DM]:[CI 0x%02X]: Freeing connection instance\r\n", (*p_instance)); - - if (m_connection_table[*p_instance].state != STATE_IDLE) - { - DM_LOG("[DM]:[%02X]: Freed connection instance.\r\n", (*p_instance)); - connection_instance_init(*p_instance); - } -} - - -/**@brief Function for storage operation dummy handler. - * - * @param[in] p_dest Destination address where data is to be stored persistently. - * @param[in] p_src Source address containing data to be stored. API assumes this to be resident - * memory and no intermediate copy of data is made by the API. - * @param[in] size Size of data to be stored expressed in bytes. Should be word aligned. - * @param[in] offset Offset in bytes to be applied when writing to the block. - * For example, if within a block of 100 bytes, application wishes to - * write 20 bytes at offset of 12, then this field should be set to 12. - * Should be word aligned. - * - * @retval NRF_SUCCESS Operation success. - */ -static uint32_t storage_operation_dummy_handler(pstorage_handle_t * p_dest, - uint8_t * p_src, - pstorage_size_t size, - pstorage_size_t offset) -{ - return NRF_SUCCESS; -} - - -/**@brief Function for saving the device context persistently. - * - * @param[in] p_handle Device handle identifying device. - * @param[in] state Device store state. - */ -static __INLINE void device_context_store(dm_handle_t const * p_handle, device_store_state_t state) -{ - pstorage_handle_t block_handle; - storage_operation store_fn; - ret_code_t err_code; - - DM_LOG("[DM]: --> device_context_store\r\n"); - - err_code = pstorage_block_identifier_get(&m_storage_handle, - p_handle->device_id, - &block_handle); - - if (err_code == NRF_SUCCESS) - { - if ((STATE_BOND_INFO_UPDATE == - (m_connection_table[p_handle->connection_id].state & STATE_BOND_INFO_UPDATE)) || - (state == UPDATE_PEER_ADDR)) - { - DM_LOG("[DM]:[DI %02X]:[CI %02X]: -> Updating bonding information.\r\n", - p_handle->device_id, p_handle->connection_id); - - store_fn = pstorage_update; - } - else if (state == FIRST_BOND_STORE) - { - DM_LOG("[DM]:[DI %02X]:[CI %02X]: -> Storing bonding information.\r\n", - p_handle->device_id, p_handle->connection_id); - - store_fn = pstorage_store; - } - else - { - DM_LOG("[DM]:[DI %02X]:[CI %02X]: -> No update in bonding information.\r\n", - p_handle->device_id, p_handle->connection_id); - - //No operation needed. - store_fn = storage_operation_dummy_handler; - } - - //Store the peer id. - err_code = store_fn(&block_handle, - (uint8_t *)&m_peer_table[p_handle->device_id], - PEER_ID_SIZE, - PEER_ID_STORAGE_OFFSET); - - if ((err_code == NRF_SUCCESS) && (state != UPDATE_PEER_ADDR)) - { - m_connection_table[p_handle->connection_id].state &= (~STATE_BOND_INFO_UPDATE); - - //Store the bond information. - err_code = store_fn(&block_handle, - (uint8_t *)&m_bond_table[p_handle->connection_id], - BOND_SIZE, - BOND_STORAGE_OFFSET); - - if (err_code != NRF_SUCCESS) - { - DM_ERR("[DM]:[0x%02X]:Failed to store bond information, reason 0x%08X\r\n", - p_handle->device_id, err_code); - } - } - - if (state != UPDATE_PEER_ADDR) - { - //Store the service information - err_code = m_service_context_store[m_application_table[p_handle->appl_id].service] - ( - &block_handle, - p_handle - ); - - if (err_code != NRF_SUCCESS) - { - //Notify application of an error event. - DM_ERR("[DM]: Failed to store service context, reason %08X\r\n", err_code); - } - } - } - - if (err_code != NRF_SUCCESS) - { - //Notify application of an error event. - DM_ERR("[DM]: Failed to store device context, reason %08X\r\n", err_code); - } -} - - -/**@brief Function for storing when there is no service registered. - * - * @param[in] p_block_handle Storage block identifier. - * @param[in] p_handle Device handle identifying device that is loaded. - * - * @retval NRF_SUCCESS - */ -static __INLINE ret_code_t no_service_context_store(pstorage_handle_t const * p_block_handle, - dm_handle_t const * p_handle) -{ - DM_LOG("[DM]: --> no_service_context_store\r\n"); - - return NRF_SUCCESS; -} - - -/**@brief Function for storing GATT Server context. - * - * @param[in] p_block_handle Storage block identifier. - * @param[in] p_handle Device handle identifying device that is stored. - * - * @retval NRF_SUCCESS Operation success. - */ -static __INLINE ret_code_t gatts_context_store(pstorage_handle_t const * p_block_handle, - dm_handle_t const * p_handle) -{ - storage_operation store_fn; - uint32_t attr_flags = BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS | BLE_GATTS_SYS_ATTR_FLAG_USR_SRVCS; - uint16_t attr_len = DM_GATT_SERVER_ATTR_MAX_SIZE; - uint8_t sys_data[DM_GATT_SERVER_ATTR_MAX_SIZE]; - - DM_LOG("[DM]: --> gatts_context_store\r\n"); - - uint32_t err_code = sd_ble_gatts_sys_attr_get( - m_connection_table[p_handle->connection_id].conn_handle, - sys_data, - &attr_len, - attr_flags); - - if (err_code == NRF_SUCCESS) - { - if (memcmp(m_gatts_table[p_handle->connection_id].attributes, sys_data, attr_len) == 0) - { - //No store operation is needed. - DM_LOG("[DM]:[0x%02X]: No change in GATTS Context information.\r\n", - p_handle->device_id); - - if ((m_connection_table[p_handle->connection_id].state & STATE_CONNECTED) != - STATE_CONNECTED) - { - DM_LOG("[DM]:[0x%02X]: Resetting GATTS for active instance.\r\n", - p_handle->connection_id); - - //Reset GATTS information for the current context. - memset(&m_gatts_table[p_handle->connection_id], 0, sizeof(dm_gatts_context_t)); - } - } - else - { - if (m_gatts_table[p_handle->connection_id].size != 0) - { - //There is data already stored in persistent memory, therefore an update is needed. - DM_LOG("[DM]:[0x%02X]: Updating stored service context\r\n", p_handle->device_id); - - store_fn = pstorage_update; - } - else - { - //Fresh write, a store is needed. - DM_LOG("[DM]:[0x%02X]: Storing service context\r\n", p_handle->device_id); - - store_fn = pstorage_store; - } - - m_gatts_table[p_handle->connection_id].flags = attr_flags; - m_gatts_table[p_handle->connection_id].size = attr_len; - memcpy(m_gatts_table[p_handle->connection_id].attributes, sys_data, attr_len); - - DM_DUMP((uint8_t *)&m_gatts_table[p_handle->connection_id], sizeof(dm_gatts_context_t)); - - DM_LOG("[DM]:[0x%02X]: GATTS Data size 0x%08X\r\n", - p_handle->device_id, - m_gatts_table[p_handle->connection_id].size); - - //Store GATTS information. - err_code = store_fn((pstorage_handle_t *)p_block_handle, - (uint8_t *)&m_gatts_table[p_handle->connection_id], - GATTS_SERVICE_CONTEXT_SIZE, - SERVICE_STORAGE_OFFSET); - - if (err_code != NRF_SUCCESS) - { - DM_ERR("[DM]:[0x%02X]:Failed to store service context, reason 0x%08X\r\n", - p_handle->device_id, - err_code); - } - else - { - DM_LOG("[DM]: Service context successfully stored.\r\n"); - } - } - } - - return NRF_SUCCESS; -} - - -/**@brief Function for storing GATT Client context. - * - * @param[in] p_block_handle Storage block identifier. - * @param[in] p_handle Device handle identifying device that is stored. - * - * @retval NRF_SUCCESS Operation success. - */ -static __INLINE ret_code_t gattc_context_store(pstorage_handle_t const * p_block_handle, - dm_handle_t const * p_handle) -{ - DM_LOG("[DM]: --> gattc_context_store\r\n"); - - return NRF_SUCCESS; -} - - -/**@brief Function for storing GATT Server & Client context. - * - * @param[in] p_block_handle Storage block identifier. - * @param[in] p_handle Device handle identifying device that is stored. - * - * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. - */ -static __INLINE ret_code_t gattsc_context_store(pstorage_handle_t const * p_block_handle, - dm_handle_t const * p_handle) -{ - DM_LOG("[DM]: --> gattsc_context_store\r\n"); - - ret_code_t err_code = gatts_context_store(p_block_handle, p_handle); - - if (NRF_SUCCESS == err_code) - { - err_code = gattc_context_store(p_block_handle, p_handle); - } - - return err_code; -} - - -/**@brief Function for loading when there is no service registered. - * - * @param[in] p_block_handle Storage block identifier. - * @param[in] p_handle Device handle identifying device that is loaded. - * - * @retval NRF_SUCCESS - */ -static __INLINE ret_code_t no_service_context_load(pstorage_handle_t const * p_block_handle, - dm_handle_t const * p_handle) -{ - DM_LOG("[DM]: --> no_service_context_load\r\n"); - - return NRF_SUCCESS; -} - - -/**@brief Function for loading GATT Server context. - * - * @param[in] p_block_handle Storage block identifier. - * @param[in] p_handle Device handle identifying device that is loaded. - * - * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. - */ -static __INLINE ret_code_t gatts_context_load(pstorage_handle_t const * p_block_handle, - dm_handle_t const * p_handle) -{ - DM_LOG("[DM]:[CI 0x%02X]:[DI 0x%02X]: --> gatts_context_load\r\n", - p_handle->connection_id, - p_handle->device_id); - - ret_code_t err_code = pstorage_load((uint8_t *)&m_gatts_table[p_handle->connection_id], - (pstorage_handle_t *)p_block_handle, - GATTS_SERVICE_CONTEXT_SIZE, - SERVICE_STORAGE_OFFSET); - - if (err_code == NRF_SUCCESS) - { - DM_LOG("[DM]:[%02X]:[Block ID 0x%08X]: Service context loaded, size 0x%08X\r\n", - p_handle->connection_id, - p_block_handle->block_id, - m_gatts_table[p_handle->connection_id].size); - DM_DUMP((uint8_t *)&m_gatts_table[p_handle->connection_id], sizeof(dm_gatts_context_t)); - - if (m_gatts_table[p_handle->connection_id].size == DM_GATTS_INVALID_SIZE) - { - m_gatts_table[p_handle->connection_id].size = 0; - } - } - else - { - DM_ERR("[DM]:[%02X]: Failed to load Service context, reason %08X\r\n", - p_handle->connection_id, - err_code); - } - - return err_code; -} - - -/**@brief Function for loading GATT Client context. - * - * @param[in] p_block_handle Storage block identifier. - * @param[in] p_handle Device handle identifying device that is loaded. - * - * @retval NRF_SUCCESS - */ -static __INLINE ret_code_t gattc_context_load(pstorage_handle_t const * p_block_handle, - dm_handle_t const * p_handle) -{ - DM_LOG("[DM]: --> gattc_context_load\r\n"); - - return NRF_SUCCESS; -} - - -/**@brief Function for loading GATT Server & Client context. - * - * @param[in] p_block_handle Storage block identifier. - * @param[in] p_handle Device handle identifying device that is loaded. - * - * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. - */ -static __INLINE ret_code_t gattsc_context_load(pstorage_handle_t const * p_block_handle, - dm_handle_t const * p_handle) -{ - DM_LOG("[DM]: --> gattsc_context_load\r\n"); - - ret_code_t err_code = gatts_context_load(p_block_handle, p_handle); - - if (NRF_SUCCESS == err_code) - { - err_code = gattc_context_load(p_block_handle, p_handle); - } - - return err_code; -} - - -/**@brief Function for applying when there is no service registered. - * - * @param[in] p_handle Device handle identifying device that is applied. - * - * @retval NRF_SUCCESS - */ -static __INLINE ret_code_t no_service_context_apply(dm_handle_t * p_handle) -{ - DM_LOG("[DM]: --> no_service_context_apply\r\n"); - DM_LOG("[DM]:[CI 0x%02X]: No Service context\r\n", p_handle->connection_id); - - return NRF_SUCCESS; -} - - -/**@brief Function for applying GATT Server context. - * - * @param[in] p_handle Device handle identifying device that is applied. - * - * @retval NRF_SUCCESS On success. - * @retval DM_SERVICE_CONTEXT_NOT_APPLIED On failure. - */ -static __INLINE ret_code_t gatts_context_apply(dm_handle_t * p_handle) -{ - uint32_t err_code; - - uint8_t * p_gatts_context = NULL; - uint16_t context_len = 0; - uint32_t context_flags = 0; - - DM_LOG("[DM]: --> gatts_context_apply\r\n"); - DM_LOG("[DM]:[CI 0x%02X]: State 0x%02X, Size 0x%08X\r\n", - p_handle->connection_id, - m_connection_table[p_handle->connection_id].state, - m_gatts_table[p_handle->connection_id].size); - - if ((m_gatts_table[p_handle->connection_id].size != 0) && - ( - ((m_connection_table[p_handle->connection_id].state & STATE_LINK_ENCRYPTED) == STATE_LINK_ENCRYPTED) && - ((m_connection_table[p_handle->connection_id].state & STATE_BOND_INFO_UPDATE) - != STATE_BOND_INFO_UPDATE) - ) - ) - { - DM_LOG("[DM]: Setting stored context.\r\n"); - - p_gatts_context = &m_gatts_table[p_handle->connection_id].attributes[0]; - context_len = m_gatts_table[p_handle->connection_id].size; - context_flags = m_gatts_table[p_handle->connection_id].flags; - } - - err_code = sd_ble_gatts_sys_attr_set(m_connection_table[p_handle->connection_id].conn_handle, - p_gatts_context, - context_len, - context_flags); - - if (err_code == NRF_ERROR_INVALID_DATA) - { - // Indication that the ATT table has changed. Restore the system attributes to system - // services only and send a service changed indication if possible. - context_flags = BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS; - err_code = sd_ble_gatts_sys_attr_set(m_connection_table[p_handle->connection_id].conn_handle, - p_gatts_context, - context_len, - context_flags); - } - - if (err_code != NRF_SUCCESS) - { - DM_LOG("[DM]: Failed to set system attributes, reason 0x%08X.\r\n", err_code); - - err_code = DM_SERVICE_CONTEXT_NOT_APPLIED; - } - - if (context_flags == BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS) - { - err_code = sd_ble_gatts_service_changed(m_connection_table[p_handle->connection_id].conn_handle, - 0x000C, - 0xFFFF); - if (err_code != NRF_SUCCESS) - { - DM_LOG("[DM]: Failed to send Service Changed indication, reason 0x%08X.\r\n", err_code); - if ((err_code != BLE_ERROR_INVALID_CONN_HANDLE) && - (err_code != NRF_ERROR_INVALID_STATE) && - (err_code != BLE_ERROR_NO_TX_BUFFERS) && - (err_code != NRF_ERROR_BUSY)) - { - // Those errors can be expected when sending trying to send Service Changed - // Indication if the CCCD is not set to indicate. Thus set the returning error - // code to success. - err_code = NRF_SUCCESS; - } - else - { - err_code = DM_SERVICE_CONTEXT_NOT_APPLIED; - } - } - } - - return err_code; -} - - -/**@brief Function for applying GATT Client context. - * - * @param[in] p_handle Device handle identifying device that is applied. - * - * @retval NRF_SUCCESS On success. - */ -static __INLINE ret_code_t gattc_context_apply(dm_handle_t * p_handle) -{ - DM_LOG("[DM]: --> gattc_context_apply\r\n"); - - return NRF_SUCCESS; -} - - -/**@brief Function for applying GATT Server & Client context. - * - * @param[in] p_handle Device handle identifying device that is applied. - * - * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. - */ -static __INLINE ret_code_t gattsc_context_apply(dm_handle_t * p_handle) -{ - uint32_t err_code; - - DM_LOG("[DM]: --> gattsc_context_apply\r\n"); - - err_code = gatts_context_apply(p_handle); - - if (err_code == NRF_SUCCESS) - { - err_code = gattc_context_apply(p_handle); - } - - return err_code; -} - - -/**@brief Function for pstorage module callback. - * - * @param[in] p_handle Identifies module and block for which callback is received. - * @param[in] op_code Identifies the operation for which the event is notified. - * @param[in] result Identifies the result of flash access operation. - * NRF_SUCCESS implies, operation succeeded. - * @param[in] p_data Identifies the application data pointer. In case of store operation, this - * points to the resident source of application memory that application can now - * free or reuse. In case of clear, this is NULL as no application pointer is - * needed for this operation. - * @param[in] data_len Length of data provided by the application for the operation. - */ -static void dm_pstorage_cb_handler(pstorage_handle_t * p_handle, - uint8_t op_code, - uint32_t result, - uint8_t * p_data, - uint32_t data_len) -{ - VERIFY_APP_REGISTERED_VOID(0); - - if (data_len > ALL_CONTEXT_SIZE) - { - //Clearing of all bonds at initialization, no event is generated. - return; - } - - DM_MUTEX_LOCK(); - - dm_event_t dm_event; - dm_handle_t dm_handle; - dm_context_t context_data; - pstorage_handle_t block_handle; - uint32_t index_count; - uint32_t err_code; - - bool app_notify = true; - - err_code = dm_handle_initialize(&dm_handle); - APP_ERROR_CHECK(err_code); - - dm_handle.appl_id = 0; - dm_event.event_id = 0x00; - - //Construct the event which it is related to. - - //Initialize context data information and length. - context_data.p_data = p_data; - context_data.len = data_len; - - for (uint32_t index = 0; index < DEVICE_MANAGER_MAX_BONDS; index++) - { - err_code = pstorage_block_identifier_get(&m_storage_handle, index, &block_handle); - if ((err_code == NRF_SUCCESS) && - ( - (memcmp(p_handle, &block_handle, sizeof(pstorage_handle_t)) == 0) - ) - ) - { - dm_handle.device_id = index; - break; - } - } - - if (dm_handle.device_id != DM_INVALID_ID) - { - if (op_code == PSTORAGE_CLEAR_OP_CODE) - { - if (data_len == ALL_CONTEXT_SIZE) - { - dm_event.event_id = DM_EVT_DEVICE_CONTEXT_BASE; - } - else - { - dm_event.event_id = DM_EVT_APP_CONTEXT_BASE; - } - } - else - { - //Update or store operation. - //Context is identified based on the pointer value. Device context, application context - //and service context all have their own value range. - index_count = ((uint32_t)(p_data - (uint8_t *)m_peer_table)) / PEER_ID_SIZE; - - if (index_count < DEVICE_MANAGER_MAX_BONDS) - { - dm_event.event_param.p_device_context = &context_data; - - //Only the peer identification is stored, not bond information. Hence do not notify - //the application yet, unless the store operation resulted in a failure. - if ((result == NRF_SUCCESS) && - ( - (update_status_bit_is_set(dm_handle.device_id) == false) - ) - ) - { - app_notify = false; - } - else - { - //Reset update status since update is complete. - update_status_bit_reset(dm_handle.device_id); - - //Notify application of error in storing the context. - dm_event.event_id = DM_EVT_DEVICE_CONTEXT_BASE; - } - } - else - { - index_count = ((uint32_t)(p_data - (uint8_t *)m_bond_table)) / BOND_SIZE; - - if (index_count < DEVICE_MANAGER_MAX_CONNECTIONS) - { - DM_LOG("[DM]:[0x%02X]:[0x%02X]: Bond context Event\r\n", - dm_handle.device_id, - dm_handle.connection_id); - - dm_event.event_param.p_device_context = &context_data; - dm_event.event_id = DM_EVT_DEVICE_CONTEXT_BASE; - dm_handle.connection_id = index_count; - - ble_gap_sec_keyset_t keys_exchanged; - keys_exchanged.keys_central.p_enc_key = NULL; - keys_exchanged.keys_central.p_id_key = &m_local_id_info; - keys_exchanged.keys_periph.p_enc_key = &m_bond_table[index_count].peer_enc_key; - keys_exchanged.keys_periph.p_id_key = - &m_peer_table[dm_handle.device_id].peer_id; - - //Context information updated to provide the keys. - context_data.p_data = (uint8_t *)&keys_exchanged; - context_data.len = sizeof(ble_gap_sec_keyset_t); - } - else - { - index_count = ((uint32_t)(p_data - (uint8_t *)m_gatts_table)) / - GATTS_SERVICE_CONTEXT_SIZE; - - if (index_count < DEVICE_MANAGER_MAX_CONNECTIONS) - { - DM_LOG("[DM]:[0x%02X]:[0x%02X]: Service context Event\r\n", - dm_handle.device_id, - dm_handle.connection_id); - - //Notify application. - dm_event.event_id = DM_EVT_SERVICE_CONTEXT_BASE; - dm_handle.connection_id = index_count; - dm_handle.service_id = DM_PROTOCOL_CNTXT_GATT_SRVR_ID; - - //Reset the service context now that it was successfully written to the - //application and the link is disconnected. - if ((m_connection_table[index_count].state & STATE_CONNECTED) != - STATE_CONNECTED) - { - DM_LOG("[DM]:[0x%02X]:[0x%02X]: Resetting bond information for " - "active instance.\r\n", - dm_handle.device_id, - dm_handle.connection_id); - - memset(&m_gatts_table[dm_handle.connection_id], - 0, - sizeof(dm_gatts_context_t)); - } - } - else - { - DM_LOG("[DM]:[0x%02X]:[0x%02X]: App context Event\r\n", - dm_handle.device_id, - dm_handle.connection_id); - - app_notify = false; - dm_event.event_id = DM_EVT_APP_CONTEXT_BASE; -#if (DEVICE_MANAGER_APP_CONTEXT_SIZE != 0) - - if (p_data == (uint8_t *)(&m_context_init_len)) - { - //Context data is deleted. - //This is a workaround to get the right event as on delete operation - //update operation is used instead of clear. - op_code = PSTORAGE_CLEAR_OP_CODE; - app_notify = true; - } - else if (m_app_context_table[dm_handle.device_id] == p_data) - { - app_notify = true; - dm_event.event_param.p_app_context = &context_data; - - //Verify if the device is connected, if yes set connection instance. - for (uint32_t index = 0; - index < DEVICE_MANAGER_MAX_CONNECTIONS; - index++) - { - if (dm_handle.device_id == m_connection_table[index].bonded_dev_id) - { - dm_handle.connection_id = index; - break; - } - } - } - else - { - //No implementation needed. - } -#endif //DEVICE_MANAGER_APP_CONTEXT_SIZE - } - } - } - } - - if (app_notify == true) - { - if (op_code == PSTORAGE_CLEAR_OP_CODE) - { - dm_event.event_id |= DM_CLEAR_OPERATION_ID; - } - else if (op_code == PSTORAGE_LOAD_OP_CODE) - { - dm_event.event_id |= DM_LOAD_OPERATION_ID; - } - else - { - dm_event.event_id |= DM_STORE_OPERATION_ID; - } - - dm_event.event_param.p_app_context = &context_data; - app_evt_notify(&dm_handle, &dm_event, result); - } - } - - DM_MUTEX_UNLOCK(); -} - - -ret_code_t dm_init(dm_init_param_t const * const p_init_param) -{ - pstorage_module_param_t param; - pstorage_handle_t block_handle; - ret_code_t err_code; - uint32_t index; - - DM_LOG("[DM]: >> dm_init.\r\n"); - - NULL_PARAM_CHECK(p_init_param); - - SDK_MUTEX_INIT(m_dm_mutex); - - DM_MUTEX_LOCK(); - - for (index = 0; index < DEVICE_MANAGER_MAX_APPLICATIONS; index++) - { - application_instance_init(index); - } - - for (index = 0; index < DEVICE_MANAGER_MAX_CONNECTIONS; index++) - { - connection_instance_init(index); - } - - memset(m_gatts_table, 0, sizeof(m_gatts_table)); - - //Initialization of all device instances. - for (index = 0; index < DEVICE_MANAGER_MAX_BONDS; index++) - { - peer_instance_init(index); - m_irk_index_table[index] = DM_INVALID_ID; - } - - //All context with respect to a particular device is stored contiguously. - param.block_size = ALL_CONTEXT_SIZE; - param.block_count = DEVICE_MANAGER_MAX_BONDS; - param.cb = dm_pstorage_cb_handler; - - err_code = pstorage_register(¶m, &m_storage_handle); - - if (err_code == NRF_SUCCESS) - { - m_module_initialized = true; - - if (p_init_param->clear_persistent_data == false) - { - DM_LOG("[DM]: Storage handle 0x%08X.\r\n", m_storage_handle.block_id); - - //Copy bonded peer device address and IRK to RAM table. - - //Bonded devices are stored in range (0,DEVICE_MANAGER_MAX_BONDS-1). The remaining - //range is for active connections that may or may not be bonded. - for (index = 0; index < DEVICE_MANAGER_MAX_BONDS; index++) - { - err_code = pstorage_block_identifier_get(&m_storage_handle, index, &block_handle); - - //Issue read request if you successfully get the block identifier. - if (err_code == NRF_SUCCESS) - { - DM_TRC("[DM]:[0x%02X]: Block handle 0x%08X.\r\n", index, block_handle.block_id); - - err_code = pstorage_load((uint8_t *)&m_peer_table[index], - &block_handle, - sizeof(peer_id_t), - 0); - - if (err_code != NRF_SUCCESS) - { - // In case a peer device could not be loaded successfully, rest of the - // initialization procedure are skipped and an error is sent to the - // application. - DM_ERR( - "[DM]: Failed to load peer device %08X from storage, reason %08X.\r\n", - index, - err_code); - - m_module_initialized = false; - break; - } - else - { - DM_TRC("[DM]:[DI 0x%02X]: Device type 0x%02X.\r\n", - index, - m_peer_table[index].peer_id.id_addr_info.addr_type); - DM_TRC("[DM]: Device Addr 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X.\r\n", - m_peer_table[index].peer_id.id_addr_info.addr[0], - m_peer_table[index].peer_id.id_addr_info.addr[1], - m_peer_table[index].peer_id.id_addr_info.addr[2], - m_peer_table[index].peer_id.id_addr_info.addr[3], - m_peer_table[index].peer_id.id_addr_info.addr[4], - m_peer_table[index].peer_id.id_addr_info.addr[5]); - } - } - else - { - //In case a peer device could not be loaded successfully, rest of the - //initialization procedure are skipped and an error is sent to the application. - DM_LOG("[DM]: Failed to get block handle for instance %08X, reason %08X.\r\n", - index, - err_code); - - m_module_initialized = false; - break; - } - } - } - else - { - err_code = pstorage_clear(&m_storage_handle, (param.block_size * param.block_count)); - DM_ERR("[DM]: Successfully requested clear of persistent data.\r\n"); - } - } - else - { - DM_ERR("[DM]: Failed to register with storage module, reason 0x%08X.\r\n", err_code); - } - - DM_MUTEX_UNLOCK(); - - DM_TRC("[DM]: << dm_init.\r\n"); - - return err_code; -} - - -ret_code_t dm_register(dm_application_instance_t * p_appl_instance, - dm_application_param_t const * p_appl_param) -{ - VERIFY_MODULE_INITIALIZED(); - NULL_PARAM_CHECK(p_appl_instance); - NULL_PARAM_CHECK(p_appl_param); - NULL_PARAM_CHECK(p_appl_param->evt_handler); - - DM_MUTEX_LOCK(); - - DM_LOG("[DM]: >> dm_register.\r\n"); - - uint32_t err_code; - - //Verify if an application instance is available. Currently only one instance is supported. - if (m_application_table[0].ntf_cb == NULL) - { - DM_LOG("[DM]: Application Instance allocated.\r\n"); - - //Mark instance as allocated. - m_application_table[0].ntf_cb = p_appl_param->evt_handler; - m_application_table[0].sec_param = p_appl_param->sec_param; - m_application_table[0].service = p_appl_param->service_type; - - m_application_table[0].sec_param.kdist_central.enc = 0; - m_application_table[0].sec_param.kdist_central.id = 1; - m_application_table[0].sec_param.kdist_central.sign = 0; - m_application_table[0].sec_param.kdist_periph.enc = 1; - m_application_table[0].sec_param.kdist_periph.id = 1; - m_application_table[0].sec_param.kdist_periph.sign = 0; - //Populate application's instance variable with the assigned allocation instance. - *p_appl_instance = 0; - err_code = NRF_SUCCESS; - } - else - { - err_code = (NRF_ERROR_NO_MEM | DEVICE_MANAGER_ERR_BASE); - } - - DM_MUTEX_UNLOCK(); - - DM_TRC("[DM]: << dm_register.\r\n"); - - return err_code; -} - - -ret_code_t dm_security_setup_req(dm_handle_t * p_handle) -{ - VERIFY_MODULE_INITIALIZED(); - NULL_PARAM_CHECK(p_handle); - VERIFY_APP_REGISTERED(p_handle->appl_id); - VERIFY_CONNECTION_INSTANCE(p_handle->connection_id); - - DM_MUTEX_LOCK(); - - DM_LOG("[DM]: >> dm_security_setup_req\r\n"); - - uint32_t err_code = (NRF_ERROR_INVALID_STATE | DEVICE_MANAGER_ERR_BASE); - - if ((m_connection_table[p_handle->connection_id].state & STATE_CONNECTED) == STATE_CONNECTED) - { - err_code = sd_ble_gap_authenticate(m_connection_table[p_handle->connection_id].conn_handle, - &m_application_table[0].sec_param); - } - - DM_TRC("[DM]: << dm_security_setup_req, 0x%08X\r\n", err_code); - - DM_MUTEX_UNLOCK(); - - return err_code; -} - - -ret_code_t dm_security_status_req(dm_handle_t const * p_handle, - dm_security_status_t * p_status) -{ - VERIFY_MODULE_INITIALIZED(); - NULL_PARAM_CHECK(p_handle); - NULL_PARAM_CHECK(p_status); - VERIFY_APP_REGISTERED(p_handle->appl_id); - VERIFY_CONNECTION_INSTANCE(p_handle->connection_id); - - DM_MUTEX_LOCK(); - - DM_LOG("[DM]: >> dm_security_status_req\r\n"); - - if ((m_connection_table[p_handle->connection_id].state & STATE_PAIRING) || - (m_connection_table[p_handle->connection_id].state & STATE_PAIRING_PENDING)) - { - (*p_status) = ENCRYPTION_IN_PROGRESS; - } - else if (m_connection_table[p_handle->connection_id].state & STATE_LINK_ENCRYPTED) - { - (*p_status) = ENCRYPTED; - } - else - { - (*p_status) = NOT_ENCRYPTED; - } - - DM_TRC("[DM]: << dm_security_status_req\r\n"); - - DM_MUTEX_UNLOCK(); - - return NRF_SUCCESS; -} - - -ret_code_t dm_whitelist_create(dm_application_instance_t const * p_handle, - ble_gap_whitelist_t * p_whitelist) -{ - VERIFY_MODULE_INITIALIZED(); - NULL_PARAM_CHECK(p_handle); - NULL_PARAM_CHECK(p_whitelist); - NULL_PARAM_CHECK(p_whitelist->pp_addrs); - NULL_PARAM_CHECK(p_whitelist->pp_irks); - VERIFY_APP_REGISTERED(*p_handle); - - DM_MUTEX_LOCK(); - - DM_LOG("[DM]: >> dm_whitelist_create\r\n"); - - uint32_t addr_count = 0; - uint32_t irk_count = 0; - bool connected = false; - - for (uint32_t index = 0; index < DEVICE_MANAGER_MAX_BONDS; index++) - { - connected = false; - - for (uint32_t c_index = 0; c_index < DEVICE_MANAGER_MAX_CONNECTIONS; c_index++) - { - if ((index == m_connection_table[c_index].bonded_dev_id) && - ((m_connection_table[c_index].state & STATE_CONNECTED) == STATE_CONNECTED)) - { - connected = true; - break; - } - } - - if (connected == false) - { - if ((irk_count < p_whitelist->irk_count) && - ((m_peer_table[index].id_bitmap & IRK_ENTRY) == 0)) - { - p_whitelist->pp_irks[irk_count] = &m_peer_table[index].peer_id.id_info; - m_irk_index_table[irk_count] = index; - irk_count++; - } - - if ((addr_count < p_whitelist->addr_count) && - (m_peer_table[index].id_bitmap & ADDR_ENTRY) == 0) - { - p_whitelist->pp_addrs[addr_count] = &m_peer_table[index].peer_id.id_addr_info; - addr_count++; - } - } - } - - p_whitelist->addr_count = addr_count; - p_whitelist->irk_count = irk_count; - - DM_LOG("[DM]: Created whitelist, number of IRK = 0x%02X, number of addr = 0x%02X\r\n", - irk_count, - addr_count); - - DM_TRC("[DM]: << dm_whitelist_create\r\n"); - - DM_MUTEX_UNLOCK(); - - return NRF_SUCCESS; -} - - -ret_code_t dm_device_add(dm_handle_t * p_handle, - dm_device_context_t const * p_context) -{ - return (API_NOT_IMPLEMENTED | DEVICE_MANAGER_ERR_BASE); -} - - -ret_code_t dm_device_delete(dm_handle_t const * p_handle) -{ - VERIFY_MODULE_INITIALIZED(); - NULL_PARAM_CHECK(p_handle); - VERIFY_APP_REGISTERED(p_handle->appl_id); - VERIFY_DEVICE_INSTANCE(p_handle->device_id); - - DM_MUTEX_LOCK(); - - DM_TRC("[DM]: >> dm_device_delete\r\n"); - - uint32_t err_code = device_instance_free(p_handle->device_id); - - DM_TRC("[DM]: << dm_device_delete\r\n"); - - DM_MUTEX_UNLOCK(); - - return err_code; -} - - -ret_code_t dm_device_delete_all(dm_application_instance_t const * p_handle) -{ - VERIFY_MODULE_INITIALIZED(); - NULL_PARAM_CHECK(p_handle); - VERIFY_APP_REGISTERED((*p_handle)); - - DM_MUTEX_LOCK(); - - uint32_t err_code = NRF_SUCCESS; - - DM_TRC("[DM]: >> dm_device_delete_all\r\n"); - - for (uint32_t index = 0; index < DEVICE_MANAGER_MAX_BONDS; index++) - { - if (m_peer_table[index].id_bitmap != UNASSIGNED) - { - err_code = device_instance_free(index); - } - } - - DM_TRC("[DM]: << dm_device_delete_all\r\n"); - - DM_MUTEX_UNLOCK(); - - return err_code; -} - - -ret_code_t dm_service_context_set(dm_handle_t const * p_handle, - dm_service_context_t const * p_context) -{ - VERIFY_MODULE_INITIALIZED(); - NULL_PARAM_CHECK(p_handle); - NULL_PARAM_CHECK(p_context); - VERIFY_APP_REGISTERED(p_handle->appl_id); - VERIFY_CONNECTION_INSTANCE(p_handle->connection_id); - VERIFY_DEVICE_INSTANCE(p_handle->device_id); - - DM_MUTEX_LOCK(); - - DM_TRC("[DM]: >> dm_service_context_set\r\n"); - - if ((p_context->context_data.p_data != NULL) && - ( - (p_context->context_data.len != 0) && - (p_context->context_data.len < DM_GATT_SERVER_ATTR_MAX_SIZE) - ) - ) - { - if (p_context->service_type == DM_PROTOCOL_CNTXT_GATT_SRVR_ID) - { - memcpy(m_gatts_table[p_handle->connection_id].attributes, - p_context->context_data.p_data, - p_context->context_data.len); - } - } - - pstorage_handle_t block_handle; - uint32_t err_code = pstorage_block_identifier_get(&m_storage_handle, - p_handle->device_id, - &block_handle); - - err_code = m_service_context_store[p_context->service_type](&block_handle, p_handle); - - DM_TRC("[DM]: << dm_service_context_set\r\n"); - - DM_MUTEX_UNLOCK(); - - return err_code; -} - - -ret_code_t dm_service_context_get(dm_handle_t const * p_handle, - dm_service_context_t * p_context) -{ - VERIFY_MODULE_INITIALIZED(); - NULL_PARAM_CHECK(p_handle); - NULL_PARAM_CHECK(p_context); - VERIFY_APP_REGISTERED(p_handle->appl_id); - VERIFY_DEVICE_INSTANCE(p_handle->device_id); - - if ((m_connection_table[p_handle->connection_id].state & STATE_CONNECTED) != STATE_CONNECTED) - { - DM_TRC("[DM]: Device must be connected to get context. \r\n"); - - return (FEATURE_NOT_ENABLED | DEVICE_MANAGER_ERR_BASE); - } - - DM_MUTEX_LOCK(); - - DM_TRC("[DM]: >> dm_service_context_get\r\n"); - - if ((p_context->context_data.p_data == NULL) && - (p_context->context_data.len < DM_GATT_SERVER_ATTR_MAX_SIZE)) - { - if (p_context->service_type == DM_PROTOCOL_CNTXT_GATT_SRVR_ID) - { - p_context->context_data.p_data = m_gatts_table[p_handle->connection_id].attributes; - p_context->context_data.len = m_gatts_table[p_handle->connection_id].size; - } - } - - pstorage_handle_t block_handle; - uint32_t err_code = pstorage_block_identifier_get(&m_storage_handle, - p_handle->device_id, - &block_handle); - - err_code = m_service_context_load[p_context->service_type](&block_handle, p_handle); - - DM_TRC("[DM]: << dm_service_context_get\r\n"); - - DM_MUTEX_UNLOCK(); - - return err_code; -} - - -ret_code_t dm_service_context_delete(dm_handle_t const * p_handle) -{ - VERIFY_MODULE_INITIALIZED(); - NULL_PARAM_CHECK(p_handle); - VERIFY_APP_REGISTERED(p_handle->appl_id); - VERIFY_DEVICE_INSTANCE(p_handle->device_id); - - DM_LOG("[DM]: Context delete is not supported yet.\r\n"); - - return (API_NOT_IMPLEMENTED | DEVICE_MANAGER_ERR_BASE); -} - - -ret_code_t dm_application_context_set(dm_handle_t const * p_handle, - dm_application_context_t const * p_context) -{ -#if (DEVICE_MANAGER_APP_CONTEXT_SIZE != 0) - VERIFY_MODULE_INITIALIZED(); - NULL_PARAM_CHECK(p_handle); - NULL_PARAM_CHECK(p_context); - NULL_PARAM_CHECK(p_context->p_data); - VERIFY_APP_REGISTERED(p_handle->appl_id); - VERIFY_DEVICE_INSTANCE(p_handle->device_id); - VERIFY_DEVICE_BOND(p_handle->connection_id); - SIZE_CHECK_APP_CONTEXT(p_context->len); - - DM_MUTEX_LOCK(); - - DM_TRC("[DM]: >> dm_application_context_set\r\n"); - - uint32_t err_code; - uint32_t context_len; - pstorage_handle_t block_handle; - - storage_operation store_fn = pstorage_store; - - err_code = pstorage_block_identifier_get(&m_storage_handle, - p_handle->device_id, - &block_handle); - - if (err_code == NRF_SUCCESS) - { - err_code = pstorage_load((uint8_t *)&context_len, - &block_handle, - sizeof(uint32_t), - APP_CONTEXT_STORAGE_OFFSET); - - if ((err_code == NRF_SUCCESS) && (context_len != INVALID_CONTEXT_LEN)) - { - //Data already exists. Need an update. - store_fn = pstorage_update; - - DM_LOG("[DM]:[DI 0x%02X]: Updating existing application context, existing len 0x%08X, " - "new length 0x%08X.\r\n", - p_handle->device_id, - context_len, - p_context->len); - } - else - { - DM_LOG("[DM]: Storing application context.\r\n"); - } - - //Store/update context length. - err_code = store_fn(&block_handle, - (uint8_t *)(&p_context->len), - sizeof(uint32_t), - APP_CONTEXT_STORAGE_OFFSET); - - if (err_code == NRF_SUCCESS) - { - //Update context data is used for application context as flash is never - //cleared if a delete of application context is called. - err_code = pstorage_update(&block_handle, - p_context->p_data, - DEVICE_MANAGER_APP_CONTEXT_SIZE, - (APP_CONTEXT_STORAGE_OFFSET + sizeof(uint32_t))); - if (err_code == NRF_SUCCESS) - { - m_app_context_table[p_handle->device_id] = p_context->p_data; - } - } - } - - DM_TRC("[DM]: << dm_application_context_set\r\n"); - - DM_MUTEX_UNLOCK(); - - return err_code; - -#else //DEVICE_MANAGER_APP_CONTEXT_SIZE - return (FEATURE_NOT_ENABLED | DEVICE_MANAGER_ERR_BASE); -#endif //DEVICE_MANAGER_APP_CONTEXT_SIZE -} - - -ret_code_t dm_application_context_get(dm_handle_t const * p_handle, - dm_application_context_t * p_context) -{ -#if (DEVICE_MANAGER_APP_CONTEXT_SIZE != 0) - VERIFY_MODULE_INITIALIZED(); - NULL_PARAM_CHECK(p_handle); - NULL_PARAM_CHECK(p_context); - VERIFY_APP_REGISTERED(p_handle->appl_id); - VERIFY_DEVICE_INSTANCE(p_handle->device_id); - - DM_MUTEX_LOCK(); - - DM_TRC("[DM]: >> dm_application_context_get\r\n"); - - uint32_t context_len; - uint32_t err_code; - pstorage_handle_t block_handle; - - //Check if the context exists. - if (NULL == p_context->p_data) - { - p_context->p_data = m_app_context_table[p_handle->device_id]; - } - else - { - m_app_context_table[p_handle->device_id] = p_context->p_data; - } - - err_code = pstorage_block_identifier_get(&m_storage_handle, - p_handle->device_id, - &block_handle); - - if (err_code == NRF_SUCCESS) - { - err_code = pstorage_load((uint8_t *)&context_len, - &block_handle, - sizeof(uint32_t), - APP_CONTEXT_STORAGE_OFFSET); - - if ((err_code == NRF_SUCCESS) && (context_len != INVALID_CONTEXT_LEN)) - { - err_code = pstorage_load(p_context->p_data, - &block_handle, - DEVICE_MANAGER_APP_CONTEXT_SIZE, - (APP_CONTEXT_STORAGE_OFFSET + sizeof(uint32_t))); - if (err_code == NRF_SUCCESS) - { - p_context->len = context_len; - } - } - else - { - err_code = DM_NO_APP_CONTEXT; - } - } - - DM_TRC("[DM]: << dm_application_context_get\r\n"); - - DM_MUTEX_UNLOCK(); - - return err_code; - -#else //DEVICE_MANAGER_APP_CONTEXT_SIZE - return (FEATURE_NOT_ENABLED | DEVICE_MANAGER_ERR_BASE); -#endif //DEVICE_MANAGER_APP_CONTEXT_SIZE -} - - -ret_code_t dm_application_context_delete(const dm_handle_t * p_handle) -{ -#if (DEVICE_MANAGER_APP_CONTEXT_SIZE != 0) - VERIFY_MODULE_INITIALIZED(); - NULL_PARAM_CHECK(p_handle); - VERIFY_APP_REGISTERED(p_handle->appl_id); - VERIFY_DEVICE_INSTANCE(p_handle->device_id); - - DM_MUTEX_LOCK(); - - DM_TRC("[DM]: >> dm_application_context_delete\r\n"); - - uint32_t err_code; - uint32_t context_len; - pstorage_handle_t block_handle; - - err_code = pstorage_block_identifier_get(&m_storage_handle, - p_handle->device_id, - &block_handle); - - if (err_code == NRF_SUCCESS) - { - err_code = pstorage_load((uint8_t *)&context_len, - &block_handle, - sizeof(uint32_t), - APP_CONTEXT_STORAGE_OFFSET); - - if (context_len != m_context_init_len) - { - err_code = pstorage_update(&block_handle, - (uint8_t *)&m_context_init_len, - sizeof(uint32_t), - APP_CONTEXT_STORAGE_OFFSET); - - if (err_code != NRF_SUCCESS) - { - DM_ERR("[DM]: Failed to delete application context, reason 0x%08X\r\n", err_code); - } - else - { - m_app_context_table[p_handle->device_id] = NULL; - } - } - } - - DM_TRC("[DM]: << dm_application_context_delete\r\n"); - - DM_MUTEX_UNLOCK(); - - return err_code; -#else //DEVICE_MANAGER_APP_CONTEXT_SIZE - return (FEATURE_NOT_ENABLED | DEVICE_MANAGER_ERR_BASE); -#endif //DEVICE_MANAGER_APP_CONTEXT_SIZE -} - - -ret_code_t dm_application_instance_set(dm_application_instance_t const * p_appl_instance, - dm_handle_t * p_handle) -{ - VERIFY_MODULE_INITIALIZED(); - NULL_PARAM_CHECK(p_handle); - NULL_PARAM_CHECK(p_appl_instance); - VERIFY_APP_REGISTERED((*p_appl_instance)); - - p_handle->appl_id = (*p_appl_instance); - - return NRF_SUCCESS; -} - - -uint32_t dm_handle_initialize(dm_handle_t * p_handle) -{ - NULL_PARAM_CHECK(p_handle); - - p_handle->appl_id = DM_INVALID_ID; - p_handle->connection_id = DM_INVALID_ID; - p_handle->device_id = DM_INVALID_ID; - p_handle->service_id = DM_INVALID_ID; - - return NRF_SUCCESS; -} - - -ret_code_t dm_peer_addr_set(dm_handle_t const * p_handle, - ble_gap_addr_t const * p_addr) -{ - VERIFY_MODULE_INITIALIZED(); - NULL_PARAM_CHECK(p_handle); - NULL_PARAM_CHECK(p_addr); - VERIFY_APP_REGISTERED(p_handle->appl_id); - VERIFY_DEVICE_INSTANCE(p_handle->device_id); - - DM_MUTEX_LOCK(); - - DM_TRC("[DM]: >> dm_peer_addr_set\r\n"); - - ret_code_t err_code; - - if ((p_handle->connection_id == DM_INVALID_ID) && - (p_addr->addr_type != BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE)) - { - m_peer_table[p_handle->device_id].peer_id.id_addr_info = (*p_addr); - update_status_bit_set(p_handle->device_id); - device_context_store(p_handle, UPDATE_PEER_ADDR); - err_code = NRF_SUCCESS; - } - else - { - err_code = (NRF_ERROR_INVALID_PARAM | DEVICE_MANAGER_ERR_BASE); - } - - DM_TRC("[DM]: << dm_peer_addr_set\r\n"); - - DM_MUTEX_UNLOCK(); - - return err_code; -} - - -ret_code_t dm_peer_addr_get(dm_handle_t const * p_handle, - ble_gap_addr_t * p_addr) -{ - VERIFY_MODULE_INITIALIZED(); - NULL_PARAM_CHECK(p_handle); - NULL_PARAM_CHECK(p_addr); - VERIFY_APP_REGISTERED(p_handle->appl_id); - - DM_MUTEX_LOCK(); - - DM_TRC("[DM]: >> dm_peer_addr_get\r\n"); - - ret_code_t err_code; - - err_code = (NRF_ERROR_NOT_FOUND | DEVICE_MANAGER_ERR_BASE); - - if (p_handle->device_id == DM_INVALID_ID) - { - if ((p_handle->connection_id != DM_INVALID_ID) && - ((m_connection_table[p_handle->connection_id].state & STATE_CONNECTED) == - STATE_CONNECTED)) - { - DM_TRC("[DM]:[CI 0x%02X]: Address get for non bonded active connection.\r\n", - p_handle->connection_id); - - (*p_addr) = m_connection_table[p_handle->connection_id].peer_addr; - err_code = NRF_SUCCESS; - } - } - else - { - if ((m_peer_table[p_handle->device_id].id_bitmap & ADDR_ENTRY) == 0) - { - DM_TRC("[DM]:[DI 0x%02X]: Address get for bonded device.\r\n", - p_handle->device_id); - - (*p_addr) = m_peer_table[p_handle->device_id].peer_id.id_addr_info; - err_code = NRF_SUCCESS; - } - } - - DM_TRC("[DM]: << dm_peer_addr_get\r\n"); - - DM_MUTEX_UNLOCK(); - - return err_code; -} - - -ret_code_t dm_distributed_keys_get(dm_handle_t const * p_handle, - dm_sec_keyset_t * p_key_dist) -{ - VERIFY_MODULE_INITIALIZED(); - NULL_PARAM_CHECK(p_handle); - NULL_PARAM_CHECK(p_key_dist); - VERIFY_APP_REGISTERED(p_handle->appl_id); - VERIFY_DEVICE_INSTANCE(p_handle->device_id); - - DM_MUTEX_LOCK(); - - DM_TRC("[DM]: >> dm_distributed_keys_get\r\n"); - - ret_code_t err_code; - ble_gap_enc_key_t peer_enc_key; - pstorage_handle_t block_handle; - - err_code = NRF_ERROR_NOT_FOUND; - p_key_dist->keys_central.enc_key.p_enc_key = NULL; - p_key_dist->keys_central.p_id_key = (dm_id_key_t *)&m_peer_table[p_handle->device_id].peer_id; - p_key_dist->keys_central.p_sign_key = NULL; - p_key_dist->keys_periph.p_id_key = (dm_id_key_t *)&m_local_id_info; - p_key_dist->keys_periph.p_sign_key = NULL; - p_key_dist->keys_periph.enc_key.p_enc_key = (dm_enc_key_t *)&peer_enc_key; - - if ((m_peer_table[p_handle->device_id].id_bitmap & IRK_ENTRY) == 0) - { -// p_key_dist->keys_periph.p_id_key->id_addr_info.addr_type = INVALID_ADDR_TYPE; - } - - err_code = pstorage_block_identifier_get(&m_storage_handle, p_handle->device_id, &block_handle); - if (err_code == NRF_SUCCESS) - { - - err_code = pstorage_load((uint8_t *)&peer_enc_key, - &block_handle, - BOND_SIZE, - BOND_STORAGE_OFFSET); - - if (err_code == NRF_SUCCESS) - { - p_key_dist->keys_central.enc_key.p_enc_key = NULL; - p_key_dist->keys_central.p_id_key = (dm_id_key_t *)&m_peer_table[p_handle->device_id].peer_id; - p_key_dist->keys_central.p_sign_key = NULL; - p_key_dist->keys_periph.p_id_key = (dm_id_key_t *)&m_local_id_info; - p_key_dist->keys_periph.p_sign_key = NULL; - p_key_dist->keys_periph.enc_key.p_enc_key = (dm_enc_key_t *)&peer_enc_key; - } - } - - DM_TRC("[DM]: << dm_distributed_keys_get\r\n"); - - DM_MUTEX_UNLOCK(); - - return err_code; -} - - -/**@brief Function for loading bond information for a connection instance. - */ -void bond_data_load(dm_handle_t * p_handle) -{ - pstorage_handle_t block_handle; - - uint32_t err_code = pstorage_block_identifier_get(&m_storage_handle, - p_handle->device_id, - &block_handle); - if (err_code == NRF_SUCCESS) - { - DM_LOG( - "[DM]:[%02X]:[Block ID 0x%08X]:Loading bond information at %p, size 0x%08X, offset 0x%08X.\r\n", - p_handle->connection_id, - block_handle.block_id, - &m_bond_table[p_handle->connection_id], - BOND_SIZE, - BOND_STORAGE_OFFSET); - - err_code = pstorage_load((uint8_t *)&m_bond_table[p_handle->connection_id], - &block_handle, - BOND_SIZE, - BOND_STORAGE_OFFSET); - - if (err_code != NRF_SUCCESS) - { - DM_ERR("[DM]:[%02X]: Failed to load Bond information, reason %08X\r\n", - p_handle->connection_id, - err_code); - } - - DM_LOG( - "[DM]:[%02X]:Loading service context at %p, size 0x%08X, offset 0x%08X.\r\n", - p_handle->connection_id, - &m_gatts_table[p_handle->connection_id], - sizeof(dm_gatts_context_t), - SERVICE_STORAGE_OFFSET); - - err_code = m_service_context_load[m_application_table[0].service]( - &block_handle, - p_handle); - - if (err_code != NRF_SUCCESS) - { - DM_ERR( - "[DM]:[%02X]: Failed to load service information, reason %08X\r\n", - p_handle->connection_id, - err_code); - } - } - else - { - DM_ERR("[DM]:[%02X]: Failed to get block identifier for " - "device %08X, reason %08X.\r\n", p_handle->connection_id, p_handle->device_id, err_code); - } -} - - -void dm_ble_evt_handler(ble_evt_t * p_ble_evt) -{ - uint32_t err_code; - uint32_t index; - uint32_t device_index = DM_INVALID_ID; - bool notify_app = false; - dm_handle_t handle; - dm_event_t event; - uint32_t event_result; - ble_gap_enc_info_t * p_enc_info = NULL; - - VERIFY_MODULE_INITIALIZED_VOID(); - VERIFY_APP_REGISTERED_VOID(0); - DM_MUTEX_LOCK(); - - err_code = dm_handle_initialize(&handle); - APP_ERROR_CHECK(err_code); - - event_result = NRF_SUCCESS; - err_code = NRF_SUCCESS; - event.event_param.p_gap_param = &p_ble_evt->evt.gap_evt; - event.event_paramlen = sizeof(ble_gap_evt_t); - handle.device_id = DM_INVALID_ID; - handle.appl_id = 0; - index = 0x00; - - if (p_ble_evt->header.evt_id != BLE_GAP_EVT_CONNECTED) - { - err_code = connection_instance_find(p_ble_evt->evt.gap_evt.conn_handle, - STATE_CONNECTED, - &index); - - if (err_code == NRF_SUCCESS) - { - handle.device_id = m_connection_table[index].bonded_dev_id; - handle.connection_id = index; - } - } - - switch (p_ble_evt->header.evt_id) - { - case BLE_GAP_EVT_CONNECTED: - //Allocate connection instance for a new connection. - err_code = connection_instance_allocate(&index); - - //Connection instance is successfully allocated. - if (err_code == NRF_SUCCESS) - { - //Application notification related information. - notify_app = true; - event.event_id = DM_EVT_CONNECTION; - handle.connection_id = index; - - m_connection_table[index].conn_handle = p_ble_evt->evt.gap_evt.conn_handle; - m_connection_table[index].state = STATE_CONNECTED; - m_connection_table[index].peer_addr = - p_ble_evt->evt.gap_evt.params.connected.peer_addr; - - if (p_ble_evt->evt.gap_evt.params.connected.irk_match == 1) - { - if (m_irk_index_table[p_ble_evt->evt.gap_evt.params.connected.irk_match_idx] != DM_INVALID_ID) - { - device_index = m_irk_index_table[p_ble_evt->evt.gap_evt.params.connected.irk_match_idx]; - err_code = NRF_SUCCESS; - } - } - else - { - //Use the device address to check if the device exists in the bonded device list. - err_code = device_instance_find(&p_ble_evt->evt.gap_evt.params.connected.peer_addr, - &device_index, EDIV_INIT_VAL); - } - - if (err_code == NRF_SUCCESS) - { - m_connection_table[index].bonded_dev_id = device_index; - m_connection_table[index].state |= STATE_BONDED; - handle.device_id = device_index; - - bond_data_load(&handle); - } - } - break; - - case BLE_GAP_EVT_DISCONNECTED: - //Disconnection could be peer or self initiated hence disconnecting and connecting - //both states are permitted, however, connection handle must be known. - DM_LOG("[DM]: Disconnect Reason 0x%04X\r\n", - p_ble_evt->evt.gap_evt.params.disconnected.reason); - - m_connection_table[index].state &= (~STATE_CONNECTED); - - if ((m_connection_table[index].state & STATE_BONDED) == STATE_BONDED) - { - if ((m_connection_table[index].state & STATE_LINK_ENCRYPTED) == STATE_LINK_ENCRYPTED) - { - //Write bond information persistently. - device_context_store(&handle, STORE_ALL_CONTEXT); - } - } - else - { - //Free any allocated instances for devices that is not bonded. - if (handle.device_id != DM_INVALID_ID) - { - peer_instance_init(handle.device_id); - handle.device_id = DM_INVALID_ID; - } - } - - m_connection_table[index].state = STATE_DISCONNECTING; - notify_app = true; - event.event_id = DM_EVT_DISCONNECTION; - - break; - - case BLE_GAP_EVT_SEC_INFO_REQUEST: - DM_LOG("[DM]: >> BLE_GAP_EVT_SEC_INFO_REQUEST\r\n"); - - //If the device is already bonded, respond with existing info, else NULL. - if (m_connection_table[index].bonded_dev_id == DM_INVALID_ID) - { - //Find device based on div. - err_code = device_instance_find(NULL,&device_index, p_ble_evt->evt.gap_evt.params.sec_info_request.master_id.ediv); - if (err_code == NRF_SUCCESS) - { - //Load needed bonding information. - m_connection_table[index].bonded_dev_id = device_index; - m_connection_table[index].state |= STATE_BONDED; - handle.device_id = device_index; - bond_data_load(&handle); - } - } - - if (m_connection_table[index].bonded_dev_id != DM_INVALID_ID) - { - p_enc_info = &m_bond_table[index].peer_enc_key.enc_info; - DM_DUMP((uint8_t *)p_enc_info, sizeof(ble_gap_enc_info_t)); - } - - err_code = sd_ble_gap_sec_info_reply(p_ble_evt->evt.gap_evt.conn_handle, - p_enc_info, - &m_peer_table[index].peer_id.id_info, - NULL); - - if (err_code != NRF_SUCCESS) - { - DM_ERR("[DM]:[CI %02X]:[DI %02X]: Security information response failed, reason " - "0x%08X\r\n", index, m_connection_table[index].bonded_dev_id, err_code); - } - break; - - case BLE_GAP_EVT_SEC_PARAMS_REQUEST: - DM_LOG("[DM]: >> BLE_GAP_EVT_SEC_PARAMS_REQUEST\r\n"); - - event.event_id = DM_EVT_SECURITY_SETUP; - - m_connection_table[index].state |= STATE_PAIRING; - notify_app = true; - - if (m_connection_table[index].bonded_dev_id == DM_INVALID_ID) - { - //Assign a peer index as a new bond or update existing bonds. - err_code = device_instance_allocate((uint8_t *)&device_index, - &m_connection_table[index].peer_addr); - - //Allocation successful. - if (err_code == NRF_SUCCESS) - { - DM_LOG("[DM]:[CI 0x%02X]:[DI 0x%02X]: Bonded!\r\n",index, device_index); - - handle.device_id = device_index; - m_connection_table[index].bonded_dev_id = device_index; - } - else - { - DM_LOG("[DM]: Security parameter request failed, reason 0x%08X.\r\n", err_code); - event_result = err_code; - notify_app = true; - } - } - else - { - //Bond/key refresh. - event.event_id = DM_EVT_SECURITY_SETUP_REFRESH; - memset(m_gatts_table[index].attributes, 0, DM_GATT_SERVER_ATTR_MAX_SIZE); - - //Set the update flag for bond data. - m_connection_table[index].state |= STATE_BOND_INFO_UPDATE; - } - - ble_gap_sec_keyset_t keys_exchanged; - - DM_LOG("[DM]: 0x%02X, 0x%02X, 0x%02X, 0x%02X\r\n", - p_ble_evt->evt.gap_evt.params.sec_params_request.peer_params.kdist_periph.enc, - p_ble_evt->evt.gap_evt.params.sec_params_request.peer_params.kdist_central.id, - p_ble_evt->evt.gap_evt.params.sec_params_request.peer_params.kdist_periph.sign, - p_ble_evt->evt.gap_evt.params.sec_params_request.peer_params.bond); - - keys_exchanged.keys_central.p_enc_key = NULL; - keys_exchanged.keys_central.p_id_key = &m_peer_table[m_connection_table[index].bonded_dev_id].peer_id; - keys_exchanged.keys_central.p_sign_key = NULL; - keys_exchanged.keys_periph.p_enc_key = &m_bond_table[index].peer_enc_key; - keys_exchanged.keys_periph.p_id_key = NULL; - keys_exchanged.keys_periph.p_sign_key = NULL; - - err_code = sd_ble_gap_sec_params_reply(p_ble_evt->evt.gap_evt.conn_handle, - BLE_GAP_SEC_STATUS_SUCCESS, - &m_application_table[0].sec_param, - &keys_exchanged); - - if (err_code != NRF_SUCCESS) - { - DM_LOG("[DM]: Security parameter reply request failed, reason 0x%08X.\r\n", err_code); - event_result = err_code; - notify_app = false; - } - break; - - case BLE_GAP_EVT_AUTH_STATUS: - { - DM_LOG("[DM]: >> BLE_GAP_EVT_AUTH_STATUS, status %08X\r\n", - p_ble_evt->evt.gap_evt.params.auth_status.auth_status); - - m_application_table[0].state &= (~STATE_CONTROL_PROCEDURE_IN_PROGRESS); - m_connection_table[index].state &= (~STATE_PAIRING); - event.event_id = DM_EVT_SECURITY_SETUP_COMPLETE; - notify_app = true; - - if (p_ble_evt->evt.gap_evt.params.auth_status.auth_status != BLE_GAP_SEC_STATUS_SUCCESS) - { - // Free the allocation as bonding failed. - ret_code_t result = device_instance_free(m_connection_table[index].bonded_dev_id); - (void) result; - event_result = p_ble_evt->evt.gap_evt.params.auth_status.auth_status; - } - else - { - DM_DUMP((uint8_t *)&p_ble_evt->evt.gap_evt.params.auth_status, - sizeof(ble_gap_evt_auth_status_t)); - DM_DUMP((uint8_t *)&m_bond_table[index], sizeof(bond_context_t)); - - if (p_ble_evt->evt.gap_evt.params.auth_status.bonded == 1) - { - if (handle.device_id != DM_INVALID_ID) - { - m_connection_table[index].state |= STATE_BONDED; - - //IRK and/or public address is shared, update it. - if (p_ble_evt->evt.gap_evt.params.auth_status.kdist_central.id == 1) - { - m_peer_table[handle.device_id].id_bitmap &= (~IRK_ENTRY); - } - - if (m_connection_table[index].bonded_dev_id != DM_INVALID_ID) - { - DM_LOG("[DM]:[CI 0x%02X]:[DI 0x%02X]: Bonded!\r\n", - index, - handle.device_id); - - if (m_connection_table[index].peer_addr.addr_type != - BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE) - { - m_peer_table[handle.device_id].peer_id.id_addr_info = - m_connection_table[index].peer_addr; - m_peer_table[handle.device_id].id_bitmap &= (~ADDR_ENTRY); - - DM_DUMP((uint8_t *)&m_peer_table[handle.device_id].peer_id.id_addr_info, - sizeof(m_peer_table[handle.device_id].peer_id.id_addr_info)); - } - else - { - // Here we must fetch the keys from the keyset distributed. - m_peer_table[handle.device_id].ediv = m_bond_table[index].peer_enc_key.master_id.ediv; - m_peer_table[handle.device_id].id_bitmap &= (~IRK_ENTRY); - } - - device_context_store(&handle, FIRST_BOND_STORE); - } - } - } - else - { - //Pairing request, no need to touch the bonding info. - } - } - break; - } - - case BLE_GAP_EVT_CONN_SEC_UPDATE: - DM_LOG("[DM]: >> BLE_GAP_EVT_CONN_SEC_UPDATE, Mode 0x%02X, Level 0x%02X\r\n", - p_ble_evt->evt.gap_evt.params.conn_sec_update.conn_sec.sec_mode.sm, - p_ble_evt->evt.gap_evt.params.conn_sec_update.conn_sec.sec_mode.lv); - - if ((p_ble_evt->evt.gap_evt.params.conn_sec_update.conn_sec.sec_mode.lv == 1) && - (p_ble_evt->evt.gap_evt.params.conn_sec_update.conn_sec.sec_mode.sm == 1) && - ((m_connection_table[index].state & STATE_BONDED) == STATE_BONDED)) - { - //Lost bond case, generate a security refresh event! - memset(m_gatts_table[index].attributes, 0, DM_GATT_SERVER_ATTR_MAX_SIZE); - - event.event_id = DM_EVT_SECURITY_SETUP_REFRESH; - m_connection_table[index].state |= STATE_PAIRING_PENDING; - m_connection_table[index].state |= STATE_BOND_INFO_UPDATE; - m_application_table[0].state |= STATE_QUEUED_CONTROL_REQUEST; - } - else - { - m_connection_table[index].state |= STATE_LINK_ENCRYPTED; - event.event_id = DM_EVT_LINK_SECURED; - - //Apply service context. - err_code = m_service_context_apply[m_application_table[0].service](&handle); - - if (err_code != NRF_SUCCESS) - { - DM_ERR("[DM]:[CI 0x%02X]:[DI 0x%02X]: Failed to apply service context\r\n", - handle.connection_id, - handle.device_id); - - event_result = DM_SERVICE_CONTEXT_NOT_APPLIED; - } - } - event_result = NRF_SUCCESS; - notify_app = true; - - break; - - case BLE_GATTS_EVT_SYS_ATTR_MISSING: - DM_LOG("[DM]: >> BLE_GATTS_EVT_SYS_ATTR_MISSING\r\n"); - - //Apply service context. - event_result = m_service_context_apply[m_application_table[0].service](&handle); - break; - - case BLE_GAP_EVT_SEC_REQUEST: - DM_LOG("[DM]: >> BLE_GAP_EVT_SEC_REQUEST\r\n"); - - //Verify if the device is already bonded, and if it is bonded, initiate encryption. - //If the device is not bonded, an instance needs to be allocated in order to initiate - //bonding. The application have to initiate the procedure, the module will not do this - //automatically. - event.event_id = DM_EVT_SECURITY_SETUP; - notify_app = true; - - break; - - default: - break; - } - - if (notify_app) - { - app_evt_notify(&handle, &event, event_result); - - //Freeing the instance after the event is notified so the application can get the context. - if (event.event_id == DM_EVT_DISCONNECTION) - { - //Free the instance. - connection_instance_free(&index); - } - } - - UNUSED_VARIABLE(err_code); - - DM_MUTEX_UNLOCK(); -} - - -ret_code_t dm_handle_get(uint16_t conn_handle, dm_handle_t * p_handle) -{ - ret_code_t err_code; - uint32_t index; - - NULL_PARAM_CHECK(p_handle); - VERIFY_APP_REGISTERED(p_handle->appl_id); - - p_handle->device_id = DM_INVALID_ID; - - err_code = NRF_ERROR_NOT_FOUND; - - for (index = 0; index < DEVICE_MANAGER_MAX_CONNECTIONS; index++) - { - //Search for matching connection handle. - if (conn_handle == m_connection_table[index].conn_handle) - { - p_handle->connection_id = index; - p_handle->device_id = m_connection_table[index].bonded_dev_id; - - err_code = NRF_SUCCESS; - break; - } - } - return err_code; -} +/* Copyright (C) 2013 Nordic Semiconductor. All Rights Reserved. + * + * The information contained herein is property of Nordic Semiconductor ASA. + * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. + * + * Licensees are granted free, non-transferable use of the information. NO + * WARRANTY of ANY KIND is provided. This heading must NOT be removed from + * the file. + * + */ + +#include "device_manager.h" +#include "app_trace.h" +#include "pstorage.h" +#include "ble_hci.h" +#include "app_error.h" + +#if defined ( __CC_ARM ) + #ifndef __ALIGN + #define __ALIGN(x) __align(x) /**< Forced aligment keyword for ARM Compiler */ + #endif +#elif defined ( __ICCARM__ ) + #ifndef __ALIGN + #define __ALIGN(x) /**< Forced aligment keyword for IAR Compiler */ + #endif +#elif defined ( __GNUC__ ) + #ifndef __ALIGN + #define __ALIGN(x) __attribute__((aligned(x))) /**< Forced aligment keyword for GNU Compiler */ + #endif +#endif + +#define INVALID_ADDR_TYPE 0xFF /**< Identifier for an invalid address type. */ +#define EDIV_INIT_VAL 0xFFFF /**< Initial value for diversifier. */ + +/** + * @defgroup device_manager_app_states Connection Manager Application States + * @{ + */ +#define STATE_CONTROL_PROCEDURE_IN_PROGRESS 0x01 /**< State where a security procedure is ongoing. */ +#define STATE_QUEUED_CONTROL_REQUEST 0x02 /**< State where it is known if there is any queued security request or not. */ +/** @} */ + +/** + * @defgroup device_manager_conn_inst_states Connection Manager Connection Instances States. + * @{ + */ +#define STATE_IDLE 0x01 /**< State where connection instance is free. */ +#define STATE_CONNECTED 0x02 /**< State where connection is successfully established. */ +#define STATE_PAIRING 0x04 /**< State where pairing procedure is in progress. This state is used for pairing and bonding, as pairing is needed for both. */ +#define STATE_BONDED 0x08 /**< State where device is bonded. */ +#define STATE_DISCONNECTING 0x10 /**< State where disconnection is in progress, application will be notified first, but no further active procedures on the link. */ +#define STATE_PAIRING_PENDING 0x20 /**< State where pairing request is pending on the link. */ +#define STATE_BOND_INFO_UPDATE 0x40 /**< State where information has been updated, update the flash. */ +#define STATE_LINK_ENCRYPTED 0x80 /**< State where link is encrypted. */ +/** @} */ + +/** + * @defgroup device_manager_peer_id_defines Peer Identification Information Defines. + * + * @brief These defines are used to know which of the peer identification is applicable for a peer. + * + * @details These defines are used for peer identification. Here, bit map is used because it is + * possible that the application has both IRK and address for identification. + * @{ + */ +#define UNASSIGNED 0xFF /**< Peer instance is unassigned/unused. */ +#define IRK_ENTRY 0x01 /**< Peer instance has IRK as identification information. */ +#define ADDR_ENTRY 0x02 /**< Peer instance has address as identification information. */ +#define SERVICE_CONTEXT_ENTRY 0x04 /**< Peer instance has service context set. */ +#define APP_CONTEXT_ENTRY 0x08 /**< Peer instance has an application context set. */ +/** @} */ + +/**@brief Device store state identifiers. */ +typedef enum +{ + STORE_ALL_CONTEXT, /**< Store all context. */ + FIRST_BOND_STORE, /**< Store bond. */ + UPDATE_PEER_ADDR /**< Update peer address. */ +} device_store_state_t; + +/** + * @defgroup device_manager_context_offsets Context Offsets + * @{ + * + * @brief Context offsets each of the context information in persistent memory. + * + * @details Below is a layout showing how each how the context information is stored in persistent + * memory. + * + * All Device context is stored in the flash as follows: + * +---------+---------+---------+------------------+----------------+--------------------+ + * | Block / Device ID + Layout of stored information in storage block | + * +---------+---------+---------+------------------+----------------+--------------------+ + * | Block 0 | Device 0| Peer Id | Bond Information | Service Context| Application Context| + * +---------+---------+---------+------------------+----------------+--------------------+ + * | Block 1 | Device 1| Peer Id | Bond Information | Service Context| Application Context| + * +---------+---------+---------+------------------+----------------+--------------------+ + * | ... | .... | + * +---------+---------+---------+------------------+----------------+--------------------+ + * | Block N | Device N| Peer Id | Bond Information | Service Context| Application Context| + * +---------+---------+---------+------------------+----------------+--------------------+ + * + * The following defines are used to get offset of each of the components within a block. + */ + +#define PEER_ID_STORAGE_OFFSET 0 /**< Offset at which peer id is stored in the block. */ +#define BOND_STORAGE_OFFSET PEER_ID_SIZE /**< Offset at which bond information is stored in the block. */ +#define SERVICE_STORAGE_OFFSET (BOND_STORAGE_OFFSET + BOND_SIZE) /**< Offset at which service context is stored in the block. */ +#define APP_CONTEXT_STORAGE_OFFSET (SERVICE_STORAGE_OFFSET + SERVICE_CONTEXT_SIZE) /**< Offset at which application context is stored in the block. */ +/** @} */ + +/** + * @defgroup device_manager_context_size Context size. + * @{ + * + * @brief This group defines the size of each of the context information. + */ +#define PEER_ID_SIZE (sizeof(peer_id_t)) /**< Size of peer identification information. */ +#define BOND_SIZE (sizeof(bond_context_t)) /**< Size of bond information. */ +#define DEVICE_CONTEXT_SIZE (PEER_ID_SIZE + BOND_SIZE) /**< Size of Device context, include peer identification and bond information. */ +#define GATTS_SERVICE_CONTEXT_SIZE (sizeof(dm_gatts_context_t)) /**< Size of GATTS service context. */ +#define GATTC_SERVICE_CONTEXT_SIZE (sizeof(dm_gatt_client_context_t)) /**< Size of GATTC service context. */ +#define SERVICE_CONTEXT_SIZE (GATTS_SERVICE_CONTEXT_SIZE + GATTC_SERVICE_CONTEXT_SIZE) /**< Combined size of GATTS and GATTC service contexts. */ +#define APP_CONTEXT_MIN_SIZE 4 /**< Minimum size for application context data. */ +#if (DEVICE_MANAGER_APP_CONTEXT_SIZE != 0) +#define APP_CONTEXT_SIZE (sizeof(uint32_t) + DEVICE_MANAGER_APP_CONTEXT_SIZE) /**< Size of application context including length field. */ +#else //DEVICE_MANAGER_APP_CONTEXT_SIZE +#define APP_CONTEXT_SIZE 0 /**< Size of application context. */ +#endif // DEVICE_MANAGER_APP_CONTEXT_SIZE +#define ALL_CONTEXT_SIZE (DEVICE_CONTEXT_SIZE + SERVICE_CONTEXT_SIZE + APP_CONTEXT_SIZE) /**< Size of all contexts. */ +/** @} */ + + +/** + * @defgroup device_manager_log Module's Log Macros + * + * @details Macros used for creating module logs which can be useful in understanding handling + * of events or actions on API requests. These are intended for debugging purposes and + * can be disabled by defining the DM_DISABLE_LOGS. + * + * @note That if ENABLE_DEBUG_LOG_SUPPORT is disabled, having DM_DISABLE_LOGS has no effect. + * @{ + */ +#define nDM_DISABLE_LOGS /**< Enable this macro to disable any logs from this module. */ + +#ifndef DM_DISABLE_LOGS +#define DM_LOG app_trace_log /**< Used for logging details. */ +#define DM_ERR app_trace_log /**< Used for logging errors in the module. */ +#define DM_TRC app_trace_log /**< Used for getting trace of execution in the module. */ +#define DM_DUMP app_trace_dump /**< Used for dumping octet information to get details of bond information etc. */ +#else //DM_DISABLE_LOGS +#define DM_DUMP(...) /**< Disables dumping of octet streams. */ +#define DM_LOG(...) /**< Disables detailed logs. */ +#define DM_ERR(...) /**< Disables error logs. */ +#define DM_TRC(...) /**< Disables traces. */ +#endif //DM_DISABLE_LOGS +/** @} */ + +/** + * @defgroup device_manager_mutex_lock_unlock Module's Mutex Lock/Unlock Macros. + * + * @details Macros used to lock and unlock modules. Currently the SDK does not use mutexes but + * framework is provided in case need arises to use an alternative architecture. + * @{ + */ +#define DM_MUTEX_LOCK() SDK_MUTEX_LOCK(m_dm_mutex) /**< Lock module using mutex. */ +#define DM_MUTEX_UNLOCK() SDK_MUTEX_UNLOCK(m_dm_mutex) /**< Unlock module using mutex. */ +/** @} */ + + +/** + * @defgroup device_manager_misc_defines Miscellaneous defines used across the module. + * @{ + */ +#define DM_GATT_ATTR_SIZE 6 /**< Size of each GATT attribute to be stored persistently. */ +#define DM_GATT_SERVER_ATTR_MAX_SIZE ((DM_GATT_ATTR_SIZE * DM_GATT_CCCD_COUNT) + 2) /**< Maximum size of GATT attributes to be stored.*/ +#define DM_SERVICE_CONTEXT_COUNT (DM_PROTOCOL_CNTXT_ALL + 1) /**< Maximum number of service contexts. */ +#define DM_EVT_DEVICE_CONTEXT_BASE 0x20 /**< Base for device context base. */ +#define DM_EVT_SERVICE_CONTEXT_BASE 0x30 /**< Base for service context base. */ +#define DM_EVT_APP_CONTEXT_BASE 0x40 /**< Base for application context base. */ +#define DM_LOAD_OPERATION_ID 0x01 /**< Load operation identifier. */ +#define DM_STORE_OPERATION_ID 0x02 /**< Store operation identifier. */ +#define DM_CLEAR_OPERATION_ID 0x03 /**< Clear operation identifier. */ +/** @} */ + +#define DM_GATTS_INVALID_SIZE 0xFFFFFFFF /**< Identifer for GATTS invalid size. */ + +/** + * @defgroup api_param_check API Parameters check macros. + * + * @details Macros for verifying parameters passed to the module in the APIs. These macros + * could be mapped to nothing in the final version of the code in order to save execution + * time and program size. + * @{ + */ + +//#define DM_DISABLE_API_PARAM_CHECK /**< Macro to disable API parameters check. */ + +#ifndef DM_DISABLE_API_PARAM_CHECK + +/**@brief Macro for verifying NULL parameters are not passed to API. + * + * @param[in] PARAM Parameter checked for NULL. + * + * @retval (NRF_ERROR_NULL | DEVICE_MANAGER_ERR_BASE) when @ref PARAM is NULL. + */ +#define NULL_PARAM_CHECK(PARAM) \ + if ((PARAM) == NULL) \ + { \ + return (NRF_ERROR_NULL | DEVICE_MANAGER_ERR_BASE); \ + } +/**@} */ + + +/**@brief Macro for verifying module's initialization status. + * + * @retval (NRF_ERROR_INVALID_STATE | DEVICE_MANAGER_ERR_BASE) when module is not initialized. + */ +#define VERIFY_MODULE_INITIALIZED() \ + do \ + { \ + if (!m_module_initialized) \ + { \ + return (NRF_ERROR_INVALID_STATE | DEVICE_MANAGER_ERR_BASE); \ + } \ + } while (0) + + +/**@brief Macro for verifying module's initialization status. Returns in case it is not initialized. + */ +#define VERIFY_MODULE_INITIALIZED_VOID() \ + do \ + { \ + if (!m_module_initialized) \ + { \ + return; \ + } \ + } while (0) + + +/**@brief Macro for verifying that the application is registered. + * + * @param[in] X Application instance identifier. + * + * @retval (NRF_ERROR_INVALID_STATE | DEVICE_MANAGER_ERR_BASE) when module API is called without + * registering an application with the module. + */ +#define VERIFY_APP_REGISTERED(X) \ + do \ + { \ + if (((X) >= DEVICE_MANAGER_MAX_APPLICATIONS) || \ + (m_application_table[(X)].ntf_cb == NULL)) \ + { \ + return (NRF_ERROR_INVALID_STATE | DEVICE_MANAGER_ERR_BASE); \ + } \ + } while (0) + + +/**@brief Macro for verifying that the application is registered. Returns in case it is not + * registered. + * + * @param[in] X Application instance identifier. + */ +#define VERIFY_APP_REGISTERED_VOID(X) \ + do \ + { \ + if (((X) >= DEVICE_MANAGER_MAX_APPLICATIONS) || \ + (m_application_table[(X)].ntf_cb == NULL)) \ + { \ + return; \ + } \ + } while (0) + + +/**@brief Macro for verifying connection instance is allocated. + * + * @param[in] X Connection instance identifier. + * + * @retval (NRF_ERROR_INVALID_ADDR | DEVICE_MANAGER_ERR_BASE) when connection instance is not + * allocated. + */ +#define VERIFY_CONNECTION_INSTANCE(X) \ + do \ + { \ + if (((X) >= DEVICE_MANAGER_MAX_CONNECTIONS) || \ + (m_connection_table[(X)].state == STATE_IDLE)) \ + { \ + return (NRF_ERROR_INVALID_ADDR | DEVICE_MANAGER_ERR_BASE); \ + } \ + } while (0) + + +/**@brief Macro for verifying if device instance is allocated. + * + * @param[in] X Device instance identifier. + * + * @retval (NRF_ERROR_INVALID_ADDR | DEVICE_MANAGER_ERR_BASE) when device instance is not allocated. + */ +#define VERIFY_DEVICE_INSTANCE(X) \ + do \ + { \ + if (((X) >= DEVICE_MANAGER_MAX_BONDS) || \ + (m_peer_table[(X)].id_bitmap == UNASSIGNED)) \ + { \ + return (NRF_ERROR_INVALID_ADDR | DEVICE_MANAGER_ERR_BASE); \ + } \ + } while (0) + +/**@brief Macro for verifying if device is bonded and thus can store data persistantly. + * + * @param[in] X Connection instance identifier. + * + * @retval (NRF_ERROR_INVALID_STATE | DEVICE_MANAGER_ERR_BASE) when device is not bonded. + */ +#define VERIFY_DEVICE_BOND(X) \ + do \ + { \ + if ((m_connection_table[(X)].state & STATE_BONDED) != STATE_BONDED)\ + { \ + return (NRF_ERROR_INVALID_STATE | DEVICE_MANAGER_ERR_BASE); \ + } \ + } while (0) +#else +#define NULL_PARAM_CHECK(X) +#define VERIFY_MODULE_INITIALIZED() +#define VERIFY_MODULE_INITIALIZED_VOID() +#define VERIFY_APP_REGISTERED(X) +#define VERIFY_APP_REGISTERED_VOID(X) +#define VERIFY_CONNECTION_INSTANCE(X) +#define VERIFY_DEVICE_INSTANCE(X) +#endif //DM_DISABLE_API_PARAM_CHECK +/** @} */ + +#define INVALID_CONTEXT_LEN 0xFFFFFFFF /**< Identifier for invalid context length. */ +/**@brief Macro for checking that application context size is greater that minimal size. + * + * @param[in] X Size of application context. + * + * @retval (NRF_ERROR_INVALID_PARAM) when size is smaller than minimun required size. + */ +#define SIZE_CHECK_APP_CONTEXT(X) \ + if ((X) < (APP_CONTEXT_MIN_SIZE)) \ + { \ + return NRF_ERROR_INVALID_PARAM; \ + } + + +/** + * @defgroup dm_data_types Module's internal data types. + * + * @brief This section describes a module's internal data structures. + * @{ + */ +/**@brief Peer identification information. + */ +typedef struct +{ + ble_gap_id_key_t peer_id; /**< IRK and/or address of peer. */ + uint16_t ediv; /**< Peer's encrypted diversifier. */ + uint8_t id_bitmap; /**< Contains information if above field is valid. */ +} peer_id_t; + +STATIC_ASSERT(sizeof(peer_id_t) % 4 == 0); /**< Check to ensure Peer identification information is a multiple of 4. */ + +/**@brief Portion of bonding information exchanged by a device during bond creation that needs to + * be stored persistently. + * + * @note An entry is not made in this table unless device is bonded. + */ +typedef struct +{ + ble_gap_enc_key_t peer_enc_key; /**< Local LTK info, central IRK and address */ +} bond_context_t; + +STATIC_ASSERT(sizeof(bond_context_t) % 4 == 0); /**< Check to ensure bond information is a multiple of 4. */ + +/**@brief GATT Server Attributes size and data. + */ +typedef struct +{ + uint32_t flags; /**< Flags identifying the stored attributes. */ + uint32_t size; /**< Size of stored attributes. */ + uint8_t attributes[DM_GATT_SERVER_ATTR_MAX_SIZE]; /**< Array to hold the server attributes. */ +} dm_gatts_context_t; + +STATIC_ASSERT(sizeof(dm_gatts_context_t) % 4 == 0); /**< Check to ensure GATT Server Attributes size and data information is a multiple of 4. */ + +/**@brief GATT Client context information. Placeholder for now. + */ +typedef struct +{ + void * p_dummy; /**< Placeholder, currently unused. */ +} dm_gatt_client_context_t; + +STATIC_ASSERT(sizeof(dm_gatt_client_context_t) % 4 == 0); /**< Check to ensure GATT Client context information is a multiple of 4. */ +STATIC_ASSERT((DEVICE_MANAGER_APP_CONTEXT_SIZE % 4) == 0); /**< Check to ensure device manager application context information is a multiple of 4. */ + +/**@brief Connection instance definition. Maintains information with respect to an active peer. + */ +typedef struct +{ + ble_gap_addr_t peer_addr; /**< Peer identification information. This information is retained as long as the connection session exists, once disconnected, for non-bonded devices this information is not stored persistently. */ + uint16_t conn_handle; /**< Connection handle for the device. */ + uint8_t state; /**< Link state. */ + uint8_t bonded_dev_id; /**< In case the device is bonded, this points to the corresponding bonded device. This index can be used to index service and bond context as well. */ +} connection_instance_t; + +/**@brief Application instance definition. Maintains information with respect to a registered + * application. + */ +typedef struct +{ + dm_event_cb_t ntf_cb; /**< Callback registered with the application. */ + ble_gap_sec_params_t sec_param; /**< Local security parameters registered by the application. */ + uint8_t state; /**< Application state. Currently this is used only for knowing if any security procedure is in progress and/or a security procedure is pending to be requested. */ + uint8_t service; /**< Service registered by the application. */ +} application_instance_t; + +/**@brief Function for performing necessary action of storing each of the service context as + * registered by the application. + * + * @param[in] p_block_handle Storage block identifier. + * @param[in] p_handle Device handle identifying device that is stored. + * + * @retval Operation result code. + */ +typedef ret_code_t (* service_context_access_t)(pstorage_handle_t const * p_block_handle, + dm_handle_t const * p_handle); + +/**@brief Function for performing necessary action of applying the context information. + * + * @param[in] p_handle Device handle identifying device that is stored. + * + * @retval Operation result code. + */ +typedef ret_code_t (* service_context_apply_t)(dm_handle_t * p_handle); + +/**@brief Function for performing necessary functions of storing or updating. + * + * @param[in] p_dest Destination address where data is stored persistently. + * @param[in] p_src Source address containing data to be stored. + * @param[in] size Size of data to be stored expressed in bytes. Must be word aligned. + * @param[in] offset Offset in bytes to be applied when writing to the block. + * + * @retval Operation result code. + */ +typedef uint32_t (* storage_operation)(pstorage_handle_t * p_dest, + uint8_t * p_src, + pstorage_size_t size, + pstorage_size_t offset); +/** @} */ + +/** + * @defgroup dm_tables Module's internal tables. + * + * @brief This section describes the module's internal tables and the static global variables + * needed for its functionality. + * @{ + */ +#if (DEVICE_MANAGER_APP_CONTEXT_SIZE != 0) +static uint8_t * m_app_context_table[DEVICE_MANAGER_MAX_BONDS]; /**< Table to remember application contexts of bonded devices. */ +#endif //DEVICE_MANAGER_APP_CONTEXT_SIZE +__ALIGN(sizeof(uint32_t)) +static peer_id_t m_peer_table[DEVICE_MANAGER_MAX_BONDS] ; /**< Table to maintain bonded devices' identification information, an instance is allocated in the table when a device is bonded and freed when bond information is deleted. */ +__ALIGN(sizeof(uint32_t)) +static bond_context_t m_bond_table[DEVICE_MANAGER_MAX_CONNECTIONS]; /**< Table to maintain bond information for active peers. */ +static dm_gatts_context_t m_gatts_table[DEVICE_MANAGER_MAX_CONNECTIONS]; /**< Table for service information for active connection instances. */ +static connection_instance_t m_connection_table[DEVICE_MANAGER_MAX_CONNECTIONS]; /**< Table to maintain active peer information. An instance is allocated in the table when a new connection is established and freed on disconnection. */ +static application_instance_t m_application_table[DEVICE_MANAGER_MAX_APPLICATIONS]; /**< Table to maintain application instances. */ +static pstorage_handle_t m_storage_handle; /**< Persistent storage handle for blocks requested by the module. */ +static uint32_t m_peer_addr_update; /**< 32-bit bitmap to remember peer device address update. */ +static ble_gap_id_key_t m_local_id_info; /**< ID information of central in case resolvable address is used. */ +static bool m_module_initialized = false; /**< State indicating if module is initialized or not. */ +static uint8_t m_irk_index_table[DEVICE_MANAGER_MAX_BONDS]; /**< List maintaining IRK index list. */ + +SDK_MUTEX_DEFINE(m_dm_mutex) /**< Mutex variable. Currently unused, this declaration does not occupy any space in RAM. */ +/** @} */ + +static __INLINE ret_code_t no_service_context_store(pstorage_handle_t const * p_block_handle, + dm_handle_t const * p_handle); + +static __INLINE ret_code_t gatts_context_store(pstorage_handle_t const * p_block_handle, + dm_handle_t const * p_handle); + +static __INLINE ret_code_t gattc_context_store(pstorage_handle_t const * p_block_handle, + dm_handle_t const * p_handle); + +static __INLINE ret_code_t gattsc_context_store(pstorage_handle_t const * p_block_handle, + dm_handle_t const * p_handle); + +static __INLINE ret_code_t no_service_context_load(pstorage_handle_t const * p_block_handle, + dm_handle_t const * p_handle); + +static __INLINE ret_code_t gatts_context_load(pstorage_handle_t const * p_block_handle, + dm_handle_t const * p_handle); + +static __INLINE ret_code_t gattc_context_load(pstorage_handle_t const * p_block_handle, + dm_handle_t const * p_handle); + +static __INLINE ret_code_t gattsc_context_load(pstorage_handle_t const * p_block_handle, + dm_handle_t const * p_handle); + +static __INLINE ret_code_t no_service_context_apply(dm_handle_t * p_handle); + +static __INLINE ret_code_t gatts_context_apply(dm_handle_t * p_handle); + +static __INLINE ret_code_t gattc_context_apply(dm_handle_t * p_handle); + +static __INLINE ret_code_t gattsc_context_apply(dm_handle_t * p_handle); + + +/**< Array of function pointers based on the types of service registered. */ +const service_context_access_t m_service_context_store[DM_SERVICE_CONTEXT_COUNT] = +{ + no_service_context_store, /**< Dummy function, when there is no service context registered. */ + gatts_context_store, /**< GATT Server context store function. */ + gattc_context_store, /**< GATT Client context store function. */ + gattsc_context_store /**< GATT Server & Client context store function. */ +}; + + +/**< Array of function pointers based on the types of service registered. */ +const service_context_access_t m_service_context_load[DM_SERVICE_CONTEXT_COUNT] = +{ + no_service_context_load, /**< Dummy function, when there is no service context registered. */ + gatts_context_load, /**< GATT Server context load function. */ + gattc_context_load, /**< GATT Client context load function. */ + gattsc_context_load /**< GATT Server & Client context load function. */ +}; + + +/**< Array of function pointers based on the types of service registered. */ +const service_context_apply_t m_service_context_apply[DM_SERVICE_CONTEXT_COUNT] = +{ + no_service_context_apply, /**< Dummy function, when there is no service context registered. */ + gatts_context_apply, /**< GATT Server context apply function. */ + gattc_context_apply, /**< GATT Client context apply function. */ + gattsc_context_apply /**< GATT Server & Client context apply function. */ +}; + + +const uint32_t m_context_init_len = 0xFFFFFFFF; /**< Constant used to update the initial value for context in the flash. */ + +/**@brief Function for setting update status for the device identified by 'index'. + * + * @param[in] index Device identifier. + */ +static __INLINE void update_status_bit_set(uint32_t index) +{ + m_peer_addr_update |= (BIT_0 << index); +} + + +/**@brief Function for resetting update status for device identified by 'index'. + * + * @param[in] index Device identifier. + */ +static __INLINE void update_status_bit_reset(uint32_t index) +{ + m_peer_addr_update &= (~((uint32_t)BIT_0 << index)); +} + + +/**@brief Function for providing update status for the device identified by 'index'. + * + * @param[in] index Device identifier. + * + * @retval true if the bit is set, false otherwise. + */ +static __INLINE bool update_status_bit_is_set(uint32_t index) +{ + return ((m_peer_addr_update & (BIT_0 << index)) ? true : false); +} + + +/**@brief Function for initialiasing the application instance identified by 'index'. + * + * @param[in] index Device identifier. + */ +static __INLINE void application_instance_init(uint32_t index) +{ + DM_TRC("[DM]: Initializing Application Instance 0x%08X.\r\n", index); + + m_application_table[index].ntf_cb = NULL; + m_application_table[index].state = 0x00; + m_application_table[index].service = 0x00; +} + + +/**@brief Function for initialiasing the connection instance identified by 'index'. + * + * @param[in] index Device identifier. + */ +static __INLINE void connection_instance_init(uint32_t index) +{ + DM_TRC("[DM]: Initializing Connection Instance 0x%08X.\r\n", index); + + m_connection_table[index].state = STATE_IDLE; + m_connection_table[index].conn_handle = BLE_CONN_HANDLE_INVALID; + m_connection_table[index].bonded_dev_id = DM_INVALID_ID; + + memset(&m_connection_table[index].peer_addr, 0, sizeof (ble_gap_addr_t)); +} + + +/**@brief Function for initialiasing the peer device instance identified by 'index'. + * + * @param[in] index Device identifier. + */ +static __INLINE void peer_instance_init(uint32_t index) +{ + DM_TRC("[DM]: Initializing Peer Instance 0x%08X.\r\n", index); + + memset(m_peer_table[index].peer_id.id_addr_info.addr, 0, BLE_GAP_ADDR_LEN); + memset(m_peer_table[index].peer_id.id_info.irk, 0, BLE_GAP_SEC_KEY_LEN); + + //Initialize the address type to invalid. + m_peer_table[index].peer_id.id_addr_info.addr_type = INVALID_ADDR_TYPE; + + //Initialize the identification bit map to unassigned. + m_peer_table[index].id_bitmap = UNASSIGNED; + + // Initialize diversifier. + m_peer_table[index].ediv = EDIV_INIT_VAL; + + + //Reset the status bit. + update_status_bit_reset(index); + +#if (DEVICE_MANAGER_APP_CONTEXT_SIZE != 0) + //Initialize the application context for bond device. + m_app_context_table[index] = NULL; +#endif //DEVICE_MANAGER_APP_CONTEXT_SIZE +} + + +/**@brief Function for searching connection instance matching the connection handle and the state + * requested. + * + * @details Connection handle and state information is used to get a connection instance, it + * is possible to ignore the connection handle by using BLE_CONN_HANDLE_INVALID. + * + * @param[in] conn_handle Connection handle. + * @param[in] state Connection instance state. + * @param[out] p_instance Connection instance. + * + * @retval NRF_SUCCESS Operation success. + * @retval NRF_ERROR_INVALID_STATE Operation failure. Invalid state + * @retval NRF_ERROR_NOT_FOUND Operation failure. Not found + */ +static ret_code_t connection_instance_find(uint16_t conn_handle, + uint8_t state, + uint32_t * p_instance) +{ + ret_code_t err_code; + uint32_t index; + + err_code = NRF_ERROR_INVALID_STATE; + + for (index = 0; index < DEVICE_MANAGER_MAX_CONNECTIONS; index++) + { + //Search only based on the state. + if (state & m_connection_table[index].state) + { + //Ignore the connection handle. + if ((conn_handle == BLE_CONN_HANDLE_INVALID) || + (conn_handle == m_connection_table[index].conn_handle)) + { + //Search for matching connection handle. + (*p_instance) = index; + err_code = NRF_SUCCESS; + + break; + } + else + { + err_code = NRF_ERROR_NOT_FOUND; + } + } + } + + return err_code; +} + + +/**@brief Function for allocating device instance for a bonded device. + * + * @param[out] p_device_index Device index. + * @param[in] p_addr Peer identification information. + * + * @retval NRF_SUCCESS Operation success. + * @retval DM_DEVICE_CONTEXT_FULL Operation failure. + */ +static __INLINE ret_code_t device_instance_allocate(uint8_t * p_device_index, + ble_gap_addr_t const * p_addr) +{ + ret_code_t err_code; + uint32_t index; + + err_code = DM_DEVICE_CONTEXT_FULL; + + for (index = 0; index < DEVICE_MANAGER_MAX_BONDS; index++) + { + DM_TRC("[DM]:[DI 0x%02X]: Device type 0x%02X.\r\n", + index, m_peer_table[index].peer_id.id_addr_info.addr_type); + DM_TRC("[DM]: Device Addr 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X.\r\n", + m_peer_table[index].peer_id.id_addr_info.addr[0], + m_peer_table[index].peer_id.id_addr_info.addr[1], + m_peer_table[index].peer_id.id_addr_info.addr[2], + m_peer_table[index].peer_id.id_addr_info.addr[3], + m_peer_table[index].peer_id.id_addr_info.addr[4], + m_peer_table[index].peer_id.id_addr_info.addr[5]); + + if (m_peer_table[index].id_bitmap == UNASSIGNED) + { + if (p_addr->addr_type != BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE) + { + m_peer_table[index].id_bitmap &= (~ADDR_ENTRY); + m_peer_table[index].peer_id.id_addr_info = (*p_addr); + } + else + { + m_peer_table[index].id_bitmap &= (~IRK_ENTRY); + } + + (*p_device_index) = index; + err_code = NRF_SUCCESS; + + DM_LOG("[DM]: Allocated device instance 0x%02X\r\n", index); + + break; + } + } + + return err_code; +} + + +/**@brief Function for freeing a device instance allocated for bonded device. + * + * @param[in] device_index Device index. + * + * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. + */ +static __INLINE ret_code_t device_instance_free(uint32_t device_index) +{ + ret_code_t err_code; + pstorage_handle_t block_handle; + + //Get the block handle. + err_code = pstorage_block_identifier_get(&m_storage_handle, device_index, &block_handle); + + if (err_code == NRF_SUCCESS) + { + DM_TRC("[DM]:[DI 0x%02X]: Freeing Instance.\r\n", device_index); + + //Request clearing of the block. + err_code = pstorage_clear(&block_handle, ALL_CONTEXT_SIZE); + + if (err_code == NRF_SUCCESS) + { + peer_instance_init(device_index); + } + } + + return err_code; +} + + +/**@brief Function for searching for the device in the bonded device list. + * + * @param[in] p_addr Peer identification information. + * @param[out] p_device_index Device index. + * + * @retval NRF_SUCCESS Operation success. + * @retval NRF_ERROR_NOT_FOUND Operation failure. + */ +static ret_code_t device_instance_find(ble_gap_addr_t const * p_addr, uint32_t * p_device_index, uint16_t ediv) +{ + ret_code_t err_code; + uint32_t index; + + err_code = NRF_ERROR_NOT_FOUND; + + if (NULL != p_addr) + { + DM_TRC("[DM]: Searching for device 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X.\r\n", + p_addr->addr[0], + p_addr->addr[1], + p_addr->addr[2], + p_addr->addr[3], + p_addr->addr[4], + p_addr->addr[5]); + } + + for (index = 0; index < DEVICE_MANAGER_MAX_BONDS; index++) + { + DM_TRC("[DM]:[DI 0x%02X]: Device type 0x%02X.\r\n", + index, m_peer_table[index].peer_id.id_addr_info.addr_type); + DM_TRC("[DM]: Device Addr 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X.\r\n", + m_peer_table[index].peer_id.id_addr_info.addr[0], + m_peer_table[index].peer_id.id_addr_info.addr[1], + m_peer_table[index].peer_id.id_addr_info.addr[2], + m_peer_table[index].peer_id.id_addr_info.addr[3], + m_peer_table[index].peer_id.id_addr_info.addr[4], + m_peer_table[index].peer_id.id_addr_info.addr[5]); + + if (((NULL == p_addr) && (ediv == m_peer_table[index].ediv)) || + ((NULL != p_addr) && (memcmp(&m_peer_table[index].peer_id.id_addr_info, p_addr, sizeof(ble_gap_addr_t)) == 0))) + { + DM_LOG("[DM]: Found device at instance 0x%02X\r\n", index); + + (*p_device_index) = index; + err_code = NRF_SUCCESS; + + break; + } + } + + return err_code; +} + + +/**@brief Function for notifying connection manager event to the application. + * + * @param[in] p_handle Device handle identifying device. + * @param[in] p_event Connection manager event details. + * @param[in] event_result Event result code. + */ +static __INLINE void app_evt_notify(dm_handle_t const * const p_handle, + dm_event_t const * const p_event, + uint32_t event_result) +{ + dm_event_cb_t app_cb = m_application_table[0].ntf_cb; + + DM_MUTEX_UNLOCK(); + + DM_TRC("[DM]: Notifying application of event 0x%02X\r\n", p_event->event_id); + + //No need to do any kind of return value processing thus can be supressed. + UNUSED_VARIABLE(app_cb(p_handle, p_event, event_result)); + + DM_MUTEX_LOCK(); +} + + +/**@brief Function for allocating instance. + * + * @details The instance identifier is provided in the 'p_instance' parameter if the routine + * succeeds. + * + * @param[out] p_instance Connection instance. + * + * @retval NRF_SUCCESS Operation success. + * @retval NRF_ERROR_NO_MEM Operation failure. No memory. + */ +static __INLINE uint32_t connection_instance_allocate(uint32_t * p_instance) +{ + uint32_t err_code; + + DM_TRC("[DM]: Request to allocation connection instance\r\n"); + + err_code = connection_instance_find(BLE_CONN_HANDLE_INVALID, STATE_IDLE, p_instance); + + if (err_code == NRF_SUCCESS) + { + DM_LOG("[DM]:[%02X]: Connection Instance Allocated.\r\n", (*p_instance)); + m_connection_table[*p_instance].state = STATE_CONNECTED; + } + else + { + DM_LOG("[DM]: No free connection instances available\r\n"); + err_code = NRF_ERROR_NO_MEM; + } + + return err_code; +} + + +/**@brief Function for freeing instance. Instance identifier is provided in the parameter + * 'p_instance' in case the routine succeeds. + * + * @param[in] p_instance Connection instance. + */ +static __INLINE void connection_instance_free(uint32_t const * p_instance) +{ + DM_TRC("[DM]:[CI 0x%02X]: Freeing connection instance\r\n", (*p_instance)); + + if (m_connection_table[*p_instance].state != STATE_IDLE) + { + DM_LOG("[DM]:[%02X]: Freed connection instance.\r\n", (*p_instance)); + connection_instance_init(*p_instance); + } +} + + +/**@brief Function for storage operation dummy handler. + * + * @param[in] p_dest Destination address where data is to be stored persistently. + * @param[in] p_src Source address containing data to be stored. API assumes this to be resident + * memory and no intermediate copy of data is made by the API. + * @param[in] size Size of data to be stored expressed in bytes. Should be word aligned. + * @param[in] offset Offset in bytes to be applied when writing to the block. + * For example, if within a block of 100 bytes, application wishes to + * write 20 bytes at offset of 12, then this field should be set to 12. + * Should be word aligned. + * + * @retval NRF_SUCCESS Operation success. + */ +static uint32_t storage_operation_dummy_handler(pstorage_handle_t * p_dest, + uint8_t * p_src, + pstorage_size_t size, + pstorage_size_t offset) +{ + return NRF_SUCCESS; +} + + +/**@brief Function for saving the device context persistently. + * + * @param[in] p_handle Device handle identifying device. + * @param[in] state Device store state. + */ +static __INLINE void device_context_store(dm_handle_t const * p_handle, device_store_state_t state) +{ + pstorage_handle_t block_handle; + storage_operation store_fn; + ret_code_t err_code; + + DM_LOG("[DM]: --> device_context_store\r\n"); + + err_code = pstorage_block_identifier_get(&m_storage_handle, + p_handle->device_id, + &block_handle); + + if (err_code == NRF_SUCCESS) + { + if ((STATE_BOND_INFO_UPDATE == + (m_connection_table[p_handle->connection_id].state & STATE_BOND_INFO_UPDATE)) || + (state == UPDATE_PEER_ADDR)) + { + DM_LOG("[DM]:[DI %02X]:[CI %02X]: -> Updating bonding information.\r\n", + p_handle->device_id, p_handle->connection_id); + + store_fn = pstorage_update; + } + else if (state == FIRST_BOND_STORE) + { + DM_LOG("[DM]:[DI %02X]:[CI %02X]: -> Storing bonding information.\r\n", + p_handle->device_id, p_handle->connection_id); + + store_fn = pstorage_store; + } + else + { + DM_LOG("[DM]:[DI %02X]:[CI %02X]: -> No update in bonding information.\r\n", + p_handle->device_id, p_handle->connection_id); + + //No operation needed. + store_fn = storage_operation_dummy_handler; + } + + //Store the peer id. + err_code = store_fn(&block_handle, + (uint8_t *)&m_peer_table[p_handle->device_id], + PEER_ID_SIZE, + PEER_ID_STORAGE_OFFSET); + + if ((err_code == NRF_SUCCESS) && (state != UPDATE_PEER_ADDR)) + { + m_connection_table[p_handle->connection_id].state &= (~STATE_BOND_INFO_UPDATE); + + //Store the bond information. + err_code = store_fn(&block_handle, + (uint8_t *)&m_bond_table[p_handle->connection_id], + BOND_SIZE, + BOND_STORAGE_OFFSET); + + if (err_code != NRF_SUCCESS) + { + DM_ERR("[DM]:[0x%02X]:Failed to store bond information, reason 0x%08X\r\n", + p_handle->device_id, err_code); + } + } + + if (state != UPDATE_PEER_ADDR) + { + //Store the service information + err_code = m_service_context_store[m_application_table[p_handle->appl_id].service] + ( + &block_handle, + p_handle + ); + + if (err_code != NRF_SUCCESS) + { + //Notify application of an error event. + DM_ERR("[DM]: Failed to store service context, reason %08X\r\n", err_code); + } + } + } + + if (err_code != NRF_SUCCESS) + { + //Notify application of an error event. + DM_ERR("[DM]: Failed to store device context, reason %08X\r\n", err_code); + } +} + + +/**@brief Function for storing when there is no service registered. + * + * @param[in] p_block_handle Storage block identifier. + * @param[in] p_handle Device handle identifying device that is loaded. + * + * @retval NRF_SUCCESS + */ +static __INLINE ret_code_t no_service_context_store(pstorage_handle_t const * p_block_handle, + dm_handle_t const * p_handle) +{ + DM_LOG("[DM]: --> no_service_context_store\r\n"); + + return NRF_SUCCESS; +} + + +/**@brief Function for storing GATT Server context. + * + * @param[in] p_block_handle Storage block identifier. + * @param[in] p_handle Device handle identifying device that is stored. + * + * @retval NRF_SUCCESS Operation success. + */ +static __INLINE ret_code_t gatts_context_store(pstorage_handle_t const * p_block_handle, + dm_handle_t const * p_handle) +{ + storage_operation store_fn; + uint32_t attr_flags = BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS | BLE_GATTS_SYS_ATTR_FLAG_USR_SRVCS; + uint16_t attr_len = DM_GATT_SERVER_ATTR_MAX_SIZE; + uint8_t sys_data[DM_GATT_SERVER_ATTR_MAX_SIZE]; + + DM_LOG("[DM]: --> gatts_context_store\r\n"); + + uint32_t err_code = sd_ble_gatts_sys_attr_get( + m_connection_table[p_handle->connection_id].conn_handle, + sys_data, + &attr_len, + attr_flags); + + if (err_code == NRF_SUCCESS) + { + if (memcmp(m_gatts_table[p_handle->connection_id].attributes, sys_data, attr_len) == 0) + { + //No store operation is needed. + DM_LOG("[DM]:[0x%02X]: No change in GATTS Context information.\r\n", + p_handle->device_id); + + if ((m_connection_table[p_handle->connection_id].state & STATE_CONNECTED) != + STATE_CONNECTED) + { + DM_LOG("[DM]:[0x%02X]: Resetting GATTS for active instance.\r\n", + p_handle->connection_id); + + //Reset GATTS information for the current context. + memset(&m_gatts_table[p_handle->connection_id], 0, sizeof(dm_gatts_context_t)); + } + } + else + { + if (m_gatts_table[p_handle->connection_id].size != 0) + { + //There is data already stored in persistent memory, therefore an update is needed. + DM_LOG("[DM]:[0x%02X]: Updating stored service context\r\n", p_handle->device_id); + + store_fn = pstorage_update; + } + else + { + //Fresh write, a store is needed. + DM_LOG("[DM]:[0x%02X]: Storing service context\r\n", p_handle->device_id); + + store_fn = pstorage_store; + } + + m_gatts_table[p_handle->connection_id].flags = attr_flags; + m_gatts_table[p_handle->connection_id].size = attr_len; + memcpy(m_gatts_table[p_handle->connection_id].attributes, sys_data, attr_len); + + DM_DUMP((uint8_t *)&m_gatts_table[p_handle->connection_id], sizeof(dm_gatts_context_t)); + + DM_LOG("[DM]:[0x%02X]: GATTS Data size 0x%08X\r\n", + p_handle->device_id, + m_gatts_table[p_handle->connection_id].size); + + //Store GATTS information. + err_code = store_fn((pstorage_handle_t *)p_block_handle, + (uint8_t *)&m_gatts_table[p_handle->connection_id], + GATTS_SERVICE_CONTEXT_SIZE, + SERVICE_STORAGE_OFFSET); + + if (err_code != NRF_SUCCESS) + { + DM_ERR("[DM]:[0x%02X]:Failed to store service context, reason 0x%08X\r\n", + p_handle->device_id, + err_code); + } + else + { + DM_LOG("[DM]: Service context successfully stored.\r\n"); + } + } + } + + return NRF_SUCCESS; +} + + +/**@brief Function for storing GATT Client context. + * + * @param[in] p_block_handle Storage block identifier. + * @param[in] p_handle Device handle identifying device that is stored. + * + * @retval NRF_SUCCESS Operation success. + */ +static __INLINE ret_code_t gattc_context_store(pstorage_handle_t const * p_block_handle, + dm_handle_t const * p_handle) +{ + DM_LOG("[DM]: --> gattc_context_store\r\n"); + + return NRF_SUCCESS; +} + + +/**@brief Function for storing GATT Server & Client context. + * + * @param[in] p_block_handle Storage block identifier. + * @param[in] p_handle Device handle identifying device that is stored. + * + * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. + */ +static __INLINE ret_code_t gattsc_context_store(pstorage_handle_t const * p_block_handle, + dm_handle_t const * p_handle) +{ + DM_LOG("[DM]: --> gattsc_context_store\r\n"); + + ret_code_t err_code = gatts_context_store(p_block_handle, p_handle); + + if (NRF_SUCCESS == err_code) + { + err_code = gattc_context_store(p_block_handle, p_handle); + } + + return err_code; +} + + +/**@brief Function for loading when there is no service registered. + * + * @param[in] p_block_handle Storage block identifier. + * @param[in] p_handle Device handle identifying device that is loaded. + * + * @retval NRF_SUCCESS + */ +static __INLINE ret_code_t no_service_context_load(pstorage_handle_t const * p_block_handle, + dm_handle_t const * p_handle) +{ + DM_LOG("[DM]: --> no_service_context_load\r\n"); + + return NRF_SUCCESS; +} + + +/**@brief Function for loading GATT Server context. + * + * @param[in] p_block_handle Storage block identifier. + * @param[in] p_handle Device handle identifying device that is loaded. + * + * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. + */ +static __INLINE ret_code_t gatts_context_load(pstorage_handle_t const * p_block_handle, + dm_handle_t const * p_handle) +{ + DM_LOG("[DM]:[CI 0x%02X]:[DI 0x%02X]: --> gatts_context_load\r\n", + p_handle->connection_id, + p_handle->device_id); + + ret_code_t err_code = pstorage_load((uint8_t *)&m_gatts_table[p_handle->connection_id], + (pstorage_handle_t *)p_block_handle, + GATTS_SERVICE_CONTEXT_SIZE, + SERVICE_STORAGE_OFFSET); + + if (err_code == NRF_SUCCESS) + { + DM_LOG("[DM]:[%02X]:[Block ID 0x%08X]: Service context loaded, size 0x%08X\r\n", + p_handle->connection_id, + p_block_handle->block_id, + m_gatts_table[p_handle->connection_id].size); + DM_DUMP((uint8_t *)&m_gatts_table[p_handle->connection_id], sizeof(dm_gatts_context_t)); + + if (m_gatts_table[p_handle->connection_id].size == DM_GATTS_INVALID_SIZE) + { + m_gatts_table[p_handle->connection_id].size = 0; + } + } + else + { + DM_ERR("[DM]:[%02X]: Failed to load Service context, reason %08X\r\n", + p_handle->connection_id, + err_code); + } + + return err_code; +} + + +/**@brief Function for loading GATT Client context. + * + * @param[in] p_block_handle Storage block identifier. + * @param[in] p_handle Device handle identifying device that is loaded. + * + * @retval NRF_SUCCESS + */ +static __INLINE ret_code_t gattc_context_load(pstorage_handle_t const * p_block_handle, + dm_handle_t const * p_handle) +{ + DM_LOG("[DM]: --> gattc_context_load\r\n"); + + return NRF_SUCCESS; +} + + +/**@brief Function for loading GATT Server & Client context. + * + * @param[in] p_block_handle Storage block identifier. + * @param[in] p_handle Device handle identifying device that is loaded. + * + * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. + */ +static __INLINE ret_code_t gattsc_context_load(pstorage_handle_t const * p_block_handle, + dm_handle_t const * p_handle) +{ + DM_LOG("[DM]: --> gattsc_context_load\r\n"); + + ret_code_t err_code = gatts_context_load(p_block_handle, p_handle); + + if (NRF_SUCCESS == err_code) + { + err_code = gattc_context_load(p_block_handle, p_handle); + } + + return err_code; +} + + +/**@brief Function for applying when there is no service registered. + * + * @param[in] p_handle Device handle identifying device that is applied. + * + * @retval NRF_SUCCESS + */ +static __INLINE ret_code_t no_service_context_apply(dm_handle_t * p_handle) +{ + DM_LOG("[DM]: --> no_service_context_apply\r\n"); + DM_LOG("[DM]:[CI 0x%02X]: No Service context\r\n", p_handle->connection_id); + + return NRF_SUCCESS; +} + + +/**@brief Function for applying GATT Server context. + * + * @param[in] p_handle Device handle identifying device that is applied. + * + * @retval NRF_SUCCESS On success. + * @retval DM_SERVICE_CONTEXT_NOT_APPLIED On failure. + */ +static __INLINE ret_code_t gatts_context_apply(dm_handle_t * p_handle) +{ + uint32_t err_code; + + uint8_t * p_gatts_context = NULL; + uint16_t context_len = 0; + uint32_t context_flags = 0; + + DM_LOG("[DM]: --> gatts_context_apply\r\n"); + DM_LOG("[DM]:[CI 0x%02X]: State 0x%02X, Size 0x%08X\r\n", + p_handle->connection_id, + m_connection_table[p_handle->connection_id].state, + m_gatts_table[p_handle->connection_id].size); + + if ((m_gatts_table[p_handle->connection_id].size != 0) && + ( + ((m_connection_table[p_handle->connection_id].state & STATE_LINK_ENCRYPTED) == STATE_LINK_ENCRYPTED) && + ((m_connection_table[p_handle->connection_id].state & STATE_BOND_INFO_UPDATE) + != STATE_BOND_INFO_UPDATE) + ) + ) + { + DM_LOG("[DM]: Setting stored context.\r\n"); + + p_gatts_context = &m_gatts_table[p_handle->connection_id].attributes[0]; + context_len = m_gatts_table[p_handle->connection_id].size; + context_flags = m_gatts_table[p_handle->connection_id].flags; + } + + err_code = sd_ble_gatts_sys_attr_set(m_connection_table[p_handle->connection_id].conn_handle, + p_gatts_context, + context_len, + context_flags); + + if (err_code == NRF_ERROR_INVALID_DATA) + { + // Indication that the ATT table has changed. Restore the system attributes to system + // services only and send a service changed indication if possible. + context_flags = BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS; + err_code = sd_ble_gatts_sys_attr_set(m_connection_table[p_handle->connection_id].conn_handle, + p_gatts_context, + context_len, + context_flags); + } + + if (err_code != NRF_SUCCESS) + { + DM_LOG("[DM]: Failed to set system attributes, reason 0x%08X.\r\n", err_code); + + err_code = DM_SERVICE_CONTEXT_NOT_APPLIED; + } + + if (context_flags == BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS) + { + err_code = sd_ble_gatts_service_changed(m_connection_table[p_handle->connection_id].conn_handle, + 0x000C, + 0xFFFF); + if (err_code != NRF_SUCCESS) + { + DM_LOG("[DM]: Failed to send Service Changed indication, reason 0x%08X.\r\n", err_code); + if ((err_code != BLE_ERROR_INVALID_CONN_HANDLE) && + (err_code != NRF_ERROR_INVALID_STATE) && + (err_code != BLE_ERROR_NO_TX_BUFFERS) && + (err_code != NRF_ERROR_BUSY)) + { + // Those errors can be expected when sending trying to send Service Changed + // Indication if the CCCD is not set to indicate. Thus set the returning error + // code to success. + err_code = NRF_SUCCESS; + } + else + { + err_code = DM_SERVICE_CONTEXT_NOT_APPLIED; + } + } + } + + return err_code; +} + + +/**@brief Function for applying GATT Client context. + * + * @param[in] p_handle Device handle identifying device that is applied. + * + * @retval NRF_SUCCESS On success. + */ +static __INLINE ret_code_t gattc_context_apply(dm_handle_t * p_handle) +{ + DM_LOG("[DM]: --> gattc_context_apply\r\n"); + + return NRF_SUCCESS; +} + + +/**@brief Function for applying GATT Server & Client context. + * + * @param[in] p_handle Device handle identifying device that is applied. + * + * @retval NRF_SUCCESS On success, else an error code indicating reason for failure. + */ +static __INLINE ret_code_t gattsc_context_apply(dm_handle_t * p_handle) +{ + uint32_t err_code; + + DM_LOG("[DM]: --> gattsc_context_apply\r\n"); + + err_code = gatts_context_apply(p_handle); + + if (err_code == NRF_SUCCESS) + { + err_code = gattc_context_apply(p_handle); + } + + return err_code; +} + + +/**@brief Function for pstorage module callback. + * + * @param[in] p_handle Identifies module and block for which callback is received. + * @param[in] op_code Identifies the operation for which the event is notified. + * @param[in] result Identifies the result of flash access operation. + * NRF_SUCCESS implies, operation succeeded. + * @param[in] p_data Identifies the application data pointer. In case of store operation, this + * points to the resident source of application memory that application can now + * free or reuse. In case of clear, this is NULL as no application pointer is + * needed for this operation. + * @param[in] data_len Length of data provided by the application for the operation. + */ +static void dm_pstorage_cb_handler(pstorage_handle_t * p_handle, + uint8_t op_code, + uint32_t result, + uint8_t * p_data, + uint32_t data_len) +{ + VERIFY_APP_REGISTERED_VOID(0); + + if (data_len > ALL_CONTEXT_SIZE) + { + //Clearing of all bonds at initialization, no event is generated. + return; + } + + DM_MUTEX_LOCK(); + + dm_event_t dm_event; + dm_handle_t dm_handle; + dm_context_t context_data; + pstorage_handle_t block_handle; + uint32_t index_count; + uint32_t err_code; + + bool app_notify = true; + + err_code = dm_handle_initialize(&dm_handle); + APP_ERROR_CHECK(err_code); + + dm_handle.appl_id = 0; + dm_event.event_id = 0x00; + + //Construct the event which it is related to. + + //Initialize context data information and length. + context_data.p_data = p_data; + context_data.len = data_len; + + for (uint32_t index = 0; index < DEVICE_MANAGER_MAX_BONDS; index++) + { + err_code = pstorage_block_identifier_get(&m_storage_handle, index, &block_handle); + if ((err_code == NRF_SUCCESS) && + ( + (memcmp(p_handle, &block_handle, sizeof(pstorage_handle_t)) == 0) + ) + ) + { + dm_handle.device_id = index; + break; + } + } + + if (dm_handle.device_id != DM_INVALID_ID) + { + if (op_code == PSTORAGE_CLEAR_OP_CODE) + { + if (data_len == ALL_CONTEXT_SIZE) + { + dm_event.event_id = DM_EVT_DEVICE_CONTEXT_BASE; + } + else + { + dm_event.event_id = DM_EVT_APP_CONTEXT_BASE; + } + } + else + { + //Update or store operation. + //Context is identified based on the pointer value. Device context, application context + //and service context all have their own value range. + index_count = ((uint32_t)(p_data - (uint8_t *)m_peer_table)) / PEER_ID_SIZE; + + if (index_count < DEVICE_MANAGER_MAX_BONDS) + { + dm_event.event_param.p_device_context = &context_data; + + //Only the peer identification is stored, not bond information. Hence do not notify + //the application yet, unless the store operation resulted in a failure. + if ((result == NRF_SUCCESS) && + ( + (update_status_bit_is_set(dm_handle.device_id) == false) + ) + ) + { + app_notify = false; + } + else + { + //Reset update status since update is complete. + update_status_bit_reset(dm_handle.device_id); + + //Notify application of error in storing the context. + dm_event.event_id = DM_EVT_DEVICE_CONTEXT_BASE; + } + } + else + { + index_count = ((uint32_t)(p_data - (uint8_t *)m_bond_table)) / BOND_SIZE; + + if (index_count < DEVICE_MANAGER_MAX_CONNECTIONS) + { + DM_LOG("[DM]:[0x%02X]:[0x%02X]: Bond context Event\r\n", + dm_handle.device_id, + dm_handle.connection_id); + + dm_event.event_param.p_device_context = &context_data; + dm_event.event_id = DM_EVT_DEVICE_CONTEXT_BASE; + dm_handle.connection_id = index_count; + + ble_gap_sec_keyset_t keys_exchanged; + keys_exchanged.keys_central.p_enc_key = NULL; + keys_exchanged.keys_central.p_id_key = &m_local_id_info; + keys_exchanged.keys_periph.p_enc_key = &m_bond_table[index_count].peer_enc_key; + keys_exchanged.keys_periph.p_id_key = + &m_peer_table[dm_handle.device_id].peer_id; + + //Context information updated to provide the keys. + context_data.p_data = (uint8_t *)&keys_exchanged; + context_data.len = sizeof(ble_gap_sec_keyset_t); + } + else + { + index_count = ((uint32_t)(p_data - (uint8_t *)m_gatts_table)) / + GATTS_SERVICE_CONTEXT_SIZE; + + if (index_count < DEVICE_MANAGER_MAX_CONNECTIONS) + { + DM_LOG("[DM]:[0x%02X]:[0x%02X]: Service context Event\r\n", + dm_handle.device_id, + dm_handle.connection_id); + + //Notify application. + dm_event.event_id = DM_EVT_SERVICE_CONTEXT_BASE; + dm_handle.connection_id = index_count; + dm_handle.service_id = DM_PROTOCOL_CNTXT_GATT_SRVR_ID; + + //Reset the service context now that it was successfully written to the + //application and the link is disconnected. + if ((m_connection_table[index_count].state & STATE_CONNECTED) != + STATE_CONNECTED) + { + DM_LOG("[DM]:[0x%02X]:[0x%02X]: Resetting bond information for " + "active instance.\r\n", + dm_handle.device_id, + dm_handle.connection_id); + + memset(&m_gatts_table[dm_handle.connection_id], + 0, + sizeof(dm_gatts_context_t)); + } + } + else + { + DM_LOG("[DM]:[0x%02X]:[0x%02X]: App context Event\r\n", + dm_handle.device_id, + dm_handle.connection_id); + + app_notify = false; + dm_event.event_id = DM_EVT_APP_CONTEXT_BASE; +#if (DEVICE_MANAGER_APP_CONTEXT_SIZE != 0) + + if (p_data == (uint8_t *)(&m_context_init_len)) + { + //Context data is deleted. + //This is a workaround to get the right event as on delete operation + //update operation is used instead of clear. + op_code = PSTORAGE_CLEAR_OP_CODE; + app_notify = true; + } + else if (m_app_context_table[dm_handle.device_id] == p_data) + { + app_notify = true; + dm_event.event_param.p_app_context = &context_data; + + //Verify if the device is connected, if yes set connection instance. + for (uint32_t index = 0; + index < DEVICE_MANAGER_MAX_CONNECTIONS; + index++) + { + if (dm_handle.device_id == m_connection_table[index].bonded_dev_id) + { + dm_handle.connection_id = index; + break; + } + } + } + else + { + //No implementation needed. + } +#endif //DEVICE_MANAGER_APP_CONTEXT_SIZE + } + } + } + } + + if (app_notify == true) + { + if (op_code == PSTORAGE_CLEAR_OP_CODE) + { + dm_event.event_id |= DM_CLEAR_OPERATION_ID; + } + else if (op_code == PSTORAGE_LOAD_OP_CODE) + { + dm_event.event_id |= DM_LOAD_OPERATION_ID; + } + else + { + dm_event.event_id |= DM_STORE_OPERATION_ID; + } + + dm_event.event_param.p_app_context = &context_data; + app_evt_notify(&dm_handle, &dm_event, result); + } + } + + DM_MUTEX_UNLOCK(); +} + + +ret_code_t dm_init(dm_init_param_t const * const p_init_param) +{ + pstorage_module_param_t param; + pstorage_handle_t block_handle; + ret_code_t err_code; + uint32_t index; + + DM_LOG("[DM]: >> dm_init.\r\n"); + + NULL_PARAM_CHECK(p_init_param); + + SDK_MUTEX_INIT(m_dm_mutex); + + DM_MUTEX_LOCK(); + + for (index = 0; index < DEVICE_MANAGER_MAX_APPLICATIONS; index++) + { + application_instance_init(index); + } + + for (index = 0; index < DEVICE_MANAGER_MAX_CONNECTIONS; index++) + { + connection_instance_init(index); + } + + memset(m_gatts_table, 0, sizeof(m_gatts_table)); + + //Initialization of all device instances. + for (index = 0; index < DEVICE_MANAGER_MAX_BONDS; index++) + { + peer_instance_init(index); + m_irk_index_table[index] = DM_INVALID_ID; + } + + //All context with respect to a particular device is stored contiguously. + param.block_size = ALL_CONTEXT_SIZE; + param.block_count = DEVICE_MANAGER_MAX_BONDS; + param.cb = dm_pstorage_cb_handler; + + err_code = pstorage_register(¶m, &m_storage_handle); + + if (err_code == NRF_SUCCESS) + { + m_module_initialized = true; + + if (p_init_param->clear_persistent_data == false) + { + DM_LOG("[DM]: Storage handle 0x%08X.\r\n", m_storage_handle.block_id); + + //Copy bonded peer device address and IRK to RAM table. + + //Bonded devices are stored in range (0,DEVICE_MANAGER_MAX_BONDS-1). The remaining + //range is for active connections that may or may not be bonded. + for (index = 0; index < DEVICE_MANAGER_MAX_BONDS; index++) + { + err_code = pstorage_block_identifier_get(&m_storage_handle, index, &block_handle); + + //Issue read request if you successfully get the block identifier. + if (err_code == NRF_SUCCESS) + { + DM_TRC("[DM]:[0x%02X]: Block handle 0x%08X.\r\n", index, block_handle.block_id); + + err_code = pstorage_load((uint8_t *)&m_peer_table[index], + &block_handle, + sizeof(peer_id_t), + 0); + + if (err_code != NRF_SUCCESS) + { + // In case a peer device could not be loaded successfully, rest of the + // initialization procedure are skipped and an error is sent to the + // application. + DM_ERR( + "[DM]: Failed to load peer device %08X from storage, reason %08X.\r\n", + index, + err_code); + + m_module_initialized = false; + break; + } + else + { + DM_TRC("[DM]:[DI 0x%02X]: Device type 0x%02X.\r\n", + index, + m_peer_table[index].peer_id.id_addr_info.addr_type); + DM_TRC("[DM]: Device Addr 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X.\r\n", + m_peer_table[index].peer_id.id_addr_info.addr[0], + m_peer_table[index].peer_id.id_addr_info.addr[1], + m_peer_table[index].peer_id.id_addr_info.addr[2], + m_peer_table[index].peer_id.id_addr_info.addr[3], + m_peer_table[index].peer_id.id_addr_info.addr[4], + m_peer_table[index].peer_id.id_addr_info.addr[5]); + } + } + else + { + //In case a peer device could not be loaded successfully, rest of the + //initialization procedure are skipped and an error is sent to the application. + DM_LOG("[DM]: Failed to get block handle for instance %08X, reason %08X.\r\n", + index, + err_code); + + m_module_initialized = false; + break; + } + } + } + else + { + err_code = pstorage_clear(&m_storage_handle, (param.block_size * param.block_count)); + DM_ERR("[DM]: Successfully requested clear of persistent data.\r\n"); + } + } + else + { + DM_ERR("[DM]: Failed to register with storage module, reason 0x%08X.\r\n", err_code); + } + + DM_MUTEX_UNLOCK(); + + DM_TRC("[DM]: << dm_init.\r\n"); + + return err_code; +} + + +ret_code_t dm_register(dm_application_instance_t * p_appl_instance, + dm_application_param_t const * p_appl_param) +{ + VERIFY_MODULE_INITIALIZED(); + NULL_PARAM_CHECK(p_appl_instance); + NULL_PARAM_CHECK(p_appl_param); + NULL_PARAM_CHECK(p_appl_param->evt_handler); + + DM_MUTEX_LOCK(); + + DM_LOG("[DM]: >> dm_register.\r\n"); + + uint32_t err_code; + + //Verify if an application instance is available. Currently only one instance is supported. + if (m_application_table[0].ntf_cb == NULL) + { + DM_LOG("[DM]: Application Instance allocated.\r\n"); + + //Mark instance as allocated. + m_application_table[0].ntf_cb = p_appl_param->evt_handler; + m_application_table[0].sec_param = p_appl_param->sec_param; + m_application_table[0].service = p_appl_param->service_type; + + m_application_table[0].sec_param.kdist_central.enc = 0; + m_application_table[0].sec_param.kdist_central.id = 1; + m_application_table[0].sec_param.kdist_central.sign = 0; + m_application_table[0].sec_param.kdist_periph.enc = 1; + m_application_table[0].sec_param.kdist_periph.id = 1; + m_application_table[0].sec_param.kdist_periph.sign = 0; + //Populate application's instance variable with the assigned allocation instance. + *p_appl_instance = 0; + err_code = NRF_SUCCESS; + } + else + { + err_code = (NRF_ERROR_NO_MEM | DEVICE_MANAGER_ERR_BASE); + } + + DM_MUTEX_UNLOCK(); + + DM_TRC("[DM]: << dm_register.\r\n"); + + return err_code; +} + + +ret_code_t dm_security_setup_req(dm_handle_t * p_handle) +{ + VERIFY_MODULE_INITIALIZED(); + NULL_PARAM_CHECK(p_handle); + VERIFY_APP_REGISTERED(p_handle->appl_id); + VERIFY_CONNECTION_INSTANCE(p_handle->connection_id); + + DM_MUTEX_LOCK(); + + DM_LOG("[DM]: >> dm_security_setup_req\r\n"); + + uint32_t err_code = (NRF_ERROR_INVALID_STATE | DEVICE_MANAGER_ERR_BASE); + + if ((m_connection_table[p_handle->connection_id].state & STATE_CONNECTED) == STATE_CONNECTED) + { + err_code = sd_ble_gap_authenticate(m_connection_table[p_handle->connection_id].conn_handle, + &m_application_table[0].sec_param); + } + + DM_TRC("[DM]: << dm_security_setup_req, 0x%08X\r\n", err_code); + + DM_MUTEX_UNLOCK(); + + return err_code; +} + + +ret_code_t dm_security_status_req(dm_handle_t const * p_handle, + dm_security_status_t * p_status) +{ + VERIFY_MODULE_INITIALIZED(); + NULL_PARAM_CHECK(p_handle); + NULL_PARAM_CHECK(p_status); + VERIFY_APP_REGISTERED(p_handle->appl_id); + VERIFY_CONNECTION_INSTANCE(p_handle->connection_id); + + DM_MUTEX_LOCK(); + + DM_LOG("[DM]: >> dm_security_status_req\r\n"); + + if ((m_connection_table[p_handle->connection_id].state & STATE_PAIRING) || + (m_connection_table[p_handle->connection_id].state & STATE_PAIRING_PENDING)) + { + (*p_status) = ENCRYPTION_IN_PROGRESS; + } + else if (m_connection_table[p_handle->connection_id].state & STATE_LINK_ENCRYPTED) + { + (*p_status) = ENCRYPTED; + } + else + { + (*p_status) = NOT_ENCRYPTED; + } + + DM_TRC("[DM]: << dm_security_status_req\r\n"); + + DM_MUTEX_UNLOCK(); + + return NRF_SUCCESS; +} + + +ret_code_t dm_whitelist_create(dm_application_instance_t const * p_handle, + ble_gap_whitelist_t * p_whitelist) +{ + VERIFY_MODULE_INITIALIZED(); + NULL_PARAM_CHECK(p_handle); + NULL_PARAM_CHECK(p_whitelist); + NULL_PARAM_CHECK(p_whitelist->pp_addrs); + NULL_PARAM_CHECK(p_whitelist->pp_irks); + VERIFY_APP_REGISTERED(*p_handle); + + DM_MUTEX_LOCK(); + + DM_LOG("[DM]: >> dm_whitelist_create\r\n"); + + uint32_t addr_count = 0; + uint32_t irk_count = 0; + bool connected = false; + + for (uint32_t index = 0; index < DEVICE_MANAGER_MAX_BONDS; index++) + { + connected = false; + + for (uint32_t c_index = 0; c_index < DEVICE_MANAGER_MAX_CONNECTIONS; c_index++) + { + if ((index == m_connection_table[c_index].bonded_dev_id) && + ((m_connection_table[c_index].state & STATE_CONNECTED) == STATE_CONNECTED)) + { + connected = true; + break; + } + } + + if (connected == false) + { + if ((irk_count < p_whitelist->irk_count) && + ((m_peer_table[index].id_bitmap & IRK_ENTRY) == 0)) + { + p_whitelist->pp_irks[irk_count] = &m_peer_table[index].peer_id.id_info; + m_irk_index_table[irk_count] = index; + irk_count++; + } + + if ((addr_count < p_whitelist->addr_count) && + (m_peer_table[index].id_bitmap & ADDR_ENTRY) == 0) + { + p_whitelist->pp_addrs[addr_count] = &m_peer_table[index].peer_id.id_addr_info; + addr_count++; + } + } + } + + p_whitelist->addr_count = addr_count; + p_whitelist->irk_count = irk_count; + + DM_LOG("[DM]: Created whitelist, number of IRK = 0x%02X, number of addr = 0x%02X\r\n", + irk_count, + addr_count); + + DM_TRC("[DM]: << dm_whitelist_create\r\n"); + + DM_MUTEX_UNLOCK(); + + return NRF_SUCCESS; +} + + +ret_code_t dm_device_add(dm_handle_t * p_handle, + dm_device_context_t const * p_context) +{ + return (API_NOT_IMPLEMENTED | DEVICE_MANAGER_ERR_BASE); +} + + +ret_code_t dm_device_delete(dm_handle_t const * p_handle) +{ + VERIFY_MODULE_INITIALIZED(); + NULL_PARAM_CHECK(p_handle); + VERIFY_APP_REGISTERED(p_handle->appl_id); + VERIFY_DEVICE_INSTANCE(p_handle->device_id); + + DM_MUTEX_LOCK(); + + DM_TRC("[DM]: >> dm_device_delete\r\n"); + + uint32_t err_code = device_instance_free(p_handle->device_id); + + DM_TRC("[DM]: << dm_device_delete\r\n"); + + DM_MUTEX_UNLOCK(); + + return err_code; +} + + +ret_code_t dm_device_delete_all(dm_application_instance_t const * p_handle) +{ + VERIFY_MODULE_INITIALIZED(); + NULL_PARAM_CHECK(p_handle); + VERIFY_APP_REGISTERED((*p_handle)); + + DM_MUTEX_LOCK(); + + uint32_t err_code = NRF_SUCCESS; + + DM_TRC("[DM]: >> dm_device_delete_all\r\n"); + + for (uint32_t index = 0; index < DEVICE_MANAGER_MAX_BONDS; index++) + { + if (m_peer_table[index].id_bitmap != UNASSIGNED) + { + err_code = device_instance_free(index); + } + } + + DM_TRC("[DM]: << dm_device_delete_all\r\n"); + + DM_MUTEX_UNLOCK(); + + return err_code; +} + + +ret_code_t dm_service_context_set(dm_handle_t const * p_handle, + dm_service_context_t const * p_context) +{ + VERIFY_MODULE_INITIALIZED(); + NULL_PARAM_CHECK(p_handle); + NULL_PARAM_CHECK(p_context); + VERIFY_APP_REGISTERED(p_handle->appl_id); + VERIFY_CONNECTION_INSTANCE(p_handle->connection_id); + VERIFY_DEVICE_INSTANCE(p_handle->device_id); + + DM_MUTEX_LOCK(); + + DM_TRC("[DM]: >> dm_service_context_set\r\n"); + + if ((p_context->context_data.p_data != NULL) && + ( + (p_context->context_data.len != 0) && + (p_context->context_data.len < DM_GATT_SERVER_ATTR_MAX_SIZE) + ) + ) + { + if (p_context->service_type == DM_PROTOCOL_CNTXT_GATT_SRVR_ID) + { + memcpy(m_gatts_table[p_handle->connection_id].attributes, + p_context->context_data.p_data, + p_context->context_data.len); + } + } + + pstorage_handle_t block_handle; + uint32_t err_code = pstorage_block_identifier_get(&m_storage_handle, + p_handle->device_id, + &block_handle); + + err_code = m_service_context_store[p_context->service_type](&block_handle, p_handle); + + DM_TRC("[DM]: << dm_service_context_set\r\n"); + + DM_MUTEX_UNLOCK(); + + return err_code; +} + + +ret_code_t dm_service_context_get(dm_handle_t const * p_handle, + dm_service_context_t * p_context) +{ + VERIFY_MODULE_INITIALIZED(); + NULL_PARAM_CHECK(p_handle); + NULL_PARAM_CHECK(p_context); + VERIFY_APP_REGISTERED(p_handle->appl_id); + VERIFY_DEVICE_INSTANCE(p_handle->device_id); + + if ((m_connection_table[p_handle->connection_id].state & STATE_CONNECTED) != STATE_CONNECTED) + { + DM_TRC("[DM]: Device must be connected to get context. \r\n"); + + return (FEATURE_NOT_ENABLED | DEVICE_MANAGER_ERR_BASE); + } + + DM_MUTEX_LOCK(); + + DM_TRC("[DM]: >> dm_service_context_get\r\n"); + + if ((p_context->context_data.p_data == NULL) && + (p_context->context_data.len < DM_GATT_SERVER_ATTR_MAX_SIZE)) + { + if (p_context->service_type == DM_PROTOCOL_CNTXT_GATT_SRVR_ID) + { + p_context->context_data.p_data = m_gatts_table[p_handle->connection_id].attributes; + p_context->context_data.len = m_gatts_table[p_handle->connection_id].size; + } + } + + pstorage_handle_t block_handle; + uint32_t err_code = pstorage_block_identifier_get(&m_storage_handle, + p_handle->device_id, + &block_handle); + + err_code = m_service_context_load[p_context->service_type](&block_handle, p_handle); + + DM_TRC("[DM]: << dm_service_context_get\r\n"); + + DM_MUTEX_UNLOCK(); + + return err_code; +} + + +ret_code_t dm_service_context_delete(dm_handle_t const * p_handle) +{ + VERIFY_MODULE_INITIALIZED(); + NULL_PARAM_CHECK(p_handle); + VERIFY_APP_REGISTERED(p_handle->appl_id); + VERIFY_DEVICE_INSTANCE(p_handle->device_id); + + DM_LOG("[DM]: Context delete is not supported yet.\r\n"); + + return (API_NOT_IMPLEMENTED | DEVICE_MANAGER_ERR_BASE); +} + + +ret_code_t dm_application_context_set(dm_handle_t const * p_handle, + dm_application_context_t const * p_context) +{ +#if (DEVICE_MANAGER_APP_CONTEXT_SIZE != 0) + VERIFY_MODULE_INITIALIZED(); + NULL_PARAM_CHECK(p_handle); + NULL_PARAM_CHECK(p_context); + NULL_PARAM_CHECK(p_context->p_data); + VERIFY_APP_REGISTERED(p_handle->appl_id); + VERIFY_DEVICE_INSTANCE(p_handle->device_id); + VERIFY_DEVICE_BOND(p_handle->connection_id); + SIZE_CHECK_APP_CONTEXT(p_context->len); + + DM_MUTEX_LOCK(); + + DM_TRC("[DM]: >> dm_application_context_set\r\n"); + + uint32_t err_code; + uint32_t context_len; + pstorage_handle_t block_handle; + + storage_operation store_fn = pstorage_store; + + err_code = pstorage_block_identifier_get(&m_storage_handle, + p_handle->device_id, + &block_handle); + + if (err_code == NRF_SUCCESS) + { + err_code = pstorage_load((uint8_t *)&context_len, + &block_handle, + sizeof(uint32_t), + APP_CONTEXT_STORAGE_OFFSET); + + if ((err_code == NRF_SUCCESS) && (context_len != INVALID_CONTEXT_LEN)) + { + //Data already exists. Need an update. + store_fn = pstorage_update; + + DM_LOG("[DM]:[DI 0x%02X]: Updating existing application context, existing len 0x%08X, " + "new length 0x%08X.\r\n", + p_handle->device_id, + context_len, + p_context->len); + } + else + { + DM_LOG("[DM]: Storing application context.\r\n"); + } + + //Store/update context length. + err_code = store_fn(&block_handle, + (uint8_t *)(&p_context->len), + sizeof(uint32_t), + APP_CONTEXT_STORAGE_OFFSET); + + if (err_code == NRF_SUCCESS) + { + //Update context data is used for application context as flash is never + //cleared if a delete of application context is called. + err_code = pstorage_update(&block_handle, + p_context->p_data, + DEVICE_MANAGER_APP_CONTEXT_SIZE, + (APP_CONTEXT_STORAGE_OFFSET + sizeof(uint32_t))); + if (err_code == NRF_SUCCESS) + { + m_app_context_table[p_handle->device_id] = p_context->p_data; + } + } + } + + DM_TRC("[DM]: << dm_application_context_set\r\n"); + + DM_MUTEX_UNLOCK(); + + return err_code; + +#else //DEVICE_MANAGER_APP_CONTEXT_SIZE + return (FEATURE_NOT_ENABLED | DEVICE_MANAGER_ERR_BASE); +#endif //DEVICE_MANAGER_APP_CONTEXT_SIZE +} + + +ret_code_t dm_application_context_get(dm_handle_t const * p_handle, + dm_application_context_t * p_context) +{ +#if (DEVICE_MANAGER_APP_CONTEXT_SIZE != 0) + VERIFY_MODULE_INITIALIZED(); + NULL_PARAM_CHECK(p_handle); + NULL_PARAM_CHECK(p_context); + VERIFY_APP_REGISTERED(p_handle->appl_id); + VERIFY_DEVICE_INSTANCE(p_handle->device_id); + + DM_MUTEX_LOCK(); + + DM_TRC("[DM]: >> dm_application_context_get\r\n"); + + uint32_t context_len; + uint32_t err_code; + pstorage_handle_t block_handle; + + //Check if the context exists. + if (NULL == p_context->p_data) + { + p_context->p_data = m_app_context_table[p_handle->device_id]; + } + else + { + m_app_context_table[p_handle->device_id] = p_context->p_data; + } + + err_code = pstorage_block_identifier_get(&m_storage_handle, + p_handle->device_id, + &block_handle); + + if (err_code == NRF_SUCCESS) + { + err_code = pstorage_load((uint8_t *)&context_len, + &block_handle, + sizeof(uint32_t), + APP_CONTEXT_STORAGE_OFFSET); + + if ((err_code == NRF_SUCCESS) && (context_len != INVALID_CONTEXT_LEN)) + { + err_code = pstorage_load(p_context->p_data, + &block_handle, + DEVICE_MANAGER_APP_CONTEXT_SIZE, + (APP_CONTEXT_STORAGE_OFFSET + sizeof(uint32_t))); + if (err_code == NRF_SUCCESS) + { + p_context->len = context_len; + } + } + else + { + err_code = DM_NO_APP_CONTEXT; + } + } + + DM_TRC("[DM]: << dm_application_context_get\r\n"); + + DM_MUTEX_UNLOCK(); + + return err_code; + +#else //DEVICE_MANAGER_APP_CONTEXT_SIZE + return (FEATURE_NOT_ENABLED | DEVICE_MANAGER_ERR_BASE); +#endif //DEVICE_MANAGER_APP_CONTEXT_SIZE +} + + +ret_code_t dm_application_context_delete(const dm_handle_t * p_handle) +{ +#if (DEVICE_MANAGER_APP_CONTEXT_SIZE != 0) + VERIFY_MODULE_INITIALIZED(); + NULL_PARAM_CHECK(p_handle); + VERIFY_APP_REGISTERED(p_handle->appl_id); + VERIFY_DEVICE_INSTANCE(p_handle->device_id); + + DM_MUTEX_LOCK(); + + DM_TRC("[DM]: >> dm_application_context_delete\r\n"); + + uint32_t err_code; + uint32_t context_len; + pstorage_handle_t block_handle; + + err_code = pstorage_block_identifier_get(&m_storage_handle, + p_handle->device_id, + &block_handle); + + if (err_code == NRF_SUCCESS) + { + err_code = pstorage_load((uint8_t *)&context_len, + &block_handle, + sizeof(uint32_t), + APP_CONTEXT_STORAGE_OFFSET); + + if (context_len != m_context_init_len) + { + err_code = pstorage_update(&block_handle, + (uint8_t *)&m_context_init_len, + sizeof(uint32_t), + APP_CONTEXT_STORAGE_OFFSET); + + if (err_code != NRF_SUCCESS) + { + DM_ERR("[DM]: Failed to delete application context, reason 0x%08X\r\n", err_code); + } + else + { + m_app_context_table[p_handle->device_id] = NULL; + } + } + } + + DM_TRC("[DM]: << dm_application_context_delete\r\n"); + + DM_MUTEX_UNLOCK(); + + return err_code; +#else //DEVICE_MANAGER_APP_CONTEXT_SIZE + return (FEATURE_NOT_ENABLED | DEVICE_MANAGER_ERR_BASE); +#endif //DEVICE_MANAGER_APP_CONTEXT_SIZE +} + + +ret_code_t dm_application_instance_set(dm_application_instance_t const * p_appl_instance, + dm_handle_t * p_handle) +{ + VERIFY_MODULE_INITIALIZED(); + NULL_PARAM_CHECK(p_handle); + NULL_PARAM_CHECK(p_appl_instance); + VERIFY_APP_REGISTERED((*p_appl_instance)); + + p_handle->appl_id = (*p_appl_instance); + + return NRF_SUCCESS; +} + + +uint32_t dm_handle_initialize(dm_handle_t * p_handle) +{ + NULL_PARAM_CHECK(p_handle); + + p_handle->appl_id = DM_INVALID_ID; + p_handle->connection_id = DM_INVALID_ID; + p_handle->device_id = DM_INVALID_ID; + p_handle->service_id = DM_INVALID_ID; + + return NRF_SUCCESS; +} + + +ret_code_t dm_peer_addr_set(dm_handle_t const * p_handle, + ble_gap_addr_t const * p_addr) +{ + VERIFY_MODULE_INITIALIZED(); + NULL_PARAM_CHECK(p_handle); + NULL_PARAM_CHECK(p_addr); + VERIFY_APP_REGISTERED(p_handle->appl_id); + VERIFY_DEVICE_INSTANCE(p_handle->device_id); + + DM_MUTEX_LOCK(); + + DM_TRC("[DM]: >> dm_peer_addr_set\r\n"); + + ret_code_t err_code; + + if ((p_handle->connection_id == DM_INVALID_ID) && + (p_addr->addr_type != BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE)) + { + m_peer_table[p_handle->device_id].peer_id.id_addr_info = (*p_addr); + update_status_bit_set(p_handle->device_id); + device_context_store(p_handle, UPDATE_PEER_ADDR); + err_code = NRF_SUCCESS; + } + else + { + err_code = (NRF_ERROR_INVALID_PARAM | DEVICE_MANAGER_ERR_BASE); + } + + DM_TRC("[DM]: << dm_peer_addr_set\r\n"); + + DM_MUTEX_UNLOCK(); + + return err_code; +} + + +ret_code_t dm_peer_addr_get(dm_handle_t const * p_handle, + ble_gap_addr_t * p_addr) +{ + VERIFY_MODULE_INITIALIZED(); + NULL_PARAM_CHECK(p_handle); + NULL_PARAM_CHECK(p_addr); + VERIFY_APP_REGISTERED(p_handle->appl_id); + + DM_MUTEX_LOCK(); + + DM_TRC("[DM]: >> dm_peer_addr_get\r\n"); + + ret_code_t err_code; + + err_code = (NRF_ERROR_NOT_FOUND | DEVICE_MANAGER_ERR_BASE); + + if (p_handle->device_id == DM_INVALID_ID) + { + if ((p_handle->connection_id != DM_INVALID_ID) && + ((m_connection_table[p_handle->connection_id].state & STATE_CONNECTED) == + STATE_CONNECTED)) + { + DM_TRC("[DM]:[CI 0x%02X]: Address get for non bonded active connection.\r\n", + p_handle->connection_id); + + (*p_addr) = m_connection_table[p_handle->connection_id].peer_addr; + err_code = NRF_SUCCESS; + } + } + else + { + if ((m_peer_table[p_handle->device_id].id_bitmap & ADDR_ENTRY) == 0) + { + DM_TRC("[DM]:[DI 0x%02X]: Address get for bonded device.\r\n", + p_handle->device_id); + + (*p_addr) = m_peer_table[p_handle->device_id].peer_id.id_addr_info; + err_code = NRF_SUCCESS; + } + } + + DM_TRC("[DM]: << dm_peer_addr_get\r\n"); + + DM_MUTEX_UNLOCK(); + + return err_code; +} + + +ret_code_t dm_distributed_keys_get(dm_handle_t const * p_handle, + dm_sec_keyset_t * p_key_dist) +{ + VERIFY_MODULE_INITIALIZED(); + NULL_PARAM_CHECK(p_handle); + NULL_PARAM_CHECK(p_key_dist); + VERIFY_APP_REGISTERED(p_handle->appl_id); + VERIFY_DEVICE_INSTANCE(p_handle->device_id); + + DM_MUTEX_LOCK(); + + DM_TRC("[DM]: >> dm_distributed_keys_get\r\n"); + + ret_code_t err_code; + ble_gap_enc_key_t peer_enc_key; + pstorage_handle_t block_handle; + + err_code = NRF_ERROR_NOT_FOUND; + p_key_dist->keys_central.enc_key.p_enc_key = NULL; + p_key_dist->keys_central.p_id_key = (dm_id_key_t *)&m_peer_table[p_handle->device_id].peer_id; + p_key_dist->keys_central.p_sign_key = NULL; + p_key_dist->keys_periph.p_id_key = (dm_id_key_t *)&m_local_id_info; + p_key_dist->keys_periph.p_sign_key = NULL; + p_key_dist->keys_periph.enc_key.p_enc_key = (dm_enc_key_t *)&peer_enc_key; + + if ((m_peer_table[p_handle->device_id].id_bitmap & IRK_ENTRY) == 0) + { +// p_key_dist->keys_periph.p_id_key->id_addr_info.addr_type = INVALID_ADDR_TYPE; + } + + err_code = pstorage_block_identifier_get(&m_storage_handle, p_handle->device_id, &block_handle); + if (err_code == NRF_SUCCESS) + { + + err_code = pstorage_load((uint8_t *)&peer_enc_key, + &block_handle, + BOND_SIZE, + BOND_STORAGE_OFFSET); + + if (err_code == NRF_SUCCESS) + { + p_key_dist->keys_central.enc_key.p_enc_key = NULL; + p_key_dist->keys_central.p_id_key = (dm_id_key_t *)&m_peer_table[p_handle->device_id].peer_id; + p_key_dist->keys_central.p_sign_key = NULL; + p_key_dist->keys_periph.p_id_key = (dm_id_key_t *)&m_local_id_info; + p_key_dist->keys_periph.p_sign_key = NULL; + p_key_dist->keys_periph.enc_key.p_enc_key = (dm_enc_key_t *)&peer_enc_key; + } + } + + DM_TRC("[DM]: << dm_distributed_keys_get\r\n"); + + DM_MUTEX_UNLOCK(); + + return err_code; +} + + +/**@brief Function for loading bond information for a connection instance. + */ +void bond_data_load(dm_handle_t * p_handle) +{ + pstorage_handle_t block_handle; + + uint32_t err_code = pstorage_block_identifier_get(&m_storage_handle, + p_handle->device_id, + &block_handle); + if (err_code == NRF_SUCCESS) + { + DM_LOG( + "[DM]:[%02X]:[Block ID 0x%08X]:Loading bond information at %p, size 0x%08X, offset 0x%08X.\r\n", + p_handle->connection_id, + block_handle.block_id, + &m_bond_table[p_handle->connection_id], + BOND_SIZE, + BOND_STORAGE_OFFSET); + + err_code = pstorage_load((uint8_t *)&m_bond_table[p_handle->connection_id], + &block_handle, + BOND_SIZE, + BOND_STORAGE_OFFSET); + + if (err_code != NRF_SUCCESS) + { + DM_ERR("[DM]:[%02X]: Failed to load Bond information, reason %08X\r\n", + p_handle->connection_id, + err_code); + } + + DM_LOG( + "[DM]:[%02X]:Loading service context at %p, size 0x%08X, offset 0x%08X.\r\n", + p_handle->connection_id, + &m_gatts_table[p_handle->connection_id], + sizeof(dm_gatts_context_t), + SERVICE_STORAGE_OFFSET); + + err_code = m_service_context_load[m_application_table[0].service]( + &block_handle, + p_handle); + + if (err_code != NRF_SUCCESS) + { + DM_ERR( + "[DM]:[%02X]: Failed to load service information, reason %08X\r\n", + p_handle->connection_id, + err_code); + } + } + else + { + DM_ERR("[DM]:[%02X]: Failed to get block identifier for " + "device %08X, reason %08X.\r\n", p_handle->connection_id, p_handle->device_id, err_code); + } +} + + +void dm_ble_evt_handler(ble_evt_t * p_ble_evt) +{ + uint32_t err_code; + uint32_t index; + uint32_t device_index = DM_INVALID_ID; + bool notify_app = false; + dm_handle_t handle; + dm_event_t event; + uint32_t event_result; + ble_gap_enc_info_t * p_enc_info = NULL; + + VERIFY_MODULE_INITIALIZED_VOID(); + VERIFY_APP_REGISTERED_VOID(0); + DM_MUTEX_LOCK(); + + err_code = dm_handle_initialize(&handle); + APP_ERROR_CHECK(err_code); + + event_result = NRF_SUCCESS; + err_code = NRF_SUCCESS; + event.event_param.p_gap_param = &p_ble_evt->evt.gap_evt; + event.event_paramlen = sizeof(ble_gap_evt_t); + handle.device_id = DM_INVALID_ID; + handle.appl_id = 0; + index = 0x00; + + if (p_ble_evt->header.evt_id != BLE_GAP_EVT_CONNECTED) + { + err_code = connection_instance_find(p_ble_evt->evt.gap_evt.conn_handle, + STATE_CONNECTED, + &index); + + if (err_code == NRF_SUCCESS) + { + handle.device_id = m_connection_table[index].bonded_dev_id; + handle.connection_id = index; + } + } + + switch (p_ble_evt->header.evt_id) + { + case BLE_GAP_EVT_CONNECTED: + //Allocate connection instance for a new connection. + err_code = connection_instance_allocate(&index); + + //Connection instance is successfully allocated. + if (err_code == NRF_SUCCESS) + { + //Application notification related information. + notify_app = true; + event.event_id = DM_EVT_CONNECTION; + handle.connection_id = index; + + m_connection_table[index].conn_handle = p_ble_evt->evt.gap_evt.conn_handle; + m_connection_table[index].state = STATE_CONNECTED; + m_connection_table[index].peer_addr = + p_ble_evt->evt.gap_evt.params.connected.peer_addr; + + if (p_ble_evt->evt.gap_evt.params.connected.irk_match == 1) + { + if (m_irk_index_table[p_ble_evt->evt.gap_evt.params.connected.irk_match_idx] != DM_INVALID_ID) + { + device_index = m_irk_index_table[p_ble_evt->evt.gap_evt.params.connected.irk_match_idx]; + err_code = NRF_SUCCESS; + } + } + else + { + //Use the device address to check if the device exists in the bonded device list. + err_code = device_instance_find(&p_ble_evt->evt.gap_evt.params.connected.peer_addr, + &device_index, EDIV_INIT_VAL); + } + + if (err_code == NRF_SUCCESS) + { + m_connection_table[index].bonded_dev_id = device_index; + m_connection_table[index].state |= STATE_BONDED; + handle.device_id = device_index; + + bond_data_load(&handle); + } + } + break; + + case BLE_GAP_EVT_DISCONNECTED: + //Disconnection could be peer or self initiated hence disconnecting and connecting + //both states are permitted, however, connection handle must be known. + DM_LOG("[DM]: Disconnect Reason 0x%04X\r\n", + p_ble_evt->evt.gap_evt.params.disconnected.reason); + + m_connection_table[index].state &= (~STATE_CONNECTED); + + if ((m_connection_table[index].state & STATE_BONDED) == STATE_BONDED) + { + if ((m_connection_table[index].state & STATE_LINK_ENCRYPTED) == STATE_LINK_ENCRYPTED) + { + //Write bond information persistently. + device_context_store(&handle, STORE_ALL_CONTEXT); + } + } + else + { + //Free any allocated instances for devices that is not bonded. + if (handle.device_id != DM_INVALID_ID) + { + peer_instance_init(handle.device_id); + handle.device_id = DM_INVALID_ID; + } + } + + m_connection_table[index].state = STATE_DISCONNECTING; + notify_app = true; + event.event_id = DM_EVT_DISCONNECTION; + + break; + + case BLE_GAP_EVT_SEC_INFO_REQUEST: + DM_LOG("[DM]: >> BLE_GAP_EVT_SEC_INFO_REQUEST\r\n"); + + //If the device is already bonded, respond with existing info, else NULL. + if (m_connection_table[index].bonded_dev_id == DM_INVALID_ID) + { + //Find device based on div. + err_code = device_instance_find(NULL,&device_index, p_ble_evt->evt.gap_evt.params.sec_info_request.master_id.ediv); + if (err_code == NRF_SUCCESS) + { + //Load needed bonding information. + m_connection_table[index].bonded_dev_id = device_index; + m_connection_table[index].state |= STATE_BONDED; + handle.device_id = device_index; + bond_data_load(&handle); + } + } + + if (m_connection_table[index].bonded_dev_id != DM_INVALID_ID) + { + p_enc_info = &m_bond_table[index].peer_enc_key.enc_info; + DM_DUMP((uint8_t *)p_enc_info, sizeof(ble_gap_enc_info_t)); + } + + err_code = sd_ble_gap_sec_info_reply(p_ble_evt->evt.gap_evt.conn_handle, + p_enc_info, + &m_peer_table[index].peer_id.id_info, + NULL); + + if (err_code != NRF_SUCCESS) + { + DM_ERR("[DM]:[CI %02X]:[DI %02X]: Security information response failed, reason " + "0x%08X\r\n", index, m_connection_table[index].bonded_dev_id, err_code); + } + break; + + case BLE_GAP_EVT_SEC_PARAMS_REQUEST: + DM_LOG("[DM]: >> BLE_GAP_EVT_SEC_PARAMS_REQUEST\r\n"); + + event.event_id = DM_EVT_SECURITY_SETUP; + + m_connection_table[index].state |= STATE_PAIRING; + notify_app = true; + + if (m_connection_table[index].bonded_dev_id == DM_INVALID_ID) + { + //Assign a peer index as a new bond or update existing bonds. + err_code = device_instance_allocate((uint8_t *)&device_index, + &m_connection_table[index].peer_addr); + + //Allocation successful. + if (err_code == NRF_SUCCESS) + { + DM_LOG("[DM]:[CI 0x%02X]:[DI 0x%02X]: Bonded!\r\n",index, device_index); + + handle.device_id = device_index; + m_connection_table[index].bonded_dev_id = device_index; + } + else + { + DM_LOG("[DM]: Security parameter request failed, reason 0x%08X.\r\n", err_code); + event_result = err_code; + notify_app = true; + } + } + else + { + //Bond/key refresh. + event.event_id = DM_EVT_SECURITY_SETUP_REFRESH; + memset(m_gatts_table[index].attributes, 0, DM_GATT_SERVER_ATTR_MAX_SIZE); + + //Set the update flag for bond data. + m_connection_table[index].state |= STATE_BOND_INFO_UPDATE; + } + + ble_gap_sec_keyset_t keys_exchanged; + + DM_LOG("[DM]: 0x%02X, 0x%02X, 0x%02X, 0x%02X\r\n", + p_ble_evt->evt.gap_evt.params.sec_params_request.peer_params.kdist_periph.enc, + p_ble_evt->evt.gap_evt.params.sec_params_request.peer_params.kdist_central.id, + p_ble_evt->evt.gap_evt.params.sec_params_request.peer_params.kdist_periph.sign, + p_ble_evt->evt.gap_evt.params.sec_params_request.peer_params.bond); + + keys_exchanged.keys_central.p_enc_key = NULL; + keys_exchanged.keys_central.p_id_key = &m_peer_table[m_connection_table[index].bonded_dev_id].peer_id; + keys_exchanged.keys_central.p_sign_key = NULL; + keys_exchanged.keys_periph.p_enc_key = &m_bond_table[index].peer_enc_key; + keys_exchanged.keys_periph.p_id_key = NULL; + keys_exchanged.keys_periph.p_sign_key = NULL; + + err_code = sd_ble_gap_sec_params_reply(p_ble_evt->evt.gap_evt.conn_handle, + BLE_GAP_SEC_STATUS_SUCCESS, + &m_application_table[0].sec_param, + &keys_exchanged); + + if (err_code != NRF_SUCCESS) + { + DM_LOG("[DM]: Security parameter reply request failed, reason 0x%08X.\r\n", err_code); + event_result = err_code; + notify_app = false; + } + break; + + case BLE_GAP_EVT_AUTH_STATUS: + { + DM_LOG("[DM]: >> BLE_GAP_EVT_AUTH_STATUS, status %08X\r\n", + p_ble_evt->evt.gap_evt.params.auth_status.auth_status); + + m_application_table[0].state &= (~STATE_CONTROL_PROCEDURE_IN_PROGRESS); + m_connection_table[index].state &= (~STATE_PAIRING); + event.event_id = DM_EVT_SECURITY_SETUP_COMPLETE; + notify_app = true; + + if (p_ble_evt->evt.gap_evt.params.auth_status.auth_status != BLE_GAP_SEC_STATUS_SUCCESS) + { + // Free the allocation as bonding failed. + ret_code_t result = device_instance_free(m_connection_table[index].bonded_dev_id); + (void) result; + event_result = p_ble_evt->evt.gap_evt.params.auth_status.auth_status; + } + else + { + DM_DUMP((uint8_t *)&p_ble_evt->evt.gap_evt.params.auth_status, + sizeof(ble_gap_evt_auth_status_t)); + DM_DUMP((uint8_t *)&m_bond_table[index], sizeof(bond_context_t)); + + if (p_ble_evt->evt.gap_evt.params.auth_status.bonded == 1) + { + if (handle.device_id != DM_INVALID_ID) + { + m_connection_table[index].state |= STATE_BONDED; + + //IRK and/or public address is shared, update it. + if (p_ble_evt->evt.gap_evt.params.auth_status.kdist_central.id == 1) + { + m_peer_table[handle.device_id].id_bitmap &= (~IRK_ENTRY); + } + + if (m_connection_table[index].bonded_dev_id != DM_INVALID_ID) + { + DM_LOG("[DM]:[CI 0x%02X]:[DI 0x%02X]: Bonded!\r\n", + index, + handle.device_id); + + if (m_connection_table[index].peer_addr.addr_type != + BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE) + { + m_peer_table[handle.device_id].peer_id.id_addr_info = + m_connection_table[index].peer_addr; + m_peer_table[handle.device_id].id_bitmap &= (~ADDR_ENTRY); + + DM_DUMP((uint8_t *)&m_peer_table[handle.device_id].peer_id.id_addr_info, + sizeof(m_peer_table[handle.device_id].peer_id.id_addr_info)); + } + else + { + // Here we must fetch the keys from the keyset distributed. + m_peer_table[handle.device_id].ediv = m_bond_table[index].peer_enc_key.master_id.ediv; + m_peer_table[handle.device_id].id_bitmap &= (~IRK_ENTRY); + } + + device_context_store(&handle, FIRST_BOND_STORE); + } + } + } + else + { + //Pairing request, no need to touch the bonding info. + } + } + break; + } + + case BLE_GAP_EVT_CONN_SEC_UPDATE: + DM_LOG("[DM]: >> BLE_GAP_EVT_CONN_SEC_UPDATE, Mode 0x%02X, Level 0x%02X\r\n", + p_ble_evt->evt.gap_evt.params.conn_sec_update.conn_sec.sec_mode.sm, + p_ble_evt->evt.gap_evt.params.conn_sec_update.conn_sec.sec_mode.lv); + + if ((p_ble_evt->evt.gap_evt.params.conn_sec_update.conn_sec.sec_mode.lv == 1) && + (p_ble_evt->evt.gap_evt.params.conn_sec_update.conn_sec.sec_mode.sm == 1) && + ((m_connection_table[index].state & STATE_BONDED) == STATE_BONDED)) + { + //Lost bond case, generate a security refresh event! + memset(m_gatts_table[index].attributes, 0, DM_GATT_SERVER_ATTR_MAX_SIZE); + + event.event_id = DM_EVT_SECURITY_SETUP_REFRESH; + m_connection_table[index].state |= STATE_PAIRING_PENDING; + m_connection_table[index].state |= STATE_BOND_INFO_UPDATE; + m_application_table[0].state |= STATE_QUEUED_CONTROL_REQUEST; + } + else + { + m_connection_table[index].state |= STATE_LINK_ENCRYPTED; + event.event_id = DM_EVT_LINK_SECURED; + + //Apply service context. + err_code = m_service_context_apply[m_application_table[0].service](&handle); + + if (err_code != NRF_SUCCESS) + { + DM_ERR("[DM]:[CI 0x%02X]:[DI 0x%02X]: Failed to apply service context\r\n", + handle.connection_id, + handle.device_id); + + event_result = DM_SERVICE_CONTEXT_NOT_APPLIED; + } + } + event_result = NRF_SUCCESS; + notify_app = true; + + break; + + case BLE_GATTS_EVT_SYS_ATTR_MISSING: + DM_LOG("[DM]: >> BLE_GATTS_EVT_SYS_ATTR_MISSING\r\n"); + + //Apply service context. + event_result = m_service_context_apply[m_application_table[0].service](&handle); + break; + + case BLE_GAP_EVT_SEC_REQUEST: + DM_LOG("[DM]: >> BLE_GAP_EVT_SEC_REQUEST\r\n"); + + //Verify if the device is already bonded, and if it is bonded, initiate encryption. + //If the device is not bonded, an instance needs to be allocated in order to initiate + //bonding. The application have to initiate the procedure, the module will not do this + //automatically. + event.event_id = DM_EVT_SECURITY_SETUP; + notify_app = true; + + break; + + default: + break; + } + + if (notify_app) + { + app_evt_notify(&handle, &event, event_result); + + //Freeing the instance after the event is notified so the application can get the context. + if (event.event_id == DM_EVT_DISCONNECTION) + { + //Free the instance. + connection_instance_free(&index); + } + } + + UNUSED_VARIABLE(err_code); + + DM_MUTEX_UNLOCK(); +} + + +ret_code_t dm_handle_get(uint16_t conn_handle, dm_handle_t * p_handle) +{ + ret_code_t err_code; + uint32_t index; + + NULL_PARAM_CHECK(p_handle); + VERIFY_APP_REGISTERED(p_handle->appl_id); + + p_handle->device_id = DM_INVALID_ID; + + err_code = NRF_ERROR_NOT_FOUND; + + for (index = 0; index < DEVICE_MANAGER_MAX_CONNECTIONS; index++) + { + //Search for matching connection handle. + if (conn_handle == m_connection_table[index].conn_handle) + { + p_handle->connection_id = index; + p_handle->device_id = m_connection_table[index].bonded_dev_id; + + err_code = NRF_SUCCESS; + break; + } + } + return err_code; +} diff --git a/source/nordic_sdk/components/device/compiler_abstraction.h b/source/nordic_sdk/components/device/compiler_abstraction.h new file mode 100644 index 0000000..545ae99 --- /dev/null +++ b/source/nordic_sdk/components/device/compiler_abstraction.h @@ -0,0 +1,126 @@ +/* Copyright (c) 2015, Nordic Semiconductor ASA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef _COMPILER_ABSTRACTION_H +#define _COMPILER_ABSTRACTION_H + +/*lint ++flb "Enter library region" */ + +#if defined ( __CC_ARM ) + + #ifndef __ASM + #define __ASM __asm + #endif + + #ifndef __INLINE + #define __INLINE __inline + #endif + + #ifndef __WEAK + #define __WEAK __weak + #endif + + #ifndef __ALIGN + #define __ALIGN(n) __align(n) + #endif + + #define GET_SP() __current_sp() + +#elif defined ( __ICCARM__ ) + + #ifndef __ASM + #define __ASM __asm + #endif + + #ifndef __INLINE + #define __INLINE inline + #endif + + #ifndef __WEAK + #define __WEAK __weak + #endif + + /* Not defined for IAR since it requires a new line to work, and C preprocessor does not allow that. */ + #ifndef __ALIGN + #define __ALIGN(n) + #endif + + #define GET_SP() __get_SP() + +#elif defined ( __GNUC__ ) + + #ifndef __ASM + #define __ASM __asm + #endif + + #ifndef __INLINE + #define __INLINE inline + #endif + + #ifndef __WEAK + #define __WEAK __attribute__((weak)) + #endif + + #ifndef __ALIGN + #define __ALIGN(n) __attribute__((aligned(n))) + #endif + + #define GET_SP() gcc_current_sp() + + static inline unsigned int gcc_current_sp(void) + { + register unsigned sp __ASM("sp"); + return sp; + } + +#elif defined ( __TASKING__ ) + + #ifndef __ASM + #define __ASM __asm + #endif + + #ifndef __INLINE + #define __INLINE inline + #endif + + #ifndef __WEAK + #define __WEAK __attribute__((weak)) + #endif + + #ifndef __ALIGN + #define __ALIGN(n) __align(n) + #endif + + #define GET_SP() __get_MSP() + +#endif + +/*lint --flb "Leave library region" */ + +#endif diff --git a/source/nordic_sdk/components/device/nrf.h b/source/nordic_sdk/components/device/nrf.h new file mode 100644 index 0000000..6f4f803 --- /dev/null +++ b/source/nordic_sdk/components/device/nrf.h @@ -0,0 +1,56 @@ +/* Copyright (c) 2015, Nordic Semiconductor ASA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef NRF_H +#define NRF_H + +#if defined(_WIN32) + /* Do not include nrf51 specific files when building for PC host */ +#elif defined(__unix) + /* Do not include nrf51 specific files when building for PC host */ +#elif defined(__APPLE__) + /* Do not include nrf51 specific files when building for PC host */ +#else + + /* Family selection for family includes. */ + #if defined (NRF51) + #include "nrf51.h" + #include "nrf51_bitfields.h" + #include "nrf51_deprecated.h" + #else + #error "Device family must be defined. See nrf.h." + #endif /* NRF51 */ + + #include "compiler_abstraction.h" + +#endif /* _WIN32 || __unix || __APPLE__ */ + +#endif /* NRF_H */ + diff --git a/source/nordic_sdk/components/drivers_nrf/hal/nrf51.h b/source/nordic_sdk/components/device/nrf51.h similarity index 94% rename from source/nordic_sdk/components/drivers_nrf/hal/nrf51.h rename to source/nordic_sdk/components/device/nrf51.h index afb61c7..46216b0 100644 --- a/source/nordic_sdk/components/drivers_nrf/hal/nrf51.h +++ b/source/nordic_sdk/components/device/nrf51.h @@ -1,1295 +1,1308 @@ -/* - * Copyright (c) Nordic Semiconductor ASA - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this - * list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of other - * contributors to this software may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -/** @addtogroup nRF51 - * @{ - */ - -#ifndef NRF51_H -#define NRF51_H - -#ifdef __cplusplus -extern "C" { -#endif - - -/* ------------------------- Interrupt Number Definition ------------------------ */ - -typedef enum { -/* ------------------- Cortex-M0 Processor Exceptions Numbers ------------------- */ - Reset_IRQn = -15, /*!< 1 Reset Vector, invoked on Power up and warm reset */ - NonMaskableInt_IRQn = -14, /*!< 2 Non maskable Interrupt, cannot be stopped or preempted */ - HardFault_IRQn = -13, /*!< 3 Hard Fault, all classes of Fault */ - SVCall_IRQn = -5, /*!< 11 System Service Call via SVC instruction */ - DebugMonitor_IRQn = -4, /*!< 12 Debug Monitor */ - PendSV_IRQn = -2, /*!< 14 Pendable request for system service */ - SysTick_IRQn = -1, /*!< 15 System Tick Timer */ -/* ---------------------- nRF51 Specific Interrupt Numbers ---------------------- */ - POWER_CLOCK_IRQn = 0, /*!< 0 POWER_CLOCK */ - RADIO_IRQn = 1, /*!< 1 RADIO */ - UART0_IRQn = 2, /*!< 2 UART0 */ - SPI0_TWI0_IRQn = 3, /*!< 3 SPI0_TWI0 */ - SPI1_TWI1_IRQn = 4, /*!< 4 SPI1_TWI1 */ - GPIOTE_IRQn = 6, /*!< 6 GPIOTE */ - ADC_IRQn = 7, /*!< 7 ADC */ - TIMER0_IRQn = 8, /*!< 8 TIMER0 */ - TIMER1_IRQn = 9, /*!< 9 TIMER1 */ - TIMER2_IRQn = 10, /*!< 10 TIMER2 */ - RTC0_IRQn = 11, /*!< 11 RTC0 */ - TEMP_IRQn = 12, /*!< 12 TEMP */ - RNG_IRQn = 13, /*!< 13 RNG */ - ECB_IRQn = 14, /*!< 14 ECB */ - CCM_AAR_IRQn = 15, /*!< 15 CCM_AAR */ - WDT_IRQn = 16, /*!< 16 WDT */ - RTC1_IRQn = 17, /*!< 17 RTC1 */ - QDEC_IRQn = 18, /*!< 18 QDEC */ - LPCOMP_IRQn = 19, /*!< 19 LPCOMP */ - SWI0_IRQn = 20, /*!< 20 SWI0 */ - SWI1_IRQn = 21, /*!< 21 SWI1 */ - SWI2_IRQn = 22, /*!< 22 SWI2 */ - SWI3_IRQn = 23, /*!< 23 SWI3 */ - SWI4_IRQn = 24, /*!< 24 SWI4 */ - SWI5_IRQn = 25 /*!< 25 SWI5 */ -} IRQn_Type; - - -/** @addtogroup Configuration_of_CMSIS - * @{ - */ - - -/* ================================================================================ */ -/* ================ Processor and Core Peripheral Section ================ */ -/* ================================================================================ */ - -/* ----------------Configuration of the Cortex-M0 Processor and Core Peripherals---------------- */ -#define __CM0_REV 0x0301 /*!< Cortex-M0 Core Revision */ -#define __MPU_PRESENT 0 /*!< MPU present or not */ -#define __NVIC_PRIO_BITS 2 /*!< Number of Bits used for Priority Levels */ -#define __Vendor_SysTickConfig 0 /*!< Set to 1 if different SysTick Config is used */ -/** @} */ /* End of group Configuration_of_CMSIS */ - -#include "core_cm0.h" /*!< Cortex-M0 processor and core peripherals */ -#include "system_nrf51.h" /*!< nRF51 System */ - - -/* ================================================================================ */ -/* ================ Device Specific Peripheral Section ================ */ -/* ================================================================================ */ - - -/** @addtogroup Device_Peripheral_Registers - * @{ - */ - - -/* ------------------- Start of section using anonymous unions ------------------ */ -#if defined(__CC_ARM) - #pragma push - #pragma anon_unions -#elif defined(__ICCARM__) - #pragma language=extended -#elif defined(__GNUC__) - /* anonymous unions are enabled by default */ -#elif defined(__TMS470__) -/* anonymous unions are enabled by default */ -#elif defined(__TASKING__) - #pragma warning 586 -#else - #warning Not supported compiler type -#endif - - -typedef struct { - __IO uint32_t CPU0; /*!< Configurable priority configuration register for CPU0. */ - __IO uint32_t SPIS1; /*!< Configurable priority configuration register for SPIS1. */ - __IO uint32_t RADIO; /*!< Configurable priority configuration register for RADIO. */ - __IO uint32_t ECB; /*!< Configurable priority configuration register for ECB. */ - __IO uint32_t CCM; /*!< Configurable priority configuration register for CCM. */ - __IO uint32_t AAR; /*!< Configurable priority configuration register for AAR. */ -} AMLI_RAMPRI_Type; - -typedef struct { - __IO uint32_t SCK; /*!< Pin select for SCK. */ - __IO uint32_t MOSI; /*!< Pin select for MOSI. */ - __IO uint32_t MISO; /*!< Pin select for MISO. */ -} SPIM_PSEL_Type; - -typedef struct { - __IO uint32_t PTR; /*!< Data pointer. */ - __IO uint32_t MAXCNT; /*!< Maximum number of buffer bytes to receive. */ - __I uint32_t AMOUNT; /*!< Number of bytes received in the last transaction. */ -} SPIM_RXD_Type; - -typedef struct { - __IO uint32_t PTR; /*!< Data pointer. */ - __IO uint32_t MAXCNT; /*!< Maximum number of buffer bytes to send. */ - __I uint32_t AMOUNT; /*!< Number of bytes sent in the last transaction. */ -} SPIM_TXD_Type; - -typedef struct { - __O uint32_t EN; /*!< Enable channel group. */ - __O uint32_t DIS; /*!< Disable channel group. */ -} PPI_TASKS_CHG_Type; - -typedef struct { - __IO uint32_t EEP; /*!< Channel event end-point. */ - __IO uint32_t TEP; /*!< Channel task end-point. */ -} PPI_CH_Type; - -typedef struct { - __I uint32_t PART; /*!< Part code */ - __I uint32_t VARIANT; /*!< Part variant */ - __I uint32_t PACKAGE; /*!< Package option */ - __I uint32_t RAM; /*!< RAM variant */ - __I uint32_t FLASH; /*!< Flash variant */ - __I uint32_t RESERVED[3]; /*!< Reserved */ -} FICR_INFO_Type; - - -/* ================================================================================ */ -/* ================ POWER ================ */ -/* ================================================================================ */ - - -/** - * @brief Power Control. (POWER) - */ - -typedef struct { /*!< POWER Structure */ - __I uint32_t RESERVED0[30]; - __O uint32_t TASKS_CONSTLAT; /*!< Enable constant latency mode. */ - __O uint32_t TASKS_LOWPWR; /*!< Enable low power mode (variable latency). */ - __I uint32_t RESERVED1[34]; - __IO uint32_t EVENTS_POFWARN; /*!< Power failure warning. */ - __I uint32_t RESERVED2[126]; - __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ - __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ - __I uint32_t RESERVED3[61]; - __IO uint32_t RESETREAS; /*!< Reset reason. */ - __I uint32_t RESERVED4[9]; - __I uint32_t RAMSTATUS; /*!< Ram status register. */ - __I uint32_t RESERVED5[53]; - __O uint32_t SYSTEMOFF; /*!< System off register. */ - __I uint32_t RESERVED6[3]; - __IO uint32_t POFCON; /*!< Power failure configuration. */ - __I uint32_t RESERVED7[2]; - __IO uint32_t GPREGRET; /*!< General purpose retention register. This register is a retained - register. */ - __I uint32_t RESERVED8; - __IO uint32_t RAMON; /*!< Ram on/off. */ - __I uint32_t RESERVED9[7]; - __IO uint32_t RESET; /*!< Pin reset functionality configuration register. This register - is a retained register. */ - __I uint32_t RESERVED10[3]; - __IO uint32_t RAMONB; /*!< Ram on/off. */ - __I uint32_t RESERVED11[8]; - __IO uint32_t DCDCEN; /*!< DCDC converter enable configuration register. */ - __I uint32_t RESERVED12[291]; - __IO uint32_t DCDCFORCE; /*!< DCDC power-up force register. */ -} NRF_POWER_Type; - - -/* ================================================================================ */ -/* ================ CLOCK ================ */ -/* ================================================================================ */ - - -/** - * @brief Clock control. (CLOCK) - */ - -typedef struct { /*!< CLOCK Structure */ - __O uint32_t TASKS_HFCLKSTART; /*!< Start HFCLK clock source. */ - __O uint32_t TASKS_HFCLKSTOP; /*!< Stop HFCLK clock source. */ - __O uint32_t TASKS_LFCLKSTART; /*!< Start LFCLK clock source. */ - __O uint32_t TASKS_LFCLKSTOP; /*!< Stop LFCLK clock source. */ - __O uint32_t TASKS_CAL; /*!< Start calibration of LFCLK RC oscillator. */ - __O uint32_t TASKS_CTSTART; /*!< Start calibration timer. */ - __O uint32_t TASKS_CTSTOP; /*!< Stop calibration timer. */ - __I uint32_t RESERVED0[57]; - __IO uint32_t EVENTS_HFCLKSTARTED; /*!< HFCLK oscillator started. */ - __IO uint32_t EVENTS_LFCLKSTARTED; /*!< LFCLK oscillator started. */ - __I uint32_t RESERVED1; - __IO uint32_t EVENTS_DONE; /*!< Calibration of LFCLK RC oscillator completed. */ - __IO uint32_t EVENTS_CTTO; /*!< Calibration timer timeout. */ - __I uint32_t RESERVED2[124]; - __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ - __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ - __I uint32_t RESERVED3[63]; - __I uint32_t HFCLKRUN; /*!< Task HFCLKSTART trigger status. */ - __I uint32_t HFCLKSTAT; /*!< High frequency clock status. */ - __I uint32_t RESERVED4; - __I uint32_t LFCLKRUN; /*!< Task LFCLKSTART triggered status. */ - __I uint32_t LFCLKSTAT; /*!< Low frequency clock status. */ - __I uint32_t LFCLKSRCCOPY; /*!< Clock source for the LFCLK clock, set when task LKCLKSTART is - triggered. */ - __I uint32_t RESERVED5[62]; - __IO uint32_t LFCLKSRC; /*!< Clock source for the LFCLK clock. */ - __I uint32_t RESERVED6[7]; - __IO uint32_t CTIV; /*!< Calibration timer interval. */ - __I uint32_t RESERVED7[5]; - __IO uint32_t XTALFREQ; /*!< Crystal frequency. */ -} NRF_CLOCK_Type; - - -/* ================================================================================ */ -/* ================ MPU ================ */ -/* ================================================================================ */ - - -/** - * @brief Memory Protection Unit. (MPU) - */ - -typedef struct { /*!< MPU Structure */ - __I uint32_t RESERVED0[330]; - __IO uint32_t PERR0; /*!< Configuration of peripherals in mpu regions. */ - __IO uint32_t RLENR0; /*!< Length of RAM region 0. */ - __I uint32_t RESERVED1[52]; - __IO uint32_t PROTENSET0; /*!< Erase and write protection bit enable set register. */ - __IO uint32_t PROTENSET1; /*!< Erase and write protection bit enable set register. */ - __IO uint32_t DISABLEINDEBUG; /*!< Disable erase and write protection mechanism in debug mode. */ - __IO uint32_t PROTBLOCKSIZE; /*!< Erase and write protection block size. */ -} NRF_MPU_Type; - - -/* ================================================================================ */ -/* ================ PU ================ */ -/* ================================================================================ */ - - -/** - * @brief Patch unit. (PU) - */ - -typedef struct { /*!< PU Structure */ - __I uint32_t RESERVED0[448]; - __IO uint32_t REPLACEADDR[8]; /*!< Address of first instruction to replace. */ - __I uint32_t RESERVED1[24]; - __IO uint32_t PATCHADDR[8]; /*!< Relative address of patch instructions. */ - __I uint32_t RESERVED2[24]; - __IO uint32_t PATCHEN; /*!< Patch enable register. */ - __IO uint32_t PATCHENSET; /*!< Patch enable register. */ - __IO uint32_t PATCHENCLR; /*!< Patch disable register. */ -} NRF_PU_Type; - - -/* ================================================================================ */ -/* ================ AMLI ================ */ -/* ================================================================================ */ - - -/** - * @brief AHB Multi-Layer Interface. (AMLI) - */ - -typedef struct { /*!< AMLI Structure */ - __I uint32_t RESERVED0[896]; - AMLI_RAMPRI_Type RAMPRI; /*!< RAM configurable priority configuration structure. */ -} NRF_AMLI_Type; - - -/* ================================================================================ */ -/* ================ RADIO ================ */ -/* ================================================================================ */ - - -/** - * @brief The radio. (RADIO) - */ - -typedef struct { /*!< RADIO Structure */ - __O uint32_t TASKS_TXEN; /*!< Enable radio in TX mode. */ - __O uint32_t TASKS_RXEN; /*!< Enable radio in RX mode. */ - __O uint32_t TASKS_START; /*!< Start radio. */ - __O uint32_t TASKS_STOP; /*!< Stop radio. */ - __O uint32_t TASKS_DISABLE; /*!< Disable radio. */ - __O uint32_t TASKS_RSSISTART; /*!< Start the RSSI and take one sample of the receive signal strength. */ - __O uint32_t TASKS_RSSISTOP; /*!< Stop the RSSI measurement. */ - __O uint32_t TASKS_BCSTART; /*!< Start the bit counter. */ - __O uint32_t TASKS_BCSTOP; /*!< Stop the bit counter. */ - __I uint32_t RESERVED0[55]; - __IO uint32_t EVENTS_READY; /*!< Ready event. */ - __IO uint32_t EVENTS_ADDRESS; /*!< Address event. */ - __IO uint32_t EVENTS_PAYLOAD; /*!< Payload event. */ - __IO uint32_t EVENTS_END; /*!< End event. */ - __IO uint32_t EVENTS_DISABLED; /*!< Disable event. */ - __IO uint32_t EVENTS_DEVMATCH; /*!< A device address match occurred on the last received packet. */ - __IO uint32_t EVENTS_DEVMISS; /*!< No device address match occurred on the last received packet. */ - __IO uint32_t EVENTS_RSSIEND; /*!< Sampling of the receive signal strength complete. A new RSSI - sample is ready for readout at the RSSISAMPLE register. */ - __I uint32_t RESERVED1[2]; - __IO uint32_t EVENTS_BCMATCH; /*!< Bit counter reached bit count value specified in BC register. */ - __I uint32_t RESERVED2[53]; - __IO uint32_t SHORTS; /*!< Shortcuts for the radio. */ - __I uint32_t RESERVED3[64]; - __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ - __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ - __I uint32_t RESERVED4[61]; - __I uint32_t CRCSTATUS; /*!< CRC status of received packet. */ - __I uint32_t CD; /*!< Carrier detect. */ - __I uint32_t RXMATCH; /*!< Received address. */ - __I uint32_t RXCRC; /*!< Received CRC. */ - __I uint32_t DAI; /*!< Device address match index. */ - __I uint32_t RESERVED5[60]; - __IO uint32_t PACKETPTR; /*!< Packet pointer. Decision point: START task. */ - __IO uint32_t FREQUENCY; /*!< Frequency. */ - __IO uint32_t TXPOWER; /*!< Output power. */ - __IO uint32_t MODE; /*!< Data rate and modulation. */ - __IO uint32_t PCNF0; /*!< Packet configuration 0. */ - __IO uint32_t PCNF1; /*!< Packet configuration 1. */ - __IO uint32_t BASE0; /*!< Radio base address 0. Decision point: START task. */ - __IO uint32_t BASE1; /*!< Radio base address 1. Decision point: START task. */ - __IO uint32_t PREFIX0; /*!< Prefixes bytes for logical addresses 0 to 3. */ - __IO uint32_t PREFIX1; /*!< Prefixes bytes for logical addresses 4 to 7. */ - __IO uint32_t TXADDRESS; /*!< Transmit address select. */ - __IO uint32_t RXADDRESSES; /*!< Receive address select. */ - __IO uint32_t CRCCNF; /*!< CRC configuration. */ - __IO uint32_t CRCPOLY; /*!< CRC polynomial. */ - __IO uint32_t CRCINIT; /*!< CRC initial value. */ - __IO uint32_t TEST; /*!< Test features enable register. */ - __IO uint32_t TIFS; /*!< Inter Frame Spacing in microseconds. */ - __I uint32_t RSSISAMPLE; /*!< RSSI sample. */ - __I uint32_t RESERVED6; - __I uint32_t STATE; /*!< Current radio state. */ - __IO uint32_t DATAWHITEIV; /*!< Data whitening initial value. */ - __I uint32_t RESERVED7[2]; - __IO uint32_t BCC; /*!< Bit counter compare. */ - __I uint32_t RESERVED8[39]; - __IO uint32_t DAB[8]; /*!< Device address base segment. */ - __IO uint32_t DAP[8]; /*!< Device address prefix. */ - __IO uint32_t DACNF; /*!< Device address match configuration. */ - __I uint32_t RESERVED9[56]; - __IO uint32_t OVERRIDE0; /*!< Trim value override register 0. */ - __IO uint32_t OVERRIDE1; /*!< Trim value override register 1. */ - __IO uint32_t OVERRIDE2; /*!< Trim value override register 2. */ - __IO uint32_t OVERRIDE3; /*!< Trim value override register 3. */ - __IO uint32_t OVERRIDE4; /*!< Trim value override register 4. */ - __I uint32_t RESERVED10[561]; - __IO uint32_t POWER; /*!< Peripheral power control. */ -} NRF_RADIO_Type; - - -/* ================================================================================ */ -/* ================ UART ================ */ -/* ================================================================================ */ - - -/** - * @brief Universal Asynchronous Receiver/Transmitter. (UART) - */ - -typedef struct { /*!< UART Structure */ - __O uint32_t TASKS_STARTRX; /*!< Start UART receiver. */ - __O uint32_t TASKS_STOPRX; /*!< Stop UART receiver. */ - __O uint32_t TASKS_STARTTX; /*!< Start UART transmitter. */ - __O uint32_t TASKS_STOPTX; /*!< Stop UART transmitter. */ - __I uint32_t RESERVED0[3]; - __O uint32_t TASKS_SUSPEND; /*!< Suspend UART. */ - __I uint32_t RESERVED1[56]; - __IO uint32_t EVENTS_CTS; /*!< CTS activated. */ - __IO uint32_t EVENTS_NCTS; /*!< CTS deactivated. */ - __IO uint32_t EVENTS_RXDRDY; /*!< Data received in RXD. */ - __I uint32_t RESERVED2[4]; - __IO uint32_t EVENTS_TXDRDY; /*!< Data sent from TXD. */ - __I uint32_t RESERVED3; - __IO uint32_t EVENTS_ERROR; /*!< Error detected. */ - __I uint32_t RESERVED4[7]; - __IO uint32_t EVENTS_RXTO; /*!< Receiver timeout. */ - __I uint32_t RESERVED5[46]; - __IO uint32_t SHORTS; /*!< Shortcuts for UART. */ - __I uint32_t RESERVED6[64]; - __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ - __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ - __I uint32_t RESERVED7[93]; - __IO uint32_t ERRORSRC; /*!< Error source. Write error field to 1 to clear error. */ - __I uint32_t RESERVED8[31]; - __IO uint32_t ENABLE; /*!< Enable UART and acquire IOs. */ - __I uint32_t RESERVED9; - __IO uint32_t PSELRTS; /*!< Pin select for RTS. */ - __IO uint32_t PSELTXD; /*!< Pin select for TXD. */ - __IO uint32_t PSELCTS; /*!< Pin select for CTS. */ - __IO uint32_t PSELRXD; /*!< Pin select for RXD. */ - __I uint32_t RXD; /*!< RXD register. On read action the buffer pointer is displaced. - Once read the character is consumed. If read when no character - available, the UART will stop working. */ - __O uint32_t TXD; /*!< TXD register. */ - __I uint32_t RESERVED10; - __IO uint32_t BAUDRATE; /*!< UART Baudrate. */ - __I uint32_t RESERVED11[17]; - __IO uint32_t CONFIG; /*!< Configuration of parity and hardware flow control register. */ - __I uint32_t RESERVED12[675]; - __IO uint32_t POWER; /*!< Peripheral power control. */ -} NRF_UART_Type; - - -/* ================================================================================ */ -/* ================ SPI ================ */ -/* ================================================================================ */ - - -/** - * @brief SPI master 0. (SPI) - */ - -typedef struct { /*!< SPI Structure */ - __I uint32_t RESERVED0[66]; - __IO uint32_t EVENTS_READY; /*!< TXD byte sent and RXD byte received. */ - __I uint32_t RESERVED1[126]; - __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ - __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ - __I uint32_t RESERVED2[125]; - __IO uint32_t ENABLE; /*!< Enable SPI. */ - __I uint32_t RESERVED3; - __IO uint32_t PSELSCK; /*!< Pin select for SCK. */ - __IO uint32_t PSELMOSI; /*!< Pin select for MOSI. */ - __IO uint32_t PSELMISO; /*!< Pin select for MISO. */ - __I uint32_t RESERVED4; - __I uint32_t RXD; /*!< RX data. */ - __IO uint32_t TXD; /*!< TX data. */ - __I uint32_t RESERVED5; - __IO uint32_t FREQUENCY; /*!< SPI frequency */ - __I uint32_t RESERVED6[11]; - __IO uint32_t CONFIG; /*!< Configuration register. */ - __I uint32_t RESERVED7[681]; - __IO uint32_t POWER; /*!< Peripheral power control. */ -} NRF_SPI_Type; - - -/* ================================================================================ */ -/* ================ TWI ================ */ -/* ================================================================================ */ - - -/** - * @brief Two-wire interface master 0. (TWI) - */ - -typedef struct { /*!< TWI Structure */ - __O uint32_t TASKS_STARTRX; /*!< Start 2-Wire master receive sequence. */ - __I uint32_t RESERVED0; - __O uint32_t TASKS_STARTTX; /*!< Start 2-Wire master transmit sequence. */ - __I uint32_t RESERVED1[2]; - __O uint32_t TASKS_STOP; /*!< Stop 2-Wire transaction. */ - __I uint32_t RESERVED2; - __O uint32_t TASKS_SUSPEND; /*!< Suspend 2-Wire transaction. */ - __O uint32_t TASKS_RESUME; /*!< Resume 2-Wire transaction. */ - __I uint32_t RESERVED3[56]; - __IO uint32_t EVENTS_STOPPED; /*!< Two-wire stopped. */ - __IO uint32_t EVENTS_RXDREADY; /*!< Two-wire ready to deliver new RXD byte received. */ - __I uint32_t RESERVED4[4]; - __IO uint32_t EVENTS_TXDSENT; /*!< Two-wire finished sending last TXD byte. */ - __I uint32_t RESERVED5; - __IO uint32_t EVENTS_ERROR; /*!< Two-wire error detected. */ - __I uint32_t RESERVED6[4]; - __IO uint32_t EVENTS_BB; /*!< Two-wire byte boundary. */ - __I uint32_t RESERVED7[3]; - __IO uint32_t EVENTS_SUSPENDED; /*!< Two-wire suspended. */ - __I uint32_t RESERVED8[45]; - __IO uint32_t SHORTS; /*!< Shortcuts for TWI. */ - __I uint32_t RESERVED9[64]; - __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ - __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ - __I uint32_t RESERVED10[110]; - __IO uint32_t ERRORSRC; /*!< Two-wire error source. Write error field to 1 to clear error. */ - __I uint32_t RESERVED11[14]; - __IO uint32_t ENABLE; /*!< Enable two-wire master. */ - __I uint32_t RESERVED12; - __IO uint32_t PSELSCL; /*!< Pin select for SCL. */ - __IO uint32_t PSELSDA; /*!< Pin select for SDA. */ - __I uint32_t RESERVED13[2]; - __I uint32_t RXD; /*!< RX data register. */ - __IO uint32_t TXD; /*!< TX data register. */ - __I uint32_t RESERVED14; - __IO uint32_t FREQUENCY; /*!< Two-wire frequency. */ - __I uint32_t RESERVED15[24]; - __IO uint32_t ADDRESS; /*!< Address used in the two-wire transfer. */ - __I uint32_t RESERVED16[668]; - __IO uint32_t POWER; /*!< Peripheral power control. */ -} NRF_TWI_Type; - - -/* ================================================================================ */ -/* ================ SPIS ================ */ -/* ================================================================================ */ - - -/** - * @brief SPI slave 1. (SPIS) - */ - -typedef struct { /*!< SPIS Structure */ - __I uint32_t RESERVED0[9]; - __O uint32_t TASKS_ACQUIRE; /*!< Acquire SPI semaphore. */ - __O uint32_t TASKS_RELEASE; /*!< Release SPI semaphore. */ - __I uint32_t RESERVED1[54]; - __IO uint32_t EVENTS_END; /*!< Granted transaction completed. */ - __I uint32_t RESERVED2[8]; - __IO uint32_t EVENTS_ACQUIRED; /*!< Semaphore acquired. */ - __I uint32_t RESERVED3[53]; - __IO uint32_t SHORTS; /*!< Shortcuts for SPIS. */ - __I uint32_t RESERVED4[64]; - __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ - __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ - __I uint32_t RESERVED5[61]; - __I uint32_t SEMSTAT; /*!< Semaphore status. */ - __I uint32_t RESERVED6[15]; - __IO uint32_t STATUS; /*!< Status from last transaction. */ - __I uint32_t RESERVED7[47]; - __IO uint32_t ENABLE; /*!< Enable SPIS. */ - __I uint32_t RESERVED8; - __IO uint32_t PSELSCK; /*!< Pin select for SCK. */ - __IO uint32_t PSELMISO; /*!< Pin select for MISO. */ - __IO uint32_t PSELMOSI; /*!< Pin select for MOSI. */ - __IO uint32_t PSELCSN; /*!< Pin select for CSN. */ - __I uint32_t RESERVED9[7]; - __IO uint32_t RXDPTR; /*!< RX data pointer. */ - __IO uint32_t MAXRX; /*!< Maximum number of bytes in the receive buffer. */ - __I uint32_t AMOUNTRX; /*!< Number of bytes received in last granted transaction. */ - __I uint32_t RESERVED10; - __IO uint32_t TXDPTR; /*!< TX data pointer. */ - __IO uint32_t MAXTX; /*!< Maximum number of bytes in the transmit buffer. */ - __I uint32_t AMOUNTTX; /*!< Number of bytes transmitted in last granted transaction. */ - __I uint32_t RESERVED11; - __IO uint32_t CONFIG; /*!< Configuration register. */ - __I uint32_t RESERVED12; - __IO uint32_t DEF; /*!< Default character. */ - __I uint32_t RESERVED13[24]; - __IO uint32_t ORC; /*!< Over-read character. */ - __I uint32_t RESERVED14[654]; - __IO uint32_t POWER; /*!< Peripheral power control. */ -} NRF_SPIS_Type; - - -/* ================================================================================ */ -/* ================ SPIM ================ */ -/* ================================================================================ */ - - -/** - * @brief SPI master with easyDMA 1. (SPIM) - */ - -typedef struct { /*!< SPIM Structure */ - __I uint32_t RESERVED0[4]; - __O uint32_t TASKS_START; /*!< Start SPI transaction. */ - __O uint32_t TASKS_STOP; /*!< Stop SPI transaction. */ - __I uint32_t RESERVED1; - __O uint32_t TASKS_SUSPEND; /*!< Suspend SPI transaction. */ - __O uint32_t TASKS_RESUME; /*!< Resume SPI transaction. */ - __I uint32_t RESERVED2[56]; - __IO uint32_t EVENTS_STOPPED; /*!< SPI transaction has stopped. */ - __I uint32_t RESERVED3[2]; - __IO uint32_t EVENTS_ENDRX; /*!< End of RXD buffer reached. */ - __I uint32_t RESERVED4; - __IO uint32_t EVENTS_END; /*!< End of RXD buffer and TXD buffer reached. */ - __I uint32_t RESERVED5; - __IO uint32_t EVENTS_ENDTX; /*!< End of TXD buffer reached. */ - __I uint32_t RESERVED6[10]; - __IO uint32_t EVENTS_STARTED; /*!< Transaction started. */ - __I uint32_t RESERVED7[44]; - __IO uint32_t SHORTS; /*!< Shortcuts for SPIM. */ - __I uint32_t RESERVED8[64]; - __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ - __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ - __I uint32_t RESERVED9[125]; - __IO uint32_t ENABLE; /*!< Enable SPIM. */ - __I uint32_t RESERVED10; - SPIM_PSEL_Type PSEL; /*!< Pin select configuration. */ - __I uint32_t RESERVED11; - __I uint32_t RXDDATA; /*!< RXD register. */ - __IO uint32_t TXDDATA; /*!< TXD register. */ - __I uint32_t RESERVED12; - __IO uint32_t FREQUENCY; /*!< SPI frequency. */ - __I uint32_t RESERVED13[3]; - SPIM_RXD_Type RXD; /*!< RXD EasyDMA configuration and status. */ - __I uint32_t RESERVED14; - SPIM_TXD_Type TXD; /*!< TXD EasyDMA configuration and status. */ - __I uint32_t RESERVED15; - __IO uint32_t CONFIG; /*!< Configuration register. */ - __I uint32_t RESERVED16[26]; - __IO uint32_t ORC; /*!< Over-read character. */ - __I uint32_t RESERVED17[654]; - __IO uint32_t POWER; /*!< Peripheral power control. */ -} NRF_SPIM_Type; - - -/* ================================================================================ */ -/* ================ GPIOTE ================ */ -/* ================================================================================ */ - - -/** - * @brief GPIO tasks and events. (GPIOTE) - */ - -typedef struct { /*!< GPIOTE Structure */ - __O uint32_t TASKS_OUT[4]; /*!< Tasks asssociated with GPIOTE channels. */ - __I uint32_t RESERVED0[60]; - __IO uint32_t EVENTS_IN[4]; /*!< Tasks asssociated with GPIOTE channels. */ - __I uint32_t RESERVED1[27]; - __IO uint32_t EVENTS_PORT; /*!< Event generated from multiple pins. */ - __I uint32_t RESERVED2[97]; - __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ - __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ - __I uint32_t RESERVED3[129]; - __IO uint32_t CONFIG[4]; /*!< Channel configuration registers. */ - __I uint32_t RESERVED4[695]; - __IO uint32_t POWER; /*!< Peripheral power control. */ -} NRF_GPIOTE_Type; - - -/* ================================================================================ */ -/* ================ ADC ================ */ -/* ================================================================================ */ - - -/** - * @brief Analog to digital converter. (ADC) - */ - -typedef struct { /*!< ADC Structure */ - __O uint32_t TASKS_START; /*!< Start an ADC conversion. */ - __O uint32_t TASKS_STOP; /*!< Stop ADC. */ - __I uint32_t RESERVED0[62]; - __IO uint32_t EVENTS_END; /*!< ADC conversion complete. */ - __I uint32_t RESERVED1[128]; - __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ - __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ - __I uint32_t RESERVED2[61]; - __I uint32_t BUSY; /*!< ADC busy register. */ - __I uint32_t RESERVED3[63]; - __IO uint32_t ENABLE; /*!< ADC enable. */ - __IO uint32_t CONFIG; /*!< ADC configuration register. */ - __I uint32_t RESULT; /*!< Result of ADC conversion. */ - __I uint32_t RESERVED4[700]; - __IO uint32_t POWER; /*!< Peripheral power control. */ -} NRF_ADC_Type; - - -/* ================================================================================ */ -/* ================ TIMER ================ */ -/* ================================================================================ */ - - -/** - * @brief Timer 0. (TIMER) - */ - -typedef struct { /*!< TIMER Structure */ - __O uint32_t TASKS_START; /*!< Start Timer. */ - __O uint32_t TASKS_STOP; /*!< Stop Timer. */ - __O uint32_t TASKS_COUNT; /*!< Increment Timer (In counter mode). */ - __O uint32_t TASKS_CLEAR; /*!< Clear timer. */ - __O uint32_t TASKS_SHUTDOWN; /*!< Shutdown timer. */ - __I uint32_t RESERVED0[11]; - __O uint32_t TASKS_CAPTURE[4]; /*!< Capture Timer value to CC[n] registers. */ - __I uint32_t RESERVED1[60]; - __IO uint32_t EVENTS_COMPARE[4]; /*!< Compare event on CC[n] match. */ - __I uint32_t RESERVED2[44]; - __IO uint32_t SHORTS; /*!< Shortcuts for Timer. */ - __I uint32_t RESERVED3[64]; - __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ - __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ - __I uint32_t RESERVED4[126]; - __IO uint32_t MODE; /*!< Timer Mode selection. */ - __IO uint32_t BITMODE; /*!< Sets timer behaviour. */ - __I uint32_t RESERVED5; - __IO uint32_t PRESCALER; /*!< 4-bit prescaler to source clock frequency (max value 9). Source - clock frequency is divided by 2^SCALE. */ - __I uint32_t RESERVED6[11]; - __IO uint32_t CC[4]; /*!< Capture/compare registers. */ - __I uint32_t RESERVED7[683]; - __IO uint32_t POWER; /*!< Peripheral power control. */ -} NRF_TIMER_Type; - - -/* ================================================================================ */ -/* ================ RTC ================ */ -/* ================================================================================ */ - - -/** - * @brief Real time counter 0. (RTC) - */ - -typedef struct { /*!< RTC Structure */ - __O uint32_t TASKS_START; /*!< Start RTC Counter. */ - __O uint32_t TASKS_STOP; /*!< Stop RTC Counter. */ - __O uint32_t TASKS_CLEAR; /*!< Clear RTC Counter. */ - __O uint32_t TASKS_TRIGOVRFLW; /*!< Set COUNTER to 0xFFFFFFF0. */ - __I uint32_t RESERVED0[60]; - __IO uint32_t EVENTS_TICK; /*!< Event on COUNTER increment. */ - __IO uint32_t EVENTS_OVRFLW; /*!< Event on COUNTER overflow. */ - __I uint32_t RESERVED1[14]; - __IO uint32_t EVENTS_COMPARE[4]; /*!< Compare event on CC[n] match. */ - __I uint32_t RESERVED2[109]; - __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ - __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ - __I uint32_t RESERVED3[13]; - __IO uint32_t EVTEN; /*!< Configures event enable routing to PPI for each RTC event. */ - __IO uint32_t EVTENSET; /*!< Enable events routing to PPI. The reading of this register gives - the value of EVTEN. */ - __IO uint32_t EVTENCLR; /*!< Disable events routing to PPI. The reading of this register - gives the value of EVTEN. */ - __I uint32_t RESERVED4[110]; - __I uint32_t COUNTER; /*!< Current COUNTER value. */ - __IO uint32_t PRESCALER; /*!< 12-bit prescaler for COUNTER frequency (32768/(PRESCALER+1)). - Must be written when RTC is STOPed. */ - __I uint32_t RESERVED5[13]; - __IO uint32_t CC[4]; /*!< Capture/compare registers. */ - __I uint32_t RESERVED6[683]; - __IO uint32_t POWER; /*!< Peripheral power control. */ -} NRF_RTC_Type; - - -/* ================================================================================ */ -/* ================ TEMP ================ */ -/* ================================================================================ */ - - -/** - * @brief Temperature Sensor. (TEMP) - */ - -typedef struct { /*!< TEMP Structure */ - __O uint32_t TASKS_START; /*!< Start temperature measurement. */ - __O uint32_t TASKS_STOP; /*!< Stop temperature measurement. */ - __I uint32_t RESERVED0[62]; - __IO uint32_t EVENTS_DATARDY; /*!< Temperature measurement complete, data ready event. */ - __I uint32_t RESERVED1[128]; - __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ - __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ - __I uint32_t RESERVED2[127]; - __I int32_t TEMP; /*!< Die temperature in degC, 2's complement format, 0.25 degC pecision. */ - __I uint32_t RESERVED3[700]; - __IO uint32_t POWER; /*!< Peripheral power control. */ -} NRF_TEMP_Type; - - -/* ================================================================================ */ -/* ================ RNG ================ */ -/* ================================================================================ */ - - -/** - * @brief Random Number Generator. (RNG) - */ - -typedef struct { /*!< RNG Structure */ - __O uint32_t TASKS_START; /*!< Start the random number generator. */ - __O uint32_t TASKS_STOP; /*!< Stop the random number generator. */ - __I uint32_t RESERVED0[62]; - __IO uint32_t EVENTS_VALRDY; /*!< New random number generated and written to VALUE register. */ - __I uint32_t RESERVED1[63]; - __IO uint32_t SHORTS; /*!< Shortcuts for the RNG. */ - __I uint32_t RESERVED2[64]; - __IO uint32_t INTENSET; /*!< Interrupt enable set register */ - __IO uint32_t INTENCLR; /*!< Interrupt enable clear register */ - __I uint32_t RESERVED3[126]; - __IO uint32_t CONFIG; /*!< Configuration register. */ - __I uint32_t VALUE; /*!< RNG random number. */ - __I uint32_t RESERVED4[700]; - __IO uint32_t POWER; /*!< Peripheral power control. */ -} NRF_RNG_Type; - - -/* ================================================================================ */ -/* ================ ECB ================ */ -/* ================================================================================ */ - - -/** - * @brief AES ECB Mode Encryption. (ECB) - */ - -typedef struct { /*!< ECB Structure */ - __O uint32_t TASKS_STARTECB; /*!< Start ECB block encrypt. If a crypto operation is running, this - will not initiate a new encryption and the ERRORECB event will - be triggered. */ - __O uint32_t TASKS_STOPECB; /*!< Stop current ECB encryption. If a crypto operation is running, - this will will trigger the ERRORECB event. */ - __I uint32_t RESERVED0[62]; - __IO uint32_t EVENTS_ENDECB; /*!< ECB block encrypt complete. */ - __IO uint32_t EVENTS_ERRORECB; /*!< ECB block encrypt aborted due to a STOPECB task or due to an - error. */ - __I uint32_t RESERVED1[127]; - __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ - __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ - __I uint32_t RESERVED2[126]; - __IO uint32_t ECBDATAPTR; /*!< ECB block encrypt memory pointer. */ - __I uint32_t RESERVED3[701]; - __IO uint32_t POWER; /*!< Peripheral power control. */ -} NRF_ECB_Type; - - -/* ================================================================================ */ -/* ================ AAR ================ */ -/* ================================================================================ */ - - -/** - * @brief Accelerated Address Resolver. (AAR) - */ - -typedef struct { /*!< AAR Structure */ - __O uint32_t TASKS_START; /*!< Start resolving addresses based on IRKs specified in the IRK - data structure. */ - __I uint32_t RESERVED0; - __O uint32_t TASKS_STOP; /*!< Stop resolving addresses. */ - __I uint32_t RESERVED1[61]; - __IO uint32_t EVENTS_END; /*!< Address resolution procedure completed. */ - __IO uint32_t EVENTS_RESOLVED; /*!< Address resolved. */ - __IO uint32_t EVENTS_NOTRESOLVED; /*!< Address not resolved. */ - __I uint32_t RESERVED2[126]; - __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ - __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ - __I uint32_t RESERVED3[61]; - __I uint32_t STATUS; /*!< Resolution status. */ - __I uint32_t RESERVED4[63]; - __IO uint32_t ENABLE; /*!< Enable AAR. */ - __IO uint32_t NIRK; /*!< Number of Identity root Keys in the IRK data structure. */ - __IO uint32_t IRKPTR; /*!< Pointer to the IRK data structure. */ - __I uint32_t RESERVED5; - __IO uint32_t ADDRPTR; /*!< Pointer to the resolvable address (6 bytes). */ - __IO uint32_t SCRATCHPTR; /*!< Pointer to a "scratch" data area used for temporary storage - during resolution. A minimum of 3 bytes must be reserved. */ - __I uint32_t RESERVED6[697]; - __IO uint32_t POWER; /*!< Peripheral power control. */ -} NRF_AAR_Type; - - -/* ================================================================================ */ -/* ================ CCM ================ */ -/* ================================================================================ */ - - -/** - * @brief AES CCM Mode Encryption. (CCM) - */ - -typedef struct { /*!< CCM Structure */ - __O uint32_t TASKS_KSGEN; /*!< Start generation of key-stream. This operation will stop by - itself when completed. */ - __O uint32_t TASKS_CRYPT; /*!< Start encrypt/decrypt. This operation will stop by itself when - completed. */ - __O uint32_t TASKS_STOP; /*!< Stop encrypt/decrypt. */ - __I uint32_t RESERVED0[61]; - __IO uint32_t EVENTS_ENDKSGEN; /*!< Keystream generation completed. */ - __IO uint32_t EVENTS_ENDCRYPT; /*!< Encrypt/decrypt completed. */ - __IO uint32_t EVENTS_ERROR; /*!< Error happened. */ - __I uint32_t RESERVED1[61]; - __IO uint32_t SHORTS; /*!< Shortcuts for the CCM. */ - __I uint32_t RESERVED2[64]; - __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ - __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ - __I uint32_t RESERVED3[61]; - __I uint32_t MICSTATUS; /*!< CCM RX MIC check result. */ - __I uint32_t RESERVED4[63]; - __IO uint32_t ENABLE; /*!< CCM enable. */ - __IO uint32_t MODE; /*!< Operation mode. */ - __IO uint32_t CNFPTR; /*!< Pointer to a data structure holding AES key and NONCE vector. */ - __IO uint32_t INPTR; /*!< Pointer to the input packet. */ - __IO uint32_t OUTPTR; /*!< Pointer to the output packet. */ - __IO uint32_t SCRATCHPTR; /*!< Pointer to a "scratch" data area used for temporary storage - during resolution. A minimum of 43 bytes must be reserved. */ - __I uint32_t RESERVED5[697]; - __IO uint32_t POWER; /*!< Peripheral power control. */ -} NRF_CCM_Type; - - -/* ================================================================================ */ -/* ================ WDT ================ */ -/* ================================================================================ */ - - -/** - * @brief Watchdog Timer. (WDT) - */ - -typedef struct { /*!< WDT Structure */ - __O uint32_t TASKS_START; /*!< Start the watchdog. */ - __I uint32_t RESERVED0[63]; - __IO uint32_t EVENTS_TIMEOUT; /*!< Watchdog timeout. */ - __I uint32_t RESERVED1[128]; - __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ - __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ - __I uint32_t RESERVED2[61]; - __I uint32_t RUNSTATUS; /*!< Watchdog running status. */ - __I uint32_t REQSTATUS; /*!< Request status. */ - __I uint32_t RESERVED3[63]; - __IO uint32_t CRV; /*!< Counter reload value in number of 32kiHz clock cycles. */ - __IO uint32_t RREN; /*!< Reload request enable. */ - __IO uint32_t CONFIG; /*!< Configuration register. */ - __I uint32_t RESERVED4[60]; - __O uint32_t RR[8]; /*!< Reload requests registers. */ - __I uint32_t RESERVED5[631]; - __IO uint32_t POWER; /*!< Peripheral power control. */ -} NRF_WDT_Type; - - -/* ================================================================================ */ -/* ================ QDEC ================ */ -/* ================================================================================ */ - - -/** - * @brief Rotary decoder. (QDEC) - */ - -typedef struct { /*!< QDEC Structure */ - __O uint32_t TASKS_START; /*!< Start the quadrature decoder. */ - __O uint32_t TASKS_STOP; /*!< Stop the quadrature decoder. */ - __O uint32_t TASKS_READCLRACC; /*!< Transfers the content from ACC registers to ACCREAD registers, - and clears the ACC registers. */ - __I uint32_t RESERVED0[61]; - __IO uint32_t EVENTS_SAMPLERDY; /*!< A new sample is written to the sample register. */ - __IO uint32_t EVENTS_REPORTRDY; /*!< REPORTPER number of samples accumulated in ACC register, and - ACC register different than zero. */ - __IO uint32_t EVENTS_ACCOF; /*!< ACC or ACCDBL register overflow. */ - __I uint32_t RESERVED1[61]; - __IO uint32_t SHORTS; /*!< Shortcuts for the QDEC. */ - __I uint32_t RESERVED2[64]; - __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ - __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ - __I uint32_t RESERVED3[125]; - __IO uint32_t ENABLE; /*!< Enable the QDEC. */ - __IO uint32_t LEDPOL; /*!< LED output pin polarity. */ - __IO uint32_t SAMPLEPER; /*!< Sample period. */ - __I int32_t SAMPLE; /*!< Motion sample value. */ - __IO uint32_t REPORTPER; /*!< Number of samples to generate an EVENT_REPORTRDY. */ - __I int32_t ACC; /*!< Accumulated valid transitions register. */ - __I int32_t ACCREAD; /*!< Snapshot of ACC register. Value generated by the TASKS_READCLEACC - task. */ - __IO uint32_t PSELLED; /*!< Pin select for LED output. */ - __IO uint32_t PSELA; /*!< Pin select for phase A input. */ - __IO uint32_t PSELB; /*!< Pin select for phase B input. */ - __IO uint32_t DBFEN; /*!< Enable debouncer input filters. */ - __I uint32_t RESERVED4[5]; - __IO uint32_t LEDPRE; /*!< Time LED is switched ON before the sample. */ - __I uint32_t ACCDBL; /*!< Accumulated double (error) transitions register. */ - __I uint32_t ACCDBLREAD; /*!< Snapshot of ACCDBL register. Value generated by the TASKS_READCLEACC - task. */ - __I uint32_t RESERVED5[684]; - __IO uint32_t POWER; /*!< Peripheral power control. */ -} NRF_QDEC_Type; - - -/* ================================================================================ */ -/* ================ LPCOMP ================ */ -/* ================================================================================ */ - - -/** - * @brief Low power comparator. (LPCOMP) - */ - -typedef struct { /*!< LPCOMP Structure */ - __O uint32_t TASKS_START; /*!< Start the comparator. */ - __O uint32_t TASKS_STOP; /*!< Stop the comparator. */ - __O uint32_t TASKS_SAMPLE; /*!< Sample comparator value. */ - __I uint32_t RESERVED0[61]; - __IO uint32_t EVENTS_READY; /*!< LPCOMP is ready and output is valid. */ - __IO uint32_t EVENTS_DOWN; /*!< Input voltage crossed the threshold going down. */ - __IO uint32_t EVENTS_UP; /*!< Input voltage crossed the threshold going up. */ - __IO uint32_t EVENTS_CROSS; /*!< Input voltage crossed the threshold in any direction. */ - __I uint32_t RESERVED1[60]; - __IO uint32_t SHORTS; /*!< Shortcuts for the LPCOMP. */ - __I uint32_t RESERVED2[64]; - __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ - __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ - __I uint32_t RESERVED3[61]; - __I uint32_t RESULT; /*!< Result of last compare. */ - __I uint32_t RESERVED4[63]; - __IO uint32_t ENABLE; /*!< Enable the LPCOMP. */ - __IO uint32_t PSEL; /*!< Input pin select. */ - __IO uint32_t REFSEL; /*!< Reference select. */ - __IO uint32_t EXTREFSEL; /*!< External reference select. */ - __I uint32_t RESERVED5[4]; - __IO uint32_t ANADETECT; /*!< Analog detect configuration. */ - __I uint32_t RESERVED6[694]; - __IO uint32_t POWER; /*!< Peripheral power control. */ -} NRF_LPCOMP_Type; - - -/* ================================================================================ */ -/* ================ SWI ================ */ -/* ================================================================================ */ - - -/** - * @brief SW Interrupts. (SWI) - */ - -typedef struct { /*!< SWI Structure */ - __I uint32_t UNUSED; /*!< Unused. */ -} NRF_SWI_Type; - - -/* ================================================================================ */ -/* ================ NVMC ================ */ -/* ================================================================================ */ - - -/** - * @brief Non Volatile Memory Controller. (NVMC) - */ - -typedef struct { /*!< NVMC Structure */ - __I uint32_t RESERVED0[256]; - __I uint32_t READY; /*!< Ready flag. */ - __I uint32_t RESERVED1[64]; - __IO uint32_t CONFIG; /*!< Configuration register. */ - __IO uint32_t ERASEPAGE; /*!< Register for erasing a non-protected non-volatile memory page. */ - __IO uint32_t ERASEALL; /*!< Register for erasing all non-volatile user memory. */ - __IO uint32_t ERASEPROTECTEDPAGE; /*!< Register for erasing a protected non-volatile memory page. */ - __IO uint32_t ERASEUICR; /*!< Register for start erasing User Information Congfiguration Registers. */ -} NRF_NVMC_Type; - - -/* ================================================================================ */ -/* ================ PPI ================ */ -/* ================================================================================ */ - - -/** - * @brief PPI controller. (PPI) - */ - -typedef struct { /*!< PPI Structure */ - PPI_TASKS_CHG_Type TASKS_CHG[4]; /*!< Channel group tasks. */ - __I uint32_t RESERVED0[312]; - __IO uint32_t CHEN; /*!< Channel enable. */ - __IO uint32_t CHENSET; /*!< Channel enable set. */ - __IO uint32_t CHENCLR; /*!< Channel enable clear. */ - __I uint32_t RESERVED1; - PPI_CH_Type CH[16]; /*!< PPI Channel. */ - __I uint32_t RESERVED2[156]; - __IO uint32_t CHG[4]; /*!< Channel group configuration. */ -} NRF_PPI_Type; - - -/* ================================================================================ */ -/* ================ FICR ================ */ -/* ================================================================================ */ - - -/** - * @brief Factory Information Configuration. (FICR) - */ - -typedef struct { /*!< FICR Structure */ - __I uint32_t RESERVED0[4]; - __I uint32_t CODEPAGESIZE; /*!< Code memory page size in bytes. */ - __I uint32_t CODESIZE; /*!< Code memory size in pages. */ - __I uint32_t RESERVED1[4]; - __I uint32_t CLENR0; /*!< Length of code region 0 in bytes. */ - __I uint32_t PPFC; /*!< Pre-programmed factory code present. */ - __I uint32_t RESERVED2; - __I uint32_t NUMRAMBLOCK; /*!< Number of individualy controllable RAM blocks. */ - - union { - __I uint32_t SIZERAMBLOCK[4]; /*!< Deprecated array of size of RAM block in bytes. This name is - kept for backward compatinility purposes. Use SIZERAMBLOCKS - instead. */ - __I uint32_t SIZERAMBLOCKS; /*!< Size of RAM blocks in bytes. */ - }; - __I uint32_t RESERVED3[5]; - __I uint32_t CONFIGID; /*!< Configuration identifier. */ - __I uint32_t DEVICEID[2]; /*!< Device identifier. */ - __I uint32_t RESERVED4[6]; - __I uint32_t ER[4]; /*!< Encryption root. */ - __I uint32_t IR[4]; /*!< Identity root. */ - __I uint32_t DEVICEADDRTYPE; /*!< Device address type. */ - __I uint32_t DEVICEADDR[2]; /*!< Device address. */ - __I uint32_t OVERRIDEEN; /*!< Radio calibration override enable. */ - __I uint32_t NRF_1MBIT[5]; /*!< Override values for the OVERRIDEn registers in RADIO for NRF_1Mbit - mode. */ - __I uint32_t RESERVED5[10]; - __I uint32_t BLE_1MBIT[5]; /*!< Override values for the OVERRIDEn registers in RADIO for BLE_1Mbit - mode. */ - FICR_INFO_Type INFO; /*!< Device info */ -} NRF_FICR_Type; - - -/* ================================================================================ */ -/* ================ UICR ================ */ -/* ================================================================================ */ - - -/** - * @brief User Information Configuration. (UICR) - */ - -typedef struct { /*!< UICR Structure */ - __IO uint32_t CLENR0; /*!< Length of code region 0. */ - __IO uint32_t RBPCONF; /*!< Readback protection configuration. */ - __IO uint32_t XTALFREQ; /*!< Reset value for CLOCK XTALFREQ register. */ - __I uint32_t RESERVED0; - __I uint32_t FWID; /*!< Firmware ID. */ - __IO uint32_t BOOTLOADERADDR; /*!< Bootloader start address. */ -} NRF_UICR_Type; - - -/* ================================================================================ */ -/* ================ GPIO ================ */ -/* ================================================================================ */ - - -/** - * @brief General purpose input and output. (GPIO) - */ - -typedef struct { /*!< GPIO Structure */ - __I uint32_t RESERVED0[321]; - __IO uint32_t OUT; /*!< Write GPIO port. */ - __IO uint32_t OUTSET; /*!< Set individual bits in GPIO port. */ - __IO uint32_t OUTCLR; /*!< Clear individual bits in GPIO port. */ - __I uint32_t IN; /*!< Read GPIO port. */ - __IO uint32_t DIR; /*!< Direction of GPIO pins. */ - __IO uint32_t DIRSET; /*!< DIR set register. */ - __IO uint32_t DIRCLR; /*!< DIR clear register. */ - __I uint32_t RESERVED1[120]; - __IO uint32_t PIN_CNF[32]; /*!< Configuration of GPIO pins. */ -} NRF_GPIO_Type; - - -/* -------------------- End of section using anonymous unions ------------------- */ -#if defined(__CC_ARM) - #pragma pop -#elif defined(__ICCARM__) - /* leave anonymous unions enabled */ -#elif defined(__GNUC__) - /* anonymous unions are enabled by default */ -#elif defined(__TMS470__) - /* anonymous unions are enabled by default */ -#elif defined(__TASKING__) - #pragma warning restore -#else - #warning Not supported compiler type -#endif - - - - -/* ================================================================================ */ -/* ================ Peripheral memory map ================ */ -/* ================================================================================ */ - -#define NRF_POWER_BASE 0x40000000UL -#define NRF_CLOCK_BASE 0x40000000UL -#define NRF_MPU_BASE 0x40000000UL -#define NRF_PU_BASE 0x40000000UL -#define NRF_AMLI_BASE 0x40000000UL -#define NRF_RADIO_BASE 0x40001000UL -#define NRF_UART0_BASE 0x40002000UL -#define NRF_SPI0_BASE 0x40003000UL -#define NRF_TWI0_BASE 0x40003000UL -#define NRF_SPI1_BASE 0x40004000UL -#define NRF_TWI1_BASE 0x40004000UL -#define NRF_SPIS1_BASE 0x40004000UL -#define NRF_SPIM1_BASE 0x40004000UL -#define NRF_GPIOTE_BASE 0x40006000UL -#define NRF_ADC_BASE 0x40007000UL -#define NRF_TIMER0_BASE 0x40008000UL -#define NRF_TIMER1_BASE 0x40009000UL -#define NRF_TIMER2_BASE 0x4000A000UL -#define NRF_RTC0_BASE 0x4000B000UL -#define NRF_TEMP_BASE 0x4000C000UL -#define NRF_RNG_BASE 0x4000D000UL -#define NRF_ECB_BASE 0x4000E000UL -#define NRF_AAR_BASE 0x4000F000UL -#define NRF_CCM_BASE 0x4000F000UL -#define NRF_WDT_BASE 0x40010000UL -#define NRF_RTC1_BASE 0x40011000UL -#define NRF_QDEC_BASE 0x40012000UL -#define NRF_LPCOMP_BASE 0x40013000UL -#define NRF_SWI_BASE 0x40014000UL -#define NRF_NVMC_BASE 0x4001E000UL -#define NRF_PPI_BASE 0x4001F000UL -#define NRF_FICR_BASE 0x10000000UL -#define NRF_UICR_BASE 0x10001000UL -#define NRF_GPIO_BASE 0x50000000UL - - -/* ================================================================================ */ -/* ================ Peripheral declaration ================ */ -/* ================================================================================ */ - -#define NRF_POWER ((NRF_POWER_Type *) NRF_POWER_BASE) -#define NRF_CLOCK ((NRF_CLOCK_Type *) NRF_CLOCK_BASE) -#define NRF_MPU ((NRF_MPU_Type *) NRF_MPU_BASE) -#define NRF_PU ((NRF_PU_Type *) NRF_PU_BASE) -#define NRF_AMLI ((NRF_AMLI_Type *) NRF_AMLI_BASE) -#define NRF_RADIO ((NRF_RADIO_Type *) NRF_RADIO_BASE) -#define NRF_UART0 ((NRF_UART_Type *) NRF_UART0_BASE) -#define NRF_SPI0 ((NRF_SPI_Type *) NRF_SPI0_BASE) -#define NRF_TWI0 ((NRF_TWI_Type *) NRF_TWI0_BASE) -#define NRF_SPI1 ((NRF_SPI_Type *) NRF_SPI1_BASE) -#define NRF_TWI1 ((NRF_TWI_Type *) NRF_TWI1_BASE) -#define NRF_SPIS1 ((NRF_SPIS_Type *) NRF_SPIS1_BASE) -#define NRF_SPIM1 ((NRF_SPIM_Type *) NRF_SPIM1_BASE) -#define NRF_GPIOTE ((NRF_GPIOTE_Type *) NRF_GPIOTE_BASE) -#define NRF_ADC ((NRF_ADC_Type *) NRF_ADC_BASE) -#define NRF_TIMER0 ((NRF_TIMER_Type *) NRF_TIMER0_BASE) -#define NRF_TIMER1 ((NRF_TIMER_Type *) NRF_TIMER1_BASE) -#define NRF_TIMER2 ((NRF_TIMER_Type *) NRF_TIMER2_BASE) -#define NRF_RTC0 ((NRF_RTC_Type *) NRF_RTC0_BASE) -#define NRF_TEMP ((NRF_TEMP_Type *) NRF_TEMP_BASE) -#define NRF_RNG ((NRF_RNG_Type *) NRF_RNG_BASE) -#define NRF_ECB ((NRF_ECB_Type *) NRF_ECB_BASE) -#define NRF_AAR ((NRF_AAR_Type *) NRF_AAR_BASE) -#define NRF_CCM ((NRF_CCM_Type *) NRF_CCM_BASE) -#define NRF_WDT ((NRF_WDT_Type *) NRF_WDT_BASE) -#define NRF_RTC1 ((NRF_RTC_Type *) NRF_RTC1_BASE) -#define NRF_QDEC ((NRF_QDEC_Type *) NRF_QDEC_BASE) -#define NRF_LPCOMP ((NRF_LPCOMP_Type *) NRF_LPCOMP_BASE) -#define NRF_SWI ((NRF_SWI_Type *) NRF_SWI_BASE) -#define NRF_NVMC ((NRF_NVMC_Type *) NRF_NVMC_BASE) -#define NRF_PPI ((NRF_PPI_Type *) NRF_PPI_BASE) -#define NRF_FICR ((NRF_FICR_Type *) NRF_FICR_BASE) -#define NRF_UICR ((NRF_UICR_Type *) NRF_UICR_BASE) -#define NRF_GPIO ((NRF_GPIO_Type *) NRF_GPIO_BASE) - - -/** @} */ /* End of group Device_Peripheral_Registers */ -/** @} */ /* End of group nRF51 */ -/** @} */ /* End of group Nordic Semiconductor */ - -#ifdef __cplusplus -} -#endif - - -#endif /* nRF51_H */ - + +/****************************************************************************************************//** + * @file nrf51.h + * + * @brief CMSIS Cortex-M0 Peripheral Access Layer Header File for + * nrf51 from Nordic Semiconductor. + * + * @version V522 + * @date 29. April 2015 + * + * @note Generated with SVDConv V2.81d + * from CMSIS SVD File 'nrf51.xml' Version 522, + * + * @par Copyright (c) 2013, Nordic Semiconductor ASA + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + *******************************************************************************************************/ + + + +/** @addtogroup Nordic Semiconductor + * @{ + */ + +/** @addtogroup nrf51 + * @{ + */ + +#ifndef NRF51_H +#define NRF51_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/* ------------------------- Interrupt Number Definition ------------------------ */ + +typedef enum { +/* ------------------- Cortex-M0 Processor Exceptions Numbers ------------------- */ + Reset_IRQn = -15, /*!< 1 Reset Vector, invoked on Power up and warm reset */ + NonMaskableInt_IRQn = -14, /*!< 2 Non maskable Interrupt, cannot be stopped or preempted */ + HardFault_IRQn = -13, /*!< 3 Hard Fault, all classes of Fault */ + SVCall_IRQn = -5, /*!< 11 System Service Call via SVC instruction */ + DebugMonitor_IRQn = -4, /*!< 12 Debug Monitor */ + PendSV_IRQn = -2, /*!< 14 Pendable request for system service */ + SysTick_IRQn = -1, /*!< 15 System Tick Timer */ +/* ---------------------- nrf51 Specific Interrupt Numbers ---------------------- */ + POWER_CLOCK_IRQn = 0, /*!< 0 POWER_CLOCK */ + RADIO_IRQn = 1, /*!< 1 RADIO */ + UART0_IRQn = 2, /*!< 2 UART0 */ + SPI0_TWI0_IRQn = 3, /*!< 3 SPI0_TWI0 */ + SPI1_TWI1_IRQn = 4, /*!< 4 SPI1_TWI1 */ + GPIOTE_IRQn = 6, /*!< 6 GPIOTE */ + ADC_IRQn = 7, /*!< 7 ADC */ + TIMER0_IRQn = 8, /*!< 8 TIMER0 */ + TIMER1_IRQn = 9, /*!< 9 TIMER1 */ + TIMER2_IRQn = 10, /*!< 10 TIMER2 */ + RTC0_IRQn = 11, /*!< 11 RTC0 */ + TEMP_IRQn = 12, /*!< 12 TEMP */ + RNG_IRQn = 13, /*!< 13 RNG */ + ECB_IRQn = 14, /*!< 14 ECB */ + CCM_AAR_IRQn = 15, /*!< 15 CCM_AAR */ + WDT_IRQn = 16, /*!< 16 WDT */ + RTC1_IRQn = 17, /*!< 17 RTC1 */ + QDEC_IRQn = 18, /*!< 18 QDEC */ + LPCOMP_IRQn = 19, /*!< 19 LPCOMP */ + SWI0_IRQn = 20, /*!< 20 SWI0 */ + SWI1_IRQn = 21, /*!< 21 SWI1 */ + SWI2_IRQn = 22, /*!< 22 SWI2 */ + SWI3_IRQn = 23, /*!< 23 SWI3 */ + SWI4_IRQn = 24, /*!< 24 SWI4 */ + SWI5_IRQn = 25 /*!< 25 SWI5 */ +} IRQn_Type; + + +/** @addtogroup Configuration_of_CMSIS + * @{ + */ + + +/* ================================================================================ */ +/* ================ Processor and Core Peripheral Section ================ */ +/* ================================================================================ */ + +/* ----------------Configuration of the Cortex-M0 Processor and Core Peripherals---------------- */ +#define __CM0_REV 0x0301 /*!< Cortex-M0 Core Revision */ +#define __MPU_PRESENT 0 /*!< MPU present or not */ +#define __NVIC_PRIO_BITS 2 /*!< Number of Bits used for Priority Levels */ +#define __Vendor_SysTickConfig 0 /*!< Set to 1 if different SysTick Config is used */ +/** @} */ /* End of group Configuration_of_CMSIS */ + +#include "core_cm0.h" /*!< Cortex-M0 processor and core peripherals */ +#include "system_nrf51.h" /*!< nrf51 System */ + + +/* ================================================================================ */ +/* ================ Device Specific Peripheral Section ================ */ +/* ================================================================================ */ + + +/** @addtogroup Device_Peripheral_Registers + * @{ + */ + + +/* ------------------- Start of section using anonymous unions ------------------ */ +#if defined(__CC_ARM) + #pragma push + #pragma anon_unions +#elif defined(__ICCARM__) + #pragma language=extended +#elif defined(__GNUC__) + /* anonymous unions are enabled by default */ +#elif defined(__TMS470__) +/* anonymous unions are enabled by default */ +#elif defined(__TASKING__) + #pragma warning 586 +#else + #warning Not supported compiler type +#endif + + +typedef struct { + __IO uint32_t CPU0; /*!< Configurable priority configuration register for CPU0. */ + __IO uint32_t SPIS1; /*!< Configurable priority configuration register for SPIS1. */ + __IO uint32_t RADIO; /*!< Configurable priority configuration register for RADIO. */ + __IO uint32_t ECB; /*!< Configurable priority configuration register for ECB. */ + __IO uint32_t CCM; /*!< Configurable priority configuration register for CCM. */ + __IO uint32_t AAR; /*!< Configurable priority configuration register for AAR. */ +} AMLI_RAMPRI_Type; + +typedef struct { + __IO uint32_t SCK; /*!< Pin select for SCK. */ + __IO uint32_t MOSI; /*!< Pin select for MOSI. */ + __IO uint32_t MISO; /*!< Pin select for MISO. */ +} SPIM_PSEL_Type; + +typedef struct { + __IO uint32_t PTR; /*!< Data pointer. */ + __IO uint32_t MAXCNT; /*!< Maximum number of buffer bytes to receive. */ + __I uint32_t AMOUNT; /*!< Number of bytes received in the last transaction. */ +} SPIM_RXD_Type; + +typedef struct { + __IO uint32_t PTR; /*!< Data pointer. */ + __IO uint32_t MAXCNT; /*!< Maximum number of buffer bytes to send. */ + __I uint32_t AMOUNT; /*!< Number of bytes sent in the last transaction. */ +} SPIM_TXD_Type; + +typedef struct { + __O uint32_t EN; /*!< Enable channel group. */ + __O uint32_t DIS; /*!< Disable channel group. */ +} PPI_TASKS_CHG_Type; + +typedef struct { + __IO uint32_t EEP; /*!< Channel event end-point. */ + __IO uint32_t TEP; /*!< Channel task end-point. */ +} PPI_CH_Type; + + +/* ================================================================================ */ +/* ================ POWER ================ */ +/* ================================================================================ */ + + +/** + * @brief Power Control. (POWER) + */ + +typedef struct { /*!< POWER Structure */ + __I uint32_t RESERVED0[30]; + __O uint32_t TASKS_CONSTLAT; /*!< Enable constant latency mode. */ + __O uint32_t TASKS_LOWPWR; /*!< Enable low power mode (variable latency). */ + __I uint32_t RESERVED1[34]; + __IO uint32_t EVENTS_POFWARN; /*!< Power failure warning. */ + __I uint32_t RESERVED2[126]; + __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ + __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ + __I uint32_t RESERVED3[61]; + __IO uint32_t RESETREAS; /*!< Reset reason. */ + __I uint32_t RESERVED4[9]; + __I uint32_t RAMSTATUS; /*!< Ram status register. */ + __I uint32_t RESERVED5[53]; + __O uint32_t SYSTEMOFF; /*!< System off register. */ + __I uint32_t RESERVED6[3]; + __IO uint32_t POFCON; /*!< Power failure configuration. */ + __I uint32_t RESERVED7[2]; + __IO uint32_t GPREGRET; /*!< General purpose retention register. This register is a retained + register. */ + __I uint32_t RESERVED8; + __IO uint32_t RAMON; /*!< Ram on/off. */ + __I uint32_t RESERVED9[7]; + __IO uint32_t RESET; /*!< Pin reset functionality configuration register. This register + is a retained register. */ + __I uint32_t RESERVED10[3]; + __IO uint32_t RAMONB; /*!< Ram on/off. */ + __I uint32_t RESERVED11[8]; + __IO uint32_t DCDCEN; /*!< DCDC converter enable configuration register. */ + __I uint32_t RESERVED12[291]; + __IO uint32_t DCDCFORCE; /*!< DCDC power-up force register. */ +} NRF_POWER_Type; + + +/* ================================================================================ */ +/* ================ CLOCK ================ */ +/* ================================================================================ */ + + +/** + * @brief Clock control. (CLOCK) + */ + +typedef struct { /*!< CLOCK Structure */ + __O uint32_t TASKS_HFCLKSTART; /*!< Start HFCLK clock source. */ + __O uint32_t TASKS_HFCLKSTOP; /*!< Stop HFCLK clock source. */ + __O uint32_t TASKS_LFCLKSTART; /*!< Start LFCLK clock source. */ + __O uint32_t TASKS_LFCLKSTOP; /*!< Stop LFCLK clock source. */ + __O uint32_t TASKS_CAL; /*!< Start calibration of LFCLK RC oscillator. */ + __O uint32_t TASKS_CTSTART; /*!< Start calibration timer. */ + __O uint32_t TASKS_CTSTOP; /*!< Stop calibration timer. */ + __I uint32_t RESERVED0[57]; + __IO uint32_t EVENTS_HFCLKSTARTED; /*!< HFCLK oscillator started. */ + __IO uint32_t EVENTS_LFCLKSTARTED; /*!< LFCLK oscillator started. */ + __I uint32_t RESERVED1; + __IO uint32_t EVENTS_DONE; /*!< Calibration of LFCLK RC oscillator completed. */ + __IO uint32_t EVENTS_CTTO; /*!< Calibration timer timeout. */ + __I uint32_t RESERVED2[124]; + __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ + __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ + __I uint32_t RESERVED3[63]; + __I uint32_t HFCLKRUN; /*!< Task HFCLKSTART trigger status. */ + __I uint32_t HFCLKSTAT; /*!< High frequency clock status. */ + __I uint32_t RESERVED4; + __I uint32_t LFCLKRUN; /*!< Task LFCLKSTART triggered status. */ + __I uint32_t LFCLKSTAT; /*!< Low frequency clock status. */ + __I uint32_t LFCLKSRCCOPY; /*!< Clock source for the LFCLK clock, set when task LKCLKSTART is + triggered. */ + __I uint32_t RESERVED5[62]; + __IO uint32_t LFCLKSRC; /*!< Clock source for the LFCLK clock. */ + __I uint32_t RESERVED6[7]; + __IO uint32_t CTIV; /*!< Calibration timer interval. */ + __I uint32_t RESERVED7[5]; + __IO uint32_t XTALFREQ; /*!< Crystal frequency. */ +} NRF_CLOCK_Type; + + +/* ================================================================================ */ +/* ================ MPU ================ */ +/* ================================================================================ */ + + +/** + * @brief Memory Protection Unit. (MPU) + */ + +typedef struct { /*!< MPU Structure */ + __I uint32_t RESERVED0[330]; + __IO uint32_t PERR0; /*!< Configuration of peripherals in mpu regions. */ + __IO uint32_t RLENR0; /*!< Length of RAM region 0. */ + __I uint32_t RESERVED1[52]; + __IO uint32_t PROTENSET0; /*!< Erase and write protection bit enable set register. */ + __IO uint32_t PROTENSET1; /*!< Erase and write protection bit enable set register. */ + __IO uint32_t DISABLEINDEBUG; /*!< Disable erase and write protection mechanism in debug mode. */ + __IO uint32_t PROTBLOCKSIZE; /*!< Erase and write protection block size. */ +} NRF_MPU_Type; + + +/* ================================================================================ */ +/* ================ PU ================ */ +/* ================================================================================ */ + + +/** + * @brief Patch unit. (PU) + */ + +typedef struct { /*!< PU Structure */ + __I uint32_t RESERVED0[448]; + __IO uint32_t REPLACEADDR[8]; /*!< Address of first instruction to replace. */ + __I uint32_t RESERVED1[24]; + __IO uint32_t PATCHADDR[8]; /*!< Relative address of patch instructions. */ + __I uint32_t RESERVED2[24]; + __IO uint32_t PATCHEN; /*!< Patch enable register. */ + __IO uint32_t PATCHENSET; /*!< Patch enable register. */ + __IO uint32_t PATCHENCLR; /*!< Patch disable register. */ +} NRF_PU_Type; + + +/* ================================================================================ */ +/* ================ AMLI ================ */ +/* ================================================================================ */ + + +/** + * @brief AHB Multi-Layer Interface. (AMLI) + */ + +typedef struct { /*!< AMLI Structure */ + __I uint32_t RESERVED0[896]; + AMLI_RAMPRI_Type RAMPRI; /*!< RAM configurable priority configuration structure. */ +} NRF_AMLI_Type; + + +/* ================================================================================ */ +/* ================ RADIO ================ */ +/* ================================================================================ */ + + +/** + * @brief The radio. (RADIO) + */ + +typedef struct { /*!< RADIO Structure */ + __O uint32_t TASKS_TXEN; /*!< Enable radio in TX mode. */ + __O uint32_t TASKS_RXEN; /*!< Enable radio in RX mode. */ + __O uint32_t TASKS_START; /*!< Start radio. */ + __O uint32_t TASKS_STOP; /*!< Stop radio. */ + __O uint32_t TASKS_DISABLE; /*!< Disable radio. */ + __O uint32_t TASKS_RSSISTART; /*!< Start the RSSI and take one sample of the receive signal strength. */ + __O uint32_t TASKS_RSSISTOP; /*!< Stop the RSSI measurement. */ + __O uint32_t TASKS_BCSTART; /*!< Start the bit counter. */ + __O uint32_t TASKS_BCSTOP; /*!< Stop the bit counter. */ + __I uint32_t RESERVED0[55]; + __IO uint32_t EVENTS_READY; /*!< Ready event. */ + __IO uint32_t EVENTS_ADDRESS; /*!< Address event. */ + __IO uint32_t EVENTS_PAYLOAD; /*!< Payload event. */ + __IO uint32_t EVENTS_END; /*!< End event. */ + __IO uint32_t EVENTS_DISABLED; /*!< Disable event. */ + __IO uint32_t EVENTS_DEVMATCH; /*!< A device address match occurred on the last received packet. */ + __IO uint32_t EVENTS_DEVMISS; /*!< No device address match occurred on the last received packet. */ + __IO uint32_t EVENTS_RSSIEND; /*!< Sampling of the receive signal strength complete. A new RSSI + sample is ready for readout at the RSSISAMPLE register. */ + __I uint32_t RESERVED1[2]; + __IO uint32_t EVENTS_BCMATCH; /*!< Bit counter reached bit count value specified in BCC register. */ + __I uint32_t RESERVED2[53]; + __IO uint32_t SHORTS; /*!< Shortcuts for the radio. */ + __I uint32_t RESERVED3[64]; + __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ + __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ + __I uint32_t RESERVED4[61]; + __I uint32_t CRCSTATUS; /*!< CRC status of received packet. */ + __I uint32_t CD; /*!< Carrier detect. */ + __I uint32_t RXMATCH; /*!< Received address. */ + __I uint32_t RXCRC; /*!< Received CRC. */ + __I uint32_t DAI; /*!< Device address match index. */ + __I uint32_t RESERVED5[60]; + __IO uint32_t PACKETPTR; /*!< Packet pointer. Decision point: START task. */ + __IO uint32_t FREQUENCY; /*!< Frequency. */ + __IO uint32_t TXPOWER; /*!< Output power. */ + __IO uint32_t MODE; /*!< Data rate and modulation. */ + __IO uint32_t PCNF0; /*!< Packet configuration 0. */ + __IO uint32_t PCNF1; /*!< Packet configuration 1. */ + __IO uint32_t BASE0; /*!< Radio base address 0. Decision point: START task. */ + __IO uint32_t BASE1; /*!< Radio base address 1. Decision point: START task. */ + __IO uint32_t PREFIX0; /*!< Prefixes bytes for logical addresses 0 to 3. */ + __IO uint32_t PREFIX1; /*!< Prefixes bytes for logical addresses 4 to 7. */ + __IO uint32_t TXADDRESS; /*!< Transmit address select. */ + __IO uint32_t RXADDRESSES; /*!< Receive address select. */ + __IO uint32_t CRCCNF; /*!< CRC configuration. */ + __IO uint32_t CRCPOLY; /*!< CRC polynomial. */ + __IO uint32_t CRCINIT; /*!< CRC initial value. */ + __IO uint32_t TEST; /*!< Test features enable register. */ + __IO uint32_t TIFS; /*!< Inter Frame Spacing in microseconds. */ + __I uint32_t RSSISAMPLE; /*!< RSSI sample. */ + __I uint32_t RESERVED6; + __I uint32_t STATE; /*!< Current radio state. */ + __IO uint32_t DATAWHITEIV; /*!< Data whitening initial value. */ + __I uint32_t RESERVED7[2]; + __IO uint32_t BCC; /*!< Bit counter compare. */ + __I uint32_t RESERVED8[39]; + __IO uint32_t DAB[8]; /*!< Device address base segment. */ + __IO uint32_t DAP[8]; /*!< Device address prefix. */ + __IO uint32_t DACNF; /*!< Device address match configuration. */ + __I uint32_t RESERVED9[56]; + __IO uint32_t OVERRIDE0; /*!< Trim value override register 0. */ + __IO uint32_t OVERRIDE1; /*!< Trim value override register 1. */ + __IO uint32_t OVERRIDE2; /*!< Trim value override register 2. */ + __IO uint32_t OVERRIDE3; /*!< Trim value override register 3. */ + __IO uint32_t OVERRIDE4; /*!< Trim value override register 4. */ + __I uint32_t RESERVED10[561]; + __IO uint32_t POWER; /*!< Peripheral power control. */ +} NRF_RADIO_Type; + + +/* ================================================================================ */ +/* ================ UART ================ */ +/* ================================================================================ */ + + +/** + * @brief Universal Asynchronous Receiver/Transmitter. (UART) + */ + +typedef struct { /*!< UART Structure */ + __O uint32_t TASKS_STARTRX; /*!< Start UART receiver. */ + __O uint32_t TASKS_STOPRX; /*!< Stop UART receiver. */ + __O uint32_t TASKS_STARTTX; /*!< Start UART transmitter. */ + __O uint32_t TASKS_STOPTX; /*!< Stop UART transmitter. */ + __I uint32_t RESERVED0[3]; + __O uint32_t TASKS_SUSPEND; /*!< Suspend UART. */ + __I uint32_t RESERVED1[56]; + __IO uint32_t EVENTS_CTS; /*!< CTS activated. */ + __IO uint32_t EVENTS_NCTS; /*!< CTS deactivated. */ + __IO uint32_t EVENTS_RXDRDY; /*!< Data received in RXD. */ + __I uint32_t RESERVED2[4]; + __IO uint32_t EVENTS_TXDRDY; /*!< Data sent from TXD. */ + __I uint32_t RESERVED3; + __IO uint32_t EVENTS_ERROR; /*!< Error detected. */ + __I uint32_t RESERVED4[7]; + __IO uint32_t EVENTS_RXTO; /*!< Receiver timeout. */ + __I uint32_t RESERVED5[111]; + __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ + __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ + __I uint32_t RESERVED6[93]; + __IO uint32_t ERRORSRC; /*!< Error source. Write error field to 1 to clear error. */ + __I uint32_t RESERVED7[31]; + __IO uint32_t ENABLE; /*!< Enable UART and acquire IOs. */ + __I uint32_t RESERVED8; + __IO uint32_t PSELRTS; /*!< Pin select for RTS. */ + __IO uint32_t PSELTXD; /*!< Pin select for TXD. */ + __IO uint32_t PSELCTS; /*!< Pin select for CTS. */ + __IO uint32_t PSELRXD; /*!< Pin select for RXD. */ + __I uint32_t RXD; /*!< RXD register. On read action the buffer pointer is displaced. + Once read the character is consumed. If read when no character + available, the UART will stop working. */ + __O uint32_t TXD; /*!< TXD register. */ + __I uint32_t RESERVED9; + __IO uint32_t BAUDRATE; /*!< UART Baudrate. */ + __I uint32_t RESERVED10[17]; + __IO uint32_t CONFIG; /*!< Configuration of parity and hardware flow control register. */ + __I uint32_t RESERVED11[675]; + __IO uint32_t POWER; /*!< Peripheral power control. */ +} NRF_UART_Type; + + +/* ================================================================================ */ +/* ================ SPI ================ */ +/* ================================================================================ */ + + +/** + * @brief SPI master 0. (SPI) + */ + +typedef struct { /*!< SPI Structure */ + __I uint32_t RESERVED0[66]; + __IO uint32_t EVENTS_READY; /*!< TXD byte sent and RXD byte received. */ + __I uint32_t RESERVED1[126]; + __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ + __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ + __I uint32_t RESERVED2[125]; + __IO uint32_t ENABLE; /*!< Enable SPI. */ + __I uint32_t RESERVED3; + __IO uint32_t PSELSCK; /*!< Pin select for SCK. */ + __IO uint32_t PSELMOSI; /*!< Pin select for MOSI. */ + __IO uint32_t PSELMISO; /*!< Pin select for MISO. */ + __I uint32_t RESERVED4; + __I uint32_t RXD; /*!< RX data. */ + __IO uint32_t TXD; /*!< TX data. */ + __I uint32_t RESERVED5; + __IO uint32_t FREQUENCY; /*!< SPI frequency */ + __I uint32_t RESERVED6[11]; + __IO uint32_t CONFIG; /*!< Configuration register. */ + __I uint32_t RESERVED7[681]; + __IO uint32_t POWER; /*!< Peripheral power control. */ +} NRF_SPI_Type; + + +/* ================================================================================ */ +/* ================ TWI ================ */ +/* ================================================================================ */ + + +/** + * @brief Two-wire interface master 0. (TWI) + */ + +typedef struct { /*!< TWI Structure */ + __O uint32_t TASKS_STARTRX; /*!< Start 2-Wire master receive sequence. */ + __I uint32_t RESERVED0; + __O uint32_t TASKS_STARTTX; /*!< Start 2-Wire master transmit sequence. */ + __I uint32_t RESERVED1[2]; + __O uint32_t TASKS_STOP; /*!< Stop 2-Wire transaction. */ + __I uint32_t RESERVED2; + __O uint32_t TASKS_SUSPEND; /*!< Suspend 2-Wire transaction. */ + __O uint32_t TASKS_RESUME; /*!< Resume 2-Wire transaction. */ + __I uint32_t RESERVED3[56]; + __IO uint32_t EVENTS_STOPPED; /*!< Two-wire stopped. */ + __IO uint32_t EVENTS_RXDREADY; /*!< Two-wire ready to deliver new RXD byte received. */ + __I uint32_t RESERVED4[4]; + __IO uint32_t EVENTS_TXDSENT; /*!< Two-wire finished sending last TXD byte. */ + __I uint32_t RESERVED5; + __IO uint32_t EVENTS_ERROR; /*!< Two-wire error detected. */ + __I uint32_t RESERVED6[4]; + __IO uint32_t EVENTS_BB; /*!< Two-wire byte boundary. */ + __I uint32_t RESERVED7[3]; + __IO uint32_t EVENTS_SUSPENDED; /*!< Two-wire suspended. */ + __I uint32_t RESERVED8[45]; + __IO uint32_t SHORTS; /*!< Shortcuts for TWI. */ + __I uint32_t RESERVED9[64]; + __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ + __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ + __I uint32_t RESERVED10[110]; + __IO uint32_t ERRORSRC; /*!< Two-wire error source. Write error field to 1 to clear error. */ + __I uint32_t RESERVED11[14]; + __IO uint32_t ENABLE; /*!< Enable two-wire master. */ + __I uint32_t RESERVED12; + __IO uint32_t PSELSCL; /*!< Pin select for SCL. */ + __IO uint32_t PSELSDA; /*!< Pin select for SDA. */ + __I uint32_t RESERVED13[2]; + __I uint32_t RXD; /*!< RX data register. */ + __IO uint32_t TXD; /*!< TX data register. */ + __I uint32_t RESERVED14; + __IO uint32_t FREQUENCY; /*!< Two-wire frequency. */ + __I uint32_t RESERVED15[24]; + __IO uint32_t ADDRESS; /*!< Address used in the two-wire transfer. */ + __I uint32_t RESERVED16[668]; + __IO uint32_t POWER; /*!< Peripheral power control. */ +} NRF_TWI_Type; + + +/* ================================================================================ */ +/* ================ SPIS ================ */ +/* ================================================================================ */ + + +/** + * @brief SPI slave 1. (SPIS) + */ + +typedef struct { /*!< SPIS Structure */ + __I uint32_t RESERVED0[9]; + __O uint32_t TASKS_ACQUIRE; /*!< Acquire SPI semaphore. */ + __O uint32_t TASKS_RELEASE; /*!< Release SPI semaphore. */ + __I uint32_t RESERVED1[54]; + __IO uint32_t EVENTS_END; /*!< Granted transaction completed. */ + __I uint32_t RESERVED2[8]; + __IO uint32_t EVENTS_ACQUIRED; /*!< Semaphore acquired. */ + __I uint32_t RESERVED3[53]; + __IO uint32_t SHORTS; /*!< Shortcuts for SPIS. */ + __I uint32_t RESERVED4[64]; + __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ + __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ + __I uint32_t RESERVED5[61]; + __I uint32_t SEMSTAT; /*!< Semaphore status. */ + __I uint32_t RESERVED6[15]; + __IO uint32_t STATUS; /*!< Status from last transaction. */ + __I uint32_t RESERVED7[47]; + __IO uint32_t ENABLE; /*!< Enable SPIS. */ + __I uint32_t RESERVED8; + __IO uint32_t PSELSCK; /*!< Pin select for SCK. */ + __IO uint32_t PSELMISO; /*!< Pin select for MISO. */ + __IO uint32_t PSELMOSI; /*!< Pin select for MOSI. */ + __IO uint32_t PSELCSN; /*!< Pin select for CSN. */ + __I uint32_t RESERVED9[7]; + __IO uint32_t RXDPTR; /*!< RX data pointer. */ + __IO uint32_t MAXRX; /*!< Maximum number of bytes in the receive buffer. */ + __I uint32_t AMOUNTRX; /*!< Number of bytes received in last granted transaction. */ + __I uint32_t RESERVED10; + __IO uint32_t TXDPTR; /*!< TX data pointer. */ + __IO uint32_t MAXTX; /*!< Maximum number of bytes in the transmit buffer. */ + __I uint32_t AMOUNTTX; /*!< Number of bytes transmitted in last granted transaction. */ + __I uint32_t RESERVED11; + __IO uint32_t CONFIG; /*!< Configuration register. */ + __I uint32_t RESERVED12; + __IO uint32_t DEF; /*!< Default character. */ + __I uint32_t RESERVED13[24]; + __IO uint32_t ORC; /*!< Over-read character. */ + __I uint32_t RESERVED14[654]; + __IO uint32_t POWER; /*!< Peripheral power control. */ +} NRF_SPIS_Type; + + +/* ================================================================================ */ +/* ================ SPIM ================ */ +/* ================================================================================ */ + + +/** + * @brief SPI master with easyDMA 1. (SPIM) + */ + +typedef struct { /*!< SPIM Structure */ + __I uint32_t RESERVED0[4]; + __O uint32_t TASKS_START; /*!< Start SPI transaction. */ + __O uint32_t TASKS_STOP; /*!< Stop SPI transaction. */ + __I uint32_t RESERVED1; + __O uint32_t TASKS_SUSPEND; /*!< Suspend SPI transaction. */ + __O uint32_t TASKS_RESUME; /*!< Resume SPI transaction. */ + __I uint32_t RESERVED2[56]; + __IO uint32_t EVENTS_STOPPED; /*!< SPI transaction has stopped. */ + __I uint32_t RESERVED3[2]; + __IO uint32_t EVENTS_ENDRX; /*!< End of RXD buffer reached. */ + __I uint32_t RESERVED4; + __IO uint32_t EVENTS_END; /*!< End of RXD buffer and TXD buffer reached. */ + __I uint32_t RESERVED5; + __IO uint32_t EVENTS_ENDTX; /*!< End of TXD buffer reached. */ + __I uint32_t RESERVED6[10]; + __IO uint32_t EVENTS_STARTED; /*!< Transaction started. */ + __I uint32_t RESERVED7[44]; + __IO uint32_t SHORTS; /*!< Shortcuts for SPIM. */ + __I uint32_t RESERVED8[64]; + __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ + __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ + __I uint32_t RESERVED9[125]; + __IO uint32_t ENABLE; /*!< Enable SPIM. */ + __I uint32_t RESERVED10; + SPIM_PSEL_Type PSEL; /*!< Pin select configuration. */ + __I uint32_t RESERVED11[4]; + __IO uint32_t FREQUENCY; /*!< SPI frequency. */ + __I uint32_t RESERVED12[3]; + SPIM_RXD_Type RXD; /*!< RXD EasyDMA configuration and status. */ + __I uint32_t RESERVED13; + SPIM_TXD_Type TXD; /*!< TXD EasyDMA configuration and status. */ + __I uint32_t RESERVED14; + __IO uint32_t CONFIG; /*!< Configuration register. */ + __I uint32_t RESERVED15[26]; + __IO uint32_t ORC; /*!< Over-read character. */ + __I uint32_t RESERVED16[654]; + __IO uint32_t POWER; /*!< Peripheral power control. */ +} NRF_SPIM_Type; + + +/* ================================================================================ */ +/* ================ GPIOTE ================ */ +/* ================================================================================ */ + + +/** + * @brief GPIO tasks and events. (GPIOTE) + */ + +typedef struct { /*!< GPIOTE Structure */ + __O uint32_t TASKS_OUT[4]; /*!< Tasks asssociated with GPIOTE channels. */ + __I uint32_t RESERVED0[60]; + __IO uint32_t EVENTS_IN[4]; /*!< Tasks asssociated with GPIOTE channels. */ + __I uint32_t RESERVED1[27]; + __IO uint32_t EVENTS_PORT; /*!< Event generated from multiple pins. */ + __I uint32_t RESERVED2[97]; + __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ + __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ + __I uint32_t RESERVED3[129]; + __IO uint32_t CONFIG[4]; /*!< Channel configuration registers. */ + __I uint32_t RESERVED4[695]; + __IO uint32_t POWER; /*!< Peripheral power control. */ +} NRF_GPIOTE_Type; + + +/* ================================================================================ */ +/* ================ ADC ================ */ +/* ================================================================================ */ + + +/** + * @brief Analog to digital converter. (ADC) + */ + +typedef struct { /*!< ADC Structure */ + __O uint32_t TASKS_START; /*!< Start an ADC conversion. */ + __O uint32_t TASKS_STOP; /*!< Stop ADC. */ + __I uint32_t RESERVED0[62]; + __IO uint32_t EVENTS_END; /*!< ADC conversion complete. */ + __I uint32_t RESERVED1[128]; + __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ + __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ + __I uint32_t RESERVED2[61]; + __I uint32_t BUSY; /*!< ADC busy register. */ + __I uint32_t RESERVED3[63]; + __IO uint32_t ENABLE; /*!< ADC enable. */ + __IO uint32_t CONFIG; /*!< ADC configuration register. */ + __I uint32_t RESULT; /*!< Result of ADC conversion. */ + __I uint32_t RESERVED4[700]; + __IO uint32_t POWER; /*!< Peripheral power control. */ +} NRF_ADC_Type; + + +/* ================================================================================ */ +/* ================ TIMER ================ */ +/* ================================================================================ */ + + +/** + * @brief Timer 0. (TIMER) + */ + +typedef struct { /*!< TIMER Structure */ + __O uint32_t TASKS_START; /*!< Start Timer. */ + __O uint32_t TASKS_STOP; /*!< Stop Timer. */ + __O uint32_t TASKS_COUNT; /*!< Increment Timer (In counter mode). */ + __O uint32_t TASKS_CLEAR; /*!< Clear timer. */ + __O uint32_t TASKS_SHUTDOWN; /*!< Shutdown timer. */ + __I uint32_t RESERVED0[11]; + __O uint32_t TASKS_CAPTURE[4]; /*!< Capture Timer value to CC[n] registers. */ + __I uint32_t RESERVED1[60]; + __IO uint32_t EVENTS_COMPARE[4]; /*!< Compare event on CC[n] match. */ + __I uint32_t RESERVED2[44]; + __IO uint32_t SHORTS; /*!< Shortcuts for Timer. */ + __I uint32_t RESERVED3[64]; + __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ + __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ + __I uint32_t RESERVED4[126]; + __IO uint32_t MODE; /*!< Timer Mode selection. */ + __IO uint32_t BITMODE; /*!< Sets timer behaviour. */ + __I uint32_t RESERVED5; + __IO uint32_t PRESCALER; /*!< 4-bit prescaler to source clock frequency (max value 9). Source + clock frequency is divided by 2^SCALE. */ + __I uint32_t RESERVED6[11]; + __IO uint32_t CC[4]; /*!< Capture/compare registers. */ + __I uint32_t RESERVED7[683]; + __IO uint32_t POWER; /*!< Peripheral power control. */ +} NRF_TIMER_Type; + + +/* ================================================================================ */ +/* ================ RTC ================ */ +/* ================================================================================ */ + + +/** + * @brief Real time counter 0. (RTC) + */ + +typedef struct { /*!< RTC Structure */ + __O uint32_t TASKS_START; /*!< Start RTC Counter. */ + __O uint32_t TASKS_STOP; /*!< Stop RTC Counter. */ + __O uint32_t TASKS_CLEAR; /*!< Clear RTC Counter. */ + __O uint32_t TASKS_TRIGOVRFLW; /*!< Set COUNTER to 0xFFFFFFF0. */ + __I uint32_t RESERVED0[60]; + __IO uint32_t EVENTS_TICK; /*!< Event on COUNTER increment. */ + __IO uint32_t EVENTS_OVRFLW; /*!< Event on COUNTER overflow. */ + __I uint32_t RESERVED1[14]; + __IO uint32_t EVENTS_COMPARE[4]; /*!< Compare event on CC[n] match. */ + __I uint32_t RESERVED2[109]; + __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ + __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ + __I uint32_t RESERVED3[13]; + __IO uint32_t EVTEN; /*!< Configures event enable routing to PPI for each RTC event. */ + __IO uint32_t EVTENSET; /*!< Enable events routing to PPI. The reading of this register gives + the value of EVTEN. */ + __IO uint32_t EVTENCLR; /*!< Disable events routing to PPI. The reading of this register + gives the value of EVTEN. */ + __I uint32_t RESERVED4[110]; + __I uint32_t COUNTER; /*!< Current COUNTER value. */ + __IO uint32_t PRESCALER; /*!< 12-bit prescaler for COUNTER frequency (32768/(PRESCALER+1)). + Must be written when RTC is STOPed. */ + __I uint32_t RESERVED5[13]; + __IO uint32_t CC[4]; /*!< Capture/compare registers. */ + __I uint32_t RESERVED6[683]; + __IO uint32_t POWER; /*!< Peripheral power control. */ +} NRF_RTC_Type; + + +/* ================================================================================ */ +/* ================ TEMP ================ */ +/* ================================================================================ */ + + +/** + * @brief Temperature Sensor. (TEMP) + */ + +typedef struct { /*!< TEMP Structure */ + __O uint32_t TASKS_START; /*!< Start temperature measurement. */ + __O uint32_t TASKS_STOP; /*!< Stop temperature measurement. */ + __I uint32_t RESERVED0[62]; + __IO uint32_t EVENTS_DATARDY; /*!< Temperature measurement complete, data ready event. */ + __I uint32_t RESERVED1[128]; + __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ + __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ + __I uint32_t RESERVED2[127]; + __I int32_t TEMP; /*!< Die temperature in degC, 2's complement format, 0.25 degC pecision. */ + __I uint32_t RESERVED3[700]; + __IO uint32_t POWER; /*!< Peripheral power control. */ +} NRF_TEMP_Type; + + +/* ================================================================================ */ +/* ================ RNG ================ */ +/* ================================================================================ */ + + +/** + * @brief Random Number Generator. (RNG) + */ + +typedef struct { /*!< RNG Structure */ + __O uint32_t TASKS_START; /*!< Start the random number generator. */ + __O uint32_t TASKS_STOP; /*!< Stop the random number generator. */ + __I uint32_t RESERVED0[62]; + __IO uint32_t EVENTS_VALRDY; /*!< New random number generated and written to VALUE register. */ + __I uint32_t RESERVED1[63]; + __IO uint32_t SHORTS; /*!< Shortcuts for the RNG. */ + __I uint32_t RESERVED2[64]; + __IO uint32_t INTENSET; /*!< Interrupt enable set register */ + __IO uint32_t INTENCLR; /*!< Interrupt enable clear register */ + __I uint32_t RESERVED3[126]; + __IO uint32_t CONFIG; /*!< Configuration register. */ + __I uint32_t VALUE; /*!< RNG random number. */ + __I uint32_t RESERVED4[700]; + __IO uint32_t POWER; /*!< Peripheral power control. */ +} NRF_RNG_Type; + + +/* ================================================================================ */ +/* ================ ECB ================ */ +/* ================================================================================ */ + + +/** + * @brief AES ECB Mode Encryption. (ECB) + */ + +typedef struct { /*!< ECB Structure */ + __O uint32_t TASKS_STARTECB; /*!< Start ECB block encrypt. If a crypto operation is running, this + will not initiate a new encryption and the ERRORECB event will + be triggered. */ + __O uint32_t TASKS_STOPECB; /*!< Stop current ECB encryption. If a crypto operation is running, + this will will trigger the ERRORECB event. */ + __I uint32_t RESERVED0[62]; + __IO uint32_t EVENTS_ENDECB; /*!< ECB block encrypt complete. */ + __IO uint32_t EVENTS_ERRORECB; /*!< ECB block encrypt aborted due to a STOPECB task or due to an + error. */ + __I uint32_t RESERVED1[127]; + __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ + __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ + __I uint32_t RESERVED2[126]; + __IO uint32_t ECBDATAPTR; /*!< ECB block encrypt memory pointer. */ + __I uint32_t RESERVED3[701]; + __IO uint32_t POWER; /*!< Peripheral power control. */ +} NRF_ECB_Type; + + +/* ================================================================================ */ +/* ================ AAR ================ */ +/* ================================================================================ */ + + +/** + * @brief Accelerated Address Resolver. (AAR) + */ + +typedef struct { /*!< AAR Structure */ + __O uint32_t TASKS_START; /*!< Start resolving addresses based on IRKs specified in the IRK + data structure. */ + __I uint32_t RESERVED0; + __O uint32_t TASKS_STOP; /*!< Stop resolving addresses. */ + __I uint32_t RESERVED1[61]; + __IO uint32_t EVENTS_END; /*!< Address resolution procedure completed. */ + __IO uint32_t EVENTS_RESOLVED; /*!< Address resolved. */ + __IO uint32_t EVENTS_NOTRESOLVED; /*!< Address not resolved. */ + __I uint32_t RESERVED2[126]; + __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ + __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ + __I uint32_t RESERVED3[61]; + __I uint32_t STATUS; /*!< Resolution status. */ + __I uint32_t RESERVED4[63]; + __IO uint32_t ENABLE; /*!< Enable AAR. */ + __IO uint32_t NIRK; /*!< Number of Identity root Keys in the IRK data structure. */ + __IO uint32_t IRKPTR; /*!< Pointer to the IRK data structure. */ + __I uint32_t RESERVED5; + __IO uint32_t ADDRPTR; /*!< Pointer to the resolvable address (6 bytes). */ + __IO uint32_t SCRATCHPTR; /*!< Pointer to a "scratch" data area used for temporary storage + during resolution. A minimum of 3 bytes must be reserved. */ + __I uint32_t RESERVED6[697]; + __IO uint32_t POWER; /*!< Peripheral power control. */ +} NRF_AAR_Type; + + +/* ================================================================================ */ +/* ================ CCM ================ */ +/* ================================================================================ */ + + +/** + * @brief AES CCM Mode Encryption. (CCM) + */ + +typedef struct { /*!< CCM Structure */ + __O uint32_t TASKS_KSGEN; /*!< Start generation of key-stream. This operation will stop by + itself when completed. */ + __O uint32_t TASKS_CRYPT; /*!< Start encrypt/decrypt. This operation will stop by itself when + completed. */ + __O uint32_t TASKS_STOP; /*!< Stop encrypt/decrypt. */ + __I uint32_t RESERVED0[61]; + __IO uint32_t EVENTS_ENDKSGEN; /*!< Keystream generation completed. */ + __IO uint32_t EVENTS_ENDCRYPT; /*!< Encrypt/decrypt completed. */ + __IO uint32_t EVENTS_ERROR; /*!< Error happened. */ + __I uint32_t RESERVED1[61]; + __IO uint32_t SHORTS; /*!< Shortcuts for the CCM. */ + __I uint32_t RESERVED2[64]; + __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ + __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ + __I uint32_t RESERVED3[61]; + __I uint32_t MICSTATUS; /*!< CCM RX MIC check result. */ + __I uint32_t RESERVED4[63]; + __IO uint32_t ENABLE; /*!< CCM enable. */ + __IO uint32_t MODE; /*!< Operation mode. */ + __IO uint32_t CNFPTR; /*!< Pointer to a data structure holding AES key and NONCE vector. */ + __IO uint32_t INPTR; /*!< Pointer to the input packet. */ + __IO uint32_t OUTPTR; /*!< Pointer to the output packet. */ + __IO uint32_t SCRATCHPTR; /*!< Pointer to a "scratch" data area used for temporary storage + during resolution. A minimum of 43 bytes must be reserved. */ + __I uint32_t RESERVED5[697]; + __IO uint32_t POWER; /*!< Peripheral power control. */ +} NRF_CCM_Type; + + +/* ================================================================================ */ +/* ================ WDT ================ */ +/* ================================================================================ */ + + +/** + * @brief Watchdog Timer. (WDT) + */ + +typedef struct { /*!< WDT Structure */ + __O uint32_t TASKS_START; /*!< Start the watchdog. */ + __I uint32_t RESERVED0[63]; + __IO uint32_t EVENTS_TIMEOUT; /*!< Watchdog timeout. */ + __I uint32_t RESERVED1[128]; + __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ + __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ + __I uint32_t RESERVED2[61]; + __I uint32_t RUNSTATUS; /*!< Watchdog running status. */ + __I uint32_t REQSTATUS; /*!< Request status. */ + __I uint32_t RESERVED3[63]; + __IO uint32_t CRV; /*!< Counter reload value in number of 32kiHz clock cycles. */ + __IO uint32_t RREN; /*!< Reload request enable. */ + __IO uint32_t CONFIG; /*!< Configuration register. */ + __I uint32_t RESERVED4[60]; + __O uint32_t RR[8]; /*!< Reload requests registers. */ + __I uint32_t RESERVED5[631]; + __IO uint32_t POWER; /*!< Peripheral power control. */ +} NRF_WDT_Type; + + +/* ================================================================================ */ +/* ================ QDEC ================ */ +/* ================================================================================ */ + + +/** + * @brief Rotary decoder. (QDEC) + */ + +typedef struct { /*!< QDEC Structure */ + __O uint32_t TASKS_START; /*!< Start the quadrature decoder. */ + __O uint32_t TASKS_STOP; /*!< Stop the quadrature decoder. */ + __O uint32_t TASKS_READCLRACC; /*!< Transfers the content from ACC registers to ACCREAD registers, + and clears the ACC registers. */ + __I uint32_t RESERVED0[61]; + __IO uint32_t EVENTS_SAMPLERDY; /*!< A new sample is written to the sample register. */ + __IO uint32_t EVENTS_REPORTRDY; /*!< REPORTPER number of samples accumulated in ACC register, and + ACC register different than zero. */ + __IO uint32_t EVENTS_ACCOF; /*!< ACC or ACCDBL register overflow. */ + __I uint32_t RESERVED1[61]; + __IO uint32_t SHORTS; /*!< Shortcuts for the QDEC. */ + __I uint32_t RESERVED2[64]; + __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ + __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ + __I uint32_t RESERVED3[125]; + __IO uint32_t ENABLE; /*!< Enable the QDEC. */ + __IO uint32_t LEDPOL; /*!< LED output pin polarity. */ + __IO uint32_t SAMPLEPER; /*!< Sample period. */ + __I int32_t SAMPLE; /*!< Motion sample value. */ + __IO uint32_t REPORTPER; /*!< Number of samples to generate an EVENT_REPORTRDY. */ + __I int32_t ACC; /*!< Accumulated valid transitions register. */ + __I int32_t ACCREAD; /*!< Snapshot of ACC register. Value generated by the TASKS_READCLEACC + task. */ + __IO uint32_t PSELLED; /*!< Pin select for LED output. */ + __IO uint32_t PSELA; /*!< Pin select for phase A input. */ + __IO uint32_t PSELB; /*!< Pin select for phase B input. */ + __IO uint32_t DBFEN; /*!< Enable debouncer input filters. */ + __I uint32_t RESERVED4[5]; + __IO uint32_t LEDPRE; /*!< Time LED is switched ON before the sample. */ + __I uint32_t ACCDBL; /*!< Accumulated double (error) transitions register. */ + __I uint32_t ACCDBLREAD; /*!< Snapshot of ACCDBL register. Value generated by the TASKS_READCLEACC + task. */ + __I uint32_t RESERVED5[684]; + __IO uint32_t POWER; /*!< Peripheral power control. */ +} NRF_QDEC_Type; + + +/* ================================================================================ */ +/* ================ LPCOMP ================ */ +/* ================================================================================ */ + + +/** + * @brief Low power comparator. (LPCOMP) + */ + +typedef struct { /*!< LPCOMP Structure */ + __O uint32_t TASKS_START; /*!< Start the comparator. */ + __O uint32_t TASKS_STOP; /*!< Stop the comparator. */ + __O uint32_t TASKS_SAMPLE; /*!< Sample comparator value. */ + __I uint32_t RESERVED0[61]; + __IO uint32_t EVENTS_READY; /*!< LPCOMP is ready and output is valid. */ + __IO uint32_t EVENTS_DOWN; /*!< Input voltage crossed the threshold going down. */ + __IO uint32_t EVENTS_UP; /*!< Input voltage crossed the threshold going up. */ + __IO uint32_t EVENTS_CROSS; /*!< Input voltage crossed the threshold in any direction. */ + __I uint32_t RESERVED1[60]; + __IO uint32_t SHORTS; /*!< Shortcuts for the LPCOMP. */ + __I uint32_t RESERVED2[64]; + __IO uint32_t INTENSET; /*!< Interrupt enable set register. */ + __IO uint32_t INTENCLR; /*!< Interrupt enable clear register. */ + __I uint32_t RESERVED3[61]; + __I uint32_t RESULT; /*!< Result of last compare. */ + __I uint32_t RESERVED4[63]; + __IO uint32_t ENABLE; /*!< Enable the LPCOMP. */ + __IO uint32_t PSEL; /*!< Input pin select. */ + __IO uint32_t REFSEL; /*!< Reference select. */ + __IO uint32_t EXTREFSEL; /*!< External reference select. */ + __I uint32_t RESERVED5[4]; + __IO uint32_t ANADETECT; /*!< Analog detect configuration. */ + __I uint32_t RESERVED6[694]; + __IO uint32_t POWER; /*!< Peripheral power control. */ +} NRF_LPCOMP_Type; + + +/* ================================================================================ */ +/* ================ SWI ================ */ +/* ================================================================================ */ + + +/** + * @brief SW Interrupts. (SWI) + */ + +typedef struct { /*!< SWI Structure */ + __I uint32_t UNUSED; /*!< Unused. */ +} NRF_SWI_Type; + + +/* ================================================================================ */ +/* ================ NVMC ================ */ +/* ================================================================================ */ + + +/** + * @brief Non Volatile Memory Controller. (NVMC) + */ + +typedef struct { /*!< NVMC Structure */ + __I uint32_t RESERVED0[256]; + __I uint32_t READY; /*!< Ready flag. */ + __I uint32_t RESERVED1[64]; + __IO uint32_t CONFIG; /*!< Configuration register. */ + + union { + __IO uint32_t ERASEPCR1; /*!< Register for erasing a non-protected non-volatile memory page. */ + __IO uint32_t ERASEPAGE; /*!< Register for erasing a non-protected non-volatile memory page. */ + }; + __IO uint32_t ERASEALL; /*!< Register for erasing all non-volatile user memory. */ + __IO uint32_t ERASEPCR0; /*!< Register for erasing a protected non-volatile memory page. */ + __IO uint32_t ERASEUICR; /*!< Register for start erasing User Information Congfiguration Registers. */ +} NRF_NVMC_Type; + + +/* ================================================================================ */ +/* ================ PPI ================ */ +/* ================================================================================ */ + + +/** + * @brief PPI controller. (PPI) + */ + +typedef struct { /*!< PPI Structure */ + PPI_TASKS_CHG_Type TASKS_CHG[4]; /*!< Channel group tasks. */ + __I uint32_t RESERVED0[312]; + __IO uint32_t CHEN; /*!< Channel enable. */ + __IO uint32_t CHENSET; /*!< Channel enable set. */ + __IO uint32_t CHENCLR; /*!< Channel enable clear. */ + __I uint32_t RESERVED1; + PPI_CH_Type CH[16]; /*!< PPI Channel. */ + __I uint32_t RESERVED2[156]; + __IO uint32_t CHG[4]; /*!< Channel group configuration. */ +} NRF_PPI_Type; + + +/* ================================================================================ */ +/* ================ FICR ================ */ +/* ================================================================================ */ + + +/** + * @brief Factory Information Configuration. (FICR) + */ + +typedef struct { /*!< FICR Structure */ + __I uint32_t RESERVED0[4]; + __I uint32_t CODEPAGESIZE; /*!< Code memory page size in bytes. */ + __I uint32_t CODESIZE; /*!< Code memory size in pages. */ + __I uint32_t RESERVED1[4]; + __I uint32_t CLENR0; /*!< Length of code region 0 in bytes. */ + __I uint32_t PPFC; /*!< Pre-programmed factory code present. */ + __I uint32_t RESERVED2; + __I uint32_t NUMRAMBLOCK; /*!< Number of individualy controllable RAM blocks. */ + + union { + __I uint32_t SIZERAMBLOCK[4]; /*!< Deprecated array of size of RAM block in bytes. This name is + kept for backward compatinility purposes. Use SIZERAMBLOCKS + instead. */ + __I uint32_t SIZERAMBLOCKS; /*!< Size of RAM blocks in bytes. */ + }; + __I uint32_t RESERVED3[5]; + __I uint32_t CONFIGID; /*!< Configuration identifier. */ + __I uint32_t DEVICEID[2]; /*!< Device identifier. */ + __I uint32_t RESERVED4[6]; + __I uint32_t ER[4]; /*!< Encryption root. */ + __I uint32_t IR[4]; /*!< Identity root. */ + __I uint32_t DEVICEADDRTYPE; /*!< Device address type. */ + __I uint32_t DEVICEADDR[2]; /*!< Device address. */ + __I uint32_t OVERRIDEEN; /*!< Radio calibration override enable. */ + __I uint32_t NRF_1MBIT[5]; /*!< Override values for the OVERRIDEn registers in RADIO for NRF_1Mbit + mode. */ + __I uint32_t RESERVED5[10]; + __I uint32_t BLE_1MBIT[5]; /*!< Override values for the OVERRIDEn registers in RADIO for BLE_1Mbit + mode. */ +} NRF_FICR_Type; + + +/* ================================================================================ */ +/* ================ UICR ================ */ +/* ================================================================================ */ + + +/** + * @brief User Information Configuration. (UICR) + */ + +typedef struct { /*!< UICR Structure */ + __IO uint32_t CLENR0; /*!< Length of code region 0. */ + __IO uint32_t RBPCONF; /*!< Readback protection configuration. */ + __IO uint32_t XTALFREQ; /*!< Reset value for CLOCK XTALFREQ register. */ + __I uint32_t RESERVED0; + __I uint32_t FWID; /*!< Firmware ID. */ + + union { + __IO uint32_t NRFFW[15]; /*!< Reserved for Nordic firmware design. */ + __IO uint32_t BOOTLOADERADDR; /*!< Bootloader start address. */ + }; + __IO uint32_t NRFHW[12]; /*!< Reserved for Nordic hardware design. */ + __IO uint32_t CUSTOMER[32]; /*!< Reserved for customer. */ +} NRF_UICR_Type; + + +/* ================================================================================ */ +/* ================ GPIO ================ */ +/* ================================================================================ */ + + +/** + * @brief General purpose input and output. (GPIO) + */ + +typedef struct { /*!< GPIO Structure */ + __I uint32_t RESERVED0[321]; + __IO uint32_t OUT; /*!< Write GPIO port. */ + __IO uint32_t OUTSET; /*!< Set individual bits in GPIO port. */ + __IO uint32_t OUTCLR; /*!< Clear individual bits in GPIO port. */ + __I uint32_t IN; /*!< Read GPIO port. */ + __IO uint32_t DIR; /*!< Direction of GPIO pins. */ + __IO uint32_t DIRSET; /*!< DIR set register. */ + __IO uint32_t DIRCLR; /*!< DIR clear register. */ + __I uint32_t RESERVED1[120]; + __IO uint32_t PIN_CNF[32]; /*!< Configuration of GPIO pins. */ +} NRF_GPIO_Type; + + +/* -------------------- End of section using anonymous unions ------------------- */ +#if defined(__CC_ARM) + #pragma pop +#elif defined(__ICCARM__) + /* leave anonymous unions enabled */ +#elif defined(__GNUC__) + /* anonymous unions are enabled by default */ +#elif defined(__TMS470__) + /* anonymous unions are enabled by default */ +#elif defined(__TASKING__) + #pragma warning restore +#else + #warning Not supported compiler type +#endif + + + + +/* ================================================================================ */ +/* ================ Peripheral memory map ================ */ +/* ================================================================================ */ + +#define NRF_POWER_BASE 0x40000000UL +#define NRF_CLOCK_BASE 0x40000000UL +#define NRF_MPU_BASE 0x40000000UL +#define NRF_PU_BASE 0x40000000UL +#define NRF_AMLI_BASE 0x40000000UL +#define NRF_RADIO_BASE 0x40001000UL +#define NRF_UART0_BASE 0x40002000UL +#define NRF_SPI0_BASE 0x40003000UL +#define NRF_TWI0_BASE 0x40003000UL +#define NRF_SPI1_BASE 0x40004000UL +#define NRF_TWI1_BASE 0x40004000UL +#define NRF_SPIS1_BASE 0x40004000UL +#define NRF_SPIM1_BASE 0x40004000UL +#define NRF_GPIOTE_BASE 0x40006000UL +#define NRF_ADC_BASE 0x40007000UL +#define NRF_TIMER0_BASE 0x40008000UL +#define NRF_TIMER1_BASE 0x40009000UL +#define NRF_TIMER2_BASE 0x4000A000UL +#define NRF_RTC0_BASE 0x4000B000UL +#define NRF_TEMP_BASE 0x4000C000UL +#define NRF_RNG_BASE 0x4000D000UL +#define NRF_ECB_BASE 0x4000E000UL +#define NRF_AAR_BASE 0x4000F000UL +#define NRF_CCM_BASE 0x4000F000UL +#define NRF_WDT_BASE 0x40010000UL +#define NRF_RTC1_BASE 0x40011000UL +#define NRF_QDEC_BASE 0x40012000UL +#define NRF_LPCOMP_BASE 0x40013000UL +#define NRF_SWI_BASE 0x40014000UL +#define NRF_NVMC_BASE 0x4001E000UL +#define NRF_PPI_BASE 0x4001F000UL +#define NRF_FICR_BASE 0x10000000UL +#define NRF_UICR_BASE 0x10001000UL +#define NRF_GPIO_BASE 0x50000000UL + + +/* ================================================================================ */ +/* ================ Peripheral declaration ================ */ +/* ================================================================================ */ + +#define NRF_POWER ((NRF_POWER_Type *) NRF_POWER_BASE) +#define NRF_CLOCK ((NRF_CLOCK_Type *) NRF_CLOCK_BASE) +#define NRF_MPU ((NRF_MPU_Type *) NRF_MPU_BASE) +#define NRF_PU ((NRF_PU_Type *) NRF_PU_BASE) +#define NRF_AMLI ((NRF_AMLI_Type *) NRF_AMLI_BASE) +#define NRF_RADIO ((NRF_RADIO_Type *) NRF_RADIO_BASE) +#define NRF_UART0 ((NRF_UART_Type *) NRF_UART0_BASE) +#define NRF_SPI0 ((NRF_SPI_Type *) NRF_SPI0_BASE) +#define NRF_TWI0 ((NRF_TWI_Type *) NRF_TWI0_BASE) +#define NRF_SPI1 ((NRF_SPI_Type *) NRF_SPI1_BASE) +#define NRF_TWI1 ((NRF_TWI_Type *) NRF_TWI1_BASE) +#define NRF_SPIS1 ((NRF_SPIS_Type *) NRF_SPIS1_BASE) +#define NRF_SPIM1 ((NRF_SPIM_Type *) NRF_SPIM1_BASE) +#define NRF_GPIOTE ((NRF_GPIOTE_Type *) NRF_GPIOTE_BASE) +#define NRF_ADC ((NRF_ADC_Type *) NRF_ADC_BASE) +#define NRF_TIMER0 ((NRF_TIMER_Type *) NRF_TIMER0_BASE) +#define NRF_TIMER1 ((NRF_TIMER_Type *) NRF_TIMER1_BASE) +#define NRF_TIMER2 ((NRF_TIMER_Type *) NRF_TIMER2_BASE) +#define NRF_RTC0 ((NRF_RTC_Type *) NRF_RTC0_BASE) +#define NRF_TEMP ((NRF_TEMP_Type *) NRF_TEMP_BASE) +#define NRF_RNG ((NRF_RNG_Type *) NRF_RNG_BASE) +#define NRF_ECB ((NRF_ECB_Type *) NRF_ECB_BASE) +#define NRF_AAR ((NRF_AAR_Type *) NRF_AAR_BASE) +#define NRF_CCM ((NRF_CCM_Type *) NRF_CCM_BASE) +#define NRF_WDT ((NRF_WDT_Type *) NRF_WDT_BASE) +#define NRF_RTC1 ((NRF_RTC_Type *) NRF_RTC1_BASE) +#define NRF_QDEC ((NRF_QDEC_Type *) NRF_QDEC_BASE) +#define NRF_LPCOMP ((NRF_LPCOMP_Type *) NRF_LPCOMP_BASE) +#define NRF_SWI ((NRF_SWI_Type *) NRF_SWI_BASE) +#define NRF_NVMC ((NRF_NVMC_Type *) NRF_NVMC_BASE) +#define NRF_PPI ((NRF_PPI_Type *) NRF_PPI_BASE) +#define NRF_FICR ((NRF_FICR_Type *) NRF_FICR_BASE) +#define NRF_UICR ((NRF_UICR_Type *) NRF_UICR_BASE) +#define NRF_GPIO ((NRF_GPIO_Type *) NRF_GPIO_BASE) + + +/** @} */ /* End of group Device_Peripheral_Registers */ +/** @} */ /* End of group nrf51 */ +/** @} */ /* End of group Nordic Semiconductor */ + +#ifdef __cplusplus +} +#endif + + +#endif /* nrf51_H */ + diff --git a/source/nordic_sdk/components/drivers_nrf/hal/nrf51_bitfields.h b/source/nordic_sdk/components/device/nrf51_bitfields.h similarity index 97% rename from source/nordic_sdk/components/drivers_nrf/hal/nrf51_bitfields.h rename to source/nordic_sdk/components/device/nrf51_bitfields.h index 930bda5..894e303 100644 --- a/source/nordic_sdk/components/drivers_nrf/hal/nrf51_bitfields.h +++ b/source/nordic_sdk/components/device/nrf51_bitfields.h @@ -1,7137 +1,7073 @@ -/* - * Copyright (c) Nordic Semiconductor ASA - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this - * list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * 3. Neither the name of Nordic Semiconductor ASA nor the names of other - * contributors to this software may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ -#ifndef __NRF51_BITS_H -#define __NRF51_BITS_H - -/*lint ++flb "Enter library region */ - -#include - -/* Peripheral: AAR */ -/* Description: Accelerated Address Resolver. */ - -/* Register: AAR_INTENSET */ -/* Description: Interrupt enable set register. */ - -/* Bit 2 : Enable interrupt on NOTRESOLVED event. */ -#define AAR_INTENSET_NOTRESOLVED_Pos (2UL) /*!< Position of NOTRESOLVED field. */ -#define AAR_INTENSET_NOTRESOLVED_Msk (0x1UL << AAR_INTENSET_NOTRESOLVED_Pos) /*!< Bit mask of NOTRESOLVED field. */ -#define AAR_INTENSET_NOTRESOLVED_Disabled (0UL) /*!< Interrupt disabled. */ -#define AAR_INTENSET_NOTRESOLVED_Enabled (1UL) /*!< Interrupt enabled. */ -#define AAR_INTENSET_NOTRESOLVED_Set (1UL) /*!< Enable interrupt on write. */ - -/* Bit 1 : Enable interrupt on RESOLVED event. */ -#define AAR_INTENSET_RESOLVED_Pos (1UL) /*!< Position of RESOLVED field. */ -#define AAR_INTENSET_RESOLVED_Msk (0x1UL << AAR_INTENSET_RESOLVED_Pos) /*!< Bit mask of RESOLVED field. */ -#define AAR_INTENSET_RESOLVED_Disabled (0UL) /*!< Interrupt disabled. */ -#define AAR_INTENSET_RESOLVED_Enabled (1UL) /*!< Interrupt enabled. */ -#define AAR_INTENSET_RESOLVED_Set (1UL) /*!< Enable interrupt on write. */ - -/* Bit 0 : Enable interrupt on END event. */ -#define AAR_INTENSET_END_Pos (0UL) /*!< Position of END field. */ -#define AAR_INTENSET_END_Msk (0x1UL << AAR_INTENSET_END_Pos) /*!< Bit mask of END field. */ -#define AAR_INTENSET_END_Disabled (0UL) /*!< Interrupt disabled. */ -#define AAR_INTENSET_END_Enabled (1UL) /*!< Interrupt enabled. */ -#define AAR_INTENSET_END_Set (1UL) /*!< Enable interrupt on write. */ - -/* Register: AAR_INTENCLR */ -/* Description: Interrupt enable clear register. */ - -/* Bit 2 : Disable interrupt on NOTRESOLVED event. */ -#define AAR_INTENCLR_NOTRESOLVED_Pos (2UL) /*!< Position of NOTRESOLVED field. */ -#define AAR_INTENCLR_NOTRESOLVED_Msk (0x1UL << AAR_INTENCLR_NOTRESOLVED_Pos) /*!< Bit mask of NOTRESOLVED field. */ -#define AAR_INTENCLR_NOTRESOLVED_Disabled (0UL) /*!< Interrupt disabled. */ -#define AAR_INTENCLR_NOTRESOLVED_Enabled (1UL) /*!< Interrupt enabled. */ -#define AAR_INTENCLR_NOTRESOLVED_Clear (1UL) /*!< Disable interrupt on write. */ - -/* Bit 1 : Disable interrupt on RESOLVED event. */ -#define AAR_INTENCLR_RESOLVED_Pos (1UL) /*!< Position of RESOLVED field. */ -#define AAR_INTENCLR_RESOLVED_Msk (0x1UL << AAR_INTENCLR_RESOLVED_Pos) /*!< Bit mask of RESOLVED field. */ -#define AAR_INTENCLR_RESOLVED_Disabled (0UL) /*!< Interrupt disabled. */ -#define AAR_INTENCLR_RESOLVED_Enabled (1UL) /*!< Interrupt enabled. */ -#define AAR_INTENCLR_RESOLVED_Clear (1UL) /*!< Disable interrupt on write. */ - -/* Bit 0 : Disable interrupt on ENDKSGEN event. */ -#define AAR_INTENCLR_END_Pos (0UL) /*!< Position of END field. */ -#define AAR_INTENCLR_END_Msk (0x1UL << AAR_INTENCLR_END_Pos) /*!< Bit mask of END field. */ -#define AAR_INTENCLR_END_Disabled (0UL) /*!< Interrupt disabled. */ -#define AAR_INTENCLR_END_Enabled (1UL) /*!< Interrupt enabled. */ -#define AAR_INTENCLR_END_Clear (1UL) /*!< Disable interrupt on write. */ - -/* Register: AAR_STATUS */ -/* Description: Resolution status. */ - -/* Bits 3..0 : The IRK used last time an address was resolved. */ -#define AAR_STATUS_STATUS_Pos (0UL) /*!< Position of STATUS field. */ -#define AAR_STATUS_STATUS_Msk (0xFUL << AAR_STATUS_STATUS_Pos) /*!< Bit mask of STATUS field. */ - -/* Register: AAR_ENABLE */ -/* Description: Enable AAR. */ - -/* Bits 1..0 : Enable AAR. */ -#define AAR_ENABLE_ENABLE_Pos (0UL) /*!< Position of ENABLE field. */ -#define AAR_ENABLE_ENABLE_Msk (0x3UL << AAR_ENABLE_ENABLE_Pos) /*!< Bit mask of ENABLE field. */ -#define AAR_ENABLE_ENABLE_Disabled (0x00UL) /*!< Disabled AAR. */ -#define AAR_ENABLE_ENABLE_Enabled (0x03UL) /*!< Enable AAR. */ - -/* Register: AAR_NIRK */ -/* Description: Number of Identity root Keys in the IRK data structure. */ - -/* Bits 4..0 : Number of Identity root Keys in the IRK data structure. */ -#define AAR_NIRK_NIRK_Pos (0UL) /*!< Position of NIRK field. */ -#define AAR_NIRK_NIRK_Msk (0x1FUL << AAR_NIRK_NIRK_Pos) /*!< Bit mask of NIRK field. */ - -/* Register: AAR_POWER */ -/* Description: Peripheral power control. */ - -/* Bit 0 : Peripheral power control. */ -#define AAR_POWER_POWER_Pos (0UL) /*!< Position of POWER field. */ -#define AAR_POWER_POWER_Msk (0x1UL << AAR_POWER_POWER_Pos) /*!< Bit mask of POWER field. */ -#define AAR_POWER_POWER_Disabled (0UL) /*!< Module power disabled. */ -#define AAR_POWER_POWER_Enabled (1UL) /*!< Module power enabled. */ - - -/* Peripheral: ADC */ -/* Description: Analog to digital converter. */ - -/* Register: ADC_INTENSET */ -/* Description: Interrupt enable set register. */ - -/* Bit 0 : Enable interrupt on END event. */ -#define ADC_INTENSET_END_Pos (0UL) /*!< Position of END field. */ -#define ADC_INTENSET_END_Msk (0x1UL << ADC_INTENSET_END_Pos) /*!< Bit mask of END field. */ -#define ADC_INTENSET_END_Disabled (0UL) /*!< Interrupt disabled. */ -#define ADC_INTENSET_END_Enabled (1UL) /*!< Interrupt enabled. */ -#define ADC_INTENSET_END_Set (1UL) /*!< Enable interrupt on write. */ - -/* Register: ADC_INTENCLR */ -/* Description: Interrupt enable clear register. */ - -/* Bit 0 : Disable interrupt on END event. */ -#define ADC_INTENCLR_END_Pos (0UL) /*!< Position of END field. */ -#define ADC_INTENCLR_END_Msk (0x1UL << ADC_INTENCLR_END_Pos) /*!< Bit mask of END field. */ -#define ADC_INTENCLR_END_Disabled (0UL) /*!< Interrupt disabled. */ -#define ADC_INTENCLR_END_Enabled (1UL) /*!< Interrupt enabled. */ -#define ADC_INTENCLR_END_Clear (1UL) /*!< Disable interrupt on write. */ - -/* Register: ADC_BUSY */ -/* Description: ADC busy register. */ - -/* Bit 0 : ADC busy register. */ -#define ADC_BUSY_BUSY_Pos (0UL) /*!< Position of BUSY field. */ -#define ADC_BUSY_BUSY_Msk (0x1UL << ADC_BUSY_BUSY_Pos) /*!< Bit mask of BUSY field. */ -#define ADC_BUSY_BUSY_Ready (0UL) /*!< No ongoing ADC conversion is taking place. ADC is ready. */ -#define ADC_BUSY_BUSY_Busy (1UL) /*!< An ADC conversion is taking place. ADC is busy. */ - -/* Register: ADC_ENABLE */ -/* Description: ADC enable. */ - -/* Bits 1..0 : ADC enable. */ -#define ADC_ENABLE_ENABLE_Pos (0UL) /*!< Position of ENABLE field. */ -#define ADC_ENABLE_ENABLE_Msk (0x3UL << ADC_ENABLE_ENABLE_Pos) /*!< Bit mask of ENABLE field. */ -#define ADC_ENABLE_ENABLE_Disabled (0x00UL) /*!< ADC is disabled. */ -#define ADC_ENABLE_ENABLE_Enabled (0x01UL) /*!< ADC is enabled. If an analog input pin is selected as source of the conversion, the selected pin is configured as an analog input. */ - -/* Register: ADC_CONFIG */ -/* Description: ADC configuration register. */ - -/* Bits 17..16 : ADC external reference pin selection. */ -#define ADC_CONFIG_EXTREFSEL_Pos (16UL) /*!< Position of EXTREFSEL field. */ -#define ADC_CONFIG_EXTREFSEL_Msk (0x3UL << ADC_CONFIG_EXTREFSEL_Pos) /*!< Bit mask of EXTREFSEL field. */ -#define ADC_CONFIG_EXTREFSEL_None (0UL) /*!< Analog external reference inputs disabled. */ -#define ADC_CONFIG_EXTREFSEL_AnalogReference0 (1UL) /*!< Use analog reference 0 as reference. */ -#define ADC_CONFIG_EXTREFSEL_AnalogReference1 (2UL) /*!< Use analog reference 1 as reference. */ - -/* Bits 15..8 : ADC analog pin selection. */ -#define ADC_CONFIG_PSEL_Pos (8UL) /*!< Position of PSEL field. */ -#define ADC_CONFIG_PSEL_Msk (0xFFUL << ADC_CONFIG_PSEL_Pos) /*!< Bit mask of PSEL field. */ -#define ADC_CONFIG_PSEL_Disabled (0UL) /*!< Analog input pins disabled. */ -#define ADC_CONFIG_PSEL_AnalogInput0 (1UL) /*!< Use analog input 0 as analog input. */ -#define ADC_CONFIG_PSEL_AnalogInput1 (2UL) /*!< Use analog input 1 as analog input. */ -#define ADC_CONFIG_PSEL_AnalogInput2 (4UL) /*!< Use analog input 2 as analog input. */ -#define ADC_CONFIG_PSEL_AnalogInput3 (8UL) /*!< Use analog input 3 as analog input. */ -#define ADC_CONFIG_PSEL_AnalogInput4 (16UL) /*!< Use analog input 4 as analog input. */ -#define ADC_CONFIG_PSEL_AnalogInput5 (32UL) /*!< Use analog input 5 as analog input. */ -#define ADC_CONFIG_PSEL_AnalogInput6 (64UL) /*!< Use analog input 6 as analog input. */ -#define ADC_CONFIG_PSEL_AnalogInput7 (128UL) /*!< Use analog input 7 as analog input. */ - -/* Bits 6..5 : ADC reference selection. */ -#define ADC_CONFIG_REFSEL_Pos (5UL) /*!< Position of REFSEL field. */ -#define ADC_CONFIG_REFSEL_Msk (0x3UL << ADC_CONFIG_REFSEL_Pos) /*!< Bit mask of REFSEL field. */ -#define ADC_CONFIG_REFSEL_VBG (0x00UL) /*!< Use internal 1.2V bandgap voltage as reference for conversion. */ -#define ADC_CONFIG_REFSEL_External (0x01UL) /*!< Use external source configured by EXTREFSEL as reference for conversion. */ -#define ADC_CONFIG_REFSEL_SupplyOneHalfPrescaling (0x02UL) /*!< Use supply voltage with 1/2 prescaling as reference for conversion. Only usable when supply voltage is between 1.7V and 2.6V. */ -#define ADC_CONFIG_REFSEL_SupplyOneThirdPrescaling (0x03UL) /*!< Use supply voltage with 1/3 prescaling as reference for conversion. Only usable when supply voltage is between 2.5V and 3.6V. */ - -/* Bits 4..2 : ADC input selection. */ -#define ADC_CONFIG_INPSEL_Pos (2UL) /*!< Position of INPSEL field. */ -#define ADC_CONFIG_INPSEL_Msk (0x7UL << ADC_CONFIG_INPSEL_Pos) /*!< Bit mask of INPSEL field. */ -#define ADC_CONFIG_INPSEL_AnalogInputNoPrescaling (0x00UL) /*!< Analog input specified by PSEL with no prescaling used as input for the conversion. */ -#define ADC_CONFIG_INPSEL_AnalogInputTwoThirdsPrescaling (0x01UL) /*!< Analog input specified by PSEL with 2/3 prescaling used as input for the conversion. */ -#define ADC_CONFIG_INPSEL_AnalogInputOneThirdPrescaling (0x02UL) /*!< Analog input specified by PSEL with 1/3 prescaling used as input for the conversion. */ -#define ADC_CONFIG_INPSEL_SupplyTwoThirdsPrescaling (0x05UL) /*!< Supply voltage with 2/3 prescaling used as input for the conversion. */ -#define ADC_CONFIG_INPSEL_SupplyOneThirdPrescaling (0x06UL) /*!< Supply voltage with 1/3 prescaling used as input for the conversion. */ - -/* Bits 1..0 : ADC resolution. */ -#define ADC_CONFIG_RES_Pos (0UL) /*!< Position of RES field. */ -#define ADC_CONFIG_RES_Msk (0x3UL << ADC_CONFIG_RES_Pos) /*!< Bit mask of RES field. */ -#define ADC_CONFIG_RES_8bit (0x00UL) /*!< 8bit ADC resolution. */ -#define ADC_CONFIG_RES_9bit (0x01UL) /*!< 9bit ADC resolution. */ -#define ADC_CONFIG_RES_10bit (0x02UL) /*!< 10bit ADC resolution. */ - -/* Register: ADC_RESULT */ -/* Description: Result of ADC conversion. */ - -/* Bits 9..0 : Result of ADC conversion. */ -#define ADC_RESULT_RESULT_Pos (0UL) /*!< Position of RESULT field. */ -#define ADC_RESULT_RESULT_Msk (0x3FFUL << ADC_RESULT_RESULT_Pos) /*!< Bit mask of RESULT field. */ - -/* Register: ADC_POWER */ -/* Description: Peripheral power control. */ - -/* Bit 0 : Peripheral power control. */ -#define ADC_POWER_POWER_Pos (0UL) /*!< Position of POWER field. */ -#define ADC_POWER_POWER_Msk (0x1UL << ADC_POWER_POWER_Pos) /*!< Bit mask of POWER field. */ -#define ADC_POWER_POWER_Disabled (0UL) /*!< Module power disabled. */ -#define ADC_POWER_POWER_Enabled (1UL) /*!< Module power enabled. */ - - -/* Peripheral: AMLI */ -/* Description: AHB Multi-Layer Interface. */ - -/* Register: AMLI_RAMPRI_CPU0 */ -/* Description: Configurable priority configuration register for CPU0. */ - -/* Bits 31..28 : Configuration field for RAM block 7. */ -#define AMLI_RAMPRI_CPU0_RAM7_Pos (28UL) /*!< Position of RAM7 field. */ -#define AMLI_RAMPRI_CPU0_RAM7_Msk (0xFUL << AMLI_RAMPRI_CPU0_RAM7_Pos) /*!< Bit mask of RAM7 field. */ -#define AMLI_RAMPRI_CPU0_RAM7_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_CPU0_RAM7_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_CPU0_RAM7_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_CPU0_RAM7_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_CPU0_RAM7_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_CPU0_RAM7_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_CPU0_RAM7_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_CPU0_RAM7_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 27..24 : Configuration field for RAM block 6. */ -#define AMLI_RAMPRI_CPU0_RAM6_Pos (24UL) /*!< Position of RAM6 field. */ -#define AMLI_RAMPRI_CPU0_RAM6_Msk (0xFUL << AMLI_RAMPRI_CPU0_RAM6_Pos) /*!< Bit mask of RAM6 field. */ -#define AMLI_RAMPRI_CPU0_RAM6_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_CPU0_RAM6_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_CPU0_RAM6_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_CPU0_RAM6_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_CPU0_RAM6_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_CPU0_RAM6_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_CPU0_RAM6_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_CPU0_RAM6_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 23..20 : Configuration field for RAM block 5. */ -#define AMLI_RAMPRI_CPU0_RAM5_Pos (20UL) /*!< Position of RAM5 field. */ -#define AMLI_RAMPRI_CPU0_RAM5_Msk (0xFUL << AMLI_RAMPRI_CPU0_RAM5_Pos) /*!< Bit mask of RAM5 field. */ -#define AMLI_RAMPRI_CPU0_RAM5_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_CPU0_RAM5_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_CPU0_RAM5_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_CPU0_RAM5_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_CPU0_RAM5_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_CPU0_RAM5_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_CPU0_RAM5_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_CPU0_RAM5_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 19..16 : Configuration field for RAM block 4. */ -#define AMLI_RAMPRI_CPU0_RAM4_Pos (16UL) /*!< Position of RAM4 field. */ -#define AMLI_RAMPRI_CPU0_RAM4_Msk (0xFUL << AMLI_RAMPRI_CPU0_RAM4_Pos) /*!< Bit mask of RAM4 field. */ -#define AMLI_RAMPRI_CPU0_RAM4_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_CPU0_RAM4_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_CPU0_RAM4_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_CPU0_RAM4_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_CPU0_RAM4_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_CPU0_RAM4_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_CPU0_RAM4_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_CPU0_RAM4_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 15..12 : Configuration field for RAM block 3. */ -#define AMLI_RAMPRI_CPU0_RAM3_Pos (12UL) /*!< Position of RAM3 field. */ -#define AMLI_RAMPRI_CPU0_RAM3_Msk (0xFUL << AMLI_RAMPRI_CPU0_RAM3_Pos) /*!< Bit mask of RAM3 field. */ -#define AMLI_RAMPRI_CPU0_RAM3_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_CPU0_RAM3_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_CPU0_RAM3_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_CPU0_RAM3_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_CPU0_RAM3_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_CPU0_RAM3_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_CPU0_RAM3_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_CPU0_RAM3_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 11..8 : Configuration field for RAM block 2. */ -#define AMLI_RAMPRI_CPU0_RAM2_Pos (8UL) /*!< Position of RAM2 field. */ -#define AMLI_RAMPRI_CPU0_RAM2_Msk (0xFUL << AMLI_RAMPRI_CPU0_RAM2_Pos) /*!< Bit mask of RAM2 field. */ -#define AMLI_RAMPRI_CPU0_RAM2_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_CPU0_RAM2_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_CPU0_RAM2_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_CPU0_RAM2_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_CPU0_RAM2_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_CPU0_RAM2_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_CPU0_RAM2_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_CPU0_RAM2_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 7..4 : Configuration field for RAM block 1. */ -#define AMLI_RAMPRI_CPU0_RAM1_Pos (4UL) /*!< Position of RAM1 field. */ -#define AMLI_RAMPRI_CPU0_RAM1_Msk (0xFUL << AMLI_RAMPRI_CPU0_RAM1_Pos) /*!< Bit mask of RAM1 field. */ -#define AMLI_RAMPRI_CPU0_RAM1_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_CPU0_RAM1_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_CPU0_RAM1_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_CPU0_RAM1_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_CPU0_RAM1_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_CPU0_RAM1_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_CPU0_RAM1_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_CPU0_RAM1_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 3..0 : Configuration field for RAM block 0. */ -#define AMLI_RAMPRI_CPU0_RAM0_Pos (0UL) /*!< Position of RAM0 field. */ -#define AMLI_RAMPRI_CPU0_RAM0_Msk (0xFUL << AMLI_RAMPRI_CPU0_RAM0_Pos) /*!< Bit mask of RAM0 field. */ -#define AMLI_RAMPRI_CPU0_RAM0_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_CPU0_RAM0_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_CPU0_RAM0_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_CPU0_RAM0_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_CPU0_RAM0_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_CPU0_RAM0_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_CPU0_RAM0_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_CPU0_RAM0_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Register: AMLI_RAMPRI_SPIS1 */ -/* Description: Configurable priority configuration register for SPIS1. */ - -/* Bits 31..28 : Configuration field for RAM block 7. */ -#define AMLI_RAMPRI_SPIS1_RAM7_Pos (28UL) /*!< Position of RAM7 field. */ -#define AMLI_RAMPRI_SPIS1_RAM7_Msk (0xFUL << AMLI_RAMPRI_SPIS1_RAM7_Pos) /*!< Bit mask of RAM7 field. */ -#define AMLI_RAMPRI_SPIS1_RAM7_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_SPIS1_RAM7_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_SPIS1_RAM7_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_SPIS1_RAM7_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_SPIS1_RAM7_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_SPIS1_RAM7_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_SPIS1_RAM7_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_SPIS1_RAM7_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 27..24 : Configuration field for RAM block 6. */ -#define AMLI_RAMPRI_SPIS1_RAM6_Pos (24UL) /*!< Position of RAM6 field. */ -#define AMLI_RAMPRI_SPIS1_RAM6_Msk (0xFUL << AMLI_RAMPRI_SPIS1_RAM6_Pos) /*!< Bit mask of RAM6 field. */ -#define AMLI_RAMPRI_SPIS1_RAM6_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_SPIS1_RAM6_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_SPIS1_RAM6_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_SPIS1_RAM6_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_SPIS1_RAM6_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_SPIS1_RAM6_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_SPIS1_RAM6_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_SPIS1_RAM6_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 23..20 : Configuration field for RAM block 5. */ -#define AMLI_RAMPRI_SPIS1_RAM5_Pos (20UL) /*!< Position of RAM5 field. */ -#define AMLI_RAMPRI_SPIS1_RAM5_Msk (0xFUL << AMLI_RAMPRI_SPIS1_RAM5_Pos) /*!< Bit mask of RAM5 field. */ -#define AMLI_RAMPRI_SPIS1_RAM5_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_SPIS1_RAM5_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_SPIS1_RAM5_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_SPIS1_RAM5_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_SPIS1_RAM5_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_SPIS1_RAM5_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_SPIS1_RAM5_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_SPIS1_RAM5_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 19..16 : Configuration field for RAM block 4. */ -#define AMLI_RAMPRI_SPIS1_RAM4_Pos (16UL) /*!< Position of RAM4 field. */ -#define AMLI_RAMPRI_SPIS1_RAM4_Msk (0xFUL << AMLI_RAMPRI_SPIS1_RAM4_Pos) /*!< Bit mask of RAM4 field. */ -#define AMLI_RAMPRI_SPIS1_RAM4_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_SPIS1_RAM4_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_SPIS1_RAM4_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_SPIS1_RAM4_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_SPIS1_RAM4_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_SPIS1_RAM4_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_SPIS1_RAM4_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_SPIS1_RAM4_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 15..12 : Configuration field for RAM block 3. */ -#define AMLI_RAMPRI_SPIS1_RAM3_Pos (12UL) /*!< Position of RAM3 field. */ -#define AMLI_RAMPRI_SPIS1_RAM3_Msk (0xFUL << AMLI_RAMPRI_SPIS1_RAM3_Pos) /*!< Bit mask of RAM3 field. */ -#define AMLI_RAMPRI_SPIS1_RAM3_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_SPIS1_RAM3_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_SPIS1_RAM3_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_SPIS1_RAM3_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_SPIS1_RAM3_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_SPIS1_RAM3_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_SPIS1_RAM3_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_SPIS1_RAM3_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 11..8 : Configuration field for RAM block 2. */ -#define AMLI_RAMPRI_SPIS1_RAM2_Pos (8UL) /*!< Position of RAM2 field. */ -#define AMLI_RAMPRI_SPIS1_RAM2_Msk (0xFUL << AMLI_RAMPRI_SPIS1_RAM2_Pos) /*!< Bit mask of RAM2 field. */ -#define AMLI_RAMPRI_SPIS1_RAM2_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_SPIS1_RAM2_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_SPIS1_RAM2_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_SPIS1_RAM2_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_SPIS1_RAM2_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_SPIS1_RAM2_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_SPIS1_RAM2_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_SPIS1_RAM2_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 7..4 : Configuration field for RAM block 1. */ -#define AMLI_RAMPRI_SPIS1_RAM1_Pos (4UL) /*!< Position of RAM1 field. */ -#define AMLI_RAMPRI_SPIS1_RAM1_Msk (0xFUL << AMLI_RAMPRI_SPIS1_RAM1_Pos) /*!< Bit mask of RAM1 field. */ -#define AMLI_RAMPRI_SPIS1_RAM1_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_SPIS1_RAM1_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_SPIS1_RAM1_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_SPIS1_RAM1_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_SPIS1_RAM1_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_SPIS1_RAM1_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_SPIS1_RAM1_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_SPIS1_RAM1_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 3..0 : Configuration field for RAM block 0. */ -#define AMLI_RAMPRI_SPIS1_RAM0_Pos (0UL) /*!< Position of RAM0 field. */ -#define AMLI_RAMPRI_SPIS1_RAM0_Msk (0xFUL << AMLI_RAMPRI_SPIS1_RAM0_Pos) /*!< Bit mask of RAM0 field. */ -#define AMLI_RAMPRI_SPIS1_RAM0_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_SPIS1_RAM0_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_SPIS1_RAM0_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_SPIS1_RAM0_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_SPIS1_RAM0_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_SPIS1_RAM0_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_SPIS1_RAM0_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_SPIS1_RAM0_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Register: AMLI_RAMPRI_RADIO */ -/* Description: Configurable priority configuration register for RADIO. */ - -/* Bits 31..28 : Configuration field for RAM block 7. */ -#define AMLI_RAMPRI_RADIO_RAM7_Pos (28UL) /*!< Position of RAM7 field. */ -#define AMLI_RAMPRI_RADIO_RAM7_Msk (0xFUL << AMLI_RAMPRI_RADIO_RAM7_Pos) /*!< Bit mask of RAM7 field. */ -#define AMLI_RAMPRI_RADIO_RAM7_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_RADIO_RAM7_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_RADIO_RAM7_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_RADIO_RAM7_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_RADIO_RAM7_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_RADIO_RAM7_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_RADIO_RAM7_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_RADIO_RAM7_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 27..24 : Configuration field for RAM block 6. */ -#define AMLI_RAMPRI_RADIO_RAM6_Pos (24UL) /*!< Position of RAM6 field. */ -#define AMLI_RAMPRI_RADIO_RAM6_Msk (0xFUL << AMLI_RAMPRI_RADIO_RAM6_Pos) /*!< Bit mask of RAM6 field. */ -#define AMLI_RAMPRI_RADIO_RAM6_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_RADIO_RAM6_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_RADIO_RAM6_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_RADIO_RAM6_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_RADIO_RAM6_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_RADIO_RAM6_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_RADIO_RAM6_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_RADIO_RAM6_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 23..20 : Configuration field for RAM block 5. */ -#define AMLI_RAMPRI_RADIO_RAM5_Pos (20UL) /*!< Position of RAM5 field. */ -#define AMLI_RAMPRI_RADIO_RAM5_Msk (0xFUL << AMLI_RAMPRI_RADIO_RAM5_Pos) /*!< Bit mask of RAM5 field. */ -#define AMLI_RAMPRI_RADIO_RAM5_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_RADIO_RAM5_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_RADIO_RAM5_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_RADIO_RAM5_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_RADIO_RAM5_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_RADIO_RAM5_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_RADIO_RAM5_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_RADIO_RAM5_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 19..16 : Configuration field for RAM block 4. */ -#define AMLI_RAMPRI_RADIO_RAM4_Pos (16UL) /*!< Position of RAM4 field. */ -#define AMLI_RAMPRI_RADIO_RAM4_Msk (0xFUL << AMLI_RAMPRI_RADIO_RAM4_Pos) /*!< Bit mask of RAM4 field. */ -#define AMLI_RAMPRI_RADIO_RAM4_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_RADIO_RAM4_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_RADIO_RAM4_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_RADIO_RAM4_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_RADIO_RAM4_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_RADIO_RAM4_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_RADIO_RAM4_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_RADIO_RAM4_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 15..12 : Configuration field for RAM block 3. */ -#define AMLI_RAMPRI_RADIO_RAM3_Pos (12UL) /*!< Position of RAM3 field. */ -#define AMLI_RAMPRI_RADIO_RAM3_Msk (0xFUL << AMLI_RAMPRI_RADIO_RAM3_Pos) /*!< Bit mask of RAM3 field. */ -#define AMLI_RAMPRI_RADIO_RAM3_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_RADIO_RAM3_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_RADIO_RAM3_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_RADIO_RAM3_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_RADIO_RAM3_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_RADIO_RAM3_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_RADIO_RAM3_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_RADIO_RAM3_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 11..8 : Configuration field for RAM block 2. */ -#define AMLI_RAMPRI_RADIO_RAM2_Pos (8UL) /*!< Position of RAM2 field. */ -#define AMLI_RAMPRI_RADIO_RAM2_Msk (0xFUL << AMLI_RAMPRI_RADIO_RAM2_Pos) /*!< Bit mask of RAM2 field. */ -#define AMLI_RAMPRI_RADIO_RAM2_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_RADIO_RAM2_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_RADIO_RAM2_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_RADIO_RAM2_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_RADIO_RAM2_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_RADIO_RAM2_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_RADIO_RAM2_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_RADIO_RAM2_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 7..4 : Configuration field for RAM block 1. */ -#define AMLI_RAMPRI_RADIO_RAM1_Pos (4UL) /*!< Position of RAM1 field. */ -#define AMLI_RAMPRI_RADIO_RAM1_Msk (0xFUL << AMLI_RAMPRI_RADIO_RAM1_Pos) /*!< Bit mask of RAM1 field. */ -#define AMLI_RAMPRI_RADIO_RAM1_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_RADIO_RAM1_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_RADIO_RAM1_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_RADIO_RAM1_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_RADIO_RAM1_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_RADIO_RAM1_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_RADIO_RAM1_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_RADIO_RAM1_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 3..0 : Configuration field for RAM block 0. */ -#define AMLI_RAMPRI_RADIO_RAM0_Pos (0UL) /*!< Position of RAM0 field. */ -#define AMLI_RAMPRI_RADIO_RAM0_Msk (0xFUL << AMLI_RAMPRI_RADIO_RAM0_Pos) /*!< Bit mask of RAM0 field. */ -#define AMLI_RAMPRI_RADIO_RAM0_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_RADIO_RAM0_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_RADIO_RAM0_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_RADIO_RAM0_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_RADIO_RAM0_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_RADIO_RAM0_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_RADIO_RAM0_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_RADIO_RAM0_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Register: AMLI_RAMPRI_ECB */ -/* Description: Configurable priority configuration register for ECB. */ - -/* Bits 31..28 : Configuration field for RAM block 7. */ -#define AMLI_RAMPRI_ECB_RAM7_Pos (28UL) /*!< Position of RAM7 field. */ -#define AMLI_RAMPRI_ECB_RAM7_Msk (0xFUL << AMLI_RAMPRI_ECB_RAM7_Pos) /*!< Bit mask of RAM7 field. */ -#define AMLI_RAMPRI_ECB_RAM7_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_ECB_RAM7_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_ECB_RAM7_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_ECB_RAM7_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_ECB_RAM7_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_ECB_RAM7_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_ECB_RAM7_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_ECB_RAM7_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 27..24 : Configuration field for RAM block 6. */ -#define AMLI_RAMPRI_ECB_RAM6_Pos (24UL) /*!< Position of RAM6 field. */ -#define AMLI_RAMPRI_ECB_RAM6_Msk (0xFUL << AMLI_RAMPRI_ECB_RAM6_Pos) /*!< Bit mask of RAM6 field. */ -#define AMLI_RAMPRI_ECB_RAM6_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_ECB_RAM6_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_ECB_RAM6_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_ECB_RAM6_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_ECB_RAM6_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_ECB_RAM6_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_ECB_RAM6_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_ECB_RAM6_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 23..20 : Configuration field for RAM block 5. */ -#define AMLI_RAMPRI_ECB_RAM5_Pos (20UL) /*!< Position of RAM5 field. */ -#define AMLI_RAMPRI_ECB_RAM5_Msk (0xFUL << AMLI_RAMPRI_ECB_RAM5_Pos) /*!< Bit mask of RAM5 field. */ -#define AMLI_RAMPRI_ECB_RAM5_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_ECB_RAM5_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_ECB_RAM5_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_ECB_RAM5_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_ECB_RAM5_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_ECB_RAM5_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_ECB_RAM5_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_ECB_RAM5_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 19..16 : Configuration field for RAM block 4. */ -#define AMLI_RAMPRI_ECB_RAM4_Pos (16UL) /*!< Position of RAM4 field. */ -#define AMLI_RAMPRI_ECB_RAM4_Msk (0xFUL << AMLI_RAMPRI_ECB_RAM4_Pos) /*!< Bit mask of RAM4 field. */ -#define AMLI_RAMPRI_ECB_RAM4_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_ECB_RAM4_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_ECB_RAM4_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_ECB_RAM4_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_ECB_RAM4_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_ECB_RAM4_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_ECB_RAM4_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_ECB_RAM4_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 15..12 : Configuration field for RAM block 3. */ -#define AMLI_RAMPRI_ECB_RAM3_Pos (12UL) /*!< Position of RAM3 field. */ -#define AMLI_RAMPRI_ECB_RAM3_Msk (0xFUL << AMLI_RAMPRI_ECB_RAM3_Pos) /*!< Bit mask of RAM3 field. */ -#define AMLI_RAMPRI_ECB_RAM3_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_ECB_RAM3_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_ECB_RAM3_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_ECB_RAM3_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_ECB_RAM3_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_ECB_RAM3_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_ECB_RAM3_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_ECB_RAM3_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 11..8 : Configuration field for RAM block 2. */ -#define AMLI_RAMPRI_ECB_RAM2_Pos (8UL) /*!< Position of RAM2 field. */ -#define AMLI_RAMPRI_ECB_RAM2_Msk (0xFUL << AMLI_RAMPRI_ECB_RAM2_Pos) /*!< Bit mask of RAM2 field. */ -#define AMLI_RAMPRI_ECB_RAM2_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_ECB_RAM2_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_ECB_RAM2_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_ECB_RAM2_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_ECB_RAM2_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_ECB_RAM2_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_ECB_RAM2_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_ECB_RAM2_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 7..4 : Configuration field for RAM block 1. */ -#define AMLI_RAMPRI_ECB_RAM1_Pos (4UL) /*!< Position of RAM1 field. */ -#define AMLI_RAMPRI_ECB_RAM1_Msk (0xFUL << AMLI_RAMPRI_ECB_RAM1_Pos) /*!< Bit mask of RAM1 field. */ -#define AMLI_RAMPRI_ECB_RAM1_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_ECB_RAM1_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_ECB_RAM1_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_ECB_RAM1_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_ECB_RAM1_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_ECB_RAM1_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_ECB_RAM1_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_ECB_RAM1_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 3..0 : Configuration field for RAM block 0. */ -#define AMLI_RAMPRI_ECB_RAM0_Pos (0UL) /*!< Position of RAM0 field. */ -#define AMLI_RAMPRI_ECB_RAM0_Msk (0xFUL << AMLI_RAMPRI_ECB_RAM0_Pos) /*!< Bit mask of RAM0 field. */ -#define AMLI_RAMPRI_ECB_RAM0_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_ECB_RAM0_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_ECB_RAM0_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_ECB_RAM0_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_ECB_RAM0_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_ECB_RAM0_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_ECB_RAM0_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_ECB_RAM0_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Register: AMLI_RAMPRI_CCM */ -/* Description: Configurable priority configuration register for CCM. */ - -/* Bits 31..28 : Configuration field for RAM block 7. */ -#define AMLI_RAMPRI_CCM_RAM7_Pos (28UL) /*!< Position of RAM7 field. */ -#define AMLI_RAMPRI_CCM_RAM7_Msk (0xFUL << AMLI_RAMPRI_CCM_RAM7_Pos) /*!< Bit mask of RAM7 field. */ -#define AMLI_RAMPRI_CCM_RAM7_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_CCM_RAM7_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_CCM_RAM7_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_CCM_RAM7_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_CCM_RAM7_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_CCM_RAM7_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_CCM_RAM7_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_CCM_RAM7_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 27..24 : Configuration field for RAM block 6. */ -#define AMLI_RAMPRI_CCM_RAM6_Pos (24UL) /*!< Position of RAM6 field. */ -#define AMLI_RAMPRI_CCM_RAM6_Msk (0xFUL << AMLI_RAMPRI_CCM_RAM6_Pos) /*!< Bit mask of RAM6 field. */ -#define AMLI_RAMPRI_CCM_RAM6_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_CCM_RAM6_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_CCM_RAM6_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_CCM_RAM6_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_CCM_RAM6_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_CCM_RAM6_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_CCM_RAM6_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_CCM_RAM6_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 23..20 : Configuration field for RAM block 5. */ -#define AMLI_RAMPRI_CCM_RAM5_Pos (20UL) /*!< Position of RAM5 field. */ -#define AMLI_RAMPRI_CCM_RAM5_Msk (0xFUL << AMLI_RAMPRI_CCM_RAM5_Pos) /*!< Bit mask of RAM5 field. */ -#define AMLI_RAMPRI_CCM_RAM5_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_CCM_RAM5_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_CCM_RAM5_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_CCM_RAM5_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_CCM_RAM5_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_CCM_RAM5_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_CCM_RAM5_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_CCM_RAM5_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 19..16 : Configuration field for RAM block 4. */ -#define AMLI_RAMPRI_CCM_RAM4_Pos (16UL) /*!< Position of RAM4 field. */ -#define AMLI_RAMPRI_CCM_RAM4_Msk (0xFUL << AMLI_RAMPRI_CCM_RAM4_Pos) /*!< Bit mask of RAM4 field. */ -#define AMLI_RAMPRI_CCM_RAM4_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_CCM_RAM4_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_CCM_RAM4_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_CCM_RAM4_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_CCM_RAM4_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_CCM_RAM4_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_CCM_RAM4_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_CCM_RAM4_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 15..12 : Configuration field for RAM block 3. */ -#define AMLI_RAMPRI_CCM_RAM3_Pos (12UL) /*!< Position of RAM3 field. */ -#define AMLI_RAMPRI_CCM_RAM3_Msk (0xFUL << AMLI_RAMPRI_CCM_RAM3_Pos) /*!< Bit mask of RAM3 field. */ -#define AMLI_RAMPRI_CCM_RAM3_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_CCM_RAM3_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_CCM_RAM3_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_CCM_RAM3_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_CCM_RAM3_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_CCM_RAM3_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_CCM_RAM3_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_CCM_RAM3_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 11..8 : Configuration field for RAM block 2. */ -#define AMLI_RAMPRI_CCM_RAM2_Pos (8UL) /*!< Position of RAM2 field. */ -#define AMLI_RAMPRI_CCM_RAM2_Msk (0xFUL << AMLI_RAMPRI_CCM_RAM2_Pos) /*!< Bit mask of RAM2 field. */ -#define AMLI_RAMPRI_CCM_RAM2_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_CCM_RAM2_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_CCM_RAM2_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_CCM_RAM2_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_CCM_RAM2_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_CCM_RAM2_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_CCM_RAM2_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_CCM_RAM2_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 7..4 : Configuration field for RAM block 1. */ -#define AMLI_RAMPRI_CCM_RAM1_Pos (4UL) /*!< Position of RAM1 field. */ -#define AMLI_RAMPRI_CCM_RAM1_Msk (0xFUL << AMLI_RAMPRI_CCM_RAM1_Pos) /*!< Bit mask of RAM1 field. */ -#define AMLI_RAMPRI_CCM_RAM1_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_CCM_RAM1_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_CCM_RAM1_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_CCM_RAM1_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_CCM_RAM1_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_CCM_RAM1_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_CCM_RAM1_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_CCM_RAM1_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 3..0 : Configuration field for RAM block 0. */ -#define AMLI_RAMPRI_CCM_RAM0_Pos (0UL) /*!< Position of RAM0 field. */ -#define AMLI_RAMPRI_CCM_RAM0_Msk (0xFUL << AMLI_RAMPRI_CCM_RAM0_Pos) /*!< Bit mask of RAM0 field. */ -#define AMLI_RAMPRI_CCM_RAM0_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_CCM_RAM0_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_CCM_RAM0_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_CCM_RAM0_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_CCM_RAM0_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_CCM_RAM0_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_CCM_RAM0_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_CCM_RAM0_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Register: AMLI_RAMPRI_AAR */ -/* Description: Configurable priority configuration register for AAR. */ - -/* Bits 31..28 : Configuration field for RAM block 7. */ -#define AMLI_RAMPRI_AAR_RAM7_Pos (28UL) /*!< Position of RAM7 field. */ -#define AMLI_RAMPRI_AAR_RAM7_Msk (0xFUL << AMLI_RAMPRI_AAR_RAM7_Pos) /*!< Bit mask of RAM7 field. */ -#define AMLI_RAMPRI_AAR_RAM7_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_AAR_RAM7_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_AAR_RAM7_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_AAR_RAM7_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_AAR_RAM7_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_AAR_RAM7_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_AAR_RAM7_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_AAR_RAM7_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 27..24 : Configuration field for RAM block 6. */ -#define AMLI_RAMPRI_AAR_RAM6_Pos (24UL) /*!< Position of RAM6 field. */ -#define AMLI_RAMPRI_AAR_RAM6_Msk (0xFUL << AMLI_RAMPRI_AAR_RAM6_Pos) /*!< Bit mask of RAM6 field. */ -#define AMLI_RAMPRI_AAR_RAM6_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_AAR_RAM6_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_AAR_RAM6_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_AAR_RAM6_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_AAR_RAM6_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_AAR_RAM6_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_AAR_RAM6_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_AAR_RAM6_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 23..20 : Configuration field for RAM block 5. */ -#define AMLI_RAMPRI_AAR_RAM5_Pos (20UL) /*!< Position of RAM5 field. */ -#define AMLI_RAMPRI_AAR_RAM5_Msk (0xFUL << AMLI_RAMPRI_AAR_RAM5_Pos) /*!< Bit mask of RAM5 field. */ -#define AMLI_RAMPRI_AAR_RAM5_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_AAR_RAM5_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_AAR_RAM5_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_AAR_RAM5_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_AAR_RAM5_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_AAR_RAM5_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_AAR_RAM5_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_AAR_RAM5_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 19..16 : Configuration field for RAM block 4. */ -#define AMLI_RAMPRI_AAR_RAM4_Pos (16UL) /*!< Position of RAM4 field. */ -#define AMLI_RAMPRI_AAR_RAM4_Msk (0xFUL << AMLI_RAMPRI_AAR_RAM4_Pos) /*!< Bit mask of RAM4 field. */ -#define AMLI_RAMPRI_AAR_RAM4_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_AAR_RAM4_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_AAR_RAM4_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_AAR_RAM4_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_AAR_RAM4_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_AAR_RAM4_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_AAR_RAM4_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_AAR_RAM4_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 15..12 : Configuration field for RAM block 3. */ -#define AMLI_RAMPRI_AAR_RAM3_Pos (12UL) /*!< Position of RAM3 field. */ -#define AMLI_RAMPRI_AAR_RAM3_Msk (0xFUL << AMLI_RAMPRI_AAR_RAM3_Pos) /*!< Bit mask of RAM3 field. */ -#define AMLI_RAMPRI_AAR_RAM3_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_AAR_RAM3_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_AAR_RAM3_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_AAR_RAM3_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_AAR_RAM3_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_AAR_RAM3_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_AAR_RAM3_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_AAR_RAM3_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 11..8 : Configuration field for RAM block 2. */ -#define AMLI_RAMPRI_AAR_RAM2_Pos (8UL) /*!< Position of RAM2 field. */ -#define AMLI_RAMPRI_AAR_RAM2_Msk (0xFUL << AMLI_RAMPRI_AAR_RAM2_Pos) /*!< Bit mask of RAM2 field. */ -#define AMLI_RAMPRI_AAR_RAM2_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_AAR_RAM2_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_AAR_RAM2_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_AAR_RAM2_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_AAR_RAM2_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_AAR_RAM2_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_AAR_RAM2_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_AAR_RAM2_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 7..4 : Configuration field for RAM block 1. */ -#define AMLI_RAMPRI_AAR_RAM1_Pos (4UL) /*!< Position of RAM1 field. */ -#define AMLI_RAMPRI_AAR_RAM1_Msk (0xFUL << AMLI_RAMPRI_AAR_RAM1_Pos) /*!< Bit mask of RAM1 field. */ -#define AMLI_RAMPRI_AAR_RAM1_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_AAR_RAM1_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_AAR_RAM1_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_AAR_RAM1_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_AAR_RAM1_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_AAR_RAM1_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_AAR_RAM1_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_AAR_RAM1_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Bits 3..0 : Configuration field for RAM block 0. */ -#define AMLI_RAMPRI_AAR_RAM0_Pos (0UL) /*!< Position of RAM0 field. */ -#define AMLI_RAMPRI_AAR_RAM0_Msk (0xFUL << AMLI_RAMPRI_AAR_RAM0_Pos) /*!< Bit mask of RAM0 field. */ -#define AMLI_RAMPRI_AAR_RAM0_Pri0 (0x0UL) /*!< Priority 0. */ -#define AMLI_RAMPRI_AAR_RAM0_Pri2 (0x2UL) /*!< Priority 2. */ -#define AMLI_RAMPRI_AAR_RAM0_Pri4 (0x4UL) /*!< Priority 4. */ -#define AMLI_RAMPRI_AAR_RAM0_Pri6 (0x6UL) /*!< Priority 6. */ -#define AMLI_RAMPRI_AAR_RAM0_Pri8 (0x8UL) /*!< Priority 8. */ -#define AMLI_RAMPRI_AAR_RAM0_Pri10 (0xAUL) /*!< Priority 10. */ -#define AMLI_RAMPRI_AAR_RAM0_Pri12 (0xCUL) /*!< Priority 12. */ -#define AMLI_RAMPRI_AAR_RAM0_Pri14 (0xEUL) /*!< Priority 14. */ - -/* Peripheral: CCM */ -/* Description: AES CCM Mode Encryption. */ - -/* Register: CCM_SHORTS */ -/* Description: Shortcuts for the CCM. */ - -/* Bit 0 : Shortcut between ENDKSGEN event and CRYPT task. */ -#define CCM_SHORTS_ENDKSGEN_CRYPT_Pos (0UL) /*!< Position of ENDKSGEN_CRYPT field. */ -#define CCM_SHORTS_ENDKSGEN_CRYPT_Msk (0x1UL << CCM_SHORTS_ENDKSGEN_CRYPT_Pos) /*!< Bit mask of ENDKSGEN_CRYPT field. */ -#define CCM_SHORTS_ENDKSGEN_CRYPT_Disabled (0UL) /*!< Shortcut disabled. */ -#define CCM_SHORTS_ENDKSGEN_CRYPT_Enabled (1UL) /*!< Shortcut enabled. */ - -/* Register: CCM_INTENSET */ -/* Description: Interrupt enable set register. */ - -/* Bit 2 : Enable interrupt on ERROR event. */ -#define CCM_INTENSET_ERROR_Pos (2UL) /*!< Position of ERROR field. */ -#define CCM_INTENSET_ERROR_Msk (0x1UL << CCM_INTENSET_ERROR_Pos) /*!< Bit mask of ERROR field. */ -#define CCM_INTENSET_ERROR_Disabled (0UL) /*!< Interrupt disabled. */ -#define CCM_INTENSET_ERROR_Enabled (1UL) /*!< Interrupt enabled. */ -#define CCM_INTENSET_ERROR_Set (1UL) /*!< Enable interrupt on write. */ - -/* Bit 1 : Enable interrupt on ENDCRYPT event. */ -#define CCM_INTENSET_ENDCRYPT_Pos (1UL) /*!< Position of ENDCRYPT field. */ -#define CCM_INTENSET_ENDCRYPT_Msk (0x1UL << CCM_INTENSET_ENDCRYPT_Pos) /*!< Bit mask of ENDCRYPT field. */ -#define CCM_INTENSET_ENDCRYPT_Disabled (0UL) /*!< Interrupt disabled. */ -#define CCM_INTENSET_ENDCRYPT_Enabled (1UL) /*!< Interrupt enabled. */ -#define CCM_INTENSET_ENDCRYPT_Set (1UL) /*!< Enable interrupt on write. */ - -/* Bit 0 : Enable interrupt on ENDKSGEN event. */ -#define CCM_INTENSET_ENDKSGEN_Pos (0UL) /*!< Position of ENDKSGEN field. */ -#define CCM_INTENSET_ENDKSGEN_Msk (0x1UL << CCM_INTENSET_ENDKSGEN_Pos) /*!< Bit mask of ENDKSGEN field. */ -#define CCM_INTENSET_ENDKSGEN_Disabled (0UL) /*!< Interrupt disabled. */ -#define CCM_INTENSET_ENDKSGEN_Enabled (1UL) /*!< Interrupt enabled. */ -#define CCM_INTENSET_ENDKSGEN_Set (1UL) /*!< Enable interrupt on write. */ - -/* Register: CCM_INTENCLR */ -/* Description: Interrupt enable clear register. */ - -/* Bit 2 : Disable interrupt on ERROR event. */ -#define CCM_INTENCLR_ERROR_Pos (2UL) /*!< Position of ERROR field. */ -#define CCM_INTENCLR_ERROR_Msk (0x1UL << CCM_INTENCLR_ERROR_Pos) /*!< Bit mask of ERROR field. */ -#define CCM_INTENCLR_ERROR_Disabled (0UL) /*!< Interrupt disabled. */ -#define CCM_INTENCLR_ERROR_Enabled (1UL) /*!< Interrupt enabled. */ -#define CCM_INTENCLR_ERROR_Clear (1UL) /*!< Disable interrupt on write. */ - -/* Bit 1 : Disable interrupt on ENDCRYPT event. */ -#define CCM_INTENCLR_ENDCRYPT_Pos (1UL) /*!< Position of ENDCRYPT field. */ -#define CCM_INTENCLR_ENDCRYPT_Msk (0x1UL << CCM_INTENCLR_ENDCRYPT_Pos) /*!< Bit mask of ENDCRYPT field. */ -#define CCM_INTENCLR_ENDCRYPT_Disabled (0UL) /*!< Interrupt disabled. */ -#define CCM_INTENCLR_ENDCRYPT_Enabled (1UL) /*!< Interrupt enabled. */ -#define CCM_INTENCLR_ENDCRYPT_Clear (1UL) /*!< Disable interrupt on write. */ - -/* Bit 0 : Disable interrupt on ENDKSGEN event. */ -#define CCM_INTENCLR_ENDKSGEN_Pos (0UL) /*!< Position of ENDKSGEN field. */ -#define CCM_INTENCLR_ENDKSGEN_Msk (0x1UL << CCM_INTENCLR_ENDKSGEN_Pos) /*!< Bit mask of ENDKSGEN field. */ -#define CCM_INTENCLR_ENDKSGEN_Disabled (0UL) /*!< Interrupt disabled. */ -#define CCM_INTENCLR_ENDKSGEN_Enabled (1UL) /*!< Interrupt enabled. */ -#define CCM_INTENCLR_ENDKSGEN_Clear (1UL) /*!< Disable interrupt on write. */ - -/* Register: CCM_MICSTATUS */ -/* Description: CCM RX MIC check result. */ - -/* Bit 0 : Result of the MIC check performed during the previous CCM RX STARTCRYPT */ -#define CCM_MICSTATUS_MICSTATUS_Pos (0UL) /*!< Position of MICSTATUS field. */ -#define CCM_MICSTATUS_MICSTATUS_Msk (0x1UL << CCM_MICSTATUS_MICSTATUS_Pos) /*!< Bit mask of MICSTATUS field. */ -#define CCM_MICSTATUS_MICSTATUS_CheckFailed (0UL) /*!< MIC check failed. */ -#define CCM_MICSTATUS_MICSTATUS_CheckPassed (1UL) /*!< MIC check passed. */ - -/* Register: CCM_ENABLE */ -/* Description: CCM enable. */ - -/* Bits 1..0 : CCM enable. */ -#define CCM_ENABLE_ENABLE_Pos (0UL) /*!< Position of ENABLE field. */ -#define CCM_ENABLE_ENABLE_Msk (0x3UL << CCM_ENABLE_ENABLE_Pos) /*!< Bit mask of ENABLE field. */ -#define CCM_ENABLE_ENABLE_Disabled (0x00UL) /*!< CCM is disabled. */ -#define CCM_ENABLE_ENABLE_Enabled (0x02UL) /*!< CCM is enabled. */ - -/* Register: CCM_MODE */ -/* Description: Operation mode. */ - -/* Bit 0 : CCM mode operation. */ -#define CCM_MODE_MODE_Pos (0UL) /*!< Position of MODE field. */ -#define CCM_MODE_MODE_Msk (0x1UL << CCM_MODE_MODE_Pos) /*!< Bit mask of MODE field. */ -#define CCM_MODE_MODE_Encryption (0UL) /*!< CCM mode TX */ -#define CCM_MODE_MODE_Decryption (1UL) /*!< CCM mode TX */ - -/* Register: CCM_POWER */ -/* Description: Peripheral power control. */ - -/* Bit 0 : Peripheral power control. */ -#define CCM_POWER_POWER_Pos (0UL) /*!< Position of POWER field. */ -#define CCM_POWER_POWER_Msk (0x1UL << CCM_POWER_POWER_Pos) /*!< Bit mask of POWER field. */ -#define CCM_POWER_POWER_Disabled (0UL) /*!< Module power disabled. */ -#define CCM_POWER_POWER_Enabled (1UL) /*!< Module power enabled. */ - - -/* Peripheral: CLOCK */ -/* Description: Clock control. */ - -/* Register: CLOCK_INTENSET */ -/* Description: Interrupt enable set register. */ - -/* Bit 4 : Enable interrupt on CTTO event. */ -#define CLOCK_INTENSET_CTTO_Pos (4UL) /*!< Position of CTTO field. */ -#define CLOCK_INTENSET_CTTO_Msk (0x1UL << CLOCK_INTENSET_CTTO_Pos) /*!< Bit mask of CTTO field. */ -#define CLOCK_INTENSET_CTTO_Disabled (0UL) /*!< Interrupt disabled. */ -#define CLOCK_INTENSET_CTTO_Enabled (1UL) /*!< Interrupt enabled. */ -#define CLOCK_INTENSET_CTTO_Set (1UL) /*!< Enable interrupt on write. */ - -/* Bit 3 : Enable interrupt on DONE event. */ -#define CLOCK_INTENSET_DONE_Pos (3UL) /*!< Position of DONE field. */ -#define CLOCK_INTENSET_DONE_Msk (0x1UL << CLOCK_INTENSET_DONE_Pos) /*!< Bit mask of DONE field. */ -#define CLOCK_INTENSET_DONE_Disabled (0UL) /*!< Interrupt disabled. */ -#define CLOCK_INTENSET_DONE_Enabled (1UL) /*!< Interrupt enabled. */ -#define CLOCK_INTENSET_DONE_Set (1UL) /*!< Enable interrupt on write. */ - -/* Bit 1 : Enable interrupt on LFCLKSTARTED event. */ -#define CLOCK_INTENSET_LFCLKSTARTED_Pos (1UL) /*!< Position of LFCLKSTARTED field. */ -#define CLOCK_INTENSET_LFCLKSTARTED_Msk (0x1UL << CLOCK_INTENSET_LFCLKSTARTED_Pos) /*!< Bit mask of LFCLKSTARTED field. */ -#define CLOCK_INTENSET_LFCLKSTARTED_Disabled (0UL) /*!< Interrupt disabled. */ -#define CLOCK_INTENSET_LFCLKSTARTED_Enabled (1UL) /*!< Interrupt enabled. */ -#define CLOCK_INTENSET_LFCLKSTARTED_Set (1UL) /*!< Enable interrupt on write. */ - -/* Bit 0 : Enable interrupt on HFCLKSTARTED event. */ -#define CLOCK_INTENSET_HFCLKSTARTED_Pos (0UL) /*!< Position of HFCLKSTARTED field. */ -#define CLOCK_INTENSET_HFCLKSTARTED_Msk (0x1UL << CLOCK_INTENSET_HFCLKSTARTED_Pos) /*!< Bit mask of HFCLKSTARTED field. */ -#define CLOCK_INTENSET_HFCLKSTARTED_Disabled (0UL) /*!< Interrupt disabled. */ -#define CLOCK_INTENSET_HFCLKSTARTED_Enabled (1UL) /*!< Interrupt enabled. */ -#define CLOCK_INTENSET_HFCLKSTARTED_Set (1UL) /*!< Enable interrupt on write. */ - -/* Register: CLOCK_INTENCLR */ -/* Description: Interrupt enable clear register. */ - -/* Bit 4 : Disable interrupt on CTTO event. */ -#define CLOCK_INTENCLR_CTTO_Pos (4UL) /*!< Position of CTTO field. */ -#define CLOCK_INTENCLR_CTTO_Msk (0x1UL << CLOCK_INTENCLR_CTTO_Pos) /*!< Bit mask of CTTO field. */ -#define CLOCK_INTENCLR_CTTO_Disabled (0UL) /*!< Interrupt disabled. */ -#define CLOCK_INTENCLR_CTTO_Enabled (1UL) /*!< Interrupt enabled. */ -#define CLOCK_INTENCLR_CTTO_Clear (1UL) /*!< Disable interrupt on write. */ - -/* Bit 3 : Disable interrupt on DONE event. */ -#define CLOCK_INTENCLR_DONE_Pos (3UL) /*!< Position of DONE field. */ -#define CLOCK_INTENCLR_DONE_Msk (0x1UL << CLOCK_INTENCLR_DONE_Pos) /*!< Bit mask of DONE field. */ -#define CLOCK_INTENCLR_DONE_Disabled (0UL) /*!< Interrupt disabled. */ -#define CLOCK_INTENCLR_DONE_Enabled (1UL) /*!< Interrupt enabled. */ -#define CLOCK_INTENCLR_DONE_Clear (1UL) /*!< Disable interrupt on write. */ - -/* Bit 1 : Disable interrupt on LFCLKSTARTED event. */ -#define CLOCK_INTENCLR_LFCLKSTARTED_Pos (1UL) /*!< Position of LFCLKSTARTED field. */ -#define CLOCK_INTENCLR_LFCLKSTARTED_Msk (0x1UL << CLOCK_INTENCLR_LFCLKSTARTED_Pos) /*!< Bit mask of LFCLKSTARTED field. */ -#define CLOCK_INTENCLR_LFCLKSTARTED_Disabled (0UL) /*!< Interrupt disabled. */ -#define CLOCK_INTENCLR_LFCLKSTARTED_Enabled (1UL) /*!< Interrupt enabled. */ -#define CLOCK_INTENCLR_LFCLKSTARTED_Clear (1UL) /*!< Disable interrupt on write. */ - -/* Bit 0 : Disable interrupt on HFCLKSTARTED event. */ -#define CLOCK_INTENCLR_HFCLKSTARTED_Pos (0UL) /*!< Position of HFCLKSTARTED field. */ -#define CLOCK_INTENCLR_HFCLKSTARTED_Msk (0x1UL << CLOCK_INTENCLR_HFCLKSTARTED_Pos) /*!< Bit mask of HFCLKSTARTED field. */ -#define CLOCK_INTENCLR_HFCLKSTARTED_Disabled (0UL) /*!< Interrupt disabled. */ -#define CLOCK_INTENCLR_HFCLKSTARTED_Enabled (1UL) /*!< Interrupt enabled. */ -#define CLOCK_INTENCLR_HFCLKSTARTED_Clear (1UL) /*!< Disable interrupt on write. */ - -/* Register: CLOCK_HFCLKRUN */ -/* Description: Task HFCLKSTART trigger status. */ - -/* Bit 0 : Task HFCLKSTART trigger status. */ -#define CLOCK_HFCLKRUN_STATUS_Pos (0UL) /*!< Position of STATUS field. */ -#define CLOCK_HFCLKRUN_STATUS_Msk (0x1UL << CLOCK_HFCLKRUN_STATUS_Pos) /*!< Bit mask of STATUS field. */ -#define CLOCK_HFCLKRUN_STATUS_NotTriggered (0UL) /*!< Task HFCLKSTART has not been triggered. */ -#define CLOCK_HFCLKRUN_STATUS_Triggered (1UL) /*!< Task HFCLKSTART has been triggered. */ - -/* Register: CLOCK_HFCLKSTAT */ -/* Description: High frequency clock status. */ - -/* Bit 16 : State for the HFCLK. */ -#define CLOCK_HFCLKSTAT_STATE_Pos (16UL) /*!< Position of STATE field. */ -#define CLOCK_HFCLKSTAT_STATE_Msk (0x1UL << CLOCK_HFCLKSTAT_STATE_Pos) /*!< Bit mask of STATE field. */ -#define CLOCK_HFCLKSTAT_STATE_NotRunning (0UL) /*!< HFCLK clock not running. */ -#define CLOCK_HFCLKSTAT_STATE_Running (1UL) /*!< HFCLK clock running. */ - -/* Bit 0 : Active clock source for the HF clock. */ -#define CLOCK_HFCLKSTAT_SRC_Pos (0UL) /*!< Position of SRC field. */ -#define CLOCK_HFCLKSTAT_SRC_Msk (0x1UL << CLOCK_HFCLKSTAT_SRC_Pos) /*!< Bit mask of SRC field. */ -#define CLOCK_HFCLKSTAT_SRC_RC (0UL) /*!< Internal 16MHz RC oscillator running and generating the HFCLK clock. */ -#define CLOCK_HFCLKSTAT_SRC_Xtal (1UL) /*!< External 16MHz/32MHz crystal oscillator running and generating the HFCLK clock. */ - -/* Register: CLOCK_LFCLKRUN */ -/* Description: Task LFCLKSTART triggered status. */ - -/* Bit 0 : Task LFCLKSTART triggered status. */ -#define CLOCK_LFCLKRUN_STATUS_Pos (0UL) /*!< Position of STATUS field. */ -#define CLOCK_LFCLKRUN_STATUS_Msk (0x1UL << CLOCK_LFCLKRUN_STATUS_Pos) /*!< Bit mask of STATUS field. */ -#define CLOCK_LFCLKRUN_STATUS_NotTriggered (0UL) /*!< Task LFCLKSTART has not been triggered. */ -#define CLOCK_LFCLKRUN_STATUS_Triggered (1UL) /*!< Task LFCLKSTART has been triggered. */ - -/* Register: CLOCK_LFCLKSTAT */ -/* Description: Low frequency clock status. */ - -/* Bit 16 : State for the LF clock. */ -#define CLOCK_LFCLKSTAT_STATE_Pos (16UL) /*!< Position of STATE field. */ -#define CLOCK_LFCLKSTAT_STATE_Msk (0x1UL << CLOCK_LFCLKSTAT_STATE_Pos) /*!< Bit mask of STATE field. */ -#define CLOCK_LFCLKSTAT_STATE_NotRunning (0UL) /*!< LFCLK clock not running. */ -#define CLOCK_LFCLKSTAT_STATE_Running (1UL) /*!< LFCLK clock running. */ - -/* Bits 1..0 : Active clock source for the LF clock. */ -#define CLOCK_LFCLKSTAT_SRC_Pos (0UL) /*!< Position of SRC field. */ -#define CLOCK_LFCLKSTAT_SRC_Msk (0x3UL << CLOCK_LFCLKSTAT_SRC_Pos) /*!< Bit mask of SRC field. */ -#define CLOCK_LFCLKSTAT_SRC_RC (0UL) /*!< Internal 32KiHz RC oscillator running and generating the LFCLK clock. */ -#define CLOCK_LFCLKSTAT_SRC_Xtal (1UL) /*!< External 32KiHz crystal oscillator running and generating the LFCLK clock. */ -#define CLOCK_LFCLKSTAT_SRC_Synth (2UL) /*!< Internal 32KiHz synthesizer from the HFCLK running and generating the LFCLK clock. */ - -/* Register: CLOCK_LFCLKSRCCOPY */ -/* Description: Clock source for the LFCLK clock, set when task LKCLKSTART is triggered. */ - -/* Bits 1..0 : Clock source for the LFCLK clock, set when task LKCLKSTART is triggered. */ -#define CLOCK_LFCLKSRCCOPY_SRC_Pos (0UL) /*!< Position of SRC field. */ -#define CLOCK_LFCLKSRCCOPY_SRC_Msk (0x3UL << CLOCK_LFCLKSRCCOPY_SRC_Pos) /*!< Bit mask of SRC field. */ -#define CLOCK_LFCLKSRCCOPY_SRC_RC (0UL) /*!< Internal 32KiHz RC oscillator. */ -#define CLOCK_LFCLKSRCCOPY_SRC_Xtal (1UL) /*!< External 32KiHz crystal. */ -#define CLOCK_LFCLKSRCCOPY_SRC_Synth (2UL) /*!< Internal 32KiHz synthesizer from HFCLK system clock. */ - -/* Register: CLOCK_LFCLKSRC */ -/* Description: Clock source for the LFCLK clock. */ - -/* Bits 1..0 : Clock source. */ -#define CLOCK_LFCLKSRC_SRC_Pos (0UL) /*!< Position of SRC field. */ -#define CLOCK_LFCLKSRC_SRC_Msk (0x3UL << CLOCK_LFCLKSRC_SRC_Pos) /*!< Bit mask of SRC field. */ -#define CLOCK_LFCLKSRC_SRC_RC (0UL) /*!< Internal 32KiHz RC oscillator. */ -#define CLOCK_LFCLKSRC_SRC_Xtal (1UL) /*!< External 32KiHz crystal. */ -#define CLOCK_LFCLKSRC_SRC_Synth (2UL) /*!< Internal 32KiHz synthesizer from HFCLK system clock. */ - -/* Register: CLOCK_CTIV */ -/* Description: Calibration timer interval. */ - -/* Bits 6..0 : Calibration timer interval in 0.25s resolution. */ -#define CLOCK_CTIV_CTIV_Pos (0UL) /*!< Position of CTIV field. */ -#define CLOCK_CTIV_CTIV_Msk (0x7FUL << CLOCK_CTIV_CTIV_Pos) /*!< Bit mask of CTIV field. */ - -/* Register: CLOCK_XTALFREQ */ -/* Description: Crystal frequency. */ - -/* Bits 7..0 : External Xtal frequency selection. */ -#define CLOCK_XTALFREQ_XTALFREQ_Pos (0UL) /*!< Position of XTALFREQ field. */ -#define CLOCK_XTALFREQ_XTALFREQ_Msk (0xFFUL << CLOCK_XTALFREQ_XTALFREQ_Pos) /*!< Bit mask of XTALFREQ field. */ -#define CLOCK_XTALFREQ_XTALFREQ_16MHz (0xFFUL) /*!< 16MHz xtal is used as source for the HFCLK oscillator. */ -#define CLOCK_XTALFREQ_XTALFREQ_32MHz (0x00UL) /*!< 32MHz xtal is used as source for the HFCLK oscillator. */ - - -/* Peripheral: ECB */ -/* Description: AES ECB Mode Encryption. */ - -/* Register: ECB_INTENSET */ -/* Description: Interrupt enable set register. */ - -/* Bit 1 : Enable interrupt on ERRORECB event. */ -#define ECB_INTENSET_ERRORECB_Pos (1UL) /*!< Position of ERRORECB field. */ -#define ECB_INTENSET_ERRORECB_Msk (0x1UL << ECB_INTENSET_ERRORECB_Pos) /*!< Bit mask of ERRORECB field. */ -#define ECB_INTENSET_ERRORECB_Disabled (0UL) /*!< Interrupt disabled. */ -#define ECB_INTENSET_ERRORECB_Enabled (1UL) /*!< Interrupt enabled. */ -#define ECB_INTENSET_ERRORECB_Set (1UL) /*!< Enable interrupt on write. */ - -/* Bit 0 : Enable interrupt on ENDECB event. */ -#define ECB_INTENSET_ENDECB_Pos (0UL) /*!< Position of ENDECB field. */ -#define ECB_INTENSET_ENDECB_Msk (0x1UL << ECB_INTENSET_ENDECB_Pos) /*!< Bit mask of ENDECB field. */ -#define ECB_INTENSET_ENDECB_Disabled (0UL) /*!< Interrupt disabled. */ -#define ECB_INTENSET_ENDECB_Enabled (1UL) /*!< Interrupt enabled. */ -#define ECB_INTENSET_ENDECB_Set (1UL) /*!< Enable interrupt on write. */ - -/* Register: ECB_INTENCLR */ -/* Description: Interrupt enable clear register. */ - -/* Bit 1 : Disable interrupt on ERRORECB event. */ -#define ECB_INTENCLR_ERRORECB_Pos (1UL) /*!< Position of ERRORECB field. */ -#define ECB_INTENCLR_ERRORECB_Msk (0x1UL << ECB_INTENCLR_ERRORECB_Pos) /*!< Bit mask of ERRORECB field. */ -#define ECB_INTENCLR_ERRORECB_Disabled (0UL) /*!< Interrupt disabled. */ -#define ECB_INTENCLR_ERRORECB_Enabled (1UL) /*!< Interrupt enabled. */ -#define ECB_INTENCLR_ERRORECB_Clear (1UL) /*!< Disable interrupt on write. */ - -/* Bit 0 : Disable interrupt on ENDECB event. */ -#define ECB_INTENCLR_ENDECB_Pos (0UL) /*!< Position of ENDECB field. */ -#define ECB_INTENCLR_ENDECB_Msk (0x1UL << ECB_INTENCLR_ENDECB_Pos) /*!< Bit mask of ENDECB field. */ -#define ECB_INTENCLR_ENDECB_Disabled (0UL) /*!< Interrupt disabled. */ -#define ECB_INTENCLR_ENDECB_Enabled (1UL) /*!< Interrupt enabled. */ -#define ECB_INTENCLR_ENDECB_Clear (1UL) /*!< Disable interrupt on write. */ - -/* Register: ECB_POWER */ -/* Description: Peripheral power control. */ - -/* Bit 0 : Peripheral power control. */ -#define ECB_POWER_POWER_Pos (0UL) /*!< Position of POWER field. */ -#define ECB_POWER_POWER_Msk (0x1UL << ECB_POWER_POWER_Pos) /*!< Bit mask of POWER field. */ -#define ECB_POWER_POWER_Disabled (0UL) /*!< Module power disabled. */ -#define ECB_POWER_POWER_Enabled (1UL) /*!< Module power enabled. */ - - -/* Peripheral: FICR */ -/* Description: Factory Information Configuration. */ - -/* Register: FICR_PPFC */ -/* Description: Pre-programmed factory code present. */ - -/* Bits 7..0 : Pre-programmed factory code present. */ -#define FICR_PPFC_PPFC_Pos (0UL) /*!< Position of PPFC field. */ -#define FICR_PPFC_PPFC_Msk (0xFFUL << FICR_PPFC_PPFC_Pos) /*!< Bit mask of PPFC field. */ -#define FICR_PPFC_PPFC_NotPresent (0xFFUL) /*!< Not present. */ -#define FICR_PPFC_PPFC_Present (0x00UL) /*!< Present. */ - -/* Register: FICR_CONFIGID */ -/* Description: Configuration identifier. */ - -/* Bits 31..16 : Firmware Identification Number pre-loaded into the flash. */ -#define FICR_CONFIGID_FWID_Pos (16UL) /*!< Position of FWID field. */ -#define FICR_CONFIGID_FWID_Msk (0xFFFFUL << FICR_CONFIGID_FWID_Pos) /*!< Bit mask of FWID field. */ - -/* Bits 15..0 : Hardware Identification Number. */ -#define FICR_CONFIGID_HWID_Pos (0UL) /*!< Position of HWID field. */ -#define FICR_CONFIGID_HWID_Msk (0xFFFFUL << FICR_CONFIGID_HWID_Pos) /*!< Bit mask of HWID field. */ - -/* Register: FICR_DEVICEADDRTYPE */ -/* Description: Device address type. */ - -/* Bit 0 : Device address type. */ -#define FICR_DEVICEADDRTYPE_DEVICEADDRTYPE_Pos (0UL) /*!< Position of DEVICEADDRTYPE field. */ -#define FICR_DEVICEADDRTYPE_DEVICEADDRTYPE_Msk (0x1UL << FICR_DEVICEADDRTYPE_DEVICEADDRTYPE_Pos) /*!< Bit mask of DEVICEADDRTYPE field. */ -#define FICR_DEVICEADDRTYPE_DEVICEADDRTYPE_Public (0UL) /*!< Public address. */ -#define FICR_DEVICEADDRTYPE_DEVICEADDRTYPE_Random (1UL) /*!< Random address. */ - -/* Register: FICR_OVERRIDEEN */ -/* Description: Radio calibration override enable. */ - -/* Bit 3 : Override default values for BLE_1Mbit mode. */ -#define FICR_OVERRIDEEN_BLE_1MBIT_Pos (3UL) /*!< Position of BLE_1MBIT field. */ -#define FICR_OVERRIDEEN_BLE_1MBIT_Msk (0x1UL << FICR_OVERRIDEEN_BLE_1MBIT_Pos) /*!< Bit mask of BLE_1MBIT field. */ -#define FICR_OVERRIDEEN_BLE_1MBIT_Override (0UL) /*!< Override the default values for BLE_1Mbit mode. */ -#define FICR_OVERRIDEEN_BLE_1MBIT_NotOverride (1UL) /*!< Do not override the default values for BLE_1Mbit mode. */ - -/* Bit 0 : Override default values for NRF_1Mbit mode. */ -#define FICR_OVERRIDEEN_NRF_1MBIT_Pos (0UL) /*!< Position of NRF_1MBIT field. */ -#define FICR_OVERRIDEEN_NRF_1MBIT_Msk (0x1UL << FICR_OVERRIDEEN_NRF_1MBIT_Pos) /*!< Bit mask of NRF_1MBIT field. */ -#define FICR_OVERRIDEEN_NRF_1MBIT_Override (0UL) /*!< Override the default values for NRF_1Mbit mode. */ -#define FICR_OVERRIDEEN_NRF_1MBIT_NotOverride (1UL) /*!< Do not override the default values for NRF_1Mbit mode. */ - -/* Register: FICR_INFO_PART */ -/* Description: Part code */ - -/* Bits 31..0 : Part code */ -#define FICR_INFO_PART_PART_Pos (0UL) /*!< Position of PART field. */ -#define FICR_INFO_PART_PART_Msk (0xFFFFFFFFUL << FICR_INFO_PART_PART_Pos) /*!< Bit mask of PART field. */ -#define FICR_INFO_PART_PART_N51822 (0x51822UL) /*!< nRF51822 */ -#define FICR_INFO_PART_PART_N51422 (0x51422UL) /*!< nRF51422 */ -#define FICR_INFO_PART_PART_Unspecified (0xFFFFFFFFUL) /*!< Unspecified */ - -/* Register: FICR_INFO_VARIANT */ -/* Description: Part variant */ - -/* Bits 31..0 : Part variant */ -#define FICR_INFO_VARIANT_VARIANT_Pos (0UL) /*!< Position of VARIANT field. */ -#define FICR_INFO_VARIANT_VARIANT_Msk (0xFFFFFFFFUL << FICR_INFO_VARIANT_VARIANT_Pos) /*!< Bit mask of VARIANT field. */ -#define FICR_INFO_VARIANT_VARIANT_nRF51C (0x1002UL) /*!< nRF51-C (XLR3) */ -#define FICR_INFO_VARIANT_VARIANT_nRF51D (0x1003UL) /*!< nRF51-D (L3) */ -#define FICR_INFO_VARIANT_VARIANT_nRF51E (0x1004UL) /*!< nRF51-E (XLR3P) */ -#define FICR_INFO_VARIANT_VARIANT_Unspecified (0xFFFFFFFFUL) /*!< Unspecified */ - -/* Register: FICR_INFO_PACKAGE */ -/* Description: Package option */ - -/* Bits 31..0 : Package option */ -#define FICR_INFO_PACKAGE_PACKAGE_Pos (0UL) /*!< Position of PACKAGE field. */ -#define FICR_INFO_PACKAGE_PACKAGE_Msk (0xFFFFFFFFUL << FICR_INFO_PACKAGE_PACKAGE_Pos) /*!< Bit mask of PACKAGE field. */ -#define FICR_INFO_PACKAGE_PACKAGE_QFN48 (0x0000UL) /*!< 48-pin QFN with 31 GPIO */ -#define FICR_INFO_PACKAGE_PACKAGE_nRF51CSP56A (0x1000UL) /*!< nRF51x22 CDxx - WLCSP 56 balls */ -#define FICR_INFO_PACKAGE_PACKAGE_nRF51CSP62A (0x1001UL) /*!< nRF51x22 CExx - WLCSP 62 balls */ -#define FICR_INFO_PACKAGE_PACKAGE_nRF51CSP62B (0x1002UL) /*!< nRF51x22 CFxx - WLCSP 62 balls */ -#define FICR_INFO_PACKAGE_PACKAGE_nRF51CSP62C (0x1003UL) /*!< nRF51x22 CTxx - WLCSP 62 balls */ -#define FICR_INFO_PACKAGE_PACKAGE_Unspecified (0xFFFFFFFFUL) /*!< Unspecified */ - -/* Register: FICR_INFO_RAM */ -/* Description: RAM variant */ - -/* Bits 31..0 : RAM variant */ -#define FICR_INFO_RAM_RAM_Pos (0UL) /*!< Position of RAM field. */ -#define FICR_INFO_RAM_RAM_Msk (0xFFFFFFFFUL << FICR_INFO_RAM_RAM_Pos) /*!< Bit mask of RAM field. */ -#define FICR_INFO_RAM_RAM_Unspecified (0xFFFFFFFFUL) /*!< Unspecified */ -#define FICR_INFO_RAM_RAM_K16 (16UL) /*!< 16 kByte RAM. */ -#define FICR_INFO_RAM_RAM_K32 (32UL) /*!< 32 kByte RAM. */ - -/* Register: FICR_INFO_FLASH */ -/* Description: Flash variant */ - -/* Bits 31..0 : Flash variant */ -#define FICR_INFO_FLASH_FLASH_Pos (0UL) /*!< Position of FLASH field. */ -#define FICR_INFO_FLASH_FLASH_Msk (0xFFFFFFFFUL << FICR_INFO_FLASH_FLASH_Pos) /*!< Bit mask of FLASH field. */ -#define FICR_INFO_FLASH_FLASH_Unspecified (0xFFFFFFFFUL) /*!< Unspecified */ -#define FICR_INFO_FLASH_FLASH_K128 (128UL) /*!< 128 kByte FLASH. */ -#define FICR_INFO_FLASH_FLASH_K256 (256UL) /*!< 256 kByte FLASH. */ - - -/* Peripheral: GPIO */ -/* Description: General purpose input and output. */ - -/* Register: GPIO_OUT */ -/* Description: Write GPIO port. */ - -/* Bit 31 : Pin 31. */ -#define GPIO_OUT_PIN31_Pos (31UL) /*!< Position of PIN31 field. */ -#define GPIO_OUT_PIN31_Msk (0x1UL << GPIO_OUT_PIN31_Pos) /*!< Bit mask of PIN31 field. */ -#define GPIO_OUT_PIN31_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUT_PIN31_High (1UL) /*!< Pin driver is high. */ - -/* Bit 30 : Pin 30. */ -#define GPIO_OUT_PIN30_Pos (30UL) /*!< Position of PIN30 field. */ -#define GPIO_OUT_PIN30_Msk (0x1UL << GPIO_OUT_PIN30_Pos) /*!< Bit mask of PIN30 field. */ -#define GPIO_OUT_PIN30_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUT_PIN30_High (1UL) /*!< Pin driver is high. */ - -/* Bit 29 : Pin 29. */ -#define GPIO_OUT_PIN29_Pos (29UL) /*!< Position of PIN29 field. */ -#define GPIO_OUT_PIN29_Msk (0x1UL << GPIO_OUT_PIN29_Pos) /*!< Bit mask of PIN29 field. */ -#define GPIO_OUT_PIN29_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUT_PIN29_High (1UL) /*!< Pin driver is high. */ - -/* Bit 28 : Pin 28. */ -#define GPIO_OUT_PIN28_Pos (28UL) /*!< Position of PIN28 field. */ -#define GPIO_OUT_PIN28_Msk (0x1UL << GPIO_OUT_PIN28_Pos) /*!< Bit mask of PIN28 field. */ -#define GPIO_OUT_PIN28_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUT_PIN28_High (1UL) /*!< Pin driver is high. */ - -/* Bit 27 : Pin 27. */ -#define GPIO_OUT_PIN27_Pos (27UL) /*!< Position of PIN27 field. */ -#define GPIO_OUT_PIN27_Msk (0x1UL << GPIO_OUT_PIN27_Pos) /*!< Bit mask of PIN27 field. */ -#define GPIO_OUT_PIN27_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUT_PIN27_High (1UL) /*!< Pin driver is high. */ - -/* Bit 26 : Pin 26. */ -#define GPIO_OUT_PIN26_Pos (26UL) /*!< Position of PIN26 field. */ -#define GPIO_OUT_PIN26_Msk (0x1UL << GPIO_OUT_PIN26_Pos) /*!< Bit mask of PIN26 field. */ -#define GPIO_OUT_PIN26_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUT_PIN26_High (1UL) /*!< Pin driver is high. */ - -/* Bit 25 : Pin 25. */ -#define GPIO_OUT_PIN25_Pos (25UL) /*!< Position of PIN25 field. */ -#define GPIO_OUT_PIN25_Msk (0x1UL << GPIO_OUT_PIN25_Pos) /*!< Bit mask of PIN25 field. */ -#define GPIO_OUT_PIN25_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUT_PIN25_High (1UL) /*!< Pin driver is high. */ - -/* Bit 24 : Pin 24. */ -#define GPIO_OUT_PIN24_Pos (24UL) /*!< Position of PIN24 field. */ -#define GPIO_OUT_PIN24_Msk (0x1UL << GPIO_OUT_PIN24_Pos) /*!< Bit mask of PIN24 field. */ -#define GPIO_OUT_PIN24_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUT_PIN24_High (1UL) /*!< Pin driver is high. */ - -/* Bit 23 : Pin 23. */ -#define GPIO_OUT_PIN23_Pos (23UL) /*!< Position of PIN23 field. */ -#define GPIO_OUT_PIN23_Msk (0x1UL << GPIO_OUT_PIN23_Pos) /*!< Bit mask of PIN23 field. */ -#define GPIO_OUT_PIN23_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUT_PIN23_High (1UL) /*!< Pin driver is high. */ - -/* Bit 22 : Pin 22. */ -#define GPIO_OUT_PIN22_Pos (22UL) /*!< Position of PIN22 field. */ -#define GPIO_OUT_PIN22_Msk (0x1UL << GPIO_OUT_PIN22_Pos) /*!< Bit mask of PIN22 field. */ -#define GPIO_OUT_PIN22_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUT_PIN22_High (1UL) /*!< Pin driver is high. */ - -/* Bit 21 : Pin 21. */ -#define GPIO_OUT_PIN21_Pos (21UL) /*!< Position of PIN21 field. */ -#define GPIO_OUT_PIN21_Msk (0x1UL << GPIO_OUT_PIN21_Pos) /*!< Bit mask of PIN21 field. */ -#define GPIO_OUT_PIN21_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUT_PIN21_High (1UL) /*!< Pin driver is high. */ - -/* Bit 20 : Pin 20. */ -#define GPIO_OUT_PIN20_Pos (20UL) /*!< Position of PIN20 field. */ -#define GPIO_OUT_PIN20_Msk (0x1UL << GPIO_OUT_PIN20_Pos) /*!< Bit mask of PIN20 field. */ -#define GPIO_OUT_PIN20_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUT_PIN20_High (1UL) /*!< Pin driver is high. */ - -/* Bit 19 : Pin 19. */ -#define GPIO_OUT_PIN19_Pos (19UL) /*!< Position of PIN19 field. */ -#define GPIO_OUT_PIN19_Msk (0x1UL << GPIO_OUT_PIN19_Pos) /*!< Bit mask of PIN19 field. */ -#define GPIO_OUT_PIN19_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUT_PIN19_High (1UL) /*!< Pin driver is high. */ - -/* Bit 18 : Pin 18. */ -#define GPIO_OUT_PIN18_Pos (18UL) /*!< Position of PIN18 field. */ -#define GPIO_OUT_PIN18_Msk (0x1UL << GPIO_OUT_PIN18_Pos) /*!< Bit mask of PIN18 field. */ -#define GPIO_OUT_PIN18_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUT_PIN18_High (1UL) /*!< Pin driver is high. */ - -/* Bit 17 : Pin 17. */ -#define GPIO_OUT_PIN17_Pos (17UL) /*!< Position of PIN17 field. */ -#define GPIO_OUT_PIN17_Msk (0x1UL << GPIO_OUT_PIN17_Pos) /*!< Bit mask of PIN17 field. */ -#define GPIO_OUT_PIN17_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUT_PIN17_High (1UL) /*!< Pin driver is high. */ - -/* Bit 16 : Pin 16. */ -#define GPIO_OUT_PIN16_Pos (16UL) /*!< Position of PIN16 field. */ -#define GPIO_OUT_PIN16_Msk (0x1UL << GPIO_OUT_PIN16_Pos) /*!< Bit mask of PIN16 field. */ -#define GPIO_OUT_PIN16_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUT_PIN16_High (1UL) /*!< Pin driver is high. */ - -/* Bit 15 : Pin 15. */ -#define GPIO_OUT_PIN15_Pos (15UL) /*!< Position of PIN15 field. */ -#define GPIO_OUT_PIN15_Msk (0x1UL << GPIO_OUT_PIN15_Pos) /*!< Bit mask of PIN15 field. */ -#define GPIO_OUT_PIN15_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUT_PIN15_High (1UL) /*!< Pin driver is high. */ - -/* Bit 14 : Pin 14. */ -#define GPIO_OUT_PIN14_Pos (14UL) /*!< Position of PIN14 field. */ -#define GPIO_OUT_PIN14_Msk (0x1UL << GPIO_OUT_PIN14_Pos) /*!< Bit mask of PIN14 field. */ -#define GPIO_OUT_PIN14_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUT_PIN14_High (1UL) /*!< Pin driver is high. */ - -/* Bit 13 : Pin 13. */ -#define GPIO_OUT_PIN13_Pos (13UL) /*!< Position of PIN13 field. */ -#define GPIO_OUT_PIN13_Msk (0x1UL << GPIO_OUT_PIN13_Pos) /*!< Bit mask of PIN13 field. */ -#define GPIO_OUT_PIN13_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUT_PIN13_High (1UL) /*!< Pin driver is high. */ - -/* Bit 12 : Pin 12. */ -#define GPIO_OUT_PIN12_Pos (12UL) /*!< Position of PIN12 field. */ -#define GPIO_OUT_PIN12_Msk (0x1UL << GPIO_OUT_PIN12_Pos) /*!< Bit mask of PIN12 field. */ -#define GPIO_OUT_PIN12_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUT_PIN12_High (1UL) /*!< Pin driver is high. */ - -/* Bit 11 : Pin 11. */ -#define GPIO_OUT_PIN11_Pos (11UL) /*!< Position of PIN11 field. */ -#define GPIO_OUT_PIN11_Msk (0x1UL << GPIO_OUT_PIN11_Pos) /*!< Bit mask of PIN11 field. */ -#define GPIO_OUT_PIN11_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUT_PIN11_High (1UL) /*!< Pin driver is high. */ - -/* Bit 10 : Pin 10. */ -#define GPIO_OUT_PIN10_Pos (10UL) /*!< Position of PIN10 field. */ -#define GPIO_OUT_PIN10_Msk (0x1UL << GPIO_OUT_PIN10_Pos) /*!< Bit mask of PIN10 field. */ -#define GPIO_OUT_PIN10_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUT_PIN10_High (1UL) /*!< Pin driver is high. */ - -/* Bit 9 : Pin 9. */ -#define GPIO_OUT_PIN9_Pos (9UL) /*!< Position of PIN9 field. */ -#define GPIO_OUT_PIN9_Msk (0x1UL << GPIO_OUT_PIN9_Pos) /*!< Bit mask of PIN9 field. */ -#define GPIO_OUT_PIN9_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUT_PIN9_High (1UL) /*!< Pin driver is high. */ - -/* Bit 8 : Pin 8. */ -#define GPIO_OUT_PIN8_Pos (8UL) /*!< Position of PIN8 field. */ -#define GPIO_OUT_PIN8_Msk (0x1UL << GPIO_OUT_PIN8_Pos) /*!< Bit mask of PIN8 field. */ -#define GPIO_OUT_PIN8_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUT_PIN8_High (1UL) /*!< Pin driver is high. */ - -/* Bit 7 : Pin 7. */ -#define GPIO_OUT_PIN7_Pos (7UL) /*!< Position of PIN7 field. */ -#define GPIO_OUT_PIN7_Msk (0x1UL << GPIO_OUT_PIN7_Pos) /*!< Bit mask of PIN7 field. */ -#define GPIO_OUT_PIN7_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUT_PIN7_High (1UL) /*!< Pin driver is high. */ - -/* Bit 6 : Pin 6. */ -#define GPIO_OUT_PIN6_Pos (6UL) /*!< Position of PIN6 field. */ -#define GPIO_OUT_PIN6_Msk (0x1UL << GPIO_OUT_PIN6_Pos) /*!< Bit mask of PIN6 field. */ -#define GPIO_OUT_PIN6_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUT_PIN6_High (1UL) /*!< Pin driver is high. */ - -/* Bit 5 : Pin 5. */ -#define GPIO_OUT_PIN5_Pos (5UL) /*!< Position of PIN5 field. */ -#define GPIO_OUT_PIN5_Msk (0x1UL << GPIO_OUT_PIN5_Pos) /*!< Bit mask of PIN5 field. */ -#define GPIO_OUT_PIN5_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUT_PIN5_High (1UL) /*!< Pin driver is high. */ - -/* Bit 4 : Pin 4. */ -#define GPIO_OUT_PIN4_Pos (4UL) /*!< Position of PIN4 field. */ -#define GPIO_OUT_PIN4_Msk (0x1UL << GPIO_OUT_PIN4_Pos) /*!< Bit mask of PIN4 field. */ -#define GPIO_OUT_PIN4_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUT_PIN4_High (1UL) /*!< Pin driver is high. */ - -/* Bit 3 : Pin 3. */ -#define GPIO_OUT_PIN3_Pos (3UL) /*!< Position of PIN3 field. */ -#define GPIO_OUT_PIN3_Msk (0x1UL << GPIO_OUT_PIN3_Pos) /*!< Bit mask of PIN3 field. */ -#define GPIO_OUT_PIN3_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUT_PIN3_High (1UL) /*!< Pin driver is high. */ - -/* Bit 2 : Pin 2. */ -#define GPIO_OUT_PIN2_Pos (2UL) /*!< Position of PIN2 field. */ -#define GPIO_OUT_PIN2_Msk (0x1UL << GPIO_OUT_PIN2_Pos) /*!< Bit mask of PIN2 field. */ -#define GPIO_OUT_PIN2_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUT_PIN2_High (1UL) /*!< Pin driver is high. */ - -/* Bit 1 : Pin 1. */ -#define GPIO_OUT_PIN1_Pos (1UL) /*!< Position of PIN1 field. */ -#define GPIO_OUT_PIN1_Msk (0x1UL << GPIO_OUT_PIN1_Pos) /*!< Bit mask of PIN1 field. */ -#define GPIO_OUT_PIN1_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUT_PIN1_High (1UL) /*!< Pin driver is high. */ - -/* Bit 0 : Pin 0. */ -#define GPIO_OUT_PIN0_Pos (0UL) /*!< Position of PIN0 field. */ -#define GPIO_OUT_PIN0_Msk (0x1UL << GPIO_OUT_PIN0_Pos) /*!< Bit mask of PIN0 field. */ -#define GPIO_OUT_PIN0_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUT_PIN0_High (1UL) /*!< Pin driver is high. */ - -/* Register: GPIO_OUTSET */ -/* Description: Set individual bits in GPIO port. */ - -/* Bit 31 : Pin 31. */ -#define GPIO_OUTSET_PIN31_Pos (31UL) /*!< Position of PIN31 field. */ -#define GPIO_OUTSET_PIN31_Msk (0x1UL << GPIO_OUTSET_PIN31_Pos) /*!< Bit mask of PIN31 field. */ -#define GPIO_OUTSET_PIN31_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTSET_PIN31_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTSET_PIN31_Set (1UL) /*!< Set pin driver high. */ - -/* Bit 30 : Pin 30. */ -#define GPIO_OUTSET_PIN30_Pos (30UL) /*!< Position of PIN30 field. */ -#define GPIO_OUTSET_PIN30_Msk (0x1UL << GPIO_OUTSET_PIN30_Pos) /*!< Bit mask of PIN30 field. */ -#define GPIO_OUTSET_PIN30_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTSET_PIN30_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTSET_PIN30_Set (1UL) /*!< Set pin driver high. */ - -/* Bit 29 : Pin 29. */ -#define GPIO_OUTSET_PIN29_Pos (29UL) /*!< Position of PIN29 field. */ -#define GPIO_OUTSET_PIN29_Msk (0x1UL << GPIO_OUTSET_PIN29_Pos) /*!< Bit mask of PIN29 field. */ -#define GPIO_OUTSET_PIN29_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTSET_PIN29_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTSET_PIN29_Set (1UL) /*!< Set pin driver high. */ - -/* Bit 28 : Pin 28. */ -#define GPIO_OUTSET_PIN28_Pos (28UL) /*!< Position of PIN28 field. */ -#define GPIO_OUTSET_PIN28_Msk (0x1UL << GPIO_OUTSET_PIN28_Pos) /*!< Bit mask of PIN28 field. */ -#define GPIO_OUTSET_PIN28_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTSET_PIN28_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTSET_PIN28_Set (1UL) /*!< Set pin driver high. */ - -/* Bit 27 : Pin 27. */ -#define GPIO_OUTSET_PIN27_Pos (27UL) /*!< Position of PIN27 field. */ -#define GPIO_OUTSET_PIN27_Msk (0x1UL << GPIO_OUTSET_PIN27_Pos) /*!< Bit mask of PIN27 field. */ -#define GPIO_OUTSET_PIN27_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTSET_PIN27_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTSET_PIN27_Set (1UL) /*!< Set pin driver high. */ - -/* Bit 26 : Pin 26. */ -#define GPIO_OUTSET_PIN26_Pos (26UL) /*!< Position of PIN26 field. */ -#define GPIO_OUTSET_PIN26_Msk (0x1UL << GPIO_OUTSET_PIN26_Pos) /*!< Bit mask of PIN26 field. */ -#define GPIO_OUTSET_PIN26_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTSET_PIN26_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTSET_PIN26_Set (1UL) /*!< Set pin driver high. */ - -/* Bit 25 : Pin 25. */ -#define GPIO_OUTSET_PIN25_Pos (25UL) /*!< Position of PIN25 field. */ -#define GPIO_OUTSET_PIN25_Msk (0x1UL << GPIO_OUTSET_PIN25_Pos) /*!< Bit mask of PIN25 field. */ -#define GPIO_OUTSET_PIN25_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTSET_PIN25_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTSET_PIN25_Set (1UL) /*!< Set pin driver high. */ - -/* Bit 24 : Pin 24. */ -#define GPIO_OUTSET_PIN24_Pos (24UL) /*!< Position of PIN24 field. */ -#define GPIO_OUTSET_PIN24_Msk (0x1UL << GPIO_OUTSET_PIN24_Pos) /*!< Bit mask of PIN24 field. */ -#define GPIO_OUTSET_PIN24_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTSET_PIN24_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTSET_PIN24_Set (1UL) /*!< Set pin driver high. */ - -/* Bit 23 : Pin 23. */ -#define GPIO_OUTSET_PIN23_Pos (23UL) /*!< Position of PIN23 field. */ -#define GPIO_OUTSET_PIN23_Msk (0x1UL << GPIO_OUTSET_PIN23_Pos) /*!< Bit mask of PIN23 field. */ -#define GPIO_OUTSET_PIN23_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTSET_PIN23_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTSET_PIN23_Set (1UL) /*!< Set pin driver high. */ - -/* Bit 22 : Pin 22. */ -#define GPIO_OUTSET_PIN22_Pos (22UL) /*!< Position of PIN22 field. */ -#define GPIO_OUTSET_PIN22_Msk (0x1UL << GPIO_OUTSET_PIN22_Pos) /*!< Bit mask of PIN22 field. */ -#define GPIO_OUTSET_PIN22_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTSET_PIN22_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTSET_PIN22_Set (1UL) /*!< Set pin driver high. */ - -/* Bit 21 : Pin 21. */ -#define GPIO_OUTSET_PIN21_Pos (21UL) /*!< Position of PIN21 field. */ -#define GPIO_OUTSET_PIN21_Msk (0x1UL << GPIO_OUTSET_PIN21_Pos) /*!< Bit mask of PIN21 field. */ -#define GPIO_OUTSET_PIN21_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTSET_PIN21_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTSET_PIN21_Set (1UL) /*!< Set pin driver high. */ - -/* Bit 20 : Pin 20. */ -#define GPIO_OUTSET_PIN20_Pos (20UL) /*!< Position of PIN20 field. */ -#define GPIO_OUTSET_PIN20_Msk (0x1UL << GPIO_OUTSET_PIN20_Pos) /*!< Bit mask of PIN20 field. */ -#define GPIO_OUTSET_PIN20_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTSET_PIN20_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTSET_PIN20_Set (1UL) /*!< Set pin driver high. */ - -/* Bit 19 : Pin 19. */ -#define GPIO_OUTSET_PIN19_Pos (19UL) /*!< Position of PIN19 field. */ -#define GPIO_OUTSET_PIN19_Msk (0x1UL << GPIO_OUTSET_PIN19_Pos) /*!< Bit mask of PIN19 field. */ -#define GPIO_OUTSET_PIN19_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTSET_PIN19_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTSET_PIN19_Set (1UL) /*!< Set pin driver high. */ - -/* Bit 18 : Pin 18. */ -#define GPIO_OUTSET_PIN18_Pos (18UL) /*!< Position of PIN18 field. */ -#define GPIO_OUTSET_PIN18_Msk (0x1UL << GPIO_OUTSET_PIN18_Pos) /*!< Bit mask of PIN18 field. */ -#define GPIO_OUTSET_PIN18_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTSET_PIN18_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTSET_PIN18_Set (1UL) /*!< Set pin driver high. */ - -/* Bit 17 : Pin 17. */ -#define GPIO_OUTSET_PIN17_Pos (17UL) /*!< Position of PIN17 field. */ -#define GPIO_OUTSET_PIN17_Msk (0x1UL << GPIO_OUTSET_PIN17_Pos) /*!< Bit mask of PIN17 field. */ -#define GPIO_OUTSET_PIN17_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTSET_PIN17_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTSET_PIN17_Set (1UL) /*!< Set pin driver high. */ - -/* Bit 16 : Pin 16. */ -#define GPIO_OUTSET_PIN16_Pos (16UL) /*!< Position of PIN16 field. */ -#define GPIO_OUTSET_PIN16_Msk (0x1UL << GPIO_OUTSET_PIN16_Pos) /*!< Bit mask of PIN16 field. */ -#define GPIO_OUTSET_PIN16_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTSET_PIN16_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTSET_PIN16_Set (1UL) /*!< Set pin driver high. */ - -/* Bit 15 : Pin 15. */ -#define GPIO_OUTSET_PIN15_Pos (15UL) /*!< Position of PIN15 field. */ -#define GPIO_OUTSET_PIN15_Msk (0x1UL << GPIO_OUTSET_PIN15_Pos) /*!< Bit mask of PIN15 field. */ -#define GPIO_OUTSET_PIN15_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTSET_PIN15_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTSET_PIN15_Set (1UL) /*!< Set pin driver high. */ - -/* Bit 14 : Pin 14. */ -#define GPIO_OUTSET_PIN14_Pos (14UL) /*!< Position of PIN14 field. */ -#define GPIO_OUTSET_PIN14_Msk (0x1UL << GPIO_OUTSET_PIN14_Pos) /*!< Bit mask of PIN14 field. */ -#define GPIO_OUTSET_PIN14_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTSET_PIN14_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTSET_PIN14_Set (1UL) /*!< Set pin driver high. */ - -/* Bit 13 : Pin 13. */ -#define GPIO_OUTSET_PIN13_Pos (13UL) /*!< Position of PIN13 field. */ -#define GPIO_OUTSET_PIN13_Msk (0x1UL << GPIO_OUTSET_PIN13_Pos) /*!< Bit mask of PIN13 field. */ -#define GPIO_OUTSET_PIN13_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTSET_PIN13_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTSET_PIN13_Set (1UL) /*!< Set pin driver high. */ - -/* Bit 12 : Pin 12. */ -#define GPIO_OUTSET_PIN12_Pos (12UL) /*!< Position of PIN12 field. */ -#define GPIO_OUTSET_PIN12_Msk (0x1UL << GPIO_OUTSET_PIN12_Pos) /*!< Bit mask of PIN12 field. */ -#define GPIO_OUTSET_PIN12_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTSET_PIN12_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTSET_PIN12_Set (1UL) /*!< Set pin driver high. */ - -/* Bit 11 : Pin 11. */ -#define GPIO_OUTSET_PIN11_Pos (11UL) /*!< Position of PIN11 field. */ -#define GPIO_OUTSET_PIN11_Msk (0x1UL << GPIO_OUTSET_PIN11_Pos) /*!< Bit mask of PIN11 field. */ -#define GPIO_OUTSET_PIN11_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTSET_PIN11_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTSET_PIN11_Set (1UL) /*!< Set pin driver high. */ - -/* Bit 10 : Pin 10. */ -#define GPIO_OUTSET_PIN10_Pos (10UL) /*!< Position of PIN10 field. */ -#define GPIO_OUTSET_PIN10_Msk (0x1UL << GPIO_OUTSET_PIN10_Pos) /*!< Bit mask of PIN10 field. */ -#define GPIO_OUTSET_PIN10_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTSET_PIN10_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTSET_PIN10_Set (1UL) /*!< Set pin driver high. */ - -/* Bit 9 : Pin 9. */ -#define GPIO_OUTSET_PIN9_Pos (9UL) /*!< Position of PIN9 field. */ -#define GPIO_OUTSET_PIN9_Msk (0x1UL << GPIO_OUTSET_PIN9_Pos) /*!< Bit mask of PIN9 field. */ -#define GPIO_OUTSET_PIN9_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTSET_PIN9_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTSET_PIN9_Set (1UL) /*!< Set pin driver high. */ - -/* Bit 8 : Pin 8. */ -#define GPIO_OUTSET_PIN8_Pos (8UL) /*!< Position of PIN8 field. */ -#define GPIO_OUTSET_PIN8_Msk (0x1UL << GPIO_OUTSET_PIN8_Pos) /*!< Bit mask of PIN8 field. */ -#define GPIO_OUTSET_PIN8_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTSET_PIN8_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTSET_PIN8_Set (1UL) /*!< Set pin driver high. */ - -/* Bit 7 : Pin 7. */ -#define GPIO_OUTSET_PIN7_Pos (7UL) /*!< Position of PIN7 field. */ -#define GPIO_OUTSET_PIN7_Msk (0x1UL << GPIO_OUTSET_PIN7_Pos) /*!< Bit mask of PIN7 field. */ -#define GPIO_OUTSET_PIN7_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTSET_PIN7_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTSET_PIN7_Set (1UL) /*!< Set pin driver high. */ - -/* Bit 6 : Pin 6. */ -#define GPIO_OUTSET_PIN6_Pos (6UL) /*!< Position of PIN6 field. */ -#define GPIO_OUTSET_PIN6_Msk (0x1UL << GPIO_OUTSET_PIN6_Pos) /*!< Bit mask of PIN6 field. */ -#define GPIO_OUTSET_PIN6_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTSET_PIN6_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTSET_PIN6_Set (1UL) /*!< Set pin driver high. */ - -/* Bit 5 : Pin 5. */ -#define GPIO_OUTSET_PIN5_Pos (5UL) /*!< Position of PIN5 field. */ -#define GPIO_OUTSET_PIN5_Msk (0x1UL << GPIO_OUTSET_PIN5_Pos) /*!< Bit mask of PIN5 field. */ -#define GPIO_OUTSET_PIN5_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTSET_PIN5_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTSET_PIN5_Set (1UL) /*!< Set pin driver high. */ - -/* Bit 4 : Pin 4. */ -#define GPIO_OUTSET_PIN4_Pos (4UL) /*!< Position of PIN4 field. */ -#define GPIO_OUTSET_PIN4_Msk (0x1UL << GPIO_OUTSET_PIN4_Pos) /*!< Bit mask of PIN4 field. */ -#define GPIO_OUTSET_PIN4_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTSET_PIN4_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTSET_PIN4_Set (1UL) /*!< Set pin driver high. */ - -/* Bit 3 : Pin 3. */ -#define GPIO_OUTSET_PIN3_Pos (3UL) /*!< Position of PIN3 field. */ -#define GPIO_OUTSET_PIN3_Msk (0x1UL << GPIO_OUTSET_PIN3_Pos) /*!< Bit mask of PIN3 field. */ -#define GPIO_OUTSET_PIN3_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTSET_PIN3_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTSET_PIN3_Set (1UL) /*!< Set pin driver high. */ - -/* Bit 2 : Pin 2. */ -#define GPIO_OUTSET_PIN2_Pos (2UL) /*!< Position of PIN2 field. */ -#define GPIO_OUTSET_PIN2_Msk (0x1UL << GPIO_OUTSET_PIN2_Pos) /*!< Bit mask of PIN2 field. */ -#define GPIO_OUTSET_PIN2_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTSET_PIN2_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTSET_PIN2_Set (1UL) /*!< Set pin driver high. */ - -/* Bit 1 : Pin 1. */ -#define GPIO_OUTSET_PIN1_Pos (1UL) /*!< Position of PIN1 field. */ -#define GPIO_OUTSET_PIN1_Msk (0x1UL << GPIO_OUTSET_PIN1_Pos) /*!< Bit mask of PIN1 field. */ -#define GPIO_OUTSET_PIN1_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTSET_PIN1_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTSET_PIN1_Set (1UL) /*!< Set pin driver high. */ - -/* Bit 0 : Pin 0. */ -#define GPIO_OUTSET_PIN0_Pos (0UL) /*!< Position of PIN0 field. */ -#define GPIO_OUTSET_PIN0_Msk (0x1UL << GPIO_OUTSET_PIN0_Pos) /*!< Bit mask of PIN0 field. */ -#define GPIO_OUTSET_PIN0_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTSET_PIN0_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTSET_PIN0_Set (1UL) /*!< Set pin driver high. */ - -/* Register: GPIO_OUTCLR */ -/* Description: Clear individual bits in GPIO port. */ - -/* Bit 31 : Pin 31. */ -#define GPIO_OUTCLR_PIN31_Pos (31UL) /*!< Position of PIN31 field. */ -#define GPIO_OUTCLR_PIN31_Msk (0x1UL << GPIO_OUTCLR_PIN31_Pos) /*!< Bit mask of PIN31 field. */ -#define GPIO_OUTCLR_PIN31_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTCLR_PIN31_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTCLR_PIN31_Clear (1UL) /*!< Set pin driver low. */ - -/* Bit 30 : Pin 30. */ -#define GPIO_OUTCLR_PIN30_Pos (30UL) /*!< Position of PIN30 field. */ -#define GPIO_OUTCLR_PIN30_Msk (0x1UL << GPIO_OUTCLR_PIN30_Pos) /*!< Bit mask of PIN30 field. */ -#define GPIO_OUTCLR_PIN30_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTCLR_PIN30_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTCLR_PIN30_Clear (1UL) /*!< Set pin driver low. */ - -/* Bit 29 : Pin 29. */ -#define GPIO_OUTCLR_PIN29_Pos (29UL) /*!< Position of PIN29 field. */ -#define GPIO_OUTCLR_PIN29_Msk (0x1UL << GPIO_OUTCLR_PIN29_Pos) /*!< Bit mask of PIN29 field. */ -#define GPIO_OUTCLR_PIN29_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTCLR_PIN29_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTCLR_PIN29_Clear (1UL) /*!< Set pin driver low. */ - -/* Bit 28 : Pin 28. */ -#define GPIO_OUTCLR_PIN28_Pos (28UL) /*!< Position of PIN28 field. */ -#define GPIO_OUTCLR_PIN28_Msk (0x1UL << GPIO_OUTCLR_PIN28_Pos) /*!< Bit mask of PIN28 field. */ -#define GPIO_OUTCLR_PIN28_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTCLR_PIN28_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTCLR_PIN28_Clear (1UL) /*!< Set pin driver low. */ - -/* Bit 27 : Pin 27. */ -#define GPIO_OUTCLR_PIN27_Pos (27UL) /*!< Position of PIN27 field. */ -#define GPIO_OUTCLR_PIN27_Msk (0x1UL << GPIO_OUTCLR_PIN27_Pos) /*!< Bit mask of PIN27 field. */ -#define GPIO_OUTCLR_PIN27_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTCLR_PIN27_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTCLR_PIN27_Clear (1UL) /*!< Set pin driver low. */ - -/* Bit 26 : Pin 26. */ -#define GPIO_OUTCLR_PIN26_Pos (26UL) /*!< Position of PIN26 field. */ -#define GPIO_OUTCLR_PIN26_Msk (0x1UL << GPIO_OUTCLR_PIN26_Pos) /*!< Bit mask of PIN26 field. */ -#define GPIO_OUTCLR_PIN26_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTCLR_PIN26_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTCLR_PIN26_Clear (1UL) /*!< Set pin driver low. */ - -/* Bit 25 : Pin 25. */ -#define GPIO_OUTCLR_PIN25_Pos (25UL) /*!< Position of PIN25 field. */ -#define GPIO_OUTCLR_PIN25_Msk (0x1UL << GPIO_OUTCLR_PIN25_Pos) /*!< Bit mask of PIN25 field. */ -#define GPIO_OUTCLR_PIN25_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTCLR_PIN25_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTCLR_PIN25_Clear (1UL) /*!< Set pin driver low. */ - -/* Bit 24 : Pin 24. */ -#define GPIO_OUTCLR_PIN24_Pos (24UL) /*!< Position of PIN24 field. */ -#define GPIO_OUTCLR_PIN24_Msk (0x1UL << GPIO_OUTCLR_PIN24_Pos) /*!< Bit mask of PIN24 field. */ -#define GPIO_OUTCLR_PIN24_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTCLR_PIN24_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTCLR_PIN24_Clear (1UL) /*!< Set pin driver low. */ - -/* Bit 23 : Pin 23. */ -#define GPIO_OUTCLR_PIN23_Pos (23UL) /*!< Position of PIN23 field. */ -#define GPIO_OUTCLR_PIN23_Msk (0x1UL << GPIO_OUTCLR_PIN23_Pos) /*!< Bit mask of PIN23 field. */ -#define GPIO_OUTCLR_PIN23_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTCLR_PIN23_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTCLR_PIN23_Clear (1UL) /*!< Set pin driver low. */ - -/* Bit 22 : Pin 22. */ -#define GPIO_OUTCLR_PIN22_Pos (22UL) /*!< Position of PIN22 field. */ -#define GPIO_OUTCLR_PIN22_Msk (0x1UL << GPIO_OUTCLR_PIN22_Pos) /*!< Bit mask of PIN22 field. */ -#define GPIO_OUTCLR_PIN22_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTCLR_PIN22_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTCLR_PIN22_Clear (1UL) /*!< Set pin driver low. */ - -/* Bit 21 : Pin 21. */ -#define GPIO_OUTCLR_PIN21_Pos (21UL) /*!< Position of PIN21 field. */ -#define GPIO_OUTCLR_PIN21_Msk (0x1UL << GPIO_OUTCLR_PIN21_Pos) /*!< Bit mask of PIN21 field. */ -#define GPIO_OUTCLR_PIN21_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTCLR_PIN21_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTCLR_PIN21_Clear (1UL) /*!< Set pin driver low. */ - -/* Bit 20 : Pin 20. */ -#define GPIO_OUTCLR_PIN20_Pos (20UL) /*!< Position of PIN20 field. */ -#define GPIO_OUTCLR_PIN20_Msk (0x1UL << GPIO_OUTCLR_PIN20_Pos) /*!< Bit mask of PIN20 field. */ -#define GPIO_OUTCLR_PIN20_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTCLR_PIN20_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTCLR_PIN20_Clear (1UL) /*!< Set pin driver low. */ - -/* Bit 19 : Pin 19. */ -#define GPIO_OUTCLR_PIN19_Pos (19UL) /*!< Position of PIN19 field. */ -#define GPIO_OUTCLR_PIN19_Msk (0x1UL << GPIO_OUTCLR_PIN19_Pos) /*!< Bit mask of PIN19 field. */ -#define GPIO_OUTCLR_PIN19_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTCLR_PIN19_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTCLR_PIN19_Clear (1UL) /*!< Set pin driver low. */ - -/* Bit 18 : Pin 18. */ -#define GPIO_OUTCLR_PIN18_Pos (18UL) /*!< Position of PIN18 field. */ -#define GPIO_OUTCLR_PIN18_Msk (0x1UL << GPIO_OUTCLR_PIN18_Pos) /*!< Bit mask of PIN18 field. */ -#define GPIO_OUTCLR_PIN18_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTCLR_PIN18_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTCLR_PIN18_Clear (1UL) /*!< Set pin driver low. */ - -/* Bit 17 : Pin 17. */ -#define GPIO_OUTCLR_PIN17_Pos (17UL) /*!< Position of PIN17 field. */ -#define GPIO_OUTCLR_PIN17_Msk (0x1UL << GPIO_OUTCLR_PIN17_Pos) /*!< Bit mask of PIN17 field. */ -#define GPIO_OUTCLR_PIN17_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTCLR_PIN17_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTCLR_PIN17_Clear (1UL) /*!< Set pin driver low. */ - -/* Bit 16 : Pin 16. */ -#define GPIO_OUTCLR_PIN16_Pos (16UL) /*!< Position of PIN16 field. */ -#define GPIO_OUTCLR_PIN16_Msk (0x1UL << GPIO_OUTCLR_PIN16_Pos) /*!< Bit mask of PIN16 field. */ -#define GPIO_OUTCLR_PIN16_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTCLR_PIN16_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTCLR_PIN16_Clear (1UL) /*!< Set pin driver low. */ - -/* Bit 15 : Pin 15. */ -#define GPIO_OUTCLR_PIN15_Pos (15UL) /*!< Position of PIN15 field. */ -#define GPIO_OUTCLR_PIN15_Msk (0x1UL << GPIO_OUTCLR_PIN15_Pos) /*!< Bit mask of PIN15 field. */ -#define GPIO_OUTCLR_PIN15_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTCLR_PIN15_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTCLR_PIN15_Clear (1UL) /*!< Set pin driver low. */ - -/* Bit 14 : Pin 14. */ -#define GPIO_OUTCLR_PIN14_Pos (14UL) /*!< Position of PIN14 field. */ -#define GPIO_OUTCLR_PIN14_Msk (0x1UL << GPIO_OUTCLR_PIN14_Pos) /*!< Bit mask of PIN14 field. */ -#define GPIO_OUTCLR_PIN14_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTCLR_PIN14_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTCLR_PIN14_Clear (1UL) /*!< Set pin driver low. */ - -/* Bit 13 : Pin 13. */ -#define GPIO_OUTCLR_PIN13_Pos (13UL) /*!< Position of PIN13 field. */ -#define GPIO_OUTCLR_PIN13_Msk (0x1UL << GPIO_OUTCLR_PIN13_Pos) /*!< Bit mask of PIN13 field. */ -#define GPIO_OUTCLR_PIN13_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTCLR_PIN13_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTCLR_PIN13_Clear (1UL) /*!< Set pin driver low. */ - -/* Bit 12 : Pin 12. */ -#define GPIO_OUTCLR_PIN12_Pos (12UL) /*!< Position of PIN12 field. */ -#define GPIO_OUTCLR_PIN12_Msk (0x1UL << GPIO_OUTCLR_PIN12_Pos) /*!< Bit mask of PIN12 field. */ -#define GPIO_OUTCLR_PIN12_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTCLR_PIN12_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTCLR_PIN12_Clear (1UL) /*!< Set pin driver low. */ - -/* Bit 11 : Pin 11. */ -#define GPIO_OUTCLR_PIN11_Pos (11UL) /*!< Position of PIN11 field. */ -#define GPIO_OUTCLR_PIN11_Msk (0x1UL << GPIO_OUTCLR_PIN11_Pos) /*!< Bit mask of PIN11 field. */ -#define GPIO_OUTCLR_PIN11_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTCLR_PIN11_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTCLR_PIN11_Clear (1UL) /*!< Set pin driver low. */ - -/* Bit 10 : Pin 10. */ -#define GPIO_OUTCLR_PIN10_Pos (10UL) /*!< Position of PIN10 field. */ -#define GPIO_OUTCLR_PIN10_Msk (0x1UL << GPIO_OUTCLR_PIN10_Pos) /*!< Bit mask of PIN10 field. */ -#define GPIO_OUTCLR_PIN10_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTCLR_PIN10_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTCLR_PIN10_Clear (1UL) /*!< Set pin driver low. */ - -/* Bit 9 : Pin 9. */ -#define GPIO_OUTCLR_PIN9_Pos (9UL) /*!< Position of PIN9 field. */ -#define GPIO_OUTCLR_PIN9_Msk (0x1UL << GPIO_OUTCLR_PIN9_Pos) /*!< Bit mask of PIN9 field. */ -#define GPIO_OUTCLR_PIN9_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTCLR_PIN9_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTCLR_PIN9_Clear (1UL) /*!< Set pin driver low. */ - -/* Bit 8 : Pin 8. */ -#define GPIO_OUTCLR_PIN8_Pos (8UL) /*!< Position of PIN8 field. */ -#define GPIO_OUTCLR_PIN8_Msk (0x1UL << GPIO_OUTCLR_PIN8_Pos) /*!< Bit mask of PIN8 field. */ -#define GPIO_OUTCLR_PIN8_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTCLR_PIN8_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTCLR_PIN8_Clear (1UL) /*!< Set pin driver low. */ - -/* Bit 7 : Pin 7. */ -#define GPIO_OUTCLR_PIN7_Pos (7UL) /*!< Position of PIN7 field. */ -#define GPIO_OUTCLR_PIN7_Msk (0x1UL << GPIO_OUTCLR_PIN7_Pos) /*!< Bit mask of PIN7 field. */ -#define GPIO_OUTCLR_PIN7_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTCLR_PIN7_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTCLR_PIN7_Clear (1UL) /*!< Set pin driver low. */ - -/* Bit 6 : Pin 6. */ -#define GPIO_OUTCLR_PIN6_Pos (6UL) /*!< Position of PIN6 field. */ -#define GPIO_OUTCLR_PIN6_Msk (0x1UL << GPIO_OUTCLR_PIN6_Pos) /*!< Bit mask of PIN6 field. */ -#define GPIO_OUTCLR_PIN6_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTCLR_PIN6_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTCLR_PIN6_Clear (1UL) /*!< Set pin driver low. */ - -/* Bit 5 : Pin 5. */ -#define GPIO_OUTCLR_PIN5_Pos (5UL) /*!< Position of PIN5 field. */ -#define GPIO_OUTCLR_PIN5_Msk (0x1UL << GPIO_OUTCLR_PIN5_Pos) /*!< Bit mask of PIN5 field. */ -#define GPIO_OUTCLR_PIN5_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTCLR_PIN5_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTCLR_PIN5_Clear (1UL) /*!< Set pin driver low. */ - -/* Bit 4 : Pin 4. */ -#define GPIO_OUTCLR_PIN4_Pos (4UL) /*!< Position of PIN4 field. */ -#define GPIO_OUTCLR_PIN4_Msk (0x1UL << GPIO_OUTCLR_PIN4_Pos) /*!< Bit mask of PIN4 field. */ -#define GPIO_OUTCLR_PIN4_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTCLR_PIN4_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTCLR_PIN4_Clear (1UL) /*!< Set pin driver low. */ - -/* Bit 3 : Pin 3. */ -#define GPIO_OUTCLR_PIN3_Pos (3UL) /*!< Position of PIN3 field. */ -#define GPIO_OUTCLR_PIN3_Msk (0x1UL << GPIO_OUTCLR_PIN3_Pos) /*!< Bit mask of PIN3 field. */ -#define GPIO_OUTCLR_PIN3_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTCLR_PIN3_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTCLR_PIN3_Clear (1UL) /*!< Set pin driver low. */ - -/* Bit 2 : Pin 2. */ -#define GPIO_OUTCLR_PIN2_Pos (2UL) /*!< Position of PIN2 field. */ -#define GPIO_OUTCLR_PIN2_Msk (0x1UL << GPIO_OUTCLR_PIN2_Pos) /*!< Bit mask of PIN2 field. */ -#define GPIO_OUTCLR_PIN2_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTCLR_PIN2_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTCLR_PIN2_Clear (1UL) /*!< Set pin driver low. */ - -/* Bit 1 : Pin 1. */ -#define GPIO_OUTCLR_PIN1_Pos (1UL) /*!< Position of PIN1 field. */ -#define GPIO_OUTCLR_PIN1_Msk (0x1UL << GPIO_OUTCLR_PIN1_Pos) /*!< Bit mask of PIN1 field. */ -#define GPIO_OUTCLR_PIN1_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTCLR_PIN1_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTCLR_PIN1_Clear (1UL) /*!< Set pin driver low. */ - -/* Bit 0 : Pin 0. */ -#define GPIO_OUTCLR_PIN0_Pos (0UL) /*!< Position of PIN0 field. */ -#define GPIO_OUTCLR_PIN0_Msk (0x1UL << GPIO_OUTCLR_PIN0_Pos) /*!< Bit mask of PIN0 field. */ -#define GPIO_OUTCLR_PIN0_Low (0UL) /*!< Pin driver is low. */ -#define GPIO_OUTCLR_PIN0_High (1UL) /*!< Pin driver is high. */ -#define GPIO_OUTCLR_PIN0_Clear (1UL) /*!< Set pin driver low. */ - -/* Register: GPIO_IN */ -/* Description: Read GPIO port. */ - -/* Bit 31 : Pin 31. */ -#define GPIO_IN_PIN31_Pos (31UL) /*!< Position of PIN31 field. */ -#define GPIO_IN_PIN31_Msk (0x1UL << GPIO_IN_PIN31_Pos) /*!< Bit mask of PIN31 field. */ -#define GPIO_IN_PIN31_Low (0UL) /*!< Pin input is low. */ -#define GPIO_IN_PIN31_High (1UL) /*!< Pin input is high. */ - -/* Bit 30 : Pin 30. */ -#define GPIO_IN_PIN30_Pos (30UL) /*!< Position of PIN30 field. */ -#define GPIO_IN_PIN30_Msk (0x1UL << GPIO_IN_PIN30_Pos) /*!< Bit mask of PIN30 field. */ -#define GPIO_IN_PIN30_Low (0UL) /*!< Pin input is low. */ -#define GPIO_IN_PIN30_High (1UL) /*!< Pin input is high. */ - -/* Bit 29 : Pin 29. */ -#define GPIO_IN_PIN29_Pos (29UL) /*!< Position of PIN29 field. */ -#define GPIO_IN_PIN29_Msk (0x1UL << GPIO_IN_PIN29_Pos) /*!< Bit mask of PIN29 field. */ -#define GPIO_IN_PIN29_Low (0UL) /*!< Pin input is low. */ -#define GPIO_IN_PIN29_High (1UL) /*!< Pin input is high. */ - -/* Bit 28 : Pin 28. */ -#define GPIO_IN_PIN28_Pos (28UL) /*!< Position of PIN28 field. */ -#define GPIO_IN_PIN28_Msk (0x1UL << GPIO_IN_PIN28_Pos) /*!< Bit mask of PIN28 field. */ -#define GPIO_IN_PIN28_Low (0UL) /*!< Pin input is low. */ -#define GPIO_IN_PIN28_High (1UL) /*!< Pin input is high. */ - -/* Bit 27 : Pin 27. */ -#define GPIO_IN_PIN27_Pos (27UL) /*!< Position of PIN27 field. */ -#define GPIO_IN_PIN27_Msk (0x1UL << GPIO_IN_PIN27_Pos) /*!< Bit mask of PIN27 field. */ -#define GPIO_IN_PIN27_Low (0UL) /*!< Pin input is low. */ -#define GPIO_IN_PIN27_High (1UL) /*!< Pin input is high. */ - -/* Bit 26 : Pin 26. */ -#define GPIO_IN_PIN26_Pos (26UL) /*!< Position of PIN26 field. */ -#define GPIO_IN_PIN26_Msk (0x1UL << GPIO_IN_PIN26_Pos) /*!< Bit mask of PIN26 field. */ -#define GPIO_IN_PIN26_Low (0UL) /*!< Pin input is low. */ -#define GPIO_IN_PIN26_High (1UL) /*!< Pin input is high. */ - -/* Bit 25 : Pin 25. */ -#define GPIO_IN_PIN25_Pos (25UL) /*!< Position of PIN25 field. */ -#define GPIO_IN_PIN25_Msk (0x1UL << GPIO_IN_PIN25_Pos) /*!< Bit mask of PIN25 field. */ -#define GPIO_IN_PIN25_Low (0UL) /*!< Pin input is low. */ -#define GPIO_IN_PIN25_High (1UL) /*!< Pin input is high. */ - -/* Bit 24 : Pin 24. */ -#define GPIO_IN_PIN24_Pos (24UL) /*!< Position of PIN24 field. */ -#define GPIO_IN_PIN24_Msk (0x1UL << GPIO_IN_PIN24_Pos) /*!< Bit mask of PIN24 field. */ -#define GPIO_IN_PIN24_Low (0UL) /*!< Pin input is low. */ -#define GPIO_IN_PIN24_High (1UL) /*!< Pin input is high. */ - -/* Bit 23 : Pin 23. */ -#define GPIO_IN_PIN23_Pos (23UL) /*!< Position of PIN23 field. */ -#define GPIO_IN_PIN23_Msk (0x1UL << GPIO_IN_PIN23_Pos) /*!< Bit mask of PIN23 field. */ -#define GPIO_IN_PIN23_Low (0UL) /*!< Pin input is low. */ -#define GPIO_IN_PIN23_High (1UL) /*!< Pin input is high. */ - -/* Bit 22 : Pin 22. */ -#define GPIO_IN_PIN22_Pos (22UL) /*!< Position of PIN22 field. */ -#define GPIO_IN_PIN22_Msk (0x1UL << GPIO_IN_PIN22_Pos) /*!< Bit mask of PIN22 field. */ -#define GPIO_IN_PIN22_Low (0UL) /*!< Pin input is low. */ -#define GPIO_IN_PIN22_High (1UL) /*!< Pin input is high. */ - -/* Bit 21 : Pin 21. */ -#define GPIO_IN_PIN21_Pos (21UL) /*!< Position of PIN21 field. */ -#define GPIO_IN_PIN21_Msk (0x1UL << GPIO_IN_PIN21_Pos) /*!< Bit mask of PIN21 field. */ -#define GPIO_IN_PIN21_Low (0UL) /*!< Pin input is low. */ -#define GPIO_IN_PIN21_High (1UL) /*!< Pin input is high. */ - -/* Bit 20 : Pin 20. */ -#define GPIO_IN_PIN20_Pos (20UL) /*!< Position of PIN20 field. */ -#define GPIO_IN_PIN20_Msk (0x1UL << GPIO_IN_PIN20_Pos) /*!< Bit mask of PIN20 field. */ -#define GPIO_IN_PIN20_Low (0UL) /*!< Pin input is low. */ -#define GPIO_IN_PIN20_High (1UL) /*!< Pin input is high. */ - -/* Bit 19 : Pin 19. */ -#define GPIO_IN_PIN19_Pos (19UL) /*!< Position of PIN19 field. */ -#define GPIO_IN_PIN19_Msk (0x1UL << GPIO_IN_PIN19_Pos) /*!< Bit mask of PIN19 field. */ -#define GPIO_IN_PIN19_Low (0UL) /*!< Pin input is low. */ -#define GPIO_IN_PIN19_High (1UL) /*!< Pin input is high. */ - -/* Bit 18 : Pin 18. */ -#define GPIO_IN_PIN18_Pos (18UL) /*!< Position of PIN18 field. */ -#define GPIO_IN_PIN18_Msk (0x1UL << GPIO_IN_PIN18_Pos) /*!< Bit mask of PIN18 field. */ -#define GPIO_IN_PIN18_Low (0UL) /*!< Pin input is low. */ -#define GPIO_IN_PIN18_High (1UL) /*!< Pin input is high. */ - -/* Bit 17 : Pin 17. */ -#define GPIO_IN_PIN17_Pos (17UL) /*!< Position of PIN17 field. */ -#define GPIO_IN_PIN17_Msk (0x1UL << GPIO_IN_PIN17_Pos) /*!< Bit mask of PIN17 field. */ -#define GPIO_IN_PIN17_Low (0UL) /*!< Pin input is low. */ -#define GPIO_IN_PIN17_High (1UL) /*!< Pin input is high. */ - -/* Bit 16 : Pin 16. */ -#define GPIO_IN_PIN16_Pos (16UL) /*!< Position of PIN16 field. */ -#define GPIO_IN_PIN16_Msk (0x1UL << GPIO_IN_PIN16_Pos) /*!< Bit mask of PIN16 field. */ -#define GPIO_IN_PIN16_Low (0UL) /*!< Pin input is low. */ -#define GPIO_IN_PIN16_High (1UL) /*!< Pin input is high. */ - -/* Bit 15 : Pin 15. */ -#define GPIO_IN_PIN15_Pos (15UL) /*!< Position of PIN15 field. */ -#define GPIO_IN_PIN15_Msk (0x1UL << GPIO_IN_PIN15_Pos) /*!< Bit mask of PIN15 field. */ -#define GPIO_IN_PIN15_Low (0UL) /*!< Pin input is low. */ -#define GPIO_IN_PIN15_High (1UL) /*!< Pin input is high. */ - -/* Bit 14 : Pin 14. */ -#define GPIO_IN_PIN14_Pos (14UL) /*!< Position of PIN14 field. */ -#define GPIO_IN_PIN14_Msk (0x1UL << GPIO_IN_PIN14_Pos) /*!< Bit mask of PIN14 field. */ -#define GPIO_IN_PIN14_Low (0UL) /*!< Pin input is low. */ -#define GPIO_IN_PIN14_High (1UL) /*!< Pin input is high. */ - -/* Bit 13 : Pin 13. */ -#define GPIO_IN_PIN13_Pos (13UL) /*!< Position of PIN13 field. */ -#define GPIO_IN_PIN13_Msk (0x1UL << GPIO_IN_PIN13_Pos) /*!< Bit mask of PIN13 field. */ -#define GPIO_IN_PIN13_Low (0UL) /*!< Pin input is low. */ -#define GPIO_IN_PIN13_High (1UL) /*!< Pin input is high. */ - -/* Bit 12 : Pin 12. */ -#define GPIO_IN_PIN12_Pos (12UL) /*!< Position of PIN12 field. */ -#define GPIO_IN_PIN12_Msk (0x1UL << GPIO_IN_PIN12_Pos) /*!< Bit mask of PIN12 field. */ -#define GPIO_IN_PIN12_Low (0UL) /*!< Pin input is low. */ -#define GPIO_IN_PIN12_High (1UL) /*!< Pin input is high. */ - -/* Bit 11 : Pin 11. */ -#define GPIO_IN_PIN11_Pos (11UL) /*!< Position of PIN11 field. */ -#define GPIO_IN_PIN11_Msk (0x1UL << GPIO_IN_PIN11_Pos) /*!< Bit mask of PIN11 field. */ -#define GPIO_IN_PIN11_Low (0UL) /*!< Pin input is low. */ -#define GPIO_IN_PIN11_High (1UL) /*!< Pin input is high. */ - -/* Bit 10 : Pin 10. */ -#define GPIO_IN_PIN10_Pos (10UL) /*!< Position of PIN10 field. */ -#define GPIO_IN_PIN10_Msk (0x1UL << GPIO_IN_PIN10_Pos) /*!< Bit mask of PIN10 field. */ -#define GPIO_IN_PIN10_Low (0UL) /*!< Pin input is low. */ -#define GPIO_IN_PIN10_High (1UL) /*!< Pin input is high. */ - -/* Bit 9 : Pin 9. */ -#define GPIO_IN_PIN9_Pos (9UL) /*!< Position of PIN9 field. */ -#define GPIO_IN_PIN9_Msk (0x1UL << GPIO_IN_PIN9_Pos) /*!< Bit mask of PIN9 field. */ -#define GPIO_IN_PIN9_Low (0UL) /*!< Pin input is low. */ -#define GPIO_IN_PIN9_High (1UL) /*!< Pin input is high. */ - -/* Bit 8 : Pin 8. */ -#define GPIO_IN_PIN8_Pos (8UL) /*!< Position of PIN8 field. */ -#define GPIO_IN_PIN8_Msk (0x1UL << GPIO_IN_PIN8_Pos) /*!< Bit mask of PIN8 field. */ -#define GPIO_IN_PIN8_Low (0UL) /*!< Pin input is low. */ -#define GPIO_IN_PIN8_High (1UL) /*!< Pin input is high. */ - -/* Bit 7 : Pin 7. */ -#define GPIO_IN_PIN7_Pos (7UL) /*!< Position of PIN7 field. */ -#define GPIO_IN_PIN7_Msk (0x1UL << GPIO_IN_PIN7_Pos) /*!< Bit mask of PIN7 field. */ -#define GPIO_IN_PIN7_Low (0UL) /*!< Pin input is low. */ -#define GPIO_IN_PIN7_High (1UL) /*!< Pin input is high. */ - -/* Bit 6 : Pin 6. */ -#define GPIO_IN_PIN6_Pos (6UL) /*!< Position of PIN6 field. */ -#define GPIO_IN_PIN6_Msk (0x1UL << GPIO_IN_PIN6_Pos) /*!< Bit mask of PIN6 field. */ -#define GPIO_IN_PIN6_Low (0UL) /*!< Pin input is low. */ -#define GPIO_IN_PIN6_High (1UL) /*!< Pin input is high. */ - -/* Bit 5 : Pin 5. */ -#define GPIO_IN_PIN5_Pos (5UL) /*!< Position of PIN5 field. */ -#define GPIO_IN_PIN5_Msk (0x1UL << GPIO_IN_PIN5_Pos) /*!< Bit mask of PIN5 field. */ -#define GPIO_IN_PIN5_Low (0UL) /*!< Pin input is low. */ -#define GPIO_IN_PIN5_High (1UL) /*!< Pin input is high. */ - -/* Bit 4 : Pin 4. */ -#define GPIO_IN_PIN4_Pos (4UL) /*!< Position of PIN4 field. */ -#define GPIO_IN_PIN4_Msk (0x1UL << GPIO_IN_PIN4_Pos) /*!< Bit mask of PIN4 field. */ -#define GPIO_IN_PIN4_Low (0UL) /*!< Pin input is low. */ -#define GPIO_IN_PIN4_High (1UL) /*!< Pin input is high. */ - -/* Bit 3 : Pin 3. */ -#define GPIO_IN_PIN3_Pos (3UL) /*!< Position of PIN3 field. */ -#define GPIO_IN_PIN3_Msk (0x1UL << GPIO_IN_PIN3_Pos) /*!< Bit mask of PIN3 field. */ -#define GPIO_IN_PIN3_Low (0UL) /*!< Pin input is low. */ -#define GPIO_IN_PIN3_High (1UL) /*!< Pin input is high. */ - -/* Bit 2 : Pin 2. */ -#define GPIO_IN_PIN2_Pos (2UL) /*!< Position of PIN2 field. */ -#define GPIO_IN_PIN2_Msk (0x1UL << GPIO_IN_PIN2_Pos) /*!< Bit mask of PIN2 field. */ -#define GPIO_IN_PIN2_Low (0UL) /*!< Pin input is low. */ -#define GPIO_IN_PIN2_High (1UL) /*!< Pin input is high. */ - -/* Bit 1 : Pin 1. */ -#define GPIO_IN_PIN1_Pos (1UL) /*!< Position of PIN1 field. */ -#define GPIO_IN_PIN1_Msk (0x1UL << GPIO_IN_PIN1_Pos) /*!< Bit mask of PIN1 field. */ -#define GPIO_IN_PIN1_Low (0UL) /*!< Pin input is low. */ -#define GPIO_IN_PIN1_High (1UL) /*!< Pin input is high. */ - -/* Bit 0 : Pin 0. */ -#define GPIO_IN_PIN0_Pos (0UL) /*!< Position of PIN0 field. */ -#define GPIO_IN_PIN0_Msk (0x1UL << GPIO_IN_PIN0_Pos) /*!< Bit mask of PIN0 field. */ -#define GPIO_IN_PIN0_Low (0UL) /*!< Pin input is low. */ -#define GPIO_IN_PIN0_High (1UL) /*!< Pin input is high. */ - -/* Register: GPIO_DIR */ -/* Description: Direction of GPIO pins. */ - -/* Bit 31 : Pin 31. */ -#define GPIO_DIR_PIN31_Pos (31UL) /*!< Position of PIN31 field. */ -#define GPIO_DIR_PIN31_Msk (0x1UL << GPIO_DIR_PIN31_Pos) /*!< Bit mask of PIN31 field. */ -#define GPIO_DIR_PIN31_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIR_PIN31_Output (1UL) /*!< Pin set as output. */ - -/* Bit 30 : Pin 30. */ -#define GPIO_DIR_PIN30_Pos (30UL) /*!< Position of PIN30 field. */ -#define GPIO_DIR_PIN30_Msk (0x1UL << GPIO_DIR_PIN30_Pos) /*!< Bit mask of PIN30 field. */ -#define GPIO_DIR_PIN30_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIR_PIN30_Output (1UL) /*!< Pin set as output. */ - -/* Bit 29 : Pin 29. */ -#define GPIO_DIR_PIN29_Pos (29UL) /*!< Position of PIN29 field. */ -#define GPIO_DIR_PIN29_Msk (0x1UL << GPIO_DIR_PIN29_Pos) /*!< Bit mask of PIN29 field. */ -#define GPIO_DIR_PIN29_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIR_PIN29_Output (1UL) /*!< Pin set as output. */ - -/* Bit 28 : Pin 28. */ -#define GPIO_DIR_PIN28_Pos (28UL) /*!< Position of PIN28 field. */ -#define GPIO_DIR_PIN28_Msk (0x1UL << GPIO_DIR_PIN28_Pos) /*!< Bit mask of PIN28 field. */ -#define GPIO_DIR_PIN28_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIR_PIN28_Output (1UL) /*!< Pin set as output. */ - -/* Bit 27 : Pin 27. */ -#define GPIO_DIR_PIN27_Pos (27UL) /*!< Position of PIN27 field. */ -#define GPIO_DIR_PIN27_Msk (0x1UL << GPIO_DIR_PIN27_Pos) /*!< Bit mask of PIN27 field. */ -#define GPIO_DIR_PIN27_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIR_PIN27_Output (1UL) /*!< Pin set as output. */ - -/* Bit 26 : Pin 26. */ -#define GPIO_DIR_PIN26_Pos (26UL) /*!< Position of PIN26 field. */ -#define GPIO_DIR_PIN26_Msk (0x1UL << GPIO_DIR_PIN26_Pos) /*!< Bit mask of PIN26 field. */ -#define GPIO_DIR_PIN26_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIR_PIN26_Output (1UL) /*!< Pin set as output. */ - -/* Bit 25 : Pin 25. */ -#define GPIO_DIR_PIN25_Pos (25UL) /*!< Position of PIN25 field. */ -#define GPIO_DIR_PIN25_Msk (0x1UL << GPIO_DIR_PIN25_Pos) /*!< Bit mask of PIN25 field. */ -#define GPIO_DIR_PIN25_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIR_PIN25_Output (1UL) /*!< Pin set as output. */ - -/* Bit 24 : Pin 24. */ -#define GPIO_DIR_PIN24_Pos (24UL) /*!< Position of PIN24 field. */ -#define GPIO_DIR_PIN24_Msk (0x1UL << GPIO_DIR_PIN24_Pos) /*!< Bit mask of PIN24 field. */ -#define GPIO_DIR_PIN24_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIR_PIN24_Output (1UL) /*!< Pin set as output. */ - -/* Bit 23 : Pin 23. */ -#define GPIO_DIR_PIN23_Pos (23UL) /*!< Position of PIN23 field. */ -#define GPIO_DIR_PIN23_Msk (0x1UL << GPIO_DIR_PIN23_Pos) /*!< Bit mask of PIN23 field. */ -#define GPIO_DIR_PIN23_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIR_PIN23_Output (1UL) /*!< Pin set as output. */ - -/* Bit 22 : Pin 22. */ -#define GPIO_DIR_PIN22_Pos (22UL) /*!< Position of PIN22 field. */ -#define GPIO_DIR_PIN22_Msk (0x1UL << GPIO_DIR_PIN22_Pos) /*!< Bit mask of PIN22 field. */ -#define GPIO_DIR_PIN22_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIR_PIN22_Output (1UL) /*!< Pin set as output. */ - -/* Bit 21 : Pin 21. */ -#define GPIO_DIR_PIN21_Pos (21UL) /*!< Position of PIN21 field. */ -#define GPIO_DIR_PIN21_Msk (0x1UL << GPIO_DIR_PIN21_Pos) /*!< Bit mask of PIN21 field. */ -#define GPIO_DIR_PIN21_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIR_PIN21_Output (1UL) /*!< Pin set as output. */ - -/* Bit 20 : Pin 20. */ -#define GPIO_DIR_PIN20_Pos (20UL) /*!< Position of PIN20 field. */ -#define GPIO_DIR_PIN20_Msk (0x1UL << GPIO_DIR_PIN20_Pos) /*!< Bit mask of PIN20 field. */ -#define GPIO_DIR_PIN20_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIR_PIN20_Output (1UL) /*!< Pin set as output. */ - -/* Bit 19 : Pin 19. */ -#define GPIO_DIR_PIN19_Pos (19UL) /*!< Position of PIN19 field. */ -#define GPIO_DIR_PIN19_Msk (0x1UL << GPIO_DIR_PIN19_Pos) /*!< Bit mask of PIN19 field. */ -#define GPIO_DIR_PIN19_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIR_PIN19_Output (1UL) /*!< Pin set as output. */ - -/* Bit 18 : Pin 18. */ -#define GPIO_DIR_PIN18_Pos (18UL) /*!< Position of PIN18 field. */ -#define GPIO_DIR_PIN18_Msk (0x1UL << GPIO_DIR_PIN18_Pos) /*!< Bit mask of PIN18 field. */ -#define GPIO_DIR_PIN18_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIR_PIN18_Output (1UL) /*!< Pin set as output. */ - -/* Bit 17 : Pin 17. */ -#define GPIO_DIR_PIN17_Pos (17UL) /*!< Position of PIN17 field. */ -#define GPIO_DIR_PIN17_Msk (0x1UL << GPIO_DIR_PIN17_Pos) /*!< Bit mask of PIN17 field. */ -#define GPIO_DIR_PIN17_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIR_PIN17_Output (1UL) /*!< Pin set as output. */ - -/* Bit 16 : Pin 16. */ -#define GPIO_DIR_PIN16_Pos (16UL) /*!< Position of PIN16 field. */ -#define GPIO_DIR_PIN16_Msk (0x1UL << GPIO_DIR_PIN16_Pos) /*!< Bit mask of PIN16 field. */ -#define GPIO_DIR_PIN16_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIR_PIN16_Output (1UL) /*!< Pin set as output. */ - -/* Bit 15 : Pin 15. */ -#define GPIO_DIR_PIN15_Pos (15UL) /*!< Position of PIN15 field. */ -#define GPIO_DIR_PIN15_Msk (0x1UL << GPIO_DIR_PIN15_Pos) /*!< Bit mask of PIN15 field. */ -#define GPIO_DIR_PIN15_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIR_PIN15_Output (1UL) /*!< Pin set as output. */ - -/* Bit 14 : Pin 14. */ -#define GPIO_DIR_PIN14_Pos (14UL) /*!< Position of PIN14 field. */ -#define GPIO_DIR_PIN14_Msk (0x1UL << GPIO_DIR_PIN14_Pos) /*!< Bit mask of PIN14 field. */ -#define GPIO_DIR_PIN14_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIR_PIN14_Output (1UL) /*!< Pin set as output. */ - -/* Bit 13 : Pin 13. */ -#define GPIO_DIR_PIN13_Pos (13UL) /*!< Position of PIN13 field. */ -#define GPIO_DIR_PIN13_Msk (0x1UL << GPIO_DIR_PIN13_Pos) /*!< Bit mask of PIN13 field. */ -#define GPIO_DIR_PIN13_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIR_PIN13_Output (1UL) /*!< Pin set as output. */ - -/* Bit 12 : Pin 12. */ -#define GPIO_DIR_PIN12_Pos (12UL) /*!< Position of PIN12 field. */ -#define GPIO_DIR_PIN12_Msk (0x1UL << GPIO_DIR_PIN12_Pos) /*!< Bit mask of PIN12 field. */ -#define GPIO_DIR_PIN12_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIR_PIN12_Output (1UL) /*!< Pin set as output. */ - -/* Bit 11 : Pin 11. */ -#define GPIO_DIR_PIN11_Pos (11UL) /*!< Position of PIN11 field. */ -#define GPIO_DIR_PIN11_Msk (0x1UL << GPIO_DIR_PIN11_Pos) /*!< Bit mask of PIN11 field. */ -#define GPIO_DIR_PIN11_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIR_PIN11_Output (1UL) /*!< Pin set as output. */ - -/* Bit 10 : Pin 10. */ -#define GPIO_DIR_PIN10_Pos (10UL) /*!< Position of PIN10 field. */ -#define GPIO_DIR_PIN10_Msk (0x1UL << GPIO_DIR_PIN10_Pos) /*!< Bit mask of PIN10 field. */ -#define GPIO_DIR_PIN10_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIR_PIN10_Output (1UL) /*!< Pin set as output. */ - -/* Bit 9 : Pin 9. */ -#define GPIO_DIR_PIN9_Pos (9UL) /*!< Position of PIN9 field. */ -#define GPIO_DIR_PIN9_Msk (0x1UL << GPIO_DIR_PIN9_Pos) /*!< Bit mask of PIN9 field. */ -#define GPIO_DIR_PIN9_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIR_PIN9_Output (1UL) /*!< Pin set as output. */ - -/* Bit 8 : Pin 8. */ -#define GPIO_DIR_PIN8_Pos (8UL) /*!< Position of PIN8 field. */ -#define GPIO_DIR_PIN8_Msk (0x1UL << GPIO_DIR_PIN8_Pos) /*!< Bit mask of PIN8 field. */ -#define GPIO_DIR_PIN8_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIR_PIN8_Output (1UL) /*!< Pin set as output. */ - -/* Bit 7 : Pin 7. */ -#define GPIO_DIR_PIN7_Pos (7UL) /*!< Position of PIN7 field. */ -#define GPIO_DIR_PIN7_Msk (0x1UL << GPIO_DIR_PIN7_Pos) /*!< Bit mask of PIN7 field. */ -#define GPIO_DIR_PIN7_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIR_PIN7_Output (1UL) /*!< Pin set as output. */ - -/* Bit 6 : Pin 6. */ -#define GPIO_DIR_PIN6_Pos (6UL) /*!< Position of PIN6 field. */ -#define GPIO_DIR_PIN6_Msk (0x1UL << GPIO_DIR_PIN6_Pos) /*!< Bit mask of PIN6 field. */ -#define GPIO_DIR_PIN6_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIR_PIN6_Output (1UL) /*!< Pin set as output. */ - -/* Bit 5 : Pin 5. */ -#define GPIO_DIR_PIN5_Pos (5UL) /*!< Position of PIN5 field. */ -#define GPIO_DIR_PIN5_Msk (0x1UL << GPIO_DIR_PIN5_Pos) /*!< Bit mask of PIN5 field. */ -#define GPIO_DIR_PIN5_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIR_PIN5_Output (1UL) /*!< Pin set as output. */ - -/* Bit 4 : Pin 4. */ -#define GPIO_DIR_PIN4_Pos (4UL) /*!< Position of PIN4 field. */ -#define GPIO_DIR_PIN4_Msk (0x1UL << GPIO_DIR_PIN4_Pos) /*!< Bit mask of PIN4 field. */ -#define GPIO_DIR_PIN4_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIR_PIN4_Output (1UL) /*!< Pin set as output. */ - -/* Bit 3 : Pin 3. */ -#define GPIO_DIR_PIN3_Pos (3UL) /*!< Position of PIN3 field. */ -#define GPIO_DIR_PIN3_Msk (0x1UL << GPIO_DIR_PIN3_Pos) /*!< Bit mask of PIN3 field. */ -#define GPIO_DIR_PIN3_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIR_PIN3_Output (1UL) /*!< Pin set as output. */ - -/* Bit 2 : Pin 2. */ -#define GPIO_DIR_PIN2_Pos (2UL) /*!< Position of PIN2 field. */ -#define GPIO_DIR_PIN2_Msk (0x1UL << GPIO_DIR_PIN2_Pos) /*!< Bit mask of PIN2 field. */ -#define GPIO_DIR_PIN2_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIR_PIN2_Output (1UL) /*!< Pin set as output. */ - -/* Bit 1 : Pin 1. */ -#define GPIO_DIR_PIN1_Pos (1UL) /*!< Position of PIN1 field. */ -#define GPIO_DIR_PIN1_Msk (0x1UL << GPIO_DIR_PIN1_Pos) /*!< Bit mask of PIN1 field. */ -#define GPIO_DIR_PIN1_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIR_PIN1_Output (1UL) /*!< Pin set as output. */ - -/* Bit 0 : Pin 0. */ -#define GPIO_DIR_PIN0_Pos (0UL) /*!< Position of PIN0 field. */ -#define GPIO_DIR_PIN0_Msk (0x1UL << GPIO_DIR_PIN0_Pos) /*!< Bit mask of PIN0 field. */ -#define GPIO_DIR_PIN0_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIR_PIN0_Output (1UL) /*!< Pin set as output. */ - -/* Register: GPIO_DIRSET */ -/* Description: DIR set register. */ - -/* Bit 31 : Set as output pin 31. */ -#define GPIO_DIRSET_PIN31_Pos (31UL) /*!< Position of PIN31 field. */ -#define GPIO_DIRSET_PIN31_Msk (0x1UL << GPIO_DIRSET_PIN31_Pos) /*!< Bit mask of PIN31 field. */ -#define GPIO_DIRSET_PIN31_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRSET_PIN31_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRSET_PIN31_Set (1UL) /*!< Set pin as output. */ - -/* Bit 30 : Set as output pin 30. */ -#define GPIO_DIRSET_PIN30_Pos (30UL) /*!< Position of PIN30 field. */ -#define GPIO_DIRSET_PIN30_Msk (0x1UL << GPIO_DIRSET_PIN30_Pos) /*!< Bit mask of PIN30 field. */ -#define GPIO_DIRSET_PIN30_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRSET_PIN30_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRSET_PIN30_Set (1UL) /*!< Set pin as output. */ - -/* Bit 29 : Set as output pin 29. */ -#define GPIO_DIRSET_PIN29_Pos (29UL) /*!< Position of PIN29 field. */ -#define GPIO_DIRSET_PIN29_Msk (0x1UL << GPIO_DIRSET_PIN29_Pos) /*!< Bit mask of PIN29 field. */ -#define GPIO_DIRSET_PIN29_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRSET_PIN29_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRSET_PIN29_Set (1UL) /*!< Set pin as output. */ - -/* Bit 28 : Set as output pin 28. */ -#define GPIO_DIRSET_PIN28_Pos (28UL) /*!< Position of PIN28 field. */ -#define GPIO_DIRSET_PIN28_Msk (0x1UL << GPIO_DIRSET_PIN28_Pos) /*!< Bit mask of PIN28 field. */ -#define GPIO_DIRSET_PIN28_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRSET_PIN28_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRSET_PIN28_Set (1UL) /*!< Set pin as output. */ - -/* Bit 27 : Set as output pin 27. */ -#define GPIO_DIRSET_PIN27_Pos (27UL) /*!< Position of PIN27 field. */ -#define GPIO_DIRSET_PIN27_Msk (0x1UL << GPIO_DIRSET_PIN27_Pos) /*!< Bit mask of PIN27 field. */ -#define GPIO_DIRSET_PIN27_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRSET_PIN27_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRSET_PIN27_Set (1UL) /*!< Set pin as output. */ - -/* Bit 26 : Set as output pin 26. */ -#define GPIO_DIRSET_PIN26_Pos (26UL) /*!< Position of PIN26 field. */ -#define GPIO_DIRSET_PIN26_Msk (0x1UL << GPIO_DIRSET_PIN26_Pos) /*!< Bit mask of PIN26 field. */ -#define GPIO_DIRSET_PIN26_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRSET_PIN26_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRSET_PIN26_Set (1UL) /*!< Set pin as output. */ - -/* Bit 25 : Set as output pin 25. */ -#define GPIO_DIRSET_PIN25_Pos (25UL) /*!< Position of PIN25 field. */ -#define GPIO_DIRSET_PIN25_Msk (0x1UL << GPIO_DIRSET_PIN25_Pos) /*!< Bit mask of PIN25 field. */ -#define GPIO_DIRSET_PIN25_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRSET_PIN25_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRSET_PIN25_Set (1UL) /*!< Set pin as output. */ - -/* Bit 24 : Set as output pin 24. */ -#define GPIO_DIRSET_PIN24_Pos (24UL) /*!< Position of PIN24 field. */ -#define GPIO_DIRSET_PIN24_Msk (0x1UL << GPIO_DIRSET_PIN24_Pos) /*!< Bit mask of PIN24 field. */ -#define GPIO_DIRSET_PIN24_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRSET_PIN24_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRSET_PIN24_Set (1UL) /*!< Set pin as output. */ - -/* Bit 23 : Set as output pin 23. */ -#define GPIO_DIRSET_PIN23_Pos (23UL) /*!< Position of PIN23 field. */ -#define GPIO_DIRSET_PIN23_Msk (0x1UL << GPIO_DIRSET_PIN23_Pos) /*!< Bit mask of PIN23 field. */ -#define GPIO_DIRSET_PIN23_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRSET_PIN23_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRSET_PIN23_Set (1UL) /*!< Set pin as output. */ - -/* Bit 22 : Set as output pin 22. */ -#define GPIO_DIRSET_PIN22_Pos (22UL) /*!< Position of PIN22 field. */ -#define GPIO_DIRSET_PIN22_Msk (0x1UL << GPIO_DIRSET_PIN22_Pos) /*!< Bit mask of PIN22 field. */ -#define GPIO_DIRSET_PIN22_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRSET_PIN22_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRSET_PIN22_Set (1UL) /*!< Set pin as output. */ - -/* Bit 21 : Set as output pin 21. */ -#define GPIO_DIRSET_PIN21_Pos (21UL) /*!< Position of PIN21 field. */ -#define GPIO_DIRSET_PIN21_Msk (0x1UL << GPIO_DIRSET_PIN21_Pos) /*!< Bit mask of PIN21 field. */ -#define GPIO_DIRSET_PIN21_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRSET_PIN21_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRSET_PIN21_Set (1UL) /*!< Set pin as output. */ - -/* Bit 20 : Set as output pin 20. */ -#define GPIO_DIRSET_PIN20_Pos (20UL) /*!< Position of PIN20 field. */ -#define GPIO_DIRSET_PIN20_Msk (0x1UL << GPIO_DIRSET_PIN20_Pos) /*!< Bit mask of PIN20 field. */ -#define GPIO_DIRSET_PIN20_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRSET_PIN20_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRSET_PIN20_Set (1UL) /*!< Set pin as output. */ - -/* Bit 19 : Set as output pin 19. */ -#define GPIO_DIRSET_PIN19_Pos (19UL) /*!< Position of PIN19 field. */ -#define GPIO_DIRSET_PIN19_Msk (0x1UL << GPIO_DIRSET_PIN19_Pos) /*!< Bit mask of PIN19 field. */ -#define GPIO_DIRSET_PIN19_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRSET_PIN19_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRSET_PIN19_Set (1UL) /*!< Set pin as output. */ - -/* Bit 18 : Set as output pin 18. */ -#define GPIO_DIRSET_PIN18_Pos (18UL) /*!< Position of PIN18 field. */ -#define GPIO_DIRSET_PIN18_Msk (0x1UL << GPIO_DIRSET_PIN18_Pos) /*!< Bit mask of PIN18 field. */ -#define GPIO_DIRSET_PIN18_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRSET_PIN18_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRSET_PIN18_Set (1UL) /*!< Set pin as output. */ - -/* Bit 17 : Set as output pin 17. */ -#define GPIO_DIRSET_PIN17_Pos (17UL) /*!< Position of PIN17 field. */ -#define GPIO_DIRSET_PIN17_Msk (0x1UL << GPIO_DIRSET_PIN17_Pos) /*!< Bit mask of PIN17 field. */ -#define GPIO_DIRSET_PIN17_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRSET_PIN17_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRSET_PIN17_Set (1UL) /*!< Set pin as output. */ - -/* Bit 16 : Set as output pin 16. */ -#define GPIO_DIRSET_PIN16_Pos (16UL) /*!< Position of PIN16 field. */ -#define GPIO_DIRSET_PIN16_Msk (0x1UL << GPIO_DIRSET_PIN16_Pos) /*!< Bit mask of PIN16 field. */ -#define GPIO_DIRSET_PIN16_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRSET_PIN16_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRSET_PIN16_Set (1UL) /*!< Set pin as output. */ - -/* Bit 15 : Set as output pin 15. */ -#define GPIO_DIRSET_PIN15_Pos (15UL) /*!< Position of PIN15 field. */ -#define GPIO_DIRSET_PIN15_Msk (0x1UL << GPIO_DIRSET_PIN15_Pos) /*!< Bit mask of PIN15 field. */ -#define GPIO_DIRSET_PIN15_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRSET_PIN15_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRSET_PIN15_Set (1UL) /*!< Set pin as output. */ - -/* Bit 14 : Set as output pin 14. */ -#define GPIO_DIRSET_PIN14_Pos (14UL) /*!< Position of PIN14 field. */ -#define GPIO_DIRSET_PIN14_Msk (0x1UL << GPIO_DIRSET_PIN14_Pos) /*!< Bit mask of PIN14 field. */ -#define GPIO_DIRSET_PIN14_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRSET_PIN14_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRSET_PIN14_Set (1UL) /*!< Set pin as output. */ - -/* Bit 13 : Set as output pin 13. */ -#define GPIO_DIRSET_PIN13_Pos (13UL) /*!< Position of PIN13 field. */ -#define GPIO_DIRSET_PIN13_Msk (0x1UL << GPIO_DIRSET_PIN13_Pos) /*!< Bit mask of PIN13 field. */ -#define GPIO_DIRSET_PIN13_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRSET_PIN13_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRSET_PIN13_Set (1UL) /*!< Set pin as output. */ - -/* Bit 12 : Set as output pin 12. */ -#define GPIO_DIRSET_PIN12_Pos (12UL) /*!< Position of PIN12 field. */ -#define GPIO_DIRSET_PIN12_Msk (0x1UL << GPIO_DIRSET_PIN12_Pos) /*!< Bit mask of PIN12 field. */ -#define GPIO_DIRSET_PIN12_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRSET_PIN12_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRSET_PIN12_Set (1UL) /*!< Set pin as output. */ - -/* Bit 11 : Set as output pin 11. */ -#define GPIO_DIRSET_PIN11_Pos (11UL) /*!< Position of PIN11 field. */ -#define GPIO_DIRSET_PIN11_Msk (0x1UL << GPIO_DIRSET_PIN11_Pos) /*!< Bit mask of PIN11 field. */ -#define GPIO_DIRSET_PIN11_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRSET_PIN11_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRSET_PIN11_Set (1UL) /*!< Set pin as output. */ - -/* Bit 10 : Set as output pin 10. */ -#define GPIO_DIRSET_PIN10_Pos (10UL) /*!< Position of PIN10 field. */ -#define GPIO_DIRSET_PIN10_Msk (0x1UL << GPIO_DIRSET_PIN10_Pos) /*!< Bit mask of PIN10 field. */ -#define GPIO_DIRSET_PIN10_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRSET_PIN10_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRSET_PIN10_Set (1UL) /*!< Set pin as output. */ - -/* Bit 9 : Set as output pin 9. */ -#define GPIO_DIRSET_PIN9_Pos (9UL) /*!< Position of PIN9 field. */ -#define GPIO_DIRSET_PIN9_Msk (0x1UL << GPIO_DIRSET_PIN9_Pos) /*!< Bit mask of PIN9 field. */ -#define GPIO_DIRSET_PIN9_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRSET_PIN9_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRSET_PIN9_Set (1UL) /*!< Set pin as output. */ - -/* Bit 8 : Set as output pin 8. */ -#define GPIO_DIRSET_PIN8_Pos (8UL) /*!< Position of PIN8 field. */ -#define GPIO_DIRSET_PIN8_Msk (0x1UL << GPIO_DIRSET_PIN8_Pos) /*!< Bit mask of PIN8 field. */ -#define GPIO_DIRSET_PIN8_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRSET_PIN8_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRSET_PIN8_Set (1UL) /*!< Set pin as output. */ - -/* Bit 7 : Set as output pin 7. */ -#define GPIO_DIRSET_PIN7_Pos (7UL) /*!< Position of PIN7 field. */ -#define GPIO_DIRSET_PIN7_Msk (0x1UL << GPIO_DIRSET_PIN7_Pos) /*!< Bit mask of PIN7 field. */ -#define GPIO_DIRSET_PIN7_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRSET_PIN7_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRSET_PIN7_Set (1UL) /*!< Set pin as output. */ - -/* Bit 6 : Set as output pin 6. */ -#define GPIO_DIRSET_PIN6_Pos (6UL) /*!< Position of PIN6 field. */ -#define GPIO_DIRSET_PIN6_Msk (0x1UL << GPIO_DIRSET_PIN6_Pos) /*!< Bit mask of PIN6 field. */ -#define GPIO_DIRSET_PIN6_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRSET_PIN6_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRSET_PIN6_Set (1UL) /*!< Set pin as output. */ - -/* Bit 5 : Set as output pin 5. */ -#define GPIO_DIRSET_PIN5_Pos (5UL) /*!< Position of PIN5 field. */ -#define GPIO_DIRSET_PIN5_Msk (0x1UL << GPIO_DIRSET_PIN5_Pos) /*!< Bit mask of PIN5 field. */ -#define GPIO_DIRSET_PIN5_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRSET_PIN5_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRSET_PIN5_Set (1UL) /*!< Set pin as output. */ - -/* Bit 4 : Set as output pin 4. */ -#define GPIO_DIRSET_PIN4_Pos (4UL) /*!< Position of PIN4 field. */ -#define GPIO_DIRSET_PIN4_Msk (0x1UL << GPIO_DIRSET_PIN4_Pos) /*!< Bit mask of PIN4 field. */ -#define GPIO_DIRSET_PIN4_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRSET_PIN4_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRSET_PIN4_Set (1UL) /*!< Set pin as output. */ - -/* Bit 3 : Set as output pin 3. */ -#define GPIO_DIRSET_PIN3_Pos (3UL) /*!< Position of PIN3 field. */ -#define GPIO_DIRSET_PIN3_Msk (0x1UL << GPIO_DIRSET_PIN3_Pos) /*!< Bit mask of PIN3 field. */ -#define GPIO_DIRSET_PIN3_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRSET_PIN3_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRSET_PIN3_Set (1UL) /*!< Set pin as output. */ - -/* Bit 2 : Set as output pin 2. */ -#define GPIO_DIRSET_PIN2_Pos (2UL) /*!< Position of PIN2 field. */ -#define GPIO_DIRSET_PIN2_Msk (0x1UL << GPIO_DIRSET_PIN2_Pos) /*!< Bit mask of PIN2 field. */ -#define GPIO_DIRSET_PIN2_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRSET_PIN2_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRSET_PIN2_Set (1UL) /*!< Set pin as output. */ - -/* Bit 1 : Set as output pin 1. */ -#define GPIO_DIRSET_PIN1_Pos (1UL) /*!< Position of PIN1 field. */ -#define GPIO_DIRSET_PIN1_Msk (0x1UL << GPIO_DIRSET_PIN1_Pos) /*!< Bit mask of PIN1 field. */ -#define GPIO_DIRSET_PIN1_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRSET_PIN1_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRSET_PIN1_Set (1UL) /*!< Set pin as output. */ - -/* Bit 0 : Set as output pin 0. */ -#define GPIO_DIRSET_PIN0_Pos (0UL) /*!< Position of PIN0 field. */ -#define GPIO_DIRSET_PIN0_Msk (0x1UL << GPIO_DIRSET_PIN0_Pos) /*!< Bit mask of PIN0 field. */ -#define GPIO_DIRSET_PIN0_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRSET_PIN0_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRSET_PIN0_Set (1UL) /*!< Set pin as output. */ - -/* Register: GPIO_DIRCLR */ -/* Description: DIR clear register. */ - -/* Bit 31 : Set as input pin 31. */ -#define GPIO_DIRCLR_PIN31_Pos (31UL) /*!< Position of PIN31 field. */ -#define GPIO_DIRCLR_PIN31_Msk (0x1UL << GPIO_DIRCLR_PIN31_Pos) /*!< Bit mask of PIN31 field. */ -#define GPIO_DIRCLR_PIN31_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRCLR_PIN31_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRCLR_PIN31_Clear (1UL) /*!< Set pin as input. */ - -/* Bit 30 : Set as input pin 30. */ -#define GPIO_DIRCLR_PIN30_Pos (30UL) /*!< Position of PIN30 field. */ -#define GPIO_DIRCLR_PIN30_Msk (0x1UL << GPIO_DIRCLR_PIN30_Pos) /*!< Bit mask of PIN30 field. */ -#define GPIO_DIRCLR_PIN30_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRCLR_PIN30_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRCLR_PIN30_Clear (1UL) /*!< Set pin as input. */ - -/* Bit 29 : Set as input pin 29. */ -#define GPIO_DIRCLR_PIN29_Pos (29UL) /*!< Position of PIN29 field. */ -#define GPIO_DIRCLR_PIN29_Msk (0x1UL << GPIO_DIRCLR_PIN29_Pos) /*!< Bit mask of PIN29 field. */ -#define GPIO_DIRCLR_PIN29_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRCLR_PIN29_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRCLR_PIN29_Clear (1UL) /*!< Set pin as input. */ - -/* Bit 28 : Set as input pin 28. */ -#define GPIO_DIRCLR_PIN28_Pos (28UL) /*!< Position of PIN28 field. */ -#define GPIO_DIRCLR_PIN28_Msk (0x1UL << GPIO_DIRCLR_PIN28_Pos) /*!< Bit mask of PIN28 field. */ -#define GPIO_DIRCLR_PIN28_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRCLR_PIN28_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRCLR_PIN28_Clear (1UL) /*!< Set pin as input. */ - -/* Bit 27 : Set as input pin 27. */ -#define GPIO_DIRCLR_PIN27_Pos (27UL) /*!< Position of PIN27 field. */ -#define GPIO_DIRCLR_PIN27_Msk (0x1UL << GPIO_DIRCLR_PIN27_Pos) /*!< Bit mask of PIN27 field. */ -#define GPIO_DIRCLR_PIN27_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRCLR_PIN27_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRCLR_PIN27_Clear (1UL) /*!< Set pin as input. */ - -/* Bit 26 : Set as input pin 26. */ -#define GPIO_DIRCLR_PIN26_Pos (26UL) /*!< Position of PIN26 field. */ -#define GPIO_DIRCLR_PIN26_Msk (0x1UL << GPIO_DIRCLR_PIN26_Pos) /*!< Bit mask of PIN26 field. */ -#define GPIO_DIRCLR_PIN26_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRCLR_PIN26_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRCLR_PIN26_Clear (1UL) /*!< Set pin as input. */ - -/* Bit 25 : Set as input pin 25. */ -#define GPIO_DIRCLR_PIN25_Pos (25UL) /*!< Position of PIN25 field. */ -#define GPIO_DIRCLR_PIN25_Msk (0x1UL << GPIO_DIRCLR_PIN25_Pos) /*!< Bit mask of PIN25 field. */ -#define GPIO_DIRCLR_PIN25_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRCLR_PIN25_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRCLR_PIN25_Clear (1UL) /*!< Set pin as input. */ - -/* Bit 24 : Set as input pin 24. */ -#define GPIO_DIRCLR_PIN24_Pos (24UL) /*!< Position of PIN24 field. */ -#define GPIO_DIRCLR_PIN24_Msk (0x1UL << GPIO_DIRCLR_PIN24_Pos) /*!< Bit mask of PIN24 field. */ -#define GPIO_DIRCLR_PIN24_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRCLR_PIN24_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRCLR_PIN24_Clear (1UL) /*!< Set pin as input. */ - -/* Bit 23 : Set as input pin 23. */ -#define GPIO_DIRCLR_PIN23_Pos (23UL) /*!< Position of PIN23 field. */ -#define GPIO_DIRCLR_PIN23_Msk (0x1UL << GPIO_DIRCLR_PIN23_Pos) /*!< Bit mask of PIN23 field. */ -#define GPIO_DIRCLR_PIN23_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRCLR_PIN23_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRCLR_PIN23_Clear (1UL) /*!< Set pin as input. */ - -/* Bit 22 : Set as input pin 22. */ -#define GPIO_DIRCLR_PIN22_Pos (22UL) /*!< Position of PIN22 field. */ -#define GPIO_DIRCLR_PIN22_Msk (0x1UL << GPIO_DIRCLR_PIN22_Pos) /*!< Bit mask of PIN22 field. */ -#define GPIO_DIRCLR_PIN22_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRCLR_PIN22_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRCLR_PIN22_Clear (1UL) /*!< Set pin as input. */ - -/* Bit 21 : Set as input pin 21. */ -#define GPIO_DIRCLR_PIN21_Pos (21UL) /*!< Position of PIN21 field. */ -#define GPIO_DIRCLR_PIN21_Msk (0x1UL << GPIO_DIRCLR_PIN21_Pos) /*!< Bit mask of PIN21 field. */ -#define GPIO_DIRCLR_PIN21_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRCLR_PIN21_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRCLR_PIN21_Clear (1UL) /*!< Set pin as input. */ - -/* Bit 20 : Set as input pin 20. */ -#define GPIO_DIRCLR_PIN20_Pos (20UL) /*!< Position of PIN20 field. */ -#define GPIO_DIRCLR_PIN20_Msk (0x1UL << GPIO_DIRCLR_PIN20_Pos) /*!< Bit mask of PIN20 field. */ -#define GPIO_DIRCLR_PIN20_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRCLR_PIN20_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRCLR_PIN20_Clear (1UL) /*!< Set pin as input. */ - -/* Bit 19 : Set as input pin 19. */ -#define GPIO_DIRCLR_PIN19_Pos (19UL) /*!< Position of PIN19 field. */ -#define GPIO_DIRCLR_PIN19_Msk (0x1UL << GPIO_DIRCLR_PIN19_Pos) /*!< Bit mask of PIN19 field. */ -#define GPIO_DIRCLR_PIN19_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRCLR_PIN19_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRCLR_PIN19_Clear (1UL) /*!< Set pin as input. */ - -/* Bit 18 : Set as input pin 18. */ -#define GPIO_DIRCLR_PIN18_Pos (18UL) /*!< Position of PIN18 field. */ -#define GPIO_DIRCLR_PIN18_Msk (0x1UL << GPIO_DIRCLR_PIN18_Pos) /*!< Bit mask of PIN18 field. */ -#define GPIO_DIRCLR_PIN18_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRCLR_PIN18_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRCLR_PIN18_Clear (1UL) /*!< Set pin as input. */ - -/* Bit 17 : Set as input pin 17. */ -#define GPIO_DIRCLR_PIN17_Pos (17UL) /*!< Position of PIN17 field. */ -#define GPIO_DIRCLR_PIN17_Msk (0x1UL << GPIO_DIRCLR_PIN17_Pos) /*!< Bit mask of PIN17 field. */ -#define GPIO_DIRCLR_PIN17_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRCLR_PIN17_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRCLR_PIN17_Clear (1UL) /*!< Set pin as input. */ - -/* Bit 16 : Set as input pin 16. */ -#define GPIO_DIRCLR_PIN16_Pos (16UL) /*!< Position of PIN16 field. */ -#define GPIO_DIRCLR_PIN16_Msk (0x1UL << GPIO_DIRCLR_PIN16_Pos) /*!< Bit mask of PIN16 field. */ -#define GPIO_DIRCLR_PIN16_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRCLR_PIN16_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRCLR_PIN16_Clear (1UL) /*!< Set pin as input. */ - -/* Bit 15 : Set as input pin 15. */ -#define GPIO_DIRCLR_PIN15_Pos (15UL) /*!< Position of PIN15 field. */ -#define GPIO_DIRCLR_PIN15_Msk (0x1UL << GPIO_DIRCLR_PIN15_Pos) /*!< Bit mask of PIN15 field. */ -#define GPIO_DIRCLR_PIN15_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRCLR_PIN15_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRCLR_PIN15_Clear (1UL) /*!< Set pin as input. */ - -/* Bit 14 : Set as input pin 14. */ -#define GPIO_DIRCLR_PIN14_Pos (14UL) /*!< Position of PIN14 field. */ -#define GPIO_DIRCLR_PIN14_Msk (0x1UL << GPIO_DIRCLR_PIN14_Pos) /*!< Bit mask of PIN14 field. */ -#define GPIO_DIRCLR_PIN14_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRCLR_PIN14_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRCLR_PIN14_Clear (1UL) /*!< Set pin as input. */ - -/* Bit 13 : Set as input pin 13. */ -#define GPIO_DIRCLR_PIN13_Pos (13UL) /*!< Position of PIN13 field. */ -#define GPIO_DIRCLR_PIN13_Msk (0x1UL << GPIO_DIRCLR_PIN13_Pos) /*!< Bit mask of PIN13 field. */ -#define GPIO_DIRCLR_PIN13_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRCLR_PIN13_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRCLR_PIN13_Clear (1UL) /*!< Set pin as input. */ - -/* Bit 12 : Set as input pin 12. */ -#define GPIO_DIRCLR_PIN12_Pos (12UL) /*!< Position of PIN12 field. */ -#define GPIO_DIRCLR_PIN12_Msk (0x1UL << GPIO_DIRCLR_PIN12_Pos) /*!< Bit mask of PIN12 field. */ -#define GPIO_DIRCLR_PIN12_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRCLR_PIN12_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRCLR_PIN12_Clear (1UL) /*!< Set pin as input. */ - -/* Bit 11 : Set as input pin 11. */ -#define GPIO_DIRCLR_PIN11_Pos (11UL) /*!< Position of PIN11 field. */ -#define GPIO_DIRCLR_PIN11_Msk (0x1UL << GPIO_DIRCLR_PIN11_Pos) /*!< Bit mask of PIN11 field. */ -#define GPIO_DIRCLR_PIN11_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRCLR_PIN11_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRCLR_PIN11_Clear (1UL) /*!< Set pin as input. */ - -/* Bit 10 : Set as input pin 10. */ -#define GPIO_DIRCLR_PIN10_Pos (10UL) /*!< Position of PIN10 field. */ -#define GPIO_DIRCLR_PIN10_Msk (0x1UL << GPIO_DIRCLR_PIN10_Pos) /*!< Bit mask of PIN10 field. */ -#define GPIO_DIRCLR_PIN10_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRCLR_PIN10_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRCLR_PIN10_Clear (1UL) /*!< Set pin as input. */ - -/* Bit 9 : Set as input pin 9. */ -#define GPIO_DIRCLR_PIN9_Pos (9UL) /*!< Position of PIN9 field. */ -#define GPIO_DIRCLR_PIN9_Msk (0x1UL << GPIO_DIRCLR_PIN9_Pos) /*!< Bit mask of PIN9 field. */ -#define GPIO_DIRCLR_PIN9_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRCLR_PIN9_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRCLR_PIN9_Clear (1UL) /*!< Set pin as input. */ - -/* Bit 8 : Set as input pin 8. */ -#define GPIO_DIRCLR_PIN8_Pos (8UL) /*!< Position of PIN8 field. */ -#define GPIO_DIRCLR_PIN8_Msk (0x1UL << GPIO_DIRCLR_PIN8_Pos) /*!< Bit mask of PIN8 field. */ -#define GPIO_DIRCLR_PIN8_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRCLR_PIN8_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRCLR_PIN8_Clear (1UL) /*!< Set pin as input. */ - -/* Bit 7 : Set as input pin 7. */ -#define GPIO_DIRCLR_PIN7_Pos (7UL) /*!< Position of PIN7 field. */ -#define GPIO_DIRCLR_PIN7_Msk (0x1UL << GPIO_DIRCLR_PIN7_Pos) /*!< Bit mask of PIN7 field. */ -#define GPIO_DIRCLR_PIN7_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRCLR_PIN7_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRCLR_PIN7_Clear (1UL) /*!< Set pin as input. */ - -/* Bit 6 : Set as input pin 6. */ -#define GPIO_DIRCLR_PIN6_Pos (6UL) /*!< Position of PIN6 field. */ -#define GPIO_DIRCLR_PIN6_Msk (0x1UL << GPIO_DIRCLR_PIN6_Pos) /*!< Bit mask of PIN6 field. */ -#define GPIO_DIRCLR_PIN6_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRCLR_PIN6_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRCLR_PIN6_Clear (1UL) /*!< Set pin as input. */ - -/* Bit 5 : Set as input pin 5. */ -#define GPIO_DIRCLR_PIN5_Pos (5UL) /*!< Position of PIN5 field. */ -#define GPIO_DIRCLR_PIN5_Msk (0x1UL << GPIO_DIRCLR_PIN5_Pos) /*!< Bit mask of PIN5 field. */ -#define GPIO_DIRCLR_PIN5_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRCLR_PIN5_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRCLR_PIN5_Clear (1UL) /*!< Set pin as input. */ - -/* Bit 4 : Set as input pin 4. */ -#define GPIO_DIRCLR_PIN4_Pos (4UL) /*!< Position of PIN4 field. */ -#define GPIO_DIRCLR_PIN4_Msk (0x1UL << GPIO_DIRCLR_PIN4_Pos) /*!< Bit mask of PIN4 field. */ -#define GPIO_DIRCLR_PIN4_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRCLR_PIN4_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRCLR_PIN4_Clear (1UL) /*!< Set pin as input. */ - -/* Bit 3 : Set as input pin 3. */ -#define GPIO_DIRCLR_PIN3_Pos (3UL) /*!< Position of PIN3 field. */ -#define GPIO_DIRCLR_PIN3_Msk (0x1UL << GPIO_DIRCLR_PIN3_Pos) /*!< Bit mask of PIN3 field. */ -#define GPIO_DIRCLR_PIN3_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRCLR_PIN3_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRCLR_PIN3_Clear (1UL) /*!< Set pin as input. */ - -/* Bit 2 : Set as input pin 2. */ -#define GPIO_DIRCLR_PIN2_Pos (2UL) /*!< Position of PIN2 field. */ -#define GPIO_DIRCLR_PIN2_Msk (0x1UL << GPIO_DIRCLR_PIN2_Pos) /*!< Bit mask of PIN2 field. */ -#define GPIO_DIRCLR_PIN2_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRCLR_PIN2_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRCLR_PIN2_Clear (1UL) /*!< Set pin as input. */ - -/* Bit 1 : Set as input pin 1. */ -#define GPIO_DIRCLR_PIN1_Pos (1UL) /*!< Position of PIN1 field. */ -#define GPIO_DIRCLR_PIN1_Msk (0x1UL << GPIO_DIRCLR_PIN1_Pos) /*!< Bit mask of PIN1 field. */ -#define GPIO_DIRCLR_PIN1_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRCLR_PIN1_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRCLR_PIN1_Clear (1UL) /*!< Set pin as input. */ - -/* Bit 0 : Set as input pin 0. */ -#define GPIO_DIRCLR_PIN0_Pos (0UL) /*!< Position of PIN0 field. */ -#define GPIO_DIRCLR_PIN0_Msk (0x1UL << GPIO_DIRCLR_PIN0_Pos) /*!< Bit mask of PIN0 field. */ -#define GPIO_DIRCLR_PIN0_Input (0UL) /*!< Pin set as input. */ -#define GPIO_DIRCLR_PIN0_Output (1UL) /*!< Pin set as output. */ -#define GPIO_DIRCLR_PIN0_Clear (1UL) /*!< Set pin as input. */ - -/* Register: GPIO_PIN_CNF */ -/* Description: Configuration of GPIO pins. */ - -/* Bits 17..16 : Pin sensing mechanism. */ -#define GPIO_PIN_CNF_SENSE_Pos (16UL) /*!< Position of SENSE field. */ -#define GPIO_PIN_CNF_SENSE_Msk (0x3UL << GPIO_PIN_CNF_SENSE_Pos) /*!< Bit mask of SENSE field. */ -#define GPIO_PIN_CNF_SENSE_Disabled (0x00UL) /*!< Disabled. */ -#define GPIO_PIN_CNF_SENSE_High (0x02UL) /*!< Wakeup on high level. */ -#define GPIO_PIN_CNF_SENSE_Low (0x03UL) /*!< Wakeup on low level. */ - -/* Bits 10..8 : Drive configuration. */ -#define GPIO_PIN_CNF_DRIVE_Pos (8UL) /*!< Position of DRIVE field. */ -#define GPIO_PIN_CNF_DRIVE_Msk (0x7UL << GPIO_PIN_CNF_DRIVE_Pos) /*!< Bit mask of DRIVE field. */ -#define GPIO_PIN_CNF_DRIVE_S0S1 (0x00UL) /*!< Standard '0', Standard '1'. */ -#define GPIO_PIN_CNF_DRIVE_H0S1 (0x01UL) /*!< High '0', Standard '1'. */ -#define GPIO_PIN_CNF_DRIVE_S0H1 (0x02UL) /*!< Standard '0', High '1'. */ -#define GPIO_PIN_CNF_DRIVE_H0H1 (0x03UL) /*!< High '0', High '1'. */ -#define GPIO_PIN_CNF_DRIVE_D0S1 (0x04UL) /*!< Disconnected '0', Standard '1'. */ -#define GPIO_PIN_CNF_DRIVE_D0H1 (0x05UL) /*!< Disconnected '0', High '1'. */ -#define GPIO_PIN_CNF_DRIVE_S0D1 (0x06UL) /*!< Standard '0', Disconnected '1'. */ -#define GPIO_PIN_CNF_DRIVE_H0D1 (0x07UL) /*!< High '0', Disconnected '1'. */ - -/* Bits 3..2 : Pull-up or -down configuration. */ -#define GPIO_PIN_CNF_PULL_Pos (2UL) /*!< Position of PULL field. */ -#define GPIO_PIN_CNF_PULL_Msk (0x3UL << GPIO_PIN_CNF_PULL_Pos) /*!< Bit mask of PULL field. */ -#define GPIO_PIN_CNF_PULL_Disabled (0x00UL) /*!< No pull. */ -#define GPIO_PIN_CNF_PULL_Pulldown (0x01UL) /*!< Pulldown on pin. */ -#define GPIO_PIN_CNF_PULL_Pullup (0x03UL) /*!< Pullup on pin. */ - -/* Bit 1 : Connect or disconnect input path. */ -#define GPIO_PIN_CNF_INPUT_Pos (1UL) /*!< Position of INPUT field. */ -#define GPIO_PIN_CNF_INPUT_Msk (0x1UL << GPIO_PIN_CNF_INPUT_Pos) /*!< Bit mask of INPUT field. */ -#define GPIO_PIN_CNF_INPUT_Connect (0UL) /*!< Connect input pin. */ -#define GPIO_PIN_CNF_INPUT_Disconnect (1UL) /*!< Disconnect input pin. */ - -/* Bit 0 : Pin direction. */ -#define GPIO_PIN_CNF_DIR_Pos (0UL) /*!< Position of DIR field. */ -#define GPIO_PIN_CNF_DIR_Msk (0x1UL << GPIO_PIN_CNF_DIR_Pos) /*!< Bit mask of DIR field. */ -#define GPIO_PIN_CNF_DIR_Input (0UL) /*!< Configure pin as an input pin. */ -#define GPIO_PIN_CNF_DIR_Output (1UL) /*!< Configure pin as an output pin. */ - - -/* Peripheral: GPIOTE */ -/* Description: GPIO tasks and events. */ - -/* Register: GPIOTE_INTENSET */ -/* Description: Interrupt enable set register. */ - -/* Bit 31 : Enable interrupt on PORT event. */ -#define GPIOTE_INTENSET_PORT_Pos (31UL) /*!< Position of PORT field. */ -#define GPIOTE_INTENSET_PORT_Msk (0x1UL << GPIOTE_INTENSET_PORT_Pos) /*!< Bit mask of PORT field. */ -#define GPIOTE_INTENSET_PORT_Disabled (0UL) /*!< Interrupt disabled. */ -#define GPIOTE_INTENSET_PORT_Enabled (1UL) /*!< Interrupt enabled. */ -#define GPIOTE_INTENSET_PORT_Set (1UL) /*!< Enable interrupt on write. */ - -/* Bit 3 : Enable interrupt on IN[3] event. */ -#define GPIOTE_INTENSET_IN3_Pos (3UL) /*!< Position of IN3 field. */ -#define GPIOTE_INTENSET_IN3_Msk (0x1UL << GPIOTE_INTENSET_IN3_Pos) /*!< Bit mask of IN3 field. */ -#define GPIOTE_INTENSET_IN3_Disabled (0UL) /*!< Interrupt disabled. */ -#define GPIOTE_INTENSET_IN3_Enabled (1UL) /*!< Interrupt enabled. */ -#define GPIOTE_INTENSET_IN3_Set (1UL) /*!< Enable interrupt on write. */ - -/* Bit 2 : Enable interrupt on IN[2] event. */ -#define GPIOTE_INTENSET_IN2_Pos (2UL) /*!< Position of IN2 field. */ -#define GPIOTE_INTENSET_IN2_Msk (0x1UL << GPIOTE_INTENSET_IN2_Pos) /*!< Bit mask of IN2 field. */ -#define GPIOTE_INTENSET_IN2_Disabled (0UL) /*!< Interrupt disabled. */ -#define GPIOTE_INTENSET_IN2_Enabled (1UL) /*!< Interrupt enabled. */ -#define GPIOTE_INTENSET_IN2_Set (1UL) /*!< Enable interrupt on write. */ - -/* Bit 1 : Enable interrupt on IN[1] event. */ -#define GPIOTE_INTENSET_IN1_Pos (1UL) /*!< Position of IN1 field. */ -#define GPIOTE_INTENSET_IN1_Msk (0x1UL << GPIOTE_INTENSET_IN1_Pos) /*!< Bit mask of IN1 field. */ -#define GPIOTE_INTENSET_IN1_Disabled (0UL) /*!< Interrupt disabled. */ -#define GPIOTE_INTENSET_IN1_Enabled (1UL) /*!< Interrupt enabled. */ -#define GPIOTE_INTENSET_IN1_Set (1UL) /*!< Enable interrupt on write. */ - -/* Bit 0 : Enable interrupt on IN[0] event. */ -#define GPIOTE_INTENSET_IN0_Pos (0UL) /*!< Position of IN0 field. */ -#define GPIOTE_INTENSET_IN0_Msk (0x1UL << GPIOTE_INTENSET_IN0_Pos) /*!< Bit mask of IN0 field. */ -#define GPIOTE_INTENSET_IN0_Disabled (0UL) /*!< Interrupt disabled. */ -#define GPIOTE_INTENSET_IN0_Enabled (1UL) /*!< Interrupt enabled. */ -#define GPIOTE_INTENSET_IN0_Set (1UL) /*!< Enable interrupt on write. */ - -/* Register: GPIOTE_INTENCLR */ -/* Description: Interrupt enable clear register. */ - -/* Bit 31 : Disable interrupt on PORT event. */ -#define GPIOTE_INTENCLR_PORT_Pos (31UL) /*!< Position of PORT field. */ -#define GPIOTE_INTENCLR_PORT_Msk (0x1UL << GPIOTE_INTENCLR_PORT_Pos) /*!< Bit mask of PORT field. */ -#define GPIOTE_INTENCLR_PORT_Disabled (0UL) /*!< Interrupt disabled. */ -#define GPIOTE_INTENCLR_PORT_Enabled (1UL) /*!< Interrupt enabled. */ -#define GPIOTE_INTENCLR_PORT_Clear (1UL) /*!< Disable interrupt on write. */ - -/* Bit 3 : Disable interrupt on IN[3] event. */ -#define GPIOTE_INTENCLR_IN3_Pos (3UL) /*!< Position of IN3 field. */ -#define GPIOTE_INTENCLR_IN3_Msk (0x1UL << GPIOTE_INTENCLR_IN3_Pos) /*!< Bit mask of IN3 field. */ -#define GPIOTE_INTENCLR_IN3_Disabled (0UL) /*!< Interrupt disabled. */ -#define GPIOTE_INTENCLR_IN3_Enabled (1UL) /*!< Interrupt enabled. */ -#define GPIOTE_INTENCLR_IN3_Clear (1UL) /*!< Disable interrupt on write. */ - -/* Bit 2 : Disable interrupt on IN[2] event. */ -#define GPIOTE_INTENCLR_IN2_Pos (2UL) /*!< Position of IN2 field. */ -#define GPIOTE_INTENCLR_IN2_Msk (0x1UL << GPIOTE_INTENCLR_IN2_Pos) /*!< Bit mask of IN2 field. */ -#define GPIOTE_INTENCLR_IN2_Disabled (0UL) /*!< Interrupt disabled. */ -#define GPIOTE_INTENCLR_IN2_Enabled (1UL) /*!< Interrupt enabled. */ -#define GPIOTE_INTENCLR_IN2_Clear (1UL) /*!< Disable interrupt on write. */ - -/* Bit 1 : Disable interrupt on IN[1] event. */ -#define GPIOTE_INTENCLR_IN1_Pos (1UL) /*!< Position of IN1 field. */ -#define GPIOTE_INTENCLR_IN1_Msk (0x1UL << GPIOTE_INTENCLR_IN1_Pos) /*!< Bit mask of IN1 field. */ -#define GPIOTE_INTENCLR_IN1_Disabled (0UL) /*!< Interrupt disabled. */ -#define GPIOTE_INTENCLR_IN1_Enabled (1UL) /*!< Interrupt enabled. */ -#define GPIOTE_INTENCLR_IN1_Clear (1UL) /*!< Disable interrupt on write. */ - -/* Bit 0 : Disable interrupt on IN[0] event. */ -#define GPIOTE_INTENCLR_IN0_Pos (0UL) /*!< Position of IN0 field. */ -#define GPIOTE_INTENCLR_IN0_Msk (0x1UL << GPIOTE_INTENCLR_IN0_Pos) /*!< Bit mask of IN0 field. */ -#define GPIOTE_INTENCLR_IN0_Disabled (0UL) /*!< Interrupt disabled. */ -#define GPIOTE_INTENCLR_IN0_Enabled (1UL) /*!< Interrupt enabled. */ -#define GPIOTE_INTENCLR_IN0_Clear (1UL) /*!< Disable interrupt on write. */ - -/* Register: GPIOTE_CONFIG */ -/* Description: Channel configuration registers. */ - -/* Bit 20 : Initial value of the output when the GPIOTE channel is configured as a Task. */ -#define GPIOTE_CONFIG_OUTINIT_Pos (20UL) /*!< Position of OUTINIT field. */ -#define GPIOTE_CONFIG_OUTINIT_Msk (0x1UL << GPIOTE_CONFIG_OUTINIT_Pos) /*!< Bit mask of OUTINIT field. */ -#define GPIOTE_CONFIG_OUTINIT_Low (0UL) /*!< Initial low output when in task mode. */ -#define GPIOTE_CONFIG_OUTINIT_High (1UL) /*!< Initial high output when in task mode. */ - -/* Bits 17..16 : Effects on output when in Task mode, or events on input that generates an event. */ -#define GPIOTE_CONFIG_POLARITY_Pos (16UL) /*!< Position of POLARITY field. */ -#define GPIOTE_CONFIG_POLARITY_Msk (0x3UL << GPIOTE_CONFIG_POLARITY_Pos) /*!< Bit mask of POLARITY field. */ -#define GPIOTE_CONFIG_POLARITY_LoToHi (0x01UL) /*!< Low to high. */ -#define GPIOTE_CONFIG_POLARITY_HiToLo (0x02UL) /*!< High to low. */ -#define GPIOTE_CONFIG_POLARITY_Toggle (0x03UL) /*!< Toggle. */ - -/* Bits 12..8 : Pin select. */ -#define GPIOTE_CONFIG_PSEL_Pos (8UL) /*!< Position of PSEL field. */ -#define GPIOTE_CONFIG_PSEL_Msk (0x1FUL << GPIOTE_CONFIG_PSEL_Pos) /*!< Bit mask of PSEL field. */ - -/* Bits 1..0 : Mode */ -#define GPIOTE_CONFIG_MODE_Pos (0UL) /*!< Position of MODE field. */ -#define GPIOTE_CONFIG_MODE_Msk (0x3UL << GPIOTE_CONFIG_MODE_Pos) /*!< Bit mask of MODE field. */ -#define GPIOTE_CONFIG_MODE_Disabled (0x00UL) /*!< Disabled. */ -#define GPIOTE_CONFIG_MODE_Event (0x01UL) /*!< Channel configure in event mode. */ -#define GPIOTE_CONFIG_MODE_Task (0x03UL) /*!< Channel configure in task mode. */ - -/* Register: GPIOTE_POWER */ -/* Description: Peripheral power control. */ - -/* Bit 0 : Peripheral power control. */ -#define GPIOTE_POWER_POWER_Pos (0UL) /*!< Position of POWER field. */ -#define GPIOTE_POWER_POWER_Msk (0x1UL << GPIOTE_POWER_POWER_Pos) /*!< Bit mask of POWER field. */ -#define GPIOTE_POWER_POWER_Disabled (0UL) /*!< Module power disabled. */ -#define GPIOTE_POWER_POWER_Enabled (1UL) /*!< Module power enabled. */ - - -/* Peripheral: LPCOMP */ -/* Description: Low power comparator. */ - -/* Register: LPCOMP_SHORTS */ -/* Description: Shortcuts for the LPCOMP. */ - -/* Bit 4 : Shortcut between CROSS event and STOP task. */ -#define LPCOMP_SHORTS_CROSS_STOP_Pos (4UL) /*!< Position of CROSS_STOP field. */ -#define LPCOMP_SHORTS_CROSS_STOP_Msk (0x1UL << LPCOMP_SHORTS_CROSS_STOP_Pos) /*!< Bit mask of CROSS_STOP field. */ -#define LPCOMP_SHORTS_CROSS_STOP_Disabled (0UL) /*!< Shortcut disabled. */ -#define LPCOMP_SHORTS_CROSS_STOP_Enabled (1UL) /*!< Shortcut enabled. */ - -/* Bit 3 : Shortcut between UP event and STOP task. */ -#define LPCOMP_SHORTS_UP_STOP_Pos (3UL) /*!< Position of UP_STOP field. */ -#define LPCOMP_SHORTS_UP_STOP_Msk (0x1UL << LPCOMP_SHORTS_UP_STOP_Pos) /*!< Bit mask of UP_STOP field. */ -#define LPCOMP_SHORTS_UP_STOP_Disabled (0UL) /*!< Shortcut disabled. */ -#define LPCOMP_SHORTS_UP_STOP_Enabled (1UL) /*!< Shortcut enabled. */ - -/* Bit 2 : Shortcut between DOWN event and STOP task. */ -#define LPCOMP_SHORTS_DOWN_STOP_Pos (2UL) /*!< Position of DOWN_STOP field. */ -#define LPCOMP_SHORTS_DOWN_STOP_Msk (0x1UL << LPCOMP_SHORTS_DOWN_STOP_Pos) /*!< Bit mask of DOWN_STOP field. */ -#define LPCOMP_SHORTS_DOWN_STOP_Disabled (0UL) /*!< Shortcut disabled. */ -#define LPCOMP_SHORTS_DOWN_STOP_Enabled (1UL) /*!< Shortcut enabled. */ - -/* Bit 1 : Shortcut between RADY event and STOP task. */ -#define LPCOMP_SHORTS_READY_STOP_Pos (1UL) /*!< Position of READY_STOP field. */ -#define LPCOMP_SHORTS_READY_STOP_Msk (0x1UL << LPCOMP_SHORTS_READY_STOP_Pos) /*!< Bit mask of READY_STOP field. */ -#define LPCOMP_SHORTS_READY_STOP_Disabled (0UL) /*!< Shortcut disabled. */ -#define LPCOMP_SHORTS_READY_STOP_Enabled (1UL) /*!< Shortcut enabled. */ - -/* Bit 0 : Shortcut between READY event and SAMPLE task. */ -#define LPCOMP_SHORTS_READY_SAMPLE_Pos (0UL) /*!< Position of READY_SAMPLE field. */ -#define LPCOMP_SHORTS_READY_SAMPLE_Msk (0x1UL << LPCOMP_SHORTS_READY_SAMPLE_Pos) /*!< Bit mask of READY_SAMPLE field. */ -#define LPCOMP_SHORTS_READY_SAMPLE_Disabled (0UL) /*!< Shortcut disabled. */ -#define LPCOMP_SHORTS_READY_SAMPLE_Enabled (1UL) /*!< Shortcut enabled. */ - -/* Register: LPCOMP_INTENSET */ -/* Description: Interrupt enable set register. */ - -/* Bit 3 : Enable interrupt on CROSS event. */ -#define LPCOMP_INTENSET_CROSS_Pos (3UL) /*!< Position of CROSS field. */ -#define LPCOMP_INTENSET_CROSS_Msk (0x1UL << LPCOMP_INTENSET_CROSS_Pos) /*!< Bit mask of CROSS field. */ -#define LPCOMP_INTENSET_CROSS_Disabled (0UL) /*!< Interrupt disabled. */ -#define LPCOMP_INTENSET_CROSS_Enabled (1UL) /*!< Interrupt enabled. */ -#define LPCOMP_INTENSET_CROSS_Set (1UL) /*!< Enable interrupt on write. */ - -/* Bit 2 : Enable interrupt on UP event. */ -#define LPCOMP_INTENSET_UP_Pos (2UL) /*!< Position of UP field. */ -#define LPCOMP_INTENSET_UP_Msk (0x1UL << LPCOMP_INTENSET_UP_Pos) /*!< Bit mask of UP field. */ -#define LPCOMP_INTENSET_UP_Disabled (0UL) /*!< Interrupt disabled. */ -#define LPCOMP_INTENSET_UP_Enabled (1UL) /*!< Interrupt enabled. */ -#define LPCOMP_INTENSET_UP_Set (1UL) /*!< Enable interrupt on write. */ - -/* Bit 1 : Enable interrupt on DOWN event. */ -#define LPCOMP_INTENSET_DOWN_Pos (1UL) /*!< Position of DOWN field. */ -#define LPCOMP_INTENSET_DOWN_Msk (0x1UL << LPCOMP_INTENSET_DOWN_Pos) /*!< Bit mask of DOWN field. */ -#define LPCOMP_INTENSET_DOWN_Disabled (0UL) /*!< Interrupt disabled. */ -#define LPCOMP_INTENSET_DOWN_Enabled (1UL) /*!< Interrupt enabled. */ -#define LPCOMP_INTENSET_DOWN_Set (1UL) /*!< Enable interrupt on write. */ - -/* Bit 0 : Enable interrupt on READY event. */ -#define LPCOMP_INTENSET_READY_Pos (0UL) /*!< Position of READY field. */ -#define LPCOMP_INTENSET_READY_Msk (0x1UL << LPCOMP_INTENSET_READY_Pos) /*!< Bit mask of READY field. */ -#define LPCOMP_INTENSET_READY_Disabled (0UL) /*!< Interrupt disabled. */ -#define LPCOMP_INTENSET_READY_Enabled (1UL) /*!< Interrupt enabled. */ -#define LPCOMP_INTENSET_READY_Set (1UL) /*!< Enable interrupt on write. */ - -/* Register: LPCOMP_INTENCLR */ -/* Description: Interrupt enable clear register. */ - -/* Bit 3 : Disable interrupt on CROSS event. */ -#define LPCOMP_INTENCLR_CROSS_Pos (3UL) /*!< Position of CROSS field. */ -#define LPCOMP_INTENCLR_CROSS_Msk (0x1UL << LPCOMP_INTENCLR_CROSS_Pos) /*!< Bit mask of CROSS field. */ -#define LPCOMP_INTENCLR_CROSS_Disabled (0UL) /*!< Interrupt disabled. */ -#define LPCOMP_INTENCLR_CROSS_Enabled (1UL) /*!< Interrupt enabled. */ -#define LPCOMP_INTENCLR_CROSS_Clear (1UL) /*!< Disable interrupt on write. */ - -/* Bit 2 : Disable interrupt on UP event. */ -#define LPCOMP_INTENCLR_UP_Pos (2UL) /*!< Position of UP field. */ -#define LPCOMP_INTENCLR_UP_Msk (0x1UL << LPCOMP_INTENCLR_UP_Pos) /*!< Bit mask of UP field. */ -#define LPCOMP_INTENCLR_UP_Disabled (0UL) /*!< Interrupt disabled. */ -#define LPCOMP_INTENCLR_UP_Enabled (1UL) /*!< Interrupt enabled. */ -#define LPCOMP_INTENCLR_UP_Clear (1UL) /*!< Disable interrupt on write. */ - -/* Bit 1 : Disable interrupt on DOWN event. */ -#define LPCOMP_INTENCLR_DOWN_Pos (1UL) /*!< Position of DOWN field. */ -#define LPCOMP_INTENCLR_DOWN_Msk (0x1UL << LPCOMP_INTENCLR_DOWN_Pos) /*!< Bit mask of DOWN field. */ -#define LPCOMP_INTENCLR_DOWN_Disabled (0UL) /*!< Interrupt disabled. */ -#define LPCOMP_INTENCLR_DOWN_Enabled (1UL) /*!< Interrupt enabled. */ -#define LPCOMP_INTENCLR_DOWN_Clear (1UL) /*!< Disable interrupt on write. */ - -/* Bit 0 : Disable interrupt on READY event. */ -#define LPCOMP_INTENCLR_READY_Pos (0UL) /*!< Position of READY field. */ -#define LPCOMP_INTENCLR_READY_Msk (0x1UL << LPCOMP_INTENCLR_READY_Pos) /*!< Bit mask of READY field. */ -#define LPCOMP_INTENCLR_READY_Disabled (0UL) /*!< Interrupt disabled. */ -#define LPCOMP_INTENCLR_READY_Enabled (1UL) /*!< Interrupt enabled. */ -#define LPCOMP_INTENCLR_READY_Clear (1UL) /*!< Disable interrupt on write. */ - -/* Register: LPCOMP_RESULT */ -/* Description: Result of last compare. */ - -/* Bit 0 : Result of last compare. Decision point SAMPLE task. */ -#define LPCOMP_RESULT_RESULT_Pos (0UL) /*!< Position of RESULT field. */ -#define LPCOMP_RESULT_RESULT_Msk (0x1UL << LPCOMP_RESULT_RESULT_Pos) /*!< Bit mask of RESULT field. */ -#define LPCOMP_RESULT_RESULT_Bellow (0UL) /*!< Input voltage is bellow the reference threshold. */ -#define LPCOMP_RESULT_RESULT_Above (1UL) /*!< Input voltage is above the reference threshold. */ - -/* Register: LPCOMP_ENABLE */ -/* Description: Enable the LPCOMP. */ - -/* Bits 1..0 : Enable or disable LPCOMP. */ -#define LPCOMP_ENABLE_ENABLE_Pos (0UL) /*!< Position of ENABLE field. */ -#define LPCOMP_ENABLE_ENABLE_Msk (0x3UL << LPCOMP_ENABLE_ENABLE_Pos) /*!< Bit mask of ENABLE field. */ -#define LPCOMP_ENABLE_ENABLE_Disabled (0x00UL) /*!< Disabled LPCOMP. */ -#define LPCOMP_ENABLE_ENABLE_Enabled (0x01UL) /*!< Enable LPCOMP. */ - -/* Register: LPCOMP_PSEL */ -/* Description: Input pin select. */ - -/* Bits 2..0 : Analog input pin select. */ -#define LPCOMP_PSEL_PSEL_Pos (0UL) /*!< Position of PSEL field. */ -#define LPCOMP_PSEL_PSEL_Msk (0x7UL << LPCOMP_PSEL_PSEL_Pos) /*!< Bit mask of PSEL field. */ -#define LPCOMP_PSEL_PSEL_AnalogInput0 (0UL) /*!< Use analog input 0 as analog input. */ -#define LPCOMP_PSEL_PSEL_AnalogInput1 (1UL) /*!< Use analog input 1 as analog input. */ -#define LPCOMP_PSEL_PSEL_AnalogInput2 (2UL) /*!< Use analog input 2 as analog input. */ -#define LPCOMP_PSEL_PSEL_AnalogInput3 (3UL) /*!< Use analog input 3 as analog input. */ -#define LPCOMP_PSEL_PSEL_AnalogInput4 (4UL) /*!< Use analog input 4 as analog input. */ -#define LPCOMP_PSEL_PSEL_AnalogInput5 (5UL) /*!< Use analog input 5 as analog input. */ -#define LPCOMP_PSEL_PSEL_AnalogInput6 (6UL) /*!< Use analog input 6 as analog input. */ -#define LPCOMP_PSEL_PSEL_AnalogInput7 (7UL) /*!< Use analog input 7 as analog input. */ - -/* Register: LPCOMP_REFSEL */ -/* Description: Reference select. */ - -/* Bits 2..0 : Reference select. */ -#define LPCOMP_REFSEL_REFSEL_Pos (0UL) /*!< Position of REFSEL field. */ -#define LPCOMP_REFSEL_REFSEL_Msk (0x7UL << LPCOMP_REFSEL_REFSEL_Pos) /*!< Bit mask of REFSEL field. */ -#define LPCOMP_REFSEL_REFSEL_SupplyOneEighthPrescaling (0UL) /*!< Use supply with a 1/8 prescaler as reference. */ -#define LPCOMP_REFSEL_REFSEL_SupplyTwoEighthsPrescaling (1UL) /*!< Use supply with a 2/8 prescaler as reference. */ -#define LPCOMP_REFSEL_REFSEL_SupplyThreeEighthsPrescaling (2UL) /*!< Use supply with a 3/8 prescaler as reference. */ -#define LPCOMP_REFSEL_REFSEL_SupplyFourEighthsPrescaling (3UL) /*!< Use supply with a 4/8 prescaler as reference. */ -#define LPCOMP_REFSEL_REFSEL_SupplyFiveEighthsPrescaling (4UL) /*!< Use supply with a 5/8 prescaler as reference. */ -#define LPCOMP_REFSEL_REFSEL_SupplySixEighthsPrescaling (5UL) /*!< Use supply with a 6/8 prescaler as reference. */ -#define LPCOMP_REFSEL_REFSEL_SupplySevenEighthsPrescaling (6UL) /*!< Use supply with a 7/8 prescaler as reference. */ -#define LPCOMP_REFSEL_REFSEL_ARef (7UL) /*!< Use external analog reference as reference. */ - -/* Register: LPCOMP_EXTREFSEL */ -/* Description: External reference select. */ - -/* Bit 0 : External analog reference pin selection. */ -#define LPCOMP_EXTREFSEL_EXTREFSEL_Pos (0UL) /*!< Position of EXTREFSEL field. */ -#define LPCOMP_EXTREFSEL_EXTREFSEL_Msk (0x1UL << LPCOMP_EXTREFSEL_EXTREFSEL_Pos) /*!< Bit mask of EXTREFSEL field. */ -#define LPCOMP_EXTREFSEL_EXTREFSEL_AnalogReference0 (0UL) /*!< Use analog reference 0 as reference. */ -#define LPCOMP_EXTREFSEL_EXTREFSEL_AnalogReference1 (1UL) /*!< Use analog reference 1 as reference. */ - -/* Register: LPCOMP_ANADETECT */ -/* Description: Analog detect configuration. */ - -/* Bits 1..0 : Analog detect configuration. */ -#define LPCOMP_ANADETECT_ANADETECT_Pos (0UL) /*!< Position of ANADETECT field. */ -#define LPCOMP_ANADETECT_ANADETECT_Msk (0x3UL << LPCOMP_ANADETECT_ANADETECT_Pos) /*!< Bit mask of ANADETECT field. */ -#define LPCOMP_ANADETECT_ANADETECT_Cross (0UL) /*!< Generate ANADETEC on crossing, both upwards and downwards crossing. */ -#define LPCOMP_ANADETECT_ANADETECT_Up (1UL) /*!< Generate ANADETEC on upwards crossing only. */ -#define LPCOMP_ANADETECT_ANADETECT_Down (2UL) /*!< Generate ANADETEC on downwards crossing only. */ - -/* Register: LPCOMP_POWER */ -/* Description: Peripheral power control. */ - -/* Bit 0 : Peripheral power control. */ -#define LPCOMP_POWER_POWER_Pos (0UL) /*!< Position of POWER field. */ -#define LPCOMP_POWER_POWER_Msk (0x1UL << LPCOMP_POWER_POWER_Pos) /*!< Bit mask of POWER field. */ -#define LPCOMP_POWER_POWER_Disabled (0UL) /*!< Module power disabled. */ -#define LPCOMP_POWER_POWER_Enabled (1UL) /*!< Module power enabled. */ - - -/* Peripheral: MPU */ -/* Description: Memory Protection Unit. */ - -/* Register: MPU_PERR0 */ -/* Description: Configuration of peripherals in mpu regions. */ - -/* Bit 31 : PPI region configuration. */ -#define MPU_PERR0_PPI_Pos (31UL) /*!< Position of PPI field. */ -#define MPU_PERR0_PPI_Msk (0x1UL << MPU_PERR0_PPI_Pos) /*!< Bit mask of PPI field. */ -#define MPU_PERR0_PPI_InRegion1 (0UL) /*!< Peripheral configured in region 1. */ -#define MPU_PERR0_PPI_InRegion0 (1UL) /*!< Peripheral configured in region 0. */ - -/* Bit 30 : NVMC region configuration. */ -#define MPU_PERR0_NVMC_Pos (30UL) /*!< Position of NVMC field. */ -#define MPU_PERR0_NVMC_Msk (0x1UL << MPU_PERR0_NVMC_Pos) /*!< Bit mask of NVMC field. */ -#define MPU_PERR0_NVMC_InRegion1 (0UL) /*!< Peripheral configured in region 1. */ -#define MPU_PERR0_NVMC_InRegion0 (1UL) /*!< Peripheral configured in region 0. */ - -/* Bit 19 : LPCOMP region configuration. */ -#define MPU_PERR0_LPCOMP_Pos (19UL) /*!< Position of LPCOMP field. */ -#define MPU_PERR0_LPCOMP_Msk (0x1UL << MPU_PERR0_LPCOMP_Pos) /*!< Bit mask of LPCOMP field. */ -#define MPU_PERR0_LPCOMP_InRegion1 (0UL) /*!< Peripheral configured in region 1. */ -#define MPU_PERR0_LPCOMP_InRegion0 (1UL) /*!< Peripheral configured in region 0. */ - -/* Bit 18 : QDEC region configuration. */ -#define MPU_PERR0_QDEC_Pos (18UL) /*!< Position of QDEC field. */ -#define MPU_PERR0_QDEC_Msk (0x1UL << MPU_PERR0_QDEC_Pos) /*!< Bit mask of QDEC field. */ -#define MPU_PERR0_QDEC_InRegion1 (0UL) /*!< Peripheral configured in region 1. */ -#define MPU_PERR0_QDEC_InRegion0 (1UL) /*!< Peripheral configured in region 0. */ - -/* Bit 17 : RTC1 region configuration. */ -#define MPU_PERR0_RTC1_Pos (17UL) /*!< Position of RTC1 field. */ -#define MPU_PERR0_RTC1_Msk (0x1UL << MPU_PERR0_RTC1_Pos) /*!< Bit mask of RTC1 field. */ -#define MPU_PERR0_RTC1_InRegion1 (0UL) /*!< Peripheral configured in region 1. */ -#define MPU_PERR0_RTC1_InRegion0 (1UL) /*!< Peripheral configured in region 0. */ - -/* Bit 16 : WDT region configuration. */ -#define MPU_PERR0_WDT_Pos (16UL) /*!< Position of WDT field. */ -#define MPU_PERR0_WDT_Msk (0x1UL << MPU_PERR0_WDT_Pos) /*!< Bit mask of WDT field. */ -#define MPU_PERR0_WDT_InRegion1 (0UL) /*!< Peripheral configured in region 1. */ -#define MPU_PERR0_WDT_InRegion0 (1UL) /*!< Peripheral configured in region 0. */ - -/* Bit 15 : CCM and AAR region configuration. */ -#define MPU_PERR0_CCM_AAR_Pos (15UL) /*!< Position of CCM_AAR field. */ -#define MPU_PERR0_CCM_AAR_Msk (0x1UL << MPU_PERR0_CCM_AAR_Pos) /*!< Bit mask of CCM_AAR field. */ -#define MPU_PERR0_CCM_AAR_InRegion1 (0UL) /*!< Peripheral configured in region 1. */ -#define MPU_PERR0_CCM_AAR_InRegion0 (1UL) /*!< Peripheral configured in region 0. */ - -/* Bit 14 : ECB region configuration. */ -#define MPU_PERR0_ECB_Pos (14UL) /*!< Position of ECB field. */ -#define MPU_PERR0_ECB_Msk (0x1UL << MPU_PERR0_ECB_Pos) /*!< Bit mask of ECB field. */ -#define MPU_PERR0_ECB_InRegion1 (0UL) /*!< Peripheral configured in region 1. */ -#define MPU_PERR0_ECB_InRegion0 (1UL) /*!< Peripheral configured in region 0. */ - -/* Bit 13 : RNG region configuration. */ -#define MPU_PERR0_RNG_Pos (13UL) /*!< Position of RNG field. */ -#define MPU_PERR0_RNG_Msk (0x1UL << MPU_PERR0_RNG_Pos) /*!< Bit mask of RNG field. */ -#define MPU_PERR0_RNG_InRegion1 (0UL) /*!< Peripheral configured in region 1. */ -#define MPU_PERR0_RNG_InRegion0 (1UL) /*!< Peripheral configured in region 0. */ - -/* Bit 12 : TEMP region configuration. */ -#define MPU_PERR0_TEMP_Pos (12UL) /*!< Position of TEMP field. */ -#define MPU_PERR0_TEMP_Msk (0x1UL << MPU_PERR0_TEMP_Pos) /*!< Bit mask of TEMP field. */ -#define MPU_PERR0_TEMP_InRegion1 (0UL) /*!< Peripheral configured in region 1. */ -#define MPU_PERR0_TEMP_InRegion0 (1UL) /*!< Peripheral configured in region 0. */ - -/* Bit 11 : RTC0 region configuration. */ -#define MPU_PERR0_RTC0_Pos (11UL) /*!< Position of RTC0 field. */ -#define MPU_PERR0_RTC0_Msk (0x1UL << MPU_PERR0_RTC0_Pos) /*!< Bit mask of RTC0 field. */ -#define MPU_PERR0_RTC0_InRegion1 (0UL) /*!< Peripheral configured in region 1. */ -#define MPU_PERR0_RTC0_InRegion0 (1UL) /*!< Peripheral configured in region 0. */ - -/* Bit 10 : TIMER2 region configuration. */ -#define MPU_PERR0_TIMER2_Pos (10UL) /*!< Position of TIMER2 field. */ -#define MPU_PERR0_TIMER2_Msk (0x1UL << MPU_PERR0_TIMER2_Pos) /*!< Bit mask of TIMER2 field. */ -#define MPU_PERR0_TIMER2_InRegion1 (0UL) /*!< Peripheral configured in region 1. */ -#define MPU_PERR0_TIMER2_InRegion0 (1UL) /*!< Peripheral configured in region 0. */ - -/* Bit 9 : TIMER1 region configuration. */ -#define MPU_PERR0_TIMER1_Pos (9UL) /*!< Position of TIMER1 field. */ -#define MPU_PERR0_TIMER1_Msk (0x1UL << MPU_PERR0_TIMER1_Pos) /*!< Bit mask of TIMER1 field. */ -#define MPU_PERR0_TIMER1_InRegion1 (0UL) /*!< Peripheral configured in region 1. */ -#define MPU_PERR0_TIMER1_InRegion0 (1UL) /*!< Peripheral configured in region 0. */ - -/* Bit 8 : TIMER0 region configuration. */ -#define MPU_PERR0_TIMER0_Pos (8UL) /*!< Position of TIMER0 field. */ -#define MPU_PERR0_TIMER0_Msk (0x1UL << MPU_PERR0_TIMER0_Pos) /*!< Bit mask of TIMER0 field. */ -#define MPU_PERR0_TIMER0_InRegion1 (0UL) /*!< Peripheral configured in region 1. */ -#define MPU_PERR0_TIMER0_InRegion0 (1UL) /*!< Peripheral configured in region 0. */ - -/* Bit 7 : ADC region configuration. */ -#define MPU_PERR0_ADC_Pos (7UL) /*!< Position of ADC field. */ -#define MPU_PERR0_ADC_Msk (0x1UL << MPU_PERR0_ADC_Pos) /*!< Bit mask of ADC field. */ -#define MPU_PERR0_ADC_InRegion1 (0UL) /*!< Peripheral configured in region 1. */ -#define MPU_PERR0_ADC_InRegion0 (1UL) /*!< Peripheral configured in region 0. */ - -/* Bit 6 : GPIOTE region configuration. */ -#define MPU_PERR0_GPIOTE_Pos (6UL) /*!< Position of GPIOTE field. */ -#define MPU_PERR0_GPIOTE_Msk (0x1UL << MPU_PERR0_GPIOTE_Pos) /*!< Bit mask of GPIOTE field. */ -#define MPU_PERR0_GPIOTE_InRegion1 (0UL) /*!< Peripheral configured in region 1. */ -#define MPU_PERR0_GPIOTE_InRegion0 (1UL) /*!< Peripheral configured in region 0. */ - -/* Bit 4 : SPI1 and TWI1 region configuration. */ -#define MPU_PERR0_SPI1_TWI1_Pos (4UL) /*!< Position of SPI1_TWI1 field. */ -#define MPU_PERR0_SPI1_TWI1_Msk (0x1UL << MPU_PERR0_SPI1_TWI1_Pos) /*!< Bit mask of SPI1_TWI1 field. */ -#define MPU_PERR0_SPI1_TWI1_InRegion1 (0UL) /*!< Peripheral configured in region 1. */ -#define MPU_PERR0_SPI1_TWI1_InRegion0 (1UL) /*!< Peripheral configured in region 0. */ - -/* Bit 3 : SPI0 and TWI0 region configuration. */ -#define MPU_PERR0_SPI0_TWI0_Pos (3UL) /*!< Position of SPI0_TWI0 field. */ -#define MPU_PERR0_SPI0_TWI0_Msk (0x1UL << MPU_PERR0_SPI0_TWI0_Pos) /*!< Bit mask of SPI0_TWI0 field. */ -#define MPU_PERR0_SPI0_TWI0_InRegion1 (0UL) /*!< Peripheral configured in region 1. */ -#define MPU_PERR0_SPI0_TWI0_InRegion0 (1UL) /*!< Peripheral configured in region 0. */ - -/* Bit 2 : UART0 region configuration. */ -#define MPU_PERR0_UART0_Pos (2UL) /*!< Position of UART0 field. */ -#define MPU_PERR0_UART0_Msk (0x1UL << MPU_PERR0_UART0_Pos) /*!< Bit mask of UART0 field. */ -#define MPU_PERR0_UART0_InRegion1 (0UL) /*!< Peripheral configured in region 1. */ -#define MPU_PERR0_UART0_InRegion0 (1UL) /*!< Peripheral configured in region 0. */ - -/* Bit 1 : RADIO region configuration. */ -#define MPU_PERR0_RADIO_Pos (1UL) /*!< Position of RADIO field. */ -#define MPU_PERR0_RADIO_Msk (0x1UL << MPU_PERR0_RADIO_Pos) /*!< Bit mask of RADIO field. */ -#define MPU_PERR0_RADIO_InRegion1 (0UL) /*!< Peripheral configured in region 1. */ -#define MPU_PERR0_RADIO_InRegion0 (1UL) /*!< Peripheral configured in region 0. */ - -/* Bit 0 : POWER_CLOCK region configuration. */ -#define MPU_PERR0_POWER_CLOCK_Pos (0UL) /*!< Position of POWER_CLOCK field. */ -#define MPU_PERR0_POWER_CLOCK_Msk (0x1UL << MPU_PERR0_POWER_CLOCK_Pos) /*!< Bit mask of POWER_CLOCK field. */ -#define MPU_PERR0_POWER_CLOCK_InRegion1 (0UL) /*!< Peripheral configured in region 1. */ -#define MPU_PERR0_POWER_CLOCK_InRegion0 (1UL) /*!< Peripheral configured in region 0. */ - -/* Register: MPU_PROTENSET0 */ -/* Description: Erase and write protection bit enable set register. */ - -/* Bit 31 : Protection enable for region 31. */ -#define MPU_PROTENSET0_PROTREG31_Pos (31UL) /*!< Position of PROTREG31 field. */ -#define MPU_PROTENSET0_PROTREG31_Msk (0x1UL << MPU_PROTENSET0_PROTREG31_Pos) /*!< Bit mask of PROTREG31 field. */ -#define MPU_PROTENSET0_PROTREG31_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET0_PROTREG31_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET0_PROTREG31_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 30 : Protection enable for region 30. */ -#define MPU_PROTENSET0_PROTREG30_Pos (30UL) /*!< Position of PROTREG30 field. */ -#define MPU_PROTENSET0_PROTREG30_Msk (0x1UL << MPU_PROTENSET0_PROTREG30_Pos) /*!< Bit mask of PROTREG30 field. */ -#define MPU_PROTENSET0_PROTREG30_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET0_PROTREG30_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET0_PROTREG30_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 29 : Protection enable for region 29. */ -#define MPU_PROTENSET0_PROTREG29_Pos (29UL) /*!< Position of PROTREG29 field. */ -#define MPU_PROTENSET0_PROTREG29_Msk (0x1UL << MPU_PROTENSET0_PROTREG29_Pos) /*!< Bit mask of PROTREG29 field. */ -#define MPU_PROTENSET0_PROTREG29_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET0_PROTREG29_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET0_PROTREG29_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 28 : Protection enable for region 28. */ -#define MPU_PROTENSET0_PROTREG28_Pos (28UL) /*!< Position of PROTREG28 field. */ -#define MPU_PROTENSET0_PROTREG28_Msk (0x1UL << MPU_PROTENSET0_PROTREG28_Pos) /*!< Bit mask of PROTREG28 field. */ -#define MPU_PROTENSET0_PROTREG28_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET0_PROTREG28_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET0_PROTREG28_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 27 : Protection enable for region 27. */ -#define MPU_PROTENSET0_PROTREG27_Pos (27UL) /*!< Position of PROTREG27 field. */ -#define MPU_PROTENSET0_PROTREG27_Msk (0x1UL << MPU_PROTENSET0_PROTREG27_Pos) /*!< Bit mask of PROTREG27 field. */ -#define MPU_PROTENSET0_PROTREG27_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET0_PROTREG27_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET0_PROTREG27_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 26 : Protection enable for region 26. */ -#define MPU_PROTENSET0_PROTREG26_Pos (26UL) /*!< Position of PROTREG26 field. */ -#define MPU_PROTENSET0_PROTREG26_Msk (0x1UL << MPU_PROTENSET0_PROTREG26_Pos) /*!< Bit mask of PROTREG26 field. */ -#define MPU_PROTENSET0_PROTREG26_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET0_PROTREG26_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET0_PROTREG26_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 25 : Protection enable for region 25. */ -#define MPU_PROTENSET0_PROTREG25_Pos (25UL) /*!< Position of PROTREG25 field. */ -#define MPU_PROTENSET0_PROTREG25_Msk (0x1UL << MPU_PROTENSET0_PROTREG25_Pos) /*!< Bit mask of PROTREG25 field. */ -#define MPU_PROTENSET0_PROTREG25_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET0_PROTREG25_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET0_PROTREG25_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 24 : Protection enable for region 24. */ -#define MPU_PROTENSET0_PROTREG24_Pos (24UL) /*!< Position of PROTREG24 field. */ -#define MPU_PROTENSET0_PROTREG24_Msk (0x1UL << MPU_PROTENSET0_PROTREG24_Pos) /*!< Bit mask of PROTREG24 field. */ -#define MPU_PROTENSET0_PROTREG24_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET0_PROTREG24_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET0_PROTREG24_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 23 : Protection enable for region 23. */ -#define MPU_PROTENSET0_PROTREG23_Pos (23UL) /*!< Position of PROTREG23 field. */ -#define MPU_PROTENSET0_PROTREG23_Msk (0x1UL << MPU_PROTENSET0_PROTREG23_Pos) /*!< Bit mask of PROTREG23 field. */ -#define MPU_PROTENSET0_PROTREG23_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET0_PROTREG23_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET0_PROTREG23_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 22 : Protection enable for region 22. */ -#define MPU_PROTENSET0_PROTREG22_Pos (22UL) /*!< Position of PROTREG22 field. */ -#define MPU_PROTENSET0_PROTREG22_Msk (0x1UL << MPU_PROTENSET0_PROTREG22_Pos) /*!< Bit mask of PROTREG22 field. */ -#define MPU_PROTENSET0_PROTREG22_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET0_PROTREG22_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET0_PROTREG22_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 21 : Protection enable for region 21. */ -#define MPU_PROTENSET0_PROTREG21_Pos (21UL) /*!< Position of PROTREG21 field. */ -#define MPU_PROTENSET0_PROTREG21_Msk (0x1UL << MPU_PROTENSET0_PROTREG21_Pos) /*!< Bit mask of PROTREG21 field. */ -#define MPU_PROTENSET0_PROTREG21_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET0_PROTREG21_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET0_PROTREG21_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 20 : Protection enable for region 20. */ -#define MPU_PROTENSET0_PROTREG20_Pos (20UL) /*!< Position of PROTREG20 field. */ -#define MPU_PROTENSET0_PROTREG20_Msk (0x1UL << MPU_PROTENSET0_PROTREG20_Pos) /*!< Bit mask of PROTREG20 field. */ -#define MPU_PROTENSET0_PROTREG20_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET0_PROTREG20_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET0_PROTREG20_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 19 : Protection enable for region 19. */ -#define MPU_PROTENSET0_PROTREG19_Pos (19UL) /*!< Position of PROTREG19 field. */ -#define MPU_PROTENSET0_PROTREG19_Msk (0x1UL << MPU_PROTENSET0_PROTREG19_Pos) /*!< Bit mask of PROTREG19 field. */ -#define MPU_PROTENSET0_PROTREG19_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET0_PROTREG19_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET0_PROTREG19_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 18 : Protection enable for region 18. */ -#define MPU_PROTENSET0_PROTREG18_Pos (18UL) /*!< Position of PROTREG18 field. */ -#define MPU_PROTENSET0_PROTREG18_Msk (0x1UL << MPU_PROTENSET0_PROTREG18_Pos) /*!< Bit mask of PROTREG18 field. */ -#define MPU_PROTENSET0_PROTREG18_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET0_PROTREG18_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET0_PROTREG18_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 17 : Protection enable for region 17. */ -#define MPU_PROTENSET0_PROTREG17_Pos (17UL) /*!< Position of PROTREG17 field. */ -#define MPU_PROTENSET0_PROTREG17_Msk (0x1UL << MPU_PROTENSET0_PROTREG17_Pos) /*!< Bit mask of PROTREG17 field. */ -#define MPU_PROTENSET0_PROTREG17_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET0_PROTREG17_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET0_PROTREG17_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 16 : Protection enable for region 16. */ -#define MPU_PROTENSET0_PROTREG16_Pos (16UL) /*!< Position of PROTREG16 field. */ -#define MPU_PROTENSET0_PROTREG16_Msk (0x1UL << MPU_PROTENSET0_PROTREG16_Pos) /*!< Bit mask of PROTREG16 field. */ -#define MPU_PROTENSET0_PROTREG16_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET0_PROTREG16_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET0_PROTREG16_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 15 : Protection enable for region 15. */ -#define MPU_PROTENSET0_PROTREG15_Pos (15UL) /*!< Position of PROTREG15 field. */ -#define MPU_PROTENSET0_PROTREG15_Msk (0x1UL << MPU_PROTENSET0_PROTREG15_Pos) /*!< Bit mask of PROTREG15 field. */ -#define MPU_PROTENSET0_PROTREG15_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET0_PROTREG15_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET0_PROTREG15_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 14 : Protection enable for region 14. */ -#define MPU_PROTENSET0_PROTREG14_Pos (14UL) /*!< Position of PROTREG14 field. */ -#define MPU_PROTENSET0_PROTREG14_Msk (0x1UL << MPU_PROTENSET0_PROTREG14_Pos) /*!< Bit mask of PROTREG14 field. */ -#define MPU_PROTENSET0_PROTREG14_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET0_PROTREG14_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET0_PROTREG14_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 13 : Protection enable for region 13. */ -#define MPU_PROTENSET0_PROTREG13_Pos (13UL) /*!< Position of PROTREG13 field. */ -#define MPU_PROTENSET0_PROTREG13_Msk (0x1UL << MPU_PROTENSET0_PROTREG13_Pos) /*!< Bit mask of PROTREG13 field. */ -#define MPU_PROTENSET0_PROTREG13_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET0_PROTREG13_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET0_PROTREG13_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 12 : Protection enable for region 12. */ -#define MPU_PROTENSET0_PROTREG12_Pos (12UL) /*!< Position of PROTREG12 field. */ -#define MPU_PROTENSET0_PROTREG12_Msk (0x1UL << MPU_PROTENSET0_PROTREG12_Pos) /*!< Bit mask of PROTREG12 field. */ -#define MPU_PROTENSET0_PROTREG12_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET0_PROTREG12_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET0_PROTREG12_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 11 : Protection enable for region 11. */ -#define MPU_PROTENSET0_PROTREG11_Pos (11UL) /*!< Position of PROTREG11 field. */ -#define MPU_PROTENSET0_PROTREG11_Msk (0x1UL << MPU_PROTENSET0_PROTREG11_Pos) /*!< Bit mask of PROTREG11 field. */ -#define MPU_PROTENSET0_PROTREG11_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET0_PROTREG11_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET0_PROTREG11_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 10 : Protection enable for region 10. */ -#define MPU_PROTENSET0_PROTREG10_Pos (10UL) /*!< Position of PROTREG10 field. */ -#define MPU_PROTENSET0_PROTREG10_Msk (0x1UL << MPU_PROTENSET0_PROTREG10_Pos) /*!< Bit mask of PROTREG10 field. */ -#define MPU_PROTENSET0_PROTREG10_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET0_PROTREG10_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET0_PROTREG10_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 9 : Protection enable for region 9. */ -#define MPU_PROTENSET0_PROTREG9_Pos (9UL) /*!< Position of PROTREG9 field. */ -#define MPU_PROTENSET0_PROTREG9_Msk (0x1UL << MPU_PROTENSET0_PROTREG9_Pos) /*!< Bit mask of PROTREG9 field. */ -#define MPU_PROTENSET0_PROTREG9_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET0_PROTREG9_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET0_PROTREG9_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 8 : Protection enable for region 8. */ -#define MPU_PROTENSET0_PROTREG8_Pos (8UL) /*!< Position of PROTREG8 field. */ -#define MPU_PROTENSET0_PROTREG8_Msk (0x1UL << MPU_PROTENSET0_PROTREG8_Pos) /*!< Bit mask of PROTREG8 field. */ -#define MPU_PROTENSET0_PROTREG8_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET0_PROTREG8_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET0_PROTREG8_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 7 : Protection enable for region 7. */ -#define MPU_PROTENSET0_PROTREG7_Pos (7UL) /*!< Position of PROTREG7 field. */ -#define MPU_PROTENSET0_PROTREG7_Msk (0x1UL << MPU_PROTENSET0_PROTREG7_Pos) /*!< Bit mask of PROTREG7 field. */ -#define MPU_PROTENSET0_PROTREG7_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET0_PROTREG7_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET0_PROTREG7_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 6 : Protection enable for region 6. */ -#define MPU_PROTENSET0_PROTREG6_Pos (6UL) /*!< Position of PROTREG6 field. */ -#define MPU_PROTENSET0_PROTREG6_Msk (0x1UL << MPU_PROTENSET0_PROTREG6_Pos) /*!< Bit mask of PROTREG6 field. */ -#define MPU_PROTENSET0_PROTREG6_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET0_PROTREG6_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET0_PROTREG6_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 5 : Protection enable for region 5. */ -#define MPU_PROTENSET0_PROTREG5_Pos (5UL) /*!< Position of PROTREG5 field. */ -#define MPU_PROTENSET0_PROTREG5_Msk (0x1UL << MPU_PROTENSET0_PROTREG5_Pos) /*!< Bit mask of PROTREG5 field. */ -#define MPU_PROTENSET0_PROTREG5_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET0_PROTREG5_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET0_PROTREG5_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 4 : Protection enable for region 4. */ -#define MPU_PROTENSET0_PROTREG4_Pos (4UL) /*!< Position of PROTREG4 field. */ -#define MPU_PROTENSET0_PROTREG4_Msk (0x1UL << MPU_PROTENSET0_PROTREG4_Pos) /*!< Bit mask of PROTREG4 field. */ -#define MPU_PROTENSET0_PROTREG4_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET0_PROTREG4_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET0_PROTREG4_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 3 : Protection enable for region 3. */ -#define MPU_PROTENSET0_PROTREG3_Pos (3UL) /*!< Position of PROTREG3 field. */ -#define MPU_PROTENSET0_PROTREG3_Msk (0x1UL << MPU_PROTENSET0_PROTREG3_Pos) /*!< Bit mask of PROTREG3 field. */ -#define MPU_PROTENSET0_PROTREG3_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET0_PROTREG3_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET0_PROTREG3_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 2 : Protection enable for region 2. */ -#define MPU_PROTENSET0_PROTREG2_Pos (2UL) /*!< Position of PROTREG2 field. */ -#define MPU_PROTENSET0_PROTREG2_Msk (0x1UL << MPU_PROTENSET0_PROTREG2_Pos) /*!< Bit mask of PROTREG2 field. */ -#define MPU_PROTENSET0_PROTREG2_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET0_PROTREG2_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET0_PROTREG2_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 1 : Protection enable for region 1. */ -#define MPU_PROTENSET0_PROTREG1_Pos (1UL) /*!< Position of PROTREG1 field. */ -#define MPU_PROTENSET0_PROTREG1_Msk (0x1UL << MPU_PROTENSET0_PROTREG1_Pos) /*!< Bit mask of PROTREG1 field. */ -#define MPU_PROTENSET0_PROTREG1_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET0_PROTREG1_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET0_PROTREG1_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 0 : Protection enable for region 0. */ -#define MPU_PROTENSET0_PROTREG0_Pos (0UL) /*!< Position of PROTREG0 field. */ -#define MPU_PROTENSET0_PROTREG0_Msk (0x1UL << MPU_PROTENSET0_PROTREG0_Pos) /*!< Bit mask of PROTREG0 field. */ -#define MPU_PROTENSET0_PROTREG0_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET0_PROTREG0_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET0_PROTREG0_Set (1UL) /*!< Enable protection on write. */ - -/* Register: MPU_PROTENSET1 */ -/* Description: Erase and write protection bit enable set register. */ - -/* Bit 31 : Protection enable for region 63. */ -#define MPU_PROTENSET1_PROTREG63_Pos (31UL) /*!< Position of PROTREG63 field. */ -#define MPU_PROTENSET1_PROTREG63_Msk (0x1UL << MPU_PROTENSET1_PROTREG63_Pos) /*!< Bit mask of PROTREG63 field. */ -#define MPU_PROTENSET1_PROTREG63_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET1_PROTREG63_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET1_PROTREG63_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 30 : Protection enable for region 62. */ -#define MPU_PROTENSET1_PROTREG62_Pos (30UL) /*!< Position of PROTREG62 field. */ -#define MPU_PROTENSET1_PROTREG62_Msk (0x1UL << MPU_PROTENSET1_PROTREG62_Pos) /*!< Bit mask of PROTREG62 field. */ -#define MPU_PROTENSET1_PROTREG62_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET1_PROTREG62_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET1_PROTREG62_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 29 : Protection enable for region 61. */ -#define MPU_PROTENSET1_PROTREG61_Pos (29UL) /*!< Position of PROTREG61 field. */ -#define MPU_PROTENSET1_PROTREG61_Msk (0x1UL << MPU_PROTENSET1_PROTREG61_Pos) /*!< Bit mask of PROTREG61 field. */ -#define MPU_PROTENSET1_PROTREG61_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET1_PROTREG61_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET1_PROTREG61_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 28 : Protection enable for region 60. */ -#define MPU_PROTENSET1_PROTREG60_Pos (28UL) /*!< Position of PROTREG60 field. */ -#define MPU_PROTENSET1_PROTREG60_Msk (0x1UL << MPU_PROTENSET1_PROTREG60_Pos) /*!< Bit mask of PROTREG60 field. */ -#define MPU_PROTENSET1_PROTREG60_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET1_PROTREG60_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET1_PROTREG60_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 27 : Protection enable for region 59. */ -#define MPU_PROTENSET1_PROTREG59_Pos (27UL) /*!< Position of PROTREG59 field. */ -#define MPU_PROTENSET1_PROTREG59_Msk (0x1UL << MPU_PROTENSET1_PROTREG59_Pos) /*!< Bit mask of PROTREG59 field. */ -#define MPU_PROTENSET1_PROTREG59_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET1_PROTREG59_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET1_PROTREG59_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 26 : Protection enable for region 58. */ -#define MPU_PROTENSET1_PROTREG58_Pos (26UL) /*!< Position of PROTREG58 field. */ -#define MPU_PROTENSET1_PROTREG58_Msk (0x1UL << MPU_PROTENSET1_PROTREG58_Pos) /*!< Bit mask of PROTREG58 field. */ -#define MPU_PROTENSET1_PROTREG58_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET1_PROTREG58_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET1_PROTREG58_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 25 : Protection enable for region 57. */ -#define MPU_PROTENSET1_PROTREG57_Pos (25UL) /*!< Position of PROTREG57 field. */ -#define MPU_PROTENSET1_PROTREG57_Msk (0x1UL << MPU_PROTENSET1_PROTREG57_Pos) /*!< Bit mask of PROTREG57 field. */ -#define MPU_PROTENSET1_PROTREG57_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET1_PROTREG57_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET1_PROTREG57_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 24 : Protection enable for region 56. */ -#define MPU_PROTENSET1_PROTREG56_Pos (24UL) /*!< Position of PROTREG56 field. */ -#define MPU_PROTENSET1_PROTREG56_Msk (0x1UL << MPU_PROTENSET1_PROTREG56_Pos) /*!< Bit mask of PROTREG56 field. */ -#define MPU_PROTENSET1_PROTREG56_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET1_PROTREG56_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET1_PROTREG56_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 23 : Protection enable for region 55. */ -#define MPU_PROTENSET1_PROTREG55_Pos (23UL) /*!< Position of PROTREG55 field. */ -#define MPU_PROTENSET1_PROTREG55_Msk (0x1UL << MPU_PROTENSET1_PROTREG55_Pos) /*!< Bit mask of PROTREG55 field. */ -#define MPU_PROTENSET1_PROTREG55_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET1_PROTREG55_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET1_PROTREG55_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 22 : Protection enable for region 54. */ -#define MPU_PROTENSET1_PROTREG54_Pos (22UL) /*!< Position of PROTREG54 field. */ -#define MPU_PROTENSET1_PROTREG54_Msk (0x1UL << MPU_PROTENSET1_PROTREG54_Pos) /*!< Bit mask of PROTREG54 field. */ -#define MPU_PROTENSET1_PROTREG54_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET1_PROTREG54_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET1_PROTREG54_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 21 : Protection enable for region 53. */ -#define MPU_PROTENSET1_PROTREG53_Pos (21UL) /*!< Position of PROTREG53 field. */ -#define MPU_PROTENSET1_PROTREG53_Msk (0x1UL << MPU_PROTENSET1_PROTREG53_Pos) /*!< Bit mask of PROTREG53 field. */ -#define MPU_PROTENSET1_PROTREG53_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET1_PROTREG53_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET1_PROTREG53_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 20 : Protection enable for region 52. */ -#define MPU_PROTENSET1_PROTREG52_Pos (20UL) /*!< Position of PROTREG52 field. */ -#define MPU_PROTENSET1_PROTREG52_Msk (0x1UL << MPU_PROTENSET1_PROTREG52_Pos) /*!< Bit mask of PROTREG52 field. */ -#define MPU_PROTENSET1_PROTREG52_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET1_PROTREG52_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET1_PROTREG52_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 19 : Protection enable for region 51. */ -#define MPU_PROTENSET1_PROTREG51_Pos (19UL) /*!< Position of PROTREG51 field. */ -#define MPU_PROTENSET1_PROTREG51_Msk (0x1UL << MPU_PROTENSET1_PROTREG51_Pos) /*!< Bit mask of PROTREG51 field. */ -#define MPU_PROTENSET1_PROTREG51_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET1_PROTREG51_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET1_PROTREG51_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 18 : Protection enable for region 50. */ -#define MPU_PROTENSET1_PROTREG50_Pos (18UL) /*!< Position of PROTREG50 field. */ -#define MPU_PROTENSET1_PROTREG50_Msk (0x1UL << MPU_PROTENSET1_PROTREG50_Pos) /*!< Bit mask of PROTREG50 field. */ -#define MPU_PROTENSET1_PROTREG50_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET1_PROTREG50_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET1_PROTREG50_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 17 : Protection enable for region 49. */ -#define MPU_PROTENSET1_PROTREG49_Pos (17UL) /*!< Position of PROTREG49 field. */ -#define MPU_PROTENSET1_PROTREG49_Msk (0x1UL << MPU_PROTENSET1_PROTREG49_Pos) /*!< Bit mask of PROTREG49 field. */ -#define MPU_PROTENSET1_PROTREG49_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET1_PROTREG49_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET1_PROTREG49_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 16 : Protection enable for region 48. */ -#define MPU_PROTENSET1_PROTREG48_Pos (16UL) /*!< Position of PROTREG48 field. */ -#define MPU_PROTENSET1_PROTREG48_Msk (0x1UL << MPU_PROTENSET1_PROTREG48_Pos) /*!< Bit mask of PROTREG48 field. */ -#define MPU_PROTENSET1_PROTREG48_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET1_PROTREG48_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET1_PROTREG48_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 15 : Protection enable for region 47. */ -#define MPU_PROTENSET1_PROTREG47_Pos (15UL) /*!< Position of PROTREG47 field. */ -#define MPU_PROTENSET1_PROTREG47_Msk (0x1UL << MPU_PROTENSET1_PROTREG47_Pos) /*!< Bit mask of PROTREG47 field. */ -#define MPU_PROTENSET1_PROTREG47_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET1_PROTREG47_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET1_PROTREG47_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 14 : Protection enable for region 46. */ -#define MPU_PROTENSET1_PROTREG46_Pos (14UL) /*!< Position of PROTREG46 field. */ -#define MPU_PROTENSET1_PROTREG46_Msk (0x1UL << MPU_PROTENSET1_PROTREG46_Pos) /*!< Bit mask of PROTREG46 field. */ -#define MPU_PROTENSET1_PROTREG46_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET1_PROTREG46_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET1_PROTREG46_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 13 : Protection enable for region 45. */ -#define MPU_PROTENSET1_PROTREG45_Pos (13UL) /*!< Position of PROTREG45 field. */ -#define MPU_PROTENSET1_PROTREG45_Msk (0x1UL << MPU_PROTENSET1_PROTREG45_Pos) /*!< Bit mask of PROTREG45 field. */ -#define MPU_PROTENSET1_PROTREG45_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET1_PROTREG45_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET1_PROTREG45_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 12 : Protection enable for region 44. */ -#define MPU_PROTENSET1_PROTREG44_Pos (12UL) /*!< Position of PROTREG44 field. */ -#define MPU_PROTENSET1_PROTREG44_Msk (0x1UL << MPU_PROTENSET1_PROTREG44_Pos) /*!< Bit mask of PROTREG44 field. */ -#define MPU_PROTENSET1_PROTREG44_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET1_PROTREG44_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET1_PROTREG44_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 11 : Protection enable for region 43. */ -#define MPU_PROTENSET1_PROTREG43_Pos (11UL) /*!< Position of PROTREG43 field. */ -#define MPU_PROTENSET1_PROTREG43_Msk (0x1UL << MPU_PROTENSET1_PROTREG43_Pos) /*!< Bit mask of PROTREG43 field. */ -#define MPU_PROTENSET1_PROTREG43_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET1_PROTREG43_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET1_PROTREG43_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 10 : Protection enable for region 42. */ -#define MPU_PROTENSET1_PROTREG42_Pos (10UL) /*!< Position of PROTREG42 field. */ -#define MPU_PROTENSET1_PROTREG42_Msk (0x1UL << MPU_PROTENSET1_PROTREG42_Pos) /*!< Bit mask of PROTREG42 field. */ -#define MPU_PROTENSET1_PROTREG42_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET1_PROTREG42_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET1_PROTREG42_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 9 : Protection enable for region 41. */ -#define MPU_PROTENSET1_PROTREG41_Pos (9UL) /*!< Position of PROTREG41 field. */ -#define MPU_PROTENSET1_PROTREG41_Msk (0x1UL << MPU_PROTENSET1_PROTREG41_Pos) /*!< Bit mask of PROTREG41 field. */ -#define MPU_PROTENSET1_PROTREG41_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET1_PROTREG41_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET1_PROTREG41_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 8 : Protection enable for region 40. */ -#define MPU_PROTENSET1_PROTREG40_Pos (8UL) /*!< Position of PROTREG40 field. */ -#define MPU_PROTENSET1_PROTREG40_Msk (0x1UL << MPU_PROTENSET1_PROTREG40_Pos) /*!< Bit mask of PROTREG40 field. */ -#define MPU_PROTENSET1_PROTREG40_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET1_PROTREG40_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET1_PROTREG40_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 7 : Protection enable for region 39. */ -#define MPU_PROTENSET1_PROTREG39_Pos (7UL) /*!< Position of PROTREG39 field. */ -#define MPU_PROTENSET1_PROTREG39_Msk (0x1UL << MPU_PROTENSET1_PROTREG39_Pos) /*!< Bit mask of PROTREG39 field. */ -#define MPU_PROTENSET1_PROTREG39_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET1_PROTREG39_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET1_PROTREG39_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 6 : Protection enable for region 38. */ -#define MPU_PROTENSET1_PROTREG38_Pos (6UL) /*!< Position of PROTREG38 field. */ -#define MPU_PROTENSET1_PROTREG38_Msk (0x1UL << MPU_PROTENSET1_PROTREG38_Pos) /*!< Bit mask of PROTREG38 field. */ -#define MPU_PROTENSET1_PROTREG38_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET1_PROTREG38_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET1_PROTREG38_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 5 : Protection enable for region 37. */ -#define MPU_PROTENSET1_PROTREG37_Pos (5UL) /*!< Position of PROTREG37 field. */ -#define MPU_PROTENSET1_PROTREG37_Msk (0x1UL << MPU_PROTENSET1_PROTREG37_Pos) /*!< Bit mask of PROTREG37 field. */ -#define MPU_PROTENSET1_PROTREG37_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET1_PROTREG37_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET1_PROTREG37_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 4 : Protection enable for region 36. */ -#define MPU_PROTENSET1_PROTREG36_Pos (4UL) /*!< Position of PROTREG36 field. */ -#define MPU_PROTENSET1_PROTREG36_Msk (0x1UL << MPU_PROTENSET1_PROTREG36_Pos) /*!< Bit mask of PROTREG36 field. */ -#define MPU_PROTENSET1_PROTREG36_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET1_PROTREG36_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET1_PROTREG36_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 3 : Protection enable for region 35. */ -#define MPU_PROTENSET1_PROTREG35_Pos (3UL) /*!< Position of PROTREG35 field. */ -#define MPU_PROTENSET1_PROTREG35_Msk (0x1UL << MPU_PROTENSET1_PROTREG35_Pos) /*!< Bit mask of PROTREG35 field. */ -#define MPU_PROTENSET1_PROTREG35_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET1_PROTREG35_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET1_PROTREG35_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 2 : Protection enable for region 34. */ -#define MPU_PROTENSET1_PROTREG34_Pos (2UL) /*!< Position of PROTREG34 field. */ -#define MPU_PROTENSET1_PROTREG34_Msk (0x1UL << MPU_PROTENSET1_PROTREG34_Pos) /*!< Bit mask of PROTREG34 field. */ -#define MPU_PROTENSET1_PROTREG34_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET1_PROTREG34_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET1_PROTREG34_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 1 : Protection enable for region 33. */ -#define MPU_PROTENSET1_PROTREG33_Pos (1UL) /*!< Position of PROTREG33 field. */ -#define MPU_PROTENSET1_PROTREG33_Msk (0x1UL << MPU_PROTENSET1_PROTREG33_Pos) /*!< Bit mask of PROTREG33 field. */ -#define MPU_PROTENSET1_PROTREG33_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET1_PROTREG33_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET1_PROTREG33_Set (1UL) /*!< Enable protection on write. */ - -/* Bit 0 : Protection enable for region 32. */ -#define MPU_PROTENSET1_PROTREG32_Pos (0UL) /*!< Position of PROTREG32 field. */ -#define MPU_PROTENSET1_PROTREG32_Msk (0x1UL << MPU_PROTENSET1_PROTREG32_Pos) /*!< Bit mask of PROTREG32 field. */ -#define MPU_PROTENSET1_PROTREG32_Disabled (0UL) /*!< Protection disabled. */ -#define MPU_PROTENSET1_PROTREG32_Enabled (1UL) /*!< Protection enabled. */ -#define MPU_PROTENSET1_PROTREG32_Set (1UL) /*!< Enable protection on write. */ - -/* Register: MPU_DISABLEINDEBUG */ -/* Description: Disable erase and write protection mechanism in debug mode. */ - -/* Bit 0 : Disable protection mechanism in debug mode. */ -#define MPU_DISABLEINDEBUG_DISABLEINDEBUG_Pos (0UL) /*!< Position of DISABLEINDEBUG field. */ -#define MPU_DISABLEINDEBUG_DISABLEINDEBUG_Msk (0x1UL << MPU_DISABLEINDEBUG_DISABLEINDEBUG_Pos) /*!< Bit mask of DISABLEINDEBUG field. */ -#define MPU_DISABLEINDEBUG_DISABLEINDEBUG_Enabled (0UL) /*!< Protection enabled. */ -#define MPU_DISABLEINDEBUG_DISABLEINDEBUG_Disabled (1UL) /*!< Protection disabled. */ - -/* Register: MPU_PROTBLOCKSIZE */ -/* Description: Erase and write protection block size. */ - -/* Bits 1..0 : Erase and write protection block size. */ -#define MPU_PROTBLOCKSIZE_PROTBLOCKSIZE_Pos (0UL) /*!< Position of PROTBLOCKSIZE field. */ -#define MPU_PROTBLOCKSIZE_PROTBLOCKSIZE_Msk (0x3UL << MPU_PROTBLOCKSIZE_PROTBLOCKSIZE_Pos) /*!< Bit mask of PROTBLOCKSIZE field. */ -#define MPU_PROTBLOCKSIZE_PROTBLOCKSIZE_4k (0UL) /*!< Erase and write protection block size is 4k. */ - - -/* Peripheral: NVMC */ -/* Description: Non Volatile Memory Controller. */ - -/* Register: NVMC_READY */ -/* Description: Ready flag. */ - -/* Bit 0 : NVMC ready. */ -#define NVMC_READY_READY_Pos (0UL) /*!< Position of READY field. */ -#define NVMC_READY_READY_Msk (0x1UL << NVMC_READY_READY_Pos) /*!< Bit mask of READY field. */ -#define NVMC_READY_READY_Busy (0UL) /*!< NVMC is busy (on-going write or erase operation). */ -#define NVMC_READY_READY_Ready (1UL) /*!< NVMC is ready. */ - -/* Register: NVMC_CONFIG */ -/* Description: Configuration register. */ - -/* Bits 1..0 : Program write enable. */ -#define NVMC_CONFIG_WEN_Pos (0UL) /*!< Position of WEN field. */ -#define NVMC_CONFIG_WEN_Msk (0x3UL << NVMC_CONFIG_WEN_Pos) /*!< Bit mask of WEN field. */ -#define NVMC_CONFIG_WEN_Ren (0x00UL) /*!< Read only access. */ -#define NVMC_CONFIG_WEN_Wen (0x01UL) /*!< Write enabled. */ -#define NVMC_CONFIG_WEN_Een (0x02UL) /*!< Erase enabled. */ - -/* Register: NVMC_ERASEALL */ -/* Description: Register for erasing all non-volatile user memory. */ - -/* Bit 0 : Starts the erasing of all user NVM (code region 0/1 and UICR registers). */ -#define NVMC_ERASEALL_ERASEALL_Pos (0UL) /*!< Position of ERASEALL field. */ -#define NVMC_ERASEALL_ERASEALL_Msk (0x1UL << NVMC_ERASEALL_ERASEALL_Pos) /*!< Bit mask of ERASEALL field. */ -#define NVMC_ERASEALL_ERASEALL_NoOperation (0UL) /*!< No operation. */ -#define NVMC_ERASEALL_ERASEALL_Erase (1UL) /*!< Start chip erase. */ - -/* Register: NVMC_ERASEUICR */ -/* Description: Register for start erasing User Information Congfiguration Registers. */ - -/* Bit 0 : It can only be used when all contents of code region 1 are erased. */ -#define NVMC_ERASEUICR_ERASEUICR_Pos (0UL) /*!< Position of ERASEUICR field. */ -#define NVMC_ERASEUICR_ERASEUICR_Msk (0x1UL << NVMC_ERASEUICR_ERASEUICR_Pos) /*!< Bit mask of ERASEUICR field. */ -#define NVMC_ERASEUICR_ERASEUICR_NoOperation (0UL) /*!< No operation. */ -#define NVMC_ERASEUICR_ERASEUICR_Erase (1UL) /*!< Start UICR erase. */ - - -/* Peripheral: POWER */ -/* Description: Power Control. */ - -/* Register: POWER_INTENSET */ -/* Description: Interrupt enable set register. */ - -/* Bit 2 : Enable interrupt on POFWARN event. */ -#define POWER_INTENSET_POFWARN_Pos (2UL) /*!< Position of POFWARN field. */ -#define POWER_INTENSET_POFWARN_Msk (0x1UL << POWER_INTENSET_POFWARN_Pos) /*!< Bit mask of POFWARN field. */ -#define POWER_INTENSET_POFWARN_Disabled (0UL) /*!< Interrupt disabled. */ -#define POWER_INTENSET_POFWARN_Enabled (1UL) /*!< Interrupt enabled. */ -#define POWER_INTENSET_POFWARN_Set (1UL) /*!< Enable interrupt on write. */ - -/* Register: POWER_INTENCLR */ -/* Description: Interrupt enable clear register. */ - -/* Bit 2 : Disable interrupt on POFWARN event. */ -#define POWER_INTENCLR_POFWARN_Pos (2UL) /*!< Position of POFWARN field. */ -#define POWER_INTENCLR_POFWARN_Msk (0x1UL << POWER_INTENCLR_POFWARN_Pos) /*!< Bit mask of POFWARN field. */ -#define POWER_INTENCLR_POFWARN_Disabled (0UL) /*!< Interrupt disabled. */ -#define POWER_INTENCLR_POFWARN_Enabled (1UL) /*!< Interrupt enabled. */ -#define POWER_INTENCLR_POFWARN_Clear (1UL) /*!< Disable interrupt on write. */ - -/* Register: POWER_RESETREAS */ -/* Description: Reset reason. */ - -/* Bit 18 : Reset from wake-up from OFF mode detected by entering into debug interface mode. */ -#define POWER_RESETREAS_DIF_Pos (18UL) /*!< Position of DIF field. */ -#define POWER_RESETREAS_DIF_Msk (0x1UL << POWER_RESETREAS_DIF_Pos) /*!< Bit mask of DIF field. */ - -/* Bit 17 : Reset from wake-up from OFF mode detected by the use of ANADETECT signal from LPCOMP. */ -#define POWER_RESETREAS_LPCOMP_Pos (17UL) /*!< Position of LPCOMP field. */ -#define POWER_RESETREAS_LPCOMP_Msk (0x1UL << POWER_RESETREAS_LPCOMP_Pos) /*!< Bit mask of LPCOMP field. */ - -/* Bit 16 : Reset from wake-up from OFF mode detected by the use of DETECT signal from GPIO. */ -#define POWER_RESETREAS_OFF_Pos (16UL) /*!< Position of OFF field. */ -#define POWER_RESETREAS_OFF_Msk (0x1UL << POWER_RESETREAS_OFF_Pos) /*!< Bit mask of OFF field. */ - -/* Bit 3 : Reset from CPU lock-up detected. */ -#define POWER_RESETREAS_LOCKUP_Pos (3UL) /*!< Position of LOCKUP field. */ -#define POWER_RESETREAS_LOCKUP_Msk (0x1UL << POWER_RESETREAS_LOCKUP_Pos) /*!< Bit mask of LOCKUP field. */ - -/* Bit 2 : Reset from AIRCR.SYSRESETREQ detected. */ -#define POWER_RESETREAS_SREQ_Pos (2UL) /*!< Position of SREQ field. */ -#define POWER_RESETREAS_SREQ_Msk (0x1UL << POWER_RESETREAS_SREQ_Pos) /*!< Bit mask of SREQ field. */ - -/* Bit 1 : Reset from watchdog detected. */ -#define POWER_RESETREAS_DOG_Pos (1UL) /*!< Position of DOG field. */ -#define POWER_RESETREAS_DOG_Msk (0x1UL << POWER_RESETREAS_DOG_Pos) /*!< Bit mask of DOG field. */ - -/* Bit 0 : Reset from pin-reset detected. */ -#define POWER_RESETREAS_RESETPIN_Pos (0UL) /*!< Position of RESETPIN field. */ -#define POWER_RESETREAS_RESETPIN_Msk (0x1UL << POWER_RESETREAS_RESETPIN_Pos) /*!< Bit mask of RESETPIN field. */ - -/* Register: POWER_RAMSTATUS */ -/* Description: Ram status register. */ - -/* Bit 3 : RAM block 3 status. */ -#define POWER_RAMSTATUS_RAMBLOCK3_Pos (3UL) /*!< Position of RAMBLOCK3 field. */ -#define POWER_RAMSTATUS_RAMBLOCK3_Msk (0x1UL << POWER_RAMSTATUS_RAMBLOCK3_Pos) /*!< Bit mask of RAMBLOCK3 field. */ -#define POWER_RAMSTATUS_RAMBLOCK3_Off (0UL) /*!< RAM block 3 is off or powering up. */ -#define POWER_RAMSTATUS_RAMBLOCK3_On (1UL) /*!< RAM block 3 is on. */ - -/* Bit 2 : RAM block 2 status. */ -#define POWER_RAMSTATUS_RAMBLOCK2_Pos (2UL) /*!< Position of RAMBLOCK2 field. */ -#define POWER_RAMSTATUS_RAMBLOCK2_Msk (0x1UL << POWER_RAMSTATUS_RAMBLOCK2_Pos) /*!< Bit mask of RAMBLOCK2 field. */ -#define POWER_RAMSTATUS_RAMBLOCK2_Off (0UL) /*!< RAM block 2 is off or powering up. */ -#define POWER_RAMSTATUS_RAMBLOCK2_On (1UL) /*!< RAM block 2 is on. */ - -/* Bit 1 : RAM block 1 status. */ -#define POWER_RAMSTATUS_RAMBLOCK1_Pos (1UL) /*!< Position of RAMBLOCK1 field. */ -#define POWER_RAMSTATUS_RAMBLOCK1_Msk (0x1UL << POWER_RAMSTATUS_RAMBLOCK1_Pos) /*!< Bit mask of RAMBLOCK1 field. */ -#define POWER_RAMSTATUS_RAMBLOCK1_Off (0UL) /*!< RAM block 1 is off or powering up. */ -#define POWER_RAMSTATUS_RAMBLOCK1_On (1UL) /*!< RAM block 1 is on. */ - -/* Bit 0 : RAM block 0 status. */ -#define POWER_RAMSTATUS_RAMBLOCK0_Pos (0UL) /*!< Position of RAMBLOCK0 field. */ -#define POWER_RAMSTATUS_RAMBLOCK0_Msk (0x1UL << POWER_RAMSTATUS_RAMBLOCK0_Pos) /*!< Bit mask of RAMBLOCK0 field. */ -#define POWER_RAMSTATUS_RAMBLOCK0_Off (0UL) /*!< RAM block 0 is off or powering up. */ -#define POWER_RAMSTATUS_RAMBLOCK0_On (1UL) /*!< RAM block 0 is on. */ - -/* Register: POWER_SYSTEMOFF */ -/* Description: System off register. */ - -/* Bit 0 : Enter system off mode. */ -#define POWER_SYSTEMOFF_SYSTEMOFF_Pos (0UL) /*!< Position of SYSTEMOFF field. */ -#define POWER_SYSTEMOFF_SYSTEMOFF_Msk (0x1UL << POWER_SYSTEMOFF_SYSTEMOFF_Pos) /*!< Bit mask of SYSTEMOFF field. */ -#define POWER_SYSTEMOFF_SYSTEMOFF_Enter (1UL) /*!< Enter system off mode. */ - -/* Register: POWER_POFCON */ -/* Description: Power failure configuration. */ - -/* Bits 2..1 : Set threshold level. */ -#define POWER_POFCON_THRESHOLD_Pos (1UL) /*!< Position of THRESHOLD field. */ -#define POWER_POFCON_THRESHOLD_Msk (0x3UL << POWER_POFCON_THRESHOLD_Pos) /*!< Bit mask of THRESHOLD field. */ -#define POWER_POFCON_THRESHOLD_V21 (0x00UL) /*!< Set threshold to 2.1Volts. */ -#define POWER_POFCON_THRESHOLD_V23 (0x01UL) /*!< Set threshold to 2.3Volts. */ -#define POWER_POFCON_THRESHOLD_V25 (0x02UL) /*!< Set threshold to 2.5Volts. */ -#define POWER_POFCON_THRESHOLD_V27 (0x03UL) /*!< Set threshold to 2.7Volts. */ - -/* Bit 0 : Power failure comparator enable. */ -#define POWER_POFCON_POF_Pos (0UL) /*!< Position of POF field. */ -#define POWER_POFCON_POF_Msk (0x1UL << POWER_POFCON_POF_Pos) /*!< Bit mask of POF field. */ -#define POWER_POFCON_POF_Disabled (0UL) /*!< Disabled. */ -#define POWER_POFCON_POF_Enabled (1UL) /*!< Enabled. */ - -/* Register: POWER_GPREGRET */ -/* Description: General purpose retention register. This register is a retained register. */ - -/* Bits 7..0 : General purpose retention register. */ -#define POWER_GPREGRET_GPREGRET_Pos (0UL) /*!< Position of GPREGRET field. */ -#define POWER_GPREGRET_GPREGRET_Msk (0xFFUL << POWER_GPREGRET_GPREGRET_Pos) /*!< Bit mask of GPREGRET field. */ - -/* Register: POWER_RAMON */ -/* Description: Ram on/off. */ - -/* Bit 17 : RAM block 1 behaviour in OFF mode. */ -#define POWER_RAMON_OFFRAM1_Pos (17UL) /*!< Position of OFFRAM1 field. */ -#define POWER_RAMON_OFFRAM1_Msk (0x1UL << POWER_RAMON_OFFRAM1_Pos) /*!< Bit mask of OFFRAM1 field. */ -#define POWER_RAMON_OFFRAM1_RAM1Off (0UL) /*!< RAM block 1 OFF in OFF mode. */ -#define POWER_RAMON_OFFRAM1_RAM1On (1UL) /*!< RAM block 1 ON in OFF mode. */ - -/* Bit 16 : RAM block 0 behaviour in OFF mode. */ -#define POWER_RAMON_OFFRAM0_Pos (16UL) /*!< Position of OFFRAM0 field. */ -#define POWER_RAMON_OFFRAM0_Msk (0x1UL << POWER_RAMON_OFFRAM0_Pos) /*!< Bit mask of OFFRAM0 field. */ -#define POWER_RAMON_OFFRAM0_RAM0Off (0UL) /*!< RAM block 0 OFF in OFF mode. */ -#define POWER_RAMON_OFFRAM0_RAM0On (1UL) /*!< RAM block 0 ON in OFF mode. */ - -/* Bit 1 : RAM block 1 behaviour in ON mode. */ -#define POWER_RAMON_ONRAM1_Pos (1UL) /*!< Position of ONRAM1 field. */ -#define POWER_RAMON_ONRAM1_Msk (0x1UL << POWER_RAMON_ONRAM1_Pos) /*!< Bit mask of ONRAM1 field. */ -#define POWER_RAMON_ONRAM1_RAM1Off (0UL) /*!< RAM block 1 OFF in ON mode. */ -#define POWER_RAMON_ONRAM1_RAM1On (1UL) /*!< RAM block 1 ON in ON mode. */ - -/* Bit 0 : RAM block 0 behaviour in ON mode. */ -#define POWER_RAMON_ONRAM0_Pos (0UL) /*!< Position of ONRAM0 field. */ -#define POWER_RAMON_ONRAM0_Msk (0x1UL << POWER_RAMON_ONRAM0_Pos) /*!< Bit mask of ONRAM0 field. */ -#define POWER_RAMON_ONRAM0_RAM0Off (0UL) /*!< RAM block 0 OFF in ON mode. */ -#define POWER_RAMON_ONRAM0_RAM0On (1UL) /*!< RAM block 0 ON in ON mode. */ - -/* Register: POWER_RESET */ -/* Description: Pin reset functionality configuration register. This register is a retained register. */ - -/* Bit 0 : Enable or disable pin reset in debug interface mode. */ -#define POWER_RESET_RESET_Pos (0UL) /*!< Position of RESET field. */ -#define POWER_RESET_RESET_Msk (0x1UL << POWER_RESET_RESET_Pos) /*!< Bit mask of RESET field. */ -#define POWER_RESET_RESET_Disabled (0UL) /*!< Pin reset in debug interface mode disabled. */ -#define POWER_RESET_RESET_Enabled (1UL) /*!< Pin reset in debug interface mode enabled. */ - -/* Register: POWER_RAMONB */ -/* Description: Ram on/off. */ - -/* Bit 17 : RAM block 3 behaviour in OFF mode. */ -#define POWER_RAMONB_OFFRAM3_Pos (17UL) /*!< Position of OFFRAM3 field. */ -#define POWER_RAMONB_OFFRAM3_Msk (0x1UL << POWER_RAMONB_OFFRAM3_Pos) /*!< Bit mask of OFFRAM3 field. */ -#define POWER_RAMONB_OFFRAM3_RAM3Off (0UL) /*!< RAM block 3 OFF in OFF mode. */ -#define POWER_RAMONB_OFFRAM3_RAM3On (1UL) /*!< RAM block 3 ON in OFF mode. */ - -/* Bit 16 : RAM block 2 behaviour in OFF mode. */ -#define POWER_RAMONB_OFFRAM2_Pos (16UL) /*!< Position of OFFRAM2 field. */ -#define POWER_RAMONB_OFFRAM2_Msk (0x1UL << POWER_RAMONB_OFFRAM2_Pos) /*!< Bit mask of OFFRAM2 field. */ -#define POWER_RAMONB_OFFRAM2_RAM2Off (0UL) /*!< RAM block 2 OFF in OFF mode. */ -#define POWER_RAMONB_OFFRAM2_RAM2On (1UL) /*!< RAM block 2 ON in OFF mode. */ - -/* Bit 1 : RAM block 3 behaviour in ON mode. */ -#define POWER_RAMONB_ONRAM3_Pos (1UL) /*!< Position of ONRAM3 field. */ -#define POWER_RAMONB_ONRAM3_Msk (0x1UL << POWER_RAMONB_ONRAM3_Pos) /*!< Bit mask of ONRAM3 field. */ -#define POWER_RAMONB_ONRAM3_RAM3Off (0UL) /*!< RAM block 33 OFF in ON mode. */ -#define POWER_RAMONB_ONRAM3_RAM3On (1UL) /*!< RAM block 3 ON in ON mode. */ - -/* Bit 0 : RAM block 2 behaviour in ON mode. */ -#define POWER_RAMONB_ONRAM2_Pos (0UL) /*!< Position of ONRAM2 field. */ -#define POWER_RAMONB_ONRAM2_Msk (0x1UL << POWER_RAMONB_ONRAM2_Pos) /*!< Bit mask of ONRAM2 field. */ -#define POWER_RAMONB_ONRAM2_RAM2Off (0UL) /*!< RAM block 2 OFF in ON mode. */ -#define POWER_RAMONB_ONRAM2_RAM2On (1UL) /*!< RAM block 2 ON in ON mode. */ - -/* Register: POWER_DCDCEN */ -/* Description: DCDC converter enable configuration register. */ - -/* Bit 0 : Enable DCDC converter. */ -#define POWER_DCDCEN_DCDCEN_Pos (0UL) /*!< Position of DCDCEN field. */ -#define POWER_DCDCEN_DCDCEN_Msk (0x1UL << POWER_DCDCEN_DCDCEN_Pos) /*!< Bit mask of DCDCEN field. */ -#define POWER_DCDCEN_DCDCEN_Disabled (0UL) /*!< DCDC converter disabled. */ -#define POWER_DCDCEN_DCDCEN_Enabled (1UL) /*!< DCDC converter enabled. */ - -/* Register: POWER_DCDCFORCE */ -/* Description: DCDC power-up force register. */ - -/* Bit 1 : DCDC power-up force on. */ -#define POWER_DCDCFORCE_FORCEON_Pos (1UL) /*!< Position of FORCEON field. */ -#define POWER_DCDCFORCE_FORCEON_Msk (0x1UL << POWER_DCDCFORCE_FORCEON_Pos) /*!< Bit mask of FORCEON field. */ -#define POWER_DCDCFORCE_FORCEON_NoForce (0UL) /*!< No force. */ -#define POWER_DCDCFORCE_FORCEON_Force (1UL) /*!< Force. */ - -/* Bit 0 : DCDC power-up force off. */ -#define POWER_DCDCFORCE_FORCEOFF_Pos (0UL) /*!< Position of FORCEOFF field. */ -#define POWER_DCDCFORCE_FORCEOFF_Msk (0x1UL << POWER_DCDCFORCE_FORCEOFF_Pos) /*!< Bit mask of FORCEOFF field. */ -#define POWER_DCDCFORCE_FORCEOFF_NoForce (0UL) /*!< No force. */ -#define POWER_DCDCFORCE_FORCEOFF_Force (1UL) /*!< Force. */ - - -/* Peripheral: PPI */ -/* Description: PPI controller. */ - -/* Register: PPI_CHEN */ -/* Description: Channel enable. */ - -/* Bit 31 : Enable PPI channel 31. */ -#define PPI_CHEN_CH31_Pos (31UL) /*!< Position of CH31 field. */ -#define PPI_CHEN_CH31_Msk (0x1UL << PPI_CHEN_CH31_Pos) /*!< Bit mask of CH31 field. */ -#define PPI_CHEN_CH31_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHEN_CH31_Enabled (1UL) /*!< Channel enabled. */ - -/* Bit 30 : Enable PPI channel 30. */ -#define PPI_CHEN_CH30_Pos (30UL) /*!< Position of CH30 field. */ -#define PPI_CHEN_CH30_Msk (0x1UL << PPI_CHEN_CH30_Pos) /*!< Bit mask of CH30 field. */ -#define PPI_CHEN_CH30_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHEN_CH30_Enabled (1UL) /*!< Channel enabled. */ - -/* Bit 29 : Enable PPI channel 29. */ -#define PPI_CHEN_CH29_Pos (29UL) /*!< Position of CH29 field. */ -#define PPI_CHEN_CH29_Msk (0x1UL << PPI_CHEN_CH29_Pos) /*!< Bit mask of CH29 field. */ -#define PPI_CHEN_CH29_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHEN_CH29_Enabled (1UL) /*!< Channel enabled. */ - -/* Bit 28 : Enable PPI channel 28. */ -#define PPI_CHEN_CH28_Pos (28UL) /*!< Position of CH28 field. */ -#define PPI_CHEN_CH28_Msk (0x1UL << PPI_CHEN_CH28_Pos) /*!< Bit mask of CH28 field. */ -#define PPI_CHEN_CH28_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHEN_CH28_Enabled (1UL) /*!< Channel enabled. */ - -/* Bit 27 : Enable PPI channel 27. */ -#define PPI_CHEN_CH27_Pos (27UL) /*!< Position of CH27 field. */ -#define PPI_CHEN_CH27_Msk (0x1UL << PPI_CHEN_CH27_Pos) /*!< Bit mask of CH27 field. */ -#define PPI_CHEN_CH27_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHEN_CH27_Enabled (1UL) /*!< Channel enabled. */ - -/* Bit 26 : Enable PPI channel 26. */ -#define PPI_CHEN_CH26_Pos (26UL) /*!< Position of CH26 field. */ -#define PPI_CHEN_CH26_Msk (0x1UL << PPI_CHEN_CH26_Pos) /*!< Bit mask of CH26 field. */ -#define PPI_CHEN_CH26_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHEN_CH26_Enabled (1UL) /*!< Channel enabled. */ - -/* Bit 25 : Enable PPI channel 25. */ -#define PPI_CHEN_CH25_Pos (25UL) /*!< Position of CH25 field. */ -#define PPI_CHEN_CH25_Msk (0x1UL << PPI_CHEN_CH25_Pos) /*!< Bit mask of CH25 field. */ -#define PPI_CHEN_CH25_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHEN_CH25_Enabled (1UL) /*!< Channel enabled. */ - -/* Bit 24 : Enable PPI channel 24. */ -#define PPI_CHEN_CH24_Pos (24UL) /*!< Position of CH24 field. */ -#define PPI_CHEN_CH24_Msk (0x1UL << PPI_CHEN_CH24_Pos) /*!< Bit mask of CH24 field. */ -#define PPI_CHEN_CH24_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHEN_CH24_Enabled (1UL) /*!< Channel enabled. */ - -/* Bit 23 : Enable PPI channel 23. */ -#define PPI_CHEN_CH23_Pos (23UL) /*!< Position of CH23 field. */ -#define PPI_CHEN_CH23_Msk (0x1UL << PPI_CHEN_CH23_Pos) /*!< Bit mask of CH23 field. */ -#define PPI_CHEN_CH23_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHEN_CH23_Enabled (1UL) /*!< Channel enabled. */ - -/* Bit 22 : Enable PPI channel 22. */ -#define PPI_CHEN_CH22_Pos (22UL) /*!< Position of CH22 field. */ -#define PPI_CHEN_CH22_Msk (0x1UL << PPI_CHEN_CH22_Pos) /*!< Bit mask of CH22 field. */ -#define PPI_CHEN_CH22_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHEN_CH22_Enabled (1UL) /*!< Channel enabled. */ - -/* Bit 21 : Enable PPI channel 21. */ -#define PPI_CHEN_CH21_Pos (21UL) /*!< Position of CH21 field. */ -#define PPI_CHEN_CH21_Msk (0x1UL << PPI_CHEN_CH21_Pos) /*!< Bit mask of CH21 field. */ -#define PPI_CHEN_CH21_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHEN_CH21_Enabled (1UL) /*!< Channel enabled. */ - -/* Bit 20 : Enable PPI channel 20. */ -#define PPI_CHEN_CH20_Pos (20UL) /*!< Position of CH20 field. */ -#define PPI_CHEN_CH20_Msk (0x1UL << PPI_CHEN_CH20_Pos) /*!< Bit mask of CH20 field. */ -#define PPI_CHEN_CH20_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHEN_CH20_Enabled (1UL) /*!< Channel enabled. */ - -/* Bit 15 : Enable PPI channel 15. */ -#define PPI_CHEN_CH15_Pos (15UL) /*!< Position of CH15 field. */ -#define PPI_CHEN_CH15_Msk (0x1UL << PPI_CHEN_CH15_Pos) /*!< Bit mask of CH15 field. */ -#define PPI_CHEN_CH15_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHEN_CH15_Enabled (1UL) /*!< Channel enabled. */ - -/* Bit 14 : Enable PPI channel 14. */ -#define PPI_CHEN_CH14_Pos (14UL) /*!< Position of CH14 field. */ -#define PPI_CHEN_CH14_Msk (0x1UL << PPI_CHEN_CH14_Pos) /*!< Bit mask of CH14 field. */ -#define PPI_CHEN_CH14_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHEN_CH14_Enabled (1UL) /*!< Channel enabled. */ - -/* Bit 13 : Enable PPI channel 13. */ -#define PPI_CHEN_CH13_Pos (13UL) /*!< Position of CH13 field. */ -#define PPI_CHEN_CH13_Msk (0x1UL << PPI_CHEN_CH13_Pos) /*!< Bit mask of CH13 field. */ -#define PPI_CHEN_CH13_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHEN_CH13_Enabled (1UL) /*!< Channel enabled. */ - -/* Bit 12 : Enable PPI channel 12. */ -#define PPI_CHEN_CH12_Pos (12UL) /*!< Position of CH12 field. */ -#define PPI_CHEN_CH12_Msk (0x1UL << PPI_CHEN_CH12_Pos) /*!< Bit mask of CH12 field. */ -#define PPI_CHEN_CH12_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHEN_CH12_Enabled (1UL) /*!< Channel enabled. */ - -/* Bit 11 : Enable PPI channel 11. */ -#define PPI_CHEN_CH11_Pos (11UL) /*!< Position of CH11 field. */ -#define PPI_CHEN_CH11_Msk (0x1UL << PPI_CHEN_CH11_Pos) /*!< Bit mask of CH11 field. */ -#define PPI_CHEN_CH11_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHEN_CH11_Enabled (1UL) /*!< Channel enabled. */ - -/* Bit 10 : Enable PPI channel 10. */ -#define PPI_CHEN_CH10_Pos (10UL) /*!< Position of CH10 field. */ -#define PPI_CHEN_CH10_Msk (0x1UL << PPI_CHEN_CH10_Pos) /*!< Bit mask of CH10 field. */ -#define PPI_CHEN_CH10_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHEN_CH10_Enabled (1UL) /*!< Channel enabled. */ - -/* Bit 9 : Enable PPI channel 9. */ -#define PPI_CHEN_CH9_Pos (9UL) /*!< Position of CH9 field. */ -#define PPI_CHEN_CH9_Msk (0x1UL << PPI_CHEN_CH9_Pos) /*!< Bit mask of CH9 field. */ -#define PPI_CHEN_CH9_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHEN_CH9_Enabled (1UL) /*!< Channel enabled. */ - -/* Bit 8 : Enable PPI channel 8. */ -#define PPI_CHEN_CH8_Pos (8UL) /*!< Position of CH8 field. */ -#define PPI_CHEN_CH8_Msk (0x1UL << PPI_CHEN_CH8_Pos) /*!< Bit mask of CH8 field. */ -#define PPI_CHEN_CH8_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHEN_CH8_Enabled (1UL) /*!< Channel enabled. */ - -/* Bit 7 : Enable PPI channel 7. */ -#define PPI_CHEN_CH7_Pos (7UL) /*!< Position of CH7 field. */ -#define PPI_CHEN_CH7_Msk (0x1UL << PPI_CHEN_CH7_Pos) /*!< Bit mask of CH7 field. */ -#define PPI_CHEN_CH7_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHEN_CH7_Enabled (1UL) /*!< Channel enabled. */ - -/* Bit 6 : Enable PPI channel 6. */ -#define PPI_CHEN_CH6_Pos (6UL) /*!< Position of CH6 field. */ -#define PPI_CHEN_CH6_Msk (0x1UL << PPI_CHEN_CH6_Pos) /*!< Bit mask of CH6 field. */ -#define PPI_CHEN_CH6_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHEN_CH6_Enabled (1UL) /*!< Channel enabled. */ - -/* Bit 5 : Enable PPI channel 5. */ -#define PPI_CHEN_CH5_Pos (5UL) /*!< Position of CH5 field. */ -#define PPI_CHEN_CH5_Msk (0x1UL << PPI_CHEN_CH5_Pos) /*!< Bit mask of CH5 field. */ -#define PPI_CHEN_CH5_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHEN_CH5_Enabled (1UL) /*!< Channel enabled. */ - -/* Bit 4 : Enable PPI channel 4. */ -#define PPI_CHEN_CH4_Pos (4UL) /*!< Position of CH4 field. */ -#define PPI_CHEN_CH4_Msk (0x1UL << PPI_CHEN_CH4_Pos) /*!< Bit mask of CH4 field. */ -#define PPI_CHEN_CH4_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHEN_CH4_Enabled (1UL) /*!< Channel enabled. */ - -/* Bit 3 : Enable PPI channel 3. */ -#define PPI_CHEN_CH3_Pos (3UL) /*!< Position of CH3 field. */ -#define PPI_CHEN_CH3_Msk (0x1UL << PPI_CHEN_CH3_Pos) /*!< Bit mask of CH3 field. */ -#define PPI_CHEN_CH3_Disabled (0UL) /*!< Channel disabled */ -#define PPI_CHEN_CH3_Enabled (1UL) /*!< Channel enabled */ - -/* Bit 2 : Enable PPI channel 2. */ -#define PPI_CHEN_CH2_Pos (2UL) /*!< Position of CH2 field. */ -#define PPI_CHEN_CH2_Msk (0x1UL << PPI_CHEN_CH2_Pos) /*!< Bit mask of CH2 field. */ -#define PPI_CHEN_CH2_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHEN_CH2_Enabled (1UL) /*!< Channel enabled. */ - -/* Bit 1 : Enable PPI channel 1. */ -#define PPI_CHEN_CH1_Pos (1UL) /*!< Position of CH1 field. */ -#define PPI_CHEN_CH1_Msk (0x1UL << PPI_CHEN_CH1_Pos) /*!< Bit mask of CH1 field. */ -#define PPI_CHEN_CH1_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHEN_CH1_Enabled (1UL) /*!< Channel enabled. */ - -/* Bit 0 : Enable PPI channel 0. */ -#define PPI_CHEN_CH0_Pos (0UL) /*!< Position of CH0 field. */ -#define PPI_CHEN_CH0_Msk (0x1UL << PPI_CHEN_CH0_Pos) /*!< Bit mask of CH0 field. */ -#define PPI_CHEN_CH0_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHEN_CH0_Enabled (1UL) /*!< Channel enabled. */ - -/* Register: PPI_CHENSET */ -/* Description: Channel enable set. */ - -/* Bit 31 : Enable PPI channel 31. */ -#define PPI_CHENSET_CH31_Pos (31UL) /*!< Position of CH31 field. */ -#define PPI_CHENSET_CH31_Msk (0x1UL << PPI_CHENSET_CH31_Pos) /*!< Bit mask of CH31 field. */ -#define PPI_CHENSET_CH31_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENSET_CH31_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENSET_CH31_Set (1UL) /*!< Enable channel on write. */ - -/* Bit 30 : Enable PPI channel 30. */ -#define PPI_CHENSET_CH30_Pos (30UL) /*!< Position of CH30 field. */ -#define PPI_CHENSET_CH30_Msk (0x1UL << PPI_CHENSET_CH30_Pos) /*!< Bit mask of CH30 field. */ -#define PPI_CHENSET_CH30_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENSET_CH30_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENSET_CH30_Set (1UL) /*!< Enable channel on write. */ - -/* Bit 29 : Enable PPI channel 29. */ -#define PPI_CHENSET_CH29_Pos (29UL) /*!< Position of CH29 field. */ -#define PPI_CHENSET_CH29_Msk (0x1UL << PPI_CHENSET_CH29_Pos) /*!< Bit mask of CH29 field. */ -#define PPI_CHENSET_CH29_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENSET_CH29_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENSET_CH29_Set (1UL) /*!< Enable channel on write. */ - -/* Bit 28 : Enable PPI channel 28. */ -#define PPI_CHENSET_CH28_Pos (28UL) /*!< Position of CH28 field. */ -#define PPI_CHENSET_CH28_Msk (0x1UL << PPI_CHENSET_CH28_Pos) /*!< Bit mask of CH28 field. */ -#define PPI_CHENSET_CH28_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENSET_CH28_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENSET_CH28_Set (1UL) /*!< Enable channel on write. */ - -/* Bit 27 : Enable PPI channel 27. */ -#define PPI_CHENSET_CH27_Pos (27UL) /*!< Position of CH27 field. */ -#define PPI_CHENSET_CH27_Msk (0x1UL << PPI_CHENSET_CH27_Pos) /*!< Bit mask of CH27 field. */ -#define PPI_CHENSET_CH27_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENSET_CH27_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENSET_CH27_Set (1UL) /*!< Enable channel on write. */ - -/* Bit 26 : Enable PPI channel 26. */ -#define PPI_CHENSET_CH26_Pos (26UL) /*!< Position of CH26 field. */ -#define PPI_CHENSET_CH26_Msk (0x1UL << PPI_CHENSET_CH26_Pos) /*!< Bit mask of CH26 field. */ -#define PPI_CHENSET_CH26_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENSET_CH26_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENSET_CH26_Set (1UL) /*!< Enable channel on write. */ - -/* Bit 25 : Enable PPI channel 25. */ -#define PPI_CHENSET_CH25_Pos (25UL) /*!< Position of CH25 field. */ -#define PPI_CHENSET_CH25_Msk (0x1UL << PPI_CHENSET_CH25_Pos) /*!< Bit mask of CH25 field. */ -#define PPI_CHENSET_CH25_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENSET_CH25_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENSET_CH25_Set (1UL) /*!< Enable channel on write. */ - -/* Bit 24 : Enable PPI channel 24. */ -#define PPI_CHENSET_CH24_Pos (24UL) /*!< Position of CH24 field. */ -#define PPI_CHENSET_CH24_Msk (0x1UL << PPI_CHENSET_CH24_Pos) /*!< Bit mask of CH24 field. */ -#define PPI_CHENSET_CH24_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENSET_CH24_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENSET_CH24_Set (1UL) /*!< Enable channel on write. */ - -/* Bit 23 : Enable PPI channel 23. */ -#define PPI_CHENSET_CH23_Pos (23UL) /*!< Position of CH23 field. */ -#define PPI_CHENSET_CH23_Msk (0x1UL << PPI_CHENSET_CH23_Pos) /*!< Bit mask of CH23 field. */ -#define PPI_CHENSET_CH23_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENSET_CH23_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENSET_CH23_Set (1UL) /*!< Enable channel on write. */ - -/* Bit 22 : Enable PPI channel 22. */ -#define PPI_CHENSET_CH22_Pos (22UL) /*!< Position of CH22 field. */ -#define PPI_CHENSET_CH22_Msk (0x1UL << PPI_CHENSET_CH22_Pos) /*!< Bit mask of CH22 field. */ -#define PPI_CHENSET_CH22_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENSET_CH22_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENSET_CH22_Set (1UL) /*!< Enable channel on write. */ - -/* Bit 21 : Enable PPI channel 21. */ -#define PPI_CHENSET_CH21_Pos (21UL) /*!< Position of CH21 field. */ -#define PPI_CHENSET_CH21_Msk (0x1UL << PPI_CHENSET_CH21_Pos) /*!< Bit mask of CH21 field. */ -#define PPI_CHENSET_CH21_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENSET_CH21_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENSET_CH21_Set (1UL) /*!< Enable channel on write. */ - -/* Bit 20 : Enable PPI channel 20. */ -#define PPI_CHENSET_CH20_Pos (20UL) /*!< Position of CH20 field. */ -#define PPI_CHENSET_CH20_Msk (0x1UL << PPI_CHENSET_CH20_Pos) /*!< Bit mask of CH20 field. */ -#define PPI_CHENSET_CH20_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENSET_CH20_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENSET_CH20_Set (1UL) /*!< Enable channel on write. */ - -/* Bit 15 : Enable PPI channel 15. */ -#define PPI_CHENSET_CH15_Pos (15UL) /*!< Position of CH15 field. */ -#define PPI_CHENSET_CH15_Msk (0x1UL << PPI_CHENSET_CH15_Pos) /*!< Bit mask of CH15 field. */ -#define PPI_CHENSET_CH15_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENSET_CH15_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENSET_CH15_Set (1UL) /*!< Enable channel on write. */ - -/* Bit 14 : Enable PPI channel 14. */ -#define PPI_CHENSET_CH14_Pos (14UL) /*!< Position of CH14 field. */ -#define PPI_CHENSET_CH14_Msk (0x1UL << PPI_CHENSET_CH14_Pos) /*!< Bit mask of CH14 field. */ -#define PPI_CHENSET_CH14_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENSET_CH14_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENSET_CH14_Set (1UL) /*!< Enable channel on write. */ - -/* Bit 13 : Enable PPI channel 13. */ -#define PPI_CHENSET_CH13_Pos (13UL) /*!< Position of CH13 field. */ -#define PPI_CHENSET_CH13_Msk (0x1UL << PPI_CHENSET_CH13_Pos) /*!< Bit mask of CH13 field. */ -#define PPI_CHENSET_CH13_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENSET_CH13_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENSET_CH13_Set (1UL) /*!< Enable channel on write. */ - -/* Bit 12 : Enable PPI channel 12. */ -#define PPI_CHENSET_CH12_Pos (12UL) /*!< Position of CH12 field. */ -#define PPI_CHENSET_CH12_Msk (0x1UL << PPI_CHENSET_CH12_Pos) /*!< Bit mask of CH12 field. */ -#define PPI_CHENSET_CH12_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENSET_CH12_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENSET_CH12_Set (1UL) /*!< Enable channel on write. */ - -/* Bit 11 : Enable PPI channel 11. */ -#define PPI_CHENSET_CH11_Pos (11UL) /*!< Position of CH11 field. */ -#define PPI_CHENSET_CH11_Msk (0x1UL << PPI_CHENSET_CH11_Pos) /*!< Bit mask of CH11 field. */ -#define PPI_CHENSET_CH11_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENSET_CH11_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENSET_CH11_Set (1UL) /*!< Enable channel on write. */ - -/* Bit 10 : Enable PPI channel 10. */ -#define PPI_CHENSET_CH10_Pos (10UL) /*!< Position of CH10 field. */ -#define PPI_CHENSET_CH10_Msk (0x1UL << PPI_CHENSET_CH10_Pos) /*!< Bit mask of CH10 field. */ -#define PPI_CHENSET_CH10_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENSET_CH10_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENSET_CH10_Set (1UL) /*!< Enable channel on write. */ - -/* Bit 9 : Enable PPI channel 9. */ -#define PPI_CHENSET_CH9_Pos (9UL) /*!< Position of CH9 field. */ -#define PPI_CHENSET_CH9_Msk (0x1UL << PPI_CHENSET_CH9_Pos) /*!< Bit mask of CH9 field. */ -#define PPI_CHENSET_CH9_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENSET_CH9_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENSET_CH9_Set (1UL) /*!< Enable channel on write. */ - -/* Bit 8 : Enable PPI channel 8. */ -#define PPI_CHENSET_CH8_Pos (8UL) /*!< Position of CH8 field. */ -#define PPI_CHENSET_CH8_Msk (0x1UL << PPI_CHENSET_CH8_Pos) /*!< Bit mask of CH8 field. */ -#define PPI_CHENSET_CH8_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENSET_CH8_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENSET_CH8_Set (1UL) /*!< Enable channel on write. */ - -/* Bit 7 : Enable PPI channel 7. */ -#define PPI_CHENSET_CH7_Pos (7UL) /*!< Position of CH7 field. */ -#define PPI_CHENSET_CH7_Msk (0x1UL << PPI_CHENSET_CH7_Pos) /*!< Bit mask of CH7 field. */ -#define PPI_CHENSET_CH7_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENSET_CH7_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENSET_CH7_Set (1UL) /*!< Enable channel on write. */ - -/* Bit 6 : Enable PPI channel 6. */ -#define PPI_CHENSET_CH6_Pos (6UL) /*!< Position of CH6 field. */ -#define PPI_CHENSET_CH6_Msk (0x1UL << PPI_CHENSET_CH6_Pos) /*!< Bit mask of CH6 field. */ -#define PPI_CHENSET_CH6_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENSET_CH6_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENSET_CH6_Set (1UL) /*!< Enable channel on write. */ - -/* Bit 5 : Enable PPI channel 5. */ -#define PPI_CHENSET_CH5_Pos (5UL) /*!< Position of CH5 field. */ -#define PPI_CHENSET_CH5_Msk (0x1UL << PPI_CHENSET_CH5_Pos) /*!< Bit mask of CH5 field. */ -#define PPI_CHENSET_CH5_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENSET_CH5_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENSET_CH5_Set (1UL) /*!< Enable channel on write. */ - -/* Bit 4 : Enable PPI channel 4. */ -#define PPI_CHENSET_CH4_Pos (4UL) /*!< Position of CH4 field. */ -#define PPI_CHENSET_CH4_Msk (0x1UL << PPI_CHENSET_CH4_Pos) /*!< Bit mask of CH4 field. */ -#define PPI_CHENSET_CH4_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENSET_CH4_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENSET_CH4_Set (1UL) /*!< Enable channel on write. */ - -/* Bit 3 : Enable PPI channel 3. */ -#define PPI_CHENSET_CH3_Pos (3UL) /*!< Position of CH3 field. */ -#define PPI_CHENSET_CH3_Msk (0x1UL << PPI_CHENSET_CH3_Pos) /*!< Bit mask of CH3 field. */ -#define PPI_CHENSET_CH3_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENSET_CH3_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENSET_CH3_Set (1UL) /*!< Enable channel on write. */ - -/* Bit 2 : Enable PPI channel 2. */ -#define PPI_CHENSET_CH2_Pos (2UL) /*!< Position of CH2 field. */ -#define PPI_CHENSET_CH2_Msk (0x1UL << PPI_CHENSET_CH2_Pos) /*!< Bit mask of CH2 field. */ -#define PPI_CHENSET_CH2_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENSET_CH2_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENSET_CH2_Set (1UL) /*!< Enable channel on write. */ - -/* Bit 1 : Enable PPI channel 1. */ -#define PPI_CHENSET_CH1_Pos (1UL) /*!< Position of CH1 field. */ -#define PPI_CHENSET_CH1_Msk (0x1UL << PPI_CHENSET_CH1_Pos) /*!< Bit mask of CH1 field. */ -#define PPI_CHENSET_CH1_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENSET_CH1_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENSET_CH1_Set (1UL) /*!< Enable channel on write. */ - -/* Bit 0 : Enable PPI channel 0. */ -#define PPI_CHENSET_CH0_Pos (0UL) /*!< Position of CH0 field. */ -#define PPI_CHENSET_CH0_Msk (0x1UL << PPI_CHENSET_CH0_Pos) /*!< Bit mask of CH0 field. */ -#define PPI_CHENSET_CH0_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENSET_CH0_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENSET_CH0_Set (1UL) /*!< Enable channel on write. */ - -/* Register: PPI_CHENCLR */ -/* Description: Channel enable clear. */ - -/* Bit 31 : Disable PPI channel 31. */ -#define PPI_CHENCLR_CH31_Pos (31UL) /*!< Position of CH31 field. */ -#define PPI_CHENCLR_CH31_Msk (0x1UL << PPI_CHENCLR_CH31_Pos) /*!< Bit mask of CH31 field. */ -#define PPI_CHENCLR_CH31_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENCLR_CH31_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENCLR_CH31_Clear (1UL) /*!< Disable channel on write. */ - -/* Bit 30 : Disable PPI channel 30. */ -#define PPI_CHENCLR_CH30_Pos (30UL) /*!< Position of CH30 field. */ -#define PPI_CHENCLR_CH30_Msk (0x1UL << PPI_CHENCLR_CH30_Pos) /*!< Bit mask of CH30 field. */ -#define PPI_CHENCLR_CH30_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENCLR_CH30_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENCLR_CH30_Clear (1UL) /*!< Disable channel on write. */ - -/* Bit 29 : Disable PPI channel 29. */ -#define PPI_CHENCLR_CH29_Pos (29UL) /*!< Position of CH29 field. */ -#define PPI_CHENCLR_CH29_Msk (0x1UL << PPI_CHENCLR_CH29_Pos) /*!< Bit mask of CH29 field. */ -#define PPI_CHENCLR_CH29_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENCLR_CH29_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENCLR_CH29_Clear (1UL) /*!< Disable channel on write. */ - -/* Bit 28 : Disable PPI channel 28. */ -#define PPI_CHENCLR_CH28_Pos (28UL) /*!< Position of CH28 field. */ -#define PPI_CHENCLR_CH28_Msk (0x1UL << PPI_CHENCLR_CH28_Pos) /*!< Bit mask of CH28 field. */ -#define PPI_CHENCLR_CH28_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENCLR_CH28_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENCLR_CH28_Clear (1UL) /*!< Disable channel on write. */ - -/* Bit 27 : Disable PPI channel 27. */ -#define PPI_CHENCLR_CH27_Pos (27UL) /*!< Position of CH27 field. */ -#define PPI_CHENCLR_CH27_Msk (0x1UL << PPI_CHENCLR_CH27_Pos) /*!< Bit mask of CH27 field. */ -#define PPI_CHENCLR_CH27_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENCLR_CH27_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENCLR_CH27_Clear (1UL) /*!< Disable channel on write. */ - -/* Bit 26 : Disable PPI channel 26. */ -#define PPI_CHENCLR_CH26_Pos (26UL) /*!< Position of CH26 field. */ -#define PPI_CHENCLR_CH26_Msk (0x1UL << PPI_CHENCLR_CH26_Pos) /*!< Bit mask of CH26 field. */ -#define PPI_CHENCLR_CH26_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENCLR_CH26_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENCLR_CH26_Clear (1UL) /*!< Disable channel on write. */ - -/* Bit 25 : Disable PPI channel 25. */ -#define PPI_CHENCLR_CH25_Pos (25UL) /*!< Position of CH25 field. */ -#define PPI_CHENCLR_CH25_Msk (0x1UL << PPI_CHENCLR_CH25_Pos) /*!< Bit mask of CH25 field. */ -#define PPI_CHENCLR_CH25_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENCLR_CH25_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENCLR_CH25_Clear (1UL) /*!< Disable channel on write. */ - -/* Bit 24 : Disable PPI channel 24. */ -#define PPI_CHENCLR_CH24_Pos (24UL) /*!< Position of CH24 field. */ -#define PPI_CHENCLR_CH24_Msk (0x1UL << PPI_CHENCLR_CH24_Pos) /*!< Bit mask of CH24 field. */ -#define PPI_CHENCLR_CH24_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENCLR_CH24_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENCLR_CH24_Clear (1UL) /*!< Disable channel on write. */ - -/* Bit 23 : Disable PPI channel 23. */ -#define PPI_CHENCLR_CH23_Pos (23UL) /*!< Position of CH23 field. */ -#define PPI_CHENCLR_CH23_Msk (0x1UL << PPI_CHENCLR_CH23_Pos) /*!< Bit mask of CH23 field. */ -#define PPI_CHENCLR_CH23_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENCLR_CH23_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENCLR_CH23_Clear (1UL) /*!< Disable channel on write. */ - -/* Bit 22 : Disable PPI channel 22. */ -#define PPI_CHENCLR_CH22_Pos (22UL) /*!< Position of CH22 field. */ -#define PPI_CHENCLR_CH22_Msk (0x1UL << PPI_CHENCLR_CH22_Pos) /*!< Bit mask of CH22 field. */ -#define PPI_CHENCLR_CH22_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENCLR_CH22_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENCLR_CH22_Clear (1UL) /*!< Disable channel on write. */ - -/* Bit 21 : Disable PPI channel 21. */ -#define PPI_CHENCLR_CH21_Pos (21UL) /*!< Position of CH21 field. */ -#define PPI_CHENCLR_CH21_Msk (0x1UL << PPI_CHENCLR_CH21_Pos) /*!< Bit mask of CH21 field. */ -#define PPI_CHENCLR_CH21_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENCLR_CH21_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENCLR_CH21_Clear (1UL) /*!< Disable channel on write. */ - -/* Bit 20 : Disable PPI channel 20. */ -#define PPI_CHENCLR_CH20_Pos (20UL) /*!< Position of CH20 field. */ -#define PPI_CHENCLR_CH20_Msk (0x1UL << PPI_CHENCLR_CH20_Pos) /*!< Bit mask of CH20 field. */ -#define PPI_CHENCLR_CH20_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENCLR_CH20_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENCLR_CH20_Clear (1UL) /*!< Disable channel on write. */ - -/* Bit 15 : Disable PPI channel 15. */ -#define PPI_CHENCLR_CH15_Pos (15UL) /*!< Position of CH15 field. */ -#define PPI_CHENCLR_CH15_Msk (0x1UL << PPI_CHENCLR_CH15_Pos) /*!< Bit mask of CH15 field. */ -#define PPI_CHENCLR_CH15_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENCLR_CH15_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENCLR_CH15_Clear (1UL) /*!< Disable channel on write. */ - -/* Bit 14 : Disable PPI channel 14. */ -#define PPI_CHENCLR_CH14_Pos (14UL) /*!< Position of CH14 field. */ -#define PPI_CHENCLR_CH14_Msk (0x1UL << PPI_CHENCLR_CH14_Pos) /*!< Bit mask of CH14 field. */ -#define PPI_CHENCLR_CH14_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENCLR_CH14_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENCLR_CH14_Clear (1UL) /*!< Disable channel on write. */ - -/* Bit 13 : Disable PPI channel 13. */ -#define PPI_CHENCLR_CH13_Pos (13UL) /*!< Position of CH13 field. */ -#define PPI_CHENCLR_CH13_Msk (0x1UL << PPI_CHENCLR_CH13_Pos) /*!< Bit mask of CH13 field. */ -#define PPI_CHENCLR_CH13_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENCLR_CH13_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENCLR_CH13_Clear (1UL) /*!< Disable channel on write. */ - -/* Bit 12 : Disable PPI channel 12. */ -#define PPI_CHENCLR_CH12_Pos (12UL) /*!< Position of CH12 field. */ -#define PPI_CHENCLR_CH12_Msk (0x1UL << PPI_CHENCLR_CH12_Pos) /*!< Bit mask of CH12 field. */ -#define PPI_CHENCLR_CH12_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENCLR_CH12_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENCLR_CH12_Clear (1UL) /*!< Disable channel on write. */ - -/* Bit 11 : Disable PPI channel 11. */ -#define PPI_CHENCLR_CH11_Pos (11UL) /*!< Position of CH11 field. */ -#define PPI_CHENCLR_CH11_Msk (0x1UL << PPI_CHENCLR_CH11_Pos) /*!< Bit mask of CH11 field. */ -#define PPI_CHENCLR_CH11_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENCLR_CH11_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENCLR_CH11_Clear (1UL) /*!< Disable channel on write. */ - -/* Bit 10 : Disable PPI channel 10. */ -#define PPI_CHENCLR_CH10_Pos (10UL) /*!< Position of CH10 field. */ -#define PPI_CHENCLR_CH10_Msk (0x1UL << PPI_CHENCLR_CH10_Pos) /*!< Bit mask of CH10 field. */ -#define PPI_CHENCLR_CH10_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENCLR_CH10_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENCLR_CH10_Clear (1UL) /*!< Disable channel on write. */ - -/* Bit 9 : Disable PPI channel 9. */ -#define PPI_CHENCLR_CH9_Pos (9UL) /*!< Position of CH9 field. */ -#define PPI_CHENCLR_CH9_Msk (0x1UL << PPI_CHENCLR_CH9_Pos) /*!< Bit mask of CH9 field. */ -#define PPI_CHENCLR_CH9_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENCLR_CH9_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENCLR_CH9_Clear (1UL) /*!< Disable channel on write. */ - -/* Bit 8 : Disable PPI channel 8. */ -#define PPI_CHENCLR_CH8_Pos (8UL) /*!< Position of CH8 field. */ -#define PPI_CHENCLR_CH8_Msk (0x1UL << PPI_CHENCLR_CH8_Pos) /*!< Bit mask of CH8 field. */ -#define PPI_CHENCLR_CH8_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENCLR_CH8_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENCLR_CH8_Clear (1UL) /*!< Disable channel on write. */ - -/* Bit 7 : Disable PPI channel 7. */ -#define PPI_CHENCLR_CH7_Pos (7UL) /*!< Position of CH7 field. */ -#define PPI_CHENCLR_CH7_Msk (0x1UL << PPI_CHENCLR_CH7_Pos) /*!< Bit mask of CH7 field. */ -#define PPI_CHENCLR_CH7_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENCLR_CH7_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENCLR_CH7_Clear (1UL) /*!< Disable channel on write. */ - -/* Bit 6 : Disable PPI channel 6. */ -#define PPI_CHENCLR_CH6_Pos (6UL) /*!< Position of CH6 field. */ -#define PPI_CHENCLR_CH6_Msk (0x1UL << PPI_CHENCLR_CH6_Pos) /*!< Bit mask of CH6 field. */ -#define PPI_CHENCLR_CH6_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENCLR_CH6_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENCLR_CH6_Clear (1UL) /*!< Disable channel on write. */ - -/* Bit 5 : Disable PPI channel 5. */ -#define PPI_CHENCLR_CH5_Pos (5UL) /*!< Position of CH5 field. */ -#define PPI_CHENCLR_CH5_Msk (0x1UL << PPI_CHENCLR_CH5_Pos) /*!< Bit mask of CH5 field. */ -#define PPI_CHENCLR_CH5_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENCLR_CH5_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENCLR_CH5_Clear (1UL) /*!< Disable channel on write. */ - -/* Bit 4 : Disable PPI channel 4. */ -#define PPI_CHENCLR_CH4_Pos (4UL) /*!< Position of CH4 field. */ -#define PPI_CHENCLR_CH4_Msk (0x1UL << PPI_CHENCLR_CH4_Pos) /*!< Bit mask of CH4 field. */ -#define PPI_CHENCLR_CH4_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENCLR_CH4_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENCLR_CH4_Clear (1UL) /*!< Disable channel on write. */ - -/* Bit 3 : Disable PPI channel 3. */ -#define PPI_CHENCLR_CH3_Pos (3UL) /*!< Position of CH3 field. */ -#define PPI_CHENCLR_CH3_Msk (0x1UL << PPI_CHENCLR_CH3_Pos) /*!< Bit mask of CH3 field. */ -#define PPI_CHENCLR_CH3_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENCLR_CH3_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENCLR_CH3_Clear (1UL) /*!< Disable channel on write. */ - -/* Bit 2 : Disable PPI channel 2. */ -#define PPI_CHENCLR_CH2_Pos (2UL) /*!< Position of CH2 field. */ -#define PPI_CHENCLR_CH2_Msk (0x1UL << PPI_CHENCLR_CH2_Pos) /*!< Bit mask of CH2 field. */ -#define PPI_CHENCLR_CH2_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENCLR_CH2_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENCLR_CH2_Clear (1UL) /*!< Disable channel on write. */ - -/* Bit 1 : Disable PPI channel 1. */ -#define PPI_CHENCLR_CH1_Pos (1UL) /*!< Position of CH1 field. */ -#define PPI_CHENCLR_CH1_Msk (0x1UL << PPI_CHENCLR_CH1_Pos) /*!< Bit mask of CH1 field. */ -#define PPI_CHENCLR_CH1_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENCLR_CH1_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENCLR_CH1_Clear (1UL) /*!< Disable channel on write. */ - -/* Bit 0 : Disable PPI channel 0. */ -#define PPI_CHENCLR_CH0_Pos (0UL) /*!< Position of CH0 field. */ -#define PPI_CHENCLR_CH0_Msk (0x1UL << PPI_CHENCLR_CH0_Pos) /*!< Bit mask of CH0 field. */ -#define PPI_CHENCLR_CH0_Disabled (0UL) /*!< Channel disabled. */ -#define PPI_CHENCLR_CH0_Enabled (1UL) /*!< Channel enabled. */ -#define PPI_CHENCLR_CH0_Clear (1UL) /*!< Disable channel on write. */ - -/* Register: PPI_CHG */ -/* Description: Channel group configuration. */ - -/* Bit 31 : Include CH31 in channel group. */ -#define PPI_CHG_CH31_Pos (31UL) /*!< Position of CH31 field. */ -#define PPI_CHG_CH31_Msk (0x1UL << PPI_CHG_CH31_Pos) /*!< Bit mask of CH31 field. */ -#define PPI_CHG_CH31_Excluded (0UL) /*!< Channel excluded. */ -#define PPI_CHG_CH31_Included (1UL) /*!< Channel included. */ - -/* Bit 30 : Include CH30 in channel group. */ -#define PPI_CHG_CH30_Pos (30UL) /*!< Position of CH30 field. */ -#define PPI_CHG_CH30_Msk (0x1UL << PPI_CHG_CH30_Pos) /*!< Bit mask of CH30 field. */ -#define PPI_CHG_CH30_Excluded (0UL) /*!< Channel excluded. */ -#define PPI_CHG_CH30_Included (1UL) /*!< Channel included. */ - -/* Bit 29 : Include CH29 in channel group. */ -#define PPI_CHG_CH29_Pos (29UL) /*!< Position of CH29 field. */ -#define PPI_CHG_CH29_Msk (0x1UL << PPI_CHG_CH29_Pos) /*!< Bit mask of CH29 field. */ -#define PPI_CHG_CH29_Excluded (0UL) /*!< Channel excluded. */ -#define PPI_CHG_CH29_Included (1UL) /*!< Channel included. */ - -/* Bit 28 : Include CH28 in channel group. */ -#define PPI_CHG_CH28_Pos (28UL) /*!< Position of CH28 field. */ -#define PPI_CHG_CH28_Msk (0x1UL << PPI_CHG_CH28_Pos) /*!< Bit mask of CH28 field. */ -#define PPI_CHG_CH28_Excluded (0UL) /*!< Channel excluded. */ -#define PPI_CHG_CH28_Included (1UL) /*!< Channel included. */ - -/* Bit 27 : Include CH27 in channel group. */ -#define PPI_CHG_CH27_Pos (27UL) /*!< Position of CH27 field. */ -#define PPI_CHG_CH27_Msk (0x1UL << PPI_CHG_CH27_Pos) /*!< Bit mask of CH27 field. */ -#define PPI_CHG_CH27_Excluded (0UL) /*!< Channel excluded. */ -#define PPI_CHG_CH27_Included (1UL) /*!< Channel included. */ - -/* Bit 26 : Include CH26 in channel group. */ -#define PPI_CHG_CH26_Pos (26UL) /*!< Position of CH26 field. */ -#define PPI_CHG_CH26_Msk (0x1UL << PPI_CHG_CH26_Pos) /*!< Bit mask of CH26 field. */ -#define PPI_CHG_CH26_Excluded (0UL) /*!< Channel excluded. */ -#define PPI_CHG_CH26_Included (1UL) /*!< Channel included. */ - -/* Bit 25 : Include CH25 in channel group. */ -#define PPI_CHG_CH25_Pos (25UL) /*!< Position of CH25 field. */ -#define PPI_CHG_CH25_Msk (0x1UL << PPI_CHG_CH25_Pos) /*!< Bit mask of CH25 field. */ -#define PPI_CHG_CH25_Excluded (0UL) /*!< Channel excluded. */ -#define PPI_CHG_CH25_Included (1UL) /*!< Channel included. */ - -/* Bit 24 : Include CH24 in channel group. */ -#define PPI_CHG_CH24_Pos (24UL) /*!< Position of CH24 field. */ -#define PPI_CHG_CH24_Msk (0x1UL << PPI_CHG_CH24_Pos) /*!< Bit mask of CH24 field. */ -#define PPI_CHG_CH24_Excluded (0UL) /*!< Channel excluded. */ -#define PPI_CHG_CH24_Included (1UL) /*!< Channel included. */ - -/* Bit 23 : Include CH23 in channel group. */ -#define PPI_CHG_CH23_Pos (23UL) /*!< Position of CH23 field. */ -#define PPI_CHG_CH23_Msk (0x1UL << PPI_CHG_CH23_Pos) /*!< Bit mask of CH23 field. */ -#define PPI_CHG_CH23_Excluded (0UL) /*!< Channel excluded. */ -#define PPI_CHG_CH23_Included (1UL) /*!< Channel included. */ - -/* Bit 22 : Include CH22 in channel group. */ -#define PPI_CHG_CH22_Pos (22UL) /*!< Position of CH22 field. */ -#define PPI_CHG_CH22_Msk (0x1UL << PPI_CHG_CH22_Pos) /*!< Bit mask of CH22 field. */ -#define PPI_CHG_CH22_Excluded (0UL) /*!< Channel excluded. */ -#define PPI_CHG_CH22_Included (1UL) /*!< Channel included. */ - -/* Bit 21 : Include CH21 in channel group. */ -#define PPI_CHG_CH21_Pos (21UL) /*!< Position of CH21 field. */ -#define PPI_CHG_CH21_Msk (0x1UL << PPI_CHG_CH21_Pos) /*!< Bit mask of CH21 field. */ -#define PPI_CHG_CH21_Excluded (0UL) /*!< Channel excluded. */ -#define PPI_CHG_CH21_Included (1UL) /*!< Channel included. */ - -/* Bit 20 : Include CH20 in channel group. */ -#define PPI_CHG_CH20_Pos (20UL) /*!< Position of CH20 field. */ -#define PPI_CHG_CH20_Msk (0x1UL << PPI_CHG_CH20_Pos) /*!< Bit mask of CH20 field. */ -#define PPI_CHG_CH20_Excluded (0UL) /*!< Channel excluded. */ -#define PPI_CHG_CH20_Included (1UL) /*!< Channel included. */ - -/* Bit 15 : Include CH15 in channel group. */ -#define PPI_CHG_CH15_Pos (15UL) /*!< Position of CH15 field. */ -#define PPI_CHG_CH15_Msk (0x1UL << PPI_CHG_CH15_Pos) /*!< Bit mask of CH15 field. */ -#define PPI_CHG_CH15_Excluded (0UL) /*!< Channel excluded. */ -#define PPI_CHG_CH15_Included (1UL) /*!< Channel included. */ - -/* Bit 14 : Include CH14 in channel group. */ -#define PPI_CHG_CH14_Pos (14UL) /*!< Position of CH14 field. */ -#define PPI_CHG_CH14_Msk (0x1UL << PPI_CHG_CH14_Pos) /*!< Bit mask of CH14 field. */ -#define PPI_CHG_CH14_Excluded (0UL) /*!< Channel excluded. */ -#define PPI_CHG_CH14_Included (1UL) /*!< Channel included. */ - -/* Bit 13 : Include CH13 in channel group. */ -#define PPI_CHG_CH13_Pos (13UL) /*!< Position of CH13 field. */ -#define PPI_CHG_CH13_Msk (0x1UL << PPI_CHG_CH13_Pos) /*!< Bit mask of CH13 field. */ -#define PPI_CHG_CH13_Excluded (0UL) /*!< Channel excluded. */ -#define PPI_CHG_CH13_Included (1UL) /*!< Channel included. */ - -/* Bit 12 : Include CH12 in channel group. */ -#define PPI_CHG_CH12_Pos (12UL) /*!< Position of CH12 field. */ -#define PPI_CHG_CH12_Msk (0x1UL << PPI_CHG_CH12_Pos) /*!< Bit mask of CH12 field. */ -#define PPI_CHG_CH12_Excluded (0UL) /*!< Channel excluded. */ -#define PPI_CHG_CH12_Included (1UL) /*!< Channel included. */ - -/* Bit 11 : Include CH11 in channel group. */ -#define PPI_CHG_CH11_Pos (11UL) /*!< Position of CH11 field. */ -#define PPI_CHG_CH11_Msk (0x1UL << PPI_CHG_CH11_Pos) /*!< Bit mask of CH11 field. */ -#define PPI_CHG_CH11_Excluded (0UL) /*!< Channel excluded. */ -#define PPI_CHG_CH11_Included (1UL) /*!< Channel included. */ - -/* Bit 10 : Include CH10 in channel group. */ -#define PPI_CHG_CH10_Pos (10UL) /*!< Position of CH10 field. */ -#define PPI_CHG_CH10_Msk (0x1UL << PPI_CHG_CH10_Pos) /*!< Bit mask of CH10 field. */ -#define PPI_CHG_CH10_Excluded (0UL) /*!< Channel excluded. */ -#define PPI_CHG_CH10_Included (1UL) /*!< Channel included. */ - -/* Bit 9 : Include CH9 in channel group. */ -#define PPI_CHG_CH9_Pos (9UL) /*!< Position of CH9 field. */ -#define PPI_CHG_CH9_Msk (0x1UL << PPI_CHG_CH9_Pos) /*!< Bit mask of CH9 field. */ -#define PPI_CHG_CH9_Excluded (0UL) /*!< Channel excluded. */ -#define PPI_CHG_CH9_Included (1UL) /*!< Channel included. */ - -/* Bit 8 : Include CH8 in channel group. */ -#define PPI_CHG_CH8_Pos (8UL) /*!< Position of CH8 field. */ -#define PPI_CHG_CH8_Msk (0x1UL << PPI_CHG_CH8_Pos) /*!< Bit mask of CH8 field. */ -#define PPI_CHG_CH8_Excluded (0UL) /*!< Channel excluded. */ -#define PPI_CHG_CH8_Included (1UL) /*!< Channel included. */ - -/* Bit 7 : Include CH7 in channel group. */ -#define PPI_CHG_CH7_Pos (7UL) /*!< Position of CH7 field. */ -#define PPI_CHG_CH7_Msk (0x1UL << PPI_CHG_CH7_Pos) /*!< Bit mask of CH7 field. */ -#define PPI_CHG_CH7_Excluded (0UL) /*!< Channel excluded. */ -#define PPI_CHG_CH7_Included (1UL) /*!< Channel included. */ - -/* Bit 6 : Include CH6 in channel group. */ -#define PPI_CHG_CH6_Pos (6UL) /*!< Position of CH6 field. */ -#define PPI_CHG_CH6_Msk (0x1UL << PPI_CHG_CH6_Pos) /*!< Bit mask of CH6 field. */ -#define PPI_CHG_CH6_Excluded (0UL) /*!< Channel excluded. */ -#define PPI_CHG_CH6_Included (1UL) /*!< Channel included. */ - -/* Bit 5 : Include CH5 in channel group. */ -#define PPI_CHG_CH5_Pos (5UL) /*!< Position of CH5 field. */ -#define PPI_CHG_CH5_Msk (0x1UL << PPI_CHG_CH5_Pos) /*!< Bit mask of CH5 field. */ -#define PPI_CHG_CH5_Excluded (0UL) /*!< Channel excluded. */ -#define PPI_CHG_CH5_Included (1UL) /*!< Channel included. */ - -/* Bit 4 : Include CH4 in channel group. */ -#define PPI_CHG_CH4_Pos (4UL) /*!< Position of CH4 field. */ -#define PPI_CHG_CH4_Msk (0x1UL << PPI_CHG_CH4_Pos) /*!< Bit mask of CH4 field. */ -#define PPI_CHG_CH4_Excluded (0UL) /*!< Channel excluded. */ -#define PPI_CHG_CH4_Included (1UL) /*!< Channel included. */ - -/* Bit 3 : Include CH3 in channel group. */ -#define PPI_CHG_CH3_Pos (3UL) /*!< Position of CH3 field. */ -#define PPI_CHG_CH3_Msk (0x1UL << PPI_CHG_CH3_Pos) /*!< Bit mask of CH3 field. */ -#define PPI_CHG_CH3_Excluded (0UL) /*!< Channel excluded. */ -#define PPI_CHG_CH3_Included (1UL) /*!< Channel included. */ - -/* Bit 2 : Include CH2 in channel group. */ -#define PPI_CHG_CH2_Pos (2UL) /*!< Position of CH2 field. */ -#define PPI_CHG_CH2_Msk (0x1UL << PPI_CHG_CH2_Pos) /*!< Bit mask of CH2 field. */ -#define PPI_CHG_CH2_Excluded (0UL) /*!< Channel excluded. */ -#define PPI_CHG_CH2_Included (1UL) /*!< Channel included. */ - -/* Bit 1 : Include CH1 in channel group. */ -#define PPI_CHG_CH1_Pos (1UL) /*!< Position of CH1 field. */ -#define PPI_CHG_CH1_Msk (0x1UL << PPI_CHG_CH1_Pos) /*!< Bit mask of CH1 field. */ -#define PPI_CHG_CH1_Excluded (0UL) /*!< Channel excluded. */ -#define PPI_CHG_CH1_Included (1UL) /*!< Channel included. */ - -/* Bit 0 : Include CH0 in channel group. */ -#define PPI_CHG_CH0_Pos (0UL) /*!< Position of CH0 field. */ -#define PPI_CHG_CH0_Msk (0x1UL << PPI_CHG_CH0_Pos) /*!< Bit mask of CH0 field. */ -#define PPI_CHG_CH0_Excluded (0UL) /*!< Channel excluded. */ -#define PPI_CHG_CH0_Included (1UL) /*!< Channel included. */ - - -/* Peripheral: PU */ -/* Description: Patch unit. */ - -/* Register: PU_PATCHADDR */ -/* Description: Relative address of patch instructions. */ - -/* Bits 24..0 : Relative address of patch instructions. */ -#define PU_PATCHADDR_PATCHADDR_Pos (0UL) /*!< Position of PATCHADDR field. */ -#define PU_PATCHADDR_PATCHADDR_Msk (0x1FFFFFFUL << PU_PATCHADDR_PATCHADDR_Pos) /*!< Bit mask of PATCHADDR field. */ - -/* Register: PU_PATCHEN */ -/* Description: Patch enable register. */ - -/* Bit 7 : Patch 7 enabled. */ -#define PU_PATCHEN_PATCH7_Pos (7UL) /*!< Position of PATCH7 field. */ -#define PU_PATCHEN_PATCH7_Msk (0x1UL << PU_PATCHEN_PATCH7_Pos) /*!< Bit mask of PATCH7 field. */ -#define PU_PATCHEN_PATCH7_Disabled (0UL) /*!< Patch disabled. */ -#define PU_PATCHEN_PATCH7_Enabled (1UL) /*!< Patch enabled. */ - -/* Bit 6 : Patch 6 enabled. */ -#define PU_PATCHEN_PATCH6_Pos (6UL) /*!< Position of PATCH6 field. */ -#define PU_PATCHEN_PATCH6_Msk (0x1UL << PU_PATCHEN_PATCH6_Pos) /*!< Bit mask of PATCH6 field. */ -#define PU_PATCHEN_PATCH6_Disabled (0UL) /*!< Patch disabled. */ -#define PU_PATCHEN_PATCH6_Enabled (1UL) /*!< Patch enabled. */ - -/* Bit 5 : Patch 5 enabled. */ -#define PU_PATCHEN_PATCH5_Pos (5UL) /*!< Position of PATCH5 field. */ -#define PU_PATCHEN_PATCH5_Msk (0x1UL << PU_PATCHEN_PATCH5_Pos) /*!< Bit mask of PATCH5 field. */ -#define PU_PATCHEN_PATCH5_Disabled (0UL) /*!< Patch disabled. */ -#define PU_PATCHEN_PATCH5_Enabled (1UL) /*!< Patch enabled. */ - -/* Bit 4 : Patch 4 enabled. */ -#define PU_PATCHEN_PATCH4_Pos (4UL) /*!< Position of PATCH4 field. */ -#define PU_PATCHEN_PATCH4_Msk (0x1UL << PU_PATCHEN_PATCH4_Pos) /*!< Bit mask of PATCH4 field. */ -#define PU_PATCHEN_PATCH4_Disabled (0UL) /*!< Patch disabled. */ -#define PU_PATCHEN_PATCH4_Enabled (1UL) /*!< Patch enabled. */ - -/* Bit 3 : Patch 3 enabled. */ -#define PU_PATCHEN_PATCH3_Pos (3UL) /*!< Position of PATCH3 field. */ -#define PU_PATCHEN_PATCH3_Msk (0x1UL << PU_PATCHEN_PATCH3_Pos) /*!< Bit mask of PATCH3 field. */ -#define PU_PATCHEN_PATCH3_Disabled (0UL) /*!< Patch disabled. */ -#define PU_PATCHEN_PATCH3_Enabled (1UL) /*!< Patch enabled. */ - -/* Bit 2 : Patch 2 enabled. */ -#define PU_PATCHEN_PATCH2_Pos (2UL) /*!< Position of PATCH2 field. */ -#define PU_PATCHEN_PATCH2_Msk (0x1UL << PU_PATCHEN_PATCH2_Pos) /*!< Bit mask of PATCH2 field. */ -#define PU_PATCHEN_PATCH2_Disabled (0UL) /*!< Patch disabled. */ -#define PU_PATCHEN_PATCH2_Enabled (1UL) /*!< Patch enabled. */ - -/* Bit 1 : Patch 1 enabled. */ -#define PU_PATCHEN_PATCH1_Pos (1UL) /*!< Position of PATCH1 field. */ -#define PU_PATCHEN_PATCH1_Msk (0x1UL << PU_PATCHEN_PATCH1_Pos) /*!< Bit mask of PATCH1 field. */ -#define PU_PATCHEN_PATCH1_Disabled (0UL) /*!< Patch disabled. */ -#define PU_PATCHEN_PATCH1_Enabled (1UL) /*!< Patch enabled. */ - -/* Bit 0 : Patch 0 enabled. */ -#define PU_PATCHEN_PATCH0_Pos (0UL) /*!< Position of PATCH0 field. */ -#define PU_PATCHEN_PATCH0_Msk (0x1UL << PU_PATCHEN_PATCH0_Pos) /*!< Bit mask of PATCH0 field. */ -#define PU_PATCHEN_PATCH0_Disabled (0UL) /*!< Patch disabled. */ -#define PU_PATCHEN_PATCH0_Enabled (1UL) /*!< Patch enabled. */ - -/* Register: PU_PATCHENSET */ -/* Description: Patch enable register. */ - -/* Bit 7 : Patch 7 enabled. */ -#define PU_PATCHENSET_PATCH7_Pos (7UL) /*!< Position of PATCH7 field. */ -#define PU_PATCHENSET_PATCH7_Msk (0x1UL << PU_PATCHENSET_PATCH7_Pos) /*!< Bit mask of PATCH7 field. */ -#define PU_PATCHENSET_PATCH7_Disabled (0UL) /*!< Patch disabled. */ -#define PU_PATCHENSET_PATCH7_Enabled (1UL) /*!< Patch enabled. */ -#define PU_PATCHENSET_PATCH7_Set (1UL) /*!< Enable patch on write. */ - -/* Bit 6 : Patch 6 enabled. */ -#define PU_PATCHENSET_PATCH6_Pos (6UL) /*!< Position of PATCH6 field. */ -#define PU_PATCHENSET_PATCH6_Msk (0x1UL << PU_PATCHENSET_PATCH6_Pos) /*!< Bit mask of PATCH6 field. */ -#define PU_PATCHENSET_PATCH6_Disabled (0UL) /*!< Patch disabled. */ -#define PU_PATCHENSET_PATCH6_Enabled (1UL) /*!< Patch enabled. */ -#define PU_PATCHENSET_PATCH6_Set (1UL) /*!< Enable patch on write. */ - -/* Bit 5 : Patch 5 enabled. */ -#define PU_PATCHENSET_PATCH5_Pos (5UL) /*!< Position of PATCH5 field. */ -#define PU_PATCHENSET_PATCH5_Msk (0x1UL << PU_PATCHENSET_PATCH5_Pos) /*!< Bit mask of PATCH5 field. */ -#define PU_PATCHENSET_PATCH5_Disabled (0UL) /*!< Patch disabled. */ -#define PU_PATCHENSET_PATCH5_Enabled (1UL) /*!< Patch enabled. */ -#define PU_PATCHENSET_PATCH5_Set (1UL) /*!< Enable patch on write. */ - -/* Bit 4 : Patch 4 enabled. */ -#define PU_PATCHENSET_PATCH4_Pos (4UL) /*!< Position of PATCH4 field. */ -#define PU_PATCHENSET_PATCH4_Msk (0x1UL << PU_PATCHENSET_PATCH4_Pos) /*!< Bit mask of PATCH4 field. */ -#define PU_PATCHENSET_PATCH4_Disabled (0UL) /*!< Patch disabled. */ -#define PU_PATCHENSET_PATCH4_Enabled (1UL) /*!< Patch enabled. */ -#define PU_PATCHENSET_PATCH4_Set (1UL) /*!< Enable patch on write. */ - -/* Bit 3 : Patch 3 enabled. */ -#define PU_PATCHENSET_PATCH3_Pos (3UL) /*!< Position of PATCH3 field. */ -#define PU_PATCHENSET_PATCH3_Msk (0x1UL << PU_PATCHENSET_PATCH3_Pos) /*!< Bit mask of PATCH3 field. */ -#define PU_PATCHENSET_PATCH3_Disabled (0UL) /*!< Patch disabled. */ -#define PU_PATCHENSET_PATCH3_Enabled (1UL) /*!< Patch enabled. */ -#define PU_PATCHENSET_PATCH3_Set (1UL) /*!< Enable patch on write. */ - -/* Bit 2 : Patch 2 enabled. */ -#define PU_PATCHENSET_PATCH2_Pos (2UL) /*!< Position of PATCH2 field. */ -#define PU_PATCHENSET_PATCH2_Msk (0x1UL << PU_PATCHENSET_PATCH2_Pos) /*!< Bit mask of PATCH2 field. */ -#define PU_PATCHENSET_PATCH2_Disabled (0UL) /*!< Patch disabled. */ -#define PU_PATCHENSET_PATCH2_Enabled (1UL) /*!< Patch enabled. */ -#define PU_PATCHENSET_PATCH2_Set (1UL) /*!< Enable patch on write. */ - -/* Bit 1 : Patch 1 enabled. */ -#define PU_PATCHENSET_PATCH1_Pos (1UL) /*!< Position of PATCH1 field. */ -#define PU_PATCHENSET_PATCH1_Msk (0x1UL << PU_PATCHENSET_PATCH1_Pos) /*!< Bit mask of PATCH1 field. */ -#define PU_PATCHENSET_PATCH1_Disabled (0UL) /*!< Patch disabled. */ -#define PU_PATCHENSET_PATCH1_Enabled (1UL) /*!< Patch enabled. */ -#define PU_PATCHENSET_PATCH1_Set (1UL) /*!< Enable patch on write. */ - -/* Bit 0 : Patch 0 enabled. */ -#define PU_PATCHENSET_PATCH0_Pos (0UL) /*!< Position of PATCH0 field. */ -#define PU_PATCHENSET_PATCH0_Msk (0x1UL << PU_PATCHENSET_PATCH0_Pos) /*!< Bit mask of PATCH0 field. */ -#define PU_PATCHENSET_PATCH0_Disabled (0UL) /*!< Patch disabled. */ -#define PU_PATCHENSET_PATCH0_Enabled (1UL) /*!< Patch enabled. */ -#define PU_PATCHENSET_PATCH0_Set (1UL) /*!< Enable patch on write. */ - -/* Register: PU_PATCHENCLR */ -/* Description: Patch disable register. */ - -/* Bit 7 : Patch 7 enabled. */ -#define PU_PATCHENCLR_PATCH7_Pos (7UL) /*!< Position of PATCH7 field. */ -#define PU_PATCHENCLR_PATCH7_Msk (0x1UL << PU_PATCHENCLR_PATCH7_Pos) /*!< Bit mask of PATCH7 field. */ -#define PU_PATCHENCLR_PATCH7_Disabled (0UL) /*!< Patch disabled. */ -#define PU_PATCHENCLR_PATCH7_Enabled (1UL) /*!< Patch enabled. */ -#define PU_PATCHENCLR_PATCH7_Clear (1UL) /*!< Disable patch on write. */ - -/* Bit 6 : Patch 6 enabled. */ -#define PU_PATCHENCLR_PATCH6_Pos (6UL) /*!< Position of PATCH6 field. */ -#define PU_PATCHENCLR_PATCH6_Msk (0x1UL << PU_PATCHENCLR_PATCH6_Pos) /*!< Bit mask of PATCH6 field. */ -#define PU_PATCHENCLR_PATCH6_Disabled (0UL) /*!< Patch disabled. */ -#define PU_PATCHENCLR_PATCH6_Enabled (1UL) /*!< Patch enabled. */ -#define PU_PATCHENCLR_PATCH6_Clear (1UL) /*!< Disable patch on write. */ - -/* Bit 5 : Patch 5 enabled. */ -#define PU_PATCHENCLR_PATCH5_Pos (5UL) /*!< Position of PATCH5 field. */ -#define PU_PATCHENCLR_PATCH5_Msk (0x1UL << PU_PATCHENCLR_PATCH5_Pos) /*!< Bit mask of PATCH5 field. */ -#define PU_PATCHENCLR_PATCH5_Disabled (0UL) /*!< Patch disabled. */ -#define PU_PATCHENCLR_PATCH5_Enabled (1UL) /*!< Patch enabled. */ -#define PU_PATCHENCLR_PATCH5_Clear (1UL) /*!< Disable patch on write. */ - -/* Bit 4 : Patch 4 enabled. */ -#define PU_PATCHENCLR_PATCH4_Pos (4UL) /*!< Position of PATCH4 field. */ -#define PU_PATCHENCLR_PATCH4_Msk (0x1UL << PU_PATCHENCLR_PATCH4_Pos) /*!< Bit mask of PATCH4 field. */ -#define PU_PATCHENCLR_PATCH4_Disabled (0UL) /*!< Patch disabled. */ -#define PU_PATCHENCLR_PATCH4_Enabled (1UL) /*!< Patch enabled. */ -#define PU_PATCHENCLR_PATCH4_Clear (1UL) /*!< Disable patch on write. */ - -/* Bit 3 : Patch 3 enabled. */ -#define PU_PATCHENCLR_PATCH3_Pos (3UL) /*!< Position of PATCH3 field. */ -#define PU_PATCHENCLR_PATCH3_Msk (0x1UL << PU_PATCHENCLR_PATCH3_Pos) /*!< Bit mask of PATCH3 field. */ -#define PU_PATCHENCLR_PATCH3_Disabled (0UL) /*!< Patch disabled. */ -#define PU_PATCHENCLR_PATCH3_Enabled (1UL) /*!< Patch enabled. */ -#define PU_PATCHENCLR_PATCH3_Clear (1UL) /*!< Disable patch on write. */ - -/* Bit 2 : Patch 2 enabled. */ -#define PU_PATCHENCLR_PATCH2_Pos (2UL) /*!< Position of PATCH2 field. */ -#define PU_PATCHENCLR_PATCH2_Msk (0x1UL << PU_PATCHENCLR_PATCH2_Pos) /*!< Bit mask of PATCH2 field. */ -#define PU_PATCHENCLR_PATCH2_Disabled (0UL) /