_FCLKFREQ = 297000000.0 ' 160_000_000.0 _CLKFREQ = round(_FCLKFREQ) mov htmp, ##_CLKFREQ _12Mbps = round((12_000_000.0 / _FCLKFREQ) * 65536.0) ' = 4369 NCO @180MHz, 9830 @80MHz wxpin ##_12Mbps, #DM ' Default to Full-Speed (NOTE: REVA only code!) USB_H_FS_NCO = %11 << 14 + _12Mbps wxpin ##USB_H_FS_NCO, #DM ' Host mode and default to 12Mbs baudrate (patched code for REVB) USB_D_FS_NCO = %01 << 14 + _12Mbps _1_5Mbps = round((1_500_000.0 / _FCLKFREQ) * 65536.0) ' = 546 NCO @180MHz, 1229 @80Mhz if_z wxpin ##_1_5Mbps, #DM ' Set 1.5Mbs baudrate if no downstream hub (NOTE: REVA only code!) USB_H_LS_NCO = %10 << 14 + _1_5Mbps if_z wxpin ##USB_H_LS_NCO, #DM ' Host mode and 1.5Mbs baudrate if no downstream hub (patched code for REVB) USB_D_LS_NCO = %00 << 14 + _1_5Mbps _1ms = round(_FCLKFREQ / 1_000.0) _1us = round(float(_1ms) / 1_000.0) _100ns = round(float(_1us) / 1_000.0 * 100.0) IP_DELAY_LS = round(4.0 * LSBTns * float(_1us) / 1000.0) ' Range @180MHz: 240 to 901 clocks (1.334us to 5.003us) mov ip_delay, ##IP_DELAY_LS ' Inter-packet delay in low-speed bit periods IP_DELAY_FS = round(4.0 * FSBTns * float(_1us) / 1000.0) ' Range @180MHz: 30 to 112 clocks (0.166us to 0.623us) _ret_ mov ip_delay, ##IP_DELAY_FS ' Inter-packet delay in full-speed bit periods TAT_WAIT_LS = round(22.0 * LSBTns * float(_1us) / 1000.0) mov tat_wait, ##TAT_WAIT_LS ' Bus turn-around time in low-speed bit periods TAT_WAIT_FS = round(28.0 * FSBTns * float(_1us) / 1000.0) mov tat_wait, ##TAT_WAIT_FS ' Bus turn-around time in full-speed bit periods TXN_OK_LS = _1us * 667 - 6 ' All USB transactions must be started within this timespan mov txn_ok_zone, ##TXN_OK_LS ' Set low-speed bandwidth usage limits NO_TXN_LS = _1us * 333 - 7 ' Low-speed needs ~33% bandwidth per max packet of 8 bytes mov no_txn_zone, ##NO_TXN_LS TXN_OK_FS = _1us * 825 - 6 ' Full-speed needs ~10% bandwidth per max packet of 64 bytes mov txn_ok_zone, ##TXN_OK_FS ' Set FS bandwidth usage limits NO_TXN_FS = _1us * 175 - 7 mov no_txn_zone, ##NO_TXN_FS mov hctwait, ##_1us * 250 ' Transaction error wait... mov hctwait, ##_1us * 33 ' Seems to be a reasonable NAK delay mov hctwait, ##_1us * 500 waitx ##_1us * 10 CONNECT_WAIT = _1ms * 250 ' Connect/disconnect verification delay RESET_HOLD = _1ms * 15 ' Host reset state hold time waitx ##RESET_HOLD ' Spec is >= 10ms XFER_WAIT = _1ms * 5 ' Transfer retry wait timespan mov hctwait, ##XFER_WAIT TO_STANDARD = _1ms * 5000 ' Non-specific maximum timout period TO_DATA = _1ms * 500 ' Standard Device requests with a data stage TO_NODATA = _1ms * 50 ' Standard Device requests without a data stage TO_SETADDR = _1ms * 50 ' Device SetAddress() command processing maximum TO_CHGADDR = _1ms * 2 ' Device SetAddress() period allowed to change its address before next request sent PULSE_TIME = _1ms * 750 ' LED-blinking heartbeat interval mov hctwait, ##PULSE_TIME >> 3 addct3 hct3, ##PULSE_TIME KBD_POLL_INTERVAL = _1ms * 8 ' Interrupt IN txn timespan if_z addct3 hct3, ##KBD_POLL_INTERVAL ' Set the timer for next poll interval addct3 hct3, ##KBD_POLL_INTERVAL ' Wait an interval before the first IN poll MOUSE_POLL_INTERVAL = _1ms * 8 ' Interrupt IN txn timespan if_z addct3 hct3, ##MOUSE_POLL_INTERVAL ' Mouse is the only connected device if_z addct3 hct3, ##MOUSE_POLL_INTERVAL ' Set first poll interval mov hctwait, ##_1ms * 21 if_nz addct3 hct3, ##_1ms * 4 ' Try to keep 4ms timespan between them if_nz addct3 hct3, ##_1ms * 4 mov hctwait, ##_1ms * 500 ' If the first GetDescriptor() fails, reset and try again mov hctwait, ##_1ms mov hctwait, ##_1ms * 8 mov hctwait, ##_1ms * 100 ' J and K high is illegal SE1 state, so wait and retest waitx ##_1ms * 100 mov hctwait, ##_1ms * 100 mov hctwait, ##_1ms mov hctwait, ##_1ms * 2 mov hctwait, ##_1ms * 500 mov hctwait, ##_1ms * 2 _1LSBT = round(_FCLKFREQ / 1_000_000_000.0 * LSBTns)' = 53 clocks @ 80Mhz, 80 clocks @ 120Mhz _1FSBT = round(_FCLKFREQ / 1_000_000_000.0 * FSBTns)' = 7 clocks @ 80Mhz, 10 clocks @ 120Mhz