Each primitive schedules exactly one hardware-timed operation on TIM1/DMA and returns immediately. Poll onewire_bus_done() to learn when the operation finished, then decode the result.
More...
|
| uint8_t | onewire_bus_done (void) |
| | Non-blocking completion check for the scheduled bus operation.
|
| void | onewire_reset (volatile uint16_t *reset_pulses) |
| | Schedule a 1-Wire bus reset (presence pulse captured via DMA).
|
| uint8_t | onewire_reset_captured (void) |
| | Edges captured by the last capture operation armed.
|
| uint8_t | onewire_present (const volatile uint16_t *pulses, uint8_t captured) |
| | Decode the presence pulse captured by onewire_reset().
|
| uint8_t | onewire_write_slots (const ow_pulse_t *pulses, uint16_t slots) |
| | Schedule a write of slots bit slots.
|
| uint8_t | onewire_write_bit (uint8_t bit) |
| | Schedule a single-slot write of one raw bit.
|
| void | onewire_read_pair (volatile uint16_t *pair_pulses) |
| | Schedule a two-slot read of a Search ROM id/cmp bit pair.
|
| void | onewire_pair_bits (const volatile uint16_t *pair_pulses, uint8_t *id_bit, uint8_t *cmp_bit) |
| | Decode the id/cmp bits of a two-slot read pair.
|
| void | onewire_write_then_read (uint8_t bit) |
| | Schedule a merged single-slot write followed by a two-slot read pair.
|
| uint8_t | onewire_read_data (volatile uint8_t *dst, uint8_t bytes) |
| | Schedule a read of bytes bytes from the bus.
|
| void | onewire_decode_pulses (uint8_t *dst, const volatile uint8_t *pulse, uint8_t nbytes) |
| | Decode captured pulse durations into data bytes (LSB-first bits).
|
| void | onewire_encode_byte (ow_pulse_t *out, uint8_t byte) |
| | Encode a byte into write-pulse durations.
|
| void | onewire_strong_pullup (uint8_t on) |
| | Engage or release the parasite-power strong pull-up on the bus.
|
Each primitive schedules exactly one hardware-timed operation on TIM1/DMA and returns immediately. Poll onewire_bus_done() to learn when the operation finished, then decode the result.
◆ onewire_bus_done()
| uint8_t onewire_bus_done |
( |
void | | ) |
|
Non-blocking completion check for the scheduled bus operation.
- Returns
- 1 if finished (update flag cleared), 0 while still running
◆ onewire_decode_pulses()
| void onewire_decode_pulses |
( |
uint8_t * | dst, |
|
|
const volatile uint8_t * | pulse, |
|
|
uint8_t | nbytes ) |
Decode captured pulse durations into data bytes (LSB-first bits).
- Parameters
-
| [out] | dst | Decoded bytes |
| [in] | pulse | Captured per-bit pulse durations (one entry per bit) |
| [in] | nbytes | Number of bytes to decode (pulse must hold nbytes × 8 entries) |
- Note
- Each bit is classified with the same <= ONEWIRE_SHORT_PULSE_MAX rule as onewire_bit_from_pulse(), slot for slot; bit 0 maps to the LSB of its byte. Recovers scratchpad / register bytes from the 1-Wire read capture.
◆ onewire_encode_byte()
| void onewire_encode_byte |
( |
ow_pulse_t * | out, |
|
|
uint8_t | byte ) |
Encode a byte into write-pulse durations.
- Parameters
-
| [out] | out | Output buffer (8 entries) |
| [in] | byte | Byte value to encode |
◆ onewire_pair_bits()
| void onewire_pair_bits |
( |
const volatile uint16_t * | pair_pulses, |
|
|
uint8_t * | id_bit, |
|
|
uint8_t * | cmp_bit ) |
Decode the id/cmp bits of a two-slot read pair.
- Parameters
-
| [in] | pair_pulses | Pulses captured by onewire_read_pair() |
| [out] | id_bit | Id bit (0 or 1) |
| [out] | cmp_bit | Complement bit (0 or 1) |
◆ onewire_present()
| uint8_t onewire_present |
( |
const volatile uint16_t * | pulses, |
|
|
uint8_t | captured ) |
Decode the presence pulse captured by onewire_reset().
- Parameters
-
- Returns
- 1 if at least one device answered, 0 otherwise
- Note
- A reset that captured only the master-release edge has no presence entry; captured is what distinguishes it from a stale pulse[1], whose value may otherwise fall inside the presence window. captured must describe the same reset as pulses: the two are one hardware fact read from two places. Both go stale the moment another capture is armed - a later completed capture makes onewire_reset_captured() return 2 again, which would otherwise bless a stale pulses[1].
◆ onewire_read_data()
| uint8_t onewire_read_data |
( |
volatile uint8_t * | dst, |
|
|
uint8_t | bytes ) |
Schedule a read of bytes bytes from the bus.
- Parameters
-
| [out] | dst | Buffer for the captured pulse durations (bytes × 8 × 8-bit) |
| [in] | bytes | Number of bytes to read, 1..ONEWIRE_MAX_READ_BYTES (32). Out-of-range values (0 or > 32) are rejected: one pass is limited to ONEWIRE_MAX_SLOTS (256) slots by the 8-bit TIM1 RCR (RCR = bytes*8 - 1); larger reads must be split. |
- Returns
- 1 if the read was scheduled, 0 if bytes is out of range (the call is rejected and no operation is scheduled). In firmware the reject path returns 0; an assert is compiled in only under DS18B20_TEST_HARNESS or OW_TEST_PARAM_GUARD (and is disabled by NDEBUG).
- Note
- On completion, the caller decodes the 8-bit pulse durations (pulse <= ONEWIRE_SHORT_PULSE_MAX reads as bit 1) into data bytes.
◆ onewire_read_pair()
| void onewire_read_pair |
( |
volatile uint16_t * | pair_pulses | ) |
|
Schedule a two-slot read of a Search ROM id/cmp bit pair.
- Parameters
-
| [out] | pair_pulses | Buffer for the captured pulse durations (2 × 16-bit) |
- Note
- On completion, decode the pair with onewire_pair_bits().
◆ onewire_reset()
| void onewire_reset |
( |
volatile uint16_t * | reset_pulses | ) |
|
Schedule a 1-Wire bus reset (presence pulse captured via DMA).
- Parameters
-
| [out] | reset_pulses | Buffer for the captured reset + presence pulse durations (2 x 16-bit; entry 1 is only valid when onewire_reset_captured() returns 2) |
- Note
- On completion, call onewire_reset_captured() and pass its count, together with this buffer, to onewire_present().
◆ onewire_reset_captured()
| uint8_t onewire_reset_captured |
( |
void | | ) |
|
Edges captured by the last capture operation armed.
- Returns
- 0..2; after a reset, 2 means the presence edge arrived, 1 means only the master-release edge was captured, 0 means neither
- Note
- Read from the capture DMA's remaining-transfer count, so the value describes whatever capture was armed last - a reset, a read pair, a merged write+read or a data read - not the reset specifically. Every completed capture drains that counter, so after any of them this call returns 2 again; before the first reset it also returns 2, because the register is still at its reset value. Treat 2 as evidence only for a reset that onewire_reset() actually armed: read the count after that reset's onewire_bus_done() and before any other capture is armed, and pass it to onewire_present() with the buffer of the same reset.
◆ onewire_strong_pullup()
| void onewire_strong_pullup |
( |
uint8_t | on | ) |
|
Engage or release the parasite-power strong pull-up on the bus.
- Parameters
-
| [in] | on | 1 drives the bus line HIGH actively (pin leaves the timer- driven open-drain mode for a push-pull HIGH), 0 releases the line back to the passive external pull-up |
- Note
- Parasite-powered devices source their supply from the bus line and need this active pull-up during energy-intensive phases: the whole temperature conversion (tCONV, up to 750 ms) after Convert T and the EEPROM programming window (tPROG) after Copy Scratchpad / Recall E². Must only be called between hardware operations (bus idle), never while a timed transaction is running.
◆ onewire_write_bit()
| uint8_t onewire_write_bit |
( |
uint8_t | bit | ) |
|
Schedule a single-slot write of one raw bit.
- Parameters
-
| [in] | bit | Bit value to write (0 or 1) |
- Returns
- 1 (the only valid range always schedules)
◆ onewire_write_slots()
| uint8_t onewire_write_slots |
( |
const ow_pulse_t * | pulses, |
|
|
uint16_t | slots ) |
Schedule a write of slots bit slots.
- Parameters
-
| [in] | pulses | Pulse buffer: one entry per slot, plus one trailing entry at index slots that must equal ONEWIRE_RELEASE_PULSE (hardware bus release) when slots > 1; in that case the buffer therefore holds slots + 1 entries. A single-slot write (slots == 1) uses the DMA-free path and only reads entry 0. |
| [in] | slots | Number of bit slots to transmit, 1..ONEWIRE_MAX_SLOTS (256). Out-of-range values (0 or > 256) are rejected: TIM1 RCR is 8-bit (RCR = slots - 1), so larger counts would truncate and desync the timer from the DMA (CNDTR). |
- Returns
- 1 if the write was scheduled, 0 if slots is out of range (the call is rejected and no operation is scheduled). In firmware the reject path returns 0; an assert is compiled in only under DS18B20_TEST_HARNESS or OW_TEST_PARAM_GUARD (and is disabled by NDEBUG).
- Note
- Non-blocking: the DMA feeds CCR3 from the buffer asynchronously, so the buffer must stay valid until onewire_bus_done() reports completion.
◆ onewire_write_then_read()
| void onewire_write_then_read |
( |
uint8_t | bit | ) |
|
Schedule a merged single-slot write followed by a two-slot read pair.
- Parameters
-
| [in] | bit | Direction bit to write in slot 1 (0 or 1) |
- Note
- One timer pass runs three slots: a write of bit, then a read of the next id/cmp pair. Halves the timer passes per search bit compared to a plain write plus a separate read pair. On completion, the internal merged buffer holds [write-slot capture, id pulse, cmp pulse]: decode the pair from entries 1 and 2 with onewire_bit_from_pulse(). Do not pass this buffer to onewire_pair_bits(), which instead decodes entries 0 and 1 as produced by onewire_read_pair().