a752c7ab
elopes
add first test an...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
/*
* Copyright (C) 2016 Phytec Messtechnik GmbH
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup drivers_kw2xrf
* @{
*
* @file
* @brief Testing function of kw2xrf driver
*
* @author Johann Fischer <j.fischer@phytec.de>
*/
#include "kw2xrf.h"
#include "kw2xrf_spi.h"
#include "kw2xrf_reg.h"
#include "kw2xrf_tm.h"
#ifdef KW2XRF_TESTMODE
inline static void enable_xcvr_test_mode(kw2xrf_t *dev)
{
uint8_t reg;
kw2xrf_read_iregs(dev, MKW2XDMI_DTM_CTRL1, ®, 1);
reg |= MKW2XDMI_DTM_CTRL1_DTM_EN;
kw2xrf_write_iregs(dev, MKW2XDMI_DTM_CTRL1, ®, 1);
kw2xrf_read_iregs(dev, MKW2XDMI_TESTMODE_CTRL, ®, 1);
reg |= MKW2XDMI_TESTMODE_CTRL_CONTINUOUS_EN | MKW2XDMI_TESTMODE_CTRL_IDEAL_PFC_EN;
kw2xrf_write_iregs(dev, MKW2XDMI_TESTMODE_CTRL, ®, 1);
}
inline static void disable_xcvr_test_mode(kw2xrf_t *dev)
{
uint8_t reg;
kw2xrf_read_iregs(dev, MKW2XDMI_DTM_CTRL1, ®, 1);
reg &= MKW2XDMI_DTM_CTRL1_DTM_EN;
kw2xrf_write_iregs(dev, MKW2XDMI_DTM_CTRL1, ®, 1);
kw2xrf_read_iregs(dev, MKW2XDMI_TESTMODE_CTRL, ®, 1);
reg &= ~(MKW2XDMI_TESTMODE_CTRL_CONTINUOUS_EN | MKW2XDMI_TESTMODE_CTRL_IDEAL_PFC_EN);
kw2xrf_write_iregs(dev, MKW2XDMI_TESTMODE_CTRL, ®, 1);
}
int kw2xrf_set_test_mode(kw2xrf_t *dev, uint8_t mode)
{
uint8_t reg = 0;
uint8_t buf[2];
kw2xrf_abort_sequence(dev);
disable_xcvr_test_mode(dev);
kw2xrf_set_channel(dev, dev->netdev.chan);
switch(mode) {
case NETOPT_RF_TESTMODE_IDLE:
reg = 0;
kw2xrf_write_iregs(dev, MKW2XDMI_TX_MODE_CTRL, ®, 1);
kw2xrf_set_sequence(dev, XCVSEQ_IDLE);
break;
case NETOPT_RF_TESTMODE_CRX:
/* set continuous RX mode */
reg = 0;
kw2xrf_write_iregs(dev, MKW2XDMI_TX_MODE_CTRL, ®, 1);
enable_xcvr_test_mode(dev);
/* set data length */
reg = 127;
kw2xrf_write_iregs(dev, MKW2XDMI_DUAL_PAN_DWELL, ®, 1);
kw2xrf_set_sequence(dev, XCVSEQ_RECEIVE);
break;
case KW2XRF_TM_CTX_PREAMBLE:
/* set continuous TX mode, transmit 10101010 pattern */
reg = 0;
kw2xrf_write_iregs(dev, MKW2XDMI_TX_MODE_CTRL, ®, 1);
enable_xcvr_test_mode(dev);
buf[0] = 1;
buf[1] = 0xaa;
kw2xrf_write_fifo(dev, buf, buf[0] + 1);
kw2xrf_set_sequence(dev, XCVSEQ_TRANSMIT);
break;
case NETOPT_RF_TESTMODE_CTX_CW:
/* set continuous TX mode, transmit unmodulated carrier */
reg = MKW2XDMI_TX_MODE_CTRL_DTS0;
kw2xrf_write_iregs(dev, MKW2XDMI_TX_MODE_CTRL, ®, 1);
enable_xcvr_test_mode(dev);
/* fix pll frequency for cw mode */
uint16_t pll_frac = kw2xrf_read_dreg(dev, MKW2XDM_PLL_FRAC0_LSB);
pll_frac |= ((uint16_t)kw2xrf_read_dreg(dev, MKW2XDM_PLL_FRAC0_MSB) << 8);
pll_frac -= 0x400;
kw2xrf_write_dreg(dev, MKW2XDM_PLL_FRAC0_LSB, (uint8_t)pll_frac);
kw2xrf_write_dreg(dev, MKW2XDM_PLL_FRAC0_MSB, (uint8_t)(pll_frac >> 8));
kw2xrf_set_sequence(dev, XCVSEQ_TRANSMIT);
break;
case KW2XRF_TM_CTX_NM1:
/* set continuous TX mode */
reg = MKW2XDMI_TX_MODE_CTRL_DTS0;
kw2xrf_write_iregs(dev, MKW2XDMI_TX_MODE_CTRL, ®, 1);
enable_xcvr_test_mode(dev);
kw2xrf_set_sequence(dev, XCVSEQ_TRANSMIT);
break;
case KW2XRF_TM_CTX_NM0:
/* set continuous TX mode */
reg = MKW2XDMI_TX_MODE_CTRL_DTS1;
kw2xrf_write_iregs(dev, MKW2XDMI_TX_MODE_CTRL, ®, 1);
enable_xcvr_test_mode(dev);
kw2xrf_set_sequence(dev, XCVSEQ_TRANSMIT);
break;
case KW2XRF_TM_CTX_2MHZ:
/* set continuous TX mode */
reg = MKW2XDMI_TX_MODE_CTRL_DTS1 | MKW2XDMI_TX_MODE_CTRL_DTS0;
kw2xrf_write_iregs(dev, MKW2XDMI_TX_MODE_CTRL, ®, 1);
enable_xcvr_test_mode(dev);
kw2xrf_set_sequence(dev, XCVSEQ_TRANSMIT);
break;
case KW2XRF_TM_CTX_200KHZ:
/* set continuous TX mode */
reg = MKW2XDMI_TX_MODE_CTRL_DTS2;
kw2xrf_write_iregs(dev, MKW2XDMI_TX_MODE_CTRL, ®, 1);
enable_xcvr_test_mode(dev);
kw2xrf_set_sequence(dev, XCVSEQ_TRANSMIT);
break;
case KW2XRF_TM_CTX_1MBPS_PRBS9:
/* set continuous TX mode, transmit PRBS9 pattern */
reg = MKW2XDMI_TX_MODE_CTRL_DTS2 | MKW2XDMI_TX_MODE_CTRL_DTS0;
kw2xrf_write_iregs(dev, MKW2XDMI_TX_MODE_CTRL, ®, 1);
enable_xcvr_test_mode(dev);
kw2xrf_set_sequence(dev, XCVSEQ_TRANSMIT);
break;
case KW2XRF_TM_CTX_EXT:
/* set continuous TX mode */
reg = MKW2XDMI_TX_MODE_CTRL_DTS2 | MKW2XDMI_TX_MODE_CTRL_DTS1;
kw2xrf_write_iregs(dev, MKW2XDMI_TX_MODE_CTRL, ®, 1);
enable_xcvr_test_mode(dev);
kw2xrf_set_sequence(dev, XCVSEQ_TRANSMIT);
break;
case NETOPT_RF_TESTMODE_CTX_PRBS9:
/* set continuous TX mode, transmit PRBS9 pattern */
reg = MKW2XDMI_TX_MODE_CTRL_DTS2 | MKW2XDMI_TX_MODE_CTRL_DTS1
| MKW2XDMI_TX_MODE_CTRL_DTS0;
kw2xrf_write_iregs(dev, MKW2XDMI_TX_MODE_CTRL, ®, 1);
enable_xcvr_test_mode(dev);
kw2xrf_set_sequence(dev, XCVSEQ_TRANSMIT);
break;
}
return 1;
}
#endif
/** @} */
|