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	emi.h
21  *
22  * @brief	This is the header file for B91
23  *
24  * @author	Driver Group
25  *
26  *******************************************************************************************************/
27 #ifndef  EMI_H_
28 #define  EMI_H_
29 
30 #include "rf.h"
31 
32 /**********************************************************************************************************************
33  *                                           global macro                                                             *
34  *********************************************************************************************************************/
35 #define EMI_ACCESS_ADDR                      0x140808
36 #define EMI_ACCESS_CODE                      0x29417671
37 
38 /**********************************************************************************************************************
39  *                                         function declaration                                                    *
40  *********************************************************************************************************************/
41 
42 /**
43  * @brief      This function serves to set singletone power and channel
44  * @param[in]  power_level - the power level.
45  * @param[in]  rf_chn      - the channel.
46  * @return     none
47  */
48 void rf_emi_tx_single_tone(rf_power_level_e power_level,signed char rf_chn);
49 
50 /**
51  * @brief      This function serves to set rx mode and channel
52  * @param[in]  mode   - mode of RF.
53  * @param[in]  rf_chn - the rx channel.
54  * @return     none
55  */
56 void rf_emi_rx_setup(rf_mode_e mode,signed char rf_chn);
57 
58 /**
59  * @brief    This function serves to update the number of receiving packet and the RSSI
60  * @return   none
61  */
62 void rf_emi_rx_loop(void);
63 
64 /**
65  * @brief    This function serves to stop emi/(close RF)
66  * @return   none
67  */
68 void rf_emi_stop(void);
69 
70 /**
71  * @brief    This function serves to get the number of packets received.
72  * @return   the number of packets received.
73  */
74 unsigned int rf_emi_get_rxpkt_cnt(void);
75 
76 /**
77  * @brief    This function serves to get the RSSI of packets received
78  * @return   the RSSI of packets received
79  */
80 char rf_emi_get_rssi_avg(void);
81 
82 
83 /**
84  * @brief      This function serves to set the CD mode correlation register
85  * @return     none
86  */
87 void rf_emi_tx_continue_setup(void);
88 
89 /**
90  * @brief      This function serves to update the CD mode data.
91  * @param[in]  rf_mode     - mode of RF.
92  * @param[in]  power_level - power level of RF.
93  * @param[in]  rf_chn      - channel of RF.
94  * @param[in]  pkt_type    - The type of data sent.
95  * -#0:random
96  * -#1:0xf0
97  * -#2:0x55
98  * @return     none
99  */
100 void rf_emi_tx_continue_update_data(rf_mode_e rf_mode,rf_power_level_e power_level,signed char rf_chn,unsigned char pkt_type);
101 
102 /**
103  * @brief      This function serves to continue to run the CD mode
104  * @return     none
105  */
106 void rf_continue_mode_run(void);
107 
108 /**
109  * @brief      This function serves to send packets in the burst mode
110  * @param[in]  rf_mode  - mode of RF.
111  * @param[in]  pkt_type - The type of data sent.
112  * -#0:random
113  * -#1:0xf0
114  * -#2:0x55
115  * @return     none
116  */
117 void rf_emi_tx_burst_loop(rf_mode_e rf_mode,unsigned char pkt_type);
118 
119 /**
120  * @brief      This function serves to set the burst mode
121  * @param[in]  rf_mode     - mode of RF.
122  * @param[in]  power_level - power level of RF.
123  * @param[in]  rf_chn      - channel of RF.
124  * @param[in]  pkt_type    - The type of data sent.
125  * -#0:random
126  * -#1:0xf0
127  * -#2:0x55
128  * @return     none
129  */
130 void rf_emi_tx_burst_setup(rf_mode_e rf_mode,rf_power_level_e power_level,signed char rf_chn,unsigned char pkt_type);
131 
132 /**
133  * @brief      This function serves to generate random packets that need to be sent in burst mode
134  * @param[in] *p - the address of random packets.
135  * @param[in]  n - the number of random packets.
136  * @return     none
137  */
138 void rf_phy_test_prbs9 (unsigned char *p, int n);
139 
140 /**
141  * @brief      This function serves to reset baseband.
142  * @return     none
143  */
144 void rf_emi_reset_baseband(void);
145 
146 /**
147  * @brief      This function serves to generate random number.
148  * @param[in]  state - the old random number.
149  * @return     the new random number
150  */
151 unsigned int emi_pn_gen(unsigned int state);
152 #endif
153