2017-08-07 16:21:19 -04:00
|
|
|
// Copyright 2017 Espressif Systems (Shanghai) PTE LTD
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
/**
|
2020-02-06 01:00:18 -05:00
|
|
|
* @file private_include/esp_timer_impl.h
|
2017-08-07 16:21:19 -04:00
|
|
|
*
|
|
|
|
* @brief Interface between common and platform-specific parts of esp_timer.
|
|
|
|
*
|
|
|
|
* The functions in this header file are implemented for each supported SoC.
|
|
|
|
* High level functions defined in esp_timer.c call the functions here to
|
|
|
|
* interact with the hardware.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "esp_err.h"
|
|
|
|
#include "esp_intr_alloc.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Initialize platform specific layer of esp_timer
|
|
|
|
* @param alarm_handler function to call on timer interrupt
|
|
|
|
* @return ESP_OK, ESP_ERR_NO_MEM, or one of the errors from interrupt allocator
|
|
|
|
*/
|
|
|
|
esp_err_t esp_timer_impl_init(intr_handler_t alarm_handler);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Deinitialize platform specific layer of esp_timer
|
|
|
|
*/
|
2019-07-16 05:33:30 -04:00
|
|
|
void esp_timer_impl_deinit(void);
|
2017-08-07 16:21:19 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set up the timer interrupt to fire at a particular time
|
|
|
|
*
|
|
|
|
* If the alarm time is too close in the future, implementation should set the
|
|
|
|
* alarm to the earliest time possible.
|
|
|
|
*
|
|
|
|
* @param timestamp time in microseconds when interrupt should fire (relative to
|
|
|
|
* boot time, i.e. as returned by esp_timer_impl_get_time)
|
|
|
|
*/
|
|
|
|
void esp_timer_impl_set_alarm(uint64_t timestamp);
|
|
|
|
|
2020-02-10 08:45:09 -05:00
|
|
|
/**
|
|
|
|
* @brief Set up the timer interrupt to fire at a particular time for a particular alarm module.
|
|
|
|
*
|
|
|
|
* If the alarm time is too close in the future, implementation should set the
|
|
|
|
* alarm to the earliest time possible.
|
|
|
|
*
|
|
|
|
* @param timestamp time in microseconds when interrupt should fire (relative to
|
|
|
|
* boot time, i.e. as returned by esp_timer_impl_get_time)
|
|
|
|
*
|
|
|
|
* @param alarm_id Id alarm:
|
|
|
|
* 0 - alarm_0 for the ESP_TIMER_TASK dispatch method,
|
|
|
|
* 1 - alarm_1 for the ESP_TIMER_ISR dispatch method.
|
|
|
|
*/
|
|
|
|
void esp_timer_impl_set_alarm_id(uint64_t timestamp, unsigned alarm_id);
|
|
|
|
|
2017-10-09 03:24:51 -04:00
|
|
|
/**
|
|
|
|
* @brief Notify esp_timer implementation that APB frequency has changed
|
|
|
|
*
|
|
|
|
* Called by the frequency switching code.
|
|
|
|
*
|
|
|
|
* @param apb_ticks_per_us new number of APB clock ticks per microsecond
|
|
|
|
*/
|
|
|
|
void esp_timer_impl_update_apb_freq(uint32_t apb_ticks_per_us);
|
|
|
|
|
2018-04-03 06:13:22 -04:00
|
|
|
/**
|
|
|
|
* @brief Adjust current esp_timer time by a certain value
|
|
|
|
*
|
|
|
|
* Called from light sleep code to synchronize esp_timer time with RTC time.
|
|
|
|
*
|
|
|
|
* @param time_us adjustment to apply to esp_timer time, in microseconds
|
|
|
|
*/
|
|
|
|
void esp_timer_impl_advance(int64_t time_us);
|
|
|
|
|
2017-08-07 16:21:19 -04:00
|
|
|
/**
|
|
|
|
* @brief Get time, in microseconds, since esp_timer_impl_init was called
|
|
|
|
* @return timestamp in microseconds
|
|
|
|
*/
|
2020-03-31 06:44:37 -04:00
|
|
|
int64_t esp_timer_impl_get_time(void);
|
2017-08-07 16:21:19 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get minimal timer period, in microseconds
|
|
|
|
* Periods shorter than the one returned may not be possible to achieve due to
|
|
|
|
* interrupt latency and context switch time. Short period of periodic timer may
|
|
|
|
* cause the system to spend all the time servicing the interrupt and timer
|
|
|
|
* callback, preventing other tasks from running.
|
|
|
|
* @return minimal period of periodic timer, in microseconds
|
|
|
|
*/
|
2019-07-16 05:33:30 -04:00
|
|
|
uint64_t esp_timer_impl_get_min_period_us(void);
|
2018-05-04 00:50:39 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief obtain internal critical section used esp_timer implementation
|
|
|
|
* This can be used when a sequence of calls to esp_timer has to be made,
|
|
|
|
* and it is necessary that the state of the timer is consistent between
|
|
|
|
* the calls. Should be treated in the same way as a spinlock.
|
|
|
|
* Call esp_timer_impl_unlock to release the lock
|
|
|
|
*/
|
2019-07-16 05:33:30 -04:00
|
|
|
void esp_timer_impl_lock(void);
|
2018-05-04 00:50:39 -04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief counterpart of esp_timer_impl_lock
|
|
|
|
*/
|
2019-07-16 05:33:30 -04:00
|
|
|
void esp_timer_impl_unlock(void);
|
2020-02-06 01:00:18 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get counting register
|
|
|
|
*
|
|
|
|
* Bit depth dependents on implementation and can be 32-bit or 64-bit.
|
|
|
|
*
|
|
|
|
* @return the value of the counting register
|
|
|
|
*/
|
|
|
|
uint64_t esp_timer_impl_get_counter_reg(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get alarm register
|
|
|
|
*
|
|
|
|
* Bit depth dependents on implementation and can be 32-bit or 64-bit.
|
|
|
|
*
|
|
|
|
* @return the value of the alarm register
|
|
|
|
*/
|
|
|
|
uint64_t esp_timer_impl_get_alarm_reg(void);
|