| 1 | /* |
| 2 | * Copyright (c) 2016, Ian Sutton <ian@kremlin.cc> |
| 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for |
| 5 | * any purpose with or without fee is hereby granted, provided that the |
| 6 | * above copyright notice and this permission notice appear in all |
| 7 | * copies. |
| 8 | * |
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL |
| 10 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED |
| 11 | * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE |
| 12 | * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL |
| 13 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 14 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 15 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 16 | * PERFORMANCE OF THIS SOFTWARE. |
| 17 | */ |
| 18 | |
| 19 | #include <stdio.h> |
| 20 | #include <stdlib.h> |
| 21 | #include <unistd.h> |
| 22 | #include <errno.h> |
| 23 | |
| 24 | #include <pruss/prussdrv.h> |
| 25 | #include <pruss/pruss_intc_mapping.h> |
| 26 | |
| 27 | int main(int argc, char *argv[]) { |
| 28 | |
| 29 | tpruss_intc_initdata init_data = PRUSS_INTC_INITDATA; |
| 30 | |
| 31 | if(argc < 2) { |
| 32 | printf("usage: %s <obj>\n", argv[0]); |
| 33 | return EINVAL; |
| 34 | } else if(geteuid()) { |
| 35 | printf("%s\n", "run as root"); |
| 36 | return EACCES; |
| 37 | } |
| 38 | |
| 39 | /* init pru drv */ |
| 40 | if(prussdrv_init()) |
| 41 | return ENXIO; |
| 42 | |
| 43 | /* open, bind intr */ |
| 44 | if(prussdrv_open(PRU_EVTOUT_0)) |
| 45 | return ENXIO; |
| 46 | if(prussdrv_pruintc_init(&init_data)) |
| 47 | return ENXIO; |
| 48 | |
| 49 | /* exec */ |
| 50 | if(prussdrv_exec_program(0, argv[1])) |
| 51 | return ENXIO; |
| 52 | |
| 53 | /* block until intr */ |
| 54 | prussdrv_pru_wait_event(PRU_EVTOUT_0); |
| 55 | |
| 56 | /* clean up, halt & disable pru, terminate pru drv */ |
| 57 | prussdrv_pru_clear_event(PRU_EVTOUT_0, PRU0_ARM_INTERRUPT); |
| 58 | prussdrv_pru_disable(0); |
| 59 | prussdrv_exit(); |
| 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |