src/nmtMaster.c
author Robert Lehmann <robert.lehmann@sitec-systems.de>
Tue, 28 Jul 2015 16:36:55 +0200
changeset 793 72e9e1064432
parent 631 08b6b903f84a
permissions -rw-r--r--
timers_unix: Fix termination problem of WaitReceiveTaskEnd

The function pthread_kill sends the Signal thread and to the own process.
If you use this construct than the application which calls uses the
canfestival api will terminate at the call of canClose. To avoid that
use pthread_cancel instead of pthread_kill. To use the pthread_cancel call
you need to set the cancel ability in the thread function. That means
you need to call pthread_setcancelstate and pthread_setcanceltype.
For the termination of the thread at any time it is important to set the
cancel type to PTHREAD_CANCEL_ASYNCHRONOUS.
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     1
/*
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
     2
  This file is part of CanFestival, a library implementing CanOpen
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
     3
  Stack.
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     4
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
     5
  Copyright (C): Edouard TISSERANT and Francis DUPIN
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     6
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
     7
  See COPYING file for copyrights details.
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     8
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
     9
  This library is free software; you can redistribute it and/or
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    10
  modify it under the terms of the GNU Lesser General Public
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    11
  License as published by the Free Software Foundation; either
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    12
  version 2.1 of the License, or (at your option) any later version.
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    13
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    14
  This library is distributed in the hope that it will be useful,
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    15
  but WITHOUT ANY WARRANTY; without even the implied warranty of
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    16
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    17
  Lesser General Public License for more details.
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    18
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    19
  You should have received a copy of the GNU Lesser General Public
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    20
  License along with this library; if not, write to the Free Software
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    21
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    22
  USA
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    23
*/
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    24
/*!
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    25
** @file   nmtMaster.c
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    26
** @author Edouard TISSERANT and Francis DUPIN
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    27
** @date   Tue Jun  5 08:47:18 2007
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    28
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    29
** @brief
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    30
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    31
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    32
*/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    33
#include "nmtMaster.h"
149
fe50ada8020b Changes in the API:
etisserant
parents: 71
diff changeset
    34
#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
    35
#include "sysdep.h"
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    36
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    37
/*!
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    38
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    39
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    40
** @param d
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    41
** @param Node_ID
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    42
** @param cs
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    43
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    44
** @return
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    45
**/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    46
UNS8 masterSendNMTstateChange(CO_Data* d, UNS8 Node_ID, UNS8 cs)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    47
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    48
  Message m;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    49
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    50
  MSG_WAR(0x3501, "Send_NMT cs : ", cs);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    51
  MSG_WAR(0x3502, "    to node : ", Node_ID);
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
    52
  /* message configuration */
365
9b76e0881beb Changed cob_id from struct{UNS32} to UNS16
etisserant
parents: 215
diff changeset
    53
  m.cob_id = 0x0000; /*(NMT) << 7*/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    54
  m.rtr = NOT_A_REQUEST;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    55
  m.len = 2;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    56
  m.data[0] = cs;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    57
  m.data[1] = Node_ID;
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    58
149
fe50ada8020b Changes in the API:
etisserant
parents: 71
diff changeset
    59
  return canSend(d->canHandle,&m);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    60
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    61
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    62
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    63
/*!
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    64
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    65
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    66
** @param d
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    67
** @param nodeId
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    68
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    69
** @return
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    70
**/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    71
UNS8 masterSendNMTnodeguard(CO_Data* d, UNS8 nodeId)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    72
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    73
  Message m;
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    74
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    75
  /* message configuration */
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
    76
  UNS16 tmp = nodeId | (NODE_GUARD << 7); 
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
    77
  m.cob_id = UNS16_LE(tmp);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    78
  m.rtr = REQUEST;
597
ea32aa303987 Fixed wrong cast in sdo.c and wrong message length in nodeguarding
edouard
parents: 370
diff changeset
    79
  m.len = 0;
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    80
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
    81
  MSG_WAR(0x3503, "Send_NODE_GUARD to node : ", nodeId);
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
    82
149
fe50ada8020b Changes in the API:
etisserant
parents: 71
diff changeset
    83
  return canSend(d->canHandle,&m);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    84
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    85
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    86
/*!
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    87
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    88
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    89
** @param d
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    90
** @param nodeId
631
08b6b903f84a Piotr Trojanek (ptroja) cleanup patche. Thanks.
edouard
parents: 597
diff changeset
    91
**
08b6b903f84a Piotr Trojanek (ptroja) cleanup patche. Thanks.
edouard
parents: 597
diff changeset
    92
** @return
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    93
**/
631
08b6b903f84a Piotr Trojanek (ptroja) cleanup patche. Thanks.
edouard
parents: 597
diff changeset
    94
UNS8 masterRequestNodeState(CO_Data* d, UNS8 nodeId)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    95
{
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
    96
  /* FIXME: should warn for bad toggle bit. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    97
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
    98
  /* NMTable configuration to indicate that the master is waiting
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
    99
    for a Node_Guard frame from the slave whose node_id is ID
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
   100
  */
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   101
  d->NMTable[nodeId] = Unknown_state; /* A state that does not exist
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 149
diff changeset
   102
                                       */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   103
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   104
  if (nodeId == 0) { /* NMT broadcast */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   105
    UNS8 i = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   106
    for (i = 0 ; i < NMT_MAX_NODE_ID ; i++) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   107
      d->NMTable[i] = Unknown_state;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   108
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   109
  }
631
08b6b903f84a Piotr Trojanek (ptroja) cleanup patche. Thanks.
edouard
parents: 597
diff changeset
   110
  return masterSendNMTnodeguard(d,nodeId);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   111
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   112