1 /** 2 * @file adc.h 3 * @brief Analog to Digital Converter(ADC) function prototypes and data types. 4 */ 5 6 /****************************************************************************** 7 * 8 * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by 9 * Analog Devices, Inc.), 10 * Copyright (C) 2023-2024 Analog Devices, Inc. 11 * 12 * Licensed under the Apache License, Version 2.0 (the "License"); 13 * you may not use this file except in compliance with the License. 14 * You may obtain a copy of the License at 15 * 16 * http://www.apache.org/licenses/LICENSE-2.0 17 * 18 * Unless required by applicable law or agreed to in writing, software 19 * distributed under the License is distributed on an "AS IS" BASIS, 20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 * See the License for the specific language governing permissions and 22 * limitations under the License. 23 * 24 ******************************************************************************/ 25 26 /* Define to prevent redundant inclusion */ 27 #ifndef LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32690_CAN_H_ 28 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32690_CAN_H_ 29 30 /* **** Includes **** */ 31 #include <stdint.h> 32 #include <stdbool.h> 33 #include "max32690.h" 34 #include "can_regs.h" 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif 39 40 /** 41 * @defgroup can CAN 42 * @ingroup periphlibs 43 * @{ 44 */ 45 46 #define MXC_CAN_FILT_PER_OBJ 2 47 48 // SEG1 = PROPAGATION_SEGMENT + PHASE_SEG1 49 #define MXC_CAN_SEG1_SHIFT 16 50 #define MXC_CAN_SEG1(seg1_tq) ((seg1_tq & 0xFF) << MXC_CAN_SEG1_SHIFT) 51 #define MXC_CAN_SEG2_SHIFT 8 52 #define MXC_CAN_SEG2(seg2_tq) ((seg2_tq & 0xFF) << MXC_CAN_SEG2_SHIFT) 53 #define MXC_CAN_SJW_SHIFT 0 54 #define MXC_CAN_SJW(sjw_tq) ((sjw_tq & 0xFF) << MXC_CAN_SJW_SHIFT) 55 #define MXC_CAN_BIT_SEGMENTS(seg1_tq, seg2_tq, sjw_tq) \ 56 (MXC_CAN_SEG1(seg1_tq) | MXC_CAN_SEG2(seg2_tq) | MXC_CAN_SJW(sjw_tq)) 57 58 #define MXC_CAN_NOMINAL_MAX_SEG1TQ 16 59 #define MXC_CAN_NOMINAL_MAX_SEG2TQ 8 60 #define MXC_CAN_NOMINAL_MAX_SJWTQ 4 61 #define MXC_CAN_NOMINAL_MAX_PRESCALER 0x400 62 #define MXC_CAN_FD_DATA_MAX_SEG1TQ 64 63 #define MXC_CAN_FD_DATA_MAX_SEG2TQ 16 64 #define MXC_CAN_FD_DATA_MAX_SJWTQ 16 65 #define MXC_CAN_FD_DATA_MAX_PRESCALER 0x400 66 67 #define MXC_CAN_FILT_OP_TYPE_SHIFT 0 68 #define MXC_CAN_FILT_OP_TYPE_MASK 0x000F 69 #define MXC_CAN_FILT_SEL_SHIFT 4 70 #define MXC_CAN_FILT_SEL_MASK 0x00F0 71 72 #define MXC_CAN_MSG_INFO_IDE_BIT 0x80000000 73 #define MXC_CAN_STANDARD_ID(id) (id & 0x7FFUL) 74 #define MXC_CAN_EXTENDED_ID(id) ((id & 0x1FFFFFFFUL) | MXC_CAN_MSG_INFO_IDE_BIT) 75 76 #define MXC_CAN_BUF_CFG_IDE 0x80 77 #define MXC_CAN_BUF_CFG_SRR 0x40 78 #define MXC_CAN_BUF_CFG_RTR(rtr) ((!!rtr) << 6) 79 #define MXC_CAN_BUF_CFG_FDF(fdf) ((!!fdf) << 5) 80 #define MXC_CAN_BUF_CFG_BRS(brs) ((!!brs) << 4) 81 #define MXC_CAN_BUF_CFG_DLC(dlc) (dlc & 0xF) 82 83 #define MXC_CAN_BUF_CFG_EXT_ID_TX1(id) ((id & (0xFF << 21)) >> 21) 84 #define MXC_CAN_BUF_CFG_EXT_ID_TX2(id) ((id & (0xFF << 13)) >> 13) 85 #define MXC_CAN_BUF_CFG_EXT_ID_TX3(id) ((id & (0xFF << 5)) >> 5) 86 #define MXC_CAN_BUF_CFG_EXT_ID_TX4(id) ((id & 0x1F) << 3) 87 #define MXC_CAN_BUF_CFG_EXT_ID_RX1(rxdata) (rxdata << 21) 88 #define MXC_CAN_BUF_CFG_EXT_ID_RX2(rxdata) (rxdata << 13) 89 #define MXC_CAN_BUF_CFG_EXT_ID_RX3(rxdata) (rxdata << 5) 90 #define MXC_CAN_BUF_CFG_EXT_ID_RX4(rxdata) ((rxdata & 0xF8) >> 3) 91 #define MXC_CAN_BUF_CFG_EXT_ID_RTR(rtr) ((!!rtr) << 2) 92 #define MXC_CAN_BUF_CFG_EXT_ID_ESI(esi) ((!!esi) << 1) 93 94 #define MXC_CAN_BUF_CFG_STD_ID_TX1(id) ((id & (0xFF << 3)) >> 3) 95 #define MXC_CAN_BUF_CFG_STD_ID_TX2(id) ((id & 0x7) << 5) 96 #define MXC_CAN_BUF_CFG_STD_ID_RX1(rxdata) (rxdata << 3) 97 #define MXC_CAN_BUF_CFG_STD_ID_RX2(rxdata) ((rxdata & 0xE0) >> 5) 98 #define MXC_CAN_BUF_CFG_STD_ID_RTR(rtr) ((!!rtr) << 6) 99 #define MXC_CAN_BUF_CFG_STD_ID_ESI(esi) ((!!esi) << 3) 100 101 #define MXC_CAN_LEC_NO_ERR 0U 102 #define MXC_CAN_LEC_BIT_ERR 1U 103 #define MXC_CAN_LEC_STUFF_ERR 2U 104 #define MXC_CAN_LEC_CRC_ERR 3U 105 #define MXC_CAN_LEC_FORM_ERR 4U 106 #define MXC_CAN_LEC_ACK_ERR 5U 107 #define MXC_CAN_ECC_ERROR_CODE_MASK \ 108 (MXC_F_CAN_REVA_ECC_ACKER | MXC_F_CAN_REVA_ECC_FRMER | MXC_F_CAN_REVA_ECC_CRCER | \ 109 MXC_F_CAN_REVA_ECC_STFER | MXC_F_CAN_REVA_ECC_BER) 110 111 #define MXC_CAN_UNIT_STATE_INACTIVE 0U 112 #define MXC_CAN_UNIT_STATE_ACTIVE 1U 113 #define MXC_CAN_UNIT_STATE_PASSIVE 2U 114 #define MXC_CAN_UNIT_STATE_BUS_OFF 3U 115 116 #define MXC_CAN_DMA_LEN(msg_id) (msg_id & MXC_CAN_MSG_INFO_IDE_BIT ? 5 : 3) 117 118 #define MXC_CAN_TXSCNT_MAX 0x80 119 #define MXC_CAN_ERRPSV_THRESH 0x80 120 121 /** 122 * @brief Struct containing information about the version of the CAN library 123 */ 124 typedef struct { 125 uint16_t api; ///< CMSIS API Version 126 uint16_t drv; ///< Maxim CAN SDK Version 127 } mxc_can_drv_version_t; 128 129 /** 130 * @brief Struct containing the capabilities of the CAN driver. 131 */ 132 typedef struct { 133 uint32_t num_objects; ///< Number of objects available 134 uint32_t 135 reentrant_operation; ///< Reentrant calls to MessageSend/Read, ObjectConfigure, and CAN_Control supported 136 uint32_t fd_mode; ///< CAN FD supported 137 uint32_t restricted_mode; ///< Restricted mode supported 138 uint32_t monitor_mode; ///< Monitor mode supported 139 uint32_t internal_loopback; ///< Internal loopback supported 140 uint32_t external_loopback; ///< External loopback supported 141 uint32_t rsv; ///< Reserved for future use 142 } mxc_can_capabilities_t; 143 144 /** 145 * @brief Selects power state of the CAN peripherals 146 */ 147 typedef enum { 148 MXC_CAN_PWR_CTRL_OFF = 0, ///< Shut off power to peripherals 149 MXC_CAN_PWR_CTRL_SLEEP, ///< Put peripherals to sleep 150 MXC_CAN_PWR_CTRL_FULL, ///< Peripherals fully awake 151 } mxc_can_pwr_ctrl_t; 152 153 /** 154 * @brief Selects which bitrate to perform operation on 155 */ 156 typedef enum { 157 MXC_CAN_BITRATE_SEL_NOMINAL = 0, ///< Set bitrate for classic CAN frames 158 MXC_CAN_BITRATE_SEL_FD_DATA, ///< Reserved for future use. Not supported on MAX32690, included to prevent build errors. 159 } mxc_can_bitrate_sel_t; 160 161 /** 162 * @brief Selects the CAN driver's mode of operation 163 */ 164 typedef enum { 165 MXC_CAN_MODE_INITIALIZATION = 0, ///< Reset mode 166 MXC_CAN_MODE_NORMAL, ///< Normal operating mode 167 MXC_CAN_MODE_RESTRICTED, ///< Restricted mode 168 MXC_CAN_MODE_MONITOR, ///< Listen-only mode 169 MXC_CAN_MODE_LOOPBACK, ///< Loopback mode 170 MXC_CAN_MODE_RSV, ///< Reserved for future use 171 MXC_CAN_MODE_LOOPBACK_W_TXD, ///< Loopback mode with transmit pin disconnected 172 } mxc_can_mode_t; 173 174 /** 175 * @brief Struct containing information about the objects associated with a particular CAN driver. 176 */ 177 typedef struct { 178 int32_t tx; ///< Object supports transmission 179 int32_t rx; ///< Object supports receive 180 int32_t rx_rtr_tx_data; ///< Object supports RTR reception and automatic data frame transmission 181 int32_t tx_rtr_rx_data; ///< Object supports RTR transmission and automatic data fram reception 182 int32_t multiple_filters; ///< Number of filters supported by the object 183 int32_t exact_filtering; ///< Object can support exact message ID filters 184 int32_t mask_filtering; ///< Object can support mask message ID filters 185 int32_t range_filtering; ///< Object can support range message ID filters 186 int32_t message_depth; ///< Message depth of transmit and receive buffers 187 int32_t reserved; ///< Reserved for future use 188 } mxc_can_obj_capabilities_t; 189 190 /** 191 * @brief Type used to select which operation to perform on message ID filter. Mask together one choice from each group to make configuration selection 192 */ 193 typedef enum { 194 // Select one from Group 1 { 195 MXC_CAN_FILT_CFG_EXACT_ADD = 0, ///< Add exact filter 196 MXC_CAN_FILT_CFG_EXACT_DEL = 1, ///< Remove exact filter 197 MXC_CAN_FILT_CFG_RSV1 = 2, ///< NOT SUPPORTED ON MAX32690 198 MXC_CAN_FILT_CFG_RSV2 = 3, ///< NOT SUPPORTED ON MAX32690 199 MXC_CAN_FILT_CFG_MASK_ADD = 4, ///< Add maskable filter 200 MXC_CAN_FILT_CFG_MASK_DEL = 5, ///< Remove maskable filter 201 // } end group 1 202 203 // Select one from group 2 { 204 MXC_CAN_FILT_CFG_DUAL_GEN = 0 205 << MXC_CAN_FILT_SEL_SHIFT, ///< Reccomended only for middleware use 206 MXC_CAN_FILT_CFG_DUAL1_STD_ID = 207 1 208 << MXC_CAN_FILT_SEL_SHIFT, ///< Perform operation on dual filter 1, for 11-bit message ID's 209 MXC_CAN_FILT_CFG_DUAL1_EXT_ID = 210 2 211 << MXC_CAN_FILT_SEL_SHIFT, ///< Perform operation on dual filter 1, for 29-bit message ID's 212 MXC_CAN_FILT_CFG_DUAL2_STD_ID = 213 3 214 << MXC_CAN_FILT_SEL_SHIFT, ///< Perform operation on dual filter 2, for 11-bit message ID's 215 MXC_CAN_FILT_CFG_DUAL2_EXT_ID = 216 4 217 << MXC_CAN_FILT_SEL_SHIFT, ///< Perform operation on dual filter 2, for 29-bit message ID's 218 MXC_CAN_FILT_CFG_SINGLE_STD_ID = 219 5 220 << MXC_CAN_FILT_SEL_SHIFT, ///< Perform operation on single filter, for 11-bit message ID's 221 MXC_CAN_FILT_CFG_SINGLE_EXT_ID = 222 6 223 << MXC_CAN_FILT_SEL_SHIFT, ///< Perform operation on single filter, for 29-bit message ID's 224 // } end group 2 225 } mxc_can_filt_cfg_t; 226 227 /** 228 * @brief Struct detailing the current status of the CAN driver. 229 */ 230 typedef struct { 231 uint32_t unit_state; ///< State of the CAN bus 232 uint32_t last_error_code; ///< Last error code recorded 233 uint32_t tx_err_cnt; ///< Number of transmission errors 234 uint32_t rx_err_cnt; ///< Number of receive errors 235 uint32_t can_idx; ///< Index of CAN peripheral status was retrieved for 236 } mxc_can_stat_t; 237 238 /** 239 * @brief Contains information about the message to be sent or the message received. 240 */ 241 typedef struct { 242 uint32_t msg_id; ///< Message ID 243 uint32_t rtr; ///< Remote transmit request frame 244 uint32_t fdf; ///< FD frame 245 uint32_t brs; ///< FD format bit rate switch 246 uint32_t esi; ///< FD format error state indicator 247 uint32_t dlc; ///< Data length code 248 uint32_t rsv; ///< Reserved for future use 249 } mxc_can_msg_info_t; 250 251 /** 252 * @brief Used to set the features available to a CAN object 253 */ 254 typedef enum { 255 MXC_CAN_OBJ_CFG_INACTIVE = 0, ///< Object disabled 256 MXC_CAN_OBJ_CFG_TXRX, ///< Object can transmit and/or receive messages 257 MXC_CAN_OBJ_CFG_RSV, ///< Reserved for future use 258 MXC_CAN_OBJ_CFG_RX_RTR_TX_DATA, ///< NOT SUPPORTED ON MAX32690 259 MXC_CAN_OBJ_CFG_TX_RTR_RX_DATA, ///< NOT SUPPORTED ON MAX32690 260 } mxc_can_obj_cfg_t; 261 262 /** 263 * @brief Selects the control operation for the CAN driver to perform 264 */ 265 typedef enum { 266 MXC_CAN_CTRL_SET_FD_MODE = 267 0, ///< No effect on MAX32690 (FD mode always enabled when CAN active) 268 MXC_CAN_CTRL_ABORT_TX, ///< Abort transmission 269 MXC_CAN_CTRL_RETRANSMISSION, ///< Enable/disable auto retransmission on error 270 MXC_CAN_CTRL_TRANSCEIVER_DLY, ///< Set transceiver delay 271 } mxc_can_ctrl_t; 272 273 /** 274 * @brief State which bus has entered to trigger unit event 275 */ 276 typedef enum { 277 MXC_CAN_UNIT_EVT_INACTIVE = 0, ///< Peripherals entered inactive state (sleep, shutdown) 278 MXC_CAN_UNIT_EVT_ACTIVE, ///< Peripherals entered active state 279 MXC_CAN_UNIT_EVT_WARNING, ///< Peripheral received error warning 280 MXC_CAN_UNIT_EVT_PASSIVE, ///< Peripheral entered passive state 281 MXC_CAN_UNIT_EVT_BUS_OFF, ///< Bus turned off 282 } mxc_can_unit_evt_t; 283 284 /** 285 * @brief Selects which object to notify/handle 286 */ 287 typedef enum { 288 MXC_CAN_OBJ_EVT_TX_COMPLETE = 0, ///< Transmission complete 289 MXC_CAN_OBJ_EVT_RX, ///< Message received 290 MXC_CAN_OBJ_EVT_RX_OVERRUN, ///< RXFIFO overflow 291 } mxc_can_obj_evt_t; 292 293 /** 294 * @brief Struct containing information about CAN message 295 */ 296 typedef struct { 297 mxc_can_msg_info_t 298 *msg_info; ///< Pointer to struct containing information about the format of the message 299 uint8_t * 300 data; ///< Pointer to array of data bytes (either data to transmit or where to store data received) 301 uint8_t 302 data_sz; ///< MessageSend - number of data bytes to transmit, MessageRead - maximum number of data bytes that can be stored in "data" 303 } mxc_can_req_t; 304 305 ///< Callback used when a bus event occurs 306 typedef void (*mxc_can_unit_event_cb_t)(uint32_t can_idx, uint32_t event); 307 308 ///< Callback used when a transmission event occurs 309 typedef void (*mxc_can_object_event_cb_t)(uint32_t can_idx, uint32_t event); 310 311 /** 312 * @brief Get information about the version of the CMSIS API and Maxim CAN SDK 313 * 314 * @return Struct containing version information 315 */ 316 mxc_can_drv_version_t MXC_CAN_GetVersion(void); 317 318 /** 319 * @brief Get information about the capabilities of the Maxim CAN SDK 320 * 321 * @return Struct containing capabilities information 322 */ 323 mxc_can_capabilities_t MXC_CAN_GetCapabilities(void); 324 325 /** 326 * @brief Initializes CAN event callbacks 327 * @note On default this function enables CAN peripheral clock and CAN gpio pins. 328 * if you wish to manage clock and gpio related things in upper level instead of here. 329 * Define MSDK_NO_GPIO_CLK_INIT flag in project.mk file. 330 * By this flag this function will remove clock and gpio related codes from file. 331 * 332 * @param can_idx Index of the CAN peripheral to initialize 333 * @param cfg Specifies how to configure CAN peripheral (see MXC_CAN_ObjectConfigure) 334 * @param unit_cb Pointer to unit event callback function 335 * @param obj_cb Pointer to object event callback function 336 * 337 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 338 */ 339 int MXC_CAN_Init(uint32_t can_idx, mxc_can_obj_cfg_t cfg, mxc_can_unit_event_cb_t unit_cb, 340 mxc_can_object_event_cb_t obj_cb); 341 342 /** 343 * @brief Free CAN resources (does not reset or disable CAN peripherals) 344 * @note On default this function enables CAN peripheral clock. 345 * if you wish to manage clock related things in upper level instead of here. 346 * Define MSDK_NO_GPIO_CLK_INIT flag in project.mk file. 347 * By this flag this function will remove clock related codes from file. 348 * 349 * @param can_idx Index of CAN peripheral to un-initialize (shutdown) 350 * 351 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 352 */ 353 int MXC_CAN_UnInit(uint32_t can_idx); 354 355 /** 356 * @brief Change Power state of the CAN peripherals 357 * @note On default this function enables CAN peripheral clock. 358 * if you wish to manage clock related things in upper level instead of here. 359 * Define MSDK_NO_GPIO_CLK_INIT flag in project.mk file. 360 * By this flag this function will remove clock related codes from file. 361 * 362 * @param can_idx Index of CAN peripheral to alter power settings for 363 * @param pwr Desired power state of the CAN peripherals 364 * 365 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 366 */ 367 int MXC_CAN_PowerControl(uint32_t can_idx, mxc_can_pwr_ctrl_t pwr); 368 369 /** 370 * @brief Enables interrupts in the interrupt and extended interrupt enable registetrs 371 * 372 * @param can_idx Index of the CAN peripheral to enable interrupts for (0 - CAN0, 1 - CAN1) 373 * @param en Mask of interrupts to enable in the interrupt enable register 374 * @param ext_en Mask of interrupts to enable in the extended interrupt enable register 375 * 376 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 377 */ 378 int MXC_CAN_EnableInt(uint32_t can_idx, uint8_t en, uint8_t ext_en); 379 380 /** 381 * @brief Disables interrupts in the interrupt and extended interrupt enable registers 382 * 383 * @param can_idx Index of the CAN peripheral to disable interrupts for (0 - CAN0, 1 - CAN1) 384 * @param dis Mask of interrupts to disable in the interrupt enable register 385 * @param ext_dis Mask of interrupts to disable in the extended interrupt enable register 386 * 387 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 388 */ 389 int MXC_CAN_DisableInt(uint32_t can_idx, uint8_t dis, uint8_t ext_dis); 390 391 /** 392 * @brief Reads interrupt status flags 393 * 394 * @param can_idx Retrieve interrupt flags for CAN peripheral specified by this parameter (0 - CAN0, 1 - CAN1) 395 * @param flags Interrupt status flags in the INTFL register 396 * @param ext_flags Interrupt status flags in the EINTFL register 397 * 398 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 399 */ 400 int MXC_CAN_GetFlags(uint32_t can_idx, uint8_t *flags, uint8_t *ext_flags); 401 402 /** 403 * @brief Clears interrupts flags 404 * 405 * @param can_idx Clear interrupt flags for CAN peripheral specified by this parameter (0 - CAN0, 1 - CAN1) 406 * @param flags Mask of interrupt flags to clear in INTFL register 407 * @param ext_flags Mask of interrupt flags to clear in EINTFL register 408 * 409 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 410 */ 411 int MXC_CAN_ClearFlags(uint32_t can_idx, uint8_t flags, uint8_t ext_flags); 412 413 /** 414 * @brief Returns the bit rate of the CAN clock 415 * 416 * @param can_idx Index of CAN peripheral to get clock rate of 417 * 418 * @return Frequency of CAN clock 419 */ 420 int MXC_CAN_GetClock(uint32_t can_idx); 421 422 /** 423 * @brief Returns the bit rate of the CAN clock 424 * 425 * @param can_idx Selects CAN peripheral (0 - CAN0, 1 - CAN1) to retrieve bit rate for 426 * @param sel Select which bitrate to return 427 * 428 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. If successful, returns value of bit rate. 429 * 430 * @warning MAX32690 does not support CAN FD, passing MXC_CAN_BITRATE_SEL_FD_DATA will return an error. 431 */ 432 int MXC_CAN_GetBitRate(uint32_t can_idx, mxc_can_bitrate_sel_t sel); 433 434 /** 435 * @brief Sets CAN clock frequency and sets time quanta values 436 * 437 * @param can_idx Index of CAN peripheral to set bitrate for 438 * @param sel Selects which bitrate to set (nominal/FD arbitration phase or FD data phase) 439 * @param bitrate Desired bitrate 440 * @param bit_segments Mask of number of time quanta in each bit segment see MXC_CAN_BIT_SEGMENTS(seg1_tq, seg2_tq, sjw_tq) defined above 441 * 442 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 443 * 444 * @warning MAX32690 does not support CAN FD, passing MXC_CAN_BITRATE_SEL_FD_DATA will return an error. 445 */ 446 int MXC_CAN_SetBitRate(uint32_t can_idx, mxc_can_bitrate_sel_t sel, uint32_t bitrate, 447 uint32_t bit_segments); 448 449 /** 450 * @brief Sets the operating mode of the CAN peripherals 451 * 452 * @param can_idx Index of CAN peripheral 453 * @param mode Selects the mode of the CAN peripherals 454 * 455 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 456 */ 457 int MXC_CAN_SetMode(uint32_t can_idx, mxc_can_mode_t mode); 458 459 /** 460 * @brief Get the capabilities of the CAN object specified by can_idx 461 * 462 * @param can_idx Index of the CAN peripheral to get capabilities of 463 * 464 * @return Object capabilities information 465 */ 466 mxc_can_obj_capabilities_t MXC_CAN_ObjectGetCapabilities(uint32_t can_idx); 467 468 /** 469 * @brief Setup message ID filter on CAN peripheral 470 * 471 * @param can_idx Pointer to CAN instance 472 * @param cfg Specifies how the filter should be configured 473 * @param id Exact ID for exact filter type. Base ID for maskable filter type. 474 * @param arg Mask for maskable filter type. Bits set to 0 are "don't care" bits and will always be accepted regardless of value, 1's are compared with ID. (Inverse of AMR register function.) 475 * 476 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 477 */ 478 int MXC_CAN_ObjectSetFilter(uint32_t can_idx, mxc_can_filt_cfg_t cfg, uint32_t id, uint32_t arg); 479 480 /** 481 * @brief Configure CAN object 482 * @note On default this function enables CAN gpio pins. 483 * if you wish to manage gpio related things in upper level instead of here. 484 * Define MSDK_NO_GPIO_CLK_INIT flag in project.mk file. 485 * By this flag this function will remove gpio related codes from file. 486 * 487 * @param can_idx Pointer to CAN instance 488 * @param cfg Specifies how the filter should be configured 489 * 490 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 491 */ 492 int MXC_CAN_ObjectConfigure(uint32_t can_idx, mxc_can_obj_cfg_t cfg); 493 494 /** 495 * @brief Write data to be transmitted to TX FIFO (does not need to be called before message send) 496 * 497 * @param can_idx Index of CAN peripheral to read RX data for 498 * @param info Pointer to struct containing information about the type of CAN message to send 499 * @param data Buffer of data bytes to be transmitted 500 * @param size Number of data bytes in "data" 501 * 502 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 503 * 504 * @warning MAX32690 does not support CAN FD, setting info->fdf will return an error. 505 */ 506 int MXC_CAN_WriteTXFIFO(uint32_t can_idx, mxc_can_msg_info_t *info, const uint8_t *data, 507 uint8_t size); 508 509 /** 510 * @brief Reads data from RX FIFO if data available 511 * 512 * @param can_idx Index of CAN peripheral to read RX data for 513 * @param info Pointer to struct to store message information in 514 * @param data Buffer to store received data bytes 515 * @param size Maximum number of data bytes that can be stored in "data" 516 * 517 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 518 * 519 * @warning MAX32690 does not support CAN FD, setting info->fdf will return an error. 520 */ 521 int MXC_CAN_ReadRXFIFO(uint32_t can_idx, mxc_can_msg_info_t *info, uint8_t *data, uint8_t size); 522 523 /** 524 * @brief Send message (this is a blocking function). 525 * 526 * @param can_idx Index of the CAN peripheral to send the message from 527 * @param req Contains information about the format and data of message to send 528 * 529 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 530 * 531 * @warning MAX32690 does not support CAN FD, setting req->msg_info->fdf will return an error. 532 */ 533 int MXC_CAN_MessageSend(uint32_t can_idx, mxc_can_req_t *req); 534 535 /** 536 * @brief Send message (non-blocking). 537 * 538 * 539 * @param can_idx Index of the CAN peripheral to send the message from 540 * @param req Contains information about the format and data of message to send 541 * 542 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 543 * 544 * @warning MAX32690 does not support CAN FD, setting req->msg_info->fdf will return an error. 545 * @warning The structure pointed to by 'req' must remain unchanged and in scope until the 546 * TX complete event has been signaled. 547 */ 548 int MXC_CAN_MessageSendAsync(uint32_t can_idx, mxc_can_req_t *req); 549 550 /** 551 * @brief Send message (non-blocking DMA). 552 * 553 * @param can_idx Index of the CAN peripheral to send the message from 554 * @param req Contains information about the format and data of message to send 555 * 556 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 557 * 558 * @warning MAX32690 does not support CAN FD, setting req->msg_info->fdf will return an error. 559 * @warning The structure pointed to by 'req' must remain unchanged and in scope until the 560 * TX complete event has been signaled. 561 */ 562 int MXC_CAN_MessageSendDMA(uint32_t can_idx, mxc_can_req_t *req); 563 564 /** 565 * @brief Read received message if any. (this is a blocking function) 566 * 567 * @param can_idx Index of the CAN peripheral to read the message for 568 * @param req Pointer to struct that stores CAN message information 569 * 570 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 571 * 572 * @warning MAX32690 does not support receiving CAN FD messages. 573 */ 574 int MXC_CAN_MessageRead(uint32_t can_idx, mxc_can_req_t *req); 575 576 /** 577 * @brief Set up CAN device for asynchronus data receive (non-blocking) 578 * 579 * @param can_idx Index of the CAN peripheral to set up asynchronus reads for 580 * @param req Pointer to struct that stores CAN message information 581 * 582 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 583 * 584 * @warning MAX32690 does not support receiving CAN FD messages. 585 * @warning The structure pointed to by 'req' must remain unchanged and in scope until the 586 * RX complete event has been signaled. 587 */ 588 int MXC_CAN_MessageReadAsync(uint32_t can_idx, mxc_can_req_t *req); 589 590 /** 591 * @brief Set up CAN device for DMA data receive 592 * 593 * @param can_idx Index of the CAN peripheral to receive data 594 * @param req Pointer to struct that stores CAN message information, initialize "msg_info" to expected configuration of the message to be received (Needed to ensure proper DMA length is set, if these are not known use MXC_CAN_MessageReadAsync instead.) 595 * @param dma_cb Pointer to DMA callback function. 596 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 597 * 598 * @warning MAX32690 does not support receiving CAN FD messages. 599 * @warning The structure pointed to by 'req' must remain unchanged and in scope until the 600 * RX complete event has been signaled. 601 */ 602 int MXC_CAN_MessageReadDMA(uint32_t can_idx, mxc_can_req_t *req, void (*dma_cb)(int, int)); 603 604 /** 605 * @brief General interrupt handler for MessageSendAsync and MessageReadAsync 606 * 607 * @param can_idx Index of the CAN peripheral to handle interrupts for 608 * 609 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 610 */ 611 int MXC_CAN_Handler(uint32_t can_idx); 612 613 /** 614 * @brief Perform control operation on CAN peripheral(s) 615 * 616 * @param can_idx Index of CAN peripheral to perform control function on 617 * @param ctrl Operation to perform on the CAN peripherals 618 * @param ctrl_arg Depends on ctrl. RETRANSMISSION: 1-Enable, 0-Disable; TRANSCEIVER_DELAY: number of time quanta to delay; any other value of control this parameter is ignored 619 * 620 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 621 * 622 * @warning MAX32690 does not support CAN FD, passing MXC_CAN_CTRL_SET_FD_MODE will return an error. 623 */ 624 int MXC_CAN_Control(uint32_t can_idx, mxc_can_ctrl_t ctrl, uint32_t ctrl_arg); 625 626 /** 627 * @brief Configure wakeup timer settings (must be called before entering sleep mode) 628 * 629 * @param can_idx Index of CAN peripheral to configure wakeup timer for 630 * @param prescaler Value to scale the CAN clock by to generate the wakup clock signal 631 * @param wup_filter_tm Value to set Wake-up filter time register to 632 * @param wup_expire_tm Value to set wake-up expire time register to 633 * 634 * @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes. 635 */ 636 int MXC_CAN_SetWakeupTimer(uint32_t can_idx, uint8_t prescaler, uint16_t wup_filter_tm, 637 uint32_t wup_expire_tm); 638 639 /* 640 * @brief Get status of the bus unit 641 * 642 * @param can_idx Index of CAN peripheralto get status of 643 * 644 * @return Information about the bus and error status 645 */ 646 mxc_can_stat_t MXC_CAN_GetStatus(uint32_t can_idx); 647 648 /** 649 * @brief Notify unit event handler of event that transpired 650 * 651 * @param can_idx Index of CAN peripheral which the event transpired on 652 * 653 * @param event Event that occured 654 */ 655 void MXC_CAN_SignalUnitEvent(uint32_t can_idx, mxc_can_unit_evt_t event); 656 657 /** 658 * @brief Notify object event handler of event that transpired 659 * 660 * @param can_idx Index of the CAN peripheral which had the event 661 * @param event Event that occured 662 */ 663 void MXC_CAN_SignalObjectEvent(uint32_t can_idx, mxc_can_obj_evt_t event); 664 665 /**@} end of group can */ 666 667 #ifdef __cplusplus 668 } 669 #endif 670 671 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32690_CAN_H_ 672