/* usb/sys/fastacc.h
 *
 * (c) 2002 Simtec Electronics
 *
 * Ben Dooks
 *
 * Definitions of fast access calls (depreciated - use the generic calls )
 *
 * $Id: fastacc.h,v 1.17 2003/08/07 22:16:25 ben Exp $
 *
 * This Library file is part of the Simtec Electronics USB stack development
 *   suite.
 * Specific licence is granted to use this file by third parties for the
 *   development of USB device drivers.
 *
 */

#ifndef __RISCOS_USBLIB_FASTACC_H
#define __RISCOS_USBLIB_FASTACC_H "$Id: fastacc.h,v 1.17 2003/08/07 22:16:25 ben Exp $"

/** This function initialises the fast-access block held within the
    library. The slow variants of this will just return zero
@memo Initialise fast acces library routines.
@return int True for sucessful init
*/
extern int usb_fast_access_init(void);

/** Gets fast access information
@memo Gets fast access information
@return number of pointers filled in in function_address_array array
@param function_address_array array to place function address in
@param no_of_array_elements size of array
@param result pointer to result code
@see SWI_USB_FastAccessInformation
*/
extern int usb_fast_access_information(unsigned long *function_address_array,
				       int no_of_array_elements,
				       int *result);

/** Returns information about a given endpoint.
@return result
@param function_address_array array to place info about endpoint
@param no_of_array_elements array size
@param act_device device
@param result pointer to result code
@memo Returns information about a given endpoint.
@see SWI_USB_EndpointInformation
*/
extern int  usb_endpoint_information(unsigned long *function_address_array,
				     int no_of_array_elements,
				     void *act_device,
				     int *result);

/* bits to make usb_request_start callable by the C veneer */

/** USB request start structure.
@memo USB request start structure.
*/
struct usb_reqstart {
	usb_buffer_t *buffer;
	usb_buffer_t *additional_buffer;
	usb_wait_t *request_waiting_mode;
	int *result;
};

/** fast access structure.
@memo fast access structure.
*/
struct usb_fast_access_struct {
  struct usb_dynamic_area_s *usb_dynamic_area;
  void                      *pw;

  int (*usb_frame_sync_number)(void *act_hostcontroller,
			       unsigned long frame_number);

  struct usb_transaction_basic_s *(*usb_transaction_get_pending)(void *act_endpoint,
								    int *result);

  struct usb_transaction_basic_s *(*usb_request_get_pending)(void *act_hostcontroller,
								unsigned long frame_number,
								unsigned long pattern_mask,
								int *result);

  int (*usb_transaction_result)(struct usb_transaction_basic_s *act_transaction,
				int *transaction_result);

  usb_wait_t *(*usb_request_start)(void *act_endpoint,
				   unsigned long transaction_information,
				   long first_frame_to_send,
				   struct usb_reqstart *info);

  int (*usb_request_get_state)(usb_wait_t *waitmode,
			       int *result);
  
  void * (*_usb_malloc)(size_t size);
  void   (*_usb_free)(void *ptr);
  void * (*_usb_realloc)(void *ptr, size_t size);
  
  int    (*usb_sendmsg)(struct usbmsg *msg);

  /* debugging variants of usb memory calls */
  void * (*usb_dbg_malloc)(size_t sz, const char *src, int line);
  void   (*usb_dbg_free)(void *ptr, const char *src, int line);
  void * (*usb_dbg_realloc)(void *ptr, size_t sz, const char *src, int line);
};

/* struct usb_fast_access_vstruct
 *
 * representation of struct usb_fast_access_struct using void *s instead
 * of real function types. This must be kept in synchronisation with the
 * definition of struct usb_fast_access_struc.
*/

struct usb_fast_access_vstruct {
  void    *da;
  void    *pw;

  void    *usb_frame_sync_number;
  void    *usb_transaction_get_pending;
  void    *usb_request_get_pending;
  void    *usb_transaction_result;
  void    *usb_request_start;
  void    *usb_request_get_state;
  void    *_usb_malloc;
  void    *_usb_free;
  void    *_usb_realloc;
  void    *usb_sendmsg;

  void    *usb_dbg_malloc;
  void    *usb_dbg_free;
  void    *usb_dbg_realloc;
};

extern struct usb_fast_access_struct usb_fast_access;

#endif /* __RISCOS_USBLIB_FASTACC_H */
