OpenCores
URL https://opencores.org/ocsvn/pss/pss/trunk

Subversion Repositories pss

[/] [pss/] [trunk/] [pss/] [SW/] [terminal/] [pss.tcl] - Diff between revs 3 and 7

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 3 Rev 7
set sync_byte       \x55
set sync_byte       \x55
set escape_byte     \x5a
set escape_byte     \x5a
set idcode_cmd      \x00
set idcode_cmd      \x00
set rst_cmd         \x80
set rst_cmd         \x80
set wr_cmd          \x81
set wr_cmd          \x81
set rd_cmd          \x82
set rd_cmd          \x82
set wr_cmd_noinc    \x83
set wr_cmd_noinc    \x83
set rd_cmd_noinc    \x84
set rd_cmd_noinc    \x84
 
 
set reg_cpu_control_addr    0x40000000
set reg_cpu_control_addr    0x40000000
set reg_cpu_pc_addr         0x40000004
set reg_cpu_pc_addr         0x40000004
set reg_cpu_a31_addr        0x40000008
set reg_cpu_a31_addr        0x40000008
set reg_dbg_a31_addr        0x4000000C
set reg_dbg_a31_addr        0x4000000C
 
 
set reg_intc_control_addr   0x40000010
set reg_intc_control_addr   0x40000010
set reg_intc_mask_addr      0x40000014
set reg_intc_mask_addr      0x40000014
set reg_intc_req_addr       0x40000018
set reg_intc_req_addr       0x40000018
set reg_memsize_kb_addr     0x4000001C
set reg_memsize_kb_addr     0x4000001C
 
 
set reg_dma_control_addr    0x40000020
set reg_dma_control_addr    0x40000020
set reg_dma_sourceaddr_addr 0x40000024
set reg_dma_sourceaddr_addr 0x40000024
set reg_dma_destaddr_addr   0x40000028
set reg_dma_destaddr_addr   0x40000028
set reg_dma_size_addr       0x4000002C
set reg_dma_size_addr       0x4000002C
 
 
set reg_sgi_addr            0x40000030
set reg_sgi_addr            0x40000030
set reg_bus_error_addr_addr 0x40000038
set reg_bus_error_addr_addr 0x40000038
set reg_bus_error_pc_addr   0x4000003C
set reg_bus_error_pc_addr   0x4000003C
 
 
set reg_trap_control_addr   0x40000040
set reg_trap_control_addr   0x40000040
set reg_trap_addr_addr      0x40000044
set reg_trap_addr_addr      0x40000044
 
 
proc pss_connect {com_num baudrate} {
proc pss_connect {com_num baudrate} {
    global com
    global com
    set parity n
    set parity n
    set databits 8
    set databits 8
    set stopbits 1
    set stopbits 1
 
 
    set com [open $com_num: r+]
    set com [open $com_num: r+]
    fconfigure $com -mode $baudrate,$parity,$databits,$stopbits \
    fconfigure $com -mode $baudrate,$parity,$databits,$stopbits \
        -blocking 1 -translation binary -buffering none -buffersize 16 -timeout 1000
        -blocking 1 -translation binary -buffering none -buffersize 16 -timeout 1000
}
}
 
 
 
 
proc pss_con {com_num baudrate} {
proc pss_con {com_num baudrate} {
    pss_connect $com_num $baudrate
    pss_connect $com_num $baudrate
}
}
 
 
 
 
proc pss_disconnect {} {
proc pss_disconnect {} {
    global com
    global com
 
 
    close $com
    close $com
    puts "Connection dropped"
    puts "Connection dropped"
}
}
 
 
 
 
proc pss_discon {} {
proc pss_discon {} {
    pss_disconnect
    pss_disconnect
}
}
 
 
 
 
proc pss_check {} {
proc pss_check {} {
    global com
    global com
    global sync_byte
    global sync_byte
    global idcode_cmd
    global idcode_cmd
 
 
    puts -nonewline $com $sync_byte
    puts -nonewline $com $sync_byte
    puts -nonewline $com $idcode_cmd
    puts -nonewline $com $idcode_cmd
    after 100
    after 100
    set resp [read -nonewline $com]
    set resp [read -nonewline $com]
 
 
    binary scan $resp H* resp_char
    binary scan $resp H* resp_char
 
 
    if {$resp == $sync_byte} {puts "Connection established, response: $resp_char"} \
    if {$resp == $sync_byte} {puts "Connection established, response: $resp_char"} \
    else {puts "Conection failed, response: $resp_char"}
    else {puts "Conection failed, response: $resp_char"}
}
}
 
 
 
 
proc pss_cc {com_num baudrate} {
proc pss_cc {com_num baudrate} {
    pss_connect $com_num $baudrate
    pss_connect $com_num $baudrate
    pss_check
    pss_check
}
}
 
 
proc pss_sendbyte {databyte} {
proc pss_sendbyte {databyte} {
    global com
    global com
    global sync_byte
    global sync_byte
    global escape_byte
    global escape_byte
 
 
    if {$databyte == $sync_byte || $databyte == $escape_byte} {puts -nonewline $com $escape_byte}
    if {$databyte == $sync_byte || $databyte == $escape_byte} {puts -nonewline $com $escape_byte}
    puts -nonewline $com $databyte
    puts -nonewline $com $databyte
}
}
 
 
proc pss_sendword {dataword} {
proc pss_sendword {dataword} {
    set byte0 [format %c [expr [expr {$dataword & 0x000000ff}] >> 0]]
    set byte0 [format %c [expr [expr {$dataword & 0x000000ff}] >> 0]]
    set byte1 [format %c [expr [expr {$dataword & 0x0000ff00}] >> 8]]
    set byte1 [format %c [expr [expr {$dataword & 0x0000ff00}] >> 8]]
    set byte2 [format %c [expr [expr {$dataword & 0x00ff0000}] >> 16]]
    set byte2 [format %c [expr [expr {$dataword & 0x00ff0000}] >> 16]]
    set byte3 [format %c [expr [expr {$dataword & 0xff000000}] >> 24]]
    set byte3 [format %c [expr [expr {$dataword & 0xff000000}] >> 24]]
    pss_sendbyte $byte0
    pss_sendbyte $byte0
    pss_sendbyte $byte1
    pss_sendbyte $byte1
    pss_sendbyte $byte2
    pss_sendbyte $byte2
    pss_sendbyte $byte3
    pss_sendbyte $byte3
}
}
 
 
 
 
proc pss_wr {address datawords} {
proc pss_wr {address datawords} {
    global com
    global com
    global sync_byte
    global sync_byte
    global wr_cmd
    global wr_cmd
 
 
    # header
    # header
    puts -nonewline $com $sync_byte
    puts -nonewline $com $sync_byte
    puts -nonewline $com $wr_cmd
    puts -nonewline $com $wr_cmd
 
 
    # address
    # address
    pss_sendword $address
    pss_sendword $address
 
 
    #length
    #length
    set trlength [expr [llength $datawords] << 2]
    set trlength [expr [llength $datawords] << 2]
    pss_sendword $trlength
    pss_sendword $trlength
 
 
    # data
    # data
    foreach dataword $datawords {
    foreach dataword $datawords {
        pss_sendword $dataword
        pss_sendword $dataword
    }
    }
}
}
 
 
 
 
proc pss_rd {address length} {
proc pss_rd {address length} {
    global com
    global com
    global sync_byte
    global sync_byte
    global rd_cmd
    global rd_cmd
 
 
    # clean input buffers
    # clean input buffers
    read $com
    read $com
 
 
    # header
    # header
    puts -nonewline $com $sync_byte
    puts -nonewline $com $sync_byte
    puts -nonewline $com $rd_cmd
    puts -nonewline $com $rd_cmd
 
 
    # address
    # address
    pss_sendword $address
    pss_sendword $address
 
 
    #length
    #length
    pss_sendword $length
    pss_sendword $length
 
 
    set finaddr [expr $length + $address]
    set finaddr [expr $length + $address]
 
 
    set resp ""
    set resp ""
    # data
    # data
    for {set curaddr $address} {$curaddr < $finaddr} {incr curaddr 4} {
    for {set curaddr $address} {$curaddr < $finaddr} {incr curaddr 4} {
        set str ""
        set str ""
        set resp0 [read $com 1]
        set resp0 [read $com 1]
        set resp1 [read $com 1]
        set resp1 [read $com 1]
        set resp2 [read $com 1]
        set resp2 [read $com 1]
        set resp3 [read $com 1]
        set resp3 [read $com 1]
        binary scan $resp0 H2 resp_show0
        binary scan $resp0 H2 resp_show0
        binary scan $resp1 H2 resp_show1
        binary scan $resp1 H2 resp_show1
        binary scan $resp2 H2 resp_show2
        binary scan $resp2 H2 resp_show2
        binary scan $resp3 H2 resp_show3
        binary scan $resp3 H2 resp_show3
        append str "0x"
        append str "0x"
        append str $resp_show3
        append str $resp_show3
        append str $resp_show2
        append str $resp_show2
        append str $resp_show1
        append str $resp_show1
        append str $resp_show0
        append str $resp_show0
        lappend resp $str
        lappend resp $str
    }
    }
 
 
    return $resp
    return $resp
}
}
 
 
 
 
proc pss_wrfile_le {address filename} {
proc pss_wrfile_le {address filename} {
    global com
    global com
    global sync_byte
    global sync_byte
    global wr_cmd
    global wr_cmd
 
 
    set datafile [open $filename]
    set datafile [open $filename]
    fconfigure $datafile -translation binary -encoding binary
    fconfigure $datafile -translation binary -encoding binary
 
 
    # header
    # header
    puts -nonewline $com $sync_byte
    puts -nonewline $com $sync_byte
    puts -nonewline $com $wr_cmd
    puts -nonewline $com $wr_cmd
 
 
    # address
    # address
    pss_sendword $address
    pss_sendword $address
 
 
    #length
    #length
    set length [file size $filename]
    set length [file size $filename]
    pss_sendword $length
    pss_sendword $length
 
 
    while {true} {
    while {true} {
 
 
        set dbuf0 [read $datafile 1]
        set dbuf0 [read $datafile 1]
        set dbuf1 [read $datafile 1]
        set dbuf1 [read $datafile 1]
        set dbuf2 [read $datafile 1]
        set dbuf2 [read $datafile 1]
        set dbuf3 [read $datafile 1]
        set dbuf3 [read $datafile 1]
        if {[eof $datafile]} {break}
        if {[eof $datafile]} {break}
 
 
        pss_sendbyte $dbuf0
        pss_sendbyte $dbuf0
        pss_sendbyte $dbuf1
        pss_sendbyte $dbuf1
        pss_sendbyte $dbuf2
        pss_sendbyte $dbuf2
        pss_sendbyte $dbuf3
        pss_sendbyte $dbuf3
 
 
        incr address 4
        incr address 4
    }
    }
 
 
    close $datafile
    close $datafile
}
}
 
 
 
 
proc pss_wrfile_be {address filename} {
proc pss_wrfile_be {address filename} {
    global com
    global com
    global sync_byte
    global sync_byte
    global wr_cmd
    global wr_cmd
 
 
    set datafile [open $filename]
    set datafile [open $filename]
    fconfigure $datafile -translation binary -encoding binary
    fconfigure $datafile -translation binary -encoding binary
 
 
    # header
    # header
    puts -nonewline $com $sync_byte
    puts -nonewline $com $sync_byte
    puts -nonewline $com $wr_cmd
    puts -nonewline $com $wr_cmd
 
 
    # address
    # address
    pss_sendword $address
    pss_sendword $address
 
 
    #length
    #length
    set length [file size $filename]
    set length [file size $filename]
    pss_sendword $length
    pss_sendword $length
 
 
    while {true} {
    while {true} {
 
 
        set dbuf0 [read $datafile 1]
        set dbuf0 [read $datafile 1]
        set dbuf1 [read $datafile 1]
        set dbuf1 [read $datafile 1]
        set dbuf2 [read $datafile 1]
        set dbuf2 [read $datafile 1]
        set dbuf3 [read $datafile 1]
        set dbuf3 [read $datafile 1]
        if {[eof $datafile]} {break}
        if {[eof $datafile]} {break}
 
 
        pss_sendbyte $dbuf3
        pss_sendbyte $dbuf3
        pss_sendbyte $dbuf2
        pss_sendbyte $dbuf2
        pss_sendbyte $dbuf1
        pss_sendbyte $dbuf1
        pss_sendbyte $dbuf0
        pss_sendbyte $dbuf0
 
 
        incr address 4
        incr address 4
    }
    }
 
 
    close $datafile
    close $datafile
}
}
 
 
 
 
proc pss_reset {} {
proc pss_reset {} {
    global reg_cpu_control_addr
    global reg_cpu_control_addr
 
 
    pss_wr $reg_cpu_control_addr 0x00000001
    pss_wr $reg_cpu_control_addr 0x00000001
    puts "CPU put in reset state"
    puts "CPU put in reset state"
}
}
 
 
 
 
proc pss_start {} {
proc pss_start {} {
    global reg_cpu_control_addr
    global reg_cpu_control_addr
 
 
    pss_wr $reg_cpu_control_addr 0x00000000
    pss_wr $reg_cpu_control_addr 0x00000000
    puts "CPU started"
    puts "CPU started"
}
}
 
 
 
 
proc pss_restart {} {
proc pss_restart {} {
    pss_reset
    pss_reset
    pss_start
    pss_start
}
}
 
 
 
 
proc pss_loadbin {filename} {
proc pss_loadbin {filename} {
    pss_reset
    pss_reset
    pss_wrfile_be 0x00000000 $filename
    pss_wrfile_be 0x00000000 $filename
    pss_start
    pss_start
}
}
 
 
 
 
proc pss_dma_wr {address datawords} {
proc pss_dma_wr {address datawords} {
    global reg_dma_sourceaddr_addr
    global reg_dma_sourceaddr_addr
    global reg_dma_destaddr_addr
    global reg_dma_destaddr_addr
    global reg_dma_size_addr
    global reg_dma_size_addr
    global reg_dma_control_addr
    global reg_dma_control_addr
 
 
    pss_reset
    pss_reset
    pss_wr 0x00000000 $datawords
    pss_wr 0x00000000 $datawords
    pss_wr $reg_dma_sourceaddr_addr 0x00000000
    pss_wr $reg_dma_sourceaddr_addr 0x00000000
    pss_wr $reg_dma_destaddr_addr $address
    pss_wr $reg_dma_destaddr_addr $address
    set trlength [expr [llength $datawords] << 2]
    set trlength [expr [llength $datawords] << 2]
    pss_wr $reg_dma_size_addr $trlength
    pss_wr $reg_dma_size_addr $trlength
    pss_wr $reg_dma_control_addr 0x00000006
    pss_wr $reg_dma_control_addr 0x00000006
}
}
 
 
 
 
proc pss_sgi {} {
proc pss_sgi {} {
    global reg_sgi_addr
    global reg_sgi_addr
 
 
    pss_wr $reg_sgi_addr 0x00000000
    pss_wr $reg_sgi_addr 0x00000000
}
}
 
 
 
 
#pss_cc com4 115200
pss_cc com4 115200
pss_loadbin "D:/Research/Computer_Science/Projects/Practice/zpu/pss/pss/SW/onboard/Interrupts/Interrupts.bin"
pss_loadbin "D:/Research/Computer_Science/Projects/Practice/zpu/pss/pss/SW/onboard/Heartbeatdelay/heartbeatdelay.bin"
#pss_discon
pss_discon
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.