summaryrefslogtreecommitdiff
path: root/usb-benchmark-project/benchm_drv.c
blob: c6295f04496db28c9522da1108b351a3cd0fb850 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdlib.h>
#include <stdint.h>
#include <board.h>
#include <utility/trace.h>

#include <usb/common/core/USBGenericRequest.h>
#include <usb/device/core/USBD.h>
#include <usb/device/core/USBDDriver.h>
#include <usb/device/core/USBDDriverDescriptors.h>
#include <usb/device/core/USBDCallbacks.h>


extern const USBDDriverDescriptors usb_perf_driver_desc;

static unsigned char driver_interfaces[3];
static USBDDriver benchm_driver;


/* call-back for control EP requests from the host */
void USBDCallbacks_RequestReceived(const USBGenericRequest *req)
{
	/* forward all (other) requests to core */
	USBDDriver_RequestHandler(&benchm_driver, req);
}

void benchmark_drv_init(void)
{
	USBDDriver_Initialize(&benchm_driver, &usb_perf_driver_desc,
				driver_interfaces);
	USBD_Init();
}

const uint8_t test_data[2048];

static void wr_compl_cb(void *arg, unsigned char status, unsigned int transferred, unsigned int remain)
{
	uint8_t epnr = arg;

	/* re-start */
	if (status == 0 && remain == 0) {
		//printf(".");
		benchmark_start(epnr);
	} else
		printf("Err: EP%u wr_compl, status 0x%02u, xfr %u, remain %u\r\n",
			epnr, status, transferred, remain);
}

void benchmark_start(uint8_t epnr)
{
	USBD_Write(epnr, &test_data, sizeof(test_data), wr_compl_cb, epnr);
}
personal git repositories of Harald Welte. Your mileage may vary