Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)

String operation

Altera_Forum
Honored Contributor II
1,051 Views

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?
0 Kudos
5 Replies
Altera_Forum
Honored Contributor II
314 Views

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;
0 Kudos
Altera_Forum
Honored Contributor II
314 Views

 

--- 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.
0 Kudos
Altera_Forum
Honored Contributor II
314 Views

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.
0 Kudos
Altera_Forum
Honored Contributor II
314 Views

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;
0 Kudos
Altera_Forum
Honored Contributor II
314 Views

I think you mean:  

 

type byte_array is array (0 to RX_BUF_SIZE-1) of std_logic_vector(7 downto 0);
0 Kudos
Reply