[PATCH 3/4] atsam: libraries: new clock config function

Alexander Krutwig alexander.krutwig at embedded-brains.de
Thu Jun 16 13:48:46 UTC 2016


This was necessary to generate set clock function for i2c driver
without resetting the whole module
---
 .../arm/atsam/libraries/libchip/include/twi.h      |  2 ++
 .../arm/atsam/libraries/libchip/source/twi.c       | 33 ++++++++++++++--------
 2 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/c/src/lib/libbsp/arm/atsam/libraries/libchip/include/twi.h b/c/src/lib/libbsp/arm/atsam/libraries/libchip/include/twi.h
index 6a5de36..07471a1 100644
--- a/c/src/lib/libbsp/arm/atsam/libraries/libchip/include/twi.h
+++ b/c/src/lib/libbsp/arm/atsam/libraries/libchip/include/twi.h
@@ -68,6 +68,8 @@ extern "C" {
  *        External function
  *----------------------------------------------------------------------------*/
 
+extern void TWI_ConfigureClock(Twihs *pTwi, uint32_t twck, uint32_t mck);
+
 extern void TWI_ConfigureMaster(Twihs *pTwi, uint32_t twck, uint32_t mck);
 
 extern void TWI_ConfigureSlave(Twihs *pTwi, uint8_t slaveAddress);
diff --git a/c/src/lib/libbsp/arm/atsam/libraries/libchip/source/twi.c b/c/src/lib/libbsp/arm/atsam/libraries/libchip/source/twi.c
index 29faee6..5012ea5 100644
--- a/c/src/lib/libbsp/arm/atsam/libraries/libchip/source/twi.c
+++ b/c/src/lib/libbsp/arm/atsam/libraries/libchip/source/twi.c
@@ -102,25 +102,15 @@ uint32_t twi_send_stop = 0;
  *        Exported functions
  *----------------------------------------------------------------------------*/
 
-/**
- * \brief Configures a TWI peripheral to operate in master mode, at the given
- * frequency (in Hz). The duty cycle of the TWI clock is set to 50%.
- * \param pTwi  Pointer to an Twihs instance.
- * \param twck  Desired TWI clock frequency.
- * \param mck  Master clock frequency.
- */
-void TWI_ConfigureMaster(Twihs *pTwi, uint32_t dwTwCk, uint32_t dwMCk)
+void TWI_ConfigureClock(Twihs *pTwi, uint32_t dwTwCk, uint32_t dwMCk)
 {
 	uint32_t dwCkDiv = 0;
 	uint32_t dwClDiv;
 	uint32_t dwOk = 0;
 
-	TRACE_DEBUG("TWI_ConfigureMaster()\n\r");
+	TRACE_DEBUG("TWI_ConfigureClock()\n\r");
 	assert(pTwi);
 
-	/* Reset the TWI */
-	pTwi->TWIHS_CR = TWIHS_CR_SWRST;
-
 	/* Configure clock */
 	while (!dwOk) {
 		dwClDiv = ((dwMCk / (2 * dwTwCk)) - 4) / (1 << dwCkDiv);
@@ -135,6 +125,25 @@ void TWI_ConfigureMaster(Twihs *pTwi, uint32_t dwTwCk, uint32_t dwMCk)
 	TRACE_DEBUG("Using CKDIV = %u and CLDIV/CHDIV = %u\n\r", dwCkDiv, dwClDiv);
 
 	pTwi->TWIHS_CWGR = (dwCkDiv << 16) | (dwClDiv << 8) | dwClDiv;
+}
+
+
+/**
+ * \brief Configures a TWI peripheral to operate in master mode, at the given
+ * frequency (in Hz). The duty cycle of the TWI clock is set to 50%.
+ * \param pTwi  Pointer to an Twihs instance.
+ * \param twck  Desired TWI clock frequency.
+ * \param mck  Master clock frequency.
+ */
+void TWI_ConfigureMaster(Twihs *pTwi, uint32_t dwTwCk, uint32_t dwMCk)
+{
+	TRACE_DEBUG("TWI_ConfigureMaster()\n\r");
+	assert(pTwi);
+
+	/* Reset the TWI */
+	pTwi->TWIHS_CR = TWIHS_CR_SWRST;
+
+	TWI_ConfigureClock(pTwi, dwTwCk, dwMCk);
 
 	/* TWI Slave Mode Disabled. */
 	pTwi->TWIHS_CR = TWIHS_CR_SVDIS;
-- 
1.8.4.5




More information about the devel mailing list