3bef1cab |
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 | |
f828c748 |
27 | #define PRU_NUM 1 |
28 | |
3bef1cab |
29 | int main(int argc, char *argv[]) { |
30 | |
31 | tpruss_intc_initdata init_data = PRUSS_INTC_INITDATA; |
32 | |
33 | if(argc < 2) { |
34 | printf("usage: %s <obj>\n", argv[0]); |
35 | return EINVAL; |
36 | } else if(geteuid()) { |
37 | printf("%s\n", "run as root"); |
38 | return EACCES; |
39 | } |
40 | |
41 | /* init pru drv */ |
42 | if(prussdrv_init()) |
43 | return ENXIO; |
44 | |
45 | /* open, bind intr */ |
1f27fd48 |
46 | if(prussdrv_open(PRU_EVTOUT_0)) |
3bef1cab |
47 | return ENXIO; |
48 | if(prussdrv_pruintc_init(&init_data)) |
49 | return ENXIO; |
50 | |
51 | /* exec */ |
f828c748 |
52 | if(prussdrv_exec_program(PRU_NUM, argv[1])) |
3bef1cab |
53 | return ENXIO; |
54 | |
55 | /* block until intr */ |
56 | prussdrv_pru_wait_event(PRU_EVTOUT_0); |
57 | |
58 | /* clean up, halt & disable pru, terminate pru drv */ |
59 | prussdrv_pru_clear_event(PRU_EVTOUT_0, PRU0_ARM_INTERRUPT); |
f828c748 |
60 | prussdrv_pru_disable(PRU_NUM); |
3bef1cab |
61 | prussdrv_exit(); |
62 | |
63 | return 0; |
64 | } |
65 | |