examples/gene_SYNC_HCS12/appli.c
author etisserant
Mon, 15 May 2006 08:00:47 +0200
changeset 4 986061160dbb
parent 0 4472ee7c6c3e
child 54 a2ca09ac1523
permissions -rwxr-xr-x
Updated manual
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     1
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     2
This file is part of CanFestival, a library implementing CanOpen Stack. 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     3
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     4
Copyright (C): Edouard TISSERANT and Francis DUPIN
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     5
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     6
See COPYING file for copyrights details.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     7
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     8
This library is free software; you can redistribute it and/or
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     9
modify it under the terms of the GNU Lesser General Public
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    10
License as published by the Free Software Foundation; either
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    11
version 2.1 of the License, or (at your option) any later version.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    12
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    13
This library is distributed in the hope that it will be useful,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    14
but WITHOUT ANY WARRANTY; without even the implied warranty of
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    16
Lesser General Public License for more details.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    17
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    18
You should have received a copy of the GNU Lesser General Public
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    19
License along with this library; if not, write to the Free Software
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    20
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    21
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    22
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    23
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
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    34
#include <applicfg.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    35
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
#include <../include/hcs12/candriver.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    39
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    40
#include "../include/def.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    41
#include "../include/can.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    42
#include "../include/objdictdef.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    43
#include "../include/objacces.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    44
#include "../include/sdo.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    45
#include "../include/pdo.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    46
#include "../include/timer.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    47
#include "../include/lifegrd.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    48
#include "../include/sync.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    49
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
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    54
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    55
// HCS12 configuration
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    56
// -----------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    57
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    58
enum E_CanBaudrate 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    59
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    60
   CAN_BAUDRATE_250K,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    61
   CAN_BAUDRATE_500K,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    62
   CAN_BAUDRATE_1M,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    63
};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    64
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    65
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    66
const canBusTime CAN_Baudrates[] =
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    67
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    68
   {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    69
      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
    70
      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
    71
      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
    72
      0,  /* samp : chose btw 0 and 3 (2 bits) (samp + 1 ) samples per bit              */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    73
      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
    74
     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
    75
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    76
      /*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    77
      With these values, 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    78
      - The width of the bit time is 16 time quantum :
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    79
          - 1 tq for the SYNC segment (could not be modified)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    80
          - 13 tq for the TIME 1 segment (tseg1 = 12)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    81
          - 2 tq for the TIME 2 segment (tseg2 = 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    82
      - Because the bus clock of the MSCAN is 16 MHZ, and the 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    83
        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
    84
        so the freq of the bit time is 250 kHz.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    85
      */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    86
   },
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    87
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    88
   {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    89
      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
    90
      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
    91
      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
    92
      0,  /* samp : chose btw 0 and 3 (2 bits) (samp + 1 ) samples per bit              */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    93
      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
    94
     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
    95
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    96
      /*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    97
      With these values, 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    98
      - The width of the bit time is 16 time quantum :
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    99
          - 1 tq for the SYNC segment (could not be modified)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   100
          - 13 tq for the TIME 1 segment (tseg1 = 12)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   101
          - 2 tq for the TIME 2 segment (tseg2 = 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   102
      - Because the bus clock of the MSCAN is 16 MHZ, and the 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   103
        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
   104
        so the freq of the bit time is 500 kHz.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   105
      */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   106
    },
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   107
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   108
	{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   109
      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
   110
      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
   111
      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
   112
      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
   113
      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
   114
      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
   115
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   116
      /*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   117
      With these values, 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   118
      - The width of the bit time is 16 time quantum :
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   119
          - 1 tq for the SYNC segment (could not be modified)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   120
          - 5 tq for the TIME 1 segment (tseg1 = 4)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   121
          - 2 tq for the TIME 2 segment (tseg2 = 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   122
      - Because the bus clock of the MSCAN is 16 MHZ, and the 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   123
        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
   124
        so the freq of the bit time is 1 MHz.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   125
      */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   126
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   127
};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   128
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   129
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
/**************************prototypes*****************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   133
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   134
//fonction d'initialisation du bus can et la couche CANOPEN pour le capteur
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   135
void initCanopencapteur (void);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   136
// les fonctions d'initialisation du capteur: timer, compteurs logiciel
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   137
void initSensor(void);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   138
void initPortB(void);
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
//Initialisation of the port B for the leds.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   142
void initPortB(void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   143
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   144
  // Port B is output
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   145
  IO_PORTS_8(DDRB)= 0XFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   146
  // RAZ
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   147
  IO_PORTS_8(PORTB) = 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   148
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   149
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   150
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   151
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   152
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   153
void initSensor(void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   154
{ 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   155
  UNS8 baudrate = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   156
  MSG_WAR(0x3F33, "I am the node :  ", getNodeId(&gene_SYNC_Data));  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   157
  // Init led control
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   158
  initPortB(); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   159
  IO_PORTS_8(PORTB) &= ~ 0x01; //One led ON
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   160
  // Init port to choose se CAN baudrate by switch
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   161
  IO_PORTS_8(ATD0DIEN) = 0x03;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   162
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   163
  canBusInit bi0 = {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   164
    0,    /* no low power                 */ 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   165
    0,    /* no time stamp                */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   166
    1,    /* enable MSCAN                 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   167
    0,    /* clock source : oscillator (In fact, it is not used)   */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   168
    0,    /* no loop back                 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   169
    0,    /* no listen only               */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   170
    0,    /* no low pass filter for wk up */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   171
	CAN_Baudrates[CAN_BAUDRATE_250K],
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   172
    {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   173
      0x00,    /* Filter on 16 bits. See Motorola Block Guide V02.14 fig 4-3 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   174
      0x00, 0xFF, /* filter 0 hight accept all msg      */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   175
      0x00, 0xFF, /* filter 0 low accept all msg        */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   176
      0x00, 0xFF, /* filter 1 hight filter all of  msg  */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   177
      0x00, 0xFF, /* filter 1 low filter all of  msg    */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   178
      0x00, 0xFF, /* filter 2 hight filter most of  msg */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   179
      0x00, 0xFF, /* filter 2 low filter most of  msg   */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   180
      0x00, 0xFF, /* filter 3 hight filter most of  msg */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   181
      0x00, 0xFF, /* filter 3 low filter most of  msg   */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   182
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   183
  };
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   184
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   185
  //Init the HCS12 microcontroler for CanOpen 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   186
  initHCS12();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   187
   
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   188
  // Chose the CAN rate
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   189
  baudrate = IO_PORTS_8(PORTAD0) & 0x03;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   190
  switch (baudrate) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   191
  case 1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   192
    bi0.clk = CAN_Baudrates[CAN_BAUDRATE_250K];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   193
    MSG_WAR(0x3F30, "CAN 250 kbps ", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   194
    break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   195
  case 2:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   196
    bi0.clk = CAN_Baudrates[CAN_BAUDRATE_500K];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   197
    MSG_WAR(0x3F31, "CAN 500 kbps ", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   198
    break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   199
  case 3:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   200
    bi0.clk = CAN_Baudrates[CAN_BAUDRATE_1M];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   201
    MSG_WAR(0x3F31, "CAN 1000 kbps ", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   202
    break;   
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   203
  default:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   204
    MSG_WAR(0x2F32, "CAN BAUD RATE NOT DEFINED ", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   205
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   206
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   207
  MSG_WAR(0x3F33, "SYNC signal generator", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   208
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   209
  canInit(CANOPEN_LINE_NUMBER_USED, bi0);  //initialize filters...
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   210
  initTimer(); // Init hcs12 timer used by CanFestival. (see timerhw.c)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   211
  unlock(); // Allow interruptions  
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
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   216
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   217
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   218
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   219
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   220
// FUNCTIONS WHICH ARE PART OF CANFESTIVAL and *must* be implemented here.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   221
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   222
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   223
void gene_SYNC_heartbeatError( UNS8 heartbeatID )
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   224
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   225
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   226
  MSG_ERR(0x1F00, "HeartBeat not received from node : ", heartbeatID);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   227
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   228
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   229
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   230
void gene_SYNC_SDOtimeoutError (UNS8 line)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   231
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   232
  MSG_ERR(0x1F01, "SDO timeout for line : ", line);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   233
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   234
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   235
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   236
UNS8 gene_SYNC_canSend(Message *m)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   237
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   238
  // HCS12 driver function to send the CAN msg
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   239
  canMsgTransmit(CAN0, *m);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   240
  return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   241
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   242
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   243
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   244
void gene_SYNC_initialisation()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   245
{  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   246
  MSG_WAR (0x3F00, "Entering in INIT ", 0); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   247
  initSensor();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   248
  IO_PORTS_8(PORTB) &= ~ 0x01; // led  0         : ON
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   249
  IO_PORTS_8(PORTB) |=   0x0E; // leds 1, 2, 3   : OFF
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   250
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   251
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   252
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   253
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   254
void gene_SYNC_preOperational()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   255
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   256
  MSG_WAR (0x3F01, "Entering in PRE-OPERATIONAL ", 0); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   257
  IO_PORTS_8(PORTB) &= ~ 0x03; // leds 0, 1      : ON
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   258
  IO_PORTS_8(PORTB) |=   0x0C; // leds 2, 3      : OFF
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
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   263
void gene_SYNC_operational()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   264
{ 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   265
   MSG_WAR (0x3F02, "Entering in OPERATIONAL ", 0); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   266
   IO_PORTS_8(PORTB) &= ~ 0x07; // leds 0, 1, 2   : ON
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   267
   IO_PORTS_8(PORTB) |=   0x08; // leds 3         : OFF
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   268
}
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
void gene_SYNC_stopped()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   272
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   273
  MSG_WAR (0x3F02, "Entering in STOPPED ", 0); 
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
void gene_SYNC_post_sync()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   278
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   279
}
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_post_TPDO()
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
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   286
// End functions which are part of Canfestival
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
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   290
/******************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   291
/********************************* MAIN ***************************************/
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 main (void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   296
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   297
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   298
  MSG_WAR(0x3F34, "Entering in the main", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   299
  //----------------------------- INITIALISATION --------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   300
  /* Defining the node Id */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   301
  setNodeId(&gene_SYNC_Data, 0x03);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   302
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   303
  /* Put the node in Initialisation mode */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   304
  MSG_WAR(0x3F35, "va passer en init", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   305
  setState(&gene_SYNC_Data, Initialisation);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   306
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   307
  //----------------------------- START -----------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   308
  /* Put the node in pre-operational mode */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   309
  //MSG_WAR(0x3F36, "va passer en pre-op", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   310
  //setState(&gene_SYNC_Data, Pre_operational);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   311
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   312
    while (1) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   313
      {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   314
	Message m;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   315
	if (f_can_receive(0, &m)) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   316
	  MSG_WAR(0x3F36, "Msg received", m.cob_id.w);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   317
	  canDispatch(&gene_SYNC_Data, &m);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   318
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   319
	  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   320
	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   321
      }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   322
      
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   323
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   324
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   325
  return (0); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   326
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   327
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   328
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   329