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 
19 /********************************************************************************************************
20  * @file	mdec.h
21  *
22  * @brief	This is the header file for B91
23  *
24  * @author	Driver Group
25  *
26  *******************************************************************************************************/
27 #pragma once
28 
29 #include "analog.h"
30 #include "reg_include/mdec_reg.h"
31 
32 /**
33  * @brief		This function servers to reset the MDEC module.When the system is wakeup by MDEC, you should
34  * 			  	to reset the MDEC module to clear the flag bit of MDEC wakeup.
35  * @return		none.
36  */
mdec_reset(void)37 static inline void mdec_reset(void)
38 {
39 	analog_write_reg8(mdec_rst_addr,analog_read_reg8(mdec_rst_addr) | FLD_MDEC_RST);
40 	analog_write_reg8(mdec_rst_addr,analog_read_reg8(mdec_rst_addr) & (~FLD_MDEC_RST));
41 }
42 
43 /**
44  * @brief		After all packet data are received, it can check whether packet transmission is finished.
45  * @param[in]	status	- the interrupt status to be obtained.
46  * @return		irq status.
47  */
mdec_get_irq_status(wakeup_status_e status)48 static inline unsigned char mdec_get_irq_status(wakeup_status_e status)
49 {
50 	return (analog_read_reg8(reg_wakeup_status) & status);
51 }
52 
53 /**
54  * @brief		This function serves to clear the wake mdec bit.After all packet
55  *				data are received, corresponding flag bit will be set as 1.
56  *				needed to manually clear this flag bit so as to avoid misjudgment.
57  * @param[in]	status	- the interrupt status that needs to be cleared.
58  * @return		none.
59  */
mdec_clr_irq_status(wakeup_status_e status)60 static inline void mdec_clr_irq_status(wakeup_status_e status)
61 {
62 	analog_write_reg8(reg_wakeup_status, (analog_read_reg8(reg_wakeup_status) | status));
63 }
64 
65 /**
66  * @brief		This function is used to initialize the MDEC module,include clock setting and input IO select.
67  * @param[in]	pin	- mdec pin.
68  * 					  In order to distinguish which pin the data is input from,only one input pin can be selected one time.
69  * @return		none.
70  */
71 void mdec_init(mdec_pin_e pin);
72 
73 /**
74  * @brief		This function is used to read the receive data of MDEC module's IO.
75  * @param[out]	dat		- The array to store date.
76  * @return		1 decode success,  0 decode failure.
77  */
78 unsigned char mdec_read_dat(unsigned char *dat);
79 
80 
81 
82