--- serial.tcl.orig Wed May 7 18:26:24 2003 +++ serial.tcl Sat Aug 2 14:20:41 2003 @@ -52,25 +52,34 @@ # The protocol between eCos and this script. variable SYNTH_SERIAL_TX 0x01 variable SYNTH_SERIAL_RX 0x02 variable SYNTH_SERIAL_GETPARAMS 0x03 + # This array holds all the interesting data for all the # interfaces, indexed by the instance id. It is also useful # to keep track of the instance id's associated with serial # devices. array set data [list] set ids [list] - + set baudRate 115200 # ------------------------------------------------------------------------- proc instantiate { id name data } { # open pty and init input handler - # FIXME: hardcoded file name - set fid [open "loop1" "r+"] - fconfigure $fid -translation binary -encoding binary -buffering none + puts "serial name : $name" + if { [string equal -length -1 $name "/dev/ser0"] } { + set serial_dev "/dev/ttyS0" + set fid [open "/dev/ttyS0" "r+"] + } else { + return "" + } + fconfigure $fid -blocking 0 -translation binary -encoding binary -buffering none \ + -mode $serial::baudRate,n,8,1 + exec -- stty -F $serial_dev crtscts + fileevent $fid readable [list serial::handle_input $id] # allocate an interrupt vector set vector [synth::interrupt_allocate $name] if { -1 == $vector } { @@ -96,17 +105,28 @@ # puts "Put char '$reqdata'" puts -nonewline $serial::data($id,fid) $reqdata } elseif { $reqcode == $serial::SYNTH_SERIAL_RX } { set len [llength $serial::data($id,in_buff)] if { $len == 0 } { - synth::send_reply -1 1 0 + synth::send_reply -1 1 0 } else { - set replay [binary format "a" \ - [lindex $serial::data($id,in_buff) 0]] - set serial::data($id,in_buff) \ - [lrange $serial::data($id,in_buff) 1 $len] - synth::send_reply [expr $len - 1] 1 $replay + if { $len >= $reply_len } { + set slen $reply_len + } else { + set slen $len + } + #puts "len $slen" + + for { set i 0 } { $i < $slen } { incr i } { + append replay [lindex $serial::data($id,in_buff) $i] + } + + #set replay [lrange $serial::data($id,in_buff) 0 [expr $len - 1]] + set serial::data($id,in_buff) \ + [lrange $serial::data($id,in_buff) $slen [expr $len - 1]] + synth::send_reply [expr $len - $slen] $slen $replay + #puts "replay $slen $replay" } } elseif { $reqcode == $serial::SYNTH_SERIAL_GETPARAMS } { synth::send_reply $serial::data($id,int_vector) 0 "" } else { synth::report_error "Received unexpected request $reqcode for serial device" @@ -114,14 +134,25 @@ } # ------------------------------------------------------------------------- proc handle_input { id } { - set ch [read $serial::data($id,fid) 1] -# puts "Got char '$ch'" - lappend serial::data($id,in_buff) $ch - synth::interrupt_raise $serial::data($id,int_vector) + set len [llength $serial::data($id,in_buff)] + if { $len < 80 } { + set ch [read $serial::data($id,fid) 1] + # puts "Got char '$ch'" + set blocked [fblocked $serial::data($id,fid)] + if { $blocked == 0 } { + lappend serial::data($id,in_buff) $ch + + } + } +#elseif { $len == 80 } { + # puts "getting full !" + # flush stdout +# } + synth::interrupt_raise $serial::data($id,int_vector) } # ------------------------------------------------------------------------- proc ecos_exited { arg_list } {