tools: add options for non-D32 access

parent 7be8a692
......@@ -7,8 +7,9 @@
#include <libvmebus.h>
static char usage_string[] =
"usage: %s [-oh?] [ -w word ] [-v vme_address]\n"
"[-s skip_bytes ] [-d data_width] "
"usage: %s [-oh?] [-w word] [-v vme_address]\n"
"[-s skip_bytes] [-d data_width] [-D effective_width]"
"[-l map_length] "
"[-a address_modifier] [-n word_count]\n";
void usage(char *prog)
......@@ -16,28 +17,39 @@ void usage(char *prog)
fprintf(stderr, usage_string, prog);
exit(1);
}
int invalid(int data_width)
{
return (data_width != 8 &&
data_width != 16 &&
data_width != 32);
}
int main(int argc, char *argv[])
{
struct vme_mapping map;
struct vme_mapping *mapp = &map;
volatile void *ptr;
unsigned int vmebase, am, data_width;
unsigned int vmebase, am, data_width, access_width;
unsigned int offset, skip_bytes;
unsigned int length;
int i, count;
int c;
int write, offsets_on;
int width;
uint32_t word;
/* vme defaults */
count = 1;
am = VME_A32_USER_DATA_SCT;
data_width = VME_D32;
data_width = access_width = VME_D32;
write = 0;
offsets_on = 1;
skip_bytes = 0;
while ((c = getopt(argc, argv, "ov:s:d:a:n:w:")) != -1) {
length = 0x80000;
while ((c = getopt(argc, argv, "ov:s:D:d:a:n:w:l:")) != -1) {
switch (c) {
case 'o':
offsets_on = 0;
......@@ -49,7 +61,16 @@ int main(int argc, char *argv[])
vmebase = strtoul(optarg, NULL, 0);
break;
case 'd':
data_width = strtoul(optarg, NULL, 0);
case 'D':
width = strtoul(optarg, NULL, 0);
if (invalid(width)) {
fprintf(stderr, "invalid data width %d\n", width);
exit(1);
}
if (c == 'd')
data_width = width;
else
access_width = width;
break;
case 'a':
am = strtoul(optarg, NULL, 0);
......@@ -57,6 +78,9 @@ int main(int argc, char *argv[])
case 'n':
count = strtoul(optarg, NULL, 0);
break;
case 'l':
length = strtoul(optarg, NULL, 0);
break;
case 'w':
write = 1;
word = strtoul(optarg, NULL, 0);
......@@ -73,8 +97,8 @@ int main(int argc, char *argv[])
memset(mapp, 0, sizeof(*mapp));
mapp->am = am;
mapp->data_width = data_width;
mapp->sizel = 0x80000;
mapp->data_width = (data_width == 8) ? 16 : data_width;
mapp->sizel = length;
mapp->vme_addrl = vmebase;
if ((ptr = vme_map(mapp, 1)) == NULL) {
......@@ -82,17 +106,41 @@ int main(int argc, char *argv[])
exit(1);
}
fprintf(stderr, "vme 0x%08x kernel 0x%p user 0x%p\n",
fprintf(stderr, "vme 0x%08x kernel %p user %p\n",
vmebase, mapp->kernel_va, mapp->user_va);
offset = skip_bytes;
for (i = 0; i < count; i++, offset += 4) {
volatile uint32_t *addr = ptr + offset;
volatile void *addr = ptr + offset;
if (!write) {
uint32_t datum;
switch (access_width) {
case 8:
datum = *(uint8_t *)addr;
break;
case 16:
datum = ntohs(*(uint16_t *)addr);
break;
case 32:
datum = ntohl(*(uint32_t *)addr);
break;
}
if (offsets_on)
printf("%08x: ", vmebase + offset);
printf("%08x\n", ntohl(*addr));
} else
*addr = htonl(word);
printf("%08x\n", datum);
} else {
switch (access_width) {
case 8:
*(uint8_t *)addr = word;
break;
case 16:
*(uint16_t *)addr = htons(word);
break;
case 32:
*(uint32_t *)addr = htonl(word);
break;
}
}
}
vme_unmap(mapp, 1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment