aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVijay Kumar B <vijaykumar@bravegnu.org>2009-09-21 01:54:00 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2009-12-11 15:23:09 -0500
commit763a998fb2d93ff86a8d1bf7bad84f640f668727 (patch)
treea27b39c0dc3923a4aefe766d5539ec8dbfb0b24d
parent949d6ae745ba2fa34bc983bb808c814898d5b77d (diff)
Staging: poch: Add sample Rx code
Add sample code Rx to README. Signed-off-by: Vijay Kumar B <vijaykumar@bravegnu.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--drivers/staging/poch/README123
1 files changed, 123 insertions, 0 deletions
diff --git a/drivers/staging/poch/README b/drivers/staging/poch/README
index 600121f7d67..ac76ff969a2 100644
--- a/drivers/staging/poch/README
+++ b/drivers/staging/poch/README
@@ -9,5 +9,128 @@ TODO:
9 - audit userspace interfaces 9 - audit userspace interfaces
10 - get reserved major/minor if needed 10 - get reserved major/minor if needed
11 11
12Sample Code:
13
14#include <sys/types.h>
15#include <sys/stat.h>
16#include <sys/mman.h>
17#include <sys/ioctl.h>
18#include <poll.h>
19#include <stdio.h>
20#include <error.h>
21#include <errno.h>
22#include <fcntl.h>
23#include <stdint.h>
24
25#include <sysfs/libsysfs.h>
26
27#include <poch.h>
28
29struct pconsume {
30 uint32_t * offsets;
31 uint32_t nfetch;
32 uint32_t nflush;
33};
34
35uint32_t offsets[10];
36
37void process_group(unsigned char *buf, uint32_t size)
38{
39 uint16_t *buf16 = (uint16_t *)buf;
40
41 printf("RX: %p %u %04x %04x %04x %04x %04x %04x\n", buf, size,
42 buf16[0], buf16[1], buf16[2], buf16[3], buf16[4], buf16[5]);
43}
44
45int main()
46{
47 struct sysfs_attribute *attr;
48 char *path;
49 int ret;
50 unsigned long mmap_size;
51 int fd;
52 unsigned char *cbuf;
53
54 uint32_t nflush;
55 struct pollfd poll_fds;
56 int count = 0;
57 int i;
58
59 path = "/sys/class/pocketchange/poch0/ch0/block_size";
60 attr = sysfs_open_attribute(path);
61 ret = sysfs_write_attribute(attr, "256", strlen("256"));
62 if (ret == -1)
63 error(1, errno, "error writing attribute %s", path);
64 sysfs_close_attribute(attr);
65
66 path = "/sys/class/pocketchange/poch0/ch0/group_size";
67 attr = sysfs_open_attribute(path);
68 ret = sysfs_write_attribute(attr, "4096", strlen("4096"));
69 if (ret == -1)
70 error(1, errno, "error writing attribute %s", path);
71 sysfs_close_attribute(attr);
72
73 path = "/sys/class/pocketchange/poch0/ch0/group_count";
74 attr = sysfs_open_attribute(path);
75 ret = sysfs_write_attribute(attr, "64", strlen("64"));
76 if (ret == -1)
77 error(1, errno, "error writing attribute %s", path);
78 sysfs_close_attribute(attr);
79
80 fd = open("/dev/ch0", O_RDWR);
81 if (fd == -1)
82 error(1, errno, "error opening device node");
83
84 path = "/sys/class/pocketchange/poch0/ch0/mmap_size";
85 attr = sysfs_open_attribute(path);
86 ret = sysfs_read_attribute(attr);
87 if (ret == -1)
88 error(1, errno, "error reading attribute %s", path);
89 printf("%s", attr->value);
90 sscanf(attr->value, "%lu", &mmap_size);
91 sysfs_close_attribute(attr);
92
93 cbuf = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE,
94 MAP_PRIVATE, fd, 0);
95 if (cbuf == MAP_FAILED)
96 error(1, errno, "error mapping DMA buffers");
97
98 ret = ioctl(fd, POCH_IOC_TRANSFER_START, 0);
99 if (ret == -1)
100 error(1, errno, "error starting transfer");
101
102 nflush = 0;
103 while (1) {
104 struct pconsume consume;
105
106 consume.offsets = offsets;
107 consume.nfetch = 10;
108 consume.nflush = nflush;
109
110 ret = ioctl(fd, POCH_IOC_CONSUME, &consume);
111 if (ret == -1)
112 error(1, errno, "error consuming groups");
113
114 nflush = consume.nfetch;
115
116 for (i = 0; i < nflush; i++) {
117 process_group(cbuf + consume.offsets[i], 4096);
118
119 count++;
120 if (count == 1000)
121 break;
122 }
123
124 if (count == 1000)
125 break;
126 }
127
128 ret = ioctl(fd, POCH_IOC_TRANSFER_STOP, 0);
129 if (ret == -1)
130 error(1, errno, "error starting transfer");
131
132 return 0;
133}
134
12Please send patches to Greg Kroah-Hartman <greg@kroah.com> and 135Please send patches to Greg Kroah-Hartman <greg@kroah.com> and
13Vijay Kumar <vijaykumar@bravegnu.org> and Jaya Kumar <jayakumar.lkml@gmail.com> 136Vijay Kumar <vijaykumar@bravegnu.org> and Jaya Kumar <jayakumar.lkml@gmail.com>