usbhprv.h 11 KB
#ifndef __usbhprv_h__
#define __usbhprv_h__ 1
/*HEADER******************************************************************
**************************************************************************
*** 
*** Copyright (c) 2001-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: usbhprv.h
***
*** Comments:      
***   This file contains the internal USB Host speicifc type definitions
***                                                               
**************************************************************************
*END*********************************************************************/

#define  USBERR_ALLOC_BD_TABLE            (0xFE)

/***************************************
**
** Code macros
**
*/

/* Macro for aligning the BDT PAGE to 512 byte boundary */
#define USB_MEM512_ALIGN(n)                  ((n) + (-(n) & 511))

#ifdef __USB_OS_MQX__
/*
**
** Low-level function list structure for USB
**
** This is the structure used to store chip specific functions to be called 
** by generic layer
*/
typedef struct usb_chip_function_struct
{

   /* The device number */
   uint_32             DEV_NUM;
  
   /* The Host/Device init function */
   RETURN_CODE (_CODE_PTR_ INIT)(pointer);

   /* The function to shutdown the host/device */
   RETURN_CODE (_CODE_PTR_ SHUTDOWN)(pointer);

   /* The function to send data */
   void (_CODE_PTR_ SEND)(pointer, PIPE_DESCRIPTOR_STRUCT_PTR);

   /* The function to send setup data */
   void (_CODE_PTR_ SEND_SETUP)(pointer, PIPE_DESCRIPTOR_STRUCT_PTR);

   /* The function to receive data */
   void (_CODE_PTR_ RECV)(pointer, PIPE_DESCRIPTOR_STRUCT_PTR);
   
   /* The function to get the transfer status */
   uint_8 (_CODE_PTR_ STATUS)(pointer, PIPE_DESCRIPTOR_STRUCT_PTR);
   
   /* The function to cancel the transfer */
   void (_CODE_PTR_ CANCEL)(pointer, PIPE_DESCRIPTOR_STRUCT_PTR);
   
   /* The function to do USB sleep */
   void (_CODE_PTR_ SLEEP)(pointer);
   
   /* The function for USB bus control */
   void (_CODE_PTR_ BUS_CONTROL)(pointer, uint_8);
   
} USB_CALLBACK_FUNCTIONS_STRUCT, _PTR_ USB_CALLBACK_FUNCTIONS_STRUCT_PTR;
#endif

/* Setup */   
typedef struct
{
   uint_8   BREQUESTTYPE;   /* (bits 6:5 must be 00) */
   uint_8   BREQUEST;
   uint_16  WVALUE;
   uint_16  WINDEX;
   uint_16  WLENGTH;
} INTERNAL_USB_SETUP, _PTR_ INTERNAL_USB_SETUP_PTR;

/* Callback function storage structure */
typedef struct host_service_struct {
   uint_32              TYPE;
   void                 (_CODE_PTR_ SERVICE)(pointer, uint_32);
   struct host_service_struct _PTR_ NEXT;
} USB_SERVICE_STRUCT, _PTR_ USB_SERVICE_STRUCT_PTR;

typedef struct
{
   uint_8               ADDRESS;          /* USB bus address */
   uint_8               EP;               /* Endpoint number */
   uint_8               DIRECTION;        /* Direction - Rx or Tx */
   uint_8               INTERVAL;         /* Interval for transfer */
   uint_8               PIPETYPE;         /* Pipe type - Ctrl, Iso, Int, Bulk */
   uint_8               CURRENT_INTERVAL;
   uint_8               NAK_COUNT;
   uint_8               CURRENT_NAK_COUNT;
   uint_8               USB_PIPE_TRANSACTION_STATE;
   uint_8               STATUS;           /* 0: Current transfer status */
   uint_8               NEXTDATA01;       /* Data 0/1 synch bit for the PID */
   uint_8               MUSTSENDNULL;     /* Status stage of control transfer */
   uint_32              SOFAR;            /* number of bytes sent/recv'd so far */
   uint_32              TODO1;            /* number of bytes to send for first 
                                          ** phase 
                                          */
   uint_32              TODO2;            /* number of bytes to send for second 
                                          ** phase 
                                          */
   uint_16              MAX_PKT_SIZE;     /* Max packet size for this pipe */
   int_16               PIPE_ID;          /* Pipe ID */
   int_16               NEXT_PIPE;        /* Next pipe id for the same type of 
                                          ** pkt 
                                          */
   boolean              OPEN;
   boolean              SEND_PHASE;       /* Second phase of setup packet: 
                                          ** Send/Receive 
                                          */                                          
   boolean              PACKETPENDING;    /* Transaction pending */                                          
   uchar_ptr            TX1_PTR;          /* address of transmit buffer for 
                                          ** first phase 
                                          */
   uchar_ptr            TX2_PTR;          /* address of transmit buffer for 
                                          ** second phase 
                                          */
   uchar_ptr            RX_PTR;           /* address of receive buffer */
   boolean              FIRST_PHASE;
   /* Terminate xfer with zero length packet */
   boolean              DONT_ZERO_TERMINATE;
   uint_8               RESERVED[PIPE_RESERVED_FOR_ALIGNMENT];
} PIPE_DESCRIPTOR_STRUCT, _PTR_ PIPE_DESCRIPTOR_STRUCT_PTR;

typedef struct usb_host_state_structure {
   USB_STRUCT_PTR                      DEV_PTR;
   HOST_BDT_STRUCT_PTR                 USB_BDT_PAGE_BASE;
   HOST_BDT_STRUCT_PTR                 USB_BDT_PAGE;
   uchar_ptr                           ENDPT_HOST_RG;
   USB_SERVICE_STRUCT_PTR              SERVICE_HEAD_PTR;
   PIPE_DESCRIPTOR_STRUCT_PTR          PIPE_DESCRIPTOR_BASE_PTR;
   pointer                             CALLBACK_STRUCT_PTR;
   HOST_BDT_STRUCT_PTR                 CURRENT_BDT;
   uint_8                              DEV_NUM;
   uint_8                              USB_OUT;             
   uint_8                              USB_IN;
   /* we now use these even when we aren't buffering tokens for xmit on the 
   ** next token_done this is so we can re-xmit if an error is returned
   */
   uint_8                              USB_BUFFERED;
   uint_8                              USB_BUFFERED_TOKEN;
   uint_8                              USB_BUFFERED_ADDRESS;
   uint_8                              USB_BUFFERED_TYPE; 
   uint_8                              USB_NEXT_BUFFERED_ADDRESS;
   uint_8                              USB_NEXT_BUFFERED_TOKEN;
   uint_8                              USB_NEXT_BUFFERED_TYPE;
   uint_8                              USB_PKT_PENDING;
   uint_8                              NO_HUB;
   uint_8                              SPEED;
   uint_8                              MAX_PIPES;
   HOST_BDT_STRUCT                     USB_BUFFERED_BDT;
   HOST_BDT_STRUCT                     USB_NEXT_BUFFERED_BDT;
   HOST_BDT_STRUCT                     USB_TEMP_SND_BDT;
   HOST_BDT_STRUCT                     USB_TEMP_RCV_BDT;
   boolean                             SND_TOK_IN_PROGRESS;
   boolean                             NEXT_PKT_QUEUED;
   boolean                             USB_TOKEN_BUFFERED;
   uint_32                             HOST_WAIT;
   int_16                              CTRL_PIPE1;
   int_16                              CURRENT_PIPE_ID; 
   int_16                              NEXT_PIPE_ID;
   int_16                              CURRENT_ISO_HEAD;
   int_16                              CURRENT_ISO_TAIL;
   int_16                              CURRENT_INTR_HEAD;
   int_16                              CURRENT_INTR_TAIL;
   int_16                              CURRENT_CTRL_HEAD;
   int_16                              CURRENT_CTRL_TAIL;
   int_16                              CURRENT_BULK_HEAD;
   int_16                              CURRENT_BULK_TAIL;
} USB_HOST_STATE_STRUCT, _PTR_ USB_HOST_STATE_STRUCT_PTR;

extern USB_HOST_STATE_STRUCT_PTR usb_host_state_struct_ptr;

/* Prototypes */

#ifdef __cplusplus
extern "C" {
#endif

#ifdef __USB_OS_MQX__
extern void _usb_hci_vusb11_isr(_usb_host_handle);
#else
extern void HOST_INTERRUPT_ROUTINE_KEYWORD _usb_hci_vusb11_isr(void);
#endif
extern void _usb_host_delay(_usb_host_handle, uint_32);
extern void _usb_host_vusb11_reset_the_device(_usb_host_handle);
extern void _usb_host_vusb11_process_attach(_usb_host_handle);
extern void _usb_host_vusb11_process_detach(_usb_host_handle);
extern void _usb_host_vusb11_process_token_done(_usb_host_handle, uint_8, 
   uint_32);
extern void _usb_host_vusb11_pipe_transaction_state_02(_usb_host_handle);
extern HOST_BDT_STRUCT_PTR _usb_host_vusb11_get_next_in_bdt(_usb_host_handle);
extern HOST_BDT_STRUCT_PTR _usb_host_vusb11_get_next_out_bdt(_usb_host_handle);
extern uint_8 _bsp_get_usb_vector(uint_8);
extern pointer _bsp_get_usb_base(uint_8);
extern void _usb_host_vusb11_set_bdt_page(_usb_host_handle);
extern void _usb_host_vusb11_init_send_bdt(_usb_host_handle, PIPE_DESCRIPTOR_STRUCT_PTR);
extern void _usb_host_vusb11_init_setup_bdt(_usb_host_handle, PIPE_DESCRIPTOR_STRUCT_PTR);
extern void _usb_host_vusb11_init_recv_bdt(_usb_host_handle, PIPE_DESCRIPTOR_STRUCT_PTR);
extern void _usb_host_vusb11_sched_pending_pkts(_usb_host_handle);
extern void _usb_host_vusb11_sched_iso_pkts(_usb_host_handle);
extern void _usb_host_buffer_bdt(_usb_host_handle, HOST_BDT_STRUCT_PTR);
extern void _usb_host_buffer_next_bdt(_usb_host_handle, HOST_BDT_STRUCT_PTR);
extern void _usb_host_queue_pkts(_usb_host_handle, PIPE_DESCRIPTOR_STRUCT_PTR);
extern void _usb_host_update_current_head(_usb_host_handle, uint_8);
extern void _usb_host_update_interval_for_pipes(_usb_host_handle);
extern void _usb_host_vusb11_send_in_token(_usb_host_handle, PIPE_DESCRIPTOR_STRUCT_PTR);
extern void _usb_host_vusb11_send_out_token(_usb_host_handle, PIPE_DESCRIPTOR_STRUCT_PTR);
extern void _usb_host_vusb11_send_token(_usb_host_handle, uint_8, uint_8, uint_8);
extern void _usb_host_vusb11_resend_token(_usb_host_handle, uint_8);
extern void _usb_host_buffer_token(_usb_host_handle, uint_8, uint_8, uint_8);
extern void _usb_host_buffer_next_token(_usb_host_handle, uint_8, uint_8, uint_8);
extern void _usb_host_vusb11_initiate_correct_bdt(_usb_host_handle, PIPE_DESCRIPTOR_STRUCT_PTR);
extern uint_8 _usb_hci_vusb11_init(_usb_host_handle);
extern void _usb_hci_vusb11_send_data(_usb_host_handle, PIPE_DESCRIPTOR_STRUCT_PTR);
extern void _usb_hci_vusb11_send_setup(_usb_host_handle, PIPE_DESCRIPTOR_STRUCT_PTR);
extern void _usb_hci_vusb11_recv_data(_usb_host_handle, PIPE_DESCRIPTOR_STRUCT_PTR);
extern void _usb_hci_vusb11_cancel_transfer(_usb_host_handle, 
   PIPE_DESCRIPTOR_STRUCT_PTR);
extern void _usb_hci_vusb11_bus_control(_usb_host_handle, uint_8);   
extern void _usb_hci_vusb11_shutdown(_usb_host_handle);

#ifdef __cplusplus
}
#endif

#endif

/* EOF */