drivers/can_copcican_comedi/can_copcican_comedi.c
author fbeaulier
Mon, 29 Aug 2011 16:59:55 +0200
changeset 664 a03f0aa7d219
parent 629 b9274b595650
permissions -rw-r--r--
CHANGE: SDO block mode added, without CRC support
WARNING : API change in client functions
629
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
     1
/*
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
     2
This file is part of CanFestival, a library implementing CanOpen Stack.
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
     3
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
     4
Copyright (C): Cosateq GmbH & Co.KG
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
     5
               http://www.cosateq.com/
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
     6
               http://www.scale-rt.com/
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
     7
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
     8
See COPYING file for copyrights details.
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
     9
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    10
This library is free software; you can redistribute it and/or
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    11
modify it under the terms of the GNU Lesser General Public
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    12
License as published by the Free Software Foundation; either
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    13
version 2.1 of the License, or (at your option) any later version.
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    14
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    15
This library is distributed in the hope that it will be useful,
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    16
but WITHOUT ANY WARRANTY; without even the implied warranty of
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    18
Lesser General Public License for more details.
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    19
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    20
You should have received a copy of the GNU Lesser General Public
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    21
License along with this library; if not, write to the Free Software
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    22
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    23
*/
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    24
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    25
/*
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    26
	COMEDI interface for CO-PCICAN card.
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    27
*/
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    28
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    29
#include <linux/module.h>
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    30
#include <linux/comedi.h>
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    31
#include <linux/comedilib.h>
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    32
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    33
#define NEED_PRINT_MESSAGE
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    34
#include "can_driver.h"
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    35
#include "def.h"
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    36
#include "co_pcicanops.h"
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    37
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    38
MODULE_LICENSE("GPL");
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    39
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    40
/* at the moment not threadsafe :-( */
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    41
static unsigned char selectedChannelRx = 0, selectedChannelTx = 0;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    42
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    43
static int rt_strcmp( const char *src, const char *dst )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    44
{
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    45
  int ret = 0;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    46
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    47
  while( ! (ret = *(unsigned char *)src - *(unsigned char *)dst) && *dst)
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    48
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    49
    src++;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    50
    dst++;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    51
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    52
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    53
  if( ret < 0 )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    54
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    55
    ret = -1 ;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    56
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    57
  else
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    58
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    59
    if( ret > 0 )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    60
      ret = 1 ;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    61
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    62
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    63
  return ret;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    64
}
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    65
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    66
static int TranslateBaudRate( char* optarg )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    67
{
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    68
  /* values see documentation of CO-PCICAN */
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    69
  if( !rt_strcmp( optarg, "1M"    ) ) return 0;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    70
  if( !rt_strcmp( optarg, "800K"  ) ) return 1;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    71
  if( !rt_strcmp( optarg, "500K"  ) ) return 2;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    72
  if( !rt_strcmp( optarg, "250K"  ) ) return 3;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    73
  if( !rt_strcmp( optarg, "125K"  ) ) return 4;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    74
  if( !rt_strcmp( optarg, "100K"  ) ) return 5;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    75
  if( !rt_strcmp( optarg, "83.3K" ) ) return 6;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    76
  if( !rt_strcmp( optarg, "10K"   ) ) return 7;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    77
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    78
  return -1;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    79
}
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    80
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    81
/*********CO-PCICAN specific functions to communicate with the board**********/
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    82
typedef struct
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    83
{
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    84
  char used;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    85
  CAN_HANDLE fd;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    86
  void* receiveTask;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    87
  void* d;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    88
} CANPort; /* taken from drivers/unix.c */
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    89
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    90
comedi_t* get_dev_of_port( CAN_PORT port )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    91
{
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    92
  CANPort *thisPort = (CANPort*)port;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    93
  CAN_HANDLE thisHandle;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    94
  comedi_t *dev;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    95
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    96
  if( thisPort == NULL )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    97
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    98
    MSG("can_copcican_comedi: get_dev_of_port(): thisPort is NULL\n");
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    99
    return NULL;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   100
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   101
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   102
  thisHandle = thisPort->fd;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   103
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   104
  if( thisHandle == NULL )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   105
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   106
    MSG("can_copcican_comedi: get_dev_of_port(): thisHandle is NULL\n");
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   107
    return NULL;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   108
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   109
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   110
  dev = (comedi_t*)thisHandle;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   111
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   112
  /*MSG("can_copcican_comedi: get_dev_of_port(): handle is 0x%08x\n", (unsigned int)dev);*/
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   113
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   114
  return dev;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   115
}
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   116
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   117
int co_pcican_enter_run_mode( comedi_t *dev )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   118
{
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   119
  unsigned int opcmd[15];
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   120
  unsigned int opcode = CMDQ_OPC_ENTER_RUN_MODE;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   121
  comedi_insn insn;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   122
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   123
  if( dev == NULL )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   124
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   125
    MSG("can_copcican_comedi: co_pcican_enter_run_mode(): dev is NULL\n");
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   126
    return 1;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   127
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   128
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   129
  memset( opcmd, 0x00, sizeof(opcmd) );
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   130
  opcmd[0] = 0;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   131
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   132
  memset( &insn, 0x00, sizeof(insn) );
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   133
  insn.insn      = INSN_CONFIG;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   134
  insn.n         = 1;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   135
  insn.data      = (void*)opcmd;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   136
  insn.subdev    = 0;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   137
  insn.unused[0] = opcode; /* in use for CO-PCICAN */
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   138
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   139
  comedi_do_insn( dev, &insn );
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   140
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   141
  opcmd[0] = 2;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   142
  insn.subdev    = 2;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   143
  insn.unused[0] = opcode; /* in use for CO-PCICAN */
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   144
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   145
  return comedi_do_insn( dev, &insn );
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   146
}
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   147
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   148
int co_pcican_enter_config_mode( comedi_t *dev )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   149
{
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   150
  unsigned int opcmd[15];
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   151
  unsigned int opcode = CMDQ_OPC_ENTER_CONFIG_MODE;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   152
  comedi_insn insn;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   153
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   154
  if( dev == NULL )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   155
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   156
    MSG("can_copcican_comedi: co_pcican_enter_config_mode(): dev is NULL\n");
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   157
    return 1;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   158
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   159
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   160
  memset( opcmd, 0x00, sizeof(opcmd) );
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   161
  opcmd[0] = 0;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   162
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   163
  memset( &insn, 0x00, sizeof(insn) );
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   164
  insn.insn      = INSN_CONFIG;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   165
  insn.n         = 1;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   166
  insn.data      = (void*)opcmd;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   167
  insn.subdev    = 0;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   168
  insn.unused[0] = opcode; /* in use for CO-PCICAN */
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   169
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   170
  comedi_do_insn( dev, &insn );
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   171
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   172
  opcmd[0] = 2;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   173
  insn.subdev    = 2;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   174
  insn.unused[0] = opcode; /* in use for CO-PCICAN */
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   175
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   176
  return comedi_do_insn( dev, &insn );
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   177
}
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   178
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   179
int co_pcican_select_channel( const unsigned char channel, const unsigned int direction )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   180
{
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   181
  if( channel >= NUM_CAN_CHANNELS )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   182
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   183
    MSG("can_copcican_comedi: co_pcican_select_channel(): invalid channel\n");
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   184
    return -1;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   185
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   186
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   187
  /* at the moment not threadsafe :-( */
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   188
  switch( direction )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   189
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   190
    case RX: selectedChannelRx = channel;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   191
             break;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   192
    case TX: selectedChannelTx = channel;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   193
             break;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   194
    default: return -1;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   195
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   196
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   197
  return 0;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   198
}
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   199
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   200
int co_pcican_configure_selected_channel( comedi_t *dev, s_BOARD *board, const unsigned int direction )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   201
{
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   202
  unsigned int opcmd[15];
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   203
  unsigned int opcode = CMDQ_OPC_SET_CONFIG_CHANNEL;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   204
  unsigned int selectedChannel;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   205
  comedi_insn insn;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   206
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   207
  if( dev == NULL )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   208
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   209
    MSG("can_copcican_comedi: co_pcican_configure_selected_channel(): dev is NULL\n");
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   210
    return -1;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   211
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   212
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   213
  if( board == NULL )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   214
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   215
    MSG("can_copcican_comedi: co_pcican_configure_selected_channel(): board is NULL\n");
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   216
    return -1;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   217
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   218
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   219
  if( board->baudrate == NULL )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   220
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   221
    MSG("can_copcican_comedi: co_pcican_configure_selected_channel(): baudrate is NULL\n");
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   222
    return -1;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   223
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   224
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   225
  switch( direction )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   226
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   227
    case RX: selectedChannel = selectedChannelRx;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   228
             break;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   229
    case TX: selectedChannel = selectedChannelTx;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   230
             break;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   231
    default: selectedChannel = 0xff;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   232
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   233
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   234
  if( selectedChannel >= NUM_CAN_CHANNELS )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   235
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   236
    MSG("can_copcican_comedi: co_pcican_configure_selected_channel(): invalid channel selected\n");
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   237
    return -1;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   238
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   239
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   240
  memset( opcmd, 0x00, sizeof(opcmd) );
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   241
  opcmd[0] = selectedChannel;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   242
  opcmd[1] = TranslateBaudRate( board->baudrate );
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   243
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   244
  memset( &insn, 0x00, sizeof(insn) );
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   245
  insn.insn      = INSN_CONFIG;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   246
  insn.n         = 1;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   247
  insn.data      = (void*)opcmd;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   248
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   249
  if( selectedChannel < 2 )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   250
    insn.subdev    = 0;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   251
  else
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   252
    insn.subdev    = 2;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   253
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   254
  insn.unused[0] = opcode; /* in use for CO-PCICAN */
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   255
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   256
  return comedi_do_insn( dev, &insn );
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   257
}
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   258
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   259
/*********functions which permit to communicate with the board****************/
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   260
UNS8 canReceive_driver( CAN_HANDLE fd0, Message *m )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   261
{
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   262
  MESSAGE_T canmsg;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   263
  comedi_insn insn;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   264
  UNS8 ret = 0;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   265
  comedi_t *dev = (comedi_t*)fd0;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   266
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   267
  if( dev == NULL )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   268
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   269
    MSG("can_copcican_comedi: canReceive_driver(): dev is NULL\n");
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   270
    return 1;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   271
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   272
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   273
  if( selectedChannelRx >= NUM_CAN_CHANNELS )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   274
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   275
    MSG("can_copcican_comedi: canReceive_driver(): invalid channel selected\n");
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   276
    return 1;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   277
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   278
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   279
  if( m == NULL )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   280
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   281
    MSG("can_copcican_comedi: canReceive_driver(): message is NULL\n");
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   282
    return 1;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   283
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   284
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   285
  memset( &canmsg, 0x00, sizeof(MESSAGE_T) );
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   286
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   287
  memset( &insn, 0x00, sizeof(insn) );
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   288
  insn.insn      = INSN_READ;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   289
  insn.n         = 1;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   290
  insn.data      = (void*)&canmsg;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   291
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   292
  if( selectedChannelRx < 2 )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   293
    insn.subdev    = comedi_find_subdevice_by_type(dev, COMEDI_SUBD_DI, 0);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   294
  else
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   295
    insn.subdev    = comedi_find_subdevice_by_type(dev, COMEDI_SUBD_DI, 2);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   296
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   297
  insn.unused[1] = selectedChannelRx; /* in use for CO-PCICAN */
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   298
  insn.unused[2] = sizeof(MESSAGE_T); /* in use for CO-PCICAN */
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   299
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   300
  comedi_do_insn( dev, &insn );
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   301
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   302
  if( canmsg.timestamp_lo == 0 )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   303
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   304
    memset( m, 0x00, sizeof(Message) );
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   305
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   306
    m->cob_id = 0xffff; /* set to invalid so nothing happens */
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   307
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   308
  else
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   309
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   310
    m->len = canmsg.size;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   311
    m->cob_id = canmsg.id;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   312
    m->rtr = canmsg.type & MSG_RTR;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   313
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   314
    if( !m->rtr )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   315
    {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   316
      /* this is for safety */
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   317
      if( m->len > 8 )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   318
        m->len = 8;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   319
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   320
      memcpy( m->data, canmsg.data, m->len);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   321
    }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   322
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   323
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   324
  return ret;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   325
}
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   326
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   327
/***************************************************************************/
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   328
UNS8 canSend_driver( CAN_HANDLE fd0, Message *m )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   329
{
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   330
  MESSAGE_T canmsg;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   331
  comedi_insn insn;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   332
  UNS8 ret = 0;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   333
  comedi_t *dev = (comedi_t*)fd0;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   334
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   335
  if( dev == NULL )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   336
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   337
    MSG("can_copcican_comedi: canSend_driver(): dev is NULL\n");
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   338
    return 1;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   339
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   340
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   341
  if( selectedChannelTx >= NUM_CAN_CHANNELS )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   342
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   343
    MSG("can_copcican_comedi: canSend_driver(): invalid channel selected\n");
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   344
    return 1;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   345
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   346
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   347
  if( m == NULL )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   348
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   349
    MSG("can_copcican_comedi: canSend_driver(): message is NULL\n");
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   350
    return 1;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   351
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   352
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   353
  memset( &canmsg, 0x00, sizeof(MESSAGE_T) );
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   354
  canmsg.size = m->len;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   355
  canmsg.id = m->cob_id;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   356
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   357
  if( canmsg.id >= 0x800 )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   358
    canmsg.type |= MSG_EXT;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   359
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   360
  if( m->rtr )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   361
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   362
    canmsg.type |= MSG_RTR;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   363
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   364
  else
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   365
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   366
    /* this is for safety */
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   367
    if( canmsg.size > 8 )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   368
      canmsg.size = 8;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   369
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   370
    memcpy( canmsg.data, m->data, canmsg.size);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   371
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   372
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   373
  memset( &insn, 0x00, sizeof(insn) );
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   374
  insn.insn      = INSN_WRITE;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   375
  insn.n         = 1;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   376
  insn.data      = (void*)&canmsg;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   377
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   378
  if( selectedChannelTx < 2 )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   379
    insn.subdev    = comedi_find_subdevice_by_type(dev, COMEDI_SUBD_DO, 0);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   380
  else
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   381
    insn.subdev    = comedi_find_subdevice_by_type(dev, COMEDI_SUBD_DO, 2);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   382
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   383
  insn.unused[1] = selectedChannelTx; /* in use for CO-PCICAN */
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   384
  insn.unused[2] = sizeof(MESSAGE_T) - sizeof(unsigned long); /* in use for CO-PCICAN, no timestamp for tx */
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   385
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   386
  if( comedi_do_insn( dev, &insn ) < 0 )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   387
    ret = 1;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   388
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   389
  return ret;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   390
}
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   391
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   392
/***************************************************************************/
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   393
CAN_HANDLE canOpen_driver( s_BOARD *board )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   394
{
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   395
  comedi_t *dev;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   396
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   397
  if( board == NULL )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   398
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   399
    MSG("can_copcican_comedi: canOpen_driver(): board is NULL\n");
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   400
    return NULL;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   401
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   402
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   403
  if( board->busname == NULL )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   404
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   405
    MSG("can_copcican_comedi: canOpen_driver(): busname is NULL\n");
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   406
    return NULL;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   407
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   408
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   409
  dev = comedi_open( board->busname );
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   410
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   411
  /*MSG("can_copcican_comedi: canOpen_driver(): handle is 0x%08x\n", (unsigned int)dev);*/
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   412
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   413
  return dev;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   414
}
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   415
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   416
/***************************************************************************/
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   417
int canClose_driver( CAN_HANDLE fd0 )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   418
{
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   419
  comedi_t *dev = (comedi_t*)fd0;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   420
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   421
  if( dev == NULL )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   422
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   423
    MSG("can_copcican_comedi: canClose_driver(): dev is NULL\n");
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   424
    return 1;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   425
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   426
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   427
  comedi_close( dev );
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   428
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   429
  selectedChannelRx = 0;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   430
  selectedChannelTx = 0;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   431
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   432
  return 0;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   433
}
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   434
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   435
/***************************************************************************/
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   436
UNS8 canChangeBaudRate_driver( CAN_HANDLE fd0, char* baud )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   437
{
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   438
  s_BOARD board;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   439
  UNS8 ret = 0;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   440
  comedi_t *dev = (comedi_t*)fd0;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   441
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   442
  if( dev == NULL )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   443
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   444
    MSG("can_copcican_comedi: canChangeBaudRate_driver(): dev is NULL\n");
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   445
    return 1;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   446
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   447
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   448
  if( baud == NULL )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   449
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   450
    MSG("can_copcican_comedi: canChangeBaudRate_driver(): baud is NULL\n");
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   451
    return 1;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   452
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   453
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   454
  memset( &board, 0x00, sizeof(s_BOARD) );
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   455
  board.baudrate = baud;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   456
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   457
  if( co_pcican_configure_selected_channel( dev, &board, RX ) < 0 )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   458
    ret = 1;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   459
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   460
  if( co_pcican_configure_selected_channel( dev, &board, TX ) < 0 )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   461
    ret = 1;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   462
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   463
  return ret;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   464
}
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   465
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   466
static int init(void)
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   467
{
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   468
  printk("can_copcican_comedi for CanFestival loaded\n");
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   469
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   470
  return 0;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   471
}
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   472
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   473
static void exit(void)
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   474
{
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   475
  printk("can_copcican_comedi unloaded\n");
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   476
}
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   477
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   478
module_init(init);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   479
module_exit(exit);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   480
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   481
EXPORT_SYMBOL(get_dev_of_port);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   482
EXPORT_SYMBOL(co_pcican_enter_run_mode);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   483
EXPORT_SYMBOL(co_pcican_enter_config_mode);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   484
EXPORT_SYMBOL(co_pcican_select_channel);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   485
EXPORT_SYMBOL(co_pcican_configure_selected_channel);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   486
EXPORT_SYMBOL(canOpen_driver);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   487
EXPORT_SYMBOL(canClose_driver);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   488
EXPORT_SYMBOL(canSend_driver);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   489
EXPORT_SYMBOL(canReceive_driver);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   490
EXPORT_SYMBOL(canChangeBaudRate_driver);