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

📄 main.c

📁 U-disk reference design
💻 C
字号:
/*------------------------------------------------------------------------------
main.c

Version:
September 13, 2005 - Version 2.1 - Updated to run on either the DK3400 or the 
DK3420 by merely making a change to the #define in the upsd3400_hardware.h file
and then rebuilding all target files.  Also, some files were renamed and the 
disclaimers were updated.

Description:  USB Reference Design - Flash Disk Application (read/write)
This reference design enumerates as a USB flash disk making use of the USB Mass 
Storage Device Class driver.  It will appear as an available drive on the system
and files can be read from and written to the flash memory.  The flash memory used
for file storage is the uPSD34xx's main flash.

This reference design is intended to demonstrate USB functionality and provide
example code on using the USB module within the uPSD34xx.

Supported platforms:
DK3400, DK3420

Note:
It is important to modify the #define setting in upsd3400_hardware.h to match 
the platform (target board) being used.  The value of the #define is used in 
several places to make appropriate settings for the target board and device 
being used.



Copyright (c) 2005 STMicroelectronics Inc.

THIS INFORMATION (or THIS SOFTWARE or THIS DOCUMENT) IS FOR GUIDANCE ONLY. ST 
MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS 
SOFTWARE nor for any infringement of patents or other rights of third parties 
which may result from its use. ST MICROELECTRONICS SHALL NOT BE HELD LIABLE FOR 
ANY DIRECT, INDIRECT INCIDENTAL OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY 
CLAIMS ARISING IN CONNECTION WITH OR ARISING FROM THE FURNISHING, PERFORMANCE, 
OR USE OF THIS SOFTWARE. Specifications mentioned in this publication are 
subject to change without notice. This publication supersedes and replaces all 
information previously supplied. STMicroelectronics products are not authorized 
for use as critical components in life support devices or systems without the 
express written approval of STMicroelectronics.

------------------------------------------------------------------------------*/


#pragma NOAREGS

#include "upsd3400.h"
#include "upsd3400_hardware.h"
#include "upsd3400_upsd_usb.h"
#include "upsd3400_usb_desc.h"
#include "upsd3400_usb.h"
#include "upsd3400_usb_app.h"

#define RemoteWakeupEnable   0

pdata unsigned char   PageDataBuffer[64];
data  unsigned char   BankCurrent;

xdata PSD_REGS UPSD_xreg _at_ PSD_REG_ADDR;
data unsigned char ReconnectDemand;
extern unsigned char data usbState;
static data unsigned int  g_debugUSB_INT_CNT = 0;

extern unsigned char volatile gbBulkPipeStage;

#define GREEN_LED P4_0                  // GREEN LED Indicator on the DK3420 board
										//  - Not present on the DK3400
extern unsigned char USB_ISR_Counter;
unsigned char Aux_USB_ISR_Counter;

data unsigned int GREEN_LED_CNT;

//PC7
#define PC7_OUT UPSD_xreg.DIRECTION_C   |=0x80             // PC7=Out (D7 = 1)
#define PC7_IN UPSD_xreg.DIRECTION_C    &=0x7F             // PC7=In  (D7 = 0)
#define PC7_PUSHPULL UPSD_xreg.DRIVE_C  &=0x7F             // PC7=Push/Pull (D7 = 0)
#define PC7_OPENDRAIN UPSD_xreg.DRIVE_C |=0x80             // PC7=open drain (D7 = 1)
#define PC7_HIGH UPSD_xreg.DATAOUT_C    |=0x80             // PC7=1 (D7 = 1)
#define PC7_LOW UPSD_xreg.DATAOUT_C     &=0x7F             // PC7=0 (D7 = 0)


void UsbDisconnectOnDemand(void)
/******************************************************************************
 Function   : UsbDisconnectOnDemand(void)
 Parameters : none
 Description: USB disconnect on demand routine
 ******************************************************************************/
 {
#ifdef DK3400
//DK3400
// Set PC7 for USB Disconnect
   PC7_OUT;
   PC7_OPENDRAIN;
   PC7_LOW;
   

#else
//DK3420
// Set PC7 for USB Disconnect
   PC7_IN; 
#endif
}

void UsbConnectOnDemand(void)
/******************************************************************************
 Function   : UsbDisconnectOnDemand(void)
 Parameters : none
 Description: USB disconnect on demand routine
 ******************************************************************************/
 {
#ifdef DK3400
//DK3400
// Set PC7 for USB Connect
   PC7_OUT;
   PC7_OPENDRAIN;		   //PC7 set for open drain, high value effectively
   PC7_HIGH;               // releases the D+ line to be pulled high through 
                           // external transistor/resistor.
#else
//DK3420
// Set PC7 for USB Connect
   PC7_OUT;                //PC7 set to output mode.
   PC7_PUSHPULL;		   //PC7 set for push-pull type when in output mode.
   PC7_HIGH;               //Output high value to apply 3.3V to pull-up resistor on D+ 

#endif
}

void Initialize(void)
/******************************************************************************
 Function   : void Initialize()
 Parameters : none
 Description: Module initialization routine.
 ******************************************************************************/
{
  UsbInitialize();
  UsbConnectOnDemand();
 }


void T0ISR (void) interrupt TF0_VECTOR using 1
/******************************************************************************
 Function   : void T0ISR ()
 Parameters : (void)
 Description: LED effects routine
 ******************************************************************************/
 {

  if (Aux_USB_ISR_Counter != USB_ISR_Counter)
   {
    Aux_USB_ISR_Counter = USB_ISR_Counter;   // USB Activity
    GREEN_LED = 1;                           //GREEN LED OFF
    GREEN_LED_CNT = 500;
   }

/* ***** GREEN LED service ***** */
  if (GREEN_LED_CNT>0)
   {
    GREEN_LED_CNT--;
    if (GREEN_LED_CNT == 0)
     {
      GREEN_LED = 0;                         //GREEN LED ON after some time
     }
   }
 }


void main(void)
/******************************************************************************
 Function   : void main()
 Parameters : (void)
 Description: The main routine
 ******************************************************************************/
 {
  UsbDisconnectOnDemand();

  GREEN_LED = 0;

  Initialize();

  UPSD_xreg.DIRECTION_D |= 2;                // RED LED ON
  UPSD_xreg.OUTENABLE_D |= 2;
  UPSD_xreg.DATAOUT_D    = 0;

  UPSD_xreg.DATAOUT_D    = 255;              // RED LED OFF

  GREEN_LED = 1;

  GREEN_LED_CNT = 1;                         // GREEN LED ON

//Timer0, blinking LEDs and SW PWM service
  TR0   = 0;                                 // stop timer 0
  TMOD &= 0xF0;                              // clear timer 0 mode bits
  TMOD |= 0x02;                              // put timer 0 into right mode
  TH0   = 0;                                 // 12MHz/12/-x

  ET0   = 1;                                 // enable timer 0 interrupt
  TR0   = 1;                                 // start timer 0


  while (1)
   {
   }

 }



/* *************************************************************************
  ***                                                                      ***
  **                         *** End of File ***                            **
  ***                                                                      ***
   *************************************************************************  */

⌨️ 快捷键说明

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