drivers/can_kvaser/can_kvaser.c
author JaFojtik
Sat, 04 Feb 2012 14:26:54 +0100
changeset 713 ca2c2dad3a22
parent 631 08b6b903f84a
permissions -rw-r--r--
Fixed PEAK Win 32 driver, for PEAK Light API 1.x and 2.x
400
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
     1
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
     2
/*
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
     3
Copyright (C): Giuseppe Massimo BERTANI
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
     4
gmbertani@users.sourceforge.net
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
     5
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
     6
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
     7
See COPYING file for copyrights details.
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
     8
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
     9
This library is free software; you can redistribute it and/or
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    10
modify it under the terms of the GNU Lesser General Public
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    11
License as published by the Free Software Foundation; either
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    12
version 2.1 of the License, or (at your option) any later version.
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    13
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    14
This library is distributed in the hope that it will be useful,
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    15
but WITHOUT ANY WARRANTY; without even the implied warranty of
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    17
Lesser General Public License for more details.
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    18
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    19
You should have received a copy of the GNU Lesser General Public
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    20
License along with this library; if not, write to the Free Software
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    21
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    22
*/
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    23
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    24
/**
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    25
 * @file can_kvaser.c
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    26
 * @author GMB
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    27
 * @date 17/1/08
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    28
 *
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    29
 * This file is needed to interface Kvaser's CAN Leaf (USB-CAN adapter) 
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    30
 * and probably others Kvaser's products compatible with Kvaser's CANLIB,
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    31
 * to CANfestival open source CANopen stack.
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    32
 *
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    33
 * It was tested under Linux 2.6 with "Leaf Professional" and CANLIB 4.72 Beta (Oct 1,2007)
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    34
*/
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    35
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    36
#include <stdio.h>
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    37
#include <string.h>
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    38
#include <errno.h>
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    39
#include <fcntl.h>
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    40
#include <signal.h>
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    41
#include <unistd.h>
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    42
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    43
/* includes Kvaser's CANLIB header */
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    44
#include <canlib.h>
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    45
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    46
#include "can_driver.h"
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    47
 
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    48
    
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    49
/**
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    50
 * CAN_HANDLES must have value >=1 while CANLIB wants handles >= 0
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    51
 * so fd0 needs to be decremented before use.
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    52
 *
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    53
 */ 
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    54
UNS8 canReceive_driver(CAN_HANDLE fd0, Message *m)
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    55
{
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    56
canStatus retval = canOK;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    57
unsigned flags = 0;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    58
unsigned long timeStamp;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    59
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    60
    fd0--;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    61
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    62
    /* checking for input message (blocking) */
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    63
    retval = canReadWait((int)fd0, (long*)&m->cob_id, &m->data, (unsigned*)&m->len, &flags, &timeStamp, -1);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    64
    if (retval != canOK)
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    65
    {
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    66
  	    fprintf(stderr, "canReceive_driver (Kvaser) : canReadWait() error, cob_id=%08X, len=%u, flags=%08X, returned value = %d\n", 
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    67
                m->cob_id, m->len, flags, retval);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    68
        canClose((int)fd0);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    69
        return retval;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    70
    }
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    71
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    72
    m->rtr = 0;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    73
    if (flags & canMSG_RTR)
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    74
    {
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    75
        m->rtr = 1;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    76
    }
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    77
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    78
    if (flags & canMSG_EXT)
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    79
    {
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    80
        /* TODO: is it correct to set this info in cob_id? */
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    81
        m->cob_id |= 0x20000000;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    82
    }
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    83
    
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    84
    //fprintf(stderr, "canReceive_driver (Kvaser) : canReadWait() received packet, cob_id=%08X, len=%u, flags=%08X, timestamp=%d  returned value = %d\n", 
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    85
    //       m->cob_id, m->len, flags, timeStamp, retval);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    86
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    87
    return retval;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    88
}
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    89
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    90
/**
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    91
 *
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    92
 * CAN_HANDLES must have value >=1 while CANLIB wants handles >= 0
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    93
 * so fd0 needs to be decremented before use.
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    94
 *
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    95
 */ 
631
08b6b903f84a Piotr Trojanek (ptroja) cleanup patche. Thanks.
edouard
parents: 400
diff changeset
    96
UNS8 canSend_driver(CAN_HANDLE fd0, Message const *m)
400
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    97
{
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    98
canStatus retval = canOK;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    99
unsigned flags = 0;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   100
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   101
    fd0--;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   102
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   103
    flags |= canMSG_STD;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   104
    
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   105
    if (m->cob_id & 0x20000000)
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   106
    {
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   107
        /* TODO: is it correct to desume this info from cob_id? */
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   108
        flags |= canMSG_EXT;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   109
    }
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   110
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   111
    if (m->cob_id & 0x40000000)
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   112
    {
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   113
        flags |= canMSG_RTR;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   114
    }
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   115
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   116
    /*
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   117
     * TODO: when should I set canMSG_ERROR_FRAME?
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   118
     */ 
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   119
    
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   120
    retval = canWriteWait((int)fd0, m->cob_id, m->data, m->len, 10000, flags);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   121
    if (retval != canOK)
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   122
    {
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   123
  	    fprintf(stderr, "canSend_driver (Kvaser) :  canWriteWait() error, cob_id=%08X, len=%u, flags=%08X, returned value = %d\n", 
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   124
                m->cob_id, m->len, flags, retval);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   125
        canClose((int)fd0);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   126
        return retval;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   127
    }
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   128
   
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   129
    //fprintf(stderr, "canSend_driver (Kvaser) :  canWriteWait() send packet, cob_id=%08X, len=%u, flags=%08X, returned value = %d\n", 
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   130
    //            m->cob_id, m->len, flags, retval);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   131
    return retval; 
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   132
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   133
}
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   134
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   135
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   136
/**
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   137
 * 
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   138
 */ 
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   139
int TranslateBaudRate(char* optarg)
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   140
{
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   141
	if(!strcmp( optarg, "1M")) 
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   142
        return BAUD_1M;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   143
	if(!strcmp( optarg, "500K")) 
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   144
        return BAUD_500K;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   145
	if(!strcmp( optarg, "250K")) 
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   146
        return BAUD_250K;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   147
	if(!strcmp( optarg, "125K")) 
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   148
        return BAUD_125K;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   149
	if(!strcmp( optarg, "100K")) 
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   150
        return BAUD_100K;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   151
	if(!strcmp( optarg, "62K")) 
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   152
        return BAUD_62K;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   153
	if(!strcmp( optarg, "50K")) 
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   154
        return BAUD_50K;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   155
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   156
	return 0;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   157
}
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   158
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   159
/**
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   160
 * Channels and their descriptors are numbered starting from zero.
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   161
 * So I need to increment by 1 the handle returned by CANLIB because
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   162
 * CANfestival CAN_HANDLEs with value zero are considered NOT VALID. 
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   163
 * 
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   164
 * The baud rate could be given directly as bit/s
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   165
 * or using one of the BAUD_* constants defined
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   166
 * in canlib.h
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   167
 */ 
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   168
CAN_HANDLE canOpen_driver(s_BOARD *board)
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   169
{
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   170
int fd0 = -1;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   171
int channel, baud;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   172
canStatus retval = canOK;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   173
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   174
    fd0--;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   175
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   176
    sscanf(board->busname, "%d", &channel);  
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   177
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   178
    baud = TranslateBaudRate(board->baudrate);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   179
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   180
    if (baud == 0)
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   181
    {
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   182
        sscanf(board->baudrate, "%d", &baud);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   183
    }
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   184
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   185
    fd0 = canOpenChannel(channel, canWANT_EXCLUSIVE|canWANT_EXTENDED);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   186
    if (fd0 < 0)
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   187
    {
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   188
  	    fprintf(stderr, "canOpen_driver (Kvaser) : error opening channel %d\n", channel);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   189
        return (CAN_HANDLE)(fd0+1);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   190
    }
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   191
    canBusOff(fd0);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   192
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   193
    /* values for tseg1, tseg2, sjw, noSamp and  syncmode
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   194
     * come from canlib example "simplewrite.c". The doc
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   195
     * says that default values will be taken if baud is one of
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   196
     * the BAUD_* values
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   197
     */ 
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   198
    retval = canSetBusParams(fd0, baud, 4, 3, 1, 1, 0);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   199
    if (retval != canOK)
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   200
    {
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   201
  	    fprintf(stderr, "canOpen_driver (Kvaser) :  canSetBusParams() error, returned value = %d, baud=%d, \n", retval, baud);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   202
        canClose((int)fd0);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   203
        return (CAN_HANDLE)retval;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   204
    }
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   205
    
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   206
    canSetBusOutputControl(fd0, canDRIVER_NORMAL);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   207
    if (retval != canOK)
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   208
    {
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   209
  	    fprintf(stderr, "canOpen_driver (Kvaser) :  canSetBusOutputControl() error, returned value = %d\n", retval);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   210
        canClose((int)fd0);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   211
        return (CAN_HANDLE)retval;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   212
    }
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   213
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   214
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   215
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   216
    
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   217
    retval = canBusOn(fd0);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   218
    if (retval != canOK)
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   219
    {
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   220
  	    fprintf(stderr, "canOpen_driver (Kvaser) :  canBusOn() error, returned value = %d\n", retval);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   221
        canClose((int)fd0);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   222
        return (CAN_HANDLE)retval;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   223
    }
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   224
    
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   225
    return (CAN_HANDLE)(fd0+1);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   226
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   227
}
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   228
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   229
UNS8 canChangeBaudRate_driver( CAN_HANDLE fd0, char* baud)
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   230
{
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   231
int baudrate;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   232
canStatus retval = canOK;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   233
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   234
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   235
    baudrate = TranslateBaudRate(baud);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   236
    if (baudrate == 0)
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   237
    {
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   238
        sscanf(baud, "%d", &baudrate);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   239
    }
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   240
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   241
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   242
    fprintf(stderr, "%x-> changing to baud rate %s[%d]\n", (int)fd0, baud, baudrate); 
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   243
    
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   244
    canBusOff((int)fd0);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   245
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   246
    /* values for tseg1, tseg2, sjw, noSamp and  syncmode
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   247
     * come from canlib example "simplewrite.c". The doc
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   248
     * says that default values will be taken if baud is one of
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   249
     * the BAUD_* values
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   250
     */ 
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   251
    retval = canSetBusParams((int)fd0, baudrate, 4, 3, 1, 1, 0);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   252
    if (retval != canOK)
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   253
    {
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   254
  	    fprintf(stderr, "canChangeBaudRate_driver (Kvaser) :  canSetBusParams() error, returned value = %d, baud=%d, \n", retval, baud);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   255
        canClose((int)fd0);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   256
        return (UNS8)retval;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   257
    }
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   258
    
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   259
    canSetBusOutputControl((int)fd0, canDRIVER_NORMAL);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   260
    if (retval != canOK)
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   261
    {
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   262
  	    fprintf(stderr, "canChangeBaudRate_driver (Kvaser) :  canSetBusOutputControl() error, returned value = %d\n", retval);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   263
        canClose((int)fd0);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   264
        return (UNS8)retval;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   265
    }
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   266
    
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   267
    retval = canBusOn((int)fd0);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   268
    if (retval != canOK)
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   269
    {
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   270
  	    fprintf(stderr, "canChangeBaudRate_driver (Kvaser) :  canBusOn() error, returned value = %d\n", retval);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   271
        canClose((int)fd0);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   272
        return (UNS8)retval;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   273
    }
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   274
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   275
    return 0;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   276
}
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   277
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   278
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   279
/**
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   280
 *
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   281
 * CAN_HANDLES must have value >=1 while CANLIB wants handles >= 0
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   282
 * so fd0 needs to be decremented before use.
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   283
 */ 
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   284
int canClose_driver(CAN_HANDLE fd0)
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   285
{
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   286
canStatus retval = canOK;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   287
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   288
    fd0--;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   289
    
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   290
    retval = canBusOff((int)fd0);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   291
    if (retval != canOK)
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   292
    {
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   293
  	    fprintf(stderr, "canClose_driver (Kvaser) :  canBusOff() error, returned value = %d\n", retval);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   294
        canClose((int)fd0);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   295
        return retval;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   296
    }
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   297
    
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   298
    retval = canClose((int)fd0);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   299
    if (retval != canOK)
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   300
    {
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   301
  	    fprintf(stderr, "canClose_driver (Kvaser) :  canClose() error, returned value = %d\n", retval);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   302
        return retval;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   303
    }
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   304
    
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   305
    return retval;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   306
}
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
   307