/*
 *              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.
 *
 */

#ifndef __DOWNLOAD_PC_USB
#define __DOWNLOAD_PC_USB

#define MAX_PKT_SIZE                16384
#define MAX_CMD_SIZE                2048
#define USB_MAX_PKT_SIZE            64
#define MAX_KP_LEN                  2048

#define SC_IN_PIPE		            0
#define SC_OUT_PIPE	                1

#define USB_MUX_STREAM_MAGIC        0xbacf
#define USB_DEV_MUX_CTRL_ID         0 
#define USB_DEV_MUX_SHELL_ID        4
#define USB_DEV_MUX_PRINTF_ID       2

typedef struct {
    unsigned short magic;           /* magic number */  
    unsigned short protonum;        /* type (to make simple, it is id) */
    unsigned short length;          /* length */
    unsigned short check;           /* not used */
    unsigned char  cachelinePad[8]; /* Make header cacheline align to eliminate bcopy */
} USBStreamHeader;

#define SHELL_RCV_SMALL_PCKET        -0x80
#define SHELL_RCV_OUT_OF_SYNC		 -0x81
#define SHELL_RCV_INVALID_LEN        -0x81    
#define SHELL_RCV_BUFFER_ERR         -0x82 

/* Kilopass Id checkup macros */
#define KP_MATCH_DONE                1
#define KP_NOT_PROG                  0

void dbgPrintf(char *s);

BOOL isUsbConnected();
HANDLE  open_usb_pipe(int which);
int shellInit();
int shellClose();
int hostSend(void *p, int n);
int hostRecv(void *p, int n);

int saveIds(FILE *fp, char *id, char *kpbuf);
int checkKpProg(char *dir, char *id, char *kpid);

int shellVer(char *cmd, char *ver);
int semihost();
int shellImport(char *cmd);
int shellWriteBoot(char *cmd);
int shellFormat(char *cmd);
int shellReadId(char *buf);
int shellProgId(char *barcode, char *idFile, int verify);
int shellPut(char *cmd);
int shellRm(char *cmd);
int shellDate(char *cmd, char *ret);
int shellMkdir(char *cmd);

#endif