able to build
This commit is contained in:
		@@ -1,23 +1,61 @@
 | 
			
		||||
/* 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(TIMER)
 | 
			
		||||
#define ENABLED_TIMER_COUNT (TIMER0_ENABLED+TIMER1_ENABLED+TIMER2_ENABLED+TIMER3_ENABLED+TIMER4_ENABLED)
 | 
			
		||||
#if ENABLED_TIMER_COUNT
 | 
			
		||||
#include "nrf_drv_timer.h"
 | 
			
		||||
#include "nrf_drv_common.h"
 | 
			
		||||
#include "app_util_platform.h"
 | 
			
		||||
 | 
			
		||||
#if (TIMER_COUNT == 0)
 | 
			
		||||
    #error "No TIMER instances enabled in the driver configuration file."
 | 
			
		||||
#endif
 | 
			
		||||
#define NRF_LOG_MODULE_NAME timer
 | 
			
		||||
 | 
			
		||||
#if TIMER_CONFIG_LOG_ENABLED
 | 
			
		||||
#define NRF_LOG_LEVEL       TIMER_CONFIG_LOG_LEVEL
 | 
			
		||||
#define NRF_LOG_INFO_COLOR  TIMER_CONFIG_INFO_COLOR
 | 
			
		||||
#define NRF_LOG_DEBUG_COLOR TIMER_CONFIG_DEBUG_COLOR
 | 
			
		||||
#else //TIMER_CONFIG_LOG_ENABLED
 | 
			
		||||
#define NRF_LOG_LEVEL       0
 | 
			
		||||
#endif //TIMER_CONFIG_LOG_ENABLED
 | 
			
		||||
#include "nrf_log.h"
 | 
			
		||||
NRF_LOG_MODULE_REGISTER();
 | 
			
		||||
 | 
			
		||||
/**@brief Timer control block. */
 | 
			
		||||
typedef struct
 | 
			
		||||
@@ -27,52 +65,53 @@ typedef struct
 | 
			
		||||
    nrf_drv_state_t           state;
 | 
			
		||||
} timer_control_block_t;
 | 
			
		||||
 | 
			
		||||
static timer_control_block_t m_cb[TIMER_COUNT];
 | 
			
		||||
 | 
			
		||||
static const nrf_drv_timer_config_t m_default_config[TIMER_COUNT] = {
 | 
			
		||||
#if TIMER0_ENABLED
 | 
			
		||||
    NRF_DRV_TIMER_DEFAULT_CONFIG(0),
 | 
			
		||||
#endif
 | 
			
		||||
#if TIMER1_ENABLED
 | 
			
		||||
    NRF_DRV_TIMER_DEFAULT_CONFIG(1),
 | 
			
		||||
#endif
 | 
			
		||||
#if TIMER2_ENABLED
 | 
			
		||||
    NRF_DRV_TIMER_DEFAULT_CONFIG(2),
 | 
			
		||||
#endif
 | 
			
		||||
#if TIMER3_ENABLED
 | 
			
		||||
    NRF_DRV_TIMER_DEFAULT_CONFIG(3),
 | 
			
		||||
#endif
 | 
			
		||||
#if TIMER4_ENABLED
 | 
			
		||||
    NRF_DRV_TIMER_DEFAULT_CONFIG(4),
 | 
			
		||||
#endif
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static timer_control_block_t m_cb[ENABLED_TIMER_COUNT];
 | 
			
		||||
 | 
			
		||||
ret_code_t nrf_drv_timer_init(nrf_drv_timer_t const * const p_instance,
 | 
			
		||||
                              nrf_drv_timer_config_t const * p_config,
 | 
			
		||||
                              nrf_timer_event_handler_t timer_event_handler)
 | 
			
		||||
{
 | 
			
		||||
    timer_control_block_t * p_cb = &m_cb[p_instance->instance_id];
 | 
			
		||||
 | 
			
		||||
    ASSERT(((p_instance->p_reg == NRF_TIMER0) && TIMER0_ENABLED) || (p_instance->p_reg != NRF_TIMER0));
 | 
			
		||||
    ASSERT(((p_instance->p_reg == NRF_TIMER1) && TIMER1_ENABLED) || (p_instance->p_reg != NRF_TIMER1));
 | 
			
		||||
    ASSERT(((p_instance->p_reg == NRF_TIMER2) && TIMER2_ENABLED) || (p_instance->p_reg != NRF_TIMER2));
 | 
			
		||||
#if defined (NRF_TIMER3)
 | 
			
		||||
    ASSERT(((p_instance->p_reg == NRF_TIMER3) && TIMER3_ENABLED) || (p_instance->p_reg != NRF_TIMER3));
 | 
			
		||||
#endif
 | 
			
		||||
#if defined (NRF_TIMER4)
 | 
			
		||||
    ASSERT(((p_instance->p_reg == NRF_TIMER4) && TIMER4_ENABLED) || (p_instance->p_reg != NRF_TIMER4));
 | 
			
		||||
#endif
 | 
			
		||||
#ifdef SOFTDEVICE_PRESENT
 | 
			
		||||
    ASSERT(p_instance->p_reg != NRF_TIMER0);
 | 
			
		||||
#endif
 | 
			
		||||
    ASSERT(NRF_TIMER_IS_BIT_WIDTH_VALID(p_instance->p_reg, p_config->bit_width));
 | 
			
		||||
    ASSERT(p_config);
 | 
			
		||||
 | 
			
		||||
    ret_code_t err_code;
 | 
			
		||||
 | 
			
		||||
    if (p_cb->state != NRF_DRV_STATE_UNINITIALIZED)
 | 
			
		||||
    {
 | 
			
		||||
        return NRF_ERROR_INVALID_STATE;
 | 
			
		||||
        err_code = NRF_ERROR_INVALID_STATE;
 | 
			
		||||
        NRF_LOG_WARNING("Function: %s, error code: %s.", (uint32_t)__func__, (uint32_t)NRF_LOG_ERROR_STRING_GET(err_code));
 | 
			
		||||
        return err_code;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (timer_event_handler == NULL)
 | 
			
		||||
    {
 | 
			
		||||
        return NRF_ERROR_INVALID_PARAM;
 | 
			
		||||
        err_code = NRF_ERROR_INVALID_PARAM;
 | 
			
		||||
        NRF_LOG_WARNING("Function: %s, error code: %s.", (uint32_t)__func__, (uint32_t)NRF_LOG_ERROR_STRING_GET(err_code));
 | 
			
		||||
        return err_code;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (p_config == NULL)
 | 
			
		||||
    {
 | 
			
		||||
        p_config = &m_default_config[p_instance->instance_id];
 | 
			
		||||
    }
 | 
			
		||||
    /* Warning 685: Relational operator '<=' always evaluates to 'true'"
 | 
			
		||||
     * Warning in NRF_TIMER_IS_BIT_WIDTH_VALID macro. Macro validate timers resolution.
 | 
			
		||||
     * Not necessary in nRF52 based systems. Obligatory in nRF51 based systems.
 | 
			
		||||
     */
 | 
			
		||||
 | 
			
		||||
    /*lint -save -e685 */
 | 
			
		||||
 | 
			
		||||
    ASSERT(NRF_TIMER_IS_BIT_WIDTH_VALID(p_instance->p_reg, p_config->bit_width));
 | 
			
		||||
 | 
			
		||||
    //lint -restore
 | 
			
		||||
 | 
			
		||||
    p_cb->handler = timer_event_handler;
 | 
			
		||||
    p_cb->context = p_config->p_context;
 | 
			
		||||
@@ -93,7 +132,9 @@ ret_code_t nrf_drv_timer_init(nrf_drv_timer_t const * const p_instance,
 | 
			
		||||
 | 
			
		||||
    p_cb->state = NRF_DRV_STATE_INITIALIZED;
 | 
			
		||||
 | 
			
		||||
    return NRF_SUCCESS;
 | 
			
		||||
    err_code = NRF_SUCCESS;
 | 
			
		||||
    NRF_LOG_INFO("Function: %s, error code: %s.", (uint32_t)__func__, (uint32_t)NRF_LOG_ERROR_STRING_GET(err_code));
 | 
			
		||||
    return err_code;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void nrf_drv_timer_uninit(nrf_drv_timer_t const * const p_instance)
 | 
			
		||||
@@ -105,9 +146,13 @@ void nrf_drv_timer_uninit(nrf_drv_timer_t const * const p_instance)
 | 
			
		||||
    nrf_timer_int_disable(p_instance->p_reg, DISABLE_ALL);
 | 
			
		||||
    #undef DISABLE_ALL
 | 
			
		||||
 | 
			
		||||
    nrf_drv_timer_disable(p_instance);
 | 
			
		||||
    if (m_cb[p_instance->instance_id].state == NRF_DRV_STATE_POWERED_ON)
 | 
			
		||||
    {
 | 
			
		||||
        nrf_drv_timer_disable(p_instance);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    m_cb[p_instance->instance_id].state = NRF_DRV_STATE_UNINITIALIZED;
 | 
			
		||||
    NRF_LOG_INFO("Uninitialized instance: %d.", p_instance->instance_id);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void nrf_drv_timer_enable(nrf_drv_timer_t const * const p_instance)
 | 
			
		||||
@@ -115,6 +160,7 @@ void nrf_drv_timer_enable(nrf_drv_timer_t const * const p_instance)
 | 
			
		||||
    ASSERT(m_cb[p_instance->instance_id].state == NRF_DRV_STATE_INITIALIZED);
 | 
			
		||||
    nrf_timer_task_trigger(p_instance->p_reg, NRF_TIMER_TASK_START);
 | 
			
		||||
    m_cb[p_instance->instance_id].state = NRF_DRV_STATE_POWERED_ON;
 | 
			
		||||
    NRF_LOG_INFO("Enabled instance: %d.", p_instance->instance_id);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void nrf_drv_timer_disable(nrf_drv_timer_t const * const p_instance)
 | 
			
		||||
@@ -122,18 +168,21 @@ void nrf_drv_timer_disable(nrf_drv_timer_t const * const p_instance)
 | 
			
		||||
    ASSERT(m_cb[p_instance->instance_id].state == NRF_DRV_STATE_POWERED_ON);
 | 
			
		||||
    nrf_timer_task_trigger(p_instance->p_reg, NRF_TIMER_TASK_SHUTDOWN);
 | 
			
		||||
    m_cb[p_instance->instance_id].state = NRF_DRV_STATE_INITIALIZED;
 | 
			
		||||
    NRF_LOG_INFO("Disabled instance: %d.", p_instance->instance_id);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void nrf_drv_timer_resume(nrf_drv_timer_t const * const p_instance)
 | 
			
		||||
{
 | 
			
		||||
    ASSERT(m_cb[p_instance->instance_id].state == NRF_DRV_STATE_POWERED_ON);
 | 
			
		||||
    nrf_timer_task_trigger(p_instance->p_reg, NRF_TIMER_TASK_START);
 | 
			
		||||
    NRF_LOG_INFO("Resumed instance: %d.", p_instance->instance_id);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void nrf_drv_timer_pause(nrf_drv_timer_t const * const p_instance)
 | 
			
		||||
{
 | 
			
		||||
    ASSERT(m_cb[p_instance->instance_id].state == NRF_DRV_STATE_POWERED_ON);
 | 
			
		||||
    nrf_timer_task_trigger(p_instance->p_reg, NRF_TIMER_TASK_STOP);
 | 
			
		||||
    NRF_LOG_INFO("Paused instance: %d.", p_instance->instance_id);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void nrf_drv_timer_clear(nrf_drv_timer_t const * const p_instance)
 | 
			
		||||
@@ -153,7 +202,7 @@ void nrf_drv_timer_increment(nrf_drv_timer_t const * const p_instance)
 | 
			
		||||
uint32_t nrf_drv_timer_capture(nrf_drv_timer_t const * const p_instance,
 | 
			
		||||
                               nrf_timer_cc_channel_t cc_channel)
 | 
			
		||||
{
 | 
			
		||||
    ASSERT(m_cb[p_instance->instance_id].state == NRF_DRV_STATE_POWERED_ON);
 | 
			
		||||
    ASSERT(m_cb[p_instance->instance_id].state != NRF_DRV_STATE_UNINITIALIZED);
 | 
			
		||||
    ASSERT(cc_channel < p_instance->cc_channel_count);
 | 
			
		||||
 | 
			
		||||
    nrf_timer_task_trigger(p_instance->p_reg,
 | 
			
		||||
@@ -178,6 +227,7 @@ void nrf_drv_timer_compare(nrf_drv_timer_t const * const p_instance,
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    nrf_timer_cc_write(p_instance->p_reg, cc_channel, cc_value);
 | 
			
		||||
    NRF_LOG_INFO("Timer id: %d, capture value set: %d, channel: %d.", p_instance->instance_id, cc_value, cc_channel);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void nrf_drv_timer_extended_compare(nrf_drv_timer_t const * const p_instance,
 | 
			
		||||
@@ -196,6 +246,7 @@ void nrf_drv_timer_extended_compare(nrf_drv_timer_t const * const p_instance,
 | 
			
		||||
                                cc_channel,
 | 
			
		||||
                                cc_value,
 | 
			
		||||
                                enable_int);
 | 
			
		||||
    NRF_LOG_INFO("Timer id: %d, capture value set: %d, channel: %d.", p_instance->instance_id, cc_value, cc_channel);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void nrf_drv_timer_compare_int_enable(nrf_drv_timer_t const * const p_instance,
 | 
			
		||||
@@ -234,12 +285,13 @@ static void irq_handler(NRF_TIMER_Type * p_reg,
 | 
			
		||||
            nrf_timer_int_enable_check(p_reg, int_mask))
 | 
			
		||||
        {
 | 
			
		||||
            nrf_timer_event_clear(p_reg, event);
 | 
			
		||||
            NRF_LOG_DEBUG("Compare event, channel: %d.", i);
 | 
			
		||||
            p_cb->handler(event, p_cb->context);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#if TIMER0_ENABLED
 | 
			
		||||
#if NRF_MODULE_ENABLED(TIMER0)
 | 
			
		||||
void TIMER0_IRQHandler(void)
 | 
			
		||||
{
 | 
			
		||||
    irq_handler(NRF_TIMER0, &m_cb[TIMER0_INSTANCE_INDEX],
 | 
			
		||||
@@ -247,7 +299,7 @@ void TIMER0_IRQHandler(void)
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if TIMER1_ENABLED
 | 
			
		||||
#if NRF_MODULE_ENABLED(TIMER1)
 | 
			
		||||
void TIMER1_IRQHandler(void)
 | 
			
		||||
{
 | 
			
		||||
    irq_handler(NRF_TIMER1, &m_cb[TIMER1_INSTANCE_INDEX],
 | 
			
		||||
@@ -255,7 +307,7 @@ void TIMER1_IRQHandler(void)
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if TIMER2_ENABLED
 | 
			
		||||
#if NRF_MODULE_ENABLED(TIMER2)
 | 
			
		||||
void TIMER2_IRQHandler(void)
 | 
			
		||||
{
 | 
			
		||||
    irq_handler(NRF_TIMER2, &m_cb[TIMER2_INSTANCE_INDEX],
 | 
			
		||||
@@ -263,18 +315,25 @@ void TIMER2_IRQHandler(void)
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if TIMER3_ENABLED
 | 
			
		||||
#if defined (NRF_TIMER3)
 | 
			
		||||
#if NRF_MODULE_ENABLED(TIMER3)
 | 
			
		||||
void TIMER3_IRQHandler(void)
 | 
			
		||||
{
 | 
			
		||||
    irq_handler(NRF_TIMER3, &m_cb[TIMER3_INSTANCE_INDEX],
 | 
			
		||||
        NRF_TIMER_CC_CHANNEL_COUNT(3));
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if TIMER4_ENABLED
 | 
			
		||||
#if defined (NRF_TIMER4)
 | 
			
		||||
#if NRF_MODULE_ENABLED(TIMER4)
 | 
			
		||||
void TIMER4_IRQHandler(void)
 | 
			
		||||
{
 | 
			
		||||
    irq_handler(NRF_TIMER4, &m_cb[TIMER4_INSTANCE_INDEX],
 | 
			
		||||
        NRF_TIMER_CC_CHANNEL_COUNT(4));
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#endif // ENABLED_TIMER_COUNT
 | 
			
		||||
#endif // NRF_MODULE_ENABLED(TIMER)
 | 
			
		||||
 
 | 
			
		||||
@@ -1,15 +1,42 @@
 | 
			
		||||
/* 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
 | 
			
		||||
 * @addtogroup nrf_timer Timer HAL and driver
 | 
			
		||||
 * @ingroup    nrf_drivers
 | 
			
		||||
@@ -17,7 +44,7 @@
 | 
			
		||||
 * @details    The timer HAL provides basic APIs for accessing the registers
 | 
			
		||||
 *             of the timer. The timer driver provides APIs on a higher level.
 | 
			
		||||
 *
 | 
			
		||||
 * @defgroup   lib_driver_timer Timer driver
 | 
			
		||||
 * @defgroup   nrf_drv_timer Timer driver
 | 
			
		||||
 * @{
 | 
			
		||||
 * @ingroup    nrf_timer
 | 
			
		||||
 * @brief      Multi-instance timer driver.
 | 
			
		||||
@@ -27,11 +54,15 @@
 | 
			
		||||
#define NRF_DRV_TIMER_H__
 | 
			
		||||
 | 
			
		||||
#include "nordic_common.h"
 | 
			
		||||
#include "nrf_drv_config.h"
 | 
			
		||||
#include "sdk_config.h"
 | 
			
		||||
#include "nrf_timer.h"
 | 
			
		||||
#include "sdk_errors.h"
 | 
			
		||||
#include "nrf_assert.h"
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
extern "C" {
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Timer driver instance data structure.
 | 
			
		||||
 */
 | 
			
		||||
@@ -42,6 +73,14 @@ typedef struct
 | 
			
		||||
    uint8_t          cc_channel_count; ///< Number of capture/compare channels.
 | 
			
		||||
} nrf_drv_timer_t;
 | 
			
		||||
 | 
			
		||||
#define ENABLED_TIMER_COUNT (TIMER0_ENABLED+TIMER1_ENABLED+TIMER2_ENABLED+TIMER3_ENABLED+TIMER4_ENABLED)
 | 
			
		||||
 | 
			
		||||
#define TIMER0_INSTANCE_INDEX 0
 | 
			
		||||
#define TIMER1_INSTANCE_INDEX TIMER0_INSTANCE_INDEX+TIMER0_ENABLED
 | 
			
		||||
#define TIMER2_INSTANCE_INDEX TIMER1_INSTANCE_INDEX+TIMER1_ENABLED
 | 
			
		||||
#define TIMER3_INSTANCE_INDEX TIMER2_INSTANCE_INDEX+TIMER2_ENABLED
 | 
			
		||||
#define TIMER4_INSTANCE_INDEX TIMER3_INSTANCE_INDEX+TIMER3_ENABLED
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Macro for creating a timer driver instance.
 | 
			
		||||
 */
 | 
			
		||||
@@ -64,21 +103,16 @@ typedef struct
 | 
			
		||||
    void *                p_context;          ///< Context passed to interrupt handler.
 | 
			
		||||
} nrf_drv_timer_config_t;
 | 
			
		||||
 | 
			
		||||
#define TIMER_CONFIG_FREQUENCY(id)    CONCAT_3(TIMER, id, _CONFIG_FREQUENCY)
 | 
			
		||||
#define TIMER_CONFIG_MODE(id)         CONCAT_3(TIMER, id, _CONFIG_MODE)
 | 
			
		||||
#define TIMER_CONFIG_BIT_WIDTH(id)    CONCAT_3(TIMER, id, _CONFIG_BIT_WIDTH)
 | 
			
		||||
#define TIMER_CONFIG_IRQ_PRIORITY(id) CONCAT_3(TIMER, id, _CONFIG_IRQ_PRIORITY)
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Timer driver instance default configuration.
 | 
			
		||||
 */
 | 
			
		||||
#define NRF_DRV_TIMER_DEFAULT_CONFIG(id) \
 | 
			
		||||
{                                                                            \
 | 
			
		||||
    .frequency          = TIMER_CONFIG_FREQUENCY(id),                        \
 | 
			
		||||
    .mode               = (nrf_timer_mode_t)TIMER_CONFIG_MODE(id),           \
 | 
			
		||||
    .bit_width          = (nrf_timer_bit_width_t)TIMER_CONFIG_BIT_WIDTH(id), \
 | 
			
		||||
    .interrupt_priority = TIMER_CONFIG_IRQ_PRIORITY(id),                     \
 | 
			
		||||
    .p_context          = NULL                                               \
 | 
			
		||||
#define NRF_DRV_TIMER_DEFAULT_CONFIG \
 | 
			
		||||
{                                                                               \
 | 
			
		||||
    .frequency          = (nrf_timer_frequency_t)TIMER_DEFAULT_CONFIG_FREQUENCY,\
 | 
			
		||||
    .mode               = (nrf_timer_mode_t)TIMER_DEFAULT_CONFIG_MODE,          \
 | 
			
		||||
    .bit_width          = (nrf_timer_bit_width_t)TIMER_DEFAULT_CONFIG_BIT_WIDTH,\
 | 
			
		||||
    .interrupt_priority = TIMER_DEFAULT_CONFIG_IRQ_PRIORITY,                    \
 | 
			
		||||
    .p_context          = NULL                                                  \
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@@ -86,8 +120,8 @@ typedef struct
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] event_type Timer event.
 | 
			
		||||
 * @param[in] p_context  General purpose parameter set during initialization of
 | 
			
		||||
 *                       the timer. This parameter can be used to pass 
 | 
			
		||||
 *                       additional information to the handler function, for 
 | 
			
		||||
 *                       the timer. This parameter can be used to pass
 | 
			
		||||
 *                       additional information to the handler function, for
 | 
			
		||||
 *                       example, the timer ID.
 | 
			
		||||
 */
 | 
			
		||||
typedef void (* nrf_timer_event_handler_t)(nrf_timer_event_t event_type,
 | 
			
		||||
@@ -96,9 +130,8 @@ typedef void (* nrf_timer_event_handler_t)(nrf_timer_event_t event_type,
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Function for initializing the timer.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] p_instance          Timer instance.
 | 
			
		||||
 * @param[in] p_config            Initial configuration.
 | 
			
		||||
 *                                If NULL, the default configuration is used.
 | 
			
		||||
 * @param[in] p_instance          Pointer to the driver instance structure.
 | 
			
		||||
 * @param[in] p_config            Initial configuration. Must not be NULL.
 | 
			
		||||
 * @param[in] timer_event_handler Event handler provided by the user.
 | 
			
		||||
 *                                Must not be NULL.
 | 
			
		||||
 *
 | 
			
		||||
@@ -113,59 +146,59 @@ ret_code_t nrf_drv_timer_init(nrf_drv_timer_t const * const p_instance,
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Function for uninitializing the timer.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] p_instance Timer instance.
 | 
			
		||||
 * @param[in] p_instance Pointer to the driver instance structure.
 | 
			
		||||
 */
 | 
			
		||||
void nrf_drv_timer_uninit(nrf_drv_timer_t const * const p_instance);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Function for turning on the timer.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] p_instance Timer instance.
 | 
			
		||||
 * @param[in] p_instance Pointer to the driver instance structure.
 | 
			
		||||
 */
 | 
			
		||||
void nrf_drv_timer_enable(nrf_drv_timer_t const * const p_instance);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Function for turning off the timer.
 | 
			
		||||
 *
 | 
			
		||||
 * Note that the timer will allow to enter the lowest possible SYSTEM_ON state 
 | 
			
		||||
 * Note that the timer will allow to enter the lowest possible SYSTEM_ON state
 | 
			
		||||
 * only after this function is called.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] p_instance Timer instance.
 | 
			
		||||
 * @param[in] p_instance Pointer to the driver instance structure.
 | 
			
		||||
 */
 | 
			
		||||
void nrf_drv_timer_disable(nrf_drv_timer_t const * const p_instance);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Function for pausing the timer.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] p_instance Timer instance.
 | 
			
		||||
 * @param[in] p_instance Pointer to the driver instance structure.
 | 
			
		||||
 */
 | 
			
		||||
void nrf_drv_timer_pause(nrf_drv_timer_t const * const p_instance);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Function for resuming the timer.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] p_instance Timer instance.
 | 
			
		||||
 * @param[in] p_instance Pointer to the driver instance structure.
 | 
			
		||||
 */
 | 
			
		||||
void nrf_drv_timer_resume(nrf_drv_timer_t const * const p_instance);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Function for clearing the timer.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] p_instance Timer instance.
 | 
			
		||||
 * @param[in] p_instance Pointer to the driver instance structure.
 | 
			
		||||
 */
 | 
			
		||||
void nrf_drv_timer_clear(nrf_drv_timer_t const * const p_instance);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Function for incrementing the timer.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] p_instance Timer instance.
 | 
			
		||||
 * @param[in] p_instance Pointer to the driver instance structure.
 | 
			
		||||
 */
 | 
			
		||||
void nrf_drv_timer_increment(nrf_drv_timer_t const * const p_instance);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Function for returning the address of a specific timer task.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] p_instance Timer instance.
 | 
			
		||||
 * @param[in] p_instance Pointer to the driver instance structure.
 | 
			
		||||
 * @param[in] timer_task Timer task.
 | 
			
		||||
 *
 | 
			
		||||
 * @return Task address.
 | 
			
		||||
@@ -177,7 +210,7 @@ __STATIC_INLINE uint32_t nrf_drv_timer_task_address_get(
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Function for returning the address of a specific timer capture task.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] p_instance Timer instance.
 | 
			
		||||
 * @param[in] p_instance Pointer to the driver instance structure.
 | 
			
		||||
 * @param[in] channel    Capture channel number.
 | 
			
		||||
 *
 | 
			
		||||
 * @return Task address.
 | 
			
		||||
@@ -189,7 +222,7 @@ __STATIC_INLINE uint32_t nrf_drv_timer_capture_task_address_get(
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Function for returning the address of a specific timer event.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] p_instance  Timer instance.
 | 
			
		||||
 * @param[in] p_instance  Pointer to the driver instance structure.
 | 
			
		||||
 * @param[in] timer_event Timer event.
 | 
			
		||||
 *
 | 
			
		||||
 * @return Event address.
 | 
			
		||||
@@ -201,7 +234,7 @@ __STATIC_INLINE uint32_t nrf_drv_timer_event_address_get(
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Function for returning the address of a specific timer compare event.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] p_instance Timer instance.
 | 
			
		||||
 * @param[in] p_instance Pointer to the driver instance structure.
 | 
			
		||||
 * @param[in] channel    Compare channel number.
 | 
			
		||||
 *
 | 
			
		||||
 * @return Event address.
 | 
			
		||||
@@ -213,7 +246,7 @@ __STATIC_INLINE uint32_t nrf_drv_timer_compare_event_address_get(
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Function for capturing the timer value.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] p_instance Timer instance.
 | 
			
		||||
 * @param[in] p_instance Pointer to the driver instance structure.
 | 
			
		||||
 * @param[in] cc_channel Capture channel number.
 | 
			
		||||
 *
 | 
			
		||||
 * @return Captured value.
 | 
			
		||||
@@ -226,7 +259,7 @@ uint32_t nrf_drv_timer_capture(nrf_drv_timer_t const * const p_instance,
 | 
			
		||||
 *
 | 
			
		||||
 * Use this function to read channel values when PPI is used for capturing.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] p_instance Timer instance.
 | 
			
		||||
 * @param[in] p_instance Pointer to the driver instance structure.
 | 
			
		||||
 * @param[in] cc_channel Capture channel number.
 | 
			
		||||
 *
 | 
			
		||||
 * @return Captured value.
 | 
			
		||||
@@ -238,7 +271,7 @@ __STATIC_INLINE uint32_t nrf_drv_timer_capture_get(
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Function for setting the timer channel in compare mode.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] p_instance Timer instance.
 | 
			
		||||
 * @param[in] p_instance Pointer to the driver instance structure.
 | 
			
		||||
 * @param[in] cc_channel Compare channel number.
 | 
			
		||||
 * @param[in] cc_value   Compare value.
 | 
			
		||||
 * @param[in] enable_int Enable or disable the interrupt for the compare channel.
 | 
			
		||||
@@ -251,7 +284,7 @@ void nrf_drv_timer_compare(nrf_drv_timer_t const * const p_instance,
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Function for setting the timer channel in extended compare mode.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] p_instance       Timer instance.
 | 
			
		||||
 * @param[in] p_instance       Pointer to the driver instance structure.
 | 
			
		||||
 * @param[in] cc_channel       Compare channel number.
 | 
			
		||||
 * @param[in] cc_value         Compare value.
 | 
			
		||||
 * @param[in] timer_short_mask Shortcut between the compare event on the channel
 | 
			
		||||
@@ -268,7 +301,7 @@ void nrf_drv_timer_extended_compare(nrf_drv_timer_t const * const p_instance,
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Function for converting time in microseconds to timer ticks.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] p_instance Timer instance.
 | 
			
		||||
 * @param[in] p_instance Pointer to the driver instance structure.
 | 
			
		||||
 * @param[in] time_us    Time in microseconds.
 | 
			
		||||
 *
 | 
			
		||||
 * @return Number of ticks.
 | 
			
		||||
@@ -280,7 +313,7 @@ __STATIC_INLINE uint32_t nrf_drv_timer_us_to_ticks(
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Function for converting time in milliseconds to timer ticks.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] p_instance Timer instance.
 | 
			
		||||
 * @param[in] p_instance Pointer to the driver instance structure.
 | 
			
		||||
 * @param[in] time_ms    Time in milliseconds.
 | 
			
		||||
 *
 | 
			
		||||
 * @return Number of ticks.
 | 
			
		||||
@@ -292,7 +325,7 @@ __STATIC_INLINE uint32_t nrf_drv_timer_ms_to_ticks(
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Function for enabling timer compare interrupt.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] p_instance Timer instance.
 | 
			
		||||
 * @param[in] p_instance Pointer to the driver instance structure.
 | 
			
		||||
 * @param[in] channel    Compare channel.
 | 
			
		||||
 */
 | 
			
		||||
void nrf_drv_timer_compare_int_enable(nrf_drv_timer_t const * const p_instance,
 | 
			
		||||
@@ -301,7 +334,7 @@ void nrf_drv_timer_compare_int_enable(nrf_drv_timer_t const * const p_instance,
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Function for disabling timer compare interrupt.
 | 
			
		||||
 *
 | 
			
		||||
 * @param[in] p_instance Timer instance.
 | 
			
		||||
 * @param[in] p_instance Pointer to the driver instance structure.
 | 
			
		||||
 * @param[in] channel    Compare channel.
 | 
			
		||||
 */
 | 
			
		||||
void nrf_drv_timer_compare_int_disable(nrf_drv_timer_t const * const p_instance,
 | 
			
		||||
@@ -367,6 +400,11 @@ __STATIC_INLINE uint32_t nrf_drv_timer_ms_to_ticks(
 | 
			
		||||
 | 
			
		||||
#endif // SUPPRESS_INLINE_IMPLEMENTATION
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#endif // NRF_DRV_TIMER_H__
 | 
			
		||||
 | 
			
		||||
/** @} */
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user