⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 memory.c

📁 nxp的LPC2888处理器的示例代码.
💻 C
字号:
/*----------------------------------------------------------------------------
 *      Name:    MEMORY.C
 *      Purpose: USB Mass Storage Demo
 *      Version: V1.10
 *----------------------------------------------------------------------------
 *      This software is supplied "AS IS" without any warranties, express,
 *      implied or statutory, including but not limited to the implied
 *      warranties of fitness for purpose, satisfactory quality and
 *      noninfringement. Keil extends you a royalty-free right to reproduce
 *      and distribute executable files created using this software for use
 *      on Philips LPC microcontroller devices only. Nothing else gives you
 *      the right to use this software.
 *
 *      Copyright (c) 2005-2006 Keil Software.
 *---------------------------------------------------------------------------*/
#include "lpc288x.h"                        /* LPC214x definitions */

#include "type.h"
#include "irq.h"
#include "target.h"
#include "timer.h"

#include "usb.h"
#include "usbcfg.h"
#include "usbhw.h"
#include "usbcore.h"
#include "mscuser.h"
#include "memory.h"

extern WORD  USB_DeviceStatus;
extern BYTE Memory[MSC_MemorySize];         /* MSC Memory in RAM */
extern DWORD timer_counter;
extern DWORD SuspendFlag;

volatile DWORD USBWakeupFlag = 0;

/*****************************************************************************
** Function name:		EVT3_ISR
**
** Descriptions:		Interrupt handler for event router group 3
**
** parameters:			None
** Returned value:		None
** 
*****************************************************************************/
void EVT3_ISR(void)
{
  if ( USB_DeviceStatus & USB_GETSTATUS_REMOTE_WAKEUP )
  {
	USBMode |= (0x1<<6);		// Resume
	USBMode &= ~(0x1<<6);
	USB_WakeUpCfg( TRUE );
  }
  else
  {
	USB_WakeUpCfg( FALSE );
  }
  EVECLR3 = ((0x1<<4)|(0x1<<5));
  return;
}

/*****************************************************************************
** Function name:		EventRouter3Init
**
** Descriptions:		
**
** parameters:			None
** Returned value:		None
** 
*****************************************************************************/
void EventRouter3Init( void )
{
  /* Configure Interrupt Controller */
  /* Set event router to IRQ1 for GPIO3 and GPIO2 */
  EVIOMS13 |= ((0x1<<4)|(0x1<<5));	/* GPIO 2 and 3 interrupt are enabled. */
  EVAPR3 = ((0x1<<4)|(0x1<<5));		/* rising edge */ 
  EVATR3 = ((0x1<<4)|(0x1<<5));		/* edge trigger */

  if ( install_IRQ(2, 1, EVT3_ISR ) == FALSE )
  {
	while ( 1 );			/* Fatal error due to ISR installation failure */	
  }
  INT_REQ2=(1<<28)|(1<<27)|(1<<26)|(1<<16)|0x1; 
  INT_VECTOR0=IRQ_TABLE_BASE & MASK_INDEX;
  return; 
}

/* Main Program */
int main (void) {
  DWORD n, DisconnectFlag = 0;
#if USB_LOW_POWER_EVENT 
  DWORD WakeupFlag = 0;
#endif

  TargetResetInit();
  init_timer( TIMER_1MS );

  for (n = 0; n < MSC_ImageSize; n++) {     /* Copy Initial Disk Image */
    Memory[n] = DiskImage[n];               /*   from Flash to RAM     */
  }	
  
  if ( install_IRQ(26, 1, USB_ISR ) == FALSE )
  {
	while ( 1 );			/* Fatal error due to ISR installation failure */	
  }
  INT_REQ26=(1<<28)|(1<<27)|(1<<26)|(1<<16)|0x1; 
  INT_VECTOR0=IRQ_TABLE_BASE & MASK_INDEX;
  
  /* Check VBUS signal, make it input */
  MODE1_7 &= ~(1<<0);
  MODE0_7 &= ~(1<<0);

  /* Make both MODE1(p2.2) and MODE2(p2.3) input */
  MODE1_2 &= ~((1<<2)|(1<<3));
  MODE0_2 &= ~((1<<2)|(1<<3));

  /* Check remote wake up signal */
  /* if either button, GPIO2, GPIO3, is pressed, set remote wake up */
  EventRouter3Init();
  
  while (1)
  {
#if USB_LOW_POWER_EVENT
	/* No need to initialize USB until VBus is sensed. 
	DisconnectFlag is a one time event. It will be set after
	connected and cleared after disconnected. */
	if ( WakeupFlag == 1 )
	{
		/* Wake up from USB */
		WakeupFlag = 0;			/* never come here again until
								another, suspend and resume sequence
								coming. */
//		USB_Init();				/* USB Initialization */
//		USB_Connect(TRUE);		/* USB Connect */
	}

	if ( SuspendFlag == TRUE )
	{
	  if ( timer_counter > 2000 )
	  {
			/* Configure Event router that USB wakeup route to 
			OUTPUT 4, the CGU. */
			EVIOMS43 |= (0x1 << 7);
			/* Warning: USB wake up is a active low.
			below two lines left intentionally as warning. */
			//  EVAPR3 = 0x1 << 7;
			//  EVATR3 = 0x1 << 7;
			USBMode |= (0x1<<2);	/* Set WKUP bit */
			WakeupFlag = 1;
			/* go to power down/low power mode. */
			PMODE = 0x3;
	  }
	}
#endif

	if ( (PINS_7 & (0x1<<0)) && !DisconnectFlag )
	{
	  USB_Init();				/* USB Initialization */
	  USB_Connect(TRUE);		/* USB Connect */
	  if ( !(PINS_7 & (0x1<<0)) )
	  {
		/* Disconnected, reset flag */
		DisconnectFlag = 0;
		/* if connected, disconnect */
		if ( USBMode & (1<<0) )
	  	{
		  USB_Connect(FALSE);
		}	
	  }
	  else	 
	  {
		/* Still connected, set flag, no need to go to Init() and 
		Connect() again */
		DisconnectFlag = 1;
	  }
	}
	else if ( !(PINS_7 & (0x1<<0)) )
	{
	  /* Disconnected, reset flag */
	  DisconnectFlag = 0;
	  /* if connected, disconnect */
	  if ( USBMode & (1<<0) )
	  {
		USB_Connect(FALSE);
	  }	
	}
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -