src/nmtMaster.c
author frdupin
Wed, 13 Dec 2006 14:14:18 +0100
changeset 53 73bc47a0db55
parent 0 4472ee7c6c3e
child 71 95cd3376cc9f
permissions -rw-r--r--
Add prototypes
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     1
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     2
This file is part of CanFestival, a library implementing CanOpen Stack. 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     3
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     4
Copyright (C): Edouard TISSERANT and Francis DUPIN
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     5
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     6
See COPYING file for copyrights details.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     7
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     8
This library is free software; you can redistribute it and/or
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     9
modify it under the terms of the GNU Lesser General Public
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    10
License as published by the Free Software Foundation; either
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    11
version 2.1 of the License, or (at your option) any later version.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    12
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    13
This library is distributed in the hope that it will be useful,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    14
but WITHOUT ANY WARRANTY; without even the implied warranty of
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    16
Lesser General Public License for more details.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    17
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    18
You should have received a copy of the GNU Lesser General Public
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    19
License along with this library; if not, write to the Free Software
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    20
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    21
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    22
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    23
#include "nmtMaster.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    24
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    25
/******************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    26
UNS8 masterSendNMTstateChange(CO_Data* d, UNS8 Node_ID, UNS8 cs)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    27
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    28
  Message m;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    29
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    30
  MSG_WAR(0x3501, "Send_NMT cs : ", cs);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    31
  MSG_WAR(0x3502, "    to node : ", Node_ID);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    32
  /* message configuration */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    33
  m.cob_id.w = 0x0000; /*(NMT) << 7*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    34
  m.rtr = NOT_A_REQUEST;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    35
  m.len = 2;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    36
  m.data[0] = cs;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    37
  m.data[1] = Node_ID;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    38
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    39
  return (*d->canSend)(&m);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    40
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    41
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    42
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    43
/****************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    44
UNS8 masterSendNMTnodeguard(CO_Data* d, UNS8 nodeId)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    45
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    46
  Message m;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    47
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    48
  MSG_WAR(0x3503, "Send_NODE_GUARD to node : ", nodeId);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    49
	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    50
  /* message configuration */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    51
  m.cob_id.w = nodeId | (NODE_GUARD << 7);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    52
  m.rtr = REQUEST;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    53
  m.len = 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    54
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    55
  return (*d->canSend)(&m);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    56
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    57
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    58
/******************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    59
void masterRequestNodeState(CO_Data* d, UNS8 nodeId)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    60
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    61
  // FIXME: should warn for bad toggle bit.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    62
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    63
  /* NMTable configuration to indicate that the master is waiting
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    64
   * for a Node_Guard frame from the slave whose node_id is ID */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    65
  d->NMTable[nodeId] = Unknown_state; // A state that does not exist
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    66
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    67
  if (nodeId == 0) { // NMT broadcast
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    68
    UNS8 i = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    69
    for (i = 0 ; i < NMT_MAX_NODE_ID ; i++) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    70
      d->NMTable[i] = Unknown_state;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    71
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    72
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    73
  masterSendNMTnodeguard(d,nodeId);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    74
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    75
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    76
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    77
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    78
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    79
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    80
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    81
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    82
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    83