drivers/can_peak_win32/can_peak_win32.c
author greg
Mon, 27 Jul 2009 09:18:04 +0200
changeset 578 eb67d9aa714f
parent 574 e5d7f4412a4c
child 598 fff217764431
permissions -rwxr-xr-x
add install/uninstall rules in Makefile.in
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents:
diff changeset
     1
/*
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
     2
This file is part of CanFestival, a library implementing CanOpen Stack.
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
     3
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
     4
Copyright (C): Edouard TISSERANT and Francis DUPIN
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
     5
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
     6
See COPYING file for copyrights details.
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
     7
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
     8
This library is free software; you can redistribute it and/or
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
     9
modify it under the terms of the GNU Lesser General Public
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    10
License as published by the Free Software Foundation; either
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    11
version 2.1 of the License, or (at your option) any later version.
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    12
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    13
This library is distributed in the hope that it will be useful,
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    14
but WITHOUT ANY WARRANTY; without even the implied warranty of
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    16
Lesser General Public License for more details.
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    17
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    18
You should have received a copy of the GNU Lesser General Public
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    19
License along with this library; if not, write to the Free Software
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    20
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents:
diff changeset
    21
*/
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents:
diff changeset
    22
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    23
#if defined(WIN32) && !defined(__CYGWIN__)
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    24
#define usleep(micro) Sleep(micro%1000 ? (micro/1000) + 1 : (micro/1000))
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    25
#else
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    26
#include <stdio.h>
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    27
#include <string.h>
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    28
#include <errno.h>
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    29
#include <fcntl.h>
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    30
#endif
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    31
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    32
#include "cancfg.h"
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    33
#include "can_driver.h"
267
96c688ebcde7 Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents: 145
diff changeset
    34
#include "def.h"
41
e70439f50539 First working cygwin/pcan_light commit. can_peak_win32.c is obfuscated.
etisserant
parents: 38
diff changeset
    35
#ifndef extra_PCAN_init_params
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    36
	#define extra_PCAN_init_params /**/
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    37
#else
574
e5d7f4412a4c Add print_getenv function wich print extra init params
greg
parents: 570
diff changeset
    38
	long int print_getenv(const char* pcanparam)
e5d7f4412a4c Add print_getenv function wich print extra init params
greg
parents: 570
diff changeset
    39
	{
e5d7f4412a4c Add print_getenv function wich print extra init params
greg
parents: 570
diff changeset
    40
		char* param=NULL;
e5d7f4412a4c Add print_getenv function wich print extra init params
greg
parents: 570
diff changeset
    41
		long int res=0;
e5d7f4412a4c Add print_getenv function wich print extra init params
greg
parents: 570
diff changeset
    42
e5d7f4412a4c Add print_getenv function wich print extra init params
greg
parents: 570
diff changeset
    43
		param = getenv(pcanparam);
e5d7f4412a4c Add print_getenv function wich print extra init params
greg
parents: 570
diff changeset
    44
		if(param != NULL){
e5d7f4412a4c Add print_getenv function wich print extra init params
greg
parents: 570
diff changeset
    45
			res = strtol(param,NULL,0);
e5d7f4412a4c Add print_getenv function wich print extra init params
greg
parents: 570
diff changeset
    46
		}
e5d7f4412a4c Add print_getenv function wich print extra init params
greg
parents: 570
diff changeset
    47
		else
e5d7f4412a4c Add print_getenv function wich print extra init params
greg
parents: 570
diff changeset
    48
			printf("Environment variable %s not defined !\n", pcanparam);
e5d7f4412a4c Add print_getenv function wich print extra init params
greg
parents: 570
diff changeset
    49
		printf("Found environment variable %s : %ld\n", pcanparam ,res);
e5d7f4412a4c Add print_getenv function wich print extra init params
greg
parents: 570
diff changeset
    50
		return res;
e5d7f4412a4c Add print_getenv function wich print extra init params
greg
parents: 570
diff changeset
    51
	}
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    52
	#define extra_PCAN_init_params\
574
e5d7f4412a4c Add print_getenv function wich print extra init params
greg
parents: 570
diff changeset
    53
		,print_getenv("PCANHwType")\
e5d7f4412a4c Add print_getenv function wich print extra init params
greg
parents: 570
diff changeset
    54
		,print_getenv("PCANIO_Port")\
e5d7f4412a4c Add print_getenv function wich print extra init params
greg
parents: 570
diff changeset
    55
		,print_getenv("PCANInterupt")
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    56
#endif
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    57
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    58
static s_BOARD *first_board = NULL;
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
    59
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
    60
//Create the Event for the first board
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
    61
HANDLE hEvent1 = NULL;
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
    62
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
    63
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
    64
#ifdef PCAN2_HEADER_
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
    65
	static s_BOARD *second_board = NULL;
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
    66
	HANDLE hEvent2 = NULL;
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
    67
#endif
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    68
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    69
// Define for rtr CAN message
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    70
#define CAN_INIT_TYPE_ST_RTR MSGTYPE_STANDARD | MSGTYPE_RTR
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    71
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    72
/***************************************************************************/
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    73
int TranslateBaudeRate(char* optarg){
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    74
	if(!strcmp( optarg, "1M")) return CAN_BAUD_1M;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    75
	if(!strcmp( optarg, "500K")) return CAN_BAUD_500K;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    76
	if(!strcmp( optarg, "250K")) return CAN_BAUD_250K;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    77
	if(!strcmp( optarg, "125K")) return CAN_BAUD_125K;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    78
	if(!strcmp( optarg, "100K")) return CAN_BAUD_100K;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    79
	if(!strcmp( optarg, "50K")) return CAN_BAUD_50K;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    80
	if(!strcmp( optarg, "20K")) return CAN_BAUD_20K;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    81
	if(!strcmp( optarg, "10K")) return CAN_BAUD_10K;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    82
	if(!strcmp( optarg, "5K")) return CAN_BAUD_5K;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    83
	if(!strcmp( optarg, "none")) return 0;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    84
	return 0x0000;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    85
}
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    86
566
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
    87
UNS8 canInit (s_BOARD *board)
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    88
{
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    89
	int baudrate;
566
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
    90
	int ret = 0;
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
    91
329
7717252e3ed9 Changes to compile for win32
greg
parents: 301
diff changeset
    92
#ifdef PCAN2_HEADER_
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    93
	// if not the first handler
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
    94
	if(second_board == (s_BOARD *)board) {
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    95
		if(baudrate = TranslateBaudeRate(board->baudrate))
566
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
    96
		{
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
    97
			ret = CAN2_Init(baudrate, CAN_INIT_TYPE_ST extra_PCAN_init_params);
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
    98
			if(ret != CAN_ERR_OK)
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
    99
				return 0;
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   100
		}
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   101
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   102
		//Create the Event for the first board
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   103
		hEvent2 = CreateEvent(NULL, // lpEventAttributes
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   104
							FALSE,  // bManualReset
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   105
							FALSE,  // bInitialState
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   106
							"");    // lpName
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   107
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   108
		//Set Event Handle for CANReadExt
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   109
		CAN2_SetRcvEvent(hEvent2);
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   110
	}
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   111
	else
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   112
#endif
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   113
	if(first_board == (s_BOARD *)board) {
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   114
		if(baudrate = TranslateBaudeRate(board->baudrate))
566
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   115
		{
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   116
			ret = CAN_Init(baudrate, CAN_INIT_TYPE_ST extra_PCAN_init_params);
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   117
			if(ret != CAN_ERR_OK)
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   118
				return 0;
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   119
		}
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   120
		//Create the Event for the first board
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   121
		hEvent1 = CreateEvent(NULL, // lpEventAttributes
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   122
							FALSE,  // bManualReset
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   123
							FALSE,  // bInitialState
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   124
							"");    // lpName
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   125
		//Set Event Handle for CANReadExt
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   126
		CAN_SetRcvEvent(hEvent1);
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   127
	}
566
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   128
	return 1;
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   129
}
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   130
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   131
/********* functions which permit to communicate with the board ****************/
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   132
UNS8 canReceive_driver (CAN_HANDLE fd0, Message * m)
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   133
{
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   134
	int ret=0;
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   135
	UNS8 data;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   136
	TPCANMsg peakMsg;
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   137
	TPCANTimestamp peakRcvTime;
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   138
	DWORD Res;
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   139
	DWORD result;
570
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   140
	// loop until valid message or fatal error
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   141
	do{
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   142
#ifdef PCAN2_HEADER_
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   143
		// if not the first handler
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   144
		if(second_board == (s_BOARD *)fd0) {
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   145
			//wait for CAN msg...
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   146
			result = WaitForSingleObject(hEvent2, INFINITE);
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   147
			if (result == WAIT_OBJECT_0)
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   148
				Res = CAN2_ReadEx(&peakMsg, &peakRcvTime);
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   149
				// Exit receive thread when handle is no more valid
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   150
				if(Res & CAN_ERRMASK_ILLHANDLE)
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   151
					return 1;
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   152
		}
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   153
		else
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   154
#endif
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   155
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   156
		// We read the queue looking for messages.
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   157
		if(first_board == (s_BOARD *)fd0) {
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   158
			result = WaitForSingleObject(hEvent1, INFINITE);
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   159
			if (result == WAIT_OBJECT_0)
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   160
			{
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   161
				Res = CAN_ReadEx(&peakMsg, &peakRcvTime);
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   162
				// Exit receive thread when handle is no more valid
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   163
				if(Res & CAN_ERRMASK_ILLHANDLE)
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   164
					return 1;
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   165
			}
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   166
		}
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   167
		else
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   168
			Res = CAN_ERR_BUSOFF;
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   169
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   170
		// A message was received : we process the message(s)
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   171
		if (Res == CAN_ERR_OK)
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   172
		{
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   173
			// if something different that 11bit or rtr... problem
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   174
			if (peakMsg.MSGTYPE & ~(MSGTYPE_STANDARD | MSGTYPE_RTR))
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   175
			{
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   176
				if (peakMsg.MSGTYPE == CAN_ERR_BUSOFF)
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   177
				{
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   178
					printf ("!!! Peak board read : re-init\n");
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   179
					canInit((s_BOARD*) fd0);
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   180
					usleep (10000);
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   181
				}
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   182
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   183
				// If status, return status if 29bit, return overrun
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   184
				return peakMsg.MSGTYPE ==
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   185
					MSGTYPE_STATUS ? peakMsg.DATA[2] : CAN_ERR_OVERRUN;
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   186
			}
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   187
			m->cob_id = peakMsg.ID;
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   188
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   189
			if (peakMsg.MSGTYPE == CAN_INIT_TYPE_ST)	/* bits of MSGTYPE_ */
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   190
				m->rtr = 0;
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   191
			else
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   192
				m->rtr = 1;
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   193
			m->len = peakMsg.LEN;	/* count of data bytes (0..8) */
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   194
			for (data = 0; data < peakMsg.LEN; data++)
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   195
				m->data[data] = peakMsg.DATA[data];	/* data bytes, up to 8 */
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   196
#if defined DEBUG_MSG_CONSOLE_ON
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   197
			MSG("in : ");
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   198
			print_message(m);
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   199
#endif
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   200
		}
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   201
		else
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   202
		{
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   203
			// not benign error => fatal error
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   204
			if (!(Res & CAN_ERR_QRCVEMPTY
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   205
					|| Res & CAN_ERR_BUSLIGHT
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   206
					|| Res & CAN_ERR_BUSHEAVY))
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   207
			{
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   208
				printf ("canReceive returned error (%d)\n", Res);
566
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   209
				return 1;
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   210
			}
570
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   211
		}
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   212
	}while(Res != CAN_ERR_OK);
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   213
	return 0;
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   214
}
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   215
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   216
/***************************************************************************/
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   217
UNS8 canSend_driver (CAN_HANDLE fd0, Message * m)
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   218
{
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   219
	UNS8 data;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   220
	TPCANMsg peakMsg;
365
9b76e0881beb Changed cob_id from struct{UNS32} to UNS16
etisserant
parents: 341
diff changeset
   221
	peakMsg.ID = m->cob_id;	/* 11/29 bit code */
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   222
	if (m->rtr == 0)
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   223
		peakMsg.MSGTYPE = CAN_INIT_TYPE_ST;	/* bits of MSGTYPE_ */
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   224
	else
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   225
	{
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   226
		peakMsg.MSGTYPE = CAN_INIT_TYPE_ST_RTR;	/* bits of MSGTYPE_ */
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   227
	}
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   228
	peakMsg.LEN = m->len;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   229
	/* count of data bytes (0..8) */
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   230
	for (data = 0; data < m->len; data++)
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   231
		peakMsg.DATA[data] = m->data[data];	/* data bytes, up to 8 */
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   232
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   233
	do
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   234
	{
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   235
#ifdef PCAN2_HEADER_
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   236
		// if not the first handler
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   237
		if(second_board == (s_BOARD *)fd0)
267
96c688ebcde7 Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents: 145
diff changeset
   238
		{
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   239
			errno = CAN2_Write (&peakMsg);
267
96c688ebcde7 Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents: 145
diff changeset
   240
		}
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   241
		else
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   242
#endif
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   243
		if(first_board == (s_BOARD *)fd0)
267
96c688ebcde7 Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents: 145
diff changeset
   244
			{
96c688ebcde7 Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents: 145
diff changeset
   245
				errno = CAN_Write (&peakMsg);
96c688ebcde7 Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents: 145
diff changeset
   246
			}
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   247
		else
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   248
			goto fail;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   249
		if (errno)
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   250
		{
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   251
			if (errno == CAN_ERR_BUSOFF)
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   252
			{
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   253
				printf ("!!! Peak board write : re-init\n");
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   254
				canInit((s_BOARD*)fd0);
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   255
				usleep (10000);
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   256
			}
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   257
			usleep (1000);
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   258
		}
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   259
	}
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   260
	while (errno != CAN_ERR_OK);
341
7ff01f109bbc Windows related enhancements
etisserant
parents: 329
diff changeset
   261
#if defined DEBUG_MSG_CONSOLE_ON
454
bc000083297a - add RTAI support
greg
parents: 384
diff changeset
   262
	MSG("out : ");
341
7ff01f109bbc Windows related enhancements
etisserant
parents: 329
diff changeset
   263
	print_message(m);
7ff01f109bbc Windows related enhancements
etisserant
parents: 329
diff changeset
   264
#endif
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   265
	return 0;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   266
fail:
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   267
	return 1;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   268
}
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   269
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   270
/***************************************************************************/
384
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 365
diff changeset
   271
UNS8 canChangeBaudRate_driver( CAN_HANDLE fd, char* baud)
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 365
diff changeset
   272
{
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 365
diff changeset
   273
	printf("canChangeBaudRate not yet supported by this driver\n");
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 365
diff changeset
   274
	return 0;
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 365
diff changeset
   275
}
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 365
diff changeset
   276
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 365
diff changeset
   277
/***************************************************************************/
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   278
CAN_HANDLE canOpen_driver (s_BOARD * board)
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   279
{
267
96c688ebcde7 Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents: 145
diff changeset
   280
  char busname[64];
96c688ebcde7 Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents: 145
diff changeset
   281
  char* pEnd;
566
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   282
  int ret;
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   283
267
96c688ebcde7 Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents: 145
diff changeset
   284
  //printf ("Board Busname=%d.\n",strtol(board->busname, &pEnd,0));
96c688ebcde7 Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents: 145
diff changeset
   285
  if (strtol(board->busname, &pEnd,0) == 0)
96c688ebcde7 Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents: 145
diff changeset
   286
  {
96c688ebcde7 Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents: 145
diff changeset
   287
      first_board = board;
566
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   288
      //printf ("First Board selected\n");
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   289
      ret = canInit(board);
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   290
      if(ret)
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   291
    	  return (CAN_HANDLE)board;
267
96c688ebcde7 Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents: 145
diff changeset
   292
  }
329
7717252e3ed9 Changes to compile for win32
greg
parents: 301
diff changeset
   293
  #ifdef PCAN2_HEADER_
267
96c688ebcde7 Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents: 145
diff changeset
   294
  if (strtol(board->busname, &pEnd,0) == 1)
96c688ebcde7 Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents: 145
diff changeset
   295
  {
329
7717252e3ed9 Changes to compile for win32
greg
parents: 301
diff changeset
   296
      second_board = board;
566
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   297
      //printf ("Second Board selected\n");
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   298
      ret = canInit(board);
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   299
      if(ret)
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   300
    	  return (CAN_HANDLE)board;
267
96c688ebcde7 Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents: 145
diff changeset
   301
  }
329
7717252e3ed9 Changes to compile for win32
greg
parents: 301
diff changeset
   302
  #endif
7717252e3ed9 Changes to compile for win32
greg
parents: 301
diff changeset
   303
  return NULL;
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   304
}
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   305
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   306
/***************************************************************************/
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   307
int canClose_driver (CAN_HANDLE fd0)
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   308
{
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   309
#ifdef PCAN2_HEADER_
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   310
	// if not the first handler
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   311
	if(second_board == (s_BOARD *)fd0)
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   312
	{
570
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   313
		CAN2_SetRcvEvent(NULL);
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   314
		CAN2_Close ();
566
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   315
		SetEvent(hEvent2);
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   316
		second_board = (s_BOARD *)NULL;
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   317
	}else
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   318
#endif
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   319
	if(first_board == (s_BOARD *)fd0)
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   320
	{
570
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   321
		CAN_SetRcvEvent(NULL);
c18397a2b035 fix method to exit properly CanReceiveLoop
greg
parents: 566
diff changeset
   322
		CAN_Close ();
566
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   323
		SetEvent(hEvent1);
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   324
		first_board = (s_BOARD *)NULL;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   325
	}
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   326
	return 0;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   327
}