MCUSW
|
This document details AUTOSAR BSW CAN module implementation
The CAN driver provides services for basic transmission and reception of CAN frames in both interrupt and polling mode. These components can be used by an application.
Please refer the CAN design, which is included as part of CSP (Compliance Support Package).
The CAN module initializes and controls the internal CAN Controllers of the microcontroller. It provides services to write, read, and configure mailboxes of the Can controllers
Programming of clock source for the can, is beyond the scope of this document. The driver expects user of this module has programmed required clock source.
16 CAN instances are supported on J7ES and 20 on J7VCL/J7AEP/J7AHP by this driver implementation (2 instances in MCU domain and rest in MAIN domain).
3 CAN instances are supported on AM62X(2 instances in MCU domain and 1 instances in MAIN domain) and 2 CAN instances supported on AM62AX(2 instances in MCU domain).
2 CAN instances supported on J7AEN(2 instances in MCU domain).
2 CAN instances supported on AM62PX(2 instances in MCU domain).
The following table lists the mapping between instance of can and controllerId of the configurator
CAN Instance Id | Can Instance | Associated ISR |
---|---|---|
0 | MCU CAN 0 | Can_0_Int0ISR (AM62X/AM62AX/J7AEN/AM62PX) |
1 | MCU CAN 1 | Can_1_Int0ISR (AM62X/AM62AX/J7AEN/AM62PX) |
2 | MAIN CAN 0 | Can_2_Int0ISR (AM62X) |
3 | MAIN CAN 1 | Can_3_Int0ISR |
4 | MAIN CAN 2 | Can_4_Int0ISR |
5 | MAIN CAN 3 | Can_5_Int0ISR |
6 | MAIN CAN 4 | Can_6_Int0ISR |
7 | MAIN CAN 5 | Can_7_Int0ISR |
8 | MAIN CAN 6 | Can_8_Int0ISR |
9 | MAIN CAN 7 | Can_9_Int0ISR |
10 | MAIN CAN 8 | Can_10_Int0ISR |
11 | MAIN CAN 9 | Can_11_Int0ISR |
12 | MAIN CAN 10 | Can_12_Int0ISR |
13 | MAIN CAN 11 | Can_13_Int0ISR |
14 | MAIN CAN 12 | Can_14_Int0ISR |
15 | MAIN CAN 13 | Can_15_Int0ISR |
16 | MAIN CAN 14 | Can_16_Int0ISR (J7VCL/J7AEP/J7AHP) |
17 | MAIN CAN 15 | Can_17_Int0ISR (J7VCL/J7AEP/J7AHP) |
18 | MAIN CAN 16 | Can_18_Int0ISR (J7VCL/J7AEP/J7AHP) |
19 | MAIN CAN 17 | Can_19_Int0ISR (J7VCL/J7AEP/J7AHP) |
The CAN Driver implementation supports multiple configuration variants (refer section Introduction), the driver expects generated Can_Cfg.h to be present as (File Structure). Please refer (Build) to specify path to generated configuration. The associated can configuration generated files Can_Cfg.c and Can_PBcfg.c to be present as show (File Structure)
NOTE: Always use configurator tool for MCAL configuration generation.
The following section details on the un-supported features and additional features added.
Wakeup functionality is not supported, this configuration parameter will NOT enable Can Wakeup Functionality.
Wakeup functionality is not supported, this configuration parameter will NOT enable Can Wakeup Functionality.
ICOM feature is not supported and CanIcomGeneral configuration parameters are not supported.
TTCAN feature is not supported and hence CanIfSupportTTCAN parameter is not supported.
The optional trigger-transmit API's are not supported in this release.
The optional configuration parameter CanLPduReceiveCalloutFunction is not supported in this release.
Can_ChangeBaudrate API's cannot be turned OFF via CAN_CHANGE_BAUDRATE_API.
SWS_Can_00442 states that The API name of Can_MainFunction_Read() shall obey the following pattern:
Similarly same w.r.o requirement SWS_Can_00441.
In function Can_SetControllerMode if maximum time CanTimeoutDuration is elapsed, DEM error CAN_E_HARDWARE_ERROR is reported.(Refer SWS_Can_00372 for details).
Can_SetControllerMode(CAN_T_WAKEUP) will not wait for a "limited time" and will update the state to STOPPED immediately. (Refer SWS_Can_00268 for details).
This driver implementation introduces below listed configurable options
Please refer the CAN design section NON Standard configurable parameters (Refer to Design Document provided in CSP).
As noted from the previous MCAL implementation, some of the critical configuration registers could potentially be corrupted by other entities (s/w or h/w). One of the recommended detection methods would be to periodically read-back the configuration and confirm configuration is consistent. The service API defined below shall be implemented to enable this detection
Description | Comments | |
Service Name | Can_RegisterReadback | Can potentially be turned OFF (Refer to Design Document provided in CSP) |
Syntax | uint32 Can_RegisterReadback ( Can_HWUnitType HWUnit, P2VAR(Can_RegisterReadbackType, AUTOMATIC, CAN_APPL_DATA) RegRbPtr) | E_OK: Register read back has been done, E_NOT_OK: Register read back failed |
Service ID | NA | |
Sync / Async | Sync | |
Reentrancy | Reentrant | |
Parameter in | HWUnit | CAN Hardware microcontroller peripheral unit ID. If this is invalid, then the API will return E_NOT_OK. |
Parameters out | RegRbPtr - Pointer to where to store the readback values. If this pointer is NULL_PTR, then the API will return E_NOT_OK. | |
Return Value | Std_ReturnType | E_OK, E_NOT_OK |
This service will enable CAN loopback mode.
Description | Comments | |
Service Name | Can_TestLoopBackModeEnable | Can potentially be turned OFF (Refer to Design Document provided in CSP) |
Syntax | uint32 Can_TestLoopBackModeEnable(uint8 Controller, uint8 Mode) | |
Service ID | 18 | |
Sync / Async | Sync | |
Reentrancy | Reentrant | |
Parameter in | Controller | CAN Controller to enable loopback mode. |
Parameter in | Mode | Mode : 0 - Digital Loopback, 1 - Analog Loopback |
Return Value | Std_ReturnType | E_OK : Loopback enable successfully E_NOT_OK : Loopback enable failed |
The Driver doesn’t register any interrupt service routine(ISR), it’s expected that consumer of this driver registers the required interrupt handler.
For every CAN instance an ISR needs to be registered. The Interrupt number associated with instance of the CAN is detailed in TRM. Please refer CanApp_InterruptConfig () in CAN demo application.
Refer section (CAN Instance ID mapping and ISR mapping), for association between instance ID and ISR
The driver doesn't configure the functional clock and power for the CAN modules. It's expected that secondary boot loader(SBL) power-up the required modules. Please refer SBL documentation.
Please follow steps detailed in section (Build) to build library or example
Please follow steps detailed in section (Build) to build example
Various objects of this implementation (e.g. variables, functions, constants) are defined under different sections. The linker command file at (Examples Linker File (Select memory location to hold example binary)) defines separate section for these objects. When the driver is integrated, its expected that these sections are created and placed in appropriate memory locations. (Locations of these objects depend on the system design and performance needs)
Section | CAN_CODE | CAN_VAR | CAN_VAR_NOINIT | CAN_CONST | CAN_CONFIG |
CAN_START_SEC_VAR_INIT_UNSPECIFIED (.data) | USED | ||||
CAN_DATA_INIT_32_SECTION | USED | ||||
CAN_TEXT_SECTION | USED | ||||
CAN_DATA_NO_INIT_UNSPECIFIED_SECTION | USED | ||||
CAN_CONST_32_SECTION | USED | ||||
CAN_ISR_TEXT_SECTION | USED | ||||
CAN_CONFIG_SECTION | USED |
NOTE: It is adviced to use of MPU at the OS level verification through the use of System level Testing. Check Autosar recommendation memory segment placements are followed.
This driver implementation has been validated with cache enabled. For optimal performance it’s recommended to place (Memory Mapping) sections in cache enabled memory area.
NOTE: Pin Muxing should be initialized before initializing the Can module.
This implementation depends on the DET in order to report development errors and can be turned OFF. Refer section (Development Error Reporting) for detailed error codes.
This implementation requires one level of exclusive access to guard critical sections. Invokes SchM_Enter_Can_CAN_EXCLUSIVE_AREA_0 (), SchM_Exit_Can_CAN_EXCLUSIVE_AREA_0 () to enter critical section and exit.
In the example implementation (File Structure SchM_Can.c) , all the interrupts on CPU are disabled. However, disabling of the enabled CAN interrupt should suffice.
NOTE: Interrupts required for error detection shall be enabled all the time.
Development errors are reported to the DET using the service Det_ReportError(), when enabled. The driver interface (Can.h File Structure) lists the SID
Production error are reported to DEM via the service DEM_ReportErrorStatus(). In addition to standard errors, this implementation reports "CAN_E_HARDWARE_ERROR" when CAN hardware register read/write fails.
The AUTOSAR BSW Can Driver specification details the APIs required for Can Driver. Please refer to (Refer to Design Document provided in CSP) for detailed API description. Also refer to (Non Standard Service APIs) for non-standard APIs which are included in this implemented.
Refer API Documentation for details Back To Top
The example application demonstrate use of CAN module, the list below identifies key steps performed the example. The configuration file is present at (File Structure)
NOTE: Connect the external CAN Transceiver to CAN instance. Please note that for internal loopback testing this is not applicable.
[MCU_R5FSS0_0] CAN_APP: Sample Application - STARTS !!! CAN_APP: Variant - Pre Compile being used !!! CAN_APP: Message Id Received 400000a0 Message Length is 64 CAN_APP: Can Controller Instance MCAN 0 Internal LoopBack Mode Test Passed CAN_APP: Message Id Received 400000a0 Message Length is 64 CAN_APP: Can Controller Instance MCAN 0 Internal LoopBack Mode Test Passed CAN_APP: Message Id Received 400000c0 Message Length is 64 CAN_APP: Can Controller Instance MCAN 1 Internal LoopBack Mode Test Passed CAN_APP: Message Id Received 400000c0 Message Length is 64 CAN_APP: Can Controller Instance MCAN 1 Internal LoopBack Mode Test Passed CAN_APP: Safety Diagnostic API functionality test for controller MCAN 0 CAN_APP: Can_EnableIntr() API test CAN_APP: Successfully Enabled TOO interrupt CAN_APP: Successfully Enabled PEA interrupt CAN_APP: Can_GetIntrStatus() API test CAN_APP: No error event occured CAN_APP: Can_ClearIntrStatus() API test CAN_APP: Interrupt Status Clear Successful CAN_APP: Can_DisableIntr() API test CAN_APP: Successfully Disable TOO interrupt CAN_APP: Successfully Disable PEA interrupt CAN_APP: Can_RegisterReadback() API test CAN_APP: Can_RegisterReadback Successful CAN_APP: Safety Diagnostic API functionality test for controller MCAN 1 CAN_APP: Can_EnableIntr() API test CAN_APP: Successfully Enabled TOO interrupt CAN_APP: Successfully Enabled PEA interrupt CAN_APP: Can_GetIntrStatus() API test CAN_APP: No error event occured CAN_APP: Can_ClearIntrStatus() API test CAN_APP: Interrupt Status Clear Successful CAN_APP: Can_DisableIntr() API test CAN_APP: Successfully Disable TOO interrupt CAN_APP: Successfully Disable PEA interrupt CAN_APP: Can_RegisterReadback() API test CAN_APP: Can_RegisterReadback Successful CAN Stack Usage: 2932 bytes CAN_APP: CAN Test Passed!!!