The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.
Dependents: hello SerialTestv11 SerialTestv12 Sierpinski ... more
mbed 2
This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.
TARGET_K66F/TOOLCHAIN_IAR/fsl_flexcan.h@172:65be27845400, 2019-02-20 (annotated)
- Committer:
- AnnaBridge
- Date:
- Wed Feb 20 20:53:29 2019 +0000
- Revision:
- 172:65be27845400
- Parent:
- 171:3a7713b1edbc
mbed library release version 165
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AnnaBridge | 143:86740a56073b | 1 | /* |
AnnaBridge | 143:86740a56073b | 2 | * Copyright (c) 2015, Freescale Semiconductor, Inc. |
AnnaBridge | 143:86740a56073b | 3 | * Copyright 2016-2017 NXP |
AnnaBridge | 143:86740a56073b | 4 | * |
AnnaBridge | 143:86740a56073b | 5 | * Redistribution and use in source and binary forms, with or without modification, |
AnnaBridge | 143:86740a56073b | 6 | * are permitted provided that the following conditions are met: |
AnnaBridge | 143:86740a56073b | 7 | * |
AnnaBridge | 143:86740a56073b | 8 | * o Redistributions of source code must retain the above copyright notice, this list |
AnnaBridge | 143:86740a56073b | 9 | * of conditions and the following disclaimer. |
AnnaBridge | 143:86740a56073b | 10 | * |
AnnaBridge | 143:86740a56073b | 11 | * o Redistributions in binary form must reproduce the above copyright notice, this |
AnnaBridge | 143:86740a56073b | 12 | * list of conditions and the following disclaimer in the documentation and/or |
AnnaBridge | 143:86740a56073b | 13 | * other materials provided with the distribution. |
AnnaBridge | 143:86740a56073b | 14 | * |
AnnaBridge | 143:86740a56073b | 15 | * o Neither the name of the copyright holder nor the names of its |
AnnaBridge | 143:86740a56073b | 16 | * contributors may be used to endorse or promote products derived from this |
AnnaBridge | 143:86740a56073b | 17 | * software without specific prior written permission. |
AnnaBridge | 143:86740a56073b | 18 | * |
AnnaBridge | 143:86740a56073b | 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
AnnaBridge | 143:86740a56073b | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
AnnaBridge | 143:86740a56073b | 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
AnnaBridge | 143:86740a56073b | 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
AnnaBridge | 143:86740a56073b | 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
AnnaBridge | 143:86740a56073b | 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
AnnaBridge | 143:86740a56073b | 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
AnnaBridge | 143:86740a56073b | 26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
AnnaBridge | 143:86740a56073b | 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
AnnaBridge | 143:86740a56073b | 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
AnnaBridge | 143:86740a56073b | 29 | */ |
AnnaBridge | 143:86740a56073b | 30 | #ifndef _FSL_FLEXCAN_H_ |
AnnaBridge | 143:86740a56073b | 31 | #define _FSL_FLEXCAN_H_ |
AnnaBridge | 143:86740a56073b | 32 | |
AnnaBridge | 143:86740a56073b | 33 | #include "fsl_common.h" |
AnnaBridge | 143:86740a56073b | 34 | |
AnnaBridge | 143:86740a56073b | 35 | /*! |
AnnaBridge | 143:86740a56073b | 36 | * @addtogroup flexcan_driver |
AnnaBridge | 143:86740a56073b | 37 | * @{ |
AnnaBridge | 143:86740a56073b | 38 | */ |
AnnaBridge | 143:86740a56073b | 39 | |
AnnaBridge | 143:86740a56073b | 40 | /****************************************************************************** |
AnnaBridge | 143:86740a56073b | 41 | * Definitions |
AnnaBridge | 143:86740a56073b | 42 | *****************************************************************************/ |
AnnaBridge | 143:86740a56073b | 43 | |
AnnaBridge | 143:86740a56073b | 44 | /*! @name Driver version */ |
AnnaBridge | 143:86740a56073b | 45 | /*@{*/ |
AnnaBridge | 143:86740a56073b | 46 | /*! @brief FlexCAN driver version 2.2.0. */ |
AnnaBridge | 143:86740a56073b | 47 | #define FLEXCAN_DRIVER_VERSION (MAKE_VERSION(2, 2, 0)) |
AnnaBridge | 143:86740a56073b | 48 | /*@}*/ |
AnnaBridge | 143:86740a56073b | 49 | |
AnnaBridge | 143:86740a56073b | 50 | /*! @brief FlexCAN Frame ID helper macro. */ |
AnnaBridge | 143:86740a56073b | 51 | #define FLEXCAN_ID_STD(id) \ |
AnnaBridge | 143:86740a56073b | 52 | (((uint32_t)(((uint32_t)(id)) << CAN_ID_STD_SHIFT)) & CAN_ID_STD_MASK) /*!< Standard Frame ID helper macro. */ |
AnnaBridge | 143:86740a56073b | 53 | #define FLEXCAN_ID_EXT(id) \ |
AnnaBridge | 143:86740a56073b | 54 | (((uint32_t)(((uint32_t)(id)) << CAN_ID_EXT_SHIFT)) & \ |
AnnaBridge | 143:86740a56073b | 55 | (CAN_ID_EXT_MASK | CAN_ID_STD_MASK)) /*!< Extend Frame ID helper macro. */ |
AnnaBridge | 143:86740a56073b | 56 | |
AnnaBridge | 143:86740a56073b | 57 | /*! @brief FlexCAN Rx Message Buffer Mask helper macro. */ |
AnnaBridge | 143:86740a56073b | 58 | #define FLEXCAN_RX_MB_STD_MASK(id, rtr, ide) \ |
AnnaBridge | 143:86740a56073b | 59 | (((uint32_t)((uint32_t)(rtr) << 31) | (uint32_t)((uint32_t)(ide) << 30)) | \ |
AnnaBridge | 143:86740a56073b | 60 | FLEXCAN_ID_STD(id)) /*!< Standard Rx Message Buffer Mask helper macro. */ |
AnnaBridge | 143:86740a56073b | 61 | #define FLEXCAN_RX_MB_EXT_MASK(id, rtr, ide) \ |
AnnaBridge | 143:86740a56073b | 62 | (((uint32_t)((uint32_t)(rtr) << 31) | (uint32_t)((uint32_t)(ide) << 30)) | \ |
AnnaBridge | 143:86740a56073b | 63 | FLEXCAN_ID_EXT(id)) /*!< Extend Rx Message Buffer Mask helper macro. */ |
AnnaBridge | 143:86740a56073b | 64 | |
AnnaBridge | 143:86740a56073b | 65 | /*! @brief FlexCAN Rx FIFO Mask helper macro. */ |
AnnaBridge | 143:86740a56073b | 66 | #define FLEXCAN_RX_FIFO_STD_MASK_TYPE_A(id, rtr, ide) \ |
AnnaBridge | 143:86740a56073b | 67 | (((uint32_t)((uint32_t)(rtr) << 31) | (uint32_t)((uint32_t)(ide) << 30)) | \ |
AnnaBridge | 143:86740a56073b | 68 | (FLEXCAN_ID_STD(id) << 1)) /*!< Standard Rx FIFO Mask helper macro Type A helper macro. */ |
AnnaBridge | 143:86740a56073b | 69 | #define FLEXCAN_RX_FIFO_STD_MASK_TYPE_B_HIGH(id, rtr, ide) \ |
AnnaBridge | 143:86740a56073b | 70 | (((uint32_t)((uint32_t)(rtr) << 31) | (uint32_t)((uint32_t)(ide) << 30)) | \ |
AnnaBridge | 143:86740a56073b | 71 | (((uint32_t)(id) & 0x7FF) << 19)) /*!< Standard Rx FIFO Mask helper macro Type B upper part helper macro. */ |
AnnaBridge | 143:86740a56073b | 72 | #define FLEXCAN_RX_FIFO_STD_MASK_TYPE_B_LOW(id, rtr, ide) \ |
AnnaBridge | 143:86740a56073b | 73 | (((uint32_t)((uint32_t)(rtr) << 15) | (uint32_t)((uint32_t)(ide) << 14)) | \ |
AnnaBridge | 143:86740a56073b | 74 | (((uint32_t)(id) & 0x7FF) << 3)) /*!< Standard Rx FIFO Mask helper macro Type B lower part helper macro. */ |
AnnaBridge | 143:86740a56073b | 75 | #define FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_HIGH(id) \ |
AnnaBridge | 143:86740a56073b | 76 | (((uint32_t)(id) & 0x7F8) << 21) /*!< Standard Rx FIFO Mask helper macro Type C upper part helper macro. */ |
AnnaBridge | 143:86740a56073b | 77 | #define FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_MID_HIGH(id) \ |
AnnaBridge | 143:86740a56073b | 78 | (((uint32_t)(id) & 0x7F8) << 13) /*!< Standard Rx FIFO Mask helper macro Type C mid-upper part helper macro. */ |
AnnaBridge | 143:86740a56073b | 79 | #define FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_MID_LOW(id) \ |
AnnaBridge | 143:86740a56073b | 80 | (((uint32_t)(id) & 0x7F8) << 5) /*!< Standard Rx FIFO Mask helper macro Type C mid-lower part helper macro. */ |
AnnaBridge | 143:86740a56073b | 81 | #define FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_LOW(id) \ |
AnnaBridge | 143:86740a56073b | 82 | (((uint32_t)(id) & 0x7F8) >> 3) /*!< Standard Rx FIFO Mask helper macro Type C lower part helper macro. */ |
AnnaBridge | 143:86740a56073b | 83 | #define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_A(id, rtr, ide) \ |
AnnaBridge | 143:86740a56073b | 84 | (((uint32_t)((uint32_t)(rtr) << 31) | (uint32_t)((uint32_t)(ide) << 30)) | \ |
AnnaBridge | 143:86740a56073b | 85 | (FLEXCAN_ID_EXT(id) << 1)) /*!< Extend Rx FIFO Mask helper macro Type A helper macro. */ |
AnnaBridge | 143:86740a56073b | 86 | #define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_B_HIGH(id, rtr, ide) \ |
AnnaBridge | 143:86740a56073b | 87 | (((uint32_t)((uint32_t)(rtr) << 31) | (uint32_t)((uint32_t)(ide) << 30)) | \ |
AnnaBridge | 143:86740a56073b | 88 | ((FLEXCAN_ID_EXT(id) & 0x1FFF8000) << 1)) /*!< Extend Rx FIFO Mask helper macro Type B upper part helper macro. */ |
AnnaBridge | 143:86740a56073b | 89 | #define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_B_LOW(id, rtr, ide) \ |
AnnaBridge | 143:86740a56073b | 90 | (((uint32_t)((uint32_t)(rtr) << 15) | (uint32_t)((uint32_t)(ide) << 14)) | \ |
AnnaBridge | 143:86740a56073b | 91 | ((FLEXCAN_ID_EXT(id) & 0x1FFF8000) >> \ |
AnnaBridge | 143:86740a56073b | 92 | 15)) /*!< Extend Rx FIFO Mask helper macro Type B lower part helper macro. */ |
AnnaBridge | 143:86740a56073b | 93 | #define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_HIGH(id) \ |
AnnaBridge | 143:86740a56073b | 94 | ((FLEXCAN_ID_EXT(id) & 0x1FE00000) << 3) /*!< Extend Rx FIFO Mask helper macro Type C upper part helper macro. */ |
AnnaBridge | 143:86740a56073b | 95 | #define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_MID_HIGH(id) \ |
AnnaBridge | 143:86740a56073b | 96 | ((FLEXCAN_ID_EXT(id) & 0x1FE00000) >> \ |
AnnaBridge | 143:86740a56073b | 97 | 5) /*!< Extend Rx FIFO Mask helper macro Type C mid-upper part helper macro. */ |
AnnaBridge | 143:86740a56073b | 98 | #define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_MID_LOW(id) \ |
AnnaBridge | 143:86740a56073b | 99 | ((FLEXCAN_ID_EXT(id) & 0x1FE00000) >> \ |
AnnaBridge | 143:86740a56073b | 100 | 13) /*!< Extend Rx FIFO Mask helper macro Type C mid-lower part helper macro. */ |
AnnaBridge | 143:86740a56073b | 101 | #define FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_LOW(id) \ |
AnnaBridge | 143:86740a56073b | 102 | ((FLEXCAN_ID_EXT(id) & 0x1FE00000) >> 21) /*!< Extend Rx FIFO Mask helper macro Type C lower part helper macro. */ |
AnnaBridge | 143:86740a56073b | 103 | |
AnnaBridge | 143:86740a56073b | 104 | /*! @brief FlexCAN Rx FIFO Filter helper macro. */ |
AnnaBridge | 143:86740a56073b | 105 | #define FLEXCAN_RX_FIFO_STD_FILTER_TYPE_A(id, rtr, ide) \ |
AnnaBridge | 143:86740a56073b | 106 | FLEXCAN_RX_FIFO_STD_MASK_TYPE_A(id, rtr, ide) /*!< Standard Rx FIFO Filter helper macro Type A helper macro. */ |
AnnaBridge | 143:86740a56073b | 107 | #define FLEXCAN_RX_FIFO_STD_FILTER_TYPE_B_HIGH(id, rtr, ide) \ |
AnnaBridge | 143:86740a56073b | 108 | FLEXCAN_RX_FIFO_STD_MASK_TYPE_B_HIGH( \ |
AnnaBridge | 143:86740a56073b | 109 | id, rtr, ide) /*!< Standard Rx FIFO Filter helper macro Type B upper part helper macro. */ |
AnnaBridge | 143:86740a56073b | 110 | #define FLEXCAN_RX_FIFO_STD_FILTER_TYPE_B_LOW(id, rtr, ide) \ |
AnnaBridge | 143:86740a56073b | 111 | FLEXCAN_RX_FIFO_STD_MASK_TYPE_B_LOW( \ |
AnnaBridge | 143:86740a56073b | 112 | id, rtr, ide) /*!< Standard Rx FIFO Filter helper macro Type B lower part helper macro. */ |
AnnaBridge | 143:86740a56073b | 113 | #define FLEXCAN_RX_FIFO_STD_FILTER_TYPE_C_HIGH(id) \ |
AnnaBridge | 143:86740a56073b | 114 | FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_HIGH( \ |
AnnaBridge | 143:86740a56073b | 115 | id) /*!< Standard Rx FIFO Filter helper macro Type C upper part helper macro. */ |
AnnaBridge | 143:86740a56073b | 116 | #define FLEXCAN_RX_FIFO_STD_FILTER_TYPE_C_MID_HIGH(id) \ |
AnnaBridge | 143:86740a56073b | 117 | FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_MID_HIGH( \ |
AnnaBridge | 143:86740a56073b | 118 | id) /*!< Standard Rx FIFO Filter helper macro Type C mid-upper part helper macro. */ |
AnnaBridge | 143:86740a56073b | 119 | #define FLEXCAN_RX_FIFO_STD_FILTER_TYPE_C_MID_LOW(id) \ |
AnnaBridge | 143:86740a56073b | 120 | FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_MID_LOW( \ |
AnnaBridge | 143:86740a56073b | 121 | id) /*!< Standard Rx FIFO Filter helper macro Type C mid-lower part helper macro. */ |
AnnaBridge | 143:86740a56073b | 122 | #define FLEXCAN_RX_FIFO_STD_FILTER_TYPE_C_LOW(id) \ |
AnnaBridge | 143:86740a56073b | 123 | FLEXCAN_RX_FIFO_STD_MASK_TYPE_C_LOW(id) /*!< Standard Rx FIFO Filter helper macro Type C lower part helper macro. \ |
AnnaBridge | 143:86740a56073b | 124 | */ |
AnnaBridge | 143:86740a56073b | 125 | #define FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_A(id, rtr, ide) \ |
AnnaBridge | 143:86740a56073b | 126 | FLEXCAN_RX_FIFO_EXT_MASK_TYPE_A(id, rtr, ide) /*!< Extend Rx FIFO Filter helper macro Type A helper macro. */ |
AnnaBridge | 143:86740a56073b | 127 | #define FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_B_HIGH(id, rtr, ide) \ |
AnnaBridge | 143:86740a56073b | 128 | FLEXCAN_RX_FIFO_EXT_MASK_TYPE_B_HIGH( \ |
AnnaBridge | 143:86740a56073b | 129 | id, rtr, ide) /*!< Extend Rx FIFO Filter helper macro Type B upper part helper macro. */ |
AnnaBridge | 143:86740a56073b | 130 | #define FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_B_LOW(id, rtr, ide) \ |
AnnaBridge | 143:86740a56073b | 131 | FLEXCAN_RX_FIFO_EXT_MASK_TYPE_B_LOW( \ |
AnnaBridge | 143:86740a56073b | 132 | id, rtr, ide) /*!< Extend Rx FIFO Filter helper macro Type B lower part helper macro. */ |
AnnaBridge | 143:86740a56073b | 133 | #define FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_C_HIGH(id) \ |
AnnaBridge | 143:86740a56073b | 134 | FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_HIGH(id) /*!< Extend Rx FIFO Filter helper macro Type C upper part helper macro. \ |
AnnaBridge | 143:86740a56073b | 135 | */ |
AnnaBridge | 143:86740a56073b | 136 | #define FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_C_MID_HIGH(id) \ |
AnnaBridge | 143:86740a56073b | 137 | FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_MID_HIGH( \ |
AnnaBridge | 143:86740a56073b | 138 | id) /*!< Extend Rx FIFO Filter helper macro Type C mid-upper part helper macro. */ |
AnnaBridge | 143:86740a56073b | 139 | #define FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_C_MID_LOW(id) \ |
AnnaBridge | 143:86740a56073b | 140 | FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_MID_LOW( \ |
AnnaBridge | 143:86740a56073b | 141 | id) /*!< Extend Rx FIFO Filter helper macro Type C mid-lower part helper macro. */ |
AnnaBridge | 143:86740a56073b | 142 | #define FLEXCAN_RX_FIFO_EXT_FILTER_TYPE_C_LOW(id) \ |
AnnaBridge | 143:86740a56073b | 143 | FLEXCAN_RX_FIFO_EXT_MASK_TYPE_C_LOW(id) /*!< Extend Rx FIFO Filter helper macro Type C lower part helper macro. */ |
AnnaBridge | 143:86740a56073b | 144 | |
AnnaBridge | 143:86740a56073b | 145 | /*! @brief FlexCAN transfer status. */ |
AnnaBridge | 143:86740a56073b | 146 | enum _flexcan_status |
AnnaBridge | 143:86740a56073b | 147 | { |
AnnaBridge | 143:86740a56073b | 148 | kStatus_FLEXCAN_TxBusy = MAKE_STATUS(kStatusGroup_FLEXCAN, 0), /*!< Tx Message Buffer is Busy. */ |
AnnaBridge | 143:86740a56073b | 149 | kStatus_FLEXCAN_TxIdle = MAKE_STATUS(kStatusGroup_FLEXCAN, 1), /*!< Tx Message Buffer is Idle. */ |
AnnaBridge | 143:86740a56073b | 150 | kStatus_FLEXCAN_TxSwitchToRx = MAKE_STATUS( |
AnnaBridge | 143:86740a56073b | 151 | kStatusGroup_FLEXCAN, 2), /*!< Remote Message is send out and Message buffer changed to Receive one. */ |
AnnaBridge | 143:86740a56073b | 152 | kStatus_FLEXCAN_RxBusy = MAKE_STATUS(kStatusGroup_FLEXCAN, 3), /*!< Rx Message Buffer is Busy. */ |
AnnaBridge | 143:86740a56073b | 153 | kStatus_FLEXCAN_RxIdle = MAKE_STATUS(kStatusGroup_FLEXCAN, 4), /*!< Rx Message Buffer is Idle. */ |
AnnaBridge | 143:86740a56073b | 154 | kStatus_FLEXCAN_RxOverflow = MAKE_STATUS(kStatusGroup_FLEXCAN, 5), /*!< Rx Message Buffer is Overflowed. */ |
AnnaBridge | 143:86740a56073b | 155 | kStatus_FLEXCAN_RxFifoBusy = MAKE_STATUS(kStatusGroup_FLEXCAN, 6), /*!< Rx Message FIFO is Busy. */ |
AnnaBridge | 143:86740a56073b | 156 | kStatus_FLEXCAN_RxFifoIdle = MAKE_STATUS(kStatusGroup_FLEXCAN, 7), /*!< Rx Message FIFO is Idle. */ |
AnnaBridge | 143:86740a56073b | 157 | kStatus_FLEXCAN_RxFifoOverflow = MAKE_STATUS(kStatusGroup_FLEXCAN, 8), /*!< Rx Message FIFO is overflowed. */ |
AnnaBridge | 143:86740a56073b | 158 | kStatus_FLEXCAN_RxFifoWarning = MAKE_STATUS(kStatusGroup_FLEXCAN, 9), /*!< Rx Message FIFO is almost overflowed. */ |
AnnaBridge | 143:86740a56073b | 159 | kStatus_FLEXCAN_ErrorStatus = MAKE_STATUS(kStatusGroup_FLEXCAN, 10), /*!< FlexCAN Module Error and Status. */ |
AnnaBridge | 143:86740a56073b | 160 | kStatus_FLEXCAN_UnHandled = MAKE_STATUS(kStatusGroup_FLEXCAN, 11), /*!< UnHadled Interrupt asserted. */ |
AnnaBridge | 143:86740a56073b | 161 | }; |
AnnaBridge | 143:86740a56073b | 162 | |
AnnaBridge | 143:86740a56073b | 163 | /*! @brief FlexCAN frame format. */ |
AnnaBridge | 143:86740a56073b | 164 | typedef enum _flexcan_frame_format |
AnnaBridge | 143:86740a56073b | 165 | { |
AnnaBridge | 143:86740a56073b | 166 | kFLEXCAN_FrameFormatStandard = 0x0U, /*!< Standard frame format attribute. */ |
AnnaBridge | 143:86740a56073b | 167 | kFLEXCAN_FrameFormatExtend = 0x1U, /*!< Extend frame format attribute. */ |
AnnaBridge | 143:86740a56073b | 168 | } flexcan_frame_format_t; |
AnnaBridge | 143:86740a56073b | 169 | |
AnnaBridge | 143:86740a56073b | 170 | /*! @brief FlexCAN frame type. */ |
AnnaBridge | 143:86740a56073b | 171 | typedef enum _flexcan_frame_type |
AnnaBridge | 143:86740a56073b | 172 | { |
AnnaBridge | 143:86740a56073b | 173 | kFLEXCAN_FrameTypeData = 0x0U, /*!< Data frame type attribute. */ |
AnnaBridge | 143:86740a56073b | 174 | kFLEXCAN_FrameTypeRemote = 0x1U, /*!< Remote frame type attribute. */ |
AnnaBridge | 143:86740a56073b | 175 | } flexcan_frame_type_t; |
AnnaBridge | 143:86740a56073b | 176 | |
AnnaBridge | 143:86740a56073b | 177 | #if (!defined(FSL_FEATURE_FLEXCAN_SUPPORT_ENGINE_CLK_SEL_REMOVE)) || !FSL_FEATURE_FLEXCAN_SUPPORT_ENGINE_CLK_SEL_REMOVE |
AnnaBridge | 143:86740a56073b | 178 | /*! @brief FlexCAN clock source. */ |
AnnaBridge | 143:86740a56073b | 179 | typedef enum _flexcan_clock_source |
AnnaBridge | 143:86740a56073b | 180 | { |
AnnaBridge | 143:86740a56073b | 181 | kFLEXCAN_ClkSrcOsc = 0x0U, /*!< FlexCAN Protocol Engine clock from Oscillator. */ |
AnnaBridge | 143:86740a56073b | 182 | kFLEXCAN_ClkSrcPeri = 0x1U, /*!< FlexCAN Protocol Engine clock from Peripheral Clock. */ |
AnnaBridge | 143:86740a56073b | 183 | } flexcan_clock_source_t; |
AnnaBridge | 143:86740a56073b | 184 | #endif /* FSL_FEATURE_FLEXCAN_SUPPORT_ENGINE_CLK_SEL_REMOVE */ |
AnnaBridge | 143:86740a56073b | 185 | |
AnnaBridge | 143:86740a56073b | 186 | /*! @brief FlexCAN Rx Fifo Filter type. */ |
AnnaBridge | 143:86740a56073b | 187 | typedef enum _flexcan_rx_fifo_filter_type |
AnnaBridge | 143:86740a56073b | 188 | { |
AnnaBridge | 143:86740a56073b | 189 | kFLEXCAN_RxFifoFilterTypeA = 0x0U, /*!< One full ID (standard and extended) per ID Filter element. */ |
AnnaBridge | 143:86740a56073b | 190 | kFLEXCAN_RxFifoFilterTypeB = |
AnnaBridge | 143:86740a56073b | 191 | 0x1U, /*!< Two full standard IDs or two partial 14-bit ID slices per ID Filter Table element. */ |
AnnaBridge | 143:86740a56073b | 192 | kFLEXCAN_RxFifoFilterTypeC = |
AnnaBridge | 143:86740a56073b | 193 | 0x2U, /*!< Four partial 8-bit Standard or extended ID slices per ID Filter Table element. */ |
AnnaBridge | 143:86740a56073b | 194 | kFLEXCAN_RxFifoFilterTypeD = 0x3U, /*!< All frames rejected. */ |
AnnaBridge | 143:86740a56073b | 195 | } flexcan_rx_fifo_filter_type_t; |
AnnaBridge | 143:86740a56073b | 196 | |
AnnaBridge | 143:86740a56073b | 197 | /*! |
AnnaBridge | 143:86740a56073b | 198 | * @brief FlexCAN Rx FIFO priority. |
AnnaBridge | 143:86740a56073b | 199 | * |
AnnaBridge | 143:86740a56073b | 200 | * The matching process starts from the Rx MB(or Rx FIFO) with higher priority. |
AnnaBridge | 143:86740a56073b | 201 | * If no MB(or Rx FIFO filter) is satisfied, the matching process goes on with |
AnnaBridge | 143:86740a56073b | 202 | * the Rx FIFO(or Rx MB) with lower priority. |
AnnaBridge | 143:86740a56073b | 203 | */ |
AnnaBridge | 143:86740a56073b | 204 | typedef enum _flexcan_rx_fifo_priority |
AnnaBridge | 143:86740a56073b | 205 | { |
AnnaBridge | 143:86740a56073b | 206 | kFLEXCAN_RxFifoPrioLow = 0x0U, /*!< Matching process start from Rx Message Buffer first*/ |
AnnaBridge | 143:86740a56073b | 207 | kFLEXCAN_RxFifoPrioHigh = 0x1U, /*!< Matching process start from Rx FIFO first*/ |
AnnaBridge | 143:86740a56073b | 208 | } flexcan_rx_fifo_priority_t; |
AnnaBridge | 143:86740a56073b | 209 | |
AnnaBridge | 143:86740a56073b | 210 | /*! |
AnnaBridge | 143:86740a56073b | 211 | * @brief FlexCAN interrupt configuration structure, default settings all disabled. |
AnnaBridge | 143:86740a56073b | 212 | * |
AnnaBridge | 143:86740a56073b | 213 | * This structure contains the settings for all of the FlexCAN Module interrupt configurations. |
AnnaBridge | 143:86740a56073b | 214 | * Note: FlexCAN Message Buffers and Rx FIFO have their own interrupts. |
AnnaBridge | 143:86740a56073b | 215 | */ |
AnnaBridge | 143:86740a56073b | 216 | enum _flexcan_interrupt_enable |
AnnaBridge | 143:86740a56073b | 217 | { |
AnnaBridge | 143:86740a56073b | 218 | kFLEXCAN_BusOffInterruptEnable = CAN_CTRL1_BOFFMSK_MASK, /*!< Bus Off interrupt. */ |
AnnaBridge | 143:86740a56073b | 219 | kFLEXCAN_ErrorInterruptEnable = CAN_CTRL1_ERRMSK_MASK, /*!< Error interrupt. */ |
AnnaBridge | 143:86740a56073b | 220 | kFLEXCAN_RxWarningInterruptEnable = CAN_CTRL1_RWRNMSK_MASK, /*!< Rx Warning interrupt. */ |
AnnaBridge | 143:86740a56073b | 221 | kFLEXCAN_TxWarningInterruptEnable = CAN_CTRL1_TWRNMSK_MASK, /*!< Tx Warning interrupt. */ |
AnnaBridge | 143:86740a56073b | 222 | kFLEXCAN_WakeUpInterruptEnable = CAN_MCR_WAKMSK_MASK, /*!< Wake Up interrupt. */ |
AnnaBridge | 143:86740a56073b | 223 | }; |
AnnaBridge | 143:86740a56073b | 224 | |
AnnaBridge | 143:86740a56073b | 225 | /*! |
AnnaBridge | 143:86740a56073b | 226 | * @brief FlexCAN status flags. |
AnnaBridge | 143:86740a56073b | 227 | * |
AnnaBridge | 143:86740a56073b | 228 | * This provides constants for the FlexCAN status flags for use in the FlexCAN functions. |
AnnaBridge | 143:86740a56073b | 229 | * Note: The CPU read action clears FlEXCAN_ErrorFlag, therefore user need to |
AnnaBridge | 143:86740a56073b | 230 | * read FlEXCAN_ErrorFlag and distinguish which error is occur using |
AnnaBridge | 143:86740a56073b | 231 | * @ref _flexcan_error_flags enumerations. |
AnnaBridge | 143:86740a56073b | 232 | */ |
AnnaBridge | 143:86740a56073b | 233 | enum _flexcan_flags |
AnnaBridge | 143:86740a56073b | 234 | { |
AnnaBridge | 143:86740a56073b | 235 | kFLEXCAN_SynchFlag = CAN_ESR1_SYNCH_MASK, /*!< CAN Synchronization Status. */ |
AnnaBridge | 143:86740a56073b | 236 | kFLEXCAN_TxWarningIntFlag = CAN_ESR1_TWRNINT_MASK, /*!< Tx Warning Interrupt Flag. */ |
AnnaBridge | 143:86740a56073b | 237 | kFLEXCAN_RxWarningIntFlag = CAN_ESR1_RWRNINT_MASK, /*!< Rx Warning Interrupt Flag. */ |
AnnaBridge | 143:86740a56073b | 238 | kFLEXCAN_TxErrorWarningFlag = CAN_ESR1_TXWRN_MASK, /*!< Tx Error Warning Status. */ |
AnnaBridge | 143:86740a56073b | 239 | kFLEXCAN_RxErrorWarningFlag = CAN_ESR1_RXWRN_MASK, /*!< Rx Error Warning Status. */ |
AnnaBridge | 143:86740a56073b | 240 | kFLEXCAN_IdleFlag = CAN_ESR1_IDLE_MASK, /*!< CAN IDLE Status Flag. */ |
AnnaBridge | 143:86740a56073b | 241 | kFLEXCAN_FaultConfinementFlag = CAN_ESR1_FLTCONF_MASK, /*!< Fault Confinement State Flag. */ |
AnnaBridge | 143:86740a56073b | 242 | kFLEXCAN_TransmittingFlag = CAN_ESR1_TX_MASK, /*!< FlexCAN In Transmission Status. */ |
AnnaBridge | 143:86740a56073b | 243 | kFLEXCAN_ReceivingFlag = CAN_ESR1_RX_MASK, /*!< FlexCAN In Reception Status. */ |
AnnaBridge | 143:86740a56073b | 244 | kFLEXCAN_BusOffIntFlag = CAN_ESR1_BOFFINT_MASK, /*!< Bus Off Interrupt Flag. */ |
AnnaBridge | 143:86740a56073b | 245 | kFLEXCAN_ErrorIntFlag = CAN_ESR1_ERRINT_MASK, /*!< Error Interrupt Flag. */ |
AnnaBridge | 143:86740a56073b | 246 | kFLEXCAN_WakeUpIntFlag = CAN_ESR1_WAKINT_MASK, /*!< Wake-Up Interrupt Flag. */ |
AnnaBridge | 143:86740a56073b | 247 | kFLEXCAN_ErrorFlag = CAN_ESR1_BIT1ERR_MASK | /*!< All FlexCAN Error Status. */ |
AnnaBridge | 143:86740a56073b | 248 | CAN_ESR1_BIT0ERR_MASK | |
AnnaBridge | 143:86740a56073b | 249 | CAN_ESR1_ACKERR_MASK | CAN_ESR1_CRCERR_MASK | CAN_ESR1_FRMERR_MASK | CAN_ESR1_STFERR_MASK, |
AnnaBridge | 143:86740a56073b | 250 | }; |
AnnaBridge | 143:86740a56073b | 251 | |
AnnaBridge | 143:86740a56073b | 252 | /*! |
AnnaBridge | 143:86740a56073b | 253 | * @brief FlexCAN error status flags. |
AnnaBridge | 143:86740a56073b | 254 | * |
AnnaBridge | 143:86740a56073b | 255 | * The FlexCAN Error Status enumerations is used to report current error of the FlexCAN bus. |
AnnaBridge | 143:86740a56073b | 256 | * This enumerations should be used with KFLEXCAN_ErrorFlag in @ref _flexcan_flags enumerations |
AnnaBridge | 143:86740a56073b | 257 | * to ditermine which error is generated. |
AnnaBridge | 143:86740a56073b | 258 | */ |
AnnaBridge | 143:86740a56073b | 259 | enum _flexcan_error_flags |
AnnaBridge | 143:86740a56073b | 260 | { |
AnnaBridge | 143:86740a56073b | 261 | kFLEXCAN_StuffingError = CAN_ESR1_STFERR_MASK, /*!< Stuffing Error. */ |
AnnaBridge | 143:86740a56073b | 262 | kFLEXCAN_FormError = CAN_ESR1_FRMERR_MASK, /*!< Form Error. */ |
AnnaBridge | 143:86740a56073b | 263 | kFLEXCAN_CrcError = CAN_ESR1_CRCERR_MASK, /*!< Cyclic Redundancy Check Error. */ |
AnnaBridge | 143:86740a56073b | 264 | kFLEXCAN_AckError = CAN_ESR1_ACKERR_MASK, /*!< Received no ACK on transmission. */ |
AnnaBridge | 143:86740a56073b | 265 | kFLEXCAN_Bit0Error = CAN_ESR1_BIT0ERR_MASK, /*!< Unable to send dominant bit. */ |
AnnaBridge | 143:86740a56073b | 266 | kFLEXCAN_Bit1Error = CAN_ESR1_BIT1ERR_MASK, /*!< Unable to send recessive bit. */ |
AnnaBridge | 143:86740a56073b | 267 | }; |
AnnaBridge | 143:86740a56073b | 268 | |
AnnaBridge | 143:86740a56073b | 269 | /*! |
AnnaBridge | 143:86740a56073b | 270 | * @brief FlexCAN Rx FIFO status flags. |
AnnaBridge | 143:86740a56073b | 271 | * |
AnnaBridge | 143:86740a56073b | 272 | * The FlexCAN Rx FIFO Status enumerations are used to determine the status of the |
AnnaBridge | 143:86740a56073b | 273 | * Rx FIFO. Because Rx FIFO occupy the MB0 ~ MB7 (Rx Fifo filter also occupies |
AnnaBridge | 143:86740a56073b | 274 | * more Message Buffer space), Rx FIFO status flags are mapped to the corresponding |
AnnaBridge | 143:86740a56073b | 275 | * Message Buffer status flags. |
AnnaBridge | 143:86740a56073b | 276 | */ |
AnnaBridge | 143:86740a56073b | 277 | enum _flexcan_rx_fifo_flags |
AnnaBridge | 143:86740a56073b | 278 | { |
AnnaBridge | 143:86740a56073b | 279 | kFLEXCAN_RxFifoOverflowFlag = CAN_IFLAG1_BUF7I_MASK, /*!< Rx FIFO overflow flag. */ |
AnnaBridge | 143:86740a56073b | 280 | kFLEXCAN_RxFifoWarningFlag = CAN_IFLAG1_BUF6I_MASK, /*!< Rx FIFO almost full flag. */ |
AnnaBridge | 143:86740a56073b | 281 | kFLEXCAN_RxFifoFrameAvlFlag = CAN_IFLAG1_BUF5I_MASK, /*!< Frames available in Rx FIFO flag. */ |
AnnaBridge | 143:86740a56073b | 282 | }; |
AnnaBridge | 143:86740a56073b | 283 | |
AnnaBridge | 143:86740a56073b | 284 | #if defined(__CC_ARM) |
AnnaBridge | 143:86740a56073b | 285 | #pragma anon_unions |
AnnaBridge | 143:86740a56073b | 286 | #endif |
AnnaBridge | 143:86740a56073b | 287 | /*! @brief FlexCAN message frame structure. */ |
AnnaBridge | 143:86740a56073b | 288 | typedef struct _flexcan_frame |
AnnaBridge | 143:86740a56073b | 289 | { |
AnnaBridge | 143:86740a56073b | 290 | struct |
AnnaBridge | 143:86740a56073b | 291 | { |
AnnaBridge | 143:86740a56073b | 292 | uint32_t timestamp : 16; /*!< FlexCAN internal Free-Running Counter Time Stamp. */ |
AnnaBridge | 143:86740a56073b | 293 | uint32_t length : 4; /*!< CAN frame payload length in bytes(Range: 0~8). */ |
AnnaBridge | 143:86740a56073b | 294 | uint32_t type : 1; /*!< CAN Frame Type(DATA or REMOTE). */ |
AnnaBridge | 143:86740a56073b | 295 | uint32_t format : 1; /*!< CAN Frame Identifier(STD or EXT format). */ |
AnnaBridge | 143:86740a56073b | 296 | uint32_t : 1; /*!< Reserved. */ |
AnnaBridge | 143:86740a56073b | 297 | uint32_t idhit : 9; /*!< CAN Rx FIFO filter hit id(This value is only used in Rx FIFO receive mode). */ |
AnnaBridge | 143:86740a56073b | 298 | }; |
AnnaBridge | 143:86740a56073b | 299 | struct |
AnnaBridge | 143:86740a56073b | 300 | { |
AnnaBridge | 143:86740a56073b | 301 | uint32_t id : 29; /*!< CAN Frame Identifier, should be set using FLEXCAN_ID_EXT() or FLEXCAN_ID_STD() macro. */ |
AnnaBridge | 143:86740a56073b | 302 | uint32_t : 3; /*!< Reserved. */ |
AnnaBridge | 143:86740a56073b | 303 | }; |
AnnaBridge | 143:86740a56073b | 304 | union |
AnnaBridge | 143:86740a56073b | 305 | { |
AnnaBridge | 143:86740a56073b | 306 | struct |
AnnaBridge | 143:86740a56073b | 307 | { |
AnnaBridge | 143:86740a56073b | 308 | uint32_t dataWord0; /*!< CAN Frame payload word0. */ |
AnnaBridge | 143:86740a56073b | 309 | uint32_t dataWord1; /*!< CAN Frame payload word1. */ |
AnnaBridge | 143:86740a56073b | 310 | }; |
AnnaBridge | 143:86740a56073b | 311 | struct |
AnnaBridge | 143:86740a56073b | 312 | { |
AnnaBridge | 143:86740a56073b | 313 | uint8_t dataByte3; /*!< CAN Frame payload byte3. */ |
AnnaBridge | 143:86740a56073b | 314 | uint8_t dataByte2; /*!< CAN Frame payload byte2. */ |
AnnaBridge | 143:86740a56073b | 315 | uint8_t dataByte1; /*!< CAN Frame payload byte1. */ |
AnnaBridge | 143:86740a56073b | 316 | uint8_t dataByte0; /*!< CAN Frame payload byte0. */ |
AnnaBridge | 143:86740a56073b | 317 | uint8_t dataByte7; /*!< CAN Frame payload byte7. */ |
AnnaBridge | 143:86740a56073b | 318 | uint8_t dataByte6; /*!< CAN Frame payload byte6. */ |
AnnaBridge | 143:86740a56073b | 319 | uint8_t dataByte5; /*!< CAN Frame payload byte5. */ |
AnnaBridge | 143:86740a56073b | 320 | uint8_t dataByte4; /*!< CAN Frame payload byte4. */ |
AnnaBridge | 143:86740a56073b | 321 | }; |
AnnaBridge | 143:86740a56073b | 322 | }; |
AnnaBridge | 143:86740a56073b | 323 | } flexcan_frame_t; |
AnnaBridge | 143:86740a56073b | 324 | |
AnnaBridge | 143:86740a56073b | 325 | /*! @brief FlexCAN module configuration structure. */ |
AnnaBridge | 143:86740a56073b | 326 | typedef struct _flexcan_config |
AnnaBridge | 143:86740a56073b | 327 | { |
AnnaBridge | 143:86740a56073b | 328 | uint32_t baudRate; /*!< FlexCAN baud rate in bps. */ |
AnnaBridge | 143:86740a56073b | 329 | #if (!defined(FSL_FEATURE_FLEXCAN_SUPPORT_ENGINE_CLK_SEL_REMOVE)) || !FSL_FEATURE_FLEXCAN_SUPPORT_ENGINE_CLK_SEL_REMOVE |
AnnaBridge | 143:86740a56073b | 330 | flexcan_clock_source_t clkSrc; /*!< Clock source for FlexCAN Protocol Engine. */ |
AnnaBridge | 143:86740a56073b | 331 | #endif /* FSL_FEATURE_FLEXCAN_SUPPORT_ENGINE_CLK_SEL_REMOVE */ |
AnnaBridge | 143:86740a56073b | 332 | uint8_t maxMbNum; /*!< The maximum number of Message Buffers used by user. */ |
AnnaBridge | 143:86740a56073b | 333 | bool enableLoopBack; /*!< Enable or Disable Loop Back Self Test Mode. */ |
AnnaBridge | 143:86740a56073b | 334 | bool enableSelfWakeup; /*!< Enable or Disable Self Wakeup Mode. */ |
AnnaBridge | 143:86740a56073b | 335 | bool enableIndividMask; /*!< Enable or Disable Rx Individual Mask. */ |
AnnaBridge | 143:86740a56073b | 336 | #if (defined(FSL_FEATURE_FLEXCAN_HAS_DOZE_MODE_SUPPORT) && FSL_FEATURE_FLEXCAN_HAS_DOZE_MODE_SUPPORT) |
AnnaBridge | 143:86740a56073b | 337 | bool enableDoze; /*!< Enable or Disable Doze Mode. */ |
AnnaBridge | 143:86740a56073b | 338 | #endif |
AnnaBridge | 143:86740a56073b | 339 | } flexcan_config_t; |
AnnaBridge | 143:86740a56073b | 340 | |
AnnaBridge | 143:86740a56073b | 341 | /*! @brief FlexCAN protocol timing characteristic configuration structure. */ |
AnnaBridge | 143:86740a56073b | 342 | typedef struct _flexcan_timing_config |
AnnaBridge | 143:86740a56073b | 343 | { |
AnnaBridge | 143:86740a56073b | 344 | uint8_t preDivider; /*!< Clock Pre-scaler Division Factor. */ |
AnnaBridge | 143:86740a56073b | 345 | uint8_t rJumpwidth; /*!< Re-sync Jump Width. */ |
AnnaBridge | 143:86740a56073b | 346 | uint8_t phaseSeg1; /*!< Phase Segment 1. */ |
AnnaBridge | 143:86740a56073b | 347 | uint8_t phaseSeg2; /*!< Phase Segment 2. */ |
AnnaBridge | 143:86740a56073b | 348 | uint8_t propSeg; /*!< Propagation Segment. */ |
AnnaBridge | 143:86740a56073b | 349 | } flexcan_timing_config_t; |
AnnaBridge | 143:86740a56073b | 350 | |
AnnaBridge | 143:86740a56073b | 351 | /*! |
AnnaBridge | 143:86740a56073b | 352 | * @brief FlexCAN Receive Message Buffer configuration structure |
AnnaBridge | 143:86740a56073b | 353 | * |
AnnaBridge | 143:86740a56073b | 354 | * This structure is used as the parameter of FLEXCAN_SetRxMbConfig() function. |
AnnaBridge | 143:86740a56073b | 355 | * The FLEXCAN_SetRxMbConfig() function is used to configure FlexCAN Receive |
AnnaBridge | 143:86740a56073b | 356 | * Message Buffer. The function abort previous receiving process, clean the |
AnnaBridge | 143:86740a56073b | 357 | * Message Buffer and activate the Rx Message Buffer using given Message Buffer |
AnnaBridge | 143:86740a56073b | 358 | * setting. |
AnnaBridge | 143:86740a56073b | 359 | */ |
AnnaBridge | 143:86740a56073b | 360 | typedef struct _flexcan_rx_mb_config |
AnnaBridge | 143:86740a56073b | 361 | { |
AnnaBridge | 143:86740a56073b | 362 | uint32_t id; /*!< CAN Message Buffer Frame Identifier, should be set using |
AnnaBridge | 143:86740a56073b | 363 | FLEXCAN_ID_EXT() or FLEXCAN_ID_STD() macro. */ |
AnnaBridge | 143:86740a56073b | 364 | flexcan_frame_format_t format; /*!< CAN Frame Identifier format(Standard of Extend). */ |
AnnaBridge | 143:86740a56073b | 365 | flexcan_frame_type_t type; /*!< CAN Frame Type(Data or Remote). */ |
AnnaBridge | 143:86740a56073b | 366 | } flexcan_rx_mb_config_t; |
AnnaBridge | 143:86740a56073b | 367 | |
AnnaBridge | 143:86740a56073b | 368 | /*! @brief FlexCAN Rx FIFO configuration structure. */ |
AnnaBridge | 143:86740a56073b | 369 | typedef struct _flexcan_rx_fifo_config |
AnnaBridge | 143:86740a56073b | 370 | { |
AnnaBridge | 143:86740a56073b | 371 | uint32_t *idFilterTable; /*!< Pointer to the FlexCAN Rx FIFO identifier filter table. */ |
AnnaBridge | 143:86740a56073b | 372 | uint8_t idFilterNum; /*!< The quantity of filter elements. */ |
AnnaBridge | 143:86740a56073b | 373 | flexcan_rx_fifo_filter_type_t idFilterType; /*!< The FlexCAN Rx FIFO Filter type. */ |
AnnaBridge | 143:86740a56073b | 374 | flexcan_rx_fifo_priority_t priority; /*!< The FlexCAN Rx FIFO receive priority. */ |
AnnaBridge | 143:86740a56073b | 375 | } flexcan_rx_fifo_config_t; |
AnnaBridge | 143:86740a56073b | 376 | |
AnnaBridge | 143:86740a56073b | 377 | /*! @brief FlexCAN Message Buffer transfer. */ |
AnnaBridge | 143:86740a56073b | 378 | typedef struct _flexcan_mb_transfer |
AnnaBridge | 143:86740a56073b | 379 | { |
AnnaBridge | 143:86740a56073b | 380 | flexcan_frame_t *frame; /*!< The buffer of CAN Message to be transfer. */ |
AnnaBridge | 143:86740a56073b | 381 | uint8_t mbIdx; /*!< The index of Message buffer used to transfer Message. */ |
AnnaBridge | 143:86740a56073b | 382 | } flexcan_mb_transfer_t; |
AnnaBridge | 143:86740a56073b | 383 | |
AnnaBridge | 143:86740a56073b | 384 | /*! @brief FlexCAN Rx FIFO transfer. */ |
AnnaBridge | 143:86740a56073b | 385 | typedef struct _flexcan_fifo_transfer |
AnnaBridge | 143:86740a56073b | 386 | { |
AnnaBridge | 143:86740a56073b | 387 | flexcan_frame_t *frame; /*!< The buffer of CAN Message to be received from Rx FIFO. */ |
AnnaBridge | 143:86740a56073b | 388 | } flexcan_fifo_transfer_t; |
AnnaBridge | 143:86740a56073b | 389 | |
AnnaBridge | 143:86740a56073b | 390 | /*! @brief FlexCAN handle structure definition. */ |
AnnaBridge | 143:86740a56073b | 391 | typedef struct _flexcan_handle flexcan_handle_t; |
AnnaBridge | 143:86740a56073b | 392 | |
AnnaBridge | 143:86740a56073b | 393 | /*! @brief FlexCAN transfer callback function. |
AnnaBridge | 143:86740a56073b | 394 | * |
AnnaBridge | 143:86740a56073b | 395 | * The FlexCAN transfer callback returns a value from the underlying layer. |
AnnaBridge | 143:86740a56073b | 396 | * If the status equals to kStatus_FLEXCAN_ErrorStatus, the result parameter is the Content of |
AnnaBridge | 143:86740a56073b | 397 | * FlexCAN status register which can be used to get the working status(or error status) of FlexCAN module. |
AnnaBridge | 143:86740a56073b | 398 | * If the status equals to other FlexCAN Message Buffer transfer status, the result is the index of |
AnnaBridge | 143:86740a56073b | 399 | * Message Buffer that generate transfer event. |
AnnaBridge | 143:86740a56073b | 400 | * If the status equals to other FlexCAN Message Buffer transfer status, the result is meaningless and should be |
AnnaBridge | 143:86740a56073b | 401 | * Ignored. |
AnnaBridge | 143:86740a56073b | 402 | */ |
AnnaBridge | 143:86740a56073b | 403 | typedef void (*flexcan_transfer_callback_t)( |
AnnaBridge | 143:86740a56073b | 404 | CAN_Type *base, flexcan_handle_t *handle, status_t status, uint32_t result, void *userData); |
AnnaBridge | 143:86740a56073b | 405 | |
AnnaBridge | 143:86740a56073b | 406 | /*! @brief FlexCAN handle structure. */ |
AnnaBridge | 143:86740a56073b | 407 | struct _flexcan_handle |
AnnaBridge | 143:86740a56073b | 408 | { |
AnnaBridge | 143:86740a56073b | 409 | flexcan_transfer_callback_t callback; /*!< Callback function. */ |
AnnaBridge | 143:86740a56073b | 410 | void *userData; /*!< FlexCAN callback function parameter.*/ |
AnnaBridge | 143:86740a56073b | 411 | flexcan_frame_t *volatile mbFrameBuf[CAN_WORD1_COUNT]; |
AnnaBridge | 143:86740a56073b | 412 | /*!< The buffer for received data from Message Buffers. */ |
AnnaBridge | 143:86740a56073b | 413 | flexcan_frame_t *volatile rxFifoFrameBuf; /*!< The buffer for received data from Rx FIFO. */ |
AnnaBridge | 143:86740a56073b | 414 | volatile uint8_t mbState[CAN_WORD1_COUNT]; /*!< Message Buffer transfer state. */ |
AnnaBridge | 143:86740a56073b | 415 | volatile uint8_t rxFifoState; /*!< Rx FIFO transfer state. */ |
AnnaBridge | 143:86740a56073b | 416 | }; |
AnnaBridge | 143:86740a56073b | 417 | |
AnnaBridge | 143:86740a56073b | 418 | /****************************************************************************** |
AnnaBridge | 143:86740a56073b | 419 | * API |
AnnaBridge | 143:86740a56073b | 420 | *****************************************************************************/ |
AnnaBridge | 143:86740a56073b | 421 | |
AnnaBridge | 143:86740a56073b | 422 | #if defined(__cplusplus) |
AnnaBridge | 143:86740a56073b | 423 | extern "C" { |
AnnaBridge | 143:86740a56073b | 424 | #endif |
AnnaBridge | 143:86740a56073b | 425 | |
AnnaBridge | 143:86740a56073b | 426 | /*! |
AnnaBridge | 143:86740a56073b | 427 | * @name Initialization and deinitialization |
AnnaBridge | 143:86740a56073b | 428 | * @{ |
AnnaBridge | 143:86740a56073b | 429 | */ |
AnnaBridge | 143:86740a56073b | 430 | |
AnnaBridge | 143:86740a56073b | 431 | /*! |
AnnaBridge | 143:86740a56073b | 432 | * @brief Initializes a FlexCAN instance. |
AnnaBridge | 143:86740a56073b | 433 | * |
AnnaBridge | 143:86740a56073b | 434 | * This function initializes the FlexCAN module with user-defined settings. |
AnnaBridge | 143:86740a56073b | 435 | * This example shows how to set up the flexcan_config_t parameters and how |
AnnaBridge | 143:86740a56073b | 436 | * to call the FLEXCAN_Init function by passing in these parameters. |
AnnaBridge | 143:86740a56073b | 437 | * @code |
AnnaBridge | 143:86740a56073b | 438 | * flexcan_config_t flexcanConfig; |
AnnaBridge | 143:86740a56073b | 439 | * flexcanConfig.clkSrc = kFLEXCAN_ClkSrcOsc; |
AnnaBridge | 143:86740a56073b | 440 | * flexcanConfig.baudRate = 125000U; |
AnnaBridge | 143:86740a56073b | 441 | * flexcanConfig.maxMbNum = 16; |
AnnaBridge | 143:86740a56073b | 442 | * flexcanConfig.enableLoopBack = false; |
AnnaBridge | 143:86740a56073b | 443 | * flexcanConfig.enableSelfWakeup = false; |
AnnaBridge | 143:86740a56073b | 444 | * flexcanConfig.enableIndividMask = false; |
AnnaBridge | 143:86740a56073b | 445 | * flexcanConfig.enableDoze = false; |
AnnaBridge | 143:86740a56073b | 446 | * FLEXCAN_Init(CAN0, &flexcanConfig, 8000000UL); |
AnnaBridge | 143:86740a56073b | 447 | * @endcode |
AnnaBridge | 143:86740a56073b | 448 | * |
AnnaBridge | 143:86740a56073b | 449 | * @param base FlexCAN peripheral base address. |
AnnaBridge | 143:86740a56073b | 450 | * @param config Pointer to the user-defined configuration structure. |
AnnaBridge | 143:86740a56073b | 451 | * @param sourceClock_Hz FlexCAN Protocol Engine clock source frequency in Hz. |
AnnaBridge | 143:86740a56073b | 452 | */ |
AnnaBridge | 143:86740a56073b | 453 | void FLEXCAN_Init(CAN_Type *base, const flexcan_config_t *config, uint32_t sourceClock_Hz); |
AnnaBridge | 143:86740a56073b | 454 | |
AnnaBridge | 143:86740a56073b | 455 | /*! |
AnnaBridge | 143:86740a56073b | 456 | * @brief De-initializes a FlexCAN instance. |
AnnaBridge | 143:86740a56073b | 457 | * |
AnnaBridge | 143:86740a56073b | 458 | * This function disables the FlexCAN module clock and sets all register values |
AnnaBridge | 143:86740a56073b | 459 | * to the reset value. |
AnnaBridge | 143:86740a56073b | 460 | * |
AnnaBridge | 143:86740a56073b | 461 | * @param base FlexCAN peripheral base address. |
AnnaBridge | 143:86740a56073b | 462 | */ |
AnnaBridge | 143:86740a56073b | 463 | void FLEXCAN_Deinit(CAN_Type *base); |
AnnaBridge | 143:86740a56073b | 464 | |
AnnaBridge | 143:86740a56073b | 465 | /*! |
AnnaBridge | 143:86740a56073b | 466 | * @brief Gets the default configuration structure. |
AnnaBridge | 143:86740a56073b | 467 | * |
AnnaBridge | 143:86740a56073b | 468 | * This function initializes the FlexCAN configuration structure to default values. The default |
AnnaBridge | 143:86740a56073b | 469 | * values are as follows. |
AnnaBridge | 143:86740a56073b | 470 | * flexcanConfig->clkSrc = KFLEXCAN_ClkSrcOsc; |
AnnaBridge | 143:86740a56073b | 471 | * flexcanConfig->baudRate = 125000U; |
AnnaBridge | 143:86740a56073b | 472 | * flexcanConfig->maxMbNum = 16; |
AnnaBridge | 143:86740a56073b | 473 | * flexcanConfig->enableLoopBack = false; |
AnnaBridge | 143:86740a56073b | 474 | * flexcanConfig->enableSelfWakeup = false; |
AnnaBridge | 143:86740a56073b | 475 | * flexcanConfig->enableIndividMask = false; |
AnnaBridge | 143:86740a56073b | 476 | * flexcanConfig->enableDoze = false; |
AnnaBridge | 143:86740a56073b | 477 | * |
AnnaBridge | 143:86740a56073b | 478 | * @param config Pointer to the FlexCAN configuration structure. |
AnnaBridge | 143:86740a56073b | 479 | */ |
AnnaBridge | 143:86740a56073b | 480 | void FLEXCAN_GetDefaultConfig(flexcan_config_t *config); |
AnnaBridge | 143:86740a56073b | 481 | |
AnnaBridge | 143:86740a56073b | 482 | /* @} */ |
AnnaBridge | 143:86740a56073b | 483 | |
AnnaBridge | 143:86740a56073b | 484 | /*! |
AnnaBridge | 143:86740a56073b | 485 | * @name Configuration. |
AnnaBridge | 143:86740a56073b | 486 | * @{ |
AnnaBridge | 143:86740a56073b | 487 | */ |
AnnaBridge | 143:86740a56073b | 488 | |
AnnaBridge | 143:86740a56073b | 489 | /*! |
AnnaBridge | 143:86740a56073b | 490 | * @brief Sets the FlexCAN protocol timing characteristic. |
AnnaBridge | 143:86740a56073b | 491 | * |
AnnaBridge | 143:86740a56073b | 492 | * This function gives user settings to CAN bus timing characteristic. |
AnnaBridge | 143:86740a56073b | 493 | * The function is for an experienced user. For less experienced users, call |
AnnaBridge | 143:86740a56073b | 494 | * the FLEXCAN_Init() and fill the baud rate field with a desired value. |
AnnaBridge | 143:86740a56073b | 495 | * This provides the default timing characteristics to the module. |
AnnaBridge | 143:86740a56073b | 496 | * |
AnnaBridge | 143:86740a56073b | 497 | * Note that calling FLEXCAN_SetTimingConfig() overrides the baud rate set |
AnnaBridge | 143:86740a56073b | 498 | * in FLEXCAN_Init(). |
AnnaBridge | 143:86740a56073b | 499 | * |
AnnaBridge | 143:86740a56073b | 500 | * @param base FlexCAN peripheral base address. |
AnnaBridge | 143:86740a56073b | 501 | * @param config Pointer to the timing configuration structure. |
AnnaBridge | 143:86740a56073b | 502 | */ |
AnnaBridge | 143:86740a56073b | 503 | void FLEXCAN_SetTimingConfig(CAN_Type *base, const flexcan_timing_config_t *config); |
AnnaBridge | 143:86740a56073b | 504 | |
AnnaBridge | 143:86740a56073b | 505 | /*! |
AnnaBridge | 143:86740a56073b | 506 | * @brief Sets the FlexCAN receive message buffer global mask. |
AnnaBridge | 143:86740a56073b | 507 | * |
AnnaBridge | 143:86740a56073b | 508 | * This function sets the global mask for the FlexCAN message buffer in a matching process. |
AnnaBridge | 143:86740a56073b | 509 | * The configuration is only effective when the Rx individual mask is disabled in the FLEXCAN_Init(). |
AnnaBridge | 143:86740a56073b | 510 | * |
AnnaBridge | 143:86740a56073b | 511 | * @param base FlexCAN peripheral base address. |
AnnaBridge | 143:86740a56073b | 512 | * @param mask Rx Message Buffer Global Mask value. |
AnnaBridge | 143:86740a56073b | 513 | */ |
AnnaBridge | 143:86740a56073b | 514 | void FLEXCAN_SetRxMbGlobalMask(CAN_Type *base, uint32_t mask); |
AnnaBridge | 143:86740a56073b | 515 | |
AnnaBridge | 143:86740a56073b | 516 | /*! |
AnnaBridge | 143:86740a56073b | 517 | * @brief Sets the FlexCAN receive FIFO global mask. |
AnnaBridge | 143:86740a56073b | 518 | * |
AnnaBridge | 143:86740a56073b | 519 | * This function sets the global mask for FlexCAN FIFO in a matching process. |
AnnaBridge | 143:86740a56073b | 520 | * |
AnnaBridge | 143:86740a56073b | 521 | * @param base FlexCAN peripheral base address. |
AnnaBridge | 143:86740a56073b | 522 | * @param mask Rx Fifo Global Mask value. |
AnnaBridge | 143:86740a56073b | 523 | */ |
AnnaBridge | 143:86740a56073b | 524 | void FLEXCAN_SetRxFifoGlobalMask(CAN_Type *base, uint32_t mask); |
AnnaBridge | 143:86740a56073b | 525 | |
AnnaBridge | 143:86740a56073b | 526 | /*! |
AnnaBridge | 143:86740a56073b | 527 | * @brief Sets the FlexCAN receive individual mask. |
AnnaBridge | 143:86740a56073b | 528 | * |
AnnaBridge | 143:86740a56073b | 529 | * This function sets the individual mask for the FlexCAN matching process. |
AnnaBridge | 143:86740a56073b | 530 | * The configuration is only effective when the Rx individual mask is enabled in the FLEXCAN_Init(). |
AnnaBridge | 143:86740a56073b | 531 | * If the Rx FIFO is disabled, the individual mask is applied to the corresponding Message Buffer. |
AnnaBridge | 143:86740a56073b | 532 | * If the Rx FIFO is enabled, the individual mask for Rx FIFO occupied Message Buffer is applied to |
AnnaBridge | 143:86740a56073b | 533 | * the Rx Filter with the same index. Note that only the first 32 |
AnnaBridge | 143:86740a56073b | 534 | * individual masks can be used as the Rx FIFO filter mask. |
AnnaBridge | 143:86740a56073b | 535 | * |
AnnaBridge | 143:86740a56073b | 536 | * @param base FlexCAN peripheral base address. |
AnnaBridge | 143:86740a56073b | 537 | * @param maskIdx The Index of individual Mask. |
AnnaBridge | 143:86740a56073b | 538 | * @param mask Rx Individual Mask value. |
AnnaBridge | 143:86740a56073b | 539 | */ |
AnnaBridge | 143:86740a56073b | 540 | void FLEXCAN_SetRxIndividualMask(CAN_Type *base, uint8_t maskIdx, uint32_t mask); |
AnnaBridge | 143:86740a56073b | 541 | |
AnnaBridge | 143:86740a56073b | 542 | /*! |
AnnaBridge | 143:86740a56073b | 543 | * @brief Configures a FlexCAN transmit message buffer. |
AnnaBridge | 143:86740a56073b | 544 | * |
AnnaBridge | 143:86740a56073b | 545 | * This function aborts the previous transmission, cleans the Message Buffer, and |
AnnaBridge | 143:86740a56073b | 546 | * configures it as a Transmit Message Buffer. |
AnnaBridge | 143:86740a56073b | 547 | * |
AnnaBridge | 143:86740a56073b | 548 | * @param base FlexCAN peripheral base address. |
AnnaBridge | 143:86740a56073b | 549 | * @param mbIdx The Message Buffer index. |
AnnaBridge | 143:86740a56073b | 550 | * @param enable Enable/disable Tx Message Buffer. |
AnnaBridge | 143:86740a56073b | 551 | * - true: Enable Tx Message Buffer. |
AnnaBridge | 143:86740a56073b | 552 | * - false: Disable Tx Message Buffer. |
AnnaBridge | 143:86740a56073b | 553 | */ |
AnnaBridge | 143:86740a56073b | 554 | void FLEXCAN_SetTxMbConfig(CAN_Type *base, uint8_t mbIdx, bool enable); |
AnnaBridge | 143:86740a56073b | 555 | |
AnnaBridge | 143:86740a56073b | 556 | /*! |
AnnaBridge | 143:86740a56073b | 557 | * @brief Configures a FlexCAN Receive Message Buffer. |
AnnaBridge | 143:86740a56073b | 558 | * |
AnnaBridge | 143:86740a56073b | 559 | * This function cleans a FlexCAN build-in Message Buffer and configures it |
AnnaBridge | 143:86740a56073b | 560 | * as a Receive Message Buffer. |
AnnaBridge | 143:86740a56073b | 561 | * |
AnnaBridge | 143:86740a56073b | 562 | * @param base FlexCAN peripheral base address. |
AnnaBridge | 143:86740a56073b | 563 | * @param mbIdx The Message Buffer index. |
AnnaBridge | 143:86740a56073b | 564 | * @param config Pointer to the FlexCAN Message Buffer configuration structure. |
AnnaBridge | 143:86740a56073b | 565 | * @param enable Enable/disable Rx Message Buffer. |
AnnaBridge | 143:86740a56073b | 566 | * - true: Enable Rx Message Buffer. |
AnnaBridge | 143:86740a56073b | 567 | * - false: Disable Rx Message Buffer. |
AnnaBridge | 143:86740a56073b | 568 | */ |
AnnaBridge | 143:86740a56073b | 569 | void FLEXCAN_SetRxMbConfig(CAN_Type *base, uint8_t mbIdx, const flexcan_rx_mb_config_t *config, bool enable); |
AnnaBridge | 143:86740a56073b | 570 | |
AnnaBridge | 143:86740a56073b | 571 | /*! |
AnnaBridge | 143:86740a56073b | 572 | * @brief Configures the FlexCAN Rx FIFO. |
AnnaBridge | 143:86740a56073b | 573 | * |
AnnaBridge | 143:86740a56073b | 574 | * This function configures the Rx FIFO with given Rx FIFO configuration. |
AnnaBridge | 143:86740a56073b | 575 | * |
AnnaBridge | 143:86740a56073b | 576 | * @param base FlexCAN peripheral base address. |
AnnaBridge | 143:86740a56073b | 577 | * @param config Pointer to the FlexCAN Rx FIFO configuration structure. |
AnnaBridge | 143:86740a56073b | 578 | * @param enable Enable/disable Rx FIFO. |
AnnaBridge | 143:86740a56073b | 579 | * - true: Enable Rx FIFO. |
AnnaBridge | 143:86740a56073b | 580 | * - false: Disable Rx FIFO. |
AnnaBridge | 143:86740a56073b | 581 | */ |
AnnaBridge | 143:86740a56073b | 582 | void FLEXCAN_SetRxFifoConfig(CAN_Type *base, const flexcan_rx_fifo_config_t *config, bool enable); |
AnnaBridge | 143:86740a56073b | 583 | |
AnnaBridge | 143:86740a56073b | 584 | /* @} */ |
AnnaBridge | 143:86740a56073b | 585 | |
AnnaBridge | 143:86740a56073b | 586 | /*! |
AnnaBridge | 143:86740a56073b | 587 | * @name Status |
AnnaBridge | 143:86740a56073b | 588 | * @{ |
AnnaBridge | 143:86740a56073b | 589 | */ |
AnnaBridge | 143:86740a56073b | 590 | |
AnnaBridge | 143:86740a56073b | 591 | /*! |
AnnaBridge | 143:86740a56073b | 592 | * @brief Gets the FlexCAN module interrupt flags. |
AnnaBridge | 143:86740a56073b | 593 | * |
AnnaBridge | 143:86740a56073b | 594 | * This function gets all FlexCAN status flags. The flags are returned as the logical |
AnnaBridge | 143:86740a56073b | 595 | * OR value of the enumerators @ref _flexcan_flags. To check the specific status, |
AnnaBridge | 143:86740a56073b | 596 | * compare the return value with enumerators in @ref _flexcan_flags. |
AnnaBridge | 143:86740a56073b | 597 | * |
AnnaBridge | 143:86740a56073b | 598 | * @param base FlexCAN peripheral base address. |
AnnaBridge | 143:86740a56073b | 599 | * @return FlexCAN status flags which are ORed by the enumerators in the _flexcan_flags. |
AnnaBridge | 143:86740a56073b | 600 | */ |
AnnaBridge | 143:86740a56073b | 601 | static inline uint32_t FLEXCAN_GetStatusFlags(CAN_Type *base) |
AnnaBridge | 143:86740a56073b | 602 | { |
AnnaBridge | 143:86740a56073b | 603 | return base->ESR1; |
AnnaBridge | 143:86740a56073b | 604 | } |
AnnaBridge | 143:86740a56073b | 605 | |
AnnaBridge | 143:86740a56073b | 606 | /*! |
AnnaBridge | 143:86740a56073b | 607 | * @brief Clears status flags with the provided mask. |
AnnaBridge | 143:86740a56073b | 608 | * |
AnnaBridge | 143:86740a56073b | 609 | * This function clears the FlexCAN status flags with a provided mask. An automatically cleared flag |
AnnaBridge | 143:86740a56073b | 610 | * can't be cleared by this function. |
AnnaBridge | 143:86740a56073b | 611 | * |
AnnaBridge | 143:86740a56073b | 612 | * @param base FlexCAN peripheral base address. |
AnnaBridge | 143:86740a56073b | 613 | * @param mask The status flags to be cleared, it is logical OR value of @ref _flexcan_flags. |
AnnaBridge | 143:86740a56073b | 614 | */ |
AnnaBridge | 143:86740a56073b | 615 | static inline void FLEXCAN_ClearStatusFlags(CAN_Type *base, uint32_t mask) |
AnnaBridge | 143:86740a56073b | 616 | { |
AnnaBridge | 143:86740a56073b | 617 | /* Write 1 to clear status flag. */ |
AnnaBridge | 143:86740a56073b | 618 | base->ESR1 = mask; |
AnnaBridge | 143:86740a56073b | 619 | } |
AnnaBridge | 143:86740a56073b | 620 | |
AnnaBridge | 143:86740a56073b | 621 | /*! |
AnnaBridge | 143:86740a56073b | 622 | * @brief Gets the FlexCAN Bus Error Counter value. |
AnnaBridge | 143:86740a56073b | 623 | * |
AnnaBridge | 143:86740a56073b | 624 | * This function gets the FlexCAN Bus Error Counter value for both Tx and |
AnnaBridge | 143:86740a56073b | 625 | * Rx direction. These values may be needed in the upper layer error handling. |
AnnaBridge | 143:86740a56073b | 626 | * |
AnnaBridge | 143:86740a56073b | 627 | * @param base FlexCAN peripheral base address. |
AnnaBridge | 143:86740a56073b | 628 | * @param txErrBuf Buffer to store Tx Error Counter value. |
AnnaBridge | 143:86740a56073b | 629 | * @param rxErrBuf Buffer to store Rx Error Counter value. |
AnnaBridge | 143:86740a56073b | 630 | */ |
AnnaBridge | 143:86740a56073b | 631 | static inline void FLEXCAN_GetBusErrCount(CAN_Type *base, uint8_t *txErrBuf, uint8_t *rxErrBuf) |
AnnaBridge | 143:86740a56073b | 632 | { |
AnnaBridge | 143:86740a56073b | 633 | if (txErrBuf) |
AnnaBridge | 143:86740a56073b | 634 | { |
AnnaBridge | 143:86740a56073b | 635 | *txErrBuf = (uint8_t)((base->ECR & CAN_ECR_TXERRCNT_MASK) >> CAN_ECR_TXERRCNT_SHIFT); |
AnnaBridge | 143:86740a56073b | 636 | } |
AnnaBridge | 143:86740a56073b | 637 | |
AnnaBridge | 143:86740a56073b | 638 | if (rxErrBuf) |
AnnaBridge | 143:86740a56073b | 639 | { |
AnnaBridge | 143:86740a56073b | 640 | *rxErrBuf = (uint8_t)((base->ECR & CAN_ECR_RXERRCNT_MASK) >> CAN_ECR_RXERRCNT_SHIFT); |
AnnaBridge | 143:86740a56073b | 641 | } |
AnnaBridge | 143:86740a56073b | 642 | } |
AnnaBridge | 143:86740a56073b | 643 | |
AnnaBridge | 143:86740a56073b | 644 | /*! |
AnnaBridge | 143:86740a56073b | 645 | * @brief Gets the FlexCAN Message Buffer interrupt flags. |
AnnaBridge | 143:86740a56073b | 646 | * |
AnnaBridge | 143:86740a56073b | 647 | * This function gets the interrupt flags of a given Message Buffers. |
AnnaBridge | 143:86740a56073b | 648 | * |
AnnaBridge | 143:86740a56073b | 649 | * @param base FlexCAN peripheral base address. |
AnnaBridge | 143:86740a56073b | 650 | * @param mask The ORed FlexCAN Message Buffer mask. |
AnnaBridge | 143:86740a56073b | 651 | * @return The status of given Message Buffers. |
AnnaBridge | 143:86740a56073b | 652 | */ |
AnnaBridge | 143:86740a56073b | 653 | #if (defined(FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER)) && (FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER > 0) |
AnnaBridge | 143:86740a56073b | 654 | static inline uint64_t FLEXCAN_GetMbStatusFlags(CAN_Type *base, uint64_t mask) |
AnnaBridge | 143:86740a56073b | 655 | #else |
AnnaBridge | 143:86740a56073b | 656 | static inline uint32_t FLEXCAN_GetMbStatusFlags(CAN_Type *base, uint32_t mask) |
AnnaBridge | 143:86740a56073b | 657 | #endif |
AnnaBridge | 143:86740a56073b | 658 | { |
AnnaBridge | 143:86740a56073b | 659 | #if (defined(FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER)) && (FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER > 0) |
AnnaBridge | 143:86740a56073b | 660 | return ((((uint64_t)base->IFLAG1) & mask) | ((((uint64_t)base->IFLAG2) << 32) & mask)); |
AnnaBridge | 143:86740a56073b | 661 | #else |
AnnaBridge | 143:86740a56073b | 662 | return (base->IFLAG1 & mask); |
AnnaBridge | 143:86740a56073b | 663 | #endif |
AnnaBridge | 143:86740a56073b | 664 | } |
AnnaBridge | 143:86740a56073b | 665 | |
AnnaBridge | 143:86740a56073b | 666 | /*! |
AnnaBridge | 143:86740a56073b | 667 | * @brief Clears the FlexCAN Message Buffer interrupt flags. |
AnnaBridge | 143:86740a56073b | 668 | * |
AnnaBridge | 143:86740a56073b | 669 | * This function clears the interrupt flags of a given Message Buffers. |
AnnaBridge | 143:86740a56073b | 670 | * |
AnnaBridge | 143:86740a56073b | 671 | * @param base FlexCAN peripheral base address. |
AnnaBridge | 143:86740a56073b | 672 | * @param mask The ORed FlexCAN Message Buffer mask. |
AnnaBridge | 143:86740a56073b | 673 | */ |
AnnaBridge | 143:86740a56073b | 674 | #if (defined(FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER)) && (FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER > 0) |
AnnaBridge | 143:86740a56073b | 675 | static inline void FLEXCAN_ClearMbStatusFlags(CAN_Type *base, uint64_t mask) |
AnnaBridge | 143:86740a56073b | 676 | #else |
AnnaBridge | 143:86740a56073b | 677 | static inline void FLEXCAN_ClearMbStatusFlags(CAN_Type *base, uint32_t mask) |
AnnaBridge | 143:86740a56073b | 678 | #endif |
AnnaBridge | 143:86740a56073b | 679 | { |
AnnaBridge | 143:86740a56073b | 680 | #if (defined(FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER)) && (FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER > 0) |
AnnaBridge | 143:86740a56073b | 681 | base->IFLAG1 = (uint32_t)(mask & 0xFFFFFFFFU); |
AnnaBridge | 143:86740a56073b | 682 | base->IFLAG2 = (uint32_t)(mask >> 32); |
AnnaBridge | 143:86740a56073b | 683 | #else |
AnnaBridge | 143:86740a56073b | 684 | base->IFLAG1 = mask; |
AnnaBridge | 143:86740a56073b | 685 | #endif |
AnnaBridge | 143:86740a56073b | 686 | } |
AnnaBridge | 143:86740a56073b | 687 | |
AnnaBridge | 143:86740a56073b | 688 | /* @} */ |
AnnaBridge | 143:86740a56073b | 689 | |
AnnaBridge | 143:86740a56073b | 690 | /*! |
AnnaBridge | 143:86740a56073b | 691 | * @name Interrupts |
AnnaBridge | 143:86740a56073b | 692 | * @{ |
AnnaBridge | 143:86740a56073b | 693 | */ |
AnnaBridge | 143:86740a56073b | 694 | |
AnnaBridge | 143:86740a56073b | 695 | /*! |
AnnaBridge | 143:86740a56073b | 696 | * @brief Enables FlexCAN interrupts according to the provided mask. |
AnnaBridge | 143:86740a56073b | 697 | * |
AnnaBridge | 143:86740a56073b | 698 | * This function enables the FlexCAN interrupts according to the provided mask. The mask |
AnnaBridge | 143:86740a56073b | 699 | * is a logical OR of enumeration members, see @ref _flexcan_interrupt_enable. |
AnnaBridge | 143:86740a56073b | 700 | * |
AnnaBridge | 143:86740a56073b | 701 | * @param base FlexCAN peripheral base address. |
AnnaBridge | 143:86740a56073b | 702 | * @param mask The interrupts to enable. Logical OR of @ref _flexcan_interrupt_enable. |
AnnaBridge | 143:86740a56073b | 703 | */ |
AnnaBridge | 143:86740a56073b | 704 | static inline void FLEXCAN_EnableInterrupts(CAN_Type *base, uint32_t mask) |
AnnaBridge | 143:86740a56073b | 705 | { |
AnnaBridge | 143:86740a56073b | 706 | /* Solve Wake Up Interrupt. */ |
AnnaBridge | 143:86740a56073b | 707 | if (mask & kFLEXCAN_WakeUpInterruptEnable) |
AnnaBridge | 143:86740a56073b | 708 | { |
AnnaBridge | 143:86740a56073b | 709 | base->MCR |= CAN_MCR_WAKMSK_MASK; |
AnnaBridge | 143:86740a56073b | 710 | } |
AnnaBridge | 143:86740a56073b | 711 | |
AnnaBridge | 143:86740a56073b | 712 | /* Solve others. */ |
AnnaBridge | 143:86740a56073b | 713 | base->CTRL1 |= (mask & (~((uint32_t)kFLEXCAN_WakeUpInterruptEnable))); |
AnnaBridge | 143:86740a56073b | 714 | } |
AnnaBridge | 143:86740a56073b | 715 | |
AnnaBridge | 143:86740a56073b | 716 | /*! |
AnnaBridge | 143:86740a56073b | 717 | * @brief Disables FlexCAN interrupts according to the provided mask. |
AnnaBridge | 143:86740a56073b | 718 | * |
AnnaBridge | 143:86740a56073b | 719 | * This function disables the FlexCAN interrupts according to the provided mask. The mask |
AnnaBridge | 143:86740a56073b | 720 | * is a logical OR of enumeration members, see @ref _flexcan_interrupt_enable. |
AnnaBridge | 143:86740a56073b | 721 | * |
AnnaBridge | 143:86740a56073b | 722 | * @param base FlexCAN peripheral base address. |
AnnaBridge | 143:86740a56073b | 723 | * @param mask The interrupts to disable. Logical OR of @ref _flexcan_interrupt_enable. |
AnnaBridge | 143:86740a56073b | 724 | */ |
AnnaBridge | 143:86740a56073b | 725 | static inline void FLEXCAN_DisableInterrupts(CAN_Type *base, uint32_t mask) |
AnnaBridge | 143:86740a56073b | 726 | { |
AnnaBridge | 143:86740a56073b | 727 | /* Solve Wake Up Interrupt. */ |
AnnaBridge | 143:86740a56073b | 728 | if (mask & kFLEXCAN_WakeUpInterruptEnable) |
AnnaBridge | 143:86740a56073b | 729 | { |
AnnaBridge | 143:86740a56073b | 730 | base->MCR &= ~CAN_MCR_WAKMSK_MASK; |
AnnaBridge | 143:86740a56073b | 731 | } |
AnnaBridge | 143:86740a56073b | 732 | |
AnnaBridge | 143:86740a56073b | 733 | /* Solve others. */ |
AnnaBridge | 143:86740a56073b | 734 | base->CTRL1 &= ~(mask & (~((uint32_t)kFLEXCAN_WakeUpInterruptEnable))); |
AnnaBridge | 143:86740a56073b | 735 | } |
AnnaBridge | 143:86740a56073b | 736 | |
AnnaBridge | 143:86740a56073b | 737 | /*! |
AnnaBridge | 143:86740a56073b | 738 | * @brief Enables FlexCAN Message Buffer interrupts. |
AnnaBridge | 143:86740a56073b | 739 | * |
AnnaBridge | 143:86740a56073b | 740 | * This function enables the interrupts of given Message Buffers. |
AnnaBridge | 143:86740a56073b | 741 | * |
AnnaBridge | 143:86740a56073b | 742 | * @param base FlexCAN peripheral base address. |
AnnaBridge | 143:86740a56073b | 743 | * @param mask The ORed FlexCAN Message Buffer mask. |
AnnaBridge | 143:86740a56073b | 744 | */ |
AnnaBridge | 143:86740a56073b | 745 | #if (defined(FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER)) && (FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER > 0) |
AnnaBridge | 143:86740a56073b | 746 | static inline void FLEXCAN_EnableMbInterrupts(CAN_Type *base, uint64_t mask) |
AnnaBridge | 143:86740a56073b | 747 | #else |
AnnaBridge | 143:86740a56073b | 748 | static inline void FLEXCAN_EnableMbInterrupts(CAN_Type *base, uint32_t mask) |
AnnaBridge | 143:86740a56073b | 749 | #endif |
AnnaBridge | 143:86740a56073b | 750 | { |
AnnaBridge | 143:86740a56073b | 751 | #if (defined(FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER)) && (FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER > 0) |
AnnaBridge | 143:86740a56073b | 752 | base->IMASK1 |= (uint32_t)(mask & 0xFFFFFFFFU); |
AnnaBridge | 143:86740a56073b | 753 | base->IMASK2 |= (uint32_t)(mask >> 32); |
AnnaBridge | 143:86740a56073b | 754 | #else |
AnnaBridge | 143:86740a56073b | 755 | base->IMASK1 |= mask; |
AnnaBridge | 143:86740a56073b | 756 | #endif |
AnnaBridge | 143:86740a56073b | 757 | } |
AnnaBridge | 143:86740a56073b | 758 | |
AnnaBridge | 143:86740a56073b | 759 | /*! |
AnnaBridge | 143:86740a56073b | 760 | * @brief Disables FlexCAN Message Buffer interrupts. |
AnnaBridge | 143:86740a56073b | 761 | * |
AnnaBridge | 143:86740a56073b | 762 | * This function disables the interrupts of given Message Buffers. |
AnnaBridge | 143:86740a56073b | 763 | * |
AnnaBridge | 143:86740a56073b | 764 | * @param base FlexCAN peripheral base address. |
AnnaBridge | 143:86740a56073b | 765 | * @param mask The ORed FlexCAN Message Buffer mask. |
AnnaBridge | 143:86740a56073b | 766 | */ |
AnnaBridge | 143:86740a56073b | 767 | #if (defined(FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER)) && (FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER > 0) |
AnnaBridge | 143:86740a56073b | 768 | static inline void FLEXCAN_DisableMbInterrupts(CAN_Type *base, uint64_t mask) |
AnnaBridge | 143:86740a56073b | 769 | #else |
AnnaBridge | 143:86740a56073b | 770 | static inline void FLEXCAN_DisableMbInterrupts(CAN_Type *base, uint32_t mask) |
AnnaBridge | 143:86740a56073b | 771 | #endif |
AnnaBridge | 143:86740a56073b | 772 | { |
AnnaBridge | 143:86740a56073b | 773 | #if (defined(FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER)) && (FSL_FEATURE_FLEXCAN_HAS_EXTENDED_FLAG_REGISTER > 0) |
AnnaBridge | 143:86740a56073b | 774 | base->IMASK1 &= ~((uint32_t)(mask & 0xFFFFFFFFU)); |
AnnaBridge | 143:86740a56073b | 775 | base->IMASK2 &= ~((uint32_t)(mask >> 32)); |
AnnaBridge | 143:86740a56073b | 776 | #else |
AnnaBridge | 143:86740a56073b | 777 | base->IMASK1 &= ~mask; |
AnnaBridge | 143:86740a56073b | 778 | #endif |
AnnaBridge | 143:86740a56073b | 779 | } |
AnnaBridge | 143:86740a56073b | 780 | |
AnnaBridge | 143:86740a56073b | 781 | /* @} */ |
AnnaBridge | 143:86740a56073b | 782 | |
AnnaBridge | 143:86740a56073b | 783 | #if (defined(FSL_FEATURE_FLEXCAN_HAS_RX_FIFO_DMA) && FSL_FEATURE_FLEXCAN_HAS_RX_FIFO_DMA) |
AnnaBridge | 143:86740a56073b | 784 | /*! |
AnnaBridge | 143:86740a56073b | 785 | * @name DMA Control |
AnnaBridge | 143:86740a56073b | 786 | * @{ |
AnnaBridge | 143:86740a56073b | 787 | */ |
AnnaBridge | 143:86740a56073b | 788 | |
AnnaBridge | 143:86740a56073b | 789 | /*! |
AnnaBridge | 143:86740a56073b | 790 | * @brief Enables or disables the FlexCAN Rx FIFO DMA request. |
AnnaBridge | 143:86740a56073b | 791 | * |
AnnaBridge | 143:86740a56073b | 792 | * This function enables or disables the DMA feature of FlexCAN build-in Rx FIFO. |
AnnaBridge | 143:86740a56073b | 793 | * |
AnnaBridge | 143:86740a56073b | 794 | * @param base FlexCAN peripheral base address. |
AnnaBridge | 143:86740a56073b | 795 | * @param enable true to enable, false to disable. |
AnnaBridge | 143:86740a56073b | 796 | */ |
AnnaBridge | 143:86740a56073b | 797 | void FLEXCAN_EnableRxFifoDMA(CAN_Type *base, bool enable); |
AnnaBridge | 143:86740a56073b | 798 | |
AnnaBridge | 143:86740a56073b | 799 | /*! |
AnnaBridge | 143:86740a56073b | 800 | * @brief Gets the Rx FIFO Head address. |
AnnaBridge | 143:86740a56073b | 801 | * |
AnnaBridge | 143:86740a56073b | 802 | * This function returns the FlexCAN Rx FIFO Head address, which is mainly used for the DMA/eDMA use case. |
AnnaBridge | 143:86740a56073b | 803 | * |
AnnaBridge | 143:86740a56073b | 804 | * @param base FlexCAN peripheral base address. |
AnnaBridge | 143:86740a56073b | 805 | * @return FlexCAN Rx FIFO Head address. |
AnnaBridge | 143:86740a56073b | 806 | */ |
AnnaBridge | 143:86740a56073b | 807 | static inline uint32_t FLEXCAN_GetRxFifoHeadAddr(CAN_Type *base) |
AnnaBridge | 143:86740a56073b | 808 | { |
AnnaBridge | 143:86740a56073b | 809 | return (uint32_t) & (base->MB[0].CS); |
AnnaBridge | 143:86740a56073b | 810 | } |
AnnaBridge | 143:86740a56073b | 811 | |
AnnaBridge | 143:86740a56073b | 812 | /* @} */ |
AnnaBridge | 143:86740a56073b | 813 | #endif /* FSL_FEATURE_FLEXCAN_HAS_RX_FIFO_DMA */ |
AnnaBridge | 143:86740a56073b | 814 | |
AnnaBridge | 143:86740a56073b | 815 | /*! |
AnnaBridge | 143:86740a56073b | 816 | * @name Bus Operations |
AnnaBridge | 143:86740a56073b | 817 | * @{ |
AnnaBridge | 143:86740a56073b | 818 | */ |
AnnaBridge | 143:86740a56073b | 819 | |
AnnaBridge | 143:86740a56073b | 820 | /*! |
AnnaBridge | 143:86740a56073b | 821 | * @brief Enables or disables the FlexCAN module operation. |
AnnaBridge | 143:86740a56073b | 822 | * |
AnnaBridge | 143:86740a56073b | 823 | * This function enables or disables the FlexCAN module. |
AnnaBridge | 143:86740a56073b | 824 | * |
AnnaBridge | 143:86740a56073b | 825 | * @param base FlexCAN base pointer. |
AnnaBridge | 143:86740a56073b | 826 | * @param enable true to enable, false to disable. |
AnnaBridge | 143:86740a56073b | 827 | */ |
AnnaBridge | 143:86740a56073b | 828 | static inline void FLEXCAN_Enable(CAN_Type *base, bool enable) |
AnnaBridge | 143:86740a56073b | 829 | { |
AnnaBridge | 143:86740a56073b | 830 | if (enable) |
AnnaBridge | 143:86740a56073b | 831 | { |
AnnaBridge | 143:86740a56073b | 832 | base->MCR &= ~CAN_MCR_MDIS_MASK; |
AnnaBridge | 143:86740a56073b | 833 | |
AnnaBridge | 143:86740a56073b | 834 | /* Wait FlexCAN exit from low-power mode. */ |
AnnaBridge | 143:86740a56073b | 835 | while (base->MCR & CAN_MCR_LPMACK_MASK) |
AnnaBridge | 143:86740a56073b | 836 | { |
AnnaBridge | 143:86740a56073b | 837 | } |
AnnaBridge | 143:86740a56073b | 838 | } |
AnnaBridge | 143:86740a56073b | 839 | else |
AnnaBridge | 143:86740a56073b | 840 | { |
AnnaBridge | 143:86740a56073b | 841 | base->MCR |= CAN_MCR_MDIS_MASK; |
AnnaBridge | 143:86740a56073b | 842 | |
AnnaBridge | 143:86740a56073b | 843 | /* Wait FlexCAN enter low-power mode. */ |
AnnaBridge | 143:86740a56073b | 844 | while (!(base->MCR & CAN_MCR_LPMACK_MASK)) |
AnnaBridge | 143:86740a56073b | 845 | { |
AnnaBridge | 143:86740a56073b | 846 | } |
AnnaBridge | 143:86740a56073b | 847 | } |
AnnaBridge | 143:86740a56073b | 848 | } |
AnnaBridge | 143:86740a56073b | 849 | |
AnnaBridge | 143:86740a56073b | 850 | /*! |
AnnaBridge | 143:86740a56073b | 851 | * @brief Writes a FlexCAN Message to the Transmit Message Buffer. |
AnnaBridge | 143:86740a56073b | 852 | * |
AnnaBridge | 143:86740a56073b | 853 | * This function writes a CAN Message to the specified Transmit Message Buffer |
AnnaBridge | 143:86740a56073b | 854 | * and changes the Message Buffer state to start CAN Message transmit. After |
AnnaBridge | 143:86740a56073b | 855 | * that the function returns immediately. |
AnnaBridge | 143:86740a56073b | 856 | * |
AnnaBridge | 143:86740a56073b | 857 | * @param base FlexCAN peripheral base address. |
AnnaBridge | 143:86740a56073b | 858 | * @param mbIdx The FlexCAN Message Buffer index. |
AnnaBridge | 143:86740a56073b | 859 | * @param txFrame Pointer to CAN message frame to be sent. |
AnnaBridge | 143:86740a56073b | 860 | * @retval kStatus_Success - Write Tx Message Buffer Successfully. |
AnnaBridge | 143:86740a56073b | 861 | * @retval kStatus_Fail - Tx Message Buffer is currently in use. |
AnnaBridge | 143:86740a56073b | 862 | */ |
AnnaBridge | 143:86740a56073b | 863 | status_t FLEXCAN_WriteTxMb(CAN_Type *base, uint8_t mbIdx, const flexcan_frame_t *txFrame); |
AnnaBridge | 143:86740a56073b | 864 | |
AnnaBridge | 143:86740a56073b | 865 | /*! |
AnnaBridge | 143:86740a56073b | 866 | * @brief Reads a FlexCAN Message from Receive Message Buffer. |
AnnaBridge | 143:86740a56073b | 867 | * |
AnnaBridge | 143:86740a56073b | 868 | * This function reads a CAN message from a specified Receive Message Buffer. |
AnnaBridge | 143:86740a56073b | 869 | * The function fills a receive CAN message frame structure with |
AnnaBridge | 143:86740a56073b | 870 | * just received data and activates the Message Buffer again. |
AnnaBridge | 143:86740a56073b | 871 | * The function returns immediately. |
AnnaBridge | 143:86740a56073b | 872 | * |
AnnaBridge | 143:86740a56073b | 873 | * @param base FlexCAN peripheral base address. |
AnnaBridge | 143:86740a56073b | 874 | * @param mbIdx The FlexCAN Message Buffer index. |
AnnaBridge | 143:86740a56073b | 875 | * @param rxFrame Pointer to CAN message frame structure for reception. |
AnnaBridge | 143:86740a56073b | 876 | * @retval kStatus_Success - Rx Message Buffer is full and has been read successfully. |
AnnaBridge | 143:86740a56073b | 877 | * @retval kStatus_FLEXCAN_RxOverflow - Rx Message Buffer is already overflowed and has been read successfully. |
AnnaBridge | 143:86740a56073b | 878 | * @retval kStatus_Fail - Rx Message Buffer is empty. |
AnnaBridge | 143:86740a56073b | 879 | */ |
AnnaBridge | 143:86740a56073b | 880 | status_t FLEXCAN_ReadRxMb(CAN_Type *base, uint8_t mbIdx, flexcan_frame_t *rxFrame); |
AnnaBridge | 143:86740a56073b | 881 | |
AnnaBridge | 143:86740a56073b | 882 | /*! |
AnnaBridge | 143:86740a56073b | 883 | * @brief Reads a FlexCAN Message from Rx FIFO. |
AnnaBridge | 143:86740a56073b | 884 | * |
AnnaBridge | 143:86740a56073b | 885 | * This function reads a CAN message from the FlexCAN build-in Rx FIFO. |
AnnaBridge | 143:86740a56073b | 886 | * |
AnnaBridge | 143:86740a56073b | 887 | * @param base FlexCAN peripheral base address. |
AnnaBridge | 143:86740a56073b | 888 | * @param rxFrame Pointer to CAN message frame structure for reception. |
AnnaBridge | 143:86740a56073b | 889 | * @retval kStatus_Success - Read Message from Rx FIFO successfully. |
AnnaBridge | 143:86740a56073b | 890 | * @retval kStatus_Fail - Rx FIFO is not enabled. |
AnnaBridge | 143:86740a56073b | 891 | */ |
AnnaBridge | 143:86740a56073b | 892 | status_t FLEXCAN_ReadRxFifo(CAN_Type *base, flexcan_frame_t *rxFrame); |
AnnaBridge | 143:86740a56073b | 893 | |
AnnaBridge | 143:86740a56073b | 894 | /* @} */ |
AnnaBridge | 143:86740a56073b | 895 | |
AnnaBridge | 143:86740a56073b | 896 | /*! |
AnnaBridge | 143:86740a56073b | 897 | * @name Transactional |
AnnaBridge | 143:86740a56073b | 898 | * @{ |
AnnaBridge | 143:86740a56073b | 899 | */ |
AnnaBridge | 143:86740a56073b | 900 | |
AnnaBridge | 143:86740a56073b | 901 | /*! |
AnnaBridge | 143:86740a56073b | 902 | * @brief Performs a polling send transaction on the CAN bus. |
AnnaBridge | 143:86740a56073b | 903 | * |
AnnaBridge | 143:86740a56073b | 904 | * Note that a transfer handle does not need to be created before calling this API. |
AnnaBridge | 143:86740a56073b | 905 | * |
AnnaBridge | 143:86740a56073b | 906 | * @param base FlexCAN peripheral base pointer. |
AnnaBridge | 143:86740a56073b | 907 | * @param mbIdx The FlexCAN Message Buffer index. |
AnnaBridge | 143:86740a56073b | 908 | * @param txFrame Pointer to CAN message frame to be sent. |
AnnaBridge | 143:86740a56073b | 909 | * @retval kStatus_Success - Write Tx Message Buffer Successfully. |
AnnaBridge | 143:86740a56073b | 910 | * @retval kStatus_Fail - Tx Message Buffer is currently in use. |
AnnaBridge | 143:86740a56073b | 911 | */ |
AnnaBridge | 143:86740a56073b | 912 | status_t FLEXCAN_TransferSendBlocking(CAN_Type *base, uint8_t mbIdx, flexcan_frame_t *txFrame); |
AnnaBridge | 143:86740a56073b | 913 | |
AnnaBridge | 143:86740a56073b | 914 | /*! |
AnnaBridge | 143:86740a56073b | 915 | * @brief Performs a polling receive transaction on the CAN bus. |
AnnaBridge | 143:86740a56073b | 916 | * |
AnnaBridge | 143:86740a56073b | 917 | * Note that a transfer handle does not need to be created before calling this API. |
AnnaBridge | 143:86740a56073b | 918 | * |
AnnaBridge | 143:86740a56073b | 919 | * @param base FlexCAN peripheral base pointer. |
AnnaBridge | 143:86740a56073b | 920 | * @param mbIdx The FlexCAN Message Buffer index. |
AnnaBridge | 143:86740a56073b | 921 | * @param rxFrame Pointer to CAN message frame structure for reception. |
AnnaBridge | 143:86740a56073b | 922 | * @retval kStatus_Success - Rx Message Buffer is full and has been read successfully. |
AnnaBridge | 143:86740a56073b | 923 | * @retval kStatus_FLEXCAN_RxOverflow - Rx Message Buffer is already overflowed and has been read successfully. |
AnnaBridge | 143:86740a56073b | 924 | * @retval kStatus_Fail - Rx Message Buffer is empty. |
AnnaBridge | 143:86740a56073b | 925 | */ |
AnnaBridge | 143:86740a56073b | 926 | status_t FLEXCAN_TransferReceiveBlocking(CAN_Type *base, uint8_t mbIdx, flexcan_frame_t *rxFrame); |
AnnaBridge | 143:86740a56073b | 927 | |
AnnaBridge | 143:86740a56073b | 928 | /*! |
AnnaBridge | 143:86740a56073b | 929 | * @brief Performs a polling receive transaction from Rx FIFO on the CAN bus. |
AnnaBridge | 143:86740a56073b | 930 | * |
AnnaBridge | 143:86740a56073b | 931 | * Note that a transfer handle does not need to be created before calling this API. |
AnnaBridge | 143:86740a56073b | 932 | * |
AnnaBridge | 143:86740a56073b | 933 | * @param base FlexCAN peripheral base pointer. |
AnnaBridge | 143:86740a56073b | 934 | * @param rxFrame Pointer to CAN message frame structure for reception. |
AnnaBridge | 143:86740a56073b | 935 | * @retval kStatus_Success - Read Message from Rx FIFO successfully. |
AnnaBridge | 143:86740a56073b | 936 | * @retval kStatus_Fail - Rx FIFO is not enabled. |
AnnaBridge | 143:86740a56073b | 937 | */ |
AnnaBridge | 143:86740a56073b | 938 | status_t FLEXCAN_TransferReceiveFifoBlocking(CAN_Type *base, flexcan_frame_t *rxFrame); |
AnnaBridge | 143:86740a56073b | 939 | |
AnnaBridge | 143:86740a56073b | 940 | /*! |
AnnaBridge | 143:86740a56073b | 941 | * @brief Initializes the FlexCAN handle. |
AnnaBridge | 143:86740a56073b | 942 | * |
AnnaBridge | 143:86740a56073b | 943 | * This function initializes the FlexCAN handle, which can be used for other FlexCAN |
AnnaBridge | 143:86740a56073b | 944 | * transactional APIs. Usually, for a specified FlexCAN instance, |
AnnaBridge | 143:86740a56073b | 945 | * call this API once to get the initialized handle. |
AnnaBridge | 143:86740a56073b | 946 | * |
AnnaBridge | 143:86740a56073b | 947 | * @param base FlexCAN peripheral base address. |
AnnaBridge | 143:86740a56073b | 948 | * @param handle FlexCAN handle pointer. |
AnnaBridge | 143:86740a56073b | 949 | * @param callback The callback function. |
AnnaBridge | 143:86740a56073b | 950 | * @param userData The parameter of the callback function. |
AnnaBridge | 143:86740a56073b | 951 | */ |
AnnaBridge | 143:86740a56073b | 952 | void FLEXCAN_TransferCreateHandle(CAN_Type *base, |
AnnaBridge | 143:86740a56073b | 953 | flexcan_handle_t *handle, |
AnnaBridge | 143:86740a56073b | 954 | flexcan_transfer_callback_t callback, |
AnnaBridge | 143:86740a56073b | 955 | void *userData); |
AnnaBridge | 143:86740a56073b | 956 | |
AnnaBridge | 143:86740a56073b | 957 | /*! |
AnnaBridge | 143:86740a56073b | 958 | * @brief Sends a message using IRQ. |
AnnaBridge | 143:86740a56073b | 959 | * |
AnnaBridge | 143:86740a56073b | 960 | * This function sends a message using IRQ. This is a non-blocking function, which returns |
AnnaBridge | 143:86740a56073b | 961 | * right away. When messages have been sent out, the send callback function is called. |
AnnaBridge | 143:86740a56073b | 962 | * |
AnnaBridge | 143:86740a56073b | 963 | * @param base FlexCAN peripheral base address. |
AnnaBridge | 143:86740a56073b | 964 | * @param handle FlexCAN handle pointer. |
AnnaBridge | 143:86740a56073b | 965 | * @param xfer FlexCAN Message Buffer transfer structure. See the #flexcan_mb_transfer_t. |
AnnaBridge | 143:86740a56073b | 966 | * @retval kStatus_Success Start Tx Message Buffer sending process successfully. |
AnnaBridge | 143:86740a56073b | 967 | * @retval kStatus_Fail Write Tx Message Buffer failed. |
AnnaBridge | 143:86740a56073b | 968 | * @retval kStatus_FLEXCAN_TxBusy Tx Message Buffer is in use. |
AnnaBridge | 143:86740a56073b | 969 | */ |
AnnaBridge | 143:86740a56073b | 970 | status_t FLEXCAN_TransferSendNonBlocking(CAN_Type *base, flexcan_handle_t *handle, flexcan_mb_transfer_t *xfer); |
AnnaBridge | 143:86740a56073b | 971 | |
AnnaBridge | 143:86740a56073b | 972 | /*! |
AnnaBridge | 143:86740a56073b | 973 | * @brief Receives a message using IRQ. |
AnnaBridge | 143:86740a56073b | 974 | * |
AnnaBridge | 143:86740a56073b | 975 | * This function receives a message using IRQ. This is non-blocking function, which returns |
AnnaBridge | 143:86740a56073b | 976 | * right away. When the message has been received, the receive callback function is called. |
AnnaBridge | 143:86740a56073b | 977 | * |
AnnaBridge | 143:86740a56073b | 978 | * @param base FlexCAN peripheral base address. |
AnnaBridge | 143:86740a56073b | 979 | * @param handle FlexCAN handle pointer. |
AnnaBridge | 143:86740a56073b | 980 | * @param xfer FlexCAN Message Buffer transfer structure. See the #flexcan_mb_transfer_t. |
AnnaBridge | 143:86740a56073b | 981 | * @retval kStatus_Success - Start Rx Message Buffer receiving process successfully. |
AnnaBridge | 143:86740a56073b | 982 | * @retval kStatus_FLEXCAN_RxBusy - Rx Message Buffer is in use. |
AnnaBridge | 143:86740a56073b | 983 | */ |
AnnaBridge | 143:86740a56073b | 984 | status_t FLEXCAN_TransferReceiveNonBlocking(CAN_Type *base, flexcan_handle_t *handle, flexcan_mb_transfer_t *xfer); |
AnnaBridge | 143:86740a56073b | 985 | |
AnnaBridge | 143:86740a56073b | 986 | /*! |
AnnaBridge | 143:86740a56073b | 987 | * @brief Receives a message from Rx FIFO using IRQ. |
AnnaBridge | 143:86740a56073b | 988 | * |
AnnaBridge | 143:86740a56073b | 989 | * This function receives a message using IRQ. This is a non-blocking function, which returns |
AnnaBridge | 143:86740a56073b | 990 | * right away. When all messages have been received, the receive callback function is called. |
AnnaBridge | 143:86740a56073b | 991 | * |
AnnaBridge | 143:86740a56073b | 992 | * @param base FlexCAN peripheral base address. |
AnnaBridge | 143:86740a56073b | 993 | * @param handle FlexCAN handle pointer. |
AnnaBridge | 143:86740a56073b | 994 | * @param xfer FlexCAN Rx FIFO transfer structure. See the @ref flexcan_fifo_transfer_t. |
AnnaBridge | 143:86740a56073b | 995 | * @retval kStatus_Success - Start Rx FIFO receiving process successfully. |
AnnaBridge | 143:86740a56073b | 996 | * @retval kStatus_FLEXCAN_RxFifoBusy - Rx FIFO is currently in use. |
AnnaBridge | 143:86740a56073b | 997 | */ |
AnnaBridge | 143:86740a56073b | 998 | status_t FLEXCAN_TransferReceiveFifoNonBlocking(CAN_Type *base, |
AnnaBridge | 143:86740a56073b | 999 | flexcan_handle_t *handle, |
AnnaBridge | 143:86740a56073b | 1000 | flexcan_fifo_transfer_t *xfer); |
AnnaBridge | 143:86740a56073b | 1001 | |
AnnaBridge | 143:86740a56073b | 1002 | /*! |
AnnaBridge | 143:86740a56073b | 1003 | * @brief Aborts the interrupt driven message send process. |
AnnaBridge | 143:86740a56073b | 1004 | * |
AnnaBridge | 143:86740a56073b | 1005 | * This function aborts the interrupt driven message send process. |
AnnaBridge | 143:86740a56073b | 1006 | * |
AnnaBridge | 143:86740a56073b | 1007 | * @param base FlexCAN peripheral base address. |
AnnaBridge | 143:86740a56073b | 1008 | * @param handle FlexCAN handle pointer. |
AnnaBridge | 143:86740a56073b | 1009 | * @param mbIdx The FlexCAN Message Buffer index. |
AnnaBridge | 143:86740a56073b | 1010 | */ |
AnnaBridge | 143:86740a56073b | 1011 | void FLEXCAN_TransferAbortSend(CAN_Type *base, flexcan_handle_t *handle, uint8_t mbIdx); |
AnnaBridge | 143:86740a56073b | 1012 | |
AnnaBridge | 143:86740a56073b | 1013 | /*! |
AnnaBridge | 143:86740a56073b | 1014 | * @brief Aborts the interrupt driven message receive process. |
AnnaBridge | 143:86740a56073b | 1015 | * |
AnnaBridge | 143:86740a56073b | 1016 | * This function aborts the interrupt driven message receive process. |
AnnaBridge | 143:86740a56073b | 1017 | * |
AnnaBridge | 143:86740a56073b | 1018 | * @param base FlexCAN peripheral base address. |
AnnaBridge | 143:86740a56073b | 1019 | * @param handle FlexCAN handle pointer. |
AnnaBridge | 143:86740a56073b | 1020 | * @param mbIdx The FlexCAN Message Buffer index. |
AnnaBridge | 143:86740a56073b | 1021 | */ |
AnnaBridge | 143:86740a56073b | 1022 | void FLEXCAN_TransferAbortReceive(CAN_Type *base, flexcan_handle_t *handle, uint8_t mbIdx); |
AnnaBridge | 143:86740a56073b | 1023 | |
AnnaBridge | 143:86740a56073b | 1024 | /*! |
AnnaBridge | 143:86740a56073b | 1025 | * @brief Aborts the interrupt driven message receive from Rx FIFO process. |
AnnaBridge | 143:86740a56073b | 1026 | * |
AnnaBridge | 143:86740a56073b | 1027 | * This function aborts the interrupt driven message receive from Rx FIFO process. |
AnnaBridge | 143:86740a56073b | 1028 | * |
AnnaBridge | 143:86740a56073b | 1029 | * @param base FlexCAN peripheral base address. |
AnnaBridge | 143:86740a56073b | 1030 | * @param handle FlexCAN handle pointer. |
AnnaBridge | 143:86740a56073b | 1031 | */ |
AnnaBridge | 143:86740a56073b | 1032 | void FLEXCAN_TransferAbortReceiveFifo(CAN_Type *base, flexcan_handle_t *handle); |
AnnaBridge | 143:86740a56073b | 1033 | |
AnnaBridge | 143:86740a56073b | 1034 | /*! |
AnnaBridge | 143:86740a56073b | 1035 | * @brief FlexCAN IRQ handle function. |
AnnaBridge | 143:86740a56073b | 1036 | * |
AnnaBridge | 143:86740a56073b | 1037 | * This function handles the FlexCAN Error, the Message Buffer, and the Rx FIFO IRQ request. |
AnnaBridge | 143:86740a56073b | 1038 | * |
AnnaBridge | 143:86740a56073b | 1039 | * @param base FlexCAN peripheral base address. |
AnnaBridge | 143:86740a56073b | 1040 | * @param handle FlexCAN handle pointer. |
AnnaBridge | 143:86740a56073b | 1041 | */ |
AnnaBridge | 143:86740a56073b | 1042 | void FLEXCAN_TransferHandleIRQ(CAN_Type *base, flexcan_handle_t *handle); |
AnnaBridge | 143:86740a56073b | 1043 | |
AnnaBridge | 143:86740a56073b | 1044 | /* @} */ |
AnnaBridge | 143:86740a56073b | 1045 | |
AnnaBridge | 143:86740a56073b | 1046 | #if defined(__cplusplus) |
AnnaBridge | 143:86740a56073b | 1047 | } |
AnnaBridge | 143:86740a56073b | 1048 | #endif |
AnnaBridge | 143:86740a56073b | 1049 | |
AnnaBridge | 143:86740a56073b | 1050 | /*! @}*/ |
AnnaBridge | 143:86740a56073b | 1051 | |
AnnaBridge | 143:86740a56073b | 1052 | #endif /* _FSL_FLEXCAN_H_ */ |