The W1 driver class. More...
Public Member Functions | |
PruW1 (BYVAL_AS_PruIo_PTR, BYVAL_AS_Uint8, BYVAL_AS_Uint8) | |
The constructor is configuring the bus pin, loading and starting the PRU code. More... | |
~PruW1 () | |
The destructor stopping PRU, freeing memory. More... | |
FUNCTION_AS_ZSTRING_PTR | scanBus (BYVAL_AS_UInt8) |
Function to scan the bus for all devices. More... | |
SUB | sendByte (BYVAL_AS_UInt8) |
Send a byte (eight bits) to the bus. More... | |
SUB | sendRom (BYVAL_AS_UInt64) |
Send a ROM id to the bus (to select a device). More... | |
FUNCTION_AS_UInt8 | recvBlock (BYVAL_AS_UInt8) |
Receive a block of data (usually 9 bytes). More... | |
FUNCTION_AS_UInt8 | recvByte () |
Receive a single byte (8 bit). More... | |
FUNCTION_AS_UInt8 | getIn () |
Get the state of the data line. More... | |
FUNCTION_AS_UInt8 | resetBus () |
Send the reset signal to the bus. More... | |
FUNCTION_AS_UInt8 | calcCrc (BYVAL_AS_UInt8) |
Compute the CRC checksum for data package. More... | |
FUNCTION_AS_UInt8 | checkPara () |
Check line for parasite powered device. More... | |
SUB | prot () |
Print the monitoring log data to STDOUT. More... | |
Public Attributes | |
ZSTRING_PTR | Errr |
The variable to report error messages. | |
UInt32 | Mask |
The mask to select the pin in use. | |
UInt32 | PruNo |
The number of the PRU to use. | |
UInt32 | PruIRam |
The PRU instruction ram to use. | |
UInt32 | PruLMod |
The line modus to use (parasite power). | |
UInt32_PTR | DRam |
A pointer to the PRU Data Ram. | |
UInt32_PTR | Raw |
Uint8 | Crc8_Table [255+1] |
A pre-computed table for fast CRC checksum computation. More... | |
UInt64 | Slots [ANY] |
The array to store the device IDs. | |
The W1 driver class.
The class providing the one wire features.
PruW1::PruW1 | ( | BYVAL_AS_PruIo_PTR | P, |
BYVAL_AS_Uint8 | B, | ||
BYVAL_AS_Uint8 | M = PRUW1_PULLUP |
||
) |
The constructor is configuring the bus pin, loading and starting the PRU code.
P | A pointer to the libpruio instance (for pinmuxing). |
B | The header pin to use as W1 bus data line. |
M | The operating modus (Parasite power, internal pull-up). |
The constructor is designed to
In case of success the variable PruW1::Errr is 0 (zero), ready for starting the communication on the bus. Otherwise the variable contains an error message. The string is owned by libpruw1 and should not be freed. In that case call the destructor (and do not start any communication).
The operating modus M is introduced in version 0.4 in order to influence power consumption (ie. for batterie powered systems):
PruW1::~PruW1 | ( | ) |
FUNCTION_AS_UInt8 PruW1::calcCrc | ( | BYVAL_AS_UInt8 | N | ) |
Compute the CRC checksum for data package.
N | The length of the package in bytes. |
A data package (usually the 64-bit scratchpad context) is in the PRU DRam after a PruW1::readBlock() operation. This function computes the CRC checksum for a package with a given length. The length parameter specifies where to find the CRC byte, so in case of an 8 byte package length has to be 9 (= the same value as in the PruW1::readBlock() call).
FUNCTION_AS_UInt8 PruW1::checkPara | ( | ) |
Check line for parasite powered device.
Id | Sensor Id, or 0 (zero) for broadcast. |
This function triggers a broadscast READ POWER command. The returned value is the (inverted) bit received. If the function returns FALSE (0) there's no parasite powered device on the bus (all VDD=3V3). In contrast, TRUE (1) means that at least one device has no external power line (VDD=GND) and needs the strong pullup in idle mode.
FUNCTION_AS_UInt8 PruW1::getIn | ( | ) |
SUB PruW1::prot | ( | ) |
Print the monitoring log data to STDOUT.
This function outputs the state of the bus data line for the monitoring log feature. When monitoring is enabled at compile time, this function gets called after each operation and prints lines of 70 characters for each transfered bit. See section Monitoring Feature for details.
FUNCTION_AS_UInt8 PruW1::recvBlock | ( | BYVAL_AS_UInt8 | N | ) |
Receive a block of data (usually 9 bytes).
N | The number of bytes to read. |
This function triggers the bus to receive a block of bytes. Parameter N
specifies the number of bytes to read. The return value is the number of bytes read, or 0 (zero) in case of an error (message text in PruW1::Errr). The received data bytes are in the PruW1::DRam, starting at byte offset &h10
(= DRam[4]).
FUNCTION_AS_UInt8 PruW1::recvByte | ( | ) |
FUNCTION_AS_UInt8 PruW1::resetBus | ( | ) |
Send the reset signal to the bus.
This function sends the reset signal to the bus. It uses special timing. After the reset signal all devices answer by a presence pulse, so that the master knows that slave devices are on the bus. In that case the return value is 0 (zero). Otherwise, in case of no devices are responding, the return value is 1.
FUNCTION_AS_ZSTRING_PTR PruW1::scanBus | ( | BYVAL_AS_UInt8 | SearchType = &hF0 | ) |
Function to scan the bus for all devices.
SearchType | The search type (defaults to &hF0). |
0
(zero) on success.This function scans the bus and collects the IDs of the found devices (if any) in the array Slots. By default it uses the default search ROM command (&hF0
).
Find the number of devices by evaluating the upper bound of array Slots.
SUB PruW1::sendByte | ( | BYVAL_AS_UInt8 | V | ) |
SUB PruW1::sendRom | ( | BYVAL_AS_UInt64 | ) |
Uint8 PruW1::Crc8_Table[255+1] |
A pre-computed table for fast CRC checksum computation.
UInt32_PTR PruW1::Raw |