<p>Hoernchen has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/osmo-ccid-firmware/+/21116">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">sercom: make waiting for the uart safe...<br><br>In error cases the uart might already be disabled, so waiting for the<br>dre bit does not work.<br><br>Change-Id: I269cf8ece48df24c9f1fcb262ef4ddd06cbe3d62<br>---<br>M sysmoOCTSIM/cuart_driver_asf4_usart_async.c<br>1 file changed, 8 insertions(+), 2 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/osmo-ccid-firmware refs/changes/16/21116/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/sysmoOCTSIM/cuart_driver_asf4_usart_async.c b/sysmoOCTSIM/cuart_driver_asf4_usart_async.c</span><br><span>index e6d180c..64ec9f2 100644</span><br><span>--- a/sysmoOCTSIM/cuart_driver_asf4_usart_async.c</span><br><span>+++ b/sysmoOCTSIM/cuart_driver_asf4_usart_async.c</span><br><span>@@ -5,6 +5,7 @@</span><br><span> #include <osmocom/core/linuxlist.h></span><br><span> #include <osmocom/core/utils.h></span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+#include <include/sam.h></span><br><span> #include <hal_usart_async.h></span><br><span> #include <utils_ringbuffer.h></span><br><span> #include "driver_init.h"</span><br><span>@@ -228,8 +229,13 @@</span><br><span>      cuart->u.asf4.extrawait_after_rx = 1./baudrate * 1000 * 1000;</span><br><span> </span><br><span>         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]);</span><br><span style="color: hsl(0, 100%, 40%);">-  while (!usart_async_is_tx_empty(slot)); // wait for transmission to complete (WARNING no timeout)</span><br><span style="color: hsl(0, 100%, 40%);">-       usart_async_disable(slot); // disable SERCOM peripheral</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     /* only wait if the uart is enabled.... */</span><br><span style="color: hsl(120, 100%, 40%);">+    if (hri_sercomusart_get_CTRLA_reg(slot->device.hw, SERCOM_USART_CTRLA_ENABLE)) {</span><br><span style="color: hsl(120, 100%, 40%);">+           while (!usart_async_is_tx_empty(slot)); // wait for transmission to complete (WARNING no timeout)</span><br><span style="color: hsl(120, 100%, 40%);">+             usart_async_disable(slot); // disable SERCOM peripheral</span><br><span style="color: hsl(120, 100%, 40%);">+       }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>  hri_gclk_clear_PCHCTRL_reg(GCLK, SIM_peripheral_GCLK_ID[slotnr], (1 << GCLK_PCHCTRL_CHEN_Pos)); // disable clock for this peripheral</span><br><span>   while (hri_gclk_get_PCHCTRL_reg(GCLK, SIM_peripheral_GCLK_ID[slotnr], (1 << GCLK_PCHCTRL_CHEN_Pos))); // wait until clock is really disabled</span><br><span>   // it does not seem we need to completely disable the peripheral using hri_mclk_clear_APBDMASK_SERCOMn_bit</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmo-ccid-firmware/+/21116">change 21116</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/osmo-ccid-firmware/+/21116"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-ccid-firmware </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I269cf8ece48df24c9f1fcb262ef4ddd06cbe3d62 </div>
<div style="display:none"> Gerrit-Change-Number: 21116 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Hoernchen <ewild@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>