Some more reasonable timeout while waiting timer thread end
authoredouard@expresso
Tue, 06 Oct 2009 17:22:11 +0200
changeset 602 cbf29cccec18
parent 601 efb6e88ad27f (diff)
parent 600 7767029937aa (current diff)
child 603 4dc76e662412
Some more reasonable timeout while waiting timer thread end
drivers/timers_win32/timers_win32.c
Binary file doc/CANOpen_memento/CANOpen_memento.odg has changed
Binary file doc/CANOpen_memento/CANOpen_memento.pdf has changed
--- a/drivers/AVR/can_AVR.c	Fri Sep 25 14:12:39 2009 +0200
+++ b/drivers/AVR/can_AVR.c	Tue Oct 06 17:22:11 2009 +0200
@@ -174,6 +174,7 @@
 CAN Interrupt
 ******************************************************************************/
 {
+  unsigned char saved_page = CANPAGE;
   unsigned char i;
 
   if (CANGIT & (1 << CANIT))	// is a messagebox interrupt
@@ -211,6 +212,8 @@
     }
   }
 
+  CANPAGE = saved_page;
+
   // Bus Off Interrupt Flag
   if (CANGIT & (1 << BOFFIT))    // Finaly clear the interrupt status register
   {
--- a/drivers/can_peak_win32/can_peak_win32.c	Fri Sep 25 14:12:39 2009 +0200
+++ b/drivers/can_peak_win32/can_peak_win32.c	Tue Oct 06 17:22:11 2009 +0200
@@ -217,6 +217,7 @@
 UNS8 canSend_driver (CAN_HANDLE fd0, Message * m)
 {
 	UNS8 data;
+	DWORD localerrno;
 	TPCANMsg peakMsg;
 	peakMsg.ID = m->cob_id;	/* 11/29 bit code */
 	if (m->rtr == 0)
@@ -236,19 +237,19 @@
 		// if not the first handler
 		if(second_board == (s_BOARD *)fd0)
 		{
-			errno = CAN2_Write (&peakMsg);
+			errno = localerrno = CAN2_Write (&peakMsg);
 		}
 		else
 #endif
 		if(first_board == (s_BOARD *)fd0)
 			{
-				errno = CAN_Write (&peakMsg);
+				errno = localerrno = CAN_Write (&peakMsg);
 			}
 		else
 			goto fail;
-		if (errno)
-		{
-			if (errno == CAN_ERR_BUSOFF)
+		if (localerrno)
+		{
+			if (localerrno == CAN_ERR_BUSOFF)
 			{
 				printf ("!!! Peak board write : re-init\n");
 				canInit((s_BOARD*)fd0);
@@ -257,7 +258,7 @@
 			usleep (1000);
 		}
 	}
-	while (errno != CAN_ERR_OK);
+	while (localerrno != CAN_ERR_OK);
 #if defined DEBUG_MSG_CONSOLE_ON
 	MSG("out : ");
 	print_message(m);
--- a/drivers/can_socket/can_socket.c	Fri Sep 25 14:12:39 2009 +0200
+++ b/drivers/can_socket/can_socket.c	Tue Oct 06 17:22:11 2009 +0200
@@ -37,6 +37,7 @@
 #define CAN_SEND       rt_dev_send
 #define CAN_BIND       rt_dev_bind
 #define CAN_IOCTL      rt_dev_ioctl
+#define CAN_SETSOCKOPT rt_dev_setsockopt
 #define CAN_ERRNO(err) (-err)
 #else
 #include <sys/socket.h>
@@ -55,6 +56,7 @@
 #define CAN_BIND       bind
 #define CAN_IOCTL      ioctl
 #define CAN_ERRNO(err) errno
+#define CAN_SETSOCKOPT setsockopt
 #endif
 
 #include "can_driver.h"
@@ -194,16 +196,25 @@
   
   {
     int loopback = 1;
-    setsockopt(*(int *)fd0, SOL_CAN_RAW, CAN_RAW_LOOPBACK,
+    err = CAN_SETSOCKOPT(*(int *)fd0, SOL_CAN_RAW, CAN_RAW_LOOPBACK,
                &loopback, sizeof(loopback));
+    if (err) {
+        fprintf(stderr, "rt_dev_setsockopt: %s\n", strerror (CAN_ERRNO (err)));
+        goto failure;
+    }
   }
   
+#ifndef RTCAN_SOCKET /*CAN_RAW_RECV_OWN_MSGS not supported in rtsocketcan*/
   {
     int recv_own_msgs = 0; /* 0 = disabled (default), 1 = enabled */
-
-    setsockopt(*(int *)fd0, SOL_CAN_RAW, CAN_RAW_RECV_OWN_MSGS,
+    err = CAN_SETSOCKOPT(*(int *)fd0, SOL_CAN_RAW, CAN_RAW_RECV_OWN_MSGS,
                &recv_own_msgs, sizeof(recv_own_msgs));
+    if (err) {
+        fprintf(stderr, "rt_dev_setsockopt: %s\n", strerror (CAN_ERRNO (err)));
+        goto failure;
+    }
   }
+#endif
   
   addr.can_family = AF_CAN;
   addr.can_ifindex = ifr.ifr_ifindex;
--- a/drivers/timers_win32/timers_win32.c	Fri Sep 25 14:12:39 2009 +0200
+++ b/drivers/timers_win32/timers_win32.c	Tue Oct 06 17:22:11 2009 +0200
@@ -127,7 +127,10 @@
 
 	stop_timer = 1;
 	setTimer(0);
-	WaitForSingleObject(timer_thread, INFINITE);
+	if(WaitForSingleObject(timer_thread,1000) == WAIT_TIMEOUT)
+	{
+		TerminateThread(timer_thread, -1);
+	}
 	CloseHandle(timer);
 	CloseHandle(timer_thread);
 }
--- a/examples/CANOpenShell/CANOpenShell.vcproj	Fri Sep 25 14:12:39 2009 +0200
+++ b/examples/CANOpenShell/CANOpenShell.vcproj	Tue Oct 06 17:22:11 2009 +0200
@@ -42,7 +42,7 @@
 				Name="VCCLCompilerTool"
 				Optimization="0"
 				AdditionalIncludeDirectories="..\..\include;..\..\include\win32"
-				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS"
 				MinimalRebuild="true"
 				BasicRuntimeChecks="3"
 				RuntimeLibrary="3"
@@ -61,7 +61,7 @@
 			/>
 			<Tool
 				Name="VCLinkerTool"
-				AdditionalDependencies="&quot;..\..\lib\static\libcanfestival.lib&quot; &quot;..\..\lib\static\libcanfestival_win32.lib&quot; &quot;..\..\lib\static\libgcc.lib&quot;"
+				AdditionalDependencies="&quot;..\..\lib\static\libcanfestival.lib&quot; &quot;..\..\lib\static\libcanfestival_win32.lib&quot;"
 				LinkIncremental="2"
 				GenerateDebugInformation="false"
 				SubSystem="1"
--- a/src/nmtMaster.c	Fri Sep 25 14:12:39 2009 +0200
+++ b/src/nmtMaster.c	Tue Oct 06 17:22:11 2009 +0200
@@ -76,7 +76,7 @@
   UNS16 tmp = nodeId | (NODE_GUARD << 7); 
   m.cob_id = UNS16_LE(tmp);
   m.rtr = REQUEST;
-  m.len = 1;
+  m.len = 0;
 
   MSG_WAR(0x3503, "Send_NODE_GUARD to node : ", nodeId);
 
--- a/src/sdo.c	Fri Sep 25 14:12:39 2009 +0200
+++ b/src/sdo.c	Tue Oct 06 17:22:11 2009 +0200
@@ -551,7 +551,7 @@
     pwCobId = (UNS32*) d->objdict[offset].pSubindex[1].pObject;
   }
   /* message copy for sending */
-  m.cob_id = (UNS8)UNS16_LE(*pwCobId);
+  m.cob_id = (UNS16)UNS16_LE(*pwCobId);
   m.rtr = NOT_A_REQUEST;
   /* the length of SDO must be 8 */
   m.len = 8;