2021-09-27 00:46:51 -04:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2019-07-15 02:21:36 -04:00
|
|
|
|
|
|
|
#include "hal/timer_hal.h"
|
2021-09-27 00:46:51 -04:00
|
|
|
#include "hal/timer_ll.h"
|
2019-07-15 02:21:36 -04:00
|
|
|
|
2021-09-27 00:46:51 -04:00
|
|
|
void timer_hal_init(timer_hal_context_t *hal, uint32_t group_num, uint32_t timer_num)
|
2019-07-15 02:21:36 -04:00
|
|
|
{
|
|
|
|
hal->dev = TIMER_LL_GET_HW(group_num);
|
2021-09-27 00:46:51 -04:00
|
|
|
hal->timer_id = timer_num;
|
2019-07-15 02:21:36 -04:00
|
|
|
}
|
2020-04-10 04:23:19 -04:00
|
|
|
|
2021-09-27 00:46:51 -04:00
|
|
|
void timer_hal_set_counter_value(timer_hal_context_t *hal, uint64_t load_val)
|
2020-04-10 04:23:19 -04:00
|
|
|
{
|
2021-09-27 00:46:51 -04:00
|
|
|
// save current reload value
|
|
|
|
uint64_t old_reload = timer_ll_get_reload_value(hal->dev, hal->timer_id);
|
|
|
|
timer_ll_set_reload_value(hal->dev, hal->timer_id, load_val);
|
|
|
|
timer_ll_trigger_soft_reload(hal->dev, hal->timer_id);
|
|
|
|
// restore the previous reload value
|
|
|
|
timer_ll_set_reload_value(hal->dev, hal->timer_id, old_reload);
|
2021-09-16 07:45:33 -04:00
|
|
|
}
|