Change in osmo-ccid-firmware[master]: sercom: make waiting for the uart safe...

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Hoernchen gerrit-no-reply at lists.osmocom.org
Thu Nov 12 02:07:33 UTC 2020


Hoernchen has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-ccid-firmware/+/21116 )


Change subject: sercom: make waiting for the uart safe...
......................................................................

sercom: make waiting for the uart safe...

In error cases the uart might already be disabled, so waiting for the
dre bit does not work.

Change-Id: I269cf8ece48df24c9f1fcb262ef4ddd06cbe3d62
---
M sysmoOCTSIM/cuart_driver_asf4_usart_async.c
1 file changed, 8 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-ccid-firmware refs/changes/16/21116/1

diff --git a/sysmoOCTSIM/cuart_driver_asf4_usart_async.c b/sysmoOCTSIM/cuart_driver_asf4_usart_async.c
index e6d180c..64ec9f2 100644
--- a/sysmoOCTSIM/cuart_driver_asf4_usart_async.c
+++ b/sysmoOCTSIM/cuart_driver_asf4_usart_async.c
@@ -5,6 +5,7 @@
 #include <osmocom/core/linuxlist.h>
 #include <osmocom/core/utils.h>
 
+#include <include/sam.h>
 #include <hal_usart_async.h>
 #include <utils_ringbuffer.h>
 #include "driver_init.h"
@@ -228,8 +229,13 @@
 	cuart->u.asf4.extrawait_after_rx = 1./baudrate * 1000 * 1000;
 
 	printf("(%u) switching SERCOM clock to GCLK%u (freq = %lu kHz) and baud rate to %lu bps (baud = %u)\r\n", slotnr, (best + 1) * 2, (uint32_t)(round(sercom_glck_freqs[best] / 1000)), baudrate, bauds[best]);
-	while (!usart_async_is_tx_empty(slot)); // wait for transmission to complete (WARNING no timeout)
-	usart_async_disable(slot); // disable SERCOM peripheral
+
+	/* only wait if the uart is enabled.... */
+	if (hri_sercomusart_get_CTRLA_reg(slot->device.hw, SERCOM_USART_CTRLA_ENABLE)) {
+		while (!usart_async_is_tx_empty(slot)); // wait for transmission to complete (WARNING no timeout)
+		usart_async_disable(slot); // disable SERCOM peripheral
+	}
+
 	hri_gclk_clear_PCHCTRL_reg(GCLK, SIM_peripheral_GCLK_ID[slotnr], (1 << GCLK_PCHCTRL_CHEN_Pos)); // disable clock for this peripheral
 	while (hri_gclk_get_PCHCTRL_reg(GCLK, SIM_peripheral_GCLK_ID[slotnr], (1 << GCLK_PCHCTRL_CHEN_Pos))); // wait until clock is really disabled
 	// it does not seem we need to completely disable the peripheral using hri_mclk_clear_APBDMASK_SERCOMn_bit

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-ccid-firmware/+/21116
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-ccid-firmware
Gerrit-Branch: master
Gerrit-Change-Id: I269cf8ece48df24c9f1fcb262ef4ddd06cbe3d62
Gerrit-Change-Number: 21116
Gerrit-PatchSet: 1
Gerrit-Owner: Hoernchen <ewild at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20201112/4915f651/attachment.htm>


More information about the gerrit-log mailing list