mbed library sources. Supersedes mbed-src. Fixed broken STM32F1xx RTC on rtc_api.c

Dependents:   Nucleo_F103RB_RTC_battery_bkup_pwr_off_okay

Fork of mbed-dev by mbed official

Committer:
<>
Date:
Thu Feb 02 17:01:33 2017 +0000
Revision:
157:ff67d9f36b67
This updates the lib to the mbed lib v135

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 157:ff67d9f36b67 1 /**
<> 157:ff67d9f36b67 2 * @file
<> 157:ff67d9f36b67 3 * @brief I2CS (Inter-Integrated Circuit Slave) function prototypes and data types.
<> 157:ff67d9f36b67 4 */
<> 157:ff67d9f36b67 5
<> 157:ff67d9f36b67 6 /* ****************************************************************************
<> 157:ff67d9f36b67 7 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
<> 157:ff67d9f36b67 8 *
<> 157:ff67d9f36b67 9 * Permission is hereby granted, free of charge, to any person obtaining a
<> 157:ff67d9f36b67 10 * copy of this software and associated documentation files (the "Software"),
<> 157:ff67d9f36b67 11 * to deal in the Software without restriction, including without limitation
<> 157:ff67d9f36b67 12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
<> 157:ff67d9f36b67 13 * and/or sell copies of the Software, and to permit persons to whom the
<> 157:ff67d9f36b67 14 * Software is furnished to do so, subject to the following conditions:
<> 157:ff67d9f36b67 15 *
<> 157:ff67d9f36b67 16 * The above copyright notice and this permission notice shall be included
<> 157:ff67d9f36b67 17 * in all copies or substantial portions of the Software.
<> 157:ff67d9f36b67 18 *
<> 157:ff67d9f36b67 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
<> 157:ff67d9f36b67 20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
<> 157:ff67d9f36b67 21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
<> 157:ff67d9f36b67 22 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
<> 157:ff67d9f36b67 23 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
<> 157:ff67d9f36b67 24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
<> 157:ff67d9f36b67 25 * OTHER DEALINGS IN THE SOFTWARE.
<> 157:ff67d9f36b67 26 *
<> 157:ff67d9f36b67 27 * Except as contained in this notice, the name of Maxim Integrated
<> 157:ff67d9f36b67 28 * Products, Inc. shall not be used except as stated in the Maxim Integrated
<> 157:ff67d9f36b67 29 * Products, Inc. Branding Policy.
<> 157:ff67d9f36b67 30 *
<> 157:ff67d9f36b67 31 * The mere transfer of this software does not imply any licenses
<> 157:ff67d9f36b67 32 * of trade secrets, proprietary technology, copyrights, patents,
<> 157:ff67d9f36b67 33 * trademarks, maskwork rights, or any other form of intellectual
<> 157:ff67d9f36b67 34 * property whatsoever. Maxim Integrated Products, Inc. retains all
<> 157:ff67d9f36b67 35 * ownership rights.
<> 157:ff67d9f36b67 36 *
<> 157:ff67d9f36b67 37 * $Date: 2016-10-10 18:59:48 -0500 (Mon, 10 Oct 2016) $
<> 157:ff67d9f36b67 38 * $Revision: 24661 $
<> 157:ff67d9f36b67 39 *
<> 157:ff67d9f36b67 40 *************************************************************************** */
<> 157:ff67d9f36b67 41
<> 157:ff67d9f36b67 42 /* Define to prevent redundant inclusion */
<> 157:ff67d9f36b67 43 #ifndef _I2CS_H_
<> 157:ff67d9f36b67 44 #define _I2CS_H_
<> 157:ff67d9f36b67 45
<> 157:ff67d9f36b67 46 /* **** Includes **** */
<> 157:ff67d9f36b67 47 #include "mxc_config.h"
<> 157:ff67d9f36b67 48 #include "mxc_sys.h"
<> 157:ff67d9f36b67 49 #include "mxc_assert.h"
<> 157:ff67d9f36b67 50 #include "i2cs_regs.h"
<> 157:ff67d9f36b67 51
<> 157:ff67d9f36b67 52 #ifdef __cplusplus
<> 157:ff67d9f36b67 53 extern "C" {
<> 157:ff67d9f36b67 54 #endif
<> 157:ff67d9f36b67 55
<> 157:ff67d9f36b67 56 /**
<> 157:ff67d9f36b67 57 * @ingroup i2c_master_slave
<> 157:ff67d9f36b67 58 * @defgroup i2cs I2C Slave
<> 157:ff67d9f36b67 59 * @brief I2C Slave (I2CS) API
<> 157:ff67d9f36b67 60 * @{
<> 157:ff67d9f36b67 61 */
<> 157:ff67d9f36b67 62
<> 157:ff67d9f36b67 63 /* **** Definitions **** */
<> 157:ff67d9f36b67 64 /**
<> 157:ff67d9f36b67 65 * Internal buffer size for storing I2C Slave Messages
<> 157:ff67d9f36b67 66 */
<> 157:ff67d9f36b67 67 #define I2CS_BUFFER_SIZE 32
<> 157:ff67d9f36b67 68
<> 157:ff67d9f36b67 69 /**
<> 157:ff67d9f36b67 70 * Enumeration type to select supported I2CS frequencies.
<> 157:ff67d9f36b67 71 */
<> 157:ff67d9f36b67 72 typedef enum {
<> 157:ff67d9f36b67 73 I2CS_SPEED_100KHZ = 0, /**< Use to select a bus communication speed of 100 kHz. */
<> 157:ff67d9f36b67 74 I2CS_SPEED_400KHZ = 1 /**< Use to select a bus communication speed of 400 kHz. */
<> 157:ff67d9f36b67 75 } i2cs_speed_t;
<> 157:ff67d9f36b67 76
<> 157:ff67d9f36b67 77 /**
<> 157:ff67d9f36b67 78 * Enumeration type to select the I2CS addressing mode.
<> 157:ff67d9f36b67 79 */
<> 157:ff67d9f36b67 80 typedef enum {
<> 157:ff67d9f36b67 81 I2CS_ADDR_8 = 0, /**< Sets the slave address mode to 8-bits (7-bits address plus read/write bit). */
<> 157:ff67d9f36b67 82 I2CS_ADDR_10 = MXC_F_I2CS_DEV_ID_TEN_BIT_ID_MODE /**< Sets the slave address mode to 10-bits. */
<> 157:ff67d9f36b67 83 } i2cs_addr_t;
<> 157:ff67d9f36b67 84
<> 157:ff67d9f36b67 85 /**
<> 157:ff67d9f36b67 86 * Type alias for an I2CS callback function that will be called when a given byte is updated by the Master, see I2CS_RegisterCallback(mxc_i2cs_regs_t *i2cs, uint8_t addr, i2cs_callback_fn callback).
<> 157:ff67d9f36b67 87 * @details The function prototype for implementing callback_fn is:
<> 157:ff67d9f36b67 88 * @code
<> 157:ff67d9f36b67 89 * void func(uint8_t addr);
<> 157:ff67d9f36b67 90 * @endcode
<> 157:ff67d9f36b67 91 */
<> 157:ff67d9f36b67 92 typedef void (*i2cs_callback_fn)(uint8_t error_code);
<> 157:ff67d9f36b67 93 /* **** Globals **** */
<> 157:ff67d9f36b67 94
<> 157:ff67d9f36b67 95 /* **** Function Prototypes **** */
<> 157:ff67d9f36b67 96
<> 157:ff67d9f36b67 97 /**
<> 157:ff67d9f36b67 98 * @brief Initialize I2CS module.
<> 157:ff67d9f36b67 99 * @param i2cs Pointer to I2CS regs.
<> 157:ff67d9f36b67 100 * @param sys_cfg Pointer to I2CS system configuration, see
<> 157:ff67d9f36b67 101 * #sys_cfg_i2cs_t.
<> 157:ff67d9f36b67 102 * @param speed I2CS frequency.
<> 157:ff67d9f36b67 103 * @param address I2CS address.
<> 157:ff67d9f36b67 104 * @param addr_len I2CS address length.
<> 157:ff67d9f36b67 105 * @return #E_NO_ERROR if everything is successful or an
<> 157:ff67d9f36b67 106 * @ref MXC_Error_Codes "error code" if unsuccessful.
<> 157:ff67d9f36b67 107 *
<> 157:ff67d9f36b67 108 */
<> 157:ff67d9f36b67 109 int I2CS_Init(mxc_i2cs_regs_t *i2cs, const sys_cfg_i2cs_t *sys_cfg, i2cs_speed_t speed, uint16_t address, i2cs_addr_t addr_len);
<> 157:ff67d9f36b67 110
<> 157:ff67d9f36b67 111 /**
<> 157:ff67d9f36b67 112 * @brief Shutdown I2CS module.
<> 157:ff67d9f36b67 113 * @param i2cs Pointer to I2CS regs.
<> 157:ff67d9f36b67 114 * @return #E_NO_ERROR if everything is successful or an
<> 157:ff67d9f36b67 115 * @ref MXC_Error_Codes "error code" if unsuccessful.
<> 157:ff67d9f36b67 116 */
<> 157:ff67d9f36b67 117 int I2CS_Shutdown(mxc_i2cs_regs_t *i2cs);
<> 157:ff67d9f36b67 118
<> 157:ff67d9f36b67 119 /**
<> 157:ff67d9f36b67 120 * @brief I2CS interrupt handler.
<> 157:ff67d9f36b67 121 * @details This function should be called by the application from the
<> 157:ff67d9f36b67 122 * interrupt handler if I2CS interrupts are enabled. Alternately,
<> 157:ff67d9f36b67 123 * this function can be periodically called by the application if
<> 157:ff67d9f36b67 124 * I2CS interrupts are disabled.
<> 157:ff67d9f36b67 125 *
<> 157:ff67d9f36b67 126 * @param i2cs Pointer to I2CS regs.
<> 157:ff67d9f36b67 127 */
<> 157:ff67d9f36b67 128 void I2CS_Handler(mxc_i2cs_regs_t *i2cs);
<> 157:ff67d9f36b67 129
<> 157:ff67d9f36b67 130 /**
<> 157:ff67d9f36b67 131 * @brief Register a callback that is triggered by an update of a specified
<> 157:ff67d9f36b67 132 * byte.
<> 157:ff67d9f36b67 133 * @details Registering a callback causes the slave to interrupt when the
<> 157:ff67d9f36b67 134 * master has updated a specified byte.
<> 157:ff67d9f36b67 135 *
<> 157:ff67d9f36b67 136 * @param i2cs Pointer to the I2CS register structure, see
<> 157:ff67d9f36b67 137 * #mxc_i2cs_regs_t.
<> 157:ff67d9f36b67 138 * @param addr Index to trigger a call to the #i2cs_callback_fn.
<> 157:ff67d9f36b67 139 * @param callback callback function of type #i2cs_callback_fn to be called
<> 157:ff67d9f36b67 140 * when the addr being written by the master matches \c addr.
<> 157:ff67d9f36b67 141 */
<> 157:ff67d9f36b67 142 void I2CS_RegisterCallback(mxc_i2cs_regs_t *i2cs, uint8_t addr, i2cs_callback_fn callback);
<> 157:ff67d9f36b67 143
<> 157:ff67d9f36b67 144 /**
<> 157:ff67d9f36b67 145 * @brief Write I2CS data to a given byte.
<> 157:ff67d9f36b67 146 * @details The slave has a buffer of registers that the external master can
<> 157:ff67d9f36b67 147 * read. Use this function to write data into a specified
<> 157:ff67d9f36b67 148 * address/index.
<> 157:ff67d9f36b67 149 *
<> 157:ff67d9f36b67 150 * @param i2cs Pointer to I2CS regs.
<> 157:ff67d9f36b67 151 * @param addr Address/Index to write.
<> 157:ff67d9f36b67 152 * @param data Data to be written.
<> 157:ff67d9f36b67 153 */
<> 157:ff67d9f36b67 154 __STATIC_INLINE void I2CS_Write(mxc_i2cs_regs_t *i2cs, uint8_t addr, uint8_t data)
<> 157:ff67d9f36b67 155 {
<> 157:ff67d9f36b67 156 // Make sure we don't overflow
<> 157:ff67d9f36b67 157 MXC_ASSERT(addr < MXC_CFG_I2CS_BUFFER_SIZE);
<> 157:ff67d9f36b67 158 i2cs->data_byte[addr] = ((i2cs->data_byte[addr] & ~MXC_F_I2CS_DATA_BYTE_DATA_FIELD) |
<> 157:ff67d9f36b67 159 (data << MXC_F_I2CS_DATA_BYTE_DATA_FIELD_POS));
<> 157:ff67d9f36b67 160 }
<> 157:ff67d9f36b67 161
<> 157:ff67d9f36b67 162 /**
<> 157:ff67d9f36b67 163 * @brief Read I2CS data from a given address .
<> 157:ff67d9f36b67 164 * @details The slave has a buffer of registers that the external master can
<> 157:ff67d9f36b67 165 * read. Use this function to read the data from the registers.
<> 157:ff67d9f36b67 166 *
<> 157:ff67d9f36b67 167 * @param i2cs Pointer to I2CS regs.
<> 157:ff67d9f36b67 168 * @param addr Address/Index to read from.
<> 157:ff67d9f36b67 169 *
<> 157:ff67d9f36b67 170 * @return Data contained in requested @c addr register.
<> 157:ff67d9f36b67 171 */
<> 157:ff67d9f36b67 172 __STATIC_INLINE uint8_t I2CS_Read(mxc_i2cs_regs_t *i2cs, uint8_t addr)
<> 157:ff67d9f36b67 173 {
<> 157:ff67d9f36b67 174 // Make sure we don't overflow
<> 157:ff67d9f36b67 175 MXC_ASSERT(addr < MXC_CFG_I2CS_BUFFER_SIZE);
<> 157:ff67d9f36b67 176 return ((i2cs->data_byte[addr] & MXC_F_I2CS_DATA_BYTE_DATA_FIELD) >>
<> 157:ff67d9f36b67 177 MXC_F_I2CS_DATA_BYTE_DATA_FIELD_POS);
<> 157:ff67d9f36b67 178 }
<> 157:ff67d9f36b67 179
<> 157:ff67d9f36b67 180 /**
<> 157:ff67d9f36b67 181 * @brief Set the given index to read only (RO).
<> 157:ff67d9f36b67 182 * @details This index will be flagged as read only. The slave will NACK the
<> 157:ff67d9f36b67 183 * master if it attempts to write this location. Multiple calls with
<> 157:ff67d9f36b67 184 * different index/address values will yield multiple read-only
<> 157:ff67d9f36b67 185 * locations within the slave register set.
<> 157:ff67d9f36b67 186 *
<> 157:ff67d9f36b67 187 * @param i2cs Pointer to I2CS regs.
<> 157:ff67d9f36b67 188 * @param addr Address/Index of the byte to set to RO.
<> 157:ff67d9f36b67 189 */
<> 157:ff67d9f36b67 190 __STATIC_INLINE void I2CS_SetRO(mxc_i2cs_regs_t *i2cs, uint8_t addr)
<> 157:ff67d9f36b67 191 {
<> 157:ff67d9f36b67 192 // Make sure we don't overflow
<> 157:ff67d9f36b67 193 MXC_ASSERT(addr < MXC_CFG_I2CS_BUFFER_SIZE);
<> 157:ff67d9f36b67 194 i2cs->data_byte[addr] |= MXC_F_I2CS_DATA_BYTE_READ_ONLY_FL;
<> 157:ff67d9f36b67 195 }
<> 157:ff67d9f36b67 196
<> 157:ff67d9f36b67 197 /**
<> 157:ff67d9f36b67 198 * @brief Sets the given address to R/W.
<> 157:ff67d9f36b67 199 * @param i2cs Pointer to I2CS regs.
<> 157:ff67d9f36b67 200 * @param addr Index to start clearing RO flag.
<> 157:ff67d9f36b67 201 */
<> 157:ff67d9f36b67 202 __STATIC_INLINE void I2CS_ClearRO(mxc_i2cs_regs_t *i2cs, uint8_t addr)
<> 157:ff67d9f36b67 203 {
<> 157:ff67d9f36b67 204 // Make sure we don't overflow
<> 157:ff67d9f36b67 205 MXC_ASSERT(addr < MXC_CFG_I2CS_BUFFER_SIZE);
<> 157:ff67d9f36b67 206 i2cs->data_byte[addr] &= ~MXC_F_I2CS_DATA_BYTE_READ_ONLY_FL;
<> 157:ff67d9f36b67 207 }
<> 157:ff67d9f36b67 208
<> 157:ff67d9f36b67 209 /**@} end of group i2cs */
<> 157:ff67d9f36b67 210
<> 157:ff67d9f36b67 211 #ifdef __cplusplus
<> 157:ff67d9f36b67 212 }
<> 157:ff67d9f36b67 213 #endif
<> 157:ff67d9f36b67 214
<> 157:ff67d9f36b67 215 #endif /* _I2CS_H_ */