k_msgq_get does not wait till the given timeout period

Hi,

I am using Echo bot example in nrf connect sdk v.2.0.2

I have connected my UART to BG95 module and i am able to send and recieve data

but , the problem is,

	uint8_t txdata[64] = "AT\r\n";
	print_uart(txdata);
	memset(tx_buf,0,MSG_SIZE);
  uint8_t ret;
	/* indefinitely wait for input from the user */
	while (ret = k_msgq_get(&uart_msgq, &tx_buf, K_TIMEOUT_ABS_MS(8000)) == 0) {
		printk("Echo:%s\r\n",tx_buf);
	}
  printf("while_ret:%d\n",ret);

when i run the above set, first time it works perfect, it waits for 8 secs as given and iam able to recieve the data,

but when i repeat the set for the second time, the k_msgq_get doesnot wait for the given 8 secs, it just execute once and then exits while loop.

What could be possibly wrong??

Parents
  • Here's my main for reference

    void main(void)
    {
    	char tx_buf[MSG_SIZE];
    
    	if (!device_is_ready(uart_dev)) {
    		printk("UART device not found!");
    		return;
    	}
    
    	/* configure interrupt and callback to receive data */
    	uart_irq_callback_user_data_set(uart_dev, serial_cb, NULL);
    	uart_irq_rx_enable(uart_dev);
    
    	print_uart("Hello! I'm your echo bot.\r\n");
    	print_uart("Tell me something and press enter:\r\n");
    	uint32_t uptime;
    	uptime = k_uptime_get();
    	printf("uptime_1:%d",uptime);
    	/* indefinitely wait for input from the user */
    	while (k_msgq_get(&uart_msgq, &tx_buf, K_TIMEOUT_ABS_MS(8000)) == 0) {
    		print_uart("Echo: ");
    		print_uart(tx_buf);
    		print_uart("\r\n");
    	}
    	uptime = k_uptime_get();
    	printf("uptime_2:%d",uptime);
    	while (k_msgq_get(&uart_msgq, &tx_buf, K_TIMEOUT_ABS_MS(8000)) == 0) {
    		print_uart("Echo: ");
    		print_uart(tx_buf);
    		print_uart("\r\n");
    	}
    		uptime = k_uptime_get();
    	printf("uptime_3:%d",uptime);
    }

    and the output

    *** Booting Zephyr OS build v3.0.99-ncs1-1  ***
    Hello! I'm your echo bot.
    Tell me something and press enter:
    uptime_1:419uptime_2:8000uptime_3:8001

Reply
  • Here's my main for reference

    void main(void)
    {
    	char tx_buf[MSG_SIZE];
    
    	if (!device_is_ready(uart_dev)) {
    		printk("UART device not found!");
    		return;
    	}
    
    	/* configure interrupt and callback to receive data */
    	uart_irq_callback_user_data_set(uart_dev, serial_cb, NULL);
    	uart_irq_rx_enable(uart_dev);
    
    	print_uart("Hello! I'm your echo bot.\r\n");
    	print_uart("Tell me something and press enter:\r\n");
    	uint32_t uptime;
    	uptime = k_uptime_get();
    	printf("uptime_1:%d",uptime);
    	/* indefinitely wait for input from the user */
    	while (k_msgq_get(&uart_msgq, &tx_buf, K_TIMEOUT_ABS_MS(8000)) == 0) {
    		print_uart("Echo: ");
    		print_uart(tx_buf);
    		print_uart("\r\n");
    	}
    	uptime = k_uptime_get();
    	printf("uptime_2:%d",uptime);
    	while (k_msgq_get(&uart_msgq, &tx_buf, K_TIMEOUT_ABS_MS(8000)) == 0) {
    		print_uart("Echo: ");
    		print_uart(tx_buf);
    		print_uart("\r\n");
    	}
    		uptime = k_uptime_get();
    	printf("uptime_3:%d",uptime);
    }

    and the output

    *** Booting Zephyr OS build v3.0.99-ncs1-1  ***
    Hello! I'm your echo bot.
    Tell me something and press enter:
    uptime_1:419uptime_2:8000uptime_3:8001

Children
No Data
Related