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