协同睡眠管理的集群,可以关联多个NmChannels(A cluster for coordinated sleep management can be associated with multiple NmChannels)
NmActiveCoordinator
指示某个channel在协同睡眠集群中是主动协同还是被动协同(Indicates whether a certain channel is an active coordinator or a passive coordinator in the coordinated sleep cluster)
topmost
如果一个集群内的所有channel的NmActiveCoordinator都配置为TRUE,那么这个集群就被称为topmost,用于嵌套网络(If the NmActiveCoordinator of all channels in a cluster is configured as TRUE, then this cluster is called topmost, which is used for nested networks)
The NmIf module serves as an adaptation layer between the AUTOSAR ComM module and bus-specific network management modules (such as CAN network management and Ethernet network management). Another function of NmIf is coordination. The NM coordinator function used by gateway ECUs can synchronously shut down one or more buses. When all networks in the coordination cluster are ready to enter sleep state or are already in bus sleep mode, the NM coordinator shall initiate coordinated shutdown on all awakened networks. The purpose of coordinated shutdown is to synchronously shut down the awakened networks in the cluster. Support for the NmIf coordination function is optional. NmIf can support only the basic function, or both the basic function and the NM coordination function.
The Nm module implements its basic functions by calling interfaces of the BusNm module and the ComM module. Taking the network request function as an example: when ComM needs to request a network, it calls the network request API of the Nm module. The Nm module then calls the corresponding bus-specific network request API, thereby simplifying network requests from the upper layer for different bus types.
When NmCoordinatorSupportEnabled is enabled, the Nm module activates the network coordination function. The NM coordinator function employs a coordination algorithm to coordinate the NM on one or more independent clusters of buses connected to the ECU, enabling their coordinated shutdown. The purpose of coordinated shutdown is to ensure that all networks corresponding to channels in the current cluster shut down as simultaneously as possible. If some channels in the cluster have not yet released the network, it is necessary to ensure that all channels in the cluster are requesting the network.
Coordinated shutdown can only be performed on currently awakened networks within the coordination cluster. Networks already in “bus sleep mode” should still be monitored but cannot participate in coordination. The bus-specific Nm indicates whether a bus is ready to enter sleep mode by calling the callback functions Nm_RemoteSleepIndication and Nm_RemoteSleepCancellation. The local ECU uses the API functions Nm_NetworkRelease and Nm_NetworkRequest to indicate whether the underlying layer is ready to enter the ReadySleep state. If a channel is configured as SleepMaster, the Nm coordinator considers that the bus can enter sleep mode at any time without waiting for a call to Nm_RemoteSleepIndication.
非嵌套子网的协调关闭过程如下:当ComM调用Nm_NetworkRelease函数,
请求释放网络时,这个时候Nm 协调功能并不会调用 BusNm 的
BusNm_NetworkRelease 函数释放网络,而是需要在接收到
Nm_RemoteSleepIndication 的函数通知后,启动协调关闭定时器计时。协调关闭
定时器的作用是,如果各总线配置的从Readysleep状态进入到BusSleep状态的
时间不一样,协调关闭定时器可以做为一个补充定时器,以达到使各总线同步进
入休眠状态。定时器应设置为NmGlobalCoordinatorTime。 如果 NmBusType 未设
置为NM_BUSNM_LOCALNM,则应减去特定通道TSHUTDOWN_CHANNEL
的关闭时间。如果NmGlobalCoordinatorTime 为零,则所有通道的关闭延迟计时
器也应为零。当定时器超时后,Nm会调用BusNm_RequestBusSynchronization函
数,然后调用BusNm_NetworkRelease 函数释放底层网络。
TSHUTDOWN_CHANNEL时间计算:
CanNm: Ready Sleep Time + Prepare BusSleep Time
UdpNm: Ready Sleep Time + Prepare BusSleep Time
The coordinated shutdown process for non-nested subnets is as follows: When ComM calls the Nm_NetworkRelease function to request network release, the Nm coordination function does not immediately call the BusNm_NetworkRelease function of BusNm to release the network. Instead, it starts the coordinated shutdown timer after receiving notification via the Nm_RemoteSleepIndication function. The coordinated shutdown timer serves as a supplementary timer if the time required for different buses to transition from the ReadySleep state to the BusSleep state varies, ensuring that all buses enter the sleep state synchronously. The timer should be set to NmGlobalCoordinatorTime. If NmBusType is not set to NM_BUSNM_LOCALNM, the shutdown time of the specific channel TSHUTDOWN_CHANNEL should be subtracted. If NmGlobalCoordinatorTime is zero, the shutdown delay timers for all channels should also be zero. When the timer expires, Nm calls the BusNm_RequestBusSynchronization function, followed by the BusNm_NetworkRelease function to release the underlying network.
TSHUTDOWN_CHANNEL time calculation:
CanNm: Ready Sleep Time + Prepare BusSleep Time
UdpNm: Ready Sleep Time + Prepare BusSleep Time
The coordinated shutdown process for nested subnets is as follows: A nested subnet has a topmost coordinator responsible for initiating coordinated shutdowns by other coordinators. In configuration terms, a topmost coordinator is characterized by having NmActiveCoordinator set to TRUE for all channels in the cluster. (NmActiveCoordinator = TRUE indicates an ActiveCoordinator channel; NmActiveCoordinator = FALSE indicates a PassiveCoordinator channel.) Other non-topmost coordinators have only one ActiveCoordinator channel, with the remaining channels being PassiveCoordinator channels. When the topmost coordinator meets the conditions for coordinated shutdown, it calls the BusNm_SetSleepReadyBit function on all its channels to set the coordinated sleep ready bit to 1 (Bit3 = 1 in CBV). When other coordinators receive the coordinated shutdown instruction on their PassiveCoordinator channels, they forward the instruction on all their ActiveCoordinator channels.
In summary, for non-topmost nodes, the conditions for all networks in the coordinated cluster of a nested subnet to be ready to enter the sleep state are:
The channel with NmActiveCoordinator = TRUE receives the RemoteSleepIndication notification from the underlying BusNm and the network management message with Bit3 = 1 in CBV (Bit3 is the coordinated sleep ready bit).
For both nested and non-nested subnets, coordinated shutdown must be terminated if any network in the NM coordination cluster displays any of the following behaviors:
BusNm module calls Nm_RemoteSleepCancellation(), which occurs when a message is received while BusNm is in Normal Operation State or Ready Sleep State.
If coordinated shutdown is aborted for any reason, the NM Coordinator must call the <BusNm>_SetSleepReadyBit API on all active coordination channels to set the NMCoordinatorSleepReady bit to UNSET (0).
If Nm_CoordReadyToSleepCancellation() is received on a passive coordination channel, the NmCoordinator must set the NMCoordinatorSleepReady bit to UNSET (0) by calling the <BusNm>_SetSleepReadyBit API on all active coordination channels.
If coordinated shutdown is aborted and BusNmType is not set to NM_BUSNM_LOCALNM, the NM Coordinator must request the network for networks that have not reported “bus sleep”.
PNC stands for Partial Network Cluster, referring to a cluster composed of multiple ECUs designed to support one or more vehicle functions within the vehicle network. A PNC bit value of 1 indicates that the corresponding PN network is currently requested, while 0 indicates network release.
By configuring the NmPnFilterMaskByte parameter, Nm can determine which PN is relevant to the ECU and which is not.
Each bit in NmPnFilterMaskByte has the following meaning:
0: The PN request is irrelevant to this ECU. Even if this bit is set to 1 in the received NM PDU, it cannot wake up the ECU’s communication stack because the request represented by this bit is irrelevant to the ECU.
1: The PN request is relevant to this ECU. If this bit is set to 1 in the received NM-PDU, the ECU’s communication stack will remain in the wake-up state.
If at least one PN request bit relevant to the ECU is set, this Nm PDU is considered useful by Nm and must be processed. If no PN request bits relevant to the ECU are set, this NM PDU will be ignored.
ERA (External Request Array) refers to the aggregation of PN requests external to the ECU. When NmPnEraCalcEnabled is enabled (a configuration parameter), it indicates ERA function support. EIRA (External and Internal Request Array) refers to the aggregation of both internal and external PN requests of the ECU. When NmPnEiraCalcEnabled is enabled (a configuration parameter), it indicates EIRA function support.
ERA is specifically used in gateway nodes, where there are no internal requests, only external PN requests from different Channels. ERA maintains a monitoring timer for each PN bit of each channel. If no PN request is received within the NmPnResetTime (a configuration parameter), the request status for that PN is set to “not requested”. The upper-layer ComM is notified whenever the request status changes.
EIRA reflects the request and release status of a specific PNC by the current node and other nodes on the network. EIRA does not distinguish between physical channels and operates only on different PNs. EIRA maintains a monitoring timer for each PN bit. If no PN request is received within the NmPnResetTime duration (a configuration parameter), the request status for that PN is set to “not requested”. The upper-layer ComM is notified whenever there is a change in the request status.
具体流程可参考下图:
For detailed procedures, please refer to the following diagrams:
Get the whole PDU data out of the most recently received NM message. For that purpose <BusNm>_GetPduData shall be called in case NmBusType is not set to NM_BUSNM_LOCALNM. (e.g. CanNm_GetPduData function is called if channel is configured as CAN).
Sync/Async
Synchronous
Reentrancy
Reentrant (Non-reentrant for the same NetworkHandle, reentrant otherwise)
Parameters
Dir
Name
Description
[in]
networkHandle
Identification of the NM-channel
[out]
nmPduData
Pointer where NM PDU shall be copied to.
Return type
Std_ReturnType
Return values
Name
Description
E_OK
No error
E_NOT_OK
Getting of NM PDU data has failed NetworkHandle does not exist (development only) Module not yet initialized (development only)
Set Repeat Message Request Bit for NM messages transmitted next on the bus. For that purpose <Bus>Nm_RepeatMessageRequest shall be called in case NmBusType is not set to NM_BUSNM_LOCALNM. (e.g. CanNm_RepeatMessageRequest function is called if channel is configured as CAN). This will force all nodes on the bus to transmit NM messages so that they can be identified.
Sync/Async
Synchronous
Reentrancy
Reentrant (Non-reentrant for the same networkHandle, reentrant otherwise)
Parameters
Dir
Name
Description
[in]
networkHandle
Identification of the NM-channel
Return type
Std_ReturnType
Return values
Name
Description
E_OK
No error
E_NOT_OK
Setting of Repeat Message Request Bit has failed networkHandle does not exist (development only) Module not yet initialized (development only)
Get node identifier out of the last successfully received NM-message. The function <Bus>Nm_GetNodeIdentifier shall be called in case NmBusType is not set to NM_BUSNM_LOCALNM. (e.g. CanNm_GetNodeIdentifier function is called if channel is configured as CAN).
Sync/Async
Synchronous
Reentrancy
Reentrant (Non-reentrant for the same NetworkHandle, reentrant otherwise)
Parameters
Dir
Name
Description
[in]
networkHandle
Identification of the NM-channel
[out]
nmNodeIdPtr
Pointer where node identifier out of the last successfully received NM-message shall be
Return type
Std_ReturnType
Return values
Name
Description
E_OK
No error
E_NOT_OK
Getting of the node identifier out of the last received NM-message has failed NetworkHandle does not exist (development only) Module not yet initialized (development only)
Get node identifier configured for the local node. For that purpose <Bus>Nm_GetLocalNodeIdentifier shall be called in case NmBusType is not set to NM_BUSNM_LOCALNM. (e.g. CanNm_GetLocalNodeIdentifier function is called if channel is configured as CAN).
Sync/Async
Synchronous
Reentrancy
Reentrant (Non-reentrant for the same NetworkHandle, reentrant otherwise)
Parameters
Dir
Name
Description
[in]
networkHandle
Identification of the NM-channel
[out]
nmNodeIdPtr
Pointer where node identifier out of the last successfully received NM-message shall be copied to
Return type
Std_ReturnType
Return values
Name
Description
E_OK
No error
E_NOT_OK
Getting of the node identifier of the local node has failed NetworkHandle does not exist (development only) Module not yet initialized (development only)
Returns the state of the network management. The function <Bus>Nm_GetState shall be called in case NmBusType is not set to NM_BUSNM_LOCALNM. (e.g. CanNm_GetState function is called if channel is configured as CAN).
Sync/Async
Synchronous
Reentrancy
Reentrant (Non-reentrant for the same NetworkHandle, reentrant otherwise)
Parameters
Dir
Name
Description
[in]
nmNetworkHandle
Identification of the NM-channel
[out]
nmStatePtr
Pointer where state of the network management
[out]
nmModePtr
Pointer to the location where the mode of the network management shall be copied to
Return type
Std_ReturnType
Return values
Name
Description
E_OK
No error
E_NOT_OK
Getting of NM state has failed NetworkHandle does not exist (development only) Module not yet initialized (development only)
Notification that a NM-message has been received in the Bus-Sleep Mode, what indicates that some nodes in the network have already entered the Network Mode.
Notification that a NM-message has been received in the Bus-Sleep Mode, what indicates that some nodes in the network have already entered the Network Mode.
This function shall perform the processing of the AUTOSAR ComM activities that are not directly initiated by
the calls. e.g. from the RTE. There shall be one dedicated Main Function for each channel of ComM.
Notification that the network management has entered Bus-Sleep Mode. This callback function should perform a transition of the hardware and
transceiver to bus-sleep mode.
ComM_Nm_NetworkMode
ComM_Nm.h
Notification that the network management has entered Network Mode.
ComM_Nm_NetworkStartIndication
ComM_Nm.h
Indication that a NM-message has been received in the Bus Sleep Mode, what indicates that some nodes in the network have already entered the Network Mode.
ComM_Nm_PrepareBusSleepMode
ComM_Nm.h
Notification that the network management has entered Prepare Bus-Sleep Mode. Reentrancy: Reentrant (but not for the same NM-Channel).
ComM_Nm_RestartIndication
ComM_Nm.h
If NmIf has started to shut down the coordinated busses, AND not all coordinated busses have indicated bus sleep state, AND on at least on one of the coordinated busses NM is restarted, THEN the
NM Interface shall call the callback function ComM_Nm_RestartIndication with the nmNetworkHandle of the channels which have already indicated bus sleep state.
Passive startup of the AUTOSAR CAN NM. It triggers the transition from Bus-Sleep Mode or Prepare Bus Sleep Mode to the Network Mode in Repeat Message State.
Caveats: CanNm is initialized correctly.
Com_SendSignal
Com.h
The service Com_SendSignal updates the signal object identified by SignalId with the signal referenced by the SignalDataPtr parameter.
Det_ReportError
Det.h
Service to report development errors.
FrNm_PassiveStartUp
FrNm.h
Initiates the Passive Startup of the FlexRay NM.
J1939Nm_PassiveStartUp
J1939Nm.h
Passive startup of the NM. It triggers the transition from Bus-Sleep Mode to the Network Mode without requesting the network.
UdpNm_PassiveStartUp
UdpNm.h
Passive startup of the AUTOSAR UdpNm. It triggers the transition from Bus-Sleep Mode or Prepare Bus Sleep Mode to the Network Mode in Repeat Message State.
Caveats: UdpNm is initialized correctly.
Although multiple coordinated sleep clusters (CoordinateCluster) can be configured, each Nm channel can only be associated with one coordinated sleep cluster.
A coordinated sleep cluster (CoordinateCluster) must contain at least one channel with NmActiveCoordinator set to TRUE. If all channels in a coordinated sleep cluster are active coordinator channels, the cluster is designated as topMost. If a coordinated sleep cluster contains any non-active coordinator (i.e., passive) channels, the cluster is classified as non-topMost.
在配置通道之前,需要进行Nm的全局配置:
Before configuring individual channels, Nm global configuration must be completed:
Nm全局配置支持协同睡眠(Nm Global Configuration Supporting Coordinated Sleep)¶
NmCoordinatorSupportEnabled enables the coordinated sleep function, while NmCoordinatorSyncSupport controls coordinated sleep nesting. Coordinated sleep nesting refers to the coordinated sleep network topology across multiple ECUs. When enabled, coordination operates at the ECU level rather than just the channel level, ensuring simultaneous sleep for channels across multiple ECUs.
Coordinated sleep requires configuration of multiple Nm channels, associating them with corresponding ComM channels. It is essential to define each channel’s coordination mode (NmActiveCoordinator), specify the associated NmCoordClusterIndex, and determine whether it functions as a NmChannelSleepMaster.
Channel 3 is configured as NmChannelSleepMaster. This parameter indicates whether sleep for this network can be determined solely by the local node without intervention from other nodes.
If set to TRUE, Nm assumes the channel is always ready to enter sleep mode, and the Nm for this channel will not issue calls to Nm_RemoteSleepIndication or NmRemoteSleepCancellation. If set to FALSE, Nm assumes the network is not ready for sleep until the Nm_RemoteSleepIndication call has been issued.