src/lifegrd.c
author etisserant
Sun, 24 Feb 2008 02:03:19 +0100
changeset 407 384c3cd7afa2
parent 378 d2abf6c8c27b
child 423 d60363d872dd
permissions -rw-r--r--
Fixed some win32 stdout related problems. May not worl wit visualstudio debug log anymore.
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     1
/*
207
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
     2
  This file is part of CanFestival, a library implementing CanOpen
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
     3
  Stack.
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
     4
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
     5
  Copyright (C): Edouard TISSERANT and Francis DUPIN
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
     6
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
     7
  See COPYING file for copyrights details.
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
     8
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
     9
  This library is free software; you can redistribute it and/or
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    10
  modify it under the terms of the GNU Lesser General Public
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    11
  License as published by the Free Software Foundation; either
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    12
  version 2.1 of the License, or (at your option) any later version.
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    13
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    14
  This library is distributed in the hope that it will be useful,
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    15
  but WITHOUT ANY WARRANTY; without even the implied warranty of
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    16
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    17
  Lesser General Public License for more details.
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    18
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    19
  You should have received a copy of the GNU Lesser General Public
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    20
  License along with this library; if not, write to the Free Software
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    21
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    22
  USA
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    23
*/
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    24
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    25
/*!
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
    26
** @file   lifegrd.c
207
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    27
** @author Edouard TISSERANT
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    28
** @date   Mon Jun  4 17:19:24 2007
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    29
**
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    30
** @brief
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    31
**
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    32
**
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    33
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    34
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    35
#include <data.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    36
#include "lifegrd.h"
149
fe50ada8020b Changes in the API:
etisserant
parents: 71
diff changeset
    37
#include "canfestival.h"
357
838e5397ae67 Fixed some build errors and warnigs, thanks to Martin Hollenweger (geautomotive.eu)
etisserant
parents: 352
diff changeset
    38
#include "dcf.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"
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    40
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
    41
53
73bc47a0db55 Add prototypes
frdupin
parents: 0
diff changeset
    42
void ConsumerHearbeatAlarm(CO_Data* d, UNS32 id);
207
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    43
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
    44
53
73bc47a0db55 Add prototypes
frdupin
parents: 0
diff changeset
    45
void ProducerHearbeatAlarm(CO_Data* d, UNS32 id);
207
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    46
185
d529e20c323c correction of lifegrd compilation warning
greg
parents: 177
diff changeset
    47
UNS32 OnHearbeatProducerUpdate(CO_Data* d, const indextable * unsused_indextable, UNS8 unsused_bSubindex);
53
73bc47a0db55 Add prototypes
frdupin
parents: 0
diff changeset
    48
207
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    49
/*!
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    50
**
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    51
**
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    52
** @param d
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    53
** @param nodeId
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    54
**
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    55
** @return
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    56
**/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    57
e_nodeState getNodeState (CO_Data* d, UNS8 nodeId)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    58
{
207
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    59
  e_nodeState networkNodeState = d->NMTable[nodeId];
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    60
  return networkNodeState;
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    61
}
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    62
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
    63
/*! 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
    64
** The Consumer Timer Callback
207
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    65
**
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    66
** @param d
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    67
** @param id
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    68
**/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    69
void ConsumerHearbeatAlarm(CO_Data* d, UNS32 id)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    70
{
207
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    71
  /*MSG_WAR(0x00, "ConsumerHearbeatAlarm", 0x00);*/
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    72
352
3347581c3140 Fixed timer problem on late Heartbeat. Thanks to Jorge.
etisserant
parents: 349
diff changeset
    73
  /* timer have been notified and is now free (non periodic)*/
3347581c3140 Fixed timer problem on late Heartbeat. Thanks to Jorge.
etisserant
parents: 349
diff changeset
    74
  /* -> avoid deleting re-assigned timer if message is received too late*/
3347581c3140 Fixed timer problem on late Heartbeat. Thanks to Jorge.
etisserant
parents: 349
diff changeset
    75
  d->ConsumerHeartBeatTimers[id]=TIMER_NONE;
207
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    76
  /*! call heartbeat error with NodeId */
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
    77
  (*d->heartbeatError)(d, (UNS8)( ((d->ConsumerHeartbeatEntries[id]) & (UNS32)0x00FF0000) >> (UNS8)16 ));
207
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    78
}
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    79
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    80
/*!
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    81
**
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    82
**
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    83
** @param d
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    84
** @param m
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    85
**/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    86
void proceedNODE_GUARD(CO_Data* d, Message* m )
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    87
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    88
  UNS8 nodeId = (UNS8) GET_NODE_ID((*m));
207
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    89
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    90
  if((m->rtr == 1) )
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    91
    /*!
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    92
    ** Notice that only the master can have sent this
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    93
    ** node guarding request
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    94
    */
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    95
    {
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    96
      /*!
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    97
      ** Receiving a NMT NodeGuarding (request of the state by the
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    98
      ** master)
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
    99
      ** Only answer to the NMT NodeGuarding request, the master is
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   100
      ** not checked (not implemented)
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   101
      */
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   102
      if (nodeId == *d->bDeviceNodeId )
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   103
        {
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   104
          Message msg;
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
   105
          UNS16 tmp = *d->bDeviceNodeId + 0x700;
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
   106
          msg.cob_id = UNS16_LE(tmp);
207
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   107
          msg.len = (UNS8)0x01;
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   108
          msg.rtr = 0;
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   109
          msg.data[0] = d->nodeState;
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   110
          if (d->toggle)
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   111
            {
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   112
              msg.data[0] |= 0x80 ;
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   113
              d->toggle = 0 ;
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   114
            }
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   115
          else
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   116
            d->toggle = 1 ;
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   117
          /* send the nodeguard response. */
207
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   118
          MSG_WAR(0x3130, "Sending NMT Nodeguard to master, state: ", d->nodeState);
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   119
          canSend(d->canHandle,&msg );
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   120
        }
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   121
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   122
    }else{ /* Not a request CAN */
207
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   123
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   124
      MSG_WAR(0x3110, "Received NMT nodeId : ", nodeId);
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   125
      /* the slave's state receievd is stored in the NMTable */
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   126
      /* The state is stored on 7 bit */
207
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   127
      d->NMTable[nodeId] = (e_nodeState) ((*m).data[0] & 0x7F) ;
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   128
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   129
      /* Boot-Up frame reception */
207
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   130
      if ( d->NMTable[nodeId] == Initialisation)
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   131
        {
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   132
          /*
207
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   133
          ** The device send the boot-up message (Initialisation)
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   134
          ** to indicate the master that it is entered in
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   135
          ** pre_operational mode
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   136
          ** Because the  device enter automaticaly in pre_operational
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   137
          ** mode,
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   138
          ** the pre_operational mode is stored
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   139
          ** NMTable[bus_id][nodeId] = Pre_operational
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   140
          */
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   141
          MSG_WAR(0x3100, "The NMT is a bootup from node : ", nodeId);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 215
diff changeset
   142
          
349
1e6dd4ef46b9 fixed the DCF-LSS conflict
groke6
parents: 343
diff changeset
   143
          if(!send_consise_dcf(d,nodeId)){
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 215
diff changeset
   144
             /* call post SlaveBootup with NodeId */
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
   145
		  	(*d->post_SlaveBootup)(d, nodeId);
349
1e6dd4ef46b9 fixed the DCF-LSS conflict
groke6
parents: 343
diff changeset
   146
          }
207
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   147
        }
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   148
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   149
      if( d->NMTable[nodeId] != Unknown_state ) {
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   150
        UNS8 index, ConsummerHeartBeat_nodeId ;
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   151
        for( index = (UNS8)0x00; index < *d->ConsumerHeartbeatCount; index++ )
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   152
          {
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   153
            ConsummerHeartBeat_nodeId = (UNS8)( ((d->ConsumerHeartbeatEntries[index]) & (UNS32)0x00FF0000) >> (UNS8)16 );
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   154
            if ( nodeId == ConsummerHeartBeat_nodeId )
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   155
              {
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   156
                TIMEVAL time = ( (d->ConsumerHeartbeatEntries[index]) & (UNS32)0x0000FFFF ) ;
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   157
                /* Renew alarm for next heartbeat. */
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   158
                DelAlarm(d->ConsumerHeartBeatTimers[index]);
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   159
                d->ConsumerHeartBeatTimers[index] = SetAlarm(d, index, &ConsumerHearbeatAlarm, MS_TO_TIMEVAL(time), 0);
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   160
              }
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   161
          }
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   162
      }
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   163
    }
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   164
}
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   165
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   166
/*! The Consumer Timer Callback
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   167
**
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   168
**
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   169
** @param d
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   170
** @param id
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   171
**/
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   172
void ProducerHearbeatAlarm(CO_Data* d, UNS32 id)
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   173
{
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   174
  if(*d->ProducerHeartBeatTime)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   175
    {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   176
      Message msg;
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   177
      /* Time expired, the heartbeat must be sent immediately
207
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   178
      ** generate the correct node-id: this is done by the offset 1792
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   179
      ** (decimal) and additionaly
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   180
      ** the node-id of this device.
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   181
      */
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
   182
      UNS16 tmp = *d->bDeviceNodeId + 0x700;
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
   183
      msg.cob_id = UNS16_LE(tmp);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   184
      msg.len = (UNS8)0x01;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   185
      msg.rtr = 0;
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   186
      msg.data[0] = d->nodeState; /* No toggle for heartbeat !*/
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   187
      /* send the heartbeat */
207
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   188
      MSG_WAR(0x3130, "Producing heartbeat: ", d->nodeState);
149
fe50ada8020b Changes in the API:
etisserant
parents: 71
diff changeset
   189
      canSend(d->canHandle,&msg );
207
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   190
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   191
    }else{
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   192
      d->ProducerHeartBeatTimer = DelAlarm(d->ProducerHeartBeatTimer);
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   193
    }
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   194
}
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   195
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   196
/*! This is called when Index 0x1017 is updated.
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   197
**
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   198
**
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   199
** @param d
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   200
** @param unsused_indextable
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   201
** @param unsused_bSubindex
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   202
**
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   203
** @return
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   204
**/
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   205
UNS32 OnHeartbeatProducerUpdate(CO_Data* d, const indextable * unsused_indextable, UNS8 unsused_bSubindex)
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   206
{
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   207
  heartbeatStop(d);
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   208
  heartbeatInit(d);
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   209
  return 0;
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   210
}
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   211
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   212
/*!
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   213
**
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   214
**
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   215
** @param d
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   216
**/
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   217
void heartbeatInit(CO_Data* d)
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   218
{
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   219
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   220
  UNS8 index; /* Index to scan the table of heartbeat consumers */
207
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   221
  RegisterSetODentryCallBack(d, 0x1017, 0x00, &OnHeartbeatProducerUpdate);
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   222
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   223
  d->toggle = 0;
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   224
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   225
  for( index = (UNS8)0x00; index < *d->ConsumerHeartbeatCount; index++ )
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   226
    {
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   227
      TIMEVAL time = (UNS16) ( (d->ConsumerHeartbeatEntries[index]) & (UNS32)0x0000FFFF ) ;
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   228
      /* MSG_WAR(0x3121, "should_time : ", should_time ) ; */
207
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   229
      if ( time )
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   230
        {
207
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   231
          d->ConsumerHeartBeatTimers[index] = SetAlarm(d, index, &ConsumerHearbeatAlarm, MS_TO_TIMEVAL(time), 0);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   232
        }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   233
    }
207
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   234
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   235
  if ( *d->ProducerHeartBeatTime )
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   236
    {
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   237
      TIMEVAL time = *d->ProducerHeartBeatTime;
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   238
      d->ProducerHeartBeatTimer = SetAlarm(d, 0, &ProducerHearbeatAlarm, MS_TO_TIMEVAL(time), MS_TO_TIMEVAL(time));
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   239
    }
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   240
}
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   241
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   242
/*!
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   243
**
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   244
**
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   245
** @param d
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   246
**/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   247
void heartbeatStop(CO_Data* d)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   248
{
207
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   249
  UNS8 index;
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   250
  for( index = (UNS8)0x00; index < *d->ConsumerHeartbeatCount; index++ )
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   251
    {
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   252
      d->ConsumerHeartBeatTimers[index + 1] = DelAlarm(d->ConsumerHeartBeatTimers[index + 1]);;
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   253
    }
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   254
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   255
  d->ProducerHeartBeatTimer = DelAlarm(d->ProducerHeartBeatTimer);;
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   256
}
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   257
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   258
/*!
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   259
**
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   260
**
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   261
** @param heartbeatID
b6572d0336c3 First doxygen implementation
nico
parents: 185
diff changeset
   262
**/
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
   263
void _heartbeatError(CO_Data* d, UNS8 heartbeatID){}
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
   264
void _post_SlaveBootup(CO_Data* d, UNS8 SlaveID){}