-
Notifications
You must be signed in to change notification settings - Fork 4
/
uio_pruss_test.c
64 lines (51 loc) · 1.24 KB
/
uio_pruss_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
#include <prussdrv.h>
#include <PRUserial485.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#define SZ_12K 0x3000
enum ioctl_cmd {
PRUSS_CLEAN = 10,
PRUSS_MODE,
PRUSS_SET_SYNC_STEP,
PRUSS_SET_PULSE_COUNT_SYNC,
PRUSS_GET_HW_ADDRESS,
PRUSS_BAUDRATE,
PRUSS_TIMEOUT,
PRUSS_GET_PULSE_COUNT_SYNC,
PRUSS_CLEAR_PULSE_COUNT_SYNC,
PRUSS_START_SYNC,
PRUSS_STOP_SYNC,
};
int main () {
int ret, fd, i;
char receive[SZ_12K];
fd = open("/dev/pruss485", O_RDWR);
ioctl(fd, PRUSS_CLEAN);
ioctl(fd, PRUSS_MODE, 'M');
ioctl(fd, PRUSS_SET_SYNC_STEP);
ioctl(fd, PRUSS_SET_PULSE_COUNT_SYNC, 0);
ioctl(fd, PRUSS_BAUDRATE, 12);
ioctl(fd, PRUSS_GET_HW_ADDRESS);
ioctl(fd, PRUSS_TIMEOUT, 8);
ioctl(fd, PRUSS_SET_PULSE_COUNT_SYNC, 0x0102);
printf("PRUSS_GET_PULSE_COUNT_SYNC = 0x%02x\n", ioctl(fd, PRUSS_GET_PULSE_COUNT_SYNC));
printf("Reading from the device...\n");
ret = read(fd, receive, SZ_12K);
if (ret < 0){
perror("Failed to read the message from the device.");
return errno;
}
for (i = 0; i < 100; i++) {
printf("[%2d] = 0x%02x ", i, receive[i]);
if (!((i+1)%8))
printf("\n");
}
printf("End of the program\n");
close(fd);
return 0;
}