• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2022 Beken Corporation
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 "hal_config.h"
22 #include "timer_hw.h"
23 #include "timer_ll.h"
24 #include <driver/hal/hal_timer_types.h>
25 
26 typedef struct {
27     timer_hw_t *hw;
28     timer_unit_t id;
29 } timer_hal_t;
30 
31 #define timer_hal_enable(hal, chan) timer_ll_enable((hal)->hw, chan)
32 #define timer_hal_disable(hal, chan) timer_ll_disable((hal)->hw, chan)
33 #define timer_hal_get_enable_status(hal) timer_ll_get_enable_status((hal)->hw)
34 #define timer_hal_enable_interrupt(hal, chan) timer_ll_enable_interrupt((hal)->hw, chan)
35 #define timer_hal_disable_interrupt(hal, chan) timer_ll_disable_interrupt((hal)->hw, chan)
36 #define timer_hal_get_interrupt_status(hal) timer_ll_get_interrupt_status((hal)->hw)
37 #define timer_hal_clear_interrupt_status(hal, status) timer_ll_clear_interrupt_status((hal)->hw, status)
38 #define timer_hal_clear_chan_interrupt_status(hal, chan) timer_ll_clear_chan_interrupt_status((hal)->hw, chan)
39 #define timer_hal_is_interrupt_triggered(hal, chan, status) timer_ll_is_interrupt_triggered((hal)->hw, (chan), (status))
40 #define timer_hal_reset_config_to_default(hal, chan) timer_ll_reset_config_to_default((hal)->hw, (chan))
41 #define timer_hal_get_end_count(hal, chan) timer_ll_get_end_count((hal)->hw, chan)
42 
43 bk_err_t timer_hal_init(timer_hal_t *hal);
44 bk_err_t timer_hal_init_timer(timer_hal_t *hal, timer_id_t chan, uint64_t time, timer_value_unit_t unit_type);
45 bk_err_t timer_hal_set_period(timer_hal_t *hal, timer_id_t chan, uint32_t time_ms);
46 bk_err_t timer_hal_start_common(timer_hal_t *hal, timer_id_t chan);
47 bk_err_t timer_hal_stop_common(timer_hal_t *hal, timer_id_t chan);
48 uint32_t timer_hal_get_count(timer_hal_t *hal, timer_id_t chan);
49 
50 uint32_t timer_hal_cal_end_count(timer_id_t chan, uint64_t time, uint32_t div, timer_value_unit_t unit_type);
51 
52 #if CFG_HAL_DEBUG_TIMER
53 void timer_struct_dump(void);
54 #else
55 #define timer_struct_dump()
56 #endif
57 
58 #ifdef __cplusplus
59 }
60 #endif
61 
62