Changeset 3471


Ignore:
Timestamp:
Dec 5, 2012, 9:02:09 AM (3 years ago)
Author:
quozl
Message:

usbserial - FTDI232 driver for OLPC serial adapters

Location:
dev/usb2/device/serial
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • dev/usb2/device/serial/common.fth

    r1 r3471  
    108108' generic-rpoll to rpoll
    109109
     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
    110133: generic-write-bytes  ( adr len -- actual )
    111134   swap >r                      ( len )  ( R: adr )
  • dev/usb2/device/serial/ftdi.fth

    r3470 r3471  
    2121: ftdi-flush-tx  ( -- )  0 2  ftdi-set  ;
    2222
     23[ifndef] rounded-/
     24: rounded-/  swap 2* swap / dup 1 and + 2/  ;
     25[then]
     26
    2327: ftdi-baud  ( baud -- )
    2428   \ There are some high bits for fractional divisors that we don't use
    2529   d# 48000000 swap rounded-/   ( divisor )
    26    0 swap  3 ftdi-set
     30   4 rshift  3 ftdi-set
    2731;
    2832
     
    7074\ If there is no data, 2-byte status messages are sent every 40 ms.
    7175
     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
    7286\ 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  
    1111
    1212variable refcount  0 refcount !
    13 
    14 : /string  ( adr len cnt -- adr' len' )  tuck - -rot + swap  ;
    1513
    1614\ Don't do this until someone calls read.  That makes the device
     
    3331: read  ( adr len -- #read )   \ -2 for none available right now
    3432   ?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
    5034;
    5135
  • dev/usb2/device/serial/usbserial.bth

    r1 r3471  
    1717fload ${BP}/dev/usb2/device/serial/mct_u232.fth \ MCT U232 device routines
    1818fload ${BP}/dev/usb2/device/serial/pl2303.fth   \ PL2303 device routines
     19fload ${BP}/dev/usb2/device/serial/ftdi.fth     \ FTDI device routines
    1920fload ${BP}/dev/usb2/device/serial/uart.fth     \ USB uart driver
    2021
  • dev/usb2/device/serial/vendor.fth

    r1134 r3471  
    77        525 w, 127a w,          \ Ajays USB 2.0 Debug Cable
    88here swap - constant /uart-generic-list
     9
     10create uart-ftdi-list  here
     11        403 w, 6001 w,          \ FT232
     12here swap - constant /uart-ftdi-list
    913
    1014create uart-pl2303-list  here
     
    3438;
    3539
     40: uart-ftdi?  ( vid pid -- flag )
     41   uart-ftdi-list /uart-ftdi-list  find-vendor-product?
     42;
    3643
    3744: uart-pl2303?  ( vid pid -- flag )
     
    4855
    4956: 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
    5159\ Not debugged yet...
    5260\   2dup uart-mct?     if  2drop true exit  then
Note: See TracChangeset for help on using the changeset viewer.