Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add vhdl textio format (output only) #52

Merged
merged 5 commits into from
Mar 25, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions doc/dictionaries/names.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Hanspeter
Heilig
hexdump
INHX
inout
Interix
Izzet
Jens
Expand Down Expand Up @@ -131,6 +132,7 @@ Telegraphique
Telephonique
Tewie
texlive
textio
tkdiff
tkenc
tmac
Expand Down
15 changes: 15 additions & 0 deletions doc/man1/srec_cat.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
sierrafoxtrot marked this conversation as resolved.
Show resolved Hide resolved
[ \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].
sierrafoxtrot marked this conversation as resolved.
Show resolved Hide resolved

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.
Expand Down
55 changes: 55 additions & 0 deletions doc/man5/srec_vhdl_textio.5
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
'\" t
.\" 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 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 <http://www.gnu.org/licenses/>.
.\"
.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)" "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 file-format contains no addressing and no comments.

.SH EXAMPLE
An example of the file looks like the following - it contains the
data \[lq]Hello, World\[rq].
.RS
.nf
.ft CW
01001000
01100101
01101100
01101100
01101111
00101100
00100000
01010111
01101111
01110010
01101100
01100100
.ft P
.fi
.RE

.ds n) srec_cat
.so man1/z_copyright.so
1 change: 1 addition & 0 deletions srecord/arglex/tool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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, },
Expand Down
1 change: 1 addition & 0 deletions srecord/arglex/tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ class arglex_tool:
token_union,
token_unsplit,
token_vhdl,
token_vhdl_textio,
token_vmem,
token_whirlpool,
token_wilson,
Expand Down
6 changes: 6 additions & 0 deletions srecord/arglex/tool/output.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include <srecord/output/file/ti_txt.h>
#include <srecord/output/file/trs80.h>
#include <srecord/output/file/vhdl.h>
#include <srecord/output/file/vhdl_textio.h>
#include <srecord/output/file/vmem.h>
#include <srecord/output/file/wilson.h>

Expand Down Expand Up @@ -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);
Expand Down
154 changes: 154 additions & 0 deletions srecord/output/file/vhdl_textio.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
//
// srecord - manipulate eprom load files
// Copyright (C) 2023 Daniel Anselmi <[email protected]>
//
// 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 <http://www.gnu.org/licenses/>.
//

#include <algorithm>
sierrafoxtrot marked this conversation as resolved.
Show resolved Hide resolved
#include <srecord/arglex/tool.h>
#include <srecord/interval.h>
#include <srecord/output/file/vhdl_textio.h>
#include <srecord/record.h>
#include <srecord/progname.h>


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 (%d)!\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::append_bits(srecord::record::data_t data,
size_t nbits, std::string &line)
{
for (srecord::record::data_t mask = 1 << (nbits - 1);
mask;
mask = mask >> 1)
{
line += (data & mask) ? "1" : "0";
}
}

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;
unsigned num_bits = gen_bits_per_word;
size_t consume_bits = num_bits % 8U;
if (!consume_bits) consume_bits = 8U;
sierrafoxtrot marked this conversation as resolved.
Show resolved Hide resolved
for (unsigned k = consume_bytes_per_word; k; --k)
{
append_bits(record.get_data(j + k - 1), consume_bits, line);
consume_bits = 8U;
}
put_string(line.append("\n"));
}
break;
}
}


bool
srecord::output_file_vhdl_textio::preferred_block_size_set(int nbytes)
{
// this looks really wrong, from vhdl.cc ???
sierrafoxtrot marked this conversation as resolved.
Show resolved Hide resolved
if (nbytes > 1 || nbytes > record::max_data_length)
sierrafoxtrot marked this conversation as resolved.
Show resolved Hide resolved
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";
}
Loading