add regfile access utility

This commit is contained in:
Benjamin Krill 2013-12-05 11:09:23 +01:00
parent a63dfb4372
commit 0f5947ee39
3 changed files with 127 additions and 1 deletions

View File

@ -8,10 +8,18 @@ BIN_STRM_DDR2 = strm_ddr2
SRC_STRM_DDR2 = strm_ddr2.c
OBJ_STRM_DDR2 = $(SRC_STRM_DDR2:%.c=%.o)
all: ${BIN_STRM_DDR2}
BIN_STRM_REGFILE = strm_regfile
SRC_STRM_REGFILE = strm_regfile.c
OBJ_STRM_REGFILE = $(SRC_STRM_REGFILE:%.c=%.o)
all: ${BIN_STRM_DDR2} ${BIN_STRM_REGFILE}
${BIN_STRM_DDR2}: ${OBJ_STRM_DDR2}
${LD} ${LDFLAGS} $^ -o $@ ${LDFLAGS_POST}
${BIN_STRM_REGFILE}: ${OBJ_STRM_REGFILE}
${LD} ${LDFLAGS} $^ -o $@ ${LDFLAGS_POST}
clean:
rm -f *.o ${BIN_STRM_DDR2}

112
linux/apps/strm_regfile.c Normal file
View File

@ -0,0 +1,112 @@
/* *****************************************************************************
* Copyright (c) 2013 Benjamin Krill <benjamin@krll.de>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* ****************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <time.h>
#include <usb.h>
#include <strm.h>
static void
show_usage(char *name)
{
printf("USAGE: %s <reg_address> [<value>]\n"
"\treg_address: address of the register\n"
"\tvalue: value to write, when not set register will be read\n"
, name);
return;
}
int
main(int argc, char **argv)
{
uint32_t *buf, value;
int address, write = 0;
int ret = -1;
usb_dev_handle *hd;
if (argc < 2 || argc > 3) {
show_usage(argv[0]);
exit(1);
}
/* check for <value> */
if (argc == 2)
write = 1;
/* init usb connection */
if ((hd = strm_init(0x04b4, 0x2342)) == NULL) {
perror("cannot init usb2strm interface");
exit(1);
}
address = strtoull(argv[1], NULL, 0);
buf = (uint32_t*)malloc(4+8);
if (buf == NULL) {
perror("cannot allocate memory\n");
goto out;
}
if (write == 1) {
value = strtoull(argv[2], NULL, 0);
buf[0] = STRM_TYPE_REGFILE << 28 | 2;
buf[1] = STRM_REGFILE_WRITE_HDR_INIT(address >> 2);
buf[2] = value;
printf("address=0x%x value=0x%04x - ", address, value);
if ((ret = usb_bulk_write(hd, 2, (const char *)buf, 4+8, 1000)) < 0) {
fprintf(stderr, "\nFAILED: write bulk transfer (%d) [%s].\n\t%s\n", ret,
__func__, usb_strerror());
}
} else {
buf[0] = STRM_TYPE_REGFILE << 28 | 1;
buf[1] = STRM_DDR2_READ_HDR_INIT(address >> 2);
printf("address=0x%x ", address);
if ((ret = usb_bulk_write(hd, 2, (const char *)buf, 8, 1000)) < 0) {
fprintf(stderr, "\nFAILED: write bulk transfer (%d) [%s].\n\t%s\n", ret,
__func__, usb_strerror());
goto free;
}
if ((ret = usb_bulk_read(hd, 6, (char *)buf, 4+4, 6000000)) < 0) {
fprintf(stderr, "\nFAILED: read bulk transfer (%d) [%s].\n\t%s\n", ret,
__func__, usb_strerror());
goto free;
}
printf("value=0x%04x\n", buf[1]);
}
free:
free(buf);
out:
strm_fini();
return 0;
}

View File

@ -31,6 +31,12 @@
#define STRM_DDR2_READ_HDR_INIT(addr) \
(uint32_t)(~(0x1 << 31) & (addr & 0x0fffffff))
#define STRM_TYPE_REGFILE 0x2
#define STRM_REGFILE_WRITE_HDR_INIT(addr) \
(uint32_t)(0x80000000 | (addr & 0x0fffffff))
#define STRM_REGFILE_READ_HDR_INIT(addr) \
(uint32_t)(~(0x1 << 31) & (addr & 0x0fffffff))
/* prototypes */
usb_dev_handle *strm_init(int vendor, int product);
int strm_fini(void);