@@ -559,14 +559,18 @@ static int exec_cmd(const struct shell *sh, size_t argc, const char **argv,
559
559
#endif
560
560
561
561
z_flag_cmd_ctx_set (sh , true);
562
+ #if CONFIG_MULTITHREADING
562
563
/* Unlock thread mutex in case command would like to borrow
563
564
* shell context to other thread to avoid mutex deadlock.
564
565
*/
565
566
k_mutex_unlock (& sh -> ctx -> wr_mtx );
567
+ #endif
566
568
ret_val = sh -> ctx -> active_cmd .handler (sh , argc ,
567
569
(char * * )argv );
570
+ #if CONFIG_MULTITHREADING
568
571
/* Bring back mutex to shell thread. */
569
572
k_mutex_lock (& sh -> ctx -> wr_mtx , K_FOREVER );
573
+ #endif
570
574
z_flag_cmd_ctx_set (sh , false);
571
575
}
572
576
@@ -1171,13 +1175,21 @@ static void state_collect(const struct shell *sh)
1171
1175
static void transport_evt_handler (enum shell_transport_evt evt_type , void * ctx )
1172
1176
{
1173
1177
struct shell * sh = (struct shell * )ctx ;
1178
+
1179
+ #if CONFIG_MULTITHREADING
1174
1180
enum shell_signal sig = evt_type == SHELL_TRANSPORT_EVT_RX_RDY
1175
1181
? SHELL_SIGNAL_RXRDY
1176
1182
: SHELL_SIGNAL_TXDONE ;
1177
1183
1178
1184
k_event_post (& sh -> ctx -> signal_event , sig );
1185
+ #endif
1186
+
1187
+ if (evt_type == SHELL_TRANSPORT_EVT_TX_RDY ) {
1188
+ z_flag_tx_rdy_set (sh , true);
1189
+ }
1179
1190
}
1180
1191
1192
+ #if CONFIG_MULTITHREADING
1181
1193
static void shell_log_process (const struct shell * sh )
1182
1194
{
1183
1195
bool processed = false;
@@ -1201,6 +1213,7 @@ static void shell_log_process(const struct shell *sh)
1201
1213
1202
1214
} while (processed && !k_event_test (& sh -> ctx -> signal_event , SHELL_SIGNAL_RXRDY ));
1203
1215
}
1216
+ #endif
1204
1217
1205
1218
static int instance_init (const struct shell * sh ,
1206
1219
const void * transport_config ,
@@ -1216,15 +1229,15 @@ static int instance_init(const struct shell *sh,
1216
1229
1217
1230
history_init (sh );
1218
1231
1232
+ #if CONFIG_MULTITHREADING
1219
1233
k_event_init (& sh -> ctx -> signal_event );
1220
1234
k_mutex_init (& sh -> ctx -> wr_mtx );
1235
+ #endif
1221
1236
1222
1237
if (IS_ENABLED (CONFIG_SHELL_STATS )) {
1223
1238
sh -> stats -> log_lost_cnt = 0 ;
1224
1239
}
1225
1240
1226
- z_flag_tx_rdy_set (sh , true);
1227
-
1228
1241
sh -> ctx -> vt100_ctx .cons .terminal_wid =
1229
1242
CONFIG_SHELL_DEFAULT_TERMINAL_WIDTH ;
1230
1243
sh -> ctx -> vt100_ctx .cons .terminal_hei =
@@ -1284,6 +1297,7 @@ static int instance_uninit(const struct shell *sh)
1284
1297
return 0 ;
1285
1298
}
1286
1299
1300
+ #if CONFIG_MULTITHREADING
1287
1301
typedef void (* shell_signal_handler_t )(const struct shell * sh );
1288
1302
1289
1303
static void shell_signal_handle (const struct shell * sh ,
@@ -1297,7 +1311,9 @@ static void shell_signal_handle(const struct shell *sh,
1297
1311
handler (sh );
1298
1312
k_event_clear (& sh -> ctx -> signal_event , sig );
1299
1313
}
1314
+ #endif
1300
1315
1316
+ #if CONFIG_MULTITHREADING
1301
1317
static void kill_handler (const struct shell * sh )
1302
1318
{
1303
1319
int err = instance_uninit (sh );
@@ -1311,7 +1327,9 @@ static void kill_handler(const struct shell *sh)
1311
1327
1312
1328
CODE_UNREACHABLE ;
1313
1329
}
1330
+ #endif
1314
1331
1332
+ #if CONFIG_MULTITHREADING
1315
1333
void shell_thread (void * shell_handle , void * arg_log_backend ,
1316
1334
void * arg_log_level )
1317
1335
{
@@ -1358,6 +1376,7 @@ void shell_thread(void *shell_handle, void *arg_log_backend,
1358
1376
k_mutex_unlock (& sh -> ctx -> wr_mtx );
1359
1377
}
1360
1378
}
1379
+ #endif
1361
1380
1362
1381
int shell_init (const struct shell * sh , const void * transport_config ,
1363
1382
struct shell_backend_config_flags cfg_flags ,
@@ -1366,16 +1385,19 @@ int shell_init(const struct shell *sh, const void *transport_config,
1366
1385
__ASSERT_NO_MSG (sh );
1367
1386
__ASSERT_NO_MSG (sh -> ctx && sh -> iface && sh -> default_prompt );
1368
1387
1388
+ #if CONFIG_MULTITHREADING
1369
1389
if (sh -> ctx -> tid ) {
1370
1390
return - EALREADY ;
1371
1391
}
1392
+ #endif
1372
1393
1373
1394
int err = instance_init (sh , transport_config , cfg_flags );
1374
1395
1375
1396
if (err != 0 ) {
1376
1397
return err ;
1377
1398
}
1378
1399
1400
+ #if CONFIG_MULTITHREADING
1379
1401
k_tid_t tid = k_thread_create (sh -> thread ,
1380
1402
sh -> stack , CONFIG_SHELL_STACK_SIZE ,
1381
1403
shell_thread , (void * )sh , (void * )log_backend ,
@@ -1384,6 +1406,7 @@ int shell_init(const struct shell *sh, const void *transport_config,
1384
1406
1385
1407
sh -> ctx -> tid = tid ;
1386
1408
k_thread_name_set (tid , sh -> name );
1409
+ #endif
1387
1410
1388
1411
return 0 ;
1389
1412
}
@@ -1392,18 +1415,17 @@ void shell_uninit(const struct shell *sh, shell_uninit_cb_t cb)
1392
1415
{
1393
1416
__ASSERT_NO_MSG (sh );
1394
1417
1395
- if (IS_ENABLED (CONFIG_MULTITHREADING )) {
1396
- k_event_post (& sh -> ctx -> signal_event , SHELL_SIGNAL_KILL );
1397
- return ;
1398
- }
1399
-
1418
+ #if CONFIG_MULTITHREADING
1419
+ k_event_post (& sh -> ctx -> signal_event , SHELL_SIGNAL_KILL );
1420
+ #else
1400
1421
int err = instance_uninit (sh );
1401
1422
1402
1423
if (cb ) {
1403
1424
cb (sh , err );
1404
1425
} else {
1405
1426
__ASSERT_NO_MSG (0 );
1406
1427
}
1428
+ #endif
1407
1429
}
1408
1430
1409
1431
int shell_start (const struct shell * sh )
@@ -1420,9 +1442,11 @@ int shell_start(const struct shell *sh)
1420
1442
z_shell_log_backend_enable (sh -> log_backend , (void * )sh , sh -> ctx -> log_level );
1421
1443
}
1422
1444
1445
+ #if CONFIG_MULTITHREADING
1423
1446
if (k_mutex_lock (& sh -> ctx -> wr_mtx , SHELL_TX_MTX_TIMEOUT ) != 0 ) {
1424
1447
return - EBUSY ;
1425
1448
}
1449
+ #endif
1426
1450
1427
1451
if (IS_ENABLED (CONFIG_SHELL_VT100_COLORS )) {
1428
1452
z_shell_vt100_color_set (sh , SHELL_NORMAL );
@@ -1442,7 +1466,9 @@ int shell_start(const struct shell *sh)
1442
1466
*/
1443
1467
z_shell_backend_rx_buffer_flush (sh );
1444
1468
1469
+ #if CONFIG_MULTITHREADING
1445
1470
k_mutex_unlock (& sh -> ctx -> wr_mtx );
1471
+ #endif
1446
1472
1447
1473
return 0 ;
1448
1474
}
@@ -1524,9 +1550,11 @@ void shell_vfprintf(const struct shell *sh, enum shell_vt100_color color,
1524
1550
return ;
1525
1551
}
1526
1552
1553
+ #if CONFIG_MULTITHREADING
1527
1554
if (k_mutex_lock (& sh -> ctx -> wr_mtx , SHELL_TX_MTX_TIMEOUT ) != 0 ) {
1528
1555
return ;
1529
1556
}
1557
+ #endif
1530
1558
1531
1559
if (!z_flag_cmd_ctx_get (sh ) && !sh -> ctx -> bypass && z_flag_use_vt100_get (sh )) {
1532
1560
z_shell_cmd_line_erase (sh );
@@ -1537,7 +1565,9 @@ void shell_vfprintf(const struct shell *sh, enum shell_vt100_color color,
1537
1565
}
1538
1566
z_transport_buffer_flush (sh );
1539
1567
1568
+ #if CONFIG_MULTITHREADING
1540
1569
k_mutex_unlock (& sh -> ctx -> wr_mtx );
1570
+ #endif
1541
1571
}
1542
1572
1543
1573
/* These functions mustn't be used from shell context to avoid deadlock:
@@ -1664,20 +1694,26 @@ int shell_prompt_change(const struct shell *sh, const char *prompt)
1664
1694
1665
1695
size_t prompt_length = z_shell_strlen (prompt );
1666
1696
1697
+ #if CONFIG_MULTITHREADING
1667
1698
if (k_mutex_lock (& sh -> ctx -> wr_mtx , SHELL_TX_MTX_TIMEOUT ) != 0 ) {
1668
1699
return - EBUSY ;
1669
1700
}
1701
+ #endif
1670
1702
1671
1703
if ((prompt_length + 1 > CONFIG_SHELL_PROMPT_BUFF_SIZE ) || (prompt_length == 0 )) {
1704
+ #if CONFIG_MULTITHREADING
1672
1705
k_mutex_unlock (& sh -> ctx -> wr_mtx );
1706
+ #endif
1673
1707
return - EINVAL ;
1674
1708
}
1675
1709
1676
1710
strcpy (sh -> ctx -> prompt , prompt );
1677
1711
1678
1712
sh -> ctx -> vt100_ctx .cons .name_len = prompt_length ;
1679
1713
1714
+ #if CONFIG_MULTITHREADING
1680
1715
k_mutex_unlock (& sh -> ctx -> wr_mtx );
1716
+ #endif
1681
1717
1682
1718
return 0 ;
1683
1719
#else
@@ -1687,11 +1723,15 @@ int shell_prompt_change(const struct shell *sh, const char *prompt)
1687
1723
1688
1724
void shell_help (const struct shell * sh )
1689
1725
{
1726
+ #if CONFIG_MULTITHREADING
1690
1727
if (k_mutex_lock (& sh -> ctx -> wr_mtx , SHELL_TX_MTX_TIMEOUT ) != 0 ) {
1691
1728
return ;
1692
1729
}
1730
+ #endif
1693
1731
shell_internal_help_print (sh );
1732
+ #if CONFIG_MULTITHREADING
1694
1733
k_mutex_unlock (& sh -> ctx -> wr_mtx );
1734
+ #endif
1695
1735
}
1696
1736
1697
1737
int shell_execute_cmd (const struct shell * sh , const char * cmd )
@@ -1722,12 +1762,15 @@ int shell_execute_cmd(const struct shell *sh, const char *cmd)
1722
1762
sh -> ctx -> cmd_buff_len = cmd_len ;
1723
1763
sh -> ctx -> cmd_buff_pos = cmd_len ;
1724
1764
1765
+ #if CONFIG_MULTITHREADING
1725
1766
if (k_mutex_lock (& sh -> ctx -> wr_mtx , SHELL_TX_MTX_TIMEOUT ) != 0 ) {
1726
1767
return - ENOEXEC ;
1727
1768
}
1769
+ #endif
1728
1770
ret_val = execute (sh );
1771
+ #if CONFIG_MULTITHREADING
1729
1772
k_mutex_unlock (& sh -> ctx -> wr_mtx );
1730
-
1773
+ #endif
1731
1774
cmd_buffer_clear (sh );
1732
1775
1733
1776
return ret_val ;
0 commit comments