[rtems commit] bsp/atsam: Fix XDMAD status

Christian Mauderer christianm at rtems.org
Thu Nov 12 07:31:05 UTC 2020


Module:    rtems
Branch:    master
Commit:    cab11b5b805b5fd54113b51992d900607870cb75
Changeset: http://git.rtems.org/rtems/commit/?id=cab11b5b805b5fd54113b51992d900607870cb75

Author:    Christian Mauderer <christian.mauderer at embedded-brains.de>
Date:      Mon Nov  9 09:16:51 2020 +0100

bsp/atsam: Fix XDMAD status

In "bsp/atsam: Simplify XDMAD_Handler()" (5f813694f68cee) the interrupt
callback has been made unconditional. That allowed to avoid some special
deadlock situations in error cases. But it removed part of the XDMAD
status handling.

This patch adds the ability to update the XDMAD status from the
callback if that is necessary for the driver.

Fixes #4173

---

 .../atsam/contrib/libraries/libchip/source/xdmad.c | 60 +++++++++++++++++++++-
 bsps/arm/atsam/include/libchip/include/xdmad.h     |  4 ++
 2 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/bsps/arm/atsam/contrib/libraries/libchip/source/xdmad.c b/bsps/arm/atsam/contrib/libraries/libchip/source/xdmad.c
index 13b2270..161cf0b 100644
--- a/bsps/arm/atsam/contrib/libraries/libchip/source/xdmad.c
+++ b/bsps/arm/atsam/contrib/libraries/libchip/source/xdmad.c
@@ -132,9 +132,66 @@ static uint32_t XDMAD_AllocateXdmacChannel(sXdmad *pXdmad,
 	return XDMAD_ALLOC_FAILED;
 }
 
+/*
+ * Update the internal xdmad state. Returns true if further processing in the
+ * callback is recommended.
+ *
+ * In an earlier version of the API this has been done by the interrupt handler
+ * directly. But in some cases the application might want to process some of the
+ * other interrupts too. Therefore the user callback should now decide itself
+ * whether this is necessary or not.
+ */
+bool XDMAD_UpdateStatusFromCallback(sXdmad *pXdmad,
+		uint32_t Channel,
+		uint32_t status)
+{
+	Xdmac *pXdmac;
+	uint32_t xdmaGlobalChStatus;
+	bool bExec;
+
+	bExec = false;
+	pXdmac = pXdmad->pXdmacs;
+	xdmaGlobalChStatus = XDMAC_GetGlobalChStatus(pXdmac);
+
+	if ((xdmaGlobalChStatus & (XDMAC_GS_ST0 << Channel)) == 0) {
+		uint32_t xdmaChannelIntMask;
+		sXdmadChannel *pCh;
+
+		pCh = &pXdmad->XdmaChannels[Channel];
+
+		xdmaChannelIntMask = XDMAC_GetChannelItMask(pXdmac, Channel);
+		status &= xdmaChannelIntMask;
+
+		if (status & XDMAC_CIS_BIS) {
+			if ((xdmaChannelIntMask & XDMAC_CIM_LIM) == 0) {
+				pCh->state = XDMAD_STATE_DONE;
+				bExec = true;
+			}
+		}
+
+		if (status & XDMAC_CIS_LIS) {
+			pCh->state = XDMAD_STATE_DONE;
+			bExec = true;
+		}
+
+		if (status & XDMAC_CIS_DIS) {
+			pCh->state = XDMAD_STATE_DONE;
+			bExec = true;
+		}
+	} else {
+		/* Block end interrupt for LLI dma mode */
+		if (XDMAC_GetChannelIsr(pXdmac, Channel) & XDMAC_CIS_BIS) {
+			bExec = true;
+		}
+	}
+
+	return bExec;
+}
+
 void XDMAD_DoNothingCallback(uint32_t Channel, void *pArg, uint32_t status)
 {
-	/* Do nothing */
+	/* Do nothing except status update */
+	XDMAD_UpdateStatusFromCallback((sXdmad *)pArg, Channel, status);
 }
 
 /*----------------------------------------------------------------------------
@@ -157,6 +214,7 @@ static void XDMAD_SysInitialize(void)
 
 	for (j = 0; j < pXdmad->numChannels; j ++) {
 		pXdmad->XdmaChannels[j].fCallback = XDMAD_DoNothingCallback;
+		pXdmad->XdmaChannels[j].pArg = (void *)pXdmad;
 	}
 
 	sc = rtems_interrupt_handler_install(
diff --git a/bsps/arm/atsam/include/libchip/include/xdmad.h b/bsps/arm/atsam/include/libchip/include/xdmad.h
index 97e24c8..cba3d05 100644
--- a/bsps/arm/atsam/include/libchip/include/xdmad.h
+++ b/bsps/arm/atsam/include/libchip/include/xdmad.h
@@ -241,6 +241,10 @@ extern eXdmadRC XDMAD_StartTransfer(sXdmad *pXdmad, uint32_t dwChannel);
 
 extern void XDMAD_DoNothingCallback(uint32_t Channel, void *pArg, uint32_t status);
 
+extern bool XDMAD_UpdateStatusFromCallback(sXdmad *pXdmad,
+		uint32_t Channel,
+		uint32_t status);
+
 extern eXdmadRC XDMAD_SetCallback(sXdmad *pXdmad,
 								   uint32_t dwChannel,
 								   XdmadTransferCallback fCallback,



More information about the vc mailing list