k2i 0 May 16, 2008 Posted May 16, 2008 · Report post Как в Verilog писать в файл двоичные данные? Функция $fwrite пишет текстовый файл. Quote Share this post Link to post Share on other sites More sharing options...
ClockworkOrange 0 May 16, 2008 Posted May 16, 2008 · Report post $fwrite (номер_файла, [текст_с_форматированием,] {выражение,}); %[0]b, %[0]B число в двоичном формате %[0]h, %[0]H число в шестнадцатеричном формате %[0]d, %[0]D число в десятичном формате %[0]c, %[0]C ASCII-символ %[0]s, %[0]S строка Quote Share this post Link to post Share on other sites More sharing options...
k2i 0 May 16, 2008 Posted May 16, 2008 · Report post Я хочу записать не число в двоичном формате, а двоичный файл. Например reg [7:0] a = 8'h55; должно быть записано в файл одним байтом. Quote Share this post Link to post Share on other sites More sharing options...
des00 26 May 16, 2008 Posted May 16, 2008 · Report post Я хочу записать не число в двоичном формате, а двоичный файл. Например reg [7:0] a = 8'h55; должно быть записано в файл одним байтом. простите что вмешиваюсь, но вот тут вы были ? IEEE Std 1364-2001 -> IEEE Standard Verilog® Hardware Description Language -> 17.2 File input-output system tasks and functions -> 17.2.1 Opening and closing files -> file_open_function ::= integer multi_channel_descriptor = $fopen ( " file_name " ); | integer fd = $fopen ( " file_name ", type ); type is a character string, or a reg containing a character string of one of the following forms in the table below, which indicates how the file should be opened. ...... .....The "b" in the above types exists to distinguish binary files from text files..... как будто на си никогда не работали. Удачи !!! ЗЫ. обычно когда у меня такие вопросы возникали я в стандарт первым делом смотрел, а не целый день на форуме терял. Quote Share this post Link to post Share on other sites More sharing options...
k2i 0 May 16, 2008 Posted May 16, 2008 · Report post Я пробовал и "w" и "wb" - никакой разницы, все равно пишет текстовый файл. :07: Many systems (such as Unix) make no distinction between binary and text files, and on these systems the "b" is ignored. However, some systems (such as machines running NT or Windows) perform data mappings on certain binary values written to and read from files that are opened for text access. У меня Windows XP. Quote Share this post Link to post Share on other sites More sharing options...
des00 26 May 16, 2008 Posted May 16, 2008 · Report post Я пробовал и "w" и "wb" - никакой разницы, все равно пишет текстовый файл. :07: У меня Windows XP. да вы правы. В верилоге заложена возможность чтения бинарных файлов, но не их записи. Единственное что можно сделать в верилоге, систем верилоге, без применения DPI, PLI это вот это : module tb; initial begin : main int fp; fp = $fopen("tst.txt", "w"); for (bit [7:0] i = 0; i < 10; i++) $fwrite(fp,"%u",i); // ищи ответ в разделе 17.1.1.2 Format specifications $fclose(fp); $stop; end endmodule но при этом размер слова приводиться к размеру слова системы, в моем случае это было 32 бита. Если мне память не изменяет в вхдл будет тоже самое. Варианты решения проблемы вижу 2 : 1. Сделать класс бинарного ввода/вывода для вывода чисел с разрядностью != слову ОС. 2. import "DPI"/PLI и все что с этим связано и импортировать сишные функции Удачи !!! Quote Share this post Link to post Share on other sites More sharing options...
k2i 0 May 16, 2008 Posted May 16, 2008 · Report post Единственное что можно сделать в верилоге, систем верилоге, без применения DPI, PLI это вот это : Спасибо! Работает! Буду писать 32-битными словами. Quote Share this post Link to post Share on other sites More sharing options...
Джеймс 5 May 16, 2008 Posted May 16, 2008 (edited) · Report post Вот еще пример записи 32-разр. значений. P.S. Sorry, это практически полностью повторяет пример выше. integer filea; reg [31:0] datawr; initial begin filea=$fopen("D:/a.bin", "wb"); #6000000 //wait.... $fclose (filea); $stop; end always @(posedge clk) begin if (~FifoWr) begin $fwrite(filea,"%u",datawr); end end Edited May 16, 2008 by Джеймс Quote Share this post Link to post Share on other sites More sharing options...
RHnd 0 May 16, 2008 Posted May 16, 2008 · Report post Помнится, для решения такой задачи я писал в файл текстом, а потом на си за пять минут накатал транслятор в бинарный файл. Quote Share this post Link to post Share on other sites More sharing options...