Skip to content

Commit

Permalink
Modify bindings and examples to use the updated daemon server
Browse files Browse the repository at this point in the history
Updated the commands sent by the bindings to the server, updated
examples and fix bugs in the daemon server.
  • Loading branch information
MuneebMohammed committed Jun 10, 2018
1 parent 24418f5 commit 04b8957
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 36 deletions.
49 changes: 26 additions & 23 deletions cpp-bindings/pruss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using namespace std;
Socket::Socket()
{
this->fd = -1;
this->socketpath = "/tmp/prusocket";
this->socketpath = "/tmp/prussd.sock";
}

bool Socket::conn()
Expand Down Expand Up @@ -65,8 +65,8 @@ PRUSS& PRUSS::get()
PRUSS::PRUSS() : pru0(0), pru1(1)
{
// boot up the PRUSS by probing the remoteproc driver
this->sock.sendcmd("disable0");
this->sock.sendcmd("disable1");
this->sock.sendcmd("DISABLE_0");
this->sock.sendcmd("DISABLE_1");

this->bootUp();

Expand All @@ -87,7 +87,7 @@ int PRUSS::bootUp()
{
if(this->on)
return -EALREADY;
int ret = -stoi(this->sock.sendcmd("probe_rproc")); //send command
int ret = stoi(this->sock.sendcmd("PROBE_RPROC")); //send command
if(!ret) {
this->on = true;
this->pru0.state = this->pru1.state = STOPPED; //PRU Cores are disabled after bootup
Expand All @@ -101,7 +101,7 @@ int PRUSS::shutDown()
return -EALREADY;
this->pru0.disable();
this->pru1.disable();
int ret = -stoi(this->sock.sendcmd("unprobe_rproc"));
int ret = stoi(this->sock.sendcmd("UNPROBE_RPROC"));
if(!ret) {
this->on = false;
this->pru0.state = this->pru1.state = NONE;
Expand Down Expand Up @@ -135,7 +135,7 @@ int PRU::enable()
return -ENODEV;
if(this->state == RUNNING || this->state == HALTED)
return -EALREADY;
int ret = -stoi(this->sock.sendcmd("enable"+to_string(this->number)));
int ret = stoi(this->sock.sendcmd("ENABLE_"+to_string(this->number)));
if(!ret)
this->state = RUNNING;
return ret;
Expand All @@ -147,7 +147,7 @@ int PRU::disable()
return -ENODEV;
if(this->state == STOPPED)
return -EALREADY;
int ret = -stoi(this->sock.sendcmd("disable"+to_string(this->number)));
int ret = stoi(this->sock.sendcmd("DISABLE_"+to_string(this->number)));
if(!ret)
this->state = STOPPED;
return ret;
Expand All @@ -165,7 +165,7 @@ int PRU::pause()
return -ENODEV;
if(this->state == HALTED)
return -EALREADY;
int ret = -stoi(this->sock.sendcmd("pause"+to_string(this->number)));
int ret = stoi(this->sock.sendcmd("PAUSE_"+to_string(this->number)));
if(!ret)
this->state = HALTED;
return ret;
Expand All @@ -177,38 +177,40 @@ int PRU::resume()
return -ENODEV;
if(this->state == RUNNING)
return -EALREADY;
int ret = -stoi(this->sock.sendcmd("resume"+to_string(this->number)));
int ret = stoi(this->sock.sendcmd("RESUME_"+to_string(this->number)));
if(!ret)
this->state = RUNNING;
return ret;
}

string PRU::showRegs()
{
return this->sock.sendcmd("showregs" + to_string(this->number));
return this->sock.sendcmd("GETREGS_" + to_string(this->number));
}

int PRU::load(string fw)
{
this->disable();
if(system(("cp "+ fw + " /tmp/pru" + to_string(this->number)).c_str())) {
return -ENOENT;
}
int ret = -stoi(this->sock.sendcmd("load" + to_string(this->number)));
char buf[PATH_MAX];
realpath(fw.c_str(), buf);
std::string fullPath(buf);
int ret = stoi(this->sock.sendcmd("LOAD_" + to_string(this->number) + " " + fullPath));
this->enable();
return ret;
}

void PRU::setChannel()
{
this->channel = (this->number)?31:30;
this->chanPort = (this->number)?31:30;
this->chanName = "rpmsg_pru";
}

int PRU::setChannel(int channel)
int PRU::setChannel(int port, string name)
{
if(channel < 0)
if(port < 0)
return -EINVAL;
this->channel = channel;
this->chanPort = port;
this->chanName = name;
return 0;
}

Expand All @@ -219,22 +221,23 @@ State PRU::getState()

int PRU::sendMsg(string message)
{
return -stoi(this->sock.sendcmd("sendmsg " + to_string(this->channel) + " " + message)); // eg. sendmsg 31 hi!
string cmd = "SENDMSG "+this->chanName+" "+to_string(this->chanPort)+" "+message;
return stoi(this->sock.sendcmd(cmd)); // eg. sendmsg rpmsg_pru 31 hi!
}

string PRU::getMsg()
{
return this->sock.sendcmd("getmsg " + to_string(this->channel));
return this->sock.sendcmd("GETMSG "+this->chanName+" "+to_string(this->chanPort));
}

int PRU::waitForEvent()
{
return -stoi(this->sock.sendcmd("eventwait " + to_string(this->channel)));
return stoi(this->sock.sendcmd("EVENTWAIT "+this->chanName+" "+to_string(this->chanPort)));
}

int PRU::waitForEvent(int timeout)
int PRU::waitForEvent(int time)
{
return -stoi(this->sock.sendcmd("eventwait " + to_string(this->channel) + " " + to_string(timeout)));
return stoi(this->sock.sendcmd("EVENTWAIT "+this->chanName+" "+to_string(this->chanPort)+" "+to_string(time)));
}


6 changes: 4 additions & 2 deletions cpp-bindings/pruss.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define PRUSS_H_

#include <stdlib.h>
#include <linux/limits.h> // realpath
#include <string> // string handling
#include <sys/socket.h> // socket
#include <sys/un.h> // socket
Expand Down Expand Up @@ -36,7 +37,8 @@ class PRU
{
private:
int number;
int channel;
int chanPort;
std::string chanName;
Socket sock;
State state = NONE;
PRU(int);
Expand All @@ -51,7 +53,7 @@ class PRU
std::string showRegs();
int load(std::string);
void setChannel();
int setChannel(int);
int setChannel(int, std::string);
State getState();
int sendMsg(std::string);
std::string getMsg();
Expand Down
5 changes: 2 additions & 3 deletions examples/pru1_to_pru0_to_arm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ int main()
gettimeofday(&after, NULL);
cout << ((after.tv_sec - before.tv_sec)*1000000L + after.tv_sec) - before.tv_sec << "\n";
}
p0.disable();
p1.disable();
p.shutDown();
p0.disable();


}
7 changes: 4 additions & 3 deletions examples/run.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#! /bin/bash

DIR=$(cd `dirname $BASH_SOURCE[0]` && pwd -P)

echo "This must be run on the BeagleBone Black itself"
echo "Tested on kernel 4.9.36-ti-r46. Firmware Code taken from the BeagleScope project"
echo "https://github.com/ZeekHuge/BeagleScope/tree/port_to_4.4.12-ti-r31%2B/examples/firmware_exmples"
echo "Press any key to continue"
read



echo "-Building Firmware"
cd ./firmware_examples/$1/
cd "${DIR}/firmware_examples/$1/"
make clean
make

Expand Down
10 changes: 5 additions & 5 deletions prussd/prussd.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def sysfs_write(path, val):

def set_config():
"""Reads the Daemon config file and sets paths accordingly."""
if os.path.exists(paths.CONFIG_FILE):
if not os.path.exists(paths.CONFIG_FILE):
return
try:
with open(paths.CONFIG_FILE, "r") as fd:
Expand Down Expand Up @@ -111,7 +111,7 @@ def load_firmware(number, cmd):

try:
fname = cmd[1].split("/")[-1]
fw_path = paths.FIRMWARE_PATH+fname
fw_path = paths.FIRMWARE_PATH+"/"+fname
if cmd[1] != fw_path:
shutil.copyfile(os.path.normpath(cmd[1]), os.path.normpath(fw_path))
return sysfs_write(rproc_sysfs("firmware", number), fname)
Expand Down Expand Up @@ -161,7 +161,7 @@ def send_msg(cmd):
if not os.path.exists(rpmsg_dev):
return -errno.ENODEV
try:
with open(rpmsg_dev, 'r') as fd:
with open(rpmsg_dev, 'w') as fd:
fd.write(' '.join(cmd[3:])+'\n')
return 0
except OSError as err:
Expand Down Expand Up @@ -191,7 +191,7 @@ def event_wait(cmd):
select.select([fd], [], [])
return 0
else:
return 0 if select.select([fd], [], [], timeout) else -errno.ETIME
return 0 if select.select([fd], [], [], timeout)[0] else -errno.ETIME
except OSError as err:
return -err.errno

Expand All @@ -208,7 +208,7 @@ def handle(self):
self.data = self.rfile.readline().strip()

#decode bytes into string and get command args
cmd = self.data.decode("utf-8").upper().split()
cmd = self.data.decode("utf-8").split()

#dict mapping commands to functions
cmds = {
Expand Down

0 comments on commit 04b8957

Please sign in to comment.