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