1 /******************************************************************************
2 * Copyright (c) 2022 Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
3 * All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *****************************************************************************/
18 #pragma once
19
20 #include "analog.h"
21 #include "reg_include/mdec_reg.h"
22
23 /**
24 * @brief This function servers to reset the MDEC module.When the system is wakeup by MDEC, you should
25 * to reset the MDEC module to clear the flag bit of MDEC wakeup.
26 * @return none.
27 */
mdec_reset(void)28 static inline void mdec_reset(void)
29 {
30 analog_write_reg8(mdec_rst_addr, analog_read_reg8(mdec_rst_addr) | FLD_MDEC_RST);
31 analog_write_reg8(mdec_rst_addr, analog_read_reg8(mdec_rst_addr) & (~FLD_MDEC_RST));
32 }
33
34 /**
35 * @brief After all packet data are received, it can check whether packet transmission is finished.
36 * @param[in] status - the interrupt status to be obtained.
37 * @return irq status.
38 */
mdec_get_irq_status(wakeup_status_e status)39 static inline unsigned char mdec_get_irq_status(wakeup_status_e status)
40 {
41 return (analog_read_reg8(reg_wakeup_status) & status);
42 }
43
44 /**
45 * @brief This function serves to clear the wake mdec bit.After all packet
46 * data are received, corresponding flag bit will be set as 1.
47 * needed to manually clear this flag bit so as to avoid misjudgment.
48 * @param[in] status - the interrupt status that needs to be cleared.
49 * @return none.
50 */
mdec_clr_irq_status(wakeup_status_e status)51 static inline void mdec_clr_irq_status(wakeup_status_e status)
52 {
53 analog_write_reg8(reg_wakeup_status, (analog_read_reg8(reg_wakeup_status) | status));
54 }
55
56 /**
57 * @brief This function is used to initialize the MDEC module,include clock setting and input IO select.
58 * @param[in] pin - mdec pin.
59 * In order to distinguish which pin the data is input from,
60 * only one input pin can be selected one time.
61 * @return none.
62 */
63 void mdec_init(mdec_pin_e pin);
64
65 /**
66 * @brief This function is used to read the receive data of MDEC module's IO.
67 * @param[out] dat - The array to store date.
68 * @return 1 decode success, 0 decode failure.
69 */
70 unsigned char mdec_read_dat(unsigned char *dat);
71