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