Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
98 lines (86 sloc) 2.404 kB
/*
* Test code for communicating with Renesas RX62N Demonstration Kit
*
* Copyright (c) 2011 Andreas Färber <andreas.faerber@web.de>
*
* Licensed under the GNU GPL version 2 or (at your option) any later version.
*/
#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
#include <libusb-1.0/libusb.h>
#include "rx.h"
#include "jlink.h"
static libusb_device_handle *jlink_open(libusb_context *usb_context)
{
libusb_device_handle *handle;
handle = libusb_open_device_with_vid_pid(usb_context, USB_VID_SEGGER, USB_PID_SEGGER_JLINK);
if (handle == NULL)
return NULL;
int ret;
ret = libusb_kernel_driver_active(handle, 0);
if (ret == 1) {
printf("kernel driver active\n");
} else if (ret == 0) {
//printf("kernel driver not active\n");
} else {
fprintf(stderr, "libusb_kernel_driver_active = %d\n", ret);
}
ret = libusb_claim_interface(handle, 0);
if (ret != LIBUSB_SUCCESS) {
fprintf(stderr, "claiming interface failed: %d\n", ret);
libusb_close(handle);
return NULL;
}
return handle;
}
static void jlink_close(libusb_device_handle *handle)
{
libusb_release_interface(handle, 0);
libusb_close(handle);
}
static void test(libusb_device_handle *handle)
{
char* version;
int ret = jlink_get_version(handle, &version);
if (ret == 0) {
printf("J-Link version: %s\n", version);
free(version);
}
uint32_t caps = 0;
ret = jlink_get_caps(handle, &caps);
if (ret == 0) {
printf("Caps: %08" PRIx32 "\n", caps);
}
if (caps & EMU_CAP_GET_HW_VERSION) {
uint32_t hw_version;
ret = jlink_get_hw_version(handle, &hw_version);
if (ret == 0) {
printf("J-Link hardware version: %" PRIu32 "\n", hw_version);
}
}
}
static void connect(libusb_context *usb_context)
{
printf("Opening RX62N device...\n");
libusb_device_handle *handle = jlink_open(usb_context);
if (handle == NULL) {
fprintf(stderr, "Opening the device failed.\n");
return;
}
test(handle);
jlink_close(handle);
}
int main(void)
{
int ret;
libusb_context *usb_context;
ret = libusb_init(&usb_context);
if (ret != 0) {
fprintf(stderr, "USB init failed.\n");
return -1;
}
connect(usb_context);
libusb_exit(usb_context);
return 0;
}
Jump to Line
Something went wrong with that request. Please try again.