mbed library sources
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_STM32F3/stm32f3xx_hal_smbus.c@634:ac7d6880524d, 2015-09-28 (annotated)
- Committer:
- mbed_official
- Date:
- Mon Sep 28 20:15:09 2015 +0100
- Revision:
- 634:ac7d6880524d
- Parent:
- 632:7687fb9c4f91
Synchronized with git revision 9b7d23d47153c298a6d24de9a415202705889d11
Full URL: https://github.com/mbedmicro/mbed/commit/9b7d23d47153c298a6d24de9a415202705889d11/
Revert "[NUCLEO_F303K8] add support of the STM32F303K8"
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 237:f3da66175598 | 1 | /** |
mbed_official | 237:f3da66175598 | 2 | ****************************************************************************** |
mbed_official | 237:f3da66175598 | 3 | * @file stm32f3xx_hal_smbus.c |
mbed_official | 237:f3da66175598 | 4 | * @author MCD Application Team |
mbed_official | 634:ac7d6880524d | 5 | * @version V1.1.0 |
mbed_official | 634:ac7d6880524d | 6 | * @date 12-Sept-2014 |
mbed_official | 237:f3da66175598 | 7 | * @brief SMBUS HAL module driver. |
mbed_official | 237:f3da66175598 | 8 | * |
mbed_official | 237:f3da66175598 | 9 | * This file provides firmware functions to manage the following |
mbed_official | 237:f3da66175598 | 10 | * functionalities of the System Management Bus (SMBus) peripheral, |
mbed_official | 237:f3da66175598 | 11 | * based on I2C principales of operation : |
mbed_official | 237:f3da66175598 | 12 | * + Initialization and de-initialization functions |
mbed_official | 237:f3da66175598 | 13 | * + IO operation functions |
mbed_official | 237:f3da66175598 | 14 | * + Peripheral State and Errors functions |
mbed_official | 237:f3da66175598 | 15 | * |
mbed_official | 237:f3da66175598 | 16 | @verbatim |
mbed_official | 237:f3da66175598 | 17 | ============================================================================== |
mbed_official | 237:f3da66175598 | 18 | ##### How to use this driver ##### |
mbed_official | 237:f3da66175598 | 19 | ============================================================================== |
mbed_official | 237:f3da66175598 | 20 | [..] |
mbed_official | 237:f3da66175598 | 21 | The SMBUS HAL driver can be used as follows: |
mbed_official | 237:f3da66175598 | 22 | |
mbed_official | 237:f3da66175598 | 23 | (#) Declare a SMBUS_HandleTypeDef handle structure, for example: |
mbed_official | 237:f3da66175598 | 24 | SMBUS_HandleTypeDef hsmbus; |
mbed_official | 237:f3da66175598 | 25 | |
mbed_official | 237:f3da66175598 | 26 | (#)Initialize the SMBUS low level resources by implement the HAL_SMBUS_MspInit ()API: |
mbed_official | 237:f3da66175598 | 27 | (##) Enable the SMBUSx interface clock |
mbed_official | 237:f3da66175598 | 28 | (##) SMBUS pins configuration |
mbed_official | 237:f3da66175598 | 29 | (+++) Enable the clock for the SMBUS GPIOs |
mbed_official | 237:f3da66175598 | 30 | (+++) Configure SMBUS pins as alternate function open-drain |
mbed_official | 237:f3da66175598 | 31 | (##) NVIC configuration if you need to use interrupt process |
mbed_official | 237:f3da66175598 | 32 | (+++) Configure the SMBUSx interrupt priority |
mbed_official | 237:f3da66175598 | 33 | (+++) Enable the NVIC SMBUS IRQ Channel |
mbed_official | 237:f3da66175598 | 34 | |
mbed_official | 237:f3da66175598 | 35 | (#) Configure the Communication Clock Timing, Bus Timeout, Own Address1, Master Adressing Mode, |
mbed_official | 237:f3da66175598 | 36 | Dual Addressing mode, Own Address2, Own Address2 Mask, General call, Nostretch mode, |
mbed_official | 237:f3da66175598 | 37 | Peripheral mode and Packet Error Check mode in the hsmbus Init structure. |
mbed_official | 237:f3da66175598 | 38 | |
mbed_official | 237:f3da66175598 | 39 | (#) Initialize the SMBUS registers by calling the HAL_SMBUS_Init() API: |
mbed_official | 237:f3da66175598 | 40 | (+) These API's configures also the low level Hardware GPIO, CLOCK, CORTEX...etc) |
mbed_official | 237:f3da66175598 | 41 | by calling the customed HAL_SMBUS_MspInit(&hsmbus) API. |
mbed_official | 237:f3da66175598 | 42 | |
mbed_official | 237:f3da66175598 | 43 | (#) To check if target device is ready for communication, use the function HAL_SMBUS_IsDeviceReady() |
mbed_official | 237:f3da66175598 | 44 | |
mbed_official | 237:f3da66175598 | 45 | (#) For SMBUS IO operations, only one mode of operations is available within this driver : |
mbed_official | 237:f3da66175598 | 46 | |
mbed_official | 237:f3da66175598 | 47 | *** Interrupt mode IO operation *** |
mbed_official | 237:f3da66175598 | 48 | =================================== |
mbed_official | 237:f3da66175598 | 49 | [..] |
mbed_official | 237:f3da66175598 | 50 | (+) Transmit in master/host SMBUS mode an amount of data in non blocking mode using HAL_SMBUS_Master_Transmit_IT() |
mbed_official | 237:f3da66175598 | 51 | (++) At transmission end of transfer HAL_SMBUS_MasterTxCpltCallback is executed and user can |
mbed_official | 237:f3da66175598 | 52 | add his own code by customization of function pointer HAL_SMBUS_MasterTxCpltCallback |
mbed_official | 237:f3da66175598 | 53 | (+) Receive in master/host SMBUS mode an amount of data in non blocking mode using HAL_SMBUS_Master_Receive_IT() |
mbed_official | 237:f3da66175598 | 54 | (++) At reception end of transfer HAL_SMBUS_MasterRxCpltCallback is executed and user can |
mbed_official | 237:f3da66175598 | 55 | add his own code by customization of function pointer HAL_SMBUS_MasterRxCpltCallback |
mbed_official | 237:f3da66175598 | 56 | (+) Abort a master/host SMBUS process commnunication with Interrupt using HAL_SMBUS_Master_Abort_IT() |
mbed_official | 237:f3da66175598 | 57 | (++) The associated previous transfer callback is called at the end of abort process |
mbed_official | 237:f3da66175598 | 58 | (++) mean HAL_SMBUS_MasterTxCpltCallback in case of previous state was master transmit |
mbed_official | 237:f3da66175598 | 59 | (++) mean HAL_SMBUS_MasterRxCpltCallback in case of previous state was master receive |
mbed_official | 237:f3da66175598 | 60 | (+) Enable/disable the Address listen mode in slave/device or host/slave SMBUS mode |
mbed_official | 237:f3da66175598 | 61 | using HAL_SMBUS_Slave_Listen_IT() HAL_SMBUS_DisableListen_IT() |
mbed_official | 237:f3da66175598 | 62 | (++) When address slave/device SMBUS match, HAL_SMBUS_SlaveAddrCallback is executed and user can |
mbed_official | 237:f3da66175598 | 63 | add his own code to check the Address Match Code and the transmission direction request by master/host (Write/Read). |
mbed_official | 237:f3da66175598 | 64 | (++) At Listen mode end HAL_SMBUS_SlaveListenCpltCallback is executed and user can |
mbed_official | 237:f3da66175598 | 65 | add his own code by customization of function pointer HAL_SMBUS_SlaveListenCpltCallback |
mbed_official | 237:f3da66175598 | 66 | (+) Transmit in slave/device SMBUS mode an amount of data in non blocking mode using HAL_SMBUS_Slave_Transmit_IT() |
mbed_official | 237:f3da66175598 | 67 | (++) At transmission end of transfer HAL_SMBUS_SlaveTxCpltCallback is executed and user can |
mbed_official | 237:f3da66175598 | 68 | add his own code by customization of function pointer HAL_SMBUS_SlaveTxCpltCallback |
mbed_official | 237:f3da66175598 | 69 | (+) Receive in slave/device SMBUS mode an amount of data in non blocking mode using HAL_SMBUS_Slave_Receive_IT() |
mbed_official | 237:f3da66175598 | 70 | (++) At reception end of transfer HAL_SMBUS_SlaveRxCpltCallback is executed and user can |
mbed_official | 237:f3da66175598 | 71 | add his own code by customization of function pointer HAL_SMBUS_SlaveRxCpltCallback |
mbed_official | 237:f3da66175598 | 72 | (+) Enable/Disable the SMBUS alert mode using HAL_SMBUS_EnableAlert_IT() HAL_SMBUS_DisableAlert_IT() |
mbed_official | 237:f3da66175598 | 73 | (++) When SMBUS Alert is generated HAL_SMBUS_ErrorCallback() is executed and user can |
mbed_official | 237:f3da66175598 | 74 | add his own code by customization of function pointer HAL_SMBUS_ErrorCallback |
mbed_official | 237:f3da66175598 | 75 | to check the Alert Error Code using function HAL_SMBUS_GetError() |
mbed_official | 237:f3da66175598 | 76 | (+) Get HAL state machine or error values using HAL_SMBUS_GetState() or HAL_SMBUS_GetError() |
mbed_official | 237:f3da66175598 | 77 | (+) In case of transfer Error, HAL_SMBUS_ErrorCallback() function is executed and user can |
mbed_official | 237:f3da66175598 | 78 | add his own code by customization of function pointer HAL_SMBUS_ErrorCallback |
mbed_official | 237:f3da66175598 | 79 | to check the Error Code using function HAL_SMBUS_GetError() |
mbed_official | 237:f3da66175598 | 80 | |
mbed_official | 237:f3da66175598 | 81 | *** SMBUS HAL driver macros list *** |
mbed_official | 237:f3da66175598 | 82 | ================================== |
mbed_official | 237:f3da66175598 | 83 | [..] |
mbed_official | 237:f3da66175598 | 84 | Below the list of most used macros in SMBUS HAL driver. |
mbed_official | 237:f3da66175598 | 85 | |
mbed_official | 237:f3da66175598 | 86 | (+) __HAL_SMBUS_ENABLE: Enable the SMBUS peripheral |
mbed_official | 237:f3da66175598 | 87 | (+) __HAL_SMBUS_DISABLE: Disable the SMBUS peripheral |
mbed_official | 237:f3da66175598 | 88 | (+) __HAL_SMBUS_GET_FLAG : Checks whether the specified SMBUS flag is set or not |
mbed_official | 237:f3da66175598 | 89 | (+) __HAL_SMBUS_CLEAR_FLAG : Clears the specified SMBUS pending flag |
mbed_official | 237:f3da66175598 | 90 | (+) __HAL_SMBUS_ENABLE_IT: Enables the specified SMBUS interrupt |
mbed_official | 237:f3da66175598 | 91 | (+) __HAL_SMBUS_DISABLE_IT: Disables the specified SMBUS interrupt |
mbed_official | 237:f3da66175598 | 92 | |
mbed_official | 237:f3da66175598 | 93 | [..] |
mbed_official | 237:f3da66175598 | 94 | (@) You can refer to the SMBUS HAL driver header file for more useful macros |
mbed_official | 237:f3da66175598 | 95 | |
mbed_official | 237:f3da66175598 | 96 | |
mbed_official | 237:f3da66175598 | 97 | @endverbatim |
mbed_official | 237:f3da66175598 | 98 | ****************************************************************************** |
mbed_official | 237:f3da66175598 | 99 | * @attention |
mbed_official | 237:f3da66175598 | 100 | * |
mbed_official | 634:ac7d6880524d | 101 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 237:f3da66175598 | 102 | * |
mbed_official | 237:f3da66175598 | 103 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 237:f3da66175598 | 104 | * are permitted provided that the following conditions are met: |
mbed_official | 237:f3da66175598 | 105 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 237:f3da66175598 | 106 | * this list of conditions and the following disclaimer. |
mbed_official | 237:f3da66175598 | 107 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 237:f3da66175598 | 108 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 237:f3da66175598 | 109 | * and/or other materials provided with the distribution. |
mbed_official | 237:f3da66175598 | 110 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 237:f3da66175598 | 111 | * may be used to endorse or promote products derived from this software |
mbed_official | 237:f3da66175598 | 112 | * without specific prior written permission. |
mbed_official | 237:f3da66175598 | 113 | * |
mbed_official | 237:f3da66175598 | 114 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 237:f3da66175598 | 115 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 237:f3da66175598 | 116 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 237:f3da66175598 | 117 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 237:f3da66175598 | 118 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 237:f3da66175598 | 119 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 237:f3da66175598 | 120 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 237:f3da66175598 | 121 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 237:f3da66175598 | 122 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 237:f3da66175598 | 123 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 237:f3da66175598 | 124 | * |
mbed_official | 237:f3da66175598 | 125 | ****************************************************************************** |
mbed_official | 237:f3da66175598 | 126 | */ |
mbed_official | 237:f3da66175598 | 127 | |
mbed_official | 237:f3da66175598 | 128 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 129 | #include "stm32f3xx_hal.h" |
mbed_official | 237:f3da66175598 | 130 | |
mbed_official | 237:f3da66175598 | 131 | /** @addtogroup STM32F3xx_HAL_Driver |
mbed_official | 237:f3da66175598 | 132 | * @{ |
mbed_official | 237:f3da66175598 | 133 | */ |
mbed_official | 237:f3da66175598 | 134 | |
mbed_official | 375:3d36234a1087 | 135 | /** @defgroup SMBUS SMBUS HAL module driver |
mbed_official | 237:f3da66175598 | 136 | * @brief SMBUS HAL module driver |
mbed_official | 237:f3da66175598 | 137 | * @{ |
mbed_official | 237:f3da66175598 | 138 | */ |
mbed_official | 237:f3da66175598 | 139 | |
mbed_official | 237:f3da66175598 | 140 | #ifdef HAL_SMBUS_MODULE_ENABLED |
mbed_official | 237:f3da66175598 | 141 | |
mbed_official | 237:f3da66175598 | 142 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 143 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 375:3d36234a1087 | 144 | /** @defgroup SMBUS_Private_Define SMBUS Private Define |
mbed_official | 375:3d36234a1087 | 145 | * @{ |
mbed_official | 375:3d36234a1087 | 146 | */ |
mbed_official | 237:f3da66175598 | 147 | #define TIMING_CLEAR_MASK ((uint32_t)0xF0FFFFFF) /*<! SMBUS TIMING clear register Mask */ |
mbed_official | 237:f3da66175598 | 148 | #define HAL_TIMEOUT_ADDR ((uint32_t)10000) /* 10 s */ |
mbed_official | 237:f3da66175598 | 149 | #define HAL_TIMEOUT_BUSY ((uint32_t)25) /* 25 ms */ |
mbed_official | 237:f3da66175598 | 150 | #define HAL_TIMEOUT_DIR ((uint32_t)25) /* 25 ms */ |
mbed_official | 237:f3da66175598 | 151 | #define HAL_TIMEOUT_RXNE ((uint32_t)25) /* 25 ms */ |
mbed_official | 237:f3da66175598 | 152 | #define HAL_TIMEOUT_STOPF ((uint32_t)25) /* 25 ms */ |
mbed_official | 237:f3da66175598 | 153 | #define HAL_TIMEOUT_TC ((uint32_t)25) /* 25 ms */ |
mbed_official | 237:f3da66175598 | 154 | #define HAL_TIMEOUT_TCR ((uint32_t)25) /* 25 ms */ |
mbed_official | 237:f3da66175598 | 155 | #define HAL_TIMEOUT_TXIS ((uint32_t)25) /* 25 ms */ |
mbed_official | 237:f3da66175598 | 156 | #define MAX_NBYTE_SIZE 255 |
mbed_official | 375:3d36234a1087 | 157 | /** |
mbed_official | 375:3d36234a1087 | 158 | * @} |
mbed_official | 375:3d36234a1087 | 159 | */ |
mbed_official | 237:f3da66175598 | 160 | |
mbed_official | 237:f3da66175598 | 161 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 375:3d36234a1087 | 162 | /** @defgroup SMBUS_Private_Macro SMBUS Private Macro |
mbed_official | 375:3d36234a1087 | 163 | * @{ |
mbed_official | 375:3d36234a1087 | 164 | */ |
mbed_official | 237:f3da66175598 | 165 | #define __SMBUS_GET_ISR_REG(__HANDLE__) ((__HANDLE__)->Instance->ISR) |
mbed_official | 237:f3da66175598 | 166 | #define __SMBUS_CHECK_FLAG(__ISR__, __FLAG__) ((((__ISR__) & ((__FLAG__) & SMBUS_FLAG_MASK)) == ((__FLAG__) & SMBUS_FLAG_MASK))) |
mbed_official | 375:3d36234a1087 | 167 | /** |
mbed_official | 375:3d36234a1087 | 168 | * @} |
mbed_official | 375:3d36234a1087 | 169 | */ |
mbed_official | 237:f3da66175598 | 170 | |
mbed_official | 237:f3da66175598 | 171 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 172 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 375:3d36234a1087 | 173 | /** @defgroup SMBUS_Private_Functions SMBUS Private Functions |
mbed_official | 375:3d36234a1087 | 174 | * @{ |
mbed_official | 375:3d36234a1087 | 175 | */ |
mbed_official | 237:f3da66175598 | 176 | static HAL_StatusTypeDef SMBUS_WaitOnFlagUntilTimeout(SMBUS_HandleTypeDef *hsmbus, uint32_t Flag, FlagStatus Status, uint32_t Timeout); |
mbed_official | 237:f3da66175598 | 177 | |
mbed_official | 237:f3da66175598 | 178 | static HAL_StatusTypeDef SMBUS_Enable_IRQ(SMBUS_HandleTypeDef *hsmbus, uint16_t InterruptRequest); |
mbed_official | 237:f3da66175598 | 179 | static HAL_StatusTypeDef SMBUS_Disable_IRQ(SMBUS_HandleTypeDef *hsmbus, uint16_t InterruptRequest); |
mbed_official | 237:f3da66175598 | 180 | static HAL_StatusTypeDef SMBUS_Master_ISR(SMBUS_HandleTypeDef *hsmbus); |
mbed_official | 237:f3da66175598 | 181 | static HAL_StatusTypeDef SMBUS_Slave_ISR(SMBUS_HandleTypeDef *hsmbus); |
mbed_official | 237:f3da66175598 | 182 | |
mbed_official | 237:f3da66175598 | 183 | static void SMBUS_TransferConfig(SMBUS_HandleTypeDef *hsmbus, uint16_t DevAddress, uint8_t Size, uint32_t Mode, uint32_t Request); |
mbed_official | 375:3d36234a1087 | 184 | /** |
mbed_official | 375:3d36234a1087 | 185 | * @} |
mbed_official | 375:3d36234a1087 | 186 | */ |
mbed_official | 237:f3da66175598 | 187 | |
mbed_official | 375:3d36234a1087 | 188 | /* Exported functions ---------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 189 | |
mbed_official | 375:3d36234a1087 | 190 | /** @defgroup SMBUS_Exported_Functions SMBUS Exported Functions |
mbed_official | 237:f3da66175598 | 191 | * @{ |
mbed_official | 237:f3da66175598 | 192 | */ |
mbed_official | 237:f3da66175598 | 193 | |
mbed_official | 375:3d36234a1087 | 194 | /** @defgroup SMBUS_Exported_Functions_Group1 Initialization and de-initialization functions |
mbed_official | 237:f3da66175598 | 195 | * @brief Initialization and Configuration functions |
mbed_official | 237:f3da66175598 | 196 | * |
mbed_official | 237:f3da66175598 | 197 | @verbatim |
mbed_official | 237:f3da66175598 | 198 | =============================================================================== |
mbed_official | 237:f3da66175598 | 199 | ##### Initialization and de-initialization functions ##### |
mbed_official | 237:f3da66175598 | 200 | =============================================================================== |
mbed_official | 237:f3da66175598 | 201 | [..] This subsection provides a set of functions allowing to initialize and |
mbed_official | 237:f3da66175598 | 202 | de-initialiaze the SMBUSx peripheral: |
mbed_official | 237:f3da66175598 | 203 | |
mbed_official | 237:f3da66175598 | 204 | (+) User must Implement HAL_SMBUS_MspInit() function in which he configures |
mbed_official | 237:f3da66175598 | 205 | all related peripherals resources (CLOCK, GPIO, IT and NVIC ). |
mbed_official | 237:f3da66175598 | 206 | |
mbed_official | 237:f3da66175598 | 207 | (+) Call the function HAL_SMBUS_Init() to configure the selected device with |
mbed_official | 237:f3da66175598 | 208 | the selected configuration: |
mbed_official | 237:f3da66175598 | 209 | (++) Clock Timing |
mbed_official | 237:f3da66175598 | 210 | (++) Bus Timeout |
mbed_official | 237:f3da66175598 | 211 | (++) Analog Filer mode |
mbed_official | 237:f3da66175598 | 212 | (++) Own Address 1 |
mbed_official | 237:f3da66175598 | 213 | (++) Addressing mode (Master, Slave) |
mbed_official | 237:f3da66175598 | 214 | (++) Dual Addressing mode |
mbed_official | 237:f3da66175598 | 215 | (++) Own Address 2 |
mbed_official | 237:f3da66175598 | 216 | (++) Own Address 2 Mask |
mbed_official | 237:f3da66175598 | 217 | (++) General call mode |
mbed_official | 237:f3da66175598 | 218 | (++) Nostretch mode |
mbed_official | 237:f3da66175598 | 219 | (++) Packet Error Check mode |
mbed_official | 237:f3da66175598 | 220 | (++) Peripheral mode |
mbed_official | 237:f3da66175598 | 221 | |
mbed_official | 237:f3da66175598 | 222 | |
mbed_official | 237:f3da66175598 | 223 | (+) Call the function HAL_SMBUS_DeInit() to restore the default configuration |
mbed_official | 237:f3da66175598 | 224 | of the selected SMBUSx periperal. |
mbed_official | 237:f3da66175598 | 225 | |
mbed_official | 237:f3da66175598 | 226 | @endverbatim |
mbed_official | 237:f3da66175598 | 227 | * @{ |
mbed_official | 237:f3da66175598 | 228 | */ |
mbed_official | 237:f3da66175598 | 229 | |
mbed_official | 237:f3da66175598 | 230 | /** |
mbed_official | 237:f3da66175598 | 231 | * @brief Initializes the SMBUS according to the specified parameters |
mbed_official | 237:f3da66175598 | 232 | * in the SMBUS_InitTypeDef and create the associated handle. |
mbed_official | 237:f3da66175598 | 233 | * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains |
mbed_official | 237:f3da66175598 | 234 | * the configuration information for the specified SMBUS. |
mbed_official | 237:f3da66175598 | 235 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 236 | */ |
mbed_official | 237:f3da66175598 | 237 | HAL_StatusTypeDef HAL_SMBUS_Init(SMBUS_HandleTypeDef *hsmbus) |
mbed_official | 237:f3da66175598 | 238 | { |
mbed_official | 237:f3da66175598 | 239 | /* Check the SMBUS handle allocation */ |
mbed_official | 634:ac7d6880524d | 240 | if(hsmbus == HAL_NULL) |
mbed_official | 237:f3da66175598 | 241 | { |
mbed_official | 237:f3da66175598 | 242 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 243 | } |
mbed_official | 237:f3da66175598 | 244 | |
mbed_official | 237:f3da66175598 | 245 | /* Check the parameters */ |
mbed_official | 237:f3da66175598 | 246 | assert_param(IS_SMBUS_ALL_INSTANCE(hsmbus->Instance)); |
mbed_official | 237:f3da66175598 | 247 | assert_param(IS_SMBUS_ANALOG_FILTER(hsmbus->Init.AnalogFilter)); |
mbed_official | 237:f3da66175598 | 248 | assert_param(IS_SMBUS_OWN_ADDRESS1(hsmbus->Init.OwnAddress1)); |
mbed_official | 237:f3da66175598 | 249 | assert_param(IS_SMBUS_ADDRESSING_MODE(hsmbus->Init.AddressingMode)); |
mbed_official | 237:f3da66175598 | 250 | assert_param(IS_SMBUS_DUAL_ADDRESS(hsmbus->Init.DualAddressMode)); |
mbed_official | 237:f3da66175598 | 251 | assert_param(IS_SMBUS_OWN_ADDRESS2(hsmbus->Init.OwnAddress2)); |
mbed_official | 237:f3da66175598 | 252 | assert_param(IS_SMBUS_OWN_ADDRESS2_MASK(hsmbus->Init.OwnAddress2Masks)); |
mbed_official | 237:f3da66175598 | 253 | assert_param(IS_SMBUS_GENERAL_CALL(hsmbus->Init.GeneralCallMode)); |
mbed_official | 237:f3da66175598 | 254 | assert_param(IS_SMBUS_NO_STRETCH(hsmbus->Init.NoStretchMode)); |
mbed_official | 237:f3da66175598 | 255 | assert_param(IS_SMBUS_PEC(hsmbus->Init.PacketErrorCheckMode)); |
mbed_official | 237:f3da66175598 | 256 | assert_param(IS_SMBUS_PERIPHERAL_MODE(hsmbus->Init.PeripheralMode)); |
mbed_official | 237:f3da66175598 | 257 | |
mbed_official | 237:f3da66175598 | 258 | if(hsmbus->State == HAL_SMBUS_STATE_RESET) |
mbed_official | 237:f3da66175598 | 259 | { |
mbed_official | 237:f3da66175598 | 260 | /* Init the low level hardware : GPIO, CLOCK, NVIC */ |
mbed_official | 237:f3da66175598 | 261 | HAL_SMBUS_MspInit(hsmbus); |
mbed_official | 237:f3da66175598 | 262 | } |
mbed_official | 237:f3da66175598 | 263 | |
mbed_official | 237:f3da66175598 | 264 | hsmbus->State = HAL_SMBUS_STATE_BUSY; |
mbed_official | 237:f3da66175598 | 265 | |
mbed_official | 237:f3da66175598 | 266 | /* Disable the selected SMBUS peripheral */ |
mbed_official | 237:f3da66175598 | 267 | __HAL_SMBUS_DISABLE(hsmbus); |
mbed_official | 237:f3da66175598 | 268 | |
mbed_official | 237:f3da66175598 | 269 | /*---------------------------- SMBUSx TIMINGR Configuration ------------------------*/ |
mbed_official | 237:f3da66175598 | 270 | /* Configure SMBUSx: Frequency range */ |
mbed_official | 237:f3da66175598 | 271 | hsmbus->Instance->TIMINGR = hsmbus->Init.Timing & TIMING_CLEAR_MASK; |
mbed_official | 237:f3da66175598 | 272 | |
mbed_official | 237:f3da66175598 | 273 | /*---------------------------- SMBUSx TIMEOUTR Configuration ------------------------*/ |
mbed_official | 237:f3da66175598 | 274 | /* Configure SMBUSx: Bus Timeout */ |
mbed_official | 237:f3da66175598 | 275 | hsmbus->Instance->TIMEOUTR &= ~I2C_TIMEOUTR_TIMOUTEN; |
mbed_official | 237:f3da66175598 | 276 | hsmbus->Instance->TIMEOUTR &= ~I2C_TIMEOUTR_TEXTEN; |
mbed_official | 237:f3da66175598 | 277 | hsmbus->Instance->TIMEOUTR = hsmbus->Init.SMBusTimeout; |
mbed_official | 237:f3da66175598 | 278 | |
mbed_official | 237:f3da66175598 | 279 | /*---------------------------- SMBUSx OAR1 Configuration -----------------------*/ |
mbed_official | 237:f3da66175598 | 280 | /* Configure SMBUSx: Own Address1 and ack own address1 mode */ |
mbed_official | 237:f3da66175598 | 281 | hsmbus->Instance->OAR1 &= ~I2C_OAR1_OA1EN; |
mbed_official | 237:f3da66175598 | 282 | |
mbed_official | 237:f3da66175598 | 283 | if(hsmbus->Init.OwnAddress1 != 0) |
mbed_official | 237:f3da66175598 | 284 | { |
mbed_official | 237:f3da66175598 | 285 | if(hsmbus->Init.AddressingMode == SMBUS_ADDRESSINGMODE_7BIT) |
mbed_official | 237:f3da66175598 | 286 | { |
mbed_official | 237:f3da66175598 | 287 | hsmbus->Instance->OAR1 = (I2C_OAR1_OA1EN | hsmbus->Init.OwnAddress1); |
mbed_official | 237:f3da66175598 | 288 | } |
mbed_official | 237:f3da66175598 | 289 | else /* SMBUS_ADDRESSINGMODE_10BIT */ |
mbed_official | 237:f3da66175598 | 290 | { |
mbed_official | 237:f3da66175598 | 291 | hsmbus->Instance->OAR1 = (I2C_OAR1_OA1EN | I2C_OAR1_OA1MODE | hsmbus->Init.OwnAddress1); |
mbed_official | 237:f3da66175598 | 292 | } |
mbed_official | 237:f3da66175598 | 293 | } |
mbed_official | 237:f3da66175598 | 294 | |
mbed_official | 237:f3da66175598 | 295 | /*---------------------------- SMBUSx CR2 Configuration ------------------------*/ |
mbed_official | 237:f3da66175598 | 296 | /* Configure SMBUSx: Addressing Master mode */ |
mbed_official | 237:f3da66175598 | 297 | if(hsmbus->Init.AddressingMode == SMBUS_ADDRESSINGMODE_10BIT) |
mbed_official | 237:f3da66175598 | 298 | { |
mbed_official | 237:f3da66175598 | 299 | hsmbus->Instance->CR2 = (I2C_CR2_ADD10); |
mbed_official | 237:f3da66175598 | 300 | } |
mbed_official | 237:f3da66175598 | 301 | /* Enable the AUTOEND by default, and enable NACK (should be disable only during Slave process) */ |
mbed_official | 237:f3da66175598 | 302 | /* AUTOEND and NACK bit will be manage during Transfer process */ |
mbed_official | 237:f3da66175598 | 303 | hsmbus->Instance->CR2 |= (I2C_CR2_AUTOEND | I2C_CR2_NACK); |
mbed_official | 237:f3da66175598 | 304 | |
mbed_official | 237:f3da66175598 | 305 | /*---------------------------- SMBUSx OAR2 Configuration -----------------------*/ |
mbed_official | 237:f3da66175598 | 306 | /* Configure SMBUSx: Dual mode and Own Address2 */ |
mbed_official | 237:f3da66175598 | 307 | hsmbus->Instance->OAR2 = (hsmbus->Init.DualAddressMode | hsmbus->Init.OwnAddress2 | (hsmbus->Init.OwnAddress2Masks << 8)); |
mbed_official | 237:f3da66175598 | 308 | |
mbed_official | 237:f3da66175598 | 309 | /*---------------------------- SMBUSx CR1 Configuration ------------------------*/ |
mbed_official | 237:f3da66175598 | 310 | /* Configure SMBUSx: Generalcall and NoStretch mode */ |
mbed_official | 237:f3da66175598 | 311 | hsmbus->Instance->CR1 = (hsmbus->Init.GeneralCallMode | hsmbus->Init.NoStretchMode | hsmbus->Init.PacketErrorCheckMode | hsmbus->Init.PeripheralMode | hsmbus->Init.AnalogFilter); |
mbed_official | 237:f3da66175598 | 312 | |
mbed_official | 237:f3da66175598 | 313 | /* Enable Slave Byte Control only in case of Packet Error Check is enabled and SMBUS Peripheral is set in Slave mode */ |
mbed_official | 237:f3da66175598 | 314 | if( (hsmbus->Init.PacketErrorCheckMode == SMBUS_PEC_ENABLED) |
mbed_official | 237:f3da66175598 | 315 | && ( (hsmbus->Init.PeripheralMode == SMBUS_PERIPHERAL_MODE_SMBUS_SLAVE) || (hsmbus->Init.PeripheralMode == SMBUS_PERIPHERAL_MODE_SMBUS_SLAVE_ARP) ) ) |
mbed_official | 237:f3da66175598 | 316 | { |
mbed_official | 237:f3da66175598 | 317 | hsmbus->Instance->CR1 |= I2C_CR1_SBC; |
mbed_official | 237:f3da66175598 | 318 | } |
mbed_official | 237:f3da66175598 | 319 | |
mbed_official | 237:f3da66175598 | 320 | /* Enable the selected SMBUS peripheral */ |
mbed_official | 237:f3da66175598 | 321 | __HAL_SMBUS_ENABLE(hsmbus); |
mbed_official | 237:f3da66175598 | 322 | |
mbed_official | 237:f3da66175598 | 323 | hsmbus->ErrorCode = HAL_SMBUS_ERROR_NONE; |
mbed_official | 237:f3da66175598 | 324 | hsmbus->PreviousState = HAL_SMBUS_STATE_READY; |
mbed_official | 237:f3da66175598 | 325 | hsmbus->State = HAL_SMBUS_STATE_READY; |
mbed_official | 237:f3da66175598 | 326 | |
mbed_official | 237:f3da66175598 | 327 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 328 | } |
mbed_official | 237:f3da66175598 | 329 | |
mbed_official | 237:f3da66175598 | 330 | /** |
mbed_official | 237:f3da66175598 | 331 | * @brief DeInitializes the SMBUS peripheral. |
mbed_official | 237:f3da66175598 | 332 | * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains |
mbed_official | 237:f3da66175598 | 333 | * the configuration information for the specified SMBUS. |
mbed_official | 237:f3da66175598 | 334 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 335 | */ |
mbed_official | 237:f3da66175598 | 336 | HAL_StatusTypeDef HAL_SMBUS_DeInit(SMBUS_HandleTypeDef *hsmbus) |
mbed_official | 237:f3da66175598 | 337 | { |
mbed_official | 237:f3da66175598 | 338 | /* Check the SMBUS handle allocation */ |
mbed_official | 634:ac7d6880524d | 339 | if(hsmbus == HAL_NULL) |
mbed_official | 237:f3da66175598 | 340 | { |
mbed_official | 237:f3da66175598 | 341 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 342 | } |
mbed_official | 237:f3da66175598 | 343 | |
mbed_official | 237:f3da66175598 | 344 | /* Check the parameters */ |
mbed_official | 237:f3da66175598 | 345 | assert_param(IS_SMBUS_ALL_INSTANCE(hsmbus->Instance)); |
mbed_official | 237:f3da66175598 | 346 | |
mbed_official | 237:f3da66175598 | 347 | hsmbus->State = HAL_SMBUS_STATE_BUSY; |
mbed_official | 237:f3da66175598 | 348 | |
mbed_official | 237:f3da66175598 | 349 | /* Disable the SMBUS Peripheral Clock */ |
mbed_official | 237:f3da66175598 | 350 | __HAL_SMBUS_DISABLE(hsmbus); |
mbed_official | 237:f3da66175598 | 351 | |
mbed_official | 237:f3da66175598 | 352 | /* DeInit the low level hardware: GPIO, CLOCK, NVIC */ |
mbed_official | 237:f3da66175598 | 353 | HAL_SMBUS_MspDeInit(hsmbus); |
mbed_official | 237:f3da66175598 | 354 | |
mbed_official | 237:f3da66175598 | 355 | hsmbus->ErrorCode = HAL_SMBUS_ERROR_NONE; |
mbed_official | 237:f3da66175598 | 356 | hsmbus->PreviousState = HAL_SMBUS_STATE_RESET; |
mbed_official | 237:f3da66175598 | 357 | hsmbus->State = HAL_SMBUS_STATE_RESET; |
mbed_official | 237:f3da66175598 | 358 | |
mbed_official | 237:f3da66175598 | 359 | /* Release Lock */ |
mbed_official | 237:f3da66175598 | 360 | __HAL_UNLOCK(hsmbus); |
mbed_official | 237:f3da66175598 | 361 | |
mbed_official | 237:f3da66175598 | 362 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 363 | } |
mbed_official | 237:f3da66175598 | 364 | |
mbed_official | 237:f3da66175598 | 365 | /** |
mbed_official | 237:f3da66175598 | 366 | * @brief SMBUS MSP Init. |
mbed_official | 237:f3da66175598 | 367 | * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains |
mbed_official | 237:f3da66175598 | 368 | * the configuration information for the specified SMBUS. |
mbed_official | 237:f3da66175598 | 369 | * @retval None |
mbed_official | 237:f3da66175598 | 370 | */ |
mbed_official | 237:f3da66175598 | 371 | __weak void HAL_SMBUS_MspInit(SMBUS_HandleTypeDef *hsmbus) |
mbed_official | 237:f3da66175598 | 372 | { |
mbed_official | 237:f3da66175598 | 373 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 374 | the HAL_SMBUS_MspInit could be implemented in the user file |
mbed_official | 237:f3da66175598 | 375 | */ |
mbed_official | 237:f3da66175598 | 376 | } |
mbed_official | 237:f3da66175598 | 377 | |
mbed_official | 237:f3da66175598 | 378 | /** |
mbed_official | 237:f3da66175598 | 379 | * @brief SMBUS MSP DeInit |
mbed_official | 237:f3da66175598 | 380 | * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains |
mbed_official | 237:f3da66175598 | 381 | * the configuration information for the specified SMBUS. |
mbed_official | 237:f3da66175598 | 382 | * @retval None |
mbed_official | 237:f3da66175598 | 383 | */ |
mbed_official | 237:f3da66175598 | 384 | __weak void HAL_SMBUS_MspDeInit(SMBUS_HandleTypeDef *hsmbus) |
mbed_official | 237:f3da66175598 | 385 | { |
mbed_official | 237:f3da66175598 | 386 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 387 | the HAL_SMBUS_MspDeInit could be implemented in the user file |
mbed_official | 237:f3da66175598 | 388 | */ |
mbed_official | 237:f3da66175598 | 389 | } |
mbed_official | 237:f3da66175598 | 390 | |
mbed_official | 237:f3da66175598 | 391 | /** |
mbed_official | 237:f3da66175598 | 392 | * @} |
mbed_official | 237:f3da66175598 | 393 | */ |
mbed_official | 237:f3da66175598 | 394 | |
mbed_official | 375:3d36234a1087 | 395 | /** @defgroup SMBUS_Exported_Functions_Group2 Input and Output operation functions |
mbed_official | 237:f3da66175598 | 396 | * @brief Data transfers functions |
mbed_official | 237:f3da66175598 | 397 | * |
mbed_official | 237:f3da66175598 | 398 | @verbatim |
mbed_official | 237:f3da66175598 | 399 | =============================================================================== |
mbed_official | 237:f3da66175598 | 400 | ##### IO operation functions ##### |
mbed_official | 237:f3da66175598 | 401 | =============================================================================== |
mbed_official | 237:f3da66175598 | 402 | [..] |
mbed_official | 237:f3da66175598 | 403 | This subsection provides a set of functions allowing to manage the SMBUS data |
mbed_official | 237:f3da66175598 | 404 | transfers. |
mbed_official | 237:f3da66175598 | 405 | |
mbed_official | 237:f3da66175598 | 406 | (#) Blocking mode function to check if device is ready for usage is : |
mbed_official | 237:f3da66175598 | 407 | (++) HAL_SMBUS_IsDeviceReady() |
mbed_official | 237:f3da66175598 | 408 | |
mbed_official | 237:f3da66175598 | 409 | (#) There is only one mode of transfer: |
mbed_official | 237:f3da66175598 | 410 | (++) No-Blocking mode : The communication is performed using Interrupts. |
mbed_official | 237:f3da66175598 | 411 | These functions return the status of the transfer startup. |
mbed_official | 237:f3da66175598 | 412 | The end of the data processing will be indicated through the |
mbed_official | 237:f3da66175598 | 413 | dedicated SMBUS IRQ when using Interrupt mode. |
mbed_official | 237:f3da66175598 | 414 | |
mbed_official | 237:f3da66175598 | 415 | (#) No-Blocking mode functions with Interrupt are : |
mbed_official | 237:f3da66175598 | 416 | (++) HAL_SMBUS_Master_Transmit_IT() |
mbed_official | 237:f3da66175598 | 417 | (++) HAL_SMBUS_Master_Receive_IT() |
mbed_official | 237:f3da66175598 | 418 | (++) HAL_SMBUS_Slave_Transmit_IT() |
mbed_official | 237:f3da66175598 | 419 | (++) HAL_SMBUS_Slave_Receive_IT() |
mbed_official | 237:f3da66175598 | 420 | (++) HAL_SMBUS_Slave_Listen_IT() or alias HAL_SMBUS_EnableListen_IT() |
mbed_official | 237:f3da66175598 | 421 | (++) HAL_SMBUS_DisableListen_IT() |
mbed_official | 237:f3da66175598 | 422 | (++) HAL_SMBUS_EnableAlert_IT() |
mbed_official | 237:f3da66175598 | 423 | (++) HAL_SMBUS_DisableAlert_IT() |
mbed_official | 237:f3da66175598 | 424 | |
mbed_official | 237:f3da66175598 | 425 | (#) A set of Transfer Complete Callbacks are provided in No_Blocking mode: |
mbed_official | 237:f3da66175598 | 426 | (++) HAL_SMBUS_MasterTxCpltCallback() |
mbed_official | 237:f3da66175598 | 427 | (++) HAL_SMBUS_MasterRxCpltCallback() |
mbed_official | 237:f3da66175598 | 428 | (++) HAL_SMBUS_SlaveTxCpltCallback() |
mbed_official | 237:f3da66175598 | 429 | (++) HAL_SMBUS_SlaveRxCpltCallback() |
mbed_official | 237:f3da66175598 | 430 | (++) HAL_SMBUS_SlaveAddrCallback() or alias HAL_SMBUS_AddrCallback() |
mbed_official | 237:f3da66175598 | 431 | (++) HAL_SMBUS_SlaveListenCpltCallback() or alias HAL_SMBUS_ListenCpltCallback() |
mbed_official | 237:f3da66175598 | 432 | (++) HAL_SMBUS_ErrorCallback() |
mbed_official | 237:f3da66175598 | 433 | |
mbed_official | 237:f3da66175598 | 434 | @endverbatim |
mbed_official | 237:f3da66175598 | 435 | * @{ |
mbed_official | 237:f3da66175598 | 436 | */ |
mbed_official | 237:f3da66175598 | 437 | |
mbed_official | 375:3d36234a1087 | 438 | /** @defgroup Non-Blocking_mode_Interrupt Non-Blocking mode Interrupt |
mbed_official | 375:3d36234a1087 | 439 | * @{ |
mbed_official | 375:3d36234a1087 | 440 | */ |
mbed_official | 375:3d36234a1087 | 441 | |
mbed_official | 237:f3da66175598 | 442 | /** |
mbed_official | 237:f3da66175598 | 443 | * @brief Transmit in master/host SMBUS mode an amount of data in no-blocking mode with Interrupt |
mbed_official | 237:f3da66175598 | 444 | * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains |
mbed_official | 237:f3da66175598 | 445 | * the configuration information for the specified SMBUS. |
mbed_official | 237:f3da66175598 | 446 | * @param DevAddress: Target device address |
mbed_official | 237:f3da66175598 | 447 | * @param pData: Pointer to data buffer |
mbed_official | 237:f3da66175598 | 448 | * @param Size: Amount of data to be sent |
mbed_official | 237:f3da66175598 | 449 | * @param XferOptions: Options of Transfer, value of @ref SMBUS_XferOptions_definition |
mbed_official | 237:f3da66175598 | 450 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 451 | */ |
mbed_official | 237:f3da66175598 | 452 | HAL_StatusTypeDef HAL_SMBUS_Master_Transmit_IT(SMBUS_HandleTypeDef *hsmbus, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t XferOptions) |
mbed_official | 237:f3da66175598 | 453 | { |
mbed_official | 237:f3da66175598 | 454 | /* Check the parameters */ |
mbed_official | 237:f3da66175598 | 455 | assert_param(IS_SMBUS_TRANSFER_OPTIONS_REQUEST(XferOptions)); |
mbed_official | 237:f3da66175598 | 456 | |
mbed_official | 237:f3da66175598 | 457 | if(hsmbus->State == HAL_SMBUS_STATE_READY) |
mbed_official | 237:f3da66175598 | 458 | { |
mbed_official | 237:f3da66175598 | 459 | /* Process Locked */ |
mbed_official | 237:f3da66175598 | 460 | __HAL_LOCK(hsmbus); |
mbed_official | 237:f3da66175598 | 461 | |
mbed_official | 237:f3da66175598 | 462 | hsmbus->State = HAL_SMBUS_STATE_MASTER_BUSY_TX; |
mbed_official | 237:f3da66175598 | 463 | hsmbus->ErrorCode = HAL_SMBUS_ERROR_NONE; |
mbed_official | 237:f3da66175598 | 464 | /* Prepare transfer parameters */ |
mbed_official | 237:f3da66175598 | 465 | hsmbus->pBuffPtr = pData; |
mbed_official | 237:f3da66175598 | 466 | hsmbus->XferCount = Size; |
mbed_official | 237:f3da66175598 | 467 | hsmbus->XferOptions = XferOptions; |
mbed_official | 237:f3da66175598 | 468 | |
mbed_official | 237:f3da66175598 | 469 | /* In case of Quick command, remove autoend mode */ |
mbed_official | 237:f3da66175598 | 470 | /* Manage the stop generation by software */ |
mbed_official | 634:ac7d6880524d | 471 | if(hsmbus->pBuffPtr == HAL_NULL) |
mbed_official | 237:f3da66175598 | 472 | { |
mbed_official | 237:f3da66175598 | 473 | hsmbus->XferOptions &= ~SMBUS_AUTOEND_MODE; |
mbed_official | 237:f3da66175598 | 474 | } |
mbed_official | 237:f3da66175598 | 475 | |
mbed_official | 237:f3da66175598 | 476 | if(Size > MAX_NBYTE_SIZE) |
mbed_official | 237:f3da66175598 | 477 | { |
mbed_official | 237:f3da66175598 | 478 | hsmbus->XferSize = MAX_NBYTE_SIZE; |
mbed_official | 237:f3da66175598 | 479 | } |
mbed_official | 237:f3da66175598 | 480 | else |
mbed_official | 237:f3da66175598 | 481 | { |
mbed_official | 237:f3da66175598 | 482 | hsmbus->XferSize = Size; |
mbed_official | 237:f3da66175598 | 483 | } |
mbed_official | 237:f3da66175598 | 484 | |
mbed_official | 237:f3da66175598 | 485 | /* Send Slave Address */ |
mbed_official | 237:f3da66175598 | 486 | /* Set NBYTES to write and reload if size > MAX_NBYTE_SIZE and generate RESTART */ |
mbed_official | 237:f3da66175598 | 487 | if( (hsmbus->XferSize == MAX_NBYTE_SIZE) && (hsmbus->XferSize < hsmbus->XferCount) ) |
mbed_official | 237:f3da66175598 | 488 | { |
mbed_official | 237:f3da66175598 | 489 | SMBUS_TransferConfig(hsmbus,DevAddress,hsmbus->XferSize, SMBUS_RELOAD_MODE | (hsmbus->XferOptions & SMBUS_SENDPEC_MODE), SMBUS_GENERATE_START_WRITE); |
mbed_official | 237:f3da66175598 | 490 | } |
mbed_official | 237:f3da66175598 | 491 | else |
mbed_official | 237:f3da66175598 | 492 | { |
mbed_official | 237:f3da66175598 | 493 | /* If transfer direction not change, do not generate Restart Condition */ |
mbed_official | 237:f3da66175598 | 494 | /* Mean Previous state is same as current state */ |
mbed_official | 237:f3da66175598 | 495 | if(hsmbus->PreviousState == HAL_SMBUS_STATE_MASTER_BUSY_TX) |
mbed_official | 237:f3da66175598 | 496 | { |
mbed_official | 237:f3da66175598 | 497 | SMBUS_TransferConfig(hsmbus,DevAddress,hsmbus->XferSize, hsmbus->XferOptions, SMBUS_NO_STARTSTOP); |
mbed_official | 237:f3da66175598 | 498 | } |
mbed_official | 237:f3da66175598 | 499 | /* Else transfer direction change, so generate Restart with new transfer direction */ |
mbed_official | 237:f3da66175598 | 500 | else |
mbed_official | 237:f3da66175598 | 501 | { |
mbed_official | 237:f3da66175598 | 502 | SMBUS_TransferConfig(hsmbus,DevAddress,hsmbus->XferSize, hsmbus->XferOptions, SMBUS_GENERATE_START_WRITE); |
mbed_official | 237:f3da66175598 | 503 | } |
mbed_official | 237:f3da66175598 | 504 | |
mbed_official | 237:f3da66175598 | 505 | /* If PEC mode is enable, size to transmit manage by SW part should be Size-1 byte, corresponding to PEC byte */ |
mbed_official | 237:f3da66175598 | 506 | /* PEC byte is automatically sent by HW block, no need to manage it in Transmit process */ |
mbed_official | 237:f3da66175598 | 507 | if(__HAL_SMBUS_GET_PEC_MODE(hsmbus) != RESET) |
mbed_official | 237:f3da66175598 | 508 | { |
mbed_official | 237:f3da66175598 | 509 | hsmbus->XferSize--; |
mbed_official | 237:f3da66175598 | 510 | hsmbus->XferCount--; |
mbed_official | 237:f3da66175598 | 511 | } |
mbed_official | 237:f3da66175598 | 512 | } |
mbed_official | 237:f3da66175598 | 513 | |
mbed_official | 237:f3da66175598 | 514 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 515 | __HAL_UNLOCK(hsmbus); |
mbed_official | 237:f3da66175598 | 516 | |
mbed_official | 237:f3da66175598 | 517 | /* Note : The SMBUS interrupts must be enabled after unlocking current process |
mbed_official | 237:f3da66175598 | 518 | to avoid the risk of SMBUS interrupt handle execution before current |
mbed_official | 237:f3da66175598 | 519 | process unlock */ |
mbed_official | 237:f3da66175598 | 520 | SMBUS_Enable_IRQ(hsmbus, SMBUS_IT_TX); |
mbed_official | 237:f3da66175598 | 521 | |
mbed_official | 237:f3da66175598 | 522 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 523 | } |
mbed_official | 237:f3da66175598 | 524 | else |
mbed_official | 237:f3da66175598 | 525 | { |
mbed_official | 237:f3da66175598 | 526 | return HAL_BUSY; |
mbed_official | 237:f3da66175598 | 527 | } |
mbed_official | 237:f3da66175598 | 528 | } |
mbed_official | 237:f3da66175598 | 529 | |
mbed_official | 237:f3da66175598 | 530 | /** |
mbed_official | 237:f3da66175598 | 531 | * @brief Receive in master/host SMBUS mode an amount of data in no-blocking mode with Interrupt |
mbed_official | 237:f3da66175598 | 532 | * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains |
mbed_official | 237:f3da66175598 | 533 | * the configuration information for the specified SMBUS. |
mbed_official | 237:f3da66175598 | 534 | * @param DevAddress: Target device address |
mbed_official | 237:f3da66175598 | 535 | * @param pData: Pointer to data buffer |
mbed_official | 237:f3da66175598 | 536 | * @param Size: Amount of data to be sent |
mbed_official | 237:f3da66175598 | 537 | * @param XferOptions: Options of Transfer, value of @ref SMBUS_XferOptions_definition |
mbed_official | 237:f3da66175598 | 538 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 539 | */ |
mbed_official | 237:f3da66175598 | 540 | HAL_StatusTypeDef HAL_SMBUS_Master_Receive_IT(SMBUS_HandleTypeDef *hsmbus, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t XferOptions) |
mbed_official | 237:f3da66175598 | 541 | { |
mbed_official | 237:f3da66175598 | 542 | /* Check the parameters */ |
mbed_official | 237:f3da66175598 | 543 | assert_param(IS_SMBUS_TRANSFER_OPTIONS_REQUEST(XferOptions)); |
mbed_official | 237:f3da66175598 | 544 | |
mbed_official | 237:f3da66175598 | 545 | if(hsmbus->State == HAL_SMBUS_STATE_READY) |
mbed_official | 237:f3da66175598 | 546 | { |
mbed_official | 237:f3da66175598 | 547 | /* Process Locked */ |
mbed_official | 237:f3da66175598 | 548 | __HAL_LOCK(hsmbus); |
mbed_official | 237:f3da66175598 | 549 | |
mbed_official | 237:f3da66175598 | 550 | hsmbus->State = HAL_SMBUS_STATE_MASTER_BUSY_RX; |
mbed_official | 237:f3da66175598 | 551 | hsmbus->ErrorCode = HAL_SMBUS_ERROR_NONE; |
mbed_official | 237:f3da66175598 | 552 | |
mbed_official | 237:f3da66175598 | 553 | /* Prepare transfer parameters */ |
mbed_official | 237:f3da66175598 | 554 | hsmbus->pBuffPtr = pData; |
mbed_official | 237:f3da66175598 | 555 | hsmbus->XferCount = Size; |
mbed_official | 237:f3da66175598 | 556 | hsmbus->XferOptions = XferOptions; |
mbed_official | 237:f3da66175598 | 557 | |
mbed_official | 237:f3da66175598 | 558 | /* In case of Quick command, remove autoend mode */ |
mbed_official | 237:f3da66175598 | 559 | /* Manage the stop generation by software */ |
mbed_official | 634:ac7d6880524d | 560 | if(hsmbus->pBuffPtr == HAL_NULL) |
mbed_official | 237:f3da66175598 | 561 | { |
mbed_official | 237:f3da66175598 | 562 | hsmbus->XferOptions &= ~SMBUS_AUTOEND_MODE; |
mbed_official | 237:f3da66175598 | 563 | } |
mbed_official | 237:f3da66175598 | 564 | |
mbed_official | 237:f3da66175598 | 565 | if(Size > MAX_NBYTE_SIZE) |
mbed_official | 237:f3da66175598 | 566 | { |
mbed_official | 237:f3da66175598 | 567 | hsmbus->XferSize = MAX_NBYTE_SIZE; |
mbed_official | 237:f3da66175598 | 568 | } |
mbed_official | 237:f3da66175598 | 569 | else |
mbed_official | 237:f3da66175598 | 570 | { |
mbed_official | 237:f3da66175598 | 571 | hsmbus->XferSize = Size; |
mbed_official | 237:f3da66175598 | 572 | } |
mbed_official | 237:f3da66175598 | 573 | |
mbed_official | 237:f3da66175598 | 574 | /* Send Slave Address */ |
mbed_official | 237:f3da66175598 | 575 | /* Set NBYTES to write and reload if size > MAX_NBYTE_SIZE and generate RESTART */ |
mbed_official | 237:f3da66175598 | 576 | if( (hsmbus->XferSize == MAX_NBYTE_SIZE) && (hsmbus->XferSize < hsmbus->XferCount) ) |
mbed_official | 237:f3da66175598 | 577 | { |
mbed_official | 237:f3da66175598 | 578 | SMBUS_TransferConfig(hsmbus,DevAddress,hsmbus->XferSize, SMBUS_RELOAD_MODE | (hsmbus->XferOptions & SMBUS_SENDPEC_MODE), SMBUS_GENERATE_START_READ); |
mbed_official | 237:f3da66175598 | 579 | } |
mbed_official | 237:f3da66175598 | 580 | else |
mbed_official | 237:f3da66175598 | 581 | { |
mbed_official | 237:f3da66175598 | 582 | /* If transfer direction not change, do not generate Restart Condition */ |
mbed_official | 237:f3da66175598 | 583 | /* Mean Previous state is same as current state */ |
mbed_official | 237:f3da66175598 | 584 | if(hsmbus->PreviousState == HAL_SMBUS_STATE_MASTER_BUSY_RX) |
mbed_official | 237:f3da66175598 | 585 | { |
mbed_official | 237:f3da66175598 | 586 | SMBUS_TransferConfig(hsmbus,DevAddress,hsmbus->XferSize, hsmbus->XferOptions, SMBUS_NO_STARTSTOP); |
mbed_official | 237:f3da66175598 | 587 | } |
mbed_official | 237:f3da66175598 | 588 | /* Else transfer direction change, so generate Restart with new transfer direction */ |
mbed_official | 237:f3da66175598 | 589 | else |
mbed_official | 237:f3da66175598 | 590 | { |
mbed_official | 237:f3da66175598 | 591 | SMBUS_TransferConfig(hsmbus,DevAddress,hsmbus->XferSize, hsmbus->XferOptions, SMBUS_GENERATE_START_READ); |
mbed_official | 237:f3da66175598 | 592 | } |
mbed_official | 237:f3da66175598 | 593 | } |
mbed_official | 237:f3da66175598 | 594 | |
mbed_official | 237:f3da66175598 | 595 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 596 | __HAL_UNLOCK(hsmbus); |
mbed_official | 237:f3da66175598 | 597 | |
mbed_official | 237:f3da66175598 | 598 | /* Note : The SMBUS interrupts must be enabled after unlocking current process |
mbed_official | 237:f3da66175598 | 599 | to avoid the risk of SMBUS interrupt handle execution before current |
mbed_official | 237:f3da66175598 | 600 | process unlock */ |
mbed_official | 237:f3da66175598 | 601 | SMBUS_Enable_IRQ(hsmbus, SMBUS_IT_RX); |
mbed_official | 237:f3da66175598 | 602 | |
mbed_official | 237:f3da66175598 | 603 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 604 | } |
mbed_official | 237:f3da66175598 | 605 | else |
mbed_official | 237:f3da66175598 | 606 | { |
mbed_official | 237:f3da66175598 | 607 | return HAL_BUSY; |
mbed_official | 237:f3da66175598 | 608 | } |
mbed_official | 237:f3da66175598 | 609 | } |
mbed_official | 237:f3da66175598 | 610 | |
mbed_official | 237:f3da66175598 | 611 | /** |
mbed_official | 237:f3da66175598 | 612 | * @brief Abort a master/host SMBUS process commnunication with Interrupt |
mbed_official | 237:f3da66175598 | 613 | * @note : This abort can be called only if state is ready |
mbed_official | 237:f3da66175598 | 614 | * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains |
mbed_official | 237:f3da66175598 | 615 | * the configuration information for the specified SMBUS. |
mbed_official | 237:f3da66175598 | 616 | * @param DevAddress: Target device address |
mbed_official | 237:f3da66175598 | 617 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 618 | */ |
mbed_official | 237:f3da66175598 | 619 | HAL_StatusTypeDef HAL_SMBUS_Master_Abort_IT(SMBUS_HandleTypeDef *hsmbus, uint16_t DevAddress) |
mbed_official | 237:f3da66175598 | 620 | { |
mbed_official | 237:f3da66175598 | 621 | if(hsmbus->State == HAL_SMBUS_STATE_READY) |
mbed_official | 237:f3da66175598 | 622 | { |
mbed_official | 237:f3da66175598 | 623 | /* Process Locked */ |
mbed_official | 237:f3da66175598 | 624 | __HAL_LOCK(hsmbus); |
mbed_official | 237:f3da66175598 | 625 | |
mbed_official | 237:f3da66175598 | 626 | /* Keep the same state as previous */ |
mbed_official | 237:f3da66175598 | 627 | /* to perform as well the call of the corresponding end of transfer callback */ |
mbed_official | 237:f3da66175598 | 628 | if(hsmbus->PreviousState == HAL_SMBUS_STATE_MASTER_BUSY_TX) |
mbed_official | 237:f3da66175598 | 629 | { |
mbed_official | 237:f3da66175598 | 630 | hsmbus->State = HAL_SMBUS_STATE_MASTER_BUSY_TX; |
mbed_official | 237:f3da66175598 | 631 | } |
mbed_official | 237:f3da66175598 | 632 | else if(hsmbus->PreviousState == HAL_SMBUS_STATE_MASTER_BUSY_RX) |
mbed_official | 237:f3da66175598 | 633 | { |
mbed_official | 237:f3da66175598 | 634 | hsmbus->State = HAL_SMBUS_STATE_MASTER_BUSY_RX; |
mbed_official | 237:f3da66175598 | 635 | } |
mbed_official | 237:f3da66175598 | 636 | else |
mbed_official | 237:f3da66175598 | 637 | { |
mbed_official | 237:f3da66175598 | 638 | /* Wrong usage of abort function */ |
mbed_official | 237:f3da66175598 | 639 | /* This function should be used only in case of abort monitored by master device */ |
mbed_official | 237:f3da66175598 | 640 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 641 | } |
mbed_official | 237:f3da66175598 | 642 | hsmbus->ErrorCode = HAL_SMBUS_ERROR_NONE; |
mbed_official | 237:f3da66175598 | 643 | |
mbed_official | 237:f3da66175598 | 644 | /* Set NBYTES to 1 to generate a dummy read on SMBUS peripheral */ |
mbed_official | 237:f3da66175598 | 645 | /* Set AUTOEND mode, this will generate a NACK then STOP condition to abort the current transfer */ |
mbed_official | 237:f3da66175598 | 646 | SMBUS_TransferConfig(hsmbus, DevAddress, 1, SMBUS_AUTOEND_MODE, SMBUS_NO_STARTSTOP); |
mbed_official | 237:f3da66175598 | 647 | |
mbed_official | 237:f3da66175598 | 648 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 649 | __HAL_UNLOCK(hsmbus); |
mbed_official | 237:f3da66175598 | 650 | |
mbed_official | 237:f3da66175598 | 651 | /* Note : The SMBUS interrupts must be enabled after unlocking current process |
mbed_official | 237:f3da66175598 | 652 | to avoid the risk of SMBUS interrupt handle execution before current |
mbed_official | 237:f3da66175598 | 653 | process unlock */ |
mbed_official | 237:f3da66175598 | 654 | if(hsmbus->State == HAL_SMBUS_STATE_MASTER_BUSY_TX) |
mbed_official | 237:f3da66175598 | 655 | { |
mbed_official | 237:f3da66175598 | 656 | SMBUS_Enable_IRQ(hsmbus, SMBUS_IT_TX); |
mbed_official | 237:f3da66175598 | 657 | } |
mbed_official | 237:f3da66175598 | 658 | else if(hsmbus->State == HAL_SMBUS_STATE_MASTER_BUSY_RX) |
mbed_official | 237:f3da66175598 | 659 | { |
mbed_official | 237:f3da66175598 | 660 | SMBUS_Enable_IRQ(hsmbus, SMBUS_IT_RX); |
mbed_official | 237:f3da66175598 | 661 | } |
mbed_official | 237:f3da66175598 | 662 | |
mbed_official | 237:f3da66175598 | 663 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 664 | } |
mbed_official | 237:f3da66175598 | 665 | else |
mbed_official | 237:f3da66175598 | 666 | { |
mbed_official | 237:f3da66175598 | 667 | return HAL_BUSY; |
mbed_official | 237:f3da66175598 | 668 | } |
mbed_official | 237:f3da66175598 | 669 | } |
mbed_official | 237:f3da66175598 | 670 | |
mbed_official | 237:f3da66175598 | 671 | /** |
mbed_official | 237:f3da66175598 | 672 | * @brief Transmit in slave/device SMBUS mode an amount of data in no-blocking mode with Interrupt |
mbed_official | 237:f3da66175598 | 673 | * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains |
mbed_official | 237:f3da66175598 | 674 | * the configuration information for the specified SMBUS. |
mbed_official | 237:f3da66175598 | 675 | * @param pData: Pointer to data buffer |
mbed_official | 237:f3da66175598 | 676 | * @param Size: Amount of data to be sent |
mbed_official | 237:f3da66175598 | 677 | * @param XferOptions: Options of Transfer, value of @ref SMBUS_XferOptions_definition |
mbed_official | 237:f3da66175598 | 678 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 679 | */ |
mbed_official | 237:f3da66175598 | 680 | HAL_StatusTypeDef HAL_SMBUS_Slave_Transmit_IT(SMBUS_HandleTypeDef *hsmbus, uint8_t *pData, uint16_t Size, uint32_t XferOptions) |
mbed_official | 237:f3da66175598 | 681 | { |
mbed_official | 237:f3da66175598 | 682 | /* Check the parameters */ |
mbed_official | 237:f3da66175598 | 683 | assert_param(IS_SMBUS_TRANSFER_OPTIONS_REQUEST(XferOptions)); |
mbed_official | 237:f3da66175598 | 684 | |
mbed_official | 237:f3da66175598 | 685 | if(hsmbus->State == HAL_SMBUS_STATE_LISTEN) |
mbed_official | 237:f3da66175598 | 686 | { |
mbed_official | 634:ac7d6880524d | 687 | if((pData == HAL_NULL) || (Size == 0)) |
mbed_official | 237:f3da66175598 | 688 | { |
mbed_official | 237:f3da66175598 | 689 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 690 | } |
mbed_official | 237:f3da66175598 | 691 | |
mbed_official | 237:f3da66175598 | 692 | /* Disable Interrupts, to prevent preemption during treatment in case of multicall */ |
mbed_official | 237:f3da66175598 | 693 | SMBUS_Disable_IRQ(hsmbus, SMBUS_IT_ADDR | SMBUS_IT_TX); |
mbed_official | 237:f3da66175598 | 694 | |
mbed_official | 237:f3da66175598 | 695 | /* Process Locked */ |
mbed_official | 237:f3da66175598 | 696 | __HAL_LOCK(hsmbus); |
mbed_official | 237:f3da66175598 | 697 | |
mbed_official | 237:f3da66175598 | 698 | hsmbus->State |= HAL_SMBUS_STATE_SLAVE_BUSY_TX; |
mbed_official | 237:f3da66175598 | 699 | hsmbus->ErrorCode = HAL_SMBUS_ERROR_NONE; |
mbed_official | 237:f3da66175598 | 700 | |
mbed_official | 375:3d36234a1087 | 701 | /* Set SBC bit to manage Acknowledge at each bit */ |
mbed_official | 375:3d36234a1087 | 702 | hsmbus->Instance->CR1 |= I2C_CR1_SBC; |
mbed_official | 375:3d36234a1087 | 703 | |
mbed_official | 237:f3da66175598 | 704 | /* Enable Address Acknowledge */ |
mbed_official | 237:f3da66175598 | 705 | hsmbus->Instance->CR2 &= ~I2C_CR2_NACK; |
mbed_official | 237:f3da66175598 | 706 | |
mbed_official | 237:f3da66175598 | 707 | /* Prepare transfer parameters */ |
mbed_official | 237:f3da66175598 | 708 | hsmbus->pBuffPtr = pData; |
mbed_official | 237:f3da66175598 | 709 | hsmbus->XferSize = Size; |
mbed_official | 237:f3da66175598 | 710 | hsmbus->XferCount = Size; |
mbed_official | 237:f3da66175598 | 711 | hsmbus->XferOptions = XferOptions; |
mbed_official | 237:f3da66175598 | 712 | |
mbed_official | 237:f3da66175598 | 713 | if(Size > MAX_NBYTE_SIZE) |
mbed_official | 237:f3da66175598 | 714 | { |
mbed_official | 237:f3da66175598 | 715 | hsmbus->XferSize = MAX_NBYTE_SIZE; |
mbed_official | 237:f3da66175598 | 716 | } |
mbed_official | 237:f3da66175598 | 717 | else |
mbed_official | 237:f3da66175598 | 718 | { |
mbed_official | 237:f3da66175598 | 719 | hsmbus->XferSize = Size; |
mbed_official | 237:f3da66175598 | 720 | } |
mbed_official | 237:f3da66175598 | 721 | |
mbed_official | 237:f3da66175598 | 722 | /* Set NBYTES to write and reload if size > MAX_NBYTE_SIZE and generate RESTART */ |
mbed_official | 237:f3da66175598 | 723 | if( (hsmbus->XferSize == MAX_NBYTE_SIZE) && (hsmbus->XferSize < hsmbus->XferCount) ) |
mbed_official | 237:f3da66175598 | 724 | { |
mbed_official | 237:f3da66175598 | 725 | SMBUS_TransferConfig(hsmbus,0,hsmbus->XferSize, SMBUS_RELOAD_MODE | (hsmbus->XferOptions & SMBUS_SENDPEC_MODE), SMBUS_NO_STARTSTOP); |
mbed_official | 237:f3da66175598 | 726 | } |
mbed_official | 237:f3da66175598 | 727 | else |
mbed_official | 237:f3da66175598 | 728 | { |
mbed_official | 237:f3da66175598 | 729 | /* Set NBYTE to transmit */ |
mbed_official | 237:f3da66175598 | 730 | SMBUS_TransferConfig(hsmbus,0,hsmbus->XferSize, hsmbus->XferOptions, SMBUS_NO_STARTSTOP); |
mbed_official | 237:f3da66175598 | 731 | |
mbed_official | 237:f3da66175598 | 732 | /* If PEC mode is enable, size to transmit should be Size-1 byte, corresponding to PEC byte */ |
mbed_official | 237:f3da66175598 | 733 | /* PEC byte is automatically sent by HW block, no need to manage it in Transmit process */ |
mbed_official | 237:f3da66175598 | 734 | if(__HAL_SMBUS_GET_PEC_MODE(hsmbus) != RESET) |
mbed_official | 237:f3da66175598 | 735 | { |
mbed_official | 237:f3da66175598 | 736 | hsmbus->XferSize--; |
mbed_official | 237:f3da66175598 | 737 | hsmbus->XferCount--; |
mbed_official | 237:f3da66175598 | 738 | } |
mbed_official | 237:f3da66175598 | 739 | } |
mbed_official | 237:f3da66175598 | 740 | |
mbed_official | 237:f3da66175598 | 741 | /* Clear ADDR flag after prepare the transfer parameters */ |
mbed_official | 237:f3da66175598 | 742 | /* This action will generate an acknowledge to the HOST */ |
mbed_official | 237:f3da66175598 | 743 | __HAL_SMBUS_CLEAR_FLAG(hsmbus,SMBUS_FLAG_ADDR); |
mbed_official | 237:f3da66175598 | 744 | |
mbed_official | 237:f3da66175598 | 745 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 746 | __HAL_UNLOCK(hsmbus); |
mbed_official | 237:f3da66175598 | 747 | |
mbed_official | 237:f3da66175598 | 748 | /* Note : The SMBUS interrupts must be enabled after unlocking current process |
mbed_official | 237:f3da66175598 | 749 | to avoid the risk of SMBUS interrupt handle execution before current |
mbed_official | 237:f3da66175598 | 750 | process unlock */ |
mbed_official | 237:f3da66175598 | 751 | /* REnable ADDR interrupt */ |
mbed_official | 237:f3da66175598 | 752 | SMBUS_Enable_IRQ(hsmbus, SMBUS_IT_TX | SMBUS_IT_ADDR); |
mbed_official | 237:f3da66175598 | 753 | |
mbed_official | 237:f3da66175598 | 754 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 755 | } |
mbed_official | 237:f3da66175598 | 756 | else |
mbed_official | 237:f3da66175598 | 757 | { |
mbed_official | 237:f3da66175598 | 758 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 759 | } |
mbed_official | 237:f3da66175598 | 760 | } |
mbed_official | 237:f3da66175598 | 761 | |
mbed_official | 237:f3da66175598 | 762 | /** |
mbed_official | 237:f3da66175598 | 763 | * @brief Receive in slave/device SMBUS mode an amount of data in no-blocking mode with Interrupt |
mbed_official | 237:f3da66175598 | 764 | * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains |
mbed_official | 237:f3da66175598 | 765 | * the configuration information for the specified SMBUS. |
mbed_official | 237:f3da66175598 | 766 | * @param pData: Pointer to data buffer |
mbed_official | 237:f3da66175598 | 767 | * @param Size: Amount of data to be sent |
mbed_official | 237:f3da66175598 | 768 | * @param XferOptions: Options of Transfer, value of @ref SMBUS_XferOptions_definition |
mbed_official | 237:f3da66175598 | 769 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 770 | */ |
mbed_official | 237:f3da66175598 | 771 | HAL_StatusTypeDef HAL_SMBUS_Slave_Receive_IT(SMBUS_HandleTypeDef *hsmbus, uint8_t *pData, uint16_t Size, uint32_t XferOptions) |
mbed_official | 237:f3da66175598 | 772 | { |
mbed_official | 237:f3da66175598 | 773 | /* Check the parameters */ |
mbed_official | 237:f3da66175598 | 774 | assert_param(IS_SMBUS_TRANSFER_OPTIONS_REQUEST(XferOptions)); |
mbed_official | 237:f3da66175598 | 775 | |
mbed_official | 237:f3da66175598 | 776 | if(hsmbus->State == HAL_SMBUS_STATE_LISTEN) |
mbed_official | 237:f3da66175598 | 777 | { |
mbed_official | 634:ac7d6880524d | 778 | if((pData == HAL_NULL) || (Size == 0)) |
mbed_official | 237:f3da66175598 | 779 | { |
mbed_official | 237:f3da66175598 | 780 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 781 | } |
mbed_official | 237:f3da66175598 | 782 | |
mbed_official | 237:f3da66175598 | 783 | /* Disable Interrupts, to prevent preemption during treatment in case of multicall */ |
mbed_official | 237:f3da66175598 | 784 | SMBUS_Disable_IRQ(hsmbus, SMBUS_IT_ADDR | SMBUS_IT_RX); |
mbed_official | 237:f3da66175598 | 785 | |
mbed_official | 237:f3da66175598 | 786 | /* Process Locked */ |
mbed_official | 237:f3da66175598 | 787 | __HAL_LOCK(hsmbus); |
mbed_official | 237:f3da66175598 | 788 | |
mbed_official | 237:f3da66175598 | 789 | hsmbus->State |= HAL_SMBUS_STATE_SLAVE_BUSY_RX; |
mbed_official | 237:f3da66175598 | 790 | hsmbus->ErrorCode = HAL_SMBUS_ERROR_NONE; |
mbed_official | 237:f3da66175598 | 791 | |
mbed_official | 375:3d36234a1087 | 792 | /* Set SBC bit to manage Acknowledge at each bit */ |
mbed_official | 375:3d36234a1087 | 793 | hsmbus->Instance->CR1 |= I2C_CR1_SBC; |
mbed_official | 375:3d36234a1087 | 794 | |
mbed_official | 237:f3da66175598 | 795 | /* Enable Address Acknowledge */ |
mbed_official | 237:f3da66175598 | 796 | hsmbus->Instance->CR2 &= ~I2C_CR2_NACK; |
mbed_official | 237:f3da66175598 | 797 | |
mbed_official | 237:f3da66175598 | 798 | /* Prepare transfer parameters */ |
mbed_official | 237:f3da66175598 | 799 | hsmbus->pBuffPtr = pData; |
mbed_official | 237:f3da66175598 | 800 | hsmbus->XferSize = Size; |
mbed_official | 237:f3da66175598 | 801 | hsmbus->XferCount = Size; |
mbed_official | 237:f3da66175598 | 802 | hsmbus->XferOptions = XferOptions; |
mbed_official | 237:f3da66175598 | 803 | |
mbed_official | 237:f3da66175598 | 804 | /* Set NBYTE to receive */ |
mbed_official | 237:f3da66175598 | 805 | /* If XferSize equal "1", or XferSize equal "2" with PEC requested (mean 1 data byte + 1 PEC byte */ |
mbed_official | 237:f3da66175598 | 806 | /* no need to set RELOAD bit mode, a ACK will be automatically generated in that case */ |
mbed_official | 237:f3da66175598 | 807 | /* else need to set RELOAD bit mode to generate an automatic ACK at each byte Received */ |
mbed_official | 237:f3da66175598 | 808 | /* This RELOAD bit will be reset for last BYTE to be receive in SMBUS_Slave_ISR */ |
mbed_official | 237:f3da66175598 | 809 | if((hsmbus->XferSize == 1) || ((hsmbus->XferSize == 2) && (__HAL_SMBUS_GET_PEC_MODE(hsmbus) != RESET))) |
mbed_official | 237:f3da66175598 | 810 | { |
mbed_official | 237:f3da66175598 | 811 | SMBUS_TransferConfig(hsmbus,0,hsmbus->XferSize, hsmbus->XferOptions, SMBUS_NO_STARTSTOP); |
mbed_official | 237:f3da66175598 | 812 | } |
mbed_official | 237:f3da66175598 | 813 | else |
mbed_official | 237:f3da66175598 | 814 | { |
mbed_official | 237:f3da66175598 | 815 | SMBUS_TransferConfig(hsmbus,0, 1, hsmbus->XferOptions | SMBUS_RELOAD_MODE, SMBUS_NO_STARTSTOP); |
mbed_official | 237:f3da66175598 | 816 | } |
mbed_official | 237:f3da66175598 | 817 | |
mbed_official | 237:f3da66175598 | 818 | /* Clear ADDR flag after prepare the transfer parameters */ |
mbed_official | 237:f3da66175598 | 819 | /* This action will generate an acknowledge to the HOST */ |
mbed_official | 237:f3da66175598 | 820 | __HAL_SMBUS_CLEAR_FLAG(hsmbus,SMBUS_FLAG_ADDR); |
mbed_official | 237:f3da66175598 | 821 | |
mbed_official | 237:f3da66175598 | 822 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 823 | __HAL_UNLOCK(hsmbus); |
mbed_official | 237:f3da66175598 | 824 | |
mbed_official | 237:f3da66175598 | 825 | /* Note : The SMBUS interrupts must be enabled after unlocking current process |
mbed_official | 237:f3da66175598 | 826 | to avoid the risk of SMBUS interrupt handle execution before current |
mbed_official | 237:f3da66175598 | 827 | process unlock */ |
mbed_official | 237:f3da66175598 | 828 | /* REnable ADDR interrupt */ |
mbed_official | 237:f3da66175598 | 829 | SMBUS_Enable_IRQ(hsmbus, SMBUS_IT_RX | SMBUS_IT_ADDR); |
mbed_official | 237:f3da66175598 | 830 | |
mbed_official | 237:f3da66175598 | 831 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 832 | } |
mbed_official | 237:f3da66175598 | 833 | else |
mbed_official | 237:f3da66175598 | 834 | { |
mbed_official | 237:f3da66175598 | 835 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 836 | } |
mbed_official | 237:f3da66175598 | 837 | } |
mbed_official | 237:f3da66175598 | 838 | |
mbed_official | 237:f3da66175598 | 839 | /** |
mbed_official | 237:f3da66175598 | 840 | * @brief This function enable the Address listen mode |
mbed_official | 237:f3da66175598 | 841 | * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains |
mbed_official | 237:f3da66175598 | 842 | * the configuration information for the specified SMBUS. |
mbed_official | 237:f3da66175598 | 843 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 844 | */ |
mbed_official | 237:f3da66175598 | 845 | HAL_StatusTypeDef HAL_SMBUS_Slave_Listen_IT(SMBUS_HandleTypeDef *hsmbus) |
mbed_official | 237:f3da66175598 | 846 | { |
mbed_official | 237:f3da66175598 | 847 | hsmbus->State = HAL_SMBUS_STATE_LISTEN; |
mbed_official | 237:f3da66175598 | 848 | |
mbed_official | 237:f3da66175598 | 849 | /* Enable the Address Match interrupt */ |
mbed_official | 237:f3da66175598 | 850 | SMBUS_Enable_IRQ(hsmbus, SMBUS_IT_ADDR); |
mbed_official | 237:f3da66175598 | 851 | |
mbed_official | 237:f3da66175598 | 852 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 853 | } |
mbed_official | 237:f3da66175598 | 854 | |
mbed_official | 237:f3da66175598 | 855 | /** |
mbed_official | 237:f3da66175598 | 856 | * @brief This function disable the Address listen mode |
mbed_official | 237:f3da66175598 | 857 | * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains |
mbed_official | 237:f3da66175598 | 858 | * the configuration information for the specified SMBUS. |
mbed_official | 237:f3da66175598 | 859 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 860 | */ |
mbed_official | 237:f3da66175598 | 861 | HAL_StatusTypeDef HAL_SMBUS_DisableListen_IT(SMBUS_HandleTypeDef *hsmbus) |
mbed_official | 237:f3da66175598 | 862 | { |
mbed_official | 237:f3da66175598 | 863 | /* Disable Address listen mode only if a transfer is not ongoing */ |
mbed_official | 237:f3da66175598 | 864 | if(hsmbus->State == HAL_SMBUS_STATE_LISTEN) |
mbed_official | 237:f3da66175598 | 865 | { |
mbed_official | 237:f3da66175598 | 866 | hsmbus->State = HAL_SMBUS_STATE_READY; |
mbed_official | 237:f3da66175598 | 867 | |
mbed_official | 237:f3da66175598 | 868 | /* Disable the Address Match interrupt */ |
mbed_official | 237:f3da66175598 | 869 | SMBUS_Disable_IRQ(hsmbus, SMBUS_IT_ADDR); |
mbed_official | 237:f3da66175598 | 870 | |
mbed_official | 237:f3da66175598 | 871 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 872 | } |
mbed_official | 237:f3da66175598 | 873 | else |
mbed_official | 237:f3da66175598 | 874 | { |
mbed_official | 237:f3da66175598 | 875 | return HAL_BUSY; |
mbed_official | 237:f3da66175598 | 876 | } |
mbed_official | 237:f3da66175598 | 877 | } |
mbed_official | 237:f3da66175598 | 878 | |
mbed_official | 237:f3da66175598 | 879 | /** |
mbed_official | 237:f3da66175598 | 880 | * @brief This function enable the SMBUS alert mode. |
mbed_official | 237:f3da66175598 | 881 | * @param hsmbus : pointer to a SMBUS_HandleTypeDef structure that contains |
mbed_official | 237:f3da66175598 | 882 | * the configuration information for the specified SMBUSx peripheral. |
mbed_official | 237:f3da66175598 | 883 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 884 | */ |
mbed_official | 237:f3da66175598 | 885 | HAL_StatusTypeDef HAL_SMBUS_EnableAlert_IT(SMBUS_HandleTypeDef *hsmbus) |
mbed_official | 237:f3da66175598 | 886 | { |
mbed_official | 237:f3da66175598 | 887 | /* Enable SMBus alert */ |
mbed_official | 237:f3da66175598 | 888 | hsmbus->Instance->CR1 |= I2C_CR1_ALERTEN; |
mbed_official | 237:f3da66175598 | 889 | |
mbed_official | 237:f3da66175598 | 890 | /* Clear ALERT flag */ |
mbed_official | 237:f3da66175598 | 891 | __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_ALERT); |
mbed_official | 237:f3da66175598 | 892 | |
mbed_official | 237:f3da66175598 | 893 | /* Enable Alert Interrupt */ |
mbed_official | 237:f3da66175598 | 894 | SMBUS_Enable_IRQ(hsmbus, SMBUS_IT_ALERT); |
mbed_official | 237:f3da66175598 | 895 | |
mbed_official | 237:f3da66175598 | 896 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 897 | } |
mbed_official | 237:f3da66175598 | 898 | /** |
mbed_official | 237:f3da66175598 | 899 | * @brief This function disable the SMBUS alert mode. |
mbed_official | 237:f3da66175598 | 900 | * @param hsmbus : pointer to a SMBUS_HandleTypeDef structure that contains |
mbed_official | 237:f3da66175598 | 901 | * the configuration information for the specified SMBUSx peripheral. |
mbed_official | 237:f3da66175598 | 902 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 903 | */ |
mbed_official | 237:f3da66175598 | 904 | HAL_StatusTypeDef HAL_SMBUS_DisableAlert_IT(SMBUS_HandleTypeDef *hsmbus) |
mbed_official | 237:f3da66175598 | 905 | { |
mbed_official | 237:f3da66175598 | 906 | /* Enable SMBus alert */ |
mbed_official | 237:f3da66175598 | 907 | hsmbus->Instance->CR1 &= ~I2C_CR1_ALERTEN; |
mbed_official | 237:f3da66175598 | 908 | |
mbed_official | 237:f3da66175598 | 909 | /* Disable Alert Interrupt */ |
mbed_official | 237:f3da66175598 | 910 | SMBUS_Disable_IRQ(hsmbus, SMBUS_IT_ALERT); |
mbed_official | 237:f3da66175598 | 911 | |
mbed_official | 237:f3da66175598 | 912 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 913 | } |
mbed_official | 375:3d36234a1087 | 914 | |
mbed_official | 375:3d36234a1087 | 915 | /** |
mbed_official | 375:3d36234a1087 | 916 | * @} |
mbed_official | 375:3d36234a1087 | 917 | */ |
mbed_official | 375:3d36234a1087 | 918 | |
mbed_official | 375:3d36234a1087 | 919 | /** @defgroup Blocking_mode_Polling Blocking mode Polling |
mbed_official | 375:3d36234a1087 | 920 | * @{ |
mbed_official | 375:3d36234a1087 | 921 | */ |
mbed_official | 237:f3da66175598 | 922 | /** |
mbed_official | 237:f3da66175598 | 923 | * @brief Checks if target device is ready for communication. |
mbed_official | 237:f3da66175598 | 924 | * @note This function is used with Memory devices |
mbed_official | 237:f3da66175598 | 925 | * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains |
mbed_official | 237:f3da66175598 | 926 | * the configuration information for the specified SMBUS. |
mbed_official | 237:f3da66175598 | 927 | * @param DevAddress: Target device address |
mbed_official | 237:f3da66175598 | 928 | * @param Trials: Number of trials |
mbed_official | 237:f3da66175598 | 929 | * @param Timeout: Timeout duration |
mbed_official | 237:f3da66175598 | 930 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 931 | */ |
mbed_official | 237:f3da66175598 | 932 | HAL_StatusTypeDef HAL_SMBUS_IsDeviceReady(SMBUS_HandleTypeDef *hsmbus, uint16_t DevAddress, uint32_t Trials, uint32_t Timeout) |
mbed_official | 237:f3da66175598 | 933 | { |
mbed_official | 237:f3da66175598 | 934 | uint32_t tickstart = 0; |
mbed_official | 237:f3da66175598 | 935 | |
mbed_official | 237:f3da66175598 | 936 | __IO uint32_t SMBUS_Trials = 0; |
mbed_official | 237:f3da66175598 | 937 | |
mbed_official | 237:f3da66175598 | 938 | if(hsmbus->State == HAL_SMBUS_STATE_READY) |
mbed_official | 237:f3da66175598 | 939 | { |
mbed_official | 237:f3da66175598 | 940 | if(__HAL_SMBUS_GET_FLAG(hsmbus, SMBUS_FLAG_BUSY) != RESET) |
mbed_official | 237:f3da66175598 | 941 | { |
mbed_official | 237:f3da66175598 | 942 | return HAL_BUSY; |
mbed_official | 237:f3da66175598 | 943 | } |
mbed_official | 237:f3da66175598 | 944 | |
mbed_official | 237:f3da66175598 | 945 | /* Process Locked */ |
mbed_official | 237:f3da66175598 | 946 | __HAL_LOCK(hsmbus); |
mbed_official | 237:f3da66175598 | 947 | |
mbed_official | 237:f3da66175598 | 948 | hsmbus->State = HAL_SMBUS_STATE_BUSY; |
mbed_official | 237:f3da66175598 | 949 | hsmbus->ErrorCode = HAL_SMBUS_ERROR_NONE; |
mbed_official | 237:f3da66175598 | 950 | |
mbed_official | 237:f3da66175598 | 951 | do |
mbed_official | 237:f3da66175598 | 952 | { |
mbed_official | 237:f3da66175598 | 953 | /* Generate Start */ |
mbed_official | 237:f3da66175598 | 954 | hsmbus->Instance->CR2 = __HAL_SMBUS_GENERATE_START(hsmbus->Init.AddressingMode,DevAddress); |
mbed_official | 237:f3da66175598 | 955 | |
mbed_official | 237:f3da66175598 | 956 | /* No need to Check TC flag, with AUTOEND mode the stop is automatically generated */ |
mbed_official | 237:f3da66175598 | 957 | /* Wait until STOPF flag is set or a NACK flag is set*/ |
mbed_official | 237:f3da66175598 | 958 | tickstart = HAL_GetTick(); |
mbed_official | 237:f3da66175598 | 959 | while((__HAL_SMBUS_GET_FLAG(hsmbus, SMBUS_FLAG_STOPF) == RESET) && (__HAL_SMBUS_GET_FLAG(hsmbus, SMBUS_FLAG_AF) == RESET) && (hsmbus->State != HAL_SMBUS_STATE_TIMEOUT)) |
mbed_official | 237:f3da66175598 | 960 | { |
mbed_official | 237:f3da66175598 | 961 | if(Timeout != HAL_MAX_DELAY) |
mbed_official | 237:f3da66175598 | 962 | { |
mbed_official | 237:f3da66175598 | 963 | if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout)) |
mbed_official | 237:f3da66175598 | 964 | { |
mbed_official | 237:f3da66175598 | 965 | /* Device is ready */ |
mbed_official | 237:f3da66175598 | 966 | hsmbus->State = HAL_SMBUS_STATE_READY; |
mbed_official | 237:f3da66175598 | 967 | |
mbed_official | 237:f3da66175598 | 968 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 969 | __HAL_UNLOCK(hsmbus); |
mbed_official | 237:f3da66175598 | 970 | return HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 971 | } |
mbed_official | 237:f3da66175598 | 972 | } |
mbed_official | 237:f3da66175598 | 973 | } |
mbed_official | 237:f3da66175598 | 974 | |
mbed_official | 237:f3da66175598 | 975 | /* Check if the NACKF flag has not been set */ |
mbed_official | 237:f3da66175598 | 976 | if (__HAL_SMBUS_GET_FLAG(hsmbus, SMBUS_FLAG_AF) == RESET) |
mbed_official | 237:f3da66175598 | 977 | { |
mbed_official | 237:f3da66175598 | 978 | /* Wait until STOPF flag is reset */ |
mbed_official | 237:f3da66175598 | 979 | if(SMBUS_WaitOnFlagUntilTimeout(hsmbus, SMBUS_FLAG_STOPF, RESET, Timeout) != HAL_OK) |
mbed_official | 237:f3da66175598 | 980 | { |
mbed_official | 237:f3da66175598 | 981 | return HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 982 | } |
mbed_official | 237:f3da66175598 | 983 | |
mbed_official | 237:f3da66175598 | 984 | /* Clear STOP Flag */ |
mbed_official | 237:f3da66175598 | 985 | __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_STOPF); |
mbed_official | 237:f3da66175598 | 986 | |
mbed_official | 237:f3da66175598 | 987 | /* Device is ready */ |
mbed_official | 237:f3da66175598 | 988 | hsmbus->State = HAL_SMBUS_STATE_READY; |
mbed_official | 237:f3da66175598 | 989 | |
mbed_official | 237:f3da66175598 | 990 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 991 | __HAL_UNLOCK(hsmbus); |
mbed_official | 237:f3da66175598 | 992 | |
mbed_official | 237:f3da66175598 | 993 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 994 | } |
mbed_official | 237:f3da66175598 | 995 | else |
mbed_official | 237:f3da66175598 | 996 | { |
mbed_official | 237:f3da66175598 | 997 | /* Wait until STOPF flag is reset */ |
mbed_official | 237:f3da66175598 | 998 | if(SMBUS_WaitOnFlagUntilTimeout(hsmbus, SMBUS_FLAG_STOPF, RESET, Timeout) != HAL_OK) |
mbed_official | 237:f3da66175598 | 999 | { |
mbed_official | 237:f3da66175598 | 1000 | return HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 1001 | } |
mbed_official | 237:f3da66175598 | 1002 | |
mbed_official | 237:f3da66175598 | 1003 | /* Clear NACK Flag */ |
mbed_official | 237:f3da66175598 | 1004 | __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_AF); |
mbed_official | 237:f3da66175598 | 1005 | |
mbed_official | 237:f3da66175598 | 1006 | /* Clear STOP Flag, auto generated with autoend*/ |
mbed_official | 237:f3da66175598 | 1007 | __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_STOPF); |
mbed_official | 237:f3da66175598 | 1008 | } |
mbed_official | 237:f3da66175598 | 1009 | |
mbed_official | 237:f3da66175598 | 1010 | /* Check if the maximum allowed number of trials has been reached */ |
mbed_official | 237:f3da66175598 | 1011 | if (SMBUS_Trials++ == Trials) |
mbed_official | 237:f3da66175598 | 1012 | { |
mbed_official | 237:f3da66175598 | 1013 | /* Generate Stop */ |
mbed_official | 237:f3da66175598 | 1014 | hsmbus->Instance->CR2 |= I2C_CR2_STOP; |
mbed_official | 237:f3da66175598 | 1015 | |
mbed_official | 237:f3da66175598 | 1016 | /* Wait until STOPF flag is reset */ |
mbed_official | 237:f3da66175598 | 1017 | if(SMBUS_WaitOnFlagUntilTimeout(hsmbus, SMBUS_FLAG_STOPF, RESET, Timeout) != HAL_OK) |
mbed_official | 237:f3da66175598 | 1018 | { |
mbed_official | 237:f3da66175598 | 1019 | return HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 1020 | } |
mbed_official | 237:f3da66175598 | 1021 | |
mbed_official | 237:f3da66175598 | 1022 | /* Clear STOP Flag */ |
mbed_official | 237:f3da66175598 | 1023 | __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_STOPF); |
mbed_official | 237:f3da66175598 | 1024 | } |
mbed_official | 237:f3da66175598 | 1025 | }while(SMBUS_Trials < Trials); |
mbed_official | 237:f3da66175598 | 1026 | |
mbed_official | 237:f3da66175598 | 1027 | hsmbus->State = HAL_SMBUS_STATE_READY; |
mbed_official | 237:f3da66175598 | 1028 | |
mbed_official | 237:f3da66175598 | 1029 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 1030 | __HAL_UNLOCK(hsmbus); |
mbed_official | 237:f3da66175598 | 1031 | |
mbed_official | 237:f3da66175598 | 1032 | return HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 1033 | } |
mbed_official | 237:f3da66175598 | 1034 | else |
mbed_official | 237:f3da66175598 | 1035 | { |
mbed_official | 237:f3da66175598 | 1036 | return HAL_BUSY; |
mbed_official | 237:f3da66175598 | 1037 | } |
mbed_official | 237:f3da66175598 | 1038 | } |
mbed_official | 375:3d36234a1087 | 1039 | /** |
mbed_official | 375:3d36234a1087 | 1040 | * @} |
mbed_official | 375:3d36234a1087 | 1041 | */ |
mbed_official | 375:3d36234a1087 | 1042 | |
mbed_official | 375:3d36234a1087 | 1043 | /** @defgroup IRQ_Handler_and_Callbacks IRQ Handler and Callbacks |
mbed_official | 375:3d36234a1087 | 1044 | * @{ |
mbed_official | 375:3d36234a1087 | 1045 | */ |
mbed_official | 237:f3da66175598 | 1046 | |
mbed_official | 237:f3da66175598 | 1047 | /** |
mbed_official | 237:f3da66175598 | 1048 | * @brief This function handles SMBUS event interrupt request. |
mbed_official | 237:f3da66175598 | 1049 | * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains |
mbed_official | 237:f3da66175598 | 1050 | * the configuration information for the specified SMBUS. |
mbed_official | 237:f3da66175598 | 1051 | * @retval None |
mbed_official | 237:f3da66175598 | 1052 | */ |
mbed_official | 237:f3da66175598 | 1053 | void HAL_SMBUS_EV_IRQHandler(SMBUS_HandleTypeDef *hsmbus) |
mbed_official | 237:f3da66175598 | 1054 | { |
mbed_official | 237:f3da66175598 | 1055 | uint32_t tmpisrvalue = 0; |
mbed_official | 237:f3da66175598 | 1056 | |
mbed_official | 237:f3da66175598 | 1057 | /* Use a local variable to store the current ISR flags */ |
mbed_official | 237:f3da66175598 | 1058 | /* This action will avoid a wrong treatment due to ISR flags change during interrupt handler */ |
mbed_official | 237:f3da66175598 | 1059 | tmpisrvalue = __SMBUS_GET_ISR_REG(hsmbus); |
mbed_official | 237:f3da66175598 | 1060 | |
mbed_official | 237:f3da66175598 | 1061 | /* SMBUS in mode Transmitter ---------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 1062 | if (((__SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_TXIS) != RESET) || (__SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_TCR) != RESET) || (__SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_TC) != RESET) || (__SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_STOPF) != RESET) || (__SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_AF) != RESET)) && (__HAL_SMBUS_GET_IT_SOURCE(hsmbus, (SMBUS_IT_TCI| SMBUS_IT_STOPI| SMBUS_IT_NACKI | SMBUS_IT_TXI)) != RESET)) |
mbed_official | 237:f3da66175598 | 1063 | { |
mbed_official | 237:f3da66175598 | 1064 | /* Slave mode selected */ |
mbed_official | 237:f3da66175598 | 1065 | if ((hsmbus->State & HAL_SMBUS_STATE_SLAVE_BUSY_TX) == HAL_SMBUS_STATE_SLAVE_BUSY_TX) |
mbed_official | 237:f3da66175598 | 1066 | { |
mbed_official | 237:f3da66175598 | 1067 | SMBUS_Slave_ISR(hsmbus); |
mbed_official | 237:f3da66175598 | 1068 | } |
mbed_official | 237:f3da66175598 | 1069 | /* Master mode selected */ |
mbed_official | 237:f3da66175598 | 1070 | else if((hsmbus->State & HAL_SMBUS_STATE_MASTER_BUSY_TX) == HAL_SMBUS_STATE_MASTER_BUSY_TX) |
mbed_official | 237:f3da66175598 | 1071 | { |
mbed_official | 237:f3da66175598 | 1072 | SMBUS_Master_ISR(hsmbus); |
mbed_official | 237:f3da66175598 | 1073 | } |
mbed_official | 237:f3da66175598 | 1074 | } |
mbed_official | 237:f3da66175598 | 1075 | |
mbed_official | 237:f3da66175598 | 1076 | /* SMBUS in mode Receiver ----------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 1077 | if (((__SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_RXNE) != RESET) || (__SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_TCR) != RESET) || (__SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_TC) != RESET) || (__SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_STOPF) != RESET) || (__SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_AF) != RESET)) && (__HAL_SMBUS_GET_IT_SOURCE(hsmbus, (SMBUS_IT_TCI| SMBUS_IT_STOPI| SMBUS_IT_NACKI | SMBUS_IT_RXI)) != RESET)) |
mbed_official | 237:f3da66175598 | 1078 | { |
mbed_official | 237:f3da66175598 | 1079 | /* Slave mode selected */ |
mbed_official | 237:f3da66175598 | 1080 | if ((hsmbus->State & HAL_SMBUS_STATE_SLAVE_BUSY_RX) == HAL_SMBUS_STATE_SLAVE_BUSY_RX) |
mbed_official | 237:f3da66175598 | 1081 | { |
mbed_official | 237:f3da66175598 | 1082 | SMBUS_Slave_ISR(hsmbus); |
mbed_official | 237:f3da66175598 | 1083 | } |
mbed_official | 237:f3da66175598 | 1084 | /* Master mode selected */ |
mbed_official | 237:f3da66175598 | 1085 | else if((hsmbus->State & HAL_SMBUS_STATE_MASTER_BUSY_RX) == HAL_SMBUS_STATE_MASTER_BUSY_RX) |
mbed_official | 237:f3da66175598 | 1086 | { |
mbed_official | 237:f3da66175598 | 1087 | SMBUS_Master_ISR(hsmbus); |
mbed_official | 237:f3da66175598 | 1088 | } |
mbed_official | 237:f3da66175598 | 1089 | } |
mbed_official | 237:f3da66175598 | 1090 | |
mbed_official | 237:f3da66175598 | 1091 | /* SMBUS in mode Listener Only --------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 1092 | if (((__SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_ADDR) != RESET) || (__SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_STOPF) != RESET) || (__SMBUS_CHECK_FLAG(tmpisrvalue, SMBUS_FLAG_AF) != RESET)) |
mbed_official | 237:f3da66175598 | 1093 | && ((__HAL_SMBUS_GET_IT_SOURCE(hsmbus, SMBUS_IT_ADDRI) != RESET) || (__HAL_SMBUS_GET_IT_SOURCE(hsmbus, SMBUS_IT_STOPI) != RESET) || (__HAL_SMBUS_GET_IT_SOURCE(hsmbus, SMBUS_IT_NACKI) != RESET))) |
mbed_official | 237:f3da66175598 | 1094 | { |
mbed_official | 237:f3da66175598 | 1095 | if (hsmbus->State == HAL_SMBUS_STATE_LISTEN) |
mbed_official | 237:f3da66175598 | 1096 | { |
mbed_official | 237:f3da66175598 | 1097 | SMBUS_Slave_ISR(hsmbus); |
mbed_official | 237:f3da66175598 | 1098 | } |
mbed_official | 237:f3da66175598 | 1099 | } |
mbed_official | 237:f3da66175598 | 1100 | } |
mbed_official | 237:f3da66175598 | 1101 | |
mbed_official | 237:f3da66175598 | 1102 | /** |
mbed_official | 237:f3da66175598 | 1103 | * @brief This function handles SMBUS error interrupt request. |
mbed_official | 237:f3da66175598 | 1104 | * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains |
mbed_official | 237:f3da66175598 | 1105 | * the configuration information for the specified SMBUS. |
mbed_official | 237:f3da66175598 | 1106 | * @retval None |
mbed_official | 237:f3da66175598 | 1107 | */ |
mbed_official | 237:f3da66175598 | 1108 | void HAL_SMBUS_ER_IRQHandler(SMBUS_HandleTypeDef *hsmbus) |
mbed_official | 237:f3da66175598 | 1109 | { |
mbed_official | 237:f3da66175598 | 1110 | /* SMBUS Bus error interrupt occurred ------------------------------------*/ |
mbed_official | 237:f3da66175598 | 1111 | if((__HAL_SMBUS_GET_FLAG(hsmbus, SMBUS_FLAG_BERR) != RESET) && (__HAL_SMBUS_GET_IT_SOURCE(hsmbus, SMBUS_IT_ERRI) != RESET)) |
mbed_official | 237:f3da66175598 | 1112 | { |
mbed_official | 237:f3da66175598 | 1113 | hsmbus->ErrorCode |= HAL_SMBUS_ERROR_BERR; |
mbed_official | 237:f3da66175598 | 1114 | |
mbed_official | 237:f3da66175598 | 1115 | /* Clear BERR flag */ |
mbed_official | 237:f3da66175598 | 1116 | __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_BERR); |
mbed_official | 237:f3da66175598 | 1117 | } |
mbed_official | 237:f3da66175598 | 1118 | |
mbed_official | 237:f3da66175598 | 1119 | /* SMBUS Over-Run/Under-Run interrupt occurred ----------------------------------------*/ |
mbed_official | 237:f3da66175598 | 1120 | if((__HAL_SMBUS_GET_FLAG(hsmbus, SMBUS_FLAG_OVR) != RESET) && (__HAL_SMBUS_GET_IT_SOURCE(hsmbus, SMBUS_IT_ERRI) != RESET)) |
mbed_official | 237:f3da66175598 | 1121 | { |
mbed_official | 237:f3da66175598 | 1122 | hsmbus->ErrorCode |= HAL_SMBUS_ERROR_OVR; |
mbed_official | 237:f3da66175598 | 1123 | |
mbed_official | 237:f3da66175598 | 1124 | /* Clear OVR flag */ |
mbed_official | 237:f3da66175598 | 1125 | __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_OVR); |
mbed_official | 237:f3da66175598 | 1126 | } |
mbed_official | 237:f3da66175598 | 1127 | |
mbed_official | 237:f3da66175598 | 1128 | /* SMBUS Arbitration Loss error interrupt occurred ------------------------------------*/ |
mbed_official | 237:f3da66175598 | 1129 | if((__HAL_SMBUS_GET_FLAG(hsmbus, SMBUS_FLAG_ARLO) != RESET) && (__HAL_SMBUS_GET_IT_SOURCE(hsmbus, SMBUS_IT_ERRI) != RESET)) |
mbed_official | 237:f3da66175598 | 1130 | { |
mbed_official | 237:f3da66175598 | 1131 | hsmbus->ErrorCode |= HAL_SMBUS_ERROR_ARLO; |
mbed_official | 237:f3da66175598 | 1132 | |
mbed_official | 237:f3da66175598 | 1133 | /* Clear ARLO flag */ |
mbed_official | 237:f3da66175598 | 1134 | __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_ARLO); |
mbed_official | 237:f3da66175598 | 1135 | } |
mbed_official | 237:f3da66175598 | 1136 | |
mbed_official | 237:f3da66175598 | 1137 | /* SMBUS Timeout error interrupt occurred ---------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 1138 | if((__HAL_SMBUS_GET_FLAG(hsmbus, SMBUS_FLAG_TIMEOUT) != RESET) && (__HAL_SMBUS_GET_IT_SOURCE(hsmbus, SMBUS_IT_ERRI) != RESET)) |
mbed_official | 237:f3da66175598 | 1139 | { |
mbed_official | 237:f3da66175598 | 1140 | hsmbus->ErrorCode |= HAL_SMBUS_ERROR_BUSTIMEOUT; |
mbed_official | 237:f3da66175598 | 1141 | |
mbed_official | 237:f3da66175598 | 1142 | /* Clear TIMEOUT flag */ |
mbed_official | 237:f3da66175598 | 1143 | __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_TIMEOUT); |
mbed_official | 237:f3da66175598 | 1144 | } |
mbed_official | 237:f3da66175598 | 1145 | |
mbed_official | 237:f3da66175598 | 1146 | /* SMBUS Alert error interrupt occurred -----------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 1147 | if((__HAL_SMBUS_GET_FLAG(hsmbus, SMBUS_FLAG_ALERT) != RESET) && (__HAL_SMBUS_GET_IT_SOURCE(hsmbus, SMBUS_IT_ERRI) != RESET)) |
mbed_official | 237:f3da66175598 | 1148 | { |
mbed_official | 237:f3da66175598 | 1149 | hsmbus->ErrorCode |= HAL_SMBUS_ERROR_ALERT; |
mbed_official | 237:f3da66175598 | 1150 | |
mbed_official | 237:f3da66175598 | 1151 | /* Clear ALERT flag */ |
mbed_official | 237:f3da66175598 | 1152 | __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_ALERT); |
mbed_official | 237:f3da66175598 | 1153 | } |
mbed_official | 237:f3da66175598 | 1154 | |
mbed_official | 237:f3da66175598 | 1155 | /* SMBUS Packet Error Check error interrupt occurred ----------------------------------*/ |
mbed_official | 237:f3da66175598 | 1156 | if((__HAL_SMBUS_GET_FLAG(hsmbus, SMBUS_FLAG_PECERR) != RESET) && (__HAL_SMBUS_GET_IT_SOURCE(hsmbus, SMBUS_IT_ERRI) != RESET)) |
mbed_official | 237:f3da66175598 | 1157 | { |
mbed_official | 237:f3da66175598 | 1158 | hsmbus->ErrorCode |= HAL_SMBUS_ERROR_PECERR; |
mbed_official | 237:f3da66175598 | 1159 | |
mbed_official | 237:f3da66175598 | 1160 | /* Clear PEC error flag */ |
mbed_official | 237:f3da66175598 | 1161 | __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_PECERR); |
mbed_official | 237:f3da66175598 | 1162 | } |
mbed_official | 237:f3da66175598 | 1163 | |
mbed_official | 237:f3da66175598 | 1164 | /* Call the Error Callback in case of Error detected */ |
mbed_official | 237:f3da66175598 | 1165 | if((hsmbus->ErrorCode != HAL_SMBUS_ERROR_NONE)&&(hsmbus->ErrorCode != HAL_SMBUS_ERROR_ACKF)) |
mbed_official | 237:f3da66175598 | 1166 | { |
mbed_official | 237:f3da66175598 | 1167 | /* Do not Reset the the HAL state in case of ALERT error */ |
mbed_official | 237:f3da66175598 | 1168 | if((hsmbus->ErrorCode & HAL_SMBUS_ERROR_ALERT) != HAL_SMBUS_ERROR_ALERT) |
mbed_official | 237:f3da66175598 | 1169 | { |
mbed_official | 375:3d36234a1087 | 1170 | if(((hsmbus->State & HAL_SMBUS_STATE_SLAVE_BUSY_TX) == HAL_SMBUS_STATE_SLAVE_BUSY_TX) |
mbed_official | 375:3d36234a1087 | 1171 | || ((hsmbus->State & HAL_SMBUS_STATE_SLAVE_BUSY_RX) == HAL_SMBUS_STATE_SLAVE_BUSY_RX)) |
mbed_official | 375:3d36234a1087 | 1172 | { |
mbed_official | 375:3d36234a1087 | 1173 | /* Reset only HAL_SMBUS_STATE_SLAVE_BUSY_XX */ |
mbed_official | 375:3d36234a1087 | 1174 | /* keep HAL_SMBUS_STATE_LISTEN if set */ |
mbed_official | 375:3d36234a1087 | 1175 | hsmbus->PreviousState = HAL_SMBUS_STATE_READY; |
mbed_official | 375:3d36234a1087 | 1176 | hsmbus->State = HAL_SMBUS_STATE_LISTEN; |
mbed_official | 375:3d36234a1087 | 1177 | } |
mbed_official | 237:f3da66175598 | 1178 | } |
mbed_official | 237:f3da66175598 | 1179 | |
mbed_official | 237:f3da66175598 | 1180 | /* Call the Error callback to prevent upper layer */ |
mbed_official | 237:f3da66175598 | 1181 | HAL_SMBUS_ErrorCallback(hsmbus); |
mbed_official | 237:f3da66175598 | 1182 | } |
mbed_official | 237:f3da66175598 | 1183 | } |
mbed_official | 237:f3da66175598 | 1184 | |
mbed_official | 237:f3da66175598 | 1185 | /** |
mbed_official | 237:f3da66175598 | 1186 | * @brief Master Tx Transfer completed callbacks. |
mbed_official | 237:f3da66175598 | 1187 | * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains |
mbed_official | 237:f3da66175598 | 1188 | * the configuration information for the specified SMBUS. |
mbed_official | 237:f3da66175598 | 1189 | * @retval None |
mbed_official | 237:f3da66175598 | 1190 | */ |
mbed_official | 237:f3da66175598 | 1191 | __weak void HAL_SMBUS_MasterTxCpltCallback(SMBUS_HandleTypeDef *hsmbus) |
mbed_official | 237:f3da66175598 | 1192 | { |
mbed_official | 237:f3da66175598 | 1193 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 1194 | the HAL_SMBUS_TxCpltCallback could be implemented in the user file |
mbed_official | 237:f3da66175598 | 1195 | */ |
mbed_official | 237:f3da66175598 | 1196 | } |
mbed_official | 237:f3da66175598 | 1197 | |
mbed_official | 237:f3da66175598 | 1198 | /** |
mbed_official | 237:f3da66175598 | 1199 | * @brief Master Rx Transfer completed callbacks. |
mbed_official | 237:f3da66175598 | 1200 | * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains |
mbed_official | 237:f3da66175598 | 1201 | * the configuration information for the specified SMBUS. |
mbed_official | 237:f3da66175598 | 1202 | * @retval None |
mbed_official | 237:f3da66175598 | 1203 | */ |
mbed_official | 237:f3da66175598 | 1204 | __weak void HAL_SMBUS_MasterRxCpltCallback(SMBUS_HandleTypeDef *hsmbus) |
mbed_official | 237:f3da66175598 | 1205 | { |
mbed_official | 237:f3da66175598 | 1206 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 1207 | the HAL_SMBUS_TxCpltCallback could be implemented in the user file |
mbed_official | 237:f3da66175598 | 1208 | */ |
mbed_official | 237:f3da66175598 | 1209 | } |
mbed_official | 237:f3da66175598 | 1210 | |
mbed_official | 237:f3da66175598 | 1211 | /** @brief Slave Tx Transfer completed callbacks. |
mbed_official | 237:f3da66175598 | 1212 | * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains |
mbed_official | 237:f3da66175598 | 1213 | * the configuration information for the specified SMBUS. |
mbed_official | 237:f3da66175598 | 1214 | * @retval None |
mbed_official | 237:f3da66175598 | 1215 | */ |
mbed_official | 237:f3da66175598 | 1216 | __weak void HAL_SMBUS_SlaveTxCpltCallback(SMBUS_HandleTypeDef *hsmbus) |
mbed_official | 237:f3da66175598 | 1217 | { |
mbed_official | 237:f3da66175598 | 1218 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 1219 | the HAL_SMBUS_TxCpltCallback could be implemented in the user file |
mbed_official | 237:f3da66175598 | 1220 | */ |
mbed_official | 237:f3da66175598 | 1221 | } |
mbed_official | 237:f3da66175598 | 1222 | |
mbed_official | 237:f3da66175598 | 1223 | /** |
mbed_official | 237:f3da66175598 | 1224 | * @brief Slave Rx Transfer completed callbacks. |
mbed_official | 237:f3da66175598 | 1225 | * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains |
mbed_official | 237:f3da66175598 | 1226 | * the configuration information for the specified SMBUS. |
mbed_official | 237:f3da66175598 | 1227 | * @retval None |
mbed_official | 237:f3da66175598 | 1228 | */ |
mbed_official | 237:f3da66175598 | 1229 | __weak void HAL_SMBUS_SlaveRxCpltCallback(SMBUS_HandleTypeDef *hsmbus) |
mbed_official | 237:f3da66175598 | 1230 | { |
mbed_official | 237:f3da66175598 | 1231 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 1232 | the HAL_SMBUS_TxCpltCallback could be implemented in the user file |
mbed_official | 237:f3da66175598 | 1233 | */ |
mbed_official | 237:f3da66175598 | 1234 | } |
mbed_official | 237:f3da66175598 | 1235 | |
mbed_official | 237:f3da66175598 | 1236 | /** |
mbed_official | 237:f3da66175598 | 1237 | * @brief Slave Address Match callbacks. |
mbed_official | 237:f3da66175598 | 1238 | * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains |
mbed_official | 237:f3da66175598 | 1239 | * the configuration information for the specified SMBUS. |
mbed_official | 237:f3da66175598 | 1240 | * @param TransferDirection: Master request Transfer Direction (Write/Read) |
mbed_official | 237:f3da66175598 | 1241 | * @param AddrMatchCode: Address Match Code |
mbed_official | 237:f3da66175598 | 1242 | * @retval None |
mbed_official | 237:f3da66175598 | 1243 | */ |
mbed_official | 237:f3da66175598 | 1244 | __weak void HAL_SMBUS_SlaveAddrCallback(SMBUS_HandleTypeDef *hsmbus, uint8_t TransferDirection, uint16_t AddrMatchCode) |
mbed_official | 237:f3da66175598 | 1245 | { |
mbed_official | 237:f3da66175598 | 1246 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 1247 | the HAL_SMBUS_SlaveAddrCallback could be implemented in the user file |
mbed_official | 237:f3da66175598 | 1248 | */ |
mbed_official | 237:f3da66175598 | 1249 | } |
mbed_official | 237:f3da66175598 | 1250 | |
mbed_official | 237:f3da66175598 | 1251 | /** |
mbed_official | 237:f3da66175598 | 1252 | * @brief Listen Complete callbacks. |
mbed_official | 237:f3da66175598 | 1253 | * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains |
mbed_official | 237:f3da66175598 | 1254 | * the configuration information for the specified SMBUS. |
mbed_official | 237:f3da66175598 | 1255 | * @retval None |
mbed_official | 237:f3da66175598 | 1256 | */ |
mbed_official | 237:f3da66175598 | 1257 | __weak void HAL_SMBUS_SlaveListenCpltCallback(SMBUS_HandleTypeDef *hsmbus) |
mbed_official | 237:f3da66175598 | 1258 | { |
mbed_official | 237:f3da66175598 | 1259 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 1260 | the HAL_SMBUS_SlaveListenCpltCallback could be implemented in the user file |
mbed_official | 237:f3da66175598 | 1261 | */ |
mbed_official | 237:f3da66175598 | 1262 | } |
mbed_official | 237:f3da66175598 | 1263 | |
mbed_official | 237:f3da66175598 | 1264 | /** |
mbed_official | 237:f3da66175598 | 1265 | * @brief SMBUS error callbacks. |
mbed_official | 237:f3da66175598 | 1266 | * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains |
mbed_official | 237:f3da66175598 | 1267 | * the configuration information for the specified SMBUS. |
mbed_official | 237:f3da66175598 | 1268 | * @retval None |
mbed_official | 237:f3da66175598 | 1269 | */ |
mbed_official | 237:f3da66175598 | 1270 | __weak void HAL_SMBUS_ErrorCallback(SMBUS_HandleTypeDef *hsmbus) |
mbed_official | 237:f3da66175598 | 1271 | { |
mbed_official | 237:f3da66175598 | 1272 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 1273 | the HAL_SMBUS_ErrorCallback could be implemented in the user file |
mbed_official | 237:f3da66175598 | 1274 | */ |
mbed_official | 237:f3da66175598 | 1275 | } |
mbed_official | 237:f3da66175598 | 1276 | |
mbed_official | 237:f3da66175598 | 1277 | /** |
mbed_official | 237:f3da66175598 | 1278 | * @} |
mbed_official | 237:f3da66175598 | 1279 | */ |
mbed_official | 237:f3da66175598 | 1280 | |
mbed_official | 375:3d36234a1087 | 1281 | /** |
mbed_official | 375:3d36234a1087 | 1282 | * @} |
mbed_official | 375:3d36234a1087 | 1283 | */ |
mbed_official | 375:3d36234a1087 | 1284 | |
mbed_official | 375:3d36234a1087 | 1285 | /** @defgroup SMBUS_Exported_Functions_Group3 Peripheral State and Errors functions |
mbed_official | 237:f3da66175598 | 1286 | * @brief Peripheral State and Errors functions |
mbed_official | 237:f3da66175598 | 1287 | * |
mbed_official | 237:f3da66175598 | 1288 | @verbatim |
mbed_official | 237:f3da66175598 | 1289 | =============================================================================== |
mbed_official | 237:f3da66175598 | 1290 | ##### Peripheral State and Errors functions ##### |
mbed_official | 237:f3da66175598 | 1291 | =============================================================================== |
mbed_official | 237:f3da66175598 | 1292 | [..] |
mbed_official | 237:f3da66175598 | 1293 | This subsection permit to get in run-time the status of the peripheral |
mbed_official | 237:f3da66175598 | 1294 | and the data flow. |
mbed_official | 237:f3da66175598 | 1295 | |
mbed_official | 237:f3da66175598 | 1296 | @endverbatim |
mbed_official | 237:f3da66175598 | 1297 | * @{ |
mbed_official | 237:f3da66175598 | 1298 | */ |
mbed_official | 237:f3da66175598 | 1299 | |
mbed_official | 237:f3da66175598 | 1300 | /** |
mbed_official | 237:f3da66175598 | 1301 | * @brief Returns the SMBUS state. |
mbed_official | 237:f3da66175598 | 1302 | * @param hsmbus : SMBUS handle |
mbed_official | 237:f3da66175598 | 1303 | * @retval HAL state |
mbed_official | 237:f3da66175598 | 1304 | */ |
mbed_official | 237:f3da66175598 | 1305 | HAL_SMBUS_StateTypeDef HAL_SMBUS_GetState(SMBUS_HandleTypeDef *hsmbus) |
mbed_official | 237:f3da66175598 | 1306 | { |
mbed_official | 237:f3da66175598 | 1307 | return hsmbus->State; |
mbed_official | 237:f3da66175598 | 1308 | } |
mbed_official | 237:f3da66175598 | 1309 | |
mbed_official | 237:f3da66175598 | 1310 | /** |
mbed_official | 237:f3da66175598 | 1311 | * @brief Return the SMBUS error code |
mbed_official | 237:f3da66175598 | 1312 | * @param hsmbus : pointer to a SMBUS_HandleTypeDef structure that contains |
mbed_official | 237:f3da66175598 | 1313 | * the configuration information for the specified SMBUS. |
mbed_official | 237:f3da66175598 | 1314 | * @retval SMBUS Error Code |
mbed_official | 237:f3da66175598 | 1315 | */ |
mbed_official | 237:f3da66175598 | 1316 | uint32_t HAL_SMBUS_GetError(SMBUS_HandleTypeDef *hsmbus) |
mbed_official | 237:f3da66175598 | 1317 | { |
mbed_official | 237:f3da66175598 | 1318 | return hsmbus->ErrorCode; |
mbed_official | 237:f3da66175598 | 1319 | } |
mbed_official | 237:f3da66175598 | 1320 | |
mbed_official | 237:f3da66175598 | 1321 | /** |
mbed_official | 237:f3da66175598 | 1322 | * @} |
mbed_official | 237:f3da66175598 | 1323 | */ |
mbed_official | 237:f3da66175598 | 1324 | |
mbed_official | 237:f3da66175598 | 1325 | /** |
mbed_official | 375:3d36234a1087 | 1326 | * @} |
mbed_official | 375:3d36234a1087 | 1327 | */ |
mbed_official | 375:3d36234a1087 | 1328 | |
mbed_official | 375:3d36234a1087 | 1329 | /** @addtogroup SMBUS_Private_Functions SMBUS Private Functions |
mbed_official | 375:3d36234a1087 | 1330 | * @brief Data transfers Private functions |
mbed_official | 375:3d36234a1087 | 1331 | * @{ |
mbed_official | 375:3d36234a1087 | 1332 | */ |
mbed_official | 375:3d36234a1087 | 1333 | |
mbed_official | 375:3d36234a1087 | 1334 | /** |
mbed_official | 237:f3da66175598 | 1335 | * @brief Interrupt Sub-Routine which handle the Interrupt Flags Master Mode |
mbed_official | 237:f3da66175598 | 1336 | * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains |
mbed_official | 237:f3da66175598 | 1337 | * the configuration information for the specified SMBUS. |
mbed_official | 237:f3da66175598 | 1338 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 1339 | */ |
mbed_official | 237:f3da66175598 | 1340 | static HAL_StatusTypeDef SMBUS_Master_ISR(SMBUS_HandleTypeDef *hsmbus) |
mbed_official | 237:f3da66175598 | 1341 | { |
mbed_official | 237:f3da66175598 | 1342 | uint16_t DevAddress; |
mbed_official | 237:f3da66175598 | 1343 | |
mbed_official | 237:f3da66175598 | 1344 | /* Process Locked */ |
mbed_official | 237:f3da66175598 | 1345 | __HAL_LOCK(hsmbus); |
mbed_official | 237:f3da66175598 | 1346 | |
mbed_official | 237:f3da66175598 | 1347 | if(__HAL_SMBUS_GET_FLAG(hsmbus, SMBUS_FLAG_AF) != RESET) |
mbed_official | 237:f3da66175598 | 1348 | { |
mbed_official | 237:f3da66175598 | 1349 | /* Clear NACK Flag */ |
mbed_official | 237:f3da66175598 | 1350 | __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_AF); |
mbed_official | 237:f3da66175598 | 1351 | |
mbed_official | 237:f3da66175598 | 1352 | /* Set corresponding Error Code */ |
mbed_official | 237:f3da66175598 | 1353 | /* No need to generate STOP, it is automatically done */ |
mbed_official | 237:f3da66175598 | 1354 | hsmbus->ErrorCode |= HAL_SMBUS_ERROR_ACKF; |
mbed_official | 237:f3da66175598 | 1355 | |
mbed_official | 237:f3da66175598 | 1356 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 1357 | __HAL_UNLOCK(hsmbus); |
mbed_official | 237:f3da66175598 | 1358 | |
mbed_official | 237:f3da66175598 | 1359 | /* Call the Error callback to prevent upper layer */ |
mbed_official | 237:f3da66175598 | 1360 | HAL_SMBUS_ErrorCallback(hsmbus); |
mbed_official | 237:f3da66175598 | 1361 | } |
mbed_official | 237:f3da66175598 | 1362 | else if(__HAL_SMBUS_GET_FLAG(hsmbus, SMBUS_FLAG_STOPF) != RESET) |
mbed_official | 237:f3da66175598 | 1363 | { |
mbed_official | 237:f3da66175598 | 1364 | |
mbed_official | 237:f3da66175598 | 1365 | /* Call the corresponding callback to inform upper layer of End of Transfer */ |
mbed_official | 237:f3da66175598 | 1366 | if(hsmbus->State == HAL_SMBUS_STATE_MASTER_BUSY_TX) |
mbed_official | 237:f3da66175598 | 1367 | { |
mbed_official | 237:f3da66175598 | 1368 | /* Disable Interrupt */ |
mbed_official | 237:f3da66175598 | 1369 | SMBUS_Disable_IRQ(hsmbus, SMBUS_IT_TX); |
mbed_official | 237:f3da66175598 | 1370 | |
mbed_official | 237:f3da66175598 | 1371 | /* Clear STOP Flag */ |
mbed_official | 237:f3da66175598 | 1372 | __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_STOPF); |
mbed_official | 237:f3da66175598 | 1373 | |
mbed_official | 237:f3da66175598 | 1374 | /* Clear Configuration Register 2 */ |
mbed_official | 237:f3da66175598 | 1375 | __HAL_SMBUS_RESET_CR2(hsmbus); |
mbed_official | 237:f3da66175598 | 1376 | |
mbed_official | 237:f3da66175598 | 1377 | /* Flush remaining data in Fifo register in case of error occurs before TXEmpty */ |
mbed_official | 237:f3da66175598 | 1378 | /* Disable the selected SMBUS peripheral */ |
mbed_official | 237:f3da66175598 | 1379 | __HAL_SMBUS_DISABLE(hsmbus); |
mbed_official | 237:f3da66175598 | 1380 | |
mbed_official | 237:f3da66175598 | 1381 | hsmbus->PreviousState = HAL_SMBUS_STATE_READY; |
mbed_official | 237:f3da66175598 | 1382 | hsmbus->State = HAL_SMBUS_STATE_READY; |
mbed_official | 237:f3da66175598 | 1383 | |
mbed_official | 237:f3da66175598 | 1384 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 1385 | __HAL_UNLOCK(hsmbus); |
mbed_official | 237:f3da66175598 | 1386 | |
mbed_official | 237:f3da66175598 | 1387 | /* REenable the selected SMBUS peripheral */ |
mbed_official | 237:f3da66175598 | 1388 | __HAL_SMBUS_ENABLE(hsmbus); |
mbed_official | 237:f3da66175598 | 1389 | |
mbed_official | 237:f3da66175598 | 1390 | HAL_SMBUS_MasterTxCpltCallback(hsmbus); |
mbed_official | 237:f3da66175598 | 1391 | } |
mbed_official | 237:f3da66175598 | 1392 | else if(hsmbus->State == HAL_SMBUS_STATE_MASTER_BUSY_RX) |
mbed_official | 237:f3da66175598 | 1393 | { |
mbed_official | 237:f3da66175598 | 1394 | /* Disable Interrupt */ |
mbed_official | 237:f3da66175598 | 1395 | SMBUS_Disable_IRQ(hsmbus, SMBUS_IT_RX); |
mbed_official | 237:f3da66175598 | 1396 | |
mbed_official | 237:f3da66175598 | 1397 | /* Clear STOP Flag */ |
mbed_official | 237:f3da66175598 | 1398 | __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_STOPF); |
mbed_official | 237:f3da66175598 | 1399 | |
mbed_official | 237:f3da66175598 | 1400 | /* Clear Configuration Register 2 */ |
mbed_official | 237:f3da66175598 | 1401 | __HAL_SMBUS_RESET_CR2(hsmbus); |
mbed_official | 237:f3da66175598 | 1402 | |
mbed_official | 237:f3da66175598 | 1403 | hsmbus->PreviousState = HAL_SMBUS_STATE_READY; |
mbed_official | 237:f3da66175598 | 1404 | hsmbus->State = HAL_SMBUS_STATE_READY; |
mbed_official | 237:f3da66175598 | 1405 | |
mbed_official | 237:f3da66175598 | 1406 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 1407 | __HAL_UNLOCK(hsmbus); |
mbed_official | 237:f3da66175598 | 1408 | |
mbed_official | 237:f3da66175598 | 1409 | HAL_SMBUS_MasterRxCpltCallback(hsmbus); |
mbed_official | 237:f3da66175598 | 1410 | } |
mbed_official | 237:f3da66175598 | 1411 | } |
mbed_official | 237:f3da66175598 | 1412 | else if(__HAL_SMBUS_GET_FLAG(hsmbus, SMBUS_FLAG_RXNE) != RESET) |
mbed_official | 237:f3da66175598 | 1413 | { |
mbed_official | 237:f3da66175598 | 1414 | /* Read data from RXDR */ |
mbed_official | 237:f3da66175598 | 1415 | (*hsmbus->pBuffPtr++) = hsmbus->Instance->RXDR; |
mbed_official | 237:f3da66175598 | 1416 | hsmbus->XferSize--; |
mbed_official | 237:f3da66175598 | 1417 | hsmbus->XferCount--; |
mbed_official | 237:f3da66175598 | 1418 | } |
mbed_official | 237:f3da66175598 | 1419 | else if(__HAL_SMBUS_GET_FLAG(hsmbus, SMBUS_FLAG_TXIS) != RESET) |
mbed_official | 237:f3da66175598 | 1420 | { |
mbed_official | 237:f3da66175598 | 1421 | /* Write data to TXDR */ |
mbed_official | 237:f3da66175598 | 1422 | hsmbus->Instance->TXDR = (*hsmbus->pBuffPtr++); |
mbed_official | 237:f3da66175598 | 1423 | hsmbus->XferSize--; |
mbed_official | 237:f3da66175598 | 1424 | hsmbus->XferCount--; |
mbed_official | 237:f3da66175598 | 1425 | } |
mbed_official | 237:f3da66175598 | 1426 | else if(__HAL_SMBUS_GET_FLAG(hsmbus, SMBUS_FLAG_TCR) != RESET) |
mbed_official | 237:f3da66175598 | 1427 | { |
mbed_official | 237:f3da66175598 | 1428 | if((hsmbus->XferSize == 0)&&(hsmbus->XferCount!=0)) |
mbed_official | 237:f3da66175598 | 1429 | { |
mbed_official | 237:f3da66175598 | 1430 | DevAddress = (hsmbus->Instance->CR2 & I2C_CR2_SADD); |
mbed_official | 237:f3da66175598 | 1431 | |
mbed_official | 237:f3da66175598 | 1432 | if(hsmbus->XferCount > MAX_NBYTE_SIZE) |
mbed_official | 237:f3da66175598 | 1433 | { |
mbed_official | 237:f3da66175598 | 1434 | SMBUS_TransferConfig(hsmbus, DevAddress, MAX_NBYTE_SIZE, (SMBUS_RELOAD_MODE | (hsmbus->XferOptions & SMBUS_SENDPEC_MODE)), SMBUS_NO_STARTSTOP); |
mbed_official | 237:f3da66175598 | 1435 | hsmbus->XferSize = MAX_NBYTE_SIZE; |
mbed_official | 237:f3da66175598 | 1436 | } |
mbed_official | 237:f3da66175598 | 1437 | else |
mbed_official | 237:f3da66175598 | 1438 | { |
mbed_official | 237:f3da66175598 | 1439 | hsmbus->XferSize = hsmbus->XferCount; |
mbed_official | 237:f3da66175598 | 1440 | SMBUS_TransferConfig(hsmbus,DevAddress,hsmbus->XferSize, hsmbus->XferOptions, SMBUS_NO_STARTSTOP); |
mbed_official | 237:f3da66175598 | 1441 | /* If PEC mode is enable, size to transmit should be Size-1 byte, corresponding to PEC byte */ |
mbed_official | 237:f3da66175598 | 1442 | /* PEC byte is automatically sent by HW block, no need to manage it in Transmit process */ |
mbed_official | 237:f3da66175598 | 1443 | if(__HAL_SMBUS_GET_PEC_MODE(hsmbus) != RESET) |
mbed_official | 237:f3da66175598 | 1444 | { |
mbed_official | 237:f3da66175598 | 1445 | hsmbus->XferSize--; |
mbed_official | 237:f3da66175598 | 1446 | hsmbus->XferCount--; |
mbed_official | 237:f3da66175598 | 1447 | } |
mbed_official | 237:f3da66175598 | 1448 | } |
mbed_official | 237:f3da66175598 | 1449 | } |
mbed_official | 237:f3da66175598 | 1450 | else if((hsmbus->XferSize == 0)&&(hsmbus->XferCount==0)) |
mbed_official | 237:f3da66175598 | 1451 | { |
mbed_official | 237:f3da66175598 | 1452 | /* Call TxCpltCallback if no stop mode is set */ |
mbed_official | 237:f3da66175598 | 1453 | if(__HAL_SMBUS_GET_STOP_MODE(hsmbus) != SMBUS_AUTOEND_MODE) |
mbed_official | 237:f3da66175598 | 1454 | { |
mbed_official | 237:f3da66175598 | 1455 | /* Call the corresponding callback to inform upper layer of End of Transfer */ |
mbed_official | 237:f3da66175598 | 1456 | if(hsmbus->State == HAL_SMBUS_STATE_MASTER_BUSY_TX) |
mbed_official | 237:f3da66175598 | 1457 | { |
mbed_official | 237:f3da66175598 | 1458 | /* Disable Interrupt */ |
mbed_official | 237:f3da66175598 | 1459 | SMBUS_Disable_IRQ(hsmbus, SMBUS_IT_TX); |
mbed_official | 237:f3da66175598 | 1460 | hsmbus->PreviousState = hsmbus->State; |
mbed_official | 237:f3da66175598 | 1461 | hsmbus->State = HAL_SMBUS_STATE_READY; |
mbed_official | 237:f3da66175598 | 1462 | |
mbed_official | 237:f3da66175598 | 1463 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 1464 | __HAL_UNLOCK(hsmbus); |
mbed_official | 237:f3da66175598 | 1465 | |
mbed_official | 237:f3da66175598 | 1466 | HAL_SMBUS_MasterTxCpltCallback(hsmbus); |
mbed_official | 237:f3da66175598 | 1467 | } |
mbed_official | 237:f3da66175598 | 1468 | else if(hsmbus->State == HAL_SMBUS_STATE_MASTER_BUSY_RX) |
mbed_official | 237:f3da66175598 | 1469 | { |
mbed_official | 237:f3da66175598 | 1470 | SMBUS_Disable_IRQ(hsmbus, SMBUS_IT_RX); |
mbed_official | 237:f3da66175598 | 1471 | hsmbus->PreviousState = hsmbus->State; |
mbed_official | 237:f3da66175598 | 1472 | hsmbus->State = HAL_SMBUS_STATE_READY; |
mbed_official | 237:f3da66175598 | 1473 | |
mbed_official | 237:f3da66175598 | 1474 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 1475 | __HAL_UNLOCK(hsmbus); |
mbed_official | 237:f3da66175598 | 1476 | |
mbed_official | 237:f3da66175598 | 1477 | HAL_SMBUS_MasterRxCpltCallback(hsmbus); |
mbed_official | 237:f3da66175598 | 1478 | } |
mbed_official | 237:f3da66175598 | 1479 | } |
mbed_official | 237:f3da66175598 | 1480 | } |
mbed_official | 237:f3da66175598 | 1481 | } |
mbed_official | 237:f3da66175598 | 1482 | else if(__HAL_SMBUS_GET_FLAG(hsmbus, SMBUS_FLAG_TC) != RESET) |
mbed_official | 237:f3da66175598 | 1483 | { |
mbed_official | 237:f3da66175598 | 1484 | if(hsmbus->XferCount == 0) |
mbed_official | 237:f3da66175598 | 1485 | { |
mbed_official | 237:f3da66175598 | 1486 | /* Specific use case for Quick command */ |
mbed_official | 634:ac7d6880524d | 1487 | if(hsmbus->pBuffPtr == HAL_NULL) |
mbed_official | 237:f3da66175598 | 1488 | { |
mbed_official | 237:f3da66175598 | 1489 | /* Generate a Stop command */ |
mbed_official | 237:f3da66175598 | 1490 | hsmbus->Instance->CR2 |= I2C_CR2_STOP; |
mbed_official | 237:f3da66175598 | 1491 | } |
mbed_official | 237:f3da66175598 | 1492 | /* Call TxCpltCallback if no stop mode is set */ |
mbed_official | 237:f3da66175598 | 1493 | else if(__HAL_SMBUS_GET_STOP_MODE(hsmbus) != SMBUS_AUTOEND_MODE) |
mbed_official | 237:f3da66175598 | 1494 | { |
mbed_official | 237:f3da66175598 | 1495 | /* No Generate Stop, to permit restart mode */ |
mbed_official | 237:f3da66175598 | 1496 | /* The stop will be done at the end of transfer, when SMBUS_AUTOEND_MODE enable */ |
mbed_official | 237:f3da66175598 | 1497 | |
mbed_official | 237:f3da66175598 | 1498 | /* Call the corresponding callback to inform upper layer of End of Transfer */ |
mbed_official | 237:f3da66175598 | 1499 | if(hsmbus->State == HAL_SMBUS_STATE_MASTER_BUSY_TX) |
mbed_official | 237:f3da66175598 | 1500 | { |
mbed_official | 237:f3da66175598 | 1501 | /* Disable Interrupt */ |
mbed_official | 237:f3da66175598 | 1502 | SMBUS_Disable_IRQ(hsmbus, SMBUS_IT_TX); |
mbed_official | 237:f3da66175598 | 1503 | hsmbus->PreviousState = hsmbus->State; |
mbed_official | 237:f3da66175598 | 1504 | hsmbus->State = HAL_SMBUS_STATE_READY; |
mbed_official | 237:f3da66175598 | 1505 | |
mbed_official | 237:f3da66175598 | 1506 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 1507 | __HAL_UNLOCK(hsmbus); |
mbed_official | 237:f3da66175598 | 1508 | |
mbed_official | 237:f3da66175598 | 1509 | HAL_SMBUS_MasterTxCpltCallback(hsmbus); |
mbed_official | 237:f3da66175598 | 1510 | } |
mbed_official | 237:f3da66175598 | 1511 | else if(hsmbus->State == HAL_SMBUS_STATE_MASTER_BUSY_RX) |
mbed_official | 237:f3da66175598 | 1512 | { |
mbed_official | 237:f3da66175598 | 1513 | SMBUS_Disable_IRQ(hsmbus, SMBUS_IT_RX); |
mbed_official | 237:f3da66175598 | 1514 | hsmbus->PreviousState = hsmbus->State; |
mbed_official | 237:f3da66175598 | 1515 | hsmbus->State = HAL_SMBUS_STATE_READY; |
mbed_official | 237:f3da66175598 | 1516 | |
mbed_official | 237:f3da66175598 | 1517 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 1518 | __HAL_UNLOCK(hsmbus); |
mbed_official | 237:f3da66175598 | 1519 | |
mbed_official | 237:f3da66175598 | 1520 | HAL_SMBUS_MasterRxCpltCallback(hsmbus); |
mbed_official | 237:f3da66175598 | 1521 | } |
mbed_official | 237:f3da66175598 | 1522 | } |
mbed_official | 237:f3da66175598 | 1523 | } |
mbed_official | 237:f3da66175598 | 1524 | } |
mbed_official | 237:f3da66175598 | 1525 | |
mbed_official | 237:f3da66175598 | 1526 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 1527 | __HAL_UNLOCK(hsmbus); |
mbed_official | 237:f3da66175598 | 1528 | |
mbed_official | 237:f3da66175598 | 1529 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 1530 | } |
mbed_official | 237:f3da66175598 | 1531 | /** |
mbed_official | 237:f3da66175598 | 1532 | * @brief Interrupt Sub-Routine which handle the Interrupt Flags Slave Mode |
mbed_official | 237:f3da66175598 | 1533 | * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains |
mbed_official | 237:f3da66175598 | 1534 | * the configuration information for the specified SMBUS. |
mbed_official | 237:f3da66175598 | 1535 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 1536 | */ |
mbed_official | 237:f3da66175598 | 1537 | static HAL_StatusTypeDef SMBUS_Slave_ISR(SMBUS_HandleTypeDef *hsmbus) |
mbed_official | 237:f3da66175598 | 1538 | { |
mbed_official | 237:f3da66175598 | 1539 | uint8_t TransferDirection = 0; |
mbed_official | 237:f3da66175598 | 1540 | uint16_t SlaveAddrCode = 0; |
mbed_official | 237:f3da66175598 | 1541 | |
mbed_official | 237:f3da66175598 | 1542 | /* Process Locked */ |
mbed_official | 237:f3da66175598 | 1543 | __HAL_LOCK(hsmbus); |
mbed_official | 237:f3da66175598 | 1544 | |
mbed_official | 237:f3da66175598 | 1545 | if(__HAL_SMBUS_GET_FLAG(hsmbus, SMBUS_FLAG_AF) != RESET) |
mbed_official | 237:f3da66175598 | 1546 | { |
mbed_official | 237:f3da66175598 | 1547 | /* Check that SMBUS transfer finished */ |
mbed_official | 237:f3da66175598 | 1548 | /* if yes, normal usecase, a NACK is sent by the HOST when Transfer is finished */ |
mbed_official | 237:f3da66175598 | 1549 | /* Mean XferCount == 0*/ |
mbed_official | 237:f3da66175598 | 1550 | /* So clear Flag NACKF only */ |
mbed_official | 237:f3da66175598 | 1551 | if(hsmbus->XferCount == 0) |
mbed_official | 237:f3da66175598 | 1552 | { |
mbed_official | 237:f3da66175598 | 1553 | /* Clear NACK Flag */ |
mbed_official | 237:f3da66175598 | 1554 | __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_AF); |
mbed_official | 237:f3da66175598 | 1555 | |
mbed_official | 237:f3da66175598 | 1556 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 1557 | __HAL_UNLOCK(hsmbus); |
mbed_official | 237:f3da66175598 | 1558 | } |
mbed_official | 237:f3da66175598 | 1559 | else |
mbed_official | 237:f3da66175598 | 1560 | { |
mbed_official | 237:f3da66175598 | 1561 | /* if no, error usecase, a Non-Acknowledge of last Data is generated by the HOST*/ |
mbed_official | 237:f3da66175598 | 1562 | /* Clear NACK Flag */ |
mbed_official | 237:f3da66175598 | 1563 | __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_AF); |
mbed_official | 237:f3da66175598 | 1564 | |
mbed_official | 237:f3da66175598 | 1565 | /* Set HAL State to "Idle" State, mean to LISTEN state */ |
mbed_official | 237:f3da66175598 | 1566 | /* So reset Slave Busy state */ |
mbed_official | 237:f3da66175598 | 1567 | hsmbus->PreviousState = hsmbus->State; |
mbed_official | 237:f3da66175598 | 1568 | hsmbus->State &= ~((uint32_t)HAL_SMBUS_STATE_SLAVE_BUSY_TX); |
mbed_official | 237:f3da66175598 | 1569 | hsmbus->State &= ~((uint32_t)HAL_SMBUS_STATE_SLAVE_BUSY_RX); |
mbed_official | 237:f3da66175598 | 1570 | |
mbed_official | 237:f3da66175598 | 1571 | /* Disable RX/TX Interrupts, keep only ADDR Interrupt */ |
mbed_official | 237:f3da66175598 | 1572 | SMBUS_Disable_IRQ(hsmbus, SMBUS_IT_RX | SMBUS_IT_TX); |
mbed_official | 375:3d36234a1087 | 1573 | |
mbed_official | 237:f3da66175598 | 1574 | /* Set ErrorCode corresponding to a Non-Acknowledge */ |
mbed_official | 237:f3da66175598 | 1575 | hsmbus->ErrorCode |= HAL_SMBUS_ERROR_ACKF; |
mbed_official | 237:f3da66175598 | 1576 | |
mbed_official | 237:f3da66175598 | 1577 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 1578 | __HAL_UNLOCK(hsmbus); |
mbed_official | 237:f3da66175598 | 1579 | |
mbed_official | 237:f3da66175598 | 1580 | /* Call the Error callback to prevent upper layer */ |
mbed_official | 237:f3da66175598 | 1581 | HAL_SMBUS_ErrorCallback(hsmbus); |
mbed_official | 237:f3da66175598 | 1582 | } |
mbed_official | 237:f3da66175598 | 1583 | } |
mbed_official | 237:f3da66175598 | 1584 | else if(__HAL_SMBUS_GET_FLAG(hsmbus, SMBUS_FLAG_ADDR) != RESET) |
mbed_official | 237:f3da66175598 | 1585 | { |
mbed_official | 237:f3da66175598 | 1586 | TransferDirection = __HAL_SMBUS_GET_DIR(hsmbus); |
mbed_official | 237:f3da66175598 | 1587 | SlaveAddrCode = __HAL_SMBUS_GET_ADDR_MATCH(hsmbus); |
mbed_official | 237:f3da66175598 | 1588 | |
mbed_official | 237:f3da66175598 | 1589 | /* Disable ADDR interrupt to prevent multiple ADDRInterrupt*/ |
mbed_official | 237:f3da66175598 | 1590 | /* Other ADDRInterrupt will be treat in next Listen usecase */ |
mbed_official | 237:f3da66175598 | 1591 | __HAL_SMBUS_DISABLE_IT(hsmbus, SMBUS_IT_ADDRI); |
mbed_official | 237:f3da66175598 | 1592 | |
mbed_official | 237:f3da66175598 | 1593 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 1594 | __HAL_UNLOCK(hsmbus); |
mbed_official | 237:f3da66175598 | 1595 | |
mbed_official | 237:f3da66175598 | 1596 | /* Call Slave Addr callback */ |
mbed_official | 237:f3da66175598 | 1597 | HAL_SMBUS_SlaveAddrCallback(hsmbus, TransferDirection, SlaveAddrCode); |
mbed_official | 237:f3da66175598 | 1598 | } |
mbed_official | 237:f3da66175598 | 1599 | else if((__HAL_SMBUS_GET_FLAG(hsmbus, SMBUS_FLAG_RXNE) != RESET) || (__HAL_SMBUS_GET_FLAG(hsmbus, SMBUS_FLAG_TCR) != RESET)) |
mbed_official | 237:f3da66175598 | 1600 | { |
mbed_official | 237:f3da66175598 | 1601 | if( (hsmbus->State & HAL_SMBUS_STATE_SLAVE_BUSY_RX) == HAL_SMBUS_STATE_SLAVE_BUSY_RX) |
mbed_official | 237:f3da66175598 | 1602 | { |
mbed_official | 237:f3da66175598 | 1603 | /* Read data from RXDR */ |
mbed_official | 237:f3da66175598 | 1604 | (*hsmbus->pBuffPtr++) = hsmbus->Instance->RXDR; |
mbed_official | 237:f3da66175598 | 1605 | hsmbus->XferSize--; |
mbed_official | 237:f3da66175598 | 1606 | hsmbus->XferCount--; |
mbed_official | 237:f3da66175598 | 1607 | |
mbed_official | 237:f3da66175598 | 1608 | if(hsmbus->XferCount == 1) |
mbed_official | 237:f3da66175598 | 1609 | { |
mbed_official | 237:f3da66175598 | 1610 | /* Receive last Byte, can be PEC byte in case of PEC BYTE enabled */ |
mbed_official | 237:f3da66175598 | 1611 | /* or only the last Byte of Transfer */ |
mbed_official | 237:f3da66175598 | 1612 | /* So reset the RELOAD bit mode */ |
mbed_official | 237:f3da66175598 | 1613 | hsmbus->XferOptions &= ~SMBUS_RELOAD_MODE; |
mbed_official | 237:f3da66175598 | 1614 | SMBUS_TransferConfig(hsmbus,0 ,1 , hsmbus->XferOptions, SMBUS_NO_STARTSTOP); |
mbed_official | 237:f3da66175598 | 1615 | } |
mbed_official | 237:f3da66175598 | 1616 | else if(hsmbus->XferCount == 0) |
mbed_official | 237:f3da66175598 | 1617 | { |
mbed_official | 237:f3da66175598 | 1618 | /* Last Byte is received, disable Interrupt */ |
mbed_official | 237:f3da66175598 | 1619 | SMBUS_Disable_IRQ(hsmbus, SMBUS_IT_RX); |
mbed_official | 237:f3da66175598 | 1620 | |
mbed_official | 237:f3da66175598 | 1621 | /* Remove HAL_SMBUS_STATE_SLAVE_BUSY_RX, keep only HAL_SMBUS_STATE_LISTEN */ |
mbed_official | 237:f3da66175598 | 1622 | hsmbus->PreviousState = hsmbus->State; |
mbed_official | 237:f3da66175598 | 1623 | hsmbus->State &= ~((uint32_t)HAL_SMBUS_STATE_SLAVE_BUSY_RX); |
mbed_official | 237:f3da66175598 | 1624 | |
mbed_official | 237:f3da66175598 | 1625 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 1626 | __HAL_UNLOCK(hsmbus); |
mbed_official | 237:f3da66175598 | 1627 | |
mbed_official | 237:f3da66175598 | 1628 | /* Call the Rx complete callback to inform upper layer of the end of receive process */ |
mbed_official | 237:f3da66175598 | 1629 | HAL_SMBUS_SlaveRxCpltCallback(hsmbus); |
mbed_official | 237:f3da66175598 | 1630 | } |
mbed_official | 237:f3da66175598 | 1631 | else |
mbed_official | 237:f3da66175598 | 1632 | { |
mbed_official | 237:f3da66175598 | 1633 | /* Set Reload for next Bytes */ |
mbed_official | 237:f3da66175598 | 1634 | SMBUS_TransferConfig(hsmbus,0, 1, SMBUS_RELOAD_MODE | (hsmbus->XferOptions & SMBUS_SENDPEC_MODE), SMBUS_NO_STARTSTOP); |
mbed_official | 237:f3da66175598 | 1635 | |
mbed_official | 237:f3da66175598 | 1636 | /* Ack last Byte Read */ |
mbed_official | 237:f3da66175598 | 1637 | hsmbus->Instance->CR2 &= ~I2C_CR2_NACK; |
mbed_official | 237:f3da66175598 | 1638 | } |
mbed_official | 237:f3da66175598 | 1639 | } |
mbed_official | 237:f3da66175598 | 1640 | else if( (hsmbus->State & HAL_SMBUS_STATE_SLAVE_BUSY_TX) == HAL_SMBUS_STATE_SLAVE_BUSY_TX) |
mbed_official | 237:f3da66175598 | 1641 | { |
mbed_official | 237:f3da66175598 | 1642 | if((hsmbus->XferSize == 0)&&(hsmbus->XferCount!=0)) |
mbed_official | 237:f3da66175598 | 1643 | { |
mbed_official | 237:f3da66175598 | 1644 | if(hsmbus->XferCount > MAX_NBYTE_SIZE) |
mbed_official | 237:f3da66175598 | 1645 | { |
mbed_official | 237:f3da66175598 | 1646 | SMBUS_TransferConfig(hsmbus, 0, MAX_NBYTE_SIZE, (SMBUS_RELOAD_MODE | (hsmbus->XferOptions & SMBUS_SENDPEC_MODE)), SMBUS_NO_STARTSTOP); |
mbed_official | 237:f3da66175598 | 1647 | hsmbus->XferSize = MAX_NBYTE_SIZE; |
mbed_official | 237:f3da66175598 | 1648 | } |
mbed_official | 237:f3da66175598 | 1649 | else |
mbed_official | 237:f3da66175598 | 1650 | { |
mbed_official | 237:f3da66175598 | 1651 | hsmbus->XferSize = hsmbus->XferCount; |
mbed_official | 237:f3da66175598 | 1652 | SMBUS_TransferConfig(hsmbus, 0, hsmbus->XferSize, hsmbus->XferOptions, SMBUS_NO_STARTSTOP); |
mbed_official | 237:f3da66175598 | 1653 | /* If PEC mode is enable, size to transmit should be Size-1 byte, corresponding to PEC byte */ |
mbed_official | 237:f3da66175598 | 1654 | /* PEC byte is automatically sent by HW block, no need to manage it in Transmit process */ |
mbed_official | 237:f3da66175598 | 1655 | if(__HAL_SMBUS_GET_PEC_MODE(hsmbus) != RESET) |
mbed_official | 237:f3da66175598 | 1656 | { |
mbed_official | 237:f3da66175598 | 1657 | hsmbus->XferSize--; |
mbed_official | 237:f3da66175598 | 1658 | hsmbus->XferCount--; |
mbed_official | 237:f3da66175598 | 1659 | } |
mbed_official | 237:f3da66175598 | 1660 | } |
mbed_official | 237:f3da66175598 | 1661 | } |
mbed_official | 237:f3da66175598 | 1662 | } |
mbed_official | 237:f3da66175598 | 1663 | } |
mbed_official | 237:f3da66175598 | 1664 | else if(__HAL_SMBUS_GET_FLAG(hsmbus, SMBUS_FLAG_TXIS) != RESET) |
mbed_official | 237:f3da66175598 | 1665 | { |
mbed_official | 237:f3da66175598 | 1666 | /* Write data to TXDR only if XferCount not reach "0" */ |
mbed_official | 237:f3da66175598 | 1667 | /* A TXIS flag can be set, during STOP treatment */ |
mbed_official | 237:f3da66175598 | 1668 | /* Check if all Datas have already been sent */ |
mbed_official | 237:f3da66175598 | 1669 | /* If it is the case, this last write in TXDR is not sent, correspond to a dummy TXIS event */ |
mbed_official | 237:f3da66175598 | 1670 | if(hsmbus->XferCount > 0) |
mbed_official | 237:f3da66175598 | 1671 | { |
mbed_official | 237:f3da66175598 | 1672 | /* Write data to TXDR */ |
mbed_official | 237:f3da66175598 | 1673 | hsmbus->Instance->TXDR = (*hsmbus->pBuffPtr++); |
mbed_official | 237:f3da66175598 | 1674 | hsmbus->XferCount--; |
mbed_official | 237:f3da66175598 | 1675 | hsmbus->XferSize--; |
mbed_official | 237:f3da66175598 | 1676 | } |
mbed_official | 237:f3da66175598 | 1677 | |
mbed_official | 237:f3da66175598 | 1678 | if(hsmbus->XferCount == 0) |
mbed_official | 237:f3da66175598 | 1679 | { |
mbed_official | 237:f3da66175598 | 1680 | /* Last Byte is Transmitted */ |
mbed_official | 237:f3da66175598 | 1681 | /* Remove HAL_SMBUS_STATE_SLAVE_BUSY_TX, keep only HAL_SMBUS_STATE_LISTEN */ |
mbed_official | 237:f3da66175598 | 1682 | SMBUS_Disable_IRQ(hsmbus, SMBUS_IT_TX); |
mbed_official | 237:f3da66175598 | 1683 | hsmbus->PreviousState = hsmbus->State; |
mbed_official | 237:f3da66175598 | 1684 | hsmbus->State &= ~((uint32_t)HAL_SMBUS_STATE_SLAVE_BUSY_TX); |
mbed_official | 237:f3da66175598 | 1685 | |
mbed_official | 237:f3da66175598 | 1686 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 1687 | __HAL_UNLOCK(hsmbus); |
mbed_official | 237:f3da66175598 | 1688 | |
mbed_official | 237:f3da66175598 | 1689 | /* Call the Tx complete callback to inform upper layer of the end of transmit process */ |
mbed_official | 237:f3da66175598 | 1690 | HAL_SMBUS_SlaveTxCpltCallback(hsmbus); |
mbed_official | 237:f3da66175598 | 1691 | } |
mbed_official | 237:f3da66175598 | 1692 | } |
mbed_official | 237:f3da66175598 | 1693 | |
mbed_official | 237:f3da66175598 | 1694 | /* Check if STOPF is set */ |
mbed_official | 237:f3da66175598 | 1695 | if(__HAL_SMBUS_GET_FLAG(hsmbus, SMBUS_FLAG_STOPF) != RESET) |
mbed_official | 237:f3da66175598 | 1696 | { |
mbed_official | 237:f3da66175598 | 1697 | if((hsmbus->State & HAL_SMBUS_STATE_LISTEN) == HAL_SMBUS_STATE_LISTEN) |
mbed_official | 237:f3da66175598 | 1698 | { |
mbed_official | 237:f3da66175598 | 1699 | /* Disable RX and TX Interrupts */ |
mbed_official | 237:f3da66175598 | 1700 | SMBUS_Disable_IRQ(hsmbus, SMBUS_IT_RX | SMBUS_IT_TX); |
mbed_official | 237:f3da66175598 | 1701 | |
mbed_official | 237:f3da66175598 | 1702 | /* Disable ADDR Interrupt */ |
mbed_official | 237:f3da66175598 | 1703 | SMBUS_Disable_IRQ(hsmbus, SMBUS_IT_ADDR); |
mbed_official | 237:f3da66175598 | 1704 | |
mbed_official | 237:f3da66175598 | 1705 | /* Disable Address Acknowledge */ |
mbed_official | 237:f3da66175598 | 1706 | hsmbus->Instance->CR2 |= I2C_CR2_NACK; |
mbed_official | 237:f3da66175598 | 1707 | |
mbed_official | 237:f3da66175598 | 1708 | /* Clear Configuration Register 2 */ |
mbed_official | 237:f3da66175598 | 1709 | __HAL_SMBUS_RESET_CR2(hsmbus); |
mbed_official | 237:f3da66175598 | 1710 | |
mbed_official | 237:f3da66175598 | 1711 | /* Clear STOP Flag */ |
mbed_official | 237:f3da66175598 | 1712 | __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_STOPF); |
mbed_official | 237:f3da66175598 | 1713 | |
mbed_official | 237:f3da66175598 | 1714 | /* Clear ADDR flag */ |
mbed_official | 237:f3da66175598 | 1715 | __HAL_SMBUS_CLEAR_FLAG(hsmbus,SMBUS_FLAG_ADDR); |
mbed_official | 237:f3da66175598 | 1716 | |
mbed_official | 237:f3da66175598 | 1717 | hsmbus->XferOptions = 0; |
mbed_official | 237:f3da66175598 | 1718 | hsmbus->PreviousState = hsmbus->State; |
mbed_official | 237:f3da66175598 | 1719 | hsmbus->State = HAL_SMBUS_STATE_READY; |
mbed_official | 237:f3da66175598 | 1720 | |
mbed_official | 237:f3da66175598 | 1721 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 1722 | __HAL_UNLOCK(hsmbus); |
mbed_official | 237:f3da66175598 | 1723 | |
mbed_official | 237:f3da66175598 | 1724 | /* Call the Listen Complete callback, to prevent upper layer of the end of Listen usecase */ |
mbed_official | 237:f3da66175598 | 1725 | HAL_SMBUS_SlaveListenCpltCallback(hsmbus); |
mbed_official | 237:f3da66175598 | 1726 | } |
mbed_official | 237:f3da66175598 | 1727 | } |
mbed_official | 237:f3da66175598 | 1728 | |
mbed_official | 237:f3da66175598 | 1729 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 1730 | __HAL_UNLOCK(hsmbus); |
mbed_official | 237:f3da66175598 | 1731 | |
mbed_official | 237:f3da66175598 | 1732 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 1733 | } |
mbed_official | 237:f3da66175598 | 1734 | /** |
mbed_official | 237:f3da66175598 | 1735 | * @brief Manage the enabling of Interrupts |
mbed_official | 237:f3da66175598 | 1736 | * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains |
mbed_official | 237:f3da66175598 | 1737 | * the configuration information for the specified SMBUS. |
mbed_official | 237:f3da66175598 | 1738 | * @param InterruptRequest : Value of @ref SMBUS_Interrupt_configuration_definition. |
mbed_official | 237:f3da66175598 | 1739 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 1740 | */ |
mbed_official | 237:f3da66175598 | 1741 | static HAL_StatusTypeDef SMBUS_Enable_IRQ(SMBUS_HandleTypeDef *hsmbus, uint16_t InterruptRequest) |
mbed_official | 237:f3da66175598 | 1742 | { |
mbed_official | 237:f3da66175598 | 1743 | uint32_t tmpisr = 0; |
mbed_official | 237:f3da66175598 | 1744 | |
mbed_official | 237:f3da66175598 | 1745 | if((InterruptRequest & SMBUS_IT_ALERT) == SMBUS_IT_ALERT) |
mbed_official | 237:f3da66175598 | 1746 | { |
mbed_official | 237:f3da66175598 | 1747 | /* Enable ERR interrupt */ |
mbed_official | 237:f3da66175598 | 1748 | tmpisr |= SMBUS_IT_ERRI; |
mbed_official | 237:f3da66175598 | 1749 | } |
mbed_official | 237:f3da66175598 | 1750 | |
mbed_official | 237:f3da66175598 | 1751 | if((InterruptRequest & SMBUS_IT_ADDR) == SMBUS_IT_ADDR) |
mbed_official | 237:f3da66175598 | 1752 | { |
mbed_official | 237:f3da66175598 | 1753 | /* Enable ADDR, STOP interrupt */ |
mbed_official | 237:f3da66175598 | 1754 | tmpisr |= SMBUS_IT_ADDRI | SMBUS_IT_STOPI | SMBUS_IT_NACKI | SMBUS_IT_ERRI; |
mbed_official | 237:f3da66175598 | 1755 | } |
mbed_official | 237:f3da66175598 | 1756 | |
mbed_official | 237:f3da66175598 | 1757 | if((InterruptRequest & SMBUS_IT_TX) == SMBUS_IT_TX) |
mbed_official | 237:f3da66175598 | 1758 | { |
mbed_official | 237:f3da66175598 | 1759 | /* Enable ERR, TC, STOP, NACK, RXI interrupt */ |
mbed_official | 237:f3da66175598 | 1760 | tmpisr |= SMBUS_IT_ERRI | SMBUS_IT_TCI | SMBUS_IT_STOPI | SMBUS_IT_NACKI | SMBUS_IT_TXI; |
mbed_official | 237:f3da66175598 | 1761 | } |
mbed_official | 237:f3da66175598 | 1762 | |
mbed_official | 237:f3da66175598 | 1763 | if((InterruptRequest & SMBUS_IT_RX) == SMBUS_IT_RX) |
mbed_official | 237:f3da66175598 | 1764 | { |
mbed_official | 237:f3da66175598 | 1765 | /* Enable ERR, TC, STOP, NACK, TXI interrupt */ |
mbed_official | 237:f3da66175598 | 1766 | tmpisr |= SMBUS_IT_ERRI | SMBUS_IT_TCI | SMBUS_IT_STOPI | SMBUS_IT_NACKI | SMBUS_IT_RXI; |
mbed_official | 237:f3da66175598 | 1767 | } |
mbed_official | 237:f3da66175598 | 1768 | |
mbed_official | 237:f3da66175598 | 1769 | /* Enable interrupts only at the end */ |
mbed_official | 237:f3da66175598 | 1770 | /* to avoid the risk of SMBUS interrupt handle execution before */ |
mbed_official | 237:f3da66175598 | 1771 | /* all interrupts requested done */ |
mbed_official | 237:f3da66175598 | 1772 | __HAL_SMBUS_ENABLE_IT(hsmbus, tmpisr); |
mbed_official | 237:f3da66175598 | 1773 | |
mbed_official | 237:f3da66175598 | 1774 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 1775 | } |
mbed_official | 237:f3da66175598 | 1776 | /** |
mbed_official | 237:f3da66175598 | 1777 | * @brief Manage the disabling of Interrupts |
mbed_official | 237:f3da66175598 | 1778 | * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains |
mbed_official | 237:f3da66175598 | 1779 | * the configuration information for the specified SMBUS. |
mbed_official | 237:f3da66175598 | 1780 | * @param InterruptRequest : Value of @ref SMBUS_Interrupt_configuration_definition. |
mbed_official | 237:f3da66175598 | 1781 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 1782 | */ |
mbed_official | 237:f3da66175598 | 1783 | static HAL_StatusTypeDef SMBUS_Disable_IRQ(SMBUS_HandleTypeDef *hsmbus, uint16_t InterruptRequest) |
mbed_official | 237:f3da66175598 | 1784 | { |
mbed_official | 237:f3da66175598 | 1785 | uint32_t tmpisr = 0; |
mbed_official | 237:f3da66175598 | 1786 | |
mbed_official | 237:f3da66175598 | 1787 | if( ((InterruptRequest & SMBUS_IT_ALERT) == SMBUS_IT_ALERT) && (hsmbus->State == HAL_SMBUS_STATE_READY) ) |
mbed_official | 237:f3da66175598 | 1788 | { |
mbed_official | 237:f3da66175598 | 1789 | /* Disable ERR interrupt */ |
mbed_official | 237:f3da66175598 | 1790 | tmpisr |= SMBUS_IT_ERRI; |
mbed_official | 237:f3da66175598 | 1791 | } |
mbed_official | 237:f3da66175598 | 1792 | |
mbed_official | 237:f3da66175598 | 1793 | if((InterruptRequest & SMBUS_IT_TX) == SMBUS_IT_TX) |
mbed_official | 237:f3da66175598 | 1794 | { |
mbed_official | 237:f3da66175598 | 1795 | /* Disable TC, STOP, NACK, TXI interrupt */ |
mbed_official | 237:f3da66175598 | 1796 | tmpisr |= SMBUS_IT_TCI | SMBUS_IT_TXI; |
mbed_official | 237:f3da66175598 | 1797 | |
mbed_official | 237:f3da66175598 | 1798 | if((__HAL_SMBUS_GET_ALERT_ENABLED(hsmbus) == RESET) |
mbed_official | 237:f3da66175598 | 1799 | && ((hsmbus->State & HAL_SMBUS_STATE_LISTEN) != HAL_SMBUS_STATE_LISTEN)) |
mbed_official | 237:f3da66175598 | 1800 | { |
mbed_official | 237:f3da66175598 | 1801 | /* Disable ERR interrupt */ |
mbed_official | 237:f3da66175598 | 1802 | tmpisr |= SMBUS_IT_ERRI; |
mbed_official | 237:f3da66175598 | 1803 | } |
mbed_official | 237:f3da66175598 | 1804 | |
mbed_official | 237:f3da66175598 | 1805 | if((hsmbus->State & HAL_SMBUS_STATE_LISTEN) != HAL_SMBUS_STATE_LISTEN) |
mbed_official | 237:f3da66175598 | 1806 | { |
mbed_official | 237:f3da66175598 | 1807 | /* Disable STOPI, NACKI */ |
mbed_official | 237:f3da66175598 | 1808 | tmpisr |= SMBUS_IT_STOPI | SMBUS_IT_NACKI; |
mbed_official | 237:f3da66175598 | 1809 | } |
mbed_official | 237:f3da66175598 | 1810 | } |
mbed_official | 237:f3da66175598 | 1811 | |
mbed_official | 237:f3da66175598 | 1812 | if((InterruptRequest & SMBUS_IT_RX) == SMBUS_IT_RX) |
mbed_official | 237:f3da66175598 | 1813 | { |
mbed_official | 237:f3da66175598 | 1814 | /* Disable TC, STOP, NACK, RXI interrupt */ |
mbed_official | 237:f3da66175598 | 1815 | tmpisr |= SMBUS_IT_TCI | SMBUS_IT_RXI; |
mbed_official | 237:f3da66175598 | 1816 | |
mbed_official | 237:f3da66175598 | 1817 | if((__HAL_SMBUS_GET_ALERT_ENABLED(hsmbus) == RESET) |
mbed_official | 237:f3da66175598 | 1818 | && ((hsmbus->State & HAL_SMBUS_STATE_LISTEN) != HAL_SMBUS_STATE_LISTEN)) |
mbed_official | 237:f3da66175598 | 1819 | { |
mbed_official | 237:f3da66175598 | 1820 | /* Disable ERR interrupt */ |
mbed_official | 237:f3da66175598 | 1821 | tmpisr |= SMBUS_IT_ERRI; |
mbed_official | 237:f3da66175598 | 1822 | } |
mbed_official | 237:f3da66175598 | 1823 | |
mbed_official | 237:f3da66175598 | 1824 | if((hsmbus->State & HAL_SMBUS_STATE_LISTEN) != HAL_SMBUS_STATE_LISTEN) |
mbed_official | 237:f3da66175598 | 1825 | { |
mbed_official | 237:f3da66175598 | 1826 | /* Disable STOPI, NACKI */ |
mbed_official | 237:f3da66175598 | 1827 | tmpisr |= SMBUS_IT_STOPI | SMBUS_IT_NACKI; |
mbed_official | 237:f3da66175598 | 1828 | } |
mbed_official | 237:f3da66175598 | 1829 | } |
mbed_official | 237:f3da66175598 | 1830 | |
mbed_official | 237:f3da66175598 | 1831 | if((InterruptRequest & SMBUS_IT_ADDR) == SMBUS_IT_ADDR) |
mbed_official | 237:f3da66175598 | 1832 | { |
mbed_official | 237:f3da66175598 | 1833 | /* Enable ADDR, STOP interrupt */ |
mbed_official | 237:f3da66175598 | 1834 | tmpisr |= SMBUS_IT_ADDRI | SMBUS_IT_STOPI | SMBUS_IT_NACKI; |
mbed_official | 237:f3da66175598 | 1835 | |
mbed_official | 237:f3da66175598 | 1836 | if(__HAL_SMBUS_GET_ALERT_ENABLED(hsmbus) == RESET) |
mbed_official | 237:f3da66175598 | 1837 | { |
mbed_official | 237:f3da66175598 | 1838 | /* Disable ERR interrupt */ |
mbed_official | 237:f3da66175598 | 1839 | tmpisr |= SMBUS_IT_ERRI; |
mbed_official | 237:f3da66175598 | 1840 | } |
mbed_official | 237:f3da66175598 | 1841 | } |
mbed_official | 237:f3da66175598 | 1842 | |
mbed_official | 237:f3da66175598 | 1843 | /* Disable interrupts only at the end */ |
mbed_official | 237:f3da66175598 | 1844 | /* to avoid a breaking situation like at "t" time */ |
mbed_official | 237:f3da66175598 | 1845 | /* all disable interrupts request are not done */ |
mbed_official | 237:f3da66175598 | 1846 | __HAL_SMBUS_DISABLE_IT(hsmbus, tmpisr); |
mbed_official | 237:f3da66175598 | 1847 | |
mbed_official | 237:f3da66175598 | 1848 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 1849 | } |
mbed_official | 237:f3da66175598 | 1850 | /** |
mbed_official | 237:f3da66175598 | 1851 | * @brief This function handles SMBUS Communication Timeout. |
mbed_official | 237:f3da66175598 | 1852 | * @param hsmbus : Pointer to a SMBUS_HandleTypeDef structure that contains |
mbed_official | 237:f3da66175598 | 1853 | * the configuration information for the specified SMBUS. |
mbed_official | 237:f3da66175598 | 1854 | * @param Flag: specifies the SMBUS flag to check. |
mbed_official | 237:f3da66175598 | 1855 | * @param Status: The new Flag status (SET or RESET). |
mbed_official | 237:f3da66175598 | 1856 | * @param Timeout: Timeout duration |
mbed_official | 237:f3da66175598 | 1857 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 1858 | */ |
mbed_official | 237:f3da66175598 | 1859 | static HAL_StatusTypeDef SMBUS_WaitOnFlagUntilTimeout(SMBUS_HandleTypeDef *hsmbus, uint32_t Flag, FlagStatus Status, uint32_t Timeout) |
mbed_official | 237:f3da66175598 | 1860 | { |
mbed_official | 237:f3da66175598 | 1861 | uint32_t tickstart = HAL_GetTick(); |
mbed_official | 237:f3da66175598 | 1862 | |
mbed_official | 237:f3da66175598 | 1863 | /* Wait until flag is set */ |
mbed_official | 237:f3da66175598 | 1864 | if(Status == RESET) |
mbed_official | 237:f3da66175598 | 1865 | { |
mbed_official | 237:f3da66175598 | 1866 | while(__HAL_SMBUS_GET_FLAG(hsmbus, Flag) == RESET) |
mbed_official | 237:f3da66175598 | 1867 | { |
mbed_official | 237:f3da66175598 | 1868 | /* Check for the Timeout */ |
mbed_official | 237:f3da66175598 | 1869 | if(Timeout != HAL_MAX_DELAY) |
mbed_official | 237:f3da66175598 | 1870 | { |
mbed_official | 237:f3da66175598 | 1871 | if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout)) |
mbed_official | 237:f3da66175598 | 1872 | { |
mbed_official | 237:f3da66175598 | 1873 | hsmbus->PreviousState = hsmbus->State; |
mbed_official | 237:f3da66175598 | 1874 | hsmbus->State= HAL_SMBUS_STATE_READY; |
mbed_official | 237:f3da66175598 | 1875 | |
mbed_official | 237:f3da66175598 | 1876 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 1877 | __HAL_UNLOCK(hsmbus); |
mbed_official | 237:f3da66175598 | 1878 | |
mbed_official | 237:f3da66175598 | 1879 | return HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 1880 | } |
mbed_official | 237:f3da66175598 | 1881 | } |
mbed_official | 237:f3da66175598 | 1882 | } |
mbed_official | 237:f3da66175598 | 1883 | } |
mbed_official | 237:f3da66175598 | 1884 | else |
mbed_official | 237:f3da66175598 | 1885 | { |
mbed_official | 237:f3da66175598 | 1886 | while(__HAL_SMBUS_GET_FLAG(hsmbus, Flag) != RESET) |
mbed_official | 237:f3da66175598 | 1887 | { |
mbed_official | 237:f3da66175598 | 1888 | /* Check for the Timeout */ |
mbed_official | 237:f3da66175598 | 1889 | if(Timeout != HAL_MAX_DELAY) |
mbed_official | 237:f3da66175598 | 1890 | { |
mbed_official | 237:f3da66175598 | 1891 | if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout)) |
mbed_official | 237:f3da66175598 | 1892 | { |
mbed_official | 237:f3da66175598 | 1893 | hsmbus->PreviousState = hsmbus->State; |
mbed_official | 237:f3da66175598 | 1894 | hsmbus->State= HAL_SMBUS_STATE_READY; |
mbed_official | 237:f3da66175598 | 1895 | |
mbed_official | 237:f3da66175598 | 1896 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 1897 | __HAL_UNLOCK(hsmbus); |
mbed_official | 237:f3da66175598 | 1898 | |
mbed_official | 237:f3da66175598 | 1899 | return HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 1900 | } |
mbed_official | 237:f3da66175598 | 1901 | } |
mbed_official | 237:f3da66175598 | 1902 | } |
mbed_official | 237:f3da66175598 | 1903 | } |
mbed_official | 237:f3da66175598 | 1904 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 1905 | } |
mbed_official | 237:f3da66175598 | 1906 | |
mbed_official | 237:f3da66175598 | 1907 | /** |
mbed_official | 237:f3da66175598 | 1908 | * @brief Handles SMBUSx communication when starting transfer or during transfer (TC or TCR flag are set). |
mbed_official | 237:f3da66175598 | 1909 | * @param hsmbus: SMBUS handle. |
mbed_official | 237:f3da66175598 | 1910 | * @param DevAddress: specifies the slave address to be programmed. |
mbed_official | 237:f3da66175598 | 1911 | * @param Size: specifies the number of bytes to be programmed. |
mbed_official | 237:f3da66175598 | 1912 | * This parameter must be a value between 0 and 255. |
mbed_official | 237:f3da66175598 | 1913 | * @param Mode: new state of the SMBUS START condition generation. |
mbed_official | 237:f3da66175598 | 1914 | * This parameter can be one or a combination of the following values: |
mbed_official | 237:f3da66175598 | 1915 | * @arg SMBUS_NO_MODE: No specific mode enabled. |
mbed_official | 237:f3da66175598 | 1916 | * @arg SMBUS_RELOAD_MODE: Enable Reload mode. |
mbed_official | 237:f3da66175598 | 1917 | * @arg SMBUS_AUTOEND_MODE: Enable Automatic end mode. |
mbed_official | 237:f3da66175598 | 1918 | * @arg SMBUS_SOFTEND_MODE: Enable Software end mode and Reload mode. |
mbed_official | 237:f3da66175598 | 1919 | * @param Request: new state of the SMBUS START condition generation. |
mbed_official | 237:f3da66175598 | 1920 | * This parameter can be one of the following values: |
mbed_official | 237:f3da66175598 | 1921 | * @arg SMBUS_NO_STARTSTOP: Don't Generate stop and start condition. |
mbed_official | 237:f3da66175598 | 1922 | * @arg SMBUS_GENERATE_STOP: Generate stop condition (Size should be set to 0). |
mbed_official | 237:f3da66175598 | 1923 | * @arg SMBUS_GENERATE_START_READ: Generate Restart for read request. |
mbed_official | 237:f3da66175598 | 1924 | * @arg SMBUS_GENERATE_START_WRITE: Generate Restart for write request. |
mbed_official | 237:f3da66175598 | 1925 | * @retval None |
mbed_official | 237:f3da66175598 | 1926 | */ |
mbed_official | 237:f3da66175598 | 1927 | static void SMBUS_TransferConfig(SMBUS_HandleTypeDef *hsmbus, uint16_t DevAddress, uint8_t Size, uint32_t Mode, uint32_t Request) |
mbed_official | 237:f3da66175598 | 1928 | { |
mbed_official | 237:f3da66175598 | 1929 | uint32_t tmpreg = 0; |
mbed_official | 237:f3da66175598 | 1930 | |
mbed_official | 237:f3da66175598 | 1931 | /* Check the parameters */ |
mbed_official | 237:f3da66175598 | 1932 | assert_param(IS_SMBUS_ALL_INSTANCE(hsmbus->Instance)); |
mbed_official | 237:f3da66175598 | 1933 | assert_param(IS_SMBUS_TRANSFER_MODE(Mode)); |
mbed_official | 237:f3da66175598 | 1934 | assert_param(IS_SMBUS_TRANSFER_REQUEST(Request)); |
mbed_official | 237:f3da66175598 | 1935 | |
mbed_official | 237:f3da66175598 | 1936 | /* Get the CR2 register value */ |
mbed_official | 237:f3da66175598 | 1937 | tmpreg = hsmbus->Instance->CR2; |
mbed_official | 237:f3da66175598 | 1938 | |
mbed_official | 237:f3da66175598 | 1939 | /* clear tmpreg specific bits */ |
mbed_official | 237:f3da66175598 | 1940 | tmpreg &= (uint32_t)~((uint32_t)(I2C_CR2_SADD | I2C_CR2_NBYTES | I2C_CR2_RELOAD | I2C_CR2_AUTOEND | I2C_CR2_RD_WRN | I2C_CR2_START | I2C_CR2_STOP | I2C_CR2_PECBYTE)); |
mbed_official | 237:f3da66175598 | 1941 | |
mbed_official | 237:f3da66175598 | 1942 | /* update tmpreg */ |
mbed_official | 237:f3da66175598 | 1943 | tmpreg |= (uint32_t)(((uint32_t)DevAddress & I2C_CR2_SADD) | (((uint32_t)Size << 16 ) & I2C_CR2_NBYTES) | \ |
mbed_official | 237:f3da66175598 | 1944 | (uint32_t)Mode | (uint32_t)Request); |
mbed_official | 237:f3da66175598 | 1945 | |
mbed_official | 237:f3da66175598 | 1946 | /* update CR2 register */ |
mbed_official | 237:f3da66175598 | 1947 | hsmbus->Instance->CR2 = tmpreg; |
mbed_official | 237:f3da66175598 | 1948 | } |
mbed_official | 237:f3da66175598 | 1949 | /** |
mbed_official | 237:f3da66175598 | 1950 | * @} |
mbed_official | 237:f3da66175598 | 1951 | */ |
mbed_official | 237:f3da66175598 | 1952 | |
mbed_official | 237:f3da66175598 | 1953 | #endif /* HAL_SMBUS_MODULE_ENABLED */ |
mbed_official | 237:f3da66175598 | 1954 | /** |
mbed_official | 237:f3da66175598 | 1955 | * @} |
mbed_official | 237:f3da66175598 | 1956 | */ |
mbed_official | 237:f3da66175598 | 1957 | |
mbed_official | 237:f3da66175598 | 1958 | /** |
mbed_official | 237:f3da66175598 | 1959 | * @} |
mbed_official | 237:f3da66175598 | 1960 | */ |
mbed_official | 237:f3da66175598 | 1961 | |
mbed_official | 237:f3da66175598 | 1962 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |