examples/gene_SYNC_HCS12/appli.c
author Christian Taedcke <hacking@taedcke.com>
Thu, 22 Dec 2011 13:46:00 +0100
changeset 675 e5c5101c4f0b
parent 378 d2abf6c8c27b
child 801 32d146b64a35
permissions -rwxr-xr-x
FIXED: - The AVR example now compiles in linux.
- adapted AVR code to current default branch.
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
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
    23
// Uncomment if you don't need console informations.
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    24
#define DEBUG_WAR_CONSOLE_ON
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    25
#define DEBUG_ERR_CONSOLE_ON
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    26
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    27
#include <stddef.h> /* for NULL */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    28
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    29
#include <asm-m68hc12/portsaccess.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    30
#include <asm-m68hc12/ports_def.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    31
#include <asm-m68hc12/ports.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    32
#include  <interrupt.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    33
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
    34
#include "../include/data.h"
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    35
#include <applicfg.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    36
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    37
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    38
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
    39
#include "../include/hcs12/candriver.h"
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
    40
#include "../include/hcs12/canOpenDriver.h"
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    41
#include "../include/def.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    42
#include "../include/can.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    43
#include "../include/objdictdef.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    44
#include "../include/objacces.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    45
#include "../include/sdo.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    46
#include "../include/pdo.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    47
#include "../include/timer.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    48
#include "../include/lifegrd.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    49
#include "../include/sync.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    50
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    51
#include "../include/nmtSlave.h"
61
813ffdfbffb2 some improvements
frdupin
parents: 56
diff changeset
    52
813ffdfbffb2 some improvements
frdupin
parents: 56
diff changeset
    53
// File created by the GUI 
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    54
#include "objdict.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    55
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
    56
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
    57
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
    58
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    59
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    60
// HCS12 configuration
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    61
// -----------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    62
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    63
enum E_CanBaudrate 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    64
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    65
   CAN_BAUDRATE_250K,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    66
   CAN_BAUDRATE_500K,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    67
   CAN_BAUDRATE_1M,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    68
};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    69
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    70
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    71
const canBusTime CAN_Baudrates[] =
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    72
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    73
   {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    74
      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
    75
      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
    76
      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
    77
      0,  /* samp : chose btw 0 and 3 (2 bits) (samp + 1 ) samples per bit              */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    78
      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
    79
     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
    80
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    81
      /*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    82
      With these values, 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    83
      - The width of the bit time is 16 time quantum :
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    84
          - 1 tq for the SYNC segment (could not be modified)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    85
          - 13 tq for the TIME 1 segment (tseg1 = 12)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    86
          - 2 tq for the TIME 2 segment (tseg2 = 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    87
      - Because the bus clock of the MSCAN is 16 MHZ, and the 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    88
        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
    89
        so the freq of the bit time is 250 kHz.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    90
      */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    91
   },
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    92
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    93
   {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    94
      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
    95
      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
    96
      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
    97
      0,  /* samp : chose btw 0 and 3 (2 bits) (samp + 1 ) samples per bit              */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    98
      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
    99
     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
   100
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   101
      /*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   102
      With these values, 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   103
      - The width of the bit time is 16 time quantum :
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   104
          - 1 tq for the SYNC segment (could not be modified)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   105
          - 13 tq for the TIME 1 segment (tseg1 = 12)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   106
          - 2 tq for the TIME 2 segment (tseg2 = 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   107
      - Because the bus clock of the MSCAN is 16 MHZ, and the 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   108
        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
   109
        so the freq of the bit time is 500 kHz.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   110
      */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   111
    },
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   112
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   113
	{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   114
      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
   115
      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
   116
      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
   117
      0,  /* samp : chose btw 0 and 3 (2 bits) (samp +MSG_WAR(0x3F33, "Je suis le noeud ", getNodeId());    1 ) samples per bit              */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   118
      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
   119
      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
   120
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   121
      /*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   122
      With these values, 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   123
      - The width of the bit time is 16 time quantum :
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   124
          - 1 tq for the SYNC segment (could not be modified)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   125
          - 5 tq for the TIME 1 segment (tseg1 = 4)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   126
          - 2 tq for the TIME 2 segment (tseg2 = 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   127
      - Because the bus clock of the MSCAN is 16 MHZ, and the 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   128
        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
   129
        so the freq of the bit time is 1 MHz.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   130
      */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   131
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   132
};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   133
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
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   137
/**************************prototypes*****************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   138
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   139
//Init can bus and Canopen
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   140
void initCanopencapteur (void);
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   141
// Init the sensor
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   142
void initSensor(void);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   143
void initPortB(void);
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   144
void initPortH(void);
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   145
0
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
//Initialisation of the port B for the leds.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   149
void initPortB(void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   150
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   151
  // Port B is output
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   152
  IO_PORTS_8(DDRB)= 0XFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   153
  // RAZ
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   154
  IO_PORTS_8(PORTB) = 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   155
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   156
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   157
//------------------------------------------------------------------------------
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   158
// Init of port H to choose the CAN rate by switch, and the nodeId
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   159
void initPortH(void)
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   160
{
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   161
  // Port H is input
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   162
  IO_PORTS_8(DDRH)= 0X00;
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   163
  // Enable pull device
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   164
  IO_PORTS_8(PERH) = 0XFF;
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   165
  // Choose the pull-up device
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   166
  IO_PORTS_8(PPSH) = 0X00;
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   167
}
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   168
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   169
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   170
void initSensor(void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   171
{ 
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   172
  UNS8 baudrate = 0; 
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   173
  UNS8 nodeId = 0; 
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   174
  // Init led control
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   175
  initPortB(); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   176
  IO_PORTS_8(PORTB) &= ~ 0x01; //One led ON
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   177
  initPortH();
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   178
  
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   179
    /* Defining the node Id */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   180
  // Uncomment to have a fixed nodeId
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   181
  //setNodeId(&gene_SYNC_Data, 0x03);
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   182
  
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   183
  // Comment below to have a fixed nodeId
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   184
  nodeId = ~(IO_PORTS_8(PTH)) & 0x3F;
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   185
  if (nodeId == 0) {
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   186
  	MSG_WAR(0x3F33, "Using default nodeId :  ", getNodeId(&gene_SYNC_Data));
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   187
  }
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   188
  else	
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   189
    setNodeId(&gene_SYNC_Data, nodeId);
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   190
  
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   191
  MSG_WAR(0x3F33, "My nodeId is :  ", getNodeId(&gene_SYNC_Data));
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   192
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   193
  canBusInit bi0 = {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   194
    0,    /* no low power                 */ 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   195
    0,    /* no time stamp                */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   196
    1,    /* enable MSCAN                 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   197
    0,    /* clock source : oscillator (In fact, it is not used)   */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   198
    0,    /* no loop back                 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   199
    0,    /* no listen only               */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   200
    0,    /* no low pass filter for wk up */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   201
	CAN_Baudrates[CAN_BAUDRATE_250K],
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   202
    {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   203
      0x00,    /* Filter on 16 bits. See Motorola Block Guide V02.14 fig 4-3 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   204
      0x00, 0xFF, /* filter 0 hight accept all msg      */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   205
      0x00, 0xFF, /* filter 0 low accept all msg        */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   206
      0x00, 0xFF, /* filter 1 hight filter all of  msg  */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   207
      0x00, 0xFF, /* filter 1 low filter all of  msg    */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   208
      0x00, 0xFF, /* filter 2 hight filter most of  msg */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   209
      0x00, 0xFF, /* filter 2 low filter most of  msg   */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   210
      0x00, 0xFF, /* filter 3 hight filter most of  msg */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   211
      0x00, 0xFF, /* filter 3 low filter most of  msg   */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   212
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   213
  };
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   214
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   215
  //Init the HCS12 microcontroler for CanOpen 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   216
  initHCS12();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   217
   
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   218
  // Chose the CAN rate (On our board, whe have switch for all purpose)
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   219
  //  7    8
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   220
  //  ON   ON   => 1000 kpbs
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   221
  //  OFF  ON   =>  500 kpbs
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   222
  //  ON   OFF  =>  250 kpbs
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   223
  
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   224
  baudrate = ~(IO_PORTS_8(PTH)) & 0xC0;
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   225
  
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   226
  // Uncomment to have a fixed baudrate of 250 kbps
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   227
  //baudrate = 1;
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   228
  
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   229
  switch (baudrate) {
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   230
  case 0x40:
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   231
    bi0.clk = CAN_Baudrates[CAN_BAUDRATE_250K];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   232
    MSG_WAR(0x3F30, "CAN 250 kbps ", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   233
    break;
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   234
  case 0x80:
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   235
    bi0.clk = CAN_Baudrates[CAN_BAUDRATE_500K];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   236
    MSG_WAR(0x3F31, "CAN 500 kbps ", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   237
    break;
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   238
  case 0xC0:
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   239
    bi0.clk = CAN_Baudrates[CAN_BAUDRATE_1M];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   240
    MSG_WAR(0x3F31, "CAN 1000 kbps ", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   241
    break;   
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   242
  default:
80
37354e408645 compilers compatibility
frdupin
parents: 61
diff changeset
   243
    bi0.clk = CAN_Baudrates[CAN_BAUDRATE_250K];
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   244
    MSG_WAR(0x2F32, "CAN BAUD RATE NOT DEFINED => 250 kbps ", 0);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   245
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   246
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   247
   
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   248
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   249
  MSG_WAR(0x3F33, "SYNC signal generator ", 0);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   250
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   251
  canInit(CANOPEN_LINE_NUMBER_USED, bi0);  //initialize filters...
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   252
  initTimer(); // Init hcs12 timer used by CanFestival. (see timerhw.c)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   253
  unlock(); // Allow interruptions  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   254
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   255
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   256
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   257
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   258
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   259
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   260
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   261
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   262
// FUNCTIONS WHICH ARE PART OF CANFESTIVAL and *must* be implemented here.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   263
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   264
//------------------------------------------------------------------------------
378
d2abf6c8c27b As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents: 365
diff changeset
   265
void gene_SYNC_heartbeatError(CO_Data* d,  UNS8 heartbeatID )
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   266
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   267
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   268
  MSG_ERR(0x1F00, "HeartBeat not received from node : ", heartbeatID);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   269
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   270
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   271
//------------------------------------------------------------------------------
378
d2abf6c8c27b As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents: 365
diff changeset
   272
void gene_SYNC_initialisation(CO_Data* d)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   273
{  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   274
  MSG_WAR (0x3F00, "Entering in INIT ", 0); 
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   275
  initSensor();  
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   276
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   277
  IO_PORTS_8(PORTB) &= ~ 0x01; // led  0         : ON
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   278
  IO_PORTS_8(PORTB) |=   0x0E; // leds 1, 2, 3   : OFF
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   279
  
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
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   283
//------------------------------------------------------------------------------
378
d2abf6c8c27b As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents: 365
diff changeset
   284
void gene_SYNC_preOperational(CO_Data* d)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   285
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   286
  MSG_WAR (0x3F01, "Entering in PRE-OPERATIONAL ", 0); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   287
  IO_PORTS_8(PORTB) &= ~ 0x03; // leds 0, 1      : ON
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   288
  IO_PORTS_8(PORTB) |=   0x0C; // leds 2, 3      : OFF
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   289
    /* default values for the msg CAN filters */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   290
  /* Accept all */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   291
    {
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   292
   	  canBusFilterInit filterConfiguration = 
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   293
   	  {
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   294
   	  0x01,  /* Filter on 16 bits. See Motorola Block Guide V02.14 */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   295
      /*canidarx, canidmrx */                        
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   296
      0x00, 0xFF,          /* filter 0 */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   297
      0x00, 0xFF, 		   /* filter 0 */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   298
      0x00, 0xFF,          /* filter 1 */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   299
      0x00, 0xFF, 		   /* filter 1 */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   300
      0x00, 0xFF,          /* filter 2 */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   301
      0x00, 0xFF, 		   /* filter 2 */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   302
      0x00, 0xFF,          /* filter 3 */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   303
      0x00, 0xFF, 	       /* filter 3 */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   304
   	 };
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   305
   	 canChangeFilter(CANOPEN_LINE_NUMBER_USED, filterConfiguration);
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   306
   } 
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   307
   // Reset the automatic change by SDO
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   308
   applyDownloadedFilters = 0;
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   309
   
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   310
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   311
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   312
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   313
//------------------------------------------------------------------------------
378
d2abf6c8c27b As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents: 365
diff changeset
   314
void gene_SYNC_operational(CO_Data* d)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   315
{ 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   316
   MSG_WAR (0x3F02, "Entering in OPERATIONAL ", 0); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   317
   IO_PORTS_8(PORTB) &= ~ 0x07; // leds 0, 1, 2   : ON
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   318
   IO_PORTS_8(PORTB) |=   0x08; // leds 3         : OFF
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   319
   
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   320
   // Filtering the CAN received msgs.
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   321
   // 2 ways
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   322
   // First :applying an automatic filter
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   323
   // Second : The values of the filtering registers are mapped in the object dictionary,
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   324
   // So that a filtering configuration can be downloaded by SDO in pre-operational mode
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   325
   	
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   326
   	if (applyDownloadedFilters == 0) {// No downloaded configuration to apply
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   327
  		UNS16 accept1 = 0x0000; // Accept NMT
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   328
   		UNS16 mask1 = 0x0FFF;   // Mask NMT
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   329
   		UNS16 accept2 = 0xE000; // Accept NMT error control (heartbeat, nodeguard)
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   330
   		UNS16 mask2 = 0x0FFF;   // Mask NMT error control (heartbeat, nodeguard)
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   331
   		
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   332
   		canBusFilterInit filterConfiguration = 
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   333
				{// filters 3 and 4 not used, so configured like filter 1.
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   334
   		  	0x01,  /* Filter on 16 bits. See Motorola Block Guide V02.14 */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   335
     	    /*canidarx, canidmrx */                        
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   336
      		(UNS8)(accept1 >> 8), (UNS8)(mask1 >> 8),    /* filter 1 id10...3*/
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   337
      		(UNS8)accept1       , (UNS8)mask1, 		       /* filter 1 id2 ... */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   338
      		(UNS8)(accept2 >> 8), (UNS8)(mask2 >> 8),    /* filter 2 id10...3*/
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   339
      		(UNS8)accept2       , (UNS8)mask2, 		       /* filter 2 id2 ... */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   340
       		(UNS8)(accept1 >> 8), (UNS8)(mask1 >> 8),    /* filter 3 id10...3*/
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   341
      		(UNS8)accept1       , (UNS8)mask1, 		       /* filter 3 id2 ... */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   342
      		(UNS8)(accept1 >> 8), (UNS8)(mask1 >> 8),    /* filter 4 id10...3*/
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   343
      		(UNS8)accept1       , (UNS8)mask1 		       /* filter 4 id2 ... */     	
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   344
   	 	 	};
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   345
   	 		canChangeFilter(CANOPEN_LINE_NUMBER_USED, filterConfiguration);
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   346
   	 		MSG_WAR (0x3F03, "Internal CAN Rcv filter applied ", 0); 
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   347
    	} 
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   348
   	  else { // Apply filters downnloaded
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   349
   			canBusFilterInit filterConfiguration = 
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   350
				{// filters 3 and 4 not used, so configured like filter 1.
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   351
   		  	0x01,  /* Filter on 16 bits. See Motorola Block Guide V02.14 */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   352
     	    /*canidarx, canidmrx */                        
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   353
      		(UNS8)( acceptanceFilter1>> 8), (UNS8)(mask1 >> 8),    /* filter 1 id10...3*/
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   354
      		(UNS8)acceptanceFilter1       , (UNS8)mask1, 		       /* filter 1 id2 ... */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   355
      		(UNS8)(acceptanceFilter2 >> 8), (UNS8)(mask2 >> 8),     /* filter 2 id10...3*/
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   356
      		(UNS8)acceptanceFilter2       , (UNS8)mask2, 		       /* filter 2 id2 ... */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   357
       		(UNS8)(acceptanceFilter3 >> 8), (UNS8)(mask3 >> 8),    /* filter 3 id10...3*/
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   358
      		(UNS8)acceptanceFilter3       , (UNS8)mask3, 		       /* filter 3 id2 ... */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   359
      		(UNS8)(acceptanceFilter4 >> 8), (UNS8)(mask4 >> 8),    /* filter 4 id10...3*/
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   360
      		(UNS8)acceptanceFilter4       , (UNS8)mask4 		       /* filter 4 id2 ... */     	
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   361
   	 	 	};
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   362
   	 		canChangeFilter(CANOPEN_LINE_NUMBER_USED, filterConfiguration);  		
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   363
   	 		MSG_WAR (0x3F04, "Downloaded CAN Rcv filter applied ", 0); 
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   364
   	}
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   365
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   366
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   367
//------------------------------------------------------------------------------
378
d2abf6c8c27b As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents: 365
diff changeset
   368
void gene_SYNC_stopped(CO_Data* d)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   369
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   370
  MSG_WAR (0x3F02, "Entering in STOPPED ", 0); 
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   371
  IO_PORTS_8(PORTB) |=   0x0E; // leds 1, 2, 3, 4   : OFF
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   372
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   373
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   374
// End functions which are part of Canfestival
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   375
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   376
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   377
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   378
/******************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   379
/********************************* MAIN ***************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   380
/******************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   381
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   382
 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   383
UNS8 main (void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   384
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   385
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   386
  MSG_WAR(0x3F34, "Entering in the main ", 0);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   387
  //----------------------------- INITIALISATION --------------------------------
149
fe50ada8020b Changes in the API:
etisserant
parents: 80
diff changeset
   388
  gene_SYNC_Data.heartbeatError = gene_SYNC_heartbeatError;
fe50ada8020b Changes in the API:
etisserant
parents: 80
diff changeset
   389
  gene_SYNC_Data.initialisation = gene_SYNC_initialisation;
fe50ada8020b Changes in the API:
etisserant
parents: 80
diff changeset
   390
  gene_SYNC_Data.preOperational = gene_SYNC_preOperational;
fe50ada8020b Changes in the API:
etisserant
parents: 80
diff changeset
   391
  gene_SYNC_Data.preOperational = gene_SYNC_operational;
fe50ada8020b Changes in the API:
etisserant
parents: 80
diff changeset
   392
  gene_SYNC_Data.stopped = gene_SYNC_stopped;
fe50ada8020b Changes in the API:
etisserant
parents: 80
diff changeset
   393
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   394
  
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   395
  /* Put the node in Initialisation mode */
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   396
  MSG_WAR(0x3F35, "Will entering in INIT ", 0);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   397
  setState(&gene_SYNC_Data, Initialisation);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   398
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   399
  //----------------------------- START -----------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   400
  /* Put the node in pre-operational mode */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   401
  //MSG_WAR(0x3F36, "va passer en pre-op", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   402
  //setState(&gene_SYNC_Data, Pre_operational);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   403
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   404
	// Loop of receiving messages
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   405
  while (1) {
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   406
	Message m;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   407
	if (f_can_receive(0, &m)) {
365
9b76e0881beb Changed cob_id from struct{UNS32} to UNS16
etisserant
parents: 172
diff changeset
   408
	  //MSG_WAR(0x3F36, "Msg received", m.cob_id);
56
904abfb26abf lock interrupt before candispatch
frdupin
parents: 54
diff changeset
   409
	  lock(); // Not to have interruptions by timer, which can corrupt the data
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   410
	  canDispatch(&gene_SYNC_Data, &m);
56
904abfb26abf lock interrupt before candispatch
frdupin
parents: 54
diff changeset
   411
	  unlock();
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   412
	}  
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   413
    	}
0
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