@@ -65,11 +65,16 @@ struct mspi_dw_data {
6565 bool standard_spi ;
6666 bool suspended ;
6767
68+ #if defined(CONFIG_MULTITHREADING )
6869 struct k_sem finished ;
6970 /* For synchronization of API calls made from different contexts. */
7071 struct k_sem ctx_lock ;
7172 /* For locking of controller configuration. */
7273 struct k_sem cfg_lock ;
74+ #else
75+ volatile bool finished ;
76+ bool cfg_lock ;
77+ #endif
7378 struct mspi_xfer xfer ;
7479
7580#if defined(CONFIG_MSPI_DW_HANDLE_FIFOS_IN_SYSTEM_WORKQUEUE )
@@ -364,7 +369,11 @@ static void handle_fifos(const struct device *dev)
364369 if (finished ) {
365370 set_imr (dev , 0 );
366371
372+ #if defined(CONFIG_MULTITHREADING )
367373 k_sem_give (& dev_data -> finished );
374+ #else
375+ dev_data -> finished = true;
376+ #endif
368377 }
369378}
370379
@@ -816,8 +825,17 @@ static int api_dev_config(const struct device *dev,
816825 int rc ;
817826
818827 if (dev_id != dev_data -> dev_id ) {
828+ #if defined(CONFIG_MULTITHREADING )
819829 rc = k_sem_take (& dev_data -> cfg_lock ,
820830 K_MSEC (CONFIG_MSPI_COMPLETION_TIMEOUT_TOLERANCE ));
831+ #else
832+ if (dev_data -> cfg_lock ) {
833+ rc = -1 ;
834+ } else {
835+ dev_data -> cfg_lock = true;
836+ rc = 0 ;
837+ }
838+ #endif
821839 if (rc < 0 ) {
822840 LOG_ERR ("Failed to switch controller to device" );
823841 return - EBUSY ;
@@ -831,15 +849,23 @@ static int api_dev_config(const struct device *dev,
831849 return 0 ;
832850 }
833851
852+ #if defined(CONFIG_MULTITHREADING )
834853 (void )k_sem_take (& dev_data -> ctx_lock , K_FOREVER );
854+ #endif
835855
836856 rc = _api_dev_config (dev , param_mask , cfg );
837857
858+ #if defined(CONFIG_MULTITHREADING )
838859 k_sem_give (& dev_data -> ctx_lock );
860+ #endif
839861
840862 if (rc < 0 ) {
841863 dev_data -> dev_id = NULL ;
864+ #if defined(CONFIG_MULTITHREADING )
842865 k_sem_give (& dev_data -> cfg_lock );
866+ #else
867+ dev_data -> cfg_lock = false;
868+ #endif
843869 }
844870
845871 return rc ;
@@ -851,12 +877,17 @@ static int api_get_channel_status(const struct device *dev, uint8_t ch)
851877
852878 struct mspi_dw_data * dev_data = dev -> data ;
853879
880+ #if defined(CONFIG_MULTITHREADING )
854881 (void )k_sem_take (& dev_data -> ctx_lock , K_FOREVER );
882+ #endif
855883
856884 dev_data -> dev_id = NULL ;
885+ #if defined(CONFIG_MULTITHREADING )
857886 k_sem_give (& dev_data -> cfg_lock );
858-
859887 k_sem_give (& dev_data -> ctx_lock );
888+ #else
889+ dev_data -> cfg_lock = false;
890+ #endif
860891
861892 return 0 ;
862893}
@@ -1119,7 +1150,17 @@ static int start_next_packet(const struct device *dev, k_timeout_t timeout)
11191150 /* Write SER to start transfer */
11201151 write_ser (dev , BIT (dev_data -> dev_id -> dev_idx ));
11211152
1153+ #if defined(CONFIG_MULTITHREADING )
11221154 rc = k_sem_take (& dev_data -> finished , timeout );
1155+ #else
1156+ if (!WAIT_FOR (dev_data -> finished ,
1157+ dev_data -> xfer .timeout * USEC_PER_MSEC ,
1158+ NULL )) {
1159+ rc = - ETIMEDOUT ;
1160+ }
1161+
1162+ dev_data -> finished = false;
1163+ #endif
11231164 if (read_risr (dev ) & RISR_RXOIR_BIT ) {
11241165 LOG_ERR ("RX FIFO overflow occurred" );
11251166 rc = - EIO ;
@@ -1232,15 +1273,19 @@ static int api_transceive(const struct device *dev,
12321273 return rc ;
12331274 }
12341275
1276+ #if defined(CONFIG_MULTITHREADING )
12351277 (void )k_sem_take (& dev_data -> ctx_lock , K_FOREVER );
1278+ #endif
12361279
12371280 if (dev_data -> suspended ) {
12381281 rc = - EFAULT ;
12391282 } else {
12401283 rc = _api_transceive (dev , req );
12411284 }
12421285
1286+ #if defined(CONFIG_MULTITHREADING )
12431287 k_sem_give (& dev_data -> ctx_lock );
1288+ #endif
12441289
12451290 rc2 = pm_device_runtime_put (dev );
12461291 if (rc2 < 0 ) {
@@ -1391,15 +1436,19 @@ static int api_xip_config(const struct device *dev,
13911436 return rc ;
13921437 }
13931438
1439+ #if defined(CONFIG_MULTITHREADING )
13941440 (void )k_sem_take (& dev_data -> ctx_lock , K_FOREVER );
1441+ #endif
13951442
13961443 if (dev_data -> suspended ) {
13971444 rc = - EFAULT ;
13981445 } else {
13991446 rc = _api_xip_config (dev , dev_id , cfg );
14001447 }
14011448
1449+ #if defined(CONFIG_MULTITHREADING )
14021450 k_sem_give (& dev_data -> ctx_lock );
1451+ #endif
14031452
14041453 rc2 = pm_device_runtime_put (dev );
14051454 if (rc2 < 0 ) {
@@ -1450,8 +1499,12 @@ static int dev_pm_action_cb(const struct device *dev,
14501499 return rc ;
14511500 }
14521501#endif
1502+ #if defined(CONFIG_MULTITHREADING )
14531503 if (xip_enabled ||
14541504 k_sem_take (& dev_data -> ctx_lock , K_NO_WAIT ) != 0 ) {
1505+ #else
1506+ if (xip_enabled ) {
1507+ #endif
14551508 LOG_ERR ("Controller in use, cannot be suspended" );
14561509 return - EBUSY ;
14571510 }
@@ -1460,7 +1513,9 @@ static int dev_pm_action_cb(const struct device *dev,
14601513
14611514 vendor_specific_suspend (dev );
14621515
1516+ #if defined(CONFIG_MULTITHREADING )
14631517 k_sem_give (& dev_data -> ctx_lock );
1518+ #endif
14641519
14651520 return 0 ;
14661521 }
@@ -1470,7 +1525,6 @@ static int dev_pm_action_cb(const struct device *dev,
14701525
14711526static int dev_init (const struct device * dev )
14721527{
1473- struct mspi_dw_data * dev_data = dev -> data ;
14741528 const struct mspi_dw_config * dev_config = dev -> config ;
14751529 const struct gpio_dt_spec * ce_gpio ;
14761530 int rc ;
@@ -1481,9 +1535,13 @@ static int dev_init(const struct device *dev)
14811535
14821536 dev_config -> irq_config ();
14831537
1538+ #if defined(CONFIG_MULTITHREADING )
1539+ struct mspi_dw_data * dev_data = dev -> data ;
1540+
14841541 k_sem_init (& dev_data -> finished , 0 , 1 );
14851542 k_sem_init (& dev_data -> cfg_lock , 1 , 1 );
14861543 k_sem_init (& dev_data -> ctx_lock , 1 , 1 );
1544+ #endif
14871545
14881546#if defined(CONFIG_MSPI_DW_HANDLE_FIFOS_IN_SYSTEM_WORKQUEUE )
14891547 dev_data -> dev = dev ;
0 commit comments