equal
deleted
inserted
replaced
67 }; |
67 }; |
68 IXXAT(s_BOARD *board); |
68 IXXAT(s_BOARD *board); |
69 ~IXXAT(); |
69 ~IXXAT(); |
70 bool send(const Message *m); |
70 bool send(const Message *m); |
71 bool receive(Message *m); |
71 bool receive(Message *m); |
|
72 |
|
73 static bool isDriverClosed() {return m_driverClosed;} |
72 private: |
74 private: |
73 bool open(int board_number, const char* baud_rate); |
75 bool open(int board_number, const char* baud_rate); |
74 bool close(); |
76 bool close(); |
75 void receive_queuedata(UINT16 que_hdl, UINT16 count, VCI_CAN_OBJ* p_obj); |
77 void receive_queuedata(UINT16 que_hdl, UINT16 count, VCI_CAN_OBJ* p_obj); |
76 // VCI2 handler |
78 // VCI2 handler |
84 UINT16 m_BoardHdl; |
86 UINT16 m_BoardHdl; |
85 UINT16 m_TxQueHdl; |
87 UINT16 m_TxQueHdl; |
86 UINT16 m_RxQueHdl; |
88 UINT16 m_RxQueHdl; |
87 async_access_que<VCI_CAN_OBJ> m_RX_Que; |
89 async_access_que<VCI_CAN_OBJ> m_RX_Que; |
88 static IXXAT* m_callbackPtr; |
90 static IXXAT* m_callbackPtr; |
|
91 |
|
92 static bool m_driverClosed; |
89 static UINT_PTR m_watchdogTimerId; |
93 static UINT_PTR m_watchdogTimerId; |
90 static const unsigned int CAN_BUS_WATCHDOG_INTERVAL_MSEC = 10000; |
94 static const unsigned int CAN_BUS_WATCHDOG_INTERVAL_MSEC = 10000; |
91 |
95 |
92 /** Bitmask inside sts from VCI_ReadCanStatus() that defines the can bus off state.*/ |
96 /** Bitmask inside sts from VCI_ReadCanStatus() that defines the can bus off state.*/ |
93 static const unsigned char STS_CAN_BUS_OFF = 0x80; |
97 static const unsigned char STS_CAN_BUS_OFF = 0x80; |
100 }; |
104 }; |
101 |
105 |
102 IXXAT *IXXAT::m_callbackPtr = NULL; |
106 IXXAT *IXXAT::m_callbackPtr = NULL; |
103 |
107 |
104 UINT_PTR IXXAT::m_watchdogTimerId = 0; |
108 UINT_PTR IXXAT::m_watchdogTimerId = 0; |
|
109 |
|
110 bool IXXAT::m_driverClosed = false; |
105 |
111 |
106 IXXAT::IXXAT(s_BOARD *board) : m_BoardHdl(0xFFFF), |
112 IXXAT::IXXAT(s_BOARD *board) : m_BoardHdl(0xFFFF), |
107 m_TxQueHdl(0xFFFF), |
113 m_TxQueHdl(0xFFFF), |
108 m_RxQueHdl(0xFFFF) |
114 m_RxQueHdl(0xFFFF) |
109 |
115 |
242 res = VCI_StartCan(m_BoardHdl, CAN_NUM); |
248 res = VCI_StartCan(m_BoardHdl, CAN_NUM); |
243 |
249 |
244 //Start CAN Bus-Off watchdog |
250 //Start CAN Bus-Off watchdog |
245 m_watchdogTimerId = SetTimer(NULL, NULL, IXXAT::CAN_BUS_WATCHDOG_INTERVAL_MSEC, IXXAT::canBusWatchdog); |
251 m_watchdogTimerId = SetTimer(NULL, NULL, IXXAT::CAN_BUS_WATCHDOG_INTERVAL_MSEC, IXXAT::canBusWatchdog); |
246 |
252 |
|
253 m_driverClosed = false; |
|
254 |
247 return true; |
255 return true; |
248 } |
256 } |
249 |
257 |
250 bool IXXAT::close() |
258 bool IXXAT::close() |
251 { |
259 { |
|
260 m_driverClosed = true; |
252 if (m_BoardHdl == 0xFFFF) |
261 if (m_BoardHdl == 0xFFFF) |
253 return true; |
262 return true; |
254 VCI_ResetBoard(m_BoardHdl); |
263 VCI_ResetBoard(m_BoardHdl); |
255 VCI_CancelBoard(m_BoardHdl); |
264 VCI_CancelBoard(m_BoardHdl); |
256 m_BoardHdl = |
265 m_BoardHdl = |
367 |
376 |
368 //------------------------------------------------------------------------ |
377 //------------------------------------------------------------------------ |
369 extern "C" |
378 extern "C" |
370 UNS8 __stdcall canReceive_driver(CAN_HANDLE inst, Message *m) |
379 UNS8 __stdcall canReceive_driver(CAN_HANDLE inst, Message *m) |
371 { |
380 { |
|
381 if (IXXAT::isDriverClosed()) return 0; |
372 return reinterpret_cast<IXXAT*>(inst)->receive(m) ? 0 : 1; |
382 return reinterpret_cast<IXXAT*>(inst)->receive(m) ? 0 : 1; |
373 } |
383 } |
374 |
384 |
375 extern "C" |
385 extern "C" |
376 UNS8 __stdcall canSend_driver(CAN_HANDLE inst, Message const *m) |
386 UNS8 __stdcall canSend_driver(CAN_HANDLE inst, Message const *m) |
377 { |
387 { |
|
388 if (IXXAT::isDriverClosed()) return 0; |
378 return reinterpret_cast<IXXAT*>(inst)->send(m) ? 0 : 1; |
389 return reinterpret_cast<IXXAT*>(inst)->send(m) ? 0 : 1; |
379 } |
390 } |
380 |
391 |
381 extern "C" |
392 extern "C" |
382 CAN_HANDLE __stdcall canOpen_driver(s_BOARD *board) |
393 CAN_HANDLE __stdcall canOpen_driver(s_BOARD *board) |