Repository: Samsung/TizenRT
Pull request #6788: os/arch/arm/amebasmart: Remove sem calling during enter PG.
Author: login: ewoodev
Created: 2025-04-18T13:58:25Z | Merged: 2025-04-22T09:43:45Z

the board sleep seqeunce is in idle.
So, we can't call sem_wait in this time because we can't give up the cpu in idle.

Therefore, Remove sem calling situation during enter PG


Diff:
diff --git a/os/arch/arm/src/amebasmart/amebasmart_i2c.c b/os/arch/arm/src/amebasmart/amebasmart_i2c.c
index 0850d1cdd2..ba4675e7fc 100644
--- a/os/arch/arm/src/amebasmart/amebasmart_i2c.c
+++ b/os/arch/arm/src/amebasmart/amebasmart_i2c.c
@@ -429,6 +429,9 @@ static inline void amebasmart_i2c_sem_wait(FAR struct amebasmart_i2c_priv_s *pri
 {
 	int ret;
 
+#ifdef CONFIG_PM
+	bsp_pm_domain_control(BSP_I2C_DRV, 1);
+#endif
 	do {
 		/* Take the semaphore (perhaps waiting) */
 
@@ -625,6 +628,9 @@ static inline void amebasmart_i2c_sem_waitstop(FAR struct amebasmart_i2c_priv_s
 static inline void amebasmart_i2c_sem_post(struct amebasmart_i2c_priv_s *priv)
 {
 	sem_post(&priv->sem_excl);
+#ifdef CONFIG_PM
+	bsp_pm_domain_control(BSP_I2C_DRV, 0);
+#endif
 }
 
 /************************************************************************************
@@ -922,9 +928,9 @@ static int amebasmart_i2c_init(FAR struct amebasmart_i2c_priv_s *priv)
 {
 	/* Power-up and configure GPIOs */
 	DEBUGASSERT(priv);
-	DEBUGASSERT(!priv->i2c_object);
-	priv->i2c_object = (i2c_t *)kmm_malloc(sizeof(i2c_t));
 	DEBUGASSERT(priv->i2c_object);
+	priv->i2c_object->i2c_idx = 0;
+	priv->i2c_object->I2Cx = NULL;
 	i2c_init(priv->i2c_object, priv->config->sda_pin, priv->config->scl_pin);
 
 #ifdef CONFIG_I2C_WRITEREAD
@@ -953,16 +959,12 @@ static int amebasmart_i2c_deinit(FAR struct amebasmart_i2c_priv_s *priv)
 {
 
 	DEBUGASSERT(priv);
-	DEBUGASSERT(priv->i2c_object);
 
 #ifndef CONFIG_I2C_POLLED
 	up_disable_irq(priv->config->irq);
 	irq_detach(priv->config->irq);
 #endif
 
-	kmm_free(priv->i2c_object);
-	priv->i2c_object = NULL;
-
 	return OK;
 }
 
@@ -1194,6 +1196,10 @@ FAR struct i2c_dev_s *up_i2cinitialize(int port)
 
 	if ((volatile int)priv->refs++ == 0) {
 		amebasmart_i2c_sem_init(priv);
+
+		DEBUGASSERT(!priv->i2c_object);
+		priv->i2c_object = (i2c_t *)kmm_malloc(sizeof(i2c_t));
+		DEBUGASSERT(priv->i2c_object);
 		amebasmart_i2c_init(priv);
 	}
 
@@ -1236,6 +1242,10 @@ int up_i2cuninitialize(FAR struct i2c_dev_s *dev)
 
 	amebasmart_i2c_deinit(priv);
 
+	DEBUGASSERT(priv->i2c_object);
+	kmm_free(priv->i2c_object);
+	priv->i2c_object = NULL;
+
 	/* Release unused resources */
 
 	amebasmart_i2c_sem_destroy(priv);
@@ -1277,10 +1287,10 @@ static uint32_t rtk_i2c_suspend(uint32_t expected_idle_time, void *param)
 
 	/* Need to destroy semaphore and release i2c object to prevent memory leak */
 #ifdef CONFIG_AMEBASMART_I2C1
-	up_i2cuninitialize((struct i2c_dev_s *)&amebasmart_i2c1_priv);
+	amebasmart_i2c_deinit(&amebasmart_i2c1_priv);
 #endif
 #ifdef CONFIG_AMEBASMART_I2C2
-	up_i2cuninitialize((struct i2c_dev_s *)&amebasmart_i2c2_priv);
+	amebasmart_i2c_deinit(&amebasmart_i2c2_priv);
 #endif
 	return 1;
 }
@@ -1292,10 +1302,10 @@ static uint32_t rtk_i2c_resume(uint32_t expected_idle_time, void *param)
 	/* For PG Sleep, I2C 1/2 HW will be lost power, thus a reinitialization is required here 
 	I2C0 is under SYSON block, so it will not require to be reinitialized*/
 #ifdef CONFIG_AMEBASMART_I2C1
-	(void) up_i2cinitialize(1);
+	amebasmart_i2c_init(&amebasmart_i2c1_priv);
 #endif
 #ifdef CONFIG_AMEBASMART_I2C2
-	(void) up_i2cinitialize(2);
+	amebasmart_i2c_init(&amebasmart_i2c2_priv);
 #endif
 	return 1;
 }
diff --git a/os/arch/arm/src/amebasmart/amebasmart_i2s.c b/os/arch/arm/src/amebasmart/amebasmart_i2s.c
index 82c62671d7..7c7781d873 100644
--- a/os/arch/arm/src/amebasmart/amebasmart_i2s.c
+++ b/os/arch/arm/src/amebasmart/amebasmart_i2s.c
@@ -1800,7 +1800,7 @@ static int i2s_allocate_wd(struct amebasmart_i2s_s *priv)
  *   Valid i2s device structure reference on succcess; a NULL on failure
  *
  ****************************************************************************/
-struct i2s_dev_s *amebasmart_i2s_initialize(uint16_t port, bool is_reinit)
+struct i2s_dev_s *amebasmart_i2s_initialize(uint16_t port)
 {
 	struct amebasmart_i2s_config_s *hw_config_s = NULL;
 	struct amebasmart_i2s_s *priv;
@@ -1822,24 +1822,18 @@ struct i2s_dev_s *amebasmart_i2s_initialize(uint16_t port, bool is_reinit)
 		return NULL;
 	}
 
-	if (!is_reinit) {
-		if (g_i2sdevice[port] != NULL) {
-			return &g_i2sdevice[port]->dev;
-		}
+	if (g_i2sdevice[port] != NULL) {
+		return &g_i2sdevice[port]->dev;
+	}
 
-		/* Allocate a new state structure for this chip select.  NOTE that there
-		* is no protection if the same chip select is used in two different
-		* chip select structures.
-		*/
-		priv = (struct amebasmart_i2s_s *)kmm_zalloc(sizeof(struct amebasmart_i2s_s));
-		if (!priv) {
-			i2serr("ERROR: Failed to allocate a chip select structure\n");
-			return NULL;
-		}
-	} else {
-		/* The I2S structure should exist after system wakeup */
-		priv = g_i2sdevice[port];
-		DEBUGASSERT(priv);
+	/* Allocate a new state structure for this chip select.  NOTE that there
+	 * is no protection if the same chip select is used in two different
+	 * chip select structures.
+	 */
+	priv = (struct amebasmart_i2s_s *)kmm_zalloc(sizeof(struct amebasmart_i2s_s));
+	if (!priv) {
+		i2serr("ERROR: Failed to allocate a chip select structure\n");
+		return NULL;
 	}
 
 	priv->i2s_object = (i2s_t *)kmm_zalloc(sizeof(i2s_t));
@@ -1891,9 +1885,7 @@ struct i2s_dev_s *amebasmart_i2s_initialize(uint16_t port, bool is_reinit)
 	}
 	/* Basic settings */
 	//priv->i2s_num = priv->i2s_object->i2s_idx;
-	if (!is_reinit) {
-		g_i2sdevice[port] = priv;
-	}
+	g_i2sdevice[port] = priv;
 
 	/* Success exit */
 	return &priv->dev;
@@ -1913,23 +1905,49 @@ static void amebasmart_i2s_suspend(uint16_t port)
 	struct amebasmart_i2s_s *priv = g_i2sdevice[port];
 
 	i2s_disable(priv->i2s_object, 1);
-	i2s_tx_enabled = 0;
-	kmm_free(priv->i2s_object);
-	priv->i2s_object = NULL;
-	sem_destroy(&priv->exclsem);
-	sem_destroy(&priv->bufsem_tx);
 #if defined(I2S_HAVE_RX) && (0 < I2S_HAVE_RX)
 	if (priv->rx.dog) {
-		wd_delete(priv->rx.dog);
+		wd_cancel(priv->rx.dog);
 		priv->rx.dog = NULL;
 	}
 #endif
 #if defined(I2S_HAVE_TX) && (0 < I2S_HAVE_TX)
 	if (priv->tx.dog) {
-		wd_delete(priv->tx.dog);
+		wd_cancel(priv->tx.dog);
 		priv->tx.dog = NULL;
 	}
 #endif
+
+}
+
+static void amebasmart_i2s_resume(uint16_t port)
+{
+	struct amebasmart_i2s_config_s *hw_config_s;
+	struct amebasmart_i2s_s *priv;
+	int ret;
+	int count;
+	/* The I2S structure should exist after system wakeup */
+	priv = g_i2sdevice[port];
+	DEBUGASSERT(priv);
+	DEBUGASSERT(priv->i2s_object);
+	memset(priv->i2s_object, 0, sizeof(i2s_t));
+	/* Config values initialization */
+	hw_config_s = priv->config;
+	DEBUGASSERT(hw_config_s);
+
+	/* Get default configuration */
+	i2s_getdefaultconfig(priv);
+
+	/* I2s object initialization */
+	i2s_init(priv->i2s_object, hw_config_s->i2s_sclk_pin, hw_config_s->i2s_ws_pin, hw_config_s->i2s_sd_tx_pin, hw_config_s->i2s_sd_rx_pin, hw_config_s->i2s_mclk_pin);
+
+	/* Initialize buffering */
+#if defined(I2S_HAVE_TX) && (0 < I2S_HAVE_TX)
+	i2s_set_dma_buffer(priv->i2s_object, (char *)priv->i2s_tx_buf, NULL, I2S_DMA_PAGE_NUM, I2S_DMA_PAGE_SIZE); /* Allocate DMA Buffer for TX */
+#endif
+
+	ret = amebasmart_i2s_isr_initialize(priv);
+	DEBUGASSERT(ret == OK)
 }
 
 static uint32_t rtk_i2s_suspend(uint32_t expected_idle_time, void *param)
@@ -1954,10 +1972,10 @@ static uint32_t rtk_i2s_resume(uint32_t expected_idle_time, void *param)
 
 	/* For PG Sleep, I2S HW will be lost power, thus a reinitialization is required here */
 #ifdef CONFIG_AMEBASMART_I2S2
-	(void)amebasmart_i2s_initialize(I2S_NUM_2, I2S_REINIT);
+	amebasmart_i2s_resume(I2S_NUM_2);
 #endif
 #ifdef CONFIG_AMEBASMART_I2S3
-	(void)amebasmart_i2s_initialize(I2S_NUM_3, I2S_REINIT);
+	amebasmart_i2s_resume(I2S_NUM_3);
 #endif
 
 	return 1;
diff --git a/os/arch/arm/src/amebasmart/amebasmart_i2s.h b/os/arch/arm/src/amebasmart/amebasmart_i2s.h
index c4e556529d..6af1783596 100644
--- a/os/arch/arm/src/amebasmart/amebasmart_i2s.h
+++ b/os/arch/arm/src/amebasmart/amebasmart_i2s.h
@@ -50,12 +50,6 @@ extern "C" {
 * @brief I2S Peripheral, 0 & 1.
 *
 */
-
-#undef I2S_INIT
-#undef I2S_REINIT
-#define I2S_INIT   0
-#define I2S_REINIT 1
-
 typedef enum {
 	I2S_NUM_2 = 0x2,			/*!< I2S 2 */
 	I2S_NUM_3 = 0x3,			/*!< I2S 3 */
@@ -85,7 +79,7 @@ typedef enum {
  *
  ****************************************************************************/
 
-FAR struct i2s_dev_s *amebasmart_i2s_initialize(uint16_t port, bool is_reinit);
+FAR struct i2s_dev_s *amebasmart_i2s_initialize(uint16_t port);
 
 #undef EXTERN
 #if defined(__cplusplus)
diff --git a/os/board/rtl8730e/src/rtl8730e_alc1019.c b/os/board/rtl8730e/src/rtl8730e_alc1019.c
index 0e15de7ac9..846465edf8 100644
--- a/os/board/rtl8730e/src/rtl8730e_alc1019.c
+++ b/os/board/rtl8730e/src/rtl8730e_alc1019.c
@@ -37,7 +37,7 @@
 #include "PinNames.h"
 #include "gpio_api.h"
 
-extern FAR struct i2s_dev_s *amebasmart_i2s_initialize(uint16_t port, bool is_reinit);
+extern FAR struct i2s_dev_s *amebasmart_i2s_initialize(uint16_t port);
 
 /****************************************************************************
  * Pre-processor Definitions
@@ -166,7 +166,7 @@ int rtl8730e_alc1019_initialize(int minor)
 		auddbg("i2c init done\n");
 		auddbg("calling init i2s\n");
 		/* Get an instance of the I2S interface for the ALC1019 data channel */
-		i2s = amebasmart_i2s_initialize(ALC1019_I2S_PORT, I2S_INIT);
+		i2s = amebasmart_i2s_initialize(ALC1019_I2S_PORT);
 		if (!i2s) {
 			auddbg("ERROR: Failed to initialize I2S\n");
 			ret = -ENODEV;
diff --git a/os/board/rtl8730e/src/rtl8730e_i2schar.c b/os/board/rtl8730e/src/rtl8730e_i2schar.c
index c570d4ce46..d348bd7352 100644
--- a/os/board/rtl8730e/src/rtl8730e_i2schar.c
+++ b/os/board/rtl8730e/src/rtl8730e_i2schar.c
@@ -74,7 +74,7 @@ int i2schar_devinit(void)
 #if defined(CONFIG_AMEBASMART_I2S2) && !defined(CONFIG_AUDIO_ALC1019)
 		/* Call amebasmart_i2s_initialize() to get an instance of the I2S interface */
 		/* Initialise I2S2 */
-		i2s = amebasmart_i2s_initialize(I2S_NUM_2, I2S_INIT);
+		i2s = amebasmart_i2s_initialize(I2S_NUM_2);
 
 		if (!i2s) {
 			lldbg("ERROR: Failed to get the amebasmart I2S driver\n");
@@ -91,7 +91,7 @@ int i2schar_devinit(void)
 		I2S_ERR_CB_REG(i2s, err_cb, "Error_Test_String");
 #endif
 #ifdef CONFIG_AMEBASMART_I2S3
-		i2s = amebasmart_i2s_initialize(I2S_NUM_3, I2S_INIT);
+		i2s = amebasmart_i2s_initialize(I2S_NUM_3);
 
 		if (!i2s) {
 			lldbg("ERROR: Failed to get the amebasmart I2S driver\n");
diff --git a/os/board/rtl8730e/src/rtl8730e_syu645b.c b/os/board/rtl8730e/src/rtl8730e_syu645b.c
index 2ed25d8240..d7b7be5849 100644
--- a/os/board/rtl8730e/src/rtl8730e_syu645b.c
+++ b/os/board/rtl8730e/src/rtl8730e_syu645b.c
@@ -121,7 +121,7 @@ static void rtl8730e_syu645b_pm(bool sleep)
  * Public Functions
  ****************************************************************************/
 
-extern FAR struct i2s_dev_s *amebasmart_i2s_initialize(uint16_t port, bool is_reinit);
+extern FAR struct i2s_dev_s *amebasmart_i2s_initialize(uint16_t port);
 
 /****************************************************************************
  * Name: rtl8730e_syu645b_initialize
@@ -171,7 +171,7 @@ int rtl8730e_syu645b_initialize(int minor)
 		auddbg("i2c init done\n");
 		auddbg("calling init i2s\n");
 		/* Get an instance of the I2S interface for the SYU645B data channel */
-		i2s = amebasmart_i2s_initialize(SYU645B_I2S_PORT, I2S_INIT);
+		i2s = amebasmart_i2s_initialize(SYU645B_I2S_PORT);
 		if (!i2s) {
 			auddbg("ERROR: Failed to initialize I2S\n");
 			ret = -ENODEV;


Reviews:
user: login: zhongnuo-tang
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-21T04:01:02Z
user: login: zhongnuo-tang
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-21T05:17:44Z
user: login: ewoodev
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-21T05:36:25Z
user: login: ewoodev
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-21T05:44:30Z
user: login: zhongnuo-tang
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-21T06:09:39Z
user: login: ewoodev
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-21T06:18:53Z
user: login: zhongnuo-tang
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-21T07:07:40Z
user: login: sunghan-chang
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-04-22T09:43:37Z

Review comments:
diff_hunk: @@ -922,9 +928,9 @@ static int amebasmart_i2c_init(FAR struct amebasmart_i2c_priv_s *priv)
 {
 	/* Power-up and configure GPIOs */
 	DEBUGASSERT(priv);
-	DEBUGASSERT(!priv->i2c_object);
-	priv->i2c_object = (i2c_t *)kmm_malloc(sizeof(i2c_t));
 	DEBUGASSERT(priv->i2c_object);
+	priv->i2c_object->i2c_idx = 0;
path: os/arch/arm/src/amebasmart/amebasmart_i2c.c
user: login: zhongnuo-tang
body: i2c_idx = 0 is for I2C0, how about we use -1 first, and let i2c_init assign the index accordingly.
created_at: 2025-04-21T04:01:01Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1913,23 +1905,49 @@ static void amebasmart_i2s_suspend(uint16_t port)
 	struct amebasmart_i2s_s *priv = g_i2sdevice[port];
 
 	i2s_disable(priv->i2s_object, 1);
-	i2s_tx_enabled = 0;
path: os/arch/arm/src/amebasmart/amebasmart_i2s.c
user: login: zhongnuo-tang
body: i2s_tx_enabled = 0 is required, please revert this changes.
created_at: 2025-04-21T05:17:44Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1913,23 +1905,49 @@ static void amebasmart_i2s_suspend(uint16_t port)
 	struct amebasmart_i2s_s *priv = g_i2sdevice[port];
 
 	i2s_disable(priv->i2s_object, 1);
-	i2s_tx_enabled = 0;
path: os/arch/arm/src/amebasmart/amebasmart_i2s.c
user: login: ewoodev
body: https://github.com/Samsung/TizenRT/blob/e2165ed207bca38e40771c331f4d55c77927cbdc/os/arch/arm/src/amebasmart/amebasmart_i2s.c#L1546-L1551

The amebasmart_i2s_suspend must be called after i2s_stop.
Could you please let me know, is it required??
created_at: 2025-04-21T05:36:21Z
author_association: CONTRIBUTOR
diff_hunk: @@ -922,9 +928,9 @@ static int amebasmart_i2c_init(FAR struct amebasmart_i2c_priv_s *priv)
 {
 	/* Power-up and configure GPIOs */
 	DEBUGASSERT(priv);
-	DEBUGASSERT(!priv->i2c_object);
-	priv->i2c_object = (i2c_t *)kmm_malloc(sizeof(i2c_t));
 	DEBUGASSERT(priv->i2c_object);
+	priv->i2c_object->i2c_idx = 0;
path: os/arch/arm/src/amebasmart/amebasmart_i2c.c
user: login: ewoodev
body: the changes repaces `memset(priv->i2c_object, 0 , sizeof(i2c_t))`

I refer https://github.com/Samsung/TizenRT/commit/1dd1ae3fc68d84b15f5352c1044be12b23907fb0

Could you please suggest changes? or Could you please make change after this PR?
created_at: 2025-04-21T05:44:18Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1913,23 +1905,49 @@ static void amebasmart_i2s_suspend(uint16_t port)
 	struct amebasmart_i2s_s *priv = g_i2sdevice[port];
 
 	i2s_disable(priv->i2s_object, 1);
-	i2s_tx_enabled = 0;
path: os/arch/arm/src/amebasmart/amebasmart_i2s.c
user: login: zhongnuo-tang
body: amebasmart_i2s_suspend will be called before board entering PG, but what if I2S_RESUME is called, but I2S_SEND is not called, then it can enter PG even without calling i2s_stop to release the lock. Then in this case amebasmart_i2s_suspend will be called even without i2s_stop.. 
I agree that if the flow is right, this flag is not necessary. 
created_at: 2025-04-21T06:09:39Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1913,23 +1905,49 @@ static void amebasmart_i2s_suspend(uint16_t port)
 	struct amebasmart_i2s_s *priv = g_i2sdevice[port];
 
 	i2s_disable(priv->i2s_object, 1);
-	i2s_tx_enabled = 0;
path: os/arch/arm/src/amebasmart/amebasmart_i2s.c
user: login: ewoodev
body: is it allow i2s_resume without i2s_send?
created_at: 2025-04-21T06:18:47Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1913,23 +1905,49 @@ static void amebasmart_i2s_suspend(uint16_t port)
 	struct amebasmart_i2s_s *priv = g_i2sdevice[port];
 
 	i2s_disable(priv->i2s_object, 1);
-	i2s_tx_enabled = 0;
path: os/arch/arm/src/amebasmart/amebasmart_i2s.c
user: login: zhongnuo-tang
body: Porting layer (amebasmart_i2s.c) cannot ensure i2s_send will be called when i2s_resume is called. So I was worried that there might be cases where driver layer didn't call I2S_SEND after I2S_RESUME, and it will cause issue.
created_at: 2025-04-21T07:07:40Z
author_association: CONTRIBUTOR

PR comments:
user: login: sunghan-chang
created_at: 2025-04-18T14:18:19Z
body: @lhenry-realtek @zhongnuo-tang @ziyik Please review this with priority. We must merge this by next Monday noon.
author_association: CONTRIBUTOR
user: login: sunghan-chang
created_at: 2025-04-18T14:20:53Z
body: @lhenry-realtek @zhongnuo-tang @ziyik We want to call amebasmart_i2c_init / deinit instead of i2cinitialize/i2cuninitialize in pm sleep and wakeup. And move memory allocation /free and sem init / destroy from i2c_init/deinint to i2cinitialize/i2cuninitialize.
author_association: CONTRIBUTOR
user: login: lhenry-realtek
created_at: 2025-04-21T02:04:17Z
body: We are looking into it
author_association: CONTRIBUTOR
user: login: zhongnuo-tang
created_at: 2025-04-21T05:27:10Z
body: Hi @ewoodev ,
I have ran a simple long-run test with this PR
CA32PG-KM4PG-WAKEUP-> soundplayer example with a very short mp3->PG...
after around 1 hour of testing, I encountered allocation fail from user heap. Attached the logs below for your reference.

CA32PG-KM4PG-Wakeup : UART LOG

TASH>>soundplayer /mnt/ToggleOnNormal.mp3 1 48000 1
TASH>>cur SoundPlayer : 6016fd58
Show Track List!! mNumContents : 1 mPlayIndex : 0
path : /mnt/ToggleOnNormal.mp3
create: create player: 6038c030
startWorker: PlayerWorker::startWorker() - increase RefCnt : 1
create: createPlayer enqueued. player: 6038c030
create: create returned. player: 6038c030
setObserver: setObserver player: 6038c030
startWorker: PlayerObserverWorker::startWorker() - increase RefCnt : 1
setObserver: setPlayerObserver enqueued. player: 6038c030
setObserver: setObserver returned. player: 6038c030
setStreamInfo: setStreamInfo player: 6038c030
setStreamInfo: setPlayerStreamInfo enqueued. player: 6038c030
setStreamInfo: setStreamInfo returned. player: 6038c030
mp : 6038c030 request focus!!
onFousChange player : 6038c030 focus : 1 isPlaying : 0 mPaused : 0
startPlayback... playIndex : 0 path : /mnt/ToggleOnNormal.mp3
setDataSource: setDataSource player: 6038c030
setDataSource: setPlayerDataSource enqueued. player: 6038c030
setDataSource: smm_manage_alloc_fail: Allocation failed from user heap.
mm_manage_alloc_fail:  - requested size 319296
mm_manage_alloc_fail:  - caller address = 0x0e0b9271
mm_manage_alloc_fail:  - largest free size : 317264
mm_manage_alloc_fail:  - total free size   : 505248
mm_check_heap_corruption: Heap start = 0x60123ce0 end = 0x607fbff0
mm_check_heap_corruption: No heap corruption detected
****************************************************************
REGION #0 Start=0x0x60123ce0, End=0x0x607fbff0, Size=7176992
****************************************************************

author_association: CONTRIBUTOR
user: login: ewoodev
created_at: 2025-04-21T05:46:17Z
body: > Hi @ewoodev , I have ran a simple long-run test with this PR CA32PG-KM4PG-WAKEUP-> soundplayer example with a very short mp3->PG... after around 1 hour of testing, I encountered allocation fail from user heap. Attached the logs below for your reference.
> 
> CA32PG-KM4PG-Wakeup : UART LOG
> 
> TASH>>soundplayer /mnt/ToggleOnNormal.mp3 1 48000 1 TASH>>cur SoundPlayer : 6016fd58 Show Track List!! mNumContents : 1 mPlayIndex : 0 path : /mnt/ToggleOnNormal.mp3 create: create player: 6038c030 startWorker: PlayerWorker::startWorker() - increase RefCnt : 1 create: createPlayer enqueued. player: 6038c030 create: create returned. player: 6038c030 setObserver: setObserver player: 6038c030 startWorker: PlayerObserverWorker::startWorker() - increase RefCnt : 1 setObserver: setPlayerObserver enqueued. player: 6038c030 setObserver: setObserver returned. player: 6038c030 setStreamInfo: setStreamInfo player: 6038c030 setStreamInfo: setPlayerStreamInfo enqueued. player: 6038c030 setStreamInfo: setStreamInfo returned. player: 6038c030 mp : 6038c030 request focus!! onFousChange player : 6038c030 focus : 1 isPlaying : 0 mPaused : 0 startPlayback... playIndex : 0 path : /mnt/ToggleOnNormal.mp3 setDataSource: setDataSource player: 6038c030 setDataSource: setPlayerDataSource enqueued. player: 6038c030 setDataSource: smm_manage_alloc_fail: Allocation failed from user heap. mm_manage_alloc_fail: - requested size 319296 mm_manage_alloc_fail: - caller address = 0x0e0b9271 mm_manage_alloc_fail: - largest free size : 317264 mm_manage_alloc_fail: - total free size : 505248 mm_check_heap_corruption: Heap start = 0x60123ce0 end = 0x607fbff0 mm_check_heap_corruption: No heap corruption detected
> 
> REGION #0 Start=0x0x60123ce0, End=0x0x607fbff0, Size=7176992

Could you please report memleak result?
you can find memory leak using `TASH>>mem_leak` during your test
author_association: CONTRIBUTOR
user: login: zhongnuo-tang
created_at: 2025-04-21T06:11:48Z
body: > > Hi @ewoodev , I have ran a simple long-run test with this PR CA32PG-KM4PG-WAKEUP-> soundplayer example with a very short mp3->PG... after around 1 hour of testing, I encountered allocation fail from user heap. Attached the logs below for your reference.
> > CA32PG-KM4PG-Wakeup : UART LOG
> > TASH>>soundplayer /mnt/ToggleOnNormal.mp3 1 48000 1 TASH>>cur SoundPlayer : 6016fd58 Show Track List!! mNumContents : 1 mPlayIndex : 0 path : /mnt/ToggleOnNormal.mp3 create: create player: 6038c030 startWorker: PlayerWorker::startWorker() - increase RefCnt : 1 create: createPlayer enqueued. player: 6038c030 create: create returned. player: 6038c030 setObserver: setObserver player: 6038c030 startWorker: PlayerObserverWorker::startWorker() - increase RefCnt : 1 setObserver: setPlayerObserver enqueued. player: 6038c030 setObserver: setObserver returned. player: 6038c030 setStreamInfo: setStreamInfo player: 6038c030 setStreamInfo: setPlayerStreamInfo enqueued. player: 6038c030 setStreamInfo: setStreamInfo returned. player: 6038c030 mp : 6038c030 request focus!! onFousChange player : 6038c030 focus : 1 isPlaying : 0 mPaused : 0 startPlayback... playIndex : 0 path : /mnt/ToggleOnNormal.mp3 setDataSource: setDataSource player: 6038c030 setDataSource: setPlayerDataSource enqueued. player: 6038c030 setDataSource: smm_manage_alloc_fail: Allocation failed from user heap. mm_manage_alloc_fail: - requested size 319296 mm_manage_alloc_fail: - caller address = 0x0e0b9271 mm_manage_alloc_fail: - largest free size : 317264 mm_manage_alloc_fail: - total free size : 505248 mm_check_heap_corruption: Heap start = 0x60123ce0 end = 0x607fbff0 mm_check_heap_corruption: No heap corruption detected
> > REGION #0 Start=0x0x60123ce0, End=0x0x607fbff0, Size=7176992
> 
> Could you please report memleak result? you can find memory leak using `TASH>>mem_leak` during your test

I will reproduce again and capture the memleak result. 
author_association: CONTRIBUTOR
user: login: zhongnuo-tang
created_at: 2025-04-21T07:06:09Z
body: > > Hi @ewoodev , I have ran a simple long-run test with this PR CA32PG-KM4PG-WAKEUP-> soundplayer example with a very short mp3->PG... after around 1 hour of testing, I encountered allocation fail from user heap. Attached the logs below for your reference.
> > CA32PG-KM4PG-Wakeup : UART LOG
> > TASH>>soundplayer /mnt/ToggleOnNormal.mp3 1 48000 1 TASH>>cur SoundPlayer : 6016fd58 Show Track List!! mNumContents : 1 mPlayIndex : 0 path : /mnt/ToggleOnNormal.mp3 create: create player: 6038c030 startWorker: PlayerWorker::startWorker() - increase RefCnt : 1 create: createPlayer enqueued. player: 6038c030 create: create returned. player: 6038c030 setObserver: setObserver player: 6038c030 startWorker: PlayerObserverWorker::startWorker() - increase RefCnt : 1 setObserver: setPlayerObserver enqueued. player: 6038c030 setObserver: setObserver returned. player: 6038c030 setStreamInfo: setStreamInfo player: 6038c030 setStreamInfo: setPlayerStreamInfo enqueued. player: 6038c030 setStreamInfo: setStreamInfo returned. player: 6038c030 mp : 6038c030 request focus!! onFousChange player : 6038c030 focus : 1 isPlaying : 0 mPaused : 0 startPlayback... playIndex : 0 path : /mnt/ToggleOnNormal.mp3 setDataSource: setDataSource player: 6038c030 setDataSource: setPlayerDataSource enqueued. player: 6038c030 setDataSource: smm_manage_alloc_fail: Allocation failed from user heap. mm_manage_alloc_fail: - requested size 319296 mm_manage_alloc_fail: - caller address = 0x0e0b9271 mm_manage_alloc_fail: - largest free size : 317264 mm_manage_alloc_fail: - total free size : 505248 mm_check_heap_corruption: Heap start = 0x60123ce0 end = 0x607fbff0 mm_check_heap_corruption: No heap corruption detected
> > REGION #0 Start=0x0x60123ce0, End=0x0x607fbff0, Size=7176992
> 
> Could you please report memleak result? you can find memory leak using `TASH>>mem_leak` during your test

Hi @ewoodev ,
The result is attached below, i think this allocation fail issue is unrelated to this PR.

mem_leak



Kernel :

Type   |    Addr    | Size(byte) |    Owner   | PID 

---------------------------------------------------

LEAK   | 0x6014dad0 |      5280  |  0xe05676d | 3

/opt/rtk-toolchain/asdk-10.2.0/linux/newlib/bin/arm-none-eabi-addr2line -e build/output/bin/tinyara.axf -a "0xe05676d"
0x0e05676d
/root/tizenrt/os/drivers/ai-soc/ndp120/src/syntiant_ndp.c:309
author_association: CONTRIBUTOR