The basic function of NmIf is to serve as an adaptation layer between the AUTOSAR ComM module and AUTOSAR bus-specific network management modules (such as CAN network management and Ethernet network management). Another function of NmIf is the coordination function. 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 the sleep state or are already in the bus sleep mode, the NM coordinator shall initiate a coordinated shutdown on all awakened networks. The purpose of the 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 principle by which the Nm module accomplishes its basic functions is through calling the interfaces of the BusNm module and the ComM module. Taking the network request function as an example, when the ComM needs to request a network, it calls the network request API of the Nm module, and 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 activated, the Nm enables the network coordination function. The NM coordinator function is a function that uses a coordination algorithm to coordinate the NM on all or 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 the currently awakened networks in the coordination cluster. Networks already in “bus sleep mode” should still be monitored but cannot be coordinated. The bus-specific Nm will indicate whether the bus is ready to enter sleep mode by calling the callback functions Nm_RemoteSleepIndication and Nm_RemoteSleepCancellation. The local ECU will use 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 the call of 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 the 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 the notification from the Nm_RemoteSleepIndication function. The role of the coordinated shutdown timer is to serve as a supplementary timer if the time taken by each bus to transition from the ReadySleep state to the BusSleep state is different, 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, the Nm will call 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 will have a topmost coordinator responsible for initiating coordinated shutdowns by other coordinators. In terms of configuration, a topmost coordinator is characterized by all channels in the cluster having NmActiveCoordinator configured as TRUE. (NmActiveCoordinator = TRUE indicates an ActiveCoordinator channel; NmActiveCoordinator = FALSE indicates a PassiveCoordinator channel.) Other non-topmost coordinators have only one ActiveCoordinator channel, with the rest being PassiveCoordinator channels. When the topmost coordinator meets the conditions for coordinated shutdown, it will call 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 will 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 instruction from the underlying BusNm and the notification instruction of the network management message with Bit3 = 1 in CBV (Bit3 is the coordinated sleep ready bit).
The channel with NmActiveCoordinator = FALSE receives the notification instruction of the network management message with Bit3 = 1 in CBV (Bit3 is the coordinated sleep ready bit).
For both nested and non-nested subnets, the coordinated shutdown shall be aborted if any network in the NM coordination cluster exhibits the following behaviors:
The BusNm module calls Nm_RemoteSleepCancellation(), which occurs when a message is received again while BusNm is in the Normal Operation State or Ready Sleep State.
If the coordinated shutdown is aborted for any reason, the NM Coordinator shall 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 passively coordinated channel, the NmCoordinator shall set the NMCoordinatorSleepReady bit to UNSET (0) by calling the <BusNm>_SetSleepReadyBit API on all actively coordinated channels.
If the coordinated shutdown is aborted, and BusNmType is not set to NM_BUSNM_LOCALNM, the NM Coordinator shall request the network for networks that have not indicated “bus sleep”.
PNC is the abbreviation of Partial Network Cluster, which refers to a cluster composed of multiple ECUs to support one or more vehicle functions in the vehicle network. A PNC corresponding to a bit value of 1 indicates that the current PN network is requested; a value of 0 indicates that the network is released.
By configuring the parameter NmPnFilterMaskByte, Nm can detect which PN is related to the ECU and which is not.
Each bit of NmPnFilterMaskByte has the following meanings:
0: The PN request is irrelevant to the ECU. If this bit is set to 1 in the received NM PDU, it cannot wake up the ECU’s communication stack because the request of this bit is irrelevant to the ECU.
1: The PN request is relevant to the 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 there is at least one PN request related to the ECU, this Nm PDU is useful for Nm and needs to be processed; if there is no PN request related to the ECU, this NM PDU will be ignored.
ERA refers to the aggregation of PN requests external to the ECU. When NmPnEraCalcEnabled is enabled (a configuration parameter), it indicates support for the ERA function. EIRA refers to the aggregation of internal and external Pn requests of the ECU. When NmPnEiraCalcEnabled is enabled (a configuration parameter), it indicates support for the EIRA function.
ERA is only used in gateway nodes, where there are no internal requests, only external PN requests from different Channels. ERA will set a monitoring timer for each PN bit of each channel. If no PN is requested within the NmPnResetTime (a configuration parameter), the request status of that PN will be set to unrequested, and the upper layer ComM will be notified whenever the request status changes.
EIRA reflects the request and release status of a certain PNC by the current node and other nodes on the network; EIRA does not distinguish between physical Channels, only targeting different PNs. EIRA will set a monitoring timer for each PN bit. If no PN is requested within the NmPnResetTime (a configuration parameter), the request status of that PN will be set to unrequested, and the upper layer ComM will be notified whenever the request status changes.
EIRA reflects the status of requests for and releases of a specific PNC by the current node and other nodes on the network; EIRA does not distinguish between physical channels and only targets different PNs. EIRA will set a monitoring timer for each PN bit. If no PN is requested within the duration of NmPnResetTime (a configuration parameter), the request status of that PN will be set to “unrequested”. The upper-layer ComM will be notified whenever there is a change in the request status.
具体流程可参考下图:
Please refer to the following figure for the specific process:
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, the same Nm channel can only be associated with a coordinated sleep cluster (Cluster) once.
A coordinated sleep cluster (CoordinateCluster) must have at least one channel with NmActiveCoordinator set to TRUE. If all channels in a coordinated sleep cluster are active coordinator channels, the cluster is called topMost.
If a coordinated sleep cluster contains non-active coordinator (i.e., passive) channels, the cluster is non-topMost.
在配置通道之前,需要进行Nm的全局配置:
Before configuring channels, global configuration of Nm is required:
NmCoordinatorSupportEnabled is the switch to enable coordinated sleep, and NmCoordinatorSyncSupport is whether to enable coordinated sleep nesting. Coordinated sleep nesting refers to the coordinated sleep network topology of multiple ECUs. When enabled, coordination is no longer based only on channels but on ECUs. In short, it ensures that channels on multiple ECUs sleep simultaneously.
Coordinated sleep requires configuring multiple Nm channels, associating them with corresponding ComM channels, and clearly defining whether the channel’s coordination mode is NmActiveCoordinator, specifying the associated NmCoordClusterIndex, and whether it is a NmChannelSleepMaster.
Channel 3 is configured with NmChannelSleepMaster. This parameter should be set to indicate whether the sleep of this network can be determined solely by the local node itself, with no other nodes able to intervene.
If this parameter is set to TRUE, Nm shall assume that the channel is always ready to enter sleep mode, and the Nm of this channel will not issue calls to Nm_RemoteSleepIndication or Nm_RemoteSleepCancellation. If this parameter is set to FALSE, Nm assumes that the network is not ready to sleep until the Nm_RemoteSleepIndication call has been issued.