Commit 7883623b28ff2bdc14696164048975b3c6b983ee

Authored by Brice Colombier
1 parent 4a3e457aa3
Exists in master

Finished "Modify design" tab, start board manager

Showing 25 changed files with 1083 additions and 145 deletions

Boards_management/HECTOR_data_acq.tcl View file @ 7883623
  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 +}
Boards_management/board_commands.py View file @ 7883623
  1 +# Author: Brice Colombier
  2 +# Laboratoire Hubert Curien
  3 +# 42000 Saint-Etienne - France
  4 +# Contact: b.colombier@univ-st-etienne.fr
  5 +# Project: Demonstrator
  6 +# File: board_commands.py
  7 +# Date: 2016-10-27
  8 +
  9 +import Tkinter
  10 +
  11 +class Board_manager():
  12 +
  13 + """Handle communication with the board
  14 +
  15 + Board-specific commands must be modified in this file
  16 +
  17 + """
  18 +
  19 + def source_tcl_package(self):
  20 + command = "source HECTOR_data_acq.tcl\n"
  21 + return command
  22 +
  23 + def connect(self, COM_port):
  24 + command = "set dev [openDevice "+COM_port+"]\n"
  25 + return command
  26 +
  27 + def reset_boards(self):
  28 + command = "softReset $dev\n\
  29 + sendDaughterReset $dev\n\
  30 + sendFabricReset $dev"
  31 + return command
  32 +
  33 + def select_DB_connection(self):
  34 + command = "selectDaughterBoard $dev 2\n"
  35 + return command
  36 +
  37 + def get_response(self):
  38 + command = "sendFabricCommand $dev 4 7\n"
  39 + return command
  40 +
  41 + def poll_board(self):
  42 + """-1 1 at the beginning if there is a problem"""
  43 + command = "getStatus $dev\n"
  44 + return command
  45 +
  46 +
  47 +
  48 +if __name__ == "__main__":
  49 +
  50 + r = Tkinter.Tcl()
  51 + Boardm = Board_manager()
  52 + r.eval(Boardm.source_tcl_package())
  53 + r.eval(Boardm.connect("COM3"))
Doc/auto/doc_demonstrator.el View file @ 7883623
... ... @@ -5,6 +5,10 @@
5 5 '(("article" "a4paper" "11pt")))
6 6 (TeX-add-to-alist 'LaTeX-provided-package-options
7 7 '(("geometry" "margin=3cm") ("biblatex" "style=ieee" "doi=false" "isbn=false" "url=false")))
  8 + (add-to-list 'LaTeX-verbatim-macros-with-braces-local "path")
  9 + (add-to-list 'LaTeX-verbatim-macros-with-braces-local "url")
  10 + (add-to-list 'LaTeX-verbatim-macros-with-delims-local "path")
  11 + (add-to-list 'LaTeX-verbatim-macros-with-delims-local "url")
8 12 (TeX-run-style-hooks
9 13 "latex2e"
10 14 "article"
11 15  
... ... @@ -21,7 +25,9 @@
21 25 "sec:logic-masking"
22 26 "sec:cascade-protocool"
23 27 "sec:usage"
  28 + "sec:parsers"
24 29 "sec:gui")
25 30 (LaTeX-add-bibliographies
26   - "F:/biblio")))
  31 + "F:/biblio"))
  32 + :latex)
Doc/doc_demonstrator.tex View file @ 7883623
... ... @@ -48,10 +48,18 @@
48 48 \section{Usage}
49 49 \label{sec:usage}
50 50  
  51 +\subsection{Parsers}
  52 +\label{sec:parsers}
  53 +
  54 +Example design file
  55 +Cells dictionnary
  56 +
51 57 \subsection{GUI}
52 58 \label{sec:gui}
53 59  
54   -Bla bla bla
  60 +VHDL code should not include comments
  61 +Describe strict syntax from example files in Parsers
  62 +
55 63  
56 64 \printbibliography
57 65  
GUI/add_frame_elements.py View file @ 7883623
... ... @@ -94,7 +94,7 @@
94 94 textvariable=self.PUF_reference_response_displayed,
95 95 font=("Courier", 8),
96 96 background="white")
97   - self.reference_response_label.pack(side=LEFT, padx=10)
  97 + self.reference_response_label.pack(side=LEFT, padx=10, fill="x")
98 98 self.derive_key_button=Button(self.key_derivation_frame,
99 99 text="Derive a key from the response",
100 100 command=self.derive_key_from_response,
101 101  
... ... @@ -105,13 +105,29 @@
105 105 textvariable=self.message_key_saved)
106 106 self.key_saved_label.pack(side=LEFT)
107 107 # ------------------------------------------------------
  108 + self.design_label=Label(self.file_frame,
  109 + text="Design:")
  110 + self.design_label.grid(row=0, column=0, sticky=E)
  111 + self.format_label=Label(self.file_frame,
  112 + text="Format:")
  113 + self.format_label.grid(row=1, column=0, sticky=E)
  114 + self.filename_entry=Entry(self.file_frame,
  115 + textvariable=self.filename, width=100)
  116 + self.filename_entry.grid(row=0, column=1, columnspan=2, sticky="EW")
108 117 self.button_open_design=Button(self.file_frame,
109   - text="Open design",
110   - command=self.open_file)
111   - self.button_open_design.pack(side=LEFT)
112   - self.filename_label=Label(self.file_frame,
113   - textvariable=self.filename)
114   - self.filename_label.pack(side=LEFT)
  118 + text="Search...",
  119 + command=self.select_file)
  120 + self.button_open_design.grid(row=0, column=3)
  121 + self.choose_design_format_option_menu = OptionMenu(self.file_frame, self.design_format, "BENCH", "BENCH", "BLIF", "SLIF", "EDIF", "Xilinx EDIF", "VHDL Dataflow", "VHDL Structural", "Verilog Dataflow", "Verilog Structural")
  122 + self.choose_design_format_option_menu.grid(row=1, column=1, sticky=W)
  123 + self.build_graph_button=Button(self.file_frame,
  124 + text="Build graph",
  125 + command=self.build_graph,
  126 + state="normal")
  127 + self.build_graph_button.grid(row=2, column=0)
  128 + self.graph_info_label=Label(self.file_frame,
  129 + textvariable=self.graph_info)
  130 + self.graph_info_label.grid(row=2, column=1, sticky=W)
115 131 # -------------------------------------------------------
116 132 self.locking_button=Checkbutton(self.modify_design_frame,
117 133 text="Locking with",
118 134  
119 135  
120 136  
121 137  
122 138  
... ... @@ -197,20 +213,51 @@
197 213 command=self.modify_design)
198 214 self.modify_design_button.grid(row=2, column=0)
199 215 # -------------------------------------------------------
  216 + self.generated_design_format_label = Label(self.generate_modified_design_frame,
  217 + text="Output format:")
  218 + self.generated_design_format_label.grid(row=0,
  219 + column=0,
  220 + sticky=E)
  221 + self.generated_design_format_bench = Radiobutton(self.generate_modified_design_frame,
  222 + text=".txt",
  223 + variable=self.generated_design_format,
  224 + value="bench")
  225 + self.generated_design_format_bench.grid(row=0,
  226 + column=1,
  227 + sticky=W)
  228 + self.generated_design_format_vhd = Radiobutton(self.generate_modified_design_frame,
  229 + text=".vhd",
  230 + variable=self.generated_design_format,
  231 + value="vhd")
  232 + self.generated_design_format_vhd.grid(row=0,
  233 + column=2,
  234 + sticky=W)
200 235 self.generate_modified_design_button=Button(self.generate_modified_design_frame,
201   - text="Generate modified design",
  236 + text="Generate and save modified design",
202 237 state="normal",
203   - width=29)
204   - self.generate_modified_design_button.grid(row=0,
  238 + command= self.generate_save_modified_design,
  239 + width=32)
  240 + self.generate_modified_design_button.grid(row=1,
205 241 column=0,
206 242 sticky=W)
  243 + self.modified_design_saved_label = Label(self.generate_modified_design_frame,
  244 + textvariable=self.message_modified_design_saved)
  245 + self.modified_design_saved_label.grid(row=1,
  246 + column=1,
  247 + sticky=W)
207 248 self.save_associated_activation_word_button=Button(self.generate_modified_design_frame,
208 249 text="Save associated Activation word",
209 250 state="normal",
210   - width=29)
211   - self.save_associated_activation_word_button.grid(row=1,
  251 + command=self.save_AW,
  252 + width=32)
  253 + self.save_associated_activation_word_button.grid(row=2,
212 254 column=0,
213 255 sticky=W)
  256 + self.activation_word_saved_label = Label(self.generate_modified_design_frame,
  257 + textvariable=self.message_AW_saved)
  258 + self.activation_word_saved_label.grid(row=2,
  259 + column=2,
  260 + sticky=W)
214 261 # -------------------------------------------------------
215 262 self.label_program=Label(self.program_daughterboard_frame,
216 263 text="Bitstream:")
... ... @@ -218,7 +265,7 @@
218 265 self.bitstream_entry = Entry(self.program_daughterboard_frame,
219 266 textvariable=self.bitstream,
220 267 width=81)
221   - self.bitstream_entry.grid(row=0,column=1)
  268 + self.bitstream_entry.grid(row=0,column=1, sticky="EW")
222 269 self.search_bitstream_button=Button(self.program_daughterboard_frame,
223 270 text="Search...",
224 271 command=self.open_bitstream_file)
... ... @@ -233,7 +280,7 @@
233 280 self.activation_word_entry = Entry(self.activation_word_encryption_frame,
234 281 textvariable=self.activation_word,
235 282 width=90)
236   - self.activation_word_entry.grid(row=0, column=1)
  283 + self.activation_word_entry.grid(row=0, column=1, sticky="EW")
237 284 self.search_activation_word_button = Button(self.activation_word_encryption_frame,
238 285 text="Search",
239 286 command=self.open_activation_word)
... ... @@ -9,6 +9,7 @@
9 9 # Date: 2016-10-13
10 10 import random
11 11 import sys
  12 +import time
12 13  
13 14 import tkFileDialog
14 15 from Tkinter import *
15 16  
16 17  
17 18  
18 19  
19 20  
20 21  
21 22  
22 23  
... ... @@ -24,29 +25,48 @@
24 25  
25 26 sys.path.extend(["../Masking/",
26 27 "../Locking/",
27   - "../Key_derivation"])
  28 + "../Key_derivation",
  29 + "../Generate_modified_netlist",
  30 + "../Parsers"])
28 31 import blake2
  32 +
29 33 import locking
  34 +
30 35 import masking
31 36  
  37 +import build_bench
  38 +import build_blif
  39 +import build_edif
  40 +import build_slif
  41 +import build_verilog_rtl
  42 +import build_verilog_struct
  43 +import build_vhd_rtl
  44 +import build_vhd_struct
  45 +import build_xilinx
32 46  
  47 +import convert_back_bench
  48 +import convert_back_vhd
  49 +
  50 +
33 51 class App:
34 52  
35 53 """Main class for the demonstrator GUI app"""
36 54  
37 55 def __init__(self, master):
38 56  
39   - master.maxsize(width=770, height=280)
40   - master.minsize(width=770, height=280)
41   - master.resizable(width=False, height=False)
42   - master.title("SALWARE IP protection tool")
43   - master.iconbitmap(default='./contents/icon.ico')
  57 + self.master = master
44 58  
  59 + self.master.maxsize(width=1000, height=350)
  60 + self.master.minsize(width=1000, height=350)
  61 + self.master.resizable(width=False, height=False)
  62 + self.master.title("SALWARE IP protection tool")
  63 + self.master.iconbitmap(default='./contents/icon.ico')
  64 +
45 65 # Tabs
46   - build_tabs.build_tabs(self, master)
  66 + build_tabs.build_tabs(self)
47 67  
48 68 # Menu bar
49   - build_menu.build_menu(self, master)
  69 + build_menu.build_menu(self)
50 70  
51 71 # Variables
52 72 declare_initialize_variables.declare_initialize_variables(self)
53 73  
54 74  
... ... @@ -58,12 +78,13 @@
58 78 add_frame_elements.add_frame_elements(self)
59 79  
60 80 # Status bar
61   - status_bar.status_bar(self, master)
  81 + status_bar.status_bar(self)
62 82  
63 83  
64   - def open_file(self):
  84 + def select_file(self):
65 85  
66   - ftypes = [("BENCH files", ".txt"),
  86 + ftypes = [("All netlist files", ".txt; .blif; .slif; .edf; .vhd; .v"),
  87 + ("BENCH files", ".txt"),
67 88 ("BLIF files", ".blif"),
68 89 ("SLIF files", ".slif"),
69 90 ("EDIF files", ".edf"),
70 91  
71 92  
72 93  
... ... @@ -72,17 +93,54 @@
72 93 ("Structural VHDL files", ".vhd"),
73