Changeset 2152
- Timestamp:
- Jan 27, 2011 12:40:25 AM (2 years ago)
- Location:
- dev/usb2
- Files:
-
- 15 edited
-
device/hub/hub.fth (modified) (1 diff)
-
hcd/dev-info.fth (modified) (1 diff)
-
hcd/device.fth (modified) (11 diffs)
-
hcd/ehci/control.fth (modified) (1 diff)
-
hcd/ehci/loadpkg.fth (modified) (1 diff)
-
hcd/ehci/probe.fth (modified) (3 diffs)
-
hcd/ehci/probehub.fth (modified) (1 diff)
-
hcd/hcd-call.fth (modified) (1 diff)
-
hcd/ohci/probe.fth (modified) (3 diffs)
-
hcd/probehub.fth (modified) (1 diff)
-
hcd/uhci/loadpkg.fth (modified) (1 diff)
-
hcd/uhci/probe.fth (modified) (2 diffs)
-
hcd/uhci/uhci.fth (modified) (1 diff)
-
pkt-data.fth (modified) (1 diff)
-
pkt-func.fth (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
dev/usb2/device/hub/hub.fth
r1 r2152 34 34 decode-int nip nip 35 35 ; 36 : ?make-hub20-dev ( hub-dev -- hub-dev ) 37 is-hub20? if ( hub-dev ) 38 " hub20-dev" get-my-property if ( hub-dev ) 39 dup encode-int " hub20-dev" property ( hub-dev ) 40 else \ Property already exists ( hub-dev adr len ) 41 2drop ( hub-dev ) 42 then ( hub-dev ) 43 then ( hub-dev ) 44 ; 36 45 : probe-hub ( -- ) 37 46 ['] hub-id catch 0= if 38 is-hub20? if 39 dup encode-int " hub20-dev" property 40 then 47 ?make-hub20-dev 41 48 probe-hub-xt execute 49 then 50 ; 51 : reprobe-hub ( -- ) 52 ['] hub-id catch 0= if 53 reprobe-hub-xt execute 42 54 then 43 55 ; -
dev/usb2/hcd/dev-info.fth
r1674 r2152 63 63 : di-out-data-toggle ( pipe idx -- ) 2dup di-out-data@ 1 xor -rot di-out-data! ; 64 64 65 : ok-to-add-device? ( -- flag ) cur-dev 1+ #max-dev < ;66 : new-address ( -- dev ) 65 : next-device# ( -- true | dev false ) 66 cur-dev 1+ #max-dev >= if true exit then 67 67 cur-dev 1+ dup to cur-dev 68 68 /pipe0 0 cur-dev di-maxpayload! 69 false 69 70 ; 70 71 -
dev/usb2/hcd/device.fth
r1690 r2152 11 11 0 value cfg-desc-buf \ Configuration Descriptor 12 12 0 value dev-desc-buf \ Device Descriptor 13 0 value gen-desc-buf \ Any Descriptor14 13 0 value d$-desc-buf \ Device String Descriptor 15 14 0 value v$-desc-buf \ Vendor String Descriptor … … 26 25 /cfg alloc-mem dup to cfg-desc-buf /cfg erase 27 26 /cfg alloc-mem dup to dev-desc-buf /cfg erase 28 /cfg alloc-mem dup to gen-desc-buf /cfg erase29 27 /str alloc-mem dup to d$-desc-buf /str erase 30 28 /str alloc-mem dup to v$-desc-buf /str erase … … 35 33 cfg-desc-buf ?dup if /cfg free-mem 0 to cfg-desc-buf then 36 34 dev-desc-buf ?dup if /cfg free-mem 0 to dev-desc-buf then 37 gen-desc-buf ?dup if /cfg free-mem 0 to gen-desc-buf then38 35 d$-desc-buf ?dup if /str free-mem 0 to d$-desc-buf then 39 36 v$-desc-buf ?dup if /str free-mem 0 to v$-desc-buf then … … 41 38 ; 42 39 40 : dev-desc@ ( index -- byte ) dev-desc-buf + c@ ; 41 : get-class ( -- class subclass protocol ) 42 4 dev-desc@ ?dup if ( class ) 43 \ Class is in device descriptor 44 true to class-in-dev? ( class ) 45 5 dev-desc@ 6 dev-desc@ ( class subclass protocol ) 46 else ( ) 47 \ Class is in interface descriptor 48 false to class-in-dev? ( ) 49 cfg-desc-buf my-address find-intf-desc ( intf-adr ) 50 >r r@ 5 + c@ r@ 6 + c@ r> 7 + c@ ( class subclass protocol ) 51 then 52 ; 53 43 54 : make-class-properties ( -- ) 44 dev-desc-buf cfg-desc-buf my-address get-class( class subclass protocol )55 get-class ( class subclass protocol ) 45 56 " protocol" int-property 46 57 " subclass" int-property … … 84 95 ; 85 96 97 : get-vid ( adr -- vendor product rev ) 98 dev-desc-buf 8 + le-w@ dev-desc-buf d# 10 + le-w@ dev-desc-buf c + le-w@ 99 ; 100 86 101 : make-vendor-properties ( -- ) 87 dev-desc-bufget-vid ( vendor product rev )102 get-vid ( vendor product rev ) 88 103 " release" int-property 89 104 " device-id" int-property … … 257 272 ; 258 273 259 : reuse-node ( dev intf port phandle -- ) 260 >r drop ( dev intf r: phandle ) 261 262 2dup reregister-pipes ( dev intf r: phandle ) 263 drop ( dev r: phandle ) 264 265 \ Change the assigned-address property without leaking memory 266 " assigned-address" r@ get-package-property if ( dev r: phandle ) 267 drop ( r: phandle ) 268 else ( dev adr len r: phandle ) 269 drop be-l! ( r: phandle ) 270 then ( r: phandle ) 271 274 : probe-hub-node ( phandle -- ) 275 >r ( r: phandle ) 272 276 " probe-hub" r@ find-method if ( xt r: phandle ) 273 277 r@ push-package ( xt r: phandle ) … … 278 282 pop-package ( r: phandle ) 279 283 then ( r: phandle ) 280 281 284 r> drop 282 285 ; 283 286 : reuse-node ( dev intf port phandle -- ) 287 >r drop ( dev intf r: phandle ) 288 289 2dup reregister-pipes ( dev intf r: phandle ) 290 drop ( dev r: phandle ) 291 292 \ Change the assigned-address property without leaking memory 293 " assigned-address" r@ get-package-property if ( dev r: phandle ) 294 drop ( r: phandle ) 295 else ( dev adr len r: phandle ) 296 drop be-l! ( r: phandle ) 297 then ( r: phandle ) 298 299 r> probe-hub-node 300 ; 284 301 : id-match? ( dev intf port phandle -- dev intf port phandle flag? ) 285 302 " vendor-id" 2 pick get-package-property if false exit then … … 289 306 " release" 2 pick get-package-property if r> r> 2drop false exit then 290 307 decode-int nip nip >r ( dev intf port phandle r: vid did rev ) 291 dev-desc-buf get-vid( dev intf port phandle vid1 did1 rev1 r: vid did rev )308 get-vid ( dev intf port phandle vid1 did1 rev1 r: vid did rev ) 292 309 r> = -rot r> = -rot r> = and and 293 310 ; … … 336 353 337 354 \ Get all the descriptors we need in making properties now because target is 338 \ questionable in the child's context. 355 \ questionable in the child's context. The descriptor buffers are not instance 356 \ data, so they can be accessed by code that is defined in the root hub node 357 \ but executing in a subordinate hub node context or a child node context. 339 358 340 359 h# 409 constant language \ Unicode id 360 \ Executed in root hub node context 341 361 : get-string ( lang idx adr -- actual ) 342 362 over 0= if 3drop 0 exit then \ No string index 343 363 -rot get-str-desc 344 364 ; 365 366 \ Executed in root hub node context 345 367 : get-str-descriptors ( -- ) 346 368 language ( lang ) … … 349 371 dev-desc-buf d# 16 + c@ s$-desc-buf get-string to /s$-desc-buf 350 372 ; 351 : refresh-desc-bufs ( -- ) 373 374 \ Executed in root hub node context 375 : refresh-desc-bufs ( dev -- ) 376 set-target 352 377 dev-desc-buf 12 get-dev-desc to /dev-desc-buf \ Refresh dev-desc-buf 353 378 cfg-desc-buf 0 get-cfg-desc to /cfg-desc-buf \ Refresh cfg-desc-buf … … 355 380 ; 356 381 357 : set-maxpayload ( dev -- ) 358 dev-desc-buf /pipe0 get-dev-desc if 359 dev-desc-buf 7 + c@ 0 rot di-maxpayload! 360 else 361 drop 362 then 363 ; 364 382 \ Executed in root hub node context 383 : get-initial-descriptors ( dev -- ) 384 dev-desc-buf /pipe0 get-dev-desc if ( dev ) 385 dev-desc-buf 7 + c@ 0 rot di-maxpayload! ( ) 386 else ( dev ) 387 drop ( ) 388 then ( ) 389 cfg-desc-buf 0 get-cfg-desc to /cfg-desc-buf ( ) 390 ; 391 392 \ Executed in hub node context (root hub or subordinate hub) - creates new child nodes via (make-device-node) 365 393 : make-device-node ( port dev -- ) 366 dup set-maxpayload ( port dev ) 367 cfg-desc-buf 0 get-cfg-desc dup to /cfg-desc-buf 368 0= if 2drop exit then 369 cfg-desc-buf 4 + c@ 0 ?do ( port dev ) 370 dup set-target ( port dev ) \ Refresh target 371 refresh-desc-bufs ( port dev ) 372 2dup swap i (make-device-node) ( port dev ) 373 loop 2drop ( ) 394 dup " get-initial-descriptors" my-self $call-method ( port dev ) 395 /cfg-desc-buf 0= if 2drop exit then ( port dev ) 396 cfg-desc-buf 4 + c@ 0 ?do ( port dev ) 397 dup " refresh-desc-bufs" my-self $call-method ( port dev ) 398 2dup swap i (make-device-node) ( port dev ) 399 loop 2drop ( ) 400 ; 401 402 \ See hcd/ehci/probehub.fth for information about hub20-dev and hub20-port 403 404 : get-hub20-dev ( -- hub-dev ) 405 " hub20-dev" get-inherited-property 0= if ( value$ ) 406 decode-int nip nip ( hub-dev ) 407 else ( ) 408 1 ( hub-dev ) 409 then ( hub-dev ) 410 ; 411 412 : get-hub20-port ( port -- port' ) 413 " hub20-port" get-inherited-property 0= if ( port value$ ) 414 rot drop ( value$ ) 415 decode-int nip nip ( port' ) 416 then ( port ) 417 ; 418 419 \ Executed in the root hub node context 420 : setup-new-node ( port speed hub-port hub-dev -- true | port dev xt false ) 421 \ Allocate device number 422 next-device# if 2drop exit then ( port speed hub-port hub-dev dev ) 423 424 tuck di-hub! ( port speed hub-port dev ) 425 tuck di-port! ( port speed dev ) 426 tuck di-speed! ( port dev ) 427 428 0 set-target ( port dev ) \ Address it as device 0 429 dup set-address if ( port dev ) \ Assign it usb addr dev 430 ." Retrying with a delay" cr 431 over reset-port d# 5000 ms 432 dup set-address if ( port dev ) \ Assign it usb addr dev 433 \ Recycle device number? 434 2drop false exit ( -- false ) 435 then ( port dev ) 436 then ( port dev ) 437 438 dup set-target ( port dev ) \ Address it as device dev 439 ['] make-device-node true ( port dev xt ) 440 ; 441 442 \ Begins execution in a (root or subordinate) hub node context, creates an instance record 443 \ for the subordinate hub node "phandle", switches to that instance context, executes 444 \ "reprobe-hub" in that context, destroys the instance, and returns to the original context. 445 : reprobe-hub-node ( phandle -- ) 446 >r ( r: phandle ) 447 " reprobe-hub" r@ find-method if ( xt r: phandle ) 448 r@ push-package ( xt r: phandle ) 449 " " new-instance ( xt r: phandle ) 450 set-default-unit ( xt r: phandle ) 451 execute ( r: phandle ) 452 destroy-instance ( r: phandle ) 453 pop-package ( r: phandle ) 454 then ( r: phandle ) 455 r> drop 456 ; 457 458 \ Returns true if there is a child hub node associated with port 459 : port-is-hub? ( port -- false | phandle true ) 460 my-self ihandle>phandle child ( port phandle ) 461 begin ?dup while ( port phandle ) 462 " name" 2 pick get-package-property 0= if ( port phandle adr len ) 463 1- " hub" $= if ( port phandle ) 464 " reg" 2 pick get-package-property 0= if ( port phandle adr len ) 465 decode-int nip nip ( port phandle port1 ) 466 2 pick = if ( port phandle ) 467 nip true exit ( -- phandle true ) 468 then ( port phandle ) 469 then ( port phandle ) 470 then ( port phandle ) 471 then ( port phandle ) 472 peer ( port phandle' ) 473 repeat ( port ) 474 drop false ( false ) 374 475 ; 375 476 -
dev/usb2/hcd/ehci/control.fth
r1651 r2152 66 66 pt-ctrl of QH_MULT1 d# 64 endof ( qh endp-char endp-cap /max ) 67 67 pt-bulk of QH_MULT1 d# 512 endof ( qh endp-char endp-cap /max ) 68 ( default ) r>QH_MULT1 my-maxpayload r>68 ( default ) >r QH_MULT1 my-maxpayload r> 69 69 ( qh endp-char endp-cap /max ) 70 70 endcase -
dev/usb2/hcd/ehci/loadpkg.fth
r1 r2152 22 22 fload ${BP}/dev/usb2/hcd/fcode.fth \ Load fcode driver for child 23 23 fload ${BP}/dev/usb2/hcd/device.fth \ Make child node & its properties 24 fload ${BP}/dev/usb2/hcd/ehci/probehub.fth \ USB 2.0 hub specific stuff 24 25 fload ${BP}/dev/usb2/hcd/ehci/probe.fth \ Probe root hub 25 fload ${BP}/dev/usb2/hcd/ehci/probehub.fth \ USB 2.0 hub specific stuff 26 fload ${BP}/dev/usb2/hcd/probehub.fth \ Probe usb hub 27 28 26 fload ${BP}/dev/usb2/hcd/probehub.fth \ Generic hub probing -
dev/usb2/hcd/ehci/probe.fth
r1998 r2152 6 6 7 7 : make-root-hub-node ( port -- ) 8 ok-to-add-device? 0= if drop exit then \ Can't add another device 9 10 0 set-target ( port ) \ Address it as device 0 11 8 \ Some devices (e.g. Lexar USB-to-SD) fail unless you get the cfg desc from device 0 first 9 0 set-target \ First address it as device 0 ( port ) 12 10 speed-high 0 di-speed! \ Use high speed for getting the device descriptor 13 \ Some devices (e.g. Lexar USB-to-SD) don't work unless you do this first 14 dev-desc-buf h# 40 get-cfg-desc drop 15 16 new-address ( port dev ) 17 speed-high over di-speed! ( port dev ) 18 19 0 set-target ( port dev ) \ Address it as device 0 20 21 dup set-address if ( port dev ) \ Assign it usb addr dev 22 ." Retrying with a delay" cr 23 over reset-port d# 5000 ms 24 dup set-address if ( port dev ) \ Assign it usb addr dev 25 2drop exit 26 then 27 then ( port dev ) 28 29 dup set-target ( port dev ) \ Address it as device dev 30 make-device-node ( ) 11 dev-desc-buf h# 40 get-cfg-desc drop ( port ) 12 13 speed-high ( port speed ) 14 15 \ hub-port and hub-dev route USB 1.1 transactions through USB 2.0 hubs 16 over get-hub20-port get-hub20-dev ( port speed hub-port hub-dev ) 17 18 \ Execute setup-new-node in root context and make-device-node in hub node context 19 setup-new-node if execute then ( ) 31 20 ; 32 21 … … 44 33 else \ A high speed device detected 45 34 dup ['] make-root-hub-node catch if \ Process high speed device 46 drop ." Failed to probe rootport " dup .d cr35 drop ." Failed to make root hub node for port " dup .d cr 47 36 true to probe-error? 48 37 then … … 106 95 \ i rm-obsolete-children \ Remove obsolete device nodes 107 96 i probe-root-hub-port \ Probe it 97 else 98 i port-is-hub? if ( phandle ) \ Already-connected hub? 99 reprobe-hub-node \ Check for changes on its ports 100 then 108 101 then 109 102 loop -
dev/usb2/hcd/ehci/probehub.fth
r1 r2152 32 32 33 33 : ?set-hub20-port ( speed dev port -- ) 34 " hub20-dev" my-parent ihandle>phandle get-package-property 0= if 35 2drop nip swap speed-high <> if 36 " hub20-port" int-property 37 else 38 drop 39 then 40 else 41 3drop 42 then 34 " hub20-dev" my-parent ihandle>phandle get-package-property 0= if ( speed dev port value$ ) 35 2drop ( speed dev port ) 36 nip swap speed-high <> if ( port ) 37 encode-int " hub20-port" property ( ) 38 else ( speed ) 39 drop ( ) 40 then ( ) 41 else ( speed dev port ) 42 3drop ( ) 43 then ( ) 43 44 ; 44 45 ' ?set-hub20-port to make-dev-property-hook 45 46 : get-hub20-dev ( -- hub-dev )47 " hub20-dev" get-inherited-property 0= if48 decode-int nip nip49 else50 151 then52 ;53 54 : get-hub20-port ( port -- port' )55 " hub20-port" get-inherited-property 0= if56 rot drop ( $ )57 decode-int nip nip58 then59 ;60 61 \ Initialize USB 2.0 specific characteristics in di62 : set-usb20-char ( port dev -- )63 get-hub20-dev over di-hub!64 swap get-hub20-port swap di-port!65 ;66 46 67 47 headers -
dev/usb2/hcd/hcd-call.fth
r1704 r2152 11 11 : dma-free ( virt size -- ) " dma-free" $call-parent ; 12 12 13 : set-target ( device -- ) " set-target" $call-parent ; 14 : probe-hub-xt ( -- adr ) " probe-hub-xt" $call-parent ; 15 : set-pipe-maxpayload ( size len -- ) " set-pipe-maxpayload" $call-parent ; 13 \ Probing support 14 : set-target ( device -- ) 15 " set-target" $call-parent 16 ; 17 : probe-hub-xt ( -- adr ) 18 " probe-hub-xt" $call-parent 19 ; 20 : reprobe-hub-xt ( -- adr ) 21 " reprobe-hub-xt" $call-parent 22 ; 23 : set-pipe-maxpayload ( size len -- ) 24 " set-pipe-maxpayload" $call-parent 25 ; 26 : setup-new-node ( port speed hub-port hub-dev -- false | port dev xt true ) 27 " setup-new-node" $call-parent 28 ; 29 : get-initial-descriptors ( dev -- ) 30 " get-initial-descriptors" $call-parent 31 ; 32 : refresh-desc-bufs ( dev -- ) 33 " refresh-desc-bufs" $call-parent 34 ; 16 35 17 36 \ Control pipe operations -
dev/usb2/hcd/ohci/probe.fth
r1654 r2152 5 5 headers 6 6 7 : enable-root-hub-port ( port -- )7 : reset-port ( port -- ) 8 8 >r 9 9 h# 1.0002 r@ hc-rh-psta! \ enable port … … 19 19 20 20 : probe-root-hub-port ( port -- ) 21 dup hc-rh-psta@ 1 and 0= if drop exit then \ No device connected 22 ok-to-add-device? 0= if drop exit then \ Can't add another device 21 dup hc-rh-psta@ 1 and 0= if drop exit then ( port ) \ No device connected 23 22 24 dup enable-root-hub-port ( port )25 new-address ( port dev)26 over hc-rh-psta@ 200 and if speed-low else speed-full then over di-speed!23 \ Reset the port to determine the speed 24 dup reset-port ( port ) 25 dup hc-rh-psta@ 200 and if speed-low else speed-full then ( port speed ) 27 26 28 0 set-target ( port dev ) \ Address it as device 0 29 dup set-address if 2drop exit then ( port dev ) \ Assign it usb addr dev 30 dup set-target ( port dev ) \ Address it as device dev 31 make-device-node ( ) 27 \ hub-port and hub-speed are irrelevant for OHCI (USB 1.1) 28 0 0 ( port speed hub-port hub-dev ) 29 30 \ Execute setup-new-node in root context and make-device-node in hub node context 31 setup-new-node if execute then ( port dev xt ) 32 32 ; 33 33 … … 100 100 then 101 101 3.0000 i hc-rh-psta! \ Clear change bits 102 else 103 i port-is-hub? if ( phandle ) \ Already-connected hub? 104 reprobe-hub-node \ Check for changes on its ports 105 then 102 106 then 103 107 loop -
dev/usb2/hcd/probehub.fth
r2070 r2152 8 8 [then] 9 9 10 : power-hub-port ( port -- ) PORT_POWER DR_PORT set-feature drop ; 11 : reset-hub-port ( dev port -- ) PORT_RESET DR_PORT set-feature drop d# 20 ms ; 10 8 buffer: hub-buf \ For hub probing 11 12 : power-hub-port ( port -- ) PORT_POWER DR_PORT " set-feature" $call-parent drop ; 13 : reset-hub-port ( port -- ) PORT_RESET DR_PORT " set-feature" $call-parent drop d# 20 ms ; 14 : clear-status-change ( port -- ) C_PORT_CONNECTION DR_PORT " clear-feature" $call-parent drop ; 15 : parent-set-target ( dev -- ) " set-target" $call-parent ; 16 : get-port-status ( port -- error? ) 17 hub-buf 4 2 pick DR_PORT " get-status" $call-parent ( port actual usberror ) 18 nip if ( port ) 19 ." Failed to get port status for port " u. cr 20 true ( true ) 21 else ( port ) 22 drop false ( false ) 23 then ( ) 24 ; 25 : port-status-changed? ( hub-dev port -- false | connected? true ) 26 swap parent-set-target ( port ) 27 dup get-port-status if ( port ) 28 drop false exit ( -- false ) 29 then ( port ) 30 31 hub-buf 2+ c@ 1 and if ( port ) 32 \ Status changed 33 clear-status-change ( ) 34 hub-buf c@ 1 and 0<> ( connected? ) 35 true ( connected? true ) 36 else ( port ) 37 drop false ( false ) 38 then 39 ; 12 40 13 41 : probe-hub-port ( hub-dev port -- ) 14 swap set-target ( port ) 15 dup reset-hub-port ( port ) 42 \ Reset the port to determine the speed 43 swap parent-set-target ( port ) 44 dup reset-hub-port ( port ) 16 45 17 gen-desc-buf 4 2 pick DR_PORT get-status nip if18 ." Failed to get port status for port " u. cr19 exit20 then( port )46 \ get-port-status fills hub-buf with connection status, speed, and other information 47 dup get-port-status ( port error? ) 48 over clear-status-change ( port error? ) 49 if drop exit then ( port ) 21 50 22 gen-desc-buf c@ 1 and 0= ifdrop exit then \ No device connected23 ok-to-add-device? 0= if drop exit then \ Can't add another device51 hub-buf c@ 1 and 0= if drop exit then \ No device connected 52 hub-buf le-w@ h# 600 and 9 >> ( port speed ) 24 53 25 new-address ( port dev ) 26 gen-desc-buf le-w@ h# 600 and 9 >> over di-speed! 27 ( port dev ) 28 2dup set-usb20-char ( port dev ) 54 \ hub-port and hub-dev route USB 1.1 transactions through USB 2.0 hubs 55 over get-hub20-port get-hub20-dev ( port speed hub-port hub-dev ) 29 56 30 0 set-target ( port dev ) \ Address it as device 0 31 dup set-address if 2drop exit then ( port dev ) \ Assign it usb addr dev 32 dup set-target ( port dev ) \ Address it as device dev 33 make-device-node ( ) 57 \ Execute setup-new-node in root context and make-device-node in hub node context 58 " setup-new-node" $call-parent if execute then ( ) 34 59 ; 35 60 61 : hub-#ports ( -- n ) 62 hub-buf 8 0 0 HUB DR_HUB " get-desc" $call-parent nip if 63 ." Failed to get hub descriptor" cr 64 0 exit 65 then 66 hub-buf 2 + c@ 1+ ( #ports ) 67 ; 68 : hub-delay ( -- #2ms ) hub-buf 5 + c@ ; 69 70 : power-hub-ports ( #ports -- ) 71 1 ?do i power-hub-port loop ( ) 72 73 hub-delay 2* ms ( ) 74 75 " usb-delay" ['] evaluate catch if ( ) 76 2drop d# 100 ( ms ) 77 then ( ms ) 78 ms 79 ; 80 81 : safe-probe-hub-port ( hub-dev port -- ) 82 tuck ['] probe-hub-port catch if ( port x x ) 83 2drop ." Failed to probe hub port " . cr ( ) 84 else ( port ) 85 drop ( ) 86 then ( ) 87 ; 36 88 external 37 89 : probe-hub ( dev -- ) 38 dup set-target ( hub-dev ) 39 gen-desc-buf 8 0 0 HUB DR_HUB get-desc nip if 40 ." Failed to get hub descriptor" cr 41 exit 42 then 90 dup parent-set-target ( hub-dev ) 91 hub-#ports ( hub-dev #ports ) 43 92 44 gen-desc-buf dup 5 + c@ swap ( hub-dev #2ms adr ) 45 2 + c@ 1+ ( hub-dev #2ms #ports ) 93 " configuration#" get-int-property 94 " set-config" $call-parent ( hub-dev #ports usberr ) 95 if drop ." Failed to set config for hub at " u. cr exit then ( hub-dev #ports ) 46 96 47 " configuration#" get-int-property set-config ( hub-dev #2ms #ports usberr ) 48 if 2drop ." Failed to set config for hub at " u. cr exit then 97 dup power-hub-ports ( hub-dev #ports ) 49 98 50 tuck 1 ?do i power-hub-port loop 2* ms 51 ( hub-dev #ports ) 52 " usb-delay" ['] evaluate catch if ( hub-dev #ports x x ) 53 2drop d# 100 ( hub-dev #ports ms ) 54 then ( hub-dev #ports ms ) 55 ms 56 57 ( hub-dev #ports ) 1 ?do 58 dup i ['] probe-hub-port catch if 59 2drop 60 ." Failed to probe hub port " i u. cr 61 then 62 loop drop 99 1 ?do ( hub-dev ) 100 dup i safe-probe-hub-port ( hub-dev ) 101 loop ( hub-dev ) 102 drop ( ) 63 103 ; 64 104 65 105 : probe-hub-xt ( -- adr ) ['] probe-hub ; 106 107 : do-reprobe-hub ( dev -- ) 108 dup parent-set-target ( hub-dev ) 109 hub-#ports 1 ?do ( hub-dev ) 110 dup i port-status-changed? if ( hub-dev connected? ) 111 if ( hub-dev ) 112 dup i safe-probe-hub-port ( hub-dev ) 113 \ else Handle disconnect 114 then ( hub-dev ) 115 else ( hub-dev ) 116 i port-is-hub? if ( hub-dev phandle ) 117 reprobe-hub-node ( hub-dev ) 118 then ( hub-dev ) 119 then ( hub-dev ) 120 loop ( hub-dev ) 121 drop ( ) 122 ; 123 124 : reprobe-hub-xt ( -- adr ) ['] do-reprobe-hub ; 66 125 67 126 headers -
dev/usb2/hcd/uhci/loadpkg.fth
r1 r2152 22 22 fload ${BP}/dev/usb2/hcd/fcode.fth \ Load fcode driver for child 23 23 fload ${BP}/dev/usb2/hcd/device.fth \ Make child node & its properties 24 fload ${BP}/dev/usb2/hcd/probehub.fth \ Probe usb hub 24 25 fload ${BP}/dev/usb2/hcd/uhci/probe.fth \ Probe root hub 25 fload ${BP}/dev/usb2/hcd/probehub.fth \ Probe usb hub26 26 27 27 -
dev/usb2/hcd/uhci/probe.fth
r1656 r2152 5 5 headers 6 6 7 \ We mustn't wait more than 3 ms between releasing the reset and enabling 8 \ the port to begin the SOF stream, otherwise some devices (e.g. pl2303) 9 \ will go into suspend state and then not respond to set-address. 10 : reset-root-hub-port ( port -- ) 11 dup >r portsc@ h# 20e invert and ( value r: port ) \ Clear reset, enable, status 12 dup h# 200 or r@ portsc! ( value r: port ) \ Reset port 13 d# 30 ms ( value r: port ) \ > 10 ms - reset time 14 dup r@ portsc! ( value r: port ) \ Release reset 15 1 ms ( value r: port ) \ > 5.3 uS - reconnect time 16 h# e or r> portsc! ( ) \ Enable port and clear status 17 ; 7 : probe-root-hub-port ( port -- ) 8 \ Reset the port to perform connection status and speed detection 9 dup reset-port ( port ) 10 dup portsc@ 1 and 0= if drop exit then ( port ) \ No device-connected 18 11 19 : probe-root-hub-port ( port -- ) 20 dup reset-root-hub-port 21 dup portsc@ 1 and 0= if drop exit then \ No device-connected 22 ok-to-add-device? 0= if drop exit then \ Can't add another device 12 dup portsc@ 100 and if speed-low else speed-full then ( port speed ) 23 13 24 new-address ( port dev ) 25 over portsc@ 100 and if speed-low else speed-full then 26 over di-speed! ( port dev ) 14 \ hub-port and hub-speed are irrelevant for UHCI (USB 1.1) 15 0 0 ( port speed hub-port hub-dev ) 27 16 28 0 set-target ( port dev ) \ Address it as device 0 29 dup set-address if 2drop exit then ( port dev ) \ Assign it usb addr dev 30 dup set-target ( port dev ) \ Address it as device dev 31 make-device-node ( ) 17 \ Execute setup-new-node in root context and make-device-node in hub node context 18 setup-new-node if execute then ( ) 32 19 ; 33 20 … … 47 34 then 48 35 i portsc@ i portsc! \ Clear change bits 36 else 37 i port-is-hub? if ( phandle ) \ Already-connected hub? 38 reprobe-hub-node \ Check for changes on its ports 39 then 49 40 then 50 41 loop -
dev/usb2/hcd/uhci/uhci.fth
r1987 r2152 38 38 : portsc@ ( port -- data ) 2* 10 + uhci-w@ ; 39 39 : portsc! ( data port -- ) 2* 10 + uhci-w! ; 40 41 \ We mustn't wait more than 3 ms between releasing the reset and enabling 42 \ the port to begin the SOF stream, otherwise some devices (e.g. pl2303) 43 \ will go into suspend state and then not respond to set-address. 44 : reset-port ( port -- ) 45 dup >r portsc@ h# 20e invert and ( value r: port ) \ Clear reset, enable, status 46 dup h# 200 or r@ portsc! ( value r: port ) \ Reset port 47 d# 30 ms ( value r: port ) \ > 10 ms - reset time 48 dup r@ portsc! ( value r: port ) \ Release reset 49 1 ms ( value r: port ) \ > 5.3 uS - reconnect time 50 h# e or r> portsc! ( ) \ Enable port and clear status 51 ; 40 52 41 53 : reset-usb ( -- ) -
dev/usb2/pkt-data.fth
r1 r2152 81 81 \ Use tmp-l to make sure that le-l! and le-w! are atomic writes 82 82 83 instancevariable tmp-l83 variable tmp-l 84 84 : le-w@ ( a -- w ) dup c@ swap ca1+ c@ bwjoin ; 85 85 : (le-w!) ( w a -- ) >r wbsplit r@ ca1+ c! r> c! ; -
dev/usb2/pkt-func.fth
r1 r2152 23 23 dup c@ + ( intfidx adr' ) 24 24 repeat 25 ;26 27 : get-class ( dev-adr cfg-adr intfidx -- protocol subclass class )28 rot dup 4 + c@ ?dup 0= if ( cfg-adr intfidx dev-adr )29 false to class-in-dev? \ Class is not in device descriptor30 drop find-intf-desc ( intf-adr )31 dup 5 + c@ swap dup 6 + c@ swap 7 + c@32 else \ Class is in device-descriptor33 true to class-in-dev? ( cfg-adr intfidx dev-adr class )34 2swap 2drop ( dev-adr class )35 swap dup 5 + c@ swap 6 + c@36 then37 ;38 39 : get-vid ( adr -- vendor product rev )40 dup 8 + le-w@ swap dup d# 10 + le-w@ swap c + le-w@41 25 ; 42 26
Note: See TracChangeset
for help on using the changeset viewer.
