From: kremlin Date: Thu, 21 Jan 2016 00:54:56 +0000 (-0500) Subject: add simple pru loader X-Git-Url: https://uglyman.kremlin.cc/gitweb/gitweb.cgi?a=commitdiff_plain;h=3bef1cab9b21bda4c53f349223a7c85a62f2ca17;p=capstone.git add simple pru loader --- diff --git a/src/pru_loader.c b/src/pru_loader.c new file mode 100644 index 0000000..e0e9c17 --- /dev/null +++ b/src/pru_loader.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2016, Ian Sutton + * + * 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 +#include +#include +#include + +#include +#include + +int main(int argc, char *argv[]) { + + tpruss_intc_initdata init_data = PRUSS_INTC_INITDATA; + + if(argc < 2) { + printf("usage: %s \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; +} +