Go Back   Velocity Reviews > Newsgroups > VHDL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

VHDL - Subtyping issue

 
Thread Tools Search this Thread
Old 06-30-2005, 01:46 PM   #1
Default Subtyping issue


I would like to restrict the space of characters.:
subtype TMYCHAR is character ('a', '1', '.'); -- not supported

I would like the interpriter to understand that the elements are characters
so that character'pos attribute were applicable to them for ASCII code
retreival. Like
constant C: character := TMYCHAR'val(1);
constant I: intger := character'pos(C); -- must be x61

Unfortunately, VHDL supports only ranges rather than enumerations in the
specification of subtype. How would you perform the convertion:
type TMYCHAR is ('a', '1', '.');
constant C: character := TMYCHAR'val(1);



I fail to write a function TMYCHAR elements with characters

function GET_ASCII(MC: TMYCHAR) return character is
begin
for C in character'left to character'right loop
if C = MC then -- incompareble types
return character'pos(C);
end if;
end loop;
end;



thanks in advance




valentin tihomirov
  Reply With Quote
Old 06-30-2005, 02:42 PM   #2
Jonathan Bromley
 
Posts: n/a
Default Re: Subtyping issue
On Thu, 30 Jun 2005 15:46:28 +0300, "valentin tihomirov"
<> wrote:

>I would like to restrict the space of characters.:
> subtype TMYCHAR is character ('a', '1', '.'); -- not supported
>
>I would like the interpriter to understand that the elements are characters
>so that character'pos attribute were applicable to them for ASCII code
>retreival. Like
> constant C: character := TMYCHAR'val(1);
> constant I: intger := character'pos(C); -- must be x61
>
>Unfortunately, VHDL supports only ranges rather than enumerations in the
>specification of subtype.


You are trying to specify a *set* of character. Modula-2 and Pascal
supported sets. VHDL does not.

> How would you perform the convertion:
> type TMYCHAR is ('a', '1', '.');
> constant C: character := TMYCHAR'val(1);


One possible solution...

function To_Character(C: TMYCHAR) return CHARACTER is
begin
return CHARACTER'VALUE(TMYCHAR'IMAGE(C));
end

Alternatively, try a lookup table:

type Char_Lookup is array (TMYCHAR) of CHARACTER;
constant To_Character: Char_Lookup :=
( 'a' => 'a'
, '1' => '1'
, '.' => '.'
);

In either case (function or lookup table) you can then write...

constant C: CHARACTER := To_Character('1');

HTH
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL, Verilog, SystemC, Perl, Tcl/Tk, Verification, Project Services

Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, BH24 1AW, UK
Tel: +44 (0)1425 471223 mail:
Fax: +44 (0)1425 471573 Web: http://www.doulos.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.


Jonathan Bromley
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Digital DIGEST - LIVE UPDATE Issue 41 Ablang DVD Video 0 01-05-2004 11:54 PM
Re: odd motherboard issue hootnholler A+ Certification 0 12-19-2003 06:34 AM
Digital DIGEST - LIVE UPDATE Issue 40 Ablang DVD Video 0 12-15-2003 02:45 PM
Digital DIGEST - LIVE UPDATE Issue 39 Ablang DVD Video 0 11-29-2003 02:17 AM
Digital DIGEST - LIVE UPDATE Issue 38 Ablang DVD Video 0 11-09-2003 01:31 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46