/*
 *               Copyright (C) 2005, BroadOn Communications Corp.
 *
 *  These coded instructions, statements, and computer programs contain
 *  unpublished  proprietary information of BroadOn Communications Corp.,
 *  and  are protected by Federal copyright law. They may not be disclosed
 *  to  third  parties or copied or duplicated in any form, in whole or in
 *  part, without the prior written consent of BroadOn Communications Corp.
 *
 */
/* Write a test pattern to interrupt endpoint in G15 keyboard.
 * Random pattern - not intended to do anything.
 */

#include <iostypes.h>
#include <ios.h>
#include <iop.h>
#include <ioslibc.h>

#ifndef ENABLE_TEST
#define STACK_SIZE 2048
const u8        _initStack[STACK_SIZE];
const u32       _initStackSize = sizeof(_initStack);
const u32       _initPriority = 20;
#endif /* ENABLE_TEST */

//u8 rdrStack[1024];
static IOSFd fd0;

#include "iosusbtypes.h"
#include "iosusb.h"

static u8 data[32];
static void
__writeTest(IOSFd fd)
{
    IOSError rv; 
    memset(data, 0xab, sizeof(data));
    if ((rv = IUSB_WriteIntrMsg(fd, 0x2, sizeof(data), data)) <= 0) {
        printf("WriteIntrMsg failed: %d\n", rv);
    }
    printf("WriteIntrMsg returned: %d\n", rv);
}

#ifdef ENABLE_TEST
void
ohci_test(u32 arg)
#else
void
main(u32 arg)
#endif
{
    usleep(100000); /* wait for device enumeration etc. */
    fd0 = IOS_Open("/dev/usb/oh0/046d/c222", 0);
    if (fd0 < 0) {
        printf("open failed: %d\n", fd0);
        goto done;
    }
    while (1) {
        __writeTest(fd0);
        usleep(1000);
    }
done:
    IOS_DestroyThread(0, NULL);
    return;
}
