upgrade to sdk12

This commit is contained in:
Shuanglei Tao
2024-12-17 00:45:30 +08:00
parent 3d7db302aa
commit 75b5b9105a
1934 changed files with 201917 additions and 194447 deletions

View File

@@ -1,24 +1,50 @@
/* Copyright (c) 2015 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.
*
/**
* Copyright (c) 2015 - 2017, 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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 "sdk_common.h"
#if NRF_MODULE_ENABLED(SIMPLE_TIMER)
#include "app_simple_timer.h"
#include "nrf.h"
#include "nordic_common.h"
#include "app_util_platform.h"
#include "app_error.h"
#include "nrf_timer.h"
#include "nrf_drv_timer.h"
#include <string.h>
#include <stdbool.h>
/**@brief States of simple timer state machine.
*/
@@ -35,42 +61,14 @@ static app_simple_timer_timeout_handler_t m_timeout_handler = NULL;
static void * mp_timeout_handler_context = NULL; /**< Registered time-out handler context. */
static simple_timer_states_t m_simple_timer_state = SIMPLE_TIMER_STATE_IDLE; /**< State machine state. */
#define APP_SIMPLE_TIMER_INSTANCE 1
#if (APP_SIMPLE_TIMER_INSTANCE == 0)
#if (TIMER_CONFIG_MODE(0) != TIMER_MODE_MODE_Timer)
#error "Unsupported timer mode."
#endif
#if (TIMER_CONFIG_BIT_WIDTH(0) != TIMER_BITMODE_BITMODE_16Bit)
#error "Unsupported timer bit width."
#endif
const nrf_drv_timer_t SIMPLE_TIMER = NRF_DRV_TIMER_INSTANCE(0);
#elif (APP_SIMPLE_TIMER_INSTANCE == 1)
#if (TIMER_CONFIG_MODE(1) != TIMER_MODE_MODE_Timer)
#error "Unsupported timer mode."
#endif
#if (TIMER_CONFIG_BIT_WIDTH(1) != TIMER_BITMODE_BITMODE_16Bit)
#error "Unsupported timer bit width."
#endif
const nrf_drv_timer_t SIMPLE_TIMER = NRF_DRV_TIMER_INSTANCE(1);
#elif (APP_SIMPLE_TIMER_INSTANCE == 2)
#if (TIMER_CONFIG_MODE(2) != TIMER_MODE_MODE_Timer)
#error "Unsupported timer mode."
#endif
#if (TIMER_CONFIG_BIT_WIDTH(2) != TIMER_BITMODE_BITMODE_16Bit)
#error "Unsupported timer bit width."
#endif
const nrf_drv_timer_t SIMPLE_TIMER = NRF_DRV_TIMER_INSTANCE(2);
#else
#error "Wrong timer instance id."
#endif
const nrf_drv_timer_t SIMPLE_TIMER = NRF_DRV_TIMER_INSTANCE(SIMPLE_TIMER_CONFIG_INSTANCE);
/**
* @brief Handler for timer events.
*/
static void app_simple_timer_event_handler(nrf_timer_event_t event_type, void * p_context)
{
switch(event_type)
switch (event_type)
{
case NRF_TIMER_EVENT_COMPARE0:
if (m_mode == APP_SIMPLE_TIMER_MODE_SINGLE_SHOT)
@@ -91,10 +89,13 @@ static void app_simple_timer_event_handler(nrf_timer_event_t event_type, void *
uint32_t app_simple_timer_init(void)
{
uint32_t err_code = NRF_SUCCESS;
nrf_drv_timer_config_t t_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
t_cfg.mode = NRF_TIMER_MODE_TIMER;
t_cfg.bit_width = NRF_TIMER_BIT_WIDTH_16;
t_cfg.frequency = (nrf_timer_frequency_t)SIMPLE_TIMER_CONFIG_FREQUENCY;
err_code = nrf_drv_timer_init(&SIMPLE_TIMER, &t_cfg, app_simple_timer_event_handler);
err_code = nrf_drv_timer_init(&SIMPLE_TIMER, NULL, app_simple_timer_event_handler);
if(NRF_SUCCESS == err_code)
if (NRF_SUCCESS == err_code)
{
m_simple_timer_state = SIMPLE_TIMER_STATE_INITIALIZED;
}
@@ -102,7 +103,7 @@ uint32_t app_simple_timer_init(void)
return err_code;
}
uint32_t app_simple_timer_start(app_simple_timer_mode_t mode,
uint32_t app_simple_timer_start(app_simple_timer_mode_t mode,
app_simple_timer_timeout_handler_t timeout_handler,
uint16_t timeout_ticks,
void * p_context)
@@ -110,16 +111,13 @@ uint32_t app_simple_timer_start(app_simple_timer_mode_t mode,
uint32_t err_code = NRF_SUCCESS;
nrf_timer_short_mask_t timer_short;
if (NULL == timeout_handler)
{
return NRF_ERROR_NULL;
}
VERIFY_PARAM_NOT_NULL(timeout_handler);
if (APP_SIMPLE_TIMER_MODE_REPEATED == mode)
{
timer_short = NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK;
}
else if(APP_SIMPLE_TIMER_MODE_SINGLE_SHOT == mode)
else if (APP_SIMPLE_TIMER_MODE_SINGLE_SHOT == mode)
{
timer_short = NRF_TIMER_SHORT_COMPARE0_STOP_MASK;
}
@@ -128,18 +126,18 @@ uint32_t app_simple_timer_start(app_simple_timer_mode_t mode,
return NRF_ERROR_INVALID_PARAM;
}
if(SIMPLE_TIMER_STATE_IDLE == m_simple_timer_state)
if (SIMPLE_TIMER_STATE_IDLE == m_simple_timer_state)
{
return NRF_ERROR_INVALID_STATE;
}
if(SIMPLE_TIMER_STATE_STARTED == m_simple_timer_state)
if (SIMPLE_TIMER_STATE_STARTED == m_simple_timer_state)
{
err_code = app_simple_timer_stop();
APP_ERROR_CHECK(err_code);
}
if(SIMPLE_TIMER_STATE_STOPPED == m_simple_timer_state)
if (SIMPLE_TIMER_STATE_STOPPED == m_simple_timer_state)
{
nrf_drv_timer_clear(&SIMPLE_TIMER);
}
@@ -168,7 +166,7 @@ uint32_t app_simple_timer_start(app_simple_timer_mode_t mode,
uint32_t app_simple_timer_stop(void)
{
if(SIMPLE_TIMER_STATE_STARTED == m_simple_timer_state)
if (SIMPLE_TIMER_STATE_STARTED == m_simple_timer_state)
{
nrf_drv_timer_pause(&SIMPLE_TIMER);
@@ -182,7 +180,7 @@ uint32_t app_simple_timer_uninit(void)
{
uint32_t err_code = NRF_SUCCESS;
if(SIMPLE_TIMER_STATE_IDLE != m_simple_timer_state)
if (SIMPLE_TIMER_STATE_IDLE != m_simple_timer_state)
{
nrf_drv_timer_uninit(&SIMPLE_TIMER);
m_simple_timer_state = SIMPLE_TIMER_STATE_IDLE;
@@ -190,3 +188,4 @@ uint32_t app_simple_timer_uninit(void)
return err_code;
}
#endif //NRF_MODULE_ENABLED(SIMPLE_TIMER)

View File

@@ -1,18 +1,46 @@
/* Copyright (c) 2015 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.
*
/**
* Copyright (c) 2015 - 2017, 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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 lib_driver_simple_timer Simple Timer
* @defgroup app_simple_timer Simple Timer
* @{
* @ingroup app_common
*
@@ -29,6 +57,10 @@
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**@brief Timer time-out handler type. */
typedef void (*app_simple_timer_timeout_handler_t)(void * p_context);
@@ -39,11 +71,9 @@ typedef enum
APP_SIMPLE_TIMER_MODE_REPEATED /**< The timer will restart each time it expires. */
} app_simple_timer_mode_t;
/**@brief Function for configuring and setting up the timer hardware.
/**@brief Function for configuring and setting up the timer hardware.
*
* @note Configuration parameters should be set in nrf_drv_config.h file.
* The TIMER1_CONFIG_MODE has to be set to NRF_TIMER_MODE_TIMER value.
* The TIMER1_CONFIG_BIT_WIDTH has to be set to NRF_TIMER_BIT_WIDTH_16 value.
* @note Timer frequency is configured statically.
*
* @retval NRF_SUCCESS If the operation is successful.
* @retval NRF_ERROR_INVALID_STATE If the operation fails because the timer is already initialized.
@@ -54,23 +84,23 @@ uint32_t app_simple_timer_init(void);
/**@brief Function for starting a timer.
*
* @note If this function is called for a timer that is already running, the currently running
* @note If this function is called for a timer that is already running, the currently running
* timer is stopped before starting the new one.
*
* @param[in] mode Timer mode (see @ref app_simple_timer_mode_t).
* @param[in] timeout_handler Function to be executed when the timer expires
* @param[in] timeout_handler Function to be executed when the timer expires
* (see @ref app_simple_timer_timeout_handler_t).
* @param[in] timeout_ticks Number of timer ticks to time-out event.
* @param[in] p_context General purpose pointer. Will be passed to the time-out handler
* @param[in] p_context General purpose pointer. Will be passed to the time-out handler
* when the timer expires.
*
*
* @retval NRF_SUCCESS If the operation is successful.
* @retval NRF_ERROR_INVALID_STATE If the operation fails because @ref app_simple_timer_init has not
* been called and the operation is not allowed in this state.
* @retval NRF_ERROR_NULL If the operation fails because timeout_handler is NULL.
* @retval NRF_ERROR_INVALID_PARAM If the operation fails because "mode" parameter is not valid.
*/
uint32_t app_simple_timer_start(app_simple_timer_mode_t mode,
app_simple_timer_timeout_handler_t timeout_handler,
uint16_t timeout_ticks,
@@ -93,6 +123,11 @@ uint32_t app_simple_timer_stop(void);
*/
uint32_t app_simple_timer_uninit(void);
#ifdef __cplusplus
}
#endif
#endif // TIMER_H__
/** @} */