add simple pru loader
authorkremlin <ian@kremlin.cc>
Thu, 21 Jan 2016 00:54:56 +0000 (19:54 -0500)
committerkremlin <ian@kremlin.cc>
Thu, 21 Jan 2016 00:54:56 +0000 (19:54 -0500)
src/pru_loader.c [new file with mode: 0644]

diff --git a/src/pru_loader.c b/src/pru_loader.c
new file mode 100644 (file)
index 0000000..e0e9c17
--- /dev/null
@@ -0,0 +1,63 @@
+/* 
+ * Copyright (c) 2016, Ian Sutton <ian@kremlin.cc>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for
+ * any purpose with or without fee is hereby granted, provided that the
+ * above copyright notice and this permission notice appear in all
+ * copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
+ * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include <pruss/prussdrv.h>
+#include <pruss/pruss_intc_mapping.h>
+
+int main(int argc, char *argv[]) {
+
+       tpruss_intc_initdata init_data = PRUSS_INTC_INITDATA;
+
+       if(argc < 2) {
+           printf("usage: %s <obj>\n", argv[0]);
+           return EINVAL;
+       } else if(geteuid()) {
+           printf("%s\n", "run as root");
+           return EACCES;
+       }
+
+       /* init pru drv */
+       if(prussdrv_init())
+           return ENXIO;
+
+       /* open, bind intr */
+       if(prussdrv_open(PRU_EVTOUT0))
+           return ENXIO;
+       if(prussdrv_pruintc_init(&init_data))
+           return ENXIO;
+
+       /* exec */
+       if(prussdrv_exec_program(0, argv[1]))
+           return ENXIO;
+
+       /* block until intr */
+       prussdrv_pru_wait_event(PRU_EVTOUT_0);
+
+       /* clean up, halt & disable pru, terminate pru drv */
+       prussdrv_pru_clear_event(PRU_EVTOUT_0, PRU0_ARM_INTERRUPT);
+       prussdrv_pru_disable(0);
+       prussdrv_exit();
+
+       return 0;
+}
+