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 #include <common/bk_include.h> 18 #include <driver/hal/hal_aon_rtc_types.h> 19 #include <driver/int_types.h> 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 #define ALARM_NAME_MAX_LEN ((uint32_t)7) 26 #define ALARM_LOOP_FOREVER (0xffffffff) 27 #define AON_RTC_MS_TICK_CNT (32) 28 #define AON_RTC_PRECISION_TICK (32) // 29 //#define AON_RTC_SET_TICK_TIME (8) //CPU compute can be set tick but the time consumes about 4~8 ticks 30 #define AON_RTC_ROUND_TICK (0XFFFFFFFF) //we can set to other value, but maybe easy to cause a new round as the max value is less then 38 hours. 31 #define AON_RTC_MAX_ALARM_CNT (8) 32 33 /** 34 * @brief AON RTC interrupt service routine 35 */ 36 37 #define BK_ERR_AON_RTC_DRIVER_NOT_INIT (BK_ERR_AON_RTC_BASE - 1) /**< AON_RTC driver not init */ 38 39 typedef void (*aon_rtc_isr_t)(aon_rtc_id_t id, uint8_t *name_p, void *param); 40 41 typedef struct { 42 aon_rtc_id_t id; 43 icu_int_src_t int_src; 44 int_group_isr_t isr; 45 } aon_rtc_int_config_t; 46 47 typedef struct _alarm_info_t 48 { 49 uint8_t name[ALARM_NAME_MAX_LEN+1]; 50 uint32_t period_tick; 51 uint32_t period_cnt; //total period count == 0Xffffffff means forever period;else period how many times 52 aon_rtc_isr_t callback; 53 void *param_p; 54 }alarm_info_t; 55 56 typedef struct _alarm_node_t 57 { 58 struct _alarm_node_t *next; 59 uint8_t name[ALARM_NAME_MAX_LEN+1]; 60 uint32_t period_tick; //tick:AON RTC use it 61 uint32_t period_cnt; //total period count == 0Xffffffff means forever period;else period how many times 62 aon_rtc_isr_t callback; 63 void *cb_param_p; 64 uint64_t start_tick; //timer tick, SW use it 65 uint64_t expired_tick; //first expired time, timer tick 66 } alarm_node_t; 67 68 #ifdef __cplusplus 69 } 70 #endif 71 72 73