1 /******************************************************************************* 2 * Copyright 2019-2021 Microchip FPGA Embedded Systems Solutions. 3 * 4 * SPDX-License-Identifier: MIT 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to 8 * deal in the Software without restriction, including without limitation the 9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 * sell copies of the Software, and to permit persons to whom the Software is 11 * furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in 14 * all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22 * IN THE SOFTWARE. 23 * 24 * PolarFire SoC Microprocessor Subsystem(MSS) CAN bare metal software driver 25 * public API. 26 * 27 */ 28 /*=========================================================================*//** 29 @mainpage PolarFire SoC MSS CAN Bare Metal Driver. 30 31 ============================================================================== 32 Introduction 33 ============================================================================== 34 The PolarFire SoC Microprocessor Subsystem (MSS) includes two CAN controller. 35 The CAN controller is configurable to provide support for up to 32 transmit 36 and 32 receive mailboxes. 37 38 This PolarFire SoC MSS CAN driver provides a set of functions for accessing 39 and controlling the MSS CAN as part of a bare metal system where no operating 40 system is available. The driver can be adapted for use as part of an 41 operating system, but the implementation of the adaptation layer between the 42 driver and the operating system's driver model is outside the scope of the 43 driver. 44 45 -------------------------------- 46 Features 47 -------------------------------- 48 The MSS CAN driver provides support for the following features: 49 - Basic CAN APIs if application needs support for Basic CAN operation. 50 (Configure as FIFO by linking several mailboxes together, one message 51 filter for entire FIFO) 52 - Full CAN APIs (each mail box has its own message filter) 53 - Support for 11 bit and 29 bit message identifiers 54 - Support for Data frame and Remote frames 55 - Error detection mechanism 56 57 ============================================================================== 58 Hardware Flow Dependencies 59 ============================================================================== 60 The configuration of all features of the PolarFire MSS CAN is covered by 61 this driver, with the exception of the PolarFire SoC IOMUX configuration. 62 The PolarFire SoC allows multiple non-concurrent uses of few external pins 63 through IOMUX configuration. This feature allows optimization of external pin 64 usage by assigning external pins for use by either the microprocessor 65 subsystem or the FPGA fabric. The MSS CAN serial signals are routed through 66 IOMUXs to the PolarFire SoC device external pins. The MSS CAN serial 67 signals can also be routed through IOMUXs to the PolarFire SoC FPGA fabric. 68 For more information on IOMUX, refer to the I/O Configuration section of the 69 PolarFire SoC Microprocessor Subsystem (MSS) User's Guide. 70 71 The IOMUXs are configured using the PolarFire SoC MSS configurator tool. You 72 must ensure that the MSS CAN peripherals are enabled and configured in the 73 PolarFire SoC MSS configurator if you wish to use them. For more information 74 on IOMUXs, refer to the IOMUX section of the PolarFire SoC microprocessor 75 Subsystem (MSS) User's Guide. 76 77 On PolarFire SoC an AXI switch forms a bus matrix interconnect among multiple 78 masters and multiple slaves. Five RISC-V CPUs connect to the Master ports M10 79 to M14 of the AXI switch. By default, all the APB peripherals are accessible 80 on AXI-Slave 5 of the AXI switch via the AXI to AHB and AHB to APB bridges 81 (referred as main APB bus). However, to support logical separation in the 82 Asymmetric Multi-Processing (AMP) mode of operation, the APB peripherals can 83 alternatively be accessed on the AXI-Slave 6 via the AXI to AHB and AHB to APB 84 bridges (referred as the AMP APB bus). 85 Application must make sure that the desired CAN instance is appropriately 86 configured on one of the APB bus described above by configuring the PolarFire 87 SoC system registers (SYSREG) as per the application need and that the 88 appropriate data structures are provided to this driver as parameter to the 89 functions provided by this driver. 90 91 The base address and the register addresses are defined in this driver as 92 constants. The interrupt number assignment for the MSS CAN peripherals is 93 defined as constants in the MPFS HAL. You must ensure that the latest MPFS HAL 94 is included in the project settings of the SoftConsole toolchain and that it 95 is generated into your project. 96 97 ============================================================================== 98 Theory of Operation 99 ============================================================================== 100 The MSS CAN driver uses one instance of the mss_can_instance_t structure per 101 port. This instance is used to identify the target port and a pointer to this 102 instance is passed as the first argument to all CAN driver functions. 103 104 The PolarFire SoC MSS CAN driver operations can be divided in following 105 sub-sections: 106 - CAN Controller Configuration 107 - Operation Status 108 - Interrupt Support 109 - Helper Functions 110 - Basic CAN Message Handling 111 - Full CAN Message Handling 112 113 -------------------------------- 114 Configuration 115 -------------------------------- 116 The MSS CAN driver must first be initialized and the mode of operation must 117 be selected before performing data transfers on CAN Bus. The MSS_CAN_init() 118 function is used to initialize the CAN controller and driver. Set CAN 119 controller operation mode as normal operation using MSS_CAN_set_mode() 120 function. The operating mode of operation is selected using 121 MSS_CAN_set_mode() function. The actual data transfer can be started using 122 start the CAN controller by using MSS_CAN_start() function, with this actual 123 data transmission or reception shall start. MSS_CAN_stop() function is used 124 to stops the CAN controller. Once initialized, during normal mode of 125 operation, the MSS CAN driver configuration can be changed using 126 MSS_CAN_set_config_reg() function is used to change the CAN controllers 127 configuration during normal operation. 128 129 -------------------------------- 130 Operation Status 131 -------------------------------- 132 MSS_CAN_get_error_status() function returns the current CAN error state 133 (error active, error passive, and bus off). The MSS_CAN_get_rx_error_count() 134 and MSS_CAN_get_tx_error_count() functions return the actual 135 receive and transmit error counter values while MSS_CAN_get_rx_gte96() 136 function and MSS_CAN_get_tx_gte96() function show if the error counters are 137 greater or equal to 96, which indicates a heavily disturbed bus. 138 139 -------------------------------- 140 Interrupt Support 141 -------------------------------- 142 The interrupt service routines are not part of the CAN driver. But access 143 functions for the interrupt registers are provided. The individual 144 interrupt enable bits can be set using MSS_CAN_set_int_ebl() function and 145 individual interrupt enable bits can be cleared using MSS_CAN_clear_int_ebl 146 while MSS_CAN_get_int_ebl() function returns their actual state. 147 MSS_CAN_get_global_int_ebl() function indicates if interrupt 148 generation is enabled at all. MSS_CAN_get_int_status() function shows the 149 current state of the different interrupt status bits. Each interrupt status 150 bit can be individually cleared using MSS_CAN_clear_int_status() function. 151 152 The interrupt service routines are not part of the MSS CAN driver and the 153 driver ships with the MSS_CAN_ENABLE_INTERRUPTS macro disabled which stops 154 the MSS CAN interrupt being enabled at the PLIC, however a stub ISR is 155 present in the mss_can.c file to show the format of the function and catch 156 any unexpected interrupts to aid in debugging. 157 158 -------------------------------- 159 Helper Functions 160 -------------------------------- 161 The MSS CAN peripheral expects all ID bits to be left aligned. This makes 162 setting the ID cumbersome. Using MSS_CAN_set_id(), a given right-aligned 163 ID field is modified according to the ID size which is indicated by the 164 IDE bit. MSS_CAN_get_id() provides the reverse operation: It returns the 165 ID right aligned. MSS_CAN_get_msg_filter_mask() packs the ID, IDE, and RTR 166 bits together as they are used in the mask registers. MSS_CAN_get_mask_n() 167 returns the message filter settings of the selected receive mailbox. 168 MSS_CAN_set_mask_n() configures the message filter settings for the 169 selected receive mailbox. 170 171 -------------------------------- 172 Basic CAN Message Handling 173 -------------------------------- 174 A Basic CAN type controller contains one or more message filter and one 175 common message buffer or FIFO. The CAN driver contains some functions to 176 emulate Basic CAN operation by linking several buffers together to form a 177 buffer array that shares one message filter. Since this buffer array is not 178 a real FIFO, message inversion might happen (eg, a newer message might be 179 pulled from the receive buffer prior to an older message). 180 Before using the Basic CAN API, the CAN controller has to be configured 181 first with a MSS_CAN_config_buffer() function call. This sets up the 182 message array and configures the message filter. MSS_CAN_send_message() 183 function and MSS_CAN_get_message() function are used to send and receive 184 a message from transmit or receive buffers. MSS_CAN_send_message_ready() 185 function indicates if a new message can be sent. MSS_CAN_get_message_av() 186 function shows if a new message is available. 187 188 -------------------------------- 189 Full CAN Message Handling 190 -------------------------------- 191 In Full CAN operation, each message mailbox has its own message filter. 192 This reduces the number of receive interrupts as the host CPU only gets an 193 interrupt when a message of interest has arrived. Further, software based 194 message filtering overhead is reduced and there is less message to 195 be checked. Before a buffer can be used for Full CAN operation, it needs to 196 be configured using MSS_CAN_config_buffer_n() function. An error is 197 generated if this buffer is already reserved for Basic CAN operation. 198 The MSS_CAN_get_rx_buffer_status() and MSS_CAN_get_tx_buffer_status() 199 functions indicate the current state of the receive and transmit buffers 200 respectively. With MSS_CAN_send_message_n() function a message can be sent 201 using buffer. A pending message transfer can be aborted with 202 MSS_CAN_send_message_abort_n() function and a message can be read with 203 MSS_CAN_get_message_n() function. If a buffer is set for automatic RTR reply, 204 MSS_CAN_set_rtr_message_n() function sets the CAN message that is returned 205 upon reception of the RTR message. MSS_CAN_get_rtr_message_abort_n() 206 function aborts a RTR message transmit request. 207 208 NOTE: 209 1. User has to set the RTR message filter to match with 210 MSS_CAN_rtr_message_abort_n() function a pending RTR auto-reply can be 211 aborted. 212 2. An error is generated if buffer is already reserved for Basic CAN 213 operation and is trying to use the same buffer for Full CAN functionality. 214 3. Special case of Full CAN where several mailboxes are linked together to 215 create FIFOs that share an identical message filter configuration, can 216 be built upon the available Full CAN functions. 217 218 *//*=========================================================================*/ 219 220 #ifndef MSS_CAN_H_ 221 #define MSS_CAN_H_ 222 223 #ifdef __cplusplus 224 extern "C" { 225 #endif 226 227 /* The following macro MSS_CAN_ENABLE_INTERRUPTS must be defined to allow the 228 * enabling of the MSS CAN peripheral interrupts at the PLIC level. 229 * This version of the MSS CAN driver does not provide any support for MSS CAN 230 * interrupts and so this MACRO should be disabled unless there is a user 231 * supplied ISR. 232 */ 233 234 #if 0 235 #define MSS_CAN_ENABLE_INTERRUPTS 236 #endif 237 238 /** 239 * Define CAN target device 240 * 241 * CANMOD3: Device with 16 Rx and 8 Tx mailboxes 242 * CANMOD3X: Device with 32 Rx and 32 Tx mailboxes 243 */ 244 245 #define CANMOD3X 246 247 #ifdef CANMOD3 248 #define CAN_RX_MAILBOX 16u 249 #define CAN_TX_MAILBOX 8u 250 #else 251 #define CAN_RX_MAILBOX 32u 252 #define CAN_TX_MAILBOX 32u 253 #endif 254 255 256 /* Configuration and Speed definitions */ 257 #define CAN_PRESET (mss_can_config_reg.L)0 258 #define CAN_SAMPLE_BOTH_EDGES 0x00000001u 259 #define CAN_THREE_SAMPLES 0x00000002u 260 #define CAN_SET_SJW(_sjw) (_sjw<<2u) 261 #define CAN_AUTO_RESTART 0x00000010u 262 #define CAN_SET_TSEG2(_tseg2) (_tseg2<<5u) 263 #define CAN_SET_TSEG1(_tseg1) (_tseg1<<8u) 264 #define CAN_SET_BITRATE(_bitrate) (_bitrate<<16u) 265 #define CAN_ARB_ROUNDROBIN 0x00000000u 266 #define CAN_ARB_FIXED_PRIO 0x00001000u 267 #define CAN_BIG_ENDIAN 0x00000000u 268 #define CAN_LITTLE_ENDIAN 0x00002000u 269 270 /* Manual setting with specified fields */ 271 #define CAN_SPEED_MANUAL 0u 272 273 /*-------------------------------------------------------------------------*//** 274 The following constants are used in the PolarFire SoC MSS CAN driver for 275 bitrate definitions: 276 277 | Constants | Description | 278 |--------------------|-----------------------------------------------------| 279 | CAN_SPEED_8M_5K | Indicates CAN controller shall be configured with | 280 | | 5Kbps baud rate if the input clock is 8MHz. | 281 | CAN_SPEED_16M_5K | Indicates CAN controller shall be configured with | 282 | | 5Kbps baud rate if the input clock is 16MHz. | 283 | CAN_SPEED_32M_5K | Indicates CAN controller shall be configured with | 284 | | 5Kbps baud rate if the input clock is 32MHz. | 285 | CAN_SPEED_8M_10K | Indicates CAN controller shall be configured with | 286 | | 10Kbps baud rate if the input clock is 8MHz. | 287 | CAN_SPEED_16M_10K | Indicates CAN controller shall be configured with | 288 | | 10Kbps baud rate if the input clock is 16MHz. | 289 | CAN_SPEED_32M_10K | Indicates CAN controller shall be configured with | 290 | | 10Kbps baud rate if the input clock is 32MHz. | 291 | CAN_SPEED_8M_20K | Indicates CAN controller shall be configured with | 292 | | 20Kbps baud rate if the input clock is 8MHz. | 293 | CAN_SPEED_16M_20K | Indicates CAN controller shall be configured with | 294 | | 20Kbps baud rate if the input clock is 16MHz. | 295 | CAN_SPEED_32M_20K | Indicates CAN controller shall be configured with | 296 | | 20Kbps baud rate if the input clock is 32MHz. | 297 | CAN_SPEED_8M_50K | Indicates CAN controller shall be configured with | 298 | | 50Kbps baud rate if the input clock is 8MHz. | 299 | CAN_SPEED_16M_50K | Indicates CAN controller shall be configured with | 300 | | 50Kbps baud rate if the input clock is 16MHz. | 301 | CAN_SPEED_32M_50K | Indicates CAN controller shall be configured with | 302 | | 50Kbps baud rate if the input clock is 32MHz. | 303 | CAN_SPEED_8M_100K | Indicates CAN controller shall be configured with | 304 | | 100Kbps baud rate if the input clock is 8MHz. | 305 | CAN_SPEED_16M_100K | Indicates CAN controller shall be configured with | 306 | | 100Kbps baud rate if the input clock is 16MHz. | 307 | CAN_SPEED_32M_100K | Indicates CAN controller shall be configured with | 308 | | 100Kbps baud rate if the input clock is 32MHz. | 309 | CAN_SPEED_8M_125K | Indicates CAN controller shall be configured with | 310 | | 125Kbps baud rate if the input clock is 8MHz. | 311 | CAN_SPEED_16M_125K | Indicates CAN controller shall be configured with | 312 | | 125Kbps baud rate if the input clock is 16MHz. | 313 | CAN_SPEED_32M_125K | Indicates CAN controller shall be configured with | 314 | | 125Kbps baud rate if the input clock is 32MHz. | 315 | AN_SPEED_8M_250K | Indicates CAN controller shall be configured with | 316 | | 250Kbps baud rate if the input clock is 8MHz. | 317 | CAN_SPEED_16M_250K | Indicates CAN controller shall be configured with | 318 | | 250Kbps baud rate if the input clock is 16MHz. | 319 | CAN_SPEED_32M_250K | Indicates CAN controller shall be configured with | 320 | | 250Kbps baud rate if the input clock is 32MHz. | 321 | CAN_SPEED_8M_500K | Indicates CAN controller shall be configured with | 322 | | 500Kbps baud rate if the input clock is 8MHz. | 323 | CAN_SPEED_16M_500K | Indicates CAN controller shall be configured with | 324 | | 500Kbps baud rate if the input clock is 16MHz. | 325 | CAN_SPEED_32M_500K | Indicates CAN controller shall be configured with | 326 | | 500Kbps baud rate if the input clock is 32MHz. | 327 | CAN_SPEED_8M_1M | Indicates CAN controller shall be configured with | 328 | | 1MBPS baud rate if the input clock is 8MHz. | 329 | CAN_SPEED_16M_1M | Indicates CAN controller shall be configured with | 330 | | 1MBPS baud rate if the input clock is 16MHz. | 331 | CAN_SPEED_32M_1M | Indicates CAN controller shall be configured with | 332 | | 1MBPS baud rate if the input clock is 32MHz. | 333 334 */ 335 /* 5000m 81% Sample bit three times */ 336 #define CAN_SPEED_8M_5K CAN_SET_BITRATE(99)|CAN_SET_TSEG1(11)|CAN_SET_TSEG2(2)|CAN_THREE_SAMPLES 337 #define CAN_SPEED_16M_5K CAN_SET_BITRATE(199)|CAN_SET_TSEG1(11)|CAN_SET_TSEG2(2)|CAN_THREE_SAMPLES 338 #define CAN_SPEED_32M_5K CAN_SET_BITRATE(399)|CAN_SET_TSEG1(11)|CAN_SET_TSEG2(2)|CAN_THREE_SAMPLES 339 340 /* 5000m 81% Sample bit three times */ 341 #define CAN_SPEED_8M_10K CAN_SET_BITRATE(49)|CAN_SET_TSEG1(11)|CAN_SET_TSEG2(2)|CAN_THREE_SAMPLES 342 #define CAN_SPEED_16M_10K CAN_SET_BITRATE(99)|CAN_SET_TSEG1(11)|CAN_SET_TSEG2(2)|CAN_THREE_SAMPLES 343 #define CAN_SPEED_32M_10K CAN_SET_BITRATE(199)|CAN_SET_TSEG1(11)|CAN_SET_TSEG2(2)|CAN_THREE_SAMPLES 344 345 /* 2500m 81% Sample bit three times */ 346 #define CAN_SPEED_8M_20K CAN_SET_BITRATE(24)|CAN_SET_TSEG1(11)|CAN_SET_TSEG2(2)|CAN_THREE_SAMPLES 347 #define CAN_SPEED_16M_20K CAN_SET_BITRATE(49)|CAN_SET_TSEG1(11)|CAN_SET_TSEG2(2)|CAN_THREE_SAMPLES 348 #define CAN_SPEED_32M_20K CAN_SET_BITRATE(99)|CAN_SET_TSEG1(11)|CAN_SET_TSEG2(2)|CAN_THREE_SAMPLES 349 350 /* 1000m 87% */ 351 #define CAN_SPEED_8M_50K CAN_SET_BITRATE(9)|CAN_SET_TSEG1(12)|CAN_SET_TSEG2(1) 352 #define CAN_SPEED_16M_50K CAN_SET_BITRATE(19)|CAN_SET_TSEG1(12)|CAN_SET_TSEG2(1) 353 #define CAN_SPEED_32M_50K CAN_SET_BITRATE(39)|CAN_SET_TSEG1(12)|CAN_SET_TSEG2(1) 354 355 /* 600m 87% */ 356 #define CAN_SPEED_8M_100K CAN_SET_BITRATE(4)|CAN_SET_TSEG1(12)|CAN_SET_TSEG2(1) 357 #define CAN_SPEED_16M_100K CAN_SET_BITRATE(9)|CAN_SET_TSEG1(12)|CAN_SET_TSEG2(1) 358 #define CAN_SPEED_32M_100K CAN_SET_BITRATE(19)|CAN_SET_TSEG1(12)|CAN_SET_TSEG2(1) 359 360 /* 500m 87% */ 361 #define CAN_SPEED_8M_125K CAN_SET_BITRATE(3)|CAN_SET_TSEG1(12)|CAN_SET_TSEG2(1) 362 #define CAN_SPEED_16M_125K CAN_SET_BITRATE(7)|CAN_SET_TSEG1(12)|CAN_SET_TSEG2(1) 363 #define CAN_SPEED_32M_125K CAN_SET_BITRATE(15)|CAN_SET_TSEG1(12)|CAN_SET_TSEG2(1) 364 365 /* 250m 87% */ 366 #define CAN_SPEED_8M_250K CAN_SET_BITRATE(1)|CAN_SET_TSEG1(12)|CAN_SET_TSEG2(1) 367 #define CAN_SPEED_16M_250K CAN_SET_BITRATE(3)|CAN_SET_TSEG1(12)|CAN_SET_TSEG2(1) 368 #define CAN_SPEED_32M_250K CAN_SET_BITRATE(7)|CAN_SET_TSEG1(12)|CAN_SET_TSEG2(1) 369 370 /* 100m 75% @ 8M, 87% @ 16M */ 371 #define CAN_SPEED_8M_500K CAN_SET_BITRATE(1)|CAN_SET_TSEG1(4)|CAN_SET_TSEG2(1) 372 #define CAN_SPEED_16M_500K CAN_SET_BITRATE(1)|CAN_SET_TSEG1(12)|CAN_SET_TSEG2(1) 373 #define CAN_SPEED_32M_500K CAN_SET_BITRATE(3)|CAN_SET_TSEG1(12)|CAN_SET_TSEG2(1) 374 375 /* 25m 75% */ 376 #define CAN_SPEED_8M_1M CAN_SET_BITRATE(0)|CAN_SET_TSEG1(4)|CAN_SET_TSEG2(1) 377 #define CAN_SPEED_16M_1M CAN_SET_BITRATE(1)|CAN_SET_TSEG1(4)|CAN_SET_TSEG2(1) 378 #define CAN_SPEED_32M_1M CAN_SET_BITRATE(1)|CAN_SET_TSEG1(12)|CAN_SET_TSEG2(1) 379 380 /*-------------------------------------------------------------------------*//** 381 The following constants are used for error codes: 382 383 | Constants | Description | 384 |-----------------------|---------------------------------------------| 385 | CAN_OK | Indicates there is no error | 386 | CAN_ERR | Indicates error condition | 387 | CAN_TSEG1_TOO_SMALL | Value provided to configure TSEG1 is too | 388 | | small | 389 | CAN_TSEG2_TOO_SMALL | Value provided to configure TSEG2 is too | 390 | | small | 391 | CAN_SJW_TOO_BIG | Value provided to configure synchronous jump| 392 | | width (SJW) is too big. | 393 | CAN_BASIC_CAN_MAILBOX | Indicates that mailbox is configured for | 394 | | Basic CAN operation | 395 | CAN_NO_RTR_MAILBOX | Indicates that there is no mailbox for | 396 | | remote transmit request (RTR) frame | 397 | CAN_INVALID_MAILBOX | Indicates invalid mailbox number | 398 399 */ 400 #define CAN_OK 0u 401 #define CAN_ERR 1u 402 #define CAN_TSEG1_TOO_SMALL 2u 403 #define CAN_TSEG2_TOO_SMALL 3u 404 #define CAN_SJW_TOO_BIG 4u 405 #define CAN_BASIC_CAN_MAILBOX 5u 406 #define CAN_NO_RTR_MAILBOX 6u 407 #define CAN_INVALID_MAILBOX 7u 408 409 /* Flag bits */ 410 #define CAN_NO_MSG 0x00u 411 #define CAN_VALID_MSG 0x01u 412 413 /* 414 * A couple of definitions just to make the code more readable so we know 415 * what a 1 and 0 mean. 416 #define CAN_RTR 1<<21 417 #define CAN_EXT_IDE 1<<20 418 419 /*-------------------------------------------------------------------------*//** 420 The following constants are used in the MSS CAN driver for Interrupt Bit 421 Definitions 422 423 | Constants | Description | 424 |--------------------------|------------------------------------------------| 425 | CAN_INT_GLOBAL | Indicates to enable global interrupts | 426 | CAN_INT_ARB_LOSS | Indicates arbitration loss interrupt | 427 | CAN_INT_OVR_LOAD | Indicates overload message detected interrupt | 428 | CAN_INT_BIT_ERR | Indicates bit error interrupt | 429 | CAN_INT_STUFF_ERR | Indicates bit stuffing error interrupt | 430 | CAN_INT_ACK_ERR | Indicates acknowledge error interrupt | 431 | CAN_INT_FORM_ERR | Indicates format error interrupt | 432 | CAN_INT_CRC_ERR | Indicates CRC error interrupt | 433 | CAN_INT_BUS_OFF | Indicates bus off interrupt | 434 | CAN_INT_RX_MSG_LOST | Indicates received message lost interrupt | 435 | CAN_INT_TX_MSG | Indicates message transmit interrupt | 436 | CAN_INT_RX_MSG | Indicates receive message available interrupt | 437 | CAN_INT_RTR_MSG | Indicates RTR auto-reply message sent interrupt| 438 | CAN_INT_STUCK_AT_0 | Indicates stuck at dominant error interrupt | 439 | CAN_INT_SST_FAILURE | Indicates single shot transmission failure | 440 | | interrupt | 441 442 */ 443 #define CAN_INT_GLOBAL 1<<0 /* Global interrupt */ 444 #define CAN_INT_ARB_LOSS 1<<2 /* Arbitration loss interrupt */ 445 #define CAN_INT_OVR_LOAD 1<<3 /*Overload interrupt */ 446 #define CAN_INT_BIT_ERR 1<<4 /* Bit error interrupt */ 447 #define CAN_INT_STUFF_ERR 1<<5 /* Bit stuffing error interrupt */ 448 #define CAN_INT_ACK_ERR 1<<6 /* Acknowledgement error interrupt */ 449 #define CAN_INT_FORM_ERR 1<<7 /* Format error interrupt */ 450 #define CAN_INT_CRC_ERR 1<<8 /* CRC error interrupt */ 451 #define CAN_INT_BUS_OFF 1<<9 /* Bus-off interrupt */ 452 #define CAN_INT_RX_MSG_LOST 1<<10 /* Rx message lost interrupt */ 453 #define CAN_INT_TX_MSG 1<<11 /* Tx message interupt */ 454 #define CAN_INT_RX_MSG 1<<12 /* Rx message interrupt */ 455 #define CAN_INT_RTR_MSG 1<<13 /* RTR message interrupt */ 456 #define CAN_INT_STUCK_AT_0 1<<14 /* Stuck-at-0 error interrupt */ 457 #define CAN_INT_SST_FAILURE 1<<15 /* Single-shot transmission error interrupt*/ 458 459 /*-------------------------------------------------------------------------*//** 460 The following constants are used for transmit message buffer control bit 461 definitions: 462 463 | Constants | Description | 464 |--------------------------|------------------------------------------------| 465 | CAN_TX_WPNH_EBL | Indicates “WPNH” bit mask | 466 | CAN_TX_WPNL_EBL | Indicates WPNL bit mask | 467 | CAN_TX_REQ | Indicates transmit request flag bit position | 468 | CAN_TX_INT_EBL | Indicates transmit Interrupt enable bit mask | 469 | CAN_TX_ABORT | Indicates Transmit abort mask | 470 471 */ 472 #define CAN_TX_WPNH_EBL 1<<23 473 #define CAN_TX_WPNL_EBL 1<<3 474 #define CAN_TX_INT_EBL 1<<2 475 #define CAN_TX_ABORT 1<<1 476 #define CAN_TX_REQ 0x01u 477 478 /*-------------------------------------------------------------------------*//** 479 The following constants are used for receive message buffer control bit 480 definitions: 481 482 | Constants | Description | 483 |--------------------------|------------------------------------------------| 484 | CAN_RX_WPNH_EBL | Indicates WPNH bit mask. | 485 | CAN_RX_WPNL_EBL | Indicates WPNL bit mask | 486 | CAN_RX_LINK_EBL | Indicates link flag bit mask | 487 | CAN_RX_INT_EBL | Indicates receive interrupt enable bit mask | 488 | CAN_RX_RTR_REPLY_EBL | Indicates RTR reply bit mask | 489 | CAN_RX_BUFFER_EBL | Indicates Transaction buffer enable bit mask | 490 | CAN_RX_RTR_ABORT | Indicates RTR abort request mask | 491 | CAN_RX_RTRP | Indicates RTReply pending status mask | 492 | CAN_RX_MSGAV | Indicates receive message available status mask| 493 494 */ 495 #define CAN_RX_WPNH_EBL 1<<23 496 #define CAN_RX_WPNL_EBL 1<<7 497 #define CAN_RX_LINK_EBL 1<<6 498 #define CAN_RX_INT_EBL 1<<5 499 #define CAN_RX_RTR_REPLY_EBL 1<<4 500 #define CAN_RX_BUFFER_EBL 1<<3 501 #define CAN_RX_RTR_ABORT 1<<2 502 #define CAN_RX_RTRP 1<<1 503 #define CAN_RX_MSGAV 0x01 504 505 /*-------------------------------------------------------------------------*//** 506 The mss_can_mode_t enumeration specifies the possible operating modes of CAN 507 controller. The meaning of the constants is as described below 508 509 | Modes | Description | 510 |----------------------------|------------------------------------------| 511 | CANOP_MODE_NORMAL | Indicates CAN controller is in normal | 512 | | operational mode. | 513 | CANOP_MODE_LISTEN_ONLY | Indicates CAN controller is in listen | 514 | | only mode. | 515 | CANOP_MODE_EXT_LOOPBACK | Indicates CAN controller is in external | 516 | | loop back mode. | 517 | CANOP_MODE_INT_LOOPBACK | Indicates CAN controller is in internal | 518 | | loop back mode. | 519 | CANOP_SRAM_TEST_MODE | Indicates CAN controller is in test mode.| 520 | CANOP_SW_RESET | Indicates CAN controller is in stop mode.| 521 522 */ 523 typedef enum mss_can_mode 524 { 525 CANOP_MODE_NORMAL = 0x01u, 526 CANOP_MODE_LISTEN_ONLY = 0x03u, 527 CANOP_MODE_EXT_LOOPBACK = 0x05u, 528 CANOP_MODE_INT_LOOPBACK = 0x07u, 529 CANOP_SRAM_TEST_MODE = 0x08u, 530 CANOP_SW_RESET = 0x10u 531 } mss_can_mode_t; 532 533 typedef struct _mss_can_msgobject 534 { 535 /* CAN Message ID. */ 536 struct 537 { 538 __IO uint32_t N_ID:3; 539 __IO uint32_t ID:29; 540 }; 541 542 /* CAN Message Data organized as two 32 bit words or 8 data bytes */ 543 union 544 { 545 struct 546 { 547 __IO uint32_t DATAHIGH; 548 __IO uint32_t DATALOW; 549 }; 550 __IO int8_t DATA[8]; 551 }; 552 553 /* CAN Message flags and smaller values organized as one single 32 bit word 554 or a number of bit fields. */ 555 union 556 { 557 __IO uint32_t L; /* 32 bit flag */ 558 struct 559 { 560 /* Flags structure. */ 561 __IO uint32_t NA0:16; 562 __IO uint32_t DLC:4; 563 __IO uint32_t IDE:1; 564 __IO uint32_t RTR:1; 565 __IO uint32_t NA1:10; 566 }; 567 }; 568 } mss_can_msgobject; 569 570 typedef mss_can_msgobject * pmss_can_msgobject; 571 572 /* _CAN_filterobject */ 573 574 typedef struct _CAN_filterobject 575 { 576 /* Acceptance mask settings */ 577 union 578 { 579 __IO uint32_t L; 580 struct 581 { 582 __IO uint32_t N_A:1; 583 __IO uint32_t RTR:1; 584 __IO uint32_t IDE:1; 585 __IO uint32_t ID:29; 586 }; 587 } AMR; 588 589 /* Acceptance code settings */ 590 union 591 { 592 __IO uint32_t L; 593 struct 594 { 595 __IO uint32_t N_A:1; 596 __IO uint32_t RTR:1; 597 __IO uint32_t IDE:1; 598 __IO uint32_t ID:29; 599 }; 600 } ACR; 601 602 /* Acceptance mask and code settings for first two data bytes */ 603 union 604 { 605 __IO uint32_t L; 606 struct 607 { 608 __IO uint32_t MASK:16; 609 __IO uint32_t CODE:16; 610 }; 611 } AMCR_D; 612 } mss_can_filterobject; 613 614 typedef mss_can_filterobject * pmss_can_filterobject; 615 616 /*_CAN_txmsgobject */ 617 618 typedef struct _CAN_txmsgobject 619 { 620 /* CAN Message flags and smaller values organized as one single 32 bit word 621 or a number of bit fields.*/ 622 union 623 { 624 __IO uint32_t L; 625 626 /* Tx Flags structure. */ 627 struct 628 { 629 __IO uint32_t TXREQ:1; 630 __IO uint32_t TXABORT:1; 631 __IO uint32_t TXINTEBL:1; 632 __IO uint32_t WPNL:1; 633 __IO uint32_t NA0:12; 634 __IO uint32_t DLC:4; 635 __IO uint32_t IDE:1; 636 __IO uint32_t RTR:1; 637 __IO uint32_t NA1:1; 638 __IO uint32_t WPNH:1; 639 __IO uint32_t NA2:8; 640 }; 641 } TXB; 642 643 /* CAN Message ID. */ 644 struct 645 { 646 __IO uint32_t N_ID:3; 647 __IO uint32_t ID:29; 648 }; 649 650 /* CAN Message Data organized as two 32 bit words or 8 data bytes */ 651 union 652 { 653 struct 654 { 655 __IO uint32_t DATAHIGH; 656 __IO uint32_t DATALOW; 657 }; 658 __IO int8_t DATA[8]; 659 }; 660 661 } mss_can_txmsgobject; 662 663 /* _mss_can_rxmsgobject */ 664 665 typedef struct _mss_can_rxmsgobject 666 { 667 /* CAN Message flags and smaller values organized as one single 32 bit word 668 or a number of bit fields. */ 669 union 670 { 671 __IO uint32_t L; /* 32 bit flag */ 672 673 /* Tx Flags structure. */ 674 struct 675 { 676 __IO uint32_t MSGAV:1; 677 __IO uint32_t RTRREPLYPEND:1; 678 __IO uint32_t RTRABORT:1; 679 __IO uint32_t BUFFEREBL:1; 680 __IO uint32_t RTRREPLY:1; 681 __IO uint32_t RXINTEBL:1; 682 __IO uint32_t LINKFLAG:1; 683 __IO uint32_t WPNL:1; 684 __IO uint32_t NA0:8; 685 __IO uint32_t DLC:4; 686 __IO uint32_t IDE:1; 687 __IO uint32_t RTR:1; 688 __IO uint32_t NA1:1; 689 __IO uint32_t WPNH:1; 690 __IO uint32_t NA2:8; 691 }; 692 } RXB; 693 694 /* CAN Message ID. */ 695 struct 696 { 697 __IO uint32_t N_ID:3; 698 __IO uint32_t ID:29; 699 }; 700 701 /* CAN Message Data organized as two 32 bit words or 8 data bytes */ 702 union 703 { 704 struct 705 { 706 __IO uint32_t DATAHIGH; 707 __IO uint32_t DATALOW; 708 }; 709 __IO int8_t DATA[8]; 710 }; 711 712 /* CAN Message Filter: Acceptance mask register */ 713 union 714 { 715 __IO uint32_t L; 716 struct 717 { 718 __IO uint32_t N_A:1; 719 __IO uint32_t RTR:1; 720 __IO uint32_t IDE:1; 721 __IO uint32_t ID:29; 722 }; 723 } AMR; 724 725 /* CAN Message Filter: Acceptance code register */ 726 union 727 { 728 __IO uint32_t L; 729 struct 730 { 731 __IO uint32_t N_A:1; 732 __IO uint32_t RTR:1; 733 __IO uint32_t IDE:1; 734 __IO uint32_t ID:29; 735 }; 736 } ACR; 737 738 __IO uint32_t AMR_D; 739 __IO uint32_t ACR_D; 740 741 } mss_can_rxmsgobject; 742 typedef mss_can_rxmsgobject * pmss_can_rxmsgobject; 743 744 /* Error status register */ 745 typedef union error_status 746 { 747 __IO uint32_t L; 748 struct 749 { 750 __IO uint32_t TX_ERR_CNT:8; 751 __IO uint32_t RX_ERR_CNT:8; 752 __IO uint32_t ERROR_STAT:2; 753 __IO uint32_t TXGTE96:1; 754 __IO uint32_t RXGTE96:1; 755 __IO uint32_t N_A:12; 756 }; 757 } mss_can_error_status; 758 759 /* 760 * Buffer status register For CANMOD3X, 761 * this are two 32-bit registers, for can, it is only one 32-bit register. 762 */ 763 #ifdef CANMOD3 764 typedef union buffer_status 765 { 766 __I uint32_t L; 767 struct 768 { 769 __I uint32_t RXMSGAV:16; 770 __I uint32_t TXREQ:8; 771 __I uint32_t N_A:8; 772 }; 773 #else 774 typedef struct buffer_status 775 { 776 __I uint32_t RXMSGAV; 777 __I uint32_t TXREQ; 778 #endif 779 } mss_can_buffer_status; 780 781 /* Interrupt enable register */ 782 typedef union int_enable 783 { 784 __IO uint32_t L; 785 struct 786 { 787 __IO uint32_t INT_EBL:1; 788 __IO uint32_t N_A0:1; 789 __IO uint32_t ARB_LOSS:1; 790 __IO uint32_t OVR_LOAD:1; 791 __IO uint32_t BIT_ERR:1; 792 __IO uint32_t STUFF_ERR:1; 793 __IO uint32_t ACK_ERR:1; 794 __IO uint32_t FORM_ERR:1; 795 __IO uint32_t CRC_ERR:1; 796 __IO uint32_t BUS_OFF:1; 797 __IO uint32_t RX_MSG_LOSS:1; 798 __IO uint32_t TX_MSG:1; 799 __IO uint32_t RX_MSG:1; 800 __IO uint32_t RTR_MSG:1; 801 __IO uint32_t STUCK_AT_0:1; 802 __IO uint32_t SST_FAILURE:1; 803 __IO uint32_t N_A1:16; 804 }; 805 } mss_can_int_enable; 806 807 typedef mss_can_int_enable * pmss_can_int_enable; 808 809 /* Interrupt status register */ 810 typedef union int_status 811 { 812 __IO uint32_t L; 813 struct 814 { 815 __IO uint32_t N_A0:2; 816 __IO uint32_t ARB_LOSS:1; 817 __IO uint32_t OVR_LOAD:1; 818 __IO uint32_t BIT_ERR:1; 819 __IO uint32_t STUFF_ERR:1; 820 __IO uint32_t ACK_ERR:1; 821 __IO uint32_t FORM_ERR:1; 822 __IO uint32_t CRC_ERR:1; 823 __IO uint32_t BUS_OFF:1; 824 __IO uint32_t RX_MSG_LOSS:1; 825 __IO uint32_t TX_MSG:1; 826 __IO uint32_t RX_MSG:1; 827 __IO uint32_t RTR_MSG:1; 828 __IO uint32_t STUCK_AT_0:1; 829 __IO uint32_t SST_FAILURE:1; 830 __IO uint32_t N_A1:16; 831 }; 832 } mss_can_int_status; 833 typedef mss_can_int_status * pmss_can_int_status; 834 835 /* Command register */ 836 typedef union command_reg 837 { 838 __IO uint32_t L; 839 struct 840 { 841 __IO uint32_t RUN_STOP:1; 842 __IO uint32_t LISTEN_ONLY:1; 843 __IO uint32_t LOOP_BACK:1; 844 __IO uint32_t SRAM_TEST:1; 845 __IO uint32_t SW_RESET:1; 846 __IO uint32_t N_A:27; 847 }; 848 } mss_can_command_reg; 849 850 /* Configuration register */ 851 typedef union can_config_reg 852 { 853 __IO uint32_t L; 854 struct 855 { 856 __IO uint32_t EDGE_MODE:1; 857 __IO uint32_t SAMPLING_MODE:1; 858 __IO uint32_t CFG_SJW:2; 859 __IO uint32_t AUTO_RESTART:1; 860 __IO uint32_t CFG_TSEG2:3; 861 __IO uint32_t CFG_TSEG1:4; 862 __IO uint32_t CFG_ARBITER:1; 863 __IO uint32_t ENDIAN:1; 864 __IO uint32_t ECR_MODE:1; 865 __IO uint32_t N_A0:1; 866 __IO uint32_t CFG_BITRATE:15; 867 __IO uint32_t N_A1:1; 868 }; 869 } mss_can_config_reg; 870 typedef mss_can_config_reg * pmss_can_config_reg ; 871 872 /* Register mapping of CAN controller */ 873 typedef struct CAN_device 874 { 875 mss_can_int_status IntStatus; /* Interrupt status register */ 876 mss_can_int_enable IntEbl; /* Interrupt enable register */ 877 mss_can_buffer_status BufferStatus; /* Buffer status indicators */ 878 mss_can_error_status ErrorStatus; /* Error status */ 879 mss_can_command_reg Command; /* CAN operating mode */ 880 mss_can_config_reg Config; /* Configuration register */ 881 #ifdef CANMOD3 882 uint32_t NA[2]; 883 #else 884 uint32_t NA; 885 #endif 886 mss_can_txmsgobject TxMsg[CAN_TX_MAILBOX]; /* Tx message buffers */ 887 mss_can_rxmsgobject RxMsg[CAN_RX_MAILBOX]; /* Rx message buffers */ 888 889 } CAN_DEVICE; 890 891 typedef CAN_DEVICE * PCAN_DEVICE; 892 893 #define MSS_CAN_0_LO_BASE (CAN_DEVICE*)0x2010C000 894 #define MSS_CAN_1_LO_BASE (CAN_DEVICE*)0x2010D000 895 #define MSS_CAN_0_HI_BASE (CAN_DEVICE*)0x2810C000 896 #define MSS_CAN_1_HI_BASE (CAN_DEVICE*)0x2810D000 897 898 #define SYSREG_CAN_A_SOFTRESET_MASK ( (uint32_t)0x01u << 14u ) 899 #define SYSREG_CAN_B_SOFTRESET_MASK ( (uint32_t)0x01u << 15u ) 900 901 /*-------------------------------------------------------------------------*//** 902 The structure mss_can_instance_t is used by the driver to manage the 903 configuration and operation of each MSS CAN peripheral. The instance content 904 should only be accessed by using the respective API functions. 905 906 Each API function has a pointer to this instance as first argument. 907 908 */ 909 typedef struct can_instance 910 { 911 /* Hardware related entries (pointer to device, interrupt number etc) */ 912 CAN_DEVICE * hw_reg; /* Pointer to CAN registers. */ 913 uint8_t irqn; /* refer to local or PLIC */ 914 uint8_t int_type; /*!< 0 => local, 1 => PLIC */ 915 /* Local data (eg pointer to local FIFO, irq number etc) */ 916 uint8_t basic_can_rx_mb; /* number of rx mailboxes */ 917 uint8_t basic_can_tx_mb; /* number of tx mailboxes */ 918 } mss_can_instance_t; 919 920 /*------------------------------------------------------------------------*//** 921 This instances of mss_can_instance_t holds all data related to the operations 922 performed by CAN. A pointer to instance is passed as the first parameter 923 to CAN driver functions to indicate that which CAN instance should perform the 924 requested operation. 925 */ 926 extern mss_can_instance_t g_mss_can_0_lo; 927 extern mss_can_instance_t g_mss_can_1_lo; 928 extern mss_can_instance_t g_mss_can_0_hi; 929 extern mss_can_instance_t g_mss_can_1_hi; 930 931 /*----------------------------------------------------------------------------*/ 932 /*-----------------------MSS CAN Public APIs ---------------------------------*/ 933 /*----------------------------------------------------------------------------*/ 934 935 /*-------------------------------------------------------------------------*//** 936 The MSS_CAN_init() function initializes the CAN driver as well as the CAN 937 controller. The basic_can_rx_mb and basic_can_tx_mb are used to configure the 938 number of receive and transmit mailboxes in basic CAN operation. This function 939 configures the CAN channel speed as per the “bitrate” parameter. It 940 initializes all receive mailboxes and make it ready for configuration. This is 941 the first function to be called before using any other function. 942 943 @param this_can 944 The this_can parameter is a pointer to the mss_can_instance_t structure. 945 946 @param bitrate 947 The bitRate parameter is used to configure CAN speed. The following standard 948 preset definitions are provided for systems with a PCLK1 of 8MHz, 16MHz or 949 32MHz: 950 +-------------------+--------------------+--------------------+ 951 | 8MHz PCLK1 | 16MHz PCLK1 | 32MHz PCLK1 | 952 +-------------------+--------------------+--------------------+ 953 | CAN_SPEED_8M_5K | CAN_SPEED_16M_5K | CAN_SPEED_32M_5K | 954 | CAN_SPEED_8M_10K | CAN_SPEED_16M_10K | CAN_SPEED_32M_10K | 955 | CAN_SPEED_8M_20K | CAN_SPEED_16M_20K | CAN_SPEED_32M_20K | 956 | CAN_SPEED_8M_50K | CAN_SPEED_16M_50K | CAN_SPEED_32M_50K | 957 | CAN_SPEED_8M_100K | CAN_SPEED_16M_100K | CAN_SPEED_32M_100K | 958 | CAN_SPEED_8M_125K | CAN_SPEED_16M_125K | CAN_SPEED_32M_125K | 959 | CAN_SPEED_8M_250K | CAN_SPEED_16M_250K | CAN_SPEED_32M_250K | 960 | CAN_SPEED_8M_500K | CAN_SPEED_16M_500K | CAN_SPEED_32M_500K | 961 | CAN_SPEED_8M_1M | CAN_SPEED_16M_1M | CAN_SPEED_32M_1M | 962 +-------------------+--------------------+--------------------+ 963 964 For custom settings, use CAN_SPEED_MANUAL and configure the settings via 965 pcan_config. 966 967 The default configurations can be altered by the addition of 0 or more of 968 the following: 969 - CAN_AUTO_RESTART 970 - CAN_ARB_FIXED_PRIO 971 - CAN_LITTLE_ENDIAN 972 973 @param pcan_config 974 The pcan_config parameter is a pointer to a mss_can_config_reg structure. This 975 structure is only used when bitrate is configured as CAN_SPEED_MANUAL. 976 977 When populating the mss_can_config_reg structure, the following should be noted: 978 979 1. CFG_BITRATE defines the length of a CAN time quantum in terms of PCLK1 980 with 0 = 1 PCLK1, 1 = 2 PCLK1s and so on. 981 2. A CAN bit time is made up of between 8 and 25 time quanta and the bit 982 rate is PCLK1 / ((CFG_BITRATE + 1) * number of time quanta per bit). 983 3. There is a fixed overhead of 1 time quantum for synchronization at the 984 start of every CAN bit and the remaining time quanta in the bit are 985 allocated with CFG_TSEG1 and CFG_TSEG2. 986 4. CFG_TSEG1 can have a value between 2 and 15 which represents between 3 987 and 16 time quanta. 988 5. If SAMPLING_MODE is 0, CFG_TSEG2 can have a value between 1 and 7 which 989 represents between 2 and 8 time quanta and if SAMPLING_MODE is 1, 990 CFG_TSEG2 can have a value between 2 and 7 which represents between 3 991 and 8 time quanta. 992 6. Receive sampling takes place at the end of the segment defined by 993 CFG_TSEG1. 994 995 For example, if CFG_TSEG1 = 3 and CFG_TSEG2 = 2 we get: 996 997 |<------------ 1 CAN bit time (8 time quanta)------------>| 998 /------+------+------+------+------+------+------+------\ 999 -+ Synch | CFG_TSEG1 + 1 | CFG_TSEG2 + 1 +- 1000 \------+------+------+------+------+------+------+------/ 1001 | 1002 Receiver samples date here -->| 1003 1004 @param basic_can_rx_mb 1005 The basic_can_rx_mb parameter is the number of receive mailboxes used in 1006 basic CAN mode. 1007 1008 @param basic_can_tx_mb 1009 The basic_can_tx_mb parameter is the number of transmit mailboxes used in 1010 basic CAN mode. 1011 1012 @return 1013 This function returns CAN_OK on successful execution, otherwise it will 1014 returns following error codes: 1015 1016 | Constants | Description | 1017 |-----------------------|---------------------------------------------| 1018 | CAN_ERR | Indicates error condition | 1019 | CAN_TSEG1_TOO_SMALL | Value provided to configure TSEG1 is too | 1020 | | small | 1021 | CAN_TSEG2_TOO_SMALL | Value provided to configure TSEG2 is too | 1022 | | small | 1023 | CAN_SJW_TOO_BIG | Value provided to configure synchronous jump| 1024 | | width (SJW) is too big. | 1025 1026 Example 1: Using a default set for bitrate, tseg1, tseg2, and sjw and 1027 additional configuration parameters. 1028 @code 1029 mss_can_instance_t g_mss_can_0_lo; 1030 int e51(void) 1031 { 1032 MSS_CAN_init(&g_mss_can_0_lo, (CAN_SPEED_16M_500K | CAN_AUTO_RESTART | \ 1033 CAN_LITTLE_ENDIAN),(pmss_can_config_reg)0,16u,7u); 1034 1035 return(0); 1036 } 1037 @endcode 1038 1039 Example 2: Using custom settings for bitrate, tseg1, tseg2, and sjw. 1040 @code 1041 mss_can_instance_t g_mss_can_0_lo; 1042 1043 #define SYSTEM_CLOCK 8000000 1044 #define BITS_PER_SECOND 10000 1045 1046 int e51(void) 1047 { 1048 mss_can_config_reg canreg; 1049 1050 canreg.CFG_BITRATE = (SYSTEM_CLOCK / (BITS_PER_SECOND * 8) - 1; 1051 canreg.CFG_TSEG1 = 4; 1052 canreg.CFG_TSEG2 = 1; 1053 canreg.AUTO_RESTART = 0; 1054 canreg.CFG_SJW = 0; 1055 canreg.SAMPLING_MODE = 0; 1056 canreg.EDGE_MODE = 0; 1057 canreg.ENDIAN = 1; 1058 1059 MSS_CAN_init(&g_mss_can_0_lo,CAN_SPEED_MANUAL,&canreg,8,4); 1060 1061 return(0); 1062 } 1063 @endcode 1064 */ 1065 uint8_t 1066 MSS_CAN_init 1067 ( 1068 mss_can_instance_t* this_can, 1069 uint32_t bitrate, 1070 pmss_can_config_reg pcan_config, 1071 uint8_t basic_can_rx_mb, 1072 uint8_t basic_can_tx_mb 1073 ); 1074 1075 /*------------------------------------------------------------------------*//** 1076 The MSS_CAN_set_config_reg() function sets the configuration register and 1077 starts the CAN controller for normal mode operation. This function is used 1078 when one needs to change the configuration settings while the CAN controller 1079 was already initialized using MSS_CAN_init() function and is running. 1080 MSS_CAN_set_config_reg() function should not be used when the CAN controller 1081 wasn't initialized yet. 1082 1083 It performs following tasks: 1084 - Clears all pending interrupts 1085 - Stops CAN controller 1086 - Disable interrupts 1087 - Sets new configuration 1088 - Starts CAN controller 1089 1090 @param this_can 1091 The this_can parameter is a pointer to the MSS_CAN_instance_t structure. 1092 1093 @param cfg 1094 The cfg parameter is a 4 bytes variable used to set the configuration 1095 settings. 1096 1097 @return 1098 This function does not return a value. 1099 1100 Example: 1101 @code 1102 mss_can_instance_t g_mss_can_0_lo; 1103 1104 int e51(void) 1105 { 1106 Return_status = MSS_CAN_init(&g_mss_can_0_lo,(CAN_SPEED_16M_500K | \ 1107 CAN_AUTO_RESTART | CAN_LITTLE_ENDIAN), 1108 (pmss_can_config_reg)0,16,7); 1109 .... 1110 1111 MSS_CAN_set_config_reg(&g_mss_can_0_lo, (CAN_SPEED_16M_500K | \ 1112 CAN_AUTO_RESTART | CAN_LITTLE_ENDIAN)); 1113 1114 .... 1115 return(0); 1116 } 1117 @endcode 1118 */ 1119 void 1120 MSS_CAN_set_config_reg 1121 ( 1122 mss_can_instance_t* this_can, 1123 uint32_t cfg 1124 ); 1125 1126 /*-------------------------------------------------------------------------*//** 1127 The MSS_CAN_set_mode() function sets the CAN controller operating mode based 1128 on the mode parameter. After this operation CAN controller is not in 1129 operational, to do that invoke MSS_CAN_start() function. 1130 1131 @param this_can 1132 The this_can parameter is a pointer to the mss_can_instance_t structure. 1133 1134 @param mode 1135 The mode parameter tells about desired operating mode of CAN controller. 1136 Possible operating modes are as mentioned below: 1137 1138 | Mode | Description | 1139 |--------------------------|-----------------------------------------| 1140 | CANOP_MODE_INT_LOOPBACK | Sets normal operating mode | 1141 | CANOP_MODE_LISTEN_ONLY | In listen-only mode, the CAN controller | 1142 | | does not send any messages. Normally | 1143 | | used for automatic bitrate detection | 1144 | CANOP_MODE_INT_LOOPBACK | Selects internal loopback mode. This is | 1145 | | used for self-test | 1146 | CANOP_MODE_EXT_LOOPBACK | Selects external loopback. The CAN | 1147 | | controller will receive a copy of each | 1148 | | message sent. | 1149 | CANOP_SRAM_TEST_MODE | Sets SRAM test mode | 1150 | CANOP_SW_RESET | Issues a software reset | 1151 1152 @return 1153 This function does not return a value. 1154 1155 Example: 1156 @code 1157 int e51(void) 1158 { 1159 MSS_CAN_init(&g_mss_can_0_lo,(CAN_SPEED_16M_500K | CAN_AUTO_RESTART | \ 1160 CAN_LITTLE_ENDIAN),(pmss_can_config_reg)0,16,7); 1161 MSS_CAN_set_mode(&g_mss_can_0_lo,CANOP_MODE_INT_LOOPBACK); 1162 1163 .... 1164 1165 return(0); 1166 } 1167 @endcode 1168 */ 1169 void 1170 MSS_CAN_set_mode 1171 ( 1172 mss_can_instance_t* this_can, 1173 mss_can_mode_t mode 1174 ); 1175 1176 /*-------------------------------------------------------------------------*//** 1177 The MSS_CAN_start() function clears all pending interrupts and enable CAN 1178 controller to perform normal operation. It enables receive interrupts also. 1179 1180 @param this_can 1181 The this_can parameter is a pointer to the mss_can_instance_t structure. 1182 1183 @return 1184 This function does not return a value. 1185 1186 Example: 1187 @code 1188 int e51(void) 1189 { 1190 MSS_CAN_init(&g_mss_can_0_lo,(CAN_SPEED_16M_500K | CAN_AUTO_RESTART | \ 1191 CAN_LITTLE_ENDIAN),(pmss_can_config_reg)0,16,7); 1192 MSS_CAN_set_mode(&g_mss_can_0_lo,CANOP_MODE_INT_LOOPBACK); 1193 MSS_CAN_start(&g_mss_can_0_lo); 1194 1195 .... 1196 1197 return(0); 1198 } 1199 @endcode 1200 */ 1201 void 1202 MSS_CAN_start 1203 ( 1204 mss_can_instance_t* this_can 1205 ); 1206 1207 /*-------------------------------------------------------------------------*//** 1208 The MSS_CAN_stop() function is used to disable the CAN controller. 1209 1210 NOTE: Interrupt flags status remain unaffected. 1211 1212 @param this_can 1213 The this_can parameter is a pointer to the mss_can_instance_t structure. 1214 1215 @return 1216 This function does not return a value. 1217 1218 Example: 1219 @code 1220 int e51(void) 1221 { 1222 MSS_CAN_init(&g_mss_can_0_lo,(CAN_SPEED_16M_500K | CAN_AUTO_RESTART | \ 1223 CAN_LITTLE_ENDIAN),(pmss_can_config_reg)0,16,7); 1224 MSS_CAN_set_mode(&g_mss_can_0_lo,CANOP_MODE_INT_LOOPBACK); 1225 MSS_CAN_start(&g_mss_can_0_lo); 1226 1227 .... 1228 .... 1229 1230 MSS_CAN_stop(&g_mss_can_0_lo); 1231 1232 return(0); 1233 } 1234 @endcode 1235 */ 1236 void 1237 MSS_CAN_stop 1238 ( 1239 mss_can_instance_t* this_can 1240 ); 1241 1242 /*-------------------------------------------------------------------------*//** 1243 The MSS_CAN_get_id() function returns the message identifier. Bits right 1244 justified based on message identifier (Extended identifier) type. 1245 1246 @param pmsg 1247 The pmsg parameter is a pointer to the message object. 1248 1249 @return 1250 This function returns message identifier. 1251 1252 Example: 1253 @code 1254 int e51(void) 1255 { 1256 ... 1257 return_id = MSS_CAN_get_id(&pmsg); 1258 1259 return(0); 1260 } 1261 @endcode 1262 */ 1263 uint32_t 1264 MSS_CAN_get_id 1265 ( 1266 pmss_can_msgobject pmsg 1267 ); 1268 1269 1270 /*-------------------------------------------------------------------------*//** 1271 The MSS_CAN_set_id() function returns ID bits left justified based on IDE 1272 type. IDE type might be either standard or extended. 1273 1274 @param pmsg 1275 The pmsg parameter is a pointer to the message object. 1276 1277 @return 1278 This function returns message identifier. 1279 1280 Example: 1281 @code 1282 int e51(void) 1283 { 1284 .... 1285 pmsg->ID = 0x120; 1286 MSS_CAN_set_id(&pmsg); 1287 1288 .... 1289 return(0); 1290 } 1291 @endcode 1292 */ 1293 uint32_t 1294 MSS_CAN_set_id 1295 ( 1296 pmss_can_msgobject pmsg 1297 ); 1298 1299 /*-------------------------------------------------------------------------*//** 1300 The MSS_CAN_get_msg_filter_mask() function packs the ID, IDE, and RTR bits 1301 together as they are used in the message filter mask and returns packed 1302 identifier. 1303 1304 @param id 1305 The id parameter is a 4 byte variable to hold message identifier. 1306 1307 @param ide 1308 The ide parameter is a 1 byte variable to indicate IDE type. Acceptable 1309 values are as mentioned below: 1310 1311 | Value | Description | 1312 |------------|-------------------------------| 1313 | 0 | Standard format | 1314 | 1 | Extended format | 1315 1316 @param rtr 1317 The rtr parameter is a 1 byte variable to indicate message type. Acceptable 1318 values are as mentioned below: 1319 1320 | Value | Description | 1321 |------------|-------------------------------| 1322 | 0 | Regular message (data frame) | 1323 | 1 | RTR message (remote frame) | 1324 1325 @return 1326 This function returns packed id. 1327 1328 Example: 1329 @code 1330 int e51(void) 1331 { 1332 .... 1333 1334 MSS_CAN_get_msg_filter_mask( 0x120, 1, 0); 1335 1336 .... 1337 return(0); 1338 } 1339 @endcode 1340 */ 1341 uint32_t 1342 MSS_CAN_get_msg_filter_mask 1343 ( 1344 uint32_t id, 1345 uint8_t ide, 1346 uint8_t rtr 1347 ); 1348 1349 /*-------------------------------------------------------------------------*//** 1350 The MSS_CAN_set_int_ebl() function enable specific interrupt based on 1351 irq_flag parameter. 1352 1353 @param this_can 1354 This is a pointer to an mss_can_instance_t structure. 1355 1356 @param irq_flag 1357 The irq_flag parameter is a 4 byte variable indicates Interrupt type. 1358 Possible values are: 1359 1360 | Constants | Description | 1361 |------------------------|------------------------------------------------| 1362 | CAN_INT_GLOBAL | Indicates to enable global interrupts | 1363 | CAN_INT_ARB_LOSS | Indicates arbitration loss interrupt | 1364 | CAN_INT_OVR_LOAD | Indicates overload message detected interrupt | 1365 | CAN_INT_BIT_ERR | Indicates bit error interrupt | 1366 | CAN_INT_STUFF_ERR | Indicates bit stuffing error interrupt | 1367 | CAN_INT_ACK_ERR | Indicates acknowledge error interrupt | 1368 | CAN_INT_FORM_ERR | Indicates format error interrupt | 1369 | CAN_INT_CRC_ERR | Indicates CRC error interrupt | 1370 | CAN_INT_BUS_OFF | Indicates bus off interrupt | 1371 | CAN_INT_RX_MSG_LOST | Indicates received message lost interrupt | 1372 | CAN_INT_TX_MSG | Indicates message transmit interrupt | 1373 | CAN_INT_RX_MSG | Indicates receive message available interrupt | 1374 | CAN_INT_RTR_MSG | Indicates RTR auto-reply message sent interrupt| 1375 | CAN_INT_STUCK_AT_0 | Indicates stuck at dominant error interrupt | 1376 | CAN_INT_SST_FAILURE | Indicates single shot transmission failure | 1377 | | interrupt | 1378 1379 @return 1380 This function does not return a value. 1381 1382 Example: 1383 @code 1384 int e51(void) 1385 { 1386 .... 1387 1388 MSS_CAN_set_int_ebl(&g_mss_can_0_lo,CAN_INT_TX_MSG); 1389 1390 .... 1391 return(0); 1392 } 1393 @endcode 1394 */ 1395 void 1396 MSS_CAN_set_int_ebl 1397 ( 1398 mss_can_instance_t* this_can, 1399 uint32_t irq_flag 1400 ); 1401 1402 /*-------------------------------------------------------------------------*//** 1403 The MSS_CAN_clear_int_ebl() function disable specific interrupt based on 1404 irq_flag parameter. 1405 1406 @param this_can 1407 This is a pointer to an mss_can_instance_t structure. 1408 1409 @param irq_flag 1410 The irq_flag parameter is a 4 byte variable indicates Interrupt type. 1411 Possible values are: 1412 1413 | Constant | Description | 1414 |------------------------|------------------------------------------------| 1415 | CAN_INT_GLOBAL | Indicates to enable global interrupts | 1416 | CAN_INT_ARB_LOSS | Indicates arbitration loss interrupt | 1417 | CAN_INT_OVR_LOAD | Indicates overload message detected interrupt | 1418 | CAN_INT_BIT_ERR | Indicates bit error interrupt | 1419 | CAN_INT_STUFF_ERR | Indicates bit stuffing error interrupt | 1420 | CAN_INT_ACK_ERR | Indicates acknowledge error interrupt | 1421 | CAN_INT_FORM_ERR | Indicates format error interrupt | 1422 | CAN_INT_CRC_ERR | Indicates CRC error interrupt | 1423 | CAN_INT_BUS_OFF | Indicates bus off interrupt | 1424 | CAN_INT_RX_MSG_LOST | Indicates received message lost interrupt | 1425 | CAN_INT_TX_MSG | Indicates message transmit interrupt | 1426 | CAN_INT_RX_MSG | Indicates receive message available interrupt | 1427 | CAN_INT_RTR_MSG | Indicates RTR auto-reply message sent interrupt| 1428 | CAN_INT_STUCK_AT_0 | Indicates stuck at dominant error interrupt | 1429 | CAN_INT_SST_FAILURE | Indicates single shot transmission failure | 1430 | | interrupt | 1431 1432 @return 1433 This function does not return a value. 1434 1435 Example: 1436 @code 1437 int e51(void) 1438 { 1439 .... 1440 1441 MSS_CAN_clear_int_ebl(&g_mss_can_0_lo,CAN_INT_TX_MSG); 1442 1443 .... 1444 return(0); 1445 } 1446 @endcode 1447 */ 1448 void 1449 MSS_CAN_clear_int_ebl 1450 ( 1451 mss_can_instance_t* this_can, 1452 uint32_t irq_flag 1453 ); 1454 1455 /*-------------------------------------------------------------------------*//** 1456 The MSS_CAN_get_global_int_ebl() function returns the status of global 1457 interrupt enable flag. 1458 1459 @param this_can 1460 The this_can parameter is a pointer to the mss_can_instance_t structure. 1461 1462 @return 1463 This function returns global interrupt enable flag status. 1464 1465 Example: 1466 @code 1467 int e51(void) 1468 { 1469 .... 1470 1471 MSS_CAN_get_global_int_ebl(&g_mss_can_0_lo); 1472 .... 1473 return(0); 1474 } 1475 @endcode 1476 */ 1477 uint32_t 1478 MSS_CAN_get_global_int_ebl 1479 ( 1480 mss_can_instance_t* this_can 1481 ); 1482 1483 /*-------------------------------------------------------------------------*//** 1484 The MSS_CAN_get_int_ebl() function returns the status of interrupt enable 1485 flags. 1486 1487 @param this_can 1488 The this_can parameter is a pointer to the mss_can_instance_t structure. 1489 1490 @return 1491 This function returns interrupt enable flag status. 1492 1493 Example: 1494 @code 1495 int e51(void) 1496 { 1497 .... 1498 1499 MSS_CAN_get_int_ebl(&g_mss_can_0_lo); 1500 .... 1501 return(0); 1502 } 1503 @endcode 1504 */ 1505 uint32_t 1506 MSS_CAN_get_int_ebl 1507 ( 1508 mss_can_instance_t* this_can 1509 ); 1510 1511 /*-------------------------------------------------------------------------*//** 1512 The MSS_CAN_clear_int_status() function clears the selected interrupt flags. 1513 1514 @param this_can 1515 The this_can parameter is a pointer to the mss_can_instance_t structure. 1516 1517 @param irq_flag 1518 The irq_flag parameter is a 4 byte variable indicates Interrupt type. 1519 Possible values are: 1520 | Constants | Description | 1521 |------------------------|------------------------------------------------| 1522 | CAN_INT_GLOBAL | Indicates to enable global interrupts | 1523 | CAN_INT_ARB_LOSS | Indicates arbitration loss interrupt | 1524 | CAN_INT_OVR_LOAD | Indicates overload message detected interrupt | 1525 | CAN_INT_BIT_ERR | Indicates bit error interrupt | 1526 | CAN_INT_STUFF_ERR | Indicates bit stuffing error interrupt | 1527 | CAN_INT_ACK_ERR | Indicates acknowledge error interrupt | 1528 | CAN_INT_FORM_ERR | Indicates format error interrupt | 1529 | CAN_INT_CRC_ERR | Indicates CRC error interrupt | 1530 | CAN_INT_BUS_OFF | Indicates bus off interrupt | 1531 | CAN_INT_RX_MSG_LOST | Indicates received message lost interrupt | 1532 | CAN_INT_TX_MSG | Indicates message transmit interrupt | 1533 | CAN_INT_RX_MSG | Indicates receive message available interrupt | 1534 | CAN_INT_RTR_MSG | Indicates RTR auto-reply message sent interrupt| 1535 | CAN_INT_STUCK_AT_0 | Indicates stuck at dominant error interrupt | 1536 | CAN_INT_SST_FAILURE | Indicates single shot transmission failure | 1537 | | interrupt | 1538 1539 @return 1540 This function does not return a value. 1541 1542 Example: 1543 @code 1544 int e51(void) 1545 { 1546 .... 1547 MSS_CAN_clear_int_status(&g_mss_can_0_lo,CAN_INT_RX_MSG); 1548 .... 1549 return(0); 1550 } 1551 @endcode 1552 */ 1553 void 1554 MSS_CAN_clear_int_status 1555 ( 1556 mss_can_instance_t* this_can, 1557 uint32_t irq_flag 1558 ); 1559 1560 /*-------------------------------------------------------------------------*//** 1561 The MSS_CAN_get_int_status() function returns the status of interrupts. 1562 1563 @param this_can 1564 The this_can parameter is a pointer to the mss_can_instance_t structure. 1565 1566 @return 1567 This function returns status of existed interrupts. 1568 1569 Example: 1570 @code 1571 int e51(void) 1572 { 1573 .... 1574 1575 MSS_CAN_get_int_status(&g_mss_can_0_lo); 1576 .... 1577 return(0); 1578 } 1579 @endcode 1580 */ 1581 uint32_t 1582 MSS_CAN_get_int_status 1583 ( 1584 mss_can_instance_t* this_can 1585 ); 1586 1587 /*-------------------------------------------------------------------------*//** 1588 The MSS_CAN_set_rtr_message_n () function loads mailbox with the given CAN 1589 message. This message will be sent out after receipt of a RTR message 1590 request. It verifies that whether the given mailbox is configured for Full 1591 CAN or not and also checks for RTR auto-reply is enabled or not. 1592 1593 @param this_can 1594 The this_can parameter is a pointer to the mss_can_instance_t structure. 1595 1596 @param mailbox_number 1597 The mailbox_number parameter is a variable to hold the mailbox number to 1598 be used for message transfer. 1599 1600 @param pmsg 1601 The pmsg parameter is a pointer to the message object. 1602 1603 @return 1604 This function returns CAN_OK on successful execution, otherwise it will 1605 returns following error codes: 1606 1607 | Constants | Description | 1608 |-----------------------|---------------------------------------------| 1609 | CAN_BASIC_CAN_MAILBOX | Indicates that mailbox is configured for | 1610 | | Basic CAN operation | 1611 | CAN_NO_RTR_MAILBOX | Indicates that there is no mailbox for | 1612 | | remote transmit request (RTR) frame | 1613 1614 1615 Example: 1616 @code 1617 e51() 1618 { 1619 ... 1620 1621 pmsg->ID = 0x120; 1622 pmsg->DATALOW = 0xAA5555AA; 1623 pmsg->DATAHIGH = 0xAA5555AA; 1624 1625 MSS_CAN_set_rtr_message_n(&g_mss_can_0_lo, 5, &pmsg); 1626 1627 ... 1628 } 1629 @endcode 1630 */ 1631 uint8_t 1632 MSS_CAN_set_rtr_message_n 1633 ( 1634 mss_can_instance_t* this_can, 1635 uint8_t mailbox_number, 1636 pmss_can_msgobject pmsg 1637 ); 1638 1639 /*-------------------------------------------------------------------------*//** 1640 The MSS_CAN_get_rtr_message_abort_n() function aborts a RTR message transmit 1641 request on mailbox mailbox_number and checks that message abort was 1642 successful. 1643 1644 @param this_can 1645 The this_can parameter is a pointer to the mss_can_instance_t structure. 1646 1647 @param mailbox_number 1648 The mailbox_number parameter is a variable to hold the mailbox number to 1649 be used for message transfer. 1650 1651 @return 1652 This function returns CAN_OK on successful execution, otherwise it will 1653 returns following error codes: 1654 1655 | Constants | Description | 1656 |-----------------------|---------------------------------------------| 1657 | CAN_ERR | Indicates error condition | 1658 | CAN_BASIC_CAN_MAILBOX | Indicates that mailbox is configured for | 1659 | | Basic CAN operation | 1660 1661 Example: 1662 @code 1663 e51() 1664 { 1665 ... 1666 1667 ret_status = MSS_CAN_get_rtr_message_abort_n((&g_mss_can_0_lo, 6); 1668 1669 ... 1670 } 1671 @endcode 1672 */ 1673 uint8_t 1674 MSS_CAN_get_rtr_message_abort_n 1675 ( 1676 mss_can_instance_t* this_can, 1677 uint8_t mailbox_number 1678 ); 1679 1680 /*-------------------------------------------------------------------------*//** 1681 The MSS_CAN_config_buffer() function configures receive mailboxes initialized 1682 for Basic CAN operation. 1683 1684 @param this_can 1685 The this_can parameter is a pointer to the mss_can_instance_t structure. 1686 1687 @param pfilter 1688 The pfilter parameter is a pointer to the CAN message filter structure. 1689 1690 @return 1691 This function returns CAN_OK on successful execution, otherwise it will 1692 returns following error codes: 1693 1694 | Constants | Description | 1695 |-----------------------|---------------------------------------------| 1696 | CAN_NO_MSG | Indicates that there is no message received | 1697 | CAN_INVALID_MAILBOX | Indicates invalid mailbox number | 1698 1699 1700 Example: 1701 @code 1702 e51() 1703 { 1704 ... 1705 pfilter.ACR.L=0x00000000; 1706 pfilter.AMR.L= 0xFFFFFFFF; 1707 pfilter.AMCR_D.MASK= 0xFFFF; 1708 pfilter.AMCR_D.CODE= 0x00; 1709 1710 ret_status = MSS_CAN_config_buffer(&g_mss_can_0_lo, &pfilter); 1711 ... 1712 } 1713 @endcode 1714 */ 1715 uint8_t 1716 MSS_CAN_config_buffer 1717 ( 1718 mss_can_instance_t* this_can, 1719 pmss_can_filterobject pfilter 1720 ); 1721 1722 /*-------------------------------------------------------------------------*//** 1723 The MSS_CAN_config_buffer_n() function configures the receive mailbox 1724 specified in mailbox_number. The function checks that the mailbox is set for 1725 Full CAN operation, if not it return with error code. 1726 1727 @param this_can 1728 The this_can parameter is a pointer to the mss_can_instance_t structure. 1729 1730 @param mailbox_number 1731 The mailbox_number parameter is a variable to hold the mailbox number to 1732 be used for message transfer. 1733 1734 @param pmsg 1735 The pmsg parameter is a pointer to the message object. 1736 1737 @return 1738 This function returns CAN_OK on successful execution, otherwise it will 1739 returns following error codes 1740 - CAN_BASIC_CAN_MAILBOX 1741 1742 | Constants | Description | 1743 |-----------------------|---------------------------------------------| 1744 | CAN_NO_MSG | Indicates that there is no message received | 1745 | CAN_INVALID_MAILBOX | Indicates invalid mailbox number | 1746 | CAN_BASIC_CAN_MAILBOX | Indicates that mailbox is configured for | 1747 | | Basic CAN operation | 1748 1749 Example: 1750 @code 1751 e51() 1752 { 1753 ... 1754 rx_msg.ID = 0x200; 1755 rx_msg.DATAHIGH = 0u; 1756 rx_msg.DATALOW = 0u; 1757 rx_msg.AMR.L = 0xFFFFFFFF; 1758 rx_msg.ACR.L = 0x00000000; 1759 rx_msg.AMR_D = 0x0000FFFF; 1760 rx_msg.ACR_D = 0x00000000; 1761 rx_msg.RXB.DLC = 8u; 1762 rx_msg.RXB.IDE = 0; 1763 1764 ret_status = MSS_CAN_config_buffer_n(&g_mss_can_0_lo, 3, &rx_msg); 1765 ... 1766 } 1767 @endcode 1768 */ 1769 uint8_t 1770 MSS_CAN_config_buffer_n 1771 ( 1772 mss_can_instance_t* this_can, 1773 uint8_t mailbox_number, 1774 pmss_can_rxmsgobject pmsg 1775 ); 1776 1777 /*-------------------------------------------------------------------------*//** 1778 The MSS_CAN_get_message_n() function read message from the receive mailbox 1779 specified in "mailbox_number" parameter and returns status of operation. 1780 1781 @param this_can 1782 The this_can parameter is a pointer to the mss_can_instance_t structure. 1783 1784 @param mailbox_number 1785 The mailbox_number parameter is a variable to hold the mailbox number to 1786 be used for message transfer. 1787 1788 @param pmsg 1789 The pmsg parameter is a pointer to the message object that will hold the 1790 received message. 1791 1792 @return 1793 This function returns CAN_VALID_MSG on successful execution, otherwise it 1794 will returns following error codes: 1795 1796 | Constants | Description | 1797 |-----------------------|---------------------------------------------| 1798 | CAN_NO_MSG | Indicates that there is no message received | 1799 | CAN_BASIC_CAN_MAILBOX | Indicates that mailbox is configured for | 1800 | | Basic CAN operation | 1801 1802 Example: 1803 @code 1804 e51() 1805 { 1806 pmss_can_msgobject msg; 1807 ... 1808 1809 ret_status = MSS_CAN_get_message_n(&g_mss_can_0_lo, 3, &msg); 1810 ... 1811 } 1812 @endcode 1813 */ 1814 uint8_t 1815 MSS_CAN_get_message_n 1816 ( 1817 mss_can_instance_t* this_can, 1818 uint8_t mailbox_number, 1819 pmss_can_msgobject pmsg 1820 ); 1821 1822 /*-------------------------------------------------------------------------*//** 1823 The MSS_CAN_get_message() function read message from the first mailbox set 1824 for Basic CAN operation that contains a message. Once the message has been 1825 read from the mailbox, the message receipt is acknowledged. 1826 Note: Since neither a hardware nor a software FIFO exists, message inversion 1827 might happen (example, a newer message might be read from the receive 1828 buffer prior to an older message). 1829 1830 @param this_can 1831 The this_can parameter is a pointer to the mss_can_instance_t structure. 1832 1833 @param pmsg 1834 The pmsg parameter is a pointer to the message object, that will hold the 1835 received message. 1836 1837 @return 1838 This function returns CAN_VALID_MSG on successful execution, otherwise it 1839 will returns following error codes 1840 1841 | Constants | Description | 1842 |-----------------------|---------------------------------------------| 1843 | CAN_NO_MSG | Indicates that there is no message received | 1844 | CAN_INVALID_MAILBOX | Indicates invalid mailbox number | 1845 1846 Example: 1847 @code 1848 e51() 1849 { 1850 pmss_can_msgobject rx_buf; 1851 ... 1852 if(CAN_VALID_MSG == MSS_CAN_get_message_av(&g_mss_can_0_lo)) 1853 { 1854 if(CAN_VALID_MSG != MSS_CAN_get_message(&g_mss_can_0_lo, &rx_buf)) 1855 { 1856 .... 1857 } 1858 } 1859 ... 1860 } 1861 @endcode 1862 */ 1863 uint8_t 1864 MSS_CAN_get_message 1865 ( 1866 mss_can_instance_t* this_can, 1867 pmss_can_msgobject pmsg 1868 ); 1869 1870 /*-------------------------------------------------------------------------*//** 1871 The MSS_CAN_get_message_av() function indicates if receive buffer contains a 1872 new message in Basic CAN operation. 1873 1874 @param this_can 1875 The this_can parameter is a pointer to the mss_can_instance_t structure. 1876 1877 @return 1878 This function returns CAN_VALID_MSG on successful execution, otherwise it 1879 will returns following error codes: 1880 1881 | Constants | Description | 1882 |-----------------------|---------------------------------------------| 1883 | CAN_NO_MSG | Indicates that there is no message received | 1884 | CAN_INVALID_MAILBOX | Indicates invalid mailbox number | 1885 1886 Example: 1887 @code 1888 e51() 1889 { 1890 pmss_can_msgobject rx_buf; 1891 ... 1892 if(CAN_VALID_MSG == MSS_CAN_get_message_av(&g_mss_can_0_lo)) 1893 { 1894 MSS_CAN_get_message(&g_mss_can_0_lo, &rx_buf); 1895 } 1896 ... 1897 } 1898 @endcode 1899 */ 1900 uint8_t 1901 MSS_CAN_get_message_av 1902 ( 1903 mss_can_instance_t* this_can 1904 ); 1905 1906 /*-------------------------------------------------------------------------*//** 1907 The MSS_CAN_send_message_n() function sends a message using mailbox 1908 "mailbox_number". The function verifies that this mailbox is configured for 1909 Full CAN operation and is empty. 1910 1911 @param this_can 1912 The this_can parameter is a pointer to the mss_can_instance_t structure. 1913 1914 @param mailbox_number 1915 The mailbox_number parameter is a variable to hold the mailbox number to 1916 be used for message transfer. 1917 1918 @param pmsg 1919 The pmsg parameter is a pointer to the message object that holds the CAN 1920 message to transmit. 1921 1922 @return 1923 This function returns CAN_VALID_MSG on successful execution, otherwise it 1924 will return the following error codes: 1925 1926 | Constants | Description | 1927 |-----------------------|---------------------------------------------| 1928 | CAN_NO_MSG | Indicates that there is no message received | 1929 | CAN_INVALID_MAILBOX | Indicates invalid mailbox number | 1930 1931 Example: 1932 @code 1933 e51() 1934 { 1935 pmss_can_msgobject pmsg; 1936 ... 1937 pmsg.ID=0x120; 1938 pmsg.DATALOW = 0x55555555; 1939 pmsg.DATAHIGH = 0x55555555; 1940 pmsg.L = ((0<<20)| 0x00080000); 1941 1942 if (CAN_OK != MSS_CAN_send_message_n(&g_mss_can_0_lo, 0, &pmsg)) 1943 { 1944 ... 1945 } 1946 1947 ... 1948 } 1949 @endcode 1950 */ 1951 uint8_t 1952 MSS_CAN_send_message_n 1953 ( 1954 mss_can_instance_t* this_can, 1955 uint8_t mailbox_number, 1956 pmss_can_msgobject pmsg 1957 ); 1958 1959 /*-------------------------------------------------------------------------*//** 1960 The MSS_CAN_send_message_abort_n() function aborts a message transmit 1961 request for the specified mailbox number in mailbox_number and checks that 1962 message abort status. 1963 1964 @param this_can 1965 The this_can parameter is a pointer to the mss_can_instance_t structure. 1966 1967 @param mailbox_number 1968 The mailbox_number parameter is a variable to hold the mailbox number to 1969 be used for message transfer. 1970 1971 @return 1972 This function returns CAN_OK on successful execution, otherwise it 1973 will return the following error codes: 1974 1975 | Constants | Description | 1976 |-----------------------|---------------------------------------------| 1977 | CAN_ERR | Indicates error condition | 1978 | CAN_BASIC_CAN_MAILBOX | Indicates that mailbox is configured for | 1979 | | Basic CAN operation | 1980 1981 Example: 1982 @code 1983 e51() 1984 { 1985 ... 1986 if (CAN_OK != MSS_CAN_send_message_abort_n(&g_mss_can_0_lo, 0)) 1987 { 1988 ... 1989 } 1990 ... 1991 } 1992 @endcode 1993 */ 1994 uint8_t 1995 MSS_CAN_send_message_abort_n 1996 ( 1997 mss_can_instance_t* this_can, 1998 uint8_t mailbox_number 1999 ); 2000 2001 /*-------------------------------------------------------------------------*//** 2002 The MSS_CAN_send_message_ready() function will identify the availability of 2003 mailbox to fill with new message in basic CAN operation. 2004 2005 @param this_can 2006 The this_can parameter is a pointer to the mss_can_instance_t structure. 2007 2008 @return 2009 This function returns CAN_OK on successful identification of free mailbox, 2010 otherwise it will returns following error codes: 2011 2012 | Constants | Description | 2013 |-----------------------|---------------------------------------------| 2014 | CAN_ERR | Indicates error condition | 2015 | CAN_INVALID_MAILBOX | Indicates invalid mailbox number | 2016 2017 Example: 2018 @code 2019 e51() 2020 { 2021 pmss_can_msgobject pmsg; 2022 ... 2023 pmsg.ID = 0x120; 2024 pmsg.DATALOW = 0x55555555; 2025 pmsg.DATAHIGH = 0x55555555; 2026 pmsg.L = ((0 << 20)| 0x00080000); 2027 2028 if(CAN_OK == MSS_CAN_send_message_ready(&g_mss_can_0_lo)) 2029 { 2030 MSS_CAN_send_message(&g_mss_can_0_lo, &pmsg); 2031 } 2032 ... 2033 } 2034 @endcode 2035 */ 2036 uint8_t 2037 MSS_CAN_send_message_ready 2038 ( 2039 mss_can_instance_t* this_can 2040 ); 2041 2042 /*-------------------------------------------------------------------------*//** 2043 The MSS_CAN_send_message() function will copy the data to the first available 2044 mailbox set for Basic CAN operation and send data on to the bus. 2045 Note: Since neither a hardware nor a software FIFO exists, message inversion 2046 might happen (example, a newer message might be send from the transmit 2047 buffer prior to an older message). 2048 2049 @param this_can 2050 The this_can parameter is a pointer to the mss_can_instance_t structure. 2051 2052 @param pmsg 2053 The pmsg parameter is a pointer to the message object that holds the CAN 2054 message to transmit. 2055 2056 @return 2057 This function returns CAN_OK on successful identification of free mailbox, 2058 otherwise it will returns following error codes: 2059 2060 | Constants | Description | 2061 |-----------------------|---------------------------------------------| 2062 | CAN_ERR | Indicates error condition | 2063 | CAN_INVALID_MAILBOX | Indicates invalid mailbox number | 2064 2065 Example: 2066 @code 2067 e51() 2068 { 2069 pmss_can_msgobject pmsg; 2070 ... 2071 pmsg.ID = 0x120; 2072 pmsg.DATALOW = 0x55555555; 2073 pmsg.DATAHIGH = 0x55555555; 2074 pmsg.L = ((0 << 20)| 0x00080000); 2075 2076 if (CAN_OK == MSS_CAN_send_message_ready(&g_mss_can_0_lo)) 2077 { 2078 if (CAN_OK != MSS_CAN_send_message(&g_mss_can_0_lo, &pmsg)) 2079 { 2080 ... 2081 } 2082 } 2083 ... 2084 } 2085 @endcode 2086 */ 2087 uint8_t 2088 MSS_CAN_send_message 2089 ( 2090 mss_can_instance_t* this_can, 2091 pmss_can_msgobject pmsg 2092 ); 2093 2094 /*-------------------------------------------------------------------------*//** 2095 The MSS_CAN_get_mask_n() function returns the message filter settings of the 2096 selected receive mailbox. The function is valid for Full CAN operation only. 2097 2098 @param this_can 2099 The this_can parameter is a pointer to the mss_can_instance_t structure. 2100 2101 @param mailbox_number 2102 The mailbox_number parameter is a variable to hold the mailbox number to 2103 be used for message transfer. 2104 2105 @param pamr 2106 The pamr parameter is a pointer to the acceptance mask. 2107 2108 @param pacr 2109 The pacr parameter is a pointer to the acceptance code. 2110 2111 @param pdta_amr 2112 The pdta_amr parameter is a pointer to the acceptance mask of first two 2113 data bytes. 2114 2115 @param pdta_acr 2116 The pdta_acr parameter is a pointer to the acceptance code of first two 2117 data bytes. 2118 2119 @return 2120 This function will returns the following error codes: 2121 2122 | Constants | Description | 2123 |-----------------------|---------------------------------------------| 2124 | CAN_OK | Indicates there is no error | 2125 | CAN_BASIC_CAN_MAILBOX | Indicates that mailbox is configured for | 2126 | | Basic CAN operation | 2127 2128 Example: 2129 @code 2130 e51() 2131 { 2132 ... 2133 2134 if (CAN_OK != MSS_CAN_get_mask_n(&g_mss_can_0_lo,mailbox_number,&pamr,&pacr, 2135 &pdamr, &pdacr)) 2136 { 2137 ... 2138 } 2139 ... 2140 } 2141 @endcode 2142 */ 2143 uint8_t 2144 MSS_CAN_get_mask_n 2145 ( 2146 mss_can_instance_t* this_can, 2147 uint8_t mailbox_number, 2148 uint32_t *pamr, 2149 uint32_t *pacr, 2150 uint16_t *pdta_amr, 2151 uint16_t *pdta_acr 2152 ); 2153 2154 /*-------------------------------------------------------------------------*//** 2155 The MSS_CAN_set_mask_n() function configures the message filter settings for 2156 the selected receive mailbox. The function is valid for Full CAN operation 2157 only. 2158 2159 @param this_can 2160 The this_can parameter is a pointer to the mss_can_instance_t structure. 2161 2162 @param mailbox_number 2163 The mailbox_number parameter is a variable to hold the mailbox number to 2164 be used for message transfer. 2165 2166 @param amr 2167 The amr parameter is a variable to hold the acceptance mask. 2168 2169 @param acr 2170 The acr parameter is a variable to hold the acceptance code. 2171 2172 @param dta_amr 2173 The dta_amr parameter is a variable to hold the acceptance mask of first two 2174 data bytes. 2175 2176 @param dta_acr 2177 The dta_acr parameter is a variable to hold the acceptance code of first two 2178 data bytes. 2179 2180 @return 2181 This function returns the following error codes: 2182 2183 | Constants | Description | 2184 |-----------------------|---------------------------------------------| 2185 | CAN_OK | Indicates there is no error | 2186 | CAN_BASIC_CAN_MAILBOX | Indicates that mailbox is configured for | 2187 | | Basic CAN operation | 2188 2189 Example: 2190 @code 2191 e51() 2192 { 2193 ... 2194 if (CAN_OK != MSS_CAN_set_mask_n(&g_mss_can_0_lo,mailbox_number,&pamr,&pacr, 2195 &pdamr, &pdacr)) 2196 { 2197 ... 2198 } 2199 ... 2200 } 2201 @endcode 2202 */ 2203 uint8_t 2204 MSS_CAN_set_mask_n 2205 ( 2206 mss_can_instance_t* this_can, 2207 uint8_t mailbox_number, 2208 uint32_t amr, 2209 uint32_t acr, 2210 uint16_t dta_amr, 2211 uint16_t dta_acr 2212 ); 2213 2214 /*-------------------------------------------------------------------------*//** 2215 The MSS_CAN_get_rx_buffer_status() function returns the buffer status of all 2216 receive (32) mailboxes. 2217 2218 @param this_can 2219 The this_can parameter is a pointer to the mss_can_instance_t structure. 2220 2221 @return 2222 This function returns status of receive buffers (32 buffers). 2223 2224 Example: 2225 @code 2226 e51() 2227 { 2228 uint32_t return_status=0; 2229 ... 2230 return_status = MSS_CAN_get_rx_buffer_status(&g_mss_can_0_lo); 2231 ... 2232 } 2233 @endcode 2234 */ 2235 uint32_t 2236 MSS_CAN_get_rx_buffer_status 2237 ( 2238 mss_can_instance_t* this_can 2239 ); 2240 2241 /*-------------------------------------------------------------------------*//** 2242 The MSS_CAN_get_tx_buffer_status() function returns the buffer status of all 2243 transmit(32) mailboxes. 2244 2245 @param this_can 2246 The this_can parameter is a pointer to the mss_can_instance_t structure. 2247 2248 @return 2249 This function returns status of transmit buffers (32 buffers). 2250 2251 Example: 2252 @code 2253 e51() 2254 { 2255 uint32_t return_status = 0; 2256 ... 2257 return_status = MSS_CAN_get_tx_buffer_status(&g_mss_can_0_lo); 2258 ... 2259 } 2260 @endcode 2261 */ 2262 uint32_t 2263 MSS_CAN_get_tx_buffer_status 2264 ( 2265 mss_can_instance_t* this_can 2266 ); 2267 2268 /*-------------------------------------------------------------------------*//** 2269 The MSS_CAN_get_error_status() function returns the present error state of 2270 the CAN controller. Error state might be error active or error passive or 2271 bus-off. 2272 2273 @param this_can 2274 The this_can parameter is a pointer to the mss_can_instance_t structure. 2275 2276 @param status 2277 The status parameter is a pointer to hold the content of error status 2278 register. 2279 2280 @return 2281 The function shall return the following codes: 2282 | Codes | Descriptions | 2283 |--------|-------------------------------| 2284 | 0 | error active | 2285 | 1 | error passive | 2286 | 2 | bus-off | 2287 2288 Example: 2289 @code 2290 e51() 2291 { 2292 uint8_t return_status = 0; 2293 ... 2294 return_status = MSS_CAN_get_error_status(&g_mss_can_0_lo); 2295 ... 2296 } 2297 @endcode 2298 */ 2299 uint8_t 2300 MSS_CAN_get_error_status 2301 ( 2302 mss_can_instance_t* this_can, 2303 uint32_t* status 2304 ); 2305 2306 /*-------------------------------------------------------------------------*//** 2307 The MSS_CAN_get_rx_error_count() function returns the current receive error 2308 counter value. Counter value ranges from 0x00 - 0xFF. 2309 2310 @param this_can 2311 The this_can parameter is a pointer to the mss_can_instance_t structure. 2312 2313 @return 2314 This function returns the receive error counter value. 2315 2316 Example: 2317 @code 2318 e51() 2319 { 2320 uint32_t return_status = 0; 2321 ... 2322 return_status = MSS_CAN_get_rx_error_count(&g_mss_can_0_lo); 2323 ... 2324 } 2325 @endcode 2326 */ 2327 uint32_t 2328 MSS_CAN_get_rx_error_count 2329 ( 2330 mss_can_instance_t* this_can 2331 ); 2332 2333 /*-------------------------------------------------------------------------*//** 2334 The MSS_CAN_get_rx_gte96() function provides information about receive 2335 error count. It identifies that receive error count is greater than or equal 2336 to 96, and reports 1 if count exceeds 96. 2337 2338 @param this_can 2339 The this_can parameter is a pointer to the mss_can_instance_t structure. 2340 2341 @return 2342 This function returns following values: 2343 2344 | Value | Description | 2345 |-------|------------------------------------------------------| 2346 | 0 | if receive error count less than 96. | 2347 | 1 | if receive error count greater than or equals to 96. | 2348 2349 Example: 2350 @code 2351 e51() 2352 { 2353 uint32_t return_status = 0; 2354 ... 2355 return_status = MSS_CAN_get_rx_gte96(&g_mss_can_0_lo); 2356 ... 2357 } 2358 @endcode 2359 */ 2360 uint32_t 2361 MSS_CAN_get_rx_gte96 2362 ( 2363 mss_can_instance_t* this_can 2364 ); 2365 2366 /*-------------------------------------------------------------------------*//** 2367 The MSS_CAN_get_tx_error_count() function returns the current transmit error 2368 counter value. Counter value ranges from 0x00 - 0xFF. 2369 2370 @param this_can 2371 The this_can parameter is a pointer to the mss_can_instance_t structure. 2372 2373 @return 2374 This function returns the transmit error counter value. 2375 2376 Example: 2377 @code 2378 e51() 2379 { 2380 uint32_t return_status = 0; 2381 ... 2382 return_status = MSS_CAN_get_tx_error_count(&g_mss_can_0_lo); 2383 ... 2384 } 2385 @endcode 2386 */ 2387 uint32_t 2388 MSS_CAN_get_tx_error_count 2389 ( 2390 mss_can_instance_t* this_can 2391 ); 2392 2393 /*-------------------------------------------------------------------------*//** 2394 The MSS_CAN_get_tx_gte96() function provides information about transmit 2395 error count. It identifies that transmit error count is greater than or equals 2396 to 96, and reports 1 if count exceeds 96. 2397 2398 @param this_can 2399 The this_can parameter is a pointer to the mss_can_instance_t structure. 2400 2401 @return 2402 This function returns following values: 2403 2404 | Value | Description | 2405 |-------|-------------------------------------------------------| 2406 | 0 | if transmit error count less than 96. | 2407 | 1 | if transmit error count greater than or equals to 96. | 2408 2409 Example: 2410 @code 2411 e51() 2412 { 2413 uint32_t return_status = 0; 2414 ... 2415 return_status = MSS_CAN_get_tx_gte96(&g_mss_can_0_lo); 2416 ... 2417 } 2418 @endcode 2419 */ 2420 uint32_t 2421 MSS_CAN_get_tx_gte96 2422 ( 2423 mss_can_instance_t* this_can 2424 ); 2425 2426 #ifdef __cplusplus 2427 } 2428 #endif 2429 2430 #endif /* MSS_CAN_H_ */ 2431