Zephyr API Documentation 3.7.99
A Scalable Open Source RTOS
|
1-Wire network layer More...
Data Structures | |
struct | w1_rom |
w1_rom struct. More... | |
struct | w1_slave_config |
Node specific 1-wire configuration struct. More... | |
Macros | |
#define | W1_SEARCH_ALL_FAMILIES 0x00 |
This flag can be passed to searches in order to not filter on family ID. | |
#define | W1_ROM_INIT_ZERO |
Initialize all w1_rom struct members to zero. | |
Typedefs | |
typedef void(* | w1_search_callback_t) (struct w1_rom rom, void *user_data) |
Define the application callback handler function signature for searches. | |
Functions | |
int | w1_read_rom (const struct device *dev, struct w1_rom *rom) |
Read Peripheral 64-bit ROM. | |
int | w1_match_rom (const struct device *dev, const struct w1_slave_config *config) |
Select a specific slave by broadcasting a selected ROM. | |
int | w1_resume_command (const struct device *dev) |
Select the slave last addressed with a Match ROM or Search ROM command. | |
int | w1_skip_rom (const struct device *dev, const struct w1_slave_config *config) |
Select all slaves regardless of ROM. | |
int | w1_reset_select (const struct device *dev, const struct w1_slave_config *config) |
In single drop configurations use Skip Select command, otherwise use Match ROM command. | |
int | w1_write_read (const struct device *dev, const struct w1_slave_config *config, const uint8_t *write_buf, size_t write_len, uint8_t *read_buf, size_t read_len) |
Write then read data from the 1-Wire slave with matching ROM. | |
int | w1_search_bus (const struct device *dev, uint8_t command, uint8_t family, w1_search_callback_t callback, void *user_data) |
Search 1-wire slaves on the bus. | |
static int | w1_search_rom (const struct device *dev, w1_search_callback_t callback, void *user_data) |
Search for 1-Wire slave on bus. | |
static int | w1_search_alarm (const struct device *dev, w1_search_callback_t callback, void *user_data) |
Search for 1-Wire slaves with an active alarm. | |
static uint64_t | w1_rom_to_uint64 (const struct w1_rom *rom) |
Function to convert a w1_rom struct to an uint64_t. | |
static void | w1_uint64_to_rom (const uint64_t rom64, struct w1_rom *rom) |
Function to write an uint64_t to struct w1_rom pointer. | |
static uint8_t | w1_crc8 (const uint8_t *src, size_t len) |
Compute CRC-8 chacksum as defined in the 1-Wire specification. | |
static uint16_t | w1_crc16 (const uint16_t seed, const uint8_t *src, const size_t len) |
Compute 1-Wire variant of CRC 16. | |
1-Wire ROM Commands | |
#define | W1_CMD_SKIP_ROM 0xCC |
This command allows the bus master to read the slave devices without providing their ROM code. | |
#define | W1_CMD_MATCH_ROM 0x55 |
This command allows the bus master to address a specific slave device by providing its ROM code. | |
#define | W1_CMD_RESUME 0xA5 |
This command allows the bus master to resume a previous read out from where it left off. | |
#define | W1_CMD_READ_ROM 0x33 |
This command allows the bus master to read the ROM code from a single slave device. | |
#define | W1_CMD_SEARCH_ROM 0xF0 |
This command allows the bus master to discover the addresses (i.e., ROM codes) of all slave devices on the bus. | |
#define | W1_CMD_SEARCH_ALARM 0xEC |
This command allows the bus master to identify which devices have experienced an alarm condition. | |
#define | W1_CMD_OVERDRIVE_SKIP_ROM 0x3C |
This command allows the bus master to address all devices on the bus and then switch them to overdrive speed. | |
#define | W1_CMD_OVERDRIVE_MATCH_ROM 0x69 |
This command allows the bus master to address a specific device and switch it to overdrive speed. | |
CRC Defines | |
#define | W1_CRC8_SEED 0x00 |
Seed value used to calculate the 1-Wire 8-bit crc. | |
#define | W1_CRC8_POLYNOMIAL 0x8C |
Polynomial used to calculate the 1-Wire 8-bit crc. | |
#define | W1_CRC16_SEED 0x0000 |
Seed value used to calculate the 1-Wire 16-bit crc. | |
#define | W1_CRC16_POLYNOMIAL 0xa001 |
Polynomial used to calculate the 1-Wire 16-bit crc. | |
1-Wire network layer
#define W1_CMD_MATCH_ROM 0x55 |
#include <zephyr/drivers/w1.h>
This command allows the bus master to address a specific slave device by providing its ROM code.
#define W1_CMD_OVERDRIVE_MATCH_ROM 0x69 |
#include <zephyr/drivers/w1.h>
This command allows the bus master to address a specific device and switch it to overdrive speed.
#define W1_CMD_OVERDRIVE_SKIP_ROM 0x3C |
#include <zephyr/drivers/w1.h>
This command allows the bus master to address all devices on the bus and then switch them to overdrive speed.
#define W1_CMD_READ_ROM 0x33 |
#include <zephyr/drivers/w1.h>
This command allows the bus master to read the ROM code from a single slave device.
This command should be used when there is only a single slave device on the bus.
#define W1_CMD_RESUME 0xA5 |
#include <zephyr/drivers/w1.h>
This command allows the bus master to resume a previous read out from where it left off.
#define W1_CMD_SEARCH_ALARM 0xEC |
#include <zephyr/drivers/w1.h>
This command allows the bus master to identify which devices have experienced an alarm condition.
#define W1_CMD_SEARCH_ROM 0xF0 |
#include <zephyr/drivers/w1.h>
This command allows the bus master to discover the addresses (i.e., ROM codes) of all slave devices on the bus.
#define W1_CMD_SKIP_ROM 0xCC |
#include <zephyr/drivers/w1.h>
This command allows the bus master to read the slave devices without providing their ROM code.
#define W1_CRC16_POLYNOMIAL 0xa001 |
#include <zephyr/drivers/w1.h>
Polynomial used to calculate the 1-Wire 16-bit crc.
#define W1_CRC16_SEED 0x0000 |
#include <zephyr/drivers/w1.h>
Seed value used to calculate the 1-Wire 16-bit crc.
#define W1_CRC8_POLYNOMIAL 0x8C |
#include <zephyr/drivers/w1.h>
Polynomial used to calculate the 1-Wire 8-bit crc.
#define W1_CRC8_SEED 0x00 |
#include <zephyr/drivers/w1.h>
Seed value used to calculate the 1-Wire 8-bit crc.
#define W1_ROM_INIT_ZERO |
#include <zephyr/drivers/w1.h>
Initialize all w1_rom struct members to zero.
#define W1_SEARCH_ALL_FAMILIES 0x00 |
#include <zephyr/drivers/w1.h>
This flag can be passed to searches in order to not filter on family ID.
typedef void(* w1_search_callback_t) (struct w1_rom rom, void *user_data) |
#include <zephyr/drivers/w1.h>
Define the application callback handler function signature for searches.
rom | found The ROM of the found slave. |
user_data | User data provided to the w1_search_bus() call. |
|
inlinestatic |
#include <zephyr/drivers/w1.h>
Compute 1-Wire variant of CRC 16.
The 16-bit 1-Wire crc variant is using the reflected polynomial function X^16 + X^15 * + X^2 + 1 with the initial value set to 0x0000. See also APPLICATION NOTE 27: "UNDERSTANDING AND USING CYCLIC REDUNDANCY CHECKS WITH MAXIM 1-WIRE AND IBUTTON PRODUCTS" https://www.maximintegrated.com/en/design/technical-documents/app-notes/2/27.html
seed | Init value for the CRC, it is usually set to 0x0000. | |
[in] | src | Input bytes for the computation. |
len | Length of the input in bytes. |
crc | The computed CRC16 value. |
#include <zephyr/drivers/w1.h>
Compute CRC-8 chacksum as defined in the 1-Wire specification.
The 1-Wire of CRC 8 variant is using 0x31 as its polynomial with the initial value set to 0x00. This CRC is used to check the correctness of the unique 56-bit ROM.
[in] | src | Input bytes for the computation. |
len | Length of the input in bytes. |
crc | The computed CRC8 value. |
int w1_match_rom | ( | const struct device * | dev, |
const struct w1_slave_config * | config ) |
#include <zephyr/drivers/w1.h>
Select a specific slave by broadcasting a selected ROM.
This routine allows the 1-Wire bus master to select a slave identified by its unique ROM, such that the next command will target only this single selected slave.
This command is only necessary in multidrop environments, otherwise the Skip ROM command can be issued. Once a slave has been selected, to reduce the communication overhead, the resume command can be used instead of this command to communicate with the selected slave.
[in] | dev | Pointer to the device structure for the driver instance. |
[in] | config | Pointer to the slave specific 1-Wire config. |
0 | If successful. |
-ENODEV | In case no slave responds to reset. |
-errno | Other negative error code on error. |
#include <zephyr/drivers/w1.h>
Read Peripheral 64-bit ROM.
This procedure allows the 1-Wire bus master to read the peripherals’ 64-bit ROM without using the Search ROM procedure. This command can be used as long as not more than a single peripheral is connected to the bus. Otherwise data collisions occur and a faulty ROM is read.
[in] | dev | Pointer to the device structure for the driver instance. |
[out] | rom | Pointer to the ROM structure. |
0 | If successful. |
-ENODEV | In case no slave responds to reset. |
-errno | Other negative error code in case of invalid crc and communication errors. |
int w1_reset_select | ( | const struct device * | dev, |
const struct w1_slave_config * | config ) |
#include <zephyr/drivers/w1.h>
In single drop configurations use Skip Select command, otherwise use Match ROM command.
[in] | dev | Pointer to the device structure for the driver instance. |
[in] | config | Pointer to the slave specific 1-Wire config. |
0 | If successful. |
-ENODEV | In case no slave responds to reset. |
-errno | Other negative error code on error. |
int w1_resume_command | ( | const struct device * | dev | ) |
#include <zephyr/drivers/w1.h>
Select the slave last addressed with a Match ROM or Search ROM command.
This routine allows the 1-Wire bus master to re-select a slave device that was already addressed using a Match ROM or Search ROM command.
dev | Pointer to the device structure for the driver instance. |
0 | If successful. |
-ENODEV | In case no slave responds to reset. |
-errno | Other negative error code on error. |
#include <zephyr/drivers/w1.h>
Function to convert a w1_rom struct to an uint64_t.
[in] | rom | Pointer to the ROM struct. |
rom64 | The ROM converted to an unsigned integer in endianness. |
|
inlinestatic |
#include <zephyr/drivers/w1.h>
Search for 1-Wire slaves with an active alarm.
This routine searches 1-Wire slaves on the bus, which currently have an active alarm.
[in] | dev | Pointer to the device structure for the driver instance. |
callback | Application callback handler function to be called for each found slave. | |
[in] | user_data | User data to pass to the application callback handler function. |
slave_count | Number of slaves found. |
-errno | Negative error code on error. |
int w1_search_bus | ( | const struct device * | dev, |
uint8_t | command, | ||
uint8_t | family, | ||
w1_search_callback_t | callback, | ||
void * | user_data ) |
#include <zephyr/drivers/w1.h>
Search 1-wire slaves on the bus.
This function searches slaves on the 1-wire bus, with the possibility to search either all slaves or only slaves that have an active alarm state. If a callback is passed, the callback is called for each found slave.
The algorithm mostly follows the suggestions of https://pdfserv.maximintegrated.com/en/an/AN187.pdf
Note: Filtering on families is not supported.
[in] | dev | Pointer to the device structure for the driver instance. |
command | Can either be W1_SEARCH_ALARM or W1_SEARCH_ROM. | |
family | W1_SEARCH_ALL_FAMILIES searcheas all families, filtering on a specific family is not yet supported. | |
callback | Application callback handler function to be called for each found slave. | |
[in] | user_data | User data to pass to the application callback handler function. |
slave_count | Number of slaves found. |
-errno | Negative error code on error. |
|
inlinestatic |
#include <zephyr/drivers/w1.h>
Search for 1-Wire slave on bus.
This routine can discover unknown slaves on the bus by scanning for the unique 64-bit registration number.
[in] | dev | Pointer to the device structure for the driver instance. |
callback | Application callback handler function to be called for each found slave. | |
[in] | user_data | User data to pass to the application callback handler function. |
slave_count | Number of slaves found. |
-errno | Negative error code on error. |
int w1_skip_rom | ( | const struct device * | dev, |
const struct w1_slave_config * | config ) |
#include <zephyr/drivers/w1.h>
Select all slaves regardless of ROM.
This routine sets up the bus slaves to receive a command. It is usually used when there is only one peripheral on the bus to avoid the overhead of the Match ROM command. But it can also be used to concurrently write to all slave devices.
[in] | dev | Pointer to the device structure for the driver instance. |
[in] | config | Pointer to the slave specific 1-Wire config. |
0 | If successful. |
-ENODEV | In case no slave responds to reset. |
-errno | Other negative error code on error. |
#include <zephyr/drivers/w1.h>
Function to write an uint64_t to struct w1_rom pointer.
rom64 | Unsigned 64 bit integer representing the ROM in host endianness. | |
[out] | rom | The ROM struct pointer. |
int w1_write_read | ( | const struct device * | dev, |
const struct w1_slave_config * | config, | ||
const uint8_t * | write_buf, | ||
size_t | write_len, | ||
uint8_t * | read_buf, | ||
size_t | read_len ) |
#include <zephyr/drivers/w1.h>
Write then read data from the 1-Wire slave with matching ROM.
This routine uses w1_reset_select to select the given ROM. Then writes given data and reads the response back from the slave.
[in] | dev | Pointer to the device structure for the driver instance. |
[in] | config | Pointer to the slave specific 1-Wire config. |
[in] | write_buf | Pointer to the data to be written. |
write_len | Number of bytes to write. | |
[out] | read_buf | Pointer to storage for read data. |
read_len | Number of bytes to read. |
0 | If successful. |
-ENODEV | In case no slave responds to reset. |
-errno | Other negative error code on error. |