Skip to content

Commit c96b8cd

Browse files
hujun260xiaoxiang781216
authored andcommitted
use small lock in following files:
arch/arm/src/stm32f0l0g0/stm32_serial_v2.c arch/arm/src/stm32f7/stm32_qencoder.c arch/arm/src/stm32f7/stm32_serial.c arch/arm/src/stm32h5/stm32_serial.c arch/arm/src/stm32h7/stm32_qencoder.c arch/arm/src/stm32h7/stm32_serial.c arch/arm/src/stm32l4/stm32l4_qencoder.c arch/arm/src/stm32l4/stm32l4_serial.c arch/arm/src/stm32l5/stm32l5_serial.c arch/arm/src/stm32u5/stm32_serial.c arch/arm/src/stm32wb/stm32wb_serial.c arch/arm/src/stm32wl5/stm32wl5_serial.c arch/arm/src/tiva/cc13xx/cc13xx_enablepwr.c arch/risc-v/src/rv32m1/rv32m1_serial.c Signed-off-by: hujun5 <[email protected]>
1 parent 798695a commit c96b8cd

File tree

14 files changed

+140
-48
lines changed

14 files changed

+140
-48
lines changed

arch/arm/src/stm32f0l0g0/stm32_serial_v2.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ struct up_dev_s
158158
const uint32_t rs485_dir_gpio; /* U[S]ART RS-485 DIR GPIO pin configuration */
159159
const bool rs485_dir_polarity; /* U[S]ART RS-485 DIR pin state for TX enabled */
160160
#endif
161+
spinlock_t lock;
161162
};
162163

163164
/****************************************************************************
@@ -285,6 +286,7 @@ static struct up_dev_s g_usart1priv =
285286
.rs485_dir_polarity = true,
286287
# endif
287288
#endif
289+
.lock = SP_UNLOCKED,
288290
};
289291
#endif
290292

@@ -339,6 +341,7 @@ static struct up_dev_s g_usart2priv =
339341
.rs485_dir_polarity = true,
340342
# endif
341343
#endif
344+
.lock = SP_UNLOCKED,
342345
};
343346
#endif
344347

@@ -393,6 +396,7 @@ static struct up_dev_s g_usart3priv =
393396
.rs485_dir_polarity = true,
394397
# endif
395398
#endif
399+
.lock = SP_UNLOCKED,
396400
};
397401
#endif
398402

@@ -447,6 +451,7 @@ static struct up_dev_s g_usart4priv =
447451
.rs485_dir_polarity = true,
448452
# endif
449453
#endif
454+
.lock = SP_UNLOCKED,
450455
};
451456
#endif
452457

@@ -534,11 +539,11 @@ static void up_restoreusartint(struct up_dev_s *priv, uint16_t ie)
534539
{
535540
irqstate_t flags;
536541

537-
flags = spin_lock_irqsave(NULL);
542+
flags = spin_lock_irqsave(&priv->lock);
538543

539544
up_setusartint(priv, ie);
540545

541-
spin_unlock_irqrestore(NULL, flags);
546+
spin_unlock_irqrestore(&priv->lock, flags);
542547
}
543548

544549
/****************************************************************************
@@ -549,7 +554,7 @@ static void up_disableusartint(struct up_dev_s *priv, uint16_t *ie)
549554
{
550555
irqstate_t flags;
551556

552-
flags = spin_lock_irqsave(NULL);
557+
flags = spin_lock_irqsave(&priv->lock);
553558

554559
if (ie)
555560
{
@@ -593,7 +598,7 @@ static void up_disableusartint(struct up_dev_s *priv, uint16_t *ie)
593598

594599
up_setusartint(priv, 0);
595600

596-
spin_unlock_irqrestore(NULL, flags);
601+
spin_unlock_irqrestore(&priv->lock, flags);
597602
}
598603

599604
/****************************************************************************

arch/arm/src/stm32f7/stm32_qencoder.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ struct stm32_lowerhalf_s
214214
#ifdef HAVE_16BIT_TIMERS
215215
volatile int32_t position; /* The current position offset */
216216
#endif
217+
spinlock_t lock;
217218
};
218219

219220
/****************************************************************************
@@ -296,6 +297,7 @@ static struct stm32_lowerhalf_s g_tim1lower =
296297
.ops = &g_qecallbacks,
297298
.config = &g_tim1config,
298299
.inuse = false,
300+
.lock = SP_UNLOCKED,
299301
};
300302

301303
#endif
@@ -321,6 +323,7 @@ static struct stm32_lowerhalf_s g_tim2lower =
321323
.ops = &g_qecallbacks,
322324
.config = &g_tim2config,
323325
.inuse = false,
326+
.lock = SP_UNLOCKED,
324327
};
325328

326329
#endif
@@ -346,6 +349,7 @@ static struct stm32_lowerhalf_s g_tim3lower =
346349
.ops = &g_qecallbacks,
347350
.config = &g_tim3config,
348351
.inuse = false,
352+
.lock = SP_UNLOCKED,
349353
};
350354

351355
#endif
@@ -371,6 +375,7 @@ static struct stm32_lowerhalf_s g_tim4lower =
371375
.ops = &g_qecallbacks,
372376
.config = &g_tim4config,
373377
.inuse = false,
378+
.lock = SP_UNLOCKED,
374379
};
375380

376381
#endif
@@ -396,6 +401,7 @@ static struct stm32_lowerhalf_s g_tim5lower =
396401
.ops = &g_qecallbacks,
397402
.config = &g_tim5config,
398403
.inuse = false,
404+
.lock = SP_UNLOCKED,
399405
};
400406

401407
#endif
@@ -421,6 +427,7 @@ static struct stm32_lowerhalf_s g_tim8lower =
421427
.ops = &g_qecallbacks,
422428
.config = &g_tim8config,
423429
.inuse = false,
430+
.lock = SP_UNLOCKED,
424431
};
425432

426433
#endif
@@ -1034,15 +1041,15 @@ static int stm32_position(struct qe_lowerhalf_s *lower, int32_t *pos)
10341041

10351042
/* Loop until we are certain that no interrupt occurred between samples */
10361043

1037-
flags = spin_lock_irqsave(NULL);
1044+
flags = spin_lock_irqsave(&priv->lock);
10381045
do
10391046
{
10401047
position = priv->position;
10411048
count = stm32_getreg32(priv, STM32_GTIM_CNT_OFFSET);
10421049
verify = priv->position;
10431050
}
10441051
while (position != verify);
1045-
spin_unlock_irqrestore(NULL, flags);
1052+
spin_unlock_irqrestore(&priv->lock, flags);
10461053

10471054
/* Return the position measurement */
10481055

arch/arm/src/stm32f7/stm32_serial.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ struct up_dev_s
507507
const bool rs485_dir_polarity; /* U[S]ART RS-485 DIR pin state for
508508
* TX enabled */
509509
#endif
510+
spinlock_t lock;
510511
};
511512

512513
#ifdef CONFIG_PM
@@ -832,6 +833,7 @@ static struct up_dev_s g_usart1priv =
832833
.rs485_dir_polarity = true,
833834
# endif
834835
#endif
836+
.lock = SP_UNLOCKED,
835837
};
836838
#endif
837839

@@ -900,6 +902,7 @@ static struct up_dev_s g_usart2priv =
900902
.rs485_dir_polarity = true,
901903
# endif
902904
#endif
905+
.lock = SP_UNLOCKED,
903906
};
904907
#endif
905908

@@ -968,6 +971,7 @@ static struct up_dev_s g_usart3priv =
968971
.rs485_dir_polarity = true,
969972
# endif
970973
#endif
974+
.lock = SP_UNLOCKED,
971975
};
972976
#endif
973977

@@ -1036,6 +1040,7 @@ static struct up_dev_s g_uart4priv =
10361040
.rs485_dir_polarity = true,
10371041
# endif
10381042
#endif
1043+
.lock = SP_UNLOCKED,
10391044
};
10401045
#endif
10411046

@@ -1104,6 +1109,7 @@ static struct up_dev_s g_uart5priv =
11041109
.rs485_dir_polarity = true,
11051110
# endif
11061111
#endif
1112+
.lock = SP_UNLOCKED,
11071113
};
11081114
#endif
11091115

@@ -1172,6 +1178,7 @@ static struct up_dev_s g_usart6priv =
11721178
.rs485_dir_polarity = true,
11731179
# endif
11741180
#endif
1181+
.lock = SP_UNLOCKED,
11751182
};
11761183
#endif
11771184

@@ -1240,6 +1247,7 @@ static struct up_dev_s g_uart7priv =
12401247
.rs485_dir_polarity = true,
12411248
# endif
12421249
#endif
1250+
.lock = SP_UNLOCKED,
12431251
};
12441252
#endif
12451253

@@ -1308,6 +1316,7 @@ static struct up_dev_s g_uart8priv =
13081316
.rs485_dir_polarity = true,
13091317
# endif
13101318
#endif
1319+
.lock = SP_UNLOCKED,
13111320
};
13121321
#endif
13131322

@@ -1408,11 +1417,11 @@ static void up_restoreusartint(struct up_dev_s *priv, uint16_t ie)
14081417
{
14091418
irqstate_t flags;
14101419

1411-
flags = spin_lock_irqsave(NULL);
1420+
flags = spin_lock_irqsave(&priv->lock);
14121421

14131422
up_setusartint(priv, ie);
14141423

1415-
spin_unlock_irqrestore(NULL, flags);
1424+
spin_unlock_irqrestore(&priv->lock, flags);
14161425
}
14171426

14181427
/****************************************************************************
@@ -1423,7 +1432,7 @@ static void up_disableusartint(struct up_dev_s *priv, uint16_t *ie)
14231432
{
14241433
irqstate_t flags;
14251434

1426-
flags = spin_lock_irqsave(NULL);
1435+
flags = spin_lock_irqsave(&priv->lock);
14271436

14281437
if (ie)
14291438
{
@@ -1467,7 +1476,7 @@ static void up_disableusartint(struct up_dev_s *priv, uint16_t *ie)
14671476

14681477
up_setusartint(priv, 0);
14691478

1470-
spin_unlock_irqrestore(NULL, flags);
1479+
spin_unlock_irqrestore(&priv->lock, flags);
14711480
}
14721481

14731482
/****************************************************************************

arch/arm/src/stm32h5/stm32_serial.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ struct stm32_serial_s
296296
const bool rs485_dir_polarity; /* U[S]ART RS-485 DIR pin state for TX enabled */
297297
#endif
298298
const bool islpuart; /* Is this device a Low Power UART? */
299+
spinlock_t lock;
299300
};
300301

301302
/****************************************************************************
@@ -506,6 +507,7 @@ static struct stm32_serial_s g_lpuart1priv =
506507
.rs485_dir_polarity = true,
507508
# endif
508509
# endif
510+
.lock = SP_UNLOCKED,
509511
};
510512
#endif
511513

@@ -566,6 +568,7 @@ static struct stm32_serial_s g_usart1priv =
566568
.rs485_dir_polarity = true,
567569
# endif
568570
# endif
571+
.lock = SP_UNLOCKED,
569572
};
570573
#endif
571574

@@ -628,6 +631,7 @@ static struct stm32_serial_s g_usart2priv =
628631
.rs485_dir_polarity = true,
629632
# endif
630633
# endif
634+
.lock = SP_UNLOCKED,
631635
};
632636
#endif
633637

@@ -690,6 +694,7 @@ static struct stm32_serial_s g_usart3priv =
690694
.rs485_dir_polarity = true,
691695
# endif
692696
# endif
697+
.lock = SP_UNLOCKED,
693698
};
694699
#endif
695700

@@ -752,6 +757,7 @@ static struct stm32_serial_s g_uart4priv =
752757
.rs485_dir_polarity = true,
753758
# endif
754759
# endif
760+
.lock = SP_UNLOCKED,
755761
};
756762
#endif
757763

@@ -814,6 +820,7 @@ static struct stm32_serial_s g_uart5priv =
814820
.rs485_dir_polarity = true,
815821
# endif
816822
# endif
823+
.lock = SP_UNLOCKED,
817824
};
818825
#endif
819826

@@ -876,6 +883,7 @@ static struct stm32_serial_s g_usart6priv =
876883
.rs485_dir_polarity = true,
877884
# endif
878885
# endif
886+
.lock = SP_UNLOCKED,
879887
};
880888
#endif
881889

@@ -938,6 +946,7 @@ static struct stm32_serial_s g_uart7priv =
938946
.rs485_dir_polarity = true,
939947
# endif
940948
# endif
949+
.lock = SP_UNLOCKED,
941950
};
942951
#endif
943952

@@ -1000,6 +1009,7 @@ static struct stm32_serial_s g_uart8priv =
10001009
.rs485_dir_polarity = true,
10011010
# endif
10021011
# endif
1012+
.lock = SP_UNLOCKED,
10031013
};
10041014
#endif
10051015

@@ -1062,6 +1072,7 @@ static struct stm32_serial_s g_uart9priv =
10621072
.rs485_dir_polarity = true,
10631073
# endif
10641074
# endif
1075+
.lock = SP_UNLOCKED,
10651076
};
10661077
#endif
10671078

@@ -1124,6 +1135,7 @@ static struct stm32_serial_s g_usart10priv =
11241135
.rs485_dir_polarity = true,
11251136
# endif
11261137
# endif
1138+
.lock = SP_UNLOCKED,
11271139
};
11281140
#endif
11291141

@@ -1186,6 +1198,7 @@ static struct stm32_serial_s g_usart11priv =
11861198
.rs485_dir_polarity = true,
11871199
# endif
11881200
# endif
1201+
.lock = SP_UNLOCKED,
11891202
};
11901203
#endif
11911204

@@ -1248,6 +1261,7 @@ static struct stm32_serial_s g_uart12priv =
12481261
.rs485_dir_polarity = true,
12491262
# endif
12501263
# endif
1264+
.lock = SP_UNLOCKED,
12511265
};
12521266
#endif
12531267

@@ -1375,11 +1389,11 @@ static void stm32serial_restoreusartint(struct stm32_serial_s *priv,
13751389
{
13761390
irqstate_t flags;
13771391

1378-
flags = spin_lock_irqsave(NULL);
1392+
flags = spin_lock_irqsave(&priv->lock);
13791393

13801394
stm32serial_setusartint(priv, ie);
13811395

1382-
spin_unlock_irqrestore(NULL, flags);
1396+
spin_unlock_irqrestore(&priv->lock, flags);
13831397
}
13841398

13851399
/****************************************************************************
@@ -1391,7 +1405,7 @@ static void stm32serial_disableusartint(struct stm32_serial_s *priv,
13911405
{
13921406
irqstate_t flags;
13931407

1394-
flags = spin_lock_irqsave(NULL);
1408+
flags = spin_lock_irqsave(&priv->lock);
13951409

13961410
if (ie)
13971411
{
@@ -1434,7 +1448,7 @@ static void stm32serial_disableusartint(struct stm32_serial_s *priv,
14341448

14351449
stm32serial_setusartint(priv, 0);
14361450

1437-
spin_unlock_irqrestore(NULL, flags);
1451+
spin_unlock_irqrestore(&priv->lock, flags);
14381452
}
14391453

14401454
/****************************************************************************

0 commit comments

Comments
 (0)