//-------------------------------------------------------------------------- // Set the 1-Wire Net line level. The values for new_level are // as follows: // // 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to // indicate the symbolic port number. // 'new_level' - new level defined as // MODE_NORMAL 0x00 // MODE_STRONG5 0x02 // MODE_PROGRAM 0x04 (not supported in this version) // MODE_BREAK 0x08 (not supported in chip) // // Returns: current 1-Wire Net level // SMALLINT owLevel(int portnum, SMALLINT new_level) { SETUP_PACKET setup; ULONG nOutput = 0; // Turn off infinite strong pullup? if ((new_level == MODE_NORMAL) && (USBLevel[portnum] == MODE_STRONG5)) { if (DS2490HaltPulse(usbhnd[portnum])) USBLevel[portnum] = MODE_NORMAL; } // Turn on infinite strong5 pullup? else if ((new_level == MODE_STRONG5) && (USBLevel[portnum] == MODE_NORMAL)) { // assume duration set to infinite during setup of device // enable the pulse setup.RequestTypeReservedBits = 0x40; setup.Request = MODE_CMD; setup.Value = MOD_PULSE_EN; setup.Index = ENABLEPULSE_SPUE; setup.Length = 0x00; setup.DataOut = FALSE; // call the driver if (!DeviceIoControl(usbhnd[portnum], DS2490_IOCTL_VENDOR, &setup, sizeof(SETUP_PACKET), NULL, 0, &nOutput, NULL)) { // failure OWERROR(OWERROR_ADAPTER_ERROR); AdapterRecover(portnum); return USBLevel[portnum]; } // start the pulse setup.RequestTypeReservedBits = 0x40; setup.Request = COMM_CMD; setup.Value = COMM_PULSE | COMM_IM; setup.Index = 0; 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_ADAPTER_ERROR); AdapterRecover(portnum); return USBLevel[portnum]; } else { // success, read the result USBLevel[portnum] = new_level; return new_level; } } // unsupported else if (new_level != USBLevel[portnum]) { OWERROR(OWERROR_FUNC_NOT_SUP); return USBLevel[portnum]; } // success, return the current level return USBLevel[portnum]; }
//-------------------------------------------------------------------------- // Set the 1-Wire Net line level. The values for new_level are // as follows: // // 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to // indicate the symbolic port number. // 'new_level' - new level defined as // MODE_NORMAL 0x00 // MODE_STRONG5 0x02 // MODE_PROGRAM 0x04 (not supported in this version) // MODE_BREAK 0x08 (not supported in chip) // // Returns: current 1-Wire Net level // SMALLINT owLevelUSB(int portnum, SMALLINT new_level) { SETUP_PACKET setup; SMALLINT ret = 0; // Turn off infinite strong pullup? if ((new_level == MODE_NORMAL) && (USBLevel[portnum] == MODE_STRONG5)) { if (DS2490HaltPulse(usb_dev_handle_list[portnum])) USBLevel[portnum] = MODE_NORMAL; } // Turn on infinite strong5 pullup? else if ((new_level == MODE_STRONG5) && (USBLevel[portnum] == MODE_NORMAL)) { // assume duration set to infinite during setup of device // enable the pulse setup.RequestTypeReservedBits = 0x40; setup.Request = MODE_CMD; setup.Value = MOD_PULSE_EN; setup.Index = ENABLEPULSE_SPUE; setup.Length = 0x00; 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_ADAPTER_ERROR); AdapterRecover(portnum); return USBLevel[portnum]; } // start the pulse setup.RequestTypeReservedBits = 0x40; setup.Request = COMM_CMD; setup.Value = COMM_PULSE | COMM_IM; setup.Index = 0; 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_ADAPTER_ERROR); AdapterRecover(portnum); return USBLevel[portnum]; } else { // success, read the result USBLevel[portnum] = new_level; return new_level; } } // unsupported else if (new_level != USBLevel[portnum]) { OWERROR(OWERROR_FUNC_NOT_SUP); return USBLevel[portnum]; } // success, return the current level return USBLevel[portnum]; }