drivers: serial: nrfx: Skip poll out when device is not active

Added early return from uart_poll_out when uart device is not in
active state. Poll_out is used from many contexts by multiple users
and currently here is no mechanism in power management to disable
them (console, logger when going to inactive power state.

Additionally, moved setting new state when disactivating the device to
ensure that no poll_out will happen after disabling the UARTE.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
Krzysztof Chruscinski 2020-11-26 11:26:09 +01:00 committed by Ioannis Glaropoulos
commit 751bdf483b

View file

@ -1122,6 +1122,11 @@ static void uarte_nrfx_poll_out(const struct device *dev, unsigned char c)
NRF_UARTE_Type *uarte = get_uarte_instance(dev); NRF_UARTE_Type *uarte = get_uarte_instance(dev);
int key; int key;
#ifdef CONFIG_DEVICE_POWER_MANAGEMENT
if (data->pm_state != DEVICE_PM_ACTIVE_STATE) {
return;
}
#endif
if (isr_mode) { if (isr_mode) {
while (1) { while (1) {
key = irq_lock(); key = irq_lock();
@ -1534,6 +1539,8 @@ static void uarte_nrfx_set_power_state(const struct device *dev,
NRF_UARTE_PSEL_DISCONNECTED) { NRF_UARTE_PSEL_DISCONNECTED) {
nrf_uarte_task_trigger(uarte, NRF_UARTE_TASK_STARTRX); nrf_uarte_task_trigger(uarte, NRF_UARTE_TASK_STARTRX);
} }
data->pm_state = new_state;
} else { } else {
__ASSERT_NO_MSG(new_state == DEVICE_PM_LOW_POWER_STATE || __ASSERT_NO_MSG(new_state == DEVICE_PM_LOW_POWER_STATE ||
new_state == DEVICE_PM_SUSPEND_STATE || new_state == DEVICE_PM_SUSPEND_STATE ||
@ -1546,6 +1553,8 @@ static void uarte_nrfx_set_power_state(const struct device *dev,
return; return;
} }
data->pm_state = new_state;
/* Disabling UART requires stopping RX, but stop RX event is /* Disabling UART requires stopping RX, but stop RX event is
* only sent after each RX if async UART API is used. * only sent after each RX if async UART API is used.
*/ */
@ -1587,7 +1596,6 @@ static int uarte_nrfx_pm_control(const struct device *dev,
if (new_state != data->pm_state) { if (new_state != data->pm_state) {
uarte_nrfx_set_power_state(dev, new_state); uarte_nrfx_set_power_state(dev, new_state);
data->pm_state = new_state;
} }
} else { } else {
__ASSERT_NO_MSG(ctrl_command == DEVICE_PM_GET_POWER_STATE); __ASSERT_NO_MSG(ctrl_command == DEVICE_PM_GET_POWER_STATE);