examples/AppliMaster_HCS12/appli.c
author etisserant
Thu, 11 May 2006 13:52:43 +0200
changeset 2 8d4a822f95e4
parent 0 4472ee7c6c3e
permissions -rwxr-xr-x
Fixed Endianisation/ValueRange order in SetODentry
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 <stddef.h> /* for NULL */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    24
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    25
#include <asm-m68hc12/portsaccess.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    26
#include <asm-m68hc12/ports_def.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    27
#include <asm-m68hc12/ports.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    28
#include  <interrupt.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    29
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    30
#include <applicfg.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    31
#include <candriver.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    32
#include <timerhw.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    33
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    34
#include "def.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    35
#include "can.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    36
#include "objdictdef.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    37
#include "objacces.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    38
#include "canOpenDriver.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    39
#include "sdo.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    40
#include "pdo.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    41
#include "init.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    42
#include "timer.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    43
#include "lifegrd.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    44
#include "sync.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    45
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    46
#include "nmtMaster.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    47
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    48
// For prototype of exit();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    49
#define exit _exit
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    50
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    51
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    52
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    53
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    54
// HCS12 configuration
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    55
// -----------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    56
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    57
enum E_CanBaudrate 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    58
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    59
   CAN_BAUDRATE_250K,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    60
   CAN_BAUDRATE_500K,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    61
   CAN_BAUDRATE_1M,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    62
   CAN_BAUDRATE_OLD_VALUE
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    63
};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    64
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    65
const canBusTime CAN_Baudrates[] =
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    66
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    67
   {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    68
      1,  /* clksrc: Use the bus clock : 16 MHz, the freq. of the quartz's board        */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    69
      3,  /* brp :  chose btw 0 and 63 (6 bits).  freq time quantum = 16MHz / (brp + 1) */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    70
      0,  /* sjw : chose btw 0 and 3 (2 bits). Sync on (sjw + 1 ) time quantum          */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    71
      0,  /* samp : chose btw 0 and 3 (2 bits) (samp + 1 ) samples per bit              */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    72
      1,  /* tseg2 : chose btw 0 and 7 (3 bits) Segment 2 width = (tseg2 + 1)  tq       */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    73
     12,  /* tseg1 : chose btw 0 and 15 (4 bits) Segment 1 width = (tseg1 + 1)  tq      */
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
      With these values, 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    77
      - The width of the bit time is 16 time quantum :
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    78
          - 1 tq for the SYNC segment (could not be modified)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    79
          - 13 tq for the TIME 1 segment (tseg1 = 12)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    80
          - 2 tq for the TIME 2 segment (tseg2 = 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    81
      - Because the bus clock of the MSCAN is 16 MHZ, and the 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    82
        freq of the time quantum is 4 MHZ (brp = 3+1), and  there are 16 tq in the bit time,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    83
        so the freq of the bit time is 250 kHz.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    84
      */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    85
   },
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    86
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    87
   {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    88
      1,  /* clksrc: Use the bus clock : 16 MHz, the freq. of the quartz's board        */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    89
      1,  /* brp :  chose btw 0 and 63 (6 bits).  freq time quantum = 16MHz / (brp + 1) */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    90
      0,  /* sjw : chose btw 0 and 3 (2 bits). Sync on (sjw + 1 ) time quantum          */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    91
      0,  /* samp : chose btw 0 and 3 (2 bits) (samp + 1 ) samples per bit              */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    92
      1,  /* tseg2 : chose btw 0 and 7 (3 bits) Segment 2 width = (tseg2 + 1)  tq       */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    93
     12,  /* tseg1 : chose btw 0 and 15 (4 bits) Segment 1 width = (tseg1 + 1)  tq      */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    94
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    95
      /*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    96
      With these values, 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    97
      - The width of the bit time is 16 time quantum :
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    98
          - 1 tq for the SYNC segment (could not be modified)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    99
          - 13 tq for the TIME 1 segment (tseg1 = 12)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   100
          - 2 tq for the TIME 2 segment (tseg2 = 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   101
      - Because the bus clock of the MSCAN is 16 MHZ, and the 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   102
        freq of the time quantum is 8 MHZ (brp = 1+1), and  there are 16 tq in the bit time,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   103
        so the freq of the bit time is 500 kHz.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   104
      */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   105
    },
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   106
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   107
	{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   108
      1,  /* clksrc: Use the bus clock : 16 MHz, the freq. of the quartz's board        */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   109
      1,  /* brp :  chose btw 0 and 63 (6 bits).  freq time quantum = 16MHz / (brp + 1) */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   110
      0,  /* sjw : chose btw 0 and 3 (2 bits). Sync on (sjw + 1 ) time quantum          */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   111
      0,  /* samp : chose btw 0 and 3 (2 bits) (samp + 1 ) samples per bit              */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   112
      1,  /* tseg2 : chose btw 0 and 7 (3 bits) Segment 2 width = (tseg2 + 1)  tq       */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   113
      4,  /* tseg1 : chose btw 0 and 15 (4 bits) Segment 1 width = (tseg1 + 1)  tq      */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   114
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   115
      /*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   116
      With these values, 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   117
      - The width of the bit time is 16 time quantum :
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   118
          - 1 tq for the SYNC segment (could not be modified)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   119
          - 5 tq for the TIME 1 segment (tseg1 = 4)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   120
          - 2 tq for the TIME 2 segment (tseg2 = 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   121
      - Because the bus clock of the MSCAN is 16 MHZ, and the 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   122
        freq of the time quantum is 8 MHZ (brp = 1+1), and  there are 8 tq in the bit time,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   123
        so the freq of the bit time is 1 MHz.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   124
      */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   125
    },
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   126
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   127
	{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   128
      1,  /* clksrc: Use the bus clock : 16 MHz, the freq. of the quartz's board        */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   129
      0,  /* brp :  chose btw 0 and 63 (6 bits).  freq time quantum = 16MHz / (brp + 1) */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   130
      1,  /* sjw : chose btw 0 and 3 (2 bits). Sync on (sjw + 1 ) time quantum          */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   131
      1,  /* samp : chose btw 0 and 3 (2 bits) (samp + 1 ) samples per bit              */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   132
      4,  /* tseg2 : chose btw 0 and 7 (3 bits) Segment 2 width = (tseg2 + 1)  tq       */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   133
      9,  /* tseg1 : chose btw 0 and 15 (4 bits) Segment 1 width = (tseg1 + 1)  tq      */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   134
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   135
      /*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   136
      With these values, 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   137
      - The width of the bit time is 16 time quantum :
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   138
          - 1 tq for the SYNC segment (could not be modified)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   139
          - 10 tq for the TIME 1 segment (tseg1 = 9)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   140
          - 5 tq for the TIME 2 segment (tseg2 = 4)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   141
      - Because the bus clock of the MSCAN is 16 MHZ, and the 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   142
        freq of the time quantum is 16 MHZ (brp = 0), and  there are 16 tq in the bit time,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   143
        so the freq of the bit time is 1 MHz.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   144
      */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   145
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   146
};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   147
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   148
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   149
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   150
// Required definition variables
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   151
// -----------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   152
// The variables that you should define for debugging.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   153
// They are used by the macro MSG_ERR and MSG_WAR in applicfg.h
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   154
// if the node is a slave, they can be mapped in the object dictionnary.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   155
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   156
UNS8 printMsgErrToConsole = 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   157
UNS8 printMsgWarToConsole = 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   158
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   159
// The variables mapped in the object dictionnary
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   160
// ----------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   161
extern UNS32 canopenErrNB_node5;   // Mapped at index 0x6000, subindex 0x0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   162
extern UNS32 canopenErrVAL_node5;  // Mapped at index 0x6001, subindex 0x0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   163
extern UNS8 second;		   // Mapped at index 0x6002, subindex 0x1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   164
extern UNS8 minutes;		   // Mapped at index 0x6002, subindex 0x2
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   165
extern UNS8 hour;		   // Mapped at index 0x6002, subindex 0x3
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   166
extern UNS8 day;		   // Mapped at index 0x6002, subindex 0x4
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   167
extern UNS32 canopenErrNB;	   // Mapped at index 0x6003, subindex 0x1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   168
extern UNS32 canopenErrVAL;	   // Mapped at index 0x6003, subindex 0x2
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   169
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   170
/*************************User's variables declaration**************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   171
UNS8 connectedNode[128];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   172
volatile UNS8 sec = 0; // To count the time every second
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   173
UNS8 softCount = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   174
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   175
/* The variable to map in a PDO is defined at index and subIndex. Its length is size bytes */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   176
typedef struct mappedVar 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   177
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   178
  UNS32 index;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   179
  UNS8  subIndex;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   180
  UNS8  size; // in byte
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   181
} s_mappedVar;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   182
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   183
typedef struct heartbeatConsumer
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   184
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   185
  UNS8 nodeProducer;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   186
  UNS16 time_ms;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   187
} s_heartbeatConsumer;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   188
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   189
/**************************prototypes*****************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   190
/* You *must* have these 2 functions in your code*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   191
void heartbeatError(UNS8 heartbeatID );
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   192
void SD0timeoutError(UNS8 bus_id, UNS8 line);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   193
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   194
void waitMessage (void );
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   195
void heartBeat (void );
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   196
void transmitSync (void);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   197
e_nodeState stateNode (UNS8 node);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   198
void configure_master_SDO (UNS32 index, UNS8 serverNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   199
UNS8 waitingWriteToSlaveDict ( UNS8 slaveNode, UNS8 error);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   200
UNS8 waitingReadToSlaveDict (UNS8 slaveNode, void * data, UNS8 * size, UNS8 error);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   201
UNS8 configure_client_SDO (UNS8 slaveNode, UNS8 clientNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   202
void masterMappingPDO (UNS32 indexPDO, UNS32 cobId, 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   203
		      s_mappedVar *tabMappedVar, UNS8 nbVar);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   204
void slaveMappingPDO (UNS8 slaveNode, UNS32 indexPDO, UNS32 cobId, 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   205
		     s_mappedVar *tabMappedVar, UNS8 nbVar);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   206
void masterHeartbeatConsumer (s_heartbeatConsumer 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   207
			     *tabHeartbeatConsumer, UNS8 nbHeartbeats);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   208
void masterHeartbeatProducer (UNS16 time);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   209
void slaveHeartbeatConsumer (UNS8 slaveNode, s_heartbeatConsumer 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   210
			    *tabHeartbeatConsumer, UNS8 nbHeartbeats);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   211
void slaveHeartbeatProducer (UNS8 slaveNode, UNS16 time);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   212
void masterPDOTransmissionMode (UNS32 indexPDO,  UNS8 transType);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   213
void slavePDOTransmissionMode (UNS8 slaveNode, UNS32 indexPDO,  UNS8 transType);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   214
void masterSYNCPeriod (UNS32 SYNCPeriod);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   215
int main (void);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   216
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   217
// Interruption timer 3. (The timer 4 is used by CanOpen)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   218
void __attribute__((interrupt)) timer3Hdl (void);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   219
void incDate (void);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   220
void initLeds (void);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   221
void initCanHCS12 (void);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   222
void initTimerClk (void);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   223
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   224
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   225
/*****************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   226
void heartbeatError(UNS8 heartbeatID)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   227
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   228
  // MSG_ERR should send the values canopenErrNB and canopenErrVAL on event in a PDO,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   229
  // But we do not have mapped the variables in a PDO, so it sends nothing.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   230
  // See the note at the end of END CONFIGURING THE NETWORK.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   231
  MSG_WAR(0x2F00, "HeartBeat, no response from node : ", heartbeatID);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   232
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   233
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   234
/*****************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   235
void SD0timeoutError (UNS8 bus_id, UNS8 line)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   236
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   237
  // Informations on what occurs are in transfers[bus_id][line]....
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   238
  // See scanSDOtimeout() in sdo.c
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   239
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   240
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   241
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   242
/************************** FUNCTIONS TO CONFIGURE THE NETWORK******************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   243
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   244
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   245
/* Node mode result after NodeGuard query */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   246
e_nodeState stateNode(UNS8 node) 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   247
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   248
  e_nodeState state = getNodeState(0, node);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   249
  switch (state) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   250
  case Unknown_state: 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   251
    MSG_WAR(0x3F05, "Not connected (Does not have sent its status) node :", node);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   252
    break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   253
  case Operational: 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   254
    MSG_WAR(0x3F06, "Ok, in operational mode, node : ", node);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   255
    break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   256
  case Pre_operational: 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   257
    MSG_WAR(0x3F07, "OK in pre-operational mode, node : ", node);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   258
    break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   259
  default:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   260
    MSG_WAR(0x3F08, "OK connected but in curious mode, node : ", node);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   261
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   262
  return state;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   263
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   264
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   265
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   266
/* The master is writing in its dictionnary to configure the SDO parameters 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   267
to communicate with server_node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   268
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   269
void configure_master_SDO(UNS32 index, UNS8 serverNode)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   270
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   271
  UNS32 data32;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   272
  UNS8  data8;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   273
  UNS8 sizeData = 4 ; // in bytes
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   274
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   275
  /* At subindex 1, the cobId of the Can message from the client.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   276
  It is always defined inside the server dictionnary as 0x600 + server_node.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   277
  So, we have no choice here ! */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   278
  data32 = 0x600 + serverNode;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   279
  setODentry(index, 1, &data32, sizeData, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   280
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   281
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   282
    // Test
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   283
    UNS32  *pbData;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   284
    UNS8 length;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   285
    UNS32 returnValue;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   286
    UNS8 dataType;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   287
    // Relecture
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   288
    MSG_WAR(0x1000, "Reading index : ", index);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   289
    MSG_WAR(0x1000, "     subindex : ", 1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   290
    returnValue = getODentry(index, 1, (void * *)&pbData, (UNS8 *)&length, &dataType, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   291
    MSG_WAR(0x1000, "          val : ", *pbData);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   292
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   293
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   294
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   295
  /* At subindex 2, the cobId of the Can message from the server to the client.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   296
  It is always defined inside the server dictionnary as 0x580 + client_node.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   297
  So, we have no choice here ! */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   298
  data32 = 0x580 + serverNode;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   299
  setODentry(index, 2, &data32, sizeData, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   300
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   301
  /* At subindex 3, the node of the server */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   302
  data8 = serverNode;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   303
  sizeData = 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   304
  setODentry(index, 3, &data8, sizeData, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   305
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   306
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   307
    UNS8  *pbData;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   308
    UNS8 length;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   309
    UNS32 returnValue;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   310
    UNS8 dataType;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   311
    // Relecture
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   312
    MSG_WAR(0x1000, "Reading  index : ", index);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   313
    MSG_WAR(0x1000, "      subindex : ", 3);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   314
    returnValue = getODentry(index, 1, (void * *)&pbData, (UNS8 *)&length, &dataType, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   315
    MSG_WAR(0x1000, "           val : ", *pbData);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   316
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   317
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   318
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   319
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   320
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   321
 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   322
UNS8 waitingWriteToSlaveDict(UNS8 slaveNode, UNS8 error)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   323
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   324
   UNS8 err;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   325
  UNS32 abortCode;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   326
  MSG_WAR(0x3F21, "Sending SDO to write in dictionnary of node : ", slaveNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   327
  if (error) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   328
    MSG_ERR(0x1F22, "Unable to send the SDO to node ", slaveNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   329
    return -1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   330
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   331
  /* Waiting until the slave has responded */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   332
  while (getWriteResultNetworkDict (0, slaveNode, &abortCode) == SDO_DOWNLOAD_IN_PROGRESS) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   333
    // Check if some SDO response are missing
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   334
    scanSDOtimeout();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   335
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   336
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   337
  err = getWriteResultNetworkDict (0, slaveNode, &abortCode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   338
  if (err == SDO_FINISHED) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   339
    MSG_WAR(0x3F22, "SDO download finished to Node : ", slaveNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   340
    // Release the line. Don't forget !!!
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   341
    closeSDOtransfer(0, slaveNode, SDO_CLIENT);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   342
    return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   343
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   344
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   345
  if (err == SDO_ABORTED_RCV) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   346
    MSG_WAR(0x2F20, "Received SDO abort from node : ", slaveNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   347
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   348
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   349
  if (err == SDO_ABORTED_INTERNAL) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   350
    MSG_WAR(0x2F20, "Internal SDO abort for node : ", slaveNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   351
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   352
  // Looking for the line transfert number to read the index, subindex and releasing the line.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   353
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   354
    UNS8 line;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   355
    err = getSDOlineOnUse(0, slaveNode, SDO_CLIENT, &line);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   356
    if (err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   357
      MSG_WAR(0x2F21, "No line found for node : ", slaveNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   358
      exit(-1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   359
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   360
    MSG_WAR (0x2F22, "while writing at his index : ", transfers[0][line].index);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   361
    MSG_WAR (0x2F23, "                  subIndex : ", transfers[0][line].subIndex);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   362
    //Releasing the line.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   363
    closeSDOtransfer(0, slaveNode, SDO_CLIENT);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   364
    exit(-1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   365
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   366
 return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   367
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   368
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   369
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   370
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   371
 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   372
UNS8 waitingReadToSlaveDict(UNS8 slaveNode, void * data, UNS8 * size, UNS8 error)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   373
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   374
  UNS8 err;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   375
  UNS32 abortCode;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   376
  MSG_WAR(0x3F2A, "Sending SDO to read in dictionnary of node : ", slaveNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   377
  if (error) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   378
    MSG_ERR(0x1F2B, "Unable to send the SDO to node ", slaveNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   379
    return -1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   380
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   381
  /* Waiting until the slave has responded */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   382
  while (getReadResultNetworkDict (0, slaveNode, data, size, &abortCode) == SDO_UPLOAD_IN_PROGRESS) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   383
    // Check if some SDO response are missing
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   384
    scanSDOtimeout();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   385
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   386
  err = getReadResultNetworkDict (0, slaveNode, data, size, &abortCode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   387
  if (err == SDO_FINISHED) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   388
    MSG_WAR(0x3F2C, "SDO upload finished to Node : ", slaveNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   389
    // Release the line. Don't forget !!!
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   390
    closeSDOtransfer(0, slaveNode, SDO_CLIENT);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   391
    return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   392
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   393
  if (err == SDO_ABORTED_RCV) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   394
    MSG_WAR(0x2F2D, "Received SDO abort from node : ", slaveNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   395
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   396
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   397
  if (err == SDO_ABORTED_INTERNAL) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   398
    MSG_WAR(0x2F2E, "Internal SDO abort for node : ", slaveNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   399
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   400
  // Looking for the line transfert number to read the index, subindex and releasing the line.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   401
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   402
    UNS8 line;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   403
    err = getSDOlineOnUse(0, slaveNode, SDO_CLIENT, &line);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   404
    if (err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   405
      MSG_WAR(0x2F2F, "No line found for node : ", slaveNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   406
      exit(-1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   407
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   408
    MSG_WAR (0x2F30, "while writing at his index : ", transfers[0][line].index);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   409
    MSG_WAR (0x2F31, "                  subIndex : ", transfers[0][line].subIndex);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   410
    //Releasing the line.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   411
    closeSDOtransfer(0, slaveNode, SDO_CLIENT);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   412
    exit(-1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   413
  }    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   414
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   415
 return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   416
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   417
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   418
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   419
/* The master is writing in the slave dictionnary to configure the SDO parameters
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   420
Remember that the slave is the server, and the master is the client.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   421
 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   422
UNS8 configure_client_SDO(UNS8 slaveNode, UNS8 clientNode)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   423
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   424
  UNS8 data;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   425
  UNS8 NbDataToWrite = 1 ; // in bytes
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   426
  UNS8 err = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   427
  MSG_WAR(0x3F20, "Configuring SDO by writing in dictionnary Node ", slaveNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   428
  /* It is only to put at subindex 3 the serverNode. It is optionnal.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   429
     In the slave dictionary, only one SDO server is defined, at index 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   430
     0x1200 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   431
  data = clientNode;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   432
  err = writeNetworkDict(0, slaveNode, 0x1200, 3, NbDataToWrite, 0, &data); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   433
  waitingWriteToSlaveDict(slaveNode, err);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   434
 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   435
  return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   436
}		
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   437
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   438
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   439
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   440
 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   441
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   442
void masterMappingPDO(UNS32 indexPDO, UNS32 cobId, 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   443
		      s_mappedVar *tabMappedVar, UNS8 nbVar)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   444
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   445
  UNS32 *pbData;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   446
  UNS32 data32; 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   447
  UNS8 i;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   448
  UNS8 size = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   449
  UNS8 dataType;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   450
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   451
  if ((indexPDO >= 0x1400) && (indexPDO <= 0x15FF))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   452
    MSG_WAR(0x3F30, "Configuring MASTER for PDO receive, COBID : ", cobId);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   453
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   454
  if ((indexPDO >= 0x1800) && (indexPDO <= 0x19FF))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   455
    MSG_WAR(0x3F31, "Configuring MASTER for PDO transmit, COBID : ", cobId);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   456
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   457
  /* At indexPDO, subindex 1, defining the cobId of the PDO */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   458
  setODentry(indexPDO, 1, &cobId, 4, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   459
  /* The mapping ... */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   460
  /* ----------------*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   461
  /* At subindex 0, the number of variables in the PDO */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   462
  setODentry(indexPDO + 0x200, 0, &nbVar, 1, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   463
  getODentry(indexPDO + 0x200, 0, (void * *)&pbData, &size, &dataType, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   464
  /* At each subindex 1 .. nbVar, The index,subindex and size of the variable to map in 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   465
     the PDO. The first variable after the COBID is defined at subindex 1, ... 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   466
     The data to write is the concatenation on 32 bits of (msb ... lsb) : 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   467
     index(16b),subIndex(8b),sizeVariable(8b)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   468
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   469
  for (i = 0 ; i < nbVar ; i++) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   470
    data32 = ((tabMappedVar + i)->index << 16) |
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   471
      (((tabMappedVar + i)->subIndex & 0xFF) << 8) |
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   472
      ((tabMappedVar + i)->size & 0xFF);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   473
    // Write dictionary
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   474
    setODentry(indexPDO + 0x200, i + 1, &data32, 4, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   475
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   476
#   ifdef MORE_COMMENTS
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   477
    printf("Mapped variable defined  at index 0x%X, subIndex 0x%X, %d bits\n", 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   478
	   (tabMappedVar + i)->index, (tabMappedVar + i)->subIndex, 8 * (tabMappedVar + i)->size);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   479
    // Only to verify.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   480
    // Read dictionnary
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   481
    getODentry(indexPDO + 0x200, i + 1, (void * *)&pbData, &size, &dataType, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   482
    printf("Writen à  index 0x%X, subIndex 0x%X, %d bits : 0x%08X\n", 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   483
	   indexPDO + 0x200, i + 1, 8 * size, *pbData);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   484
#   endif
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   485
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   486
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   487
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   488
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   489
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   490
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   491
 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   492
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   493
void slaveMappingPDO(UNS8 slaveNode, UNS32 indexPDO, UNS32 cobId, 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   494
		     s_mappedVar *tabMappedVar, UNS8 nbVar)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   495
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   496
  UNS32 data32; 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   497
  UNS8 i;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   498
  UNS8 err;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   499
  UNS8 nbBytes = 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   500
  if ((indexPDO >= 0x1400) && (indexPDO <= 0x15FF))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   501
    MSG_WAR(0x3F32, "Configuring slave for PDO receive, COBID : ", cobId);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   502
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   503
  if ((indexPDO >= 0x1800) && (indexPDO <= 0x19FF))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   504
    MSG_WAR(0x3F33, "Configuring slave for PDO transmit, COBID : ", cobId);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   505
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   506
  /* At indexPDO, subindex 1, defining the cobId of the PDO */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   507
  err = writeNetworkDict(0, slaveNode, indexPDO, 1, 4, 0, &cobId); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   508
  waitingWriteToSlaveDict(slaveNode, err);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   509
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   510
  /* The mapping ... */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   511
  /* ----------------*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   512
  /* At subindex 0, the number of variables in the PDO */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   513
  err = writeNetworkDict(0, slaveNode, indexPDO + 0x200, 0, nbBytes, 0, &nbVar); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   514
  waitingWriteToSlaveDict(slaveNode, err);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   515
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   516
  /* At each subindex 1 .. nbVar, The index,subindex and size of the variable to map in 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   517
     the PDO. The first variable after the COBID is defined at subindex 1, ... 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   518
     The data to write is the concatenation on 32 bits of (msb ... lsb) : 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   519
     index(16b),subIndex(8b),sizeVariable(8b)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   520
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   521
  for (i = 0 ; i < nbVar ; i++) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   522
    data32 = ((tabMappedVar + i)->index << 16) |
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   523
      (((tabMappedVar + i)->subIndex & 0xFF) << 8) |
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   524
      ((tabMappedVar + i)->size & 0xFF);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   525
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   526
    // Write dictionary
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   527
    err = writeNetworkDict(0, slaveNode, indexPDO + 0x200, i + 1, 4, 0, &data32); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   528
    waitingWriteToSlaveDict(slaveNode, err);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   529
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   530
#   ifdef MORE_COMMENTS
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   531
    printf("Mapped variable defined  at index 0x%X, subIndex 0x%X, %d bits\n", 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   532
	   (tabMappedVar + i)->index, (tabMappedVar + i)->subIndex, 8 * (tabMappedVar + i)->size);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   533
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   534
    printf("At node 0x%X Writen at  index 0x%X, subIndex 0x%X, %d bits : 0x%08X\n", 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   535
	   slaveNode, indexPDO + 0x200, i + 1, 32, data32);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   536
#   endif
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   537
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   538
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   539
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   540
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   541
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   542
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   543
 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   544
void masterHeartbeatConsumer(s_heartbeatConsumer 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   545
			     *tabHeartbeatConsumer, UNS8 nbHeartbeats)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   546
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   547
  UNS32 data;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   548
  UNS8 i;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   549
  UNS8 nbHB = nbHeartbeats;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   550
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   551
  MSG_WAR(0x3F40, "Configuring heartbeats consumers for master", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   552
  /* At index 1016, subindex 0 : the nb of consumers (ie nb of nodes of which are expecting heartbeats) */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   553
  setODentry(0x1016, 0, & nbHB, 1, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   554
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   555
  /* At Index 1016, subindex 1, ... : 32 bit values : msb ... lsb :
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   556
     00 - node_consumer (8b) - time_ms (16b)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   557
     Put 0 to ignore the entry.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   558
  */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   559
  for (i = 0 ; i < nbHeartbeats ; i++) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   560
    data = (((tabHeartbeatConsumer + i)->nodeProducer & 0xFF)<< 16) | ((tabHeartbeatConsumer + i)->time_ms & 0xFFFF);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   561
    setODentry(0x1016, i + 1, & data, 4, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   562
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   563
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   564
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   565
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   566
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   567
 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   568
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   569
void masterHeartbeatProducer(UNS16 time)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   570
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   571
  UNS16 hbTime = time;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   572
  MSG_WAR(0x3F45, "Configuring heartbeat producer for master", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   573
  /* At index 1017, subindex 0, defining the time to send the heartbeat. Put 0 to never send heartbeat */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   574
  setODentry(0x1017, 0, &hbTime, 2, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   575
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   576
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   577
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   578
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   579
 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   580
void slaveHeartbeatConsumer(UNS8 slaveNode, s_heartbeatConsumer 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   581
			    *tabHeartbeatConsumer, UNS8 nbHeartbeats)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   582
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   583
  UNS32 data;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   584
  UNS8 err;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   585
  UNS8 i;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   586
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   587
  MSG_WAR(0x3F46, "Configuring heartbeats consumers for node  : ", slaveNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   588
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   589
  /* At Index 1016, subindex 1, ... : 32 bit values : msb ... lsb :
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   590
     00 - node_consumer (8b) - time_ms (16b)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   591
     Put 0 to ignore the entry.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   592
  */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   593
  for (i = 0 ; i < nbHeartbeats ; i++) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   594
    data = (((tabHeartbeatConsumer + i)->nodeProducer & 0xFF)<< 16) | 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   595
      ((tabHeartbeatConsumer + i)->time_ms & 0xFFFF);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   596
    err = writeNetworkDict(0, slaveNode, 0x1016, i + 1, 4, 0, &data); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   597
    waitingWriteToSlaveDict(slaveNode, err);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   598
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   599
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   600
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   601
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   602
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   603
 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   604
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   605
void slaveHeartbeatProducer(UNS8 slaveNode, UNS16 time)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   606
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   607
  UNS8 err;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   608
  MSG_WAR(0x3F47, "Configuring heartbeat producer for node  : ", slaveNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   609
  /* At index 1017, subindex 0, defining the time to send the heartbeat. Put 0 to never send heartbeat */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   610
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   611
  err = writeNetworkDict(0, slaveNode, 0x1017, 0, 2, 0, &time); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   612
  waitingWriteToSlaveDict(slaveNode, err);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   613
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   614
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   615
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   616
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   617
 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   618
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   619
void masterPDOTransmissionMode(UNS32 indexPDO,  UNS8 transType)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   620
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   621
  MSG_WAR(0x3F48, "Configuring transmission from master, indexPDO : ", indexPDO);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   622
 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   623
  /* At subindex 2, the transmission type */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   624
  setODentry(indexPDO, 2, &transType, 1, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   625
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   626
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   627
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   628
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   629
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   630
 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   631
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   632
void slavePDOTransmissionMode(UNS8 slaveNode, UNS32 indexPDO,  UNS8 transType)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   633
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   634
  UNS8 err;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   635
  MSG_WAR(0x3F41, "Configuring transmission mode for node : ", slaveNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   636
  MSG_WAR(0x3F42, "                              indexPDO : ", indexPDO);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   637
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   638
  err = writeNetworkDict(0, slaveNode, indexPDO, 2, 1, 0, &transType); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   639
  waitingWriteToSlaveDict(slaveNode, err);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   640
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   641
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   642
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   643
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   644
 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   645
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   646
void masterSYNCPeriod(UNS32 SYNCPeriod)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   647
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   648
 UNS32 cobId = 0x40000080;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   649
 MSG_WAR(0x3F49, "Configuring master to send SYNC every ... micro-seconds :", SYNCPeriod);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   650
 /* At index 0x1006, subindex 0 : the period in ms */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   651
 setODentry(0x1006, 0, &SYNCPeriod , 4, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   652
 /* At index 0x1005, subindex 0 : Device generate SYNC signal with CobId 0x80 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   653
 setODentry(0x1005, 0, &cobId, 4, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   654
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   655
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   656
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   657
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   658
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   659
//Initialisation of the port B for the leds.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   660
void initLeds(void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   661
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   662
  // Port B is output
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   663
  IO_PORTS_8(DDRB)= 0XFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   664
  // RAZ
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   665
  IO_PORTS_8(PORTB) = 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   666
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   667
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   668
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   669
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   670
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   671
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   672
void initCanHCS12 (void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   673
{  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   674
  //Init the HCS12 microcontroler for CanOpen 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   675
  initHCS12();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   676
   // Init the HCS12  CAN driver
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   677
  const canBusInit bi0 = {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   678
    0,    /* no low power                 */ 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   679
    0,    /* no time stamp                */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   680
    1,    /* enable MSCAN                 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   681
    0,    /* clock source : oscillator (In fact, it is not used)   */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   682
    0,    /* no loop back                 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   683
    0,    /* no listen only               */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   684
    0,    /* no low pass filter for wk up */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   685
	CAN_Baudrates[CAN_BAUDRATE_250K],
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   686
    {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   687
      0x00,    /* Filter on 16 bits. See Motorola Block Guide V02.14 fig 4-3 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   688
      0x00, 0xFF, /* filter 0 hight accept all msg      */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   689
      0x00, 0xFF, /* filter 0 low accept all msg        */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   690
      0x00, 0xFF, /* filter 1 hight filter all of  msg  */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   691
      0x00, 0xFF, /* filter 1 low filter all of  msg    */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   692
      0x00, 0xFF, /* filter 2 hight filter most of  msg */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   693
      0x00, 0xFF, /* filter 2 low filter most of  msg   */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   694
      0x00, 0xFF, /* filter 3 hight filter most of  msg */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   695
      0x00, 0xFF, /* filter 3 low filter most of  msg   */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   696
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   697
  };   
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   698
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   699
  canInit(CANOPEN_LINE_NUMBER_USED, bi0);  //initialize filters...
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   700
  unlock(); // Allow interruptions
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   701
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   702
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   703
/*********************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   704
// For Second timer
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   705
void incDate(void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   706
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   707
  if (sec == 59) 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   708
    sec = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   709
  else
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   710
    sec++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   711
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   712
  // Toggle the led 4 every seconds
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   713
  IO_PORTS_8(PORTB) ^= 0x10;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   714
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   715
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   716
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   717
// Init the time for the second counter
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   718
void initTimerClk(void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   719
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   720
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   721
  lock();   // Inhibe les interruptions
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   722
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   723
  // Configuration du Channel 3
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   724
  IO_PORTS_8(TIOS) |= 0x08;     // Canal 3 en sortie
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   725
  IO_PORTS_8(TCTL2) &= ~(0xC0); // Canal 3 déconnecté du pin de sortie
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   726
  IO_PORTS_8(TIE) |= 0x08;      // Autorise interruption Canal 3
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   727
  IO_PORTS_8(TSCR1) |= 0x80;    // Mise en route du timer
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   728
  unlock(); // Autorise les interruptions
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   729
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   730
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   731
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   732
/*********************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   733
void __attribute__((interrupt)) timer3Hdl(void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   734
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   735
  //IO_PORTS_8(PORTB) ^= 0x10;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   736
  //IO_PORTS_8(PORTB) &= ~0x20;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   737
  IO_PORTS_8(TFLG1) = 0x08; // RAZ du flag interruption timer 3
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   738
  // Calcul evt suivant. Clock 8 MHz -> 8000 evt de 1 ms!! Doit tenir sur 16 bits
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   739
  // Attention, ça change si on utilise la pll
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   740
  // Lorsque le timer atteindra la valeur de TC3 (16 bits), l'interruption timer3Hdl sera déclenchée
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   741
  // Si on utilise la PLL à 24 MHZ, alors la vitesse du bus est multipliée par 3.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   742
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   743
/*   Assume that our board uses a 16 MHz quartz */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   744
/*   Without pre-division, 8000 counts takes 1 ms. */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   745
/*   We are using a pre-divisor of 32. (register TSCR2) See in CanOpenDriverHC12/timerhw.c  */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   746
/*   So 1000 counts takes 4 ms. */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   747
/*   We must have a soft counter of 250 to count a second. */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   748
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   749
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   750
  We check in an interrupt handler if a message is arrived.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   751
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   752
  receiveMsgHandler(0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   753
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   754
  IO_PORTS_16(TC3H) += (1000); // IT every 4000 count.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   755
  softCount++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   756
  if (softCount == 250) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   757
    softCount = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   758
    incDate();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   759
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   760
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   761
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   762
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   763
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   764
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   765
/*****************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   766
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   767
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   768
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   769
/********************************* MAIN ***************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   770
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   771
 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   772
int main()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   773
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   774
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   775
  UNS8 second_last;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   776
  UNS8 minutes_last;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   777
  UNS8 sendingResetError = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   778
  UNS8 ok, i;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   779
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   780
  /* initialisation du bus Can */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   781
  initCanHCS12();  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   782
 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   783
  /* arrays initialisation, etc */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   784
  initCANopenMain();     
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   785
      
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   786
  /* arrays initialisation, etc */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   787
  initCANopenMaster();  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   788
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   789
/* Defining the node Id */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   790
  setNodeId(0x01);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   791
  MSG_WAR(0x3F50, "My node ID is : ", getNodeId()); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   792
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   793
  /* Put the master in operational mode */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   794
  setState(Operational);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   795
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   796
 /* Init the table of connected nodes */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   797
  for (i = 0 ; i < 128 ; i++)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   798
    connectedNode[i] = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   799
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   800
  /* Initialisation */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   801
  initLeds();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   802
  initTimer( );
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   803
  initTimerClk();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   804
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   805
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   806
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   807
  /******************** CONFIGURING THE NETWORK **************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   808
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   809
  /* Which nodes are connected ? */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   810
  /* Sending a request Node guard to node 5 and 6 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   811
  MSG_WAR(0x3F04, "Sending a node guard to node : ", 5);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   812
  masterReadNodeState(0, 0x05);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   813
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   814
  /* Sending a message to the node 6, only as example */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   815
  MSG_WAR(0x3F04, "Sending a node guard to node : ", 6);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   816
  masterReadNodeState(0, 0x06);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   817
  /* Waiting for a second the response */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   818
  sec = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   819
  while (sec < 2) {};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   820
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   821
  /* Whose node have answered ? */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   822
  connectedNode[5] = stateNode(5);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   823
  if (connectedNode[5] != Unknown_state) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   824
    MSG_WAR(0x3F06, "Node 5 connected. Its state is : ", connectedNode[5]);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   825
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   826
  else {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   827
    MSG_WAR(0x3F07, "Node 5 NOT connected ", connectedNode[5]);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   828
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   829
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   830
  connectedNode[6] = stateNode(6);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   831
  if (connectedNode[6] != Unknown_state) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   832
    MSG_WAR(0x3F08, "Node 6 connected. Its state is : ", connectedNode[6]);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   833
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   834
  else {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   835
    MSG_WAR(0x3F09, "Node 6 NOT connected ", connectedNode[6]);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   836
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   837
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   838
  /* Configure the SDO master to communicate with node 5 and node 6 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   839
  configure_master_SDO(0x1280, 0x05);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   840
  /* Configure the SDO of node 5 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   841
  /* getNodeId() returns my node Id */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   842
  configure_client_SDO(0x05, getNodeId());
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   843
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   844
  /* Mapping of the PDO 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   845
     Chose some COBID in (hexa) 181-1FF, 201-27F, 281-2FF, 301-37F, 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   846
     381-3FF, 401-47F, 481-4FF, 501-57F,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   847
     without other restriction.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   848
     (Of course, you must not define 2 PDO transmit with the same cobId !!)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   849
  */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   850
 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   851
  /*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   852
     *** PDO node 1 <-- node 5 ***
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   853
     *** cobId 0x181 *************
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   854
     MASTER (node 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   855
     Mapped to variables (node1) [index-subindex-size_bits]: 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   856
       day    [0x6002 - 0x04 - 8]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   857
       hour   [0x6002 - 0x03 - 8]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   858
       second [0x6002 - 0x01 - 8]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   859
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   860
     SLAVE (node 5)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   861
     Mapped to variables (node5) [index-subindex-size_bits]: 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   862
       day    [0x2000 - 0x04 - 8]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   863
       hour   [0x2000 - 0x03 - 8]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   864
       second [0x2000 - 0x01 - 8]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   865
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   866
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   867
  /* Configuring the first PDO receive, defined at index 0x1400 and 0x1600 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   868
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   869
    s_mappedVar tabMappedVar[8] = { {0x6002,4,8}, {0x6002,3,8}, {0x6002,1,8}, };
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   870
    masterMappingPDO(0x1400, 0x181, tabMappedVar, 3);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   871
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   872
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   873
  /* Configuring the first PDO transmit, defined at index 0x1800 and 0x1A00 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   874
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   875
    s_mappedVar tabMappedVar[8] = { {0x2000,4,8}, {0x2000,3,8}, {0x2000,1,8}, };
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   876
    slaveMappingPDO(0x05, 0x1800, 0x181, tabMappedVar, 3);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   877
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   878
   /*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   879
     *** PDO node 1 <-- node 5 ***
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   880
     *** cobId 0x182 *************
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   881
     MASTER (node 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   882
     Mapped to variables (node1) [index-subindex-size_bits]: 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   883
       minute    [0x6002 - 0x02 - 8]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   884
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   885
     SLAVE (node 5)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   886
     Mapped to variables (node5) [index-subindex-size_bits]: 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   887
       minute    [0x2000 - 0x02 - 8]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   888
   */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   889
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   890
  /* Configuring PDO receive, defined at index 0x1400 and 0x1600 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   891
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   892
    s_mappedVar tabMappedVar[8] = { {0x6002,2,8} };
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   893
    masterMappingPDO(0x1401, 0x182, tabMappedVar, 1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   894
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   895
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   896
  /* Configuring PDO transmit, defined at index 0x1800 and 0x1A00 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   897
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   898
    s_mappedVar tabMappedVar[8] = { {0x2000,2,8} };
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   899
    slaveMappingPDO(0x05, 0x1801, 0x182, tabMappedVar, 1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   900
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   901
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   902
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   903
  /*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   904
     *** PDO node 1 <-- node 5 ***
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   905
     *** cobId 0x183 *************
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   906
     Error management :  By this way, The node can send by PDO an error
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   907
     MASTER (node 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   908
     Mapped to variables (node1) [index-subindex-size_bits]: 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   909
       canopenErrNb_node5     [0x6000 - 0x00 - 32]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   910
       canopenErrVal_node5    [0x6001 - 0x00 - 32] 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   911
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   912
     SLAVE (node 5)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   913
     Mapped to variables (node5) [index-subindex-size_bytes]: 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   914
       canopenErrNb     [0x6000 - 0x00 - 32]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   915
       canopenErrVal    [0x6001 - 0x00 - 32]  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   916
  */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   917
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   918
  /* Configuring  PDO receive, defined at index 0x1402 and 0x1602 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   919
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   920
    s_mappedVar tabMappedVar[8] = { {0x6000,0,32}, {0x6001, 0, 32}};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   921
    masterMappingPDO(0x1402, 0x183, tabMappedVar, 2);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   922
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   923
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   924
  /* Configuring PDO transmit, defined at index 0x1802 and 0x1A02 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   925
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   926
    s_mappedVar tabMappedVar[8] = { {0x6000,0,32}, {0x6001, 0, 32}};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   927
    slaveMappingPDO(0x05, 0x1802, 0x183, tabMappedVar, 2);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   928
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   929
 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   930
  /*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   931
     *** PDO node 1 --> node 5 ***
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   932
     *** cobId 0x184 *************
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   933
     Error management :  To reset the error
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   934
     MASTER (node 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   935
     Mapped to variables (node1) [index-subindex-size_bits]: 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   936
       canopenErrNb_node5     [0x6000 - 0x00 - 32]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   937
       canopenErrVal_node5    [0x6001 - 0x00 - 32] 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   938
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   939
     SLAVE (node 5)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   940
     Mapped to variables (node5) [index-subindex-size_bytes]: 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   941
       canopenErrNb     [0x6000 - 0x00 - 32]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   942
       canopenErrVal    [0x6001 - 0x00 - 32]  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   943
  */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   944
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   945
  /* Configuring  PDO transmit, defined at index 0x1803 and 0x1103 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   946
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   947
    s_mappedVar tabMappedVar[8] = { {0x6000,0,32}, {0x6001, 0, 32}};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   948
    masterMappingPDO(0x1801, 0x184, tabMappedVar, 2);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   949
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   950
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   951
  /* Configuring PDO transmit, defined at index 0x1403 and 0x1603 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   952
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   953
    s_mappedVar tabMappedVar[8] = { {0x6000,0,32}, {0x6001, 0, 32}};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   954
    slaveMappingPDO(0x05, 0x1400, 0x184, tabMappedVar, 2);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   955
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   956
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   957
  /* Configuring the node 5 heartbeat */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   958
  /* Check every 3000 ms if it have received a heartbeat from node 1 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   959
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   960
    UNS8 nbHeartbeatsToReceive = 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   961
    s_heartbeatConsumer tabHeartbeatConsumer[10] = {{1, 0xBB8}};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   962
    slaveHeartbeatConsumer(0x05, tabHeartbeatConsumer, nbHeartbeatsToReceive);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   963
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   964
  /* Sending every 1000 ms an heartbeat */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   965
  slaveHeartbeatProducer(0x05, 0x3E8);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   966
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   967
  /* Configuring the master heartbeat */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   968
  /* Check every 3000 ms if it have received a heartbeat from node 5 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   969
    {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   970
    UNS8 nbHeartbeatsToReceive = 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   971
    s_heartbeatConsumer tabHeartbeatConsumer[10] = {{5, 0xBB8}};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   972
    masterHeartbeatConsumer(tabHeartbeatConsumer, nbHeartbeatsToReceive);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   973
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   974
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   975
    /* Sending every 1000 ms an heartbeat */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   976
    masterHeartbeatProducer(0x3E8);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   977
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   978
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   979
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   980
    /* Configuring the transmission mode of the PDO */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   981
    slavePDOTransmissionMode(0x05, 0x1800,  TRANS_EVERY_N_SYNC (1));
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   982
    slavePDOTransmissionMode(0x05, 0x1801,  TRANS_EVENT);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   983
    slavePDOTransmissionMode(0x05, 0x1802,  TRANS_EVENT);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   984
    masterPDOTransmissionMode(0x1801,  TRANS_EVENT);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   985
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   986
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   987
    /* Configuring the master to send a SYNC message every 1 s */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   988
    /* Note than any other node can send the SYNC instead of the master */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   989
    masterSYNCPeriod(1000000); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   990
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   991
    {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   992
      // Reading the period of heartbeat which has been written in node 5 dictionary
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   993
      UNS8 node = 5;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   994
      UNS16 index = 0x1017;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   995
      UNS8 subindex = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   996
      //UNS8 notused = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   997
      UNS16 hb = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   998
      UNS8  size_data = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   999
      UNS8 error;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1000
      MSG_WAR(0x3F50, "Reading dictionary noeud 5, 1017/0", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1001
      error = readNetworkDict(0, node, index, subindex, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1002
      //error = readNetworkDict(0, node, index, subindex, &notused);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1003
      if (error) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1004
	MSG_ERR(0x1F50, "!!! ERROR reading dictionary noeud 5, 1017/0", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1005
	exit (-1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1006
      }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1007
      /* Waiting until the server has responded */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1008
      error = waitingReadToSlaveDict(node,  (UNS16 *)&hb,  &size_data, error);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1009
      MSG_WAR(0x1F51, "Read dictionary of node 5, index/subindex 1017/0 value = ", hb);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1010
      MSG_WAR(0x1F51, "         size of data (bytes) = ", size_data);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1011
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1012
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1013
    /* Put the node 5 in operational mode 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1014
       The mode is changed according to the slave state machine mode :
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1015
         initialisation  ---> pre-operational (Automatic transition)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1016
         pre-operational <--> operational
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1017
         pre-operational <--> stopped
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1018
         pre-operational, operational, stopped -> initialisation
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1019
       NMT_Start_Node           // Put the node in operational mode       
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1020
       NMT_Stop_Node		// Put the node in stopped mode    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1021
       NMT_Enter_PreOperational // Put the node in pre_operational mode
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1022
       NMT_Reset_Node		// Put the node in initialization mode 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1023
       NMT_Reset_Comunication	// Put the node in initialization mode 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1024
    */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1025
    masterSendNMTstateChange(0, 0x05, NMT_Start_Node);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1026
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1027
    // Note
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1028
    //-----
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1029
    // We do not have mapped the variable canopenErrNB and canopenErrVAL.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1030
    // We should have done that !
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1031
    // the macro MSG_ERR try to send the PDO(s) which contains these two variables.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1032
    // While the PDO will not be found, if you are printing the warnings in file pdo.c,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1033
    // it will print "0X393B Unable to send variable on event :  not mapped in a PDO to send on event" for  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1034
    // example when you enter the function heartbeatError. 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1035
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1036
   /******************** END CONFIGURING THE NETWORK **********************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1037
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1038
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1039
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1040
    /* Init the errors values that may send the node 5 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1041
    canopenErrNB_node5 = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1042
    canopenErrVAL_node5 = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1043
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1044
    /***********/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1045
    /* Running */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1046
    /***********/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1047
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1048
  /* SDO test with node 5 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1049
  /* This code may takes too much room in memory if you are also debugging the file sdo.c */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1050
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1051
    // Reading string
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1052
    UNS8 dataW[20];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1053
    UNS8 dataR[20];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1054
    UNS8 size;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1055
    UNS8 err;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1056
    MSG_WAR(0x3F05, "Test SDO", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1057
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1058
    MSG_WAR(0x3F10, "Writing to node 5 at 0x6002-0 ...", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1059
    strcpy(dataW, "Au Revoir");
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1060
    MSG_WAR(0x3F10, dataW, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1061
    size = 20;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1062
    err = writeNetworkDict(0, 5, 0x6002, 0, 10, visible_string, dataW);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1063
    err = waitingWriteToSlaveDict(5, err);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1064
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1065
    err = readNetworkDict(0, 5, 0x6002, 0, visible_string);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1066
    err = waitingReadToSlaveDict(5, dataR, &size, err);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1067
    MSG_WAR(0x3F08, "Read from node 5 at 0x6002-0" , 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1068
    MSG_WAR(0x3F08, dataR, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1069
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1070
    MSG_WAR(0x3F08, "node 5. Hardware version. (default = compil. date) ...", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1071
    err = readNetworkDict(0, 5, 0x1009, 0, visible_string);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1072
 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1073
    err = waitingReadToSlaveDict(5, dataR, &size, err);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1074
    MSG_WAR(0x3F08, dataR, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1075
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1076
    MSG_WAR(0x3F08, "node 5. Software version. (default = compil. time) ...", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1077
    err = readNetworkDict(0, 5, 0x100A, 0, visible_string);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1078
    err = waitingReadToSlaveDict(5, dataR, &size, err);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1079
    MSG_WAR(0x3F08, dataR, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1080
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1081
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1082
  // Node identity ?
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1083
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1084
    UNS8 *data;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1085
    UNS8 size;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1086
    UNS8 dataType;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1087
    // Manufacturer Device name (default = empty string)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1088
    getODentry(0x1008, 0x0, (void **)&data, &size, &dataType, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1089
    MSG_WAR(0x3F09, data, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1090
    // Manufacturer Hardware version. (default = compilation. date)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1091
    getODentry(0x1009, 0x0, (void **)&data, &size, &dataType, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1092
    MSG_WAR(0x3F09, data, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1093
    // Manufacturer Software version. (default = compilation. time)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1094
    getODentry(0x100A, 0x0, (void **)&data, &size, &dataType, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1095
    MSG_WAR(0x3F09, data, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1096
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1097
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1098
  while(1) { 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1099
    // To transmit the SYNC if it is time to do.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1100
    computeSYNC();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1101
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1102
    // Testing if heartsbeat have been received, and send a heartbeat if it is time.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1103
     heartbeatMGR();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1104
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1105
     // Messages received ?
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1106
     // The function is called in void __attribute__((interrupt)) timer3Hdl (void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1107
     //receiveMsgHandler(0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1108
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1109
 if (minutes != minutes_last) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1110
	MSG_WAR(0x3F80, "Minutes changed :", minutes);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1111
	minutes_last = minutes;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1112
      }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1113
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1114
      if (second != second_last) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1115
	MSG_WAR(0x3F81, "Seconds : ", second);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1116
	second_last = second;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1117
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1118
	if (canopenErrNB_node5) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1119
	  MSG_WAR(0x3F82, "Received an error from node 5, NB : ", canopenErrNB_node5);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1120
	  MSG_WAR(0x3F83, "                            VALUE : ", canopenErrVAL_node5);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1121
	  // Reseting the error
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1122
	  canopenErrNB_node5 = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1123
	  canopenErrVAL_node5 = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1124
	  sendingResetError = 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1125
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1126
       
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1127
	if ((second == 00) && sendingResetError) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1128
	  MSG_WAR(0x3F84, 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1129
		 "Sending to node 5 a PDO envent to reset the error NB and VAL : ",0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1130
	  sendPDOevent(0, &canopenErrNB_node5);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1131
	  sendingResetError = 0; 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1132
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1133
      
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1134
      
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1135
      }	// end if (second != second_last)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1136
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1137
      
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1138
  } // end while
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1139
      
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1140
 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1141
  return (0); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1142
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1143