📄 usbch9.c
字号:
devid[ 9] = '>'; devid[10] = '<';
devid[11] = p[1] >> 4;
devid[11] += ((devid[11] > 9) ? 'A' - 10 : '0');
devid[12] = p[1] & 15;
devid[12] += ((devid[12] > 9) ? 'A' - 10 : '0');
devid[13] = '>';
ix = 14;
for (i = 2; i < cnt; i++) {
devid[ix++] = p[i];
if (p[i] == ';') {
devid[ix++] = 0x27;
devid[ix++] = '\n';
devid[ix] = 0;
PRINT1("%s", devid);
ix = 0;
devid[ix++] = 'U'; devid[ix++] = 'S'; devid[ix++] = 'B';
devid[ix++] = ':'; devid[ix++] = ' '; devid[ix++] = 0x27;
}
}
}
diff = status ^ USB_DB_StatusLast;
/*
* Note: only print out byte counts if some other status value changed
* to reduce "noise polution".
*/
if (diff) {
if (diff & ENUMERATED) {
PRINT0("USB: Connected to host\n");
}
if (status & DID_USB_TASK_RESET) {
PRINT0("USB: Did task-level reset\n");
status &= ~DID_USB_TASK_RESET;
USB_STATUS_CLR(DID_USB_TASK_RESET);
}
if (diff & DATA_RCVPRN) {
PRINT0("USB: Beginning to receive printer data\n");
}
if (diff & DATA_RCVSCN) {
PRINT0("USB: Beginning to receive scanner data\n");
}
if (diff & DATA_RCVDBG) {
PRINT0("USB: Beginning to receive debug data\n");
}
if (diff & SPEED_MASK) {
if (status & FULL_SPEED) {
PRINT0("USB: Speed FULL SPEED (old USB 1.1)\n");
}
if (status & HIGH_SPEED) {
PRINT0("USB: Speed HIGH SPEED (new USB 2.0)\n");
}
}
if (diff & VBUS_HIGH) {
if (status & VBUS_HIGH) {
PRINT0("USB: Cable connected and host on\n");
}
else {
PRINT0("USB: Cable unplugged and/or host (PC) off\n");
}
}
if (diff & TEST_MODE) {
PRINT1("USB: Enter USB Test Mode %d - POWER CYCLE REQUIRED\n",
(unsigned int)USB_DB_tmode);
}
if (ConsumeBytes) {
PRINT1("USB: %d bytes consumed\n", (int)ConsumeBytes);
}
if (USB_RecvdLastPRN != USB_RcvPRN ||
USB_ConsumedLastPRN != USBConsumedPRN ||
USB_SentLastPRN != USB_SentPRN)
{
USB_RecvdLastPRN = USB_RcvPRN;
USB_ConsumedLastPRN = USBConsumedPRN;
USB_SentLastPRN = USB_SentPRN;
PRINT2("USB-Print: In Rcv Buff %d, Total consumed %d, ",
(int)USB_RcvPRN, (int)USBConsumedPRN);
PRINT1("Sent %d \n", (int)USB_SentPRN);
}
if (USB_RecvdLastSCN != USB_RcvSCN ||
USB_ConsumedLastSCN != USBConsumedSCN ||
USB_SentLastSCN != USB_SentSCN)
{
USB_RecvdLastSCN = USB_RcvSCN;
USB_ConsumedLastSCN = USBConsumedSCN;
USB_SentLastSCN = USB_SentSCN;
PRINT2("USB-Scan: In Rcv Buff %d, Total consumed %d, ",
(int)USB_RcvSCN, (int)USBConsumedSCN);
PRINT1("Sent %d \n", (int)USB_SentSCN);
}
if (USB_RecvdLastMEM != USB_RcvMEM ||
USB_ConsumedLastMEM != USBConsumedMEM ||
USB_SentLastMEM != USB_SentMEM)
{
USB_RecvdLastMEM = USB_RcvMEM;
USB_ConsumedLastMEM = USBConsumedMEM;
USB_SentLastMEM = USB_SentMEM;
PRINT2("USB-Card: In Rcv Buff %d, Total consumed %d, ",
(int)USB_RcvMEM, (int)USBConsumedMEM);
PRINT1("Sent %d \n", (int)USB_SentMEM);
}
if (USB_RecvdLastDBG != USB_RcvDBG ||
USB_ConsumedLastDBG != USBConsumedDBG ||
USB_SentLastDBG != USB_SentDBG)
{
USB_RecvdLastDBG = USB_RcvDBG;
USB_ConsumedLastDBG = USBConsumedDBG;
USB_SentLastDBG = USB_SentDBG;
PRINT2("USB-Debug: In Rcv Buff %d, Total consumed %d, ",
(int)USB_RcvDBG, (int)USBConsumedDBG);
PRINT1("Sent %d \n", (int)USB_SentDBG);
}
USB_DB_StatusLast = status;
}
reenter = 0;
}
#else /* else not USB_STATUS_PRINT */
#define PRINT0(a0)
#define PRINT1(a0,a1)
#define PRINT2(a0,a1,a2)
#define PRINT3(a0,a1,a2,a3)
#define USB_STATUS_MSK_SET(m, v)
#define USB_STATUS_SET(val)
#define USB_STATUS_CLR(val)
#define USB_STATUS_TESTMODE(val)
#endif /* not USB_STATUS_PRINT */
/******************************************************************************/
/* Variables & structures declared in or shared with other modules: */
/* USB state structure */
extern USB_DEV_STATE_STRUCT usb_state;
/* Local copy of USB control packet setup array: REQUEST, VALUE, INDEX, etc. */
extern SETUP_STRUCT usb_setup;
/* Flag indicating that USB_task needs wake-up call for H/W reset. */
extern volatile int USB_ForceReset;
/*
* USB Configuration structure: Passes configuration initialization
* from USBConfigurationInit() (in usbconf.c).
*/
extern USB_CONFIGURATION USB_Conf;
#ifdef FUNAI_POWER_SEQ
/* This flag is TRUE once the front panel is finished booting */
extern Boolean gfFPAllowUSB;
#endif
/* PreventRemoval (usbmass.c) set by host if card should not be removed. */
extern Boolean PreventRemoval;
/* USB High Speed (vs. Full Speed) flag */
Boolean USB20_HighSpeed;
/* Array of USB endpoint service routines */
void(*USBserviceEP[32])(Uint8, Boolean, Uint32);
/* HISR and wake-up found in usb20hw.c */
void USB_WakeUpUSB_Task(void);
void USB_hisr(void);
/******************************************************************************/
/* Local defines: */
/* Macro for aligning buffers to 4 byte boundary in non-cachable memory */
#define USB_MEM4_ALIGN(n) ((((Uint32)(n)) + (-((Uint32)(n)) & 3))|0x20000000)
#define STALL_ENDPOINT_0 USB_ISR_set_endpoint_status(0, 1)
/*
* Endpoint status states:
* . undefined
* . defined for this alternate interface but not currently configured
* . configured for reading (OUT)
* . configured for writing (IN)
*/
#define EP_UNDEF 0 /* EP not defined for any interface */
#define EP_UNCONF 1 /* EP defined but not configured for current iface */
#define EP_CONFIG_R 2 /* EP defined, configured for READ and initialized */
#define EP_CONFIG_W 4 /* EP defined, configured for WRITE and initialized */
#define EP_CONFIG_RW 6 /* EP defined, configured for R/W and initialized */
#define EP_CONFIG 6 /* "EndPoint is configured" mask */
#define PACKET_SIZE_MASK (~(HS_BULK_SIZE-1)) /* ~(64 - 1) = 0xfffffe00 */
/*
* Output (device to host) packet parameters:
* A few long packets and many short packets.
*/
#define LONG_PACKET_CNT 10
#define LONG_PACKET_SIZE 512
#define SHORT_PACKET_CNT 50
#define SHORT_PACKET_SIZE 64
#define HID_PACKET_CNT 10
#define HID_PACKET_SIZE 16
/******************************************************************************/
/* Local structures: definitions and allocation: */
typedef struct { /* Common I/O parameters: */
volatile Boolean request_active; /* I/O (read) has been initiated */
volatile Boolean full_flag; /* buffer was full at ISR level; */
/* must be restarted by task */
volatile Uint32 request_index; /* where the read starts */
volatile Uint32 request_length; /* no. bytes requested on read */
volatile Uint32 tick; /* ISR/task flag used to get */
/* active-read byte cnt */
Uint8 *buffer; /* input ring buffer base address */
volatile Uint32 inx; /* index of next address to add data */
volatile Uint32 outx; /* index of next address to remove data */
volatile Uint32 limit; /* current end-of-buffer count */
Uint32 max_buff_size; /* maximum end-of-buffer count */
} EP_RECV;
#define PRN_SEND (2*PRN_EP + 1)
#define PRN_RECV (2*PRN_EP + 0)
#define SCN_SEND (2*SCN_EP + 1)
#define SCN_RECV (2*SCN_EP + 0)
#define HID_SEND (2*HID_EP + 1)
#define MEM_SEND (2*MEM_EP + 1)
#define MEM_RECV (2*MEM_EP + 0)
#define DBG_SEND (2*DBG_EP + 1)
#define DBG_RECV (2*DBG_EP + 0)
/* status of endpoint - undefined, unconfigured, configured for R, W or both */
static EP_RECV prn_recv; /* Printer */
static volatile Uint8 prn_status;
static volatile Uint8 hid_status;
#if SCANNER_EPS
static volatile Uint8 scn_status;
static EP_RECV scn_recv; /* Scanner */
#endif
#if DEBUG_EPS
static volatile Uint8 dbg_status;
static EP_RECV dbg_recv; /* Debug */
#endif
#ifdef MEMORY_CARD_READER
static volatile Uint8 mem_status;
static EP_RECV mem_recv; /* Memory Card Reader */
static tsSemaphore USB_CARD_Semaphore;
#endif
/*
* OUT_PACKET:
* These packets are used to ship data back to the host. They come in
* two flavors, long and short, and the choice depends on the size of
* the data to send. The packets can be intermixed on queues and are
* returned to the appropriate pool based on the pool address, home_pool.
*/
typedef struct outpacket {
struct outpacket **home_pool; /* Set to &long_packet_pool */
struct outpacket *next; /* link to next packet */
Uint16 length; /* length of packet */
Uint8 data[LONG_PACKET_SIZE]; /* actual USB packet to send */
} OUT_PACKET;
/*
* Short packet packet version of structure.
*/
typedef struct {
struct outpacket **home_pool; /* Set to &short_packet_pool */
struct outpacket *next; /* link to next packet */
Uint16 length; /* length of packet */
Uint8 data[SHORT_PACKET_SIZE]; /* actual USB packet to send */
} OUT_PACKET_SHORT;
/*
* HID packet packet version of structure.
*/
typedef struct {
struct outpacket **home_pool; /* Set to &short_packet_pool */
struct outpacket *next; /* link to next packet */
Uint16 length; /* length of packet */
Uint8 data[HID_PACKET_SIZE]; /* actual USB packet to send */
} OUT_PACKET_HID;
/******************************************************************************/
/* Static variable declarations: */
#ifndef BOOTCODE
/* NUCLEUS O/S and ts task related declarations */
/* HISR (High Interrupt Service Routine) declaration */
extern NU_HISR usbHISR;
static Uint32 pHISRStack[HISR_STACKSIZE/4];
/* ts: task and semaphore */
static void *TaskUSB_VBUS_data;
static tsTaskID TaskUSB_VBUS_ID;
static int TaskUSB_VBUS_arg;
static Uint32 TaskUSB_VBUS_stack[USBTASK_STACKSIZE/4];
static void *TaskUSB_data;
static tsTaskID TaskUSB_ID;
static int TaskUSB_arg;
static Uint32 TaskUSB_stack[USBTASK_STACKSIZE/4];
tsSemaphore USBSemaphore;
#if SCANNER_EPS
static void *TaskUSB_SCAN_data;
static tsTaskID TaskUSB_SCAN_ID;
static int TaskUSB_SCAN_arg;
static Uint32 TaskUSB_SCAN_stack[USBTASK_STACKSIZE/4];
static tsSemaphore USB_SCAN_Semaphore;
#endif /* SCANNER_EPS */
#endif /* not BOOTCODE */
static volatile Boolean USB_TaskSleeping;
static volatile Uint32 USB_TaskTick;
/*
* Output packets queued for sending are linked to the outpacketHead chain.
* These packets are packets used for sending back-channel data to
* the host from the application. The packets may be of mixed sizes. The packet
* carries the address of the head of its home pool so that it can be returned
* to the correct pool after it has been sent.
*
* outpacketHead[1] Printer endpoint
* outpacketHead[3] HID endpoint
* outpacketHead[7] Debug endpoint
*
* other entries are not used.
*/
static OUT_PACKET *outpacketHead[8];
#if SCANNER_EPS
#define SCAN_TABLE_SIZE 200
static struct {
Uint8 *data;
volatile Uint32 length;
volatile Uint32 index_req; /* index of next packet to send (FIFO mode) */
volatile Uint32 index_done; /* index of data already sent */
#if USB_ENA_SCN_FLUSH
volatile Boolean null_req; /* need to send a zero-length packet at end */
#endif
} scan_table[SCAN_TABLE_SIZE];
static volatile int scan_inx, scan_outx;
static volatile Boolean scan_active;
#if SCAN_TO_HOST_ENABLED
void USBConsumeWriteScan(Uint8 *buffer);
# define CONSUME_WRITE_SCAN(_b) USBConsumeWriteScan(_b)
#else
# define CONSUME_WRITE_SCAN(_b)
#endif
#endif /* SCANNER_EPS */
#ifdef MEMORY_CARD_READER
static volatile struct {
Uint8 *data; /* pointer to application's data buffer */
volatile Uint32 length; /* total length */
volatile Uint32 index_req; /* index of next packet to send (FIFO mode) */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -