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

📄 main.c

📁 基于ADSP-BF535 USB驱动应用程序
💻 C
字号:
/*----------------------------------------------------------------------------------
*
* COPYRIGHT (c) 2001 by Singing Electrons, Inc. All rights reserved.
*
*
* Module Name			: C:\se\adi\hidclass\source\main.c
*
* Description			: The Main entrypoint
*
*
* Revision History	: At bottom of the file.
*
*---------------------------------------------------------------------------------*/

/** include files **/
#include <sys/exception.h>
#include <sys/excause.h>
#include <defBF535.h>
#include "register.h"
#include "dtype.h"
#include "usb.h"
#include "usbdriver.h"
#include "audioclass.h"
#include "dprintf.h"

/** local definitions **/
#define DisplayError //Later on we will do something special to display the error?


//This is for Eagle-35 only!
#define kVal 0xff00
#define kValSome 0xaa00
#define kValClear 0x7f00 //do not want to reset the AC97!

static inline void initLEDs(void) {
  *(volatile uint16 *)FIO_DIR = (uint16)kVal;
  asm("ssync;");
}

static inline void setLEDs(void) {
  *(volatile uint16 *)FIO_FLAG_S = (uint16)kVal;
  asm("ssync;");
}

static inline void setSomeLEDs(void) {
  *(volatile uint16 *)FIO_FLAG_S = (uint16)kValSome;
  asm("ssync;");
}


static inline void clearLEDs(void) {
  *(volatile uint16 *)FIO_FLAG_C = (uint16)kValClear;
  asm("ssync;");
} 

static inline uint16 getPushBtns(void) {
  uint16 val = *(volatile uint16 *)FIO_FLAG_S;
  asm("ssync;");
  return val;
}
#define	DELAY_LOOP 300000



#define VENDOR_ID 0xCB00
#define PRODUCT_ID 0x0006
#define DEVICE_RELEASE 0x0006 //0.06


/* default settings */

/** external functions **/

/** external data **/

/** internal functions **/
static void delay(void);

/** public data **/

/** private data **/
int dumpDprintf = 0;

/** public functions **/

/** private functions **/

/** callbacks **/
static void OnSuspend (void);
static void OnResume (void);
static void OnReset (void);

#define IAR_SPORT0_MASK 0x00ff0000;
#define IAR_USB_MASK 0x00000f00;

/*------------------------------------------------------------
*	main
*
*	Parameters:  
*		None
*
*	Globals Used:
*		None
*
*	Description:
*		This is the entry-point. 
*
*	Returns:
*		Nothing
*
*
*------------------------------------------------------------*/
void main (void)
	{
		UINT regValue;
		InitDprintf ();

		//Change IAR priorities to have USB as ivg8 and SPORT0 as ivg7
		regValue = SIC_IAR0_REG;
		asm ("csync;");
		regValue = regValue & IAR_SPORT0_MASK; //this sets SPORT0 for ivg7
		regValue = regValue & IAR_USB_MASK;
		regValue = regValue | (0x01 << 8); //this sets USB for ivg8
		SIC_IAR0_REG = regValue;
		asm ("ssync;");


		if (!AUDIOCLASS_Init (VENDOR_ID, PRODUCT_ID, DEVICE_RELEASE, 
			OnSuspend, OnResume, OnReset))
			goto done;

		//printf ("Init complete\n");
		//A real application would at this point do something!
	//  initLEDs(); 
    //clearLEDs();  

	  while(1) 
	  	{
		    clearLEDs();  
		    delay();
				if (gIsPlaybackActive)
			    setLEDs();
				else
			    setSomeLEDs();
		    delay();

				if (dumpDprintf)
					{
						DumpDprintf (dumpDprintf);
						dumpDprintf = 0;
					}
		  }

done:
		//Run happily ever after
		while (1)
			;
				
	}


void delay(void)
{
  unsigned long i;
  
  for(i=0; i<DELAY_LOOP; i++)
    {
		AUDIOCLASS_DoForegroundTasks ();
    }
}







/*------------------------------------------------------------
*	OnSuspend
*
*	Parameters:  
*
*	Globals Used:
*		None
*
*	Description:
*		This routine will be called when USBDriver detects a
*		suspend condition. Currently, it does nothing.
*
*	Returns:
*		Nothing.
*
*------------------------------------------------------------*/
void OnSuspend (void)
	{
	}



/*------------------------------------------------------------
*	OnResume
*
*	Parameters:  
*
*	Globals Used:
*		None
*
*	Description:
*		This routine will be called when the USBDriver detects that
*		the bus is out of suspend. Currently, it does nothing for custom
*		device. For the mouse, it prepares the IN endpoint with the report.
*
*	Returns:
*		Nothing.
*
*------------------------------------------------------------*/
void OnResume (void)
	{

	}


/*------------------------------------------------------------
*	OnReset
*
*	Parameters:  
*
*	Globals Used:
*		None
*
*	Description:
*		This routine will be called when the USBDriver detects reset
*		signalling on the bus. Currently, it does nothing
*
*	Returns:
*		Nothing.
*
*------------------------------------------------------------*/
void OnReset (void)
	{
	}


/*----------------------------------------------------------------------------------
* $Log: main.c,v $
* Revision 1.8  2003/01/17 00:51:13  Devendra
* Updated version number.
*
* Revision 1.7  2003/01/16 19:06:45  Devendra
* - Changed foreground task to blink the LEDs after initialization.
* - Changed foreground task to blink "all" the LEDs when playback is active.
* - Added support for AudioClass to perform non-ISR(foreground) tasks.
*
* Revision 1.6  2003/01/15 01:34:15  Devendra
* Updated version number.
*
* Revision 1.5  2003/01/13 20:00:25  Devendra
* Updated version number.
*
* Revision 1.4  2003/01/13 19:50:40  Devendra
* Removed DMA buffer init from main()
* Changed the priorities of interrupts - now SPORT0 is ivg7, USB is ivg8
*
* Revision 1.2  2003/01/10 01:41:32  Devendra
* Changed the revision number.
*
* Revision 1.1  2003/01/09 01:16:36  Devendra
* First Rev of AudioClass - have the device enumerated as audio device, and the volume control and mute are functional!
*
* Revision 1.2  2003/01/08 01:41:56  Devendra
* - Changes to remove divide operations (to improve DSP cycle utilization).
* - Supressed dprintfs
*
* Revision 1.1  2002/10/31 00:30:59  Devendra
* Moved all files in one folder to avoid IDE related problems.
*
* Revision 1.3  2002/10/30 02:36:40  Devendra
* - Added more abstraction to HIDCLASS. So that it's possible to build
*   different devices without making any changes to the HIDCLASS module.
* - Added proper support for handling USB SUSPEND, RESUME, and RESET events.
*
* Revision 1.2  2002/10/22 17:47:47  Devendra
* - Refine LED blinking, etc.
* - Change output location.
*
* Revision 1.1  2002/10/22 17:23:39  Devendra
* Rearranged file locations.
*
* Revision 1.6  2002/10/14 05:16:04  Devendra
* - Custom Device now using Feature reports for I/O
* - Added compiler define/project configuration to switch between mouse and custom device.
*
* Revision 1.5  2002/10/14 01:33:15  Devendra
* Got "custom" device functional with buttons and lights!
*
* Revision 1.4  2002/10/09 17:09:32  Devendra
* - Added support for handling IN endpoints.
* - Added HID descriptors (HID and HID Report)
* - Modified the Interface descriptors to comply to HID Class Spec.
* - Added functionality to use the push-buttons on the Eagle-35 as a mouse (for buttons as well as for movement).
* - The device is now a fully functioning USB Mouse!
*
* Revision 1.3  2002/10/08 20:44:03  Devendra
* - Separated the printf logging to a different c module.
*
* Revision 1.2  2002/10/08 19:57:02  Devendra
* - Added specific callbacks for getting Device, Config, and String descriptors.
* - BugFix: Max. Packet Size was not being set correctly in ArmEndpoint.
* - Added internal buffer based logging to allow real-time "printfs".
* - Added String descriptors.
*
* Revision 1.1  2002/09/20 06:51:30  Devendra
* First Rev.
*
*
*---------------------------------------------------------------------------------*/

⌨️ 快捷键说明

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