Erlang NIF library

Erlang NIF library

Postby mafleming » Thu Feb 19, 2015 11:45 pm

Hello all,

I have an Erlang NIF (Natively Implemented Functions) library that provides all of the functions available in the Epiphany eHAL library. You can use it to write the main program communicating with the Epiphany chip in Erlang. There are some demonstration programs with the package and some edoc documentation.

As an example, one of the demos spawns an Erlang process for each Epiphany core. Each process loads a program to the core and returns the program result to its parent process. Another demo shows how to use an Erlang Escript to program the Epiphany. Although the demos are written in Erlang, the program running on the core still needs to be programmed in C.

I wanted to gauge interest among those in the forum for the source code and get an idea (from the moderator?) on how to make the code available.


Posts: 6
Joined: Tue Feb 17, 2015 11:03 pm

Re: Erlang NIF library

Postby greytery » Fri Feb 20, 2015 10:12 am


Very much an Erlang novice, but I'm interested in your NIF library.
Can you describe more about dependencies, etc? e.g. mini-Erlang, ...?

When it's 'ready' I suggest it could end up @ examples - but 9600 can best advise.

User avatar
Posts: 205
Joined: Sat Dec 07, 2013 12:19 pm
Location: ^Wycombe, UK

Re: Erlang NIF library

Postby mafleming » Fri Feb 20, 2015 3:55 pm

I've built and tested the NIF library with the standard Linaro distribution of Erlang. Nothing special required there. As with regular C main implementations, you need to run as root and the environment variables need to point to the location of the library. There is also some information on communicating between say an Erlang node on your workstation and the one running on your Parallella board.

Posts: 6
Joined: Tue Feb 17, 2015 11:03 pm

Re: Erlang NIF library

Postby aolofsson » Sun Feb 22, 2015 7:24 pm


Very cool indeed!! Note that with the new beta SDK (which is really supposed to be as stable as the old SDK, but with less actual miles), you don't need to run as root.

We are working on a new library, and we are making wrappers a first order concern from day one. Here is the place we have in mind for them. ... ers/erlang

Also, if you have an example showing how the NIF would be used, the best place for it would be here:

User avatar
Posts: 1005
Joined: Tue Dec 11, 2012 6:59 pm
Location: Lexington, Massachusetts,USA

Re: Erlang NIF library

Postby 9600 » Mon Feb 23, 2015 10:24 am

+1. This sounds very cool indeed!

I suspect OmerK may have some comments and I'll ping him, but IIRC he could be traveling at present so may not reply straight away.


Andrew Back (a.k.a. 9600 / carrierdetect)
User avatar
Posts: 997
Joined: Mon Dec 17, 2012 3:25 am

Re: Erlang NIF library

Postby mafleming » Mon Feb 23, 2015 5:54 pm


The wrapper location looks like just the place to put the NIF library. I currently have files arranged in a directory structure as they would be for an Erlang application (src, bin and so on). What remains to be done is pasting in a standard license text to each source file, and converting the HTML documentation to a PDF document for easier reading.

Since you mentioned the Parallella examples github location, would the directions for submitting the files to the wrapper location be the same as described for the examples location?

Posts: 6
Joined: Tue Feb 17, 2015 11:03 pm

Re: Erlang NIF library

Postby mafleming » Wed Mar 04, 2015 11:47 pm


The Erlang NIF library "Erlpiphany" has been loaded into the wrappers/erlang section of the parallella/pal tree. You'll find it at

There is documentation in HTML and PDF format providing instructions on how to build and use the library to write your own main drivers. There are also examples to get you started. I look forward to testing the release with the new SDK when it is released. As always, feedback is appreciated.

Happy coding!
Posts: 6
Joined: Tue Feb 17, 2015 11:03 pm

Re: Erlang NIF library

Postby rsneekes » Sun Mar 22, 2015 4:44 pm


Thanks for this wrapper. To get it working with the latest(?) image (, I had to make the changes below. Two function declaration changes and e-loader.h needs to be included and linked against.


Code: Select all
diff -ur pal-orig/src/wrappers/erlang/erlpiphany/Makefile pal/src/wrappers/erlang/erlpiphany/Makefile
--- pal-orig/src/wrappers/erlang/erlpiphany/Makefile   2015-03-22 16:36:48.716122144 +0000
+++ pal/src/wrappers/erlang/erlpiphany/Makefile   2015-03-22 16:34:07.032583075 +0000
@@ -25,7 +25,7 @@
 $(PRIV)/ $(CSRC)/ehal.c
    gcc -o $(PRIV)/ -fpic -shared $(CSRC)/ehal.c \
    -I${EPIPHANY_HOME}/tools/host/include   \
-   -L${EPIPHANY_HOME}/tools/host/lib -le-hal
+   -L${EPIPHANY_HOME}/tools/host/lib -le-hal -le-loader
 $(EBIN)/%.beam: $(SRC)/%.erl
    erlc -I$(INCLUDE) -o$(EBIN) $<
diff -ur pal-orig/src/wrappers/erlang/erlpiphany/c_src/ehal.c pal/src/wrappers/erlang/erlpiphany/c_src/ehal.c
--- pal-orig/src/wrappers/erlang/erlpiphany/c_src/ehal.c   2015-03-22 16:36:48.716122144 +0000
+++ pal/src/wrappers/erlang/erlpiphany/c_src/ehal.c   2015-03-22 16:34:37.968133579 +0000
@@ -47,7 +47,7 @@
 #include <string.h>
 // SDK includes
-#include "e-hal.h"
+#include "e-loader.h"
 // References to SDK functions
 // 14.2 Platform Configuration Functions
@@ -78,9 +78,9 @@
 extern int e_resume(e_epiphany_t *dev, unsigned row, unsigned col);
 // 14.6 Program Load Functions
-extern int e_load(char *executable, e_epiphany_t *dev, unsigned row,
+extern int e_load(const char *executable, e_epiphany_t *dev, unsigned row,
         unsigned col, e_bool_t start);
-extern int e_load_group(char *executable, e_epiphany_t *dev, unsigned row,
+extern int e_load_group(const char *executable, e_epiphany_t *dev, unsigned row,
          unsigned col, unsigned rows, unsigned cols,
          e_bool_t start);
Binary files pal-orig/src/wrappers/erlang/erlpiphany/ebin/ehal.beam and pal/src/wrappers/erlang/erlpiphany/ebin/ehal.beam differ
Only in pal/src/wrappers/erlang/erlpiphany: priv
Posts: 4
Joined: Mon Dec 17, 2012 3:23 am

Re: Erlang NIF library

Postby mafleming » Thu Apr 02, 2015 2:41 pm

Thanks Raymond. I've been waiting for the dust to settle on the new release before trying a build. Good to see there's so little to change!

~ Mark
Posts: 6
Joined: Tue Feb 17, 2015 11:03 pm

Return to Erlang

Who is online

Users browsing this forum: No registered users and 1 guest