drivers/win32/win32.c
author laurent
Wed, 16 Jun 2010 21:28:34 +0200
changeset 622 f0935accb93b
parent 600 7767029937aa
child 629 b9274b595650
permissions -rwxr-xr-x
Bug in Subindex grid right click with i18n fixed
556
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
     1
/*
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
     2
This file is part of CanFestival, a library implementing CanOpen Stack.
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
     3
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
     4
Copyright (C): Edouard TISSERANT and Francis DUPIN
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
     5
Copyright (C) Win32 Port Leonid Tochinski
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
     6
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
     7
See COPYING file for copyrights details.
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
     8
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
     9
This library is free software; you can redistribute it and/or
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    10
modify it under the terms of the GNU Lesser General Public
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    11
License as published by the Free Software Foundation; either
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    12
version 2.1 of the License, or (at your option) any later version.
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    13
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    14
This library is distributed in the hope that it will be useful,
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    15
but WITHOUT ANY WARRANTY; without even the implied warranty of
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    17
Lesser General Public License for more details.
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    18
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    19
You should have received a copy of the GNU Lesser General Public
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    20
License along with this library; if not, write to the Free Software
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    21
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    22
*/
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    23
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    24
/*
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    25
 CAN driver interface.
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    26
*/
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    27
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    28
#include <windows.h>
591
513f5ec8b628 add extern C to maintain compatibility with C++
greg
parents: 577
diff changeset
    29
513f5ec8b628 add extern C to maintain compatibility with C++
greg
parents: 577
diff changeset
    30
#ifdef __cplusplus
513f5ec8b628 add extern C to maintain compatibility with C++
greg
parents: 577
diff changeset
    31
extern "C" {
513f5ec8b628 add extern C to maintain compatibility with C++
greg
parents: 577
diff changeset
    32
#endif
513f5ec8b628 add extern C to maintain compatibility with C++
greg
parents: 577
diff changeset
    33
556
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    34
#include "canfestival.h"
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    35
#include "timer.h"
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    36
#include "timers_driver.h"
591
513f5ec8b628 add extern C to maintain compatibility with C++
greg
parents: 577
diff changeset
    37
513f5ec8b628 add extern C to maintain compatibility with C++
greg
parents: 577
diff changeset
    38
#ifdef __cplusplus
577
0bb82be64630 add extern \"C\" to keep compatibilty with C++
greg
parents: 556
diff changeset
    39
};
591
513f5ec8b628 add extern C to maintain compatibility with C++
greg
parents: 577
diff changeset
    40
#endif
513f5ec8b628 add extern C to maintain compatibility with C++
greg
parents: 577
diff changeset
    41
556
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    42
// GetProcAddress doesn't have an UNICODE version for NT
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    43
#ifdef UNDER_CE
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    44
  #define myTEXT(str) TEXT(str)
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    45
#else
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    46
  #define myTEXT(str) str
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    47
#endif
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    48
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    49
#define MAX_NB_CAN_PORTS 16
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    50
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    51
typedef UNS8 (CALLBACK* CANRECEIVE_DRIVER_PROC)(void* inst, Message *m);
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    52
typedef UNS8 (CALLBACK* CANSEND_DRIVER_PROC)(void* inst, const Message *m);
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    53
typedef void* (CALLBACK* CANOPEN_DRIVER_PROC)(s_BOARD *board);
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    54
typedef int (CALLBACK* CANCLOSE_DRIVER_PROC)(void* inst);
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    55
typedef UNS8 (CALLBACK* CANCHANGEBAUDRATE_DRIVER_PROC)(void* fd, char* baud);
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    56
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    57
CANRECEIVE_DRIVER_PROC m_canReceive;
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    58
CANSEND_DRIVER_PROC m_canSend;
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    59
CANOPEN_DRIVER_PROC m_canOpen;
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    60
CANCLOSE_DRIVER_PROC m_canClose;
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    61
CANCHANGEBAUDRATE_DRIVER_PROC m_canChangeBaudRate;
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    62
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    63
/* CAN port structure */
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    64
typedef struct
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    65
{
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    66
  char used;  /**< flag indicating CAN port usage, will be used to abort Receiver task*/
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    67
  CAN_HANDLE fd; /**< CAN port file descriptor*/
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    68
  TASK_HANDLE receiveTask; /**< CAN Receiver task*/
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    69
  CO_Data* d; /**< CAN object data*/
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    70
}CANPort;
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    71
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    72
CANPort canports[MAX_NB_CAN_PORTS] = {{0,},{0,},{0,},{0,},{0,},{0,},{0,},{0,},{0,},{0,},{0,},{0,},{0,},{0,},{0,},{0,}};
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    73
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    74
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    75
/***************************************************************************/
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    76
UNS8 UnLoadCanDriver(LIB_HANDLE handle)
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    77
{
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    78
	if(handle != NULL)
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    79
	{
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    80
		FreeLibrary(handle);
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    81
		handle=NULL;
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    82
		return 0;
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    83
	}
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    84
	return -1;
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    85
}
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    86
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    87
/***************************************************************************/
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    88
/**
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    89
 * Loads the dll and get funcs ptr
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    90
 *
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    91
 * @param driver_name String containing driver's dynamic library name
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    92
 * @return Library handle
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    93
 */
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    94
LIB_HANDLE LoadCanDriver(LPCTSTR driver_name)
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    95
{
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    96
	// driver module handle
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    97
	LIB_HANDLE handle = NULL;
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    98
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
    99
	if(handle == NULL)
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   100
	{
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   101
		handle = LoadLibrary(driver_name);
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   102
	}
577
0bb82be64630 add extern \"C\" to keep compatibilty with C++
greg
parents: 556
diff changeset
   103
0bb82be64630 add extern \"C\" to keep compatibilty with C++
greg
parents: 556
diff changeset
   104
	if (!handle)
556
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   105
	{
600
7767029937aa add timeout for waitreceivetaskend for the win32, fix GetLastError print
'Gr?gory Tr?lat <gregory.trelat@lolitech.fr>'
parents: 591
diff changeset
   106
		fprintf (stderr, "%d\n", GetLastError());
556
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   107
    	return NULL;
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   108
	}
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   109
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   110
	m_canReceive = (CANRECEIVE_DRIVER_PROC)GetProcAddress(handle, myTEXT("canReceive_driver"));
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   111
	m_canSend = (CANSEND_DRIVER_PROC)GetProcAddress(handle, myTEXT("canSend_driver"));
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   112
	m_canOpen = (CANOPEN_DRIVER_PROC)GetProcAddress(handle, myTEXT("canOpen_driver"));
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   113
	m_canClose = (CANCLOSE_DRIVER_PROC)GetProcAddress(handle, myTEXT("canClose_driver"));
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   114
	m_canChangeBaudRate = (CANCHANGEBAUDRATE_DRIVER_PROC)GetProcAddress(handle, myTEXT("canChangeBaudRate_driver"));
577
0bb82be64630 add extern \"C\" to keep compatibilty with C++
greg
parents: 556
diff changeset
   115
556
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   116
	return handle;
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   117
}
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   118
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   119
/***************************************************************************/
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   120
UNS8 canSend(CAN_PORT port, Message *m)
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   121
{
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   122
	UNS8 res;
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   123
	if (port && (m_canSend != NULL))
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   124
	{
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   125
		res = m_canSend(((CANPort*)port)->fd, m);
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   126
		if (res) return 1; // OK
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   127
	}
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   128
	return 0; // NOT OK
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   129
}
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   130
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   131
/***************************************************************************/
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   132
void canReceiveLoop(CAN_PORT port)
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   133
{
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   134
	Message m;
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   135
	while(((CANPort*)port)->used)
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   136
	{
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   137
		if(m_canReceive(((CANPort*)port)->fd, &m) != 0) break;
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   138
		EnterMutex();
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   139
		canDispatch(((CANPort*)port)->d, &m);
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   140
		LeaveMutex();
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   141
	}
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   142
}
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   143
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   144
/***************************************************************************/
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   145
CAN_HANDLE canOpen(s_BOARD *board, CO_Data * d)
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   146
{
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   147
	int i;
591
513f5ec8b628 add extern C to maintain compatibility with C++
greg
parents: 577
diff changeset
   148
    CAN_HANDLE fd0;
513f5ec8b628 add extern C to maintain compatibility with C++
greg
parents: 577
diff changeset
   149
556
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   150
	for(i=0; i < MAX_NB_CAN_PORTS; i++)
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   151
	{
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   152
		if(!canports[i].used)
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   153
		break;
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   154
	}
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   155
577
0bb82be64630 add extern \"C\" to keep compatibilty with C++
greg
parents: 556
diff changeset
   156
	#ifndef NOT_USE_DYNAMIC_LOADING
556
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   157
	if (m_canOpen == NULL)
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   158
	{
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   159
	   	fprintf(stderr,"CanOpen : Can Driver dll not loaded\n");
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   160
	   	return NULL;
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   161
	}
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   162
	#endif
577
0bb82be64630 add extern \"C\" to keep compatibilty with C++
greg
parents: 556
diff changeset
   163
591
513f5ec8b628 add extern C to maintain compatibility with C++
greg
parents: 577
diff changeset
   164
	fd0 = m_canOpen(board);
556
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   165
	if(fd0)
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   166
	{
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   167
		canports[i].used = 1;
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   168
		canports[i].fd = fd0;
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   169
		canports[i].d = d;
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   170
		d->canHandle = (CAN_PORT)&canports[i];
577
0bb82be64630 add extern \"C\" to keep compatibilty with C++
greg
parents: 556
diff changeset
   171
		CreateReceiveTask(&(canports[i]), &canports[i].receiveTask, (void *)canReceiveLoop);
556
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   172
		return (CAN_PORT)&canports[i];
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   173
	}
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   174
	else
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   175
	{
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   176
		MSG("CanOpen : Cannot open board {busname='%s',baudrate='%s'}\n",board->busname, board->baudrate);
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   177
		return NULL;
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   178
	}
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   179
}
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   180
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   181
/***************************************************************************/
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   182
int canClose(CO_Data * d)
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   183
{
600
7767029937aa add timeout for waitreceivetaskend for the win32, fix GetLastError print
'Gr?gory Tr?lat <gregory.trelat@lolitech.fr>'
parents: 591
diff changeset
   184
	UNS8 res = 1;
591
513f5ec8b628 add extern C to maintain compatibility with C++
greg
parents: 577
diff changeset
   185
	CANPort* tmp;
513f5ec8b628 add extern C to maintain compatibility with C++
greg
parents: 577
diff changeset
   186
513f5ec8b628 add extern C to maintain compatibility with C++
greg
parents: 577
diff changeset
   187
	if((CANPort*)d->canHandle)
513f5ec8b628 add extern C to maintain compatibility with C++
greg
parents: 577
diff changeset
   188
	{
513f5ec8b628 add extern C to maintain compatibility with C++
greg
parents: 577
diff changeset
   189
	  ((CANPort*)d->canHandle)->used = 0;
513f5ec8b628 add extern C to maintain compatibility with C++
greg
parents: 577
diff changeset
   190
	}
513f5ec8b628 add extern C to maintain compatibility with C++
greg
parents: 577
diff changeset
   191
513f5ec8b628 add extern C to maintain compatibility with C++
greg
parents: 577
diff changeset
   192
	tmp = (CANPort*)d->canHandle;
556
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   193
	d->canHandle = NULL;
577
0bb82be64630 add extern \"C\" to keep compatibilty with C++
greg
parents: 556
diff changeset
   194
591
513f5ec8b628 add extern C to maintain compatibility with C++
greg
parents: 577
diff changeset
   195
	if(tmp)
513f5ec8b628 add extern C to maintain compatibility with C++
greg
parents: 577
diff changeset
   196
	{
513f5ec8b628 add extern C to maintain compatibility with C++
greg
parents: 577
diff changeset
   197
	  // close CAN port
513f5ec8b628 add extern C to maintain compatibility with C++
greg
parents: 577
diff changeset
   198
	  res = m_canClose(tmp->fd);
513f5ec8b628 add extern C to maintain compatibility with C++
greg
parents: 577
diff changeset
   199
513f5ec8b628 add extern C to maintain compatibility with C++
greg
parents: 577
diff changeset
   200
	  // kill receiver task
513f5ec8b628 add extern C to maintain compatibility with C++
greg
parents: 577
diff changeset
   201
	  WaitReceiveTaskEnd(&tmp->receiveTask);
513f5ec8b628 add extern C to maintain compatibility with C++
greg
parents: 577
diff changeset
   202
	}
556
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   203
	return res;
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   204
}
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   205
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   206
UNS8 canChangeBaudRate(CAN_PORT port, char* baud)
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   207
{
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   208
   if(port){
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   209
		UNS8 res;
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   210
	    //LeaveMutex();
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   211
		res = m_canChangeBaudRate(((CANPort*)port)->fd, baud);
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   212
		//EnterMutex();
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   213
		return res; // OK
577
0bb82be64630 add extern \"C\" to keep compatibilty with C++
greg
parents: 556
diff changeset
   214
	}
556
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   215
	return 1; // NOT OK
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   216
}
8296acd119a9 Rewrite win32 code (C only)
greg
parents:
diff changeset
   217