Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
general-cores
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
DAQ
Externals
general-cores
Commits
481dea4a
Commit
481dea4a
authored
7 years ago
by
Dimitris Lampridis
Browse files
Options
Downloads
Patches
Plain Diff
hdl: introduce functions to convert characters and strings to std_logic_vectors
parent
6efede39
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/common/gencores_pkg.vhd
+35
-1
35 additions, 1 deletion
modules/common/gencores_pkg.vhd
with
35 additions
and
1 deletion
modules/common/gencores_pkg.vhd
+
35
−
1
View file @
481dea4a
...
...
@@ -10,7 +10,7 @@
-- Dimitrios Lampridis
-- Company : CERN
-- Created : 2009-09-01
-- Last update: 2018-03-2
0
-- Last update: 2018-03-2
3
-- Platform : FPGA-generic
-- Standard : VHDL '93
-------------------------------------------------------------------------------
...
...
@@ -607,6 +607,10 @@ package gencores_pkg is
-- Reduce-OR an std_logic_vector to std_logic
function
f_reduce_or
(
x
:
std_logic_vector
)
return
std_logic
;
-- Character/String to std_logic_vector
function
f_to_std_logic_vector
(
c
:
character
)
return
std_logic_vector
;
function
f_to_std_logic_vector
(
s
:
string
)
return
std_logic_vector
;
end
package
;
package
body
gencores_pkg
is
...
...
@@ -768,4 +772,34 @@ package body gencores_pkg is
return
rv
;
end
f_reduce_or
;
------------------------------------------------------------------------------
-- Convert a character to an 8-bit std_logic_vector
------------------------------------------------------------------------------
function
f_to_std_logic_vector
(
c
:
character
)
return
std_logic_vector
is
variable
rv
:
std_logic_vector
(
7
downto
0
);
begin
rv
:
=
std_logic_vector
(
to_unsigned
(
character
'pos
(
c
),
8
));
return
rv
;
end
function
f_to_std_logic_vector
;
------------------------------------------------------------------------------
-- Convert a string of characters to a std_logic_vector of bytes.
-- NOTE: right-most character is stored at rv(7 downto 0).
------------------------------------------------------------------------------
function
f_to_std_logic_vector
(
s
:
string
)
return
std_logic_vector
is
variable
rv
:
std_logic_vector
(
s
'length
*
8-1
downto
0
);
variable
k
:
natural
;
begin
for
i
in
s
'range
loop
-- calculate offset within rv
k
:
=
8
*
(
4
-
i
);
-- do the character conversion and write to proper offset
rv
(
k
+
7
downto
k
)
:
=
f_to_std_logic_vector
(
s
(
i
));
end
loop
;
return
rv
;
end
function
f_to_std_logic_vector
;
end
gencores_pkg
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment