2021-09-27 04:46:51 +00:00
|
|
|
/*
|
2022-01-02 08:14:17 +00:00
|
|
|
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
2021-09-27 04:46:51 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2019-07-15 06:21:36 +00:00
|
|
|
|
2022-07-13 05:17:32 +00:00
|
|
|
#include <stdlib.h>
|
2019-07-15 06:21:36 +00:00
|
|
|
#include "hal/timer_hal.h"
|
2021-09-27 04:46:51 +00:00
|
|
|
#include "hal/timer_ll.h"
|
2022-07-13 05:17:32 +00:00
|
|
|
#include "soc/soc_caps.h"
|
2019-07-15 06:21:36 +00:00
|
|
|
|
2021-09-27 04:46:51 +00:00
|
|
|
void timer_hal_init(timer_hal_context_t *hal, uint32_t group_num, uint32_t timer_num)
|
2019-07-15 06:21:36 +00:00
|
|
|
{
|
|
|
|
hal->dev = TIMER_LL_GET_HW(group_num);
|
2021-09-27 04:46:51 +00:00
|
|
|
hal->timer_id = timer_num;
|
2022-07-13 05:17:32 +00:00
|
|
|
// enable peripheral clock
|
|
|
|
timer_ll_enable_clock(hal->dev, timer_num, true);
|
|
|
|
// stop counter, alarm, auto-reload at first place
|
|
|
|
timer_ll_enable_counter(hal->dev, timer_num, false);
|
|
|
|
timer_ll_enable_auto_reload(hal->dev, timer_num, false);
|
|
|
|
timer_ll_enable_alarm(hal->dev, timer_num, false);
|
|
|
|
// enable RTM subsystem if available
|
|
|
|
#if SOC_TIMER_SUPPORT_ETM
|
|
|
|
timer_ll_enable_etm(hal->dev, true);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void timer_hal_deinit(timer_hal_context_t *hal)
|
|
|
|
{
|
|
|
|
// disable peripheral clock
|
|
|
|
timer_ll_enable_clock(hal->dev, hal->timer_id, false);
|
|
|
|
// ensure counter, alarm, auto-reload are disabled
|
|
|
|
timer_ll_enable_counter(hal->dev, hal->timer_id, false);
|
|
|
|
timer_ll_enable_auto_reload(hal->dev, hal->timer_id, false);
|
|
|
|
timer_ll_enable_alarm(hal->dev, hal->timer_id, false);
|
|
|
|
#if SOC_TIMER_SUPPORT_ETM
|
|
|
|
timer_ll_enable_etm(hal->dev, false);
|
|
|
|
#endif
|
|
|
|
hal->dev = NULL;
|
2019-07-15 06:21:36 +00:00
|
|
|
}
|