Choose the UARTE API (Async/interrupt driven) during runtime

Hello,

I need a way to decide on which Api to use for UARTE (configured as uart1) once in main(). I am not intending to switch between them nor to use them at the same time. I am aware that it is not possible to use both simultaneously on the same uart. I am using the the nRF52840 with the following configuration

/ {
    chosen {
        zephyr,console = &uart0;
    };
};


&uart0 {
    compatible = "nordic,nrf-uart";
    current-speed = <115200>;
    status = "okay";
    pinctrl-0 = <&uart0_default_alt>;
    pinctrl-1 = <&uart0_sleep_alt>;
    pinctrl-names = "default", "sleep";
};


&uart1 {
    compatible = "nordic,nrf-uarte";
    current-speed = <115200>;
    status = "okay";
    pinctrl-0 = <&uart1_default_alt>;
    pinctrl-1 = <&uart1_sleep_alt>;
    pinctrl-names = "default", "sleep";
    
    /* Used for communication on modbus sensor */
    test_dev: modbus0 {
		compatible = "zephyr,modbus-serial";
		status = "okay";
	};
};

  • Uart0 is chosen for the console debugging.
  • Uart1 needs to work using
    • the interrupt driven api if the sensor is of type x
    • and work with the async api if the sensor is of type y.

Any help, even a hacky workaround, will be much appreciated. 

Related