📄 main.c
字号:
/* `=========================================================================`
main.c
USB IAP (In Application Programming) Demo for uPSD32xx
Version:
April 30, 2004 - Beta Version 1.0
Description:
The demo code provided is considered beta. It provides a good example of the
uPSD32xx operating as a low speed, HID class device performing IAP features.
The firmware is for the uPSD32xx device on a DK3200 for IAP communicating
over USB to a Windows application.
USB Compliance:
This beta code passes the Chapter 9 and HID tests provided by the USB Command
Verifier program (USBCV R1.2.1). USBCV is available from the USB IF website at:
http://www.usb.org/developers/developers/tools/
The Passing test result reports for the Chapter 9 and HID tests run on this
firmware in the DK3200 are included in the "..\USBCV Test Reports" subdirectory.
Regarding the warnings in the test reports, see the known limitations listed
below.
Known Limitations:
1. The uPSD32xx hardware does not support remote wakeup but does support host
resume.
2. This version of the demo code doesn't support the GetIdle and SetIdle
commands.
3. This version of the demo code passes the Chapter 9 EnumerateTest the majority
of the time but on occasion fails.
Important !!!
=============
If you have a previous beta version, please replace all parts
of your SW with this new version, there are many small but
important changes that are not
obvious for the first look.
Notes:
======
supports USB SUSPEND and RESUME features
supports USB DisconnectOndemand feature
- Version >= Beta 1.0 - DDC int only
- this version of USB demo was designed for uPSD3234A. Check your type of uPSD.
- be sure you have jumpers PB0-PB3 present on your DK3200 kit
to avoid some false detect of button press.
This version supports DisconnectOnDemand feature and tests PB port.
- We recommend to design your USB-isr to be as shortest as possible,
make your USB ISR part as short as possible if you add something
- set the USB priority to the max.level (bit 0 of IPA, see uPSD323X datasheet).
- This version uses relative register addressing,
use #pragma NOAREGS directive in your applications ...
- Use data directive or place your variables to data area directly
(data variables are executed faster than xdata, but their amount is more limited.)
- use 36MHz xtal (or 24MHz if not posssible) oscillator freq.only
- be careful of using <string.h> and other routines in USB ISRs
Tested on DK3200 board. Rev.0.1.
..........................
. .
. ****************** .
. **PPPPPPPPPPPPPPPP .
. *PPPP*******PP**** .
. **PPP********PP*** .
. ***PPP******PP**** .
. *****PPP****PP**** .
. *****PPP****PP**** .
. PPPPPPPP****PP**** (R) .
. .
..........................
=-=-=-=-=-=
=-=-=-=-=-=-=-=-=-=-=-=-=
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Copyright 2004 ST Microelectronics
This code/file is provided as is and has no warranty,
implied or otherwise. You are free to use/modify any of the provided
code at your own risk in your applications with the expressed limitation
of liability (see below) so long as your product using the code
contains at least one uPSD products (device).
LIMITATION OF LIABILITY:
========================
NEITHER STMicroelectronics NOR ITS VENDORS OR AGENTS
SHALL BE LIABLE FOR ANY LOSS OF PROFITS, LOSS OF USE, LOSS OF DATA,
INTERRUPTION OF BUSINESS, NOR FOR INDIRECT, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES OF ANY KIND WHETHER UNDER THIS AGREEMENT OR
OTHERWISE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
=-=-=-=-=-=-=-=-=-=-=-=-=
=-=-=-=-=-=
For current information on uPSD products,
please consult our pages on the World Wide Web:
www.st.com/psm
- - - - - - - - - - - -
STMicroelectronics GROUP OF COMPANIES
Australia - Brazil - China - Czech Republic - Finland - France - Germany
Hong Kong - India - Italy - Japan - Malaysia - Malta - Morocco - Singapore
Spain - Sweden - Switzerland - United Kingdom - U.S.A.
http://www.st.com
`========================================================================` */
#pragma NOAREGS //this source must use relative registers !!!
#include <string.h>
#include "upsd3200.h"
#include "upsd_usb.h"
#include "lcd_3200.h"
#include "app_intr.h"
/*========= Prototypes =========*/
extern uchar flash_write_with_poll(volatile uchar xdata *addr, uchar dat);
extern uchar flash_boot_write_with_poll(volatile uchar xdata *addr, uchar dat);
extern uchar flash_erase_sector(volatile uchar xdata* addr);
extern uchar flash_boot_erase_sector(volatile uchar xdata* addr);
extern void flash_reset();
extern void flash_boot_reset();
extern void initXREG();
//extern
extern PSD_REGS UPSD_xreg; // UPSD registers (upsd_cfg.c)
extern data uchar LCD_buffer[]; // LCD mirror buffer (lcd_32xx.c)
/*=========== Globals ===========*/
// uncomment the following line to enable DisconnectOndemand feature
//#define DisconnectOnDemand
/*
Enable this DisconnectOnDemand define in case of usage of Disconnect-on-demand
feature ONLY. Be sure that all hardware modifications are present !!!
*/
unsigned char DDCCONintc = 0;
data int counter; // Incremented in do_timer0 (timer_func.c)
MCU_CMD status; // Status from last command executed
data uchar returnStatus; // Set TRUE if we should return status record to host
MCU_CMD currentCmd; // Current command we're working on
MCU_CMD rcvReport; // Incoming report
data uchar rcvIndex; // Current byte position in incoming report
MCU_CMD txReport; // Outgoing report
data uchar txIndex;
// Current byte position in outgoing report, but be a byte only !!!
xdata char AuxTXBuf[8]; //Aux. buffer for TXing of LCD content
data uchar LCDBufTXIndex; //current position of LCD buffer for USB TX
data unsigned int g_debugUSB_INT_CNT = 0;
data unsigned char g_debugTimer2_INT_CNT = 0;
void initXREG(void)
/******************************************************************************
Function : void initXREG()
Parameters : (void)
Description: Init of uPSD's xregs
******************************************************************************/
{
/************ VM ************/
UPSD_xreg.VM |= 0x80;
// bit 7 - PIO (1=enable)
// bit 4 - RD access FLASH (1=enable)
// bit 3 - RD access EEPROM (1=enable)
// bit 2 - PSEN access FLASH (1=enable)
// bit 1 - PSEN access EEPROM (1=enable)
// bit 0 - PSEN access SRAM (1=enable)
/****** power management ******/
UPSD_xreg.PMMR0=0x38; // power-on default = 0x00
// bit 5 - CLKIN input to MCell (1=off)
// bit 4 - CLKIN input to PLD array (1=off)
// bit 3 - PLD turbo mode (ZPSD only) (1=disable)
// bit 1 - APD unit (1=enable)
UPSD_xreg.PMMR2=0x70; // power-on default = 0x00
// bit 6 - DBE input to PLD array (1=off)
// bit 5 - ALE input to PLD array (1=off)
// bit 4 - CNTL2 input to PLD array (1=off)
// bit 3 - CNTL1 input to PLD array (1=off)
// bit 2 - CNTL0 input to PLD array (1=off)
}
#ifdef DisconnectOnDemand
static void ReConnectUSB()
/******************************************************************************
Function : static void ReConnectUSB()
Parameters : none
Description: Use insted of UsbInitialize when DisconnectOnDemand feature
is implemented.
Be sure that the DisconnectOnDemand feature is present on DK3200.
******************************************************************************/
{
data int w;
UIEN = 0; // Disable all USB interrupts
UADR = 0; // Disable USB hardware
LCDBufTXIndex = 0; // LCD disp position for USB
UPSD_xreg.DATAOUT_C &= 0xEF; // PC4=0
UPSD_xreg.DRIVE_C |= 0x10; // set as OpenDrain
UPSD_xreg.DIRECTION_C |= 0x10; // set as output
printfLCD("\rUSB Disconnected");
while ((UPSD_xreg.DATAIN_B & 0x04)==0)
{
for (w=0;w<600*50;w++); // wait 50 ms
}
UPSD_xreg.DRIVE_C &= 0xEF; // set PC4 as input
UPSD_xreg.DIRECTION_C &= 0xEF; // set PC4 as input
UsbInitialize();
printfLCD("\rUSB Reconnected.");
}
#endif
static void WriteBufferToFlash(uchar flash, uint16 address, uchar* buf, uint16 cb)
/******************************************************************************
Function : static void WriteBufferToFlash()
Parameters : (uchar flash, uint16 address, uchar* buf, uint16 cb)
Description: WriteBufferToFlash()
******************************************************************************/
{
// Assume desired flash segment is mapped into high 32k of xdata space
volatile uchar xdata* p = (volatile uchar xdata*) address;
if (flash == PRIMARY_FLASH)
{
while (cb--)
{
flash_write_with_poll(p, *buf++);
status.u.status.checkSum += *p++;
}
}
else
{
while (cb--)
{
flash_boot_write_with_poll(p, *buf++);
status.u.status.checkSum += *p++;
}
}
}
static void ReadBufferFromFlash(uint16 address, uchar* buf, uint16 cb)
/******************************************************************************
Function : static void ReadBufferFromFlash()
Parameters : (uint16 address, uchar* buf, uint16 cb)
Description: ReadBufferFromFlash()
******************************************************************************/
{
// Assume desired flash segment is mapped into high 32k of xdata space
volatile uchar xdata* p = (volatile uchar xdata*) address;
while (cb--)
{
*buf++ = *p++;
}
}
void OnDeviceConfigured()
/******************************************************************************
Function : void OnDeviceConfigured()
Parameters : none
Description: Called after device is completely configured.
******************************************************************************/
{
TXD1F = 1; // Set up first tx on EP1 if not
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -