Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

problem of "if" condition

Altera_Forum
Honored Contributor II
993 Views

I wrote a program to process data from PC through uart, but there is something wrong. 

 

<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

main() 

    ...... 

    init_uart0(); 

    ...... 

    while(1) 

    { 

          if(uart0_rbuf_out_cnt != uart0_rbuf_in_cnt ) 

          { 

              ...... 

          } 

    } 

}[/b] 

--- Quote End ---  

 

 

I receive data in uart0_ISR(), if there is one new byte, at first put it into the uart0_rbuf, and then the uart0_rbuf_in_cnt add 1. 

 

 

The problem is when (uart0_rbuf_out_cnt != uart0_rbuf_in_cnt ) is true, it can not go into the program to process the data. 

 

What&#39;s the matter?Thanks.
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
291 Views

Hi, 

define uart0_rbuf_out_cnt and uart0_rbuf_in_cnt variable as volatile, for example: 

 

volatile int uart0_rbuf_out_cnt 

 

if not, the compiler optimize these variables because they aren&#39;t managed in the main program...
0 Kudos
Altera_Forum
Honored Contributor II
291 Views

http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/tongue.gif Thanks,Soin,I&#39;ll try.

0 Kudos
Reply