Initial commit
mbed-dev-master/targets/TARGET_STM/TARGET_STM32F4/device/stm32f4xx_hal_can.c@0:bb348c97df44, 2020-09-16 (annotated)
- Committer:
- lypinator
- Date:
- Wed Sep 16 01:11:49 2020 +0000
- Revision:
- 0:bb348c97df44
Added PWM
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lypinator | 0:bb348c97df44 | 1 | /** |
lypinator | 0:bb348c97df44 | 2 | ****************************************************************************** |
lypinator | 0:bb348c97df44 | 3 | * @file stm32f4xx_hal_can.c |
lypinator | 0:bb348c97df44 | 4 | * @author MCD Application Team |
lypinator | 0:bb348c97df44 | 5 | * @brief CAN HAL module driver. |
lypinator | 0:bb348c97df44 | 6 | * This file provides firmware functions to manage the following |
lypinator | 0:bb348c97df44 | 7 | * functionalities of the Controller Area Network (CAN) peripheral: |
lypinator | 0:bb348c97df44 | 8 | * + Initialization and de-initialization functions |
lypinator | 0:bb348c97df44 | 9 | * + Configuration functions |
lypinator | 0:bb348c97df44 | 10 | * + Control functions |
lypinator | 0:bb348c97df44 | 11 | * + Interrupts management |
lypinator | 0:bb348c97df44 | 12 | * + Callbacks functions |
lypinator | 0:bb348c97df44 | 13 | * + Peripheral State and Error functions |
lypinator | 0:bb348c97df44 | 14 | * |
lypinator | 0:bb348c97df44 | 15 | @verbatim |
lypinator | 0:bb348c97df44 | 16 | ============================================================================== |
lypinator | 0:bb348c97df44 | 17 | ##### How to use this driver ##### |
lypinator | 0:bb348c97df44 | 18 | ============================================================================== |
lypinator | 0:bb348c97df44 | 19 | [..] |
lypinator | 0:bb348c97df44 | 20 | (#) Initialize the CAN low level resources by implementing the |
lypinator | 0:bb348c97df44 | 21 | HAL_CAN_MspInit(): |
lypinator | 0:bb348c97df44 | 22 | (++) Enable the CAN interface clock using __HAL_RCC_CANx_CLK_ENABLE() |
lypinator | 0:bb348c97df44 | 23 | (++) Configure CAN pins |
lypinator | 0:bb348c97df44 | 24 | (+++) Enable the clock for the CAN GPIOs |
lypinator | 0:bb348c97df44 | 25 | (+++) Configure CAN pins as alternate function open-drain |
lypinator | 0:bb348c97df44 | 26 | (++) In case of using interrupts (e.g. HAL_CAN_ActivateNotification()) |
lypinator | 0:bb348c97df44 | 27 | (+++) Configure the CAN interrupt priority using |
lypinator | 0:bb348c97df44 | 28 | HAL_NVIC_SetPriority() |
lypinator | 0:bb348c97df44 | 29 | (+++) Enable the CAN IRQ handler using HAL_NVIC_EnableIRQ() |
lypinator | 0:bb348c97df44 | 30 | (+++) In CAN IRQ handler, call HAL_CAN_IRQHandler() |
lypinator | 0:bb348c97df44 | 31 | |
lypinator | 0:bb348c97df44 | 32 | (#) Initialize the CAN peripheral using HAL_CAN_Init() function. This |
lypinator | 0:bb348c97df44 | 33 | function resorts to HAL_CAN_MspInit() for low-level initialization. |
lypinator | 0:bb348c97df44 | 34 | |
lypinator | 0:bb348c97df44 | 35 | (#) Configure the reception filters using the following configuration |
lypinator | 0:bb348c97df44 | 36 | functions: |
lypinator | 0:bb348c97df44 | 37 | (++) HAL_CAN_ConfigFilter() |
lypinator | 0:bb348c97df44 | 38 | |
lypinator | 0:bb348c97df44 | 39 | (#) Start the CAN module using HAL_CAN_Start() function. At this level |
lypinator | 0:bb348c97df44 | 40 | the node is active on the bus: it receive messages, and can send |
lypinator | 0:bb348c97df44 | 41 | messages. |
lypinator | 0:bb348c97df44 | 42 | |
lypinator | 0:bb348c97df44 | 43 | (#) To manage messages transmission, the following Tx control functions |
lypinator | 0:bb348c97df44 | 44 | can be used: |
lypinator | 0:bb348c97df44 | 45 | (++) HAL_CAN_AddTxMessage() to request transmission of a new |
lypinator | 0:bb348c97df44 | 46 | message. |
lypinator | 0:bb348c97df44 | 47 | (++) HAL_CAN_AbortTxRequest() to abort transmission of a pending |
lypinator | 0:bb348c97df44 | 48 | message. |
lypinator | 0:bb348c97df44 | 49 | (++) HAL_CAN_GetTxMailboxesFreeLevel() to get the number of free Tx |
lypinator | 0:bb348c97df44 | 50 | mailboxes. |
lypinator | 0:bb348c97df44 | 51 | (++) HAL_CAN_IsTxMessagePending() to check if a message is pending |
lypinator | 0:bb348c97df44 | 52 | in a Tx mailbox. |
lypinator | 0:bb348c97df44 | 53 | (++) HAL_CAN_GetTxTimestamp() to get the timestamp of Tx message |
lypinator | 0:bb348c97df44 | 54 | sent, if time triggered communication mode is enabled. |
lypinator | 0:bb348c97df44 | 55 | |
lypinator | 0:bb348c97df44 | 56 | (#) When a message is received into the CAN Rx FIFOs, it can be retrieved |
lypinator | 0:bb348c97df44 | 57 | using the HAL_CAN_GetRxMessage() function. The function |
lypinator | 0:bb348c97df44 | 58 | HAL_CAN_GetRxFifoFillLevel() allows to know how many Rx message are |
lypinator | 0:bb348c97df44 | 59 | stored in the Rx Fifo. |
lypinator | 0:bb348c97df44 | 60 | |
lypinator | 0:bb348c97df44 | 61 | (#) Calling the HAL_CAN_Stop() function stops the CAN module. |
lypinator | 0:bb348c97df44 | 62 | |
lypinator | 0:bb348c97df44 | 63 | (#) The deinitialization is achieved with HAL_CAN_DeInit() function. |
lypinator | 0:bb348c97df44 | 64 | |
lypinator | 0:bb348c97df44 | 65 | |
lypinator | 0:bb348c97df44 | 66 | *** Polling mode operation *** |
lypinator | 0:bb348c97df44 | 67 | ============================== |
lypinator | 0:bb348c97df44 | 68 | [..] |
lypinator | 0:bb348c97df44 | 69 | (#) Reception: |
lypinator | 0:bb348c97df44 | 70 | (++) Monitor reception of message using HAL_CAN_GetRxFifoFillLevel() |
lypinator | 0:bb348c97df44 | 71 | until at least one message is received. |
lypinator | 0:bb348c97df44 | 72 | (++) Then get the message using HAL_CAN_GetRxMessage(). |
lypinator | 0:bb348c97df44 | 73 | |
lypinator | 0:bb348c97df44 | 74 | (#) Transmission: |
lypinator | 0:bb348c97df44 | 75 | (++) Monitor the Tx mailboxes availability until at least one Tx |
lypinator | 0:bb348c97df44 | 76 | mailbox is free, using HAL_CAN_GetTxMailboxesFreeLevel(). |
lypinator | 0:bb348c97df44 | 77 | (++) Then request transmission of a message using |
lypinator | 0:bb348c97df44 | 78 | HAL_CAN_AddTxMessage(). |
lypinator | 0:bb348c97df44 | 79 | |
lypinator | 0:bb348c97df44 | 80 | |
lypinator | 0:bb348c97df44 | 81 | *** Interrupt mode operation *** |
lypinator | 0:bb348c97df44 | 82 | ================================ |
lypinator | 0:bb348c97df44 | 83 | [..] |
lypinator | 0:bb348c97df44 | 84 | (#) Notifications are activated using HAL_CAN_ActivateNotification() |
lypinator | 0:bb348c97df44 | 85 | function. Then, the process can be controlled through the |
lypinator | 0:bb348c97df44 | 86 | available user callbacks: HAL_CAN_xxxCallback(), using same APIs |
lypinator | 0:bb348c97df44 | 87 | HAL_CAN_GetRxMessage() and HAL_CAN_AddTxMessage(). |
lypinator | 0:bb348c97df44 | 88 | |
lypinator | 0:bb348c97df44 | 89 | (#) Notifications can be deactivated using |
lypinator | 0:bb348c97df44 | 90 | HAL_CAN_DeactivateNotification() function. |
lypinator | 0:bb348c97df44 | 91 | |
lypinator | 0:bb348c97df44 | 92 | (#) Special care should be taken for CAN_IT_RX_FIFO0_MSG_PENDING and |
lypinator | 0:bb348c97df44 | 93 | CAN_IT_RX_FIFO1_MSG_PENDING notifications. These notifications trig |
lypinator | 0:bb348c97df44 | 94 | the callbacks HAL_CAN_RxFIFO0MsgPendingCallback() and |
lypinator | 0:bb348c97df44 | 95 | HAL_CAN_RxFIFO1MsgPendingCallback(). User has two possible options |
lypinator | 0:bb348c97df44 | 96 | here. |
lypinator | 0:bb348c97df44 | 97 | (++) Directly get the Rx message in the callback, using |
lypinator | 0:bb348c97df44 | 98 | HAL_CAN_GetRxMessage(). |
lypinator | 0:bb348c97df44 | 99 | (++) Or deactivate the notification in the callback without |
lypinator | 0:bb348c97df44 | 100 | getting the Rx message. The Rx message can then be got later |
lypinator | 0:bb348c97df44 | 101 | using HAL_CAN_GetRxMessage(). Once the Rx message have been |
lypinator | 0:bb348c97df44 | 102 | read, the notification can be activated again. |
lypinator | 0:bb348c97df44 | 103 | |
lypinator | 0:bb348c97df44 | 104 | |
lypinator | 0:bb348c97df44 | 105 | *** Sleep mode *** |
lypinator | 0:bb348c97df44 | 106 | ================== |
lypinator | 0:bb348c97df44 | 107 | [..] |
lypinator | 0:bb348c97df44 | 108 | (#) The CAN peripheral can be put in sleep mode (low power), using |
lypinator | 0:bb348c97df44 | 109 | HAL_CAN_RequestSleep(). The sleep mode will be entered as soon as the |
lypinator | 0:bb348c97df44 | 110 | current CAN activity (transmission or reception of a CAN frame) will |
lypinator | 0:bb348c97df44 | 111 | be completed. |
lypinator | 0:bb348c97df44 | 112 | |
lypinator | 0:bb348c97df44 | 113 | (#) A notification can be activated to be informed when the sleep mode |
lypinator | 0:bb348c97df44 | 114 | will be entered. |
lypinator | 0:bb348c97df44 | 115 | |
lypinator | 0:bb348c97df44 | 116 | (#) It can be checked if the sleep mode is entered using |
lypinator | 0:bb348c97df44 | 117 | HAL_CAN_IsSleepActive(). |
lypinator | 0:bb348c97df44 | 118 | Note that the CAN state (accessible from the API HAL_CAN_GetState()) |
lypinator | 0:bb348c97df44 | 119 | is HAL_CAN_STATE_SLEEP_PENDING as soon as the sleep mode request is |
lypinator | 0:bb348c97df44 | 120 | submitted (the sleep mode is not yet entered), and become |
lypinator | 0:bb348c97df44 | 121 | HAL_CAN_STATE_SLEEP_ACTIVE when the sleep mode is effective. |
lypinator | 0:bb348c97df44 | 122 | |
lypinator | 0:bb348c97df44 | 123 | (#) The wake-up from sleep mode can be trigged by two ways: |
lypinator | 0:bb348c97df44 | 124 | (++) Using HAL_CAN_WakeUp(). When returning from this function, |
lypinator | 0:bb348c97df44 | 125 | the sleep mode is exited (if return status is HAL_OK). |
lypinator | 0:bb348c97df44 | 126 | (++) When a start of Rx CAN frame is detected by the CAN peripheral, |
lypinator | 0:bb348c97df44 | 127 | if automatic wake up mode is enabled. |
lypinator | 0:bb348c97df44 | 128 | |
lypinator | 0:bb348c97df44 | 129 | @endverbatim |
lypinator | 0:bb348c97df44 | 130 | ****************************************************************************** |
lypinator | 0:bb348c97df44 | 131 | * @attention |
lypinator | 0:bb348c97df44 | 132 | * |
lypinator | 0:bb348c97df44 | 133 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
lypinator | 0:bb348c97df44 | 134 | * |
lypinator | 0:bb348c97df44 | 135 | * Redistribution and use in source and binary forms, with or without modification, |
lypinator | 0:bb348c97df44 | 136 | * are permitted provided that the following conditions are met: |
lypinator | 0:bb348c97df44 | 137 | * 1. Redistributions of source code must retain the above copyright notice, |
lypinator | 0:bb348c97df44 | 138 | * this list of conditions and the following disclaimer. |
lypinator | 0:bb348c97df44 | 139 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
lypinator | 0:bb348c97df44 | 140 | * this list of conditions and the following disclaimer in the documentation |
lypinator | 0:bb348c97df44 | 141 | * and/or other materials provided with the distribution. |
lypinator | 0:bb348c97df44 | 142 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
lypinator | 0:bb348c97df44 | 143 | * may be used to endorse or promote products derived from this software |
lypinator | 0:bb348c97df44 | 144 | * without specific prior written permission. |
lypinator | 0:bb348c97df44 | 145 | * |
lypinator | 0:bb348c97df44 | 146 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
lypinator | 0:bb348c97df44 | 147 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
lypinator | 0:bb348c97df44 | 148 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
lypinator | 0:bb348c97df44 | 149 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
lypinator | 0:bb348c97df44 | 150 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
lypinator | 0:bb348c97df44 | 151 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
lypinator | 0:bb348c97df44 | 152 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
lypinator | 0:bb348c97df44 | 153 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
lypinator | 0:bb348c97df44 | 154 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
lypinator | 0:bb348c97df44 | 155 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
lypinator | 0:bb348c97df44 | 156 | * |
lypinator | 0:bb348c97df44 | 157 | ****************************************************************************** |
lypinator | 0:bb348c97df44 | 158 | */ |
lypinator | 0:bb348c97df44 | 159 | |
lypinator | 0:bb348c97df44 | 160 | /* Includes ------------------------------------------------------------------*/ |
lypinator | 0:bb348c97df44 | 161 | #include "stm32f4xx_hal.h" |
lypinator | 0:bb348c97df44 | 162 | |
lypinator | 0:bb348c97df44 | 163 | /** @addtogroup STM32F4xx_HAL_Driver |
lypinator | 0:bb348c97df44 | 164 | * @{ |
lypinator | 0:bb348c97df44 | 165 | */ |
lypinator | 0:bb348c97df44 | 166 | |
lypinator | 0:bb348c97df44 | 167 | #if defined(CAN1) |
lypinator | 0:bb348c97df44 | 168 | |
lypinator | 0:bb348c97df44 | 169 | /** @defgroup CAN CAN |
lypinator | 0:bb348c97df44 | 170 | * @brief CAN driver modules |
lypinator | 0:bb348c97df44 | 171 | * @{ |
lypinator | 0:bb348c97df44 | 172 | */ |
lypinator | 0:bb348c97df44 | 173 | |
lypinator | 0:bb348c97df44 | 174 | #ifdef HAL_CAN_MODULE_ENABLED |
lypinator | 0:bb348c97df44 | 175 | |
lypinator | 0:bb348c97df44 | 176 | #ifdef HAL_CAN_LEGACY_MODULE_ENABLED |
lypinator | 0:bb348c97df44 | 177 | #error "The CAN driver cannot be used with its legacy, Please enable only one CAN module at once" |
lypinator | 0:bb348c97df44 | 178 | #endif |
lypinator | 0:bb348c97df44 | 179 | |
lypinator | 0:bb348c97df44 | 180 | /* Private typedef -----------------------------------------------------------*/ |
lypinator | 0:bb348c97df44 | 181 | /* Private define ------------------------------------------------------------*/ |
lypinator | 0:bb348c97df44 | 182 | /** @defgroup CAN_Private_Constants CAN Private Constants |
lypinator | 0:bb348c97df44 | 183 | * @{ |
lypinator | 0:bb348c97df44 | 184 | */ |
lypinator | 0:bb348c97df44 | 185 | #define CAN_TIMEOUT_VALUE 10U |
lypinator | 0:bb348c97df44 | 186 | /** |
lypinator | 0:bb348c97df44 | 187 | * @} |
lypinator | 0:bb348c97df44 | 188 | */ |
lypinator | 0:bb348c97df44 | 189 | /* Private macro -------------------------------------------------------------*/ |
lypinator | 0:bb348c97df44 | 190 | /* Private variables ---------------------------------------------------------*/ |
lypinator | 0:bb348c97df44 | 191 | /* Private function prototypes -----------------------------------------------*/ |
lypinator | 0:bb348c97df44 | 192 | /* Exported functions --------------------------------------------------------*/ |
lypinator | 0:bb348c97df44 | 193 | |
lypinator | 0:bb348c97df44 | 194 | /** @defgroup CAN_Exported_Functions CAN Exported Functions |
lypinator | 0:bb348c97df44 | 195 | * @{ |
lypinator | 0:bb348c97df44 | 196 | */ |
lypinator | 0:bb348c97df44 | 197 | |
lypinator | 0:bb348c97df44 | 198 | /** @defgroup CAN_Exported_Functions_Group1 Initialization and de-initialization functions |
lypinator | 0:bb348c97df44 | 199 | * @brief Initialization and Configuration functions |
lypinator | 0:bb348c97df44 | 200 | * |
lypinator | 0:bb348c97df44 | 201 | @verbatim |
lypinator | 0:bb348c97df44 | 202 | ============================================================================== |
lypinator | 0:bb348c97df44 | 203 | ##### Initialization and de-initialization functions ##### |
lypinator | 0:bb348c97df44 | 204 | ============================================================================== |
lypinator | 0:bb348c97df44 | 205 | [..] This section provides functions allowing to: |
lypinator | 0:bb348c97df44 | 206 | (+) HAL_CAN_Init : Initialize and configure the CAN. |
lypinator | 0:bb348c97df44 | 207 | (+) HAL_CAN_DeInit : De-initialize the CAN. |
lypinator | 0:bb348c97df44 | 208 | (+) HAL_CAN_MspInit : Initialize the CAN MSP. |
lypinator | 0:bb348c97df44 | 209 | (+) HAL_CAN_MspDeInit : DeInitialize the CAN MSP. |
lypinator | 0:bb348c97df44 | 210 | |
lypinator | 0:bb348c97df44 | 211 | @endverbatim |
lypinator | 0:bb348c97df44 | 212 | * @{ |
lypinator | 0:bb348c97df44 | 213 | */ |
lypinator | 0:bb348c97df44 | 214 | |
lypinator | 0:bb348c97df44 | 215 | /** |
lypinator | 0:bb348c97df44 | 216 | * @brief Initializes the CAN peripheral according to the specified |
lypinator | 0:bb348c97df44 | 217 | * parameters in the CAN_InitStruct. |
lypinator | 0:bb348c97df44 | 218 | * @param hcan pointer to a CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 219 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 220 | * @retval HAL status |
lypinator | 0:bb348c97df44 | 221 | */ |
lypinator | 0:bb348c97df44 | 222 | HAL_StatusTypeDef HAL_CAN_Init(CAN_HandleTypeDef *hcan) |
lypinator | 0:bb348c97df44 | 223 | { |
lypinator | 0:bb348c97df44 | 224 | uint32_t tickstart = 0U; |
lypinator | 0:bb348c97df44 | 225 | |
lypinator | 0:bb348c97df44 | 226 | /* Check CAN handle */ |
lypinator | 0:bb348c97df44 | 227 | if (hcan == NULL) |
lypinator | 0:bb348c97df44 | 228 | { |
lypinator | 0:bb348c97df44 | 229 | return HAL_ERROR; |
lypinator | 0:bb348c97df44 | 230 | } |
lypinator | 0:bb348c97df44 | 231 | |
lypinator | 0:bb348c97df44 | 232 | /* Check the parameters */ |
lypinator | 0:bb348c97df44 | 233 | assert_param(IS_CAN_ALL_INSTANCE(hcan->Instance)); |
lypinator | 0:bb348c97df44 | 234 | assert_param(IS_FUNCTIONAL_STATE(hcan->Init.TimeTriggeredMode)); |
lypinator | 0:bb348c97df44 | 235 | assert_param(IS_FUNCTIONAL_STATE(hcan->Init.AutoBusOff)); |
lypinator | 0:bb348c97df44 | 236 | assert_param(IS_FUNCTIONAL_STATE(hcan->Init.AutoWakeUp)); |
lypinator | 0:bb348c97df44 | 237 | assert_param(IS_FUNCTIONAL_STATE(hcan->Init.AutoRetransmission)); |
lypinator | 0:bb348c97df44 | 238 | assert_param(IS_FUNCTIONAL_STATE(hcan->Init.ReceiveFifoLocked)); |
lypinator | 0:bb348c97df44 | 239 | assert_param(IS_FUNCTIONAL_STATE(hcan->Init.TransmitFifoPriority)); |
lypinator | 0:bb348c97df44 | 240 | assert_param(IS_CAN_MODE(hcan->Init.Mode)); |
lypinator | 0:bb348c97df44 | 241 | assert_param(IS_CAN_SJW(hcan->Init.SyncJumpWidth)); |
lypinator | 0:bb348c97df44 | 242 | assert_param(IS_CAN_BS1(hcan->Init.TimeSeg1)); |
lypinator | 0:bb348c97df44 | 243 | assert_param(IS_CAN_BS2(hcan->Init.TimeSeg2)); |
lypinator | 0:bb348c97df44 | 244 | assert_param(IS_CAN_PRESCALER(hcan->Init.Prescaler)); |
lypinator | 0:bb348c97df44 | 245 | |
lypinator | 0:bb348c97df44 | 246 | if (hcan->State == HAL_CAN_STATE_RESET) |
lypinator | 0:bb348c97df44 | 247 | { |
lypinator | 0:bb348c97df44 | 248 | /* Init the low level hardware: CLOCK, NVIC */ |
lypinator | 0:bb348c97df44 | 249 | HAL_CAN_MspInit(hcan); |
lypinator | 0:bb348c97df44 | 250 | } |
lypinator | 0:bb348c97df44 | 251 | |
lypinator | 0:bb348c97df44 | 252 | /* Exit from sleep mode */ |
lypinator | 0:bb348c97df44 | 253 | CLEAR_BIT(hcan->Instance->MCR, CAN_MCR_SLEEP); |
lypinator | 0:bb348c97df44 | 254 | |
lypinator | 0:bb348c97df44 | 255 | /* Get tick */ |
lypinator | 0:bb348c97df44 | 256 | tickstart = HAL_GetTick(); |
lypinator | 0:bb348c97df44 | 257 | |
lypinator | 0:bb348c97df44 | 258 | /* Check Sleep mode leave acknowledge */ |
lypinator | 0:bb348c97df44 | 259 | while ((hcan->Instance->MSR & CAN_MSR_SLAK) != RESET) |
lypinator | 0:bb348c97df44 | 260 | { |
lypinator | 0:bb348c97df44 | 261 | if ((HAL_GetTick() - tickstart) > CAN_TIMEOUT_VALUE) |
lypinator | 0:bb348c97df44 | 262 | { |
lypinator | 0:bb348c97df44 | 263 | /* Update error code */ |
lypinator | 0:bb348c97df44 | 264 | hcan->ErrorCode |= HAL_CAN_ERROR_TIMEOUT; |
lypinator | 0:bb348c97df44 | 265 | |
lypinator | 0:bb348c97df44 | 266 | /* Change CAN state */ |
lypinator | 0:bb348c97df44 | 267 | hcan->State = HAL_CAN_STATE_ERROR; |
lypinator | 0:bb348c97df44 | 268 | |
lypinator | 0:bb348c97df44 | 269 | return HAL_ERROR; |
lypinator | 0:bb348c97df44 | 270 | } |
lypinator | 0:bb348c97df44 | 271 | } |
lypinator | 0:bb348c97df44 | 272 | |
lypinator | 0:bb348c97df44 | 273 | /* Request initialisation */ |
lypinator | 0:bb348c97df44 | 274 | SET_BIT(hcan->Instance->MCR, CAN_MCR_INRQ); |
lypinator | 0:bb348c97df44 | 275 | |
lypinator | 0:bb348c97df44 | 276 | /* Get tick */ |
lypinator | 0:bb348c97df44 | 277 | tickstart = HAL_GetTick(); |
lypinator | 0:bb348c97df44 | 278 | |
lypinator | 0:bb348c97df44 | 279 | /* Wait initialisation acknowledge */ |
lypinator | 0:bb348c97df44 | 280 | while ((hcan->Instance->MSR & CAN_MSR_INAK) == RESET) |
lypinator | 0:bb348c97df44 | 281 | { |
lypinator | 0:bb348c97df44 | 282 | if ((HAL_GetTick() - tickstart) > CAN_TIMEOUT_VALUE) |
lypinator | 0:bb348c97df44 | 283 | { |
lypinator | 0:bb348c97df44 | 284 | /* Update error code */ |
lypinator | 0:bb348c97df44 | 285 | hcan->ErrorCode |= HAL_CAN_ERROR_TIMEOUT; |
lypinator | 0:bb348c97df44 | 286 | |
lypinator | 0:bb348c97df44 | 287 | /* Change CAN state */ |
lypinator | 0:bb348c97df44 | 288 | hcan->State = HAL_CAN_STATE_ERROR; |
lypinator | 0:bb348c97df44 | 289 | |
lypinator | 0:bb348c97df44 | 290 | return HAL_ERROR; |
lypinator | 0:bb348c97df44 | 291 | } |
lypinator | 0:bb348c97df44 | 292 | } |
lypinator | 0:bb348c97df44 | 293 | |
lypinator | 0:bb348c97df44 | 294 | /* Set the time triggered communication mode */ |
lypinator | 0:bb348c97df44 | 295 | if (hcan->Init.TimeTriggeredMode == ENABLE) |
lypinator | 0:bb348c97df44 | 296 | { |
lypinator | 0:bb348c97df44 | 297 | SET_BIT(hcan->Instance->MCR, CAN_MCR_TTCM); |
lypinator | 0:bb348c97df44 | 298 | } |
lypinator | 0:bb348c97df44 | 299 | else |
lypinator | 0:bb348c97df44 | 300 | { |
lypinator | 0:bb348c97df44 | 301 | CLEAR_BIT(hcan->Instance->MCR, CAN_MCR_TTCM); |
lypinator | 0:bb348c97df44 | 302 | } |
lypinator | 0:bb348c97df44 | 303 | |
lypinator | 0:bb348c97df44 | 304 | /* Set the automatic bus-off management */ |
lypinator | 0:bb348c97df44 | 305 | if (hcan->Init.AutoBusOff == ENABLE) |
lypinator | 0:bb348c97df44 | 306 | { |
lypinator | 0:bb348c97df44 | 307 | SET_BIT(hcan->Instance->MCR, CAN_MCR_ABOM); |
lypinator | 0:bb348c97df44 | 308 | } |
lypinator | 0:bb348c97df44 | 309 | else |
lypinator | 0:bb348c97df44 | 310 | { |
lypinator | 0:bb348c97df44 | 311 | CLEAR_BIT(hcan->Instance->MCR, CAN_MCR_ABOM); |
lypinator | 0:bb348c97df44 | 312 | } |
lypinator | 0:bb348c97df44 | 313 | |
lypinator | 0:bb348c97df44 | 314 | /* Set the automatic wake-up mode */ |
lypinator | 0:bb348c97df44 | 315 | if (hcan->Init.AutoWakeUp == ENABLE) |
lypinator | 0:bb348c97df44 | 316 | { |
lypinator | 0:bb348c97df44 | 317 | SET_BIT(hcan->Instance->MCR, CAN_MCR_AWUM); |
lypinator | 0:bb348c97df44 | 318 | } |
lypinator | 0:bb348c97df44 | 319 | else |
lypinator | 0:bb348c97df44 | 320 | { |
lypinator | 0:bb348c97df44 | 321 | CLEAR_BIT(hcan->Instance->MCR, CAN_MCR_AWUM); |
lypinator | 0:bb348c97df44 | 322 | } |
lypinator | 0:bb348c97df44 | 323 | |
lypinator | 0:bb348c97df44 | 324 | /* Set the automatic retransmission */ |
lypinator | 0:bb348c97df44 | 325 | if (hcan->Init.AutoRetransmission == ENABLE) |
lypinator | 0:bb348c97df44 | 326 | { |
lypinator | 0:bb348c97df44 | 327 | CLEAR_BIT(hcan->Instance->MCR, CAN_MCR_NART); |
lypinator | 0:bb348c97df44 | 328 | } |
lypinator | 0:bb348c97df44 | 329 | else |
lypinator | 0:bb348c97df44 | 330 | { |
lypinator | 0:bb348c97df44 | 331 | SET_BIT(hcan->Instance->MCR, CAN_MCR_NART); |
lypinator | 0:bb348c97df44 | 332 | } |
lypinator | 0:bb348c97df44 | 333 | |
lypinator | 0:bb348c97df44 | 334 | /* Set the receive FIFO locked mode */ |
lypinator | 0:bb348c97df44 | 335 | if (hcan->Init.ReceiveFifoLocked == ENABLE) |
lypinator | 0:bb348c97df44 | 336 | { |
lypinator | 0:bb348c97df44 | 337 | SET_BIT(hcan->Instance->MCR, CAN_MCR_RFLM); |
lypinator | 0:bb348c97df44 | 338 | } |
lypinator | 0:bb348c97df44 | 339 | else |
lypinator | 0:bb348c97df44 | 340 | { |
lypinator | 0:bb348c97df44 | 341 | CLEAR_BIT(hcan->Instance->MCR, CAN_MCR_RFLM); |
lypinator | 0:bb348c97df44 | 342 | } |
lypinator | 0:bb348c97df44 | 343 | |
lypinator | 0:bb348c97df44 | 344 | /* Set the transmit FIFO priority */ |
lypinator | 0:bb348c97df44 | 345 | if (hcan->Init.TransmitFifoPriority == ENABLE) |
lypinator | 0:bb348c97df44 | 346 | { |
lypinator | 0:bb348c97df44 | 347 | SET_BIT(hcan->Instance->MCR, CAN_MCR_TXFP); |
lypinator | 0:bb348c97df44 | 348 | } |
lypinator | 0:bb348c97df44 | 349 | else |
lypinator | 0:bb348c97df44 | 350 | { |
lypinator | 0:bb348c97df44 | 351 | CLEAR_BIT(hcan->Instance->MCR, CAN_MCR_TXFP); |
lypinator | 0:bb348c97df44 | 352 | } |
lypinator | 0:bb348c97df44 | 353 | |
lypinator | 0:bb348c97df44 | 354 | /* Set the bit timing register */ |
lypinator | 0:bb348c97df44 | 355 | WRITE_REG(hcan->Instance->BTR, (uint32_t)(hcan->Init.Mode | |
lypinator | 0:bb348c97df44 | 356 | hcan->Init.SyncJumpWidth | |
lypinator | 0:bb348c97df44 | 357 | hcan->Init.TimeSeg1 | |
lypinator | 0:bb348c97df44 | 358 | hcan->Init.TimeSeg2 | |
lypinator | 0:bb348c97df44 | 359 | (hcan->Init.Prescaler - 1U))); |
lypinator | 0:bb348c97df44 | 360 | |
lypinator | 0:bb348c97df44 | 361 | /* Initialize the error code */ |
lypinator | 0:bb348c97df44 | 362 | hcan->ErrorCode = HAL_CAN_ERROR_NONE; |
lypinator | 0:bb348c97df44 | 363 | |
lypinator | 0:bb348c97df44 | 364 | /* Initialize the CAN state */ |
lypinator | 0:bb348c97df44 | 365 | hcan->State = HAL_CAN_STATE_READY; |
lypinator | 0:bb348c97df44 | 366 | |
lypinator | 0:bb348c97df44 | 367 | /* Return function status */ |
lypinator | 0:bb348c97df44 | 368 | return HAL_OK; |
lypinator | 0:bb348c97df44 | 369 | } |
lypinator | 0:bb348c97df44 | 370 | |
lypinator | 0:bb348c97df44 | 371 | /** |
lypinator | 0:bb348c97df44 | 372 | * @brief Deinitializes the CAN peripheral registers to their default |
lypinator | 0:bb348c97df44 | 373 | * reset values. |
lypinator | 0:bb348c97df44 | 374 | * @param hcan pointer to a CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 375 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 376 | * @retval HAL status |
lypinator | 0:bb348c97df44 | 377 | */ |
lypinator | 0:bb348c97df44 | 378 | HAL_StatusTypeDef HAL_CAN_DeInit(CAN_HandleTypeDef *hcan) |
lypinator | 0:bb348c97df44 | 379 | { |
lypinator | 0:bb348c97df44 | 380 | /* Check CAN handle */ |
lypinator | 0:bb348c97df44 | 381 | if (hcan == NULL) |
lypinator | 0:bb348c97df44 | 382 | { |
lypinator | 0:bb348c97df44 | 383 | return HAL_ERROR; |
lypinator | 0:bb348c97df44 | 384 | } |
lypinator | 0:bb348c97df44 | 385 | |
lypinator | 0:bb348c97df44 | 386 | /* Check the parameters */ |
lypinator | 0:bb348c97df44 | 387 | assert_param(IS_CAN_ALL_INSTANCE(hcan->Instance)); |
lypinator | 0:bb348c97df44 | 388 | |
lypinator | 0:bb348c97df44 | 389 | /* Stop the CAN module */ |
lypinator | 0:bb348c97df44 | 390 | HAL_CAN_Stop(hcan); |
lypinator | 0:bb348c97df44 | 391 | |
lypinator | 0:bb348c97df44 | 392 | /* DeInit the low level hardware: CLOCK, NVIC */ |
lypinator | 0:bb348c97df44 | 393 | HAL_CAN_MspDeInit(hcan); |
lypinator | 0:bb348c97df44 | 394 | |
lypinator | 0:bb348c97df44 | 395 | /* Reset the CAN peripheral */ |
lypinator | 0:bb348c97df44 | 396 | SET_BIT(hcan->Instance->MCR, CAN_MCR_RESET); |
lypinator | 0:bb348c97df44 | 397 | |
lypinator | 0:bb348c97df44 | 398 | /* Reset the CAN ErrorCode */ |
lypinator | 0:bb348c97df44 | 399 | hcan->ErrorCode = HAL_CAN_ERROR_NONE; |
lypinator | 0:bb348c97df44 | 400 | |
lypinator | 0:bb348c97df44 | 401 | /* Change CAN state */ |
lypinator | 0:bb348c97df44 | 402 | hcan->State = HAL_CAN_STATE_RESET; |
lypinator | 0:bb348c97df44 | 403 | |
lypinator | 0:bb348c97df44 | 404 | /* Return function status */ |
lypinator | 0:bb348c97df44 | 405 | return HAL_OK; |
lypinator | 0:bb348c97df44 | 406 | } |
lypinator | 0:bb348c97df44 | 407 | |
lypinator | 0:bb348c97df44 | 408 | /** |
lypinator | 0:bb348c97df44 | 409 | * @brief Initializes the CAN MSP. |
lypinator | 0:bb348c97df44 | 410 | * @param hcan pointer to a CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 411 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 412 | * @retval None |
lypinator | 0:bb348c97df44 | 413 | */ |
lypinator | 0:bb348c97df44 | 414 | __weak void HAL_CAN_MspInit(CAN_HandleTypeDef *hcan) |
lypinator | 0:bb348c97df44 | 415 | { |
lypinator | 0:bb348c97df44 | 416 | /* Prevent unused argument(s) compilation warning */ |
lypinator | 0:bb348c97df44 | 417 | UNUSED(hcan); |
lypinator | 0:bb348c97df44 | 418 | |
lypinator | 0:bb348c97df44 | 419 | /* NOTE : This function Should not be modified, when the callback is needed, |
lypinator | 0:bb348c97df44 | 420 | the HAL_CAN_MspInit could be implemented in the user file |
lypinator | 0:bb348c97df44 | 421 | */ |
lypinator | 0:bb348c97df44 | 422 | } |
lypinator | 0:bb348c97df44 | 423 | |
lypinator | 0:bb348c97df44 | 424 | /** |
lypinator | 0:bb348c97df44 | 425 | * @brief DeInitializes the CAN MSP. |
lypinator | 0:bb348c97df44 | 426 | * @param hcan pointer to a CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 427 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 428 | * @retval None |
lypinator | 0:bb348c97df44 | 429 | */ |
lypinator | 0:bb348c97df44 | 430 | __weak void HAL_CAN_MspDeInit(CAN_HandleTypeDef *hcan) |
lypinator | 0:bb348c97df44 | 431 | { |
lypinator | 0:bb348c97df44 | 432 | /* Prevent unused argument(s) compilation warning */ |
lypinator | 0:bb348c97df44 | 433 | UNUSED(hcan); |
lypinator | 0:bb348c97df44 | 434 | |
lypinator | 0:bb348c97df44 | 435 | /* NOTE : This function Should not be modified, when the callback is needed, |
lypinator | 0:bb348c97df44 | 436 | the HAL_CAN_MspDeInit could be implemented in the user file |
lypinator | 0:bb348c97df44 | 437 | */ |
lypinator | 0:bb348c97df44 | 438 | } |
lypinator | 0:bb348c97df44 | 439 | |
lypinator | 0:bb348c97df44 | 440 | |
lypinator | 0:bb348c97df44 | 441 | /** |
lypinator | 0:bb348c97df44 | 442 | * @} |
lypinator | 0:bb348c97df44 | 443 | */ |
lypinator | 0:bb348c97df44 | 444 | |
lypinator | 0:bb348c97df44 | 445 | /** @defgroup CAN_Exported_Functions_Group2 Configuration functions |
lypinator | 0:bb348c97df44 | 446 | * @brief Configuration functions. |
lypinator | 0:bb348c97df44 | 447 | * |
lypinator | 0:bb348c97df44 | 448 | @verbatim |
lypinator | 0:bb348c97df44 | 449 | ============================================================================== |
lypinator | 0:bb348c97df44 | 450 | ##### Configuration functions ##### |
lypinator | 0:bb348c97df44 | 451 | ============================================================================== |
lypinator | 0:bb348c97df44 | 452 | [..] This section provides functions allowing to: |
lypinator | 0:bb348c97df44 | 453 | (+) HAL_CAN_ConfigFilter : Configure the CAN reception filters |
lypinator | 0:bb348c97df44 | 454 | |
lypinator | 0:bb348c97df44 | 455 | @endverbatim |
lypinator | 0:bb348c97df44 | 456 | * @{ |
lypinator | 0:bb348c97df44 | 457 | */ |
lypinator | 0:bb348c97df44 | 458 | |
lypinator | 0:bb348c97df44 | 459 | /** |
lypinator | 0:bb348c97df44 | 460 | * @brief Configures the CAN reception filter according to the specified |
lypinator | 0:bb348c97df44 | 461 | * parameters in the CAN_FilterInitStruct. |
lypinator | 0:bb348c97df44 | 462 | * @param hcan pointer to a CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 463 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 464 | * @param sFilterConfig pointer to a CAN_FilterTypeDef structure that |
lypinator | 0:bb348c97df44 | 465 | * contains the filter configuration information. |
lypinator | 0:bb348c97df44 | 466 | * @retval None |
lypinator | 0:bb348c97df44 | 467 | */ |
lypinator | 0:bb348c97df44 | 468 | HAL_StatusTypeDef HAL_CAN_ConfigFilter(CAN_HandleTypeDef *hcan, CAN_FilterTypeDef *sFilterConfig) |
lypinator | 0:bb348c97df44 | 469 | { |
lypinator | 0:bb348c97df44 | 470 | uint32_t filternbrbitpos = 0U; |
lypinator | 0:bb348c97df44 | 471 | CAN_TypeDef *can_ip = hcan->Instance; |
lypinator | 0:bb348c97df44 | 472 | |
lypinator | 0:bb348c97df44 | 473 | if ((hcan->State == HAL_CAN_STATE_READY) || |
lypinator | 0:bb348c97df44 | 474 | (hcan->State == HAL_CAN_STATE_LISTENING)) |
lypinator | 0:bb348c97df44 | 475 | { |
lypinator | 0:bb348c97df44 | 476 | /* Check the parameters */ |
lypinator | 0:bb348c97df44 | 477 | assert_param(IS_CAN_FILTER_ID_HALFWORD(sFilterConfig->FilterIdHigh)); |
lypinator | 0:bb348c97df44 | 478 | assert_param(IS_CAN_FILTER_ID_HALFWORD(sFilterConfig->FilterIdLow)); |
lypinator | 0:bb348c97df44 | 479 | assert_param(IS_CAN_FILTER_ID_HALFWORD(sFilterConfig->FilterMaskIdHigh)); |
lypinator | 0:bb348c97df44 | 480 | assert_param(IS_CAN_FILTER_ID_HALFWORD(sFilterConfig->FilterMaskIdLow)); |
lypinator | 0:bb348c97df44 | 481 | assert_param(IS_CAN_FILTER_MODE(sFilterConfig->FilterMode)); |
lypinator | 0:bb348c97df44 | 482 | assert_param(IS_CAN_FILTER_SCALE(sFilterConfig->FilterScale)); |
lypinator | 0:bb348c97df44 | 483 | assert_param(IS_CAN_FILTER_FIFO(sFilterConfig->FilterFIFOAssignment)); |
lypinator | 0:bb348c97df44 | 484 | assert_param(IS_FUNCTIONAL_STATE(sFilterConfig->FilterActivation)); |
lypinator | 0:bb348c97df44 | 485 | |
lypinator | 0:bb348c97df44 | 486 | #if defined(CAN3) |
lypinator | 0:bb348c97df44 | 487 | /* Check the CAN instance */ |
lypinator | 0:bb348c97df44 | 488 | if (hcan->Instance == CAN3) |
lypinator | 0:bb348c97df44 | 489 | { |
lypinator | 0:bb348c97df44 | 490 | /* CAN3 is single instance with 14 dedicated filters banks */ |
lypinator | 0:bb348c97df44 | 491 | |
lypinator | 0:bb348c97df44 | 492 | /* Check the parameters */ |
lypinator | 0:bb348c97df44 | 493 | assert_param(IS_CAN_FILTER_BANK_SINGLE(sFilterConfig->FilterBank)); |
lypinator | 0:bb348c97df44 | 494 | } |
lypinator | 0:bb348c97df44 | 495 | else |
lypinator | 0:bb348c97df44 | 496 | { |
lypinator | 0:bb348c97df44 | 497 | /* CAN1 and CAN2 are dual instances with 28 common filters banks */ |
lypinator | 0:bb348c97df44 | 498 | /* Select master instance to access the filter banks */ |
lypinator | 0:bb348c97df44 | 499 | can_ip = CAN1; |
lypinator | 0:bb348c97df44 | 500 | |
lypinator | 0:bb348c97df44 | 501 | /* Check the parameters */ |
lypinator | 0:bb348c97df44 | 502 | assert_param(IS_CAN_FILTER_BANK_DUAL(sFilterConfig->FilterBank)); |
lypinator | 0:bb348c97df44 | 503 | assert_param(IS_CAN_FILTER_BANK_DUAL(sFilterConfig->SlaveStartFilterBank)); |
lypinator | 0:bb348c97df44 | 504 | } |
lypinator | 0:bb348c97df44 | 505 | #elif defined(CAN2) |
lypinator | 0:bb348c97df44 | 506 | /* CAN1 and CAN2 are dual instances with 28 common filters banks */ |
lypinator | 0:bb348c97df44 | 507 | /* Select master instance to access the filter banks */ |
lypinator | 0:bb348c97df44 | 508 | can_ip = CAN1; |
lypinator | 0:bb348c97df44 | 509 | |
lypinator | 0:bb348c97df44 | 510 | /* Check the parameters */ |
lypinator | 0:bb348c97df44 | 511 | assert_param(IS_CAN_FILTER_BANK_DUAL(sFilterConfig->FilterBank)); |
lypinator | 0:bb348c97df44 | 512 | assert_param(IS_CAN_FILTER_BANK_DUAL(sFilterConfig->SlaveStartFilterBank)); |
lypinator | 0:bb348c97df44 | 513 | #else |
lypinator | 0:bb348c97df44 | 514 | /* CAN1 is single instance with 14 dedicated filters banks */ |
lypinator | 0:bb348c97df44 | 515 | |
lypinator | 0:bb348c97df44 | 516 | /* Check the parameters */ |
lypinator | 0:bb348c97df44 | 517 | assert_param(IS_CAN_FILTER_BANK_SINGLE(sFilterConfig->FilterBank)); |
lypinator | 0:bb348c97df44 | 518 | #endif |
lypinator | 0:bb348c97df44 | 519 | |
lypinator | 0:bb348c97df44 | 520 | /* Initialisation mode for the filter */ |
lypinator | 0:bb348c97df44 | 521 | SET_BIT(can_ip->FMR, CAN_FMR_FINIT); |
lypinator | 0:bb348c97df44 | 522 | |
lypinator | 0:bb348c97df44 | 523 | #if defined(CAN3) |
lypinator | 0:bb348c97df44 | 524 | /* Check the CAN instance */ |
lypinator | 0:bb348c97df44 | 525 | if (can_ip == CAN1) |
lypinator | 0:bb348c97df44 | 526 | { |
lypinator | 0:bb348c97df44 | 527 | /* Select the start filter number of CAN2 slave instance */ |
lypinator | 0:bb348c97df44 | 528 | CLEAR_BIT(can_ip->FMR, CAN_FMR_CAN2SB); |
lypinator | 0:bb348c97df44 | 529 | SET_BIT(can_ip->FMR, sFilterConfig->SlaveStartFilterBank << CAN_FMR_CAN2SB_Pos); |
lypinator | 0:bb348c97df44 | 530 | } |
lypinator | 0:bb348c97df44 | 531 | |
lypinator | 0:bb348c97df44 | 532 | #elif defined(CAN2) |
lypinator | 0:bb348c97df44 | 533 | /* Select the start filter number of CAN2 slave instance */ |
lypinator | 0:bb348c97df44 | 534 | CLEAR_BIT(can_ip->FMR, CAN_FMR_CAN2SB); |
lypinator | 0:bb348c97df44 | 535 | SET_BIT(can_ip->FMR, sFilterConfig->SlaveStartFilterBank << CAN_FMR_CAN2SB_Pos); |
lypinator | 0:bb348c97df44 | 536 | |
lypinator | 0:bb348c97df44 | 537 | #endif |
lypinator | 0:bb348c97df44 | 538 | /* Convert filter number into bit position */ |
lypinator | 0:bb348c97df44 | 539 | filternbrbitpos = (1U) << sFilterConfig->FilterBank; |
lypinator | 0:bb348c97df44 | 540 | |
lypinator | 0:bb348c97df44 | 541 | /* Filter Deactivation */ |
lypinator | 0:bb348c97df44 | 542 | CLEAR_BIT(can_ip->FA1R, filternbrbitpos); |
lypinator | 0:bb348c97df44 | 543 | |
lypinator | 0:bb348c97df44 | 544 | /* Filter Scale */ |
lypinator | 0:bb348c97df44 | 545 | if (sFilterConfig->FilterScale == CAN_FILTERSCALE_16BIT) |
lypinator | 0:bb348c97df44 | 546 | { |
lypinator | 0:bb348c97df44 | 547 | /* 16-bit scale for the filter */ |
lypinator | 0:bb348c97df44 | 548 | CLEAR_BIT(can_ip->FS1R, filternbrbitpos); |
lypinator | 0:bb348c97df44 | 549 | |
lypinator | 0:bb348c97df44 | 550 | /* First 16-bit identifier and First 16-bit mask */ |
lypinator | 0:bb348c97df44 | 551 | /* Or First 16-bit identifier and Second 16-bit identifier */ |
lypinator | 0:bb348c97df44 | 552 | can_ip->sFilterRegister[sFilterConfig->FilterBank].FR1 = |
lypinator | 0:bb348c97df44 | 553 | ((0x0000FFFFU & (uint32_t)sFilterConfig->FilterMaskIdLow) << 16U) | |
lypinator | 0:bb348c97df44 | 554 | (0x0000FFFFU & (uint32_t)sFilterConfig->FilterIdLow); |
lypinator | 0:bb348c97df44 | 555 | |
lypinator | 0:bb348c97df44 | 556 | /* Second 16-bit identifier and Second 16-bit mask */ |
lypinator | 0:bb348c97df44 | 557 | /* Or Third 16-bit identifier and Fourth 16-bit identifier */ |
lypinator | 0:bb348c97df44 | 558 | can_ip->sFilterRegister[sFilterConfig->FilterBank].FR2 = |
lypinator | 0:bb348c97df44 | 559 | ((0x0000FFFFU & (uint32_t)sFilterConfig->FilterMaskIdHigh) << 16U) | |
lypinator | 0:bb348c97df44 | 560 | (0x0000FFFFU & (uint32_t)sFilterConfig->FilterIdHigh); |
lypinator | 0:bb348c97df44 | 561 | } |
lypinator | 0:bb348c97df44 | 562 | |
lypinator | 0:bb348c97df44 | 563 | if (sFilterConfig->FilterScale == CAN_FILTERSCALE_32BIT) |
lypinator | 0:bb348c97df44 | 564 | { |
lypinator | 0:bb348c97df44 | 565 | /* 32-bit scale for the filter */ |
lypinator | 0:bb348c97df44 | 566 | SET_BIT(can_ip->FS1R, filternbrbitpos); |
lypinator | 0:bb348c97df44 | 567 | |
lypinator | 0:bb348c97df44 | 568 | /* 32-bit identifier or First 32-bit identifier */ |
lypinator | 0:bb348c97df44 | 569 | can_ip->sFilterRegister[sFilterConfig->FilterBank].FR1 = |
lypinator | 0:bb348c97df44 | 570 | ((0x0000FFFFU & (uint32_t)sFilterConfig->FilterIdHigh) << 16U) | |
lypinator | 0:bb348c97df44 | 571 | (0x0000FFFFU & (uint32_t)sFilterConfig->FilterIdLow); |
lypinator | 0:bb348c97df44 | 572 | |
lypinator | 0:bb348c97df44 | 573 | /* 32-bit mask or Second 32-bit identifier */ |
lypinator | 0:bb348c97df44 | 574 | can_ip->sFilterRegister[sFilterConfig->FilterBank].FR2 = |
lypinator | 0:bb348c97df44 | 575 | ((0x0000FFFFU & (uint32_t)sFilterConfig->FilterMaskIdHigh) << 16U) | |
lypinator | 0:bb348c97df44 | 576 | (0x0000FFFFU & (uint32_t)sFilterConfig->FilterMaskIdLow); |
lypinator | 0:bb348c97df44 | 577 | } |
lypinator | 0:bb348c97df44 | 578 | |
lypinator | 0:bb348c97df44 | 579 | /* Filter Mode */ |
lypinator | 0:bb348c97df44 | 580 | if (sFilterConfig->FilterMode == CAN_FILTERMODE_IDMASK) |
lypinator | 0:bb348c97df44 | 581 | { |
lypinator | 0:bb348c97df44 | 582 | /* Id/Mask mode for the filter*/ |
lypinator | 0:bb348c97df44 | 583 | CLEAR_BIT(can_ip->FM1R, filternbrbitpos); |
lypinator | 0:bb348c97df44 | 584 | } |
lypinator | 0:bb348c97df44 | 585 | else /* CAN_FilterInitStruct->CAN_FilterMode == CAN_FilterMode_IdList */ |
lypinator | 0:bb348c97df44 | 586 | { |
lypinator | 0:bb348c97df44 | 587 | /* Identifier list mode for the filter*/ |
lypinator | 0:bb348c97df44 | 588 | SET_BIT(can_ip->FM1R, filternbrbitpos); |
lypinator | 0:bb348c97df44 | 589 | } |
lypinator | 0:bb348c97df44 | 590 | |
lypinator | 0:bb348c97df44 | 591 | /* Filter FIFO assignment */ |
lypinator | 0:bb348c97df44 | 592 | if (sFilterConfig->FilterFIFOAssignment == CAN_FILTER_FIFO0) |
lypinator | 0:bb348c97df44 | 593 | { |
lypinator | 0:bb348c97df44 | 594 | /* FIFO 0 assignation for the filter */ |
lypinator | 0:bb348c97df44 | 595 | CLEAR_BIT(can_ip->FFA1R, filternbrbitpos); |
lypinator | 0:bb348c97df44 | 596 | } |
lypinator | 0:bb348c97df44 | 597 | else |
lypinator | 0:bb348c97df44 | 598 | { |
lypinator | 0:bb348c97df44 | 599 | /* FIFO 1 assignation for the filter */ |
lypinator | 0:bb348c97df44 | 600 | SET_BIT(can_ip->FFA1R, filternbrbitpos); |
lypinator | 0:bb348c97df44 | 601 | } |
lypinator | 0:bb348c97df44 | 602 | |
lypinator | 0:bb348c97df44 | 603 | /* Filter activation */ |
lypinator | 0:bb348c97df44 | 604 | if (sFilterConfig->FilterActivation == ENABLE) |
lypinator | 0:bb348c97df44 | 605 | { |
lypinator | 0:bb348c97df44 | 606 | SET_BIT(can_ip->FA1R, filternbrbitpos); |
lypinator | 0:bb348c97df44 | 607 | } |
lypinator | 0:bb348c97df44 | 608 | |
lypinator | 0:bb348c97df44 | 609 | /* Leave the initialisation mode for the filter */ |
lypinator | 0:bb348c97df44 | 610 | CLEAR_BIT(can_ip->FMR, CAN_FMR_FINIT); |
lypinator | 0:bb348c97df44 | 611 | |
lypinator | 0:bb348c97df44 | 612 | /* Return function status */ |
lypinator | 0:bb348c97df44 | 613 | return HAL_OK; |
lypinator | 0:bb348c97df44 | 614 | } |
lypinator | 0:bb348c97df44 | 615 | else |
lypinator | 0:bb348c97df44 | 616 | { |
lypinator | 0:bb348c97df44 | 617 | /* Update error code */ |
lypinator | 0:bb348c97df44 | 618 | hcan->ErrorCode |= HAL_CAN_ERROR_NOT_INITIALIZED; |
lypinator | 0:bb348c97df44 | 619 | |
lypinator | 0:bb348c97df44 | 620 | return HAL_ERROR; |
lypinator | 0:bb348c97df44 | 621 | } |
lypinator | 0:bb348c97df44 | 622 | } |
lypinator | 0:bb348c97df44 | 623 | |
lypinator | 0:bb348c97df44 | 624 | /** |
lypinator | 0:bb348c97df44 | 625 | * @} |
lypinator | 0:bb348c97df44 | 626 | */ |
lypinator | 0:bb348c97df44 | 627 | |
lypinator | 0:bb348c97df44 | 628 | /** @defgroup CAN_Exported_Functions_Group3 Control functions |
lypinator | 0:bb348c97df44 | 629 | * @brief Control functions |
lypinator | 0:bb348c97df44 | 630 | * |
lypinator | 0:bb348c97df44 | 631 | @verbatim |
lypinator | 0:bb348c97df44 | 632 | ============================================================================== |
lypinator | 0:bb348c97df44 | 633 | ##### Control functions ##### |
lypinator | 0:bb348c97df44 | 634 | ============================================================================== |
lypinator | 0:bb348c97df44 | 635 | [..] This section provides functions allowing to: |
lypinator | 0:bb348c97df44 | 636 | (+) HAL_CAN_Start : Start the CAN module |
lypinator | 0:bb348c97df44 | 637 | (+) HAL_CAN_Stop : Stop the CAN module |
lypinator | 0:bb348c97df44 | 638 | (+) HAL_CAN_RequestSleep : Request sleep mode entry. |
lypinator | 0:bb348c97df44 | 639 | (+) HAL_CAN_WakeUp : Wake up from sleep mode. |
lypinator | 0:bb348c97df44 | 640 | (+) HAL_CAN_IsSleepActive : Check is sleep mode is active. |
lypinator | 0:bb348c97df44 | 641 | (+) HAL_CAN_AddTxMessage : Add a message to the Tx mailboxes |
lypinator | 0:bb348c97df44 | 642 | and activate the corresponding |
lypinator | 0:bb348c97df44 | 643 | transmission request |
lypinator | 0:bb348c97df44 | 644 | (+) HAL_CAN_AbortTxRequest : Abort transmission request |
lypinator | 0:bb348c97df44 | 645 | (+) HAL_CAN_GetTxMailboxesFreeLevel : Return Tx mailboxes free level |
lypinator | 0:bb348c97df44 | 646 | (+) HAL_CAN_IsTxMessagePending : Check if a transmission request is |
lypinator | 0:bb348c97df44 | 647 | pending on the selected Tx mailbox |
lypinator | 0:bb348c97df44 | 648 | (+) HAL_CAN_GetRxMessage : Get a CAN frame from the Rx FIFO |
lypinator | 0:bb348c97df44 | 649 | (+) HAL_CAN_GetRxFifoFillLevel : Return Rx FIFO fill level |
lypinator | 0:bb348c97df44 | 650 | |
lypinator | 0:bb348c97df44 | 651 | @endverbatim |
lypinator | 0:bb348c97df44 | 652 | * @{ |
lypinator | 0:bb348c97df44 | 653 | */ |
lypinator | 0:bb348c97df44 | 654 | |
lypinator | 0:bb348c97df44 | 655 | /** |
lypinator | 0:bb348c97df44 | 656 | * @brief Start the CAN module. |
lypinator | 0:bb348c97df44 | 657 | * @param hcan pointer to an CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 658 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 659 | * @retval HAL status |
lypinator | 0:bb348c97df44 | 660 | */ |
lypinator | 0:bb348c97df44 | 661 | HAL_StatusTypeDef HAL_CAN_Start(CAN_HandleTypeDef *hcan) |
lypinator | 0:bb348c97df44 | 662 | { |
lypinator | 0:bb348c97df44 | 663 | uint32_t tickstart = 0U; |
lypinator | 0:bb348c97df44 | 664 | |
lypinator | 0:bb348c97df44 | 665 | if (hcan->State == HAL_CAN_STATE_READY) |
lypinator | 0:bb348c97df44 | 666 | { |
lypinator | 0:bb348c97df44 | 667 | /* Change CAN peripheral state */ |
lypinator | 0:bb348c97df44 | 668 | hcan->State = HAL_CAN_STATE_LISTENING; |
lypinator | 0:bb348c97df44 | 669 | |
lypinator | 0:bb348c97df44 | 670 | /* Request leave initialisation */ |
lypinator | 0:bb348c97df44 | 671 | CLEAR_BIT(hcan->Instance->MCR, CAN_MCR_INRQ); |
lypinator | 0:bb348c97df44 | 672 | |
lypinator | 0:bb348c97df44 | 673 | /* Get tick */ |
lypinator | 0:bb348c97df44 | 674 | tickstart = HAL_GetTick(); |
lypinator | 0:bb348c97df44 | 675 | |
lypinator | 0:bb348c97df44 | 676 | /* Wait the acknowledge */ |
lypinator | 0:bb348c97df44 | 677 | while ((hcan->Instance->MSR & CAN_MSR_INAK) != RESET) |
lypinator | 0:bb348c97df44 | 678 | { |
lypinator | 0:bb348c97df44 | 679 | /* Check for the Timeout */ |
lypinator | 0:bb348c97df44 | 680 | if ((HAL_GetTick() - tickstart) > CAN_TIMEOUT_VALUE) |
lypinator | 0:bb348c97df44 | 681 | { |
lypinator | 0:bb348c97df44 | 682 | /* Update error code */ |
lypinator | 0:bb348c97df44 | 683 | hcan->ErrorCode |= HAL_CAN_ERROR_TIMEOUT; |
lypinator | 0:bb348c97df44 | 684 | |
lypinator | 0:bb348c97df44 | 685 | /* Change CAN state */ |
lypinator | 0:bb348c97df44 | 686 | hcan->State = HAL_CAN_STATE_ERROR; |
lypinator | 0:bb348c97df44 | 687 | |
lypinator | 0:bb348c97df44 | 688 | return HAL_ERROR; |
lypinator | 0:bb348c97df44 | 689 | } |
lypinator | 0:bb348c97df44 | 690 | } |
lypinator | 0:bb348c97df44 | 691 | |
lypinator | 0:bb348c97df44 | 692 | /* Reset the CAN ErrorCode */ |
lypinator | 0:bb348c97df44 | 693 | hcan->ErrorCode = HAL_CAN_ERROR_NONE; |
lypinator | 0:bb348c97df44 | 694 | |
lypinator | 0:bb348c97df44 | 695 | /* Return function status */ |
lypinator | 0:bb348c97df44 | 696 | return HAL_OK; |
lypinator | 0:bb348c97df44 | 697 | } |
lypinator | 0:bb348c97df44 | 698 | else |
lypinator | 0:bb348c97df44 | 699 | { |
lypinator | 0:bb348c97df44 | 700 | /* Update error code */ |
lypinator | 0:bb348c97df44 | 701 | hcan->ErrorCode |= HAL_CAN_ERROR_NOT_READY; |
lypinator | 0:bb348c97df44 | 702 | |
lypinator | 0:bb348c97df44 | 703 | return HAL_ERROR; |
lypinator | 0:bb348c97df44 | 704 | } |
lypinator | 0:bb348c97df44 | 705 | } |
lypinator | 0:bb348c97df44 | 706 | |
lypinator | 0:bb348c97df44 | 707 | /** |
lypinator | 0:bb348c97df44 | 708 | * @brief Stop the CAN module and enable access to configuration registers. |
lypinator | 0:bb348c97df44 | 709 | * @param hcan pointer to an CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 710 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 711 | * @retval HAL status |
lypinator | 0:bb348c97df44 | 712 | */ |
lypinator | 0:bb348c97df44 | 713 | HAL_StatusTypeDef HAL_CAN_Stop(CAN_HandleTypeDef *hcan) |
lypinator | 0:bb348c97df44 | 714 | { |
lypinator | 0:bb348c97df44 | 715 | uint32_t tickstart = 0U; |
lypinator | 0:bb348c97df44 | 716 | |
lypinator | 0:bb348c97df44 | 717 | if (hcan->State == HAL_CAN_STATE_LISTENING) |
lypinator | 0:bb348c97df44 | 718 | { |
lypinator | 0:bb348c97df44 | 719 | /* Request initialisation */ |
lypinator | 0:bb348c97df44 | 720 | SET_BIT(hcan->Instance->MCR, CAN_MCR_INRQ); |
lypinator | 0:bb348c97df44 | 721 | |
lypinator | 0:bb348c97df44 | 722 | /* Get tick */ |
lypinator | 0:bb348c97df44 | 723 | tickstart = HAL_GetTick(); |
lypinator | 0:bb348c97df44 | 724 | |
lypinator | 0:bb348c97df44 | 725 | /* Wait the acknowledge */ |
lypinator | 0:bb348c97df44 | 726 | while ((hcan->Instance->MSR & CAN_MSR_INAK) == RESET) |
lypinator | 0:bb348c97df44 | 727 | { |
lypinator | 0:bb348c97df44 | 728 | /* Check for the Timeout */ |
lypinator | 0:bb348c97df44 | 729 | if ((HAL_GetTick() - tickstart) > CAN_TIMEOUT_VALUE) |
lypinator | 0:bb348c97df44 | 730 | { |
lypinator | 0:bb348c97df44 | 731 | /* Update error code */ |
lypinator | 0:bb348c97df44 | 732 | hcan->ErrorCode |= HAL_CAN_ERROR_TIMEOUT; |
lypinator | 0:bb348c97df44 | 733 | |
lypinator | 0:bb348c97df44 | 734 | /* Change CAN state */ |
lypinator | 0:bb348c97df44 | 735 | hcan->State = HAL_CAN_STATE_ERROR; |
lypinator | 0:bb348c97df44 | 736 | |
lypinator | 0:bb348c97df44 | 737 | return HAL_ERROR; |
lypinator | 0:bb348c97df44 | 738 | } |
lypinator | 0:bb348c97df44 | 739 | } |
lypinator | 0:bb348c97df44 | 740 | |
lypinator | 0:bb348c97df44 | 741 | /* Exit from sleep mode */ |
lypinator | 0:bb348c97df44 | 742 | CLEAR_BIT(hcan->Instance->MCR, CAN_MCR_SLEEP); |
lypinator | 0:bb348c97df44 | 743 | |
lypinator | 0:bb348c97df44 | 744 | /* Change CAN peripheral state */ |
lypinator | 0:bb348c97df44 | 745 | hcan->State = HAL_CAN_STATE_READY; |
lypinator | 0:bb348c97df44 | 746 | |
lypinator | 0:bb348c97df44 | 747 | /* Return function status */ |
lypinator | 0:bb348c97df44 | 748 | return HAL_OK; |
lypinator | 0:bb348c97df44 | 749 | } |
lypinator | 0:bb348c97df44 | 750 | else |
lypinator | 0:bb348c97df44 | 751 | { |
lypinator | 0:bb348c97df44 | 752 | /* Update error code */ |
lypinator | 0:bb348c97df44 | 753 | hcan->ErrorCode |= HAL_CAN_ERROR_NOT_STARTED; |
lypinator | 0:bb348c97df44 | 754 | |
lypinator | 0:bb348c97df44 | 755 | return HAL_ERROR; |
lypinator | 0:bb348c97df44 | 756 | } |
lypinator | 0:bb348c97df44 | 757 | } |
lypinator | 0:bb348c97df44 | 758 | |
lypinator | 0:bb348c97df44 | 759 | /** |
lypinator | 0:bb348c97df44 | 760 | * @brief Request the sleep mode (low power) entry. |
lypinator | 0:bb348c97df44 | 761 | * When returning from this function, Sleep mode will be entered |
lypinator | 0:bb348c97df44 | 762 | * as soon as the current CAN activity (transmission or reception |
lypinator | 0:bb348c97df44 | 763 | * of a CAN frame) has been completed. |
lypinator | 0:bb348c97df44 | 764 | * @param hcan pointer to a CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 765 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 766 | * @retval HAL status. |
lypinator | 0:bb348c97df44 | 767 | */ |
lypinator | 0:bb348c97df44 | 768 | HAL_StatusTypeDef HAL_CAN_RequestSleep(CAN_HandleTypeDef *hcan) |
lypinator | 0:bb348c97df44 | 769 | { |
lypinator | 0:bb348c97df44 | 770 | if ((hcan->State == HAL_CAN_STATE_READY) || |
lypinator | 0:bb348c97df44 | 771 | (hcan->State == HAL_CAN_STATE_LISTENING)) |
lypinator | 0:bb348c97df44 | 772 | { |
lypinator | 0:bb348c97df44 | 773 | /* Request Sleep mode */ |
lypinator | 0:bb348c97df44 | 774 | SET_BIT(hcan->Instance->MCR, CAN_MCR_SLEEP); |
lypinator | 0:bb348c97df44 | 775 | |
lypinator | 0:bb348c97df44 | 776 | /* Return function status */ |
lypinator | 0:bb348c97df44 | 777 | return HAL_OK; |
lypinator | 0:bb348c97df44 | 778 | } |
lypinator | 0:bb348c97df44 | 779 | else |
lypinator | 0:bb348c97df44 | 780 | { |
lypinator | 0:bb348c97df44 | 781 | /* Update error code */ |
lypinator | 0:bb348c97df44 | 782 | hcan->ErrorCode |= HAL_CAN_ERROR_NOT_INITIALIZED; |
lypinator | 0:bb348c97df44 | 783 | |
lypinator | 0:bb348c97df44 | 784 | /* Return function status */ |
lypinator | 0:bb348c97df44 | 785 | return HAL_ERROR; |
lypinator | 0:bb348c97df44 | 786 | } |
lypinator | 0:bb348c97df44 | 787 | } |
lypinator | 0:bb348c97df44 | 788 | |
lypinator | 0:bb348c97df44 | 789 | /** |
lypinator | 0:bb348c97df44 | 790 | * @brief Wake up from sleep mode. |
lypinator | 0:bb348c97df44 | 791 | * When returning with HAL_OK status from this function, Sleep mode |
lypinator | 0:bb348c97df44 | 792 | * is exited. |
lypinator | 0:bb348c97df44 | 793 | * @param hcan pointer to a CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 794 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 795 | * @retval HAL status. |
lypinator | 0:bb348c97df44 | 796 | */ |
lypinator | 0:bb348c97df44 | 797 | HAL_StatusTypeDef HAL_CAN_WakeUp(CAN_HandleTypeDef *hcan) |
lypinator | 0:bb348c97df44 | 798 | { |
lypinator | 0:bb348c97df44 | 799 | __IO uint32_t count = 0; |
lypinator | 0:bb348c97df44 | 800 | uint32_t timeout = 1000000U; |
lypinator | 0:bb348c97df44 | 801 | |
lypinator | 0:bb348c97df44 | 802 | if ((hcan->State == HAL_CAN_STATE_READY) || |
lypinator | 0:bb348c97df44 | 803 | (hcan->State == HAL_CAN_STATE_LISTENING)) |
lypinator | 0:bb348c97df44 | 804 | { |
lypinator | 0:bb348c97df44 | 805 | /* Wake up request */ |
lypinator | 0:bb348c97df44 | 806 | CLEAR_BIT(hcan->Instance->MCR, CAN_MCR_SLEEP); |
lypinator | 0:bb348c97df44 | 807 | |
lypinator | 0:bb348c97df44 | 808 | /* Wait sleep mode is exited */ |
lypinator | 0:bb348c97df44 | 809 | do |
lypinator | 0:bb348c97df44 | 810 | { |
lypinator | 0:bb348c97df44 | 811 | /* Check if timeout is reached */ |
lypinator | 0:bb348c97df44 | 812 | if (++count > timeout) |
lypinator | 0:bb348c97df44 | 813 | { |
lypinator | 0:bb348c97df44 | 814 | /* Update error code */ |
lypinator | 0:bb348c97df44 | 815 | hcan->ErrorCode |= HAL_CAN_ERROR_TIMEOUT; |
lypinator | 0:bb348c97df44 | 816 | |
lypinator | 0:bb348c97df44 | 817 | return HAL_ERROR; |
lypinator | 0:bb348c97df44 | 818 | } |
lypinator | 0:bb348c97df44 | 819 | } |
lypinator | 0:bb348c97df44 | 820 | while ((hcan->Instance->MSR & CAN_MSR_SLAK) != RESET); |
lypinator | 0:bb348c97df44 | 821 | |
lypinator | 0:bb348c97df44 | 822 | /* Return function status */ |
lypinator | 0:bb348c97df44 | 823 | return HAL_OK; |
lypinator | 0:bb348c97df44 | 824 | } |
lypinator | 0:bb348c97df44 | 825 | else |
lypinator | 0:bb348c97df44 | 826 | { |
lypinator | 0:bb348c97df44 | 827 | /* Update error code */ |
lypinator | 0:bb348c97df44 | 828 | hcan->ErrorCode |= HAL_CAN_ERROR_NOT_INITIALIZED; |
lypinator | 0:bb348c97df44 | 829 | |
lypinator | 0:bb348c97df44 | 830 | return HAL_ERROR; |
lypinator | 0:bb348c97df44 | 831 | } |
lypinator | 0:bb348c97df44 | 832 | } |
lypinator | 0:bb348c97df44 | 833 | |
lypinator | 0:bb348c97df44 | 834 | /** |
lypinator | 0:bb348c97df44 | 835 | * @brief Check is sleep mode is active. |
lypinator | 0:bb348c97df44 | 836 | * @param hcan pointer to a CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 837 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 838 | * @retval Status |
lypinator | 0:bb348c97df44 | 839 | * - 0 : Sleep mode is not active. |
lypinator | 0:bb348c97df44 | 840 | * - 1 : Sleep mode is active. |
lypinator | 0:bb348c97df44 | 841 | */ |
lypinator | 0:bb348c97df44 | 842 | uint32_t HAL_CAN_IsSleepActive(CAN_HandleTypeDef *hcan) |
lypinator | 0:bb348c97df44 | 843 | { |
lypinator | 0:bb348c97df44 | 844 | uint32_t status = 0U; |
lypinator | 0:bb348c97df44 | 845 | |
lypinator | 0:bb348c97df44 | 846 | if ((hcan->State == HAL_CAN_STATE_READY) || |
lypinator | 0:bb348c97df44 | 847 | (hcan->State == HAL_CAN_STATE_LISTENING)) |
lypinator | 0:bb348c97df44 | 848 | { |
lypinator | 0:bb348c97df44 | 849 | /* Check Sleep mode */ |
lypinator | 0:bb348c97df44 | 850 | if ((hcan->Instance->MSR & CAN_MSR_SLAK) != RESET) |
lypinator | 0:bb348c97df44 | 851 | { |
lypinator | 0:bb348c97df44 | 852 | status = 1U; |
lypinator | 0:bb348c97df44 | 853 | } |
lypinator | 0:bb348c97df44 | 854 | } |
lypinator | 0:bb348c97df44 | 855 | |
lypinator | 0:bb348c97df44 | 856 | /* Return function status */ |
lypinator | 0:bb348c97df44 | 857 | return status; |
lypinator | 0:bb348c97df44 | 858 | } |
lypinator | 0:bb348c97df44 | 859 | |
lypinator | 0:bb348c97df44 | 860 | /** |
lypinator | 0:bb348c97df44 | 861 | * @brief Add a message to the first free Tx mailbox and activate the |
lypinator | 0:bb348c97df44 | 862 | * corresponding transmission request. |
lypinator | 0:bb348c97df44 | 863 | * @param hcan pointer to a CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 864 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 865 | * @param pHeader pointer to a CAN_TxHeaderTypeDef structure. |
lypinator | 0:bb348c97df44 | 866 | * @param aData array containing the payload of the Tx frame. |
lypinator | 0:bb348c97df44 | 867 | * @param pTxMailbox pointer to a variable where the function will return |
lypinator | 0:bb348c97df44 | 868 | * the TxMailbox used to store the Tx message. |
lypinator | 0:bb348c97df44 | 869 | * This parameter can be a value of @arg CAN_Tx_Mailboxes. |
lypinator | 0:bb348c97df44 | 870 | * @retval HAL status |
lypinator | 0:bb348c97df44 | 871 | */ |
lypinator | 0:bb348c97df44 | 872 | HAL_StatusTypeDef HAL_CAN_AddTxMessage(CAN_HandleTypeDef *hcan, CAN_TxHeaderTypeDef *pHeader, uint8_t aData[], uint32_t *pTxMailbox) |
lypinator | 0:bb348c97df44 | 873 | { |
lypinator | 0:bb348c97df44 | 874 | uint32_t transmitmailbox; |
lypinator | 0:bb348c97df44 | 875 | |
lypinator | 0:bb348c97df44 | 876 | /* Check the parameters */ |
lypinator | 0:bb348c97df44 | 877 | assert_param(IS_CAN_IDTYPE(pHeader->IDE)); |
lypinator | 0:bb348c97df44 | 878 | assert_param(IS_CAN_RTR(pHeader->RTR)); |
lypinator | 0:bb348c97df44 | 879 | assert_param(IS_CAN_DLC(pHeader->DLC)); |
lypinator | 0:bb348c97df44 | 880 | if (pHeader->IDE == CAN_ID_STD) |
lypinator | 0:bb348c97df44 | 881 | { |
lypinator | 0:bb348c97df44 | 882 | assert_param(IS_CAN_STDID(pHeader->StdId)); |
lypinator | 0:bb348c97df44 | 883 | } |
lypinator | 0:bb348c97df44 | 884 | else |
lypinator | 0:bb348c97df44 | 885 | { |
lypinator | 0:bb348c97df44 | 886 | assert_param(IS_CAN_EXTID(pHeader->ExtId)); |
lypinator | 0:bb348c97df44 | 887 | } |
lypinator | 0:bb348c97df44 | 888 | assert_param(IS_FUNCTIONAL_STATE(pHeader->TransmitGlobalTime)); |
lypinator | 0:bb348c97df44 | 889 | |
lypinator | 0:bb348c97df44 | 890 | if ((hcan->State == HAL_CAN_STATE_READY) || |
lypinator | 0:bb348c97df44 | 891 | (hcan->State == HAL_CAN_STATE_LISTENING)) |
lypinator | 0:bb348c97df44 | 892 | { |
lypinator | 0:bb348c97df44 | 893 | /* Check that all the Tx mailboxes are not full */ |
lypinator | 0:bb348c97df44 | 894 | if (((hcan->Instance->TSR & CAN_TSR_TME0) != RESET) || |
lypinator | 0:bb348c97df44 | 895 | ((hcan->Instance->TSR & CAN_TSR_TME1) != RESET) || |
lypinator | 0:bb348c97df44 | 896 | ((hcan->Instance->TSR & CAN_TSR_TME2) != RESET)) |
lypinator | 0:bb348c97df44 | 897 | { |
lypinator | 0:bb348c97df44 | 898 | /* Select an empty transmit mailbox */ |
lypinator | 0:bb348c97df44 | 899 | transmitmailbox = (hcan->Instance->TSR & CAN_TSR_CODE) >> CAN_TSR_CODE_Pos; |
lypinator | 0:bb348c97df44 | 900 | |
lypinator | 0:bb348c97df44 | 901 | /* Store the Tx mailbox */ |
lypinator | 0:bb348c97df44 | 902 | *pTxMailbox = 1U << transmitmailbox; |
lypinator | 0:bb348c97df44 | 903 | |
lypinator | 0:bb348c97df44 | 904 | /* Set up the Id */ |
lypinator | 0:bb348c97df44 | 905 | if (pHeader->IDE == CAN_ID_STD) |
lypinator | 0:bb348c97df44 | 906 | { |
lypinator | 0:bb348c97df44 | 907 | hcan->Instance->sTxMailBox[transmitmailbox].TIR = ((pHeader->StdId << CAN_TI0R_STID_Pos) | |
lypinator | 0:bb348c97df44 | 908 | pHeader->RTR); |
lypinator | 0:bb348c97df44 | 909 | } |
lypinator | 0:bb348c97df44 | 910 | else |
lypinator | 0:bb348c97df44 | 911 | { |
lypinator | 0:bb348c97df44 | 912 | hcan->Instance->sTxMailBox[transmitmailbox].TIR = ((pHeader->ExtId << CAN_TI0R_EXID_Pos) | |
lypinator | 0:bb348c97df44 | 913 | pHeader->IDE | |
lypinator | 0:bb348c97df44 | 914 | pHeader->RTR); |
lypinator | 0:bb348c97df44 | 915 | } |
lypinator | 0:bb348c97df44 | 916 | |
lypinator | 0:bb348c97df44 | 917 | /* Set up the DLC */ |
lypinator | 0:bb348c97df44 | 918 | hcan->Instance->sTxMailBox[transmitmailbox].TDTR = (pHeader->DLC); |
lypinator | 0:bb348c97df44 | 919 | |
lypinator | 0:bb348c97df44 | 920 | /* Set up the Transmit Global Time mode */ |
lypinator | 0:bb348c97df44 | 921 | if (pHeader->TransmitGlobalTime == ENABLE) |
lypinator | 0:bb348c97df44 | 922 | { |
lypinator | 0:bb348c97df44 | 923 | SET_BIT(hcan->Instance->sTxMailBox[transmitmailbox].TDTR, CAN_TDT0R_TGT); |
lypinator | 0:bb348c97df44 | 924 | } |
lypinator | 0:bb348c97df44 | 925 | |
lypinator | 0:bb348c97df44 | 926 | /* Set up the data field */ |
lypinator | 0:bb348c97df44 | 927 | WRITE_REG(hcan->Instance->sTxMailBox[transmitmailbox].TDHR, |
lypinator | 0:bb348c97df44 | 928 | ((uint32_t)aData[7] << CAN_TDH0R_DATA7_Pos) | |
lypinator | 0:bb348c97df44 | 929 | ((uint32_t)aData[6] << CAN_TDH0R_DATA6_Pos) | |
lypinator | 0:bb348c97df44 | 930 | ((uint32_t)aData[5] << CAN_TDH0R_DATA5_Pos) | |
lypinator | 0:bb348c97df44 | 931 | ((uint32_t)aData[4] << CAN_TDH0R_DATA4_Pos)); |
lypinator | 0:bb348c97df44 | 932 | WRITE_REG(hcan->Instance->sTxMailBox[transmitmailbox].TDLR, |
lypinator | 0:bb348c97df44 | 933 | ((uint32_t)aData[3] << CAN_TDL0R_DATA3_Pos) | |
lypinator | 0:bb348c97df44 | 934 | ((uint32_t)aData[2] << CAN_TDL0R_DATA2_Pos) | |
lypinator | 0:bb348c97df44 | 935 | ((uint32_t)aData[1] << CAN_TDL0R_DATA1_Pos) | |
lypinator | 0:bb348c97df44 | 936 | ((uint32_t)aData[0] << CAN_TDL0R_DATA0_Pos)); |
lypinator | 0:bb348c97df44 | 937 | |
lypinator | 0:bb348c97df44 | 938 | /* Request transmission */ |
lypinator | 0:bb348c97df44 | 939 | SET_BIT(hcan->Instance->sTxMailBox[transmitmailbox].TIR, CAN_TI0R_TXRQ); |
lypinator | 0:bb348c97df44 | 940 | |
lypinator | 0:bb348c97df44 | 941 | /* Return function status */ |
lypinator | 0:bb348c97df44 | 942 | return HAL_OK; |
lypinator | 0:bb348c97df44 | 943 | } |
lypinator | 0:bb348c97df44 | 944 | else |
lypinator | 0:bb348c97df44 | 945 | { |
lypinator | 0:bb348c97df44 | 946 | /* Update error code */ |
lypinator | 0:bb348c97df44 | 947 | hcan->ErrorCode |= HAL_CAN_ERROR_PARAM; |
lypinator | 0:bb348c97df44 | 948 | |
lypinator | 0:bb348c97df44 | 949 | return HAL_ERROR; |
lypinator | 0:bb348c97df44 | 950 | } |
lypinator | 0:bb348c97df44 | 951 | } |
lypinator | 0:bb348c97df44 | 952 | else |
lypinator | 0:bb348c97df44 | 953 | { |
lypinator | 0:bb348c97df44 | 954 | /* Update error code */ |
lypinator | 0:bb348c97df44 | 955 | hcan->ErrorCode |= HAL_CAN_ERROR_NOT_INITIALIZED; |
lypinator | 0:bb348c97df44 | 956 | |
lypinator | 0:bb348c97df44 | 957 | return HAL_ERROR; |
lypinator | 0:bb348c97df44 | 958 | } |
lypinator | 0:bb348c97df44 | 959 | } |
lypinator | 0:bb348c97df44 | 960 | |
lypinator | 0:bb348c97df44 | 961 | /** |
lypinator | 0:bb348c97df44 | 962 | * @brief Abort transmission requests |
lypinator | 0:bb348c97df44 | 963 | * @param hcan pointer to an CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 964 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 965 | * @param TxMailboxes List of the Tx Mailboxes to abort. |
lypinator | 0:bb348c97df44 | 966 | * This parameter can be any combination of @arg CAN_Tx_Mailboxes. |
lypinator | 0:bb348c97df44 | 967 | * @retval HAL status |
lypinator | 0:bb348c97df44 | 968 | */ |
lypinator | 0:bb348c97df44 | 969 | HAL_StatusTypeDef HAL_CAN_AbortTxRequest(CAN_HandleTypeDef *hcan, uint32_t TxMailboxes) |
lypinator | 0:bb348c97df44 | 970 | { |
lypinator | 0:bb348c97df44 | 971 | /* Check function parameters */ |
lypinator | 0:bb348c97df44 | 972 | assert_param(IS_CAN_TX_MAILBOX_LIST(TxMailboxes)); |
lypinator | 0:bb348c97df44 | 973 | |
lypinator | 0:bb348c97df44 | 974 | if ((hcan->State == HAL_CAN_STATE_READY) || |
lypinator | 0:bb348c97df44 | 975 | (hcan->State == HAL_CAN_STATE_LISTENING)) |
lypinator | 0:bb348c97df44 | 976 | { |
lypinator | 0:bb348c97df44 | 977 | /* Check Tx Mailbox 0 */ |
lypinator | 0:bb348c97df44 | 978 | if ((TxMailboxes & CAN_TX_MAILBOX0) != RESET) |
lypinator | 0:bb348c97df44 | 979 | { |
lypinator | 0:bb348c97df44 | 980 | /* Add cancellation request for Tx Mailbox 0 */ |
lypinator | 0:bb348c97df44 | 981 | SET_BIT(hcan->Instance->TSR, CAN_TSR_ABRQ0); |
lypinator | 0:bb348c97df44 | 982 | } |
lypinator | 0:bb348c97df44 | 983 | |
lypinator | 0:bb348c97df44 | 984 | /* Check Tx Mailbox 1 */ |
lypinator | 0:bb348c97df44 | 985 | if ((TxMailboxes & CAN_TX_MAILBOX1) != RESET) |
lypinator | 0:bb348c97df44 | 986 | { |
lypinator | 0:bb348c97df44 | 987 | /* Add cancellation request for Tx Mailbox 1 */ |
lypinator | 0:bb348c97df44 | 988 | SET_BIT(hcan->Instance->TSR, CAN_TSR_ABRQ1); |
lypinator | 0:bb348c97df44 | 989 | } |
lypinator | 0:bb348c97df44 | 990 | |
lypinator | 0:bb348c97df44 | 991 | /* Check Tx Mailbox 2 */ |
lypinator | 0:bb348c97df44 | 992 | if ((TxMailboxes & CAN_TX_MAILBOX2) != RESET) |
lypinator | 0:bb348c97df44 | 993 | { |
lypinator | 0:bb348c97df44 | 994 | /* Add cancellation request for Tx Mailbox 2 */ |
lypinator | 0:bb348c97df44 | 995 | SET_BIT(hcan->Instance->TSR, CAN_TSR_ABRQ2); |
lypinator | 0:bb348c97df44 | 996 | } |
lypinator | 0:bb348c97df44 | 997 | |
lypinator | 0:bb348c97df44 | 998 | /* Return function status */ |
lypinator | 0:bb348c97df44 | 999 | return HAL_OK; |
lypinator | 0:bb348c97df44 | 1000 | } |
lypinator | 0:bb348c97df44 | 1001 | else |
lypinator | 0:bb348c97df44 | 1002 | { |
lypinator | 0:bb348c97df44 | 1003 | /* Update error code */ |
lypinator | 0:bb348c97df44 | 1004 | hcan->ErrorCode |= HAL_CAN_ERROR_NOT_INITIALIZED; |
lypinator | 0:bb348c97df44 | 1005 | |
lypinator | 0:bb348c97df44 | 1006 | return HAL_ERROR; |
lypinator | 0:bb348c97df44 | 1007 | } |
lypinator | 0:bb348c97df44 | 1008 | } |
lypinator | 0:bb348c97df44 | 1009 | |
lypinator | 0:bb348c97df44 | 1010 | /** |
lypinator | 0:bb348c97df44 | 1011 | * @brief Return Tx Mailboxes free level: number of free Tx Mailboxes. |
lypinator | 0:bb348c97df44 | 1012 | * @param hcan pointer to a CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 1013 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 1014 | * @retval Number of free Tx Mailboxes. |
lypinator | 0:bb348c97df44 | 1015 | */ |
lypinator | 0:bb348c97df44 | 1016 | uint32_t HAL_CAN_GetTxMailboxesFreeLevel(CAN_HandleTypeDef *hcan) |
lypinator | 0:bb348c97df44 | 1017 | { |
lypinator | 0:bb348c97df44 | 1018 | uint32_t freelevel = 0U; |
lypinator | 0:bb348c97df44 | 1019 | |
lypinator | 0:bb348c97df44 | 1020 | if ((hcan->State == HAL_CAN_STATE_READY) || |
lypinator | 0:bb348c97df44 | 1021 | (hcan->State == HAL_CAN_STATE_LISTENING)) |
lypinator | 0:bb348c97df44 | 1022 | { |
lypinator | 0:bb348c97df44 | 1023 | /* Check Tx Mailbox 0 status */ |
lypinator | 0:bb348c97df44 | 1024 | if ((hcan->Instance->TSR & CAN_TSR_TME0) != RESET) |
lypinator | 0:bb348c97df44 | 1025 | { |
lypinator | 0:bb348c97df44 | 1026 | freelevel++; |
lypinator | 0:bb348c97df44 | 1027 | } |
lypinator | 0:bb348c97df44 | 1028 | |
lypinator | 0:bb348c97df44 | 1029 | /* Check Tx Mailbox 1 status */ |
lypinator | 0:bb348c97df44 | 1030 | if ((hcan->Instance->TSR & CAN_TSR_TME1) != RESET) |
lypinator | 0:bb348c97df44 | 1031 | { |
lypinator | 0:bb348c97df44 | 1032 | freelevel++; |
lypinator | 0:bb348c97df44 | 1033 | } |
lypinator | 0:bb348c97df44 | 1034 | |
lypinator | 0:bb348c97df44 | 1035 | /* Check Tx Mailbox 2 status */ |
lypinator | 0:bb348c97df44 | 1036 | if ((hcan->Instance->TSR & CAN_TSR_TME2) != RESET) |
lypinator | 0:bb348c97df44 | 1037 | { |
lypinator | 0:bb348c97df44 | 1038 | freelevel++; |
lypinator | 0:bb348c97df44 | 1039 | } |
lypinator | 0:bb348c97df44 | 1040 | } |
lypinator | 0:bb348c97df44 | 1041 | |
lypinator | 0:bb348c97df44 | 1042 | /* Return Tx Mailboxes free level */ |
lypinator | 0:bb348c97df44 | 1043 | return freelevel; |
lypinator | 0:bb348c97df44 | 1044 | } |
lypinator | 0:bb348c97df44 | 1045 | |
lypinator | 0:bb348c97df44 | 1046 | /** |
lypinator | 0:bb348c97df44 | 1047 | * @brief Check if a transmission request is pending on the selected Tx |
lypinator | 0:bb348c97df44 | 1048 | * Mailboxes. |
lypinator | 0:bb348c97df44 | 1049 | * @param hcan pointer to an CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 1050 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 1051 | * @param TxMailboxes List of Tx Mailboxes to check. |
lypinator | 0:bb348c97df44 | 1052 | * This parameter can be any combination of @arg CAN_Tx_Mailboxes. |
lypinator | 0:bb348c97df44 | 1053 | * @retval Status |
lypinator | 0:bb348c97df44 | 1054 | * - 0 : No pending transmission request on any selected Tx Mailboxes. |
lypinator | 0:bb348c97df44 | 1055 | * - 1 : Pending transmission request on at least one of the selected |
lypinator | 0:bb348c97df44 | 1056 | * Tx Mailbox. |
lypinator | 0:bb348c97df44 | 1057 | */ |
lypinator | 0:bb348c97df44 | 1058 | uint32_t HAL_CAN_IsTxMessagePending(CAN_HandleTypeDef *hcan, uint32_t TxMailboxes) |
lypinator | 0:bb348c97df44 | 1059 | { |
lypinator | 0:bb348c97df44 | 1060 | uint32_t status = 0U; |
lypinator | 0:bb348c97df44 | 1061 | |
lypinator | 0:bb348c97df44 | 1062 | /* Check function parameters */ |
lypinator | 0:bb348c97df44 | 1063 | assert_param(IS_CAN_TX_MAILBOX_LIST(TxMailboxes)); |
lypinator | 0:bb348c97df44 | 1064 | |
lypinator | 0:bb348c97df44 | 1065 | if ((hcan->State == HAL_CAN_STATE_READY) || |
lypinator | 0:bb348c97df44 | 1066 | (hcan->State == HAL_CAN_STATE_LISTENING)) |
lypinator | 0:bb348c97df44 | 1067 | { |
lypinator | 0:bb348c97df44 | 1068 | /* Check pending transmission request on the selected Tx Mailboxes */ |
lypinator | 0:bb348c97df44 | 1069 | if ((hcan->Instance->TSR & (TxMailboxes << CAN_TSR_TME0_Pos)) != (TxMailboxes << CAN_TSR_TME0_Pos)) |
lypinator | 0:bb348c97df44 | 1070 | { |
lypinator | 0:bb348c97df44 | 1071 | status = 1U; |
lypinator | 0:bb348c97df44 | 1072 | } |
lypinator | 0:bb348c97df44 | 1073 | } |
lypinator | 0:bb348c97df44 | 1074 | |
lypinator | 0:bb348c97df44 | 1075 | /* Return status */ |
lypinator | 0:bb348c97df44 | 1076 | return status; |
lypinator | 0:bb348c97df44 | 1077 | } |
lypinator | 0:bb348c97df44 | 1078 | |
lypinator | 0:bb348c97df44 | 1079 | /** |
lypinator | 0:bb348c97df44 | 1080 | * @brief Return timestamp of Tx message sent, if time triggered communication |
lypinator | 0:bb348c97df44 | 1081 | mode is enabled. |
lypinator | 0:bb348c97df44 | 1082 | * @param hcan pointer to a CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 1083 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 1084 | * @param TxMailbox Tx Mailbox where the timestamp of message sent will be |
lypinator | 0:bb348c97df44 | 1085 | * read. |
lypinator | 0:bb348c97df44 | 1086 | * This parameter can be one value of @arg CAN_Tx_Mailboxes. |
lypinator | 0:bb348c97df44 | 1087 | * @retval Timestamp of message sent from Tx Mailbox. |
lypinator | 0:bb348c97df44 | 1088 | */ |
lypinator | 0:bb348c97df44 | 1089 | uint32_t HAL_CAN_GetTxTimestamp(CAN_HandleTypeDef *hcan, uint32_t TxMailbox) |
lypinator | 0:bb348c97df44 | 1090 | { |
lypinator | 0:bb348c97df44 | 1091 | uint32_t timestamp = 0U; |
lypinator | 0:bb348c97df44 | 1092 | uint32_t transmitmailbox; |
lypinator | 0:bb348c97df44 | 1093 | |
lypinator | 0:bb348c97df44 | 1094 | /* Check function parameters */ |
lypinator | 0:bb348c97df44 | 1095 | assert_param(IS_CAN_TX_MAILBOX(TxMailbox)); |
lypinator | 0:bb348c97df44 | 1096 | |
lypinator | 0:bb348c97df44 | 1097 | if ((hcan->State == HAL_CAN_STATE_READY) || |
lypinator | 0:bb348c97df44 | 1098 | (hcan->State == HAL_CAN_STATE_LISTENING)) |
lypinator | 0:bb348c97df44 | 1099 | { |
lypinator | 0:bb348c97df44 | 1100 | /* Select the Tx mailbox */ |
lypinator | 0:bb348c97df44 | 1101 | transmitmailbox = POSITION_VAL(TxMailbox); |
lypinator | 0:bb348c97df44 | 1102 | |
lypinator | 0:bb348c97df44 | 1103 | /* Get timestamp */ |
lypinator | 0:bb348c97df44 | 1104 | timestamp = (hcan->Instance->sTxMailBox[transmitmailbox].TDTR & CAN_TDT0R_TIME) >> CAN_TDT0R_TIME_Pos; |
lypinator | 0:bb348c97df44 | 1105 | } |
lypinator | 0:bb348c97df44 | 1106 | |
lypinator | 0:bb348c97df44 | 1107 | /* Return the timestamp */ |
lypinator | 0:bb348c97df44 | 1108 | return timestamp; |
lypinator | 0:bb348c97df44 | 1109 | } |
lypinator | 0:bb348c97df44 | 1110 | |
lypinator | 0:bb348c97df44 | 1111 | /** |
lypinator | 0:bb348c97df44 | 1112 | * @brief Get an CAN frame from the Rx FIFO zone into the message RAM. |
lypinator | 0:bb348c97df44 | 1113 | * @param hcan pointer to an CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 1114 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 1115 | * @param RxFifo Fifo number of the received message to be read. |
lypinator | 0:bb348c97df44 | 1116 | * This parameter can be a value of @arg CAN_receive_FIFO_number. |
lypinator | 0:bb348c97df44 | 1117 | * @param pHeader pointer to a CAN_RxHeaderTypeDef structure where the header |
lypinator | 0:bb348c97df44 | 1118 | * of the Rx frame will be stored. |
lypinator | 0:bb348c97df44 | 1119 | * @param aData array where the payload of the Rx frame will be stored. |
lypinator | 0:bb348c97df44 | 1120 | * @retval HAL status |
lypinator | 0:bb348c97df44 | 1121 | */ |
lypinator | 0:bb348c97df44 | 1122 | HAL_StatusTypeDef HAL_CAN_GetRxMessage(CAN_HandleTypeDef *hcan, uint32_t RxFifo, CAN_RxHeaderTypeDef *pHeader, uint8_t aData[]) |
lypinator | 0:bb348c97df44 | 1123 | { |
lypinator | 0:bb348c97df44 | 1124 | assert_param(IS_CAN_RX_FIFO(RxFifo)); |
lypinator | 0:bb348c97df44 | 1125 | |
lypinator | 0:bb348c97df44 | 1126 | if ((hcan->State == HAL_CAN_STATE_READY) || |
lypinator | 0:bb348c97df44 | 1127 | (hcan->State == HAL_CAN_STATE_LISTENING)) |
lypinator | 0:bb348c97df44 | 1128 | { |
lypinator | 0:bb348c97df44 | 1129 | /* Check the Rx FIFO */ |
lypinator | 0:bb348c97df44 | 1130 | if (RxFifo == CAN_RX_FIFO0) /* Rx element is assigned to Rx FIFO 0 */ |
lypinator | 0:bb348c97df44 | 1131 | { |
lypinator | 0:bb348c97df44 | 1132 | /* Check that the Rx FIFO 0 is not empty */ |
lypinator | 0:bb348c97df44 | 1133 | if ((hcan->Instance->RF0R & CAN_RF0R_FMP0) == RESET) |
lypinator | 0:bb348c97df44 | 1134 | { |
lypinator | 0:bb348c97df44 | 1135 | /* Update error code */ |
lypinator | 0:bb348c97df44 | 1136 | hcan->ErrorCode |= HAL_CAN_ERROR_PARAM; |
lypinator | 0:bb348c97df44 | 1137 | |
lypinator | 0:bb348c97df44 | 1138 | return HAL_ERROR; |
lypinator | 0:bb348c97df44 | 1139 | } |
lypinator | 0:bb348c97df44 | 1140 | } |
lypinator | 0:bb348c97df44 | 1141 | else if (RxFifo == CAN_RX_FIFO1) /* Rx element is assigned to Rx FIFO 1 */ |
lypinator | 0:bb348c97df44 | 1142 | { |
lypinator | 0:bb348c97df44 | 1143 | /* Check that the Rx FIFO 1 is not empty */ |
lypinator | 0:bb348c97df44 | 1144 | if ((hcan->Instance->RF1R & CAN_RF1R_FMP1) == RESET) |
lypinator | 0:bb348c97df44 | 1145 | { |
lypinator | 0:bb348c97df44 | 1146 | /* Update error code */ |
lypinator | 0:bb348c97df44 | 1147 | hcan->ErrorCode |= HAL_CAN_ERROR_PARAM; |
lypinator | 0:bb348c97df44 | 1148 | |
lypinator | 0:bb348c97df44 | 1149 | return HAL_ERROR; |
lypinator | 0:bb348c97df44 | 1150 | } |
lypinator | 0:bb348c97df44 | 1151 | } |
lypinator | 0:bb348c97df44 | 1152 | |
lypinator | 0:bb348c97df44 | 1153 | /* Get the header */ |
lypinator | 0:bb348c97df44 | 1154 | pHeader->IDE = CAN_RI0R_IDE & hcan->Instance->sFIFOMailBox[RxFifo].RIR; |
lypinator | 0:bb348c97df44 | 1155 | if (pHeader->IDE == CAN_ID_STD) |
lypinator | 0:bb348c97df44 | 1156 | { |
lypinator | 0:bb348c97df44 | 1157 | pHeader->StdId = (CAN_RI0R_STID & hcan->Instance->sFIFOMailBox[RxFifo].RIR) >> CAN_TI0R_STID_Pos; |
lypinator | 0:bb348c97df44 | 1158 | } |
lypinator | 0:bb348c97df44 | 1159 | else |
lypinator | 0:bb348c97df44 | 1160 | { |
lypinator | 0:bb348c97df44 | 1161 | pHeader->ExtId = ((CAN_RI0R_EXID | CAN_RI0R_STID) & hcan->Instance->sFIFOMailBox[RxFifo].RIR) >> CAN_RI0R_EXID_Pos; |
lypinator | 0:bb348c97df44 | 1162 | } |
lypinator | 0:bb348c97df44 | 1163 | pHeader->RTR = (CAN_RI0R_RTR & hcan->Instance->sFIFOMailBox[RxFifo].RIR) >> CAN_RI0R_RTR_Pos; |
lypinator | 0:bb348c97df44 | 1164 | pHeader->DLC = (CAN_RDT0R_DLC & hcan->Instance->sFIFOMailBox[RxFifo].RDTR) >> CAN_RDT0R_DLC_Pos; |
lypinator | 0:bb348c97df44 | 1165 | pHeader->FilterMatchIndex = (CAN_RDT0R_FMI & hcan->Instance->sFIFOMailBox[RxFifo].RDTR) >> CAN_RDT0R_FMI_Pos; |
lypinator | 0:bb348c97df44 | 1166 | pHeader->Timestamp = (CAN_RDT0R_TIME & hcan->Instance->sFIFOMailBox[RxFifo].RDTR) >> CAN_RDT0R_TIME_Pos; |
lypinator | 0:bb348c97df44 | 1167 | |
lypinator | 0:bb348c97df44 | 1168 | /* Get the data */ |
lypinator | 0:bb348c97df44 | 1169 | aData[0] = (CAN_RDL0R_DATA0 & hcan->Instance->sFIFOMailBox[RxFifo].RDLR) >> CAN_RDL0R_DATA0_Pos; |
lypinator | 0:bb348c97df44 | 1170 | aData[1] = (CAN_RDL0R_DATA1 & hcan->Instance->sFIFOMailBox[RxFifo].RDLR) >> CAN_RDL0R_DATA1_Pos; |
lypinator | 0:bb348c97df44 | 1171 | aData[2] = (CAN_RDL0R_DATA2 & hcan->Instance->sFIFOMailBox[RxFifo].RDLR) >> CAN_RDL0R_DATA2_Pos; |
lypinator | 0:bb348c97df44 | 1172 | aData[3] = (CAN_RDL0R_DATA3 & hcan->Instance->sFIFOMailBox[RxFifo].RDLR) >> CAN_RDL0R_DATA3_Pos; |
lypinator | 0:bb348c97df44 | 1173 | aData[4] = (CAN_RDH0R_DATA4 & hcan->Instance->sFIFOMailBox[RxFifo].RDHR) >> CAN_RDH0R_DATA4_Pos; |
lypinator | 0:bb348c97df44 | 1174 | aData[5] = (CAN_RDH0R_DATA5 & hcan->Instance->sFIFOMailBox[RxFifo].RDHR) >> CAN_RDH0R_DATA5_Pos; |
lypinator | 0:bb348c97df44 | 1175 | aData[6] = (CAN_RDH0R_DATA6 & hcan->Instance->sFIFOMailBox[RxFifo].RDHR) >> CAN_RDH0R_DATA6_Pos; |
lypinator | 0:bb348c97df44 | 1176 | aData[7] = (CAN_RDH0R_DATA7 & hcan->Instance->sFIFOMailBox[RxFifo].RDHR) >> CAN_RDH0R_DATA7_Pos; |
lypinator | 0:bb348c97df44 | 1177 | |
lypinator | 0:bb348c97df44 | 1178 | /* Release the FIFO */ |
lypinator | 0:bb348c97df44 | 1179 | if (RxFifo == CAN_RX_FIFO0) /* Rx element is assigned to Rx FIFO 0 */ |
lypinator | 0:bb348c97df44 | 1180 | { |
lypinator | 0:bb348c97df44 | 1181 | /* Release RX FIFO 0 */ |
lypinator | 0:bb348c97df44 | 1182 | SET_BIT(hcan->Instance->RF0R, CAN_RF0R_RFOM0); |
lypinator | 0:bb348c97df44 | 1183 | } |
lypinator | 0:bb348c97df44 | 1184 | else if (RxFifo == CAN_RX_FIFO1) /* Rx element is assigned to Rx FIFO 1 */ |
lypinator | 0:bb348c97df44 | 1185 | { |
lypinator | 0:bb348c97df44 | 1186 | /* Release RX FIFO 1 */ |
lypinator | 0:bb348c97df44 | 1187 | SET_BIT(hcan->Instance->RF1R, CAN_RF1R_RFOM1); |
lypinator | 0:bb348c97df44 | 1188 | } |
lypinator | 0:bb348c97df44 | 1189 | |
lypinator | 0:bb348c97df44 | 1190 | /* Return function status */ |
lypinator | 0:bb348c97df44 | 1191 | return HAL_OK; |
lypinator | 0:bb348c97df44 | 1192 | } |
lypinator | 0:bb348c97df44 | 1193 | else |
lypinator | 0:bb348c97df44 | 1194 | { |
lypinator | 0:bb348c97df44 | 1195 | /* Update error code */ |
lypinator | 0:bb348c97df44 | 1196 | hcan->ErrorCode |= HAL_CAN_ERROR_NOT_INITIALIZED; |
lypinator | 0:bb348c97df44 | 1197 | |
lypinator | 0:bb348c97df44 | 1198 | return HAL_ERROR; |
lypinator | 0:bb348c97df44 | 1199 | } |
lypinator | 0:bb348c97df44 | 1200 | } |
lypinator | 0:bb348c97df44 | 1201 | |
lypinator | 0:bb348c97df44 | 1202 | /** |
lypinator | 0:bb348c97df44 | 1203 | * @brief Return Rx FIFO fill level. |
lypinator | 0:bb348c97df44 | 1204 | * @param hcan pointer to an CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 1205 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 1206 | * @param RxFifo Rx FIFO. |
lypinator | 0:bb348c97df44 | 1207 | * This parameter can be a value of @arg CAN_receive_FIFO_number. |
lypinator | 0:bb348c97df44 | 1208 | * @retval Number of messages available in Rx FIFO. |
lypinator | 0:bb348c97df44 | 1209 | */ |
lypinator | 0:bb348c97df44 | 1210 | uint32_t HAL_CAN_GetRxFifoFillLevel(CAN_HandleTypeDef *hcan, uint32_t RxFifo) |
lypinator | 0:bb348c97df44 | 1211 | { |
lypinator | 0:bb348c97df44 | 1212 | uint32_t filllevel = 0U; |
lypinator | 0:bb348c97df44 | 1213 | |
lypinator | 0:bb348c97df44 | 1214 | /* Check function parameters */ |
lypinator | 0:bb348c97df44 | 1215 | assert_param(IS_CAN_RX_FIFO(RxFifo)); |
lypinator | 0:bb348c97df44 | 1216 | |
lypinator | 0:bb348c97df44 | 1217 | if ((hcan->State == HAL_CAN_STATE_READY) || |
lypinator | 0:bb348c97df44 | 1218 | (hcan->State == HAL_CAN_STATE_LISTENING)) |
lypinator | 0:bb348c97df44 | 1219 | { |
lypinator | 0:bb348c97df44 | 1220 | if (RxFifo == CAN_RX_FIFO0) |
lypinator | 0:bb348c97df44 | 1221 | { |
lypinator | 0:bb348c97df44 | 1222 | filllevel = hcan->Instance->RF0R & CAN_RF0R_FMP0; |
lypinator | 0:bb348c97df44 | 1223 | } |
lypinator | 0:bb348c97df44 | 1224 | else /* RxFifo == CAN_RX_FIFO1 */ |
lypinator | 0:bb348c97df44 | 1225 | { |
lypinator | 0:bb348c97df44 | 1226 | filllevel = hcan->Instance->RF1R & CAN_RF1R_FMP1; |
lypinator | 0:bb348c97df44 | 1227 | } |
lypinator | 0:bb348c97df44 | 1228 | } |
lypinator | 0:bb348c97df44 | 1229 | |
lypinator | 0:bb348c97df44 | 1230 | /* Return Rx FIFO fill level */ |
lypinator | 0:bb348c97df44 | 1231 | return filllevel; |
lypinator | 0:bb348c97df44 | 1232 | } |
lypinator | 0:bb348c97df44 | 1233 | |
lypinator | 0:bb348c97df44 | 1234 | /** |
lypinator | 0:bb348c97df44 | 1235 | * @} |
lypinator | 0:bb348c97df44 | 1236 | */ |
lypinator | 0:bb348c97df44 | 1237 | |
lypinator | 0:bb348c97df44 | 1238 | /** @defgroup CAN_Exported_Functions_Group4 Interrupts management |
lypinator | 0:bb348c97df44 | 1239 | * @brief Interrupts management |
lypinator | 0:bb348c97df44 | 1240 | * |
lypinator | 0:bb348c97df44 | 1241 | @verbatim |
lypinator | 0:bb348c97df44 | 1242 | ============================================================================== |
lypinator | 0:bb348c97df44 | 1243 | ##### Interrupts management ##### |
lypinator | 0:bb348c97df44 | 1244 | ============================================================================== |
lypinator | 0:bb348c97df44 | 1245 | [..] This section provides functions allowing to: |
lypinator | 0:bb348c97df44 | 1246 | (+) HAL_CAN_ActivateNotification : Enable interrupts |
lypinator | 0:bb348c97df44 | 1247 | (+) HAL_CAN_DeactivateNotification : Disable interrupts |
lypinator | 0:bb348c97df44 | 1248 | (+) HAL_CAN_IRQHandler : Handles CAN interrupt request |
lypinator | 0:bb348c97df44 | 1249 | |
lypinator | 0:bb348c97df44 | 1250 | @endverbatim |
lypinator | 0:bb348c97df44 | 1251 | * @{ |
lypinator | 0:bb348c97df44 | 1252 | */ |
lypinator | 0:bb348c97df44 | 1253 | |
lypinator | 0:bb348c97df44 | 1254 | /** |
lypinator | 0:bb348c97df44 | 1255 | * @brief Enable interrupts. |
lypinator | 0:bb348c97df44 | 1256 | * @param hcan pointer to an CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 1257 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 1258 | * @param ActiveITs indicates which interrupts will be enabled. |
lypinator | 0:bb348c97df44 | 1259 | * This parameter can be any combination of @arg CAN_Interrupts. |
lypinator | 0:bb348c97df44 | 1260 | * @retval HAL status |
lypinator | 0:bb348c97df44 | 1261 | */ |
lypinator | 0:bb348c97df44 | 1262 | HAL_StatusTypeDef HAL_CAN_ActivateNotification(CAN_HandleTypeDef *hcan, uint32_t ActiveITs) |
lypinator | 0:bb348c97df44 | 1263 | { |
lypinator | 0:bb348c97df44 | 1264 | /* Check function parameters */ |
lypinator | 0:bb348c97df44 | 1265 | assert_param(IS_CAN_IT(ActiveITs)); |
lypinator | 0:bb348c97df44 | 1266 | |
lypinator | 0:bb348c97df44 | 1267 | if ((hcan->State == HAL_CAN_STATE_READY) || |
lypinator | 0:bb348c97df44 | 1268 | (hcan->State == HAL_CAN_STATE_LISTENING)) |
lypinator | 0:bb348c97df44 | 1269 | { |
lypinator | 0:bb348c97df44 | 1270 | /* Enable the selected interrupts */ |
lypinator | 0:bb348c97df44 | 1271 | __HAL_CAN_ENABLE_IT(hcan, ActiveITs); |
lypinator | 0:bb348c97df44 | 1272 | |
lypinator | 0:bb348c97df44 | 1273 | /* Return function status */ |
lypinator | 0:bb348c97df44 | 1274 | return HAL_OK; |
lypinator | 0:bb348c97df44 | 1275 | } |
lypinator | 0:bb348c97df44 | 1276 | else |
lypinator | 0:bb348c97df44 | 1277 | { |
lypinator | 0:bb348c97df44 | 1278 | /* Update error code */ |
lypinator | 0:bb348c97df44 | 1279 | hcan->ErrorCode |= HAL_CAN_ERROR_NOT_INITIALIZED; |
lypinator | 0:bb348c97df44 | 1280 | |
lypinator | 0:bb348c97df44 | 1281 | return HAL_ERROR; |
lypinator | 0:bb348c97df44 | 1282 | } |
lypinator | 0:bb348c97df44 | 1283 | } |
lypinator | 0:bb348c97df44 | 1284 | |
lypinator | 0:bb348c97df44 | 1285 | /** |
lypinator | 0:bb348c97df44 | 1286 | * @brief Disable interrupts. |
lypinator | 0:bb348c97df44 | 1287 | * @param hcan pointer to an CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 1288 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 1289 | * @param InactiveITs indicates which interrupts will be disabled. |
lypinator | 0:bb348c97df44 | 1290 | * This parameter can be any combination of @arg CAN_Interrupts. |
lypinator | 0:bb348c97df44 | 1291 | * @retval HAL status |
lypinator | 0:bb348c97df44 | 1292 | */ |
lypinator | 0:bb348c97df44 | 1293 | HAL_StatusTypeDef HAL_CAN_DeactivateNotification(CAN_HandleTypeDef *hcan, uint32_t InactiveITs) |
lypinator | 0:bb348c97df44 | 1294 | { |
lypinator | 0:bb348c97df44 | 1295 | /* Check function parameters */ |
lypinator | 0:bb348c97df44 | 1296 | assert_param(IS_CAN_IT(InactiveITs)); |
lypinator | 0:bb348c97df44 | 1297 | |
lypinator | 0:bb348c97df44 | 1298 | if ((hcan->State == HAL_CAN_STATE_READY) || |
lypinator | 0:bb348c97df44 | 1299 | (hcan->State == HAL_CAN_STATE_LISTENING)) |
lypinator | 0:bb348c97df44 | 1300 | { |
lypinator | 0:bb348c97df44 | 1301 | /* Disable the selected interrupts */ |
lypinator | 0:bb348c97df44 | 1302 | __HAL_CAN_DISABLE_IT(hcan, InactiveITs); |
lypinator | 0:bb348c97df44 | 1303 | |
lypinator | 0:bb348c97df44 | 1304 | /* Return function status */ |
lypinator | 0:bb348c97df44 | 1305 | return HAL_OK; |
lypinator | 0:bb348c97df44 | 1306 | } |
lypinator | 0:bb348c97df44 | 1307 | else |
lypinator | 0:bb348c97df44 | 1308 | { |
lypinator | 0:bb348c97df44 | 1309 | /* Update error code */ |
lypinator | 0:bb348c97df44 | 1310 | hcan->ErrorCode |= HAL_CAN_ERROR_NOT_INITIALIZED; |
lypinator | 0:bb348c97df44 | 1311 | |
lypinator | 0:bb348c97df44 | 1312 | return HAL_ERROR; |
lypinator | 0:bb348c97df44 | 1313 | } |
lypinator | 0:bb348c97df44 | 1314 | } |
lypinator | 0:bb348c97df44 | 1315 | |
lypinator | 0:bb348c97df44 | 1316 | /** |
lypinator | 0:bb348c97df44 | 1317 | * @brief Handles CAN interrupt request |
lypinator | 0:bb348c97df44 | 1318 | * @param hcan pointer to a CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 1319 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 1320 | * @retval None |
lypinator | 0:bb348c97df44 | 1321 | */ |
lypinator | 0:bb348c97df44 | 1322 | void HAL_CAN_IRQHandler(CAN_HandleTypeDef *hcan) |
lypinator | 0:bb348c97df44 | 1323 | { |
lypinator | 0:bb348c97df44 | 1324 | uint32_t errorcode = HAL_CAN_ERROR_NONE; |
lypinator | 0:bb348c97df44 | 1325 | uint32_t interrupts = READ_REG(hcan->Instance->IER); |
lypinator | 0:bb348c97df44 | 1326 | uint32_t msrflags = READ_REG(hcan->Instance->MSR); |
lypinator | 0:bb348c97df44 | 1327 | uint32_t tsrflags = READ_REG(hcan->Instance->TSR); |
lypinator | 0:bb348c97df44 | 1328 | uint32_t rf0rflags = READ_REG(hcan->Instance->RF0R); |
lypinator | 0:bb348c97df44 | 1329 | uint32_t rf1rflags = READ_REG(hcan->Instance->RF1R); |
lypinator | 0:bb348c97df44 | 1330 | uint32_t esrflags = READ_REG(hcan->Instance->ESR); |
lypinator | 0:bb348c97df44 | 1331 | |
lypinator | 0:bb348c97df44 | 1332 | /* Transmit Mailbox empty interrupt management *****************************/ |
lypinator | 0:bb348c97df44 | 1333 | if ((interrupts & CAN_IT_TX_MAILBOX_EMPTY) != RESET) |
lypinator | 0:bb348c97df44 | 1334 | { |
lypinator | 0:bb348c97df44 | 1335 | /* Transmit Mailbox 0 management *****************************************/ |
lypinator | 0:bb348c97df44 | 1336 | if ((tsrflags & CAN_TSR_RQCP0) != RESET) |
lypinator | 0:bb348c97df44 | 1337 | { |
lypinator | 0:bb348c97df44 | 1338 | /* Clear the Transmission Complete flag (and TXOK0,ALST0,TERR0 bits) */ |
lypinator | 0:bb348c97df44 | 1339 | __HAL_CAN_CLEAR_FLAG(hcan, CAN_FLAG_RQCP0); |
lypinator | 0:bb348c97df44 | 1340 | |
lypinator | 0:bb348c97df44 | 1341 | if ((tsrflags & CAN_TSR_TXOK0) != RESET) |
lypinator | 0:bb348c97df44 | 1342 | { |
lypinator | 0:bb348c97df44 | 1343 | /* Transmission Mailbox 0 complete callback */ |
lypinator | 0:bb348c97df44 | 1344 | /* Call weak (surcharged) callback */ |
lypinator | 0:bb348c97df44 | 1345 | HAL_CAN_TxMailbox0CompleteCallback(hcan); |
lypinator | 0:bb348c97df44 | 1346 | } |
lypinator | 0:bb348c97df44 | 1347 | else |
lypinator | 0:bb348c97df44 | 1348 | { |
lypinator | 0:bb348c97df44 | 1349 | if ((tsrflags & CAN_TSR_ALST0) != RESET) |
lypinator | 0:bb348c97df44 | 1350 | { |
lypinator | 0:bb348c97df44 | 1351 | /* Update error code */ |
lypinator | 0:bb348c97df44 | 1352 | errorcode |= HAL_CAN_ERROR_TX_ALST0; |
lypinator | 0:bb348c97df44 | 1353 | } |
lypinator | 0:bb348c97df44 | 1354 | else if ((tsrflags & CAN_TSR_TERR0) != RESET) |
lypinator | 0:bb348c97df44 | 1355 | { |
lypinator | 0:bb348c97df44 | 1356 | /* Update error code */ |
lypinator | 0:bb348c97df44 | 1357 | errorcode |= HAL_CAN_ERROR_TX_TERR0; |
lypinator | 0:bb348c97df44 | 1358 | } |
lypinator | 0:bb348c97df44 | 1359 | else |
lypinator | 0:bb348c97df44 | 1360 | { |
lypinator | 0:bb348c97df44 | 1361 | /* Transmission Mailbox 0 abort callback */ |
lypinator | 0:bb348c97df44 | 1362 | /* Call weak (surcharged) callback */ |
lypinator | 0:bb348c97df44 | 1363 | HAL_CAN_TxMailbox0AbortCallback(hcan); |
lypinator | 0:bb348c97df44 | 1364 | } |
lypinator | 0:bb348c97df44 | 1365 | } |
lypinator | 0:bb348c97df44 | 1366 | } |
lypinator | 0:bb348c97df44 | 1367 | |
lypinator | 0:bb348c97df44 | 1368 | /* Transmit Mailbox 1 management *****************************************/ |
lypinator | 0:bb348c97df44 | 1369 | if ((tsrflags & CAN_TSR_RQCP1) != RESET) |
lypinator | 0:bb348c97df44 | 1370 | { |
lypinator | 0:bb348c97df44 | 1371 | /* Clear the Transmission Complete flag (and TXOK1,ALST1,TERR1 bits) */ |
lypinator | 0:bb348c97df44 | 1372 | __HAL_CAN_CLEAR_FLAG(hcan, CAN_FLAG_RQCP1); |
lypinator | 0:bb348c97df44 | 1373 | |
lypinator | 0:bb348c97df44 | 1374 | if ((tsrflags & CAN_TSR_TXOK1) != RESET) |
lypinator | 0:bb348c97df44 | 1375 | { |
lypinator | 0:bb348c97df44 | 1376 | /* Transmission Mailbox 1 complete callback */ |
lypinator | 0:bb348c97df44 | 1377 | /* Call weak (surcharged) callback */ |
lypinator | 0:bb348c97df44 | 1378 | HAL_CAN_TxMailbox1CompleteCallback(hcan); |
lypinator | 0:bb348c97df44 | 1379 | } |
lypinator | 0:bb348c97df44 | 1380 | else |
lypinator | 0:bb348c97df44 | 1381 | { |
lypinator | 0:bb348c97df44 | 1382 | if ((tsrflags & CAN_TSR_ALST1) != RESET) |
lypinator | 0:bb348c97df44 | 1383 | { |
lypinator | 0:bb348c97df44 | 1384 | /* Update error code */ |
lypinator | 0:bb348c97df44 | 1385 | errorcode |= HAL_CAN_ERROR_TX_ALST1; |
lypinator | 0:bb348c97df44 | 1386 | } |
lypinator | 0:bb348c97df44 | 1387 | else if ((tsrflags & CAN_TSR_TERR1) != RESET) |
lypinator | 0:bb348c97df44 | 1388 | { |
lypinator | 0:bb348c97df44 | 1389 | /* Update error code */ |
lypinator | 0:bb348c97df44 | 1390 | errorcode |= HAL_CAN_ERROR_TX_TERR1; |
lypinator | 0:bb348c97df44 | 1391 | } |
lypinator | 0:bb348c97df44 | 1392 | else |
lypinator | 0:bb348c97df44 | 1393 | { |
lypinator | 0:bb348c97df44 | 1394 | /* Transmission Mailbox 1 abort callback */ |
lypinator | 0:bb348c97df44 | 1395 | /* Call weak (surcharged) callback */ |
lypinator | 0:bb348c97df44 | 1396 | HAL_CAN_TxMailbox1AbortCallback(hcan); |
lypinator | 0:bb348c97df44 | 1397 | } |
lypinator | 0:bb348c97df44 | 1398 | } |
lypinator | 0:bb348c97df44 | 1399 | } |
lypinator | 0:bb348c97df44 | 1400 | |
lypinator | 0:bb348c97df44 | 1401 | /* Transmit Mailbox 2 management *****************************************/ |
lypinator | 0:bb348c97df44 | 1402 | if ((tsrflags & CAN_TSR_RQCP2) != RESET) |
lypinator | 0:bb348c97df44 | 1403 | { |
lypinator | 0:bb348c97df44 | 1404 | /* Clear the Transmission Complete flag (and TXOK2,ALST2,TERR2 bits) */ |
lypinator | 0:bb348c97df44 | 1405 | __HAL_CAN_CLEAR_FLAG(hcan, CAN_FLAG_RQCP2); |
lypinator | 0:bb348c97df44 | 1406 | |
lypinator | 0:bb348c97df44 | 1407 | if ((tsrflags & CAN_TSR_TXOK2) != RESET) |
lypinator | 0:bb348c97df44 | 1408 | { |
lypinator | 0:bb348c97df44 | 1409 | /* Transmission Mailbox 2 complete callback */ |
lypinator | 0:bb348c97df44 | 1410 | /* Call weak (surcharged) callback */ |
lypinator | 0:bb348c97df44 | 1411 | HAL_CAN_TxMailbox2CompleteCallback(hcan); |
lypinator | 0:bb348c97df44 | 1412 | } |
lypinator | 0:bb348c97df44 | 1413 | else |
lypinator | 0:bb348c97df44 | 1414 | { |
lypinator | 0:bb348c97df44 | 1415 | if ((tsrflags & CAN_TSR_ALST2) != RESET) |
lypinator | 0:bb348c97df44 | 1416 | { |
lypinator | 0:bb348c97df44 | 1417 | /* Update error code */ |
lypinator | 0:bb348c97df44 | 1418 | errorcode |= HAL_CAN_ERROR_TX_ALST2; |
lypinator | 0:bb348c97df44 | 1419 | } |
lypinator | 0:bb348c97df44 | 1420 | else if ((tsrflags & CAN_TSR_TERR2) != RESET) |
lypinator | 0:bb348c97df44 | 1421 | { |
lypinator | 0:bb348c97df44 | 1422 | /* Update error code */ |
lypinator | 0:bb348c97df44 | 1423 | errorcode |= HAL_CAN_ERROR_TX_TERR2; |
lypinator | 0:bb348c97df44 | 1424 | } |
lypinator | 0:bb348c97df44 | 1425 | else |
lypinator | 0:bb348c97df44 | 1426 | { |
lypinator | 0:bb348c97df44 | 1427 | /* Transmission Mailbox 2 abort callback */ |
lypinator | 0:bb348c97df44 | 1428 | /* Call weak (surcharged) callback */ |
lypinator | 0:bb348c97df44 | 1429 | HAL_CAN_TxMailbox2AbortCallback(hcan); |
lypinator | 0:bb348c97df44 | 1430 | } |
lypinator | 0:bb348c97df44 | 1431 | } |
lypinator | 0:bb348c97df44 | 1432 | } |
lypinator | 0:bb348c97df44 | 1433 | } |
lypinator | 0:bb348c97df44 | 1434 | |
lypinator | 0:bb348c97df44 | 1435 | /* Receive FIFO 0 overrun interrupt management *****************************/ |
lypinator | 0:bb348c97df44 | 1436 | if ((interrupts & CAN_IT_RX_FIFO0_OVERRUN) != RESET) |
lypinator | 0:bb348c97df44 | 1437 | { |
lypinator | 0:bb348c97df44 | 1438 | if ((rf0rflags & CAN_RF0R_FOVR0) != RESET) |
lypinator | 0:bb348c97df44 | 1439 | { |
lypinator | 0:bb348c97df44 | 1440 | /* Set CAN error code to Rx Fifo 0 overrun error */ |
lypinator | 0:bb348c97df44 | 1441 | errorcode |= HAL_CAN_ERROR_RX_FOV0; |
lypinator | 0:bb348c97df44 | 1442 | |
lypinator | 0:bb348c97df44 | 1443 | /* Clear FIFO0 Overrun Flag */ |
lypinator | 0:bb348c97df44 | 1444 | __HAL_CAN_CLEAR_FLAG(hcan, CAN_FLAG_FOV0); |
lypinator | 0:bb348c97df44 | 1445 | } |
lypinator | 0:bb348c97df44 | 1446 | } |
lypinator | 0:bb348c97df44 | 1447 | |
lypinator | 0:bb348c97df44 | 1448 | /* Receive FIFO 0 full interrupt management ********************************/ |
lypinator | 0:bb348c97df44 | 1449 | if ((interrupts & CAN_IT_RX_FIFO0_FULL) != RESET) |
lypinator | 0:bb348c97df44 | 1450 | { |
lypinator | 0:bb348c97df44 | 1451 | if ((rf0rflags & CAN_RF0R_FULL0) != RESET) |
lypinator | 0:bb348c97df44 | 1452 | { |
lypinator | 0:bb348c97df44 | 1453 | /* Clear FIFO 0 full Flag */ |
lypinator | 0:bb348c97df44 | 1454 | __HAL_CAN_CLEAR_FLAG(hcan, CAN_FLAG_FF0); |
lypinator | 0:bb348c97df44 | 1455 | |
lypinator | 0:bb348c97df44 | 1456 | /* Receive FIFO 0 full Callback */ |
lypinator | 0:bb348c97df44 | 1457 | /* Call weak (surcharged) callback */ |
lypinator | 0:bb348c97df44 | 1458 | HAL_CAN_RxFifo0FullCallback(hcan); |
lypinator | 0:bb348c97df44 | 1459 | } |
lypinator | 0:bb348c97df44 | 1460 | } |
lypinator | 0:bb348c97df44 | 1461 | |
lypinator | 0:bb348c97df44 | 1462 | /* Receive FIFO 0 message pending interrupt management *********************/ |
lypinator | 0:bb348c97df44 | 1463 | if ((interrupts & CAN_IT_RX_FIFO0_MSG_PENDING) != RESET) |
lypinator | 0:bb348c97df44 | 1464 | { |
lypinator | 0:bb348c97df44 | 1465 | /* Check if message is still pending */ |
lypinator | 0:bb348c97df44 | 1466 | if ((hcan->Instance->RF0R & CAN_RF0R_FMP0) != RESET) |
lypinator | 0:bb348c97df44 | 1467 | { |
lypinator | 0:bb348c97df44 | 1468 | /* Receive FIFO 0 mesage pending Callback */ |
lypinator | 0:bb348c97df44 | 1469 | /* Call weak (surcharged) callback */ |
lypinator | 0:bb348c97df44 | 1470 | HAL_CAN_RxFifo0MsgPendingCallback(hcan); |
lypinator | 0:bb348c97df44 | 1471 | } |
lypinator | 0:bb348c97df44 | 1472 | } |
lypinator | 0:bb348c97df44 | 1473 | |
lypinator | 0:bb348c97df44 | 1474 | /* Receive FIFO 1 overrun interrupt management *****************************/ |
lypinator | 0:bb348c97df44 | 1475 | if ((interrupts & CAN_IT_RX_FIFO1_OVERRUN) != RESET) |
lypinator | 0:bb348c97df44 | 1476 | { |
lypinator | 0:bb348c97df44 | 1477 | if ((rf1rflags & CAN_RF1R_FOVR1) != RESET) |
lypinator | 0:bb348c97df44 | 1478 | { |
lypinator | 0:bb348c97df44 | 1479 | /* Set CAN error code to Rx Fifo 1 overrun error */ |
lypinator | 0:bb348c97df44 | 1480 | errorcode |= HAL_CAN_ERROR_RX_FOV1; |
lypinator | 0:bb348c97df44 | 1481 | |
lypinator | 0:bb348c97df44 | 1482 | /* Clear FIFO1 Overrun Flag */ |
lypinator | 0:bb348c97df44 | 1483 | __HAL_CAN_CLEAR_FLAG(hcan, CAN_FLAG_FOV1); |
lypinator | 0:bb348c97df44 | 1484 | } |
lypinator | 0:bb348c97df44 | 1485 | } |
lypinator | 0:bb348c97df44 | 1486 | |
lypinator | 0:bb348c97df44 | 1487 | /* Receive FIFO 1 full interrupt management ********************************/ |
lypinator | 0:bb348c97df44 | 1488 | if ((interrupts & CAN_IT_RX_FIFO1_FULL) != RESET) |
lypinator | 0:bb348c97df44 | 1489 | { |
lypinator | 0:bb348c97df44 | 1490 | if ((rf1rflags & CAN_RF1R_FULL1) != RESET) |
lypinator | 0:bb348c97df44 | 1491 | { |
lypinator | 0:bb348c97df44 | 1492 | /* Clear FIFO 1 full Flag */ |
lypinator | 0:bb348c97df44 | 1493 | __HAL_CAN_CLEAR_FLAG(hcan, CAN_FLAG_FF1); |
lypinator | 0:bb348c97df44 | 1494 | |
lypinator | 0:bb348c97df44 | 1495 | /* Receive FIFO 1 full Callback */ |
lypinator | 0:bb348c97df44 | 1496 | /* Call weak (surcharged) callback */ |
lypinator | 0:bb348c97df44 | 1497 | HAL_CAN_RxFifo1FullCallback(hcan); |
lypinator | 0:bb348c97df44 | 1498 | } |
lypinator | 0:bb348c97df44 | 1499 | } |
lypinator | 0:bb348c97df44 | 1500 | |
lypinator | 0:bb348c97df44 | 1501 | /* Receive FIFO 1 message pending interrupt management *********************/ |
lypinator | 0:bb348c97df44 | 1502 | if ((interrupts & CAN_IT_RX_FIFO1_MSG_PENDING) != RESET) |
lypinator | 0:bb348c97df44 | 1503 | { |
lypinator | 0:bb348c97df44 | 1504 | /* Check if message is still pending */ |
lypinator | 0:bb348c97df44 | 1505 | if ((hcan->Instance->RF1R & CAN_RF1R_FMP1) != RESET) |
lypinator | 0:bb348c97df44 | 1506 | { |
lypinator | 0:bb348c97df44 | 1507 | /* Receive FIFO 1 mesage pending Callback */ |
lypinator | 0:bb348c97df44 | 1508 | /* Call weak (surcharged) callback */ |
lypinator | 0:bb348c97df44 | 1509 | HAL_CAN_RxFifo1MsgPendingCallback(hcan); |
lypinator | 0:bb348c97df44 | 1510 | } |
lypinator | 0:bb348c97df44 | 1511 | } |
lypinator | 0:bb348c97df44 | 1512 | |
lypinator | 0:bb348c97df44 | 1513 | /* Sleep interrupt management *********************************************/ |
lypinator | 0:bb348c97df44 | 1514 | if ((interrupts & CAN_IT_SLEEP_ACK) != RESET) |
lypinator | 0:bb348c97df44 | 1515 | { |
lypinator | 0:bb348c97df44 | 1516 | if ((msrflags & CAN_MSR_SLAKI) != RESET) |
lypinator | 0:bb348c97df44 | 1517 | { |
lypinator | 0:bb348c97df44 | 1518 | /* Clear Sleep interrupt Flag */ |
lypinator | 0:bb348c97df44 | 1519 | __HAL_CAN_CLEAR_FLAG(hcan, CAN_FLAG_SLAKI); |
lypinator | 0:bb348c97df44 | 1520 | |
lypinator | 0:bb348c97df44 | 1521 | /* Sleep Callback */ |
lypinator | 0:bb348c97df44 | 1522 | /* Call weak (surcharged) callback */ |
lypinator | 0:bb348c97df44 | 1523 | HAL_CAN_SleepCallback(hcan); |
lypinator | 0:bb348c97df44 | 1524 | } |
lypinator | 0:bb348c97df44 | 1525 | } |
lypinator | 0:bb348c97df44 | 1526 | |
lypinator | 0:bb348c97df44 | 1527 | /* WakeUp interrupt management *********************************************/ |
lypinator | 0:bb348c97df44 | 1528 | if ((interrupts & CAN_IT_WAKEUP) != RESET) |
lypinator | 0:bb348c97df44 | 1529 | { |
lypinator | 0:bb348c97df44 | 1530 | if ((msrflags & CAN_MSR_WKUI) != RESET) |
lypinator | 0:bb348c97df44 | 1531 | { |
lypinator | 0:bb348c97df44 | 1532 | /* Clear WakeUp Flag */ |
lypinator | 0:bb348c97df44 | 1533 | __HAL_CAN_CLEAR_FLAG(hcan, CAN_FLAG_WKU); |
lypinator | 0:bb348c97df44 | 1534 | |
lypinator | 0:bb348c97df44 | 1535 | /* WakeUp Callback */ |
lypinator | 0:bb348c97df44 | 1536 | /* Call weak (surcharged) callback */ |
lypinator | 0:bb348c97df44 | 1537 | HAL_CAN_WakeUpFromRxMsgCallback(hcan); |
lypinator | 0:bb348c97df44 | 1538 | } |
lypinator | 0:bb348c97df44 | 1539 | } |
lypinator | 0:bb348c97df44 | 1540 | |
lypinator | 0:bb348c97df44 | 1541 | /* Error interrupts management *********************************************/ |
lypinator | 0:bb348c97df44 | 1542 | if ((interrupts & CAN_IT_ERROR) != RESET) |
lypinator | 0:bb348c97df44 | 1543 | { |
lypinator | 0:bb348c97df44 | 1544 | if ((msrflags & CAN_MSR_ERRI) != RESET) |
lypinator | 0:bb348c97df44 | 1545 | { |
lypinator | 0:bb348c97df44 | 1546 | /* Check Error Warning Flag */ |
lypinator | 0:bb348c97df44 | 1547 | if (((interrupts & CAN_IT_ERROR_WARNING) != RESET) && |
lypinator | 0:bb348c97df44 | 1548 | ((esrflags & CAN_ESR_EWGF) != RESET)) |
lypinator | 0:bb348c97df44 | 1549 | { |
lypinator | 0:bb348c97df44 | 1550 | /* Set CAN error code to Error Warning */ |
lypinator | 0:bb348c97df44 | 1551 | errorcode |= HAL_CAN_ERROR_EWG; |
lypinator | 0:bb348c97df44 | 1552 | |
lypinator | 0:bb348c97df44 | 1553 | /* No need for clear of Error Warning Flag as read-only */ |
lypinator | 0:bb348c97df44 | 1554 | } |
lypinator | 0:bb348c97df44 | 1555 | |
lypinator | 0:bb348c97df44 | 1556 | /* Check Error Passive Flag */ |
lypinator | 0:bb348c97df44 | 1557 | if (((interrupts & CAN_IT_ERROR_PASSIVE) != RESET) && |
lypinator | 0:bb348c97df44 | 1558 | ((esrflags & CAN_ESR_EPVF) != RESET)) |
lypinator | 0:bb348c97df44 | 1559 | { |
lypinator | 0:bb348c97df44 | 1560 | /* Set CAN error code to Error Passive */ |
lypinator | 0:bb348c97df44 | 1561 | errorcode |= HAL_CAN_ERROR_EPV; |
lypinator | 0:bb348c97df44 | 1562 | |
lypinator | 0:bb348c97df44 | 1563 | /* No need for clear of Error Passive Flag as read-only */ |
lypinator | 0:bb348c97df44 | 1564 | } |
lypinator | 0:bb348c97df44 | 1565 | |
lypinator | 0:bb348c97df44 | 1566 | /* Check Bus-off Flag */ |
lypinator | 0:bb348c97df44 | 1567 | if (((interrupts & CAN_IT_BUSOFF) != RESET) && |
lypinator | 0:bb348c97df44 | 1568 | ((esrflags & CAN_ESR_BOFF) != RESET)) |
lypinator | 0:bb348c97df44 | 1569 | { |
lypinator | 0:bb348c97df44 | 1570 | /* Set CAN error code to Bus-Off */ |
lypinator | 0:bb348c97df44 | 1571 | errorcode |= HAL_CAN_ERROR_BOF; |
lypinator | 0:bb348c97df44 | 1572 | |
lypinator | 0:bb348c97df44 | 1573 | /* No need for clear of Error Bus-Off as read-only */ |
lypinator | 0:bb348c97df44 | 1574 | } |
lypinator | 0:bb348c97df44 | 1575 | |
lypinator | 0:bb348c97df44 | 1576 | /* Check Last Error Code Flag */ |
lypinator | 0:bb348c97df44 | 1577 | if (((interrupts & CAN_IT_LAST_ERROR_CODE) != RESET) && |
lypinator | 0:bb348c97df44 | 1578 | ((esrflags & CAN_ESR_LEC) != RESET)) |
lypinator | 0:bb348c97df44 | 1579 | { |
lypinator | 0:bb348c97df44 | 1580 | switch (esrflags & CAN_ESR_LEC) |
lypinator | 0:bb348c97df44 | 1581 | { |
lypinator | 0:bb348c97df44 | 1582 | case (CAN_ESR_LEC_0): |
lypinator | 0:bb348c97df44 | 1583 | /* Set CAN error code to Stuff error */ |
lypinator | 0:bb348c97df44 | 1584 | errorcode |= HAL_CAN_ERROR_STF; |
lypinator | 0:bb348c97df44 | 1585 | break; |
lypinator | 0:bb348c97df44 | 1586 | case (CAN_ESR_LEC_1): |
lypinator | 0:bb348c97df44 | 1587 | /* Set CAN error code to Form error */ |
lypinator | 0:bb348c97df44 | 1588 | errorcode |= HAL_CAN_ERROR_FOR; |
lypinator | 0:bb348c97df44 | 1589 | break; |
lypinator | 0:bb348c97df44 | 1590 | case (CAN_ESR_LEC_1 | CAN_ESR_LEC_0): |
lypinator | 0:bb348c97df44 | 1591 | /* Set CAN error code to Acknowledgement error */ |
lypinator | 0:bb348c97df44 | 1592 | errorcode |= HAL_CAN_ERROR_ACK; |
lypinator | 0:bb348c97df44 | 1593 | break; |
lypinator | 0:bb348c97df44 | 1594 | case (CAN_ESR_LEC_2): |
lypinator | 0:bb348c97df44 | 1595 | /* Set CAN error code to Bit recessive error */ |
lypinator | 0:bb348c97df44 | 1596 | errorcode |= HAL_CAN_ERROR_BR; |
lypinator | 0:bb348c97df44 | 1597 | break; |
lypinator | 0:bb348c97df44 | 1598 | case (CAN_ESR_LEC_2 | CAN_ESR_LEC_0): |
lypinator | 0:bb348c97df44 | 1599 | /* Set CAN error code to Bit Dominant error */ |
lypinator | 0:bb348c97df44 | 1600 | errorcode |= HAL_CAN_ERROR_BD; |
lypinator | 0:bb348c97df44 | 1601 | break; |
lypinator | 0:bb348c97df44 | 1602 | case (CAN_ESR_LEC_2 | CAN_ESR_LEC_1): |
lypinator | 0:bb348c97df44 | 1603 | /* Set CAN error code to CRC error */ |
lypinator | 0:bb348c97df44 | 1604 | errorcode |= HAL_CAN_ERROR_CRC; |
lypinator | 0:bb348c97df44 | 1605 | break; |
lypinator | 0:bb348c97df44 | 1606 | default: |
lypinator | 0:bb348c97df44 | 1607 | break; |
lypinator | 0:bb348c97df44 | 1608 | } |
lypinator | 0:bb348c97df44 | 1609 | |
lypinator | 0:bb348c97df44 | 1610 | /* Clear Last error code Flag */ |
lypinator | 0:bb348c97df44 | 1611 | CLEAR_BIT(hcan->Instance->ESR, CAN_ESR_LEC); |
lypinator | 0:bb348c97df44 | 1612 | } |
lypinator | 0:bb348c97df44 | 1613 | } |
lypinator | 0:bb348c97df44 | 1614 | |
lypinator | 0:bb348c97df44 | 1615 | /* Clear ERRI Flag */ |
lypinator | 0:bb348c97df44 | 1616 | __HAL_CAN_CLEAR_FLAG(hcan, CAN_FLAG_ERRI); |
lypinator | 0:bb348c97df44 | 1617 | } |
lypinator | 0:bb348c97df44 | 1618 | |
lypinator | 0:bb348c97df44 | 1619 | /* Call the Error call Back in case of Errors */ |
lypinator | 0:bb348c97df44 | 1620 | if (errorcode != HAL_CAN_ERROR_NONE) |
lypinator | 0:bb348c97df44 | 1621 | { |
lypinator | 0:bb348c97df44 | 1622 | /* Update error code in handle */ |
lypinator | 0:bb348c97df44 | 1623 | hcan->ErrorCode |= errorcode; |
lypinator | 0:bb348c97df44 | 1624 | |
lypinator | 0:bb348c97df44 | 1625 | /* Call Error callback function */ |
lypinator | 0:bb348c97df44 | 1626 | /* Call weak (surcharged) callback */ |
lypinator | 0:bb348c97df44 | 1627 | HAL_CAN_ErrorCallback(hcan); |
lypinator | 0:bb348c97df44 | 1628 | } |
lypinator | 0:bb348c97df44 | 1629 | } |
lypinator | 0:bb348c97df44 | 1630 | |
lypinator | 0:bb348c97df44 | 1631 | /** |
lypinator | 0:bb348c97df44 | 1632 | * @} |
lypinator | 0:bb348c97df44 | 1633 | */ |
lypinator | 0:bb348c97df44 | 1634 | |
lypinator | 0:bb348c97df44 | 1635 | /** @defgroup CAN_Exported_Functions_Group5 Callback functions |
lypinator | 0:bb348c97df44 | 1636 | * @brief CAN Callback functions |
lypinator | 0:bb348c97df44 | 1637 | * |
lypinator | 0:bb348c97df44 | 1638 | @verbatim |
lypinator | 0:bb348c97df44 | 1639 | ============================================================================== |
lypinator | 0:bb348c97df44 | 1640 | ##### Callback functions ##### |
lypinator | 0:bb348c97df44 | 1641 | ============================================================================== |
lypinator | 0:bb348c97df44 | 1642 | [..] |
lypinator | 0:bb348c97df44 | 1643 | This subsection provides the following callback functions: |
lypinator | 0:bb348c97df44 | 1644 | (+) HAL_CAN_TxMailbox0CompleteCallback |
lypinator | 0:bb348c97df44 | 1645 | (+) HAL_CAN_TxMailbox1CompleteCallback |
lypinator | 0:bb348c97df44 | 1646 | (+) HAL_CAN_TxMailbox2CompleteCallback |
lypinator | 0:bb348c97df44 | 1647 | (+) HAL_CAN_TxMailbox0AbortCallback |
lypinator | 0:bb348c97df44 | 1648 | (+) HAL_CAN_TxMailbox1AbortCallback |
lypinator | 0:bb348c97df44 | 1649 | (+) HAL_CAN_TxMailbox2AbortCallback |
lypinator | 0:bb348c97df44 | 1650 | (+) HAL_CAN_RxFifo0MsgPendingCallback |
lypinator | 0:bb348c97df44 | 1651 | (+) HAL_CAN_RxFifo0FullCallback |
lypinator | 0:bb348c97df44 | 1652 | (+) HAL_CAN_RxFifo1MsgPendingCallback |
lypinator | 0:bb348c97df44 | 1653 | (+) HAL_CAN_RxFifo1FullCallback |
lypinator | 0:bb348c97df44 | 1654 | (+) HAL_CAN_SleepCallback |
lypinator | 0:bb348c97df44 | 1655 | (+) HAL_CAN_WakeUpFromRxMsgCallback |
lypinator | 0:bb348c97df44 | 1656 | (+) HAL_CAN_ErrorCallback |
lypinator | 0:bb348c97df44 | 1657 | |
lypinator | 0:bb348c97df44 | 1658 | @endverbatim |
lypinator | 0:bb348c97df44 | 1659 | * @{ |
lypinator | 0:bb348c97df44 | 1660 | */ |
lypinator | 0:bb348c97df44 | 1661 | |
lypinator | 0:bb348c97df44 | 1662 | /** |
lypinator | 0:bb348c97df44 | 1663 | * @brief Transmission Mailbox 0 complete callback. |
lypinator | 0:bb348c97df44 | 1664 | * @param hcan pointer to a CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 1665 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 1666 | * @retval None |
lypinator | 0:bb348c97df44 | 1667 | */ |
lypinator | 0:bb348c97df44 | 1668 | __weak void HAL_CAN_TxMailbox0CompleteCallback(CAN_HandleTypeDef *hcan) |
lypinator | 0:bb348c97df44 | 1669 | { |
lypinator | 0:bb348c97df44 | 1670 | /* Prevent unused argument(s) compilation warning */ |
lypinator | 0:bb348c97df44 | 1671 | UNUSED(hcan); |
lypinator | 0:bb348c97df44 | 1672 | |
lypinator | 0:bb348c97df44 | 1673 | /* NOTE : This function Should not be modified, when the callback is needed, |
lypinator | 0:bb348c97df44 | 1674 | the HAL_CAN_TxMailbox0CompleteCallback could be implemented in the |
lypinator | 0:bb348c97df44 | 1675 | user file |
lypinator | 0:bb348c97df44 | 1676 | */ |
lypinator | 0:bb348c97df44 | 1677 | } |
lypinator | 0:bb348c97df44 | 1678 | |
lypinator | 0:bb348c97df44 | 1679 | /** |
lypinator | 0:bb348c97df44 | 1680 | * @brief Transmission Mailbox 1 complete callback. |
lypinator | 0:bb348c97df44 | 1681 | * @param hcan pointer to a CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 1682 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 1683 | * @retval None |
lypinator | 0:bb348c97df44 | 1684 | */ |
lypinator | 0:bb348c97df44 | 1685 | __weak void HAL_CAN_TxMailbox1CompleteCallback(CAN_HandleTypeDef *hcan) |
lypinator | 0:bb348c97df44 | 1686 | { |
lypinator | 0:bb348c97df44 | 1687 | /* Prevent unused argument(s) compilation warning */ |
lypinator | 0:bb348c97df44 | 1688 | UNUSED(hcan); |
lypinator | 0:bb348c97df44 | 1689 | |
lypinator | 0:bb348c97df44 | 1690 | /* NOTE : This function Should not be modified, when the callback is needed, |
lypinator | 0:bb348c97df44 | 1691 | the HAL_CAN_TxMailbox1CompleteCallback could be implemented in the |
lypinator | 0:bb348c97df44 | 1692 | user file |
lypinator | 0:bb348c97df44 | 1693 | */ |
lypinator | 0:bb348c97df44 | 1694 | } |
lypinator | 0:bb348c97df44 | 1695 | |
lypinator | 0:bb348c97df44 | 1696 | /** |
lypinator | 0:bb348c97df44 | 1697 | * @brief Transmission Mailbox 2 complete callback. |
lypinator | 0:bb348c97df44 | 1698 | * @param hcan pointer to a CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 1699 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 1700 | * @retval None |
lypinator | 0:bb348c97df44 | 1701 | */ |
lypinator | 0:bb348c97df44 | 1702 | __weak void HAL_CAN_TxMailbox2CompleteCallback(CAN_HandleTypeDef *hcan) |
lypinator | 0:bb348c97df44 | 1703 | { |
lypinator | 0:bb348c97df44 | 1704 | /* Prevent unused argument(s) compilation warning */ |
lypinator | 0:bb348c97df44 | 1705 | UNUSED(hcan); |
lypinator | 0:bb348c97df44 | 1706 | |
lypinator | 0:bb348c97df44 | 1707 | /* NOTE : This function Should not be modified, when the callback is needed, |
lypinator | 0:bb348c97df44 | 1708 | the HAL_CAN_TxMailbox2CompleteCallback could be implemented in the |
lypinator | 0:bb348c97df44 | 1709 | user file |
lypinator | 0:bb348c97df44 | 1710 | */ |
lypinator | 0:bb348c97df44 | 1711 | } |
lypinator | 0:bb348c97df44 | 1712 | |
lypinator | 0:bb348c97df44 | 1713 | /** |
lypinator | 0:bb348c97df44 | 1714 | * @brief Transmission Mailbox 0 Cancellation callback. |
lypinator | 0:bb348c97df44 | 1715 | * @param hcan pointer to an CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 1716 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 1717 | * @retval None |
lypinator | 0:bb348c97df44 | 1718 | */ |
lypinator | 0:bb348c97df44 | 1719 | __weak void HAL_CAN_TxMailbox0AbortCallback(CAN_HandleTypeDef *hcan) |
lypinator | 0:bb348c97df44 | 1720 | { |
lypinator | 0:bb348c97df44 | 1721 | /* Prevent unused argument(s) compilation warning */ |
lypinator | 0:bb348c97df44 | 1722 | UNUSED(hcan); |
lypinator | 0:bb348c97df44 | 1723 | |
lypinator | 0:bb348c97df44 | 1724 | /* NOTE : This function Should not be modified, when the callback is needed, |
lypinator | 0:bb348c97df44 | 1725 | the HAL_CAN_TxMailbox0AbortCallback could be implemented in the |
lypinator | 0:bb348c97df44 | 1726 | user file |
lypinator | 0:bb348c97df44 | 1727 | */ |
lypinator | 0:bb348c97df44 | 1728 | } |
lypinator | 0:bb348c97df44 | 1729 | |
lypinator | 0:bb348c97df44 | 1730 | /** |
lypinator | 0:bb348c97df44 | 1731 | * @brief Transmission Mailbox 1 Cancellation callback. |
lypinator | 0:bb348c97df44 | 1732 | * @param hcan pointer to an CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 1733 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 1734 | * @retval None |
lypinator | 0:bb348c97df44 | 1735 | */ |
lypinator | 0:bb348c97df44 | 1736 | __weak void HAL_CAN_TxMailbox1AbortCallback(CAN_HandleTypeDef *hcan) |
lypinator | 0:bb348c97df44 | 1737 | { |
lypinator | 0:bb348c97df44 | 1738 | /* Prevent unused argument(s) compilation warning */ |
lypinator | 0:bb348c97df44 | 1739 | UNUSED(hcan); |
lypinator | 0:bb348c97df44 | 1740 | |
lypinator | 0:bb348c97df44 | 1741 | /* NOTE : This function Should not be modified, when the callback is needed, |
lypinator | 0:bb348c97df44 | 1742 | the HAL_CAN_TxMailbox1AbortCallback could be implemented in the |
lypinator | 0:bb348c97df44 | 1743 | user file |
lypinator | 0:bb348c97df44 | 1744 | */ |
lypinator | 0:bb348c97df44 | 1745 | } |
lypinator | 0:bb348c97df44 | 1746 | |
lypinator | 0:bb348c97df44 | 1747 | /** |
lypinator | 0:bb348c97df44 | 1748 | * @brief Transmission Mailbox 2 Cancellation callback. |
lypinator | 0:bb348c97df44 | 1749 | * @param hcan pointer to an CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 1750 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 1751 | * @retval None |
lypinator | 0:bb348c97df44 | 1752 | */ |
lypinator | 0:bb348c97df44 | 1753 | __weak void HAL_CAN_TxMailbox2AbortCallback(CAN_HandleTypeDef *hcan) |
lypinator | 0:bb348c97df44 | 1754 | { |
lypinator | 0:bb348c97df44 | 1755 | /* Prevent unused argument(s) compilation warning */ |
lypinator | 0:bb348c97df44 | 1756 | UNUSED(hcan); |
lypinator | 0:bb348c97df44 | 1757 | |
lypinator | 0:bb348c97df44 | 1758 | /* NOTE : This function Should not be modified, when the callback is needed, |
lypinator | 0:bb348c97df44 | 1759 | the HAL_CAN_TxMailbox2AbortCallback could be implemented in the |
lypinator | 0:bb348c97df44 | 1760 | user file |
lypinator | 0:bb348c97df44 | 1761 | */ |
lypinator | 0:bb348c97df44 | 1762 | } |
lypinator | 0:bb348c97df44 | 1763 | |
lypinator | 0:bb348c97df44 | 1764 | /** |
lypinator | 0:bb348c97df44 | 1765 | * @brief Rx FIFO 0 message pending callback. |
lypinator | 0:bb348c97df44 | 1766 | * @param hcan pointer to a CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 1767 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 1768 | * @retval None |
lypinator | 0:bb348c97df44 | 1769 | */ |
lypinator | 0:bb348c97df44 | 1770 | __weak void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan) |
lypinator | 0:bb348c97df44 | 1771 | { |
lypinator | 0:bb348c97df44 | 1772 | /* Prevent unused argument(s) compilation warning */ |
lypinator | 0:bb348c97df44 | 1773 | UNUSED(hcan); |
lypinator | 0:bb348c97df44 | 1774 | |
lypinator | 0:bb348c97df44 | 1775 | /* NOTE : This function Should not be modified, when the callback is needed, |
lypinator | 0:bb348c97df44 | 1776 | the HAL_CAN_RxFifo0MsgPendingCallback could be implemented in the |
lypinator | 0:bb348c97df44 | 1777 | user file |
lypinator | 0:bb348c97df44 | 1778 | */ |
lypinator | 0:bb348c97df44 | 1779 | } |
lypinator | 0:bb348c97df44 | 1780 | |
lypinator | 0:bb348c97df44 | 1781 | /** |
lypinator | 0:bb348c97df44 | 1782 | * @brief Rx FIFO 0 full callback. |
lypinator | 0:bb348c97df44 | 1783 | * @param hcan pointer to a CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 1784 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 1785 | * @retval None |
lypinator | 0:bb348c97df44 | 1786 | */ |
lypinator | 0:bb348c97df44 | 1787 | __weak void HAL_CAN_RxFifo0FullCallback(CAN_HandleTypeDef *hcan) |
lypinator | 0:bb348c97df44 | 1788 | { |
lypinator | 0:bb348c97df44 | 1789 | /* Prevent unused argument(s) compilation warning */ |
lypinator | 0:bb348c97df44 | 1790 | UNUSED(hcan); |
lypinator | 0:bb348c97df44 | 1791 | |
lypinator | 0:bb348c97df44 | 1792 | /* NOTE : This function Should not be modified, when the callback is needed, |
lypinator | 0:bb348c97df44 | 1793 | the HAL_CAN_RxFifo0FullCallback could be implemented in the user |
lypinator | 0:bb348c97df44 | 1794 | file |
lypinator | 0:bb348c97df44 | 1795 | */ |
lypinator | 0:bb348c97df44 | 1796 | } |
lypinator | 0:bb348c97df44 | 1797 | |
lypinator | 0:bb348c97df44 | 1798 | /** |
lypinator | 0:bb348c97df44 | 1799 | * @brief Rx FIFO 1 message pending callback. |
lypinator | 0:bb348c97df44 | 1800 | * @param hcan pointer to a CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 1801 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 1802 | * @retval None |
lypinator | 0:bb348c97df44 | 1803 | */ |
lypinator | 0:bb348c97df44 | 1804 | __weak void HAL_CAN_RxFifo1MsgPendingCallback(CAN_HandleTypeDef *hcan) |
lypinator | 0:bb348c97df44 | 1805 | { |
lypinator | 0:bb348c97df44 | 1806 | /* Prevent unused argument(s) compilation warning */ |
lypinator | 0:bb348c97df44 | 1807 | UNUSED(hcan); |
lypinator | 0:bb348c97df44 | 1808 | |
lypinator | 0:bb348c97df44 | 1809 | /* NOTE : This function Should not be modified, when the callback is needed, |
lypinator | 0:bb348c97df44 | 1810 | the HAL_CAN_RxFifo1MsgPendingCallback could be implemented in the |
lypinator | 0:bb348c97df44 | 1811 | user file |
lypinator | 0:bb348c97df44 | 1812 | */ |
lypinator | 0:bb348c97df44 | 1813 | } |
lypinator | 0:bb348c97df44 | 1814 | |
lypinator | 0:bb348c97df44 | 1815 | /** |
lypinator | 0:bb348c97df44 | 1816 | * @brief Rx FIFO 1 full callback. |
lypinator | 0:bb348c97df44 | 1817 | * @param hcan pointer to a CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 1818 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 1819 | * @retval None |
lypinator | 0:bb348c97df44 | 1820 | */ |
lypinator | 0:bb348c97df44 | 1821 | __weak void HAL_CAN_RxFifo1FullCallback(CAN_HandleTypeDef *hcan) |
lypinator | 0:bb348c97df44 | 1822 | { |
lypinator | 0:bb348c97df44 | 1823 | /* Prevent unused argument(s) compilation warning */ |
lypinator | 0:bb348c97df44 | 1824 | UNUSED(hcan); |
lypinator | 0:bb348c97df44 | 1825 | |
lypinator | 0:bb348c97df44 | 1826 | /* NOTE : This function Should not be modified, when the callback is needed, |
lypinator | 0:bb348c97df44 | 1827 | the HAL_CAN_RxFifo1FullCallback could be implemented in the user |
lypinator | 0:bb348c97df44 | 1828 | file |
lypinator | 0:bb348c97df44 | 1829 | */ |
lypinator | 0:bb348c97df44 | 1830 | } |
lypinator | 0:bb348c97df44 | 1831 | |
lypinator | 0:bb348c97df44 | 1832 | /** |
lypinator | 0:bb348c97df44 | 1833 | * @brief Sleep callback. |
lypinator | 0:bb348c97df44 | 1834 | * @param hcan pointer to a CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 1835 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 1836 | * @retval None |
lypinator | 0:bb348c97df44 | 1837 | */ |
lypinator | 0:bb348c97df44 | 1838 | __weak void HAL_CAN_SleepCallback(CAN_HandleTypeDef *hcan) |
lypinator | 0:bb348c97df44 | 1839 | { |
lypinator | 0:bb348c97df44 | 1840 | /* Prevent unused argument(s) compilation warning */ |
lypinator | 0:bb348c97df44 | 1841 | UNUSED(hcan); |
lypinator | 0:bb348c97df44 | 1842 | |
lypinator | 0:bb348c97df44 | 1843 | /* NOTE : This function Should not be modified, when the callback is needed, |
lypinator | 0:bb348c97df44 | 1844 | the HAL_CAN_SleepCallback could be implemented in the user file |
lypinator | 0:bb348c97df44 | 1845 | */ |
lypinator | 0:bb348c97df44 | 1846 | } |
lypinator | 0:bb348c97df44 | 1847 | |
lypinator | 0:bb348c97df44 | 1848 | /** |
lypinator | 0:bb348c97df44 | 1849 | * @brief WakeUp from Rx message callback. |
lypinator | 0:bb348c97df44 | 1850 | * @param hcan pointer to a CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 1851 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 1852 | * @retval None |
lypinator | 0:bb348c97df44 | 1853 | */ |
lypinator | 0:bb348c97df44 | 1854 | __weak void HAL_CAN_WakeUpFromRxMsgCallback(CAN_HandleTypeDef *hcan) |
lypinator | 0:bb348c97df44 | 1855 | { |
lypinator | 0:bb348c97df44 | 1856 | /* Prevent unused argument(s) compilation warning */ |
lypinator | 0:bb348c97df44 | 1857 | UNUSED(hcan); |
lypinator | 0:bb348c97df44 | 1858 | |
lypinator | 0:bb348c97df44 | 1859 | /* NOTE : This function Should not be modified, when the callback is needed, |
lypinator | 0:bb348c97df44 | 1860 | the HAL_CAN_WakeUpFromRxMsgCallback could be implemented in the |
lypinator | 0:bb348c97df44 | 1861 | user file |
lypinator | 0:bb348c97df44 | 1862 | */ |
lypinator | 0:bb348c97df44 | 1863 | } |
lypinator | 0:bb348c97df44 | 1864 | |
lypinator | 0:bb348c97df44 | 1865 | /** |
lypinator | 0:bb348c97df44 | 1866 | * @brief Error CAN callback. |
lypinator | 0:bb348c97df44 | 1867 | * @param hcan pointer to a CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 1868 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 1869 | * @retval None |
lypinator | 0:bb348c97df44 | 1870 | */ |
lypinator | 0:bb348c97df44 | 1871 | __weak void HAL_CAN_ErrorCallback(CAN_HandleTypeDef *hcan) |
lypinator | 0:bb348c97df44 | 1872 | { |
lypinator | 0:bb348c97df44 | 1873 | /* Prevent unused argument(s) compilation warning */ |
lypinator | 0:bb348c97df44 | 1874 | UNUSED(hcan); |
lypinator | 0:bb348c97df44 | 1875 | |
lypinator | 0:bb348c97df44 | 1876 | /* NOTE : This function Should not be modified, when the callback is needed, |
lypinator | 0:bb348c97df44 | 1877 | the HAL_CAN_ErrorCallback could be implemented in the user file |
lypinator | 0:bb348c97df44 | 1878 | */ |
lypinator | 0:bb348c97df44 | 1879 | } |
lypinator | 0:bb348c97df44 | 1880 | |
lypinator | 0:bb348c97df44 | 1881 | /** |
lypinator | 0:bb348c97df44 | 1882 | * @} |
lypinator | 0:bb348c97df44 | 1883 | */ |
lypinator | 0:bb348c97df44 | 1884 | |
lypinator | 0:bb348c97df44 | 1885 | /** @defgroup CAN_Exported_Functions_Group6 Peripheral State and Error functions |
lypinator | 0:bb348c97df44 | 1886 | * @brief CAN Peripheral State functions |
lypinator | 0:bb348c97df44 | 1887 | * |
lypinator | 0:bb348c97df44 | 1888 | @verbatim |
lypinator | 0:bb348c97df44 | 1889 | ============================================================================== |
lypinator | 0:bb348c97df44 | 1890 | ##### Peripheral State and Error functions ##### |
lypinator | 0:bb348c97df44 | 1891 | ============================================================================== |
lypinator | 0:bb348c97df44 | 1892 | [..] |
lypinator | 0:bb348c97df44 | 1893 | This subsection provides functions allowing to : |
lypinator | 0:bb348c97df44 | 1894 | (+) HAL_CAN_GetState() : Return the CAN state. |
lypinator | 0:bb348c97df44 | 1895 | (+) HAL_CAN_GetError() : Return the CAN error codes if any. |
lypinator | 0:bb348c97df44 | 1896 | (+) HAL_CAN_ResetError(): Reset the CAN error codes if any. |
lypinator | 0:bb348c97df44 | 1897 | |
lypinator | 0:bb348c97df44 | 1898 | @endverbatim |
lypinator | 0:bb348c97df44 | 1899 | * @{ |
lypinator | 0:bb348c97df44 | 1900 | */ |
lypinator | 0:bb348c97df44 | 1901 | |
lypinator | 0:bb348c97df44 | 1902 | /** |
lypinator | 0:bb348c97df44 | 1903 | * @brief Return the CAN state. |
lypinator | 0:bb348c97df44 | 1904 | * @param hcan pointer to a CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 1905 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 1906 | * @retval HAL state |
lypinator | 0:bb348c97df44 | 1907 | */ |
lypinator | 0:bb348c97df44 | 1908 | HAL_CAN_StateTypeDef HAL_CAN_GetState(CAN_HandleTypeDef *hcan) |
lypinator | 0:bb348c97df44 | 1909 | { |
lypinator | 0:bb348c97df44 | 1910 | HAL_CAN_StateTypeDef state = hcan->State; |
lypinator | 0:bb348c97df44 | 1911 | |
lypinator | 0:bb348c97df44 | 1912 | if ((hcan->State == HAL_CAN_STATE_READY) || |
lypinator | 0:bb348c97df44 | 1913 | (hcan->State == HAL_CAN_STATE_LISTENING)) |
lypinator | 0:bb348c97df44 | 1914 | { |
lypinator | 0:bb348c97df44 | 1915 | /* Check sleep mode acknowledge flag */ |
lypinator | 0:bb348c97df44 | 1916 | if ((hcan->Instance->MSR & CAN_MSR_SLAK) != RESET) |
lypinator | 0:bb348c97df44 | 1917 | { |
lypinator | 0:bb348c97df44 | 1918 | /* Sleep mode is active */ |
lypinator | 0:bb348c97df44 | 1919 | state = HAL_CAN_STATE_SLEEP_ACTIVE; |
lypinator | 0:bb348c97df44 | 1920 | } |
lypinator | 0:bb348c97df44 | 1921 | /* Check sleep mode request flag */ |
lypinator | 0:bb348c97df44 | 1922 | else if ((hcan->Instance->MCR & CAN_MCR_SLEEP) != RESET) |
lypinator | 0:bb348c97df44 | 1923 | { |
lypinator | 0:bb348c97df44 | 1924 | /* Sleep mode request is pending */ |
lypinator | 0:bb348c97df44 | 1925 | state = HAL_CAN_STATE_SLEEP_PENDING; |
lypinator | 0:bb348c97df44 | 1926 | } |
lypinator | 0:bb348c97df44 | 1927 | } |
lypinator | 0:bb348c97df44 | 1928 | |
lypinator | 0:bb348c97df44 | 1929 | /* Return CAN state */ |
lypinator | 0:bb348c97df44 | 1930 | return state; |
lypinator | 0:bb348c97df44 | 1931 | } |
lypinator | 0:bb348c97df44 | 1932 | |
lypinator | 0:bb348c97df44 | 1933 | /** |
lypinator | 0:bb348c97df44 | 1934 | * @brief Return the CAN error code. |
lypinator | 0:bb348c97df44 | 1935 | * @param hcan pointer to a CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 1936 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 1937 | * @retval CAN Error Code |
lypinator | 0:bb348c97df44 | 1938 | */ |
lypinator | 0:bb348c97df44 | 1939 | uint32_t HAL_CAN_GetError(CAN_HandleTypeDef *hcan) |
lypinator | 0:bb348c97df44 | 1940 | { |
lypinator | 0:bb348c97df44 | 1941 | /* Return CAN error code */ |
lypinator | 0:bb348c97df44 | 1942 | return hcan->ErrorCode; |
lypinator | 0:bb348c97df44 | 1943 | } |
lypinator | 0:bb348c97df44 | 1944 | |
lypinator | 0:bb348c97df44 | 1945 | /** |
lypinator | 0:bb348c97df44 | 1946 | * @brief Reset the CAN error code. |
lypinator | 0:bb348c97df44 | 1947 | * @param hcan pointer to a CAN_HandleTypeDef structure that contains |
lypinator | 0:bb348c97df44 | 1948 | * the configuration information for the specified CAN. |
lypinator | 0:bb348c97df44 | 1949 | * @retval HAL status |
lypinator | 0:bb348c97df44 | 1950 | */ |
lypinator | 0:bb348c97df44 | 1951 | HAL_StatusTypeDef HAL_CAN_ResetError(CAN_HandleTypeDef *hcan) |
lypinator | 0:bb348c97df44 | 1952 | { |
lypinator | 0:bb348c97df44 | 1953 | HAL_StatusTypeDef status = HAL_OK; |
lypinator | 0:bb348c97df44 | 1954 | |
lypinator | 0:bb348c97df44 | 1955 | if ((hcan->State == HAL_CAN_STATE_READY) || |
lypinator | 0:bb348c97df44 | 1956 | (hcan->State == HAL_CAN_STATE_LISTENING)) |
lypinator | 0:bb348c97df44 | 1957 | { |
lypinator | 0:bb348c97df44 | 1958 | /* Reset CAN error code */ |
lypinator | 0:bb348c97df44 | 1959 | hcan->ErrorCode = 0U; |
lypinator | 0:bb348c97df44 | 1960 | } |
lypinator | 0:bb348c97df44 | 1961 | else |
lypinator | 0:bb348c97df44 | 1962 | { |
lypinator | 0:bb348c97df44 | 1963 | /* Update error code */ |
lypinator | 0:bb348c97df44 | 1964 | hcan->ErrorCode |= HAL_CAN_ERROR_NOT_INITIALIZED; |
lypinator | 0:bb348c97df44 | 1965 | |
lypinator | 0:bb348c97df44 | 1966 | status = HAL_ERROR; |
lypinator | 0:bb348c97df44 | 1967 | } |
lypinator | 0:bb348c97df44 | 1968 | |
lypinator | 0:bb348c97df44 | 1969 | /* Return the status */ |
lypinator | 0:bb348c97df44 | 1970 | return status; |
lypinator | 0:bb348c97df44 | 1971 | } |
lypinator | 0:bb348c97df44 | 1972 | |
lypinator | 0:bb348c97df44 | 1973 | /** |
lypinator | 0:bb348c97df44 | 1974 | * @} |
lypinator | 0:bb348c97df44 | 1975 | */ |
lypinator | 0:bb348c97df44 | 1976 | |
lypinator | 0:bb348c97df44 | 1977 | /** |
lypinator | 0:bb348c97df44 | 1978 | * @} |
lypinator | 0:bb348c97df44 | 1979 | */ |
lypinator | 0:bb348c97df44 | 1980 | |
lypinator | 0:bb348c97df44 | 1981 | #endif /* HAL_CAN_MODULE_ENABLED */ |
lypinator | 0:bb348c97df44 | 1982 | |
lypinator | 0:bb348c97df44 | 1983 | /** |
lypinator | 0:bb348c97df44 | 1984 | * @} |
lypinator | 0:bb348c97df44 | 1985 | */ |
lypinator | 0:bb348c97df44 | 1986 | |
lypinator | 0:bb348c97df44 | 1987 | #endif /* CAN1 */ |
lypinator | 0:bb348c97df44 | 1988 | |
lypinator | 0:bb348c97df44 | 1989 | /** |
lypinator | 0:bb348c97df44 | 1990 | * @} |
lypinator | 0:bb348c97df44 | 1991 | */ |
lypinator | 0:bb348c97df44 | 1992 | |
lypinator | 0:bb348c97df44 | 1993 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |