1 /*! 2 * Copyright (c) 2015, Freescale Semiconductor, Inc. 3 * All rights reserved. 4 * 5 * \file ifr_mkw40z4_radio.h 6 * Header file for the MKW40Z4 Radio IFR bits handling. 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 __IFR_MKW40Z4_RADIO_H__ 35 #define __IFR_MKW40Z4_RADIO_H__ 36 37 /*! ********************************************************************************* 38 ************************************************************************************* 39 * Include 40 ************************************************************************************* 41 ********************************************************************************** */ 42 #include <stdint.h> 43 #include "EmbeddedTypes.h" 44 45 /*! ********************************************************************************* 46 ************************************************************************************* 47 * Macros 48 ************************************************************************************* 49 ********************************************************************************** */ 50 #define IFR_EOF_SYMBOL (0xFEED0E0F) /* Denotes the "End of File" for IFR data */ 51 #define IFR_VERSION_HDR (0xABCD0000) /* Constant value for upper 16 bits of IFR data header */ 52 #define IFR_VERSION_MASK (0x0000FFFF) /* Mask for version number (lower 16 bits) of IFR data header */ 53 #define IFR_SW_ID_MIN (0x00000000) /* Lower limit of SW trim IDs */ 54 #define IFR_SW_ID_MAX (0x0000FFFF) /* Lower limit of SW trim IDs */ 55 56 #define IS_A_SW_ID(x) ((IFR_SW_ID_MIN<x) && (IFR_SW_ID_MAX>=x)) 57 #define IS_VALID_REG_ADDR(x) (((x)&0xFFFF0000) == 0x40050000) /* Valid addresses are 0x4005xxxx */ 58 59 #define MAKE_MASK(size) ((1<<(size))-1) 60 #define MAKE_MASKSHFT(size,bitpos) (MAKE_MASK(size)<<bitpos) 61 #define RDRSRC 0x03 62 63 #define IFR_TZA_CAP_TUNE_MASK (0x0000000F) 64 #define IFR_TZA_CAP_TUNE_SHIFT (0) 65 #define IFR_BBF_CAP_TUNE_MASK (0x000F0000) 66 #define IFR_BBF_CAP_TUNE_SHIFT (16) 67 #define IFR_RES_TUNE2_MASK (0x00F00000) 68 #define IFR_RES_TUNE2_SHIFT (20) 69 70 /*! ********************************************************************************* 71 ************************************************************************************* 72 * Enums 73 ************************************************************************************* 74 ********************************************************************************** */ 75 76 /*! ********************************************************************************* 77 * \var typedef uint8_t IFR_ERROR_T 78 * 79 * \brief The IFR error reporting type. 80 * 81 * See #IFR_ERROR_T_enum for the enumeration definitions. 82 * 83 ********************************************************************************** */ 84 typedef uint8_t IFR_ERROR_T; 85 86 /*! ********************************************************************************* 87 * \brief The enumerations used to describe IFR errors. 88 * 89 ********************************************************************************** */ 90 enum IFR_ERROR_T_enum 91 { 92 IFR_SUCCESS = 0, 93 INVALID_POINTER = 1, /* NULL pointer error */ 94 INVALID_DEST_SIZE_SHIFT = 2, /* The bits won't fit as specified in the destination */ 95 }; 96 97 /*! ********************************************************************************* 98 * \var typedef uint16_t SW_TRIM_ID_T 99 * 100 * \brief The SW trim ID type. 101 * 102 * See #SW_TRIM_ID_T_enum for the enumeration definitions. 103 * 104 ********************************************************************************** */ 105 typedef uint16_t SW_TRIM_ID_T; 106 107 /*! ********************************************************************************* 108 * \brief The enumerations used to define SW trim IDs. 109 * 110 ********************************************************************************** */ 111 enum SW_TRIM_ID_T_enum 112 { 113 Q_RELATIVE_GAIN_BY_PART = 0, /* Q vs I relative gain trim ID */ 114 ADC_GAIN = 1, /* ADC gain trim ID */ 115 ZB_FILT_TRIM = 2, /* Baseband Bandwidth filter trim ID for BLE */ 116 BLE_FILT_TRIM = 3, /* Baseband Bandwidth filter trim ID for BLE */ 117 TRIM_STATUS = 4, /* Status result of the trim process (error indications) */ 118 TRIM_VERSION = 0xABCD, /* Version number of the IFR trim algorithm/format. */ 119 }; 120 121 /*! ********************************************************************************* 122 * \var typedef uint32_t IFR_TRIM_STATUS_T 123 * 124 * \brief The definition of failure bits stored in IFR trim status word. 125 * 126 * See #IFR_TRIM_STATUS_T_enum for the enumeration definitions. 127 * 128 ********************************************************************************** */ 129 typedef uint32_t IFR_TRIM_STATUS_T; 130 131 /*! ********************************************************************************* 132 * \brief The enumerations used to describe trim algorithm failures in the status entry in IFR. 133 * This enum represents multiple values which can be OR'd together in a single status word. 134 * 135 ********************************************************************************** */ 136 enum IFR_TRIM_STATUS_T_enum 137 { 138 TRIM_ALGORITHM_SUCCESS = 0, 139 BGAP_VOLTAGE_TRIM_FAILED = 1, /* Algorithm failure in BGAP voltagetrim */ 140 IQMC_GAIN_ADJ_FAILED = 2, /* Algorithm failure in IQMC gain trim */ 141 IQMC_PHASE_ADJ_FAILED = 4, /* Algorithm failure in IQMC phase trim */ 142 IQMC_DC_GAIN_ADJ_FAILED = 8, 143 ADC_GAIN_TRIM_FAILED = 10, 144 ZB_FILT_TRIM_FAILED = 20, 145 BLE_FILT_TRIM_FAILED = 40, 146 }; 147 148 /*! ********************************************************************************* 149 ************************************************************************************* 150 * Structures 151 ************************************************************************************* 152 ********************************************************************************** */ 153 154 /*! ********************************************************************************* 155 * \var typedef struct IFR_SW_TRIM_TBL_ENTRY_T 156 * 157 * \brief Structure defining an entry in a table used to contain values to be passed back from IFR 158 * handling routine to XCVR driver software. 159 * 160 ********************************************************************************** */ 161 typedef struct 162 { 163 SW_TRIM_ID_T trim_id; /* The assigned ID */ 164 uint32_t trim_value; /* The value fetched from IFR. */ 165 uint8_t valid; /* Validity of the trim_value field after IFR processing is complete (TRUE/FALSE). */ 166 } IFR_SW_TRIM_TBL_ENTRY_T; 167 168 /*! ********************************************************************************* 169 ************************************************************************************* 170 * Public prototypes 171 ************************************************************************************* 172 ********************************************************************************** */ 173 uint32_t read_resource_ifr(uint32_t read_addr); /* Reads IFR and it appropriate location */ 174 uint32_t read_resource(uint16_t resource_id); 175 void handle_ifr(IFR_SW_TRIM_TBL_ENTRY_T * sw_trim_tbl, uint16_t num_entries); 176 uint32_t handle_ifr_die_id(void); 177 uint32_t handle_ifr_die_kw_type(void); 178 void dump_ifr(uint32_t * dump_tbl, uint8_t num_entries); 179 180 #endif /* __IFR_MKW40Z4_RADIO_H__ */