📄 usbch9.c
字号:
/*
* Start of Zoran Standard Header
* Copyright (c) 2003 - 2004 Zoran Corporation.
*
*
* All rights reserved. Proprietary and confidential.
*
* DESCRIPTION for usbch9.c
* USB 2.0 Chapter 9 printer.
*
* NEW HISTORY COMMENT (description must be followed by a blank line)
* <Enter change description here>
* ===== HISTORY of changes in //depot/misc/projects/tps/usb/usbch9.c
*
* 1/Jul/04 #103 lee Completed change for sending HID NULLs for USB 2.0.
* 1/Jul/04 #102 lee "-DUSB_HID_NULL2" for sending HID NULL for USB 2.0 as well as 1.1.
* 1/Jul/04 #101 lee I forgot to run stdhdr; sorry.
* 1/Jul/04 #100 lee Make USB20_HighSpeed flag public for usbmass.c.
* 15/Jun/04 #99 lee Make USB_SEND_NULL_HID=1 the default case.
* 15/Jun/04 #98 lee Remove no longer needed debug code.
* 15/Jun/04 #97 lee Added test code to send zero-length data packet
* for NO-OP HID packet. This is for test builds using the build flag
* "-DUSB_SEND_NULL_HID=1".
* 15/Jun/04 #96 lee Fix for USB 1.1 issue, send NO-OP HID packet if real
* one not available. Can be reverted with -DUSB_ALWAYS_SEND_HID=0
* 10/Jun/04 #95 lee ENA changes now on by default for both printer and scanner
* channels, for USB1.1 and 2.0.
* 10/Jun/04 #94 lee Finished reverting #85; also stop card reader LED
* from blinking if cable removed.
* 10/Jun/04 #93 imgeng make DEBUG_USB_RESET_CAUSE
* 10/Jun/04 #92 imgeng make DEBUG_USB_RESET_CAUSE
* 9/Jun/04 #91 lee Workaround for External Network Adaptor (under
* USB_ENA_PRN_WORKAROUND, USB_ENA_SCN_WORKAROUND and USB_ENA_11_ONLY
* build flags).
* 1/Jun/04 #90 lee Fix USB1.1 scanner bug introduced during revision #86.
* 1/Jun/04 #89 lee Fix USB1.1 Mass Storage bug introduced during revision #86.
* 1/Jun/04 #88 lee Fix scan bug introduced during revision #86.
* 28/May/04 #87 lee Reverted FunaiModify052804 change #85.
* 28/May/04 #86 lee Big change for USB 2.0 scan-to-host speed-up.
* 28/May/04 #85 hchuang Funai's update
* 21/May/04 #84 lee Fix bug in checking HID descriptor index
* 12/May/04 #83 lee Fixed Warnings from USB Command Verifier
* (implemented HID GET IDLE command)
* 11/May/04 #82 lee Give HID packets their own pool.
* 11/May/04 #81 lee Only hold off USB enumeration on power up if mfg mode.
* 10/May/04 #80 lee Support config w/o scanner and/or debug channels, e.g., CH*
* 10/May/04 #79 lee Remove RAM_FLASH debug code.
* 10/May/04 #78 lee Remove GRINDSTONE build option; remove unused
* FlashMemoryIface; fix SetInterface warnings in USB Command Verifier
* 5/May/04 #77 ebradsha Application hook for collecting system info every second or more.
* (Be careful.)
* 3/May/04 #76 lee Remove erroneous ASSERT from service_EPn_OUT().
* 30/Apr/04 #75 lee Add more de-glitching to VBUS test.
* 28/Apr/04 #74 lee Give USB tasks different priorities to help with debugging.
* 26/Apr/04 #73 lee Stop Card Reader LED blinking if USB cable removed.
* 26/Apr/04 #72 lee Hold off enumeration until FP initialized (for Funai power sequence)
* 23/Apr/04 #71 lee Workaround for bug 38390 - only check VBUS PIO
* if not connected based on USB frame counter.
* 22/Apr/04 #70 lee I/O routines now return FALSE if USB cable disconnected.
* 22/Apr/04 #69 mrhines USB_DELAYED_TURNON is now 0 by default per Lexmark request.
* 20/Apr/04 #68 lee Fix bug in card reader FIFO code, sometimes 1-3 bad
* data bytes at end of packet were sent to host.
* 13/Apr/04 #67 jwv Funai changes for built-in self test
* 7/Apr/04 #66 lee Back out HPC interface (function replaced by tps debug)
* 7/Apr/04 #65 lee Remove unnecessary stuff left from change #63
* 7/Apr/04 #64 lee Go back to 512 byte USB packets for debug channels.
* 5/Apr/04 #63 lee Change max scanner data per packet to 128
* 2/Apr/04 #62 mrhines Enable USB2.0 Data FIFO workaround as default.
* 1/Apr/04 #61 lee Changes for using FIFO for memory card write to host (-DUSB_USES_FIFO)
* 31/Mar/04 #60 emiller Make USB_DELAYED_TURNON the default for non-Boot builds
* 30/Mar/04 #59 lee Remove redundant "DoNotRemoveFlashMemory" declaration.
* 15/Mar/04 #58 lee Fix for Dell PC boot hang under USB_DELAYED_TURNON build flag
* 15/Mar/04 #57 lee Added MAC_SCANNER_WORKAROUND to force 64-byte scanner packets
* 12/Mar/04 #56 lee Workaround to limit high-speed scanner packets to 256 bytes
* 10/Mar/04 #55 lee Fix revision history.
* 10/Mar/04 #54 lee Force NO_USB_VBUS_POLL for boot code.
* 10/Mar/04 #53 lee Fix compiler warnings: make task prototypes match TASKCREATE()
* 8/Mar/04 #52 lee Make sure Vbus PIO direction is input
* 5/Mar/04 #51 lee Work-around version of USB cable detect if VBUS
* detection hardware doesn't work.
* 4/Mar/04 #50 lee VBUS polling now on by default for non-boot builds
* if not FIRE4 ref board; explicitly turned off
* by "-DNO_USB_VBUS_POLL".
* 24/Feb/04 #49 lee Make USBConfigured() return FALSE within 1 sec. of USB
* cable being removed. Requires USB_VBUS_POLL on.
* 17/Feb/04 #48 BDodge Merge in customer's UI
* 10/Feb/04 #47 lee All USB buffers to non-cachable memory.
* 28/Jan/04 #46 lee Fix for Print-from-host hangs.
* 27/Jan/04 #45 lee Restore PACKET_SIZE_MASK to mod 512 to see if it fixes regression.
* 23/Jan/04 #44 lee Use one define for each send and receive packet size specifier.
* 19/Jan/04 #43 lee Removed obsolete reference to STALL_WORKAROUND.
* 19/Jan/04 #42 lee Change for USB Speed print out.
* 8/Jan/04 #41 lee Removed temporary work-around; move fix to usb20hw.c
* 6/Jan/04 #40 lee Temporary work-around for USB HW problem clearing stall.
* 22/Dec/03 #39 emiller Remove unused variable warning
* 22/Dec/03 #38 lee Added USBConfigured(), removed USBBurnFlash().
* 19/Dec/03 #37 lee Forgot to run stdhdr last time.
* 19/Dec/03 #36 lee Moved HISR code to usb20hw.c
* 11/Dec/03 #35 lee Don't do VBUS polling by default, require -DUSB_VBUS_POLL.
* 5/Dec/03 #34 emiller Allow external tuning of task priority and stack size
* 24/Nov/03 #33 lee Fixed USB_VBUS_POLL code for actual hardware (detects
* USB disconnect, flushed scan table). Default if not
* FIRE4 reference board.
* 13/Nov/03 #32 lee Minor fix to Device ID string printout.
* 13/Nov/03 #31 lee Finish HPC changes, fix bug in service_EPn_IN().
* 12/Nov/03 #30 mrhines No HPC semaphore if bootcode
* 12/Nov/03 #29 lee Add HPC changes for sending PSPRINTF strings to host PC
* 10/Nov/03 #28 emiller Make USB_SCAN_CALLBACK the default for scan-enabled builds
* 10/Nov/03 #27 lee Changes for HPC debug channel for sending printf's to host PC
* 31/Oct/03 #26 lee Fixes for USB2.0 and HID compliance.
* 30/Oct/03 #25 lee Check "DoNotRemoveFlashMemory" flag for task wakeup
* when interface deinit'ed.
* 29/Oct/03 #24 lee Removed interface test for class-specific requests.
* 17/Oct/03 #23 lee Put calls to USBConsumeWriteScan() under
* "USB_SCAN_CALLBACK" manifest.
* 15/Oct/03 #22 lee Last fix not complete; moved check to usbpriv.h.
* 15/Oct/03 #21 lee Fix GRINDSTONE build (MEMORY_CARD_READER now default)
* 14/Oct/03 #20 lee Name change for RAM_FLASH initialization.
* 14/Oct/03 #19 pshread Don't call MemoryCardInit unless if using DUMMY_FLASH
* 7/Oct/03 #18 lee Fix for GRINDSTONE (introduced in revision #17)
* 7/Oct/03 #17 lee Memory card reader development.
* 6/Oct/03 #16 lee Fix so usbutila.exe will work again.
* 6/Oct/03 #15 lee Fixed bug in flash memory card routine USBWriteCard().
* 2/Oct/03 #14 emiller Define PSPRINTF for boot builds
* 2/Oct/03 #13 lee Use PSPRINTF for BOOTCODE too.
* 1/Oct/03 #12 lee Fixed USBWritePrint() bug (in WriteEPn()).
* 29/Sep/03 #11 lee Fixes for STALL code.
* 26/Sep/03 #10 lee Provide stubs for scanner, etc., to link Grindstone builds.
* 26/Sep/03 #9 lee Memory card bug fixes.
* 24/Sep/03 #8 lee Changed for Grindstone support, also fixed bugs.
* 19/Sep/03 #7 lee Work continues on Mass Storage Class for memory cards.
* 18/Sep/03 #6 lee Many bug fixes found will developing memory card code.
* 8/Sep/03 #5 lee Got rid of unused-variables warnings.
* 29/Aug/03 #4 lee Made memory card reader depend on MEMORY_CARD_READER manifest
* 28/Aug/03 #3 lee Removed test code, added memory card reader interface.
* 27/Aug/03 #2 emiller Getting builds building
* 21/Aug/03 #1 lee Created
*
* End of Zoran Standard Header
*/
/******************************************************************************/
/*
* USB_POWER_ON_ENUM_MODE (only applies if FUNAI_POWER_SEQ defined):
* 0 - default, wait for Funai's front-panel flag, gfFPAllowUSB,
* to be TRUE before allowing USB enumeration only if printer
* in manufacturing mode (i.e., Serial Number "000000000000000")
* 1 - always wait for Funai's front-panel flag gfFPAllowUSB
* 2 - never wait for Funai's front-panel flag gfFPAllowUSB
*/
#ifndef USB_POWER_ON_ENUM_MODE
#define USB_POWER_ON_ENUM_MODE 0
// FunaiModify052804 removed because it caused problems for customer operation
#endif
/*
* These flags, if true, cause null packets to be sent back to the host
* when data ends with full packets in order to flush data out of the
* External Network Adaptor (ENA). They are on by default by can be
* overridden by using build flags, e.g., "-DUSB_ENA_PRN_FLUSH=0".
* The extra packets are added for USB 2.0 communication too, by default,
* but can be disabled by overriding with a build flag.
*/
#ifndef USB_ENA_PRN_FLUSH
#define USB_ENA_PRN_FLUSH 1 /* Add null packets to print back-channel data */
#endif
#ifndef USB_ENA_SCN_FLUSH
#define USB_ENA_SCN_FLUSH 1 /* Add null packets to scan back-channel data */
#endif
/* If this flag is set, the above will not affect USB 2.0, only USB 1.1 */
#ifndef USB_ENA_FOR_USB11_ONLY
#define USB_ENA_FOR_USB11_ONLY 0
#endif
#ifndef USB_DELAYED_TURNON
# ifdef BOOTCODE
# define USB_DELAYED_TURNON 0
# else
# define USB_DELAYED_TURNON 0
# endif
#endif
#ifndef USB_USES_FIFO
# define USB_USES_FIFO 1
#endif
#ifdef BOOTCODE
#ifndef NO_USB_VBUS_POLL
# define NO_USB_VBUS_POLL
#endif
#ifdef USB_ALWAYS_SEND_HID
#undef USB_ALWAYS_SEND_HID
#endif
#define USB_ALWAYS_SEND_HID 0
typedef unsigned char uchar; /* unsigned character */
typedef unsigned char Uint8; /* 8-bit signed integer */
typedef unsigned short Uint16; /* 16-bit unsigned integer*/
typedef unsigned long Uint32; /* 32-bit unsigned integer*/
typedef long Sint32; /* 32-bit unsigned integer*/
typedef int Boolean;
#include "usbpriv.h"
#include "oti4100.h"
#ifdef SCANNER_EPS
#undef SCANNER_EPS
#endif
#define SCANNER_EPS 0
#ifdef DEBUG_EPS
#undef DEBUG_EPS
#endif
#define DEBUG_EPS 0
#define ARM_INTS_OFF {*(unsigned long *)EXMSK1A &= ~2;}
#define ARM_INTS_ON {*(unsigned long *)EXMSK1A |= 2;}
#define USB_INTS_OFF {*(unsigned long *)EXMSK1A &= ~2;}
#define USB_INTS_ON {*(unsigned long *)EXMSK1A |= 2;}
#define USB_RCV_LIMIT 3000000
extern int xprintf(const char *, ...);
#define PSPRINTF xprintf
extern void micropause(int);
#define DELAY_5MSEC micropause(5*1000)
#define DELAY_10MSEC micropause(10*1000)
#define DELAY_SEC micropause(1000*1000)
#define SCAN_TO_HOST_ENABLED 0
#else /* else not BOOTCODE */
#include "univ.gh"
#include "targmach.gh"
#include "scan.gh"
#include "arch.h"
#include "pile.h"
#include "dbg.h"
#include "ts.h"
#include "nucleus.h"
#include "oti4100.h"
#include "usb.h"
#include "propman.h"
#include "usbpriv.h"
#include "memfs.h" /* Required for memfsFIFOProtect(), memfsFIFOUnprotect() */
#ifndef USB_ALWAYS_SEND_HID
#define USB_ALWAYS_SEND_HID 1
#endif
#ifndef USB_SEND_NULL_HID
#define USB_SEND_NULL_HID 1
#endif
#if USB_ALWAYS_SEND_HID
/* prototype for fp/hostio.c function */
void GetNopHidReport(Uint8 **nop, Uint16 *size);
static Uint8 *hid_nop;
static Uint16 hid_nop_size;
#endif
/* prototype for interrupts off/on functions */
void armIntsOff(void);
void armIntsOn(void);
/* Just turn off ARM chip interrupts for brief protection. */
#define ARM_INTS_OFF armIntsOff();
#define ARM_INTS_ON armIntsOn();
/* For protection over longer periods, only disable the USB interrupt. */
#define USB_INTS_OFF {armIntsOff();*(unsigned long *)EXMSK1A &= ~2;armIntsOn();}
#define USB_INTS_ON {armIntsOff();*(unsigned long *)EXMSK1A |= 2;armIntsOn();}
#define DELAY_5MSEC TASKSLEEP_MILLISECONDS(5)
#define DELAY_10MSEC TASKSLEEP_MILLISECONDS(10)
#define DELAY_SEC TASKSLEEP_SECONDS(1)
/*
* Poll D+ line for USB connection - default if not FIRE4 Reference board
* but may be explicitly turned off by "-DNO_USB_VBUS_POLL"
*/
#if CONTROLLER_BOARD == FIRE4_REFERENCE_CONTROLLER
# ifndef NO_USB_VBUS_POLL
# define NO_USB_VBUS_POLL
# endif
#endif
#endif /* not BOOTCODE */
/******************************************************************************/
#ifndef USB_STATUS_PRINT
# define USB_STATUS_PRINT
#endif
#if USB_STATUS_PRINT
#define PRINT0 PSPRINTF
#define PRINT1 PSPRINTF
#define PRINT2 PSPRINTF
#define PRINT3 PSPRINTF
#define USB_STATUS_MSK_SET(m , v) USB_DB_Status = (USB_DB_Status & ~(m)) | (v)
#define USB_STATUS_SET(val) USB_DB_Status |= (val)
#define USB_STATUS_CLR(val) USB_DB_Status &= ~(val)
#define USB_STATUS_TESTMODE(val) USB_DB_Status|=TEST_MODE; USB_DB_tmode=(val)
static volatile Uint32 USB_DB_Status, USB_DB_StatusLast;
static volatile Uint32 USB_RcvPRN, USBConsumedPRN, USB_SentPRN;
static volatile Uint32 USB_RcvSCN, USBConsumedSCN, USB_SentSCN;
static volatile Uint32 USB_RcvMEM, USBConsumedMEM, USB_SentMEM;
static volatile Uint32 USB_RcvDBG, USBConsumedDBG, USB_SentDBG;
static volatile Uint32 USB_RecvdLastPRN, USB_ConsumedLastPRN, USB_SentLastPRN;
static volatile Uint32 USB_RecvdLastSCN, USB_ConsumedLastSCN, USB_SentLastSCN;
static volatile Uint32 USB_RecvdLastMEM, USB_ConsumedLastMEM, USB_SentLastMEM;
static volatile Uint32 USB_RecvdLastDBG, USB_ConsumedLastDBG, USB_SentLastDBG;
static Uint32 USB_DB_tmode;
extern USB_CONFIGURATION USB_Conf;
#define ENUMERATED 0x0001
#define DID_USB_TASK_RESET 0x0010
#define DATA_RCVPRN 0x0040
#define DATA_RCVSCN 0x0080
#define DATA_RCVMEM 0x0100
#define DATA_RCVDBG 0x0200
#define FULL_SPEED 0x0400
#define HIGH_SPEED 0x0800
#define SPEED_MASK 0x0c00
#define TEST_MODE 0x1000
#define VBUS_HIGH 0x2000
static void printUSBstatus(Uint32 ConsumeBytes)
{
Uint32 status = USB_DB_Status, diff;
static int first_time = 1, reenter = 0;
/* Primative gate-keeper to avoid confusing print-outs */
if (reenter)
return;
reenter++;
if (first_time) {
int i, ix, cnt;
const Uint8 *p;
Uint8 serial_no[21], devid[100];
p = USB_Conf.DeviceID;
cnt = (Uint32)p[0] * 256 + (Uint32)p[1];
first_time = 0;
p = (Uint8 *)USB_Conf.StrDescTable[3];
cnt = *p;
if (cnt > 40)
cnt = 40;
for (i = 2, ix = 0; i < cnt; i += 2)
serial_no[ix++] = p[i];
serial_no[ix] = 0;
PRINT1("\nUSB: Board Serial No.: '%s'\n", serial_no);
p = USB_Conf.DeviceID;
cnt = (Uint32)p[0] * 256 + (Uint32)p[1];
PRINT1("USB: Device ID string (%d bytes):\n", cnt);
devid[ 0] = 'U'; devid[ 1] = 'S'; devid[ 2] = 'B';
devid[ 3] = ':'; devid[ 4] = ' '; devid[ 5] = 0x27;
devid[ 6] = '<';
devid[ 7] = p[0] >> 4;
devid[ 7] += ((devid[ 7] > 9) ? 'A' - 10 : '0');
devid[ 8] = p[0] & 15;
devid[ 8] += ((devid[ 8] > 9) ? 'A' - 10 : '0');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -