Changeset 3471
- Timestamp:
- Dec 5, 2012 9:02:09 AM (6 months ago)
- Location:
- dev/usb2/device/serial
- Files:
-
- 5 edited
-
common.fth (modified) (1 diff)
-
ftdi.fth (modified) (2 diffs)
-
uart.fth (modified) (2 diffs)
-
usbserial.bth (modified) (1 diff)
-
vendor.fth (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
dev/usb2/device/serial/common.fth
r1 r3471 108 108 ' generic-rpoll to rpoll 109 109 110 [ifndef] /string 111 : /string ( adr len cnt -- adr' len' ) tuck - -rot + swap ; 112 [then] 113 114 : generic-read-bytes ( adr len -- #read ) \ -2 for none available right now 115 rpoll 116 dup 0= if nip exit then ( adr len ) 117 read-q deque? 0= if ( adr len ) 118 2drop ( ) 119 lost-carrier? if -1 false to lost-carrier? else -2 then 120 ( -2:none | -1:down ) 121 exit 122 then ( adr len char ) 123 over >r ( adr len char r: len ) 124 begin ( adr len char r: len ) 125 2 pick c! ( adr len r: len ) 126 1 /string ( adr' len' ) 127 dup 0= if 2drop r> exit then ( adr' len' ) 128 read-q deque? 0= until ( adr len r: len ) 129 nip r> swap - ( actual ) 130 ; 131 ' generic-read-bytes to read-bytes 132 110 133 : generic-write-bytes ( adr len -- actual ) 111 134 swap >r ( len ) ( R: adr ) -
dev/usb2/device/serial/ftdi.fth
r3470 r3471 21 21 : ftdi-flush-tx ( -- ) 0 2 ftdi-set ; 22 22 23 [ifndef] rounded-/ 24 : rounded-/ swap 2* swap / dup 1 and + 2/ ; 25 [then] 26 23 27 : ftdi-baud ( baud -- ) 24 28 \ There are some high bits for fractional divisors that we don't use 25 29 d# 48000000 swap rounded-/ ( divisor ) 26 0 swap3 ftdi-set30 4 rshift 3 ftdi-set 27 31 ; 28 32 … … 70 74 \ If there is no data, 2-byte status messages are sent every 40 ms. 71 75 76 : ftdi-rpoll ( -- ) 77 bulk-in? if drop restart-bulk-in exit then \ USB error; restart 78 ?dup if 79 2 ?do 80 inbuf i ca+ c@ read-q enque 81 loop 82 restart-bulk-in 83 then 84 ; 85 72 86 \ Data is transmitted on bulk endpoint 2, verbatim. 87 88 : ftdi-rts-dtr-off ( -- ) 89 ftdi-rts-off 90 ftdi-dtr-off 91 ; 92 93 : ftdi-rts-dtr-on ( -- ) 94 ftdi-rts-on 95 ftdi-dtr-on 96 ; 97 98 : ftdi-set-baud ( -- ) 99 d# 115200 ftdi-baud 100 ftdi-rts-dtr-on 101 ftdi-8n1 102 ftdi-flow-none 103 ; 104 105 : ftdi-inituart ( -- ) 106 ftdi-set-baud 107 ; 108 109 110 : init-ftdi ( -- ) 111 ['] ftdi-rts-dtr-off to rts-dtr-off 112 ['] ftdi-rts-dtr-on to rts-dtr-on 113 ['] ftdi-rpoll to rpoll 114 ['] ftdi-inituart to inituart 115 ; 116 117 : init ( -- ) 118 init 119 vid pid uart-ftdi? if init-ftdi then 120 ; 121 122 123 \ LICENSE_BEGIN 124 \ Copyright (c) 2012 FirmWorks 125 \ 126 \ Permission is hereby granted, free of charge, to any person obtaining 127 \ a copy of this software and associated documentation files (the 128 \ "Software"), to deal in the Software without restriction, including 129 \ without limitation the rights to use, copy, modify, merge, publish, 130 \ distribute, sublicense, and/or sell copies of the Software, and to 131 \ permit persons to whom the Software is furnished to do so, subject to 132 \ the following conditions: 133 \ 134 \ The above copyright notice and this permission notice shall be 135 \ included in all copies or substantial portions of the Software. 136 \ 137 \ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 138 \ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 139 \ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 140 \ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 141 \ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 142 \ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 143 \ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 144 \ 145 \ LICENSE_END -
dev/usb2/device/serial/uart.fth
r2208 r3471 11 11 12 12 variable refcount 0 refcount ! 13 14 : /string ( adr len cnt -- adr' len' ) tuck - -rot + swap ;15 13 16 14 \ Don't do this until someone calls read. That makes the device … … 33 31 : read ( adr len -- #read ) \ -2 for none available right now 34 32 ?start-reading 35 rpoll 36 dup 0= if nip exit then ( adr len ) 37 read-q deque? 0= if ( adr len ) 38 2drop ( ) 39 lost-carrier? if -1 false to lost-carrier? else -2 then 40 ( -2:none | -1:down ) 41 exit 42 then ( adr len char ) 43 over >r ( adr len char r: len ) 44 begin ( adr len char r: len ) 45 2 pick c! ( adr len r: len ) 46 1 /string ( adr' len' ) 47 dup 0= if 2drop r> exit then ( adr' len' ) 48 read-q deque? 0= until ( adr len r: len ) 49 nip r> swap - ( actual ) 33 read-bytes 50 34 ; 51 35 -
dev/usb2/device/serial/usbserial.bth
r1 r3471 17 17 fload ${BP}/dev/usb2/device/serial/mct_u232.fth \ MCT U232 device routines 18 18 fload ${BP}/dev/usb2/device/serial/pl2303.fth \ PL2303 device routines 19 fload ${BP}/dev/usb2/device/serial/ftdi.fth \ FTDI device routines 19 20 fload ${BP}/dev/usb2/device/serial/uart.fth \ USB uart driver 20 21 -
dev/usb2/device/serial/vendor.fth
r1134 r3471 7 7 525 w, 127a w, \ Ajays USB 2.0 Debug Cable 8 8 here swap - constant /uart-generic-list 9 10 create uart-ftdi-list here 11 403 w, 6001 w, \ FT232 12 here swap - constant /uart-ftdi-list 9 13 10 14 create uart-pl2303-list here … … 34 38 ; 35 39 40 : uart-ftdi? ( vid pid -- flag ) 41 uart-ftdi-list /uart-ftdi-list find-vendor-product? 42 ; 36 43 37 44 : uart-pl2303? ( vid pid -- flag ) … … 48 55 49 56 : usb-uart? ( vid pid -- flag ) 50 2dup uart-pl2303? if 2drop true exit then 57 2dup uart-ftdi? if 2drop true exit then 58 2dup uart-pl2303? if 2drop true exit then 51 59 \ Not debugged yet... 52 60 \ 2dup uart-mct? if 2drop true exit then
Note: See TracChangeset
for help on using the changeset viewer.
