author | lbessard |
Mon, 24 Sep 2007 09:37:04 +0200 | |
changeset 280 | d9b232ec7057 |
parent 267 | 96c688ebcde7 |
child 480 | d0d76932ad74 |
permissions | -rwxr-xr-x |
267
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
1 |
/* |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
2 |
This file is part of CanFestival, a library implementing CanOpen Stack. |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
3 |
|
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
4 |
Copyright (C): Edouard TISSERANT and Francis DUPIN |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
5 |
Copyright (C) Win32 Port Leonid Tochinski |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
6 |
|
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
7 |
See COPYING file for copyrights details. |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
8 |
|
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
9 |
This library is free software; you can redistribute it and/or |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
10 |
modify it under the terms of the GNU Lesser General Public |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
11 |
License as published by the Free Software Foundation; either |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
12 |
version 2.1 of the License, or (at your option) any later version. |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
13 |
|
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
14 |
This library is distributed in the hope that it will be useful, |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
15 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
16 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
17 |
Lesser General Public License for more details. |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
18 |
|
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
19 |
You should have received a copy of the GNU Lesser General Public |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
20 |
License along with this library; if not, write to the Free Software |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
21 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
22 |
*/ |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
23 |
|
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
24 |
/* |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
25 |
CAN driver interface. |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
26 |
*/ |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
27 |
|
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
28 |
#include <windows.h> |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
29 |
|
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
30 |
extern "C" |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
31 |
{ |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
32 |
#define DLL_CALL(funcname) (*_##funcname) |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
33 |
#define FCT_PTR_INIT =NULL |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
34 |
#include "canfestival.h" |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
35 |
#include "timer.h" |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
36 |
|
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
37 |
#include "timers_driver.h" |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
38 |
}; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
39 |
|
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
40 |
typedef UNS8 (*CANRECEIVE_DRIVER_PROC)(void* inst, Message *m); |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
41 |
typedef UNS8 (*CANSEND_DRIVER_PROC)(void* inst, const Message *m); |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
42 |
typedef void* (*CANOPEN_DRIVER_PROC)(s_BOARD *board); |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
43 |
typedef int (*CANCLOSE_DRIVER_PROC)(void* inst); |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
44 |
|
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
45 |
|
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
46 |
class driver_procs |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
47 |
{ |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
48 |
public: |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
49 |
driver_procs(); |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
50 |
~driver_procs(); |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
51 |
|
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
52 |
HMODULE load_canfestival_driver(LPCTSTR driver_name); |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
53 |
bool can_driver_valid() const; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
54 |
|
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
55 |
public: |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
56 |
// can driver |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
57 |
CANRECEIVE_DRIVER_PROC m_canReceive; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
58 |
CANSEND_DRIVER_PROC m_canSend; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
59 |
CANOPEN_DRIVER_PROC m_canOpen; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
60 |
CANCLOSE_DRIVER_PROC m_canClose; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
61 |
|
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
62 |
// driver module habndle |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
63 |
HMODULE m_driver_handle; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
64 |
}; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
65 |
|
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
66 |
driver_procs::driver_procs() : m_canReceive(0), |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
67 |
m_canSend(0), |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
68 |
m_canOpen(0), |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
69 |
m_canClose(0), |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
70 |
m_driver_handle(0) |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
71 |
{} |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
72 |
|
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
73 |
driver_procs::~driver_procs() |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
74 |
{ |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
75 |
if (m_driver_handle) |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
76 |
::FreeLibrary(m_driver_handle); |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
77 |
} |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
78 |
|
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
79 |
bool driver_procs::can_driver_valid() const |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
80 |
{ |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
81 |
return ((m_canReceive != NULL) && |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
82 |
(m_canSend != NULL) && |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
83 |
(m_canOpen != NULL) && |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
84 |
(m_canClose != NULL)); |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
85 |
} |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
86 |
|
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
87 |
// GetProcAddress doesn't have an UNICODE version for NT |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
88 |
#ifdef UNDER_CE |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
89 |
#define myTEXT(str) TEXT(str) |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
90 |
#else |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
91 |
#define myTEXT(str) str |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
92 |
#endif |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
93 |
|
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
94 |
HMODULE driver_procs::load_canfestival_driver(LPCTSTR driver_name) |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
95 |
{ |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
96 |
//LPCTSTR driver1 = "C:\\msys\\1.0\\home\\Ontaide\\can\\CanFestival-3\\drivers\\can_peak_win32\\cygcan_peak_win32.dll"; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
97 |
//LPCTSTR driver2 = "C:\\msys\\1.0\\home\\Ontaide\\can\\CanFestival-3\\drivers\\can_peak_win32\\cygcan_peak_win32.dll"; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
98 |
//printf("can_driver_valid=%d\n",can_driver_valid()); |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
99 |
if (can_driver_valid()) |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
100 |
return m_driver_handle; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
101 |
printf("driver_name=%s\n",driver_name); |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
102 |
m_driver_handle = ::LoadLibrary(driver_name); |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
103 |
//printf("m_driver_handle=%d\n",m_driver_handle); |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
104 |
//printf("testerror =%s\n",GetLastError()); |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
105 |
if (m_driver_handle == NULL) |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
106 |
return NULL; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
107 |
|
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
108 |
m_canReceive = (CANRECEIVE_DRIVER_PROC)::GetProcAddress(m_driver_handle, myTEXT("canReceive_driver")); |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
109 |
m_canSend = (CANSEND_DRIVER_PROC)::GetProcAddress(m_driver_handle, myTEXT("canSend_driver")); |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
110 |
m_canOpen = (CANOPEN_DRIVER_PROC)::GetProcAddress(m_driver_handle, myTEXT("canOpen_driver")); |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
111 |
m_canClose = (CANCLOSE_DRIVER_PROC)::GetProcAddress(m_driver_handle, myTEXT("canClose_driver")); |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
112 |
return can_driver_valid()?m_driver_handle:NULL; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
113 |
} |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
114 |
|
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
115 |
struct driver_data |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
116 |
{ |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
117 |
CO_Data * d; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
118 |
HANDLE receive_thread; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
119 |
void* inst; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
120 |
volatile bool continue_receive_thread; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
121 |
}; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
122 |
|
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
123 |
driver_procs s_driver_procs; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
124 |
|
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
125 |
LIB_HANDLE LoadCanDriver(char* driver_name) |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
126 |
{ |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
127 |
return s_driver_procs.load_canfestival_driver((LPCTSTR)driver_name); |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
128 |
} |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
129 |
|
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
130 |
UNS8 canReceive(CAN_PORT fd0, Message *m) |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
131 |
{ |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
132 |
|
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
133 |
if (fd0 != NULL && s_driver_procs.m_canReceive != NULL) |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
134 |
{ |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
135 |
driver_data* data = (driver_data*)fd0; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
136 |
return (*s_driver_procs.m_canReceive)(data->inst, m); |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
137 |
} |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
138 |
return 1; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
139 |
} |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
140 |
|
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
141 |
void* canReceiveLoop(CAN_PORT fd0) |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
142 |
{ |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
143 |
driver_data* data = (driver_data*)fd0; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
144 |
Message m; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
145 |
while (data->continue_receive_thread) |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
146 |
{ |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
147 |
if (!canReceive(fd0, &m)) |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
148 |
{ |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
149 |
EnterMutex(); |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
150 |
canDispatch(data->d, &m); |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
151 |
LeaveMutex(); |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
152 |
} |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
153 |
else |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
154 |
{ |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
155 |
break; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
156 |
::Sleep(1); |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
157 |
} |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
158 |
} |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
159 |
return 0; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
160 |
} |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
161 |
|
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
162 |
/***************************************************************************/ |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
163 |
UNS8 canSend(CAN_PORT fd0, Message *m) |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
164 |
{ |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
165 |
if (fd0 != NULL && s_driver_procs.m_canSend != NULL) |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
166 |
{ |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
167 |
UNS8 res; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
168 |
driver_data* data = (driver_data*)fd0; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
169 |
res = (*s_driver_procs.m_canSend)(data->inst, m); |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
170 |
if (res) |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
171 |
return 1; // OK |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
172 |
} |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
173 |
return 0; // NOT OK |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
174 |
} |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
175 |
|
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
176 |
/***************************************************************************/ |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
177 |
CAN_HANDLE canOpen(s_BOARD *board, CO_Data * d) |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
178 |
{ |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
179 |
if (board != NULL && s_driver_procs.m_canOpen != NULL) |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
180 |
{ |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
181 |
void* inst = (*s_driver_procs.m_canOpen)(board); |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
182 |
if (inst != NULL) |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
183 |
{ |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
184 |
driver_data* data = new driver_data; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
185 |
data->d = d; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
186 |
data->inst = inst; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
187 |
data->continue_receive_thread = true; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
188 |
CreateReceiveTask(data, &data->receive_thread, (void*)&canReceiveLoop); |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
189 |
EnterMutex(); |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
190 |
d->canHandle = data; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
191 |
LeaveMutex(); |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
192 |
return data; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
193 |
} |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
194 |
} |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
195 |
return NULL; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
196 |
} |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
197 |
|
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
198 |
/***************************************************************************/ |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
199 |
int canClose(CO_Data * d) |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
200 |
{ |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
201 |
if (s_driver_procs.m_canClose != NULL) |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
202 |
{ |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
203 |
driver_data* data; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
204 |
EnterMutex(); |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
205 |
if(d->canHandle != NULL){ |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
206 |
data = (driver_data*)d->canHandle; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
207 |
d->canHandle = NULL; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
208 |
data->continue_receive_thread = false;} |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
209 |
LeaveMutex(); |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
210 |
WaitReceiveTaskEnd(&data->receive_thread); |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
211 |
(*s_driver_procs.m_canClose)(data->inst); |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
212 |
delete data; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
213 |
return 0; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
214 |
} |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
215 |
return 0; |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
216 |
} |
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
217 |
|
96c688ebcde7
Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents:
diff
changeset
|
218 |