1 /* 2 * @file hi_hwtimer.h 3 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef __HI_HWTIMER_H__ 18 #define __HI_HWTIMER_H__ 19 20 #include <hi_types_base.h> 21 22 23 typedef enum { 24 HI_RTC_CLK_32K = 32, 25 HI_RTC_CLK_24M = 24, 26 HI_RTC_CLK_40M = 40, 27 } hi_rtc_clk; /**< In low-power deep sleep mode, the 24 MHz or 40 MHz clock is unavailable. */ 28 29 typedef void (*hi_hwtimer_callback)(hi_u32 data); 30 31 typedef void (*hi_hwrtc_callback)(hi_u32 data); 32 33 typedef void (*hwtimer_clken_callback)(hi_void); 34 35 /** 36 * @ingroup hw_timer 37 * 38 * Timer mode control. CNcomment:定时器模式控制。CNend 39 */ 40 typedef enum { 41 TIMER_MODE_FREE = 0, 42 TIMER_MODE_CYCLE = 1, 43 } timer_mode; 44 45 /** 46 * @ingroup hw_timer 47 * 48 * Timer interrupt mask control. CNcomment:定时器中断模式控制。CNend 49 */ 50 typedef enum { 51 TIMER_INT_UNMASK = 0, /**< Not masked */ 52 TIMER_INT_MASK = 1, /**< Masked */ 53 } timer_int_mask; 54 55 /** 56 * @ingroup hw_timer 57 * 58 * hwtimer ID. CNcomment:硬件定时器ID。CNend 59 */ 60 typedef enum { 61 HI_TIMER_ID_0, 62 HI_TIMER_ID_1, 63 HI_TIMER_ID_2, 64 HI_TIMER_ID_MAX, /* Invalid value. */ 65 } hi_timer_id; 66 67 /** 68 * @ingroup hw_timer 69 * 70 * hwrtc ID. CNcomment:硬件RTC ID。CNend 71 */ 72 typedef enum { 73 HI_RTC_ID_0 = HI_TIMER_ID_MAX, 74 HI_RTC_ID_1, 75 HI_RTC_ID_2, 76 HI_RTC_ID_3, 77 HI_RTC_ID_MAX, /* Invalid value. */ 78 } hi_rtc_id; 79 80 /** 81 * @ingroup hw_timer 82 * 83 * hwtimer working mode. CNcomment:硬件定时器工作模式。CNend 84 */ 85 typedef enum { 86 HI_HWTIMER_MODE_ONCE, 87 HI_HWTIMER_MODE_PERIOD, 88 HI_HWTIMER_MODE_INVALID, 89 } hi_hwtimer_mode; 90 91 /** 92 * @ingroup hw_timer 93 * 94 * hwrtc working mode. CNcomment:硬件RTC工作模式。CNend 95 */ 96 typedef enum { 97 HI_HWRTC_MODE_ONCE, 98 HI_HWRTC_MODE_PERIOD, 99 HI_HWRTC_MODE_INVALID, 100 } hi_hwrtc_mode; 101 102 /** 103 * @ingroup hw_timer 104 * 105 * hwtimer handle structure. CNcomment:硬件定时器句柄结构。CNend 106 */ 107 typedef struct { 108 hi_hwtimer_mode mode; 109 hi_u32 expire; 110 hi_u32 data; 111 hi_hwtimer_callback func; 112 hi_timer_id timer_id; 113 } hi_hwtimer_ctl; 114 115 /** 116 * @ingroup hw_timer 117 * 118 * hwrtc handle structure. CNcomment:硬件RTC句柄结构。CNend 119 */ 120 typedef struct { 121 hi_hwrtc_mode mode; 122 hi_u32 expire; 123 hi_u32 data; 124 hi_hwrtc_callback func; 125 hi_rtc_id rtc_id; 126 } hi_hwrtc_ctl; 127 128 hi_void hi_hwrtc_set_clk(hi_rtc_clk clk); 129 130 hi_u32 hi_hwtimer_init_new(hi_timer_id timer_id); 131 hi_u32 hi_hwtimer_start(const hi_hwtimer_ctl *timer); 132 hi_u32 hi_hwtimer_stop(hi_timer_id timer_id); 133 hi_u32 hi_hwtimer_destroy_new(hi_timer_id timer_id); 134 hi_u32 hi_hwtimer_get_cur_val(hi_timer_id timer_id, hi_u32 *val); 135 hi_u32 hi_hwtimer_get_load(hi_timer_id timer_id, hi_u32 *load); 136 137 hi_u32 hi_hwrtc_start(const hi_hwrtc_ctl *rtc); 138 hi_u32 hi_hwrtc_init(hi_rtc_id timer_id); 139 hi_u32 hi_hwrtc_stop(hi_rtc_id rtc_id); 140 hi_u32 hi_hwrtc_destroy(hi_rtc_id rtc_id); 141 hi_u32 hi_hwrtc_get_cur_val(hi_rtc_id rtc_id, hi_u32 *val); 142 hi_u32 hi_hwrtc_get_load(hi_rtc_id rtc_id, hi_u32 *load); 143 hi_u32 hwtimer_start(hi_u32 tick_cnt, const hi_hwtimer_ctl *timer); 144 145 #endif 146