Beispiel #1
0
//--------------------------------------------------------------------------
// Reset all of the devices on the 1-Wire Net and return the result.
//
// 'portnum'     - number 0 to MAX_PORTNUM-1.  This number is provided to
//                 indicate the symbolic port number.
//
// Returns: TRUE(1):  presense pulse(s) detected, device(s) reset
//          FALSE(0): no presense pulses detected
//
SMALLINT owTouchResetUSB(int portnum)
{
   SETUP_PACKET setup;
   SMALLINT present,vpp;
   SMALLINT ret = 0;

   // make sure strong pullup is not on
   if (USBLevel[portnum] == MODE_STRONG5)
      owLevelUSB(portnum, MODE_NORMAL);

   // construct command
   setup.RequestTypeReservedBits = 0x40;
   setup.Request = COMM_CMD;
   setup.Value = COMM_1_WIRE_RESET | COMM_F | COMM_IM | COMM_SE;
   setup.Index = (USBSpeed[portnum] == MODE_OVERDRIVE) ?
                  ONEWIREBUSSPEED_OVERDRIVE : ONEWIREBUSSPEED_FLEXIBLE;
   setup.Length = 0;
   setup.DataOut = FALSE;
   // call the libusb driver
   ret = usb_control_msg(usb_dev_handle_list[portnum], 
                         setup.RequestTypeReservedBits, 
			 setup.Request, 
			 setup.Value, 
			 setup.Index, 
			 NULL, 
			 setup.Length, 
			 TIMEOUT_LIBUSB);
   if (ret < 0)
   {
      // failure
      OWERROR(OWERROR_RESET_FAILED);
      AdapterRecover(portnum);
      return FALSE;
   }
   else
   {
      // extra delay for alarming DS1994/DS2404 complience
      if ((FAMILY_CODE_04_ALARM_TOUCHRESET_COMPLIANCE) && (USBSpeed[portnum] != MODE_OVERDRIVE))
         msDelay(5);

      // success, check for shorts
      if (DS2490ShortCheck(usb_dev_handle_list[portnum], &present,&vpp))
      {
         USBVpp[portnum] = vpp;     
         return present;
      }
      else
      {
         OWERROR(OWERROR_OW_SHORTED);
         // short occuring
         msDelay(300);
         AdapterRecover(portnum);
         return FALSE;
      }
   }
}
Beispiel #2
0
//--------------------------------------------------------------------------
// Reset all of the devices on the 1-Wire Net and return the result.
//
// 'portnum'     - number 0 to MAX_PORTNUM-1.  This number is provided to
//                 indicate the symbolic port number.
//
// Returns: TRUE(1):  presense pulse(s) detected, device(s) reset
//          FALSE(0): no presense pulses detected
//
SMALLINT owTouchReset(int portnum)
{
   SETUP_PACKET setup;
   ULONG nOutput = 0;
   SMALLINT present,vpp;

   // make sure strong pullup is not on
   if (USBLevel[portnum] == MODE_STRONG5)
      owLevel(portnum, MODE_NORMAL);

   // construct command
   setup.RequestTypeReservedBits = 0x40;
   setup.Request = COMM_CMD;
   setup.Value = COMM_1_WIRE_RESET | COMM_F | COMM_IM | COMM_SE;
   setup.Index = (USBSpeed[portnum] == MODE_OVERDRIVE) ?
                  ONEWIREBUSSPEED_OVERDRIVE : ONEWIREBUSSPEED_FLEXIBLE;
   setup.Length = 0;
   setup.DataOut = FALSE;
   // call the driver
   if (!DeviceIoControl(usbhnd[portnum],
					    DS2490_IOCTL_VENDOR,
					    &setup,
					    sizeof(SETUP_PACKET),
					    NULL,
					    0,
					    &nOutput,
					    NULL))
   {
      // failure
      OWERROR(OWERROR_RESET_FAILED);
      AdapterRecover(portnum);
      return FALSE;
   }
   else
   {
      // extra delay for alarming DS1994/DS2404 complience
      if ((FAMILY_CODE_04_ALARM_TOUCHRESET_COMPLIANCE) && (USBSpeed[portnum] != MODE_OVERDRIVE))
         Sleep(5);

      // success, check for shorts
      if (DS2490ShortCheck(usbhnd[portnum], &present,&vpp))
      {
         USBVpp[portnum] = vpp;     
         return present;
      }
      else
      {
         OWERROR(OWERROR_OW_SHORTED);
         // short occuring
         msDelay(300);
         AdapterRecover(portnum);
         return FALSE;
      }
   }
}
Beispiel #3
0
//---------------------------------------------------------------------------
// Attempt to resync and detect a DS2490
//
// 'portnum'    - number 0 to MAX_PORTNUM-1.  This number was provided to
//                OpenCOM to indicate the port number.
//
// Returns:  TRUE  - DS2490 detected successfully
//           FALSE - Could not detect DS2490
//
SMALLINT DS2490Detect(usb_dev_handle *hDevice)
{
   SMALLINT present,vpp,ret;
   SETUP_PACKET setup;

   // reset the DS2490
   DS2490Reset(hDevice);

   // set the strong pullup duration to infinite
   setup.RequestTypeReservedBits = 0x40;
   setup.Request = COMM_CMD;
   setup.Value = COMM_SET_DURATION | COMM_IM;
   setup.Index = 0x0000;
   setup.Length = 0;
   setup.DataOut = FALSE;
   // call the libusb driver
   ret = usb_control_msg(hDevice,
                         setup.RequestTypeReservedBits,
                         setup.Request,
                         setup.Value,
                         setup.Index,
                         NULL,
                         setup.Length,
                         TIMEOUT_LIBUSB);

   // set the 12V pullup duration to 512us
   setup.RequestTypeReservedBits = 0x40;
   setup.Request = COMM_CMD;
   setup.Value = COMM_SET_DURATION | COMM_IM | COMM_TYPE;
   setup.Index = 0x0040;
   setup.Length = 0;
   setup.DataOut = FALSE;
   // call the libusb driver
   ret = usb_control_msg(hDevice, 
                         setup.RequestTypeReservedBits, 
                         setup.Request, 
                         setup.Value, 
                         setup.Index, 
                         NULL, 
                         setup.Length, 
                         TIMEOUT_LIBUSB);

   // disable strong pullup, but leave program pulse enabled (faster)
   setup.RequestTypeReservedBits = 0x40;
   setup.Request = MODE_CMD;
   setup.Value = MOD_PULSE_EN;
   setup.Index = ENABLEPULSE_PRGE; 
   setup.Length = 0x00;
   setup.DataOut = FALSE;
   // call the libusb driver
   ret = usb_control_msg(hDevice, 
                         setup.RequestTypeReservedBits, 
                         setup.Request, 
                         setup.Value, 
                         setup.Index, 
                         NULL, 
                         setup.Length, 
                         TIMEOUT_LIBUSB);

   // return result of short check
   return DS2490ShortCheck(hDevice,&present,&vpp);
}