libpruw1  0.4
One wire (W1) driver for Beaglebone hardware based on libpruio
PruW1 Class Reference

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.
 

Detailed Description

The W1 driver class.

The class providing the one wire features.

Since
0.0

Definition at line 40 of file pruw1.bi.

Constructor & Destructor Documentation

◆ PruW1()

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.

Parameters
PA pointer to the libpruio instance (for pinmuxing).
BThe header pin to use as W1 bus data line.
MThe operating modus (Parasite power, internal pull-up).

The constructor is designed to

  • allocate and initialize memory for the class variables,
  • evaluate the free PRU (not used by libpruio)
  • check the header pin configuration (and, if not matching, try to adapt it - pinmuxing),
  • load the firmware and start it

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):

  • Bit-0 controlls the idle state of the line during sensor operation. By default the line is in input state (only the pull-up resistor pulls the line high). Set this bit in order to bring the line in high output state during sensor operation for parasite powering.
Note
For parasite powering the sensor VDD line must get grounded. The sensors current is up to 1.5 mA, so you must not run more than 4 sensors in parasite powering on a BBB-GPIO.
  • Bit-1 controlls the resistor configuration. By default By default the internal pull-up resistor pulls the line high, so that a sensor can operate without any further wiring. For long cables use an external resistor (usually 4k7 Ohm). Clear the bit in oder to save some energy consumption.
Since
0.0

Definition at line 61 of file pruw1.bas.

◆ ~PruW1()

PruW1::~PruW1 ( )

The destructor stopping PRU, freeing memory.

The destructor stops the PRU by disabling it. Then it frees the memory.

Since
0.0

Definition at line 110 of file pruw1.bas.

Member Function Documentation

◆ calcCrc()

FUNCTION_AS_UInt8 PruW1::calcCrc ( BYVAL_AS_UInt8  N)

Compute the CRC checksum for data package.

Parameters
NThe length of the package in bytes.
Returns
The CRC checksum for a data package (0 = success).

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).

Since
0.0

Definition at line 282 of file pruw1.bas.

◆ checkPara()

FUNCTION_AS_UInt8 PruW1::checkPara ( )

Check line for parasite powered device.

Parameters
IdSensor Id, or 0 (zero) for broadcast.
Returns
TRUE (1) if at least one device uses parasite power, FALSE (0) otherwise.

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.

Since
0.4

Definition at line 322 of file pruw1.bas.

◆ getIn()

FUNCTION_AS_UInt8 PruW1::getIn ( )

Get the state of the data line.

Returns
The state (1 = high, 0 = low)

This function returns the current state of the GPIO line used for the bus. The function uses libpruio to fetch the state, so only use it after the PruIo::config() call.

Since
0.0

Definition at line 247 of file pruw1.bas.

◆ prot()

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.

Since
0.0

Definition at line 299 of file pruw1.bas.

◆ recvBlock()

FUNCTION_AS_UInt8 PruW1::recvBlock ( BYVAL_AS_UInt8  N)

Receive a block of data (usually 9 bytes).

Parameters
NThe number of bytes to read.
Returns
The number of bytes 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]).

Note
When compiled with monitor feature, the maximum block size is 112 bytes, due to limited size of logging memory (PruW1::DRam)
Since
0.0

Definition at line 215 of file pruw1.bas.

◆ recvByte()

FUNCTION_AS_UInt8 PruW1::recvByte ( )

Receive a single byte (8 bit).

Returns
The byte read from the bus.

This function triggers the bus to receive a single byte. The return value is the byte received.

Since
0.0

Definition at line 232 of file pruw1.bas.

◆ resetBus()

FUNCTION_AS_UInt8 PruW1::resetBus ( )

Send the reset signal to the bus.

Returns
The presence pulse from 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.

Since
0.0

Definition at line 263 of file pruw1.bas.

◆ scanBus()

FUNCTION_AS_ZSTRING_PTR PruW1::scanBus ( BYVAL_AS_UInt8  SearchType = &hF0)

Function to scan the bus for all devices.

Parameters
SearchTypeThe search type (defaults to &hF0).
Returns
An error message or 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.

Note
Usually the bus gets scanned once in the init process of an application. When you intend to use dynamic sensor connections (plug them in and out), then you have to periodically re-scan the bus. In that case clear the Slots array before each scan, in order to avoid double entries.
Since
0.0

Definition at line 133 of file pruw1.bas.

◆ sendByte()

SUB PruW1::sendByte ( BYVAL_AS_UInt8  V)

Send a byte (eight bits) to the bus.

Parameters
VThe value to send.

This procedure sends a byte to the bus. It's usually used to issue a ROM command.

Since
0.0

Definition at line 182 of file pruw1.bas.

◆ sendRom()

SUB PruW1::sendRom ( BYVAL_AS_UInt64  )

Send a ROM id to the bus (to select a device).

Parameters
VThe ROM id (8 btes) to send.

This procedure sends a ROM ID to the bus. It's usually used to adress a single device, ie. to read its scratchpad.

Since
0.0

Definition at line 195 of file pruw1.bas.

Member Data Documentation

◆ Crc8_Table

Uint8 PruW1::Crc8_Table[255+1]
Initial value:
= {
0, 94, 188, 226, 97, 63, 221, 131, 194, 156, 126, 32, 163, 253, 31, 65
, 157, 195, 33, 127, 252, 162, 64, 30, 95, 1, 227, 189, 62, 96, 130, 220
, 35, 125, 159, 193, 66, 28, 254, 160, 225, 191, 93, 3, 128, 222, 60, 98
, 190, 224, 2, 92, 223, 129, 99, 61, 124, 34, 192, 158, 29, 67, 161, 255
, 70, 24, 250, 164, 39, 121, 155, 197, 132, 218, 56, 102, 229, 187, 89, 7
, 219, 133, 103, 57, 186, 228, 6, 88, 25, 71, 165, 251, 120, 38, 196, 154
, 101, 59, 217, 135, 4, 90, 184, 230, 167, 249, 27, 69, 198, 152, 122, 36
, 248, 166, 68, 26, 153, 199, 37, 123, 58, 100, 134, 216, 91, 5, 231, 185
, 140, 210, 48, 110, 237, 179, 81, 15, 78, 16, 242, 172, 47, 113, 147, 205
, 17, 79, 173, 243, 112, 46, 204, 146, 211, 141, 111, 49, 178, 236, 14, 80
, 175, 241, 19, 77, 206, 144, 114, 44, 109, 51, 209, 143, 12, 82, 176, 238
, 50, 108, 142, 208, 83, 13, 239, 177, 240, 174, 76, 18, 145, 207, 45, 115
, 202, 148, 118, 40, 171, 245, 23, 73, 8, 86, 180, 234, 105, 55, 213, 139
, 87, 9, 235, 181, 54, 104, 138, 212, 149, 203, 41, 119, 244, 170, 72, 22
, 233, 183, 85, 11, 136, 214, 52, 106, 43, 117, 151, 201, 74, 20, 246, 168
, 116, 42, 200, 150, 21, 75, 169, 247, 182, 232, 10, 84, 215, 137, 107, 53
}

A pre-computed table for fast CRC checksum computation.

Definition at line 51 of file pruw1.bi.

◆ Raw

UInt32_PTR PruW1::Raw

A pointer to the libpruio raw GPIO data

Definition at line 49 of file pruw1.bi.


The documentation for this class was generated from the following files: