113 lines
3.2 KiB
C
113 lines
3.2 KiB
C
/* *****************************************************************************
|
|
* 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;
|
|
}
|