2021-09-27 00:46:51 -04:00
|
|
|
/*
|
2022-01-02 03:19:49 -05:00
|
|
|
* SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
|
2021-09-27 00:46:51 -04:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2020-11-05 23:00:07 -05:00
|
|
|
|
|
|
|
#include "test_utils.h"
|
2022-01-02 03:19:49 -05:00
|
|
|
#include "unity_config.h"
|
|
|
|
#include "driver/gptimer.h"
|
2020-11-05 23:00:07 -05:00
|
|
|
|
2022-01-02 03:19:49 -05:00
|
|
|
static gptimer_handle_t ts_gptimer;
|
2020-11-05 23:00:07 -05:00
|
|
|
|
|
|
|
void ref_clock_init(void)
|
|
|
|
{
|
2022-01-02 03:19:49 -05:00
|
|
|
gptimer_config_t timer_config = {
|
|
|
|
.clk_src = GPTIMER_CLK_SRC_XTAL,
|
|
|
|
.direction = GPTIMER_COUNT_UP,
|
|
|
|
.resolution_hz = 1000000, // Resolution is configured to 1MHz
|
|
|
|
};
|
|
|
|
TEST_ESP_OK(gptimer_new_timer(&timer_config, &ts_gptimer));
|
2022-04-23 06:59:38 -04:00
|
|
|
TEST_ESP_OK(gptimer_enable(ts_gptimer));
|
2022-01-02 03:19:49 -05:00
|
|
|
TEST_ESP_OK(gptimer_start(ts_gptimer));
|
2020-11-05 23:00:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void ref_clock_deinit(void)
|
|
|
|
{
|
2022-01-02 03:19:49 -05:00
|
|
|
TEST_ESP_OK(gptimer_stop(ts_gptimer));
|
2022-04-23 06:59:38 -04:00
|
|
|
TEST_ESP_OK(gptimer_disable(ts_gptimer));
|
2022-01-02 03:19:49 -05:00
|
|
|
TEST_ESP_OK(gptimer_del_timer(ts_gptimer));
|
|
|
|
ts_gptimer = NULL;
|
2020-11-05 23:00:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t ref_clock_get(void)
|
|
|
|
{
|
2022-01-02 03:19:49 -05:00
|
|
|
uint64_t ts;
|
|
|
|
gptimer_get_raw_count(ts_gptimer, &ts);
|
|
|
|
return ts;
|
2020-11-05 23:00:07 -05:00
|
|
|
}
|