Skip to content

Commit

Permalink
PocketBeagle/TechLab: add rpmsg example
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Kridner committed Jan 29, 2020
1 parent 7bce79f commit 85fe903
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 18 deletions.
41 changes: 41 additions & 0 deletions PocketBeagle/TechLab/.challenges/rgbLEDrpmsg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env node
var fs = require('fs');
var os = require('os');
var process = require('process');

var buffer = Buffer.alloc(16);

fs.open("/dev/rpmsg_pru30", "r+", null, onOpen);

function onOpen(err, fd) {
if (err) {
console.log("Unble to open /dev/rpmsg_pru30");
os.exit(-1);
}
fs.read(fd, buffer, 0, 10, null, onData);

process.stdin.setEncoding('utf8');
process.stdin.on('readable', onStdin);
console.log("Type red, green, blue or white and press <ENTER>");

function onStdin(err) {
var chunk;
if (err) {
console.log("Error reading from /dev/rpmsg_pru30");
os.exit(-1);
}
while ((chunk = process.stdin.read()) !== null) {
fs.write(fd, chunk);
}
}

function onData(err, bytes, data) {
if(err) {
console.log("Error reading from /dev/rpmsg_pru30");
os.exit(-1);
}
console.log('response: ' + data.toString('ascii'));
fs.read(fd, buffer, 0, 10, null, onData);
}
}

35 changes: 18 additions & 17 deletions PocketBeagle/TechLab/.challenges/rgbLEDrpmsg.pru0.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
////////////////////////////////////////
// rgbLEDrpmsg.pru0
// Uses rpmsg to control the NeoPixels via /dev/rpmsg_pru30 on the ARM
// Usage: echo index R G B > /dev/rpmsg_pru30 to set the color at the given index
// echo -1 0 0 0 > /dev/rpmsg_pro30 to update the string
// echo 0 0xf0 0 0 > /dev/rpmsg_pru30 Turns pixel 0 to Red
// neopixelRainbow.py to display moving rainbow pattern
// Wiring: The NeoPixel Data In goes to P1_36, the plus lead to P1_14 (3.3V)
// and the ground to P2_22. If you have more then 40 some
// NeoPixels you will need and external supply.
// Setup: config_pin P1_36 pruout
// Uses rpmsg accept messages to /dev/rpmsg_pru30 by the ARM
// Usage: echo green > /dev/rpmsg_pru30 to set the TechLab RGB LED green
// Wiring: PocketBeagle + TechLab
// Setup: tested with 4.14.108-ti-r124 kernel
// See:
// PRU: pru0
////////////////////////////////////////
Expand Down Expand Up @@ -52,8 +47,8 @@ volatile register uint32_t __R31;
#define VIRTIO_CONFIG_S_DRIVER_OK 4

/* GPIO1 */
unsigned int volatile * const GPIO1_CLEAR = (unsigned int *) (GPIO1 + GPIO_CLEARDATAOUT);
unsigned int volatile * const GPIO1_SET = (unsigned int *) (GPIO1 + GPIO_SETDATAOUT);
unsigned int volatile * const GPIO1_CLEAR = ((unsigned int *) GPIO1) + (GPIO_CLEARDATAOUT);
unsigned int volatile * const GPIO1_SET = ((unsigned int *) GPIO1) + (GPIO_SETDATAOUT);

/* PRU GPIO */
volatile register unsigned int __R30;
Expand All @@ -69,7 +64,7 @@ volatile register unsigned int __R31;
void setLED(void);

char payload[RPMSG_BUF_SIZE];
int state = RED;
volatile int state = RED;

/*
* main.c
Expand Down Expand Up @@ -104,16 +99,22 @@ void main(void)
CT_INTC.SICR_bit.STS_CLR_IDX = FROM_ARM_HOST;
/* Receive all available messages, multiple messages can be sent per kick */
while (pru_rpmsg_receive(&transport, &src, &dst, payload, &len) == PRU_RPMSG_SUCCESS) {
if(!strcmp("red", payload)) {
/* Set the state based on the payload */
if(!strncmp("red\n", payload, 1)) {
pru_rpmsg_send(&transport, dst, src, "r", 2);
state = RED;
} else if(!strcmp("blue", payload)) {
} else if(!strncmp("blue\n", payload, 1)) {
pru_rpmsg_send(&transport, dst, src, "b", 2);
state = BLUE;
} else if(!strcmp("green", payload)) {
} else if(!strncmp("green\n", payload, 1)) {
pru_rpmsg_send(&transport, dst, src, "g", 2);
state = GREEN;
} else if(!strcmp("white", payload)) {
} else if(!strncmp("white\n", payload, 1)) {
pru_rpmsg_send(&transport, dst, src, "w", 2);
state = WHITE;
} else {
state = 0;
pru_rpmsg_send(&transport, dst, src, payload, len);
state = 0;
}

setLED();
Expand Down
2 changes: 1 addition & 1 deletion common/prugpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

#else

#warning "Found else"
#warning "Found am335x"
// These are addresses for the am35xx
#define GPIO0 0x44E09000
#define GPIO1 0x4804C000
Expand Down

0 comments on commit 85fe903

Please sign in to comment.