host.h 4.91 KB
#ifndef _host_h_
#define _host_h_ 1
/*HEADER****************************************************************
************************************************************************
***
*** Copyright (c) 1992-2002 ARC International
*** All rights reserved
***
*** This software embodies materials and concepts which are
*** confidential to ARC International and is made available solely
*** pursuant to the terms of a written license agreement with
*** ARC International.
***
*** File: host.h
***
*** Comments:  
***            
***
************************************************************************
*END*******************************************************************/

#ifdef USB_DEBUG
extern int dramPrintf(const char *fmt, ...);
extern void drambufswitch(int);
#define	PRINTF	dramPrintf
#define	printf	dramPrintf
#else
#define PRINTF(format, args...)
#define printf(format, args...)
#define drambufswitch(i)
#endif /* !USB_DEBUG */

#define  USB_STR_SIZE		64
#define  DEMO_CONFIG_DESC_SIZE	64
#define  BIDIRECTIONAL		0x4d

/* Setup */   
typedef struct
{
   uchar     BREQUESTTYPE;
   uchar     BREQUEST;
   uint_16   WVALUE;
   uint_16   WINDEX;
   uint_16   WLENGTH;
} USB_SETUP, _PTR_ USB_SETUP_PTR;

/* Standard Device decriptors */
typedef struct dev_desc
{
   uchar    BLENGTH;
   uchar    BDESCTYPE;
   uint_16  BCDUSB;
   uchar    BDEVICECLASS;
   uchar    BDEVICESUBCLASS;
   uchar    BDEVICEPROTOCOL;
   uchar    BMAXPACKETSIZE;
   uint_16  IDVENDOR;
   uint_16  IDPRODUCT;
   uint_16  BCDDEVICE;
   uchar    BMANUFACTURER;
   uchar    BPRODUCT;
   uchar    BSERIALNUMBER;
   uchar    BNUMCONFIGURATIONS;
} USB_DEV_DESC, _PTR_ USB_DEV_DESC_PTR, usb_dev_desc;

typedef struct usb_host_driver_funcs_s {
	int (*match)(usb_dev_desc *);
	void (*open)(_usb_host_handle);
	void (*poll)(_usb_host_handle);
	void (*send)(_usb_host_handle, u8 *, s32, u64);
	void (*recv)(_usb_host_handle, u8 *, s32, u64);
	void (*detach)(_usb_host_handle, uint_32);
	void (*chap9)(_usb_host_handle);
} usb_host_driver_funcs;

/*
 * Host USB driver definition
 *
 * Each host side driver registers one of these structures
 * to allow the generic host code to recognize the device
 * and access the device specific driver functions.
 */
typedef struct usb_host_driver_s {
	usb_dev_desc		*desc;
	usb_host_driver_funcs	*funcs;
	char			*name;
} usb_host_driver;

/*
 * External handle used by libultra API
 */
typedef struct _usb_ext_handle_s {
	s32			uh_which;
	s32			uh_blksize;
	OSMesgQueue		*uh_mq;
	_usb_host_handle	uh_host_handle;
	__OSBbUsbMesg 		*uh_wr_msg;
	u8			*uh_wr_buffer;
	u64			uh_wr_offset;
	s32			uh_wr_len;
	__OSBbUsbMesg		*uh_rd_msg;
	u8			*uh_rd_buffer;
	u64			uh_rd_offset;
	s32			uh_rd_len;
} _usb_ext_handle;

/*
 * Global state for each USB host controller
 */
typedef volatile struct host_global_struct
{
   uint_8                  USB_CURRENT_ADDRESS;
   uint_8                  DEVICE_ADDRESS;
   int_16                  DEFAULT_PIPE;
   volatile boolean        DEVICE_ATTACHED;
   volatile boolean        ENUMERATION_DONE;
   volatile boolean        REGISTER_SERVICES;
   volatile boolean        TRANSACTION_COMPLETE;
   volatile uint_8         ENUMERATION_STATE;
   uchar                   RX_TEST_BUFFER[20];
   USB_DEV_DESC            RX_DESC_DEVICE;
   uint_8                  RX_CONFIG_DESC[DEMO_CONFIG_DESC_SIZE];
   uchar                   MFG_STR[USB_STR_SIZE];
   uchar                   PROD_STR[USB_STR_SIZE];
   usb_host_driver         *driver;
   _usb_ext_handle         *curhandle;
} HOST_GLOBAL_STRUCT, _PTR_ HOST_GLOBAL_STRUCT_PTR;

extern HOST_GLOBAL_STRUCT host_global_struct[OS_USB_MAX_CONTROLLERS];

extern _usb_host_handle		__osArcHostHandle[OS_USB_MAX_CONTROLLERS];

extern _usb_ext_handle		_usb_ext_handles[OS_USB_MAX_HANDLES];

extern USB_SETUP tx_get_status;
extern USB_SETUP tx_clear_feature;
extern USB_SETUP tx_set_feature;
extern USB_SETUP tx_synch_frame;
extern USB_SETUP tx_get_desc;
extern USB_SETUP tx_get_config_desc;
extern USB_SETUP tx_set_address;
extern USB_SETUP tx_get_config;
extern USB_SETUP tx_set_config;
extern USB_SETUP tx_set_interface;
extern USB_SETUP tx_get_interface;
extern USB_SETUP tx_get_alt_interface;
extern USB_SETUP tx_get_port_status;

#ifdef __cplusplus
extern "C" {
#endif
extern void __usb_service_ep0(_usb_device_handle, boolean, uint_8, uint_8_ptr, uint_32);
extern void __usb_reset_ep0(_usb_device_handle, boolean, uint_8, uint_8_ptr, uint_32);
extern void __usb_host_driver_register(usb_host_driver *);
extern void __usb_host_chapter9_negotiation(s32);
extern void __usb_host_process_attach(_usb_host_handle, uint_32);
extern void __usb_host_process_detach(_usb_host_handle, uint_32);
extern void __usb_host_process_host_resume(_usb_host_handle, uint_32);
extern void __usb_host_process_default_pipe(_usb_host_handle, uint_32);
extern void __usb_host_process_pipe_transaction_done(_usb_host_handle, uint_32);
extern void __usb_bus_sof(_usb_device_handle, boolean, uint_8, uint_8_ptr, uint_32);
#ifdef __cplusplus
}
#endif
#endif /* _host_h_ */