arc.c 4.56 KB
/*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             
***
*** $Workfile:arc.c$
*** $Revision: 1.1 $
*** $Date: 2003/02/17 20:49:00 $
***
*** Description:      
***   This file contains the USB functions specific to ARC processor.
***                                                               
**************************************************************************
*END*********************************************************************/
#ifdef __USB_OS_MQX__
#include "mqx.h"
#include "bsp.h"
#else
#include "arc.h"
#endif

#ifndef __USB_OS_MQX__
static uint_8 disable_count = 0;
volatile boolean  IN_ISR = FALSE;
#endif

/*FUNCTION*-------------------------------------------------------------
*
*  Function Name  : USB_int_install_isr
*  Returned Value : None
*  Comments       :
*        Installs the USB interrupt service routine
*
*END*-----------------------------------------------------------------*/

void USB_int_install_isr
   (
      /* [IN] vector number */
      uint_8 vector_number,

      /* [IN] interrupt service routine address */
      INTERRUPT_ROUTINE_KEYWORD void (_CODE_PTR_ isr_ptr)(void),
            
      /* [IN] parameter for ISR - unused for standalone version */
      pointer  handle
   )
{ /* Body */
   
#ifdef __OTG_ARC5__

   uint_16_ptr  loc_ptr;
   uint_32      loc;

   loc     = (uint_32)isr_ptr;
   loc_ptr = (uint_16_ptr)_lr(0x25);

   /* Offset into the vector table */   
   loc_ptr += (4 * vector_number);
   
   *loc_ptr++ = 0x2020; /* Hi word of JL */
   *loc_ptr++ = 0x0F80; /* Lo word of JL */
   *loc_ptr++ = loc >> 16;
   *loc_ptr   = (uint_16)loc;
#else
   uint_32_ptr                loc_ptr = (uint_32_ptr)0;

   /* Offset into the vector table */   
   loc_ptr += (2 * vector_number);
   
   *loc_ptr++ = ARC_JMP_TO_ADDR_INSTRN;   /* OpCode for Jump to addr */
   *loc_ptr++ = (uint_32)isr_ptr;         /* Address of the ISR */
#endif
   
} /* EndBody */

/*FUNCTION*-------------------------------------------------------------
*
*  Function Name  : _bsp_get_usb_vector
*  Returned Value : interrupt vector number
*  Comments       :
*        Get the vector number for the specified device number
*END*-----------------------------------------------------------------*/

uint_8 _bsp_get_usb_vector
   (
      uint_8 device_number
   )
{ /* Body */
#ifdef __USB_HOST__
   if (device_number == 0) {
      return BSP_VUSB11_HOST_VECTOR0;
   } /* Endif */
#endif

#ifdef __USB_DEVICE__
   if (device_number == 0) {
      return BSP_VUSB11_DEVICE_VECTOR0;
   } /* Endif */
#endif

#ifdef __USB_OTG__
   if (device_number == 0) {
      return BSP_VUSB11_OTG_VECTOR0;
   } /* Endif */
#endif
 
} /* EndBody */

/*FUNCTION*-------------------------------------------------------------
*
*  Function Name  : _bsp_get_usb_base
*  Returned Value : Address of the VUSB1.1 register base
*  Comments       :
*        Get the USB register base address
*END*-----------------------------------------------------------------*/

pointer _bsp_get_usb_base
   (
      uint_8 device_number
   )
{ /* Body */
#ifdef __USB_HOST__
   if (device_number == 0) {
      return (pointer)BSP_VUSB11_HOST_BASE_ADDRESS0;
   } /* Endif */
#endif

#ifdef __USB_DEVICE__
   if (device_number == 0) {
      return (pointer)BSP_VUSB11_DEVICE_BASE_ADDRESS0;
   } /* Endif */
#endif

#ifdef __USB_OTG__
   if (device_number == 0) {
      return (pointer)BSP_VUSB11_OTG_BASE_ADDRESS0;
   } /* Endif */
#endif
   
} /* EndBody */

#ifndef __USB_OS_MQX__
void _disable_interrupts
   (
      void
   )
{ /* Body */
   
   if ((!disable_count) && (!IN_ISR)) {
      DISABLE_INTERRUPTS();
   } /* Endif */

   if (!IN_ISR) {
      disable_count++;
   } /* Endif */
   
} /* EndBody */

void _enable_interrupts
   (
      void
   )
{ /* Body */

   if (!IN_ISR) {
      disable_count--;
   } /* Endif */
   
   if ((!disable_count) && (!IN_ISR)) {
      ENABLE_INTERRUPTS();
   } /* Endif */
   
} /* EndBody */

#endif /* __MQX__ */


/* EOF */