PRU User Space API  v1.0.0
An API to control the BeagleBone PRUs using the RemoteProc and RPMsg framework.
Public Member Functions | Friends | List of all members
PRU Class Reference

class PRU More...

#include <pruss.h>

Public Member Functions

int enable ()
 Enable the PRU. More...
 
int disable ()
 Disable the PRU. More...
 
int reset ()
 Reset the PRU. More...
 
int pause ()
 Pause the PRU execution. More...
 
int resume ()
 Resume PRU execution in single step mode. More...
 
std::string showRegs ()
 Show PRU register values. More...
 
int load (std::string)
 Install compiled firmware to the PRU. More...
 
void setChannel ()
 Set the RPMsg communication channel according to the "pruss_api" driver. More...
 
int setChannel (int, std::string)
 
State getState ()
 Get the current state of the PRU object. More...
 
int sendMsg_string (std::string)
 Send a message to PRU in the form of characters. More...
 
void sendMsg_raw (std::string)
 Send a raw integer value to PRU. More...
 
std::string getMsg ()
 Receive message from PRU. More...
 
int waitForEvent ()
 Wait till an event occurs at the RPMsg channel of the given PRU. More...
 
int waitForEvent (int)
 Wait till an event occurs at the RPMsg channel of the given PRU. More...
 
std::string mem_read (Memory mem, std::string)
 Read from PRU SRAM/DRAM0/DRAM1. More...
 
std::string mem_write (Memory mem, std::string, std::string)
 Write to PRU SRAM/DRAM0/DRAM1. More...
 

Friends

class PRUSS
 

Detailed Description

class PRU

Member Function Documentation

◆ disable()

int PRU::disable ( )

Disable the PRU.

Stops the PRU by echoing stop into the /sys/class/remoteproc/remoteprocN/state directory

Returns
0 if the write was done successfully

◆ enable()

int PRU::enable ( )

Enable the PRU.

Starts the PRU by echoing start into the /sys/class/remoteproc/remoteprocN/state directory

Returns
0 if write was done successfully

◆ getMsg()

string PRU::getMsg ( )

Receive message from PRU.

Receive a string message from pruss_api_pruN channel. The message should already be present in the buffer before this function is called.

Returns
the message received from the PRU at the RPMsg channel as a string, if no message is found, return '
'

◆ getState()

State PRU::getState ( )

Get the current state of the PRU object.

Used to know the current whether the PRU is currently in a stopped, running, halted or none state.

See also
enum State
Returns
state of the PRU

◆ load()

int PRU::load ( std::string  )

Install compiled firmware to the PRU.

Installs compiled PRU firmware by copying it into /lib/firmware and echoing the name of the elf file into /sys/class/remoteproc/remoteprocN/firmware

Parameters
fwis the relative path/absolute path to the firmware that is to be loaded to the PRU.
Returns
0 if the firmware is loaded successfully.

◆ mem_read()

string PRU::mem_read ( Memory  mem,
std::string   
)

Read from PRU SRAM/DRAM0/DRAM1.

Read a 1-byte integer value from the PRU memory block specified in the parameter. The 1-byte integer value will be read as a string.

Parameters
memdescribes which PRU memory block is to be used from the enumeration Memory.
offsetsets the address offset for the memory block.
See also
enum Memory
Returns
the 1-byte integer value present at thae address offset as a string.

◆ mem_write()

string PRU::mem_write ( Memory  mem,
std::string  ,
std::string   
)

Write to PRU SRAM/DRAM0/DRAM1.

Write a 1-byte integer value to the PRU memory block specified in the parameter. The 1-byte integer value must be specified as a string.

Parameters
memdescribes which PRU memory block is to be used from the enumeration Memory.
offsetsets the address offset for the memory block.
datathe integer data that needs to be written to that address offset.
See also
enum Memory
Returns
"0" if write is done else the negative of EINVAL

◆ pause()

int PRU::pause ( )

Pause the PRU execution.

This function pauses the PRU execution in such a way that the execution can be resumed from the same point where it stopped. (This is not the case when echoing stop into /sys/class/remoteproc/remoteprocN because then the PRU would have to re start from its first instruction)

The PRU is paused by echoing '1' into /sys/kernel/debug/remoteproc/remoteprocN/single_step

Returns
0 if the echoing is done successfully

◆ reset()

int PRU::reset ( )

Reset the PRU.

Completely stops the PRU execution and starts again from first instruction.

See also
PRU::disable()
PRU::enable()
Returns
0 if writes were done successfully

◆ resume()

int PRU::resume ( )

Resume PRU execution in single step mode.

This function is used to execute the PRU in single_step mode. Every time this function is called, the PRU executes one instruction cycle by echoing '1' into /sys/kernel/debug/remoteproc/remoteprocN/single_step

Returns
0 if the echoing is done successfully

◆ sendMsg_raw()

void PRU::sendMsg_raw ( std::string  )

Send a raw integer value to PRU.

It is difficult to reconstruct data on the PRU side if data is sent as a string. This is because the PRU compilers have limited memory and can't perform string operations.

Sending data in raw form makes it easier for it to be reconstructed on the PRU side.

Parameters
messagestring representing 1-byte integer that needs to be passed to the PRU. The string will be converted to integer once passed to the daemon.
Returns
0 if the message is written to the RPMsg channel successfully else appropriate error code.

◆ sendMsg_string()

int PRU::sendMsg_string ( std::string  )

Send a message to PRU in the form of characters.

Send a string of characters through pruss_api_pruN to the PRUN of maximum length of 496 bytes (512 limit - 16 header size) The firmware that uses RPMsg MUST be running so that the communication channel is created.

Parameters
messageof not more than 496 characters.
Returns
0 if the message is written to the RPMsg channel successfully else appropriate error code.

◆ setChannel()

void PRU::setChannel ( )

Set the RPMsg communication channel according to the "pruss_api" driver.

This driver creates "pruss_api_pru0" channel for PRU0 and "pruss_api_pru1" for PRU1.

chanPort maps to which PRU object is being used. chanName specifies the channel name that is common for both the PRUs.

◆ showRegs()

string PRU::showRegs ( )

Show PRU register values.

Displays all the current values of the PRU Control Registers and displats all the PRU General Purpose Registers if the PRU is not running.

Returns
The entire contents of the regs file in /sys/kernel/debug/remoteproc/remoteprocN The return string is large more than 1kB

◆ waitForEvent() [1/2]

int PRU::waitForEvent ( )

Wait till an event occurs at the RPMsg channel of the given PRU.

Waits indefinitely on the RPMsg channel pruss_api_pruN in /dev until an event occurs.

Returns
0 if event occurs

◆ waitForEvent() [2/2]

int PRU::waitForEvent ( int  time)

Wait till an event occurs at the RPMsg channel of the given PRU.

Waits on the RPMsg channel pruss_api_pruN in /dev until an event occurs within the specified time limit.

Parameters
timeinteger that specifies for how much time to wait for any event before returning.
Returns
0 if event occurs or appropriate error code.

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