From 8e9fd5c056a2fb9fbf9039bcb073a23e76b41f4a Mon Sep 17 00:00:00 2001 From: Daniel Anselmi Date: Fri, 10 Mar 2023 23:37:38 +0100 Subject: [PATCH 1/5] add vhdl textio format (output only) --- README.md | 1 + doc/man5/srec_vhdl_textio.5 | 51 ++++++++++ srecord/arglex/tool.cc | 1 + srecord/arglex/tool.h | 1 + srecord/arglex/tool/output.cc | 6 ++ srecord/output/file/vhdl_textio.cc | 151 +++++++++++++++++++++++++++++ srecord/output/file/vhdl_textio.h | 119 +++++++++++++++++++++++ test/02/t0266a.sh | 78 +++++++++++++++ 8 files changed, 408 insertions(+) create mode 100644 doc/man5/srec_vhdl_textio.5 create mode 100644 srecord/output/file/vhdl_textio.cc create mode 100644 srecord/output/file/vhdl_textio.h create mode 100755 test/02/t0266a.sh diff --git a/README.md b/README.md index cfeca88e..73e98bd4 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ The SRecord package understands a number of file formats: * **Texas Instruments ti-txt**: input/output; used by bootstrap loader of *TI MSP430* * **TRS-80**: input/output; used by *The Radio Shack* * **VHDL**: output only +* **VHDL textio**: output only; suitable for loading with `textio.read()` into a bit_vector * **Verilog VMEM**: input/output; suitable for loading with `$readmemh()` * **Wilson**: input/output; mysterious type of EPROM writer diff --git a/doc/man5/srec_vhdl_textio.5 b/doc/man5/srec_vhdl_textio.5 new file mode 100644 index 00000000..6a9b50c0 --- /dev/null +++ b/doc/man5/srec_vhdl_textio.5 @@ -0,0 +1,51 @@ +'\" t +.\" srecord - Manipulate EPROM load files +.\" Copyright (C) 2012 Peter Miller +.\" +.\" This program is free software; you can redistribute it and/or modify +.\" it under the terms of the GNU General Public License as published by +.\" the Free Software Foundation; either version 3 of the License, or +.\" (at your option) any later version. +.\" +.\" This program is distributed in the hope that it will be useful, +.\" but WITHOUT ANY WARRANTY; without even the implied warranty of +.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +.\" General Public License for more details. +.\" +.\" You should have received a copy of the GNU General Public License +.\" along with this program. If not, see . +.\" +.ds n) srec_vhdl_textio +.TH \*(n) 5 SRecord "Reference Manual" +.SH NAME +srec_vhdl_textio \- file-format readable by vhdl textio.read functions. +.if require_index \{ +.XX "srec_vhdl_textio(5)" "Xilinx Coefficient File Format" +.\} +.SH DESCRIPTION +This format is used by VHDL IEEE Std 1076 tools implementing the textio package functions. +They can be used in synthesis (to initialize memories) or simulations (to read simulis). + +The intended type is bit_vector, which means the lines generated by SRecord can be read with +the procedures \[lq]procedure READ (L: inout LINE; VALUE: out BIT_VECTOR; GOOD: out BOOLEAN);\[rq]. or +\[lq]procedure READ (L: inout LINE; VALUE: out BIT_VECTOR);\[rq]. +This file-format contains no addressing and no comments. + +Two optional arguments configure the number of bits consumed from the input and the number of +bits written into the output file. Default is 8 for each. +The number of bits consumed must be a multiple of 8. +It is not allowed to generate more bits than consumed. + +.SH EXAMPLE +An example of the file looks like the following: +.RS +.nf +.ft CW +10010101 +01101011 +.ft P +.fi +.RE + +.ds n) srec_cat +.so man1/z_copyright.so diff --git a/srecord/arglex/tool.cc b/srecord/arglex/tool.cc index 0e150127..764ba127 100644 --- a/srecord/arglex/tool.cc +++ b/srecord/arglex/tool.cc @@ -218,6 +218,7 @@ srecord::arglex_tool::arglex_tool(int argc, char **argv) : { "-Un_Fill", token_unfill, }, { "-Un_SPlit", token_unsplit, }, { "-VHdl", token_vhdl, }, + { "-VHdl_Textio", token_vhdl_textio, }, { "-VMem", token_vmem, }, { "-WHIrlpool", token_whirlpool }, { "-WILson", token_wilson, }, diff --git a/srecord/arglex/tool.h b/srecord/arglex/tool.h index 7a75a9b5..cbeb0eca 100644 --- a/srecord/arglex/tool.h +++ b/srecord/arglex/tool.h @@ -199,6 +199,7 @@ class arglex_tool: token_union, token_unsplit, token_vhdl, + token_vhdl_textio, token_vmem, token_whirlpool, token_wilson, diff --git a/srecord/arglex/tool/output.cc b/srecord/arglex/tool/output.cc index 1413d6e1..a568ed38 100644 --- a/srecord/arglex/tool/output.cc +++ b/srecord/arglex/tool/output.cc @@ -60,6 +60,7 @@ #include #include #include +#include #include #include @@ -335,6 +336,11 @@ srecord::arglex_tool::get_output() ofp = srecord::output_file_vhdl::create(fn); break; + case token_vhdl_textio: + token_next(); + ofp = srecord::output_file_vhdl_textio::create(fn); + break; + case token_vmem: token_next(); ofp = srecord::output_file_vmem::create(fn); diff --git a/srecord/output/file/vhdl_textio.cc b/srecord/output/file/vhdl_textio.cc new file mode 100644 index 00000000..3ae03f18 --- /dev/null +++ b/srecord/output/file/vhdl_textio.cc @@ -0,0 +1,151 @@ +// +// srecord - manipulate eprom load files +// Copyright (C) 2023 Daniel Anselmi +// +// This program is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 3 of the License, or (at +// your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser +// General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +// + +#include +#include +#include +#include +#include +#include + + +srecord::output_file_vhdl_textio::output_file_vhdl_textio(const std::string &a_file_name) : + srecord::output_file(a_file_name) +{ +} + + +srecord::output::pointer +srecord::output_file_vhdl_textio::create(const std::string &a_file_name) +{ + return pointer(new srecord::output_file_vhdl_textio(a_file_name)); +} + + +void +srecord::output_file_vhdl_textio::command_line(srecord::arglex_tool *cmdln) +{ + if (cmdln->can_get_number()) + { + int in_width = cmdln->get_number("input_width"); + if (in_width % 8) + { + warning("input width %d is not a multiple of 8, rounding up!\n", in_width); + in_width += in_width % 8; + } + + int out_width = in_width; + if (cmdln->can_get_number()) + { + out_width = cmdln->get_number("output_width"); + if (out_width > in_width) + { + warning("output width %d is greater than input width!\n", out_width, in_width); + out_width = in_width; + } + } + consume_bytes_per_word = (in_width + 7) / 8; + gen_bits_per_word = out_width; + } +} + +void +srecord::output_file_vhdl_textio::prepend_bits(srecord::record::data_t data, size_t nbits, std::string &line) +{ + for (size_t i = 0; i < nbits ; ++i) + { + if (data % 2) + line = "1" + line; + else + line = "0" + line; + data /= 2; + } +} + +void +srecord::output_file_vhdl_textio::write(const srecord::record &record) +{ + + switch (record.get_type()) + { + case srecord::record::type_unknown: + case srecord::record::type_header: + case srecord::record::type_data_count: + case srecord::record::type_execution_start_address: + // Ignore. + break; + case srecord::record::type_data: + // + // Make sure the data is aligned. + // + if ((record.get_address() % consume_bytes_per_word) || + (record.get_length() % consume_bytes_per_word)) + fatal_alignment_error(consume_bytes_per_word); + + for (size_t j = 0; j < record.get_length(); j += consume_bytes_per_word) + { + std::string line = "\n"; + unsigned num_bits = gen_bits_per_word; + srecord::record::address_t current_word = 0; + for (unsigned k = 0; k < consume_bytes_per_word; ++k) + { + prepend_bits(record.get_data(j + k), std::min(num_bits, 8u), line); + num_bits -= 8; + } + put_string(line); + } + break; + + } +} + + +bool +srecord::output_file_vhdl_textio::preferred_block_size_set(int nbytes) +{ + // this looks really wrong, from vhdl.cc ??? + if (nbytes > 1 || nbytes > record::max_data_length) + return false; + + if (consume_bytes_per_word > 1 && nbytes % consume_bytes_per_word) + return false; + return true; +} + + +int +srecord::output_file_vhdl_textio::preferred_block_size_get() + const +{ + // + // Use the largest we can get, but it has to be a multiple of our + // input word size. + // + int n = srecord::record::max_data_length; + if (consume_bytes_per_word > 1) + n -= (n % consume_bytes_per_word); + return n; +} + + +const char * +srecord::output_file_vhdl_textio::format_name() + const +{ + return "VHDL textio"; +} diff --git a/srecord/output/file/vhdl_textio.h b/srecord/output/file/vhdl_textio.h new file mode 100644 index 00000000..4bf32fe1 --- /dev/null +++ b/srecord/output/file/vhdl_textio.h @@ -0,0 +1,119 @@ +// +// srecord - manipulate eprom load files +// Copyright (C) 2023 Daniel Anselmi +// +// This program is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 3 of the License, or (at +// your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser +// General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +// + +#ifndef SRECORD_OUTPUT_FILE_VHDL_TEXTIO_H +#define SRECORD_OUTPUT_FILE_VHDL_TEXTIO_H + +#include +#include + +namespace srecord +{ + +/** + * The srecord::output_file_vhdl_textio class is used to represent the state out + * an output file in VHDL format. + */ +class output_file_vhdl_textio: + public output_file +{ +public: + /** + * The destructor. + */ + ~output_file_vhdl_textio() override = default; + +private: + /** + * The constructor. It is private on purpose, use the #create + * class method instead. + * + * @param file_name + * The name of the file to be written. The special name "-" + * indicates the standard output is to be used. + */ + output_file_vhdl_textio(const std::string &file_name); + +public: + /** + * The create class method is used to create new dynamically + * allocated instances of this class. + * + * @param file_name + * The name of the file to be written. + */ + static pointer create(const std::string &file_name); + +protected: + // See base class for documentation + void write(const record &) override; + + // See base class for documentation + void line_length_set(int) override {} + + // See base class for documentation + int preferred_block_size_get() const override; + + // See base class for documentation. + bool preferred_block_size_set(int nbytes) override; + + // See base class for documentation + void command_line(arglex_tool *cmdln) override; + + // See base class for documentation. + const char *format_name() const override; + + // See base class for documentation. + void address_length_set(int nbytes) override {} + +private: + /** + * The consume_bytes_per_word instance variable is used to remember how + * many bytes to consume for each output row. + */ + unsigned consume_bytes_per_word{1}; + + /** + * The gen_bits_per_word instance variable is used to remember how + * many bits to generate on each output row. + * must be smaller than consume_bits_per_word + */ + unsigned gen_bits_per_word{8}; + + static void prepend_bits(record::data_t inp, size_t nbits, std::string &line); + +public: + /** + * The default constructor. + */ + output_file_vhdl_textio() = delete; + + /** + * The copy constructor. + */ + output_file_vhdl_textio(const output_file_vhdl_textio &) = delete; + + /** + * The assignment operator. + */ + output_file_vhdl_textio &operator=(const output_file_vhdl_textio &) = delete; +}; + +}; + +#endif // SRECORD_OUTPUT_FILE_VHDL_TEXTIO_H diff --git a/test/02/t0266a.sh b/test/02/t0266a.sh new file mode 100755 index 00000000..0170169d --- /dev/null +++ b/test/02/t0266a.sh @@ -0,0 +1,78 @@ +#!/bin/sh +# +# srecord - Manipulate EPROM load files +# Copyright (C) 2013 Peter Miller +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +TEST_SUBJECT="output vhdl_textio" +. test_prelude.sh + +cat > test.in1 << 'fubar' +S0220000687474703A2F2F737265636F72642E736F75726365666F7267652E6E65742F1D +S1230000FB0BD0707D37A17B0940F850E3B8ADC5F9DEBECBA8F201C38081EB41A3B9EACE29 +S12300205631573C8F926267B25C15F54AF182B222E3CFA4BBDAE85512C391E0B89FC8C4BE +S5030002FA +fubar +if test $? -ne 0; then no_result; fi + +cat > test.ok << 'fubar' +101111111011 +000011010000 +011101111101 +101110100001 +000000001001 +000011111000 +100011100011 +010110101101 +111011111001 +101110111110 +001010101000 +001100000001 +000110000000 +000111101011 +100110100011 +111011101010 +000101010110 +110001010111 +001010001111 +011101100010 +110010110010 +010100010101 +000101001010 +001010000010 +001100100010 +010011001111 +101010111011 +010111101000 +001100010010 +000010010001 +111110111000 +010011001000 +fubar +if test $? -ne 0; then no_result; fi + +srec_cat test.in1 -o test.out -vhdl_textio 16 12 +if test $? -ne 0; then fail; fi + +diff test.ok test.out +if test $? -ne 0; then fail; fi + +# +# The things tested here, worked. +# No other guarantees are made. +# +pass + From d8778a3b0378714dbdd3865fbcc1d348f6ce2f46 Mon Sep 17 00:00:00 2001 From: Daniel Anselmi Date: Fri, 17 Mar 2023 00:06:35 +0100 Subject: [PATCH 2/5] fix ci complainung about different things --- srecord/output/file/vhdl_textio.cc | 37 ++++++++++++++++-------------- srecord/output/file/vhdl_textio.h | 11 +++++---- test/02/t0266a.sh | 1 - 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/srecord/output/file/vhdl_textio.cc b/srecord/output/file/vhdl_textio.cc index 3ae03f18..6cbb4c7b 100644 --- a/srecord/output/file/vhdl_textio.cc +++ b/srecord/output/file/vhdl_textio.cc @@ -24,7 +24,9 @@ #include -srecord::output_file_vhdl_textio::output_file_vhdl_textio(const std::string &a_file_name) : +srecord::output_file_vhdl_textio::output_file_vhdl_textio( + const std::string &a_file_name) +: srecord::output_file(a_file_name) { } @@ -45,7 +47,8 @@ srecord::output_file_vhdl_textio::command_line(srecord::arglex_tool *cmdln) int in_width = cmdln->get_number("input_width"); if (in_width % 8) { - warning("input width %d is not a multiple of 8, rounding up!\n", in_width); + warning("input width (%d) is not a multiple of 8, rounding up!\n", + in_width); in_width += in_width % 8; } @@ -55,7 +58,8 @@ srecord::output_file_vhdl_textio::command_line(srecord::arglex_tool *cmdln) out_width = cmdln->get_number("output_width"); if (out_width > in_width) { - warning("output width %d is greater than input width!\n", out_width, in_width); + warning("output width (%d) is greater than input width (%d)!\n", + out_width, in_width); out_width = in_width; } } @@ -65,15 +69,14 @@ srecord::output_file_vhdl_textio::command_line(srecord::arglex_tool *cmdln) } void -srecord::output_file_vhdl_textio::prepend_bits(srecord::record::data_t data, size_t nbits, std::string &line) +srecord::output_file_vhdl_textio::append_bits(srecord::record::data_t data, + size_t nbits, std::string &line) { - for (size_t i = 0; i < nbits ; ++i) + for (srecord::record::data_t mask = 1 << (nbits - 1); + mask; + mask = mask >> 1) { - if (data % 2) - line = "1" + line; - else - line = "0" + line; - data /= 2; + line += (data & mask) ? "1" : "0"; } } @@ -99,18 +102,18 @@ srecord::output_file_vhdl_textio::write(const srecord::record &record) for (size_t j = 0; j < record.get_length(); j += consume_bytes_per_word) { - std::string line = "\n"; + std::string line; unsigned num_bits = gen_bits_per_word; - srecord::record::address_t current_word = 0; - for (unsigned k = 0; k < consume_bytes_per_word; ++k) + size_t consume_bits = num_bits % 8U; + if (!consume_bits) consume_bits = 8U; + for (unsigned k = consume_bytes_per_word; k; --k) { - prepend_bits(record.get_data(j + k), std::min(num_bits, 8u), line); - num_bits -= 8; + append_bits(record.get_data(j + k - 1), consume_bits, line); + consume_bits = 8U; } - put_string(line); + put_string(line.append("\n")); } break; - } } diff --git a/srecord/output/file/vhdl_textio.h b/srecord/output/file/vhdl_textio.h index 4bf32fe1..439cccde 100644 --- a/srecord/output/file/vhdl_textio.h +++ b/srecord/output/file/vhdl_textio.h @@ -26,8 +26,8 @@ namespace srecord { /** - * The srecord::output_file_vhdl_textio class is used to represent the state out - * an output file in VHDL format. + * The srecord::output_file_vhdl_textio class is used to represent the + * state out an output file in VHDL textio format. */ class output_file_vhdl_textio: public output_file @@ -79,7 +79,7 @@ class output_file_vhdl_textio: const char *format_name() const override; // See base class for documentation. - void address_length_set(int nbytes) override {} + void address_length_set(int /*nbytes*/) override {} private: /** @@ -95,7 +95,8 @@ class output_file_vhdl_textio: */ unsigned gen_bits_per_word{8}; - static void prepend_bits(record::data_t inp, size_t nbits, std::string &line); + static void append_bits(record::data_t inp, size_t nbits, + std::string &line); public: /** @@ -111,7 +112,7 @@ class output_file_vhdl_textio: /** * The assignment operator. */ - output_file_vhdl_textio &operator=(const output_file_vhdl_textio &) = delete; + output_file_vhdl_textio &operator=(const output_file_vhdl_textio&) = delete; }; }; diff --git a/test/02/t0266a.sh b/test/02/t0266a.sh index 0170169d..5410f2f6 100755 --- a/test/02/t0266a.sh +++ b/test/02/t0266a.sh @@ -75,4 +75,3 @@ if test $? -ne 0; then fail; fi # No other guarantees are made. # pass - From 76997fed1f761e569ea78d51e74a3f69badc1e59 Mon Sep 17 00:00:00 2001 From: Daniel Anselmi Date: Fri, 17 Mar 2023 16:42:45 +0100 Subject: [PATCH 3/5] fix more cmplaints from ci --- doc/dictionaries/names.txt | 2 ++ doc/man5/srec_vhdl_textio.5 | 2 +- srecord/output/file/vhdl_textio.cc | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/dictionaries/names.txt b/doc/dictionaries/names.txt index f50fb9bc..113b28d4 100644 --- a/doc/dictionaries/names.txt +++ b/doc/dictionaries/names.txt @@ -60,6 +60,7 @@ Hanspeter Heilig hexdump INHX +inout Interix Izzet Jens @@ -131,6 +132,7 @@ Telegraphique Telephonique Tewie texlive +textio tkdiff tkenc tmac diff --git a/doc/man5/srec_vhdl_textio.5 b/doc/man5/srec_vhdl_textio.5 index 6a9b50c0..a8815915 100644 --- a/doc/man5/srec_vhdl_textio.5 +++ b/doc/man5/srec_vhdl_textio.5 @@ -24,7 +24,7 @@ srec_vhdl_textio \- file-format readable by vhdl textio.read functions. .\} .SH DESCRIPTION This format is used by VHDL IEEE Std 1076 tools implementing the textio package functions. -They can be used in synthesis (to initialize memories) or simulations (to read simulis). +They can be used in synthesis (to initialize memories) or simulations (to read stimuli). The intended type is bit_vector, which means the lines generated by SRecord can be read with the procedures \[lq]procedure READ (L: inout LINE; VALUE: out BIT_VECTOR; GOOD: out BOOLEAN);\[rq]. or diff --git a/srecord/output/file/vhdl_textio.cc b/srecord/output/file/vhdl_textio.cc index 6cbb4c7b..ba16c267 100644 --- a/srecord/output/file/vhdl_textio.cc +++ b/srecord/output/file/vhdl_textio.cc @@ -25,7 +25,7 @@ srecord::output_file_vhdl_textio::output_file_vhdl_textio( - const std::string &a_file_name) + const std::string &a_file_name) : srecord::output_file(a_file_name) { From 223ba991541426560facfd3bc07c6191f38eef09 Mon Sep 17 00:00:00 2001 From: Daniel Anselmi Date: Mon, 20 Mar 2023 22:38:42 +0100 Subject: [PATCH 4/5] split doc into format description and srec_cat usage --- doc/man1/srec_cat.1 | 15 ++++++++++++++ doc/man5/srec_vhdl_textio.5 | 34 +++++++++++++++++-------------- srecord/output/file/vhdl_textio.h | 2 +- test/02/t0266a.sh | 2 +- 4 files changed, 36 insertions(+), 17 deletions(-) diff --git a/doc/man1/srec_cat.1 b/doc/man1/srec_cat.1 index f4b3df25..5e64db10 100644 --- a/doc/man1/srec_cat.1 +++ b/doc/man1/srec_cat.1 @@ -435,6 +435,21 @@ the \f[I]name\fP defaults to \f[CW]eprom\fP. The \f[I]etc/x_defs_pack.vhd\fP file in the source distribution contains an example ROM definitions pack for the type\[hy]independent output. You may need to use the \-byte\[hy]swap filter to get the byte order you want. +.TP 8n +\fB\-VHdl_Textio\fP [ \f[I]in\[hy]bits\[hy]per\[hy]word\fP +[ \f[I]out\[hy]bits\[hy]per\[hy]word\fP ]] +A VHDL textio format file will be written. +Two optional arguments configure the number of bits consumed from the input +and the number of bits written into the output file. Default is 8 for each. +The number of bits consumed must be a multiple of 8. +It is not allowed to generate more bits than consumed. +The intended type is bit_vector, which means the lines generated by SRecord can +be read with the procedures \[lq]procedure READ (L: inout LINE; +VALUE: out BIT_VECTOR; GOOD: out BOOLEAN);\[rq]. or +\[lq]procedure READ (L: inout LINE; VALUE: out BIT_VECTOR);\[rq]. + +You may need to use the \-byte\[hy]swap filter to get the byte order you want. + .TP 8n \fB\-VMem\fP [ \f[I]memory\[hy]width\fP ] A Verilog VMEM format file will be written. diff --git a/doc/man5/srec_vhdl_textio.5 b/doc/man5/srec_vhdl_textio.5 index a8815915..470487b0 100644 --- a/doc/man5/srec_vhdl_textio.5 +++ b/doc/man5/srec_vhdl_textio.5 @@ -1,6 +1,6 @@ '\" t .\" srecord - Manipulate EPROM load files -.\" Copyright (C) 2012 Peter Miller +.\" Copyright (C) 2023 Daniel Anselmi .\" .\" This program is free software; you can redistribute it and/or modify .\" it under the terms of the GNU General Public License as published by @@ -20,29 +20,33 @@ .SH NAME srec_vhdl_textio \- file-format readable by vhdl textio.read functions. .if require_index \{ -.XX "srec_vhdl_textio(5)" "Xilinx Coefficient File Format" +.XX "srec_vhdl_textio(5)" "VHDL textio readable format" .\} .SH DESCRIPTION -This format is used by VHDL IEEE Std 1076 tools implementing the textio package functions. -They can be used in synthesis (to initialize memories) or simulations (to read stimuli). +This format is used by VHDL IEEE Std 1076 tools implementing the textio +package functions. They can be used in synthesis (to initialize memories) or +simulations (to read stimuli). -The intended type is bit_vector, which means the lines generated by SRecord can be read with -the procedures \[lq]procedure READ (L: inout LINE; VALUE: out BIT_VECTOR; GOOD: out BOOLEAN);\[rq]. or -\[lq]procedure READ (L: inout LINE; VALUE: out BIT_VECTOR);\[rq]. This file-format contains no addressing and no comments. -Two optional arguments configure the number of bits consumed from the input and the number of -bits written into the output file. Default is 8 for each. -The number of bits consumed must be a multiple of 8. -It is not allowed to generate more bits than consumed. - .SH EXAMPLE -An example of the file looks like the following: +An example of the file looks like the following - it contains the +data \[lq]Hello, World\[rq]. .RS .nf .ft CW -10010101 -01101011 +01001000 +01100101 +01101100 +01101100 +01101111 +00101100 +00100000 +01010111 +01101111 +01110010 +01101100 +01100100 .ft P .fi .RE diff --git a/srecord/output/file/vhdl_textio.h b/srecord/output/file/vhdl_textio.h index 439cccde..4af0a58b 100644 --- a/srecord/output/file/vhdl_textio.h +++ b/srecord/output/file/vhdl_textio.h @@ -91,7 +91,7 @@ class output_file_vhdl_textio: /** * The gen_bits_per_word instance variable is used to remember how * many bits to generate on each output row. - * must be smaller than consume_bits_per_word + * must be smaller or equal to consume_bytes_per_word * 8 */ unsigned gen_bits_per_word{8}; diff --git a/test/02/t0266a.sh b/test/02/t0266a.sh index 5410f2f6..858e9959 100755 --- a/test/02/t0266a.sh +++ b/test/02/t0266a.sh @@ -1,7 +1,7 @@ #!/bin/sh # # srecord - Manipulate EPROM load files -# Copyright (C) 2013 Peter Miller +# Copyright (C) 2023 Daniel Anselmi # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by From c9ee40cfb83fc17a3f2c58d88582d92f8930c528 Mon Sep 17 00:00:00 2001 From: Daniel Anselmi Date: Sat, 25 Mar 2023 20:34:57 +0100 Subject: [PATCH 5/5] weave in feedback from review (thanks scott) --- doc/man1/srec_cat.1 | 5 +++-- doc/man5/srec_vhdl_textio.5 | 6 ++++++ srecord/output/file/vhdl_textio.cc | 8 ++++---- srecord/output/file/vhdl_textio.h | 5 +++++ 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/doc/man1/srec_cat.1 b/doc/man1/srec_cat.1 index 5e64db10..838f98e8 100644 --- a/doc/man1/srec_cat.1 +++ b/doc/man1/srec_cat.1 @@ -436,7 +436,7 @@ The \f[I]etc/x_defs_pack.vhd\fP file in the source distribution contains an example ROM definitions pack for the type\[hy]independent output. You may need to use the \-byte\[hy]swap filter to get the byte order you want. .TP 8n -\fB\-VHdl_Textio\fP [ \f[I]in\[hy]bits\[hy]per\[hy]word\fP +\fB\-VHdl_Textio\fP [ \f[I]in\[hy]bits\[hy]per\[hy]word\fP \ [ \f[I]out\[hy]bits\[hy]per\[hy]word\fP ]] A VHDL textio format file will be written. Two optional arguments configure the number of bits consumed from the input @@ -445,8 +445,9 @@ The number of bits consumed must be a multiple of 8. It is not allowed to generate more bits than consumed. The intended type is bit_vector, which means the lines generated by SRecord can be read with the procedures \[lq]procedure READ (L: inout LINE; -VALUE: out BIT_VECTOR; GOOD: out BOOLEAN);\[rq]. or +VALUE: out BIT_VECTOR; GOOD: out BOOLEAN);\[rq] or \[lq]procedure READ (L: inout LINE; VALUE: out BIT_VECTOR);\[rq]. +These procedures are available after \[lq]use std.textio.all;\[rq]. You may need to use the \-byte\[hy]swap filter to get the byte order you want. diff --git a/doc/man5/srec_vhdl_textio.5 b/doc/man5/srec_vhdl_textio.5 index 470487b0..b0db4f03 100644 --- a/doc/man5/srec_vhdl_textio.5 +++ b/doc/man5/srec_vhdl_textio.5 @@ -27,6 +27,12 @@ This format is used by VHDL IEEE Std 1076 tools implementing the textio package functions. They can be used in synthesis (to initialize memories) or simulations (to read stimuli). +The intended type is bit_vector, which means the lines generated by SRecord can +be read with the procedures \[lq]procedure READ (L: inout LINE; +VALUE: out BIT_VECTOR; GOOD: out BOOLEAN);\[rq] or +\[lq]procedure READ (L: inout LINE; VALUE: out BIT_VECTOR);\[rq]. +These procedures are available after \[lq]use std.textio.all;\[rq]. + This file-format contains no addressing and no comments. .SH EXAMPLE diff --git a/srecord/output/file/vhdl_textio.cc b/srecord/output/file/vhdl_textio.cc index ba16c267..0e3e818d 100644 --- a/srecord/output/file/vhdl_textio.cc +++ b/srecord/output/file/vhdl_textio.cc @@ -16,7 +16,6 @@ // along with this program. If not, see . // -#include #include #include #include @@ -105,7 +104,8 @@ srecord::output_file_vhdl_textio::write(const srecord::record &record) std::string line; unsigned num_bits = gen_bits_per_word; size_t consume_bits = num_bits % 8U; - if (!consume_bits) consume_bits = 8U; + if (!consume_bits) + consume_bits = 8U; for (unsigned k = consume_bytes_per_word; k; --k) { append_bits(record.get_data(j + k - 1), consume_bits, line); @@ -121,12 +121,12 @@ srecord::output_file_vhdl_textio::write(const srecord::record &record) bool srecord::output_file_vhdl_textio::preferred_block_size_set(int nbytes) { - // this looks really wrong, from vhdl.cc ??? - if (nbytes > 1 || nbytes > record::max_data_length) + if (nbytes < 1 || nbytes > record::max_data_length) return false; if (consume_bytes_per_word > 1 && nbytes % consume_bytes_per_word) return false; + return true; } diff --git a/srecord/output/file/vhdl_textio.h b/srecord/output/file/vhdl_textio.h index 4af0a58b..adacbdfd 100644 --- a/srecord/output/file/vhdl_textio.h +++ b/srecord/output/file/vhdl_textio.h @@ -95,6 +95,11 @@ class output_file_vhdl_textio: */ unsigned gen_bits_per_word{8}; + /** + * helper function to append nbits from inp to line + * converts nbits from byte data_t inp to a string of '0' and '1', + * appending each to the string line. + */ static void append_bits(record::data_t inp, size_t nbits, std::string &line);