BBBCSIO

The PRUDriver Class

 

The PRUDriver Class

Provides the functionality to interact with a PRU on the Beaglebone Black.

 

Source Code

The source code for this class is available online for download and also in browseable form.

 

Example Code

Sample code which demonstrates the use of this class can be found on the PRU Blink USR3 LED, PRU Data In Out, PRU Pin Input and Output and PRU Interrupts Host example pages.

 

Syntax

public class PRUDriver

Provides the functionality to interact with a PRU on the Beaglebone Black.

 

Public Constructors

public PRUDriver (PRUEnum pruIDIn)

Constructor.

Parameters
pruIDIn - The pru we interact with.

 

Public Methods

public void ClearEvent(PRUEventEnum pruEventIn)

Clears the specified event - this should be called after every event (synchronous or asynchronous) and must be done or the event cannot be re-triggered.

Parameters
pruEventIn - the host event we clear.

 

public void CloseAllEvents()

Closes all events.

 

public void CloseEvent(PRUEventEnum pruEventIn)

Closes an event.

Parameters
pruEventIn - the host event we close.

 

public void Dispose()

Implements IDisposable. Should be called after the class is closed to release resources.

 

public void EnablePRUHostEvent(PRUEventEnum pruEventIn)

Enables a PRU System Event at the Host level. Our standard mapping has ensured that PRU systemInterrupts 16-23 are mapped to host Interrupts 2-9 and all we need to do is enable that if we want to use the functionality.

NOTE: host interrupts 0 and 1 are left by the UIO subsystem for signalling between the two PRUs because the functionality to support this is hard coded into the PRU INTC system. Host Interrupts 2 to 9 appear in userspace via the uio device files /dev/uio0 to /dev/uio7.

This means that if you trigger PRU systemInterrupt16 you will see it appear on /dev/uio0. Similarly triggering PRU systemInterrupt17 will cause it to appear on /dev/uio1 The UIO file number which receives the event is always the low four bits of the system interrupt. The only reason this works like that is because the standard setup routes sysInt16 through channel2 through host2 and host2 is tied to uio0 by the UIO subsystem.

Parameters
pruEventIn - the host event. This must have been opened with a call to OpenPRUEvent

 

public void ExecutePRUProgram(string binaryToRun)

Loads a compiled binary into a PRU and runs it.

Parameters
binaryToRun - The binary file to run. Cannot be NULL.

 

public void ExecutePRUProgram(string binaryToRun, byte[] dataBytes)

Loads a compiled binary into a PRU and runs it.

Parameters
binaryToRun - The binary file to run. Cannot be NULL.
dataBytes - The databyes to load into the PRU dataRAM. The offset is assumed to be 0. This is intended for data which should be in place and which the PRU should find when it starts. Can be NULL

 

public void InitInterruptsForAllPRUs()

Resets and initializes the interrupts and events for all PRU's (PRU0 and PRU1). The PRU's share a interrupt controller subsystem so calling this function once is sufficient for both PRUs. Note: if you set up events for one PRU then call this to init the events for the other PRU you will clear the event configuration for the first PRU. Call this function once!

 

public void PRUEventMonitorOff(PRUEventEnum pruEventIn)

Stop monitoring a PRU event.

Parameters
pruEventIn - the host event we stop monitoring.

 

public void PRUEventMonitorOn(PRUEventEnum pruEventIn, PRUInterruptEventHandlerUIO pruEventHander)

Begins Monitoring a PRU event. This allows us to process asynchronous event actions. The pruEventHander will get the event information when the event is triggered.

Parameters
pruEventIn - the host event we begin monitoring.
pruEventHander - the event data handler. Cannot be NULL.

 

public void PRUStop()

Stop the PRU.

 

public byte ReadPRUDataByte(uint offset)

Reads a byte from the PRU data memory.

Parameters
offset - The offset into the PRU DataRAM we read the databytes from. Note that the sizeof(byte) + offset cannot be more than the PRU_DRAM_SIZE

Returns
a byte read from the PRU Data Ram at the offset

 

public byte[] ReadPRUDataByteArray(uint offset, uint length)

Reads a byte array from the PRU data memory

Parameters
offset - The offset into the PRU DataRAM we read the databytes from. Note that the length + offset cannot be more than the PRU_DRAM_SIZE
length - the number of bytes to read

Returns
a byte array read from the PRU Data Ram at the offset

 

public Int16 ReadPRUDataInt16(uint offset)

Reads the PRU data memory and returns it as a Int16

Parameters
offset - The offset into the PRU DataRAM we read the databytes from. Note that the sizeof(Int16) + offset cannot be more than the PRU_DRAM_SIZE

Returns
an Int16 read from the PRU Data Ram at the offset

 

public Int32 ReadPRUDataInt32(uint offset)

Reads the PRU data memory and returns it as a Int32

Parameters
offset - The offset into the PRU DataRAM we read the databytes from. Note that the sizeof(Int32) + offset cannot be more than the PRU_DRAM_SIZE

Returns
an Int32 read from the PRU Data Ram at the offset

 

public Int64 ReadPRUDataInt64(uint offset)

Reads the PRU data memory and returns it as a Int64

Parameters
offset - The offset into the PRU DataRAM we read the databytes from. Note that the sizeof(Int64) + offset cannot be more than the PRU_DRAM_SIZE

Returns
an Int64 read from the PRU Data Ram at the offset

 

public UInt16 ReadPRUDataUInt16(uint offset)

Reads the PRU data memory and returns it as a UInt16

Parameters
offset - The offset into the PRU DataRAM we read the databytes from. Note that the sizeof(UInt16) + offset cannot be more than the PRU_DRAM_SIZE

Returns
a UInt16 read from the PRU Data Ram at the offset

 

public UInt32 ReadPRUDataUInt32(uint offset)

Reads the PRU data memory and returns it as a UInt32

Parameters
offset - The offset into the PRU DataRAM we read the databytes from. Note that the sizeof(UInt32) + offset cannot be more than the PRU_DRAM_SIZE

Returns
a UInt32 read from the PRU Data Ram at the offset

 

public UInt64 ReadPRUDataUInt64(uint offset)

Reads the PRU data memory and returns it as a UInt64

Parameters
offset - The offset into the PRU DataRAM we read the databytes from. Note that the sizeof(UInt64) + offset cannot be more than the PRU_DRAM_SIZE

Returns
a UInt64 read from the PRU Data Ram at the offset

 

public void ResetInterruptsForAllPRUs()

Resets the events for all PRU's (PRU0 and PRU1).

The PRU's share a interrupt controller subsystem so calling this function resets the interrupts and events for both PRUs

 

public void SetupStandardHostAndChannelMappingForAllPRUs()

The system interrupts, channels, hosts and corresponding events and interrupts can be configured in a near infinite number of ways.

In order to keep things simple a standard, documented, arrangement is configured and the user can then enable specific interrupts to perform the desired actions. This does mean that many of the PRU system interrupts are left unconnected. This setup is intended primarily to let the PRU trigger a host interrupt which will propagate down to user space and be visible on one of the uio* files

The PRU's share a interrupt controller subsystem so calling this function sets the standard configuration for both PRUs

NOTE: a call to ResetInterruptsForAllPRUs() should be made to reset things before calling this function

 

public UInt32 WaitForEvent(PRUEventEnum pruEventIn)

Waits for the specified event. Will stall with a blocking read until the event is triggered. It also possible to set up an asynchronous event via the PRUEventMonitorOn/Off call and receive the events via a handler function while the main thread is doing something.

Parameters
pruEventIn - the host event we wait for

Returns
the total number of events processed by the uio file (from any source) since boot up.

 

public void WritePRUDataByte(byte byteVal, uint offset)

Writes the contents of a specified byte into the PRU data memory. NOTE: the max size here is PRU_DRAM_SIZE

Parameters
byteVal - The byte to write
offset - The offset into the PRU DataRAM we write the byte into. Note that the sizeof(byte) + offset cannot be more than the PRU_DRAM_SIZE

 

public void WritePRUDataByteArray(byte[] byteArray, uint offset)

Writes the contents of a specified byte array into the PRU data memory.

Parameters
byteArray - The byte array to write
offset - The offset into the PRU DataRAM we write the byte array into. Note that the byteArray.Length + offset cannot be more than the PRU_DRAM_SIZE

 

public void WritePRUDataInt16(Int16 dataVal, uint offset)

Writes the contents of a specified Int16 into the PRU data memory.

Parameters
dataVal - The Int16 to write
offset - The offset into the PRU DataRAM we write the Int16 into. Note that the sizeof(Int16) + offset cannot be more than the PRU_DRAM_SIZE

 

public void WritePRUDataInt32(Int32 dataVal, uint offset)

Writes the contents of a specified Int32 into the PRU data memory.

Parameters
dataVal - The Int32 to write
offset - The offset into the PRU DataRAM we write the Int32 into. Note that the sizeof(Int32) + offset cannot be more than the PRU_DRAM_SIZE

 

public void WritePRUDataInt64(Int64 dataVal, uint offset)

Writes the contents of a specified Int64 into the PRU data memory.

Parameters
dataVal - The Int64 to write
offset - The offset into the PRU DataRAM we write the Int64 into. Note that the sizeof(Int64) + offset cannot be more than the PRU_DRAM_SIZE

 

public void WritePRUDataUInt16(UInt16 dataVal, uint offset)

Writes the contents of a specified UInt16 into the PRU data memory.

Parameters
dataVal - The UInt16 to write
offset - The offset into the PRU DataRAM we write the UInt16 into. Note that the sizeof(UInt16) + offset cannot be more than the PRU_DRAM_SIZE

 

public void WritePRUDataUInt32(UInt32 dataVal, uint offset)

Writes the contents of a specified UInt32 into the PRU data memory.

Parameters
dataVal - The UInt32 to write
offset - The offset into the PRU DataRAM we write the UInt32 into. Note that the sizeof(UInt32) + offset cannot be more than the PRU_DRAM_SIZE

 

public void WritePRUDataUInt64(UInt64 dataVal, uint offset)

Writes the contents of a specified UInt64 into the PRU data memory.

Parameters
dataVal - The UInt64 to write
offset - The offset into the PRU DataRAM we write the UInt64 into. Note that the sizeof(UInt64) + offset cannot be more than the PRU_DRAM_SIZE

 

Public Properties

public PRUEnum PRUID { get }

Gets the ID of the PRU we are using. There is no set accessor - this value is fixed when this object is created.

value
The PRU ID.