mbed library sources
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_NUCLEO_F411RE/stm32f4xx_hal_can.c@308:59cc78a25982, 2014-09-05 (annotated)
- Committer:
- todotani
- Date:
- Fri Sep 05 14:20:33 2014 +0000
- Revision:
- 308:59cc78a25982
- Parent:
- 235:685d5f11838f
BLE_Health_Thermometer for mbed HRM1017 with BLE library 0.1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 235:685d5f11838f | 1 | /** |
mbed_official | 235:685d5f11838f | 2 | ****************************************************************************** |
mbed_official | 235:685d5f11838f | 3 | * @file stm32f4xx_hal_can.c |
mbed_official | 235:685d5f11838f | 4 | * @author MCD Application Team |
mbed_official | 235:685d5f11838f | 5 | * @version V1.1.0 |
mbed_official | 235:685d5f11838f | 6 | * @date 19-June-2014 |
mbed_official | 235:685d5f11838f | 7 | * @brief This file provides firmware functions to manage the following |
mbed_official | 235:685d5f11838f | 8 | * functionalities of the Controller Area Network (CAN) peripheral: |
mbed_official | 235:685d5f11838f | 9 | * + Initialization and de-initialization functions |
mbed_official | 235:685d5f11838f | 10 | * + IO operation functions |
mbed_official | 235:685d5f11838f | 11 | * + Peripheral Control functions |
mbed_official | 235:685d5f11838f | 12 | * + Peripheral State and Error functions |
mbed_official | 235:685d5f11838f | 13 | * |
mbed_official | 235:685d5f11838f | 14 | @verbatim |
mbed_official | 235:685d5f11838f | 15 | ============================================================================== |
mbed_official | 235:685d5f11838f | 16 | ##### How to use this driver ##### |
mbed_official | 235:685d5f11838f | 17 | ============================================================================== |
mbed_official | 235:685d5f11838f | 18 | [..] |
mbed_official | 235:685d5f11838f | 19 | (#) Enable the CAN controller interface clock using |
mbed_official | 235:685d5f11838f | 20 | __CAN1_CLK_ENABLE() for CAN1 and __CAN1_CLK_ENABLE() for CAN2 |
mbed_official | 235:685d5f11838f | 21 | -@- In case you are using CAN2 only, you have to enable the CAN1 clock. |
mbed_official | 235:685d5f11838f | 22 | |
mbed_official | 235:685d5f11838f | 23 | (#) CAN pins configuration |
mbed_official | 235:685d5f11838f | 24 | (++) Enable the clock for the CAN GPIOs using the following function: |
mbed_official | 235:685d5f11838f | 25 | __GPIOx_CLK_ENABLE() |
mbed_official | 235:685d5f11838f | 26 | (++) Connect and configure the involved CAN pins to AF9 using the |
mbed_official | 235:685d5f11838f | 27 | following function HAL_GPIO_Init() |
mbed_official | 235:685d5f11838f | 28 | |
mbed_official | 235:685d5f11838f | 29 | (#) Initialise and configure the CAN using CAN_Init() function. |
mbed_official | 235:685d5f11838f | 30 | |
mbed_official | 235:685d5f11838f | 31 | (#) Transmit the desired CAN frame using HAL_CAN_Transmit() function. |
mbed_official | 235:685d5f11838f | 32 | |
mbed_official | 235:685d5f11838f | 33 | (#) Receive a CAN frame using HAL_CAN_Recieve() function. |
mbed_official | 235:685d5f11838f | 34 | |
mbed_official | 235:685d5f11838f | 35 | *** Polling mode IO operation *** |
mbed_official | 235:685d5f11838f | 36 | ================================= |
mbed_official | 235:685d5f11838f | 37 | [..] |
mbed_official | 235:685d5f11838f | 38 | (+) Start the CAN peripheral transmission and wait the end of this operation |
mbed_official | 235:685d5f11838f | 39 | using HAL_CAN_Transmit(), at this stage user can specify the value of timeout |
mbed_official | 235:685d5f11838f | 40 | according to his end application |
mbed_official | 235:685d5f11838f | 41 | (+) Start the CAN peripheral reception and wait the end of this operation |
mbed_official | 235:685d5f11838f | 42 | using HAL_CAN_Receive(), at this stage user can specify the value of timeout |
mbed_official | 235:685d5f11838f | 43 | according to his end application |
mbed_official | 235:685d5f11838f | 44 | |
mbed_official | 235:685d5f11838f | 45 | *** Interrupt mode IO operation *** |
mbed_official | 235:685d5f11838f | 46 | =================================== |
mbed_official | 235:685d5f11838f | 47 | [..] |
mbed_official | 235:685d5f11838f | 48 | (+) Start the CAN peripheral transmission using HAL_CAN_Transmit_IT() |
mbed_official | 235:685d5f11838f | 49 | (+) Start the CAN peripheral reception using HAL_CAN_Receive_IT() |
mbed_official | 235:685d5f11838f | 50 | (+) Use HAL_CAN_IRQHandler() called under the used CAN Interrupt subroutine |
mbed_official | 235:685d5f11838f | 51 | (+) At CAN end of transmission HAL_CAN_TxCpltCallback() function is executed and user can |
mbed_official | 235:685d5f11838f | 52 | add his own code by customization of function pointer HAL_CAN_TxCpltCallback |
mbed_official | 235:685d5f11838f | 53 | (+) In case of CAN Error, HAL_CAN_ErrorCallback() function is executed and user can |
mbed_official | 235:685d5f11838f | 54 | add his own code by customization of function pointer HAL_CAN_ErrorCallback |
mbed_official | 235:685d5f11838f | 55 | |
mbed_official | 235:685d5f11838f | 56 | *** CAN HAL driver macros list *** |
mbed_official | 235:685d5f11838f | 57 | ============================================= |
mbed_official | 235:685d5f11838f | 58 | [..] |
mbed_official | 235:685d5f11838f | 59 | Below the list of most used macros in CAN HAL driver. |
mbed_official | 235:685d5f11838f | 60 | |
mbed_official | 235:685d5f11838f | 61 | (+) __HAL_CAN_ENABLE_IT: Enable the specified CAN interrupts |
mbed_official | 235:685d5f11838f | 62 | (+) __HAL_CAN_DISABLE_IT: Disable the specified CAN interrupts |
mbed_official | 235:685d5f11838f | 63 | (+) __HAL_CAN_GET_IT_SOURCE: Check if the specified CAN interrupt source is enabled or disabled |
mbed_official | 235:685d5f11838f | 64 | (+) __HAL_CAN_CLEAR_FLAG: Clear the CAN's pending flags |
mbed_official | 235:685d5f11838f | 65 | (+) __HAL_CAN_GET_FLAG: Get the selected CAN's flag status |
mbed_official | 235:685d5f11838f | 66 | |
mbed_official | 235:685d5f11838f | 67 | [..] |
mbed_official | 235:685d5f11838f | 68 | (@) You can refer to the CAN HAL driver header file for more useful macros |
mbed_official | 235:685d5f11838f | 69 | |
mbed_official | 235:685d5f11838f | 70 | @endverbatim |
mbed_official | 235:685d5f11838f | 71 | |
mbed_official | 235:685d5f11838f | 72 | ****************************************************************************** |
mbed_official | 235:685d5f11838f | 73 | * @attention |
mbed_official | 235:685d5f11838f | 74 | * |
mbed_official | 235:685d5f11838f | 75 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 235:685d5f11838f | 76 | * |
mbed_official | 235:685d5f11838f | 77 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 235:685d5f11838f | 78 | * are permitted provided that the following conditions are met: |
mbed_official | 235:685d5f11838f | 79 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 235:685d5f11838f | 80 | * this list of conditions and the following disclaimer. |
mbed_official | 235:685d5f11838f | 81 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 235:685d5f11838f | 82 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 235:685d5f11838f | 83 | * and/or other materials provided with the distribution. |
mbed_official | 235:685d5f11838f | 84 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 235:685d5f11838f | 85 | * may be used to endorse or promote products derived from this software |
mbed_official | 235:685d5f11838f | 86 | * without specific prior written permission. |
mbed_official | 235:685d5f11838f | 87 | * |
mbed_official | 235:685d5f11838f | 88 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 235:685d5f11838f | 89 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 235:685d5f11838f | 90 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 235:685d5f11838f | 91 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 235:685d5f11838f | 92 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 235:685d5f11838f | 93 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 235:685d5f11838f | 94 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 235:685d5f11838f | 95 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 235:685d5f11838f | 96 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 235:685d5f11838f | 97 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 235:685d5f11838f | 98 | * |
mbed_official | 235:685d5f11838f | 99 | ****************************************************************************** |
mbed_official | 235:685d5f11838f | 100 | */ |
mbed_official | 235:685d5f11838f | 101 | |
mbed_official | 235:685d5f11838f | 102 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 235:685d5f11838f | 103 | #include "stm32f4xx_hal.h" |
mbed_official | 235:685d5f11838f | 104 | |
mbed_official | 235:685d5f11838f | 105 | /** @addtogroup STM32F4xx_HAL_Driver |
mbed_official | 235:685d5f11838f | 106 | * @{ |
mbed_official | 235:685d5f11838f | 107 | */ |
mbed_official | 235:685d5f11838f | 108 | |
mbed_official | 235:685d5f11838f | 109 | /** @defgroup CAN |
mbed_official | 235:685d5f11838f | 110 | * @brief CAN driver modules |
mbed_official | 235:685d5f11838f | 111 | * @{ |
mbed_official | 235:685d5f11838f | 112 | */ |
mbed_official | 235:685d5f11838f | 113 | |
mbed_official | 235:685d5f11838f | 114 | #ifdef HAL_CAN_MODULE_ENABLED |
mbed_official | 235:685d5f11838f | 115 | |
mbed_official | 235:685d5f11838f | 116 | #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) || defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) |
mbed_official | 235:685d5f11838f | 117 | |
mbed_official | 235:685d5f11838f | 118 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 235:685d5f11838f | 119 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 235:685d5f11838f | 120 | #define CAN_TIMEOUT_VALUE 10 |
mbed_official | 235:685d5f11838f | 121 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 235:685d5f11838f | 122 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 235:685d5f11838f | 123 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 235:685d5f11838f | 124 | static HAL_StatusTypeDef CAN_Receive_IT(CAN_HandleTypeDef* hcan, uint8_t FIFONumber); |
mbed_official | 235:685d5f11838f | 125 | static HAL_StatusTypeDef CAN_Transmit_IT(CAN_HandleTypeDef* hcan); |
mbed_official | 235:685d5f11838f | 126 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 235:685d5f11838f | 127 | |
mbed_official | 235:685d5f11838f | 128 | /** @defgroup CAN_Private_Functions |
mbed_official | 235:685d5f11838f | 129 | * @{ |
mbed_official | 235:685d5f11838f | 130 | */ |
mbed_official | 235:685d5f11838f | 131 | |
mbed_official | 235:685d5f11838f | 132 | /** @defgroup CAN_Group1 Initialization and de-initialization functions |
mbed_official | 235:685d5f11838f | 133 | * @brief Initialization and Configuration functions |
mbed_official | 235:685d5f11838f | 134 | * |
mbed_official | 235:685d5f11838f | 135 | @verbatim |
mbed_official | 235:685d5f11838f | 136 | ============================================================================== |
mbed_official | 235:685d5f11838f | 137 | ##### Initialization and de-initialization functions ##### |
mbed_official | 235:685d5f11838f | 138 | ============================================================================== |
mbed_official | 235:685d5f11838f | 139 | [..] This section provides functions allowing to: |
mbed_official | 235:685d5f11838f | 140 | (+) Initialize and configure the CAN. |
mbed_official | 235:685d5f11838f | 141 | (+) De-initialize the CAN. |
mbed_official | 235:685d5f11838f | 142 | |
mbed_official | 235:685d5f11838f | 143 | @endverbatim |
mbed_official | 235:685d5f11838f | 144 | * @{ |
mbed_official | 235:685d5f11838f | 145 | */ |
mbed_official | 235:685d5f11838f | 146 | |
mbed_official | 235:685d5f11838f | 147 | /** |
mbed_official | 235:685d5f11838f | 148 | * @brief Initializes the CAN peripheral according to the specified |
mbed_official | 235:685d5f11838f | 149 | * parameters in the CAN_InitStruct. |
mbed_official | 235:685d5f11838f | 150 | * @param hcan: pointer to a CAN_HandleTypeDef structure that contains |
mbed_official | 235:685d5f11838f | 151 | * the configuration information for the specified CAN. |
mbed_official | 235:685d5f11838f | 152 | * @retval HAL status |
mbed_official | 235:685d5f11838f | 153 | */ |
mbed_official | 235:685d5f11838f | 154 | HAL_StatusTypeDef HAL_CAN_Init(CAN_HandleTypeDef* hcan) |
mbed_official | 235:685d5f11838f | 155 | { |
mbed_official | 235:685d5f11838f | 156 | uint32_t InitStatus = 3; |
mbed_official | 235:685d5f11838f | 157 | uint32_t tickstart = 0; |
mbed_official | 235:685d5f11838f | 158 | |
mbed_official | 235:685d5f11838f | 159 | /* Check CAN handle */ |
mbed_official | 235:685d5f11838f | 160 | if(hcan == NULL) |
mbed_official | 235:685d5f11838f | 161 | { |
mbed_official | 235:685d5f11838f | 162 | return HAL_ERROR; |
mbed_official | 235:685d5f11838f | 163 | } |
mbed_official | 235:685d5f11838f | 164 | |
mbed_official | 235:685d5f11838f | 165 | /* Check the parameters */ |
mbed_official | 235:685d5f11838f | 166 | assert_param(IS_CAN_ALL_INSTANCE(hcan->Instance)); |
mbed_official | 235:685d5f11838f | 167 | assert_param(IS_FUNCTIONAL_STATE(hcan->Init.TTCM)); |
mbed_official | 235:685d5f11838f | 168 | assert_param(IS_FUNCTIONAL_STATE(hcan->Init.ABOM)); |
mbed_official | 235:685d5f11838f | 169 | assert_param(IS_FUNCTIONAL_STATE(hcan->Init.AWUM)); |
mbed_official | 235:685d5f11838f | 170 | assert_param(IS_FUNCTIONAL_STATE(hcan->Init.NART)); |
mbed_official | 235:685d5f11838f | 171 | assert_param(IS_FUNCTIONAL_STATE(hcan->Init.RFLM)); |
mbed_official | 235:685d5f11838f | 172 | assert_param(IS_FUNCTIONAL_STATE(hcan->Init.TXFP)); |
mbed_official | 235:685d5f11838f | 173 | assert_param(IS_CAN_MODE(hcan->Init.Mode)); |
mbed_official | 235:685d5f11838f | 174 | assert_param(IS_CAN_SJW(hcan->Init.SJW)); |
mbed_official | 235:685d5f11838f | 175 | assert_param(IS_CAN_BS1(hcan->Init.BS1)); |
mbed_official | 235:685d5f11838f | 176 | assert_param(IS_CAN_BS2(hcan->Init.BS2)); |
mbed_official | 235:685d5f11838f | 177 | assert_param(IS_CAN_PRESCALER(hcan->Init.Prescaler)); |
mbed_official | 235:685d5f11838f | 178 | |
mbed_official | 235:685d5f11838f | 179 | |
mbed_official | 235:685d5f11838f | 180 | if(hcan->State == HAL_CAN_STATE_RESET) |
mbed_official | 235:685d5f11838f | 181 | { |
mbed_official | 235:685d5f11838f | 182 | /* Init the low level hardware */ |
mbed_official | 235:685d5f11838f | 183 | HAL_CAN_MspInit(hcan); |
mbed_official | 235:685d5f11838f | 184 | } |
mbed_official | 235:685d5f11838f | 185 | |
mbed_official | 235:685d5f11838f | 186 | /* Initialize the CAN state*/ |
mbed_official | 235:685d5f11838f | 187 | hcan->State = HAL_CAN_STATE_BUSY; |
mbed_official | 235:685d5f11838f | 188 | |
mbed_official | 235:685d5f11838f | 189 | /* Exit from sleep mode */ |
mbed_official | 235:685d5f11838f | 190 | hcan->Instance->MCR &= (~(uint32_t)CAN_MCR_SLEEP); |
mbed_official | 235:685d5f11838f | 191 | |
mbed_official | 235:685d5f11838f | 192 | /* Request initialisation */ |
mbed_official | 235:685d5f11838f | 193 | hcan->Instance->MCR |= CAN_MCR_INRQ ; |
mbed_official | 235:685d5f11838f | 194 | |
mbed_official | 235:685d5f11838f | 195 | /* Get tick */ |
mbed_official | 235:685d5f11838f | 196 | tickstart = HAL_GetTick(); |
mbed_official | 235:685d5f11838f | 197 | |
mbed_official | 235:685d5f11838f | 198 | /* Wait the acknowledge */ |
mbed_official | 235:685d5f11838f | 199 | while((hcan->Instance->MSR & CAN_MSR_INAK) != CAN_MSR_INAK) |
mbed_official | 235:685d5f11838f | 200 | { |
mbed_official | 235:685d5f11838f | 201 | if((HAL_GetTick() - tickstart ) > CAN_TIMEOUT_VALUE) |
mbed_official | 235:685d5f11838f | 202 | { |
mbed_official | 235:685d5f11838f | 203 | hcan->State= HAL_CAN_STATE_TIMEOUT; |
mbed_official | 235:685d5f11838f | 204 | /* Process unlocked */ |
mbed_official | 235:685d5f11838f | 205 | __HAL_UNLOCK(hcan); |
mbed_official | 235:685d5f11838f | 206 | return HAL_TIMEOUT; |
mbed_official | 235:685d5f11838f | 207 | } |
mbed_official | 235:685d5f11838f | 208 | } |
mbed_official | 235:685d5f11838f | 209 | |
mbed_official | 235:685d5f11838f | 210 | /* Check acknowledge */ |
mbed_official | 235:685d5f11838f | 211 | if ((hcan->Instance->MSR & CAN_MSR_INAK) != CAN_MSR_INAK) |
mbed_official | 235:685d5f11838f | 212 | { |
mbed_official | 235:685d5f11838f | 213 | InitStatus = CAN_INITSTATUS_FAILED; |
mbed_official | 235:685d5f11838f | 214 | } |
mbed_official | 235:685d5f11838f | 215 | else |
mbed_official | 235:685d5f11838f | 216 | { |
mbed_official | 235:685d5f11838f | 217 | /* Set the time triggered communication mode */ |
mbed_official | 235:685d5f11838f | 218 | if (hcan->Init.TTCM == ENABLE) |
mbed_official | 235:685d5f11838f | 219 | { |
mbed_official | 235:685d5f11838f | 220 | hcan->Instance->MCR |= CAN_MCR_TTCM; |
mbed_official | 235:685d5f11838f | 221 | } |
mbed_official | 235:685d5f11838f | 222 | else |
mbed_official | 235:685d5f11838f | 223 | { |
mbed_official | 235:685d5f11838f | 224 | hcan->Instance->MCR &= ~(uint32_t)CAN_MCR_TTCM; |
mbed_official | 235:685d5f11838f | 225 | } |
mbed_official | 235:685d5f11838f | 226 | |
mbed_official | 235:685d5f11838f | 227 | /* Set the automatic bus-off management */ |
mbed_official | 235:685d5f11838f | 228 | if (hcan->Init.ABOM == ENABLE) |
mbed_official | 235:685d5f11838f | 229 | { |
mbed_official | 235:685d5f11838f | 230 | hcan->Instance->MCR |= CAN_MCR_ABOM; |
mbed_official | 235:685d5f11838f | 231 | } |
mbed_official | 235:685d5f11838f | 232 | else |
mbed_official | 235:685d5f11838f | 233 | { |
mbed_official | 235:685d5f11838f | 234 | hcan->Instance->MCR &= ~(uint32_t)CAN_MCR_ABOM; |
mbed_official | 235:685d5f11838f | 235 | } |
mbed_official | 235:685d5f11838f | 236 | |
mbed_official | 235:685d5f11838f | 237 | /* Set the automatic wake-up mode */ |
mbed_official | 235:685d5f11838f | 238 | if (hcan->Init.AWUM == ENABLE) |
mbed_official | 235:685d5f11838f | 239 | { |
mbed_official | 235:685d5f11838f | 240 | hcan->Instance->MCR |= CAN_MCR_AWUM; |
mbed_official | 235:685d5f11838f | 241 | } |
mbed_official | 235:685d5f11838f | 242 | else |
mbed_official | 235:685d5f11838f | 243 | { |
mbed_official | 235:685d5f11838f | 244 | hcan->Instance->MCR &= ~(uint32_t)CAN_MCR_AWUM; |
mbed_official | 235:685d5f11838f | 245 | } |
mbed_official | 235:685d5f11838f | 246 | |
mbed_official | 235:685d5f11838f | 247 | /* Set the no automatic retransmission */ |
mbed_official | 235:685d5f11838f | 248 | if (hcan->Init.NART == ENABLE) |
mbed_official | 235:685d5f11838f | 249 | { |
mbed_official | 235:685d5f11838f | 250 | hcan->Instance->MCR |= CAN_MCR_NART; |
mbed_official | 235:685d5f11838f | 251 | } |
mbed_official | 235:685d5f11838f | 252 | else |
mbed_official | 235:685d5f11838f | 253 | { |
mbed_official | 235:685d5f11838f | 254 | hcan->Instance->MCR &= ~(uint32_t)CAN_MCR_NART; |
mbed_official | 235:685d5f11838f | 255 | } |
mbed_official | 235:685d5f11838f | 256 | |
mbed_official | 235:685d5f11838f | 257 | /* Set the receive FIFO locked mode */ |
mbed_official | 235:685d5f11838f | 258 | if (hcan->Init.RFLM == ENABLE) |
mbed_official | 235:685d5f11838f | 259 | { |
mbed_official | 235:685d5f11838f | 260 | hcan->Instance->MCR |= CAN_MCR_RFLM; |
mbed_official | 235:685d5f11838f | 261 | } |
mbed_official | 235:685d5f11838f | 262 | else |
mbed_official | 235:685d5f11838f | 263 | { |
mbed_official | 235:685d5f11838f | 264 | hcan->Instance->MCR &= ~(uint32_t)CAN_MCR_RFLM; |
mbed_official | 235:685d5f11838f | 265 | } |
mbed_official | 235:685d5f11838f | 266 | |
mbed_official | 235:685d5f11838f | 267 | /* Set the transmit FIFO priority */ |
mbed_official | 235:685d5f11838f | 268 | if (hcan->Init.TXFP == ENABLE) |
mbed_official | 235:685d5f11838f | 269 | { |
mbed_official | 235:685d5f11838f | 270 | hcan->Instance->MCR |= CAN_MCR_TXFP; |
mbed_official | 235:685d5f11838f | 271 | } |
mbed_official | 235:685d5f11838f | 272 | else |
mbed_official | 235:685d5f11838f | 273 | { |
mbed_official | 235:685d5f11838f | 274 | hcan->Instance->MCR &= ~(uint32_t)CAN_MCR_TXFP; |
mbed_official | 235:685d5f11838f | 275 | } |
mbed_official | 235:685d5f11838f | 276 | |
mbed_official | 235:685d5f11838f | 277 | /* Set the bit timing register */ |
mbed_official | 235:685d5f11838f | 278 | hcan->Instance->BTR = (uint32_t)((uint32_t)hcan->Init.Mode) | \ |
mbed_official | 235:685d5f11838f | 279 | ((uint32_t)hcan->Init.SJW) | \ |
mbed_official | 235:685d5f11838f | 280 | ((uint32_t)hcan->Init.BS1) | \ |
mbed_official | 235:685d5f11838f | 281 | ((uint32_t)hcan->Init.BS2) | \ |
mbed_official | 235:685d5f11838f | 282 | ((uint32_t)hcan->Init.Prescaler - 1); |
mbed_official | 235:685d5f11838f | 283 | |
mbed_official | 235:685d5f11838f | 284 | /* Request leave initialisation */ |
mbed_official | 235:685d5f11838f | 285 | hcan->Instance->MCR &= ~(uint32_t)CAN_MCR_INRQ; |
mbed_official | 235:685d5f11838f | 286 | |
mbed_official | 235:685d5f11838f | 287 | /* Get tick */ |
mbed_official | 235:685d5f11838f | 288 | tickstart = HAL_GetTick(); |
mbed_official | 235:685d5f11838f | 289 | |
mbed_official | 235:685d5f11838f | 290 | /* Wait the acknowledge */ |
mbed_official | 235:685d5f11838f | 291 | while((hcan->Instance->MSR & CAN_MSR_INAK) == CAN_MSR_INAK) |
mbed_official | 235:685d5f11838f | 292 | { |
mbed_official | 235:685d5f11838f | 293 | if((HAL_GetTick() - tickstart ) > CAN_TIMEOUT_VALUE) |
mbed_official | 235:685d5f11838f | 294 | { |
mbed_official | 235:685d5f11838f | 295 | hcan->State= HAL_CAN_STATE_TIMEOUT; |
mbed_official | 235:685d5f11838f | 296 | /* Process unlocked */ |
mbed_official | 235:685d5f11838f | 297 | __HAL_UNLOCK(hcan); |
mbed_official | 235:685d5f11838f | 298 | return HAL_TIMEOUT; |
mbed_official | 235:685d5f11838f | 299 | } |
mbed_official | 235:685d5f11838f | 300 | } |
mbed_official | 235:685d5f11838f | 301 | |
mbed_official | 235:685d5f11838f | 302 | /* Check acknowledged */ |
mbed_official | 235:685d5f11838f | 303 | if ((hcan->Instance->MSR & CAN_MSR_INAK) == CAN_MSR_INAK) |
mbed_official | 235:685d5f11838f | 304 | { |
mbed_official | 235:685d5f11838f | 305 | InitStatus = CAN_INITSTATUS_FAILED; |
mbed_official | 235:685d5f11838f | 306 | } |
mbed_official | 235:685d5f11838f | 307 | else |
mbed_official | 235:685d5f11838f | 308 | { |
mbed_official | 235:685d5f11838f | 309 | InitStatus = CAN_INITSTATUS_SUCCESS; |
mbed_official | 235:685d5f11838f | 310 | } |
mbed_official | 235:685d5f11838f | 311 | } |
mbed_official | 235:685d5f11838f | 312 | |
mbed_official | 235:685d5f11838f | 313 | if(InitStatus == CAN_INITSTATUS_SUCCESS) |
mbed_official | 235:685d5f11838f | 314 | { |
mbed_official | 235:685d5f11838f | 315 | /* Set CAN error code to none */ |
mbed_official | 235:685d5f11838f | 316 | hcan->ErrorCode = HAL_CAN_ERROR_NONE; |
mbed_official | 235:685d5f11838f | 317 | |
mbed_official | 235:685d5f11838f | 318 | /* Initialize the CAN state */ |
mbed_official | 235:685d5f11838f | 319 | hcan->State = HAL_CAN_STATE_READY; |
mbed_official | 235:685d5f11838f | 320 | |
mbed_official | 235:685d5f11838f | 321 | /* Return function status */ |
mbed_official | 235:685d5f11838f | 322 | return HAL_OK; |
mbed_official | 235:685d5f11838f | 323 | } |
mbed_official | 235:685d5f11838f | 324 | else |
mbed_official | 235:685d5f11838f | 325 | { |
mbed_official | 235:685d5f11838f | 326 | /* Initialize the CAN state */ |
mbed_official | 235:685d5f11838f | 327 | hcan->State = HAL_CAN_STATE_ERROR; |
mbed_official | 235:685d5f11838f | 328 | |
mbed_official | 235:685d5f11838f | 329 | /* Return function status */ |
mbed_official | 235:685d5f11838f | 330 | return HAL_ERROR; |
mbed_official | 235:685d5f11838f | 331 | } |
mbed_official | 235:685d5f11838f | 332 | } |
mbed_official | 235:685d5f11838f | 333 | |
mbed_official | 235:685d5f11838f | 334 | /** |
mbed_official | 235:685d5f11838f | 335 | * @brief Configures the CAN reception filter according to the specified |
mbed_official | 235:685d5f11838f | 336 | * parameters in the CAN_FilterInitStruct. |
mbed_official | 235:685d5f11838f | 337 | * @param hcan: pointer to a CAN_HandleTypeDef structure that contains |
mbed_official | 235:685d5f11838f | 338 | * the configuration information for the specified CAN. |
mbed_official | 235:685d5f11838f | 339 | * @param sFilterConfig: pointer to a CAN_FilterConfTypeDef structure that |
mbed_official | 235:685d5f11838f | 340 | * contains the filter configuration information. |
mbed_official | 235:685d5f11838f | 341 | * @retval None |
mbed_official | 235:685d5f11838f | 342 | */ |
mbed_official | 235:685d5f11838f | 343 | HAL_StatusTypeDef HAL_CAN_ConfigFilter(CAN_HandleTypeDef* hcan, CAN_FilterConfTypeDef* sFilterConfig) |
mbed_official | 235:685d5f11838f | 344 | { |
mbed_official | 235:685d5f11838f | 345 | uint32_t filternbrbitpos = 0; |
mbed_official | 235:685d5f11838f | 346 | |
mbed_official | 235:685d5f11838f | 347 | /* Check the parameters */ |
mbed_official | 235:685d5f11838f | 348 | assert_param(IS_CAN_FILTER_NUMBER(sFilterConfig->FilterNumber)); |
mbed_official | 235:685d5f11838f | 349 | assert_param(IS_CAN_FILTER_MODE(sFilterConfig->FilterMode)); |
mbed_official | 235:685d5f11838f | 350 | assert_param(IS_CAN_FILTER_SCALE(sFilterConfig->FilterScale)); |
mbed_official | 235:685d5f11838f | 351 | assert_param(IS_CAN_FILTER_FIFO(sFilterConfig->FilterFIFOAssignment)); |
mbed_official | 235:685d5f11838f | 352 | assert_param(IS_FUNCTIONAL_STATE(sFilterConfig->FilterActivation)); |
mbed_official | 235:685d5f11838f | 353 | assert_param(IS_CAN_BANKNUMBER(sFilterConfig->BankNumber)); |
mbed_official | 235:685d5f11838f | 354 | |
mbed_official | 235:685d5f11838f | 355 | filternbrbitpos = ((uint32_t)1) << sFilterConfig->FilterNumber; |
mbed_official | 235:685d5f11838f | 356 | |
mbed_official | 235:685d5f11838f | 357 | /* Initialisation mode for the filter */ |
mbed_official | 235:685d5f11838f | 358 | CAN1->FMR |= (uint32_t)CAN_FMR_FINIT; |
mbed_official | 235:685d5f11838f | 359 | |
mbed_official | 235:685d5f11838f | 360 | /* Select the start slave bank */ |
mbed_official | 235:685d5f11838f | 361 | CAN1->FMR &= ~((uint32_t)CAN_FMR_CAN2SB); |
mbed_official | 235:685d5f11838f | 362 | CAN1->FMR |= (uint32_t)(sFilterConfig->BankNumber << 8); |
mbed_official | 235:685d5f11838f | 363 | |
mbed_official | 235:685d5f11838f | 364 | /* Filter Deactivation */ |
mbed_official | 235:685d5f11838f | 365 | CAN1->FA1R &= ~(uint32_t)filternbrbitpos; |
mbed_official | 235:685d5f11838f | 366 | |
mbed_official | 235:685d5f11838f | 367 | /* Filter Scale */ |
mbed_official | 235:685d5f11838f | 368 | if (sFilterConfig->FilterScale == CAN_FILTERSCALE_16BIT) |
mbed_official | 235:685d5f11838f | 369 | { |
mbed_official | 235:685d5f11838f | 370 | /* 16-bit scale for the filter */ |
mbed_official | 235:685d5f11838f | 371 | CAN1->FS1R &= ~(uint32_t)filternbrbitpos; |
mbed_official | 235:685d5f11838f | 372 | |
mbed_official | 235:685d5f11838f | 373 | /* First 16-bit identifier and First 16-bit mask */ |
mbed_official | 235:685d5f11838f | 374 | /* Or First 16-bit identifier and Second 16-bit identifier */ |
mbed_official | 235:685d5f11838f | 375 | CAN1->sFilterRegister[sFilterConfig->FilterNumber].FR1 = |
mbed_official | 235:685d5f11838f | 376 | ((0x0000FFFF & (uint32_t)sFilterConfig->FilterMaskIdLow) << 16) | |
mbed_official | 235:685d5f11838f | 377 | (0x0000FFFF & (uint32_t)sFilterConfig->FilterIdLow); |
mbed_official | 235:685d5f11838f | 378 | |
mbed_official | 235:685d5f11838f | 379 | /* Second 16-bit identifier and Second 16-bit mask */ |
mbed_official | 235:685d5f11838f | 380 | /* Or Third 16-bit identifier and Fourth 16-bit identifier */ |
mbed_official | 235:685d5f11838f | 381 | CAN1->sFilterRegister[sFilterConfig->FilterNumber].FR2 = |
mbed_official | 235:685d5f11838f | 382 | ((0x0000FFFF & (uint32_t)sFilterConfig->FilterMaskIdHigh) << 16) | |
mbed_official | 235:685d5f11838f | 383 | (0x0000FFFF & (uint32_t)sFilterConfig->FilterIdHigh); |
mbed_official | 235:685d5f11838f | 384 | } |
mbed_official | 235:685d5f11838f | 385 | |
mbed_official | 235:685d5f11838f | 386 | if (sFilterConfig->FilterScale == CAN_FILTERSCALE_32BIT) |
mbed_official | 235:685d5f11838f | 387 | { |
mbed_official | 235:685d5f11838f | 388 | /* 32-bit scale for the filter */ |
mbed_official | 235:685d5f11838f | 389 | CAN1->FS1R |= filternbrbitpos; |
mbed_official | 235:685d5f11838f | 390 | /* 32-bit identifier or First 32-bit identifier */ |
mbed_official | 235:685d5f11838f | 391 | CAN1->sFilterRegister[sFilterConfig->FilterNumber].FR1 = |
mbed_official | 235:685d5f11838f | 392 | ((0x0000FFFF & (uint32_t)sFilterConfig->FilterIdHigh) << 16) | |
mbed_official | 235:685d5f11838f | 393 | (0x0000FFFF & (uint32_t)sFilterConfig->FilterIdLow); |
mbed_official | 235:685d5f11838f | 394 | /* 32-bit mask or Second 32-bit identifier */ |
mbed_official | 235:685d5f11838f | 395 | CAN1->sFilterRegister[sFilterConfig->FilterNumber].FR2 = |
mbed_official | 235:685d5f11838f | 396 | ((0x0000FFFF & (uint32_t)sFilterConfig->FilterMaskIdHigh) << 16) | |
mbed_official | 235:685d5f11838f | 397 | (0x0000FFFF & (uint32_t)sFilterConfig->FilterMaskIdLow); |
mbed_official | 235:685d5f11838f | 398 | } |
mbed_official | 235:685d5f11838f | 399 | |
mbed_official | 235:685d5f11838f | 400 | /* Filter Mode */ |
mbed_official | 235:685d5f11838f | 401 | if (sFilterConfig->FilterMode == CAN_FILTERMODE_IDMASK) |
mbed_official | 235:685d5f11838f | 402 | { |
mbed_official | 235:685d5f11838f | 403 | /*Id/Mask mode for the filter*/ |
mbed_official | 235:685d5f11838f | 404 | CAN1->FM1R &= ~(uint32_t)filternbrbitpos; |
mbed_official | 235:685d5f11838f | 405 | } |
mbed_official | 235:685d5f11838f | 406 | else /* CAN_FilterInitStruct->CAN_FilterMode == CAN_FilterMode_IdList */ |
mbed_official | 235:685d5f11838f | 407 | { |
mbed_official | 235:685d5f11838f | 408 | /*Identifier list mode for the filter*/ |
mbed_official | 235:685d5f11838f | 409 | CAN1->FM1R |= (uint32_t)filternbrbitpos; |
mbed_official | 235:685d5f11838f | 410 | } |
mbed_official | 235:685d5f11838f | 411 | |
mbed_official | 235:685d5f11838f | 412 | /* Filter FIFO assignment */ |
mbed_official | 235:685d5f11838f | 413 | if (sFilterConfig->FilterFIFOAssignment == CAN_FILTER_FIFO0) |
mbed_official | 235:685d5f11838f | 414 | { |
mbed_official | 235:685d5f11838f | 415 | /* FIFO 0 assignation for the filter */ |
mbed_official | 235:685d5f11838f | 416 | CAN1->FFA1R &= ~(uint32_t)filternbrbitpos; |
mbed_official | 235:685d5f11838f | 417 | } |
mbed_official | 235:685d5f11838f | 418 | |
mbed_official | 235:685d5f11838f | 419 | if (sFilterConfig->FilterFIFOAssignment == CAN_FILTER_FIFO1) |
mbed_official | 235:685d5f11838f | 420 | { |
mbed_official | 235:685d5f11838f | 421 | /* FIFO 1 assignation for the filter */ |
mbed_official | 235:685d5f11838f | 422 | CAN1->FFA1R |= (uint32_t)filternbrbitpos; |
mbed_official | 235:685d5f11838f | 423 | } |
mbed_official | 235:685d5f11838f | 424 | |
mbed_official | 235:685d5f11838f | 425 | /* Filter activation */ |
mbed_official | 235:685d5f11838f | 426 | if (sFilterConfig->FilterActivation == ENABLE) |
mbed_official | 235:685d5f11838f | 427 | { |
mbed_official | 235:685d5f11838f | 428 | CAN1->FA1R |= filternbrbitpos; |
mbed_official | 235:685d5f11838f | 429 | } |
mbed_official | 235:685d5f11838f | 430 | |
mbed_official | 235:685d5f11838f | 431 | /* Leave the initialisation mode for the filter */ |
mbed_official | 235:685d5f11838f | 432 | CAN1->FMR &= ~((uint32_t)CAN_FMR_FINIT); |
mbed_official | 235:685d5f11838f | 433 | |
mbed_official | 235:685d5f11838f | 434 | /* Return function status */ |
mbed_official | 235:685d5f11838f | 435 | return HAL_OK; |
mbed_official | 235:685d5f11838f | 436 | } |
mbed_official | 235:685d5f11838f | 437 | |
mbed_official | 235:685d5f11838f | 438 | /** |
mbed_official | 235:685d5f11838f | 439 | * @brief Deinitializes the CANx peripheral registers to their default reset values. |
mbed_official | 235:685d5f11838f | 440 | * @param hcan: pointer to a CAN_HandleTypeDef structure that contains |
mbed_official | 235:685d5f11838f | 441 | * the configuration information for the specified CAN. |
mbed_official | 235:685d5f11838f | 442 | * @retval HAL status |
mbed_official | 235:685d5f11838f | 443 | */ |
mbed_official | 235:685d5f11838f | 444 | HAL_StatusTypeDef HAL_CAN_DeInit(CAN_HandleTypeDef* hcan) |
mbed_official | 235:685d5f11838f | 445 | { |
mbed_official | 235:685d5f11838f | 446 | /* Check CAN handle */ |
mbed_official | 235:685d5f11838f | 447 | if(hcan == NULL) |
mbed_official | 235:685d5f11838f | 448 | { |
mbed_official | 235:685d5f11838f | 449 | return HAL_ERROR; |
mbed_official | 235:685d5f11838f | 450 | } |
mbed_official | 235:685d5f11838f | 451 | |
mbed_official | 235:685d5f11838f | 452 | /* Check the parameters */ |
mbed_official | 235:685d5f11838f | 453 | assert_param(IS_CAN_ALL_INSTANCE(hcan->Instance)); |
mbed_official | 235:685d5f11838f | 454 | |
mbed_official | 235:685d5f11838f | 455 | /* Change CAN state */ |
mbed_official | 235:685d5f11838f | 456 | hcan->State = HAL_CAN_STATE_BUSY; |
mbed_official | 235:685d5f11838f | 457 | |
mbed_official | 235:685d5f11838f | 458 | /* DeInit the low level hardware */ |
mbed_official | 235:685d5f11838f | 459 | HAL_CAN_MspDeInit(hcan); |
mbed_official | 235:685d5f11838f | 460 | |
mbed_official | 235:685d5f11838f | 461 | /* Change CAN state */ |
mbed_official | 235:685d5f11838f | 462 | hcan->State = HAL_CAN_STATE_RESET; |
mbed_official | 235:685d5f11838f | 463 | |
mbed_official | 235:685d5f11838f | 464 | /* Release Lock */ |
mbed_official | 235:685d5f11838f | 465 | __HAL_UNLOCK(hcan); |
mbed_official | 235:685d5f11838f | 466 | |
mbed_official | 235:685d5f11838f | 467 | /* Return function status */ |
mbed_official | 235:685d5f11838f | 468 | return HAL_OK; |
mbed_official | 235:685d5f11838f | 469 | } |
mbed_official | 235:685d5f11838f | 470 | |
mbed_official | 235:685d5f11838f | 471 | /** |
mbed_official | 235:685d5f11838f | 472 | * @brief Initializes the CAN MSP. |
mbed_official | 235:685d5f11838f | 473 | * @param hcan: pointer to a CAN_HandleTypeDef structure that contains |
mbed_official | 235:685d5f11838f | 474 | * the configuration information for the specified CAN. |
mbed_official | 235:685d5f11838f | 475 | * @retval None |
mbed_official | 235:685d5f11838f | 476 | */ |
mbed_official | 235:685d5f11838f | 477 | __weak void HAL_CAN_MspInit(CAN_HandleTypeDef* hcan) |
mbed_official | 235:685d5f11838f | 478 | { |
mbed_official | 235:685d5f11838f | 479 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 235:685d5f11838f | 480 | the HAL_CAN_MspInit could be implemented in the user file |
mbed_official | 235:685d5f11838f | 481 | */ |
mbed_official | 235:685d5f11838f | 482 | } |
mbed_official | 235:685d5f11838f | 483 | |
mbed_official | 235:685d5f11838f | 484 | /** |
mbed_official | 235:685d5f11838f | 485 | * @brief DeInitializes the CAN MSP. |
mbed_official | 235:685d5f11838f | 486 | * @param hcan: pointer to a CAN_HandleTypeDef structure that contains |
mbed_official | 235:685d5f11838f | 487 | * the configuration information for the specified CAN. |
mbed_official | 235:685d5f11838f | 488 | * @retval None |
mbed_official | 235:685d5f11838f | 489 | */ |
mbed_official | 235:685d5f11838f | 490 | __weak void HAL_CAN_MspDeInit(CAN_HandleTypeDef* hcan) |
mbed_official | 235:685d5f11838f | 491 | { |
mbed_official | 235:685d5f11838f | 492 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 235:685d5f11838f | 493 | the HAL_CAN_MspDeInit could be implemented in the user file |
mbed_official | 235:685d5f11838f | 494 | */ |
mbed_official | 235:685d5f11838f | 495 | } |
mbed_official | 235:685d5f11838f | 496 | |
mbed_official | 235:685d5f11838f | 497 | /** |
mbed_official | 235:685d5f11838f | 498 | * @} |
mbed_official | 235:685d5f11838f | 499 | */ |
mbed_official | 235:685d5f11838f | 500 | |
mbed_official | 235:685d5f11838f | 501 | /** @defgroup CAN_Group2 IO operation functions |
mbed_official | 235:685d5f11838f | 502 | * @brief IO operation functions |
mbed_official | 235:685d5f11838f | 503 | * |
mbed_official | 235:685d5f11838f | 504 | @verbatim |
mbed_official | 235:685d5f11838f | 505 | ============================================================================== |
mbed_official | 235:685d5f11838f | 506 | ##### IO operation functions ##### |
mbed_official | 235:685d5f11838f | 507 | ============================================================================== |
mbed_official | 235:685d5f11838f | 508 | [..] This section provides functions allowing to: |
mbed_official | 235:685d5f11838f | 509 | (+) Transmit a CAN frame message. |
mbed_official | 235:685d5f11838f | 510 | (+) Receive a CAN frame message. |
mbed_official | 235:685d5f11838f | 511 | (+) Enter CAN peripheral in sleep mode. |
mbed_official | 235:685d5f11838f | 512 | (+) Wake up the CAN peripheral from sleep mode. |
mbed_official | 235:685d5f11838f | 513 | |
mbed_official | 235:685d5f11838f | 514 | @endverbatim |
mbed_official | 235:685d5f11838f | 515 | * @{ |
mbed_official | 235:685d5f11838f | 516 | */ |
mbed_official | 235:685d5f11838f | 517 | |
mbed_official | 235:685d5f11838f | 518 | /** |
mbed_official | 235:685d5f11838f | 519 | * @brief Initiates and transmits a CAN frame message. |
mbed_official | 235:685d5f11838f | 520 | * @param hcan: pointer to a CAN_HandleTypeDef structure that contains |
mbed_official | 235:685d5f11838f | 521 | * the configuration information for the specified CAN. |
mbed_official | 235:685d5f11838f | 522 | * @param Timeout: Specify Timeout value |
mbed_official | 235:685d5f11838f | 523 | * @retval HAL status |
mbed_official | 235:685d5f11838f | 524 | */ |
mbed_official | 235:685d5f11838f | 525 | HAL_StatusTypeDef HAL_CAN_Transmit(CAN_HandleTypeDef* hcan, uint32_t Timeout) |
mbed_official | 235:685d5f11838f | 526 | { |
mbed_official | 235:685d5f11838f | 527 | uint32_t transmitmailbox = 5; |
mbed_official | 235:685d5f11838f | 528 | uint32_t tickstart = 0; |
mbed_official | 235:685d5f11838f | 529 | |
mbed_official | 235:685d5f11838f | 530 | /* Check the parameters */ |
mbed_official | 235:685d5f11838f | 531 | assert_param(IS_CAN_IDTYPE(hcan->pTxMsg->IDE)); |
mbed_official | 235:685d5f11838f | 532 | assert_param(IS_CAN_RTR(hcan->pTxMsg->RTR)); |
mbed_official | 235:685d5f11838f | 533 | assert_param(IS_CAN_DLC(hcan->pTxMsg->DLC)); |
mbed_official | 235:685d5f11838f | 534 | |
mbed_official | 235:685d5f11838f | 535 | /* Process locked */ |
mbed_official | 235:685d5f11838f | 536 | __HAL_LOCK(hcan); |
mbed_official | 235:685d5f11838f | 537 | |
mbed_official | 235:685d5f11838f | 538 | if(hcan->State == HAL_CAN_STATE_BUSY_RX) |
mbed_official | 235:685d5f11838f | 539 | { |
mbed_official | 235:685d5f11838f | 540 | /* Change CAN state */ |
mbed_official | 235:685d5f11838f | 541 | hcan->State = HAL_CAN_STATE_BUSY_TX_RX; |
mbed_official | 235:685d5f11838f | 542 | } |
mbed_official | 235:685d5f11838f | 543 | else |
mbed_official | 235:685d5f11838f | 544 | { |
mbed_official | 235:685d5f11838f | 545 | /* Change CAN state */ |
mbed_official | 235:685d5f11838f | 546 | hcan->State = HAL_CAN_STATE_BUSY_TX; |
mbed_official | 235:685d5f11838f | 547 | } |
mbed_official | 235:685d5f11838f | 548 | |
mbed_official | 235:685d5f11838f | 549 | /* Select one empty transmit mailbox */ |
mbed_official | 235:685d5f11838f | 550 | if ((hcan->Instance->TSR&CAN_TSR_TME0) == CAN_TSR_TME0) |
mbed_official | 235:685d5f11838f | 551 | { |
mbed_official | 235:685d5f11838f | 552 | transmitmailbox = 0; |
mbed_official | 235:685d5f11838f | 553 | } |
mbed_official | 235:685d5f11838f | 554 | else if ((hcan->Instance->TSR&CAN_TSR_TME1) == CAN_TSR_TME1) |
mbed_official | 235:685d5f11838f | 555 | { |
mbed_official | 235:685d5f11838f | 556 | transmitmailbox = 1; |
mbed_official | 235:685d5f11838f | 557 | } |
mbed_official | 235:685d5f11838f | 558 | else if ((hcan->Instance->TSR&CAN_TSR_TME2) == CAN_TSR_TME2) |
mbed_official | 235:685d5f11838f | 559 | { |
mbed_official | 235:685d5f11838f | 560 | transmitmailbox = 2; |
mbed_official | 235:685d5f11838f | 561 | } |
mbed_official | 235:685d5f11838f | 562 | else |
mbed_official | 235:685d5f11838f | 563 | { |
mbed_official | 235:685d5f11838f | 564 | transmitmailbox = CAN_TXSTATUS_NOMAILBOX; |
mbed_official | 235:685d5f11838f | 565 | } |
mbed_official | 235:685d5f11838f | 566 | |
mbed_official | 235:685d5f11838f | 567 | if (transmitmailbox != CAN_TXSTATUS_NOMAILBOX) |
mbed_official | 235:685d5f11838f | 568 | { |
mbed_official | 235:685d5f11838f | 569 | /* Set up the Id */ |
mbed_official | 235:685d5f11838f | 570 | hcan->Instance->sTxMailBox[transmitmailbox].TIR &= CAN_TI0R_TXRQ; |
mbed_official | 235:685d5f11838f | 571 | if (hcan->pTxMsg->IDE == CAN_ID_STD) |
mbed_official | 235:685d5f11838f | 572 | { |
mbed_official | 235:685d5f11838f | 573 | assert_param(IS_CAN_STDID(hcan->pTxMsg->StdId)); |
mbed_official | 235:685d5f11838f | 574 | hcan->Instance->sTxMailBox[transmitmailbox].TIR |= ((hcan->pTxMsg->StdId << 21) | \ |
mbed_official | 235:685d5f11838f | 575 | hcan->pTxMsg->RTR); |
mbed_official | 235:685d5f11838f | 576 | } |
mbed_official | 235:685d5f11838f | 577 | else |
mbed_official | 235:685d5f11838f | 578 | { |
mbed_official | 235:685d5f11838f | 579 | assert_param(IS_CAN_EXTID(hcan->pTxMsg->ExtId)); |
mbed_official | 235:685d5f11838f | 580 | hcan->Instance->sTxMailBox[transmitmailbox].TIR |= ((hcan->pTxMsg->ExtId << 3) | \ |
mbed_official | 235:685d5f11838f | 581 | hcan->pTxMsg->IDE | \ |
mbed_official | 235:685d5f11838f | 582 | hcan->pTxMsg->RTR); |
mbed_official | 235:685d5f11838f | 583 | } |
mbed_official | 235:685d5f11838f | 584 | |
mbed_official | 235:685d5f11838f | 585 | /* Set up the DLC */ |
mbed_official | 235:685d5f11838f | 586 | hcan->pTxMsg->DLC &= (uint8_t)0x0000000F; |
mbed_official | 235:685d5f11838f | 587 | hcan->Instance->sTxMailBox[transmitmailbox].TDTR &= (uint32_t)0xFFFFFFF0; |
mbed_official | 235:685d5f11838f | 588 | hcan->Instance->sTxMailBox[transmitmailbox].TDTR |= hcan->pTxMsg->DLC; |
mbed_official | 235:685d5f11838f | 589 | |
mbed_official | 235:685d5f11838f | 590 | /* Set up the data field */ |
mbed_official | 235:685d5f11838f | 591 | hcan->Instance->sTxMailBox[transmitmailbox].TDLR = (((uint32_t)hcan->pTxMsg->Data[3] << 24) | |
mbed_official | 235:685d5f11838f | 592 | ((uint32_t)hcan->pTxMsg->Data[2] << 16) | |
mbed_official | 235:685d5f11838f | 593 | ((uint32_t)hcan->pTxMsg->Data[1] << 8) | |
mbed_official | 235:685d5f11838f | 594 | ((uint32_t)hcan->pTxMsg->Data[0])); |
mbed_official | 235:685d5f11838f | 595 | hcan->Instance->sTxMailBox[transmitmailbox].TDHR = (((uint32_t)hcan->pTxMsg->Data[7] << 24) | |
mbed_official | 235:685d5f11838f | 596 | ((uint32_t)hcan->pTxMsg->Data[6] << 16) | |
mbed_official | 235:685d5f11838f | 597 | ((uint32_t)hcan->pTxMsg->Data[5] << 8) | |
mbed_official | 235:685d5f11838f | 598 | ((uint32_t)hcan->pTxMsg->Data[4])); |
mbed_official | 235:685d5f11838f | 599 | /* Request transmission */ |
mbed_official | 235:685d5f11838f | 600 | hcan->Instance->sTxMailBox[transmitmailbox].TIR |= CAN_TI0R_TXRQ; |
mbed_official | 235:685d5f11838f | 601 | |
mbed_official | 235:685d5f11838f | 602 | /* Get tick */ |
mbed_official | 235:685d5f11838f | 603 | tickstart = HAL_GetTick(); |
mbed_official | 235:685d5f11838f | 604 | |
mbed_official | 235:685d5f11838f | 605 | /* Check End of transmission flag */ |
mbed_official | 235:685d5f11838f | 606 | while(!(__HAL_CAN_TRANSMIT_STATUS(hcan, transmitmailbox))) |
mbed_official | 235:685d5f11838f | 607 | { |
mbed_official | 235:685d5f11838f | 608 | /* Check for the Timeout */ |
mbed_official | 235:685d5f11838f | 609 | if(Timeout != HAL_MAX_DELAY) |
mbed_official | 235:685d5f11838f | 610 | { |
mbed_official | 235:685d5f11838f | 611 | if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) |
mbed_official | 235:685d5f11838f | 612 | { |
mbed_official | 235:685d5f11838f | 613 | hcan->State = HAL_CAN_STATE_TIMEOUT; |
mbed_official | 235:685d5f11838f | 614 | /* Process unlocked */ |
mbed_official | 235:685d5f11838f | 615 | __HAL_UNLOCK(hcan); |
mbed_official | 235:685d5f11838f | 616 | return HAL_TIMEOUT; |
mbed_official | 235:685d5f11838f | 617 | } |
mbed_official | 235:685d5f11838f | 618 | } |
mbed_official | 235:685d5f11838f | 619 | } |
mbed_official | 235:685d5f11838f | 620 | if(hcan->State == HAL_CAN_STATE_BUSY_TX_RX) |
mbed_official | 235:685d5f11838f | 621 | { |
mbed_official | 235:685d5f11838f | 622 | /* Change CAN state */ |
mbed_official | 235:685d5f11838f | 623 | hcan->State = HAL_CAN_STATE_BUSY_RX; |
mbed_official | 235:685d5f11838f | 624 | |
mbed_official | 235:685d5f11838f | 625 | /* Process unlocked */ |
mbed_official | 235:685d5f11838f | 626 | __HAL_UNLOCK(hcan); |
mbed_official | 235:685d5f11838f | 627 | } |
mbed_official | 235:685d5f11838f | 628 | else |
mbed_official | 235:685d5f11838f | 629 | { |
mbed_official | 235:685d5f11838f | 630 | /* Change CAN state */ |
mbed_official | 235:685d5f11838f | 631 | hcan->State = HAL_CAN_STATE_READY; |
mbed_official | 235:685d5f11838f | 632 | |
mbed_official | 235:685d5f11838f | 633 | /* Process unlocked */ |
mbed_official | 235:685d5f11838f | 634 | __HAL_UNLOCK(hcan); |
mbed_official | 235:685d5f11838f | 635 | } |
mbed_official | 235:685d5f11838f | 636 | |
mbed_official | 235:685d5f11838f | 637 | /* Return function status */ |
mbed_official | 235:685d5f11838f | 638 | return HAL_OK; |
mbed_official | 235:685d5f11838f | 639 | } |
mbed_official | 235:685d5f11838f | 640 | else |
mbed_official | 235:685d5f11838f | 641 | { |
mbed_official | 235:685d5f11838f | 642 | /* Change CAN state */ |
mbed_official | 235:685d5f11838f | 643 | hcan->State = HAL_CAN_STATE_ERROR; |
mbed_official | 235:685d5f11838f | 644 | |
mbed_official | 235:685d5f11838f | 645 | /* Return function status */ |
mbed_official | 235:685d5f11838f | 646 | return HAL_ERROR; |
mbed_official | 235:685d5f11838f | 647 | } |
mbed_official | 235:685d5f11838f | 648 | } |
mbed_official | 235:685d5f11838f | 649 | |
mbed_official | 235:685d5f11838f | 650 | /** |
mbed_official | 235:685d5f11838f | 651 | * @brief Initiates and transmits a CAN frame message. |
mbed_official | 235:685d5f11838f | 652 | * @param hcan: pointer to a CAN_HandleTypeDef structure that contains |
mbed_official | 235:685d5f11838f | 653 | * the configuration information for the specified CAN. |
mbed_official | 235:685d5f11838f | 654 | * @retval HAL status |
mbed_official | 235:685d5f11838f | 655 | */ |
mbed_official | 235:685d5f11838f | 656 | HAL_StatusTypeDef HAL_CAN_Transmit_IT(CAN_HandleTypeDef* hcan) |
mbed_official | 235:685d5f11838f | 657 | { |
mbed_official | 235:685d5f11838f | 658 | uint32_t transmitmailbox = 5; |
mbed_official | 235:685d5f11838f | 659 | uint32_t tmp = 0; |
mbed_official | 235:685d5f11838f | 660 | |
mbed_official | 235:685d5f11838f | 661 | /* Check the parameters */ |
mbed_official | 235:685d5f11838f | 662 | assert_param(IS_CAN_IDTYPE(hcan->pTxMsg->IDE)); |
mbed_official | 235:685d5f11838f | 663 | assert_param(IS_CAN_RTR(hcan->pTxMsg->RTR)); |
mbed_official | 235:685d5f11838f | 664 | assert_param(IS_CAN_DLC(hcan->pTxMsg->DLC)); |
mbed_official | 235:685d5f11838f | 665 | |
mbed_official | 235:685d5f11838f | 666 | tmp = hcan->State; |
mbed_official | 235:685d5f11838f | 667 | if((tmp == HAL_CAN_STATE_READY) || (tmp == HAL_CAN_STATE_BUSY_RX)) |
mbed_official | 235:685d5f11838f | 668 | { |
mbed_official | 235:685d5f11838f | 669 | /* Process Locked */ |
mbed_official | 235:685d5f11838f | 670 | __HAL_LOCK(hcan); |
mbed_official | 235:685d5f11838f | 671 | |
mbed_official | 235:685d5f11838f | 672 | /* Select one empty transmit mailbox */ |
mbed_official | 235:685d5f11838f | 673 | if((hcan->Instance->TSR&CAN_TSR_TME0) == CAN_TSR_TME0) |
mbed_official | 235:685d5f11838f | 674 | { |
mbed_official | 235:685d5f11838f | 675 | transmitmailbox = 0; |
mbed_official | 235:685d5f11838f | 676 | } |
mbed_official | 235:685d5f11838f | 677 | else if((hcan->Instance->TSR&CAN_TSR_TME1) == CAN_TSR_TME1) |
mbed_official | 235:685d5f11838f | 678 | { |
mbed_official | 235:685d5f11838f | 679 | transmitmailbox = 1; |
mbed_official | 235:685d5f11838f | 680 | } |
mbed_official | 235:685d5f11838f | 681 | else if((hcan->Instance->TSR&CAN_TSR_TME2) == CAN_TSR_TME2) |
mbed_official | 235:685d5f11838f | 682 | { |
mbed_official | 235:685d5f11838f | 683 | transmitmailbox = 2; |
mbed_official | 235:685d5f11838f | 684 | } |
mbed_official | 235:685d5f11838f | 685 | else |
mbed_official | 235:685d5f11838f | 686 | { |
mbed_official | 235:685d5f11838f | 687 | transmitmailbox = CAN_TXSTATUS_NOMAILBOX; |
mbed_official | 235:685d5f11838f | 688 | } |
mbed_official | 235:685d5f11838f | 689 | |
mbed_official | 235:685d5f11838f | 690 | if(transmitmailbox != CAN_TXSTATUS_NOMAILBOX) |
mbed_official | 235:685d5f11838f | 691 | { |
mbed_official | 235:685d5f11838f | 692 | /* Set up the Id */ |
mbed_official | 235:685d5f11838f | 693 | hcan->Instance->sTxMailBox[transmitmailbox].TIR &= CAN_TI0R_TXRQ; |
mbed_official | 235:685d5f11838f | 694 | if(hcan->pTxMsg->IDE == CAN_ID_STD) |
mbed_official | 235:685d5f11838f | 695 | { |
mbed_official | 235:685d5f11838f | 696 | assert_param(IS_CAN_STDID(hcan->pTxMsg->StdId)); |
mbed_official | 235:685d5f11838f | 697 | hcan->Instance->sTxMailBox[transmitmailbox].TIR |= ((hcan->pTxMsg->StdId << 21) | \ |
mbed_official | 235:685d5f11838f | 698 | hcan->pTxMsg->RTR); |
mbed_official | 235:685d5f11838f | 699 | } |
mbed_official | 235:685d5f11838f | 700 | else |
mbed_official | 235:685d5f11838f | 701 | { |
mbed_official | 235:685d5f11838f | 702 | assert_param(IS_CAN_EXTID(hcan->pTxMsg->ExtId)); |
mbed_official | 235:685d5f11838f | 703 | hcan->Instance->sTxMailBox[transmitmailbox].TIR |= ((hcan->pTxMsg->ExtId << 3) | \ |
mbed_official | 235:685d5f11838f | 704 | hcan->pTxMsg->IDE | \ |
mbed_official | 235:685d5f11838f | 705 | hcan->pTxMsg->RTR); |
mbed_official | 235:685d5f11838f | 706 | } |
mbed_official | 235:685d5f11838f | 707 | |
mbed_official | 235:685d5f11838f | 708 | /* Set up the DLC */ |
mbed_official | 235:685d5f11838f | 709 | hcan->pTxMsg->DLC &= (uint8_t)0x0000000F; |
mbed_official | 235:685d5f11838f | 710 | hcan->Instance->sTxMailBox[transmitmailbox].TDTR &= (uint32_t)0xFFFFFFF0; |
mbed_official | 235:685d5f11838f | 711 | hcan->Instance->sTxMailBox[transmitmailbox].TDTR |= hcan->pTxMsg->DLC; |
mbed_official | 235:685d5f11838f | 712 | |
mbed_official | 235:685d5f11838f | 713 | /* Set up the data field */ |
mbed_official | 235:685d5f11838f | 714 | hcan->Instance->sTxMailBox[transmitmailbox].TDLR = (((uint32_t)hcan->pTxMsg->Data[3] << 24) | |
mbed_official | 235:685d5f11838f | 715 | ((uint32_t)hcan->pTxMsg->Data[2] << 16) | |
mbed_official | 235:685d5f11838f | 716 | ((uint32_t)hcan->pTxMsg->Data[1] << 8) | |
mbed_official | 235:685d5f11838f | 717 | ((uint32_t)hcan->pTxMsg->Data[0])); |
mbed_official | 235:685d5f11838f | 718 | hcan->Instance->sTxMailBox[transmitmailbox].TDHR = (((uint32_t)hcan->pTxMsg->Data[7] << 24) | |
mbed_official | 235:685d5f11838f | 719 | ((uint32_t)hcan->pTxMsg->Data[6] << 16) | |
mbed_official | 235:685d5f11838f | 720 | ((uint32_t)hcan->pTxMsg->Data[5] << 8) | |
mbed_official | 235:685d5f11838f | 721 | ((uint32_t)hcan->pTxMsg->Data[4])); |
mbed_official | 235:685d5f11838f | 722 | |
mbed_official | 235:685d5f11838f | 723 | if(hcan->State == HAL_CAN_STATE_BUSY_RX) |
mbed_official | 235:685d5f11838f | 724 | { |
mbed_official | 235:685d5f11838f | 725 | /* Change CAN state */ |
mbed_official | 235:685d5f11838f | 726 | hcan->State = HAL_CAN_STATE_BUSY_TX_RX; |
mbed_official | 235:685d5f11838f | 727 | } |
mbed_official | 235:685d5f11838f | 728 | else |
mbed_official | 235:685d5f11838f | 729 | { |
mbed_official | 235:685d5f11838f | 730 | /* Change CAN state */ |
mbed_official | 235:685d5f11838f | 731 | hcan->State = HAL_CAN_STATE_BUSY_TX; |
mbed_official | 235:685d5f11838f | 732 | } |
mbed_official | 235:685d5f11838f | 733 | |
mbed_official | 235:685d5f11838f | 734 | /* Set CAN error code to none */ |
mbed_official | 235:685d5f11838f | 735 | hcan->ErrorCode = HAL_CAN_ERROR_NONE; |
mbed_official | 235:685d5f11838f | 736 | |
mbed_official | 235:685d5f11838f | 737 | /* Process Unlocked */ |
mbed_official | 235:685d5f11838f | 738 | __HAL_UNLOCK(hcan); |
mbed_official | 235:685d5f11838f | 739 | |
mbed_official | 235:685d5f11838f | 740 | /* Enable Error warning Interrupt */ |
mbed_official | 235:685d5f11838f | 741 | __HAL_CAN_ENABLE_IT(hcan, CAN_IT_EWG); |
mbed_official | 235:685d5f11838f | 742 | |
mbed_official | 235:685d5f11838f | 743 | /* Enable Error passive Interrupt */ |
mbed_official | 235:685d5f11838f | 744 | __HAL_CAN_ENABLE_IT(hcan, CAN_IT_EPV); |
mbed_official | 235:685d5f11838f | 745 | |
mbed_official | 235:685d5f11838f | 746 | /* Enable Bus-off Interrupt */ |
mbed_official | 235:685d5f11838f | 747 | __HAL_CAN_ENABLE_IT(hcan, CAN_IT_BOF); |
mbed_official | 235:685d5f11838f | 748 | |
mbed_official | 235:685d5f11838f | 749 | /* Enable Last error code Interrupt */ |
mbed_official | 235:685d5f11838f | 750 | __HAL_CAN_ENABLE_IT(hcan, CAN_IT_LEC); |
mbed_official | 235:685d5f11838f | 751 | |
mbed_official | 235:685d5f11838f | 752 | /* Enable Error Interrupt */ |
mbed_official | 235:685d5f11838f | 753 | __HAL_CAN_ENABLE_IT(hcan, CAN_IT_ERR); |
mbed_official | 235:685d5f11838f | 754 | |
mbed_official | 235:685d5f11838f | 755 | /* Enable Transmit mailbox empty Interrupt */ |
mbed_official | 235:685d5f11838f | 756 | __HAL_CAN_ENABLE_IT(hcan, CAN_IT_TME); |
mbed_official | 235:685d5f11838f | 757 | |
mbed_official | 235:685d5f11838f | 758 | /* Request transmission */ |
mbed_official | 235:685d5f11838f | 759 | hcan->Instance->sTxMailBox[transmitmailbox].TIR |= CAN_TI0R_TXRQ; |
mbed_official | 235:685d5f11838f | 760 | } |
mbed_official | 235:685d5f11838f | 761 | } |
mbed_official | 235:685d5f11838f | 762 | else |
mbed_official | 235:685d5f11838f | 763 | { |
mbed_official | 235:685d5f11838f | 764 | return HAL_BUSY; |
mbed_official | 235:685d5f11838f | 765 | } |
mbed_official | 235:685d5f11838f | 766 | |
mbed_official | 235:685d5f11838f | 767 | return HAL_OK; |
mbed_official | 235:685d5f11838f | 768 | } |
mbed_official | 235:685d5f11838f | 769 | |
mbed_official | 235:685d5f11838f | 770 | /** |
mbed_official | 235:685d5f11838f | 771 | * @brief Receives a correct CAN frame. |
mbed_official | 235:685d5f11838f | 772 | * @param hcan: pointer to a CAN_HandleTypeDef structure that contains |
mbed_official | 235:685d5f11838f | 773 | * the configuration information for the specified CAN. |
mbed_official | 235:685d5f11838f | 774 | * @param FIFONumber: FIFO Number value |
mbed_official | 235:685d5f11838f | 775 | * @param Timeout: Specify Timeout value |
mbed_official | 235:685d5f11838f | 776 | * @retval HAL status |
mbed_official | 235:685d5f11838f | 777 | */ |
mbed_official | 235:685d5f11838f | 778 | HAL_StatusTypeDef HAL_CAN_Receive(CAN_HandleTypeDef* hcan, uint8_t FIFONumber, uint32_t Timeout) |
mbed_official | 235:685d5f11838f | 779 | { |
mbed_official | 235:685d5f11838f | 780 | uint32_t tickstart = 0; |
mbed_official | 235:685d5f11838f | 781 | |
mbed_official | 235:685d5f11838f | 782 | /* Check the parameters */ |
mbed_official | 235:685d5f11838f | 783 | assert_param(IS_CAN_FIFO(FIFONumber)); |
mbed_official | 235:685d5f11838f | 784 | |
mbed_official | 235:685d5f11838f | 785 | /* Process locked */ |
mbed_official | 235:685d5f11838f | 786 | __HAL_LOCK(hcan); |
mbed_official | 235:685d5f11838f | 787 | |
mbed_official | 235:685d5f11838f | 788 | if(hcan->State == HAL_CAN_STATE_BUSY_TX) |
mbed_official | 235:685d5f11838f | 789 | { |
mbed_official | 235:685d5f11838f | 790 | /* Change CAN state */ |
mbed_official | 235:685d5f11838f | 791 | hcan->State = HAL_CAN_STATE_BUSY_TX_RX; |
mbed_official | 235:685d5f11838f | 792 | } |
mbed_official | 235:685d5f11838f | 793 | else |
mbed_official | 235:685d5f11838f | 794 | { |
mbed_official | 235:685d5f11838f | 795 | /* Change CAN state */ |
mbed_official | 235:685d5f11838f | 796 | hcan->State = HAL_CAN_STATE_BUSY_RX; |
mbed_official | 235:685d5f11838f | 797 | } |
mbed_official | 235:685d5f11838f | 798 | |
mbed_official | 235:685d5f11838f | 799 | /* Get tick */ |
mbed_official | 235:685d5f11838f | 800 | tickstart = HAL_GetTick(); |
mbed_official | 235:685d5f11838f | 801 | |
mbed_official | 235:685d5f11838f | 802 | /* Check pending message */ |
mbed_official | 235:685d5f11838f | 803 | while(__HAL_CAN_MSG_PENDING(hcan, FIFONumber) == 0) |
mbed_official | 235:685d5f11838f | 804 | { |
mbed_official | 235:685d5f11838f | 805 | /* Check for the Timeout */ |
mbed_official | 235:685d5f11838f | 806 | if(Timeout != HAL_MAX_DELAY) |
mbed_official | 235:685d5f11838f | 807 | { |
mbed_official | 235:685d5f11838f | 808 | if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) |
mbed_official | 235:685d5f11838f | 809 | { |
mbed_official | 235:685d5f11838f | 810 | hcan->State = HAL_CAN_STATE_TIMEOUT; |
mbed_official | 235:685d5f11838f | 811 | /* Process unlocked */ |
mbed_official | 235:685d5f11838f | 812 | __HAL_UNLOCK(hcan); |
mbed_official | 235:685d5f11838f | 813 | return HAL_TIMEOUT; |
mbed_official | 235:685d5f11838f | 814 | } |
mbed_official | 235:685d5f11838f | 815 | } |
mbed_official | 235:685d5f11838f | 816 | } |
mbed_official | 235:685d5f11838f | 817 | |
mbed_official | 235:685d5f11838f | 818 | /* Get the Id */ |
mbed_official | 235:685d5f11838f | 819 | hcan->pRxMsg->IDE = (uint8_t)0x04 & hcan->Instance->sFIFOMailBox[FIFONumber].RIR; |
mbed_official | 235:685d5f11838f | 820 | if (hcan->pRxMsg->IDE == CAN_ID_STD) |
mbed_official | 235:685d5f11838f | 821 | { |
mbed_official | 235:685d5f11838f | 822 | hcan->pRxMsg->StdId = (uint32_t)0x000007FF & (hcan->Instance->sFIFOMailBox[FIFONumber].RIR >> 21); |
mbed_official | 235:685d5f11838f | 823 | } |
mbed_official | 235:685d5f11838f | 824 | else |
mbed_official | 235:685d5f11838f | 825 | { |
mbed_official | 235:685d5f11838f | 826 | hcan->pRxMsg->ExtId = (uint32_t)0x1FFFFFFF & (hcan->Instance->sFIFOMailBox[FIFONumber].RIR >> 3); |
mbed_official | 235:685d5f11838f | 827 | } |
mbed_official | 235:685d5f11838f | 828 | |
mbed_official | 235:685d5f11838f | 829 | hcan->pRxMsg->RTR = (uint8_t)0x02 & hcan->Instance->sFIFOMailBox[FIFONumber].RIR; |
mbed_official | 235:685d5f11838f | 830 | /* Get the DLC */ |
mbed_official | 235:685d5f11838f | 831 | hcan->pRxMsg->DLC = (uint8_t)0x0F & hcan->Instance->sFIFOMailBox[FIFONumber].RDTR; |
mbed_official | 235:685d5f11838f | 832 | /* Get the FMI */ |
mbed_official | 235:685d5f11838f | 833 | hcan->pRxMsg->FMI = (uint8_t)0xFF & (hcan->Instance->sFIFOMailBox[FIFONumber].RDTR >> 8); |
mbed_official | 235:685d5f11838f | 834 | /* Get the data field */ |
mbed_official | 235:685d5f11838f | 835 | hcan->pRxMsg->Data[0] = (uint8_t)0xFF & hcan->Instance->sFIFOMailBox[FIFONumber].RDLR; |
mbed_official | 235:685d5f11838f | 836 | hcan->pRxMsg->Data[1] = (uint8_t)0xFF & (hcan->Instance->sFIFOMailBox[FIFONumber].RDLR >> 8); |
mbed_official | 235:685d5f11838f | 837 | hcan->pRxMsg->Data[2] = (uint8_t)0xFF & (hcan->Instance->sFIFOMailBox[FIFONumber].RDLR >> 16); |
mbed_official | 235:685d5f11838f | 838 | hcan->pRxMsg->Data[3] = (uint8_t)0xFF & (hcan->Instance->sFIFOMailBox[FIFONumber].RDLR >> 24); |
mbed_official | 235:685d5f11838f | 839 | hcan->pRxMsg->Data[4] = (uint8_t)0xFF & hcan->Instance->sFIFOMailBox[FIFONumber].RDHR; |
mbed_official | 235:685d5f11838f | 840 | hcan->pRxMsg->Data[5] = (uint8_t)0xFF & (hcan->Instance->sFIFOMailBox[FIFONumber].RDHR >> 8); |
mbed_official | 235:685d5f11838f | 841 | hcan->pRxMsg->Data[6] = (uint8_t)0xFF & (hcan->Instance->sFIFOMailBox[FIFONumber].RDHR >> 16); |
mbed_official | 235:685d5f11838f | 842 | hcan->pRxMsg->Data[7] = (uint8_t)0xFF & (hcan->Instance->sFIFOMailBox[FIFONumber].RDHR >> 24); |
mbed_official | 235:685d5f11838f | 843 | |
mbed_official | 235:685d5f11838f | 844 | /* Release the FIFO */ |
mbed_official | 235:685d5f11838f | 845 | if(FIFONumber == CAN_FIFO0) |
mbed_official | 235:685d5f11838f | 846 | { |
mbed_official | 235:685d5f11838f | 847 | /* Release FIFO0 */ |
mbed_official | 235:685d5f11838f | 848 | __HAL_CAN_FIFO_RELEASE(hcan, CAN_FIFO0); |
mbed_official | 235:685d5f11838f | 849 | } |
mbed_official | 235:685d5f11838f | 850 | else /* FIFONumber == CAN_FIFO1 */ |
mbed_official | 235:685d5f11838f | 851 | { |
mbed_official | 235:685d5f11838f | 852 | /* Release FIFO1 */ |
mbed_official | 235:685d5f11838f | 853 | __HAL_CAN_FIFO_RELEASE(hcan, CAN_FIFO1); |
mbed_official | 235:685d5f11838f | 854 | } |
mbed_official | 235:685d5f11838f | 855 | |
mbed_official | 235:685d5f11838f | 856 | if(hcan->State == HAL_CAN_STATE_BUSY_TX_RX) |
mbed_official | 235:685d5f11838f | 857 | { |
mbed_official | 235:685d5f11838f | 858 | /* Change CAN state */ |
mbed_official | 235:685d5f11838f | 859 | hcan->State = HAL_CAN_STATE_BUSY_TX; |
mbed_official | 235:685d5f11838f | 860 | |
mbed_official | 235:685d5f11838f | 861 | /* Process unlocked */ |
mbed_official | 235:685d5f11838f | 862 | __HAL_UNLOCK(hcan); |
mbed_official | 235:685d5f11838f | 863 | } |
mbed_official | 235:685d5f11838f | 864 | else |
mbed_official | 235:685d5f11838f | 865 | { |
mbed_official | 235:685d5f11838f | 866 | /* Change CAN state */ |
mbed_official | 235:685d5f11838f | 867 | hcan->State = HAL_CAN_STATE_READY; |
mbed_official | 235:685d5f11838f | 868 | |
mbed_official | 235:685d5f11838f | 869 | /* Process unlocked */ |
mbed_official | 235:685d5f11838f | 870 | __HAL_UNLOCK(hcan); |
mbed_official | 235:685d5f11838f | 871 | } |
mbed_official | 235:685d5f11838f | 872 | |
mbed_official | 235:685d5f11838f | 873 | /* Return function status */ |
mbed_official | 235:685d5f11838f | 874 | return HAL_OK; |
mbed_official | 235:685d5f11838f | 875 | } |
mbed_official | 235:685d5f11838f | 876 | |
mbed_official | 235:685d5f11838f | 877 | /** |
mbed_official | 235:685d5f11838f | 878 | * @brief Receives a correct CAN frame. |
mbed_official | 235:685d5f11838f | 879 | * @param hcan: Pointer to a CAN_HandleTypeDef structure that contains |
mbed_official | 235:685d5f11838f | 880 | * the configuration information for the specified CAN. |
mbed_official | 235:685d5f11838f | 881 | * @param FIFONumber: Specify the FIFO number |
mbed_official | 235:685d5f11838f | 882 | * @retval HAL status |
mbed_official | 235:685d5f11838f | 883 | */ |
mbed_official | 235:685d5f11838f | 884 | HAL_StatusTypeDef HAL_CAN_Receive_IT(CAN_HandleTypeDef* hcan, uint8_t FIFONumber) |
mbed_official | 235:685d5f11838f | 885 | { |
mbed_official | 235:685d5f11838f | 886 | uint32_t tmp = 0; |
mbed_official | 235:685d5f11838f | 887 | |
mbed_official | 235:685d5f11838f | 888 | /* Check the parameters */ |
mbed_official | 235:685d5f11838f | 889 | assert_param(IS_CAN_FIFO(FIFONumber)); |
mbed_official | 235:685d5f11838f | 890 | |
mbed_official | 235:685d5f11838f | 891 | tmp = hcan->State; |
mbed_official | 235:685d5f11838f | 892 | if((tmp == HAL_CAN_STATE_READY) || (tmp == HAL_CAN_STATE_BUSY_TX)) |
mbed_official | 235:685d5f11838f | 893 | { |
mbed_official | 235:685d5f11838f | 894 | /* Process locked */ |
mbed_official | 235:685d5f11838f | 895 | __HAL_LOCK(hcan); |
mbed_official | 235:685d5f11838f | 896 | |
mbed_official | 235:685d5f11838f | 897 | if(hcan->State == HAL_CAN_STATE_BUSY_TX) |
mbed_official | 235:685d5f11838f | 898 | { |
mbed_official | 235:685d5f11838f | 899 | /* Change CAN state */ |
mbed_official | 235:685d5f11838f | 900 | hcan->State = HAL_CAN_STATE_BUSY_TX_RX; |
mbed_official | 235:685d5f11838f | 901 | } |
mbed_official | 235:685d5f11838f | 902 | else |
mbed_official | 235:685d5f11838f | 903 | { |
mbed_official | 235:685d5f11838f | 904 | /* Change CAN state */ |
mbed_official | 235:685d5f11838f | 905 | hcan->State = HAL_CAN_STATE_BUSY_RX; |
mbed_official | 235:685d5f11838f | 906 | } |
mbed_official | 235:685d5f11838f | 907 | |
mbed_official | 235:685d5f11838f | 908 | /* Set CAN error code to none */ |
mbed_official | 235:685d5f11838f | 909 | hcan->ErrorCode = HAL_CAN_ERROR_NONE; |
mbed_official | 235:685d5f11838f | 910 | |
mbed_official | 235:685d5f11838f | 911 | /* Enable Error warning Interrupt */ |
mbed_official | 235:685d5f11838f | 912 | __HAL_CAN_ENABLE_IT(hcan, CAN_IT_EWG); |
mbed_official | 235:685d5f11838f | 913 | |
mbed_official | 235:685d5f11838f | 914 | /* Enable Error passive Interrupt */ |
mbed_official | 235:685d5f11838f | 915 | __HAL_CAN_ENABLE_IT(hcan, CAN_IT_EPV); |
mbed_official | 235:685d5f11838f | 916 | |
mbed_official | 235:685d5f11838f | 917 | /* Enable Bus-off Interrupt */ |
mbed_official | 235:685d5f11838f | 918 | __HAL_CAN_ENABLE_IT(hcan, CAN_IT_BOF); |
mbed_official | 235:685d5f11838f | 919 | |
mbed_official | 235:685d5f11838f | 920 | /* Enable Last error code Interrupt */ |
mbed_official | 235:685d5f11838f | 921 | __HAL_CAN_ENABLE_IT(hcan, CAN_IT_LEC); |
mbed_official | 235:685d5f11838f | 922 | |
mbed_official | 235:685d5f11838f | 923 | /* Enable Error Interrupt */ |
mbed_official | 235:685d5f11838f | 924 | __HAL_CAN_ENABLE_IT(hcan, CAN_IT_ERR); |
mbed_official | 235:685d5f11838f | 925 | |
mbed_official | 235:685d5f11838f | 926 | /* Process unlocked */ |
mbed_official | 235:685d5f11838f | 927 | __HAL_UNLOCK(hcan); |
mbed_official | 235:685d5f11838f | 928 | |
mbed_official | 235:685d5f11838f | 929 | if(FIFONumber == CAN_FIFO0) |
mbed_official | 235:685d5f11838f | 930 | { |
mbed_official | 235:685d5f11838f | 931 | /* Enable FIFO 0 message pending Interrupt */ |
mbed_official | 235:685d5f11838f | 932 | __HAL_CAN_ENABLE_IT(hcan, CAN_IT_FMP0); |
mbed_official | 235:685d5f11838f | 933 | } |
mbed_official | 235:685d5f11838f | 934 | else |
mbed_official | 235:685d5f11838f | 935 | { |
mbed_official | 235:685d5f11838f | 936 | /* Enable FIFO 1 message pending Interrupt */ |
mbed_official | 235:685d5f11838f | 937 | __HAL_CAN_ENABLE_IT(hcan, CAN_IT_FMP1); |
mbed_official | 235:685d5f11838f | 938 | } |
mbed_official | 235:685d5f11838f | 939 | |
mbed_official | 235:685d5f11838f | 940 | } |
mbed_official | 235:685d5f11838f | 941 | else |
mbed_official | 235:685d5f11838f | 942 | { |
mbed_official | 235:685d5f11838f | 943 | return HAL_BUSY; |
mbed_official | 235:685d5f11838f | 944 | } |
mbed_official | 235:685d5f11838f | 945 | |
mbed_official | 235:685d5f11838f | 946 | /* Return function status */ |
mbed_official | 235:685d5f11838f | 947 | return HAL_OK; |
mbed_official | 235:685d5f11838f | 948 | } |
mbed_official | 235:685d5f11838f | 949 | |
mbed_official | 235:685d5f11838f | 950 | /** |
mbed_official | 235:685d5f11838f | 951 | * @brief Enters the Sleep (low power) mode. |
mbed_official | 235:685d5f11838f | 952 | * @param hcan: pointer to a CAN_HandleTypeDef structure that contains |
mbed_official | 235:685d5f11838f | 953 | * the configuration information for the specified CAN. |
mbed_official | 235:685d5f11838f | 954 | * @retval HAL status. |
mbed_official | 235:685d5f11838f | 955 | */ |
mbed_official | 235:685d5f11838f | 956 | HAL_StatusTypeDef HAL_CAN_Sleep(CAN_HandleTypeDef* hcan) |
mbed_official | 235:685d5f11838f | 957 | { |
mbed_official | 235:685d5f11838f | 958 | uint32_t tickstart = 0; |
mbed_official | 235:685d5f11838f | 959 | |
mbed_official | 235:685d5f11838f | 960 | /* Process locked */ |
mbed_official | 235:685d5f11838f | 961 | __HAL_LOCK(hcan); |
mbed_official | 235:685d5f11838f | 962 | |
mbed_official | 235:685d5f11838f | 963 | /* Change CAN state */ |
mbed_official | 235:685d5f11838f | 964 | hcan->State = HAL_CAN_STATE_BUSY; |
mbed_official | 235:685d5f11838f | 965 | |
mbed_official | 235:685d5f11838f | 966 | /* Request Sleep mode */ |
mbed_official | 235:685d5f11838f | 967 | hcan->Instance->MCR = (((hcan->Instance->MCR) & (uint32_t)(~(uint32_t)CAN_MCR_INRQ)) | CAN_MCR_SLEEP); |
mbed_official | 235:685d5f11838f | 968 | |
mbed_official | 235:685d5f11838f | 969 | /* Sleep mode status */ |
mbed_official | 235:685d5f11838f | 970 | if ((hcan->Instance->MSR & (CAN_MSR_SLAK|CAN_MSR_INAK)) != CAN_MSR_SLAK) |
mbed_official | 235:685d5f11838f | 971 | { |
mbed_official | 235:685d5f11838f | 972 | /* Return function status */ |
mbed_official | 235:685d5f11838f | 973 | return HAL_ERROR; |
mbed_official | 235:685d5f11838f | 974 | } |
mbed_official | 235:685d5f11838f | 975 | |
mbed_official | 235:685d5f11838f | 976 | /* Get tick */ |
mbed_official | 235:685d5f11838f | 977 | tickstart = HAL_GetTick(); |
mbed_official | 235:685d5f11838f | 978 | |
mbed_official | 235:685d5f11838f | 979 | /* Wait the acknowledge */ |
mbed_official | 235:685d5f11838f | 980 | while((hcan->Instance->MSR & (CAN_MSR_SLAK|CAN_MSR_INAK)) != CAN_MSR_SLAK) |
mbed_official | 235:685d5f11838f | 981 | { |
mbed_official | 235:685d5f11838f | 982 | if((HAL_GetTick() - tickstart) > CAN_TIMEOUT_VALUE) |
mbed_official | 235:685d5f11838f | 983 | { |
mbed_official | 235:685d5f11838f | 984 | hcan->State = HAL_CAN_STATE_TIMEOUT; |
mbed_official | 235:685d5f11838f | 985 | /* Process unlocked */ |
mbed_official | 235:685d5f11838f | 986 | __HAL_UNLOCK(hcan); |
mbed_official | 235:685d5f11838f | 987 | return HAL_TIMEOUT; |
mbed_official | 235:685d5f11838f | 988 | } |
mbed_official | 235:685d5f11838f | 989 | } |
mbed_official | 235:685d5f11838f | 990 | |
mbed_official | 235:685d5f11838f | 991 | /* Change CAN state */ |
mbed_official | 235:685d5f11838f | 992 | hcan->State = HAL_CAN_STATE_READY; |
mbed_official | 235:685d5f11838f | 993 | |
mbed_official | 235:685d5f11838f | 994 | /* Process unlocked */ |
mbed_official | 235:685d5f11838f | 995 | __HAL_UNLOCK(hcan); |
mbed_official | 235:685d5f11838f | 996 | |
mbed_official | 235:685d5f11838f | 997 | /* Return function status */ |
mbed_official | 235:685d5f11838f | 998 | return HAL_OK; |
mbed_official | 235:685d5f11838f | 999 | } |
mbed_official | 235:685d5f11838f | 1000 | |
mbed_official | 235:685d5f11838f | 1001 | /** |
mbed_official | 235:685d5f11838f | 1002 | * @brief Wakes up the CAN peripheral from sleep mode, after that the CAN peripheral |
mbed_official | 235:685d5f11838f | 1003 | * is in the normal mode. |
mbed_official | 235:685d5f11838f | 1004 | * @param hcan: pointer to a CAN_HandleTypeDef structure that contains |
mbed_official | 235:685d5f11838f | 1005 | * the configuration information for the specified CAN. |
mbed_official | 235:685d5f11838f | 1006 | * @retval HAL status. |
mbed_official | 235:685d5f11838f | 1007 | */ |
mbed_official | 235:685d5f11838f | 1008 | HAL_StatusTypeDef HAL_CAN_WakeUp(CAN_HandleTypeDef* hcan) |
mbed_official | 235:685d5f11838f | 1009 | { |
mbed_official | 235:685d5f11838f | 1010 | uint32_t tickstart = 0; |
mbed_official | 235:685d5f11838f | 1011 | |
mbed_official | 235:685d5f11838f | 1012 | /* Process locked */ |
mbed_official | 235:685d5f11838f | 1013 | __HAL_LOCK(hcan); |
mbed_official | 235:685d5f11838f | 1014 | |
mbed_official | 235:685d5f11838f | 1015 | /* Change CAN state */ |
mbed_official | 235:685d5f11838f | 1016 | hcan->State = HAL_CAN_STATE_BUSY; |
mbed_official | 235:685d5f11838f | 1017 | |
mbed_official | 235:685d5f11838f | 1018 | /* Wake up request */ |
mbed_official | 235:685d5f11838f | 1019 | hcan->Instance->MCR &= ~(uint32_t)CAN_MCR_SLEEP; |
mbed_official | 235:685d5f11838f | 1020 | |
mbed_official | 235:685d5f11838f | 1021 | /* Get tick */ |
mbed_official | 235:685d5f11838f | 1022 | tickstart = HAL_GetTick(); |
mbed_official | 235:685d5f11838f | 1023 | |
mbed_official | 235:685d5f11838f | 1024 | /* Sleep mode status */ |
mbed_official | 235:685d5f11838f | 1025 | while((hcan->Instance->MSR & CAN_MSR_SLAK) == CAN_MSR_SLAK) |
mbed_official | 235:685d5f11838f | 1026 | { |
mbed_official | 235:685d5f11838f | 1027 | if((HAL_GetTick() - tickstart) > CAN_TIMEOUT_VALUE) |
mbed_official | 235:685d5f11838f | 1028 | { |
mbed_official | 235:685d5f11838f | 1029 | hcan->State= HAL_CAN_STATE_TIMEOUT; |
mbed_official | 235:685d5f11838f | 1030 | /* Process unlocked */ |
mbed_official | 235:685d5f11838f | 1031 | __HAL_UNLOCK(hcan); |
mbed_official | 235:685d5f11838f | 1032 | return HAL_TIMEOUT; |
mbed_official | 235:685d5f11838f | 1033 | } |
mbed_official | 235:685d5f11838f | 1034 | } |
mbed_official | 235:685d5f11838f | 1035 | if((hcan->Instance->MSR & CAN_MSR_SLAK) == CAN_MSR_SLAK) |
mbed_official | 235:685d5f11838f | 1036 | { |
mbed_official | 235:685d5f11838f | 1037 | /* Return function status */ |
mbed_official | 235:685d5f11838f | 1038 | return HAL_ERROR; |
mbed_official | 235:685d5f11838f | 1039 | } |
mbed_official | 235:685d5f11838f | 1040 | |
mbed_official | 235:685d5f11838f | 1041 | /* Change CAN state */ |
mbed_official | 235:685d5f11838f | 1042 | hcan->State = HAL_CAN_STATE_READY; |
mbed_official | 235:685d5f11838f | 1043 | |
mbed_official | 235:685d5f11838f | 1044 | /* Process unlocked */ |
mbed_official | 235:685d5f11838f | 1045 | __HAL_UNLOCK(hcan); |
mbed_official | 235:685d5f11838f | 1046 | |
mbed_official | 235:685d5f11838f | 1047 | /* Return function status */ |
mbed_official | 235:685d5f11838f | 1048 | return HAL_OK; |
mbed_official | 235:685d5f11838f | 1049 | } |
mbed_official | 235:685d5f11838f | 1050 | |
mbed_official | 235:685d5f11838f | 1051 | /** |
mbed_official | 235:685d5f11838f | 1052 | * @brief Handles CAN interrupt request |
mbed_official | 235:685d5f11838f | 1053 | * @param hcan: pointer to a CAN_HandleTypeDef structure that contains |
mbed_official | 235:685d5f11838f | 1054 | * the configuration information for the specified CAN. |
mbed_official | 235:685d5f11838f | 1055 | * @retval None |
mbed_official | 235:685d5f11838f | 1056 | */ |
mbed_official | 235:685d5f11838f | 1057 | void HAL_CAN_IRQHandler(CAN_HandleTypeDef* hcan) |
mbed_official | 235:685d5f11838f | 1058 | { |
mbed_official | 235:685d5f11838f | 1059 | uint32_t tmp1 = 0, tmp2 = 0, tmp3 = 0; |
mbed_official | 235:685d5f11838f | 1060 | |
mbed_official | 235:685d5f11838f | 1061 | /* Check End of transmission flag */ |
mbed_official | 235:685d5f11838f | 1062 | if(__HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_TME)) |
mbed_official | 235:685d5f11838f | 1063 | { |
mbed_official | 235:685d5f11838f | 1064 | tmp1 = __HAL_CAN_TRANSMIT_STATUS(hcan, CAN_TXMAILBOX_0); |
mbed_official | 235:685d5f11838f | 1065 | tmp2 = __HAL_CAN_TRANSMIT_STATUS(hcan, CAN_TXMAILBOX_1); |
mbed_official | 235:685d5f11838f | 1066 | tmp3 = __HAL_CAN_TRANSMIT_STATUS(hcan, CAN_TXMAILBOX_2); |
mbed_official | 235:685d5f11838f | 1067 | if(tmp1 || tmp2 || tmp3) |
mbed_official | 235:685d5f11838f | 1068 | { |
mbed_official | 235:685d5f11838f | 1069 | /* Call transmit function */ |
mbed_official | 235:685d5f11838f | 1070 | CAN_Transmit_IT(hcan); |
mbed_official | 235:685d5f11838f | 1071 | } |
mbed_official | 235:685d5f11838f | 1072 | } |
mbed_official | 235:685d5f11838f | 1073 | |
mbed_official | 235:685d5f11838f | 1074 | tmp1 = __HAL_CAN_MSG_PENDING(hcan, CAN_FIFO0); |
mbed_official | 235:685d5f11838f | 1075 | tmp2 = __HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_FMP0); |
mbed_official | 235:685d5f11838f | 1076 | /* Check End of reception flag for FIFO0 */ |
mbed_official | 235:685d5f11838f | 1077 | if((tmp1 != 0) && tmp2) |
mbed_official | 235:685d5f11838f | 1078 | { |
mbed_official | 235:685d5f11838f | 1079 | /* Call receive function */ |
mbed_official | 235:685d5f11838f | 1080 | CAN_Receive_IT(hcan, CAN_FIFO0); |
mbed_official | 235:685d5f11838f | 1081 | } |
mbed_official | 235:685d5f11838f | 1082 | |
mbed_official | 235:685d5f11838f | 1083 | tmp1 = __HAL_CAN_MSG_PENDING(hcan, CAN_FIFO1); |
mbed_official | 235:685d5f11838f | 1084 | tmp2 = __HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_FMP1); |
mbed_official | 235:685d5f11838f | 1085 | /* Check End of reception flag for FIFO1 */ |
mbed_official | 235:685d5f11838f | 1086 | if((tmp1 != 0) && tmp2) |
mbed_official | 235:685d5f11838f | 1087 | { |
mbed_official | 235:685d5f11838f | 1088 | /* Call receive function */ |
mbed_official | 235:685d5f11838f | 1089 | CAN_Receive_IT(hcan, CAN_FIFO1); |
mbed_official | 235:685d5f11838f | 1090 | } |
mbed_official | 235:685d5f11838f | 1091 | |
mbed_official | 235:685d5f11838f | 1092 | tmp1 = __HAL_CAN_GET_FLAG(hcan, CAN_FLAG_EWG); |
mbed_official | 235:685d5f11838f | 1093 | tmp2 = __HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_EWG); |
mbed_official | 235:685d5f11838f | 1094 | tmp3 = __HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_ERR); |
mbed_official | 235:685d5f11838f | 1095 | /* Check Error Warning Flag */ |
mbed_official | 235:685d5f11838f | 1096 | if(tmp1 && tmp2 && tmp3) |
mbed_official | 235:685d5f11838f | 1097 | { |
mbed_official | 235:685d5f11838f | 1098 | /* Set CAN error code to EWG error */ |
mbed_official | 235:685d5f11838f | 1099 | hcan->ErrorCode |= HAL_CAN_ERROR_EWG; |
mbed_official | 235:685d5f11838f | 1100 | /* Clear Error Warning Flag */ |
mbed_official | 235:685d5f11838f | 1101 | __HAL_CAN_CLEAR_FLAG(hcan, CAN_FLAG_EWG); |
mbed_official | 235:685d5f11838f | 1102 | } |
mbed_official | 235:685d5f11838f | 1103 | |
mbed_official | 235:685d5f11838f | 1104 | tmp1 = __HAL_CAN_GET_FLAG(hcan, CAN_FLAG_EPV); |
mbed_official | 235:685d5f11838f | 1105 | tmp2 = __HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_EPV); |
mbed_official | 235:685d5f11838f | 1106 | tmp3 = __HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_ERR); |
mbed_official | 235:685d5f11838f | 1107 | /* Check Error Passive Flag */ |
mbed_official | 235:685d5f11838f | 1108 | if(tmp1 && tmp2 && tmp3) |
mbed_official | 235:685d5f11838f | 1109 | { |
mbed_official | 235:685d5f11838f | 1110 | /* Set CAN error code to EPV error */ |
mbed_official | 235:685d5f11838f | 1111 | hcan->ErrorCode |= HAL_CAN_ERROR_EPV; |
mbed_official | 235:685d5f11838f | 1112 | /* Clear Error Passive Flag */ |
mbed_official | 235:685d5f11838f | 1113 | __HAL_CAN_CLEAR_FLAG(hcan, CAN_FLAG_EPV); |
mbed_official | 235:685d5f11838f | 1114 | } |
mbed_official | 235:685d5f11838f | 1115 | |
mbed_official | 235:685d5f11838f | 1116 | tmp1 = __HAL_CAN_GET_FLAG(hcan, CAN_FLAG_BOF); |
mbed_official | 235:685d5f11838f | 1117 | tmp2 = __HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_BOF); |
mbed_official | 235:685d5f11838f | 1118 | tmp3 = __HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_ERR); |
mbed_official | 235:685d5f11838f | 1119 | /* Check Bus-Off Flag */ |
mbed_official | 235:685d5f11838f | 1120 | if(tmp1 && tmp2 && tmp3) |
mbed_official | 235:685d5f11838f | 1121 | { |
mbed_official | 235:685d5f11838f | 1122 | /* Set CAN error code to BOF error */ |
mbed_official | 235:685d5f11838f | 1123 | hcan->ErrorCode |= HAL_CAN_ERROR_BOF; |
mbed_official | 235:685d5f11838f | 1124 | /* Clear Bus-Off Flag */ |
mbed_official | 235:685d5f11838f | 1125 | __HAL_CAN_CLEAR_FLAG(hcan, CAN_FLAG_BOF); |
mbed_official | 235:685d5f11838f | 1126 | } |
mbed_official | 235:685d5f11838f | 1127 | |
mbed_official | 235:685d5f11838f | 1128 | tmp1 = HAL_IS_BIT_CLR(hcan->Instance->ESR, CAN_ESR_LEC); |
mbed_official | 235:685d5f11838f | 1129 | tmp2 = __HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_LEC); |
mbed_official | 235:685d5f11838f | 1130 | tmp3 = __HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_ERR); |
mbed_official | 235:685d5f11838f | 1131 | /* Check Last error code Flag */ |
mbed_official | 235:685d5f11838f | 1132 | if((!tmp1) && tmp2 && tmp3) |
mbed_official | 235:685d5f11838f | 1133 | { |
mbed_official | 235:685d5f11838f | 1134 | tmp1 = (hcan->Instance->ESR) & CAN_ESR_LEC; |
mbed_official | 235:685d5f11838f | 1135 | switch(tmp1) |
mbed_official | 235:685d5f11838f | 1136 | { |
mbed_official | 235:685d5f11838f | 1137 | case(CAN_ESR_LEC_0): |
mbed_official | 235:685d5f11838f | 1138 | /* Set CAN error code to STF error */ |
mbed_official | 235:685d5f11838f | 1139 | hcan->ErrorCode |= HAL_CAN_ERROR_STF; |
mbed_official | 235:685d5f11838f | 1140 | break; |
mbed_official | 235:685d5f11838f | 1141 | case(CAN_ESR_LEC_1): |
mbed_official | 235:685d5f11838f | 1142 | /* Set CAN error code to FOR error */ |
mbed_official | 235:685d5f11838f | 1143 | hcan->ErrorCode |= HAL_CAN_ERROR_FOR; |
mbed_official | 235:685d5f11838f | 1144 | break; |
mbed_official | 235:685d5f11838f | 1145 | case(CAN_ESR_LEC_1 | CAN_ESR_LEC_0): |
mbed_official | 235:685d5f11838f | 1146 | /* Set CAN error code to ACK error */ |
mbed_official | 235:685d5f11838f | 1147 | hcan->ErrorCode |= HAL_CAN_ERROR_ACK; |
mbed_official | 235:685d5f11838f | 1148 | break; |
mbed_official | 235:685d5f11838f | 1149 | case(CAN_ESR_LEC_2): |
mbed_official | 235:685d5f11838f | 1150 | /* Set CAN error code to BR error */ |
mbed_official | 235:685d5f11838f | 1151 | hcan->ErrorCode |= HAL_CAN_ERROR_BR; |
mbed_official | 235:685d5f11838f | 1152 | break; |
mbed_official | 235:685d5f11838f | 1153 | case(CAN_ESR_LEC_2 | CAN_ESR_LEC_0): |
mbed_official | 235:685d5f11838f | 1154 | /* Set CAN error code to BD error */ |
mbed_official | 235:685d5f11838f | 1155 | hcan->ErrorCode |= HAL_CAN_ERROR_BD; |
mbed_official | 235:685d5f11838f | 1156 | break; |
mbed_official | 235:685d5f11838f | 1157 | case(CAN_ESR_LEC_2 | CAN_ESR_LEC_1): |
mbed_official | 235:685d5f11838f | 1158 | /* Set CAN error code to CRC error */ |
mbed_official | 235:685d5f11838f | 1159 | hcan->ErrorCode |= HAL_CAN_ERROR_CRC; |
mbed_official | 235:685d5f11838f | 1160 | break; |
mbed_official | 235:685d5f11838f | 1161 | default: |
mbed_official | 235:685d5f11838f | 1162 | break; |
mbed_official | 235:685d5f11838f | 1163 | } |
mbed_official | 235:685d5f11838f | 1164 | |
mbed_official | 235:685d5f11838f | 1165 | /* Clear Last error code Flag */ |
mbed_official | 235:685d5f11838f | 1166 | hcan->Instance->ESR &= ~(CAN_ESR_LEC); |
mbed_official | 235:685d5f11838f | 1167 | } |
mbed_official | 235:685d5f11838f | 1168 | |
mbed_official | 235:685d5f11838f | 1169 | /* Call the Error call Back in case of Errors */ |
mbed_official | 235:685d5f11838f | 1170 | if(hcan->ErrorCode != HAL_CAN_ERROR_NONE) |
mbed_official | 235:685d5f11838f | 1171 | { |
mbed_official | 235:685d5f11838f | 1172 | /* Set the CAN state ready to be able to start again the process */ |
mbed_official | 235:685d5f11838f | 1173 | hcan->State = HAL_CAN_STATE_READY; |
mbed_official | 235:685d5f11838f | 1174 | /* Call Error callback function */ |
mbed_official | 235:685d5f11838f | 1175 | HAL_CAN_ErrorCallback(hcan); |
mbed_official | 235:685d5f11838f | 1176 | } |
mbed_official | 235:685d5f11838f | 1177 | } |
mbed_official | 235:685d5f11838f | 1178 | |
mbed_official | 235:685d5f11838f | 1179 | /** |
mbed_official | 235:685d5f11838f | 1180 | * @brief Transmission complete callback in non blocking mode |
mbed_official | 235:685d5f11838f | 1181 | * @param hcan: pointer to a CAN_HandleTypeDef structure that contains |
mbed_official | 235:685d5f11838f | 1182 | * the configuration information for the specified CAN. |
mbed_official | 235:685d5f11838f | 1183 | * @retval None |
mbed_official | 235:685d5f11838f | 1184 | */ |
mbed_official | 235:685d5f11838f | 1185 | __weak void HAL_CAN_TxCpltCallback(CAN_HandleTypeDef* hcan) |
mbed_official | 235:685d5f11838f | 1186 | { |
mbed_official | 235:685d5f11838f | 1187 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 235:685d5f11838f | 1188 | the HAL_CAN_TxCpltCallback could be implemented in the user file |
mbed_official | 235:685d5f11838f | 1189 | */ |
mbed_official | 235:685d5f11838f | 1190 | } |
mbed_official | 235:685d5f11838f | 1191 | |
mbed_official | 235:685d5f11838f | 1192 | /** |
mbed_official | 235:685d5f11838f | 1193 | * @brief Transmission complete callback in non blocking mode |
mbed_official | 235:685d5f11838f | 1194 | * @param hcan: pointer to a CAN_HandleTypeDef structure that contains |
mbed_official | 235:685d5f11838f | 1195 | * the configuration information for the specified CAN. |
mbed_official | 235:685d5f11838f | 1196 | * @retval None |
mbed_official | 235:685d5f11838f | 1197 | */ |
mbed_official | 235:685d5f11838f | 1198 | __weak void HAL_CAN_RxCpltCallback(CAN_HandleTypeDef* hcan) |
mbed_official | 235:685d5f11838f | 1199 | { |
mbed_official | 235:685d5f11838f | 1200 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 235:685d5f11838f | 1201 | the HAL_CAN_RxCpltCallback could be implemented in the user file |
mbed_official | 235:685d5f11838f | 1202 | */ |
mbed_official | 235:685d5f11838f | 1203 | } |
mbed_official | 235:685d5f11838f | 1204 | |
mbed_official | 235:685d5f11838f | 1205 | /** |
mbed_official | 235:685d5f11838f | 1206 | * @brief Error CAN callback. |
mbed_official | 235:685d5f11838f | 1207 | * @param hcan: pointer to a CAN_HandleTypeDef structure that contains |
mbed_official | 235:685d5f11838f | 1208 | * the configuration information for the specified CAN. |
mbed_official | 235:685d5f11838f | 1209 | * @retval None |
mbed_official | 235:685d5f11838f | 1210 | */ |
mbed_official | 235:685d5f11838f | 1211 | __weak void HAL_CAN_ErrorCallback(CAN_HandleTypeDef *hcan) |
mbed_official | 235:685d5f11838f | 1212 | { |
mbed_official | 235:685d5f11838f | 1213 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 235:685d5f11838f | 1214 | the HAL_CAN_ErrorCallback could be implemented in the user file |
mbed_official | 235:685d5f11838f | 1215 | */ |
mbed_official | 235:685d5f11838f | 1216 | } |
mbed_official | 235:685d5f11838f | 1217 | |
mbed_official | 235:685d5f11838f | 1218 | /** |
mbed_official | 235:685d5f11838f | 1219 | * @} |
mbed_official | 235:685d5f11838f | 1220 | */ |
mbed_official | 235:685d5f11838f | 1221 | |
mbed_official | 235:685d5f11838f | 1222 | /** @defgroup CAN_Group3 Peripheral State and Error functions |
mbed_official | 235:685d5f11838f | 1223 | * @brief CAN Peripheral State functions |
mbed_official | 235:685d5f11838f | 1224 | * |
mbed_official | 235:685d5f11838f | 1225 | @verbatim |
mbed_official | 235:685d5f11838f | 1226 | ============================================================================== |
mbed_official | 235:685d5f11838f | 1227 | ##### Peripheral State and Error functions ##### |
mbed_official | 235:685d5f11838f | 1228 | ============================================================================== |
mbed_official | 235:685d5f11838f | 1229 | [..] |
mbed_official | 235:685d5f11838f | 1230 | This subsection provides functions allowing to : |
mbed_official | 235:685d5f11838f | 1231 | (+) Check the CAN state. |
mbed_official | 235:685d5f11838f | 1232 | (+) Check CAN Errors detected during interrupt process |
mbed_official | 235:685d5f11838f | 1233 | |
mbed_official | 235:685d5f11838f | 1234 | @endverbatim |
mbed_official | 235:685d5f11838f | 1235 | * @{ |
mbed_official | 235:685d5f11838f | 1236 | */ |
mbed_official | 235:685d5f11838f | 1237 | |
mbed_official | 235:685d5f11838f | 1238 | /** |
mbed_official | 235:685d5f11838f | 1239 | * @brief return the CAN state |
mbed_official | 235:685d5f11838f | 1240 | * @param hcan: pointer to a CAN_HandleTypeDef structure that contains |
mbed_official | 235:685d5f11838f | 1241 | * the configuration information for the specified CAN. |
mbed_official | 235:685d5f11838f | 1242 | * @retval HAL state |
mbed_official | 235:685d5f11838f | 1243 | */ |
mbed_official | 235:685d5f11838f | 1244 | HAL_CAN_StateTypeDef HAL_CAN_GetState(CAN_HandleTypeDef* hcan) |
mbed_official | 235:685d5f11838f | 1245 | { |
mbed_official | 235:685d5f11838f | 1246 | /* Return CAN state */ |
mbed_official | 235:685d5f11838f | 1247 | return hcan->State; |
mbed_official | 235:685d5f11838f | 1248 | } |
mbed_official | 235:685d5f11838f | 1249 | |
mbed_official | 235:685d5f11838f | 1250 | /** |
mbed_official | 235:685d5f11838f | 1251 | * @brief Return the CAN error code |
mbed_official | 235:685d5f11838f | 1252 | * @param hcan: pointer to a CAN_HandleTypeDef structure that contains |
mbed_official | 235:685d5f11838f | 1253 | * the configuration information for the specified CAN. |
mbed_official | 235:685d5f11838f | 1254 | * @retval CAN Error Code |
mbed_official | 235:685d5f11838f | 1255 | */ |
mbed_official | 235:685d5f11838f | 1256 | uint32_t HAL_CAN_GetError(CAN_HandleTypeDef *hcan) |
mbed_official | 235:685d5f11838f | 1257 | { |
mbed_official | 235:685d5f11838f | 1258 | return hcan->ErrorCode; |
mbed_official | 235:685d5f11838f | 1259 | } |
mbed_official | 235:685d5f11838f | 1260 | |
mbed_official | 235:685d5f11838f | 1261 | /** |
mbed_official | 235:685d5f11838f | 1262 | * @} |
mbed_official | 235:685d5f11838f | 1263 | */ |
mbed_official | 235:685d5f11838f | 1264 | /** |
mbed_official | 235:685d5f11838f | 1265 | * @brief Initiates and transmits a CAN frame message. |
mbed_official | 235:685d5f11838f | 1266 | * @param hcan: pointer to a CAN_HandleTypeDef structure that contains |
mbed_official | 235:685d5f11838f | 1267 | * the configuration information for the specified CAN. |
mbed_official | 235:685d5f11838f | 1268 | * @retval HAL status |
mbed_official | 235:685d5f11838f | 1269 | */ |
mbed_official | 235:685d5f11838f | 1270 | static HAL_StatusTypeDef CAN_Transmit_IT(CAN_HandleTypeDef* hcan) |
mbed_official | 235:685d5f11838f | 1271 | { |
mbed_official | 235:685d5f11838f | 1272 | /* Disable Transmit mailbox empty Interrupt */ |
mbed_official | 235:685d5f11838f | 1273 | __HAL_CAN_DISABLE_IT(hcan, CAN_IT_TME); |
mbed_official | 235:685d5f11838f | 1274 | |
mbed_official | 235:685d5f11838f | 1275 | if(hcan->State == HAL_CAN_STATE_BUSY_TX) |
mbed_official | 235:685d5f11838f | 1276 | { |
mbed_official | 235:685d5f11838f | 1277 | /* Disable Error warning Interrupt */ |
mbed_official | 235:685d5f11838f | 1278 | __HAL_CAN_DISABLE_IT(hcan, CAN_IT_EWG); |
mbed_official | 235:685d5f11838f | 1279 | |
mbed_official | 235:685d5f11838f | 1280 | /* Disable Error passive Interrupt */ |
mbed_official | 235:685d5f11838f | 1281 | __HAL_CAN_DISABLE_IT(hcan, CAN_IT_EPV); |
mbed_official | 235:685d5f11838f | 1282 | |
mbed_official | 235:685d5f11838f | 1283 | /* Disable Bus-off Interrupt */ |
mbed_official | 235:685d5f11838f | 1284 | __HAL_CAN_DISABLE_IT(hcan, CAN_IT_BOF); |
mbed_official | 235:685d5f11838f | 1285 | |
mbed_official | 235:685d5f11838f | 1286 | /* Disable Last error code Interrupt */ |
mbed_official | 235:685d5f11838f | 1287 | __HAL_CAN_DISABLE_IT(hcan, CAN_IT_LEC); |
mbed_official | 235:685d5f11838f | 1288 | |
mbed_official | 235:685d5f11838f | 1289 | /* Disable Error Interrupt */ |
mbed_official | 235:685d5f11838f | 1290 | __HAL_CAN_DISABLE_IT(hcan, CAN_IT_ERR); |
mbed_official | 235:685d5f11838f | 1291 | } |
mbed_official | 235:685d5f11838f | 1292 | |
mbed_official | 235:685d5f11838f | 1293 | if(hcan->State == HAL_CAN_STATE_BUSY_TX_RX) |
mbed_official | 235:685d5f11838f | 1294 | { |
mbed_official | 235:685d5f11838f | 1295 | /* Change CAN state */ |
mbed_official | 235:685d5f11838f | 1296 | hcan->State = HAL_CAN_STATE_BUSY_RX; |
mbed_official | 235:685d5f11838f | 1297 | } |
mbed_official | 235:685d5f11838f | 1298 | else |
mbed_official | 235:685d5f11838f | 1299 | { |
mbed_official | 235:685d5f11838f | 1300 | /* Change CAN state */ |
mbed_official | 235:685d5f11838f | 1301 | hcan->State = HAL_CAN_STATE_READY; |
mbed_official | 235:685d5f11838f | 1302 | } |
mbed_official | 235:685d5f11838f | 1303 | |
mbed_official | 235:685d5f11838f | 1304 | /* Transmission complete callback */ |
mbed_official | 235:685d5f11838f | 1305 | HAL_CAN_TxCpltCallback(hcan); |
mbed_official | 235:685d5f11838f | 1306 | |
mbed_official | 235:685d5f11838f | 1307 | return HAL_OK; |
mbed_official | 235:685d5f11838f | 1308 | } |
mbed_official | 235:685d5f11838f | 1309 | |
mbed_official | 235:685d5f11838f | 1310 | /** |
mbed_official | 235:685d5f11838f | 1311 | * @brief Receives a correct CAN frame. |
mbed_official | 235:685d5f11838f | 1312 | * @param hcan: Pointer to a CAN_HandleTypeDef structure that contains |
mbed_official | 235:685d5f11838f | 1313 | * the configuration information for the specified CAN. |
mbed_official | 235:685d5f11838f | 1314 | * @param FIFONumber: Specify the FIFO number |
mbed_official | 235:685d5f11838f | 1315 | * @retval HAL status |
mbed_official | 235:685d5f11838f | 1316 | * @retval None |
mbed_official | 235:685d5f11838f | 1317 | */ |
mbed_official | 235:685d5f11838f | 1318 | static HAL_StatusTypeDef CAN_Receive_IT(CAN_HandleTypeDef* hcan, uint8_t FIFONumber) |
mbed_official | 235:685d5f11838f | 1319 | { |
mbed_official | 235:685d5f11838f | 1320 | /* Get the Id */ |
mbed_official | 235:685d5f11838f | 1321 | hcan->pRxMsg->IDE = (uint8_t)0x04 & hcan->Instance->sFIFOMailBox[FIFONumber].RIR; |
mbed_official | 235:685d5f11838f | 1322 | if (hcan->pRxMsg->IDE == CAN_ID_STD) |
mbed_official | 235:685d5f11838f | 1323 | { |
mbed_official | 235:685d5f11838f | 1324 | hcan->pRxMsg->StdId = (uint32_t)0x000007FF & (hcan->Instance->sFIFOMailBox[FIFONumber].RIR >> 21); |
mbed_official | 235:685d5f11838f | 1325 | } |
mbed_official | 235:685d5f11838f | 1326 | else |
mbed_official | 235:685d5f11838f | 1327 | { |
mbed_official | 235:685d5f11838f | 1328 | hcan->pRxMsg->ExtId = (uint32_t)0x1FFFFFFF & (hcan->Instance->sFIFOMailBox[FIFONumber].RIR >> 3); |
mbed_official | 235:685d5f11838f | 1329 | } |
mbed_official | 235:685d5f11838f | 1330 | |
mbed_official | 235:685d5f11838f | 1331 | hcan->pRxMsg->RTR = (uint8_t)0x02 & hcan->Instance->sFIFOMailBox[FIFONumber].RIR; |
mbed_official | 235:685d5f11838f | 1332 | /* Get the DLC */ |
mbed_official | 235:685d5f11838f | 1333 | hcan->pRxMsg->DLC = (uint8_t)0x0F & hcan->Instance->sFIFOMailBox[FIFONumber].RDTR; |
mbed_official | 235:685d5f11838f | 1334 | /* Get the FMI */ |
mbed_official | 235:685d5f11838f | 1335 | hcan->pRxMsg->FMI = (uint8_t)0xFF & (hcan->Instance->sFIFOMailBox[FIFONumber].RDTR >> 8); |
mbed_official | 235:685d5f11838f | 1336 | /* Get the data field */ |
mbed_official | 235:685d5f11838f | 1337 | hcan->pRxMsg->Data[0] = (uint8_t)0xFF & hcan->Instance->sFIFOMailBox[FIFONumber].RDLR; |
mbed_official | 235:685d5f11838f | 1338 | hcan->pRxMsg->Data[1] = (uint8_t)0xFF & (hcan->Instance->sFIFOMailBox[FIFONumber].RDLR >> 8); |
mbed_official | 235:685d5f11838f | 1339 | hcan->pRxMsg->Data[2] = (uint8_t)0xFF & (hcan->Instance->sFIFOMailBox[FIFONumber].RDLR >> 16); |
mbed_official | 235:685d5f11838f | 1340 | hcan->pRxMsg->Data[3] = (uint8_t)0xFF & (hcan->Instance->sFIFOMailBox[FIFONumber].RDLR >> 24); |
mbed_official | 235:685d5f11838f | 1341 | hcan->pRxMsg->Data[4] = (uint8_t)0xFF & hcan->Instance->sFIFOMailBox[FIFONumber].RDHR; |
mbed_official | 235:685d5f11838f | 1342 | hcan->pRxMsg->Data[5] = (uint8_t)0xFF & (hcan->Instance->sFIFOMailBox[FIFONumber].RDHR >> 8); |
mbed_official | 235:685d5f11838f | 1343 | hcan->pRxMsg->Data[6] = (uint8_t)0xFF & (hcan->Instance->sFIFOMailBox[FIFONumber].RDHR >> 16); |
mbed_official | 235:685d5f11838f | 1344 | hcan->pRxMsg->Data[7] = (uint8_t)0xFF & (hcan->Instance->sFIFOMailBox[FIFONumber].RDHR >> 24); |
mbed_official | 235:685d5f11838f | 1345 | /* Release the FIFO */ |
mbed_official | 235:685d5f11838f | 1346 | /* Release FIFO0 */ |
mbed_official | 235:685d5f11838f | 1347 | if (FIFONumber == CAN_FIFO0) |
mbed_official | 235:685d5f11838f | 1348 | { |
mbed_official | 235:685d5f11838f | 1349 | __HAL_CAN_FIFO_RELEASE(hcan, CAN_FIFO0); |
mbed_official | 235:685d5f11838f | 1350 | |
mbed_official | 235:685d5f11838f | 1351 | /* Disable FIFO 0 message pending Interrupt */ |
mbed_official | 235:685d5f11838f | 1352 | __HAL_CAN_DISABLE_IT(hcan, CAN_IT_FMP0); |
mbed_official | 235:685d5f11838f | 1353 | } |
mbed_official | 235:685d5f11838f | 1354 | /* Release FIFO1 */ |
mbed_official | 235:685d5f11838f | 1355 | else /* FIFONumber == CAN_FIFO1 */ |
mbed_official | 235:685d5f11838f | 1356 | { |
mbed_official | 235:685d5f11838f | 1357 | __HAL_CAN_FIFO_RELEASE(hcan, CAN_FIFO1); |
mbed_official | 235:685d5f11838f | 1358 | |
mbed_official | 235:685d5f11838f | 1359 | /* Disable FIFO 1 message pending Interrupt */ |
mbed_official | 235:685d5f11838f | 1360 | __HAL_CAN_DISABLE_IT(hcan, CAN_IT_FMP1); |
mbed_official | 235:685d5f11838f | 1361 | } |
mbed_official | 235:685d5f11838f | 1362 | |
mbed_official | 235:685d5f11838f | 1363 | if(hcan->State == HAL_CAN_STATE_BUSY_RX) |
mbed_official | 235:685d5f11838f | 1364 | { |
mbed_official | 235:685d5f11838f | 1365 | /* Disable Error warning Interrupt */ |
mbed_official | 235:685d5f11838f | 1366 | __HAL_CAN_DISABLE_IT(hcan, CAN_IT_EWG); |
mbed_official | 235:685d5f11838f | 1367 | |
mbed_official | 235:685d5f11838f | 1368 | /* Disable Error passive Interrupt */ |
mbed_official | 235:685d5f11838f | 1369 | __HAL_CAN_DISABLE_IT(hcan, CAN_IT_EPV); |
mbed_official | 235:685d5f11838f | 1370 | |
mbed_official | 235:685d5f11838f | 1371 | /* Disable Bus-off Interrupt */ |
mbed_official | 235:685d5f11838f | 1372 | __HAL_CAN_DISABLE_IT(hcan, CAN_IT_BOF); |
mbed_official | 235:685d5f11838f | 1373 | |
mbed_official | 235:685d5f11838f | 1374 | /* Disable Last error code Interrupt */ |
mbed_official | 235:685d5f11838f | 1375 | __HAL_CAN_DISABLE_IT(hcan, CAN_IT_LEC); |
mbed_official | 235:685d5f11838f | 1376 | |
mbed_official | 235:685d5f11838f | 1377 | /* Disable Error Interrupt */ |
mbed_official | 235:685d5f11838f | 1378 | __HAL_CAN_DISABLE_IT(hcan, CAN_IT_ERR); |
mbed_official | 235:685d5f11838f | 1379 | } |
mbed_official | 235:685d5f11838f | 1380 | |
mbed_official | 235:685d5f11838f | 1381 | if(hcan->State == HAL_CAN_STATE_BUSY_TX_RX) |
mbed_official | 235:685d5f11838f | 1382 | { |
mbed_official | 235:685d5f11838f | 1383 | /* Disable CAN state */ |
mbed_official | 235:685d5f11838f | 1384 | hcan->State = HAL_CAN_STATE_BUSY_TX; |
mbed_official | 235:685d5f11838f | 1385 | } |
mbed_official | 235:685d5f11838f | 1386 | else |
mbed_official | 235:685d5f11838f | 1387 | { |
mbed_official | 235:685d5f11838f | 1388 | /* Change CAN state */ |
mbed_official | 235:685d5f11838f | 1389 | hcan->State = HAL_CAN_STATE_READY; |
mbed_official | 235:685d5f11838f | 1390 | } |
mbed_official | 235:685d5f11838f | 1391 | |
mbed_official | 235:685d5f11838f | 1392 | /* Receive complete callback */ |
mbed_official | 235:685d5f11838f | 1393 | HAL_CAN_RxCpltCallback(hcan); |
mbed_official | 235:685d5f11838f | 1394 | |
mbed_official | 235:685d5f11838f | 1395 | /* Return function status */ |
mbed_official | 235:685d5f11838f | 1396 | return HAL_OK; |
mbed_official | 235:685d5f11838f | 1397 | } |
mbed_official | 235:685d5f11838f | 1398 | |
mbed_official | 235:685d5f11838f | 1399 | /** |
mbed_official | 235:685d5f11838f | 1400 | * @} |
mbed_official | 235:685d5f11838f | 1401 | */ |
mbed_official | 235:685d5f11838f | 1402 | #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */ |
mbed_official | 235:685d5f11838f | 1403 | |
mbed_official | 235:685d5f11838f | 1404 | #endif /* HAL_CAN_MODULE_ENABLED */ |
mbed_official | 235:685d5f11838f | 1405 | /** |
mbed_official | 235:685d5f11838f | 1406 | * @} |
mbed_official | 235:685d5f11838f | 1407 | */ |
mbed_official | 235:685d5f11838f | 1408 | |
mbed_official | 235:685d5f11838f | 1409 | /** |
mbed_official | 235:685d5f11838f | 1410 | * @} |
mbed_official | 235:685d5f11838f | 1411 | */ |
mbed_official | 235:685d5f11838f | 1412 | |
mbed_official | 235:685d5f11838f | 1413 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |