-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathadcpru-test.c
110 lines (92 loc) · 3 KB
/
adcpru-test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* NXCTRL BeagleBone Black Control Library
*
* TSCADC from PRU Test Program
*
* Copyright (C) 2014 Sungjin Chun <chunsj@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <NXCTRL.h>
#include <unistd.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <errno.h>
#include <prussdrv.h>
#include <pruss_intc_mapping.h>
#define PRU_NUM PRU0 // use PRU_0
#define PRU_PATH "./adcpru-test.bin"
#define OFFSET_SHAREDRAM 2048
NXCTRL_VOID
NXCTRLSetup (NXCTRL_VOID) {
int nRet;
void *pSharedMem;
unsigned int *pnSharedMem;
tpruss_intc_initdata intc = PRUSS_INTC_INITDATA;
// initialize PRU
if ((nRet = prussdrv_init())) {
fprintf(stderr, "prussdrv_init() failed\n");
exit(nRet);
}
// open the interrupt
if ((nRet = prussdrv_open(PRU_EVTOUT_0))) {
fprintf(stderr, "prussdrv_open() failed: %s\n", strerror(errno));
exit(nRet);
}
// initialize interrupt
if ((nRet = prussdrv_pruintc_init(&intc))) {
fprintf(stderr, "prussdrv_pruintc_init() failed\n");
exit(nRet);
}
// load and run the PRU program
if ((nRet = prussdrv_exec_program(PRU_NUM, PRU_PATH))) {
fprintf(stderr, "prussdrv_exec_program() failed\n");
exit(nRet);
}
// wait for PRU to generate interrupt for completion indication
printf("waiting for interrupt from PRU0...\n");
nRet = prussdrv_pru_wait_event(PRU_EVTOUT_0);
printf("PRU program completed with: %d\n", nRet);
// clear the event
if (prussdrv_pru_clear_event(PRU_EVTOUT_0, PRU0_ARM_INTERRUPT))
fprintf(stderr, "prussdrv_pru_clear_event() failed\n");
// locate PRU shared RAM
if ((nRet = prussdrv_map_prumem(PRUSS0_SHARED_DATARAM, &pSharedMem))) {
fprintf(stderr, "prussdrv_map_prumem() failed\n");
exit(nRet);
}
pnSharedMem = (unsigned int *)pSharedMem + OFFSET_SHAREDRAM;
printf("AIN0 VL: %04d\n", pnSharedMem[0] & 0xFFF);
printf("IRQSTAT: "); printINT32(pnSharedMem[1]);
printf("EXITCNT: %02d\n", pnSharedMem[2]);
// halt and disable the PRU
if (prussdrv_pru_disable(PRU_NUM))
fprintf(stderr, "prussdrv_pru_disable() failed\n");
// release the PRU clocks and disable prussdrv module
if (prussdrv_exit())
fprintf(stderr, "prussdrv_exit() failed\n");
}
NXCTRL_VOID
NXCTRLLoop (NXCTRL_VOID) {
NXCTRLExitLoop();
}
int
main (void) {
return NXCTRLMain();
}