Xilinx Spartan 3 Demo rs232 clock set

TV

http://82.170.247.158/Wiki/xilledson.jpg

I've been working with a Xilinx Spartan-3 demo board[L1 ], for which there is a clock example that can be burned in the config FLASH with little effort, and that clock can be set (and some other things) over an RS-232 link.

This tcl script programs the computer clock automatically into the board with a readable command:

 #open serial port
 set fh [open COM1: RDWR]
 fconfigure $fh -blocking 0 -mode 9600,n,8,1 -translation binary -translation cr -buffering none

 # make a text window for incoming communication
 text .t -width 40 -height 10
 pack .t -expand y -fill both
 fileevent $fh readable {.t insert end [read $fh] ;.t see end}

 # print time, and set the xilinx time
 puts [clock format [clock seconds] -format "%H:%M:%S"]
 puts $fh "time" ; flush $fh
 puts $fh "time [clock format [clock seconds] -format \"%H:%M:%S\"]" ; flush $fh

To put all the leds on or off from tcl connected over the serial port:

 proc s a {global fh; puts $fh $a ; flush $fh}
 for {set i 0} {$i <=7} {incr i} {s "led$i on" ; after 1; update}
 for {set i 0} {$i <=7} {incr i} {s "led$i off"; after 1; update}

http://82.170.247.158/Wiki/xilledsoff.jpg


I've made a script which runs in a tclsh to communicate with theboard over the serial link, this runs also in a remote x window, the above troubles I didn't check out (timing, flow control), but it runs ok.

 set fh [open COM1: RDWR]
 fconfigure $fh -blocking 0 -mode 9600,n,8,1 -translation binary -translation cr -buffering full
 fileevent $fh readable {set v [read $fh] ;}
 clock format [clock seconds] -format "%H:%M:%S"
 puts $fh "time" ; flush $fh
 after 1000 {puts $fh "time" ; flush $fh}
 fileevent stdin readable { puts  $fh [gets  stdin]; flush $fh; }
 while {1} {
    vwait v
    flush $fh
    after 100
    puts -nonewline $v
    flush stdout
 }

Example:

 tclsh setclock.tcl
  KCPSM3>time
  13:17:20

  KCPSM3>led
  led
  LED0 OFF
  LED1 OFF
  LED2 OFF
  LED3 OFF
  LED4 OFF
  LED5 OFF
  LED6 OFF
  LED7 OFF

  KCPSM3>led0 on
  led0 on

  KCPSM3>