mirror of
https://github.com/espressif/esp-idf.git
synced 2025-12-11 02:07:46 +00:00
gptimer: clean up hal and ll for driver-ng
This commit is contained in:
@@ -1,21 +1,14 @@
|
||||
// Copyright 2020 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.
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "test_utils.h"
|
||||
#include "driver/periph_ctrl.h"
|
||||
#include "soc/periph_defs.h"
|
||||
#include "hal/timer_hal.h"
|
||||
#include "hal/timer_ll.h"
|
||||
|
||||
#define TIMER_GROUP_ID (1)
|
||||
#define TIMER_ID (0)
|
||||
@@ -25,26 +18,24 @@ void ref_clock_init(void)
|
||||
{
|
||||
periph_module_enable(PERIPH_TIMG1_MODULE);
|
||||
timer_hal_init(&timer_hal, TIMER_GROUP_ID, TIMER_ID);
|
||||
timer_hal_set_use_xtal(&timer_hal, true); // Select XTAL, so ref_clock is independent of the APL clock
|
||||
timer_hal_set_divider(&timer_hal, 40); // Resolution is configured to 1MHz
|
||||
timer_hal_set_counter_increase(&timer_hal, true); // increase mode
|
||||
timer_hal_set_counter_enable(&timer_hal, false); // stop timer from running
|
||||
timer_ll_set_clock_source(timer_hal.dev, TIMER_ID, GPTIMER_CLK_SRC_XTAL); // Select XTAL, so ref_clock is independent of the APL clock
|
||||
timer_ll_enable_counter(timer_hal.dev, TIMER_ID, false); // stop timer from running
|
||||
timer_ll_set_clock_prescale(timer_hal.dev, TIMER_ID, 40); // Resolution is configured to 1MHz
|
||||
timer_ll_set_count_direction(timer_hal.dev, timer_hal.timer_id, GPTIMER_COUNT_UP); // increase mode
|
||||
timer_hal_set_counter_value(&timer_hal, 0); // initial count value to zero
|
||||
timer_hal_intr_disable(&timer_hal); // disable interrupt
|
||||
timer_hal_set_alarm_enable(&timer_hal, false); // we don't need to generate any interrupt
|
||||
timer_hal_set_auto_reload(&timer_hal, false);
|
||||
timer_hal_set_counter_enable(&timer_hal, true); // start counter
|
||||
timer_ll_enable_intr(timer_hal.dev, TIMER_LL_EVENT_ALARM(TIMER_ID), false); // disable interrupt
|
||||
timer_ll_enable_alarm(timer_hal.dev, TIMER_ID, false); // alarm event is not needed
|
||||
timer_ll_enable_auto_reload(timer_hal.dev, TIMER_ID, false);
|
||||
timer_ll_enable_counter(timer_hal.dev, TIMER_ID, true); // start counter
|
||||
}
|
||||
|
||||
void ref_clock_deinit(void)
|
||||
{
|
||||
timer_hal_set_counter_enable(&timer_hal, false); // stop timer from running
|
||||
timer_ll_enable_counter(timer_hal.dev, TIMER_ID, false); // stop timer from running
|
||||
periph_module_disable(PERIPH_TIMG1_MODULE);
|
||||
}
|
||||
|
||||
uint64_t ref_clock_get(void)
|
||||
{
|
||||
uint64_t count_value = 0;
|
||||
timer_hal_get_counter_value(&timer_hal, &count_value);
|
||||
return count_value;
|
||||
return timer_ll_get_counter_value(timer_hal.dev, timer_hal.timer_id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user