/*
 *               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.
 *
 */
#include <iostypes.h>
#include <iop.h>
#include <ioslibc.h>

#ifndef XFER_DBG
#define XFER_DBG 1
#endif /* XFER_DBG */
#include "ohci.h"
#include "ohci_regs.h"
#include "usb11.h" 
#include "ohci_core.h" 

#define STACK_SIZE 2048
const u8        _initStack[STACK_SIZE];
const u32       _initStackSize = sizeof(_initStack);
const u32       _initPriority = 20;

u32 
atohex(char *str)
{
    u32 v = 0;
    while ((*str >= '0' && *str <= '9') ||
            (*str >= 'a' && *str <= 'f') ||
            (*str >= 'A' && *str <= 'F')) {
        char c = *str++;
        if (c <= '9') c -= '0';
        else if (c <= 'F') c -= 'A'-10;
        else c -= 'a'-10;
        v = (v << 4) + c;
    }
    return v;
}

void
main(u32 arg)
{
    u8 i;
    char buf[DBG_LINE_SIZE + 1];
    u32 id;
    u32 irp;
    u16 size;
    char sreqTyp[8];
    char sTyp[8];
    char sDir[4];

   strncpy(sreqTyp,"unk", 4);
   strncpy(sTyp,"unk", 4);
   strncpy(sDir,"unk", 4);

   for (i = 0; i < DBG_LINES_MAX; ++i) {
       char *line = (char *) (DBG_BASE + i*DBG_LINE_SIZE);
       buf[DBG_LINE_SIZE] = '\0';
       memcpy(buf, line, DBG_LINE_SIZE);
       
       memset(buf, 0, sizeof(buf));
       memcpy(buf, line, 8);
       id = atohex(buf);
       if (0 == id) { /* unused line */
           continue;
       }
       line += 8;

       memset(buf, 0, sizeof(buf));
       memcpy(buf, line, 1);
       if (buf[0] == 'R') strncpy(sTyp,"Reply  ", 8);
       else if (buf[0] == 'Q') strncpy(sTyp,"Request", 8);
       ++line;
        
       memset(buf, 0, sizeof(buf));
       memcpy(buf, line, 1);
       if (buf[0] == 'C') strncpy(sreqTyp, "Ctrl", 5);
       else if (buf[0] == 'I') strncpy(sreqTyp, "Intr", 5);
       else if (buf[0] == 'B') strncpy(sreqTyp, "Bulk", 5);
       ++line;
         
       memset(buf, 0, sizeof(buf));
       memcpy(buf, line, 8);
       irp = atohex(buf);
       line += 8;
       
       memset(buf, 0, sizeof(buf));
       memcpy(buf, line, 1);
       if (buf[0] == 'i') strncpy(sDir, "In ", 4);
       else if (buf[0] == 'o') strncpy(sDir, "Out", 4);
       else strncpy(sDir," - ", 4);
       ++line;
       
       memset(buf, 0, sizeof(buf));
       memcpy(buf, line, 8);
       size = atohex(buf);
       printf("[%08x] %s %s %s Size:%04u IRP:%08x\n", id, sreqTyp,
               sTyp, sDir, size, irp);
   }
   return;
}

