/**HEADER********************************************************************
*
* Copyright (c) 2009 Freescale Semiconductor;
* All Rights Reserved
*
***************************************************************************
*
* THIS SOFTWARE IS PROVIDED BY FREESCALE "AS IS" AND ANY EXPRESSED OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL FREESCALE OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
**************************************************************************
*
* $FileName: usbfs_dev_main.h$
* $Version : 3.5.4.0$
* $Date    : Dec-17-2009$
*
* Comments:
*
*   This file contains the macros, function prototypes and data structure
*   definitions required by the Full Speed USB Device Controller driver.
*
*END************************************************************************/

#ifndef __usbfs_dev_main_h__
#define __usbfs_dev_main_h__

#include "usbprv_fs.h"

#ifdef __ICCCF__
    #pragma segment="USB_BDT_Z"
//    #pragma location="USB_BDT_Z"
    __no_init static uint_8 bdt[512] @ "USB_BDT_Z";
#else
  #pragma define_section usb_bdt ".usb_bdt" RW
  __declspec(usb_bdt) static uint_8 bdt[512] = { 1 };    // DO NOT REMOVE INITIALIZATION !!! bug in CW (cw 7.1) - generate wrong binary code, data
#endif  


#define BDT_BASE                ((uint_32*)(bdt))
#define BD_PTR(ep, rxtx, odd)   (((uint_32)BDT_BASE) & 0xfffffe00 | ((ep & 0x0f) << 5) | ((rxtx & 1) << 4) | ((odd & 1) << 3))

#define BD_CTRL(ep,rxtx,odd)    (*((uint_32*)BD_PTR(ep, rxtx, odd)))
#define BD_CTRL_RX(ep, odd)     (*((uint_32*)BD_PTR(ep, 0, odd)))
#define BD_CTRL_TX(ep, odd)     (*((uint_32*)BD_PTR(ep, 1, odd)))

#define BD_ADDR(ep,rxtx,odd)    (*((uint_32*)BD_PTR(ep, rxtx, odd) + 1))
#define BD_ADDR_RX(ep, odd)     (*((uint_32*)BD_PTR(ep, 0, odd) + 1))
#define BD_ADDR_TX(ep, odd)     (*((uint_32*)BD_PTR(ep, 1, odd) + 1))

#define _DATA0                  (MCF522X_USBOTG_BD_DATA01(0)>>6)
#define _DATA1                  (MCF522X_USBOTG_BD_DATA01(1)>>6)
#define EP_DISABLE              (0)
#define ASSERT_RESUME_DELAY_COUNT       (8000)/* Delay for assert resume */

#define INT_STAT_CLEAR_ALL        (0xFF)
#define ERR_STAT_CLEAR_ALL        (0xFF) /* Value to clear
                                            all Errors */
#define ERR_ENB_ENABLE_ALL        (0xFF)/* Value to enable
                                            all Error Interrupts */
#define INTENB_BUS_RESET_VAL      (0x9F)/* Value to enable
                                           Interrupts in Bus Reset */

#define BYTES_512                 (512)
#define BYTES_1024                (1024)
#define ENDPOINT_NUMBER_SHIFT     (4)   /* endpoint shift & mask to */
#define ENDPOINT_NUMBER_MASK      (0xf0)/* use in setting and getting status */
#define MAX_EP_BUFFER_SIZE        (64)
#define ZERO_LENGTH               (0)
#define USB_SETUP_TOKEN           (0x0d)/* Setup Token PID */
#define FRAME_HIGH_BYTE_SHIFT     (8)

/***************************************
**
** Prototypes
**/
#ifdef __cplusplus
extern "C" {
#endif

extern uint_8 _usb_dci_usbfs_init(uint_8, _usb_device_handle);
extern uint_8 _usb_dci_usbfs_send(_usb_device_handle, XD_STRUCT_PTR);
extern uint_8 _usb_dci_usbfs_recv(_usb_device_handle, XD_STRUCT_PTR);
extern uint_8 _usb_dci_usbfs_cancel(_usb_device_handle, uint_8, uint_8);
extern uint_8 _usb_dci_usbfs_set_addr(_usb_device_handle, uint_8);
extern uint_8 _usb_dci_usbfs_shutdown(_usb_device_handle);
extern uint_8 _usb_dci_usbfs_get_setup_data(_usb_device_handle, uint_8, uchar_ptr);
extern uint_8 _usb_dci_usbfs_assert_resume(_usb_device_handle);
extern uint_8 _usb_dci_usbfs_stall_endpoint(_usb_device_handle, uint_8, uint_8);

extern uint_8 _usb_dci_usbfs_init_endpoint(_usb_device_handle, XD_STRUCT_PTR);
extern uint_8 _usb_dci_usbfs_deinit_endpoint(_usb_device_handle, uint_8, uint_8);
extern uint_8 _usb_dci_usbfs_unstall_endpoint(_usb_device_handle, uint_8, uint_8);
extern uint_8 _usb_dci_usbfs_get_endpoint_status(_usb_device_handle, uint_8, uint_16_ptr);
extern uint_8 _usb_dci_usbfs_set_endpoint_status(_usb_device_handle, uint_8, uint_16);
extern uint_8 _usb_dci_usbfs_get_transfer_status(_usb_device_handle,uint_8,uint_8);

#ifdef __cplusplus
}
#endif

#endif