drivers/can_copcican_win32/can_copcican_win32.cpp
author mwildbolz
Mon, 01 Oct 2012 17:09:55 +0200
changeset 752 48a0ebbefa74
parent 629 b9274b595650
permissions -rw-r--r--
Removed auto-generated object dictionary files from example folders
Updated .hgignore file (generated Makefiles, auto-generated OD files)
629
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
     1
// can_copcican_win32.cpp : Defines the exported functions for the DLL application.
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
     2
//
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
     3
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
     4
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
     5
#include "stdafx.h"
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
     6
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
     7
/*
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
     8
This file is part of CanFestival, a library implementing CanOpen Stack.
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
     9
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    10
Copyright (C): Cosateq GmbH & Co.KG
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    11
               http://www.cosateq.com/
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    12
               http://www.scale-rt.com/
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    13
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    14
See COPYING file for copyrights details.
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    15
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    16
This library is free software; you can redistribute it and/or
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    17
modify it under the terms of the GNU Lesser General Public
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    18
License as published by the Free Software Foundation; either
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    19
version 2.1 of the License, or (at your option) any later version.
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    20
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    21
This library is distributed in the hope that it will be useful,
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    22
but WITHOUT ANY WARRANTY; without even the implied warranty of
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    23
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    24
Lesser General Public License for more details.
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    25
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    26
You should have received a copy of the GNU Lesser General Public
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    27
License along with this library; if not, write to the Free Software
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    28
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    29
*/
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    30
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    31
/*
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    32
	CAN driver interface for CO-PCICAN card.
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    33
*/
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    34
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    35
#include <stdio.h>
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    36
//#include <unistd.h>
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    37
#include <fcntl.h>
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    38
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    39
//#define NEED_PRINT_MESSAGE
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    40
static int initdone = 0;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    41
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    42
inline void * maskDevID(int devId){	return ((void*)( (devId & 0x0000000F) | 0xC05A0000)); }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    43
inline int unmaskDevID(void * Ptr){	return ((int)((int)Ptr & 0x0000000F)); }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    44
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    45
/* at the moment not threadsafe :-( */
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    46
static unsigned char selectedChannelRx = 1, selectedChannelTx = 1;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    47
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    48
static cosateq::devices::can::co_baudrate_t TranslateBaudRate( char* optarg )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    49
{
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    50
  /* values see documentation of CO-PCICAN */
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    51
	if( !strcmp( optarg, "1M"    ) ) return cosateq::devices::can::CO_BAUD_1M;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    52
	if( !strcmp( optarg, "800K"  ) ) return cosateq::devices::can::CO_BAUD_800k;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    53
	if( !strcmp( optarg, "500K"  ) ) return cosateq::devices::can::CO_BAUD_500k;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    54
  if( !strcmp( optarg, "250K"  ) ) return cosateq::devices::can::CO_BAUD_250k;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    55
  if( !strcmp( optarg, "125K"  ) ) return cosateq::devices::can::CO_BAUD_125k;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    56
  if( !strcmp( optarg, "100K"  ) ) return cosateq::devices::can::CO_BAUD_100k;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    57
  if( !strcmp( optarg, "83.3K" ) ) return cosateq::devices::can::CO_BAUD_83k;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    58
  if( !strcmp( optarg, "10K"   ) ) return cosateq::devices::can::CO_BAUD_10k;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    59
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    60
  return (cosateq::devices::can::co_baudrate_t)-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
int co_pcican_select_channel( const unsigned char channel, const unsigned int direction )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    64
{
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    65
  if( channel >= CHANNELS )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    66
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    67
    MSG("can_copcican_linux: co_pcican_select_channel(): invalid channel\n");
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    68
    return -1;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    69
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    70
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    71
  /* at the moment not threadsafe :-( */
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    72
  switch( direction )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    73
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    74
    case cosateq::devices::can::CO_CAN_RX: selectedChannelRx = channel;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    75
             break;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    76
    case cosateq::devices::can::CO_CAN_TX: selectedChannelTx = channel;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    77
             break;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    78
    default: 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
  return 0;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    82
}
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    83
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    84
int co_pcican_configure_selected_channel( const int fd, s_BOARD *board, const unsigned int direction )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    85
{
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    86
  unsigned int selectedChannel;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    87
  int ret = 0;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    88
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    89
  if( fd < 0 )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    90
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    91
    MSG("can_copcican_linux: co_pcican_configure_selected_channel(): invalid file descriptor\n");
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    92
    return -1;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    93
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    94
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    95
  if( board == NULL )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    96
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    97
    MSG("can_copcican_linux: co_pcican_configure_selected_channel(): board is NULL\n");
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    98
    return -1;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
    99
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   100
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   101
  if( board->baudrate == NULL )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   102
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   103
    MSG("can_copcican_linux: co_pcican_configure_selected_channel(): baudrate is NULL\n");
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   104
    return -1;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   105
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   106
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   107
  switch( direction )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   108
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   109
    case cosateq::devices::can::CO_CAN_RX: selectedChannel = selectedChannelRx;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   110
             break;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   111
    case cosateq::devices::can::CO_CAN_TX: selectedChannel = selectedChannelTx;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   112
             break;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   113
    default: selectedChannel = 0xff;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   114
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   115
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   116
  if( selectedChannel >= CHANNELS )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   117
  {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   118
    MSG("can_copcican_linux: co_pcican_configure_selected_channel(): invalid channel selected\n");
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   119
    return -1;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   120
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   121
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   122
  ret = can_setChannelConfig( TranslateBaudRate( board->baudrate ),0x0,unmaskDevID((void*)fd),selectedChannel);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   123
  if ( ret != 0 ) {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   124
	  can_enterRunMode(unmaskDevID((void*)fd),selectedChannel/2);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   125
	  return -ret;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   126
  }else{
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   127
	  ret = can_setIrqMode(unmaskDevID((void*)fd),selectedChannel);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   128
	  can_enterRunMode(unmaskDevID((void*)fd),selectedChannel/2);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   129
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   130
  return ret;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   131
}
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   132
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   133
/*********functions which permit to communicate with the board****************/
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   134
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   135
UNS8 __stdcall canReceive_driver( CAN_HANDLE fd0, Message *m )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   136
{
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   137
  cosateq::devices::can::co_can_packet_t p;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   138
  int ret = 0;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   139
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   140
  if ( !m )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   141
	  return 0;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   142
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   143
  memset(&p,0,sizeof(cosateq::devices::can::co_can_packet_t));
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   144
  ret = can_receive(&p,unmaskDevID(fd0),selectedChannelRx);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   145
  //printf("rec: %d\n",ret);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   146
  if ( ret != 0 )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   147
	  return 1;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   148
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   149
  //printf("rec2: %d\n",ret);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   150
  if ( p.size > 8 )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   151
	  p.size = 8;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   152
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   153
  if ( !(p.type & MSG_RTR ) )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   154
    memcpy(m->data,p.data,p.size);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   155
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   156
  m->cob_id = p.id;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   157
  m->len = p.size;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   158
  m->rtr = p.type & MSG_RTR;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   159
  
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   160
  return 0;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   161
}
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   162
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   163
/***************************************************************************/
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   164
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   165
UNS8 __stdcall canSend_driver( CAN_HANDLE fd0, Message *m )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   166
{
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   167
  cosateq::devices::can::co_can_packet_t p;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   168
  
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   169
  if ( !m )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   170
	  return 0;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   171
  memset(&p,0,sizeof(cosateq::devices::can::co_can_packet_t));
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   172
  p.id = m->cob_id;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   173
  p.size = (m->len > 8) ? 8 : m->len;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   174
  p.type = ( m->rtr ) ? 0x2:0x0;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   175
  if ( p.id > 0x800 )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   176
	  p.type |= MSG_EXT;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   177
  memcpy(p.data,m->data,p.size);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   178
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   179
  return can_send(&p,unmaskDevID(fd0),selectedChannelTx);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   180
}
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   181
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   182
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   183
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   184
/***************************************************************************/
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   185
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   186
UNS8 __stdcall canChangeBaudRate_driver( CAN_HANDLE fd0, char* baud )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   187
{
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   188
  UNS8 ret = 0;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   189
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   190
  ret = can_enterCfgMode(unmaskDevID(fd0),0);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   191
  if ( ret != 0)
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   192
    MSG("Enter config mode for Channelpair 0 failed in Function %s! Error: %d\n",__FUNCTION__,ret);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   193
  ret = can_enterCfgMode(unmaskDevID(fd0),1);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   194
  if ( ret != 0)
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   195
    MSG("Enter config mode for Channelpair 1 failed in Function %s! Error: %d\n",__FUNCTION__,ret);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   196
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   197
  for ( int i = 0; i < 4; i++ ) {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   198
      ret = can_setChannelConfig(TranslateBaudRate(baud),0x0,unmaskDevID(fd0),i);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   199
      if ( ret != 0)
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   200
        MSG("Set config for channel %d failed in Function %s! Error: %d\n",i,__FUNCTION__,ret);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   201
	  can_setIrqMode(unmaskDevID(fd0),i);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   202
  }
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   203
  ret = can_enterRunMode(unmaskDevID(fd0),0);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   204
  if ( ret != 0)
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   205
    MSG("Enter run mode for Channelpair 1 failed in Function %s! Error: %d\n",__FUNCTION__,ret);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   206
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   207
  ret = can_enterRunMode(unmaskDevID(fd0),1);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   208
  if ( ret != 0)
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   209
    MSG("Enter run mode for Channelpair 1 failed in Function %s! Error: %d\n",__FUNCTION__,ret);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   210
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   211
  return ret;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   212
}
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   213
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   214
CAN_HANDLE __stdcall canOpen_driver( s_BOARD *board )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   215
{
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   216
	int ret = 0;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   217
	int devId = 0;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   218
	if ( !board )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   219
		return NULL;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   220
	if ( !board->busname )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   221
		return NULL;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   222
	//TODO find out how boardname resolves
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   223
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   224
	//printf("BOARD: 0x%x %s\n",board,board->busname);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   225
	//sscanf_s(board->busname,"%d",&devId);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   226
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   227
	if ( devId < 0 || devId > 15 )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   228
		return NULL;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   229
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   230
	//return (can_HANDLE)NULL;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   231
	if ( !initdone ) {
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   232
		can_init();
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   233
		initdone = 1;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   234
	}
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   235
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   236
	ret = can_open(devId);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   237
	if ( ret < 0 )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   238
		return (CAN_HANDLE)NULL;
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   239
	
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   240
	canChangeBaudRate_driver( maskDevID(devId),board->baudrate );
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   241
	
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   242
	return maskDevID(devId);
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   243
}
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   244
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   245
int __stdcall canClose_driver(CAN_HANDLE fd0 )
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   246
{
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   247
	return can_close(unmaskDevID(fd0));
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   248
}
b9274b595650 CosateQ contribution.
edouard
parents:
diff changeset
   249