📄 sl811hs_appnote.txt
字号:
{
BYTE tmp;
tmp = SL11Read(CtrlReg); // Read Control Status
SL11Write(CtrlReg,tmp | 8); // Setup USB Reset
Delayms(250,0);
SL11Write(CtrlReg,tmp | 0x18); // suspend/resume, reset
Delayms(150,0);
SL11Write(CtrlReg,tmp | 8); // Setup USB Reset
Delayms(10,0); // Delay 10 ms
SL11Write(CtrlReg,tmp); // enable USB
}
USB Trace 1: USB Reset
4.1.5 CRC5/16 Generation
The SL811HS automatically computes and verifies all CRC5 and CRC16 by hardware. No CRC is required to be generated or verified by external firmware.
4.1.6 Zero Length Packet
The Zero Length Packet is a NULL packet during the IN or OUT transaction phase. For example, SL811HS will send the Zero Length Packet after a successful IN, OUT transaction to verify that the device endpoint has successfully returned the contents of the descriptor.
Figure 4: Zero Length Data Packet
4.1.7 Double Buffer Operation
SL811HS memory structure is a ping-pong (double buffer) scheme. The software sequentially sets up Data PID, Endpoint, Device Address, and Payload for each USB packet transfer. The Data PID includes DATA0 PID and DATA1 PID. The DATA0 starts from a memory location at 0x10 and DATA1 PID starts at (DATA0 + Payload). The SL811HS provides two control registers to setup Endpoint, and Address to USB Device. The Payload is available from 8,16, 32, 64 for Control/Interrupt/Bulk USB Transactions and up to 118-bytes for ISO transactions.
Program Sample 7: Data, Endpoint, and Address
SL811HS provides two EP0Status=0x03 and EP0Counter =0x04 registers for setting USB device PID, Endpoint, and Address. SL811HS host mode allows the user to setup any of the 16 endpoints and any of the 127 addresses.
ep = (crc>>7) & 0xf;
data0 = 0x10; // Memory start
SL11Write(EP0Address, (BYTE)data0); // DATA0
...
// Setup PID, Endpoint, and device Address
SL11Write(EP0Status, (BYTE)( (pid << 4) + ep ) );
SL11Write(EP0Counter, (BYTE)(crc & 0x7f));
// setup 3-byte header + payload
SL11Write(EP0XferLen,(BYTE)(payload));
...
// setup next ping-pong buffer
data1 = data0 + payload; // next buffer
...
4.1.8 Single IN Packet
Example of a single IN Packet transaction: The IN Packet includes transmission of IN PID with device address and endpoint. The device responds with either DATA0 or DATA1 token and data payload. The program sample shows PID IN packet followed by a Data0 packet. For continuous IN packets, the device is required to toggle Data tokens i.e., Data0, Data1, and so on.
Program Sample 8: Single IN Packet
short addr = 3; // address 3
...
SL11Write(EP0Address, (BYTE)cMemStart); // DATA0
// PID_IN and endpoint 1
SL11Write(EP0Status, ((PID_IN & 0xff)<<4) | 1); // PID + ep
SL11Write(EP0Counter, addr);
SL11Write(EP0XferLen,payload); // payload
SL11Write(EP0Control,DATA0_RD);
USB Trace 2: IN Packet
4.1.9 Single OUT Packet
Example of a single OUT Packet: The OUT Packet transaction consists of an OUT PID containing device USB address and Endpoint. It is followed by a DATA token with data payload. The program sample shows a PID OUT token followed by a Data0 packet. For continuous OUT packets, Data tokens are required to toggle between Data0 and Data1, and so on.
Program Sample 9: Single OUT Packet
short addr = 3; // address 3
...
SL11Write(EP0Address, (BYTE)cMemStart); // DATA0
// PID_IN and endpoint 2
SL11Write(EP0Status, ((PID_OUT & 0xff)<<4) | 2); // PID + ep
SL11Write(EP0Counter, addr);
SL11Write(EP0XferLen,payload); // payload
SL11Write(EP0Control,DATA0_WR);
USB Trace 3: OUT Packet
4.1.10 Short Data Packet
Cypress Semiconductor Corporation
SL811HS and SL811HST: Application Notes
The short Data Packet occurs when the host does not know the transfer length of the USB device during the IN transaction. This can cause a Bus Time-out or a Babble condition.
Program Sample 10: Short Data Packet
... // check PID IN
if (pid == PID_IN)
rem = (BYTE)SL11Read(EP0Counter);
len -= rLen; // rLen = actual read/write
if (bLen && len > 0)
{
SL11Write(EP0XferLen, (BYTE)(bLen));
SL11Write(EP0Address, addr); // data address
// Clear the Interrupt Status
SL11Write(IntStatus, 0xff);
if (pid == PID_IN && rem == 0) // Check to arm
SL11Write(EP0Control, (DATA0_RD));
}
if (pid == PID_IN)
{
SL11BufRead((short)((Cmd & 0x40) ? data0: data1), buf, rLen);
//Short packet detection
if (rem > 0) // Remainder Packet
{
printf("\nShort packet detection %x\n", rem);
return len; // return Length
}
}
...
4.1.11 USB Device Detection
USB device attachment and the speed of the attached device can be determined by monitoring the SL811HS Interrupt status register bits -5 and bit-7 (IntStatus =0x0d). When a full-speed device is attached, both bits -5 and bit-7 will be set =’1’. If a low speed device is attached, then bit-5 = ‘1’ and bit-7=0.
SL811HS detects HUB as a full-speed USB device. After Enumeration process, SL811HS software is able to determine the devices attached downstream of the HUB.
4.1.12 Full/Low Speed Detect
The SL811HS is able to detect attachment of full or low speed devices by monitoring bit-5, bit-6, and bit-7 of register 0x0d. The speed_detect () function detects full/low speed device attachment to the USB port. Also, this function generates the SOF/EOP for low/full speed within 1ms.
When the SL811H is connected to a hub, the software must perform the following to avoid a babble problem. This software implementation is a requirement for our chip. The developer must follow this code so they will not have a missing packet problem. Initialization is required for the interrupt.
Program Sample 11: Speed Detect Function
int speed_detect()
{
full_speed = 0xffff;
int i =0;
SL11HMemTest();
SL11Write(IntEna, 0x63);
SL11Write(cSOFcnt, 0xae);
SL11Write(CtrlReg, 0x48);
SL11Write(CtrlReg, i);
// Memory test
// USBA/B, Insert/Remove,USBRest/Resume.
// Set SOF high counter, no change D+/D-
// Setup Normal Operation
// Disable USB transfer operation and SOF
#ifdef SL811H
SL11Write(cSOFcnt, 0xae);
SL11Write(CtrlReg, 0x48);
Delayms(10,0);
SL11Write(CtrlReg, 0);
Delayms(10,0);
i =
SL11Read(IntStatus);
/
// Set SOF high counter, no change D+/D-
// Clear SL811H mode and setup normal operation
// Delay for HW stablize
// Disable USB transfer operation and SOF
/ Read Interrupt Status
if(i & 0x40)
{
SL11Write(IntStatus,0x40);
printf("No device or No Power\n");
}
if(!(SL11Read(IntStatus)&0x40))
{
if ((i & 0x80) == 0) // Checking full or low speed
{
printf("Low Speed is detected %x\n", i);
// Set up Master and low Speed direct and SOF cnt high=0x2e
SL11Write(cSOFcnt,0xee);
// SOF Counter Low = 0xe0; 1ms interval
SL11Write(cDATASet,0xe0);
// Setup 6MHz and EOP enable
SL11Write(CtrlReg,0x21);
full_speed = 0;
}
else
{
printf("Full Speed is detected %x\n", i);
// Set up Master and low Speed direct and SOF cnt high=0x2e
SL11Write(cSOFcnt,0xae);
// SOF Counter Low = 0xe0; 1ms interval
SL11Write(cDATASet,0xe0);
// Setup 48MHz and SOF enable
SL11Write(CtrlReg,0x05);
}
}
else
{
SL11Write(IntStatus,0xff);
}
SL11Write(EP0Status, 0x50); // Setup SOF Token
SL11Write(EP0Counter, 0);
SL11Write(EP0Control, 0x01); // start generate SOF or EOP
Delayms(25,0); // Hub required approx. 24.1mS
#endif
return 0;
}
Cypress Semiconductor Corporation
SL811HS and SL811HST: Application Notes
Example for doing PID_IN or PID_OUT or PID_SETUP with payload = 8; then the Software requirement is:
static short low_speed_via_hub = 0;
// the low_speed_via_hub will be set high only when the HUB detect low
// speed device attach to the HUB.
short int_cnt=0;
short pl, Cmd=DATA0_RD, loop=30000;
if (low_speed_via_hub)
{
pl = payload + 16; // low speed
Cmd |= 0x80; //
}
else pl = (payload>>3) + 3;
SL11Write(EP0Status, (BYTE)( (PID_IN << 4) + 0 ) );
SL11Write(EP0Counter, 0);
SL11Write(EP0XferLen, payload); // setup 3-byte header + payload
SL11Write(EP0Address, 0x10); // DATA0
while( loop-- )
{
int_cnt++;
SL11Write(IntStatus,0xff);
if (SL11Read(0xf) > (BYTE)pl)
SL11Write(EP0Control,Cmd); // Enable ARM
else
SL11Write(EP0Control,Cmd|0x20); // Enable ARM and Wait after SOF
// just for example only. If CPU uses the Interrupt
Delay1ms(2,0);
// should check the interrupt variable "int_cnt"
if ((SL11Read(IntStatus)&1)==0)
printf("Missing Interrupt\n");
else int_cnt--;
}
if (int_cnt)
printf("Missing interrupt\n");
4.1.13 SOF or EOP Generation
The USB Specification v1.1 requires a host controller to generate an End of Packet (EOP) at regular timed intervals -nominally every 1 millisecond -to keep low speed devices alive. An EOP is defined as two single-ended zeros (SE0) followed by a J State. See figure below for EOP pulse width.
Figure 5: EOP Pulse Width
The width of the SE0 in the EOP is approximately 2 * TPERIOD. The SE0 width is measured with the same load used for maximum rise and fall times and is measured at the same level as the differential signal crossover points of the data lines.
Program Sample 12: Hardware EOP Generation
int hw_sof()
{
... // Need USB Reset
SL11Write(cDATASet,0xe0); // Set up SOF or EOP for 1ms interval
SL11Write(cSOFcnt,0xae); // Set up frame counter
SL11Write(CtrlReg,05); // Enable SOF/EOP
SL11Write(EP0Control, 0x01); // Start SOF/EOP
}
An EOP is generated by within the SL811HS hardware; therefore, there is no need to use an external CPU to generate an EOP when using the SL811HS. The following is a sequence showing the SL811HS generating the EOP during Token, Data, and Handshaking phases.
Figure 6: Token Phase
Figure 7: Data Phase
Figure 8: Handshaking phase
USB Trace 4: SOF Packet USB Trace 5: EOP Packet
4.1.14 Suspend State
When SL811HS is placed in suspend state, it will stop all activity on the USB Bus. Since no activity is seen downstream, slave devices will also suspend activity.
Program Sample 13: Suspend State
...
SL11Write(CtrlReg, 0);
// Stop sending SOF
SL11Write(CtrlReg,0x40);
// Suspend enable
...
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -