libpruio
0.0.2
AM33xx-PRU driver for digital input / output and analog input
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Pages
analyse.c
Go to the documentation of this file.
1
/*! \file analyse.c
2
\brief Example: analyse the devices configurations.
3
4
This file contains an example on how to use libpruio to read the
5
original configuration of the devices. It creates a PruIo structure
6
containing the initial data and then prints out in a human-readable
7
form.
8
9
Licence: GPLv3
10
11
Copyright 2014 by Thomas{ dOt ]Freiherr[ At ]gmx[ DoT }net
12
13
14
Compile by:
15
16
gcc -Wall -o analyse analyse.c /usr/local/lib/freebasic/fbrt0.o -lpruio -L"/usr/local/lib/freebasic/" -lfb -lpthread -lprussdrv -ltermcap -lsupc++ -Wno-unused-variable
17
18
*/
19
20
#include "stdio.h"
21
#include "../c_wrapper/pruio_c_wrapper.h"
22
#include "../c_wrapper/pruio_pins.h"
23
24
25
int
main
(
int
argc,
char
**argv)
26
{
27
PruIo
*
io
=
pruio_new
(0, 0x98, 0, 1);
/* create new driver UDT */
28
do
{
29
if
(io->
Errr
) {
30
printf(
"initialisation failed (%s)\n"
, io->
Errr
);
break
;}
31
32
int
i
;
33
for
(i = 0; i <=
PRUIO_GPIO_AZ
; i++) {
34
int
x
= i * (
PRUIO_GPIO_DATA
>> 2);
35
if
(io->
GpioOrg
[x + 4] == 2) {
36
printf(
"GPIO%d was on\n"
, i);
37
printf(
" OE: %12o\n"
, io->
GpioOrg
[x + 1]);
38
printf(
" INT0: %12o\n"
, io->
GpioOrg
[x + 2]);
39
printf(
" INT1: %12o\n"
, io->
GpioOrg
[x + 3]);
40
}
else
{
41
printf(
"GPIO%d was off, COUNT: %d\n"
, i, io->
GpioOrg
[x + 5]);
42
}
43
}
44
45
printf(
"Unlocked Pins:\n"
);
46
for
(i = 0; i <=
PRUIO_BALL_AZ
; i++) {
47
if
(io->
BallRef
[i] != 255) printf(
" %s\n"
,
pruio_gpio_get_config
(io, i));
48
}
49
50
printf(
"Locked header Pins:\n"
);
51
for
(i = 0; i <=
sizeof
(
P8_Pins
) /
sizeof
(
uint8
); i++) {
52
uint8
b
=
P8_Pins
[
i
];
53
if
(io->
BallRef
[b] == 255) printf(
" %s\n"
,
pruio_gpio_get_config
(io, b));
54
}
55
for
(i = 0; i <=
sizeof
(
P9_Pins
) /
sizeof
(
uint8
); i++) {
56
uint8
b
=
P9_Pins
[
i
];
57
if
(io->
BallRef
[b] == 255) printf(
" %s\n"
,
pruio_gpio_get_config
(io, b));
58
}
59
60
if
(io->
AdcOrg
[0]) {
61
printf(
"ADC was on\n"
);
62
printf(
" REVISION: %8X\n"
, io->
AdcOrg
[ 0]);
63
printf(
" SYSCONFIG: %12o\n"
, io->
AdcOrg
[ 4]);
64
printf(
" IRQ_STATUS_RAW: %12o\n"
, io->
AdcOrg
[ 9]);
65
printf(
" IRQ_STATUS: %12o\n"
, io->
AdcOrg
[10]);
66
printf(
" IRQENABLE_SET: %12o\n"
, io->
AdcOrg
[11]);
67
printf(
" IRQENABLE_CLR: %12o\n"
, io->
AdcOrg
[12]);
68
printf(
" IRQWAKEUP: %12o\n"
, io->
AdcOrg
[13]);
69
printf(
" DMAENABLE_SET: %12o\n"
, io->
AdcOrg
[14]);
70
printf(
" DMAENABLE_CLR: %12o\n"
, io->
AdcOrg
[15]);
71
printf(
" CRTL: %12o\n"
, io->
AdcOrg
[16]);
72
printf(
" ADCSTAT: %12o\n"
, io->
AdcOrg
[17]);
73
printf(
" ADCRANGE: %8X\n"
, io->
AdcOrg
[18]);
74
printf(
" ADC_CLKDIV: %8X\n"
, io->
AdcOrg
[19]);
75
printf(
" ADC_MISC: %12o\n"
, io->
AdcOrg
[20]);
76
printf(
" Steps: config , delay\n"
);
77
printf(
" idle step: 0x%8X\n"
, io->
AdcOrg
[22]);
78
printf(
" charge step: 0x%8X, 0x%8X\n"
, io->
AdcOrg
[23], io->
AdcOrg
[24]);
79
for
(i = 1; i <= 16; i++) {
80
int
x
= 23 + 2 *
i
;
81
printf(
" step%2d: 0x%8X, 0x%8X\n"
, i, io->
AdcOrg
[x], io->
AdcOrg
[x + 1]);
82
}
83
}
84
else
{
85
printf(
"ADC was off\n"
);
86
printf(
" REVISION: %8X\n"
, io->
AdcOrg
[1]);
87
printf(
" wakeup-count: %8X\n"
, io->
AdcOrg
[2]);
88
}
89
90
}
while
(0);
91
92
pruio_destroy
(io);
/* destroy driver structure */
93
return
0;
94
}
src
c_examples
analyse.c
Generated on Fri Jun 6 2014 13:22:54 for libpruio by
1.8.4