annotate Common/Drivers/STM32F4xx_HAL_DRIVER_v120/Src/stm32f4xx_hal_can.c @ 96:6eec2db15cf8 kittz

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