1 /* 2 * Copyright (c) 2021 Chipsea Technologies (Shenzhen) Corp., Ltd. All rights reserved. 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 #ifndef _CO_MAIN_H_ 16 #define _CO_MAIN_H_ 17 18 #include <stdbool.h> 19 #include "wb_co_list.h" 20 #include "co_message.h" 21 #include "pinname.h" 22 23 #define CO_EVT_MAX (30) 24 #define CO_TIMER_ALLOW_MIN_SLEEP_DURATION 100 //ms 25 #define CO_MAIN_AUTO_POWER_DOWEN 0 26 27 typedef enum { 28 CO_TIMER_LP_LEVEL_ACTIVE = 0, 29 CO_TIMER_LP_LEVEL_HIBERNATE, 30 }CO_TIMER_LP_LEVEL; 31 32 typedef enum { 33 CO_MODUAL_KEY = 0, 34 CO_MODUAL_TIMER, 35 CO_MODUAL_LED, 36 CO_MODUAL_LIGHT_SENSOR, 37 CO_MODUAL_NUM 38 } CO_MODUAL_ID_T; 39 40 typedef struct { 41 uint32_t EvtId; 42 uint32_t Param; 43 } CO_EVENT; 44 45 typedef struct { 46 uint32_t mod_id; 47 CO_EVENT mod_evt; 48 }CO_MODUAL_EVENT; 49 50 51 typedef struct _co_timer_ co_timer; 52 53 typedef void (*co_timer_callback)(void*); 54 55 typedef struct _co_timer_ 56 { 57 struct co_list_hdr node; 58 co_timer_callback cb; 59 void* cb_param; 60 uint32_t time_duration; 61 uint32_t time_start; 62 uint32_t timer_addr; 63 uint32_t is_period; 64 }co_timer; 65 66 typedef bool (*CO_EVT_HANDLER_T)(CO_EVENT *); 67 68 typedef int (*co_main_batt_reg_cb_t)(uint32_t vaule); 69 70 void co_main_batt_register_cb(co_main_batt_reg_cb_t callback); 71 72 void co_main_init(void); 73 74 int co_main_evt_handler_rigister(CO_MODUAL_ID_T mod_id, CO_EVT_HANDLER_T handler); 75 76 int co_event_send(CO_MODUAL_EVENT *msg_src, bool isr); 77 78 int co_event_get(CO_MODUAL_EVENT* msg_p); 79 /** 80 **************************************************************************************** 81 * @brief * co_timer_start : co_timer which will be run in DEEP SLEEP POWER DOWEN state . 82 * 83 * @param[] timer : the address of timer handler pointer,used for restore the timer handler pointer after power up from AON. 84 * duration : duration likes xTicksToWait Specifies the time, in ticks . eg : now ticks step is 1ms,so unit of duration is 1ms. 85 * cb_param : paramter pointer of co_timer_callback. 86 * cb : co_timer_callback. 87 * is_period : periodic or not. 88 **************************************************************************************** 89 */ 90 void co_timer_start(co_timer **timer, uint32_t duration, void *cb_param, co_timer_callback cb, uint32_t is_period); 91 /** 92 **************************************************************************************** 93 * @brief * co_timer_stop : cancel and delete co_timer . 94 * 95 * @param : timer : timer handler pointer. 96 * 97 **************************************************************************************** 98 */ 99 void co_timer_stop(co_timer *timer); 100 #if PLF_AON_SUPPORT 101 void co_timer_save(void); 102 103 void co_timer_restore(void); 104 #endif 105 uint32_t get_co_main_timer_min_duration(void); 106 #endif 107