examples/gene_SYNC_HCS12/appli.c
author lbessard
Wed, 13 Dec 2006 18:48:01 +0100
changeset 59 3a553c789116
parent 56 904abfb26abf
child 61 813ffdfbffb2
permissions -rwxr-xr-x
Some bugs reported by Francis Dupin corrected.
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"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    52
#include "objdict.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    53
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
    54
// Variables defined in the object dictionary (See objdict.c)
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
    55
extern UNS16 acceptanceFilter1;		// Mapped at index 0x2015, subindex 0x00
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
    56
extern UNS16 acceptanceFilter2;		// Mapped at index 0x2016, subindex 0x00
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
    57
extern UNS16 acceptanceFilter3;		// Mapped at index 0x2017, subindex 0x00
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
    58
extern UNS16 acceptanceFilter4;		// Mapped at index 0x2018, subindex 0x00
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
    59
extern UNS16 mask1;		// Mapped at index 0x2019, subindex 0x00
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
    60
extern UNS16 mask2;		// Mapped at index 0x2020, subindex 0x00
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
    61
extern UNS16 mask3;		// Mapped at index 0x2021, subindex 0x00
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
    62
extern UNS16 mask4;		// Mapped at index 0x2022, subindex 0x00
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
    63
extern UNS8 applyDownloadedFilters;
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
    64
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
    65
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
    66
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    67
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    68
// HCS12 configuration
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
enum E_CanBaudrate 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    72
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    73
   CAN_BAUDRATE_250K,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    74
   CAN_BAUDRATE_500K,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    75
   CAN_BAUDRATE_1M,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    76
};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    77
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    78
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    79
const canBusTime CAN_Baudrates[] =
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
      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
    83
      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
    84
      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
    85
      0,  /* samp : chose btw 0 and 3 (2 bits) (samp + 1 ) samples per bit              */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    86
      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
    87
     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
    88
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    89
      /*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    90
      With these values, 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    91
      - The width of the bit time is 16 time quantum :
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    92
          - 1 tq for the SYNC segment (could not be modified)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    93
          - 13 tq for the TIME 1 segment (tseg1 = 12)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    94
          - 2 tq for the TIME 2 segment (tseg2 = 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    95
      - Because the bus clock of the MSCAN is 16 MHZ, and the 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    96
        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
    97
        so the freq of the bit time is 250 kHz.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    98
      */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    99
   },
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
      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
   103
      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
   104
      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
   105
      0,  /* samp : chose btw 0 and 3 (2 bits) (samp + 1 ) samples per bit              */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   106
      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
   107
     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
   108
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   109
      /*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   110
      With these values, 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   111
      - The width of the bit time is 16 time quantum :
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   112
          - 1 tq for the SYNC segment (could not be modified)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   113
          - 13 tq for the TIME 1 segment (tseg1 = 12)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   114
          - 2 tq for the TIME 2 segment (tseg2 = 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   115
      - Because the bus clock of the MSCAN is 16 MHZ, and the 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   116
        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
   117
        so the freq of the bit time is 500 kHz.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   118
      */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   119
    },
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
      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
   123
      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
   124
      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
   125
      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
   126
      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
   127
      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
   128
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   129
      /*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   130
      With these values, 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   131
      - The width of the bit time is 16 time quantum :
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   132
          - 1 tq for the SYNC segment (could not be modified)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   133
          - 5 tq for the TIME 1 segment (tseg1 = 4)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   134
          - 2 tq for the TIME 2 segment (tseg2 = 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   135
      - Because the bus clock of the MSCAN is 16 MHZ, and the 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   136
        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
   137
        so the freq of the bit time is 1 MHz.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   138
      */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   139
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   140
};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   141
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   142
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   143
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   144
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   145
/**************************prototypes*****************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   146
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   147
//Init can bus and Canopen
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   148
void initCanopencapteur (void);
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   149
// Init the sensor
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   150
void initSensor(void);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   151
void initPortB(void);
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   152
void initPortH(void);
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   153
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   154
// Functions needed by Canfestival
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   155
// Notice that gene_SYNC is the name of the sensor defined in python GUI.
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   156
// Do not change it !.
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   157
void gene_SYNC_initialisation(void);
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   158
void gene_SYNC_preOperational(void);
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   159
void gene_SYNC_operational(void);
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   160
void gene_SYNC_stopped(void);
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   161
void gene_SYNC_post_sync(void);
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   162
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   163
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   164
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   165
//Initialisation of the port B for the leds.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   166
void initPortB(void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   167
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   168
  // Port B is output
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   169
  IO_PORTS_8(DDRB)= 0XFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   170
  // RAZ
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   171
  IO_PORTS_8(PORTB) = 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   172
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   173
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   174
//------------------------------------------------------------------------------
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   175
// 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
   176
void initPortH(void)
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   177
{
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   178
  // Port H is input
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   179
  IO_PORTS_8(DDRH)= 0X00;
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   180
  // Enable pull device
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   181
  IO_PORTS_8(PERH) = 0XFF;
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   182
  // Choose the pull-up device
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   183
  IO_PORTS_8(PPSH) = 0X00;
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   184
}
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   185
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   186
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   187
void initSensor(void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   188
{ 
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   189
  UNS8 baudrate = 0; 
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   190
  UNS8 nodeId = 0; 
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   191
  // Init led control
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   192
  initPortB(); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   193
  IO_PORTS_8(PORTB) &= ~ 0x01; //One led ON
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   194
  initPortH();
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   195
  
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   196
    /* Defining the node Id */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   197
  // Uncomment to have a fixed nodeId
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   198
  //setNodeId(&gene_SYNC_Data, 0x03);
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   199
  
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   200
  // Comment below to have a fixed nodeId
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   201
  nodeId = ~(IO_PORTS_8(PTH)) & 0x3F;
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   202
  if (nodeId == 0) {
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   203
  	MSG_WAR(0x3F33, "Using default nodeId :  ", getNodeId(&gene_SYNC_Data));
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   204
  }
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   205
  else	
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   206
    setNodeId(&gene_SYNC_Data, nodeId);
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   207
  
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   208
  MSG_WAR(0x3F33, "My nodeId is :  ", getNodeId(&gene_SYNC_Data));
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   209
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   210
  canBusInit bi0 = {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   211
    0,    /* no low power                 */ 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   212
    0,    /* no time stamp                */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   213
    1,    /* enable MSCAN                 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   214
    0,    /* clock source : oscillator (In fact, it is not used)   */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   215
    0,    /* no loop back                 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   216
    0,    /* no listen only               */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   217
    0,    /* no low pass filter for wk up */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   218
	CAN_Baudrates[CAN_BAUDRATE_250K],
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   219
    {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   220
      0x00,    /* Filter on 16 bits. See Motorola Block Guide V02.14 fig 4-3 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   221
      0x00, 0xFF, /* filter 0 hight accept all msg      */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   222
      0x00, 0xFF, /* filter 0 low accept all msg        */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   223
      0x00, 0xFF, /* filter 1 hight filter all of  msg  */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   224
      0x00, 0xFF, /* filter 1 low filter all of  msg    */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   225
      0x00, 0xFF, /* filter 2 hight filter most of  msg */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   226
      0x00, 0xFF, /* filter 2 low filter most of  msg   */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   227
      0x00, 0xFF, /* filter 3 hight filter most of  msg */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   228
      0x00, 0xFF, /* filter 3 low filter most of  msg   */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   229
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   230
  };
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   231
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   232
  //Init the HCS12 microcontroler for CanOpen 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   233
  initHCS12();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   234
   
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   235
  // 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
   236
  //  7    8
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   237
  //  ON   ON   => 1000 kpbs
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   238
  //  OFF  ON   =>  500 kpbs
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   239
  //  ON   OFF  =>  250 kpbs
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   240
  
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   241
  baudrate = ~(IO_PORTS_8(PTH)) & 0xC0;
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   242
  
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   243
  // Uncomment to have a fixed baudrate of 250 kbps
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   244
  //baudrate = 1;
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   245
  
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   246
  switch (baudrate) {
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   247
  case 0x40:
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   248
    bi0.clk = CAN_Baudrates[CAN_BAUDRATE_250K];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   249
    MSG_WAR(0x3F30, "CAN 250 kbps ", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   250
    break;
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   251
  case 0x80:
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   252
    bi0.clk = CAN_Baudrates[CAN_BAUDRATE_500K];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   253
    MSG_WAR(0x3F31, "CAN 500 kbps ", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   254
    break;
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   255
  case 0xC0:
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   256
    bi0.clk = CAN_Baudrates[CAN_BAUDRATE_1M];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   257
    MSG_WAR(0x3F31, "CAN 1000 kbps ", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   258
    break;   
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   259
  default:
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   260
    bi0.clk = CAN_Baudrates[CAN_BAUDRATE_1M];
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   261
    MSG_WAR(0x2F32, "CAN BAUD RATE NOT DEFINED => 250 kbps ", 0);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   262
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   263
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   264
   
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   265
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   266
  MSG_WAR(0x3F33, "SYNC signal generator ", 0);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   267
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   268
  canInit(CANOPEN_LINE_NUMBER_USED, bi0);  //initialize filters...
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   269
  initTimer(); // Init hcs12 timer used by CanFestival. (see timerhw.c)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   270
  unlock(); // Allow interruptions  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   271
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   272
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   273
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   274
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   275
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   276
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   277
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   278
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   279
// FUNCTIONS WHICH ARE PART OF CANFESTIVAL and *must* be implemented here.
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
void gene_SYNC_heartbeatError( UNS8 heartbeatID )
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   283
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   284
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   285
  MSG_ERR(0x1F00, "HeartBeat not received from node : ", heartbeatID);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   286
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   287
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   288
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   289
void gene_SYNC_SDOtimeoutError (UNS8 line)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   290
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   291
  MSG_ERR(0x1F01, "SDO timeout for line : ", line);
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
UNS8 gene_SYNC_canSend(Message *m)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   296
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   297
  // HCS12 driver function to send the CAN msg
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   298
  canMsgTransmit(CAN0, *m);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   299
  return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   300
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   301
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   302
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   303
void gene_SYNC_initialisation()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   304
{  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   305
  MSG_WAR (0x3F00, "Entering in INIT ", 0); 
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   306
  initSensor();  
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   307
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   308
  IO_PORTS_8(PORTB) &= ~ 0x01; // led  0         : ON
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   309
  IO_PORTS_8(PORTB) |=   0x0E; // leds 1, 2, 3   : OFF
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   310
  
0
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
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   314
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   315
void gene_SYNC_preOperational()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   316
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   317
  MSG_WAR (0x3F01, "Entering in PRE-OPERATIONAL ", 0); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   318
  IO_PORTS_8(PORTB) &= ~ 0x03; // leds 0, 1      : ON
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   319
  IO_PORTS_8(PORTB) |=   0x0C; // leds 2, 3      : OFF
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   320
    /* default values for the msg CAN filters */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   321
  /* Accept all */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   322
    {
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   323
   	  canBusFilterInit filterConfiguration = 
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   324
   	  {
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   325
   	  0x01,  /* Filter on 16 bits. See Motorola Block Guide V02.14 */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   326
      /*canidarx, canidmrx */                        
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   327
      0x00, 0xFF,          /* filter 0 */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   328
      0x00, 0xFF, 		   /* filter 0 */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   329
      0x00, 0xFF,          /* filter 1 */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   330
      0x00, 0xFF, 		   /* filter 1 */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   331
      0x00, 0xFF,          /* filter 2 */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   332
      0x00, 0xFF, 		   /* filter 2 */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   333
      0x00, 0xFF,          /* filter 3 */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   334
      0x00, 0xFF, 	       /* filter 3 */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   335
   	 };
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   336
   	 canChangeFilter(CANOPEN_LINE_NUMBER_USED, filterConfiguration);
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   337
   } 
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   338
   // Reset the automatic change by SDO
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   339
   applyDownloadedFilters = 0;
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   340
   
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   341
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   342
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
void gene_SYNC_operational()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   346
{ 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   347
   MSG_WAR (0x3F02, "Entering in OPERATIONAL ", 0); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   348
   IO_PORTS_8(PORTB) &= ~ 0x07; // leds 0, 1, 2   : ON
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   349
   IO_PORTS_8(PORTB) |=   0x08; // leds 3         : OFF
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   350
   
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   351
   // Filtering the CAN received msgs.
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   352
   // 2 ways
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   353
   // First :applying an automatic filter
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   354
   // 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
   355
   // 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
   356
   	
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   357
   	if (applyDownloadedFilters == 0) {// No downloaded configuration to apply
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   358
  		UNS16 accept1 = 0x0000; // Accept NMT
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   359
   		UNS16 mask1 = 0x0FFF;   // Mask NMT
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   360
   		UNS16 accept2 = 0xE000; // Accept NMT error control (heartbeat, nodeguard)
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   361
   		UNS16 mask2 = 0x0FFF;   // Mask NMT error control (heartbeat, nodeguard)
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   362
   		
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   363
   		canBusFilterInit filterConfiguration = 
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   364
				{// filters 3 and 4 not used, so configured like filter 1.
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   365
   		  	0x01,  /* Filter on 16 bits. See Motorola Block Guide V02.14 */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   366
     	    /*canidarx, canidmrx */                        
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   367
      		(UNS8)(accept1 >> 8), (UNS8)(mask1 >> 8),    /* filter 1 id10...3*/
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   368
      		(UNS8)accept1       , (UNS8)mask1, 		       /* filter 1 id2 ... */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   369
      		(UNS8)(accept2 >> 8), (UNS8)(mask2 >> 8),    /* filter 2 id10...3*/
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   370
      		(UNS8)accept2       , (UNS8)mask2, 		       /* filter 2 id2 ... */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   371
       		(UNS8)(accept1 >> 8), (UNS8)(mask1 >> 8),    /* filter 3 id10...3*/
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   372
      		(UNS8)accept1       , (UNS8)mask1, 		       /* filter 3 id2 ... */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   373
      		(UNS8)(accept1 >> 8), (UNS8)(mask1 >> 8),    /* filter 4 id10...3*/
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   374
      		(UNS8)accept1       , (UNS8)mask1 		       /* filter 4 id2 ... */     	
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   375
   	 	 	};
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   376
   	 		canChangeFilter(CANOPEN_LINE_NUMBER_USED, filterConfiguration);
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   377
   	 		MSG_WAR (0x3F03, "Internal CAN Rcv filter applied ", 0); 
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   378
    	} 
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   379
   	  else { // Apply filters downnloaded
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   380
   			canBusFilterInit filterConfiguration = 
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   381
				{// filters 3 and 4 not used, so configured like filter 1.
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   382
   		  	0x01,  /* Filter on 16 bits. See Motorola Block Guide V02.14 */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   383
     	    /*canidarx, canidmrx */                        
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   384
      		(UNS8)( acceptanceFilter1>> 8), (UNS8)(mask1 >> 8),    /* filter 1 id10...3*/
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   385
      		(UNS8)acceptanceFilter1       , (UNS8)mask1, 		       /* filter 1 id2 ... */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   386
      		(UNS8)(acceptanceFilter2 >> 8), (UNS8)(mask2 >> 8),     /* filter 2 id10...3*/
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   387
      		(UNS8)acceptanceFilter2       , (UNS8)mask2, 		       /* filter 2 id2 ... */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   388
       		(UNS8)(acceptanceFilter3 >> 8), (UNS8)(mask3 >> 8),    /* filter 3 id10...3*/
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   389
      		(UNS8)acceptanceFilter3       , (UNS8)mask3, 		       /* filter 3 id2 ... */
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   390
      		(UNS8)(acceptanceFilter4 >> 8), (UNS8)(mask4 >> 8),    /* filter 4 id10...3*/
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   391
      		(UNS8)acceptanceFilter4       , (UNS8)mask4 		       /* filter 4 id2 ... */     	
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   392
   	 	 	};
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   393
   	 		canChangeFilter(CANOPEN_LINE_NUMBER_USED, filterConfiguration);  		
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   394
   	 		MSG_WAR (0x3F04, "Downloaded CAN Rcv filter applied ", 0); 
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   395
   	}
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   396
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   397
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   398
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   399
void gene_SYNC_stopped()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   400
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   401
  MSG_WAR (0x3F02, "Entering in STOPPED ", 0); 
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   402
  IO_PORTS_8(PORTB) |=   0x0E; // leds 1, 2, 3, 4   : OFF
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   403
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   404
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   405
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   406
void gene_SYNC_post_sync()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   407
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   408
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   409
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   410
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   411
void gene_SYNC_post_TPDO()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   412
{
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
// End functions which are part of Canfestival
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
/******************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   420
/********************************* MAIN ***************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   421
/******************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   422
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   423
 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   424
UNS8 main (void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   425
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   426
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   427
  MSG_WAR(0x3F34, "Entering in the main ", 0);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   428
  //----------------------------- INITIALISATION --------------------------------
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   429
  
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   430
  /* Put the node in Initialisation mode */
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   431
  MSG_WAR(0x3F35, "Will entering in INIT ", 0);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   432
  setState(&gene_SYNC_Data, Initialisation);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   433
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   434
  //----------------------------- START -----------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   435
  /* Put the node in pre-operational mode */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   436
  //MSG_WAR(0x3F36, "va passer en pre-op", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   437
  //setState(&gene_SYNC_Data, Pre_operational);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   438
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   439
	// Loop of receiving messages
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   440
  while (1) {
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   441
	Message m;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   442
	if (f_can_receive(0, &m)) {
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   443
	  //MSG_WAR(0x3F36, "Msg received", m.cob_id.w);
56
904abfb26abf lock interrupt before candispatch
frdupin
parents: 54
diff changeset
   444
	  lock(); // Not to have interruptions by timer, which can corrupt the data
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   445
	  canDispatch(&gene_SYNC_Data, &m);
56
904abfb26abf lock interrupt before candispatch
frdupin
parents: 54
diff changeset
   446
	  unlock();
54
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   447
	}  
a2ca09ac1523 Tested. OK on Canfestival 3 rc2
frdupin
parents: 0
diff changeset
   448
    	}
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   449
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   450
  return (0); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   451
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   452
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   453
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   454