📄 test_sl811.c
字号:
//-----------------------------------------------------------------------------
// File: fw.c
// Contents: Firmware frameworks task dispatcher and device request parser
// source.
//
// Copyright (c) 2002 Cypress Semiconductor, Inc. All rights reserved
//
// $Archive: /USB/ez811/firmware/Emb_Host/fw.c $
// $Date: 4/03/02 4:32p $
// $Revision: 1 $
//-----------------------------------------------------------------------------
#include "ezusb.h"
#include "ezregs.h"
#include "def.h"
#include "utils.h"
//-----------------------------------------------------------------------------
// Random Macros
//-----------------------------------------------------------------------------
//#define min(a,b) (((a)<(b))?(a):(b))
//#define max(a,b) (((a)>(b))?(a):(b))
//-----------------------------------------------------------------------------
// Constants
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Global Variables
//-----------------------------------------------------------------------------
volatile BOOL GotSUD;
BOOL Rwuen;
BOOL Selfpwr;
volatile BOOL Sleep; // Sleep mode enable flag
DWORD pDeviceDscr; // Pointer to Device Descriptor; Descriptors may be moved
DWORD pConfigDscr;
DWORD pStringDscr;
//-----------------------------------------------------------------------------
// Prototypes
//-----------------------------------------------------------------------------
void SetupCommand(void);
void TD_Init(void);
void TD_Poll(void);
BOOL TD_Suspend(void);
BOOL TD_Resume(void);
BOOL DR_GetDescriptor(void);
BOOL DR_SetConfiguration(void);
BOOL DR_GetConfiguration(void);
BOOL DR_SetInterface(void);
BOOL DR_GetInterface(void);
BOOL DR_GetStatus(void);
BOOL DR_ClearFeature(void);
BOOL DR_SetFeature(void);
BOOL DR_VendorCmnd(void);
//-----------------------------------------------------------------------------
// Code
//-----------------------------------------------------------------------------
// Task dispatcher
void TestSL811(void)
{
Uart_Printf("\nSL811HST test\n") ;
Uart_Printf("Please insert a USB Device\n") ;
Uart_Printf("for example : USB Flash Disk, USB MOUSE, USB keyboard......\n") ;
// Initialize Global States
Sleep = FALSE; // Disable sleep mode
Rwuen = FALSE; // Disable remote wakeup
Selfpwr = FALSE; // Disable self powered
GotSUD = FALSE; // Clear "Got setup data" flag
// Initialize user device
TD_Init();
//EZUSB_IRQ_ENABLE(); // Enable USB interrupt (INT2)
EZUSB_ENABLE_RSMIRQ(); // Wake-up interrupt
// The 8051 is responsible for all USB events, even those that have happened
// before this point. We cannot ignore pending USB interrupts.
// The chip will come out of reset with the flags all cleared.
// USBIRQ = 0xff; // Clear any pending USB interrupt requests
PORTCCFG |= 0xc0; // Turn on r/w lines for external memory
USBBAV = USBBAV | 1 & ~bmBREAK; // Disable breakpoints and autovectoring
USBIEN |= bmSUDAV | bmSUTOK | bmSUSP | bmURES; // Enable selected interrupts
//rINTMSK &= ~BIT_GLOBAL; // Enable interrupts
//EA = 1;
// Task Dispatcher
while(Uart_GetKey()!=ESC_KEY) // Main Loop
{
if(GotSUD) // Wait for SUDAV
{
//SetupCommand(); // Implement setup command
GotSUD = FALSE; // Clear SUDAV flag
}
// Poll User Device
// NOTE: Idle mode stops the processor clock. There are only two
// ways out of idle mode, the WAKEUP pin, and detection of the USB
// resume state on the USB bus. The timers will stop and the
// processor will not wake up on any other interrupts.
if (Sleep)
{
if(TD_Suspend())
{
Sleep = FALSE; // Clear the "go to sleep" flag. Do it here to prevent any race condition between wakeup and the next sleep.
do
{
//EZUSB_Susp(); // Place processor in idle mode.
}
while(!Rwuen && EZUSB_EXTWAKEUP());
// Must continue to go back into suspend if the host has disabled remote wakeup
// *and* the wakeup was caused by the external wakeup pin.
// 8051 activity will resume here due to USB bus or Wakeup# pin activity.
//EZUSB_Resume(); // If source is the Wakeup# pin, signal the host to Resume.
TD_Resume();
}
}
TD_Poll();
}
}
static char title[] = "USB HOST实验";
static char tip[] = "实验USB HOST控制芯片SL811HS,插入USB设备后查看实验结果,按ESC键返回";
//TestSL811Item在prog_entry.c里被引用
TEST_PROGRAM_ITEM TestSL811Item = {
(TEST_PROGRAM)TestSL811, //入口地址
title, //显示名称
tip, //帮助或提示信息,可为NULL
1}; //使用printf,puts,putch等函数时在LCD上也显示输出字符(串)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -