Contiki 3.x
|
One wire driver using hardware UART as a bus master.More...
#include <stdint.h>
Go to the source code of this file.
Functions | |
void | ow_init (void) |
Initialize the 1-wire driver. More... | |
void | ow_reset (void) |
Reset the 1-wire bus. More... | |
void | ow_write_bytes (const uint8_t *src, const uint8_t count) |
Write a sequence of bytes to the 1-wire bus. More... | |
void | ow_write_byte (const uint8_t data) |
Shorthand function to write a single byte to the 1-wire bus. More... | |
void | ow_read_bytes (uint8_t *dest, const uint8_t count) |
Read a sequence of bytes from the 1-wire bus. More... | |
uint8_t | ow_compute_crc (const uint8_t *data, const uint8_t count) |
Compute a 1-wire 8-bit CRC. More... | |
ow_rom_code_t | ow_read_rom (void) |
Issue a 1-wire READ ROM command. More... | |
void | ow_skip_rom (void) |
Issue a 1-wire SKIP ROM command. More... | |
void | ow_match_rom (const ow_rom_code_t id) |
Issue a 1-wire MATCH ROM command. More... | |
void | ow_skip_or_match_rom (const ow_rom_code_t id) |
Shorthand function for MATCH ROM or SKIP ROM if id is zero. More... | |
One wire driver using hardware UART as a bus master.
Definition in file onewire.h.
uint8_t ow_compute_crc | ( | const uint8_t * | data, |
const uint8_t | count | ||
) |
Compute a 1-wire 8-bit CRC.
This function uses a lookup table method of computing the CRC one byte at a time, instead of bit per bit. The table is found in ow_crc_table in onewire-crc-table.h.
The polynomial used by the 1-wire bus is x^8 + x^5 + x^4 + x^0, or 0x31. But take care when computing the CRC (or producing a lookup table) that the CRC is computed LSB first and using the reversed polynomial 0x8C instead.
data | The message. |
count | Number of bytes in the message. |
Definition at line 401 of file onewire.c.
Referenced by ds18b20_read_scratchpad(), and ow_read_rom().
void ow_init | ( | void | ) |
Initialize the 1-wire driver.
This will set up the clocks, interrupts and I/O pins.
Definition at line 220 of file onewire.c.
References NVIC_EnableIRQ(), SIM, and uart_module_enable().
void ow_match_rom | ( | const ow_rom_code_t | id | ) |
Issue a 1-wire MATCH ROM command.
The MATCH ROM command is used to single out a specific device using its ROM code as identifier.
id | The ROM code of the selected device. |
Definition at line 482 of file onewire.c.
References ow_reset(), and ow_write_bytes().
Referenced by ow_skip_or_match_rom().
void ow_read_bytes | ( | uint8_t * | dest, |
const uint8_t | count | ||
) |
Read a sequence of bytes from the 1-wire bus.
Contrary to the ow_write_bytes function, this function is synchronous and will do a busy wait until all bits have been read. This is not really desirable but is so only because of laziness and lack of time.
dest | the destination buffer. |
count | number of bytes to read from the bus. |
Definition at line 365 of file onewire.c.
Referenced by ds18b20_read_scratchpad(), and ow_read_rom().
ow_rom_code_t ow_read_rom | ( | void | ) |
Issue a 1-wire READ ROM command.
The value will be returned in the order it arrives on the bus, i.e. 8 bit family code first, then 48 bit serial number, last 8 bit CRC.
On a little endian machine this will be the exact same representation as in the 1-wire data sheets, LSB first.
Definition at line 428 of file onewire.c.
References ow_compute_crc(), ow_read_bytes(), ow_reset(), and ow_write_bytes().
void ow_reset | ( | void | ) |
Reset the 1-wire bus.
A reset is always the first step in communicating with the bus slaves.
Definition at line 269 of file onewire.c.
Referenced by ow_match_rom(), ow_read_rom(), and ow_skip_rom().
void ow_skip_or_match_rom | ( | const ow_rom_code_t | id | ) |
Shorthand function for MATCH ROM or SKIP ROM if id is zero.
id | The ROM code of the selected device, or 0 for all devices. |
Definition at line 500 of file onewire.c.
References ow_match_rom(), and ow_skip_rom().
Referenced by ds18b20_convert_temperature(), and ds18b20_read_scratchpad().
void ow_skip_rom | ( | void | ) |
Issue a 1-wire SKIP ROM command.
The SKIP ROM command is used to issue commands to all devices on the bus.
Definition at line 466 of file onewire.c.
References ow_reset(), and ow_write_bytes().
Referenced by ow_skip_or_match_rom().
void ow_write_byte | ( | const uint8_t | data | ) |
Shorthand function to write a single byte to the 1-wire bus.
data | the data byte to write. |
Definition at line 348 of file onewire.c.
References ow_write_bytes().
void ow_write_bytes | ( | const uint8_t * | src, |
const uint8_t | count | ||
) |
Write a sequence of bytes to the 1-wire bus.
The transmission to the 1-wire bus is asynchronous, which means this function will return before all bits have gone out the wire.
src | the source buffer. |
count | number of bytes to write to the bus. |
Definition at line 329 of file onewire.c.
Referenced by ds18b20_convert_temperature(), ds18b20_read_scratchpad(), ow_match_rom(), ow_read_rom(), ow_skip_rom(), and ow_write_byte().