1 /*!
2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
3 * All rights reserved.
4 *
5 * \file KW4xXcvrDrv.h
6 * This is a header file for the transceiver driver interface.
7 *
8 * Redistribution and use in source and binary forms, with or without modification,
9 * are permitted provided that the following conditions are met:
10 *
11 * o Redistributions of source code must retain the above copyright notice, this list
12 *   of conditions and the following disclaimer.
13 *
14 * o Redistributions in binary form must reproduce the above copyright notice, this
15 *   list of conditions and the following disclaimer in the documentation and/or
16 *   other materials provided with the distribution.
17 *
18 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
19 *   contributors may be used to endorse or promote products derived from this
20 *   software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
26 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33 
34 #ifndef __KW4X_XCVR_DRV_H__
35 #define __KW4X_XCVR_DRV_H__
36 
37 /*! *********************************************************************************
38 *************************************************************************************
39 * Include
40 *************************************************************************************
41 ********************************************************************************** */
42 #include "EmbeddedTypes.h"
43 #include "fsl_device_registers.h"
44 
45 /*! *********************************************************************************
46 *************************************************************************************
47 * Constants
48 *************************************************************************************
49 ********************************************************************************** */
50 #define channelMapTableSize (128)
51 
52 #define gPllDenom_c 0x02000000      /* Denominator is a constant value */
53 #define IQMCalibrationTrials (32)   /* Number of times the calibration is repeated & averaged */
54 #define IQMCalibrationIter (0x80)   /* Number of iterations per IQMC trial calibration */
55 #define ENGINEERING_TRIM_BYPASS (0) /* Forces Hardware DCOC calibration to run, regardless of presence of trims in IFR */
56 
57 /* ANA_SPARE Bit Fields */
58 #define XCVR_ANA_SPARE_HPM_LSB_INVERT_MASK       0xC000u
59 #define XCVR_ANA_SPARE_HPM_LSB_INVERT_SHIFT      14
60 #define XCVR_ANA_SPARE_HPM_LSB_INVERT_WIDTH      2
61 #define XCVR_ANA_SPARE_HPM_LSB_INVERT(x)         (((uint32_t)(((uint32_t)(x))<<XCVR_ANA_SPARE_HPM_LSB_INVERT_SHIFT))&XCVR_ANA_SPARE_HPM_LSB_INVERT_MASK)
62 
63 /*!
64  * @name Register XCVR_ANA_SPARE, field HPM_LSB_INVERT[15:14] (RW)
65  *
66  * Provides individual inversion settings for the two HPM LSB Array Units
67  */
68 /*@{*/
69 /*! @brief Read current value of the XCVR_ANA_SPARE_HPM_LSB_INVERT field. */
70 #define XCVR_RD_ANA_SPARE_HPM_LSB_INVERT(base) ((XCVR_ANA_SPARE_REG(base) & XCVR_ANA_SPARE_HPM_LSB_INVERT_MASK) >> XCVR_ANA_SPARE_HPM_LSB_INVERT_SHIFT)
71 #define XCVR_BRD_ANA_SPARE_HPM_LSB_INVERT(base) (BME_UBFX32(&XCVR_ANA_SPARE_REG(base), XCVR_ANA_SPARE_HPM_LSB_INVERT_SHIFT, XCVR_ANA_SPARE_HPM_LSB_INVERT_WIDTH))
72 
73 /*! @brief Set the HPM_LSB_INVERT field to a new value. */
74 #define XCVR_WR_ANA_SPARE_HPM_LSB_INVERT(base, value) (XCVR_RMW_ANA_SPARE(base, XCVR_ANA_SPARE_HPM_LSB_INVERT_MASK, XCVR_ANA_SPARE_HPM_LSB_INVERT(value)))
75 #define XCVR_BWR_ANA_SPARE_HPM_LSB_INVERT(base, value) (BME_BFI32(&XCVR_ANA_SPARE_REG(base), ((uint32_t)(value) << XCVR_ANA_SPARE_HPM_LSB_INVERT_SHIFT), XCVR_ANA_SPARE_HPM_LSB_INVERT_SHIFT, XCVR_ANA_SPARE_HPM_LSB_INVERT_WIDTH))
76 /*@}*/
77 
78 /*! *********************************************************************************
79 *************************************************************************************
80 * Public type definitions
81 *************************************************************************************
82 ********************************************************************************** */
83 typedef enum
84 {
85     gXcvrSuccess_c = 0,
86     gXcvrInvalidParameters_c,
87     gXcvrUnsupportedOperation_c
88 } xcvrStatus_t;
89 
90 typedef enum
91 {
92     NO_ERRORS = 0,
93     PLL_CTUNE_FAIL = 1,
94     PLL_CYCLE_SLIP_FAIL = 2,
95     PLL_FREQ_TARG_FAIL = 4,
96     PLL_TSM_ABORT_FAIL = 8,
97 } healthStatus_t;
98 
99 typedef struct pllChannel_tag
100 {
101     unsigned int integer;
102     unsigned int numerator;
103 } pllChannel_t;
104 
105 typedef enum
106 {
107     BLE = 0x00,
108     ZIGBEE = 0x01,
109     INVALID_MODE = 0xFF
110 } radio_mode_t;
111 
112 typedef enum
113 {
114     NONE = 0,
115     FAD_ENABLED = 1,
116     LPPS_ENABLED = 2
117 } FAD_LPPS_CTRL_T;
118 
119 typedef enum
120 {
121     WRONG_RADIO_ID_DETECTED = 1,
122     CALIBRATION_INVALID = 2,
123 } XCVR_PANIC_ID_T;
124 
125 typedef void (*panic_fptr)(uint32_t panic_id, uint32_t location, uint32_t extra1, uint32_t extra2);
126 
127 /*! *********************************************************************************
128 *************************************************************************************
129 * Public prototypes
130 *************************************************************************************
131 ********************************************************************************** */
132 #ifdef __cplusplus
133 extern "C" {
134 #endif
135 
136 /* Normal radio functions */
137 void XcvrInit ( radio_mode_t radioMode ); /* Full XCVR initialization for a radio mode */
138 xcvrStatus_t XcvrChangeMode ( radio_mode_t radioMode ); /* Change from one radio mode to another */
139 void XcvrEnaNBRSSIMeas( bool_t IIRnbEnable );
140 xcvrStatus_t XcvrOverrideFrequency ( uint32_t freq, uint32_t refOsc );
141 void XcvrRegisterPanicCb ( panic_fptr fptr ); /* allow upper layers to provide PANIC callback */
142 healthStatus_t XcvrHealthCheck ( void ); /* allow upper layers to poll the radio health */
143 void XcvrFadLppsControl(FAD_LPPS_CTRL_T control);
144 
145 /* Customer level trim functions */
146 xcvrStatus_t XcvrSetXtalTrim(int8_t xtalTrim);
147 int8_t  XcvrGetXtalTrim(void);
148 
149 /* Radio debug functions */
150 xcvrStatus_t XcvrSetGain ( uint8_t entry );
151 xcvrStatus_t XcvrOverrideChannel ( uint8_t channel, uint8_t useMappedChannel );
152 uint32_t XcvrGetFreq ( void );
153 void XcvrForceRxWu ( void );
154 void XcvrForceRxWd ( void );
155 void XcvrForceTxWu ( void );
156 void XcvrForceTxWd ( void );
157 void XcvrTxTest ( void );
158 void XcvrIQMCal ( void );       /* Manual IQ Mismatch Calibration */
159 void XcvrManualDCOCCal (uint8_t chnum); /* Allow tests to run multiple SW DC calibrations */
160 
161 #ifdef __cplusplus
162 }
163 #endif
164 
165 #endif /* __KW4X_XCVR_DRV_H__ */