📄 stm32f10x_can.lst
字号:
462
463 /*******************************************************************************
464 * Function Name : CAN_TransmitStatus
465 * Description : Checks the transmission of a message.
466 * Input : TransmitMailbox: the number of the mailbox that is used for
467 * transmission.
468 * Output : None.
469 * Return : CANTXOK if the CAN driver transmits the message, CANTXFAILED
470 * in an other case.
471 *******************************************************************************/
472 u8 CAN_TransmitStatus(u8 TransmitMailbox)
473 {
474 /* RQCP, TXOK and TME bits */
475 u8 State = 0;
476
477 /* Check the parameters */
478 assert_param(IS_CAN_TRANSMITMAILBOX(TransmitMailbox));
479
480 switch (TransmitMailbox)
481 {
482 case (0): State |= ((CAN->TSR & CAN_TSR_RQCP0) << 2);
483 State |= ((CAN->TSR & CAN_TSR_TXOK0) >> 0);
484 State |= ((CAN->TSR & CAN_TSR_TME0) >> 26);
485 break;
486 case (1): State |= ((CAN->TSR & CAN_TSR_RQCP1) >> 6);
487 State |= ((CAN->TSR & CAN_TSR_TXOK1) >> 8);
488 State |= ((CAN->TSR & CAN_TSR_TME1) >> 27);
489 break;
490 case (2): State |= ((CAN->TSR & CAN_TSR_RQCP2) >> 14);
491 State |= ((CAN->TSR & CAN_TSR_TXOK2) >> 16);
492 State |= ((CAN->TSR & CAN_TSR_TME2) >> 28);
493 break;
494 default:
495 State = CANTXFAILED;
496 break;
497 }
498
499 switch (State)
500 {
501 /* transmit pending */
502 case (0x0): State = CANTXPENDING;
503 break;
504 /* transmit failed */
505 case (0x5): State = CANTXFAILED;
506 break;
507 /* transmit succedeed */
508 case (0x7): State = CANTXOK;
509 break;
510 default:
511 State = CANTXFAILED;
512 break;
513 }
514
515 return State;
516 }
517
518 /*******************************************************************************
519 * Function Name : CAN_CancelTransmit
520 * Description : Cancels a transmit request.
521 * Input : Mailbox number.
522 * Output : None.
523 * Return : None.
524 *******************************************************************************/
525 void CAN_CancelTransmit(u8 Mailbox)
526 {
527 /* Check the parameters */
528 assert_param(IS_CAN_TRANSMITMAILBOX(Mailbox));
529
530 /* abort transmission */
531 switch (Mailbox)
532 {
533 case (0): CAN->TSR |= CAN_TSR_ABRQ0;
534 break;
535 case (1): CAN->TSR |= CAN_TSR_ABRQ1;
536 break;
537 case (2): CAN->TSR |= CAN_TSR_ABRQ2;
538 break;
539 default:
540 break;
541 }
542 }
543
544 /*******************************************************************************
545 * Function Name : CAN_FIFORelease
546 * Description : Releases a FIFO.
547 * Input : FIFONumber: FIFO to release, CAN_FIFO0 or CAN_FIFO1.
548 * Output : None.
549 * Return : None.
550 *******************************************************************************/
551 void CAN_FIFORelease(u8 FIFONumber)
552 {
553 /* Check the parameters */
554 assert_param(IS_CAN_FIFO(FIFONumber));
555
556 /* Release FIFO0 */
557 if (FIFONumber == CAN_FIFO0)
558 {
559 CAN->RF0R = CAN_RF0R_RFOM0;
560 }
561 /* Release FIFO1 */
562 else /* FIFONumber == CAN_FIFO1 */
563 {
564 CAN->RF1R = CAN_RF1R_RFOM1;
565 }
566 }
567
568 /*******************************************************************************
569 * Function Name : CAN_MessagePending
570 * Description : Returns the number of pending messages.
571 * Input : FIFONumber: Receive FIFO number, CAN_FIFO0 or CAN_FIFO1.
572 * Output : None.
573 * Return : NbMessage which is the number of pending message.
574 *******************************************************************************/
575 u8 CAN_MessagePending(u8 FIFONumber)
576 {
577 u8 MessagePending=0;
578
579 /* Check the parameters */
580 assert_param(IS_CAN_FIFO(FIFONumber));
581
582 if (FIFONumber == CAN_FIFO0)
583 {
584 MessagePending = (u8)(CAN->RF0R&(u32)0x03);
585 }
586 else if (FIFONumber == CAN_FIFO1)
587 {
588 MessagePending = (u8)(CAN->RF1R&(u32)0x03);
589 }
590 else
591 {
592 MessagePending = 0;
593 }
594 return MessagePending;
595 }
596
597 /*******************************************************************************
598 * Function Name : CAN_Receive
599 * Description : Receives a message.
600 * Input : FIFONumber: Receive FIFO number, CAN_FIFO0 or CAN_FIFO1.
601 * Output : RxMessage: pointer to a structure which contains CAN Id,
602 * CAN DLC, CAN datas and FMI number.
603 * Return : None.
604 *******************************************************************************/
605 void CAN_Receive(u8 FIFONumber, CanRxMsg* RxMessage)
606 {
607 /* Check the parameters */
608 assert_param(IS_CAN_FIFO(FIFONumber));
609
610 /* Get the Id */
611 RxMessage->StdId = (u32)0x000007FF & (CAN->sFIFOMailBox[FIFONumber].RIR >> 21);
612 RxMessage->ExtId = (u32)0x0003FFFF & (CAN->sFIFOMailBox[FIFONumber].RIR >> 3);
613
614 RxMessage->IDE = (u32)0x00000004 & CAN->sFIFOMailBox[FIFONumber].RIR;
615 RxMessage->RTR = (u32)0x00000002 & CAN->sFIFOMailBox[FIFONumber].RIR;
616
617 /* Get the DLC */
618 RxMessage->DLC = (u32)0x0000000F & CAN->sFIFOMailBox[FIFONumber].RDTR;
619
620 /* Get the FMI */
621 RxMessage->FMI = (u32)0x000000FF & (CAN->sFIFOMailBox[FIFONumber].RDTR >> 8);
622
623 /* Get the data field */
624 RxMessage->Data[0] = (u32)0x000000FF & CAN->sFIFOMailBox[FIFONumber].RDLR;
625 RxMessage->Data[1] = (u32)0x000000FF & (CAN->sFIFOMailBox[FIFONumber].RDLR >> 8);
626 RxMessage->Data[2] = (u32)0x000000FF & (CAN->sFIFOMailBox[FIFONumber].RDLR >> 16);
627 RxMessage->Data[3] = (u32)0x000000FF & (CAN->sFIFOMailBox[FIFONumber].RDLR >> 24);
628
629 RxMessage->Data[4] = (u32)0x000000FF & CAN->sFIFOMailBox[FIFONumber].RDHR;
630 RxMessage->Data[5] = (u32)0x000000FF & (CAN->sFIFOMailBox[FIFONumber].RDHR >> 8);
631 RxMessage->Data[6] = (u32)0x000000FF & (CAN->sFIFOMailBox[FIFONumber].RDHR >> 16);
632 RxMessage->Data[7] = (u32)0x000000FF & (CAN->sFIFOMailBox[FIFONumber].RDHR >> 24);
633
634 /* Release the FIFO */
635 CAN_FIFORelease(FIFONumber);
636 }
637
638 /*******************************************************************************
639 * Function Name : CAN_Sleep
640 * Description : Enters the low power mode.
641 * Input : None.
642 * Output : None.
643 * Return : CANSLEEPOK if sleep entered, CANSLEEPFAILED in an other case.
644 *******************************************************************************/
645 u8 CAN_Sleep(void)
646 {
647 u8 SleepStatus = 0;
648
649 /* Sleep mode entering request */
650 CAN->MCR |= CAN_MCR_SLEEP;
651 SleepStatus = CANSLEEPOK;
652
653 /* Sleep mode status */
654 if ((CAN->MCR&CAN_MCR_SLEEP) == 0)
655 {
656 /* Sleep mode not entered */
657 SleepStatus = CANSLEEPFAILED;
658 }
659
660 /* At this step, sleep mode status */
661 return SleepStatus;
662 }
663
664 /*******************************************************************************
665 * Function Name : CAN_WakeUp
666 * Description : Wakes the CAN up.
667 * Input : None.
668 * Output : None.
669 * Return : CANWAKEUPOK if sleep mode left, CANWAKEUPFAILED in an other
670 * case.
671 *******************************************************************************/
672 u8 CAN_WakeUp(void)
673 {
674 u8 WakeUpStatus = 0;
675
676 /* Wake up request */
677 CAN->MCR &= ~CAN_MCR_SLEEP;
678 WakeUpStatus = CANWAKEUPFAILED;
679
680 /* Sleep mode status */
681 if ((CAN->MCR&CAN_MCR_SLEEP) == 0)
682 {
683 /* Sleep mode exited */
684 WakeUpStatus = CANWAKEUPOK;
685 }
686
687 /* At this step, sleep mode status */
688 return WakeUpStatus;
689 }
690
691 /*******************************************************************************
692 * Function Name : CAN_GetFlagStatus
693 * Description : Checks whether the specified CAN flag is set or not.
694 * Input : CAN_FLAG: specifies the flag to check.
695 * This parameter can be: CAN_FLAG_EWG, CAN_FLAG_EPV or
696 * CAN_FLAG_BOF.
697 * Output : None.
698 * Return : The new state of CAN_FLAG (SET or RESET).
699 *******************************************************************************/
700 FlagStatus CAN_GetFlagStatus(u32 CAN_FLAG)
701 {
702 FlagStatus bitstatus = RESET;
703
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -