You can now transfer gibberish from the FluxEngine to the PC to test bandwidth.
On Windows we're getting 620kB/s.
This commit is contained in:
parent
c174e5cafe
commit
e5155d98cc
5 changed files with 85 additions and 7 deletions
|
|
@ -14,12 +14,13 @@
|
|||
#define STEP_TOWARDS0 1
|
||||
#define STEP_AWAYFROM0 0
|
||||
|
||||
static uint32_t clock = 0;
|
||||
static volatile uint32_t clock = 0;
|
||||
static volatile bool index_irq = false;
|
||||
|
||||
static bool motor_on = false;
|
||||
static uint32_t motor_on_time = 0;
|
||||
static bool homed = false;
|
||||
static int current_track = 0;
|
||||
static volatile bool index_irq = false;
|
||||
|
||||
#if 0
|
||||
static uint8_t td[BUFFER_COUNT];
|
||||
|
|
@ -107,10 +108,15 @@ CY_ISR(dma_finished_isr)
|
|||
}
|
||||
#endif
|
||||
|
||||
static void wait_until_writeable(int ep)
|
||||
{
|
||||
while (USBFS_GetEPState(ep) != USBFS_IN_BUFFER_EMPTY)
|
||||
;
|
||||
}
|
||||
|
||||
static void send_reply(struct any_frame* f)
|
||||
{
|
||||
while (USBFS_GetEPState(FLUXENGINE_CMD_IN_EP_NUM) != USBFS_IN_BUFFER_EMPTY)
|
||||
;
|
||||
wait_until_writeable(FLUXENGINE_CMD_IN_EP_NUM);
|
||||
USBFS_LoadInEP(FLUXENGINE_CMD_IN_EP_NUM, (uint8_t*) f, f->f.size);
|
||||
}
|
||||
|
||||
|
|
@ -172,23 +178,41 @@ static void cmd_measure_speed(struct any_frame* f)
|
|||
{
|
||||
start_motor();
|
||||
|
||||
UART_PutString("wait for index\n");
|
||||
index_irq = false;
|
||||
while (!index_irq)
|
||||
;
|
||||
index_irq = false;
|
||||
int start_clock = clock;
|
||||
UART_PutString("wait for another index\n");
|
||||
while (!index_irq)
|
||||
;
|
||||
int end_clock = clock;
|
||||
UART_PutString("done\n");
|
||||
|
||||
DECLARE_REPLY_FRAME(struct speed_frame, F_FRAME_MEASURE_SPEED_REPLY);
|
||||
r.period_ms = end_clock - start_clock;
|
||||
send_reply((struct any_frame*) &r);
|
||||
}
|
||||
|
||||
static void cmd_bulk_test(struct any_frame* f)
|
||||
{
|
||||
uint8_t buffer[64];
|
||||
|
||||
for (int x=0; x<16; x++)
|
||||
for (int y=0; y<256; y++)
|
||||
{
|
||||
for (unsigned z=0; z<sizeof(buffer); z++)
|
||||
buffer[z] = x+y+z;
|
||||
|
||||
wait_until_writeable(FLUXENGINE_DATA_IN_EP_NUM);
|
||||
USBFS_LoadInEP(FLUXENGINE_DATA_IN_EP_NUM, buffer, sizeof(buffer));
|
||||
}
|
||||
|
||||
wait_until_writeable(FLUXENGINE_DATA_IN_EP_NUM);
|
||||
USBFS_LoadInEP(FLUXENGINE_DATA_IN_EP_NUM, NULL, 0);
|
||||
|
||||
DECLARE_REPLY_FRAME(struct any_frame, F_FRAME_BULK_TEST_REPLY);
|
||||
send_reply(&r);
|
||||
}
|
||||
|
||||
static void handle_command(void)
|
||||
{
|
||||
static uint8_t input_buffer[FRAME_SIZE];
|
||||
|
|
@ -210,6 +234,10 @@ static void handle_command(void)
|
|||
cmd_measure_speed(f);
|
||||
break;
|
||||
|
||||
case F_FRAME_BULK_TEST_CMD:
|
||||
cmd_bulk_test(f);
|
||||
break;
|
||||
|
||||
default:
|
||||
send_error(F_ERROR_BAD_COMMAND);
|
||||
}
|
||||
|
|
@ -256,9 +284,14 @@ int main(void)
|
|||
UART_PutString("USB ready\r");
|
||||
//CyDmaChEnable(dma_channel, true);
|
||||
USBFS_EnableOutEP(FLUXENGINE_CMD_OUT_EP_NUM);
|
||||
USBFS_EnableOutEP(FLUXENGINE_DATA_OUT_EP_NUM);
|
||||
}
|
||||
|
||||
if (USBFS_GetEPState(FLUXENGINE_CMD_OUT_EP_NUM) == USBFS_OUT_BUFFER_FULL)
|
||||
{
|
||||
UART_PutString("incoming USB command\r");
|
||||
handle_command();
|
||||
USBFS_EnableOutEP(FLUXENGINE_CMD_OUT_EP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
#include "protocol.h"
|
||||
|
||||
extern void error(const char* message, ...);
|
||||
extern double gettime(void);
|
||||
|
||||
extern void usb_init(void);
|
||||
extern void usb_cmd_send(void* ptr, int len);
|
||||
|
|
@ -21,5 +22,6 @@ extern void usb_cmd_recv(void* ptr, int len);
|
|||
extern int usb_get_version(void);
|
||||
extern void usb_seek(int track);
|
||||
extern int usb_measure_speed(void);
|
||||
extern void usb_bulk_test(void);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
2
main.c
2
main.c
|
|
@ -51,6 +51,8 @@ int main(int argc, char* const* argv)
|
|||
int period_ms = usb_measure_speed();
|
||||
printf("Rotational period is %d ms (%f rpm)\n", period_ms, 60000.0/period_ms);
|
||||
|
||||
usb_bulk_test();
|
||||
|
||||
#if 0
|
||||
parse_options(argc, argv);
|
||||
if (!serialport)
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ enum
|
|||
F_FRAME_SEEK_REPLY, /* any_frame */
|
||||
F_FRAME_MEASURE_SPEED_CMD, /* any_frame */
|
||||
F_FRAME_MEASURE_SPEED_REPLY, /* speed_frame */
|
||||
F_FRAME_BULK_TEST_CMD, /* any_frame */
|
||||
F_FRAME_BULK_TEST_REPLY, /* any_frame */
|
||||
};
|
||||
|
||||
enum
|
||||
|
|
|
|||
39
usb.c
39
usb.c
|
|
@ -97,3 +97,42 @@ int usb_measure_speed(void)
|
|||
return r->period_ms;
|
||||
}
|
||||
|
||||
static void large_bulk_transfer(int ep, void* buffer, int total_len)
|
||||
{
|
||||
int count = 0;
|
||||
while (count < total_len)
|
||||
{
|
||||
int len = total_len - count;
|
||||
int i = libusb_bulk_transfer(device, ep,
|
||||
((uint8_t*)buffer)+count, len, &len, TIMEOUT);
|
||||
if (i < 0)
|
||||
error("data transfer failed: %s", libusb_strerror(i));
|
||||
count += len;
|
||||
}
|
||||
}
|
||||
|
||||
void usb_bulk_test(void)
|
||||
{
|
||||
struct any_frame f = { .f = {.type = F_FRAME_BULK_TEST_CMD, .size = sizeof(f)} };
|
||||
usb_cmd_send(&f, f.f.size);
|
||||
|
||||
uint8_t bulk_buffer[16*256*64];
|
||||
int total_len = sizeof(bulk_buffer);
|
||||
double start_time = gettime();
|
||||
large_bulk_transfer(FLUXENGINE_DATA_IN_EP, bulk_buffer, total_len);
|
||||
double elapsed_time = gettime() - start_time;
|
||||
|
||||
printf("Transferred %d bytes in %d ms (%d kB/s)\n",
|
||||
total_len, (int)(elapsed_time * 1000.0),
|
||||
(int)((total_len / 1024.0) / elapsed_time));
|
||||
for (int x=0; x<16; x++)
|
||||
for (int y=0; y<256; y++)
|
||||
for (int z=0; z<64; z++)
|
||||
{
|
||||
int offset = x*16384 + y*64 + z;
|
||||
if (bulk_buffer[offset] != (uint8_t)(x+y+z))
|
||||
error("data transfer corrupted at 0x%x (%d.%d.%d)", offset, x, y, z);
|
||||
}
|
||||
|
||||
await_reply(F_FRAME_BULK_TEST_REPLY);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue