src/emcy.c
author Laurent Bessard
Thu, 02 May 2013 09:42:37 +0200
changeset 782 c0869429c72a
parent 759 ed78c627f666
permissions -rw-r--r--
Removed call of deprecated function on wxSplitterWindow
284
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
     1
/*
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
     2
  This file is part of CanFestival, a library implementing CanOpen
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
     3
  Stack.
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
     4
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
     5
  Copyright (C): Edouard TISSERANT and Francis DUPIN
759
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
     6
  Modified by: Jaroslav Fojtik
284
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
     7
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
     8
  See COPYING file for copyrights details.
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
     9
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    10
  This library is free software; you can redistribute it and/or
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    11
  modify it under the terms of the GNU Lesser General Public
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    12
  License as published by the Free Software Foundation; either
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    13
  version 2.1 of the License, or (at your option) any later version.
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    14
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    15
  This library is distributed in the hope that it will be useful,
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    16
  but WITHOUT ANY WARRANTY; without even the implied warranty of
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    17
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    18
  Lesser General Public License for more details.
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    19
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    20
  You should have received a copy of the GNU Lesser General Public
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    21
  License along with this library; if not, write to the Free Software
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    22
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    23
  USA
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    24
*/
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    25
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    26
/*!
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    27
** @file   emcy.c
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    28
** @author Luis Jimenez
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    29
** @date   Wed Sep 26 2007
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    30
**
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    31
** @brief Definitions of the functions that manage EMCY (emergency) messages
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    32
**
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    33
**
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    34
*/
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    35
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    36
#include <data.h>
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    37
#include "emcy.h"
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    38
#include "canfestival.h"
370
6fecf36df407 Fixed some endianization problems caused by switch to UNS16 for cob_id member in CAN messages. To be continued.
etisserant
parents: 365
diff changeset
    39
#include "sysdep.h"
284
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    40
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    41
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    42
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    43
UNS32 OnNumberOfErrorsUpdate(CO_Data* d, const indextable * unsused_indextable, UNS8 unsused_bSubindex);
759
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
    44
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
    45
#define Data data  /* temporary fix */
284
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    46
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    47
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    48
/*! This is called when Index 0x1003 is updated.
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    49
**
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    50
**
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    51
** @param d
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    52
** @param unsused_indextable
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    53
** @param unsused_bSubindex
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    54
**
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    55
** @return
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    56
**/
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    57
UNS32 OnNumberOfErrorsUpdate(CO_Data* d, const indextable * unsused_indextable, UNS8 unsused_bSubindex)
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    58
{
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    59
	UNS8 index;
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    60
  // if 0, reset Pre-defined Error Field
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    61
  // else, don't change and give an abort message (eeror code: 0609 0030h)
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    62
	if (*d->error_number == 0)
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    63
		for (index = 0; index < d->error_history_size; ++index)
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    64
			*(d->error_first_element + index) = 0;		/* clear all the fields in Pre-defined Error Field (1003h) */
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    65
	else
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    66
		;// abort message
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    67
  return 0;
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    68
}
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    69
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    70
/*! start the EMCY mangagement.
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    71
**
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    72
**
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    73
** @param d
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    74
**/
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    75
void emergencyInit(CO_Data* d)
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    76
{
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    77
  RegisterSetODentryCallBack(d, 0x1003, 0x00, &OnNumberOfErrorsUpdate);
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    78
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    79
  *d->error_number = 0;
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    80
}
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    81
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    82
/*!
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    83
**
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    84
**
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    85
** @param d
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    86
**/
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    87
void emergencyStop(CO_Data* d)
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    88
{
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    89
  
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    90
}
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    91
759
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
    92
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
    93
/*!
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
    94
 **
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
    95
 ** @param d
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
    96
 ** @param cob_id
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
    97
 **
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
    98
 ** @return
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
    99
 **/
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
   100
UNS8 sendEMCY(CO_Data* d, UNS16 errCode, UNS8 errRegister, const void *Specific, UNS8 SpecificLength)
284
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   101
{
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   102
	Message m;
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   103
  
288
26015ee2c2c9 Modified codes in MSG_ERR and MSG_WAR in emcy.c
luis
parents: 284
diff changeset
   104
	MSG_WAR(0x3051, "sendEMCY", 0);
284
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   105
  
759
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
   106
	m.cob_id = (UNS16)(*(UNS32*)d->error_cobid);
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
   107
	m.rtr = NOT_A_REQUEST;	
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
   108
	m.Data[0] = errCode & 0xFF;        /* LSB */
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
   109
	m.Data[1] = (errCode >> 8) & 0xFF; /* MSB */
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
   110
	m.Data[2] = errRegister;
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
   111
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
   112
	if(Specific==NULL)
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
   113
	{
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
   114
	  m.Data[3] = 0;		/* Manufacturer specific Error Field omitted */
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
   115
	  m.Data[4] = 0;
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
   116
	  m.Data[5] = 0;
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
   117
	  m.Data[6] = 0;
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
   118
	  m.Data[7] = 0;
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
   119
	  SpecificLength = 5;
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
   120
	}
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
   121
	else
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
   122
	{
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
   123
          if(SpecificLength>5) SpecificLength = 5;
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
   124
	  memcpy(&m.Data[3],Specific,SpecificLength);	  
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
   125
	}
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
   126
	m.len = SpecificLength + 3;
284
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   127
  
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   128
	return canSend(d->canHandle,&m);
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   129
}
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   130
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   131
/*! Sets a new error with code errCode. Also sets corresponding bits in Error register (1001h)
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   132
 **                                                                                                 
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   133
 **  
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   134
 ** @param d
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   135
 ** @param errCode Code of the error                                                                                        
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   136
 ** @param errRegister Bits of Error register (1001h) to be set.
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   137
 ** @return 1 if error, 0 if successful
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   138
 */
296
03f2b8b8cb0b Solved a small bug in emcy.c (errRegMask was always '1' in EMCY_setError.
luis
parents: 288
diff changeset
   139
UNS8 EMCY_setError(CO_Data* d, UNS16 errCode, UNS8 errRegMask, UNS16 addInfo)
284
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   140
{
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   141
	UNS8 index;
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   142
	UNS8 errRegister_tmp;
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   143
	
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   144
	for (index = 0; index < EMCY_MAX_ERRORS; ++index)
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   145
	{
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   146
		if (d->error_data[index].errCode == errCode)		/* error already registered */
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   147
		{
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   148
			if (d->error_data[index].active)
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   149
			{
288
26015ee2c2c9 Modified codes in MSG_ERR and MSG_WAR in emcy.c
luis
parents: 284
diff changeset
   150
				MSG_WAR(0x3052, "EMCY message already sent", 0);
284
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   151
				return 0;
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   152
			} else d->error_data[index].active = 1;		/* set as active error */
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   153
			break;
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   154
		}
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   155
	}
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   156
	
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   157
	if (index == EMCY_MAX_ERRORS)		/* if errCode not already registered */
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   158
		for (index = 0; index < EMCY_MAX_ERRORS; ++index) if (d->error_data[index].active == 0) break;	/* find first inactive error */
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   159
	
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   160
	if (index == EMCY_MAX_ERRORS)		/* error_data full */
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   161
	{
288
26015ee2c2c9 Modified codes in MSG_ERR and MSG_WAR in emcy.c
luis
parents: 284
diff changeset
   162
		MSG_ERR(0x3053, "error_data full", 0);
284
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   163
		return 1;
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   164
	}
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   165
	
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   166
	d->error_data[index].errCode = errCode;
296
03f2b8b8cb0b Solved a small bug in emcy.c (errRegMask was always '1' in EMCY_setError.
luis
parents: 288
diff changeset
   167
	d->error_data[index].errRegMask = errRegMask;
284
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   168
	d->error_data[index].active = 1;
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   169
	
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   170
	/* set the new state in the error state machine */
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   171
	d->error_state = Error_occurred;
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   172
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   173
	/* set Error Register (1001h) */
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   174
	for (index = 0, errRegister_tmp = 0; index < EMCY_MAX_ERRORS; ++index)
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   175
		if (d->error_data[index].active == 1) errRegister_tmp |= d->error_data[index].errRegMask;
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   176
	*d->error_register = errRegister_tmp;
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   177
	
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   178
	/* set Pre-defined Error Field (1003h) */
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   179
	for (index = d->error_history_size - 1; index > 0; --index)
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   180
		*(d->error_first_element + index) = *(d->error_first_element + index - 1);
296
03f2b8b8cb0b Solved a small bug in emcy.c (errRegMask was always '1' in EMCY_setError.
luis
parents: 288
diff changeset
   181
	*(d->error_first_element) = errCode | ((UNS32)addInfo << 16);
284
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   182
	if(*d->error_number < d->error_history_size) ++(*d->error_number);
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   183
	
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   184
	/* send EMCY message */
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   185
	if (d->CurrentCommunicationState.csEmergency)
759
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
   186
		return sendEMCY(d, errCode, *d->error_register, NULL, 0);
284
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   187
	else return 1;
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   188
}
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   189
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   190
/*! Deletes error errCode. Also clears corresponding bits in Error register (1001h)
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   191
 **                                                                                                 
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   192
 **  
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   193
 ** @param d
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   194
 ** @param errCode Code of the error                                                                                        
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   195
 ** @param errRegister Bits of Error register (1001h) to be set.
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   196
 ** @return 1 if error, 0 if successful
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   197
 */
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   198
void EMCY_errorRecovered(CO_Data* d, UNS16 errCode)
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   199
{
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   200
	UNS8 index;
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   201
	UNS8 errRegister_tmp;
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   202
	UNS8 anyActiveError = 0;
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   203
	
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   204
	for (index = 0; index < EMCY_MAX_ERRORS; ++index)
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   205
		if (d->error_data[index].errCode == errCode) break;		/* find the position of the error */
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   206
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   207
	
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   208
	if ((index != EMCY_MAX_ERRORS) && (d->error_data[index].active == 1))
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   209
	{
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   210
		d->error_data[index].active = 0;
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   211
		
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   212
		/* set Error Register (1001h) and check error state machine */
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   213
		for (index = 0, errRegister_tmp = 0; index < EMCY_MAX_ERRORS; ++index)
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   214
			if (d->error_data[index].active == 1)
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   215
			{
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   216
				anyActiveError = 1;
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   217
				errRegister_tmp |= d->error_data[index].errRegMask;
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   218
			}
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   219
		if(anyActiveError == 0)
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   220
		{
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   221
			d->error_state = Error_free;
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   222
			/* send a EMCY message with code "Error Reset or No Error" */
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   223
			if (d->CurrentCommunicationState.csEmergency)
759
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
   224
				sendEMCY(d, 0x0000, 0x00, NULL, 0);
284
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   225
		}
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   226
		*d->error_register = errRegister_tmp;
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   227
	}
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   228
	else
288
26015ee2c2c9 Modified codes in MSG_ERR and MSG_WAR in emcy.c
luis
parents: 284
diff changeset
   229
		MSG_WAR(0x3054, "recovered error was not active", 0);
284
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   230
}
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   231
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   232
/*! This function is responsible to process an EMCY canopen-message.
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   233
 **
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   234
 **
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   235
 ** @param d
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   236
 ** @param m The CAN-message which has to be analysed.
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   237
 **
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   238
 **/
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   239
void proceedEMCY(CO_Data* d, Message* m)
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   240
{
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   241
	UNS8 nodeID;
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   242
	UNS16 errCode;
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   243
	UNS8 errReg;
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   244
	
288
26015ee2c2c9 Modified codes in MSG_ERR and MSG_WAR in emcy.c
luis
parents: 284
diff changeset
   245
	MSG_WAR(0x3055, "EMCY received. Proceed. ", 0);
284
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   246
  
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   247
	/* Test if the size of the EMCY is ok */
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   248
	if ( m->len != 8) {
365
9b76e0881beb Changed cob_id from struct{UNS32} to UNS16
etisserant
parents: 314
diff changeset
   249
		MSG_ERR(0x1056, "Error size EMCY. CobId  : ", m->cob_id);
284
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   250
		return;
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   251
	}
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   252
	
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   253
	/* post the received EMCY */
759
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
   254
	nodeID = m->cob_id & 0x7F;
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
   255
	errCode = m->Data[0] | ((UNS16)m->Data[1] << 8);
ed78c627f666 Ability to send content of emergency data.
fojtik <>
parents: 587
diff changeset
   256
	errReg = m->Data[2];
378
d2abf6c8c27b As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents: 370
diff changeset
   257
	(*d->post_emcy)(d, nodeID, errCode, errReg);
d2abf6c8c27b As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents: 370
diff changeset
   258
}
d2abf6c8c27b As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents: 370
diff changeset
   259
d2abf6c8c27b As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents: 370
diff changeset
   260
void _post_emcy(CO_Data* d, UNS8 nodeID, UNS16 errCode, UNS8 errReg){}