2013-08-09 46 views
8

VHDLで、Cソースコード - マクロ__DATE__および__TIME__ と同様のものを使用して、FPGAのバージョンタイムスタンプの種類として利用できますか?FPGAで日付と時刻をコンパイル

>>>新しい投稿者< < < to VHDL次の既存コードを変更して、ハードコードされた日付をFPGAレジスタに追加します。私はいつもコンパイルする前に値を調整することを覚えていなければなりません。これが自動的に行われるのは簡単でしょう。時間/分/秒も含めることができますか?

LIBRARY ieee; 
USE ieee.std_logic_1164.all; 
USE ieee.std_logic_arith.all; 

ENTITY Datum2 IS 
    PORT 
    (
     Day   :OUT std_logic_vector(4 downto 0); 
     Month  :OUT std_logic_vector(3 downto 0); 
     Year  :OUT std_logic_vector(4 downto 0) 
    ); 
END Datum2 ; 

ARCHITECTURE rtl OF Datum2 IS 

BEGIN 
-- "08.08.0013" 
    Day <= conv_std_logic_vector(8, 5); 
    Month <= conv_std_logic_vector(8, 4); 
    Year <= conv_std_logic_vector(13, 5); 
END ARCHITECTURE rtl; 

答えて

14

現在の日付と時刻はVHDLで直接利用できませんが、解決方法を以下に示します。

EDITED 2013-08-10:アルテラのQuartus II Tcl自動生成についての説明が追加されました。

日付と時刻を利用できるようにする一つの方法は、以下のように自動的に生成されたVHDLパッケージを介してである:このVHDLパッケージは、次のようにTclスクリプトを使用して作成することができます

library ieee; 
use ieee.std_logic_1164.all; 

package datetime is 
    -- Date information 
    constant YEAR_INT : integer      := 2013; 
    constant YEAR_HEX : std_logic_vector(15 downto 0) := X"2013"; 
    constant MONTH_INT : integer      := 08; 
    constant MONTH_HEX : std_logic_vector(7 downto 0) := X"08"; 
    constant DAY_INT : integer      := 09; 
    constant DAY_HEX : std_logic_vector(7 downto 0) := X"09"; 
    constant DATE_HEX : std_logic_vector(31 downto 0) := YEAR_HEX & MONTH_HEX & DAY_HEX; 
    -- Time information 
    constant HOUR_INT : integer      := 13; 
    constant HOUR_HEX : std_logic_vector(7 downto 0) := X"13"; 
    constant MINUTE_INT : integer      := 06; 
    constant MINUTE_HEX : std_logic_vector(7 downto 0) := X"06"; 
    constant SECOND_INT : integer      := 29; 
    constant SECOND_HEX : std_logic_vector(7 downto 0) := X"29"; 
    constant TIME_HEX : std_logic_vector(31 downto 0) := X"00" & HOUR_HEX & MINUTE_HEX & SECOND_HEX; 
    -- Miscellaneous information 
    constant EPOCH_INT : integer := 1376046389; -- Seconds since 1970-01-01_00:00:00 
end package; 

# Make datetime.vhd package from Tcl script 

# Current date, time, and seconds since epoch 
# Array index           0 1 2 3 4 5 6 
set datetime_arr [clock format [clock seconds] -format {%Y %m %d %H %M %S %s}] 

# Write VHDL package 
set filename datetime.vhd 
set file [open $filename w] 
puts $file "library ieee;" 
puts $file "use ieee.std_logic_1164.all;" 
puts $file "" 
puts $file "package datetime is" 
puts $file " -- Date information" 
puts $file " constant YEAR_INT : integer      := [lindex $datetime_arr 0];" 
puts $file " constant YEAR_HEX : std_logic_vector(15 downto 0) := X\"[lindex $datetime_arr 0]\";" 
puts $file " constant MONTH_INT : integer      := [lindex $datetime_arr 1];" 
puts $file " constant MONTH_HEX : std_logic_vector(7 downto 0) := X\"[lindex $datetime_arr 1]\";" 
puts $file " constant DAY_INT : integer      := [lindex $datetime_arr 2];" 
puts $file " constant DAY_HEX : std_logic_vector(7 downto 0) := X\"[lindex $datetime_arr 2]\";" 
puts $file " constant DATE_HEX : std_logic_vector(31 downto 0) := YEAR_HEX & MONTH_HEX & DAY_HEX;" 
puts $file " -- Time information" 
puts $file " constant HOUR_INT : integer      := [lindex $datetime_arr 3];" 
puts $file " constant HOUR_HEX : std_logic_vector(7 downto 0) := X\"[lindex $datetime_arr 3]\";" 
puts $file " constant MINUTE_INT : integer      := [lindex $datetime_arr 4];" 
puts $file " constant MINUTE_HEX : std_logic_vector(7 downto 0) := X\"[lindex $datetime_arr 4]\";" 
puts $file " constant SECOND_INT : integer      := [lindex $datetime_arr 5];" 
puts $file " constant SECOND_HEX : std_logic_vector(7 downto 0) := X\"[lindex $datetime_arr 5]\";" 
puts $file " constant TIME_HEX : std_logic_vector(31 downto 0) := X\"00\" & HOUR_HEX & MINUTE_HEX & SECOND_HEX;" 
puts $file " -- Miscellaneous information" 
puts $file " constant EPOCH_INT : integer := [lindex $datetime_arr 6]; -- Seconds since 1970-01-01_00:00:00" 
puts $file "end package;" 
close $file 

アルテラのQuartus IIでは、合成前にこのスクリプトを実行して、日時パッケージを作成することができます。これは、スクリプトは、「make_datetime.tcl」と命名され、以下の行を持つ.qsfファイル、で行われます。

set_global_assignment -name PRE_FLOW_SCRIPT_FILE "quartus_sh:make_datetime.tcl" 

このQuartus IIの機能のさらなる説明がQuartus II Tcl Example: Automatic Script Executionで見つけることができます。

Datum2モジュールは、このようなパッケージを使用することができます:のQuartus IIで合成した後

library ieee; 
use ieee.std_logic_1164.all; 
use ieee.std_logic_arith.all; 

entity Datum2 is 
    port(
    Day : out std_logic_vector(4 downto 0); 
    Month : out std_logic_vector(3 downto 0); 
    Year : out std_logic_vector(4 downto 0)); 
end Datum2; 


library work; 
use work.datetime; 

architecture rtl of Datum2 is 
begin 
    Day <= conv_std_logic_vector(datetime.day_int, 5); 
    Month <= conv_std_logic_vector(datetime.month_int, 4); 
    Year <= conv_std_logic_vector(datetime.year_int mod 100, 5); 
end architecture rtl; 

をRTLビューアは以下のようにモジュールの出力を示しています

enter image description here

以前別の解決策を記載次のようなBashスクリプトを使ってVHDLパッケージを作成することです:

# Make datetime.vhd package from shell script 

# Current date, time, and seconds since epoch 
# Array index   0 1 2 3 4 5 6 
datetime_arr=($(date +"%Y %m %d %H %M %S %s")) 

# Write VHDL package 
filename="datetime.vhd" 
echo "library ieee;" > $filename 
echo "use ieee.std_logic_1164.all;" >> $filename 
echo "" >> $filename 
echo "package datetime is" >> $filename 
echo " -- Date information" >> $filename 
echo " constant YEAR_INT : integer      := ${datetime_arr[0]};" >> $filename 
echo " constant YEAR_HEX : std_logic_vector(15 downto 0) := X\"${datetime_arr[0]}\";" >> $filename 
echo " constant MONTH_INT : integer      := ${datetime_arr[1]};" >> $filename 
echo " constant MONTH_HEX : std_logic_vector(7 downto 0) := X\"${datetime_arr[1]}\";" >> $filename 
echo " constant DAY_INT : integer      := ${datetime_arr[2]};" >> $filename 
echo " constant DAY_HEX : std_logic_vector(7 downto 0) := X\"${datetime_arr[2]}\";" >> $filename 
echo " constant DATE_HEX : std_logic_vector(31 downto 0) := YEAR_HEX & MONTH_HEX & DAY_HEX;" >> $filename 
echo " -- Time information" >> $filename 
echo " constant HOUR_INT : integer      := ${datetime_arr[3]};" >> $filename 
echo " constant HOUR_HEX : std_logic_vector(7 downto 0) := X\"${datetime_arr[3]}\";" >> $filename 
echo " constant MINUTE_INT : integer      := ${datetime_arr[4]};" >> $filename 
echo " constant MINUTE_HEX : std_logic_vector(7 downto 0) := X\"${datetime_arr[4]}\";" >> $filename 
echo " constant SECOND_INT : integer      := ${datetime_arr[5]};" >> $filename 
echo " constant SECOND_HEX : std_logic_vector(7 downto 0) := X\"${datetime_arr[5]}\";" >> $filename 
echo " constant TIME_HEX : std_logic_vector(31 downto 0) := X\"00\" & HOUR_HEX & MINUTE_HEX & SECOND_HEX;" >> $filename 
echo " -- Miscellaneous information" >> $filename 
echo " constant EPOCH_INT : integer := ${datetime_arr[6]}; -- Seconds since 1970-01-01_00:00:00" >> $filename 
echo "end package;" >> $filename 
プラットフォーム独立性について3210

このようなPythonの3.xのスクリプトを使用することができる。

# Make datetime.vhd package from Python 3.x script 

# Get date and time 
import datetime 
import time 
now = datetime.datetime.now() 
now_epoch_sec = int(time.time()) 

# Write VHDL package 
file = open('datetime.vhd', 'wt') 
file.write('library ieee;\n') 
file.write('use ieee.std_logic_1164.all;\n') 
file.write('\n') 
file.write('package datetime is\n') 
file.write(' -- Date information\n') 
file.write(' constant YEAR_INT : integer      := {};\n'.format(now.strftime('%Y'))) 
file.write(' constant YEAR_HEX : std_logic_vector(15 downto 0) := X\"{}\";\n'.format(now.strftime('%Y'))) 
file.write(' constant MONTH_INT : integer      := {};\n'.format(now.strftime('%m'))) 
file.write(' constant MONTH_HEX : std_logic_vector(7 downto 0) := X\"{}\";\n'.format(now.strftime('%m'))) 
file.write(' constant DAY_INT : integer      := {};\n'.format(now.strftime('%d'))) 
file.write(' constant DAY_HEX : std_logic_vector(7 downto 0) := X\"{}\";\n'.format(now.strftime('%d'))) 
file.write(' constant DATE_HEX : std_logic_vector(31 downto 0) := YEAR_HEX & MONTH_HEX & DAY_HEX;\n') 
file.write(' -- Time information\n') 
file.write(' constant HOUR_INT : integer      := {};\n'.format(now.strftime('%H'))) 
file.write(' constant HOUR_HEX : std_logic_vector(7 downto 0) := X\"{}\";\n'.format(now.strftime('%H'))) 
file.write(' constant MINUTE_INT : integer      := {};\n'.format(now.strftime('%M'))) 
file.write(' constant MINUTE_HEX : std_logic_vector(7 downto 0) := X\"{}\";\n'.format(now.strftime('%M'))) 
file.write(' constant SECOND_INT : integer      := {};\n'.format(now.strftime('%S'))) 
file.write(' constant SECOND_HEX : std_logic_vector(7 downto 0) := X\"{}\";\n'.format(now.strftime('%S'))) 
file.write(' constant TIME_HEX : std_logic_vector(31 downto 0) := X\"00\" & HOUR_HEX & MINUTE_HEX & SECOND_HEX;\n') 
file.write(' -- Miscellaneous information\n') 
file.write(' constant EPOCH_INT : integer := {}; -- Seconds since 1970-01-01_00:00:00\n'.format(now_epoch_sec)) 
file.write('end package;\n') 
file.close() 

日時を提示するための32ビットレジスタ値に、モジュールは、このようにすることができ:

library ieee; 
use ieee.std_logic_1164.all; 
entity tb is 
end entity; 

library work; 
use work.datetime; 
architecture sim of tb is 
    signal date_hex : std_logic_vector(31 downto 0); 
    signal time_hex : std_logic_vector(31 downto 0); 
begin 
    date_hex <= datetime.DATE_HEX; 
    time_hex <= datetime.TIME_HEX; 
    process is begin wait; end process; 
end architecture; 

以下に波形を示します。

enter image description here

バッシュやPythonスクリプトのアプローチは、自動パッケージ生成のためのビルド・フローの統合が必要です。

EDITED 2016-08-08(Damienによる更新):アルテラQuartusの非Tclスクリプト呼び出しの説明。

bashスクリプトを(Linux上で)統合するには、プロセスの一部としてbashスクリプトを呼び出すTclラッパースクリプトを作成します。この例では、実際の作業を行い、「call_bash.tcl」スクリプトと「make_datetime.shを」持っている「スクリプト」ディレクトリがあります:

# Useful if the script is in a subdirectory 
proc getScriptDirectory {} { 
    set dispScriptFile [file normalize [info script]] 
    set scriptFolder [file dirname $dispScriptFile] 
    return $scriptFolder 
} 

set scriptDir [getScriptDirectory] 

# Call the bash script which does the real work 
exec $scriptDir/make_datetime_vhdl.sh 

# Add a message the Altera workflow 
post_message -type info "Created datetime.vhd" 

アルテラのビルド・フローに統合、その後することにより達成することができますqsfファイルに以下を追加してください。

set_global_assignment -name PRE_FLOW_SCRIPT_FILE "quartus_sh:scripts/call_bash.tcl" 
+1

私は何か似たようなことを行い、自動ビルドスクリプトの一部としてSubversionリビジョンと日付をバージョンレジスタに入れます。これを行うには多くの方法がありますが、非VHDLプロセスで、デザインに使用するVHDLファイルを更新して、必要な特定のメタデータとともに使用することが一般的です。 –

+0

欠けているのは、特定のツール環境のプロセスを、タグfpga altera、niosから自動化する方法です。適切な応答は、その環境を使用している人を要求するように見えます。また、3つのビットフィールドDay std_logic_vector(4 downto 0)、月std_logic_vector(3 downto 0)、および年std_logic_vector(4〜0)を中心に質問に注意してください。また、いくつかのツール環境(http://www.doulos.com/knowhow/fpga/Setting_Generics_Parameters_for_Synthesis/を参照)には、パラメータを直接設定する機能があります。 – user1155120

+0

@David Koontz:良い点;私は、自動実行のためにQuartus IIフローに統合されたアルテラのQuartus II特有の提案を使用して、その答えを更新しました。 –

1

私は64ビットのstd_logic_vector定数を使用します。

私は現在の時刻をパッケージ内の定数にエンコードするために、合成の直前に実行されるTCLスクリプトを持っています。このスクリプトは、FPGAに組み込まれているので、何らかの方法で読み出すことができます。

私がシミュレーションで使用するのと同じパッケージの自動生成されていないバージョンです - に変更されていないので、テストを更新し続ける必要はありません。

0

タイムスタンプが更新されるたびに完全なコードを書き出す必要はありません。 Quartusでは、コンパイル前にトップレベルのジェネリックを設定するTCLを使用することができます。

は、タイムスタンプエンティティあなたまでジェネリックを渡します。その後、

entity top is 
generic (day, month, year : integer); 
end entity top; 

architecture struct of top is 
begin 
timestamp_inst : entity work.timestamp generic map(day, month, year); 
end architecture struct; 

そしてジェネリックを設定するプリフロースクリプトを使用します。

set_parameter -name day $someday 
set_parameter -name year $someyear 
# etc 

私はこのアプローチを、タイムスタンプ、gitリビジョン、ビルドIDの両方でうまく使用しました。私はそれを単語配列に変換してROMとしてアクセスすると便利だと分かります。あなたの想像力を使ってください。