Beispiel #1
0
uint8_t noinline reset_onewire(uint8_t busmask)
{

    /* pull bus low */
    OW_CONFIG_OUTPUT(busmask);
    OW_LOW(busmask);

    /* wait 480us */
    _delay_loop_2(OW_RESET_TIMEOUT_1);

    /* release bus */
    OW_CONFIG_INPUT(busmask);

    /* wait 60us (maximal pause) + 30 us (half minimum pulse) */
    _delay_loop_2(OW_RESET_TIMEOUT_2);

    /* sample data */
    uint8_t data1 = OW_GET_INPUT(busmask);

    /* wait 390us */
    _delay_loop_2(OW_RESET_TIMEOUT_3);

    /* sample data again */
    uint8_t data2 = OW_GET_INPUT(busmask);

    /* if first sample is low and second sample is high, at least one device is
     * attached to this bus */
    return (uint8_t)(~data1 & data2 & busmask);

}
Beispiel #2
0
uint8_t noinline ow_read(uint8_t busmask)
{
    /* a read timeslot is sent by holding the data line low for
     * 1us, then wait approximately 14us, then sample data and
     * wait */
    /* this is also used as ow_write_1, as the only difference
     * is that the return value is discarded */

    OW_CONFIG_OUTPUT(busmask);
    OW_LOW(busmask);

    _delay_loop_2(OW_READ_TIMEOUT_1);

    OW_HIGH(busmask);
    OW_CONFIG_INPUT(busmask);

    _delay_loop_2(OW_READ_TIMEOUT_2);

    /* sample data now */
    uint8_t data = (uint8_t)(OW_GET_INPUT(busmask) > 0);

    /* wait for remaining slot time */
    _delay_loop_2(OW_READ_TIMEOUT_3);

    OW_CONFIG_OUTPUT(busmask);
    return data;
}
Beispiel #3
0
uint8_t
ow_reset(uint8_t pin)
{
  uint8_t err;
  err = 0;
  /* Pull bus low */
  OW_OUT_LOW(pin); /* disable internal pull-up (can be on from parasite) */
  OW_DIR_OUTPUT(pin); /* pull OW-Pin low for 480us */
  ow_delay_usec(RESET_DELAY); /* Wait for some time */
  /* Release bus */
  OW_DIR_INPUT(pin); /* Set pin as input - wait for clients to pull low. */
  ow_delay_usec(DIR_DELAY);
  /* Sample data */
  err = OW_GET_INPUT(pin); /* no presence detect */
  /* After a delay the clients should release the line
     and input-pin gets back to high due to pull-up-resistor. */
  ow_delay_usec(INPUT_DELAY);
  if (OW_GET_INPUT(pin) == 0) { /* short circuit */
    err = 1;
  }
  return err;
}
Beispiel #4
0
uint8_t
ow_io_bit(uint8_t bit, uint8_t pin)
{
  OW_DIR_OUTPUT(pin); /* drive bus low */
#if 0 /* NOTE(Alexander) Too fast! */
  ow_delay_usec(RECOVERY_DELAY); /* Recovery-Time wuffwuff was 1 */
#endif
  if (bit) {
    OW_DIR_INPUT(pin); /* if bit is 1 set bus high (by ext. pull-up) */
  }
#if 0
  /* wuff-wuff delay was 15uS-1 see comment above */
  ow_delay_usec(WUFF_DELAY);
#endif
  if (OW_GET_INPUT(pin) == 0) {
    bit = 0;  /* sample at end of read-timeslot */
  }
  ow_delay_usec(END_DELAY);
  OW_DIR_INPUT(pin);
  return bit;
}
Beispiel #5
0
unsigned
ow_input_pin_state(uint8_t pin)
{
  return OW_GET_INPUT(pin);
}