lib_uart uart_rx.xc bug?

Technical questions regarding the XTC tools and programming with XMOS.
Post Reply
User avatar
akp
XCore Expert
Posts: 578
Joined: Thu Nov 26, 2015 11:47 pm

lib_uart uart_rx.xc bug?

Post by akp »

Hi,

I found when I am inputting a break (i.e. uart input stuck at zero) with the uart_rx.xc the code outputs continuous 0x00 bytes, even though there is no stop bit -> start bit transition. I believe that is due to the INPUTTING_STOP_BIT state not functioning correctly. I think it may arise in situations where stop_bits is set to 1 (probably the most common situation I would imagine). Here is the existing code:

Code: Select all

      case INPUTTING_STOP_BIT:
        int level_test = p_rxd.input();
        if (level_test == 0) {
          p_rxd.event_when_pins_eq(1);
          state = WAITING_FOR_HIGH;
        }
        stop_bit_count--;
        t += bit_time;
        if (stop_bit_count == 0) {
          p_rxd.event_when_pins_eq(0);
          state = WAITING_FOR_INPUT;
        }
        break;
I have changed it as follows and it seems to work better (i.e. not returning continuous 0x00 bytes in stuck at zero line state but still returning expected data in normal line state):

Code: Select all

      case INPUTTING_STOP_BIT:
        int level_test = p_rxd.input();
        if (level_test == 0) {
          p_rxd.event_when_pins_eq(1);
          state = WAITING_FOR_HIGH;
        }
        else {
          stop_bit_count--;
          t += bit_time;
          if (stop_bit_count == 0) {
            p_rxd.event_when_pins_eq(0);
            state = WAITING_FOR_INPUT;
          }
        }
        break;


User avatar
andrewxcav
Active Member
Posts: 62
Joined: Wed Feb 17, 2016 5:10 pm
Contact:

Post by andrewxcav »

I agree that one stop bit is going to be the most likely (only?) use case. It looks like your fix would work for multiple stop bits as well.

Can you submit a pull request to GitHub?
Post Reply