mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Thu Apr 03 11:45:06 2014 +0100
Revision:
149:1fb5f62b92bd
Parent:
targets/hal/TARGET_Freescale/TARGET_KSDK_MCUS/TARGET_KSDK_CODE/hal/i2c/fsl_i2c_hal.c@146:f64d43ff0c18
Child:
324:406fd2029f23
Synchronized with git revision 220c0bb39ceee40016e1e86350c058963d01ed42

Full URL: https://github.com/mbedmicro/mbed/commit/220c0bb39ceee40016e1e86350c058963d01ed42/

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 146:f64d43ff0c18 1 /*
mbed_official 146:f64d43ff0c18 2 * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
mbed_official 146:f64d43ff0c18 3 * All rights reserved.
mbed_official 146:f64d43ff0c18 4 *
mbed_official 146:f64d43ff0c18 5 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 146:f64d43ff0c18 6 * are permitted provided that the following conditions are met:
mbed_official 146:f64d43ff0c18 7 *
mbed_official 146:f64d43ff0c18 8 * o Redistributions of source code must retain the above copyright notice, this list
mbed_official 146:f64d43ff0c18 9 * of conditions and the following disclaimer.
mbed_official 146:f64d43ff0c18 10 *
mbed_official 146:f64d43ff0c18 11 * o Redistributions in binary form must reproduce the above copyright notice, this
mbed_official 146:f64d43ff0c18 12 * list of conditions and the following disclaimer in the documentation and/or
mbed_official 146:f64d43ff0c18 13 * other materials provided with the distribution.
mbed_official 146:f64d43ff0c18 14 *
mbed_official 146:f64d43ff0c18 15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
mbed_official 146:f64d43ff0c18 16 * contributors may be used to endorse or promote products derived from this
mbed_official 146:f64d43ff0c18 17 * software without specific prior written permission.
mbed_official 146:f64d43ff0c18 18 *
mbed_official 146:f64d43ff0c18 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
mbed_official 146:f64d43ff0c18 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
mbed_official 146:f64d43ff0c18 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 146:f64d43ff0c18 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
mbed_official 146:f64d43ff0c18 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
mbed_official 146:f64d43ff0c18 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
mbed_official 146:f64d43ff0c18 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
mbed_official 146:f64d43ff0c18 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
mbed_official 146:f64d43ff0c18 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
mbed_official 146:f64d43ff0c18 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 146:f64d43ff0c18 29 */
mbed_official 146:f64d43ff0c18 30
mbed_official 146:f64d43ff0c18 31 #include "fsl_i2c_hal.h"
mbed_official 146:f64d43ff0c18 32
mbed_official 146:f64d43ff0c18 33 /* Computes the number of elements in an array.*/
mbed_official 146:f64d43ff0c18 34 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
mbed_official 146:f64d43ff0c18 35
mbed_official 146:f64d43ff0c18 36 /*******************************************************************************
mbed_official 146:f64d43ff0c18 37 * Definitions
mbed_official 146:f64d43ff0c18 38 ******************************************************************************/
mbed_official 146:f64d43ff0c18 39
mbed_official 146:f64d43ff0c18 40 /*! @brief An entry in the I2C divider table.*/
mbed_official 146:f64d43ff0c18 41 /*!*/
mbed_official 146:f64d43ff0c18 42 /*! This struct pairs the value of the I2C_F.ICR bitfield with the resulting*/
mbed_official 146:f64d43ff0c18 43 /*! clock divider value.*/
mbed_official 146:f64d43ff0c18 44 typedef struct I2CDividerTableEntry {
mbed_official 146:f64d43ff0c18 45 uint8_t icr; /*!< F register ICR value.*/
mbed_official 146:f64d43ff0c18 46 uint16_t sclDivider; /*!< SCL clock divider.*/
mbed_official 146:f64d43ff0c18 47 } i2c_divider_table_entry_t;
mbed_official 146:f64d43ff0c18 48
mbed_official 146:f64d43ff0c18 49 /*******************************************************************************
mbed_official 146:f64d43ff0c18 50 * Variables
mbed_official 146:f64d43ff0c18 51 ******************************************************************************/
mbed_official 146:f64d43ff0c18 52
mbed_official 146:f64d43ff0c18 53 /*! @brief I2C divider values.*/
mbed_official 146:f64d43ff0c18 54 /*!*/
mbed_official 146:f64d43ff0c18 55 /*! This table is taken from the I2C Divider and Hold values section of the*/
mbed_official 146:f64d43ff0c18 56 /*! reference manual. In the original table there are, in some cases, multiple*/
mbed_official 146:f64d43ff0c18 57 /*! entries with the same divider but different hold values. This table*/
mbed_official 146:f64d43ff0c18 58 /*! includes only one entry for every divider, selecting the lowest hold value.*/
mbed_official 146:f64d43ff0c18 59 const i2c_divider_table_entry_t kI2CDividerTable[] = {
mbed_official 146:f64d43ff0c18 60 /* ICR Divider*/
mbed_official 146:f64d43ff0c18 61 { 0x00, 20 },
mbed_official 146:f64d43ff0c18 62 { 0x01, 22 },
mbed_official 146:f64d43ff0c18 63 { 0x02, 24 },
mbed_official 146:f64d43ff0c18 64 { 0x03, 26 },
mbed_official 146:f64d43ff0c18 65 { 0x04, 28 },
mbed_official 146:f64d43ff0c18 66 { 0x05, 30 },
mbed_official 146:f64d43ff0c18 67 { 0x09, 32 },
mbed_official 146:f64d43ff0c18 68 { 0x06, 34 },
mbed_official 146:f64d43ff0c18 69 { 0x0a, 36 },
mbed_official 146:f64d43ff0c18 70 { 0x07, 40 },
mbed_official 146:f64d43ff0c18 71 { 0x0c, 44 },
mbed_official 146:f64d43ff0c18 72 { 0x0d, 48 },
mbed_official 146:f64d43ff0c18 73 { 0x0e, 56 },
mbed_official 146:f64d43ff0c18 74 { 0x12, 64 },
mbed_official 146:f64d43ff0c18 75 { 0x0f, 68 },
mbed_official 146:f64d43ff0c18 76 { 0x13, 72 },
mbed_official 146:f64d43ff0c18 77 { 0x14, 80 },
mbed_official 146:f64d43ff0c18 78 { 0x15, 88 },
mbed_official 146:f64d43ff0c18 79 { 0x19, 96 },
mbed_official 146:f64d43ff0c18 80 { 0x16, 104 },
mbed_official 146:f64d43ff0c18 81 { 0x1a, 112 },
mbed_official 146:f64d43ff0c18 82 { 0x17, 128 },
mbed_official 146:f64d43ff0c18 83 { 0x1c, 144 },
mbed_official 146:f64d43ff0c18 84 { 0x1d, 160 },
mbed_official 146:f64d43ff0c18 85 { 0x1e, 192 },
mbed_official 146:f64d43ff0c18 86 { 0x22, 224 },
mbed_official 146:f64d43ff0c18 87 { 0x1f, 240 },
mbed_official 146:f64d43ff0c18 88 { 0x23, 256 },
mbed_official 146:f64d43ff0c18 89 { 0x24, 288 },
mbed_official 146:f64d43ff0c18 90 { 0x25, 320 },
mbed_official 146:f64d43ff0c18 91 { 0x26, 384 },
mbed_official 146:f64d43ff0c18 92 { 0x2a, 448 },
mbed_official 146:f64d43ff0c18 93 { 0x27, 480 },
mbed_official 146:f64d43ff0c18 94 { 0x2b, 512 },
mbed_official 146:f64d43ff0c18 95 { 0x2c, 576 },
mbed_official 146:f64d43ff0c18 96 { 0x2d, 640 },
mbed_official 146:f64d43ff0c18 97 { 0x2e, 768 },
mbed_official 146:f64d43ff0c18 98 { 0x32, 896 },
mbed_official 146:f64d43ff0c18 99 { 0x2f, 960 },
mbed_official 146:f64d43ff0c18 100 { 0x33, 1024 },
mbed_official 146:f64d43ff0c18 101 { 0x34, 1152 },
mbed_official 146:f64d43ff0c18 102 { 0x35, 1280 },
mbed_official 146:f64d43ff0c18 103 { 0x36, 1536 },
mbed_official 146:f64d43ff0c18 104 { 0x3a, 1792 },
mbed_official 146:f64d43ff0c18 105 { 0x37, 1920 },
mbed_official 146:f64d43ff0c18 106 { 0x3b, 2048 },
mbed_official 146:f64d43ff0c18 107 { 0x3c, 2304 },
mbed_official 146:f64d43ff0c18 108 { 0x3d, 2560 },
mbed_official 146:f64d43ff0c18 109 { 0x3e, 3072 },
mbed_official 146:f64d43ff0c18 110 { 0x3f, 3840 }
mbed_official 146:f64d43ff0c18 111 };
mbed_official 146:f64d43ff0c18 112
mbed_official 146:f64d43ff0c18 113 /*******************************************************************************
mbed_official 146:f64d43ff0c18 114 * Code
mbed_official 146:f64d43ff0c18 115 ******************************************************************************/
mbed_official 146:f64d43ff0c18 116
mbed_official 146:f64d43ff0c18 117 /* Documentation for this function is in fsl_i2c_hal.h.*/
mbed_official 146:f64d43ff0c18 118 void i2c_hal_init(uint32_t instance, const i2c_config_t * config, uint32_t sourceClockInHz)
mbed_official 146:f64d43ff0c18 119 {
mbed_official 146:f64d43ff0c18 120 assert(config);
mbed_official 146:f64d43ff0c18 121
mbed_official 146:f64d43ff0c18 122 /* Enable module if requested.*/
mbed_official 146:f64d43ff0c18 123 if (config->enableModule)
mbed_official 146:f64d43ff0c18 124 {
mbed_official 146:f64d43ff0c18 125 i2c_hal_enable(instance);
mbed_official 146:f64d43ff0c18 126 }
mbed_official 146:f64d43ff0c18 127 else
mbed_official 146:f64d43ff0c18 128 {
mbed_official 146:f64d43ff0c18 129 i2c_hal_disable(instance);
mbed_official 146:f64d43ff0c18 130 }
mbed_official 146:f64d43ff0c18 131
mbed_official 146:f64d43ff0c18 132 /* Set baud rate if nonzero.*/
mbed_official 146:f64d43ff0c18 133 if (config->baudRate_kbps)
mbed_official 146:f64d43ff0c18 134 {
mbed_official 146:f64d43ff0c18 135 i2c_hal_set_baud(instance, sourceClockInHz, config->baudRate_kbps, NULL);
mbed_official 146:f64d43ff0c18 136 }
mbed_official 146:f64d43ff0c18 137
mbed_official 146:f64d43ff0c18 138 /* Configure miscellaneous options.*/
mbed_official 146:f64d43ff0c18 139 i2c_hal_set_independent_slave_baud(instance, config->useIndependentSlaveBaud);
mbed_official 146:f64d43ff0c18 140 i2c_hal_set_dma_enable(instance, config->enableDma);
mbed_official 146:f64d43ff0c18 141 i2c_hal_set_high_drive(instance, config->enableHighDrive);
mbed_official 146:f64d43ff0c18 142 i2c_hal_set_wakeup_enable(instance, config->enableWakeup);
mbed_official 146:f64d43ff0c18 143 i2c_hal_set_glitch_filter(instance, config->glitchFilterWidth);
mbed_official 146:f64d43ff0c18 144
mbed_official 146:f64d43ff0c18 145 /* Configure the slave address options.*/
mbed_official 146:f64d43ff0c18 146 if (config->use10bitSlaveAddress)
mbed_official 146:f64d43ff0c18 147 {
mbed_official 146:f64d43ff0c18 148 i2c_hal_set_slave_address_10bit(instance, config->slaveAddress);
mbed_official 146:f64d43ff0c18 149 }
mbed_official 146:f64d43ff0c18 150 else
mbed_official 146:f64d43ff0c18 151 {
mbed_official 146:f64d43ff0c18 152 i2c_hal_set_slave_address_7bit(instance, (uint8_t)((config->slaveAddress) & 0xff));
mbed_official 146:f64d43ff0c18 153 }
mbed_official 146:f64d43ff0c18 154
mbed_official 146:f64d43ff0c18 155 i2c_hal_set_general_call_enable(instance, config->enableGeneralCallAddress);
mbed_official 146:f64d43ff0c18 156 i2c_hal_set_slave_range_address_enable(instance, config->enableRangeAddressMatch);
mbed_official 146:f64d43ff0c18 157
mbed_official 146:f64d43ff0c18 158 /* Enable or disable the I2C interrupt.*/
mbed_official 146:f64d43ff0c18 159 if (config->enableInterrupt)
mbed_official 146:f64d43ff0c18 160 {
mbed_official 146:f64d43ff0c18 161 i2c_hal_enable_interrupt(instance);
mbed_official 146:f64d43ff0c18 162 }
mbed_official 146:f64d43ff0c18 163 else
mbed_official 146:f64d43ff0c18 164 {
mbed_official 146:f64d43ff0c18 165 i2c_hal_disable_interrupt(instance);
mbed_official 146:f64d43ff0c18 166 }
mbed_official 146:f64d43ff0c18 167
mbed_official 146:f64d43ff0c18 168 /* Configure stop detect related features.*/
mbed_official 146:f64d43ff0c18 169 #if FSL_FEATURE_I2C_HAS_STOP_DETECT
mbed_official 146:f64d43ff0c18 170 #if FSL_FEATURE_I2C_HAS_STOP_HOLD_OFF
mbed_official 146:f64d43ff0c18 171 i2c_hal_set_stop_holdoff(instance, config->enableStopModeHoldoff);
mbed_official 146:f64d43ff0c18 172 #endif /* FSL_FEATURE_I2C_HAS_STOP_HOLD_OFF*/
mbed_official 146:f64d43ff0c18 173
mbed_official 146:f64d43ff0c18 174 if (config->enableBusStopInterrupt)
mbed_official 146:f64d43ff0c18 175 {
mbed_official 146:f64d43ff0c18 176 i2c_hal_enable_bus_stop_interrupt(instance);
mbed_official 146:f64d43ff0c18 177 }
mbed_official 146:f64d43ff0c18 178 else
mbed_official 146:f64d43ff0c18 179 {
mbed_official 146:f64d43ff0c18 180 i2c_hal_disable_bus_stop_interrupt(instance);
mbed_official 146:f64d43ff0c18 181 }
mbed_official 146:f64d43ff0c18 182 #endif /* FSL_FEATURE_I2C_HAS_STOP_DETECT*/
mbed_official 146:f64d43ff0c18 183 }
mbed_official 146:f64d43ff0c18 184
mbed_official 146:f64d43ff0c18 185 /* Documentation for this function is in fsl_i2c_hal.h.*/
mbed_official 146:f64d43ff0c18 186 void i2c_hal_reset(uint32_t instance)
mbed_official 146:f64d43ff0c18 187 {
mbed_official 146:f64d43ff0c18 188 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 189
mbed_official 146:f64d43ff0c18 190 HW_I2C_A1_WR(instance, 0u);
mbed_official 146:f64d43ff0c18 191 HW_I2C_F_WR(instance, 0u);
mbed_official 146:f64d43ff0c18 192 HW_I2C_C1_WR(instance, 0u);
mbed_official 146:f64d43ff0c18 193 HW_I2C_S_WR(instance, 0u);
mbed_official 146:f64d43ff0c18 194 HW_I2C_D_WR(instance, 0u);
mbed_official 146:f64d43ff0c18 195 HW_I2C_C2_WR(instance, 0u);
mbed_official 146:f64d43ff0c18 196 HW_I2C_FLT_WR(instance, 0u);
mbed_official 146:f64d43ff0c18 197 HW_I2C_RA_WR(instance, 0u);
mbed_official 146:f64d43ff0c18 198
mbed_official 146:f64d43ff0c18 199 #if FSL_FEATURE_I2C_HAS_SMBUS
mbed_official 146:f64d43ff0c18 200 HW_I2C_SMB_WR(instance, 0u);
mbed_official 146:f64d43ff0c18 201 HW_I2C_A2_WR(instance, 0xc2u);
mbed_official 146:f64d43ff0c18 202 HW_I2C_SLTH_WR(instance, 0u);
mbed_official 146:f64d43ff0c18 203 HW_I2C_SLTL_WR(instance, 0u);
mbed_official 146:f64d43ff0c18 204 #endif /* FSL_FEATURE_I2C_HAS_SMBUS*/
mbed_official 146:f64d43ff0c18 205 }
mbed_official 146:f64d43ff0c18 206
mbed_official 146:f64d43ff0c18 207 /* Documentation for this function is in fsl_i2c_hal.h.*/
mbed_official 146:f64d43ff0c18 208 uint32_t i2c_hal_get_max_baud(uint32_t instance, uint32_t sourceClockInHz)
mbed_official 146:f64d43ff0c18 209 {
mbed_official 146:f64d43ff0c18 210 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 211
mbed_official 146:f64d43ff0c18 212 return (sourceClockInHz / (1U * 20U)) / 1000;
mbed_official 146:f64d43ff0c18 213 }
mbed_official 146:f64d43ff0c18 214
mbed_official 146:f64d43ff0c18 215 /* Documentation for this function is in fsl_i2c_hal.h.*/
mbed_official 146:f64d43ff0c18 216 i2c_status_t i2c_hal_set_baud(uint32_t instance, uint32_t sourceClockInHz, uint32_t kbps,
mbed_official 146:f64d43ff0c18 217 uint32_t * absoluteError_Hz)
mbed_official 146:f64d43ff0c18 218 {
mbed_official 146:f64d43ff0c18 219 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 220
mbed_official 146:f64d43ff0c18 221 /* Check if the requested frequency is greater than the max supported baud.*/
mbed_official 146:f64d43ff0c18 222 if ((kbps * 1000U) > (sourceClockInHz / (1U * 20U)))
mbed_official 146:f64d43ff0c18 223 {
mbed_official 146:f64d43ff0c18 224 return kStatus_I2C_OutOfRange;
mbed_official 146:f64d43ff0c18 225 }
mbed_official 146:f64d43ff0c18 226
mbed_official 146:f64d43ff0c18 227 uint32_t mult;
mbed_official 146:f64d43ff0c18 228 uint32_t hz = kbps * 1000u;
mbed_official 146:f64d43ff0c18 229 uint32_t bestError = 0xffffffffu;
mbed_official 146:f64d43ff0c18 230 uint32_t bestMult = 0u;
mbed_official 146:f64d43ff0c18 231 uint32_t bestIcr = 0u;
mbed_official 146:f64d43ff0c18 232
mbed_official 146:f64d43ff0c18 233 /* Search for the settings with the lowest error.*/
mbed_official 146:f64d43ff0c18 234 /**/
mbed_official 146:f64d43ff0c18 235 /* mult is the MULT field of the I2C_F register, and ranges from 0-2. It selects the*/
mbed_official 146:f64d43ff0c18 236 /* multiplier factor for the divider.*/
mbed_official 146:f64d43ff0c18 237 for (mult = 0u; (mult <= 2u) && (bestError != 0); ++mult)
mbed_official 146:f64d43ff0c18 238 {
mbed_official 146:f64d43ff0c18 239 uint32_t multiplier = 1u << mult;
mbed_official 146:f64d43ff0c18 240
mbed_official 146:f64d43ff0c18 241 /* Scan table to find best match.*/
mbed_official 146:f64d43ff0c18 242 uint32_t i;
mbed_official 146:f64d43ff0c18 243 for (i = 0u; i < ARRAY_SIZE(kI2CDividerTable); ++i)
mbed_official 146:f64d43ff0c18 244 {
mbed_official 146:f64d43ff0c18 245 uint32_t computedRate = sourceClockInHz / (multiplier * kI2CDividerTable[i].sclDivider);
mbed_official 146:f64d43ff0c18 246 uint32_t absError = hz > computedRate ? hz - computedRate : computedRate - hz;
mbed_official 146:f64d43ff0c18 247
mbed_official 146:f64d43ff0c18 248 if (absError < bestError)
mbed_official 146:f64d43ff0c18 249 {
mbed_official 146:f64d43ff0c18 250 bestMult = mult;
mbed_official 146:f64d43ff0c18 251 bestIcr = kI2CDividerTable[i].icr;
mbed_official 146:f64d43ff0c18 252 bestError = absError;
mbed_official 146:f64d43ff0c18 253
mbed_official 146:f64d43ff0c18 254 /* If the error is 0, then we can stop searching because we won't find a*/
mbed_official 146:f64d43ff0c18 255 /* better match.*/
mbed_official 146:f64d43ff0c18 256 if (absError == 0)
mbed_official 146:f64d43ff0c18 257 {
mbed_official 146:f64d43ff0c18 258 break;
mbed_official 146:f64d43ff0c18 259 }
mbed_official 146:f64d43ff0c18 260 }
mbed_official 146:f64d43ff0c18 261 }
mbed_official 146:f64d43ff0c18 262 }
mbed_official 146:f64d43ff0c18 263
mbed_official 146:f64d43ff0c18 264 /* Set the resulting error.*/
mbed_official 146:f64d43ff0c18 265 if (absoluteError_Hz)
mbed_official 146:f64d43ff0c18 266 {
mbed_official 146:f64d43ff0c18 267 *absoluteError_Hz = bestError;
mbed_official 146:f64d43ff0c18 268 }
mbed_official 146:f64d43ff0c18 269
mbed_official 146:f64d43ff0c18 270 /* Set frequency register based on best settings.*/
mbed_official 146:f64d43ff0c18 271 HW_I2C_F_WR(instance, BF_I2C_F_MULT(bestMult) | BF_I2C_F_ICR(bestIcr));
mbed_official 146:f64d43ff0c18 272
mbed_official 146:f64d43ff0c18 273 return kStatus_I2C_Success;
mbed_official 146:f64d43ff0c18 274 }
mbed_official 146:f64d43ff0c18 275
mbed_official 146:f64d43ff0c18 276 /* Documentation for this function is in fsl_i2c_hal.h.*/
mbed_official 146:f64d43ff0c18 277 void i2c_hal_send_start(uint32_t instance)
mbed_official 146:f64d43ff0c18 278 {
mbed_official 146:f64d43ff0c18 279 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 280
mbed_official 146:f64d43ff0c18 281 /* Check if we're in a master mode transfer.*/
mbed_official 146:f64d43ff0c18 282 if (HW_I2C_C1(instance).B.MST)
mbed_official 146:f64d43ff0c18 283 {
mbed_official 146:f64d43ff0c18 284 #if FSL_FEATURE_I2C_HAS_ERRATA_6070
mbed_official 146:f64d43ff0c18 285 /* Errata 6070: Repeat start cannot be generated if the I2Cx_F[MULT] field is set to a*/
mbed_official 146:f64d43ff0c18 286 /* non- zero value.*/
mbed_official 146:f64d43ff0c18 287 /**/
mbed_official 146:f64d43ff0c18 288 /* The workaround is to either always keep MULT set to 0, or to temporarily set it to*/
mbed_official 146:f64d43ff0c18 289 /* 0 while performing the repeated start and then restore it.*/
mbed_official 146:f64d43ff0c18 290 uint32_t savedMult = 0;
mbed_official 146:f64d43ff0c18 291 if (HW_I2C_F(instance).B.MULT != 0)
mbed_official 146:f64d43ff0c18 292 {
mbed_official 146:f64d43ff0c18 293 savedMult = HW_I2C_F(instance).B.MULT;
mbed_official 146:f64d43ff0c18 294 HW_I2C_F(instance).B.MULT = 0;
mbed_official 146:f64d43ff0c18 295 }
mbed_official 146:f64d43ff0c18 296 #endif /* FSL_FEATURE_I2C_HAS_ERRATA_6070*/
mbed_official 146:f64d43ff0c18 297
mbed_official 146:f64d43ff0c18 298 /* We are already in a transfer, so send a repeated start.*/
mbed_official 146:f64d43ff0c18 299 HW_I2C_C1_SET(instance, BM_I2C_C1_RSTA);
mbed_official 146:f64d43ff0c18 300
mbed_official 146:f64d43ff0c18 301 #if FSL_FEATURE_I2C_HAS_ERRATA_6070
mbed_official 146:f64d43ff0c18 302 if (savedMult)
mbed_official 146:f64d43ff0c18 303 {
mbed_official 146:f64d43ff0c18 304 HW_I2C_F(instance).B.MULT = savedMult;
mbed_official 146:f64d43ff0c18 305 }
mbed_official 146:f64d43ff0c18 306 #endif /* FSL_FEATURE_I2C_HAS_ERRATA_6070*/
mbed_official 146:f64d43ff0c18 307 }
mbed_official 146:f64d43ff0c18 308 else
mbed_official 146:f64d43ff0c18 309 {
mbed_official 146:f64d43ff0c18 310 /* Initiate a transfer by sending the start signal.*/
mbed_official 146:f64d43ff0c18 311 HW_I2C_C1_SET(instance, BM_I2C_C1_MST | BM_I2C_C1_TX);
mbed_official 146:f64d43ff0c18 312 }
mbed_official 146:f64d43ff0c18 313 }
mbed_official 146:f64d43ff0c18 314
mbed_official 146:f64d43ff0c18 315 /* Documentation for this function is in fsl_i2c_hal.h.*/
mbed_official 146:f64d43ff0c18 316 void i2c_hal_set_slave_address_7bit(uint32_t instance, uint8_t address)
mbed_official 146:f64d43ff0c18 317 {
mbed_official 146:f64d43ff0c18 318 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 319
mbed_official 146:f64d43ff0c18 320 /* Set 7-bit slave address.*/
mbed_official 146:f64d43ff0c18 321 HW_I2C_A1_WR(instance, address << 1U);
mbed_official 146:f64d43ff0c18 322
mbed_official 146:f64d43ff0c18 323 /* Disable the address extension option, selecting 7-bit mode.*/
mbed_official 146:f64d43ff0c18 324 HW_I2C_C2_CLR(instance, BM_I2C_C2_ADEXT);
mbed_official 146:f64d43ff0c18 325 }
mbed_official 146:f64d43ff0c18 326
mbed_official 146:f64d43ff0c18 327 /* Documentation for this function is in fsl_i2c_hal.h.*/
mbed_official 146:f64d43ff0c18 328 void i2c_hal_set_slave_address_10bit(uint32_t instance, uint16_t address)
mbed_official 146:f64d43ff0c18 329 {
mbed_official 146:f64d43ff0c18 330 uint8_t temp;
mbed_official 146:f64d43ff0c18 331 assert(instance < HW_I2C_INSTANCE_COUNT);
mbed_official 146:f64d43ff0c18 332
mbed_official 146:f64d43ff0c18 333 /* Set bottom 7 bits of slave address.*/
mbed_official 146:f64d43ff0c18 334 temp = address & 0x7f;
mbed_official 146:f64d43ff0c18 335 HW_I2C_A1_WR(instance, temp << 1U);
mbed_official 146:f64d43ff0c18 336
mbed_official 146:f64d43ff0c18 337 /* Enable 10-bit address extension.*/
mbed_official 146:f64d43ff0c18 338 HW_I2C_C2_SET(instance, BM_I2C_C2_ADEXT);
mbed_official 146:f64d43ff0c18 339
mbed_official 146:f64d43ff0c18 340 /* Set top 3 bits of slave address.*/
mbed_official 146:f64d43ff0c18 341 BW_I2C_C2_AD(instance, address >> 7U);
mbed_official 146:f64d43ff0c18 342 }
mbed_official 146:f64d43ff0c18 343
mbed_official 146:f64d43ff0c18 344 /*******************************************************************************
mbed_official 146:f64d43ff0c18 345 * EOF
mbed_official 146:f64d43ff0c18 346 ******************************************************************************/
mbed_official 146:f64d43ff0c18 347