2 ******************************************************************************
\r
3 * @file stm32f10x_can.c
\r
4 * @author MCD Application Team
\r
6 * @date 11-March-2011
\r
7 * @brief This file provides all the CAN firmware functions.
\r
8 ******************************************************************************
\r
11 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
\r
12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
\r
13 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
\r
14 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
\r
15 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
\r
16 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
\r
18 * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
\r
19 ******************************************************************************
\r
22 /* Includes ------------------------------------------------------------------*/
\r
23 #include "stm32f10x_can.h"
\r
24 #include "stm32f10x_rcc.h"
\r
26 /** @addtogroup STM32F10x_StdPeriph_Driver
\r
31 * @brief CAN driver modules
\r
35 /** @defgroup CAN_Private_TypesDefinitions
\r
43 /** @defgroup CAN_Private_Defines
\r
47 /* CAN Master Control Register bits */
\r
49 #define MCR_DBF ((uint32_t)0x00010000) /* software master reset */
\r
51 /* CAN Mailbox Transmit Request */
\r
52 #define TMIDxR_TXRQ ((uint32_t)0x00000001) /* Transmit mailbox request */
\r
54 /* CAN Filter Master Register bits */
\r
55 #define FMR_FINIT ((uint32_t)0x00000001) /* Filter init mode */
\r
57 /* Time out for INAK bit */
\r
58 #define INAK_TIMEOUT ((uint32_t)0x0000FFFF)
\r
59 /* Time out for SLAK bit */
\r
60 #define SLAK_TIMEOUT ((uint32_t)0x0000FFFF)
\r
64 /* Flags in TSR register */
\r
65 #define CAN_FLAGS_TSR ((uint32_t)0x08000000)
\r
66 /* Flags in RF1R register */
\r
67 #define CAN_FLAGS_RF1R ((uint32_t)0x04000000)
\r
68 /* Flags in RF0R register */
\r
69 #define CAN_FLAGS_RF0R ((uint32_t)0x02000000)
\r
70 /* Flags in MSR register */
\r
71 #define CAN_FLAGS_MSR ((uint32_t)0x01000000)
\r
72 /* Flags in ESR register */
\r
73 #define CAN_FLAGS_ESR ((uint32_t)0x00F00000)
\r
75 /* Mailboxes definition */
\r
76 #define CAN_TXMAILBOX_0 ((uint8_t)0x00)
\r
77 #define CAN_TXMAILBOX_1 ((uint8_t)0x01)
\r
78 #define CAN_TXMAILBOX_2 ((uint8_t)0x02)
\r
82 #define CAN_MODE_MASK ((uint32_t) 0x00000003)
\r
87 /** @defgroup CAN_Private_Macros
\r
95 /** @defgroup CAN_Private_Variables
\r
103 /** @defgroup CAN_Private_FunctionPrototypes
\r
107 static ITStatus CheckITStatus(uint32_t CAN_Reg, uint32_t It_Bit);
\r
113 /** @defgroup CAN_Private_Functions
\r
118 * @brief Deinitializes the CAN peripheral registers to their default reset values.
\r
119 * @param CANx: where x can be 1 or 2 to select the CAN peripheral.
\r
122 void CAN_DeInit(CAN_TypeDef* CANx)
\r
124 /* Check the parameters */
\r
125 assert_param(IS_CAN_ALL_PERIPH(CANx));
\r
129 /* Enable CAN1 reset state */
\r
130 RCC_APB1PeriphResetCmd(RCC_APB1Periph_CAN1, ENABLE);
\r
131 /* Release CAN1 from reset state */
\r
132 RCC_APB1PeriphResetCmd(RCC_APB1Periph_CAN1, DISABLE);
\r
136 /* Enable CAN2 reset state */
\r
137 RCC_APB1PeriphResetCmd(RCC_APB1Periph_CAN2, ENABLE);
\r
138 /* Release CAN2 from reset state */
\r
139 RCC_APB1PeriphResetCmd(RCC_APB1Periph_CAN2, DISABLE);
\r
144 * @brief Initializes the CAN peripheral according to the specified
\r
145 * parameters in the CAN_InitStruct.
\r
146 * @param CANx: where x can be 1 or 2 to to select the CAN
\r
148 * @param CAN_InitStruct: pointer to a CAN_InitTypeDef structure that
\r
149 * contains the configuration information for the
\r
151 * @retval Constant indicates initialization succeed which will be
\r
152 * CAN_InitStatus_Failed or CAN_InitStatus_Success.
\r
154 uint8_t CAN_Init(CAN_TypeDef* CANx, CAN_InitTypeDef* CAN_InitStruct)
\r
156 uint8_t InitStatus = CAN_InitStatus_Failed;
\r
157 uint32_t wait_ack = 0x00000000;
\r
158 /* Check the parameters */
\r
159 assert_param(IS_CAN_ALL_PERIPH(CANx));
\r
160 assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_TTCM));
\r
161 assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_ABOM));
\r
162 assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_AWUM));
\r
163 assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_NART));
\r
164 assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_RFLM));
\r
165 assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_TXFP));
\r
166 assert_param(IS_CAN_MODE(CAN_InitStruct->CAN_Mode));
\r
167 assert_param(IS_CAN_SJW(CAN_InitStruct->CAN_SJW));
\r
168 assert_param(IS_CAN_BS1(CAN_InitStruct->CAN_BS1));
\r
169 assert_param(IS_CAN_BS2(CAN_InitStruct->CAN_BS2));
\r
170 assert_param(IS_CAN_PRESCALER(CAN_InitStruct->CAN_Prescaler));
\r
172 /* Exit from sleep mode */
\r
173 CANx->MCR &= (~(uint32_t)CAN_MCR_SLEEP);
\r
175 /* Request initialisation */
\r
176 CANx->MCR |= CAN_MCR_INRQ ;
\r
178 /* Wait the acknowledge */
\r
179 while (((CANx->MSR & CAN_MSR_INAK) != CAN_MSR_INAK) && (wait_ack != INAK_TIMEOUT))
\r
184 /* Check acknowledge */
\r
185 if ((CANx->MSR & CAN_MSR_INAK) != CAN_MSR_INAK)
\r
187 InitStatus = CAN_InitStatus_Failed;
\r
191 /* Set the time triggered communication mode */
\r
192 if (CAN_InitStruct->CAN_TTCM == ENABLE)
\r
194 CANx->MCR |= CAN_MCR_TTCM;
\r
198 CANx->MCR &= ~(uint32_t)CAN_MCR_TTCM;
\r
201 /* Set the automatic bus-off management */
\r
202 if (CAN_InitStruct->CAN_ABOM == ENABLE)
\r
204 CANx->MCR |= CAN_MCR_ABOM;
\r
208 CANx->MCR &= ~(uint32_t)CAN_MCR_ABOM;
\r
211 /* Set the automatic wake-up mode */
\r
212 if (CAN_InitStruct->CAN_AWUM == ENABLE)
\r
214 CANx->MCR |= CAN_MCR_AWUM;
\r
218 CANx->MCR &= ~(uint32_t)CAN_MCR_AWUM;
\r
221 /* Set the no automatic retransmission */
\r
222 if (CAN_InitStruct->CAN_NART == ENABLE)
\r
224 CANx->MCR |= CAN_MCR_NART;
\r
228 CANx->MCR &= ~(uint32_t)CAN_MCR_NART;
\r
231 /* Set the receive FIFO locked mode */
\r
232 if (CAN_InitStruct->CAN_RFLM == ENABLE)
\r
234 CANx->MCR |= CAN_MCR_RFLM;
\r
238 CANx->MCR &= ~(uint32_t)CAN_MCR_RFLM;
\r
241 /* Set the transmit FIFO priority */
\r
242 if (CAN_InitStruct->CAN_TXFP == ENABLE)
\r
244 CANx->MCR |= CAN_MCR_TXFP;
\r
248 CANx->MCR &= ~(uint32_t)CAN_MCR_TXFP;
\r
251 /* Set the bit timing register */
\r
252 CANx->BTR = (uint32_t)((uint32_t)CAN_InitStruct->CAN_Mode << 30) | \
\r
253 ((uint32_t)CAN_InitStruct->CAN_SJW << 24) | \
\r
254 ((uint32_t)CAN_InitStruct->CAN_BS1 << 16) | \
\r
255 ((uint32_t)CAN_InitStruct->CAN_BS2 << 20) | \
\r
256 ((uint32_t)CAN_InitStruct->CAN_Prescaler - 1);
\r
258 /* Request leave initialisation */
\r
259 CANx->MCR &= ~(uint32_t)CAN_MCR_INRQ;
\r
261 /* Wait the acknowledge */
\r
264 while (((CANx->MSR & CAN_MSR_INAK) == CAN_MSR_INAK) && (wait_ack != INAK_TIMEOUT))
\r
269 /* ...and check acknowledged */
\r
270 if ((CANx->MSR & CAN_MSR_INAK) == CAN_MSR_INAK)
\r
272 InitStatus = CAN_InitStatus_Failed;
\r
276 InitStatus = CAN_InitStatus_Success ;
\r
280 /* At this step, return the status of initialization */
\r
285 * @brief Initializes the CAN peripheral according to the specified
\r
286 * parameters in the CAN_FilterInitStruct.
\r
287 * @param CAN_FilterInitStruct: pointer to a CAN_FilterInitTypeDef
\r
288 * structure that contains the configuration
\r
292 void CAN_FilterInit(CAN_FilterInitTypeDef* CAN_FilterInitStruct)
\r
294 uint32_t filter_number_bit_pos = 0;
\r
295 /* Check the parameters */
\r
296 assert_param(IS_CAN_FILTER_NUMBER(CAN_FilterInitStruct->CAN_FilterNumber));
\r
297 assert_param(IS_CAN_FILTER_MODE(CAN_FilterInitStruct->CAN_FilterMode));
\r
298 assert_param(IS_CAN_FILTER_SCALE(CAN_FilterInitStruct->CAN_FilterScale));
\r
299 assert_param(IS_CAN_FILTER_FIFO(CAN_FilterInitStruct->CAN_FilterFIFOAssignment));
\r
300 assert_param(IS_FUNCTIONAL_STATE(CAN_FilterInitStruct->CAN_FilterActivation));
\r
302 filter_number_bit_pos = ((uint32_t)1) << CAN_FilterInitStruct->CAN_FilterNumber;
\r
304 /* Initialisation mode for the filter */
\r
305 CAN1->FMR |= FMR_FINIT;
\r
307 /* Filter Deactivation */
\r
308 CAN1->FA1R &= ~(uint32_t)filter_number_bit_pos;
\r
311 if (CAN_FilterInitStruct->CAN_FilterScale == CAN_FilterScale_16bit)
\r
313 /* 16-bit scale for the filter */
\r
314 CAN1->FS1R &= ~(uint32_t)filter_number_bit_pos;
\r
316 /* First 16-bit identifier and First 16-bit mask */
\r
317 /* Or First 16-bit identifier and Second 16-bit identifier */
\r
318 CAN1->sFilterRegister[CAN_FilterInitStruct->CAN_FilterNumber].FR1 =
\r
319 ((0x0000FFFF & (uint32_t)CAN_FilterInitStruct->CAN_FilterMaskIdLow) << 16) |
\r
320 (0x0000FFFF & (uint32_t)CAN_FilterInitStruct->CAN_FilterIdLow);
\r
322 /* Second 16-bit identifier and Second 16-bit mask */
\r
323 /* Or Third 16-bit identifier and Fourth 16-bit identifier */
\r
324 CAN1->sFilterRegister[CAN_FilterInitStruct->CAN_FilterNumber].FR2 =
\r
325 ((0x0000FFFF & (uint32_t)CAN_FilterInitStruct->CAN_FilterMaskIdHigh) << 16) |
\r
326 (0x0000FFFF & (uint32_t)CAN_FilterInitStruct->CAN_FilterIdHigh);
\r
329 if (CAN_FilterInitStruct->CAN_FilterScale == CAN_FilterScale_32bit)
\r
331 /* 32-bit scale for the filter */
\r
332 CAN1->FS1R |= filter_number_bit_pos;
\r
333 /* 32-bit identifier or First 32-bit identifier */
\r
334 CAN1->sFilterRegister[CAN_FilterInitStruct->CAN_FilterNumber].FR1 =
\r
335 ((0x0000FFFF & (uint32_t)CAN_FilterInitStruct->CAN_FilterIdHigh) << 16) |
\r
336 (0x0000FFFF & (uint32_t)CAN_FilterInitStruct->CAN_FilterIdLow);
\r
337 /* 32-bit mask or Second 32-bit identifier */
\r
338 CAN1->sFilterRegister[CAN_FilterInitStruct->CAN_FilterNumber].FR2 =
\r
339 ((0x0000FFFF & (uint32_t)CAN_FilterInitStruct->CAN_FilterMaskIdHigh) << 16) |
\r
340 (0x0000FFFF & (uint32_t)CAN_FilterInitStruct->CAN_FilterMaskIdLow);
\r
344 if (CAN_FilterInitStruct->CAN_FilterMode == CAN_FilterMode_IdMask)
\r
346 /*Id/Mask mode for the filter*/
\r
347 CAN1->FM1R &= ~(uint32_t)filter_number_bit_pos;
\r
349 else /* CAN_FilterInitStruct->CAN_FilterMode == CAN_FilterMode_IdList */
\r
351 /*Identifier list mode for the filter*/
\r
352 CAN1->FM1R |= (uint32_t)filter_number_bit_pos;
\r
355 /* Filter FIFO assignment */
\r
356 if (CAN_FilterInitStruct->CAN_FilterFIFOAssignment == CAN_Filter_FIFO0)
\r
358 /* FIFO 0 assignation for the filter */
\r
359 CAN1->FFA1R &= ~(uint32_t)filter_number_bit_pos;
\r
362 if (CAN_FilterInitStruct->CAN_FilterFIFOAssignment == CAN_Filter_FIFO1)
\r
364 /* FIFO 1 assignation for the filter */
\r
365 CAN1->FFA1R |= (uint32_t)filter_number_bit_pos;
\r
368 /* Filter activation */
\r
369 if (CAN_FilterInitStruct->CAN_FilterActivation == ENABLE)
\r
371 CAN1->FA1R |= filter_number_bit_pos;
\r
374 /* Leave the initialisation mode for the filter */
\r
375 CAN1->FMR &= ~FMR_FINIT;
\r
379 * @brief Fills each CAN_InitStruct member with its default value.
\r
380 * @param CAN_InitStruct: pointer to a CAN_InitTypeDef structure which
\r
381 * will be initialized.
\r
384 void CAN_StructInit(CAN_InitTypeDef* CAN_InitStruct)
\r
386 /* Reset CAN init structure parameters values */
\r
388 /* Initialize the time triggered communication mode */
\r
389 CAN_InitStruct->CAN_TTCM = DISABLE;
\r
391 /* Initialize the automatic bus-off management */
\r
392 CAN_InitStruct->CAN_ABOM = DISABLE;
\r
394 /* Initialize the automatic wake-up mode */
\r
395 CAN_InitStruct->CAN_AWUM = DISABLE;
\r
397 /* Initialize the no automatic retransmission */
\r
398 CAN_InitStruct->CAN_NART = DISABLE;
\r
400 /* Initialize the receive FIFO locked mode */
\r
401 CAN_InitStruct->CAN_RFLM = DISABLE;
\r
403 /* Initialize the transmit FIFO priority */
\r
404 CAN_InitStruct->CAN_TXFP = DISABLE;
\r
406 /* Initialize the CAN_Mode member */
\r
407 CAN_InitStruct->CAN_Mode = CAN_Mode_Normal;
\r
409 /* Initialize the CAN_SJW member */
\r
410 CAN_InitStruct->CAN_SJW = CAN_SJW_1tq;
\r
412 /* Initialize the CAN_BS1 member */
\r
413 CAN_InitStruct->CAN_BS1 = CAN_BS1_4tq;
\r
415 /* Initialize the CAN_BS2 member */
\r
416 CAN_InitStruct->CAN_BS2 = CAN_BS2_3tq;
\r
418 /* Initialize the CAN_Prescaler member */
\r
419 CAN_InitStruct->CAN_Prescaler = 1;
\r
423 * @brief Select the start bank filter for slave CAN.
\r
424 * @note This function applies only to STM32 Connectivity line devices.
\r
425 * @param CAN_BankNumber: Select the start slave bank filter from 1..27.
\r
428 void CAN_SlaveStartBank(uint8_t CAN_BankNumber)
\r
430 /* Check the parameters */
\r
431 assert_param(IS_CAN_BANKNUMBER(CAN_BankNumber));
\r
433 /* Enter Initialisation mode for the filter */
\r
434 CAN1->FMR |= FMR_FINIT;
\r
436 /* Select the start slave bank */
\r
437 CAN1->FMR &= (uint32_t)0xFFFFC0F1 ;
\r
438 CAN1->FMR |= (uint32_t)(CAN_BankNumber)<<8;
\r
440 /* Leave Initialisation mode for the filter */
\r
441 CAN1->FMR &= ~FMR_FINIT;
\r
445 * @brief Enables or disables the DBG Freeze for CAN.
\r
446 * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
\r
447 * @param NewState: new state of the CAN peripheral. This parameter can
\r
448 * be: ENABLE or DISABLE.
\r
451 void CAN_DBGFreeze(CAN_TypeDef* CANx, FunctionalState NewState)
\r
453 /* Check the parameters */
\r
454 assert_param(IS_CAN_ALL_PERIPH(CANx));
\r
455 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
457 if (NewState != DISABLE)
\r
459 /* Enable Debug Freeze */
\r
460 CANx->MCR |= MCR_DBF;
\r
464 /* Disable Debug Freeze */
\r
465 CANx->MCR &= ~MCR_DBF;
\r
471 * @brief Enables or disabes the CAN Time TriggerOperation communication mode.
\r
472 * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
\r
473 * @param NewState : Mode new state , can be one of @ref FunctionalState.
\r
474 * @note when enabled, Time stamp (TIME[15:0]) value is sent in the last
\r
475 * two data bytes of the 8-byte message: TIME[7:0] in data byte 6
\r
476 * and TIME[15:8] in data byte 7
\r
477 * @note DLC must be programmed as 8 in order Time Stamp (2 bytes) to be
\r
478 * sent over the CAN bus.
\r
481 void CAN_TTComModeCmd(CAN_TypeDef* CANx, FunctionalState NewState)
\r
483 /* Check the parameters */
\r
484 assert_param(IS_CAN_ALL_PERIPH(CANx));
\r
485 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
486 if (NewState != DISABLE)
\r
488 /* Enable the TTCM mode */
\r
489 CANx->MCR |= CAN_MCR_TTCM;
\r
492 CANx->sTxMailBox[0].TDTR |= ((uint32_t)CAN_TDT0R_TGT);
\r
493 CANx->sTxMailBox[1].TDTR |= ((uint32_t)CAN_TDT1R_TGT);
\r
494 CANx->sTxMailBox[2].TDTR |= ((uint32_t)CAN_TDT2R_TGT);
\r
498 /* Disable the TTCM mode */
\r
499 CANx->MCR &= (uint32_t)(~(uint32_t)CAN_MCR_TTCM);
\r
501 /* Reset TGT bits */
\r
502 CANx->sTxMailBox[0].TDTR &= ((uint32_t)~CAN_TDT0R_TGT);
\r
503 CANx->sTxMailBox[1].TDTR &= ((uint32_t)~CAN_TDT1R_TGT);
\r
504 CANx->sTxMailBox[2].TDTR &= ((uint32_t)~CAN_TDT2R_TGT);
\r
508 * @brief Initiates the transmission of a message.
\r
509 * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
\r
510 * @param TxMessage: pointer to a structure which contains CAN Id, CAN
\r
511 * DLC and CAN data.
\r
512 * @retval The number of the mailbox that is used for transmission
\r
513 * or CAN_TxStatus_NoMailBox if there is no empty mailbox.
\r
515 uint8_t CAN_Transmit(CAN_TypeDef* CANx, CanTxMsg* TxMessage)
\r
517 uint8_t transmit_mailbox = 0;
\r
518 /* Check the parameters */
\r
519 assert_param(IS_CAN_ALL_PERIPH(CANx));
\r
520 assert_param(IS_CAN_IDTYPE(TxMessage->IDE));
\r
521 assert_param(IS_CAN_RTR(TxMessage->RTR));
\r
522 assert_param(IS_CAN_DLC(TxMessage->DLC));
\r
524 /* Select one empty transmit mailbox */
\r
525 if ((CANx->TSR&CAN_TSR_TME0) == CAN_TSR_TME0)
\r
527 transmit_mailbox = 0;
\r
529 else if ((CANx->TSR&CAN_TSR_TME1) == CAN_TSR_TME1)
\r
531 transmit_mailbox = 1;
\r
533 else if ((CANx->TSR&CAN_TSR_TME2) == CAN_TSR_TME2)
\r
535 transmit_mailbox = 2;
\r
539 transmit_mailbox = CAN_TxStatus_NoMailBox;
\r
542 if (transmit_mailbox != CAN_TxStatus_NoMailBox)
\r
544 /* Set up the Id */
\r
545 CANx->sTxMailBox[transmit_mailbox].TIR &= TMIDxR_TXRQ;
\r
546 if (TxMessage->IDE == CAN_Id_Standard)
\r
548 assert_param(IS_CAN_STDID(TxMessage->StdId));
\r
549 CANx->sTxMailBox[transmit_mailbox].TIR |= ((TxMessage->StdId << 21) | \
\r
554 assert_param(IS_CAN_EXTID(TxMessage->ExtId));
\r
555 CANx->sTxMailBox[transmit_mailbox].TIR |= ((TxMessage->ExtId << 3) | \
\r
560 /* Set up the DLC */
\r
561 TxMessage->DLC &= (uint8_t)0x0000000F;
\r
562 CANx->sTxMailBox[transmit_mailbox].TDTR &= (uint32_t)0xFFFFFFF0;
\r
563 CANx->sTxMailBox[transmit_mailbox].TDTR |= TxMessage->DLC;
\r
565 /* Set up the data field */
\r
566 CANx->sTxMailBox[transmit_mailbox].TDLR = (((uint32_t)TxMessage->Data[3] << 24) |
\r
567 ((uint32_t)TxMessage->Data[2] << 16) |
\r
568 ((uint32_t)TxMessage->Data[1] << 8) |
\r
569 ((uint32_t)TxMessage->Data[0]));
\r
570 CANx->sTxMailBox[transmit_mailbox].TDHR = (((uint32_t)TxMessage->Data[7] << 24) |
\r
571 ((uint32_t)TxMessage->Data[6] << 16) |
\r
572 ((uint32_t)TxMessage->Data[5] << 8) |
\r
573 ((uint32_t)TxMessage->Data[4]));
\r
574 /* Request transmission */
\r
575 CANx->sTxMailBox[transmit_mailbox].TIR |= TMIDxR_TXRQ;
\r
577 return transmit_mailbox;
\r
581 * @brief Checks the transmission of a message.
\r
582 * @param CANx: where x can be 1 or 2 to to select the
\r
584 * @param TransmitMailbox: the number of the mailbox that is used for
\r
586 * @retval CAN_TxStatus_Ok if the CAN driver transmits the message, CAN_TxStatus_Failed
\r
587 * in an other case.
\r
589 uint8_t CAN_TransmitStatus(CAN_TypeDef* CANx, uint8_t TransmitMailbox)
\r
591 uint32_t state = 0;
\r
593 /* Check the parameters */
\r
594 assert_param(IS_CAN_ALL_PERIPH(CANx));
\r
595 assert_param(IS_CAN_TRANSMITMAILBOX(TransmitMailbox));
\r
597 switch (TransmitMailbox)
\r
599 case (CAN_TXMAILBOX_0):
\r
600 state = CANx->TSR & (CAN_TSR_RQCP0 | CAN_TSR_TXOK0 | CAN_TSR_TME0);
\r
602 case (CAN_TXMAILBOX_1):
\r
603 state = CANx->TSR & (CAN_TSR_RQCP1 | CAN_TSR_TXOK1 | CAN_TSR_TME1);
\r
605 case (CAN_TXMAILBOX_2):
\r
606 state = CANx->TSR & (CAN_TSR_RQCP2 | CAN_TSR_TXOK2 | CAN_TSR_TME2);
\r
609 state = CAN_TxStatus_Failed;
\r
614 /* transmit pending */
\r
615 case (0x0): state = CAN_TxStatus_Pending;
\r
617 /* transmit failed */
\r
618 case (CAN_TSR_RQCP0 | CAN_TSR_TME0): state = CAN_TxStatus_Failed;
\r
620 case (CAN_TSR_RQCP1 | CAN_TSR_TME1): state = CAN_TxStatus_Failed;
\r
622 case (CAN_TSR_RQCP2 | CAN_TSR_TME2): state = CAN_TxStatus_Failed;
\r
624 /* transmit succeeded */
\r
625 case (CAN_TSR_RQCP0 | CAN_TSR_TXOK0 | CAN_TSR_TME0):state = CAN_TxStatus_Ok;
\r
627 case (CAN_TSR_RQCP1 | CAN_TSR_TXOK1 | CAN_TSR_TME1):state = CAN_TxStatus_Ok;
\r
629 case (CAN_TSR_RQCP2 | CAN_TSR_TXOK2 | CAN_TSR_TME2):state = CAN_TxStatus_Ok;
\r
631 default: state = CAN_TxStatus_Failed;
\r
634 return (uint8_t) state;
\r
638 * @brief Cancels a transmit request.
\r
639 * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
\r
640 * @param Mailbox: Mailbox number.
\r
643 void CAN_CancelTransmit(CAN_TypeDef* CANx, uint8_t Mailbox)
\r
645 /* Check the parameters */
\r
646 assert_param(IS_CAN_ALL_PERIPH(CANx));
\r
647 assert_param(IS_CAN_TRANSMITMAILBOX(Mailbox));
\r
648 /* abort transmission */
\r
651 case (CAN_TXMAILBOX_0): CANx->TSR |= CAN_TSR_ABRQ0;
\r
653 case (CAN_TXMAILBOX_1): CANx->TSR |= CAN_TSR_ABRQ1;
\r
655 case (CAN_TXMAILBOX_2): CANx->TSR |= CAN_TSR_ABRQ2;
\r
664 * @brief Receives a message.
\r
665 * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
\r
666 * @param FIFONumber: Receive FIFO number, CAN_FIFO0 or CAN_FIFO1.
\r
667 * @param RxMessage: pointer to a structure receive message which contains
\r
668 * CAN Id, CAN DLC, CAN datas and FMI number.
\r
671 void CAN_Receive(CAN_TypeDef* CANx, uint8_t FIFONumber, CanRxMsg* RxMessage)
\r
673 /* Check the parameters */
\r
674 assert_param(IS_CAN_ALL_PERIPH(CANx));
\r
675 assert_param(IS_CAN_FIFO(FIFONumber));
\r
677 RxMessage->IDE = (uint8_t)0x04 & CANx->sFIFOMailBox[FIFONumber].RIR;
\r
678 if (RxMessage->IDE == CAN_Id_Standard)
\r
680 RxMessage->StdId = (uint32_t)0x000007FF & (CANx->sFIFOMailBox[FIFONumber].RIR >> 21);
\r
684 RxMessage->ExtId = (uint32_t)0x1FFFFFFF & (CANx->sFIFOMailBox[FIFONumber].RIR >> 3);
\r
687 RxMessage->RTR = (uint8_t)0x02 & CANx->sFIFOMailBox[FIFONumber].RIR;
\r
689 RxMessage->DLC = (uint8_t)0x0F & CANx->sFIFOMailBox[FIFONumber].RDTR;
\r
691 RxMessage->FMI = (uint8_t)0xFF & (CANx->sFIFOMailBox[FIFONumber].RDTR >> 8);
\r
692 /* Get the data field */
\r
693 RxMessage->Data[0] = (uint8_t)0xFF & CANx->sFIFOMailBox[FIFONumber].RDLR;
\r
694 RxMessage->Data[1] = (uint8_t)0xFF & (CANx->sFIFOMailBox[FIFONumber].RDLR >> 8);
\r
695 RxMessage->Data[2] = (uint8_t)0xFF & (CANx->sFIFOMailBox[FIFONumber].RDLR >> 16);
\r
696 RxMessage->Data[3] = (uint8_t)0xFF & (CANx->sFIFOMailBox[FIFONumber].RDLR >> 24);
\r
697 RxMessage->Data[4] = (uint8_t)0xFF & CANx->sFIFOMailBox[FIFONumber].RDHR;
\r
698 RxMessage->Data[5] = (uint8_t)0xFF & (CANx->sFIFOMailBox[FIFONumber].RDHR >> 8);
\r
699 RxMessage->Data[6] = (uint8_t)0xFF & (CANx->sFIFOMailBox[FIFONumber].RDHR >> 16);
\r
700 RxMessage->Data[7] = (uint8_t)0xFF & (CANx->sFIFOMailBox[FIFONumber].RDHR >> 24);
\r
701 /* Release the FIFO */
\r
702 /* Release FIFO0 */
\r
703 if (FIFONumber == CAN_FIFO0)
\r
705 CANx->RF0R |= CAN_RF0R_RFOM0;
\r
707 /* Release FIFO1 */
\r
708 else /* FIFONumber == CAN_FIFO1 */
\r
710 CANx->RF1R |= CAN_RF1R_RFOM1;
\r
715 * @brief Releases the specified FIFO.
\r
716 * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
\r
717 * @param FIFONumber: FIFO to release, CAN_FIFO0 or CAN_FIFO1.
\r
720 void CAN_FIFORelease(CAN_TypeDef* CANx, uint8_t FIFONumber)
\r
722 /* Check the parameters */
\r
723 assert_param(IS_CAN_ALL_PERIPH(CANx));
\r
724 assert_param(IS_CAN_FIFO(FIFONumber));
\r
725 /* Release FIFO0 */
\r
726 if (FIFONumber == CAN_FIFO0)
\r
728 CANx->RF0R |= CAN_RF0R_RFOM0;
\r
730 /* Release FIFO1 */
\r
731 else /* FIFONumber == CAN_FIFO1 */
\r
733 CANx->RF1R |= CAN_RF1R_RFOM1;
\r
738 * @brief Returns the number of pending messages.
\r
739 * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
\r
740 * @param FIFONumber: Receive FIFO number, CAN_FIFO0 or CAN_FIFO1.
\r
741 * @retval NbMessage : which is the number of pending message.
\r
743 uint8_t CAN_MessagePending(CAN_TypeDef* CANx, uint8_t FIFONumber)
\r
745 uint8_t message_pending=0;
\r
746 /* Check the parameters */
\r
747 assert_param(IS_CAN_ALL_PERIPH(CANx));
\r
748 assert_param(IS_CAN_FIFO(FIFONumber));
\r
749 if (FIFONumber == CAN_FIFO0)
\r
751 message_pending = (uint8_t)(CANx->RF0R&(uint32_t)0x03);
\r
753 else if (FIFONumber == CAN_FIFO1)
\r
755 message_pending = (uint8_t)(CANx->RF1R&(uint32_t)0x03);
\r
759 message_pending = 0;
\r
761 return message_pending;
\r
766 * @brief Select the CAN Operation mode.
\r
767 * @param CAN_OperatingMode : CAN Operating Mode. This parameter can be one
\r
768 * of @ref CAN_OperatingMode_TypeDef enumeration.
\r
769 * @retval status of the requested mode which can be
\r
770 * - CAN_ModeStatus_Failed CAN failed entering the specific mode
\r
771 * - CAN_ModeStatus_Success CAN Succeed entering the specific mode
\r
774 uint8_t CAN_OperatingModeRequest(CAN_TypeDef* CANx, uint8_t CAN_OperatingMode)
\r
776 uint8_t status = CAN_ModeStatus_Failed;
\r
778 /* Timeout for INAK or also for SLAK bits*/
\r
779 uint32_t timeout = INAK_TIMEOUT;
\r
781 /* Check the parameters */
\r
782 assert_param(IS_CAN_ALL_PERIPH(CANx));
\r
783 assert_param(IS_CAN_OPERATING_MODE(CAN_OperatingMode));
\r
785 if (CAN_OperatingMode == CAN_OperatingMode_Initialization)
\r
787 /* Request initialisation */
\r
788 CANx->MCR = (uint32_t)((CANx->MCR & (uint32_t)(~(uint32_t)CAN_MCR_SLEEP)) | CAN_MCR_INRQ);
\r
790 /* Wait the acknowledge */
\r
791 while (((CANx->MSR & CAN_MODE_MASK) != CAN_MSR_INAK) && (timeout != 0))
\r
795 if ((CANx->MSR & CAN_MODE_MASK) != CAN_MSR_INAK)
\r
797 status = CAN_ModeStatus_Failed;
\r
801 status = CAN_ModeStatus_Success;
\r
804 else if (CAN_OperatingMode == CAN_OperatingMode_Normal)
\r
806 /* Request leave initialisation and sleep mode and enter Normal mode */
\r
807 CANx->MCR &= (uint32_t)(~(CAN_MCR_SLEEP|CAN_MCR_INRQ));
\r
809 /* Wait the acknowledge */
\r
810 while (((CANx->MSR & CAN_MODE_MASK) != 0) && (timeout!=0))
\r
814 if ((CANx->MSR & CAN_MODE_MASK) != 0)
\r
816 status = CAN_ModeStatus_Failed;
\r
820 status = CAN_ModeStatus_Success;
\r
823 else if (CAN_OperatingMode == CAN_OperatingMode_Sleep)
\r
825 /* Request Sleep mode */
\r
826 CANx->MCR = (uint32_t)((CANx->MCR & (uint32_t)(~(uint32_t)CAN_MCR_INRQ)) | CAN_MCR_SLEEP);
\r
828 /* Wait the acknowledge */
\r
829 while (((CANx->MSR & CAN_MODE_MASK) != CAN_MSR_SLAK) && (timeout!=0))
\r
833 if ((CANx->MSR & CAN_MODE_MASK) != CAN_MSR_SLAK)
\r
835 status = CAN_ModeStatus_Failed;
\r
839 status = CAN_ModeStatus_Success;
\r
844 status = CAN_ModeStatus_Failed;
\r
847 return (uint8_t) status;
\r
851 * @brief Enters the low power mode.
\r
852 * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
\r
853 * @retval status: CAN_Sleep_Ok if sleep entered, CAN_Sleep_Failed in an
\r
856 uint8_t CAN_Sleep(CAN_TypeDef* CANx)
\r
858 uint8_t sleepstatus = CAN_Sleep_Failed;
\r
860 /* Check the parameters */
\r
861 assert_param(IS_CAN_ALL_PERIPH(CANx));
\r
863 /* Request Sleep mode */
\r
864 CANx->MCR = (((CANx->MCR) & (uint32_t)(~(uint32_t)CAN_MCR_INRQ)) | CAN_MCR_SLEEP);
\r
866 /* Sleep mode status */
\r
867 if ((CANx->MSR & (CAN_MSR_SLAK|CAN_MSR_INAK)) == CAN_MSR_SLAK)
\r
869 /* Sleep mode not entered */
\r
870 sleepstatus = CAN_Sleep_Ok;
\r
872 /* return sleep mode status */
\r
873 return (uint8_t)sleepstatus;
\r
877 * @brief Wakes the CAN up.
\r
878 * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
\r
879 * @retval status: CAN_WakeUp_Ok if sleep mode left, CAN_WakeUp_Failed in an
\r
882 uint8_t CAN_WakeUp(CAN_TypeDef* CANx)
\r
884 uint32_t wait_slak = SLAK_TIMEOUT;
\r
885 uint8_t wakeupstatus = CAN_WakeUp_Failed;
\r
887 /* Check the parameters */
\r
888 assert_param(IS_CAN_ALL_PERIPH(CANx));
\r
890 /* Wake up request */
\r
891 CANx->MCR &= ~(uint32_t)CAN_MCR_SLEEP;
\r
893 /* Sleep mode status */
\r
894 while(((CANx->MSR & CAN_MSR_SLAK) == CAN_MSR_SLAK)&&(wait_slak!=0x00))
\r
898 if((CANx->MSR & CAN_MSR_SLAK) != CAN_MSR_SLAK)
\r
900 /* wake up done : Sleep mode exited */
\r
901 wakeupstatus = CAN_WakeUp_Ok;
\r
903 /* return wakeup status */
\r
904 return (uint8_t)wakeupstatus;
\r
909 * @brief Returns the CANx's last error code (LEC).
\r
910 * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
\r
911 * @retval CAN_ErrorCode: specifies the Error code :
\r
912 * - CAN_ERRORCODE_NoErr No Error
\r
913 * - CAN_ERRORCODE_StuffErr Stuff Error
\r
914 * - CAN_ERRORCODE_FormErr Form Error
\r
915 * - CAN_ERRORCODE_ACKErr Acknowledgment Error
\r
916 * - CAN_ERRORCODE_BitRecessiveErr Bit Recessive Error
\r
917 * - CAN_ERRORCODE_BitDominantErr Bit Dominant Error
\r
918 * - CAN_ERRORCODE_CRCErr CRC Error
\r
919 * - CAN_ERRORCODE_SoftwareSetErr Software Set Error
\r
922 uint8_t CAN_GetLastErrorCode(CAN_TypeDef* CANx)
\r
924 uint8_t errorcode=0;
\r
926 /* Check the parameters */
\r
927 assert_param(IS_CAN_ALL_PERIPH(CANx));
\r
929 /* Get the error code*/
\r
930 errorcode = (((uint8_t)CANx->ESR) & (uint8_t)CAN_ESR_LEC);
\r
932 /* Return the error code*/
\r
936 * @brief Returns the CANx Receive Error Counter (REC).
\r
937 * @note In case of an error during reception, this counter is incremented
\r
938 * by 1 or by 8 depending on the error condition as defined by the CAN
\r
939 * standard. After every successful reception, the counter is
\r
940 * decremented by 1 or reset to 120 if its value was higher than 128.
\r
941 * When the counter value exceeds 127, the CAN controller enters the
\r
942 * error passive state.
\r
943 * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
\r
944 * @retval CAN Receive Error Counter.
\r
946 uint8_t CAN_GetReceiveErrorCounter(CAN_TypeDef* CANx)
\r
950 /* Check the parameters */
\r
951 assert_param(IS_CAN_ALL_PERIPH(CANx));
\r
953 /* Get the Receive Error Counter*/
\r
954 counter = (uint8_t)((CANx->ESR & CAN_ESR_REC)>> 24);
\r
956 /* Return the Receive Error Counter*/
\r
962 * @brief Returns the LSB of the 9-bit CANx Transmit Error Counter(TEC).
\r
963 * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
\r
964 * @retval LSB of the 9-bit CAN Transmit Error Counter.
\r
966 uint8_t CAN_GetLSBTransmitErrorCounter(CAN_TypeDef* CANx)
\r
970 /* Check the parameters */
\r
971 assert_param(IS_CAN_ALL_PERIPH(CANx));
\r
973 /* Get the LSB of the 9-bit CANx Transmit Error Counter(TEC) */
\r
974 counter = (uint8_t)((CANx->ESR & CAN_ESR_TEC)>> 16);
\r
976 /* Return the LSB of the 9-bit CANx Transmit Error Counter(TEC) */
\r
982 * @brief Enables or disables the specified CANx interrupts.
\r
983 * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
\r
984 * @param CAN_IT: specifies the CAN interrupt sources to be enabled or disabled.
\r
985 * This parameter can be:
\r
999 * @param NewState: new state of the CAN interrupts.
\r
1000 * This parameter can be: ENABLE or DISABLE.
\r
1003 void CAN_ITConfig(CAN_TypeDef* CANx, uint32_t CAN_IT, FunctionalState NewState)
\r
1005 /* Check the parameters */
\r
1006 assert_param(IS_CAN_ALL_PERIPH(CANx));
\r
1007 assert_param(IS_CAN_IT(CAN_IT));
\r
1008 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
1010 if (NewState != DISABLE)
\r
1012 /* Enable the selected CANx interrupt */
\r
1013 CANx->IER |= CAN_IT;
\r
1017 /* Disable the selected CANx interrupt */
\r
1018 CANx->IER &= ~CAN_IT;
\r
1022 * @brief Checks whether the specified CAN flag is set or not.
\r
1023 * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
\r
1024 * @param CAN_FLAG: specifies the flag to check.
\r
1025 * This parameter can be one of the following flags:
\r
1029 * - CAN_FLAG_RQCP0
\r
1030 * - CAN_FLAG_RQCP1
\r
1031 * - CAN_FLAG_RQCP2
\r
1032 * - CAN_FLAG_FMP1
\r
1034 * - CAN_FLAG_FOV1
\r
1035 * - CAN_FLAG_FMP0
\r
1037 * - CAN_FLAG_FOV0
\r
1039 * - CAN_FLAG_SLAK
\r
1041 * @retval The new state of CAN_FLAG (SET or RESET).
\r
1043 FlagStatus CAN_GetFlagStatus(CAN_TypeDef* CANx, uint32_t CAN_FLAG)
\r
1045 FlagStatus bitstatus = RESET;
\r
1047 /* Check the parameters */
\r
1048 assert_param(IS_CAN_ALL_PERIPH(CANx));
\r
1049 assert_param(IS_CAN_GET_FLAG(CAN_FLAG));
\r
1052 if((CAN_FLAG & CAN_FLAGS_ESR) != (uint32_t)RESET)
\r
1054 /* Check the status of the specified CAN flag */
\r
1055 if ((CANx->ESR & (CAN_FLAG & 0x000FFFFF)) != (uint32_t)RESET)
\r
1057 /* CAN_FLAG is set */
\r
1062 /* CAN_FLAG is reset */
\r
1063 bitstatus = RESET;
\r
1066 else if((CAN_FLAG & CAN_FLAGS_MSR) != (uint32_t)RESET)
\r
1068 /* Check the status of the specified CAN flag */
\r
1069 if ((CANx->MSR & (CAN_FLAG & 0x000FFFFF)) != (uint32_t)RESET)
\r
1071 /* CAN_FLAG is set */
\r
1076 /* CAN_FLAG is reset */
\r
1077 bitstatus = RESET;
\r
1080 else if((CAN_FLAG & CAN_FLAGS_TSR) != (uint32_t)RESET)
\r
1082 /* Check the status of the specified CAN flag */
\r
1083 if ((CANx->TSR & (CAN_FLAG & 0x000FFFFF)) != (uint32_t)RESET)
\r
1085 /* CAN_FLAG is set */
\r
1090 /* CAN_FLAG is reset */
\r
1091 bitstatus = RESET;
\r
1094 else if((CAN_FLAG & CAN_FLAGS_RF0R) != (uint32_t)RESET)
\r
1096 /* Check the status of the specified CAN flag */
\r
1097 if ((CANx->RF0R & (CAN_FLAG & 0x000FFFFF)) != (uint32_t)RESET)
\r
1099 /* CAN_FLAG is set */
\r
1104 /* CAN_FLAG is reset */
\r
1105 bitstatus = RESET;
\r
1108 else /* If(CAN_FLAG & CAN_FLAGS_RF1R != (uint32_t)RESET) */
\r
1110 /* Check the status of the specified CAN flag */
\r
1111 if ((uint32_t)(CANx->RF1R & (CAN_FLAG & 0x000FFFFF)) != (uint32_t)RESET)
\r
1113 /* CAN_FLAG is set */
\r
1118 /* CAN_FLAG is reset */
\r
1119 bitstatus = RESET;
\r
1122 /* Return the CAN_FLAG status */
\r
1127 * @brief Clears the CAN's pending flags.
\r
1128 * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
\r
1129 * @param CAN_FLAG: specifies the flag to clear.
\r
1130 * This parameter can be one of the following flags:
\r
1131 * - CAN_FLAG_RQCP0
\r
1132 * - CAN_FLAG_RQCP1
\r
1133 * - CAN_FLAG_RQCP2
\r
1135 * - CAN_FLAG_FOV1
\r
1137 * - CAN_FLAG_FOV0
\r
1139 * - CAN_FLAG_SLAK
\r
1143 void CAN_ClearFlag(CAN_TypeDef* CANx, uint32_t CAN_FLAG)
\r
1145 uint32_t flagtmp=0;
\r
1146 /* Check the parameters */
\r
1147 assert_param(IS_CAN_ALL_PERIPH(CANx));
\r
1148 assert_param(IS_CAN_CLEAR_FLAG(CAN_FLAG));
\r
1150 if (CAN_FLAG == CAN_FLAG_LEC) /* ESR register */
\r
1152 /* Clear the selected CAN flags */
\r
1153 CANx->ESR = (uint32_t)RESET;
\r
1155 else /* MSR or TSR or RF0R or RF1R */
\r
1157 flagtmp = CAN_FLAG & 0x000FFFFF;
\r
1159 if ((CAN_FLAG & CAN_FLAGS_RF0R)!=(uint32_t)RESET)
\r
1161 /* Receive Flags */
\r
1162 CANx->RF0R = (uint32_t)(flagtmp);
\r
1164 else if ((CAN_FLAG & CAN_FLAGS_RF1R)!=(uint32_t)RESET)
\r
1166 /* Receive Flags */
\r
1167 CANx->RF1R = (uint32_t)(flagtmp);
\r
1169 else if ((CAN_FLAG & CAN_FLAGS_TSR)!=(uint32_t)RESET)
\r
1171 /* Transmit Flags */
\r
1172 CANx->TSR = (uint32_t)(flagtmp);
\r
1174 else /* If((CAN_FLAG & CAN_FLAGS_MSR)!=(uint32_t)RESET) */
\r
1176 /* Operating mode Flags */
\r
1177 CANx->MSR = (uint32_t)(flagtmp);
\r
1183 * @brief Checks whether the specified CANx interrupt has occurred or not.
\r
1184 * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
\r
1185 * @param CAN_IT: specifies the CAN interrupt source to check.
\r
1186 * This parameter can be one of the following flags:
\r
1201 * @retval The current state of CAN_IT (SET or RESET).
\r
1203 ITStatus CAN_GetITStatus(CAN_TypeDef* CANx, uint32_t CAN_IT)
\r
1205 ITStatus itstatus = RESET;
\r
1206 /* Check the parameters */
\r
1207 assert_param(IS_CAN_ALL_PERIPH(CANx));
\r
1208 assert_param(IS_CAN_IT(CAN_IT));
\r
1210 /* check the enable interrupt bit */
\r
1211 if((CANx->IER & CAN_IT) != RESET)
\r
1213 /* in case the Interrupt is enabled, .... */
\r
1217 /* Check CAN_TSR_RQCPx bits */
\r
1218 itstatus = CheckITStatus(CANx->TSR, CAN_TSR_RQCP0|CAN_TSR_RQCP1|CAN_TSR_RQCP2);
\r
1221 /* Check CAN_RF0R_FMP0 bit */
\r
1222 itstatus = CheckITStatus(CANx->RF0R, CAN_RF0R_FMP0);
\r
1225 /* Check CAN_RF0R_FULL0 bit */
\r
1226 itstatus = CheckITStatus(CANx->RF0R, CAN_RF0R_FULL0);
\r
1229 /* Check CAN_RF0R_FOVR0 bit */
\r
1230 itstatus = CheckITStatus(CANx->RF0R, CAN_RF0R_FOVR0);
\r
1233 /* Check CAN_RF1R_FMP1 bit */
\r
1234 itstatus = CheckITStatus(CANx->RF1R, CAN_RF1R_FMP1);
\r
1237 /* Check CAN_RF1R_FULL1 bit */
\r
1238 itstatus = CheckITStatus(CANx->RF1R, CAN_RF1R_FULL1);
\r
1241 /* Check CAN_RF1R_FOVR1 bit */
\r
1242 itstatus = CheckITStatus(CANx->RF1R, CAN_RF1R_FOVR1);
\r
1245 /* Check CAN_MSR_WKUI bit */
\r
1246 itstatus = CheckITStatus(CANx->MSR, CAN_MSR_WKUI);
\r
1249 /* Check CAN_MSR_SLAKI bit */
\r
1250 itstatus = CheckITStatus(CANx->MSR, CAN_MSR_SLAKI);
\r
1253 /* Check CAN_ESR_EWGF bit */
\r
1254 itstatus = CheckITStatus(CANx->ESR, CAN_ESR_EWGF);
\r
1257 /* Check CAN_ESR_EPVF bit */
\r
1258 itstatus = CheckITStatus(CANx->ESR, CAN_ESR_EPVF);
\r
1261 /* Check CAN_ESR_BOFF bit */
\r
1262 itstatus = CheckITStatus(CANx->ESR, CAN_ESR_BOFF);
\r
1265 /* Check CAN_ESR_LEC bit */
\r
1266 itstatus = CheckITStatus(CANx->ESR, CAN_ESR_LEC);
\r
1269 /* Check CAN_MSR_ERRI bit */
\r
1270 itstatus = CheckITStatus(CANx->MSR, CAN_MSR_ERRI);
\r
1273 /* in case of error, return RESET */
\r
1280 /* in case the Interrupt is not enabled, return RESET */
\r
1284 /* Return the CAN_IT status */
\r
1289 * @brief Clears the CANx's interrupt pending bits.
\r
1290 * @param CANx: where x can be 1 or 2 to to select the CAN peripheral.
\r
1291 * @param CAN_IT: specifies the interrupt pending bit to clear.
\r
1306 void CAN_ClearITPendingBit(CAN_TypeDef* CANx, uint32_t CAN_IT)
\r
1308 /* Check the parameters */
\r
1309 assert_param(IS_CAN_ALL_PERIPH(CANx));
\r
1310 assert_param(IS_CAN_CLEAR_IT(CAN_IT));
\r
1315 /* Clear CAN_TSR_RQCPx (rc_w1)*/
\r
1316 CANx->TSR = CAN_TSR_RQCP0|CAN_TSR_RQCP1|CAN_TSR_RQCP2;
\r
1319 /* Clear CAN_RF0R_FULL0 (rc_w1)*/
\r
1320 CANx->RF0R = CAN_RF0R_FULL0;
\r
1323 /* Clear CAN_RF0R_FOVR0 (rc_w1)*/
\r
1324 CANx->RF0R = CAN_RF0R_FOVR0;
\r
1327 /* Clear CAN_RF1R_FULL1 (rc_w1)*/
\r
1328 CANx->RF1R = CAN_RF1R_FULL1;
\r
1331 /* Clear CAN_RF1R_FOVR1 (rc_w1)*/
\r
1332 CANx->RF1R = CAN_RF1R_FOVR1;
\r
1335 /* Clear CAN_MSR_WKUI (rc_w1)*/
\r
1336 CANx->MSR = CAN_MSR_WKUI;
\r
1339 /* Clear CAN_MSR_SLAKI (rc_w1)*/
\r
1340 CANx->MSR = CAN_MSR_SLAKI;
\r
1343 /* Clear CAN_MSR_ERRI (rc_w1) */
\r
1344 CANx->MSR = CAN_MSR_ERRI;
\r
1345 /* Note : the corresponding Flag is cleared by hardware depending
\r
1346 of the CAN Bus status*/
\r
1349 /* Clear CAN_MSR_ERRI (rc_w1) */
\r
1350 CANx->MSR = CAN_MSR_ERRI;
\r
1351 /* Note : the corresponding Flag is cleared by hardware depending
\r
1352 of the CAN Bus status*/
\r
1355 /* Clear CAN_MSR_ERRI (rc_w1) */
\r
1356 CANx->MSR = CAN_MSR_ERRI;
\r
1357 /* Note : the corresponding Flag is cleared by hardware depending
\r
1358 of the CAN Bus status*/
\r
1361 /* Clear LEC bits */
\r
1362 CANx->ESR = RESET;
\r
1363 /* Clear CAN_MSR_ERRI (rc_w1) */
\r
1364 CANx->MSR = CAN_MSR_ERRI;
\r
1367 /*Clear LEC bits */
\r
1368 CANx->ESR = RESET;
\r
1369 /* Clear CAN_MSR_ERRI (rc_w1) */
\r
1370 CANx->MSR = CAN_MSR_ERRI;
\r
1371 /* Note : BOFF, EPVF and EWGF Flags are cleared by hardware depending
\r
1372 of the CAN Bus status*/
\r
1380 * @brief Checks whether the CAN interrupt has occurred or not.
\r
1381 * @param CAN_Reg: specifies the CAN interrupt register to check.
\r
1382 * @param It_Bit: specifies the interrupt source bit to check.
\r
1383 * @retval The new state of the CAN Interrupt (SET or RESET).
\r
1385 static ITStatus CheckITStatus(uint32_t CAN_Reg, uint32_t It_Bit)
\r
1387 ITStatus pendingbitstatus = RESET;
\r
1389 if ((CAN_Reg & It_Bit) != (uint32_t)RESET)
\r
1391 /* CAN_IT is set */
\r
1392 pendingbitstatus = SET;
\r
1396 /* CAN_IT is reset */
\r
1397 pendingbitstatus = RESET;
\r
1399 return pendingbitstatus;
\r
1415 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
\r