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

📄 fw.c

📁 linux下数据下载器的设计与实现
💻 C
📖 第 1 页 / 共 2 页
字号:
#pragma NOIV
//-----------------------------------------------------------------------------
// File:     fw.c
// Contents: Firmware frameworks task dispatcher and device request parser
//           source.

//--------------------------------------------------------------------------

#include "globals.h"
void NM_ReadPageTEST();
//-----------------------------------------------------------------------------
// Code
// Task dispatcher
//-----------------------------------------------------------------------------
void main(void)
{
   //OEE = 0xFE;                // NAND chip select use PD0-7
   //TM_ClearWTD();
   TD_Init();                     // HW/SW initialization

   EZUSB_IRQ_ENABLE();            // Enable USB interrupt (INT2)
   EZUSB_ENABLE_RSMIRQ();         // Wake-up interrupt
   INTSETUP |= (bmAV2EN);         // Enable INT 2 autovectoring

   USBIE = bmSUDAV | bmSUSP | bmURES | bmHSGRANT;   // Enable selected interrupts

   //////////////////////////////////////////////////////////////////////////////
   //
   // How we got here         Renum Bit Discon Bit  Desired Action
   // ---------------         --------- ----------  --------------------
   // LI Boot-Loader Good_FW     0          1       Set the renum bit and connect
   // LI Boot-Loader !Good_FW    0          0       renumerate
   // USB Reset                  1          0       do nothing
   // Debug Mode (no bootloader) 0          0       renumerate
   // I2C Boot-Loader Good_FW    1          0       do nothing
   // I2C Boot-Loader !Good_FW   0          0       renumerate
   //
   //////////////////////////////////////////////////////////////////////////////
   if(!(USBCS & (bmRENUM | bmDISCON)))
   {
      EA = 0;
      // disconnect from USB and set the renumerate bit
      USBCS |= (bmDISCON | bmRENUM);        
      EZUSB_Delay(2500);      // Wait 2500 ms  
      USBIRQ = 0xff;          // Clear any pending USB interrupt requests.  
      EPIRQ = 0xff;
      EZUSB_IRQ_CLEAR();
   }

   EA = 1;                  // Enable 8051 interrupts
   TR0 = 1;                 // Make sure that the timer ISR runs at once.  

   // unconditionally re-connect.  If we loaded from eeprom we are
   // disconnected and need to connect.  If we just renumerated this
   // is not necessary but doesn't hurt anything
   USBCS = (bmRENUM|bmNOSYNSOF);

   // complete the handshake phase of any pending SETUP transfer.
   // The only time this should happen is after a MSC Reset.  We want
   // to go through all of the EP init code before handshaking the status
   // phase of the MSC Reset.
   EP0CS |= bmHSNAK;
   Sleep = 0;                     // sleep is off
   //TM_ClearWTD();
   /////////////////////////////////////////////////////////////////////////////

   //chech power
#ifdef DEBUG_VER
   TM_Timer0_Init();
   UM_InitUART();
#endif

#ifndef DEBUG_VER
   if((IOE & 0x01) == 0)  
#endif
   {
	   RM_InitDS1302();
	   if(FM_fat_install())
	   {
	   		;//UM_SendString("FAT32 install ok\n");
	   }
#ifndef DEBUG_VER
	   TM_Timer0_Init();
	   UM_InitUART();	   
#endif
   }
   /////////////////////////////////////////////////////////////////////////////
   // Task Dispatcher

   while(TRUE)                     // Main Loop
   {
	  //TM_ClearWTD();
#ifndef DEBUG_VER
      if((IOE & 0x01) == 1)
#endif
	  {
	      // Suspend code -- Turn off LEDs, chip enables and put CPU into suspend.
	      // We don't support remote wakeup.  Only wake on SOFs.
	      if (Sleep)
	      {
	         Sleep = FALSE;
	         WAKEUPCS = bmWU2 | bmWU | bmDPEN;      
	         EZUSB_Susp();         // Place processor in idle mode.
	      }  // endif (sleep)
	      TD_Poll();
      }
#ifndef DEBUG_VER
	  else
#endif
	  {
		  //timeout auto save
		  if(timer0_tick >= 50)
		  {
		  		if(FM_CurrentBuff == 0)			 
				{
					if(FM_DPointer1 != 0)
					{
						FM_CurrentBuff = 1;
						FM_DataBuff1[FM_DPointer1] = 0;
						FM_WriteFile(FM_DataBuff1, FM_DPointer1);
						FM_DPointer1 = 0;
					}
				}
				else
				{
					if(FM_DPointer2 != 0)
					{
						FM_CurrentBuff = 0;
						FM_DataBuff2[FM_DPointer2] = 0;
						FM_WriteFile(FM_DataBuff2, FM_DPointer2);
						FM_DPointer2 = 0;
					}
				}	
		
				//clear timer count
				timer0_tick = 0;
		  }
	
		  if(FM_CurrentBuff == 0)			 
		  {
			  if(FM_DPointer2 >= (MAX_RS232_BUFF))
			  {
				  FM_WriteFile(FM_DataBuff2, FM_DPointer2);
				  FM_DPointer2 = 0;
			  }
	   	  }
		  else
		  {
			  if(FM_DPointer1 >= (MAX_RS232_BUFF))
			  {
				  FM_WriteFile(FM_DataBuff1, FM_DPointer1);
				  FM_DPointer1 = 0;
			  }
		  }		
	  }
   }  // End while-forever loop
}

//-----------------------------------------------------------------------------
// Standard requests are 
// Device request parser
//-----------------------------------------------------------------------------
void SetupCommand(void)
{
   WORD xdata Tmp;
   BYTE xdata setupdat0 = SETUPDAT[0];
   BYTE xdata setupdat2 = SETUPDAT[2];
   BYTE xdata setupdat4 = SETUPDAT[4];
   EP0BCH = 0;                                     // Default to MSB of the length is 0
   SUDPTRH = MSB(halfKBuffer);                     // Default to descriptor table

   if ((setupdat0 & SETUP_MASK) == SETUP_STANDARD_REQUEST)
      {
      switch(SETUPDAT[1])
         {
         case SC_GET_DESCRIPTOR:                       // *** Get Descriptor
            switch(SETUPDAT[3])         
               {
                  case GD_DEVICE:                      // Device
                     SUDPTRL = pLSB(DeviceDscrOffset); //sendDescriptor(LSB(pDeviceDscr), 0);
                     break;
                  case GD_DEVICE_QUALIFIER:            // Device Qualifier
                     // if high-speed is disabled, we are supposed to STALL this request
                     if (!CT1)
                     {
                        // high-speed is enabled, return the device qualifier
                        // sendDescriptor(LSB(pDeviceQualDscr), 0);
                        SUDPTRL = pLSB(DeviceQualDscrOffset);
                     }
                     else
                     {
                        // high-speed is disabled, STALL this request
                        EZUSB_STALL_EP0();
                     }
                     break;
                  case GD_CONFIGURATION:              // Configuration
                     ((CONFIGDSCR xdata *) pHighSpeedConfigDscr)->type = CONFIG_DSCR;
                     Tmp = wPacketSize;
                     goto gd_cases;

                  case GD_OTHER_SPEED_CONFIGURATION:  // Other Speed Configuration
                     ((CONFIGDSCR xdata *) pHighSpeedConfigDscr)->type = OTHERSPEED_DSCR;
                     if (EZUSB_HIGHSPEED()) Tmp = 64; else Tmp = 512;
                     gd_cases:
                     ((BYTE xdata *) pHighSpeedConfigDscr)[9+9+4] =       
                     ((BYTE xdata *) pHighSpeedConfigDscr)[9+9+7+4] = ((BYTE*)&Tmp)[1];      
                     ((BYTE xdata *) pHighSpeedConfigDscr)[9+9+5] =       
                     ((BYTE xdata *) pHighSpeedConfigDscr)[9+9+7+5] = ((BYTE*)&Tmp)[0];      
                     sendDescriptor(LSB(pHighSpeedConfigDscr), (BYTE)&HighSpeedConfigLen);
                     break;

                  case GD_STRING:            // String
                     SUDPTRH = MSB(halfKBuffer+cHALF_BUFF_OFFSET);
                     SUDPTRL = cINQUIRY_LENGTH + (setupdat2 * 48);
                     break;
#ifdef HID
                  case GD_REPORT: 	 // Get-Descriptor: Report
                     if (halfKBuffer[(WORD)&HIDIntrfcDscrOffset+3] == setupdat4)
                     {  
                        sendDescriptor(pLSB(HIDReportDscrOffset), (BYTE)&HIDReportDscrLen);
                        break;
                     }

⌨️ 快捷键说明

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