libpruw1  0.4
One wire (W1) driver for Beaglebone hardware based on libpruio
pruw1.h File Reference

The main header code of the C wrapper for libpruw1. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  pruw1
 The PruW1 C wrapper structure. More...
 

Macros

#define pruw1_scanBus(W1)   pruw1_scanBus(W1, 0xF0)
 

Typedefs

typedef unsigned char UInt8
 8 bit unsigned integer data type.
 
typedef short Int16
 16 bit signed integer data type.
 
typedef int Int32
 32 bit signed integer data type.
 
typedef unsigned int UInt32
 32 bit unsigned integer data type.
 
typedef unsigned long long int UInt64
 64 bit unsigned integer data type.
 
typedef struct pruw1 pruw1
 forward declaration More...
 

Enumerations

enum  LineModus { PRUW1_PARPOW = &b01 , PRUW1_PULLUP = &b10 , PRUW1_PARPOW = 0x1 , PRUW1_PULLUP = 0x2 }
 Masks for line idle configuration. More...
 

Functions

Int16 T_FAM10 (UInt8 *Rom)
 Compute the temperature for a series 10 sensor (old format). More...
 
Int16 T_FAM20 (UInt8 *Rom)
 Compute the temperature for a series 20 sensor (new format). More...
 
pruw1pruw1_new (pruIo *P, UInt8 B, UInt8 M)
 Wrapper function for the constructor PruW1::PruW1(). More...
 
void pruw1_destroy (pruw1 *W1)
 Wrapper function for the destructor PruW1::~PruW1(). More...
 
char * pruw1_scanBus (pruw1 *W1, UInt8 SearchType)
 Function to scan the bus for all devices. More...
 
void pruw1_sendByte (pruw1 *W1, UInt8 V)
 Send a byte (eight bits) to the bus. More...
 
void pruw1_sendRom (pruw1 *W1, UInt64 V)
 Send a ROM ID to the bus (to select a device). More...
 
UInt8 pruw1_recvBlock (pruw1 *W1, UInt8 N)
 Receive a block of data (usually 9 bytes). More...
 
UInt8 pruw1_recvByte (pruw1 *W1)
 Receive a single byte (8 bit). More...
 
UInt8 pruw1_getIn (pruw1 *W1)
 Get the state of the data line. More...
 
UInt8 pruw1_resetBus (pruw1 *W1)
 Send the reset signal to the bus. More...
 
UInt8 pruw1_checkPara (pruw1 *W1)
 Check line for parasite powered device. More...
 
UInt8 pruw1_calcCrc (pruw1 *W1, UInt8 N)
 Compute the CRC checksum for data package. More...
 
Int32 pruw1_getSlotMax (pruw1 *W1)
 Property to get size of array PruW1::Slots from C. More...
 
void pruw1_eraseSlots (pruw1 *W1)
 Function to empty the array PruW1::Slots from C. More...
 
UInt64 pruw1_getId (pruw1 *W1, UInt32 N)
 Function to get ID from array PruW1::Slots from C. More...
 

Detailed Description

The main header code of the C wrapper for libpruw1.

This file provides the declarations of macros, types and classes in C syntax. Include this file in your code to make use of libpruw1. This file contains a translation of the context of all FreeBASIC headers (pruw1.bi) in one file.

Feel free to translate this file in order to create language bindings for non-C languages in order to use libpruio in polyglot applications.

Licence: LGPLv2 (http://www.gnu.org/licenses/lgpl-2.0.html)

Copyright 2015-2023 by Thomas{ dOt ]Freiherr[ aT ]gmx[DoT}net

Definition in file pruw1.h.

Typedef Documentation

◆ pruw1

typedef struct pruw1 pruw1

forward declaration

The PruW1 C wrapper structure.

The class providing the one wire features.

Since
0.0

Definition at line 26 of file pruw1.h.

Enumeration Type Documentation

◆ LineModus

enum LineModus

Masks for line idle configuration.

This enumerators are for use in CTOR PruW1::PruW1() to configure the line idle modus, regarding parasite power support and the use of the internal pull up resistor.

Since
0.4
Enumerator
PRUW1_PARPOW 

Set line output high during idle.

PRUW1_PULLUP 

Activate internal pull up resistor (default)

PRUW1_PARPOW 

Set line output high during idle.

PRUW1_PULLUP 

Activate the internal pull up resistor.

Definition at line 73 of file pruw1.h.

Function Documentation

◆ pruw1_calcCrc()

UInt8 pruw1_calcCrc ( pruw1 W1,
UInt8  N 
)

Compute the CRC checksum for data package.

Parameters
W1The driver instance.
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

◆ pruw1_checkPara()

UInt8 pruw1_checkPara ( pruw1 W1)

Check line for parasite powered device.

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 byte received. If the function returns FALSE (0) there's no parasite powered device on the bus (all VDD=3V3). In contrast, TRUE (1) means at least one device has no external power line (VDD=GND) and needs the strong pullup in idle mode.

Since
0.4

◆ pruw1_destroy()

void pruw1_destroy ( pruw1 W1)

Wrapper function for the destructor PruW1::~PruW1().

Parameters
W1The driver instance.
Since
0.0

◆ pruw1_eraseSlots()

void pruw1_eraseSlots ( pruw1 W1)

Function to empty the array PruW1::Slots from C.

Parameters
W1The driver instance.

Auxiliary function to work aroung a missing feature in C syntax.

Since
0.0

◆ pruw1_getId()

UInt64 pruw1_getId ( pruw1 W1,
UInt32  N 
)

Function to get ID from array PruW1::Slots from C.

Parameters
W1The driver instance.
NThe number of the slot entry.

Auxiliary function to work aroung a missing feature in C syntax.

Since
0.2

◆ pruw1_getIn()

UInt8 pruw1_getIn ( pruw1 W1)

Get the state of the data line.

Parameters
W1The driver instance.
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

◆ pruw1_getSlotMax()

Int32 pruw1_getSlotMax ( pruw1 W1)

Property to get size of array PruW1::Slots from C.

Parameters
W1The driver instance.
Returns
The number of elements array PruW1::Slots.

Auxiliary function to work aroung a missing feature in C syntax.

Since
0.0

◆ pruw1_new()

pruw1* pruw1_new ( pruIo *  P,
UInt8  B,
UInt8  M 
)

Wrapper function for the constructor PruW1::PruW1().

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).
Returns
A pointer to the new instance, call pruw1_destroy() when done.

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

◆ pruw1_recvBlock()

UInt8 pruw1_recvBlock ( pruw1 W1,
UInt8  N 
)

Receive a block of data (usually 9 bytes).

Parameters
W1The driver instance.
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

◆ pruw1_recvByte()

UInt8 pruw1_recvByte ( pruw1 W1)

Receive a single byte (8 bit).

Parameters
W1The driver instance.
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

◆ pruw1_resetBus()

UInt8 pruw1_resetBus ( pruw1 W1)

Send the reset signal to the bus.

Parameters
W1The driver instance.
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

◆ pruw1_scanBus()

char* pruw1_scanBus ( pruw1 W1,
UInt8  SearchType 
)

Function to scan the bus for all devices.

Parameters
W1The driver instance.
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, using function getSlotsSize().

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 by function eraseSlots().
Since
0.0

◆ pruw1_sendByte()

void pruw1_sendByte ( pruw1 W1,
UInt8  V 
)

Send a byte (eight bits) to the bus.

Parameters
W1The driver instance.
VThe value to send.

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

Since
0.0

◆ pruw1_sendRom()

void pruw1_sendRom ( pruw1 W1,
UInt64  V 
)

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

Parameters
W1The driver instance.
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

◆ T_FAM10()

Int16 T_FAM10 ( UInt8 Rom)

Compute the temperature for a series 10 sensor (old format).

Parameters
RomThe pointer where to find the data received from the device.
Returns
The temperature (high byte = decimal value, low byte = digits).

This function decodes the temperature value from a DS18S20 sensor (such sensors have &h10 in the lowest byte of their ID). The returned value contains the temperature in grad Celsius in the high byte and the decimal places in the low byte. Divide the value by 256 to get a real number containing the temperatur in grad Celsius.

Parameter Rom is usually the adress of PruW1::DRam[4].

Since
0.0

◆ T_FAM20()

Int16 T_FAM20 ( UInt8 Rom)

Compute the temperature for a series 20 sensor (new format).

Parameters
RomThe pointer where to find the data received from the device.
Returns
The temperature (high byte = decimal value, low byte = digits).

This function decodes the temperature value from a DS18B20 sensor (such sensors have &h20 in the lowest byte of their ID). The returned value contains the temperature in grad Celsius in the high byte and the decimal places in the low byte. Divide the value by 256 to get a real number containing the temperatur in grad Celsius.

Parameter Rom is usually the adress of PruW1::DRam[4].

Since
0.0