1 // Copyright 2020 Espressif Systems (Shanghai) PTE LTD 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #pragma once 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 #include <stdint.h> 22 #include <stdbool.h> 23 #include "hal/systimer_types.h" 24 25 /** 26 * @brief enable systimer counter 27 */ 28 void systimer_hal_enable_counter(systimer_counter_id_t counter_id); 29 30 /** 31 * @brief get current counter value 32 */ 33 uint64_t systimer_hal_get_counter_value(systimer_counter_id_t counter_id); 34 35 /** 36 * @brief get current time (in microseconds) 37 */ 38 uint64_t systimer_hal_get_time(systimer_counter_id_t counter_id); 39 40 /* 41 * @brief set alarm target value (used in one-shot mode) 42 */ 43 void systimer_hal_set_alarm_target(systimer_alarm_id_t alarm_id, uint64_t target); 44 45 /** 46 * @brief set alarm period value (used in period mode) 47 */ 48 void systimer_hal_set_alarm_period(systimer_alarm_id_t alarm_id, uint32_t period); 49 50 /** 51 * @brief get alarm time 52 */ 53 uint64_t systimer_hal_get_alarm_value(systimer_alarm_id_t alarm_id); 54 55 /** 56 * @brief enable alarm interrupt 57 */ 58 void systimer_hal_enable_alarm_int(systimer_alarm_id_t alarm_id); 59 60 /** 61 * @brief select alarm mode 62 */ 63 void systimer_hal_select_alarm_mode(systimer_alarm_id_t alarm_id, systimer_alarm_mode_t mode); 64 65 /** 66 * @brief update systimer step when apb clock gets changed 67 */ 68 void systimer_hal_on_apb_freq_update(uint32_t apb_ticks_per_us); 69 70 /** 71 * @brief move systimer counter value forward or backward 72 */ 73 void systimer_hal_counter_value_advance(systimer_counter_id_t counter_id, int64_t time_us); 74 75 /** 76 * @brief initialize systimer in HAL layer 77 */ 78 void systimer_hal_init(void); 79 80 /** 81 * @brief connect alarm unit to selected counter 82 */ 83 void systimer_hal_connect_alarm_counter(systimer_alarm_id_t alarm_id, systimer_counter_id_t counter_id); 84 85 /** 86 * @brief set if a counter should be stalled when CPU is halted by the debugger 87 */ 88 void systimer_hal_counter_can_stall_by_cpu(uint32_t counter_id, uint32_t cpu_id, bool can); 89 90 #ifdef __cplusplus 91 } 92 #endif 93