Platform-specific layer provides a consistent 1-Wire API to upper layers of the driver.
1-Wire API Overview
1-Wire is a device communications bus system designed by Dallas Semiconductor Corp. that provides low-speed data, signaling, and power over a single signal.
This API contains the functions to configure and control a 1 Wire bus by bit-banging a GPIO of the programmable XBee devices.
Platform-specific layer provides a consistent MACROS API to upper layers of the driver.
1-Wire ROM-Commands
The 1-Wire protocol has 5 generic ROM-Commands that may be used with one_wire_write() and one_wire_write_byte() functions:
- ONE_WIRE_READ_ROM : Read rom of device (only works when there is a unique device conected to the bus).
- ONE_WIRE_MATCH_ROM : Master will transfer the ROM of desired device, devices with different ROM will stay idle.
- ONE_WIRE_SEARCH_ROM : Starts a ROM search over the 1-Wire bus.
- ONE_WIRE_SKIP_ROM : All devices will listen to command regardless their ROM, use with care.
- ONE_WIRE_AlARM_SEARCH: Similar to search ROM algorithm but only devices with a triggered alarm will answer.
Performs a CRC (Cyclic Redundancy Check) over a buffer.
- Parameters
-
[in] | buffer | the buffer which will be checked. |
[in] | len | the number of bytes to be considered. |
- Return values
-
Used for addressing a specific device connected to the 1-Wire bus. Usually used after a one_wire_reset() command.
- Parameters
-
[in] | romcode | the ROM code of the device to be addressed. |
- Return values
-
ssize_t | 0 on success. |
ssize_t | <0 if there is an error. |
int one_wire_config |
( |
void |
| ) |
|
Initializes and configures the 1-Wire interface.
- Return values
-
Reads from the 1-Wire bus determined number of bytes.
- Parameters
-
[out] | rxbuf | the buffer where the received bytes will be stored. |
[in] | len | the number of bytes to be read. |
- Return values
-
int | 0 on success. |
int | <0 if there is an error while reading. |
Reads one byte from the 1-Wire bus.
- Parameters
-
[out] | rxbyte | the buffer where the received byte will be stored. |
- Return values
-
If there is only one device connected to the 1-Wire bus, reads its ROM code. This ROM is CRC8 checked before reporting a success.
- Parameters
-
[out] | romcode | the buffer where the ROM code will be stored. |
- Return values
-
int | 0 on success. |
int | <0 if there is an error while reading. |
Performs a reset on the 1-Wire bus.
- Return values
-
0 | on success. |
<0 | if there is an error |
Performs the 1-Wire search algorithm and store ROM codes found.
- Parameters
-
[in] | rombuf | the buffer where ROM codes will be stored (should be big enough to store maximum number of devices (e.g.: rombuf[8 * len]). |
[in] | len | the maximum number of device that can be found. |
- Return values
-
int | number of devices found. |
<0 | if there is any error while looking for devices. |
uint8_t one_wire_single_bit_rx |
( |
void |
| ) |
|
Reads 1 bit from the 1-Wire bus.
- Return values
-
Sends 1 bit over the 1-Wire bus.
- Parameters
-
[in] | bit | bit to be transferred. |
- Return values
-
Used when only one device is connected to the 1-Wire bus, so sending 32-bit ROM code is unnecessary. Usually used after a one_wire_reset() command.
- Return values
-
ssize_t | 0 on success. |
ssize_t | <0 if there is an error while reading. |
void one_wire_spp_enable |
( |
bool_t |
val | ) |
|
Activates or deactivates the strong pull-up (if enabled) on the 1-Wire bus.
- Parameters
-
[in] | val | 1 for enabling, 0 for disabling. |
- Return values
-
Sends over the 1-Wire bus a buffer with a determined length.
- Parameters
-
[in] | txbuf | the buffer containing the bytes to be transferred. Frist byte may be 1-Wire ROM-Commands or device-specific commands. |
[in] | len | the number of bytes to be transferred. |
- Return values
-
int | 0 on success. |
int | <0 if there is an error while transferring. |
Sends 1 byte over the 1-Wire bus.
- Parameters
-
- Return values
-