- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a string
signal rx_uart_buf : string (0 to 127);
Now I want to test every char value
when ST_PARSE_COM =>
if (idx < RX_BUF_SIZE) then
case character'pos(rx_uart_buf(idx)) is
when 0 => ParseState <= ST_PARSE_IDLE;
when 32 => ParseState <= ST_PARSE_ARG1;
end case;
idx := idx + 1;
end if;
Is it right way to do it?
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In what context? Strings are not suitable for synthesis, so I assume this is simulation only code?
Also, strings can only have a positive range, so cannot start at 0 - it must start at 1 or above? Why bother coverting the char to an integer? why not just use the chars directly?
if (idx < RX_BUF_SIZE) then
case rx_uart_buf(idx) is
when NUL => ParseState <= ST_PARSE_IDLE;
when ' ' => ParseState <= ST_PARSE_ARG1;
end case;
idx := idx + 1;
end if;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- In what context? Strings are not suitable for synthesis, so I assume this is simulation only code? Also, strings can only have a positive range, so cannot start at 0 - it must start at 1 or above? Why bother coverting the char to an integer? why not just use the chars directly?
if (idx < RX_BUF_SIZE) then
case rx_uart_buf(idx) is
when NUL => ParseState <= ST_PARSE_IDLE;
when ' ' => ParseState <= ST_PARSE_ARG1;
end case;
idx := idx + 1;
end if;
--- Quote End --- I see. Thank you. So it doesn't work in real life? I was planning to accumulate chars from terminal to rx_uart_buf and then parse the string.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
A string is just an abstract concept. At hardware level they are just a set of integers.
You could try using a string, and qartus may compile it (Ive done it as a proof of concept to myself) but I wouldnt trust it.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I see. Thank you. Quartus compiles it. But to be on safety side I've decided to define a string as array of bytes
type byte_array is array (0 to RX_BUF_SIZE) of std_logic_vector(7 downto 0); signal rx_uart_buf : byte_array;- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think you mean:
type byte_array is array (0 to RX_BUF_SIZE-1) of std_logic_vector(7 downto 0);
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page