drivers/hcs12/canOpenDriver.c
author edouard
Sat, 13 Nov 2010 23:08:34 +0100
changeset 633 2c43383a1d57
parent 384 83793fc7ce48
child 801 32d146b64a35
permissions -rw-r--r--
Fix mingw32 cross build for can_peak_win32 and can_tcp_win32 server.
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
#define DEBUG_WAR_CONSOLE_ON
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    24
#define DEBUG_ERR_CONSOLE_ON
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    25
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    26
#include <stddef.h> /* for NULL */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    27
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    28
#include "../include/hcs12/asm-m68hc12/portsaccess.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    29
#include "../include/hcs12/asm-m68hc12/ports_def.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    30
#include "../include/hcs12/asm-m68hc12/ports.h"
7
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
    31
#include "../include/data.h"
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    32
#include "../include/hcs12/applicfg.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    33
#include "../include/hcs12/candriver.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    34
#include "../include/hcs12/interrupt.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    35
#include "../include/hcs12/canOpenDriver.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    36
#include "../include/can.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    37
#include "../include/objdictdef.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    38
#include "../include/timer.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    39
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    40
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    41
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    42
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    43
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    44
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    45
volatile static Message stackMsgRcv[NB_LINE_CAN][MAX_STACK_MSG_RCV]; 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    46
volatile static t_pointerStack ptrMsgRcv[NB_LINE_CAN];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    47
 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    48
volatile static TIMEVAL last_time_set = TIMEVAL_MAX;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    49
static UNS8 timer_is_set = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    50
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    51
/* Prototypes */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    52
UNS8 f_can_receive(UNS8 notused, Message *m);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    53
UNS8 canSend(UNS8 notused, Message *m);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    54
void __attribute__((interrupt)) timer4Hdl (void);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    55
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    56
#define max(a,b) a>b?a:b
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    57
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    58
/******************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    59
void setTimer(TIMEVAL value)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    60
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    61
  IO_PORTS_16(TC4H) += value;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    62
  timer_is_set = 1; 
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
TIMEVAL getElapsedTime()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    67
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    68
  return (IO_PORTS_16(TC4H) > last_time_set ? IO_PORTS_16(TC4H) - last_time_set : last_time_set - IO_PORTS_16(TC4H));
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
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    72
/******************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    73
void resetTimer(void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    74
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    75
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    76
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    77
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    78
/******************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    79
void initTimer(void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    80
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    81
  lock();   // Inhibition of interruptions
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    82
 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    83
  // Configure the timer channel 4
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    84
  IO_PORTS_8(TIOS) |= 0x10; // Canal 4 in output
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    85
  IO_PORTS_8(TCTL1) &= ~(0x01 + 0x02); // Canal 4 unconnected to pin output
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    86
  IO_PORTS_8(TIE) |= 0x10; // allow interruption channel 4
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    87
  IO_PORTS_8(TSCR2) |= 0X05; // Pre-scaler = 32 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    88
                             // If this value is changed, change must be done also
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    89
                             // in void __attribute__((interrupt)) timer4Hdl (void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    90
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    91
  IO_PORTS_8(TSCR1) |= 0x80; // Start timer
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    92
  unlock(); // Allow interruptions
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    93
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    94
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    95
/******************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    96
void __attribute__((interrupt)) timer4Hdl (void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    97
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    98
  lock();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    99
  last_time_set = IO_PORTS_16(TC4H);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   100
  IO_PORTS_8(TFLG1) = 0x10; // RAZ flag interruption timer channel 4
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   101
  // Compute the next event : When the timer reach the value of TC4, an interrupt is
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   102
  // started 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   103
  //IO_PORTS_16(TC4H) += 250; // To have an interruption every 1 ms
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   104
  //timerInterrupt(0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   105
  //MSG_WAR(0xFFFF, "timer4 IT", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   106
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   107
    //MSG_WAR(0xFFFF, "t4 ", IO_PORTS_16(TCNTH) - IO_PORTS_16(TC4H));
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   108
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   109
  TimeDispatch();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   110
  unlock();
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
/******************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   115
void initSCI_0(void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   116
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   117
  IO_PORTS_16(SCI0 + SCIBDH) = 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   118
    ((1000000 / SERIAL_SCI0_BAUD_RATE) * BUS_CLOCK) >> 4 ;  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   119
  IO_PORTS_8(SCI0  + SCICR1) = 0;    // format 8N1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   120
  IO_PORTS_8(SCI0  + SCICR2) = 0x08; // Transmit enable only
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   121
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   122
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   123
/******************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   124
void initSCI_1(void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   125
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   126
  IO_PORTS_16(SCI1 + SCIBDH) = 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   127
    ((1000000 / SERIAL_SCI1_BAUD_RATE) * BUS_CLOCK) >> 4 ;  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   128
  IO_PORTS_8(SCI1  + SCICR1) = 0;    // format 8N1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   129
  IO_PORTS_8(SCI1  + SCICR2) = 0x08; // Transmit enable only
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
char *
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   135
hex_convert (char *buf, unsigned long value, char lastCar)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   136
{
384
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 365
diff changeset
   137
  //Thanks to Stphane Carrez for this function
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   138
  char num[32];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   139
  int pos;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   140
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   141
  *buf++ = '0';
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   142
  *buf++ = 'x';
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   143
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   144
  pos = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   145
  while (value != 0) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   146
    char c = value & 0x0F;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   147
    num[pos++] = "0123456789ABCDEF"[(unsigned) c];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   148
    value = (value >> 4) & (0x0fffffffL);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   149
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   150
  if (pos == 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   151
    num[pos++] = '0';
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   152
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   153
  while (--pos >= 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   154
    *buf++ = num[pos];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   155
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   156
  *buf++ = lastCar;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   157
  *buf = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   158
  return buf;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   159
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   160
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   161
/******************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   162
void printSCI_str(char sci, const char * str) 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   163
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   164
  char i = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   165
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   166
  while ((*(str + i) != 0) && (i < 0xFF)) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   167
    if (*(str + i) == '\n')
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   168
      {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   169
	while ((IO_PORTS_8(sci + SCISR1) & 0X80) == 0); // wait if buffer not empty	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   170
	IO_PORTS_8(sci + SCIDRL) = 13; // return to start of line
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   171
      }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   172
    while ((IO_PORTS_8(sci + SCISR1) & 0X80) == 0); // wait if buffer not empty
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   173
    IO_PORTS_8(sci + SCIDRL) = *(str + i++);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   174
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   175
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   176
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   177
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   178
/******************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   179
void printSCI_nbr(char sci, unsigned long nbr, char lastCar) 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   180
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   181
  char strNbr[12];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   182
  hex_convert(strNbr, nbr, lastCar);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   183
  printSCI_str(sci, strNbr);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   184
}
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
// PLL 24 MHZ if quartz on board is 16 MHZ
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   188
void initPLL(void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   189
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   190
  IO_PORTS_8(CLKSEL) &= ~0x80; // unselect the PLL
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   191
  IO_PORTS_8(PLLCTL) |= 0X60;  // PLL ON and bandwidth auto
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   192
  IO_PORTS_8(SYNR) = 0x02;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   193
  IO_PORTS_8(REFDV) = 0x01;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   194
  while ((IO_PORTS_8(CRGFLG) & 0x08) == 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   195
  IO_PORTS_8(CLKSEL) |= 0x80;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   196
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   197
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   198
/******************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   199
void initHCS12(void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   200
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   201
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   202
# ifdef USE_PLL
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   203
  MSG_WAR(0x3620, "Use the PLL ", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   204
  initPLL();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   205
# endif
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   206
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   207
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   208
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   209
/***************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   210
char canAddIdToFilter(UNS16 adrCAN, UNS8 nFilter, UNS16 id)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   211
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   212
  UNS8 fiMsb;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   213
  UNS8 fiLsb;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   214
  UNS8 idMsb = (UNS8) (id >> 3);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   215
  UNS8 idLsb = (UNS8) (id << 5);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   216
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   217
  if (! canTestInitMode(adrCAN)) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   218
    /* Error because not init mode */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   219
    MSG_WAR(0X2600, "Not in init mode ", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   220
    return 1;   
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   221
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   222
  switch (nFilter) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   223
    case 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   224
      nFilter = CANIDAR0; /* First  bank */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   225
      break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   226
    case 1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   227
      nFilter = CANIDAR2; /* First  bank */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   228
      break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   229
    case 2:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   230
      nFilter = CANIDAR4; /* Second bank */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   231
      break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   232
    case 3:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   233
      nFilter = CANIDAR6; /* Second bank */   
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   234
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   235
  if (! IO_PORTS_16(adrCAN + nFilter)) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   236
    /* if CANIDARx = 0 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   237
    IO_PORTS_8(adrCAN + nFilter) = idMsb;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   238
    IO_PORTS_8(adrCAN + nFilter + 1) = idLsb;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   239
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   240
  fiMsb = IO_PORTS_8(adrCAN + nFilter) ^ idMsb;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   241
  fiLsb = IO_PORTS_8(adrCAN + nFilter + 1) ^ idLsb;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   242
  /* address of CANIDMRx */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   243
  IO_PORTS_8(adrCAN + nFilter + 4) = IO_PORTS_8(adrCAN + nFilter + 4) | fiMsb;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   244
  IO_PORTS_8(adrCAN + nFilter + 5) = IO_PORTS_8(adrCAN + nFilter + 5) | fiLsb;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   245
  IO_PORTS_8(adrCAN + nFilter + 5) |= 0x10; /* Not filtering on rtr value */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   246
  return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   247
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   248
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   249
/***************************************************************************/
7
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   250
char canChangeFilter(UNS16 adrCAN, canBusFilterInit fi)
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   251
{
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   252
  /* If not in init mode, go to sleep before going in init mode*/
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   253
  if (! canTestInitMode(adrCAN)) {
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   254
    canSleepMode(adrCAN);
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   255
    canInitMode(adrCAN); 
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   256
  }
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   257
  //update the filters configuration
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   258
  canInitFilter(adrCAN, fi);
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   259
  canInitModeQ(adrCAN);
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   260
  canSleepModeQ(adrCAN);
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   261
  canSetInterrupt(adrCAN);
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   262
  return 0;
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   263
}
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   264
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   265
/***************************************************************************/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   266
char canEnable(UNS16 adrCAN)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   267
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   268
  /* Register CANCTL1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   269
  bit 7 : 1 MSCAN enabled
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   270
  Other bits : default reset values
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   271
  */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   272
  IO_PORTS_8(adrCAN + CANCTL1) = 0X80;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   273
  return 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
char canInit(UNS16 adrCAN, canBusInit bi)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   278
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   279
  /* If not in init mode, go to sleep before going in init mode*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   280
  if (! canTestInitMode(adrCAN)) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   281
    canSleepMode(adrCAN);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   282
    canInitMode(adrCAN); 
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
  canEnable(adrCAN);                  /* Does nothing if already enable */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   286
     /* The most secure way to go in init mode : put before MSCAN in sleep mode */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   287
      //canSleepMode(adrCAN);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   288
     /* Put MSCAN in Init mode */ 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   289
     //canInitMode(adrCAN);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   290
  canInitClock(adrCAN, bi.clk); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   291
  /* Init CANCTL1 register. Must be in init mode */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   292
  IO_PORTS_8(adrCAN + CANCTL1) &=0xC4;// 0xCB; /* Clr the bits that may be modified */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   293
  IO_PORTS_8(adrCAN + CANCTL1) = (bi.cane << 7) | (bi.loopb << 5 ) | 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   294
    (bi.listen << 4) | (bi.wupm << 2);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   295
  /* Initialize the filters for received msgs */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   296
  /* We should decide to accept all the msgs  */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   297
  canInitFilter(adrCAN, bi.fi);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   298
  /* Before to modify CANCTL0, we must leave the init mode */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   299
  canInitModeQ(adrCAN);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   300
  /* Init CANCTL0 register. MSCAN must not be in init mode */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   301
  /* Do not change the value of wupe (should be 0) and slprq (should be 1) */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   302
  /* Do not change the value of initrq (should be 0) */	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   303
  /* rxfrm is cleared, mupe also (should be before)*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   304
    IO_PORTS_8(adrCAN + CANCTL0) &= 0x53; /* Clr the bits that may be modified */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   305
    IO_PORTS_8(adrCAN + CANCTL0) = (bi.cswai << 5) | (bi.time << 3);
7
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   306
    canSetInterrupt(adrCAN);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   307
    canInitModeQ(adrCAN); /* Leave the init mode */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   308
    canSleepModeQ(adrCAN); /* Leave the sleep mode */    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   309
  return 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
char canInitClock(UNS16 adrCAN, canBusTime clk)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   314
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   315
  if (! canTestInitMode(adrCAN)) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   316
    /* Not in Init mode */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   317
    MSG_WAR(0X2601, "not in init mode ", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   318
    return 1;   
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   319
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   320
  /* Set or reset CLKSRC (register CANCTL1). Does not change the other bits*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   321
  clk.clksrc = clk.clksrc << 6;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   322
  IO_PORTS_8(adrCAN + CANCTL1) &= 0xBF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   323
  IO_PORTS_8(adrCAN + CANCTL1) |= clk.clksrc;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   324
  /* Build the CANBTR0 register */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   325
  IO_PORTS_8(adrCAN + CANBTR0) = 0x00;        /* Clear before changes */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   326
  IO_PORTS_8(adrCAN + CANBTR0) = (clk.sjw << 6) | (clk.brp);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   327
  /* Build the CANBTR1 register */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   328
  IO_PORTS_8(adrCAN + CANBTR1) = 0x00;        /* Clear before changes */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   329
  IO_PORTS_8(adrCAN + CANBTR1) = (clk.samp << 7) | (clk.tseg2 << 4) | 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   330
    (clk.tseg1);  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   331
  return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   332
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   333
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   334
/***************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   335
char canInit1Filter(UNS16 adrCAN, UNS8 nFilter, UNS16 ar, UNS16 mr)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   336
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   337
  if (! canTestInitMode(adrCAN)) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   338
    /* Error because not init mode */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   339
    MSG_WAR(0X2602, "not in init mode ", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   340
    return 1;   
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   341
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   342
  switch (nFilter) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   343
    case 0:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   344
      nFilter = CANIDAR0; /* First  bank */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   345
      break; 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   346
    case 1:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   347
      nFilter = CANIDAR2; /* First  bank */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   348
      break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   349
    case 2:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   350
      nFilter = CANIDAR4; /* Second bank */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   351
      break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   352
    case 3:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   353
      nFilter = CANIDAR6; /* Second bank */   
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   354
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   355
  /* address of CANIDARx */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   356
  IO_PORTS_8(adrCAN + nFilter)     = (UNS8) (ar >> 8);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   357
  IO_PORTS_8(adrCAN + nFilter + 1) = (UNS8) (ar);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   358
  IO_PORTS_8(adrCAN + nFilter + 4) = (UNS8) (mr >> 8);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   359
  IO_PORTS_8(adrCAN + nFilter + 5) = (UNS8) (mr);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   360
  return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   361
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   362
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   363
/***************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   364
char canInitFilter(UNS16 adrCAN, canBusFilterInit fi)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   365
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   366
if (! canTestInitMode(adrCAN)) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   367
    /* Error because not init mode */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   368
    MSG_WAR(0X2603, "not in init mode ", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   369
    return 1;   
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   370
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   371
  IO_PORTS_8(adrCAN + CANIDAC)  = fi.idam << 4;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   372
  IO_PORTS_8(adrCAN + CANIDAR0) = fi.canidar0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   373
  IO_PORTS_8(adrCAN + CANIDMR0) = fi.canidmr0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   374
  IO_PORTS_8(adrCAN + CANIDAR1) = fi.canidar1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   375
  IO_PORTS_8(adrCAN + CANIDMR1) = fi.canidmr1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   376
  IO_PORTS_8(adrCAN + CANIDAR2) = fi.canidar2;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   377
  IO_PORTS_8(adrCAN + CANIDMR2) = fi.canidmr2;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   378
  IO_PORTS_8(adrCAN + CANIDAR3) = fi.canidar3;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   379
  IO_PORTS_8(adrCAN + CANIDMR3) = fi.canidmr3;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   380
  IO_PORTS_8(adrCAN + CANIDAR4) = fi.canidar4;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   381
  IO_PORTS_8(adrCAN + CANIDMR4) = fi.canidmr4;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   382
  IO_PORTS_8(adrCAN + CANIDAR5) = fi.canidar5;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   383
  IO_PORTS_8(adrCAN + CANIDMR5) = fi.canidmr5;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   384
  IO_PORTS_8(adrCAN + CANIDAR6) = fi.canidar6;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   385
  IO_PORTS_8(adrCAN + CANIDMR6) = fi.canidmr6;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   386
  IO_PORTS_8(adrCAN + CANIDAR7) = fi.canidar7;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   387
  IO_PORTS_8(adrCAN + CANIDMR7) = fi.canidmr7;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   388
  return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   389
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   390
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   391
/***************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   392
char canInitMode(UNS16 adrCAN)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   393
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   394
  IO_PORTS_8(adrCAN + CANCTL0) |= 0x01; /* Set the bit INITRQ */ 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   395
  while (! canTestInitMode(adrCAN)) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   396
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   397
  return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   398
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   399
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   400
/***************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   401
char canInitModeQ(UNS16 adrCAN)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   402
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   403
  IO_PORTS_8(adrCAN + CANCTL0) &= 0xFE; /* Clear the bit INITRQ */ 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   404
  while (canTestInitMode(adrCAN)) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   405
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   406
  return 0;
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
char canMsgTransmit(UNS16 adrCAN, Message msg)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   411
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   412
  /* Remind : only CAN A msg implemented. ie id on 11 bits, not 29 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   413
  UNS8 cantflg;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   414
  UNS8 i;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   415
  /* Looking for a free buffer */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   416
  cantflg = IO_PORTS_8(adrCAN + CANTFLG);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   417
  if ( cantflg == 0) { /* all the TXEx are set */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   418
    MSG_WAR(0X2604, "No buffer free. Msg to transmit is losted ", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   419
    return 1; /* No buffer free */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   420
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   421
  else{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   422
    /* Selecting a buffer */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   423
    IO_PORTS_8(adrCAN + CANTBSEL) = cantflg;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   424
    /* We put ide = 0 because id is on 11 bits only */
365
9b76e0881beb Changed cob_id from struct{UNS32} to UNS16
etisserant
parents: 7
diff changeset
   425
     IO_PORTS_8(adrCAN + CANTRSID) = (UNS8)(msg.cob_id >> 3);
9b76e0881beb Changed cob_id from struct{UNS32} to UNS16
etisserant
parents: 7
diff changeset
   426
    IO_PORTS_8(adrCAN + CANTRSID + 1) = (UNS8)((msg.cob_id << 5)|
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   427
    (msg.rtr << 4));
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   428
   
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   429
    IO_PORTS_8(adrCAN + CANTRSLEN) = msg.len & 0X0F;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   430
    /* For the priority, we put the highter bits of the cob_id */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   431
    IO_PORTS_8(adrCAN + CANTRSPRI) = IO_PORTS_8(adrCAN + CANTRSID);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   432
    for (i = 0 ; i < msg.len ; i++) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   433
      IO_PORTS_8(adrCAN + CANTRSDTA + i) = msg.data[i];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   434
    } 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   435
    /* Transmitting the message */ 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   436
    cantflg = IO_PORTS_8(adrCAN + CANTBSEL);/* to know which buf is selected */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   437
    IO_PORTS_8(adrCAN + CANTBSEL) = 0x00;  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   438
    IO_PORTS_8(adrCAN + CANTFLG) = cantflg;  /* Ready to transmit ! */  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   439
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   440
 }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   441
  return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   442
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   443
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   444
/***************************************************************************/
7
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   445
char canSetInterrupt(UNS16 adrCAN) 
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   446
{
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   447
  IO_PORTS_8(adrCAN + CANRIER) = 0X01; /* Allow interruptions on receive */
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   448
  IO_PORTS_8(adrCAN + CANTIER) = 0X00; /* disallow  interruptions on transmit */
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   449
  return 0;  
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   450
}
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   451
/***************************************************************************/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   452
char canSleepMode(UNS16 adrCAN)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   453
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   454
  IO_PORTS_8(adrCAN + CANCTL0) &= 0xFB;   /* clr the bit WUPE  to avoid a wake-up*/ 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   455
  IO_PORTS_8(adrCAN + CANCTL0) |= 0x02;   /* Set the bit SLPRQ. go to Sleep !*/ 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   456
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   457
   // IO_PORTS_8(adrCAN + CANCTL1) |= 0x04;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   458
   // IO_PORTS_8(adrCAN + CANCTL0) |= 0x02;   /* Set the bit SLPRQ */ 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   459
   while ( ! canTestSleepMode(adrCAN)) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   460
     }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   461
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   462
  return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   463
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   464
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   465
/***************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   466
char canSleepModeQ(UNS16 adrCAN)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   467
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   468
  if (canTestInitMode(adrCAN)) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   469
    /* Error because in init mode */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   470
    MSG_WAR(0X2606, "not in init mode ", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   471
    return 1;   
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   472
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   473
  IO_PORTS_8(adrCAN + CANCTL0) &= 0xFD;   /* clr the bit SLPRQ */ 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   474
    while ( canTestSleepMode(adrCAN)) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   475
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   476
  return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   477
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   478
 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   479
/***************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   480
char canSleepWupMode(UNS16 adrCAN)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   481
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   482
  if (canTestInitMode(adrCAN)) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   483
    MSG_WAR(0X2607, "not in init mode ", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   484
    return 1;   
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   485
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   486
  IO_PORTS_8(adrCAN + CANCTL0) |= 0x06;   /* Set the bits WUPE & SLPRQ */ 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   487
  while ( ! canTestSleepMode(adrCAN)) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   488
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   489
  return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   490
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   491
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   492
/***************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   493
char canTestInitMode(UNS16 adrCAN)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   494
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   495
  return IO_PORTS_8(adrCAN + CANCTL1) & 0x01; /* Test the bit INITAK */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   496
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   497
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   498
/***************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   499
char canTestSleepMode(UNS16 adrCAN)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   500
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   501
  return IO_PORTS_8(adrCAN + CANCTL1) & 0x02; /* Test the bit SLPAK */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   502
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   503
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   504
/***************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   505
UNS8 canSend(UNS8 notused, Message *m)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   506
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   507
  canMsgTransmit(CANOPEN_LINE_NUMBER_USED, *m);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   508
  return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   509
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   510
384
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 365
diff changeset
   511
UNS8 canChangeBaudRate_driver( CAN_HANDLE fd, char* baud)
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 365
diff changeset
   512
{
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 365
diff changeset
   513
    return 0;
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 365
diff changeset
   514
}
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   515
/**************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   516
UNS8 f_can_receive(UNS8 notused, Message *msgRcv)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   517
{ 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   518
  UNS8 i, j;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   519
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   520
  switch (CANOPEN_LINE_NUMBER_USED) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   521
  case CAN0 : j = 0; break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   522
  case CAN1 : j = 1; break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   523
  case CAN2 : j = 2; break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   524
  case CAN3 : j = 3; break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   525
  case CAN4 : j = 4; break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   526
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   527
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   528
  /* See if a message is pending in the stack */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   529
  if (ptrMsgRcv[j].r == ptrMsgRcv[j].w)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   530
    return 0x0; // No new message
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   531
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   532
  /* Increment the reading pointer of the stack */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   533
  if (ptrMsgRcv[j].r == (MAX_STACK_MSG_RCV - 1)) 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   534
     ptrMsgRcv[j].r = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   535
  else
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   536
    ptrMsgRcv[j].r ++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   537
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   538
  /* Store the message from the stack*/
365
9b76e0881beb Changed cob_id from struct{UNS32} to UNS16
etisserant
parents: 7
diff changeset
   539
  msgRcv->cob_id = stackMsgRcv[j][ptrMsgRcv[j].r].cob_id;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   540
  msgRcv->len = stackMsgRcv[j][ptrMsgRcv[j].r].len;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   541
  msgRcv->rtr = stackMsgRcv[j][ptrMsgRcv[j].r].rtr;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   542
  for (i = 0 ; i < stackMsgRcv[j][ptrMsgRcv[j].r].len ; i++)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   543
    msgRcv->data[i] = stackMsgRcv[j][ptrMsgRcv[j].r].data[i];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   544
  return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   545
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   546
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   547
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   548
/******************************************************************************
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   549
 ******************************* CAN INTERRUPT  *******************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   550
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   551
void __attribute__((interrupt)) can0HdlTra (void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   552
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   553
 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   554
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   555
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   556
void __attribute__((interrupt)) can0HdlRcv (void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   557
{ 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   558
  UNS8 i;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   559
  lock();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   560
  IO_PORTS_8(PORTB) &= ~ 0x40; // led 6 port B : ON
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   561
  UNS8 NewPtrW; 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   562
  /* We are obliged to save the message while the interruption is pending */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   563
  /* Increment the writing stack pointer before writing the msg */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   564
  if (ptrMsgRcv[0].w == (MAX_STACK_MSG_RCV - 1)) 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   565
    NewPtrW = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   566
  else
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   567
    NewPtrW = ptrMsgRcv[0].w + 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   568
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   569
  if (NewPtrW == ptrMsgRcv[0].r) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   570
    /* The stack is full. The last msg received before this one is lost */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   571
    MSG_WAR(0X1620, "Stack for received msg is full", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   572
    //IO_PORTS_8(PORTB) &= ~0x40; // led  6         : ON (for debogue)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   573
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   574
  else
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   575
    ptrMsgRcv[0].w = NewPtrW;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   576
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   577
  /* Store the message */
365
9b76e0881beb Changed cob_id from struct{UNS32} to UNS16
etisserant
parents: 7
diff changeset
   578
  stackMsgRcv[0][ptrMsgRcv[0].w].cob_id = IO_PORTS_16(CAN0 + CANRCVID) >> 5;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   579
  stackMsgRcv[0][ptrMsgRcv[0].w].len = IO_PORTS_8(CAN0 + CANRCVLEN) & 0x0F;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   580
  stackMsgRcv[0][ptrMsgRcv[0].w].rtr = (IO_PORTS_8(CAN0 + CANRCVID + 1) >> 4) & 0x01;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   581
  for (i = 0 ; i < stackMsgRcv[0][ptrMsgRcv[0].w].len ; i++)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   582
    stackMsgRcv[0][ptrMsgRcv[0].w].data[i] = IO_PORTS_8(CAN0 + CANRCVDTA + i);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   583
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   584
  // The message is stored , so
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   585
  // we can now release the receive foreground buffer
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   586
  // and acknowledge the interruption
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   587
  IO_PORTS_8(CAN0 + CANRFLG) |= 0x01;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   588
  // Not very usefull
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   589
  IO_PORTS_8(CAN0 + CANCTL0) |= 0x80;
7
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   590
  IO_PORTS_8(PORTB) |= 0x40; // led 6 port B : OFF
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   591
  unlock();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   592
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   593
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   594
void __attribute__((interrupt)) can0HdlWup (void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   595
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   596
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   597
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   598
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   599
void __attribute__((interrupt)) can0HdlErr (void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   600
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   601
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   602
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   603
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   604
void __attribute__((interrupt)) can1HdlTra (void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   605
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   606
 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   607
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   608
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   609
void __attribute__((interrupt)) can1HdlRcv (void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   610
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   611
  UNS8 i;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   612
  lock();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   613
  UNS8 NewPtrW; 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   614
  /* We are obliged to save the message while the interruption is pending */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   615
  /* Increment the writing stack pointer before writing the msg */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   616
  if (ptrMsgRcv[1].w == (MAX_STACK_MSG_RCV - 1)) 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   617
    NewPtrW = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   618
  else
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   619
    NewPtrW = ptrMsgRcv[1].w + 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   620
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   621
  if (NewPtrW == ptrMsgRcv[1].r) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   622
    /* The stack is full. The last msg received before this one is lost */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   623
    MSG_WAR(0X2620, "Stack for received msg is full", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   624
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   625
  else
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   626
    ptrMsgRcv[1].w = NewPtrW;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   627
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   628
  /* Store the message */
365
9b76e0881beb Changed cob_id from struct{UNS32} to UNS16
etisserant
parents: 7
diff changeset
   629
  stackMsgRcv[1][ptrMsgRcv[1].w].cob_id = IO_PORTS_16(CAN1 + CANRCVID) >> 5;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   630
  stackMsgRcv[1][ptrMsgRcv[1].w].len = IO_PORTS_8(CAN1 + CANRCVLEN) & 0x0F;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   631
  stackMsgRcv[0][ptrMsgRcv[0].w].rtr = (IO_PORTS_8(CAN1 + CANRCVID + 1) >> 4) & 0x01;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   632
  for (i = 0 ; i < stackMsgRcv[1][ptrMsgRcv[1].w].len ; i++)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   633
    stackMsgRcv[1][ptrMsgRcv[1].w].data[i] = IO_PORTS_8(CAN1 + CANRCVDTA + i);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   634
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   635
  // The message is stored , so
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   636
  // we can now release the receive foreground buffer
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   637
  // and acknowledge the interruption
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   638
  IO_PORTS_8(CAN1 + CANRFLG) |= 0x01;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   639
  // Not very usefull
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   640
  IO_PORTS_8(CAN1 + CANCTL0) |= 0x80;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   641
  unlock();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   642
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   643
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   644
void __attribute__((interrupt)) can1HdlWup (void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   645
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   646
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   647
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   648
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   649
void __attribute__((interrupt)) can1HdlErr (void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   650
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   651
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   652
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   653
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   654
void __attribute__((interrupt)) can2HdlTra (void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   655
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   656
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   657
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   658
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   659
void __attribute__((interrupt)) can2HdlRcv (void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   660
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   661
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   662
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   663
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   664
void __attribute__((interrupt)) can2HdlWup (void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   665
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   666
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   667
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   668
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   669
void __attribute__((interrupt)) can2HdlErr (void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   670
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   671
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   672
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   673
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   674
void __attribute__((interrupt)) can3HdlTra (void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   675
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   676
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   677
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   678
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   679
void __attribute__((interrupt)) can3HdlRcv (void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   680
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   681
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   682
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   683
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   684
void __attribute__((interrupt)) can3HdlWup (void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   685
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   686
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   687
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   688
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   689
void __attribute__((interrupt)) can3HdlErr (void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   690
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   691
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   692
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   693
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   694
void __attribute__((interrupt)) can4HdlTra (void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   695
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   696
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   697
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   698
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   699
void __attribute__((interrupt)) can4HdlRcv (void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   700
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   701
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   702
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   703
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   704
void __attribute__((interrupt)) can4HdlWup (void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   705
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   706
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   707
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   708
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   709
void __attribute__((interrupt)) can4HdlErr (void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   710
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   711
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   712
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   713
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   714
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   715