NNP STM Generic Remote Module git-main
Loading...
Searching...
No Matches
nmtSlave.c
Go to the documentation of this file.
1
12#include "canfestival.h"
13#include "sysdep.h"
14#include "ObjDict.h"
15#include "eedata.h"
16#include "nmtSlave.h"
17#include "states.h"
18#include "main.h"
19#include "acceltemp.h"
20
21#include "app.h"
22
23
35{
36
37 // check to see if the system can handle external messages
38 if( d->nodeState != Hibernate ||
39 d->nodeState != BootCheckReset )
40 {
41
42 MSG_WAR(0x3400, "NMT received. for node : ", (*m).data[1]);
43
44 // Check if this NMT-message is for this node
45 // byte 1 = 0 : all the nodes are concerned (broadcast)
46 if( ( (*m).data[1] == 0 ) || ( (*m).data[1] == *d->bDeviceNodeId ) )
47 {
48 switch( (*m).data[0]) /* NMT command specifier (cs) in def.h*/
49 {
50 // command interpreter
51
52 case NMT_Start_Nodes:
53 StartNodesFunc(d, m);
54 break;
55
56 case NMT_Stop_Nodes:
57 StopNodesFunc(d, m);
58 break;
59
60 case NMT_Enter_Wait_Mode:
61 EnterWaitingFunc(d, m);
62 break;
63
64 case NMT_Enter_Patient_Operation:
66 break;
67
68 case NMT_Enter_X_Manual:
69 EnterXManualFunc(d, m);
70 break;
71
72 case NMT_Enter_Y_Manual:
73 EnterYManualFunc(d, m);
74 break;
75
76 case NMT_Enter_Stop_Stim:
78 break;
79
80 case NMT_Enter_Patient_Manual:
82 break;
83
84 case NMT_Enter_Produce_X_Manual:
86 break;
87
88 case NMT_Enter_Record_X:
89 EnterRecordXFunc(d, m);
90 break;
91
93 //must be in waiting and targeted to this node
94 if ( ((*m).data[1] == *d->bDeviceNodeId) && (d->nodeState == Waiting))
95 changeModeIMU((*m).data[2]);
96 break;
97
98 case NMT_Start_Sync:
99 startSYNC(d);
100 break;
101
102 case NMT_Stop_Sync:
103 stopSYNC(d);
104 break;
105
106 case NMT_Start_PDO:
107 PDOInit(d);
108 break;
109
110 case NMT_Stop_PDO:
111 PDOStop(d);
112 break;
113
114 case NMT_Reset_Watchdog:
115 if ( (*m).data[1] == *d->bDeviceNodeId) // must be targeted to this node
116 StartWatchDog(d, 10000);
117 break;
118
119 case NMT_Reset_Node:
120 if(d->NMT_Slave_Node_Reset_Callback != NULL)
121 d->NMT_Slave_Node_Reset_Callback(d);
122 if ((*m).data[1] == *d->bDeviceNodeId)
123 setState(d, Waiting);
124 break;
125
126 case NMT_Reset_OD_Defaults:
127 if (d->nodeState == Waiting || d->nodeState == Stopped )
129 break;
130
131 case NMT_Reset_Module:
132 if (d->nodeState == Waiting || d->nodeState == Stopped )
133 ResetModule();
134 break;
135
136 case NMT_Clear_CAN_Errors:
137 CAN_FormErrors = 0;
138 CAN_StuffErrors = 0;
139 CAN_BitErrors = 0;
140 CAN_OtherErrors = 0;
141 CAN_TotalErrors = 0;
142 CAN_Receive_BEI = 0;
143 CAN_Receive_Messages = 0;
144 CAN_Transmit_Messages = 0;
145 break;
146
147 case NMT_Erase_Serial_Eprom:
148 if (d->nodeState == Waiting)
149 EEPROM_erase((*m).data[2]); //param1 specifies all EEPROM(0), RestoreSpace(1) or PatternSpace(2)
150 break;
151
152 case NMT_Do_Save_Cmd:
153 if (d->nodeState == Waiting)
154 SaveValues();
155 break;
156
157 case NMT_Do_Restore_Cmd:
158 if (d->nodeState == Waiting)
160 break;
161
162 case NMT_Init_NV_Memory: //JML: why? what for
163 //if (d->nodeState == Waiting)
164 break;
165
166 case NMT_Enter_Low_Power:
167 //must be in waiting and targeted to this node
168 //assume that only way to come out of sleep mode is power cycle
169 if ( ((*m).data[1] == *d->bDeviceNodeId) && (d->nodeState == Waiting))
170 {
171 //Other power saving functions before sleeping
175
176 // Trigger Full Shutdown (No brownout reset}
177 __disable_irq();
178 __disable_fault_irq();
179 HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1); // Disable wakeup pins
180 HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN2);
181 HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN3);
182 HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN4);
183 HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN5);
184 __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); // Clear all wakeup flags
185 HAL_PWREx_DisableInternalWakeUpLine();
186
187 // Enable internal pullup to prevent shutdown from taking down network
188 HAL_PWREx_EnablePullUpPullDownConfig();
189 HAL_PWREx_EnableGPIOPullUp(PWR_GPIO_B, PWR_GPIO_BIT_8 | PWR_GPIO_BIT_9);
190 HAL_PWREx_EnterSHUTDOWNMode();
191 // If the module somehow goes from shutdown to run mode we're gonna have a bad time
192 }
193 break;
194
195 case NMT_Reset_Comunication:
196 if ( ((*m).data[1] == *d->bDeviceNodeId) && (d->nodeState == Waiting))
197 {
198 UNS8 newNodeId = (*m).data[2]; //Param1
199
200 if(d->NMT_Slave_Communications_Reset_Callback != NULL)
201 d->NMT_Slave_Communications_Reset_Callback(d);
202 #ifdef CO_ENABLE_LSS
203
204 if(newNodeId != d->lss_transfer.nodeID)
205 d->lss_transfer.nodeID = newNodeId;
206 #endif
207
208 Status_NodeId = newNodeId;
209 SaveValues();
210 ResetModule();
211 }
212 break;
213 }/* end switch */
214
215 }
216 }
217}
218
219
228{
229 Message m;
230
231#ifdef CO_ENABLE_LSS
232 if(*d->bDeviceNodeId==0xFF)return 0;
233#endif
234
235 MSG_WAR(0x3407, "Send a Boot-Up msg ", 0);
236
237 /* message configuration */
238 {
239 UNS16 tmp = NODE_GUARD << 7 | *d->bDeviceNodeId;
240 m.cob_id = UNS16_LE(tmp);
241 }
242 m.rtr = NOT_A_REQUEST;
243 m.len = 1;
244 m.data[0] = 0x00;
245
246 return canSend(d->canHandle, &m);
247}
248
249
250//=====================
251// WATCH DOG ROUTINES
252//=====================
253
254static CO_Data *wdogCoData;
255
262void StartWatchDog( CO_Data* d, UNS16 timebase )
263{
264 wdogCoData = d;
265}
266
273{
274 wdogCoData = d;
275}
276
282{
283 if( wdogCoData != NULL )
284 {
285 setState( wdogCoData, Stopped);
286 }
287}
288
289
290
This file is generated by the NNP Tool – Object Dictionary Editor, as originally developed by CAN Fes...
void sleepTemperature(void)
puts thermometer to sleep
Definition acceltemp.c:430
void changeModeIMU(UNS8 mode)
Changes functional mode of ISM330IS accelerometer.
Definition acceltemp.c:71
void sleepAccelerometer(void)
puts Accelerometer to sleep
Definition acceltemp.c:59
Header file for app.c.
#define UNS8
Unsigned int8 representation in CANFest.
Definition applicfg.h:25
#define UNS16
Unsigned int16 representation in CANFest.
Definition applicfg.h:26
#define MSG_WAR(num, str, val)
Definition of MSG_WAR.
Definition applicfg.h:64
#define NMT_Set_IMU_Mode
Set IMU mode (ISPU, Accelerometer, and Gyroscope)
Definition def.h:174
void RestoreValues(void)
Restores the values of custom OD entries (specified in RestoreList OD index 0x2900) to the OD from EE...
Definition eedata.c:117
void ResetToODDefault(void)
invoked by nmt_master – writes 0's to size causing bypass of OD restore, then causes reset
Definition eedata.c:173
void ResetModule(void)
resets module, called by ResetToODDefault()
Definition eedata.c:191
void SaveValues(void)
Saves the values of custom OD entries (specified in RestoreList OD index 0x2900) to EEPROM from the O...
Definition eedata.c:51
void EEPROM_erase(UNS8 space)
writes 0xFF to entire EEPROM (6KB).
Definition eedata.c:228
void EnterProduceXManualFunc(CO_Data *d, Message *m)
Lets application process NMT_Produce_X_Manual.
Definition app.c:260
void EnterPatientOperationFunc(CO_Data *d, Message *m)
Lets application process NMT_Enter_Patient_Operation.
Definition app.c:188
void EnterStopStimFunc(CO_Data *d, Message *m)
Lets application process NMT_Enter_Stop_Stim.
Definition app.c:232
void EnterYManualFunc(CO_Data *d, Message *m)
Lets application process NMT_Enter_Y_Manual.
Definition app.c:217
void EnterPatientManualFunc(CO_Data *d, Message *m)
Lets application process NMT_Enter_Patient_Manual.
Definition app.c:245
void EnterRecordXFunc(CO_Data *d, Message *m)
Lets application process NMT_Enter_Record_X.
Definition app.c:274
void StopNodesFunc(CO_Data *d, Message *m)
Lets application process NMT_Stop_Nodes.
Definition app.c:161
void EnterWaitingFunc(CO_Data *d, Message *m)
Lets application process NMT_Enter_Waiting.
Definition app.c:174
void StartNodesFunc(CO_Data *d, Message *m)
Lets application process NMT_Start_Nodes (unused)
Definition app.c:147
void EnterXManualFunc(CO_Data *d, Message *m)
Lets application process NMT_Enter_X_Manual.
Definition app.c:202
void sleepApplication(void)
This function is called when the module recieves an NMT to enter low power mode.
Definition app.c:124
void setNodeStateToStopped(void)
<BRIEF> setNodeStateToStopped
Definition nmtSlave.c:281
void processNMTstateChange(CO_Data *d, Message *m)
Manage the reception of a NMT message from the master.
Definition nmtSlave.c:34
UNS8 slaveSendBootUp(CO_Data *d)
Transmit the boot-Up frame when the slave is moving from initialization state to pre_operational stat...
Definition nmtSlave.c:227
void StartWatchDog(CO_Data *d, UNS16 timebase)
Starts watchdog on slave.
Definition nmtSlave.c:262
void StopWatchDog(CO_Data *d)
Stops watchdog on slave.
Definition nmtSlave.c:272
void PDOInit(CO_Data *d)
Initialize PDO feature.
Definition pdo.c:752
void PDOStop(CO_Data *d)
Stop PDO feature.
Definition pdo.c:790
UNS8 setState(CO_Data *d, e_nodeState newState)
Change the state of the node.
Definition states.c:161
void startSYNC(CO_Data *d)
<BRIEF> startSYNC
Definition sync.c:58
void stopSYNC(CO_Data *d)
<BRIEF> stopSYNC
Definition sync.c:83
: Header for main.c file. This file contains the common defines of the application.
Definition can.h:13
UNS16 cob_id
Definition can.h:14
UNS8 data[8]
Definition can.h:17
UNS8 rtr
Definition can.h:15
UNS8 len
Definition can.h:16
This structure contains all necessary informations to define a CANOpen node.
Definition data.h:44