]> rtime.felk.cvut.cz Git - arc.git/blob - communication/Nm/Nm.c
Added support for LIN on MPC5567. Also make it possible to build a standalone LIN...
[arc.git] / communication / Nm / Nm.c
1 /* -------------------------------- Arctic Core ------------------------------\r
2  * Arctic Core - the open source AUTOSAR platform http://arccore.com\r
3  *\r
4  * Copyright (C) 2009  ArcCore AB <contact@arccore.com>\r
5  *\r
6  * This source code is free software; you can redistribute it and/or modify it\r
7  * under the terms of the GNU General Public License version 2 as published by the\r
8  * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.\r
9  *\r
10  * This program is distributed in the hope that it will be useful, but\r
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
12  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License\r
13  * for more details.\r
14  * -------------------------------- Arctic Core ------------------------------*/\r
15 \r
16 \r
17 #if defined(USE_CANNM)\r
18 #include "CanNm.h"\r
19 #endif\r
20 #include "Nm.h"\r
21 #include "Nm_Internal.h"\r
22 \r
23 /* Globally fulfilled requirements */\r
24 /** @req NM006 */\r
25 /** @req NM026 */\r
26 \r
27 const Nm_ConfigType* Nm_ConfigPtr;\r
28 \r
29 /** Initializes the NM Interface. */\r
30 void Nm_Init( const Nm_ConfigType * const nmConfigPtr ){\r
31         Nm_ConfigPtr = nmConfigPtr;\r
32 }\r
33 \r
34 /** This service returns the version information of this module */\r
35 void Nm_GetVersionInfo( Std_VersionInfoType* nmVerInfoPtr ){}\r
36 \r
37 /** This function calls the <BusNm>_PassiveStartUp function\r
38   * (e.g. CanNm_PassiveStartUp function is called if channel is configured as CAN). */\r
39 Nm_ReturnType Nm_PassiveStartUp( const NetworkHandleType NetworkHandle ){\r
40         const Nm_ChannelType* ChannelConf = &Nm_ConfigPtr->Channels[NetworkHandle];\r
41         NM_CALL_BUSNM(PassiveStartUp, ChannelConf);\r
42 }\r
43 \r
44 /** This function calls the <BusNm>_NetworkRequest\r
45   * (e.g. CanNm_NetworkRequest function is called if channel is configured as CAN). */\r
46 Nm_ReturnType Nm_NetworkRequest( const NetworkHandleType NetworkHandle ){\r
47         const Nm_ChannelType* ChannelConf = &Nm_ConfigPtr->Channels[NetworkHandle];\r
48         NM_CALL_BUSNM(NetworkRequest, ChannelConf)\r
49 }\r
50 \r
51 /** This function calls the <BusNm>_NetworkRelease bus specific function\r
52   * (e.g. CanNm_NetworkRelease function is called if channel is configured as CAN). */\r
53 Nm_ReturnType Nm_NetworkRelease( const NetworkHandleType NetworkHandle ){\r
54         const Nm_ChannelType* ChannelConf = &Nm_ConfigPtr->Channels[NetworkHandle];\r
55         NM_CALL_BUSNM(NetworkRelease, ChannelConf)\r
56 }\r
57 \r
58 /** This function calls the CanNm_NetworkRelease bus specific function, to disable\r
59   * the NM PDU transmission ability due to a ISO14229 Communication Control (28hex) service */\r
60 Nm_ReturnType Nm_DisableCommunication( const NetworkHandleType NetworkHandle ){\r
61         const Nm_ChannelType* ChannelConf = &Nm_ConfigPtr->Channels[NetworkHandle];\r
62         NM_CALL_BUSNM(DisableCommunication, ChannelConf)\r
63 }\r
64 \r
65 /** This function calls the CanNm_NetworkRequest bus specific function, to enable\r
66   * the NM PDU transmission ability due to a ISO14229 Communication Control (28hex) service */\r
67 Nm_ReturnType Nm_EnableCommunication( const NetworkHandleType NetworkHandle ){\r
68         const Nm_ChannelType* ChannelConf = &Nm_ConfigPtr->Channels[NetworkHandle];\r
69         NM_CALL_BUSNM(EnableCommunication, ChannelConf)\r
70 }\r
71 \r
72 /** Set user data for NM messages transmitted next on the bus.\r
73   * For that purpose <BusNm>_SetUserData shall be called\r
74   * (e.g. CanNm_SetUserData function is called if channel is configured as CAN). */\r
75 #if (NM_USER_DATA_ENABLED == STD_ON)\r
76 Nm_ReturnType Nm_SetUserData( const NetworkHandleType NetworkHandle, const uint8 * const nmUserDataPtr ){\r
77         const Nm_ChannelType* ChannelConf = &Nm_ConfigPtr->Channels[NetworkHandle];\r
78         NM_CALL_BUSNM(SetUserData, ChannelConf, nmUserDataPtr)\r
79 }\r
80 #endif\r
81 \r
82 /** Get user data out of the last successfully received NM message.\r
83   * For that purpose <BusNm>_GetUserData shall be called\r
84   * (e.g. CanNm_GetUserData function is called if channel is configured as CAN). */\r
85 #if (NM_USER_DATA_ENABLED == STD_ON)\r
86 Nm_ReturnType Nm_GetUserData( const NetworkHandleType NetworkHandle, uint8 * const nmUserDataPtr, uint8 * const nmNodeIdPtr ){\r
87         /* For some reason the signature of this service differs from its busNm equivalents... */\r
88         const Nm_ChannelType* ChannelConf = &Nm_ConfigPtr->Channels[NetworkHandle];\r
89         switch(ChannelConf->BusType) {\r
90 #if defined(USE_CANNM)\r
91         case NM_BUSNM_CANNM:\r
92                 NM_BUSNM_GET_USERDATA_AND_NODEID( CanNm, ChannelConf, nmUserDataPtr, nmNodeIdPtr )\r
93 #endif\r
94 #if defined(USE_FRNM)\r
95         case NM_BUSNM_FRNM:\r
96                 NM_BUSNM_GET_USERDATA_AND_NODEID( FrNm, ChannelConf, nmUserDataPtr, nmNodeIdPtr )\r
97 #endif\r
98 #if defined(USE_LINNM)\r
99         case NM_BUSNM_LINNM:\r
100                 NM_BUSNM_GET_USERDATA_AND_NODEID( LinNm, ChannelConf, nmUserDataPtr, nmNodeIdPtr )\r
101 #endif\r
102         default: return NM_E_NOT_OK;\r
103         }\r
104 }\r
105 #endif\r
106 \r
107 /** Get the whole PDU data out of the most recently received NM message.\r
108   * For that purpose CanNm_GetPduData shall be called. */\r
109 #if ((NM_NODE_ID_ENABLED == STD_ON) || (NM_NODE_DETECTION_ENABLED == STD_ON) || (NM_USER_DATA_ENABLED == STD_ON))\r
110 Nm_ReturnType Nm_GetPduData( const NetworkHandleType NetworkHandle, uint8 * const nmPduData ){\r
111         const Nm_ChannelType* ChannelConf = &Nm_ConfigPtr->Channels[NetworkHandle];\r
112         NM_CALL_BUSNM(GetPduData, ChannelConf, nmPduData)\r
113 }\r
114 #endif\r
115 \r
116 /** Set Repeat Message Request Bit for NM messages transmitted next on the bus.\r
117   * For that purpose <BusNm>_RepeatMessageRequest shall be called\r
118   * (e.g. CanNm_RepeatMessageRequest function is called if channel is configured as CAN) */\r
119 #if (NM_NODE_DETECTION_ENABLED == STD_ON)\r
120 Nm_ReturnType Nm_RepeatMessageRequest( const NetworkHandleType NetworkHandle ){\r
121         const Nm_ChannelType* ChannelConf = &Nm_ConfigPtr->Channels[NetworkHandle];\r
122         NM_CALL_BUSNM(RepeatMessageRequest, ChannelConf)\r
123 }\r
124 #endif\r
125 \r
126 /** Get node identifier out of the last successfully received NM-message.\r
127   * The function <BusNm>_GetNodeIdentifier shall be called. */\r
128 #if (NM_NODE_ID_ENABLED == STD_ON)\r
129 Nm_ReturnType Nm_GetNodeIdentifier( const NetworkHandleType NetworkHandle, uint8 * const nmNodeIdPtr ){\r
130         const Nm_ChannelType* ChannelConf = &Nm_ConfigPtr->Channels[NetworkHandle];\r
131         NM_CALL_BUSNM(GetNodeIdentifier, ChannelConf, nmNodeIdPtr)\r
132 }\r
133 \r
134 /** Get node identifier configured for the local node.\r
135   * For that purpose <BusNm>_GetLocalNodeIdentifier shall be called\r
136   * (e.g. CanNm_GetLocalNodeIdentifier function is called if channel is configured as CAN). */\r
137 Nm_ReturnType Nm_GetLocalNodeIdentifier( const NetworkHandleType NetworkHandle, uint8 * const nmNodeIdPtr ){\r
138         const Nm_ChannelType* ChannelConf = &Nm_ConfigPtr->Channels[NetworkHandle];\r
139         NM_CALL_BUSNM(GetLocalNodeIdentifier, ChannelConf, nmNodeIdPtr)\r
140 }\r
141 #endif\r
142 \r
143 /** Check if remote sleep indication takes place or not. This in turn calls the\r
144   * <BusNm>_CheckRemoteSleepIndication for the bus specific NM layer\r
145   * (e.g. CanNm_CheckRemoteSleepIndication function is called if channel is configured as CAN). */\r
146 Nm_ReturnType Nm_CheckRemoteSleepIndication( const NetworkHandleType NetworkHandle, boolean * const nmRemoteSleepIndPtr ){\r
147         return E_NOT_OK;\r
148 }\r
149 \r
150 /** Returns the state of the network management. This function in turn calls the\r
151   * <BusNm>_GetState function (e.g. CanNm_GetState function is called if channel is configured as CAN). */\r
152 Nm_ReturnType Nm_GetState( const NetworkHandleType NetworkHandle, Nm_StateType* const nmStatePtr, Nm_ModeType* const nmModePtr ){\r
153         const Nm_ChannelType* ChannelConf = &Nm_ConfigPtr->Channels[NetworkHandle];\r
154         NM_CALL_BUSNM(GetState, ChannelConf, nmStatePtr, nmModePtr)\r
155 }\r
156 \r
157 /** Notification that a NM-message has been received in the Bus-Sleep Mode, what\r
158   * indicates that some nodes in the network have already entered the Network Mode.\r
159   * The callback function shall start the network management state machine. */\r
160 /** @req NM012.partially.1 */\r
161 void Nm_NetworkStartIndication( const NetworkHandleType NetworkHandle ){\r
162         const Nm_ChannelType* ChannelConf = &Nm_ConfigPtr->Channels[NetworkHandle];\r
163         ComM_Nm_NetworkStartIndication(ChannelConf->ComMNetworkHandle);\r
164 }\r
165 \r
166 /** Notification that the network management has entered Network Mode. The\r
167   * callback function shall enable transmission of application messages. */\r
168 /** @req NM012.partially.2 */\r
169 void Nm_NetworkMode( const NetworkHandleType NetworkHandle ){\r
170         const Nm_ChannelType* ChannelConf = &Nm_ConfigPtr->Channels[NetworkHandle];\r
171         ComM_Nm_NetworkMode(ChannelConf->ComMNetworkHandle);\r
172 }\r
173 \r
174 /** Notification that the network management has entered Prepare Bus-Sleep Mode.\r
175   * The callback function shall disable transmission of application messages. */\r
176 /** @req NM012.partially.3 */\r
177 void Nm_PrepareBusSleepMode( const NetworkHandleType NetworkHandle ){\r
178         const Nm_ChannelType* ChannelConf = &Nm_ConfigPtr->Channels[NetworkHandle];\r
179         ComM_Nm_PrepareBusSleepMode(ChannelConf->ComMNetworkHandle);\r
180 }\r
181 \r
182 /** Notification that the network management has entered Bus-Sleep Mode. */\r
183 /** @req NM012.partially.4 */\r
184 void Nm_BusSleepMode( const NetworkHandleType NetworkHandle ){\r
185         const Nm_ChannelType* ChannelConf = &Nm_ConfigPtr->Channels[NetworkHandle];\r
186         ComM_Nm_BusSleepMode(ChannelConf->ComMNetworkHandle);\r
187 }\r
188 \r
189 /** Notification that a NM message has been received. */\r
190 void Nm_PduRxIndication( const NetworkHandleType NetworkHandle ){}\r
191 \r
192 /** Notification that the CAN Generic NM state has changed. */\r
193 void Nm_StateChangeNotification(\r
194                 const NetworkHandleType nmNetworkHandle,\r
195                 const Nm_StateType nmPreviousState,\r
196                 const Nm_StateType nmCurrentState ){}\r
197 \r
198 /** This function implements the processes of the NM Interface, which need a fix\r
199   * cyclic scheduling. This function is supplied for the NM coordinator functionality\r
200   * (Nm020). However, specific implementation may not need it (Nm093) */\r
201 /** @req 121 */\r
202 void Nm_MainFunction(){}\r
203 \r