Commit e49b36ce5244bfa335d2c0770dd776ff6ad50efb

Authored by Brice Colombier
1 parent 3fdd375281
Exists in master

3 first tabs working, test with the HECTOR board

Showing 9 changed files with 823 additions and 121 deletions

Boards_management/board_commands.py View file @ e49b36c
... ... @@ -73,9 +73,9 @@
73 73 Boardm = Board_manager()
74 74 r.eval(Boardm.source_tcl_package())
75 75 r.eval(Boardm.connect("COM3"))
76   - r.eval(Boardm.select_DB_connection(2))
77   - r.eval(Boardm.reset_boards())
78   - print(r.eval(Boardm.generate_and_offload_response()))
79   - r.eval(Boardm.get_parity_from_indices([0, 1, 2, 3]))
80   - r.eval(Boardm.disconnect())
  76 + # r.eval(Boardm.select_DB_connection(2))
  77 + # r.eval(Boardm.reset_boards())
  78 + # print(r.eval(Boardm.generate_and_offload_response()))
  79 + # r.eval(Boardm.get_parity_from_indices([0, 1, 2, 3]))
  80 + # r.eval(Boardm.disconnect())
GUI/HECTOR_data_acq.tcl View file @ e49b36c
  1 +##############################################################################
  2 +#
  3 +# Design unit: HECTOR TCL language extension
  4 +#
  5 +# File name: HECTOR_data_acq.tcl
  6 +#
  7 +# Description: TCL language extension providing high-level access to
  8 +# communication interface with HECTOR evaluation boards.
  9 +#
  10 +# System: TCL v. 8.5 and higher
  11 +#
  12 +# Author: O. Petura - Hubert Curien Laboratory
  13 +#
  14 +# Copyright: Hubert Curien Laboratory, 2016
  15 +#
  16 +# Revision: Version 1.00, April 2016
  17 +#
  18 +##############################################################################
  19 +
  20 +
  21 +# Timeout for the UART response in seconds
  22 +set UART_timeout 5
  23 +
  24 +# Timeout between two consequent checks of UART input buffer
  25 +set uart_check_timeout 100
  26 +
  27 +# Opens a connection to HECTOR evaluation board
  28 +proc openDevice {dev {verbose 0}} {
  29 +
  30 + global tcl_platform
  31 +
  32 +# Append \\.\ to serial port number when we are running on Windows
  33 + if {[string first "Win" $tcl_platform(os)] != -1} {
  34 + set dev "\\\\.\\$dev"
  35 + }
  36 +
  37 +# Open the serial device
  38 + if { [catch { open $dev "r+" } fd ] } {
  39 + if {$verbose != 0} {
  40 + puts "Error opening device '$dev'\n Error description: $::errorInfo"
  41 + }
  42 + puts "Error opening device '$dev'"
  43 + set ret -1
  44 + } else {
  45 +# Configure communication parameters
  46 + fconfigure $fd -blocking 0 -buffering none -mode "115200,n,8,1" -translation binary -eofchar {}
  47 +
  48 +# Update the application status
  49 + puts "Connection to '$dev' opened"
  50 +
  51 +# Create device handle
  52 + set ret [list $dev $fd]
  53 +
  54 + }
  55 +
  56 + return $ret
  57 +
  58 +}
  59 +
  60 +# Disconnect from the HECTOR evaluation board
  61 +proc disconnect {device} {
  62 +
  63 +# Close the connection to the serial device
  64 + close [lindex $device 1]
  65 +
  66 +# Update the application status
  67 + puts "Connection to '[lindex $device 0]' closed"
  68 +}
  69 +
  70 +# Poll the serial device for input data
  71 +proc pollDevice {device {verbose 0}} {
  72 +
  73 +# Read the input serial buffer
  74 + set data [read [lindex $device 1]]
  75 +
  76 +# If there is something, process it
  77 + if {[string length $data] != 0} {
  78 + if {$verbose != 0} {
  79 + puts "Received data: [toHEX $data]"
  80 + }
  81 +
  82 +# Get the MSS status packet header offset
  83 + set offset [string first "\x13\x57\x00\x00" $data]
  84 + if {$offset != -1} {
  85 +# Get the status fields
  86 + set response [string range $data [expr $offset + 11] [expr $offset + 11]]
  87 + set progress [string range $data [expr $offset + 8] [expr $offset + 8]]
  88 + set aq_state [string range $data [expr $offset + 9] [expr $offset + 9]]
  89 + set gpio [string range $data [expr $offset + 10] [expr $offset + 10]]
  90 +
  91 + binary scan $response c1 ret(response)
  92 + binary scan $progress c1 ret(progress)
  93 + binary scan $aq_state c1 ret(aq_state)
  94 + set ret(gpio) [toHEX $gpio]
  95 + return [list $ret(response) $ret(progress) $ret(aq_state) $ret(gpio)]
  96 + } else {
  97 +
  98 +# Get the FPGA status packet header offset
  99 + set offset [string first "\x13\xF5\x00\x00" $data]
  100 + if {$offset != -1} {
  101 +# Get the status fields
  102 + set fpga_data [string range $data [expr $offset + 4] [expr $offset + 7]]
  103 + set fpga_status [string range $data [expr $offset + 8] [expr $offset + 11]]
  104 +
  105 + set ret(fpga_data) [toHEX $fpga_data]
  106 + set ret(fpga_status) [toHEX $fpga_status]
  107 + return [list $ret(fpga_status) $ret(fpga_data)]
  108 + }
  109 + }
  110 + } else {
  111 + set ret(response) -1
  112 + set ret(appError) 1
  113 + return [list $ret(response) $ret(appError)]
  114 + }
  115 +
  116 +}
  117 +
  118 +# Wait for a specified time
  119 +proc wait_ms {ms} {
  120 +
  121 +# Create a variable name
  122 + set varName finished_[clock clicks]
  123 + global $varName
  124 +
  125 +# Set the variable after a specified timeout
  126 + after $ms set $varName 1
  127 +
  128 +# Wait for the variable to be set
  129 + vwait $varName
  130 +
  131 +# Clear the variable from memory
  132 + unset $varName
  133 +}
  134 +
  135 +# Convert a binary string to HEX
  136 +proc toHEX {in} {
  137 + set ret ""
  138 + for {set i 0} {$i < [string length $in]} {incr i} {
  139 + binary scan [string index $in $i] c1 byte
  140 + if {$byte < 0} {set byte [expr 256 + $byte]}
  141 + set HI [expr $byte >> 4]
  142 + set LO [expr $byte & 15]
  143 + switch $HI {
  144 + 0 {append ret "0"}
  145 + 1 {append ret "1"}
  146 + 2 {append ret "2"}
  147 + 3 {append ret "3"}
  148 + 4 {append ret "4"}
  149 + 5 {append ret "5"}
  150 + 6 {append ret "6"}
  151 + 7 {append ret "7"}
  152 + 8 {append ret "8"}
  153 + 9 {append ret "9"}
  154 + 10 {append ret "A"}
  155 + 11 {append ret "B"}
  156 + 12 {append ret "C"}
  157 + 13 {append ret "D"}
  158 + 14 {append ret "E"}
  159 + 15 {append ret "F"}
  160 + }
  161 + switch $LO {
  162 + 0 {append ret "0"}
  163 + 1 {append ret "1"}
  164 + 2 {append ret "2"}
  165 + 3 {append ret "3"}
  166 + 4 {append ret "4"}
  167 + 5 {append ret "5"}
  168 + 6 {append ret "6"}
  169 + 7 {append ret "7"}
  170 + 8 {append ret "8"}
  171 + 9 {append ret "9"}
  172 + 10 {append ret "A"}
  173 + 11 {append ret "B"}
  174 + 12 {append ret "C"}
  175 + 13 {append ret "D"}
  176 + 14 {append ret "E"}
  177 + 15 {append ret "F"}
  178 + }
  179 + }
  180 + return $ret
  181 +}
  182 +
  183 +# Function to convert HEX to DEC
  184 +proc fromHEX {in} {
  185 + set in_end [expr [string length $in] - 1]
  186 + set ret 0
  187 + for {set i $in_end} {$i >= 0} {incr i -1} {
  188 + switch [string index $in $i] {
  189 + "0" {set val 0}
  190 + "1" {set val 1}
  191 + "2" {set val 2}
  192 + "3" {set val 3}
  193 + "4" {set val 4}
  194 + "5" {set val 5}
  195 + "6" {set val 6}
  196 + "7" {set val 7}
  197 + "8" {set val 8}
  198 + "9" {set val 9}
  199 + "A" {set val 10}
  200 + "B" {set val 11}
  201 + "C" {set val 12}
  202 + "D" {set val 13}
  203 + "E" {set val 14}
  204 + "F" {set val 15}
  205 + }
  206 + set ret [expr $ret + ($val * (16**($in_end - $i)))]
  207 + }
  208 + return $ret
  209 +}
  210 +
  211 +# Function to read bit value from a specific bit field in decimal value
  212 +proc getBitValue {decNumber bitFieldIndex} {
  213 + return [expr ( $decNumber & (2**$bitFieldIndex) ) >> $bitFieldIndex]
  214 +}
  215 +
  216 +# Bitwise XOR of two HEX values
  217 +proc xorHEX { in1 in2 } {
  218 + if { [string length $in1] != [string length $in2] } {
  219 + return -1
  220 + } else {
  221 + set ret ""
  222 + for {set i 0} {$i < [string length $in1]} {incr i} {
  223 + set num1 [fromHEX [string index $in1 $i]]
  224 + set num2 [fromHEX [string index $in2 $i]]
  225 + set xor_val [expr $num1^$num2]
  226 + if {$xor_val < 10} {
  227 + set hex_val $xor_val
  228 + } else {
  229 + switch $xor_val {
  230 + "10" {set hex_val "A"}
  231 + "11" {set hex_val "B"}
  232 + "12" {set hex_val "C"}
  233 + "13" {set hex_val "D"}
  234 + "14" {set hex_val "E"}
  235 + "15" {set hex_val "F"}
  236 + }
  237 + }
  238 + set ret "$ret$hex_val"
  239 + }
  240 + return $ret
  241 + }
  242 +}
  243 +
  244 +##############
  245 +## COMMANDS ##
  246 +##############
  247 +
  248 +proc getStatus {device {verbose 0}} {
  249 + global UART_timeout
  250 + global uart_check_timeout
  251 +
  252 + set data "\x13\xC0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x07"
  253 + puts -nonewline [lindex $device 1] $data
  254 + if {$verbose != 0} {
  255 + puts "Sending: [toHEX $data]"
  256 + }
  257 +
  258 + set resp "-1 1"
  259 + set start [clock seconds]
  260 + while { [string match $resp "-1 1"] } {
  261 + set resp [pollDevice $device $verbose]
  262 + if { [clock seconds] > [expr $start + $UART_timeout] } {
  263 + break
  264 + }
  265 + wait_ms $uart_check_timeout
  266 + }
  267 + set st1 $resp
  268 +
  269 + set data "\x13\xFB\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  270 + puts -nonewline [lindex $device 1] $data
  271 + if {$verbose != 0} {
  272 + puts "Sending: [toHEX $data]"
  273 + }
  274 +# Return the response of the command
  275 + set resp "-1 1"
  276 + set start [clock seconds]
  277 + while { [string match $resp "-1 1"] } {
  278 + set resp [pollDevice $device $verbose]
  279 + if { [clock seconds] > [expr $start + $UART_timeout] } {
  280 + break
  281 + }
  282 + wait_ms $uart_check_timeout
  283 + }
  284 + set st2 $resp
  285 +
  286 + set status [list [lindex $st1 0] [lindex $st1 1] [lindex $st1 2] [lindex $st1 3] [lindex $st2 0] [lindex $st2 1]]
  287 +
  288 + return $status
  289 +}
  290 +
  291 +proc sendFabricCommand {device command data {verbose 0}} {
  292 + global UART_timeout
  293 + global uart_check_timeout
  294 +
  295 + set data "\x13\xFB\x00\x00[binary format I1 $data][binary format I1 $command]"
  296 + puts -nonewline [lindex $device 1] $data
  297 + if {$verbose != 0} {
  298 + puts "Sending: [toHEX $data]"
  299 + }
  300 +# Return the response of the command
  301 + set resp "-1 1"
  302 + set start [clock seconds]
  303 + while { [string match $resp "-1 1"] } {
  304 + set resp [pollDevice $device $verbose]
  305 + if { [clock seconds] > [expr $start + $UART_timeout] } {
  306 + break
  307 + }
  308 + wait_ms $uart_check_timeout
  309 + }
  310 + return $resp
  311 +}
  312 +
  313 +proc sendFabricReset {device {verbose 0}} {
  314 + global UART_timeout
  315 + global uart_check_timeout
  316 +
  317 + set data "\x13\xC0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04"
  318 + puts -nonewline [lindex $device 1] $data
  319 + if {$verbose != 0} {
  320 + puts "Sending: [toHEX $data]"
  321 + }
  322 +# Return the response of the command
  323 + set resp "-1 1"
  324 + set start [clock seconds]
  325 + while { [string match $resp "-1 1"] } {
  326 + set resp [pollDevice $device $verbose]
  327 + if { [clock seconds] > [expr $start + $UART_timeout] } {
  328 + break
  329 + }
  330 + wait_ms $uart_check_timeout
  331 + }
  332 + return $resp
  333 +}
  334 +
  335 +proc sendDaughterReset {device {verbose 0}} {
  336 + global UART_timeout
  337 + global uart_check_timeout
  338 +
  339 + set data "\x13\xC0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05"
  340 + puts -nonewline [lindex $device 1] $data
  341 + if {$verbose != 0} {
  342 + puts "Sending: [toHEX $data]"
  343 + }
  344 +# Return the response of the command
  345 + set resp "-1 1"
  346 + set start [clock seconds]
  347 + while { [string match $resp "-1 1"] } {
  348 + set resp [pollDevice $device $verbose]
  349 + if { [clock seconds] > [expr $start + $UART_timeout] } {
  350 + break
  351 + }
  352 + wait_ms $uart_check_timeout
  353 + }
  354 + return $resp
  355 +}
  356 +
  357 +proc mountDisk {device {verbose 0}} {
  358 + global UART_timeout
  359 + global uart_check_timeout
  360 +
  361 + set data "\x13\xC0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x06"
  362 + puts -nonewline [lindex $device 1] $data
  363 + if {$verbose != 0} {
  364 + puts "Sending: [toHEX $data]"
  365 + }
  366 +# Return the response of the command
  367 + set resp "-1 1"
  368 + set start [clock seconds]
  369 + while { [string match $resp "-1 1"] } {
  370 + set resp [pollDevice $device $verbose]
  371 + if { [clock seconds] > [expr $start + $UART_timeout] } {
  372 + break
  373 + }
  374 + wait_ms $uart_check_timeout
  375 + }
  376 + return $resp
  377 +}
  378 +
  379 +proc createFileSystem {device {verbose 0}} {
  380 + global UART_timeout
  381 + global uart_check_timeout
  382 +
  383 + set data "\x13\xC0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08"
  384 + puts -nonewline [lindex $device 1] $data
  385 + if {$verbose != 0} {
  386 + puts "Sending: [toHEX $data]"
  387 + }
  388 +# Return the response of the command
  389 + set resp "-1 1"
  390 + set start [clock seconds]
  391 + while { [string match $resp "-1 1"] } {
  392 + set resp [pollDevice $device $verbose]
  393 + if { [clock seconds] > [expr $start + $UART_timeout] } {
  394 + break
  395 + }
  396 + wait_ms $uart_check_timeout
  397 + }
  398 + return $resp
  399 +}
  400 +
  401 +proc beginAcquisition {device filename size {verbose 0}} {
  402 + global UART_timeout
  403 + global uart_check_timeout
  404 +
  405 + set data "\x13\xFD\x00\x00$filename [binary format I1 $size]"
  406 + puts -nonewline [lindex $device 1] $data
  407 + if {$verbose != 0} {
  408 + puts "Sending command: [toHEX $data]"
  409 + }
  410 +# Return the response of the command
  411 + set resp "-1 1"
  412 + set start [clock seconds]
  413 + while { [string match $resp "-1 1"] } {
  414 + set resp [pollDevice $device $verbose]
  415 + if { [clock seconds] > [expr $start + $UART_timeout] } {
  416 + break
  417 + }
  418 + wait_ms $uart_check_timeout
  419 + }
  420 + return $resp
  421 +}
  422 +
  423 +proc loadInputFile {device filename size {verbose 0}} {
  424 + global UART_timeout
  425 + global uart_check_timeout
  426 +
  427 + set data "\x13\x3D\x00\x00$filename [binary format I1 $size]"
  428 + puts -nonewline [lindex $device 1] $data
  429 + if {$verbose != 0} {
  430 + puts "Sending command: [toHEX $data]"
  431 + }
  432 +# Return the response of the command
  433 + set resp "-1 1"
  434 + set start [clock seconds]
  435 + while { [string match $resp "-1 1"] } {
  436 + set resp [pollDevice $device $verbose]
  437 + if { [clock seconds] > [expr $start + $UART_timeout] } {
  438 + break
  439 + }
  440 + wait_ms $uart_check_timeout
  441 + }
  442 + return $resp
  443 +}
  444 +
  445 +proc configureGPIO {device GPIO {verbose 0}} {
  446 + global UART_timeout
  447 + global uart_check_timeout
  448 +
  449 + set data "\x13\xC0\x00\x00\x00\x00\x00\x00\x00\x00[binary format c1 $GPIO]\x09"
  450 + puts -nonewline [lindex $device 1] $data
  451 + if {$verbose != 0} {
  452 + puts "Sending command: [toHEX $data]"
  453 + }
  454 +# Return the response of the command
  455 + set resp "-1 1"
  456 + set start [clock seconds]
  457 + while { [string match $resp "-1 1"] } {
  458 + set resp [pollDevice $device $verbose]
  459 + if { [clock seconds] > [expr $start + $UART_timeout] } {
  460 + break
  461 + }
  462 + wait_ms $uart_check_timeout
  463 + }
  464 + return $resp
  465 +}
  466 +
  467 +proc setGPIO {device GPIO {verbose 0}} {
  468 + global UART_timeout
  469 + global uart_check_timeout
  470 +
  471 + set data "\x13\xC0\x00\x00\x00\x00\x00\x00\x00\x00[binary format c1 $GPIO]\x0A"
  472 + puts -nonewline [lindex $device 1] $data
  473 + if {$verbose != 0} {
  474 + puts "Sending command: [toHEX $data]"
  475 + }
  476 +# Return the response of the command
  477 + set resp "-1 1"
  478 + set start [clock seconds]
  479 + while { [string match $resp "-1 1"] } {
  480 + set resp [pollDevice $device $verbose]
  481 + if { [clock seconds] > [expr $start + $UART_timeout] } {
  482 + break
  483 + }
  484 + wait_ms $uart_check_timeout
  485 + }
  486 + return $resp
  487 +}
  488 +
  489 +proc softReset {device {verbose 0}} {
  490 + global UART_timeout
  491 + global uart_check_timeout
  492 +
  493 + set data "\x13\xC0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0B"
  494 + puts -nonewline [lindex $device 1] $data
  495 + if {$verbose != 0} {
  496 + puts "Sending command: [toHEX $data]"
  497 + }
  498 +# Return the response of the command
  499 + set resp "-1 1"
  500 + set start [clock seconds]
  501 + while { [string match $resp "-1 1"] } {
  502 + set resp [pollDevice $device $verbose]
  503 + if { [clock seconds] > [expr $start + $UART_timeout] } {
  504 + break
  505 + }
  506 + wait_ms $uart_check_timeout
  507 + }
  508 + return $resp
  509 +}
  510 +
  511 +# board =
  512 +# 1 - HDMI
  513 +# 2 - SATA
  514 +proc selectDaughterBoard {device board {verbose 0}} {
  515 + global UART_timeout
  516 + global uart_check_timeout
  517 +
  518 + if { $board == 1 } {
  519 + set command 2
  520 + } elseif { $board == 2 } {
  521 + set command 3
  522 + } else {
  523 + set command 0
  524 + }
  525 + set data "\x13\xFB\x00\x00\x00\x00\x00\x00[binary format I1 $command]"
  526 + puts -nonewline [lindex $device 1] $data
  527 + if {$verbose != 0} {
  528 + puts "Sending command: [toHEX $data]"
  529 + }
  530 +# Return the response of the command
  531 + set resp "-1 1"
  532 + set start [clock seconds]
  533 + while { [string match $resp "-1 1"] } {
  534 + set resp [pollDevice $device $verbose]
  535 + if { [clock seconds] > [expr $start + $UART_timeout] } {
  536 + break
  537 + }
  538 + wait_ms $uart_check_timeout
  539 + }
  540 + return $resp
  541 +}
  542 +
  543 +###########################
  544 +## Application functions ##
  545 +###########################
  546 +
  547 +# Find the connected disk drives
  548 +proc findDiskDrives {} {
  549 + global tcl_platform
  550 +
  551 + set drives ""
  552 +
  553 + if {[string match $tcl_platform(os) "Linux"]} {
  554 + if { [catch {exec blkid} disks] } {
  555 + puts "blkid is not available. Automatic disk recognition is impossible."
  556 + return -1
  557 + } else {
  558 + set disks [split $disks "\n"]
  559 + foreach disk $disks {
  560 + set uuid_offset [string first "UUID=" $disk]
  561 + set device [string range $disk 0 [expr [string first ":" $disk] - 1]]
  562 +# Get the mountpoint
  563 + set mountpoint ""
  564 + set f [open "/proc/mounts" "r"]
  565 + while { [gets $f line] >= 0} {
  566 + if {[string first $device $line] != -1} {
  567 + set mountpoint [lindex $line 1]
  568 + break
  569 + }
  570 + }
  571 + close $f
  572 +
  573 + if { $uuid_offset != -1 } {
  574 + set uuidStart [expr $uuid_offset + 5]
  575 + set uuidEnd [string first "\"" $disk [expr $uuidStart + 1]]
  576 + set uuidString [string range $disk [expr $uuidStart + 1] [expr $uuidEnd - 1]]
  577 + lappend drives [list $device $uuidString $mountpoint]
  578 + }
  579 + }
  580 + }
  581 + } elseif {[string first "Win" $tcl_platform(os)] != -1} {
  582 + set disks [file volumes]
  583 + foreach disk $disks {
  584 + set disk [string range $disk 0 end-1]
  585 + if {[catch {exec cmd /c vol $disk} resp]} {
  586 + continue
  587 + } else {
  588 + set disk [string range $disk 0 end-1]
  589 + set uuidString [string range $resp end-8 end]
  590 + lappend drives [list $disk $uuidString "$disk:/"]
  591 + }
  592 + }
  593 + } else {
  594 + puts "Only linux and windows platforms are supported for the moment"
  595 + return -1
  596 + }
  597 +
  598 + return $drives
  599 +}
  600 +
  601 +# Find HECTOR disk
  602 +proc findHECTOR {{timeout 5}} {
  603 + set start [clock seconds]
  604 + set hectorDrive 0
  605 +
  606 + while { $hectorDrive == 0 && [expr [clock seconds] - $start] < $timeout} {
  607 + set disks [findDiskDrives]
  608 + foreach disk $disks {
  609 + if { [string match "48A1-0000" [lindex $disk 1]] } {
  610 + set hectorDrive $disk
  611 + break
  612 + }
  613 + }
  614 + wait_ms 100
  615 + }
  616 + return $hectorDrive
  617 +}
  618 +
  619 +# Sync filesystem
  620 +proc syncDrives {} {
  621 + global tcl_platform
  622 +
  623 + if {[string match $tcl_platform(os) "Linux"]} {
  624 + if { [catch {exec sync} ret] } {
  625 + puts "Disk sync failed."
  626 + return -1
  627 + } else {
  628 + return 0
  629 + }
  630 + } elseif {[string first "Win" $tcl_platform(os)] != -1} {
  631 + if { [catch {exec "sync.exe"} ret] } {
  632 + puts "Disk sync failed."
  633 + return -1
  634 + } else {
  635 + return 0
  636 + }
  637 + } else {
  638 + puts "Only linux and windows platforms are supported for the moment"
  639 + return -1
  640 + }
  641 +}
  642 +
  643 +proc acquireData {device filename filesize {interface 0} {debug 0}} {
  644 + global tcl_platform
  645 +
  646 +
  647 +# Reset the FPGA controller
  648 + set err [softReset $device $debug]
  649 + if {[lindex $err 0] != 0} {
  650 + puts "Soft reset failed with code $err"
  651 + return $err
  652 + }
  653 +
  654 +# Set the right interface
  655 +# 0 = SATA
  656 +# 1 = HDMI
  657 + if { $interface == 0 } {
  658 + set err [sendFabricCommand $device 3]
  659 + if { [lindex $err 0] != 0 } {
  660 + puts "Interface set error. Code: $err"
  661 + }
  662 + } elseif { $interface == 1 } {
  663 + set err [sendFabricCommand $device 4]
  664 + if { [lindex $err 0] != 0 } {
  665 + puts "Interface set error. Code: $err"
  666 + }
  667 + }
  668 +
  669 +# Reset the daugther module
  670 + set err [sendDaughterReset $device $debug]
  671 + if {[lindex $err 0] != 0} {
  672 + puts "Daughter reset failed with code $err"
  673 + return $err
  674 + }
  675 +
  676 +# Create filesystem
  677 + set err [createFileSystem $device $debug]
  678 + if {[lindex $err 0] != 0 } {
  679 + puts "Filesystem creation failed with code $err"
  680 + return $err
  681 + }
  682 +
  683 +## Create a progressbar
  684 +# set progressbar {[=====|=====|=====|=====]}
  685 +# puts $progressbar
  686 +# set progressStep [expr 100.0 / ([string length $progressbar] - 2)]
  687 +
  688 +# Start the measurement
  689 + set err [beginAcquisition $device ACQ $filesize]
  690 + if {[lindex $err 0] != 0 } {
  691 + puts "Acquisition failed to start. Error code: $err"
  692 + return $err
  693 + }
  694 +
  695 +# set progress 0
  696 +# puts -nonewline {[}
  697 +# flush stdout
  698 + while {[lindex $err 2] != 0} {
  699 + set err [getStatus $device $debug]
  700 + if {[lindex $err 0] != 0 } {
  701 + puts "An error occured during data acquisition. Error code: $err"
  702 + return $err
  703 + } else {
  704 + puts -nonewline "[lindex $err 1] %\r"
  705 + flush stdout
  706 + #if { [lindex $err 1] > $progress } {
  707 + # set steps [expr ([lindex $err 1] - $progress) / $progressStep]
  708 + # if { $steps >= 1 } {
  709 + # set progress [expr $progress + ( floor($steps) * $progressStep)]
  710 + # #puts "$progress - $steps"
  711 + # for {set i 0} {$i < [expr floor($steps)]} {incr i} {
  712 + # puts -nonewline "#"
  713 + # flush stdout
  714 + # }
  715 + # }
  716 + #}
  717 + }
  718 + }
  719 + puts {}
  720 + flush stdout
  721 +
  722 +# Mount the disk
  723 + set err [mountDisk $device $debug]
  724 + if {[lindex $err 0] != 0} {
  725 + puts "Mounting disk failed with error code $err"
  726 + return $err
  727 + }
  728 +
  729 +# Search for the hector disk
  730 + set hectorDrive [findHECTOR 5]
  731 +
  732 + if { $hectorDrive == 0 } {
  733 + puts "Hector disk drive not found. You will have to search for it manually."
  734 + return 1
  735 + }
  736 +
  737 +# Check for the mountpoint
  738 + if { [string length [lindex $hectorDrive 2]] == 0 } {
  739 + puts "Hector disk drive is not mounted. Please mount the device [lindex $hectorDrive 0]."
  740 + return 1
  741 + }
  742 +
  743 +# Copy the file from hector disk to the PC
  744 + if { [string match $tcl_platform(os) "Linux"] } {
  745 + puts [lindex $hectorDrive 2]/ACQ
  746 + file copy -force [lindex $hectorDrive 2]/ACQ $filename
  747 + } elseif { [string first $tcl_platform(os) "Win"] != -1 } {
  748 + file copy -force {"[lindex $hectorDrive 2]/ACQ"} $filename
  749 + }
  750 +
  751 + puts "Acquired data are available in the file $filename"
  752 +
  753 + return 0
  754 +}
GUI/add_frame_elements.py View file @ e49b36c
... ... @@ -31,26 +31,6 @@
31 31 command=self.disconnect)
32 32 self.com_port_button_disconnect.pack(side=LEFT)
33 33 # ------------------------------------------------------
34   - self.Spartan_6_pick = Radiobutton(self.daughterboard_frame,
35   - text="Xilinx Spartan 6",
36   - variable=self.daughter_board,
37   - value="S6")
38   - self.Spartan_6_pick.grid(row=0,
39   - column=0)
40   - self.Cyclone_5_pick = Radiobutton(self.daughterboard_frame,
41   - text="Altera Cyclone V",
42   - variable=self.daughter_board,
43   - value="C5")
44   - self.Cyclone_5_pick.grid(row=0,
45   - column=1,
46   - padx=20)
47   - self.SmartFusion_2_pick = Radiobutton(self.daughterboard_frame,
48   - text="MicroSemi SmartFusion 2",
49   - variable=self.daughter_board,
50   - value="SF2")
51   - self.SmartFusion_2_pick.grid(row=0,
52   - column=2)
53   - # ------------------------------------------------------
54 34 self.reconciliation_parameters_label = Label(self.CASCADE_frame,
55 35 text="Parameters:")
56 36 self.reconciliation_parameters_label.grid(row=0, column=0)
... ... @@ -78,7 +58,6 @@
78 58 column=2)
79 59 self.perform_reconciliation_button=Button(self.CASCADE_frame,
80 60 text="Perform reconciliation",
81   - command=self.perform_reconciliation,
82 61 state="normal")
83 62 self.perform_reconciliation_button.grid(row=0,
84 63 column=3,
85 64  
86 65  
... ... @@ -229,20 +208,20 @@
229 208 text=".vhd",
230 209 variable=self.generated_design_format,
231 210 value="vhd")
232   - self.generated_design_format_vhd.grid(row=0,
233   - column=2,
  211 + self.generated_design_format_vhd.grid(row=1,
  212 + column=1,
234 213 sticky=W)
235 214 self.generate_modified_design_button=Button(self.generate_modified_design_frame,
236 215 text="Generate and save modified design",
237 216 state="normal",
238 217 command= self.generate_save_modified_design,
239 218 width=32)
240   - self.generate_modified_design_button.grid(row=1,
  219 + self.generate_modified_design_button.grid(row=2,
241 220 column=0,
242 221 sticky=W)
243 222 self.modified_design_saved_label = Label(self.generate_modified_design_frame,
244 223 textvariable=self.message_modified_design_saved)
245   - self.modified_design_saved_label.grid(row=1,
  224 + self.modified_design_saved_label.grid(row=2,
246 225 column=1,
247 226 sticky=W)
248 227 self.save_associated_activation_word_button=Button(self.generate_modified_design_frame,
249 228  
250 229  
... ... @@ -250,29 +229,14 @@
250 229 state="normal",
251 230 command=self.save_AW,
252 231 width=32)
253   - self.save_associated_activation_word_button.grid(row=2,
  232 + self.save_associated_activation_word_button.grid(row=3,
254 233 column=0,
255 234 sticky=W)
256 235 self.activation_word_saved_label = Label(self.generate_modified_design_frame,
257 236 textvariable=self.message_AW_saved)
258   - self.activation_word_saved_label.grid(row=2,
259   - column=2,
  237 + self.activation_word_saved_label.grid(row=3,
  238 + column=1,
260 239 sticky=W)
261   - # -------------------------------------------------------
262   - self.label_program=Label(self.program_daughterboard_frame,
263   - text="Bitstream:")
264   - self.label_program.grid(row=0,column=0,sticky=E)
265   - self.bitstream_entry = Entry(self.program_daughterboard_frame,
266   - textvariable=self.bitstream,
267   - width=81)
268   - self.bitstream_entry.grid(row=0,column=1, sticky="EW")
269   - self.search_bitstream_button=Button(self.program_daughterboard_frame,
270   - text="Search...",
271   - command=self.open_bitstream_file)
272   - self.search_bitstream_button.grid(row=0,column=2)
273   - self.program_daughterboard_button=Button(self.program_daughterboard_frame,
274   - text="Program HECTOR daughterboard")
275   - self.program_daughterboard_button.grid(row=1, column=0)
276 240 # -------------------------------------------------------
277 241 self.activation_word_label = Label(self.activation_word_encryption_frame,
278 242 text="Activation word:")
... ... @@ -7,6 +7,7 @@
7 7 # Project: Demonstrator
8 8 # File: app.py
9 9 # Date: 2016-10-13
  10 +from subprocess import call
10 11 import random
11 12 import sys
12 13 import time
... ... @@ -27,7 +28,8 @@
27 28 "../Locking/",
28 29 "../Key_derivation",
29 30 "../Generate_modified_netlist",
30   - "../Parsers"])
  31 + "../Parsers",
  32 + "../Boards_management"])
31 33 import blake2
32 34  
33 35 import locking
34 36  
... ... @@ -47,7 +49,9 @@
47 49 import convert_back_bench
48 50 import convert_back_vhd
49 51  
  52 +import board_commands
50 53  
  54 +
51 55 class App:
52 56  
53 57 """Main class for the demonstrator GUI app"""
54 58  
... ... @@ -56,12 +60,15 @@
56 60  
57 61 self.master = master
58 62  
59   - self.master.maxsize(width=1000, height=350)
60   - self.master.minsize(width=1000, height=350)
  63 + self.master.maxsize(width=1000, height=370)
  64 + self.master.minsize(width=1000, height=370)
61 65 self.master.resizable(width=False, height=False)
62 66 self.master.title("SALWARE IP protection tool")
63 67 self.master.iconbitmap(default='./contents/icon.ico')
64 68  
  69 + self.tcl_obj = Tcl()
  70 + self.board_manager = board_commands.Board_manager()
  71 +
65 72 # Tabs
66 73 build_tabs.build_tabs(self)
67 74  
... ... @@ -131,9 +138,8 @@
131 138  
132 139  
133 140 def open_bitstream_file(self):
134   - btypes = [("Xilinx bitstream", ".bit"),
135   - ("Altera bitstream", ".sof"),
136   - ("Microsemi bitstream", "")]
  141 + btypes = [("Xilinx", ".bit"),
  142 + ("Altera", ".cdf")]
137 143 self.bitstream.set(tkFileDialog.askopenfilename(initialdir = "./../User_space/",
138 144 filetypes=btypes))
139 145  
140 146  
... ... @@ -149,39 +155,13 @@
149 155 self.locking_overhead.set(int(round(self.locking_overhead.get())))
150 156  
151 157 def get_PUF_reference_response(self):
152   - self.PUF_reference_response = ''.join(random.SystemRandom().choice(["0", "1"]) for _ in range(256))
153   - self.PUF_reference_response_displayed.set(hex(int(self.PUF_reference_response, 2))[2:-1])
  158 + self.PUF_reference_response_displayed.set("")
  159 + try:
  160 + self.PUF_reference_response = self.tcl_obj.eval(self.board_manager.generate_and_offload_response())
  161 + self.PUF_reference_response_displayed.set(self.PUF_reference_response)
  162 + except:
  163 + self.status.set("Reference response could not be obtained")
154 164  
155   - # To be continued
156   - self.reconciliation_performed.set(False)
157   - self.reference_response_available.set(True)
158   - self.message_key_saved.set("")
159   -
160   - def check_reference_response_available(self, a, b, c): # a, b, c dummy variables
161   - if self.reference_response_available.get():
162   - self.perform_reconciliation_button.configure(state="normal")
163   - self.reconciliation_parameter_initial_block_size_spinbox.configure(state="normal")
164   - self.reconciliation_parameter_number_of_passes_spinbox.configure(state="normal")
165   - self.derive_key_button.configure(state="normal")
166   -
167   - def perform_reconciliation(self):
168   - # To be continued
169   - self.reconciliation_performed.set(True)
170   -
171   - def check_reconciliation_performed(self, a, b, c):
172   - if self.reconciliation_performed.get():
173   - self.masking_button.configure(state="normal")
174   - self.locking_button.configure(state="normal")
175   - self.masking_overhead_spinbox.configure(state="normal")
176   - self.locking_overhead_spinbox.configure(state="normal")
177   - self.modify_design_button.configure(state="normal")
178   - else:
179   - self.masking_button.configure(state="disabled")
180   - self.locking_button.configure(state="disabled")
181   - self.masking_overhead_spinbox.configure(state="disabled")
182   - self.locking_overhead_spinbox.configure(state="disabled")
183   - self.modify_design_button.configure(state="disabled")
184   -
185 165 def pop_up_about(self):
186 166 self.top = Toplevel(background="White")
187 167 self.top.title("About")
188 168  
... ... @@ -223,18 +203,28 @@
223 203 self.msg.pack()
224 204  
225 205 def connect(self):
226   - self.com_port_button_connect.configure(state=DISABLED)
227   - self.com_port_button_disconnect.configure(state=NORMAL)
228   - self.connected.set(True)
229   - self.status.set("Board Connected")
230   - self.status_label.configure(foreground="darkgreen")
  206 + self.tcl_obj.eval(self.board_manager.source_tcl_package())
  207 + tcl_return = self.tcl_obj.eval(self.board_manager.connect(self.com_port.get()))
  208 + if tcl_return == "-1": # Error handling
  209 + self.status.set("Could not connect to the board")
  210 + else: # Connection successful
  211 + self.com_port_button_connect.configure(state=DISABLED)
  212 + self.com_port_button_disconnect.configure(state=NORMAL)
  213 + self.connected.set(True)
  214 + self.board_status.set("Board Connected")
  215 + self.board_status_label.configure(foreground="darkgreen")
  216 + self.status.set("")
231 217  
232 218 def disconnect(self):
233   - self.com_port_button_disconnect.configure(state=DISABLED)
234   - self.com_port_button_connect.configure(state=NORMAL)
235   - self.connected.set(False)
236   - self.status.set("Board not connected")
237   - self.status_label.configure(foreground="red")
  219 + try:
  220 + self.tcl_obj.eval(self.board_manager.disconnect())
  221 + self.com_port_button_disconnect.configure(state=DISABLED)
  222 + self.com_port_button_connect.configure(state=NORMAL)
  223 + self.connected.set(False)
  224 + self.board_status.set("Board not connected")
  225 + self.board_status_label.configure(foreground="red")
  226 + except:
  227 + pass
238 228  
239 229 def modify_design(self):
240 230 self.unlocking_word = ""
GUI/declare_initialize_variables.py View file @ e49b36c
... ... @@ -24,21 +24,15 @@
24 24 self.filename = StringVar()
25 25 self.filename.set("No design loaded")
26 26 self.com_port = StringVar()
27   - self.com_port.set("COM3")
  27 + self.com_port.set("COM5")
28 28 self.masking_overhead = IntVar()
29 29 self.masking_overhead.set(5)
30 30 self.locking_overhead = IntVar()
31 31 self.locking_overhead.set(5)
32   - self.reference_response_available = BooleanVar()
33   - self.reference_response_available.set(False)
34   - self.reference_response_available.trace("w",
35   - self.check_reference_response_available)
  32 +
36 33 self.graph_info = StringVar()
37 34 self.graph_info.set("")
38   - self.reconciliation_performed = BooleanVar()
39   - self.reconciliation_performed.set(False)
40   - self.reconciliation_performed.trace("w",
41   - self.check_reconciliation_performed)
  35 +
42 36 self.masking_heuristic = StringVar()
43 37 self.masking_heuristic.set("random")
44 38 self.connected = BooleanVar()
45 39  
46 40  
... ... @@ -52,14 +46,16 @@
52 46 self.message_modified_design_saved.set("")
53 47  
54 48 self.status = StringVar()
55   - self.status.set("Board not connected")
  49 + self.status.set("")
  50 + self.board_status = StringVar()
  51 + self.board_status.set("Board not connected")
56 52  
57   - self.bitstream = StringVar()
58   - self.bitstream.set("./../User_space/design.bit")
59 53 self.activation_word = StringVar()
60 54 self.activation_word.set("")
61 55 self.design_format = StringVar()
62 56 self.design_format.set("BENCH")
63 57 self.generated_design_format = StringVar()
64 58 self.generated_design_format.set("bench")
  59 + self.programming_command = StringVar()
  60 + self.programming_command.set("")
GUI/declare_pack_frames.py View file @ e49b36c
... ... @@ -32,14 +32,6 @@
32 32 self.motherboard_frame = LabelFrame(self.tab_HECTOR_board_management, text="HECTOR motherboard")
33 33 self.motherboard_frame.pack(side=TOP, fill=X)
34 34  
35   - self.daughterboard_frame = LabelFrame(self.tab_HECTOR_board_management, text="HECTOR daughterboard")
36   - self.daughterboard_frame.pack(side=TOP, fill=X)
37   -
38   - self.program_daughterboard_frame = LabelFrame(self.tab_HECTOR_board_management,
39   - text="Program HECTOR daughterboard")
40   - self.program_daughterboard_frame.pack(fill="x")
41   - self.program_daughterboard_frame.grid_columnconfigure(1, weight=1)
42   -
43 35 # Tab enrolment
44 36  
45 37 self.get_PUF_reference_response_frame = LabelFrame(self.tab_enrolment,
GUI/status_bar.py View file @ e49b36c
... ... @@ -19,10 +19,17 @@
19