include/hcs12/candriver.h
author etisserant
Thu, 12 Apr 2007 17:10:57 +0200
changeset 156 515d11cb496e
parent 7 126e37bcca0f
permissions -rw-r--r--
Removed dead code.
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
#ifndef __CANDRIVER__
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    24
#define __CANDRIVER__
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    25
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    26
//#include DEBUG_CAN
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    27
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    28
#include <can.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    29
#include <objdictdef.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    30
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    31
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    32
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    33
The CAN message received are stored in a fifo stack
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    34
We consider one stack for all the 5 can devices. It is a choice !
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
/* Be free to change this value */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    38
#define MAX_STACK_MSG_RCV 5
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    39
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    40
/* Number of incomings and outcomings CAN Line. The layer CanOpen must be
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    41
used only for ONE line CAN. But you may used one or more CAN drivers, without
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    42
a CanOpen layer.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    43
Only 2 lines are implemented. If more lines are needed, copy void __attribute__((interrupt)) can0HdlRcv (void) to void __attribute__((interrupt)) canXHdlRcv (void) and make 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    44
changes : [0] to [x], CAN0 to CANX, etc
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    45
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    46
#define NB_LINE_CAN 1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    47
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    48
/* Whose hardware HCS12 CAN block is used for CanOpen ? Chose between CAN0, ..., CAN4
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    49
If you use CANOPEN_LINE_NUMBER_USED = CANI, the value of NB_LINE_CAN must be
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    50
more or equal to I + 1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    51
Value other than CAN0 not tested, but should work fine.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    52
 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    53
#define CANOPEN_LINE_NUMBER_USED CAN0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    54
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    55
/* Stack of received messages 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    56
MSG received on CAN0 module is stored in stackMsgRcv[0], etc
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    57
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    58
extern volatile Message stackMsgRcv[NB_LINE_CAN][MAX_STACK_MSG_RCV];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    59
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    60
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    61
/* Copy from the stack of the message to treat */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    62
extern Message msgRcv;
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
/* To move on the stack of messages 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    66
 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    67
typedef struct {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    68
  UNS8 w ; /* received */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    69
  UNS8 r ; /* To transmit */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    70
} t_pointerStack;
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
/* Pointer for write or read a message in/from the reception stack */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    74
extern volatile t_pointerStack ptrMsgRcv[NB_LINE_CAN];
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
Parameters to define the  clock system for the CAN bus
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    78
example : 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    79
CAN_BUS_TIME clk = {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    80
      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
    81
      0,  // brp :  chose btw 0 and 63 (6 bits).  freq time quantum = 16MHz / (brp + 1) 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    82
      1,  // sjw : chose btw 0 and 3 (2 bits). Sync on (sjw + 1 ) time quantum          
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    83
      1,  // samp : chose btw 0 and 3 (2 bits) (samp + 1 ) samples per bit              
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    84
      4,  // tseg2 : chose btw 0 and 7 (3 bits) Segment 2 width = (tseg2 + 1)  tq       
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    85
      9,  // tseg1 : chose btw 0 and 15 (4 bits) Segment 1 width = (tseg1 + 1)  tq      
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    86
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    87
      
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    88
      With these values, 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    89
      - The width of the bit time is 16 time quantum :
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    90
          - 1 tq for the SYNC segment (could not be modified)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    91
          - 10 tq for the TIME 1 segment (tseg1 = 9)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    92
          - 5 tq for the TIME 2 segment (tseg2 = 4)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    93
      - Because the bus clock of the MSCAN is 16 MHZ, and the 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    94
        freq of the time quantum is 16 MHZ (brp = 0), and  there are 16 tq in the bit time,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    95
        so the freq of the bit time is 1 MHz.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    96
      
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    97
  };
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    98
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    99
typedef struct {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   100
  UNS8  clksrc;     /* use of internal clock  or clock bus        */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   101
  UNS8  brp;        /* define the bus speed                       */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   102
  UNS8  sjw;        /* Number of time quantum for synchro - 1     */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   103
  UNS8  samp;       /* Number of sample per bit (1 or 3)          */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   104
  UNS8  tseg2;      /* Width of the time segment 2 (in tq) - 1    */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   105
  UNS8  tseg1;      /* Width of the time segment 1 (in tq) - 1    */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   106
} canBusTime;
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
Parameters to init the filters for received messages
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   110
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   111
typedef struct {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   112
  UNS8  idam;        /* Put 0x01 for 16 bits acceptance filter    */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   113
  UNS8  canidar0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   114
  UNS8  canidmr0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   115
  UNS8  canidar1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   116
  UNS8  canidmr1; 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   117
  UNS8  canidar2;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   118
  UNS8  canidmr2;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   119
  UNS8  canidar3;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   120
  UNS8  canidmr3;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   121
  UNS8  canidar4;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   122
  UNS8  canidmr4;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   123
  UNS8  canidar5;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   124
  UNS8  canidmr5; 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   125
  UNS8  canidar6;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   126
  UNS8  canidmr6;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   127
  UNS8  canidar7;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   128
  UNS8  canidmr7;  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   129
} canBusFilterInit;
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
Parameters to init MSCAN
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   133
Example
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   134
CAN_BUS_INIT bi = {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   135
    0,     no low power                  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   136
    0,     no time stamp                
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   137
    1,     enable MSCAN                 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   138
    0,     clock source : oscillator    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   139
    0,     no loop back                 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   140
    0,     no listen only               
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   141
    0,     no low pass filter for wk up 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   142
    {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   143
      1,       Use the oscillator clock                         
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   144
      0,       Quartz oscillator : freq time quantum =  freq oscillator clock / (0 + 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   145
      1,       Sync on (1 + 1) time quantum                            
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   146
      1,       1 sample per bit                                  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   147
      4,       time segment 2 width : (4 + 1) tq                     
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   148
      9,       time segment 1 width : (9 + 1) tq                     
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
typedef struct {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   154
  UNS8  cswai;      /* Low power/normal in wait mode   (1/0)      */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   155
  UNS8  time;       /* Timer for time-stamp enable/disable (1/0)  */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   156
  UNS8  cane;       /* Enable MSCAN (yes=1) Do it !               */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   157
  UNS8  clksrc;     /* clock source bus/oscillator (1/0)          */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   158
  UNS8  loopb;      /* loop back mode for test (yes=1/no=0)       */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   159
  UNS8  listen;     /* MSCAN is listen only (yes=1/no=0 ie normal)*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   160
  UNS8  wupm;       /* low pas filter for wake up (yes=1/no=0)    */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   161
  canBusTime 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   162
        clk;        /* Values for clock system init               */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   163
  canBusFilterInit
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   164
  fi;               /* Values for filter acceptance msg init      */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   165
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   166
} canBusInit;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   167
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   168
extern canBusInit bi;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   169
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   170
7
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   171
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   172
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   173
For the received messsage, add a Identificator to
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   174
the list of ID to accept.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   175
You can use several times this function to accept several messages.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   176
It configures registers on 16 bits.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   177
Automatically, it configure the filter to
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   178
- not accepting the msg on 29 bits (ide=1 refused)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   179
- not filtering on rtr state (rtr = 1 and rtr = 0 are accepted)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   180
Algo :
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   181
if CANIDARx = 0 then  CANIDARx = id . else do nothing
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   182
CANIDMRx = CANIDMRx OR (CANIDARx XOR id )
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   183
nFilter : 0 to 3
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   184
Must be in init mode before.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   185
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   186
char canAddIdToFilter (
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   187
		       UNS16 adrCAN,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   188
		       UNS8 nFilter,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   189
		       UNS16 id /* 11 bits, the 5 msb not used */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   190
		       );
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   191
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   192
/*
7
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   193
 Use this function to change the CAN message acceptance filters and masks.
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   194
 */
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   195
char canChangeFilter (UNS16 adrCAN, canBusFilterInit fi);
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   196
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   197
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   198
/*
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   199
Enable one of the 5 MSCAN.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   200
Must be done only one time after a reset of the CPU.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   201
To do before any CAN initialisation
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   202
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   203
char canEnable (
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   204
		UNS16 adrCAN /* First address of MSCANx registers */
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
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   208
/* 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   209
Initialize one of the 5 mscan
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   210
can be done multiple times in your code
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   211
Return 0 : OK
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   212
When it return from the function,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   213
mscan is on sleep mode with wake up disabled.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   214
      is not on init mode
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   215
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   216
char canInit (
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   217
	      UNS16 adrCAN,   /* First address of MSCANx registers  */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   218
	      canBusInit 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   219
	      bi       /* All the parameters to init the bus */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   220
	      );
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   221
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   222
Initialize the parameters of the system clock for the MSCAN
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   223
You must put the MSCAN in sleep mode before with canSleepMode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   224
Return 0 : OK
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   225
       1 : Not in sleep mode. Unable to init MSCAN 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   226
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   227
char canInitClock (
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   228
		   UNS16 adrCAN, /* First address of MSCANx registers */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   229
		   canBusTime clk);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   230
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   231
/* 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   232
Initialize one filter for acceptance of received msg.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   233
Filters MUST be configured on 16 bits 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   234
(See doc Motorola mscan bloc guide fig 4.3)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   235
Must be in init mode before.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   236
adrCAN  : adress of the first register of the mscan module
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   237
nFilter : the filter : 0 to 3.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   238
ar : Value to write in acceptance register
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   239
     Beware ! hight byte and low byte inverted.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   240
     for example if nFilter = 0, hight byte of ar -> CANIDAR0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   241
                                 low   byte of ar -> CANIDAR1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   242
mr : Value to write in mask register
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   243
     Beware ! hight byte and low byte inverted.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   244
     for example if nFilter = 2, hight byte of ar -> CANIDMR4
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   245
                                 low   byte of ar -> CANIDMR5
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   246
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   247
char canInit1Filter (
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   248
		     UNS16 adrCAN, 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   249
		     UNS8 nFilter,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   250
		     UNS16 ar,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   251
		     UNS16 mr
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
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   255
Initialise the parameters for filtering the messages received.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   256
You must put the MSCAN in init mode before with canInitMode()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   257
Return 0 : OK
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   258
       1 : Not in init mode. Unable to init MSCAN 
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
char canInitFilter (
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   262
		    UNS16 adrCAN, /* First address of MSCANx registers */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   263
		    canBusFilterInit fi);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   264
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   265
Put one of the 5 mscan in Init mode
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   266
Loop until init mode is reached.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   267
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   268
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   269
char canInitMode (
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   270
		  UNS16 adrCAN /* First address of MSCANx registers */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   271
		  );	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   272
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   273
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   274
Leave the Init mode
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   275
loop until init mode leaved.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   276
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   277
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   278
char canInitModeQ (
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   279
		   UNS16 adrCAN /* First address of MSCANx registers */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   280
		   );
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   281
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   282
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   283
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   284
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   285
Transmit a msg on CAN "adrCan"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   286
Return : 0      No error
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   287
         other  error : no buffer available to make the transmission
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
char canMsgTransmit (
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   291
		     UNS16 adrCAN,  /* First address of MSCANx registers */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   292
		     Message msg  /* Message to transmit                */
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
/*
7
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   296
 Set the interruptions. Must be call just after having left the init mode.
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   297
 */	     
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   298
char canSetInterrupt (UNS16 adrCAN);		     
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   299
126e37bcca0f ajout filtrage msgs
dejoigny
parents: 0
diff changeset
   300
/*
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   301
Put one of the 5 mscan in sleep mode
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   302
Beware! If some messages are to be sent,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   303
or if it is receiving, going into sleep mode
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   304
may take time.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   305
Wake up is disabled : stay in sleep mode even if
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   306
bus traffic detected.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   307
return 0 if 0K, other if error : mscan is on init mode.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   308
Stay in this function until the sleep mode
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   309
is reached.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   310
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   311
char canSleepMode (
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   312
		   UNS16 adrCAN /* First address of MSCANx registers */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   313
		   );	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   314
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   315
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   316
Leave the sleep mode
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   317
loop until sleep mode leaved.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   318
return 0 : OK
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   319
return 1 : error : in init mode
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   320
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   321
char canSleepModeQ (
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   322
		    UNS16 adrCAN /* First address of MSCANx registers */
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
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   326
Put one of the 5 mscan in sleep mode
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   327
MSCAN must not be in init mode.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   328
wake up is enabled : wake up if traffic on CAN is detected
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   329
Beware! If some messages are to be sent,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   330
or if it is receiving, going into sleep mode
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   331
may take time.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   332
Loop until sleep mode reached.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   333
return 0 if 0K, other if error
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   334
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   335
char canSleepWupMode (
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   336
		      UNS16 adrCAN /* First address of MSCANx registers */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   337
		      );	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   338
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   339
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   340
Test if one of the 5 mscan is in init mode.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   341
Return 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   342
       0     -> Not in init mode
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   343
       other -> In init mode
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   344
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   345
char canTestInitMode (
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   346
		      UNS16 adrCAN /* First address of MSCANx registers */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   347
		      );   
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   348
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   349
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   350
Test if one of the 5 mscan is in sleep mode.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   351
Return 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   352
       0     -> Not in sleep mode
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   353
       other -> In sleep mode
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   354
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   355
char canTestSleepMode (
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   356
		       UNS16 adrCAN /* First address of MSCANx registers */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   357
		       );   
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   358
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   359
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   360
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   361
#endif /*__CANDRIVER__*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   362