1 /*-----------------------------------------------------------------------------
3 * Purpose: CMSIS CORE validation tests implementation
4 *-----------------------------------------------------------------------------
5 * Copyright (c) 2017 - 2021 Arm Limited. All rights reserved.
6 *----------------------------------------------------------------------------*/
8 #include "CV_Framework.h"
11 #if defined(__CORTEX_M)
12 #elif defined(__CORTEX_A)
15 #error __CORTEX_M or __CORTEX_A must be defined!
18 /*-----------------------------------------------------------------------------
20 *----------------------------------------------------------------------------*/
22 /*-----------------------------------------------------------------------------
24 *----------------------------------------------------------------------------*/
26 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
28 \brief Test case: TC_CoreInstr_NOP
30 - Check if __NOP instrinsic is available
31 - No real assertion is deployed, just a compile time check.
33 void TC_CoreInstr_NOP (void) {
35 ASSERT_TRUE(1U == 1U);
38 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
40 \brief Test case: TC_CoreInstr_SEV
42 - Check if __SEV instrinsic is available
43 - No real assertion is deployed, just a compile time check.
45 void TC_CoreInstr_SEV (void) {
47 ASSERT_TRUE(1U == 1U);
50 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
52 \brief Test case: TC_CoreInstr_BKPT
54 - Check if __BKPT instrinsic is available
55 - No real assertion is deployed, just a compile time check.
57 void TC_CoreInstr_BKPT (void) {
59 ASSERT_TRUE(1U == 1U);
62 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
64 \brief Test case: TC_CoreInstr_ISB
66 - Check if __ISB instrinsic is available
67 - No real assertion is deployed, just a compile time check.
69 void TC_CoreInstr_ISB (void) {
71 ASSERT_TRUE(1U == 1U);
74 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
76 \brief Test case: TC_CoreInstr_DSB
78 - Check if __DSB instrinsic is available
79 - No real assertion is deployed, just a compile time check.
81 void TC_CoreInstr_DSB (void) {
83 ASSERT_TRUE(1U == 1U);
86 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
88 \brief Test case: TC_CoreInstr_DMB
90 - Check if __DNB instrinsic is available
91 - No real assertion is deployed, just a compile time check.
93 void TC_CoreInstr_DMB (void) {
95 ASSERT_TRUE(1U == 1U);
98 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
100 \brief Test case: TC_CoreInstr_WFI
102 - Check if __WFI instrinsic is available
103 - No real assertion is deployed, just a compile time check.
105 void TC_CoreInstr_WFI (void) {
107 ASSERT_TRUE(1U == 1U);
110 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
112 \brief Test case: TC_CoreInstr_WFE
114 - Check if __WFE instrinsic is available
115 - No real assertion is deployed, just a compile time check.
117 void TC_CoreInstr_WFE (void) {
119 ASSERT_TRUE(1U == 1U);
122 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
124 \brief Test case: TC_CoreInstr_REV
126 - Check if __REV instrinsic swaps all bytes in a word.
128 void TC_CoreInstr_REV (void) {
129 volatile uint32_t op1_u32;
130 volatile uint32_t res_u32;
132 op1_u32 = 0x47110815U;
133 res_u32 = __REV(op1_u32);
134 ASSERT_TRUE(res_u32 == 0x15081147U);
136 op1_u32 = 0x80000000U;
137 res_u32 = __REV(op1_u32);
138 ASSERT_TRUE(res_u32 == 0x00000080U);
140 op1_u32 = 0x00000080U;
141 res_u32 = __REV(op1_u32);
142 ASSERT_TRUE(res_u32 == 0x80000000U);
145 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
147 \brief Test case: TC_CoreInstr_REV16
149 - Check if __REV16 instrinsic swaps the bytes in both halfwords independendly.
151 void TC_CoreInstr_REV16(void) {
152 volatile uint32_t op1_u32;
153 volatile uint32_t res_u32;
155 op1_u32 = 0x47110815U;
156 res_u32 = __REV16(op1_u32);
157 ASSERT_TRUE(res_u32 == 0x11471508U);
159 op1_u32 = 0x00001234U;
160 res_u32 = __REV16(op1_u32);
161 ASSERT_TRUE(res_u32 == 0x00003412U);
164 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
166 \brief Test case: TC_CoreInstr_REVSH
168 - Check if __REVSH instrinsic swaps bytes in a signed halfword keeping the sign.
170 void TC_CoreInstr_REVSH(void) {
171 volatile int16_t value = 0U;
175 result = __REVSH(value);
176 ASSERT_TRUE(result == 0x1147);
178 value = (int16_t)0x8000;
179 result = __REVSH(value);
180 ASSERT_TRUE(result == 0x0080);
183 result = __REVSH(value);
184 ASSERT_TRUE(result == (int16_t)0x8000);
187 result = __REVSH(value);
188 ASSERT_TRUE(result == (int16_t)0xcced);
191 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
193 \brief Test case: TC_CoreInstr_RBIT
195 - Check if __RBIT instrinsic revserses the bit order of arbitrary words.
197 void TC_CoreInstr_RBIT (void) {
198 volatile uint32_t value = 0U;
199 uint32_t result = 0U;
202 result = __RBIT(value);
203 ASSERT_TRUE(result == 0x55555555U);
206 result = __RBIT(value);
207 ASSERT_TRUE(result == 0xAAAAAAAAU);
210 result = __RBIT(value);
211 ASSERT_TRUE(result == 0x80000000U);
214 result = __RBIT(value);
215 ASSERT_TRUE(result == 0x00000001U);
218 result = __RBIT(value);
219 ASSERT_TRUE(result == 0xF77DB57BU);
222 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
224 \brief Test case: TC_CoreInstr_ROR
226 - Check if __ROR instrinsic moves all bits as expected.
228 void TC_CoreInstr_ROR(void) {
229 volatile uint32_t value = 0U;
230 uint32_t result = 0U;
233 result = __ROR(value, 1U);
234 ASSERT_TRUE(result == 0x80000000U);
237 result = __ROR(value, 1U);
238 ASSERT_TRUE(result == 0x40000000U);
241 result = __ROR(value, 30U);
242 ASSERT_TRUE(result == 0x00000001U);
245 result = __ROR(value, 32U);
246 ASSERT_TRUE(result == 0x00000001U);
249 result = __ROR(value, 8U);
250 ASSERT_TRUE(result == 0x11081547U);
253 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
255 \brief Test case: TC_CoreInstr_CLZ
257 - Check if __CLZ instrinsic counts leading zeros.
259 void TC_CoreInstr_CLZ (void) {
260 volatile uint32_t value = 0U;
261 uint32_t result = 0U;
264 result = __CLZ(value);
265 ASSERT_TRUE(result == 32);
268 result = __CLZ(value);
269 ASSERT_TRUE(result == 31);
272 result = __CLZ(value);
273 ASSERT_TRUE(result == 1);
276 result = __CLZ(value);
277 ASSERT_TRUE(result == 0);
280 result = __CLZ(value);
281 ASSERT_TRUE(result == 0);
284 result = __CLZ(value);
285 ASSERT_TRUE(result == 0);
288 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
290 \brief Test case: TC_CoreInstr_SSAT
292 - Check if __SSAT instrinsic saturates signed integer values.
294 void TC_CoreInstr_SSAT (void) {
295 volatile int32_t value = 0;
299 result = __SSAT(value, 32U);
300 ASSERT_TRUE(result == INT32_MAX);
303 result = __SSAT(value, 16U);
304 ASSERT_TRUE(result == INT16_MAX);
307 result = __SSAT(value, 8U);
308 ASSERT_TRUE(result == INT8_MAX);
311 result = __SSAT(value, 1U);
312 ASSERT_TRUE(result == 0);
315 result = __SSAT(value, 32U);
316 ASSERT_TRUE(result == INT32_MIN);
319 result = __SSAT(value, 16U);
320 ASSERT_TRUE(result == INT16_MIN);
323 result = __SSAT(value, 8U);
324 ASSERT_TRUE(result == INT8_MIN);
327 result = __SSAT(value, 1U);
328 ASSERT_TRUE(result == -1);
331 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
333 \brief Test case: TC_CoreInstr_USAT
335 - Check if __USAT instrinsic saturates unsigned integer values.
337 void TC_CoreInstr_USAT (void) {
338 volatile int32_t value = 0U;
339 uint32_t result = 0U;
342 result = __USAT(value, 31U);
343 ASSERT_TRUE(result == (UINT32_MAX >> 1U));
346 result = __USAT(value, 16U);
347 ASSERT_TRUE(result == UINT16_MAX);
350 result = __USAT(value, 8U);
351 ASSERT_TRUE(result == UINT8_MAX);
354 result = __USAT(value, 0U);
355 ASSERT_TRUE(result == 0U);
358 result = __USAT(value, 31U);
359 ASSERT_TRUE(result == 0U);
362 result = __USAT(value, 16U);
363 ASSERT_TRUE(result == 0U);
366 result = __USAT(value, 8U);
367 ASSERT_TRUE(result == 0U);
370 result = __USAT(value, 0U);
371 ASSERT_TRUE(result == 0U);
374 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
376 \brief Test case: TC_CoreInstr_RRX
378 - Check if __USAT instrinsic saturates unsigned integer values.
380 void TC_CoreInstr_RRX (void) {
381 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
382 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
383 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
384 (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) )
386 volatile uint32_t value = 0U;
387 volatile uint32_t result = 0U;
388 volatile xPSR_Type xPSR;
391 xPSR.w = __get_xPSR();
392 result = __RRX(value);
393 ASSERT_TRUE(result == (0x40000001 | (uint32_t)(xPSR.b.C << 31)));
397 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
398 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
399 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
400 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
401 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) || \
402 (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) || \
403 (defined(__CORTEX_A) ) )
405 /// Exclusive byte value
406 static volatile uint8_t TC_CoreInstr_LoadStoreExclusive_byte = 0x47U;
408 /// Exclusive halfword value
409 static volatile uint16_t TC_CoreInstr_LoadStoreExclusive_hword = 0x0815U;
411 /// Exclusive word value
412 static volatile uint32_t TC_CoreInstr_LoadStoreExclusive_word = 0x08154711U;
415 \brief Interrupt function for TC_CoreInstr_LoadStoreExclusive
417 The interrupt manipulates all the global data
418 which disrupts the exclusive sequences in the test
420 static void TC_CoreInstr_LoadStoreExclusive_IRQHandler(void) {
422 const uint8_t b = __LDREXB(&TC_CoreInstr_LoadStoreExclusive_byte);
423 __STREXB((uint8_t)~b, &TC_CoreInstr_LoadStoreExclusive_byte);
425 const uint16_t hw = __LDREXH(&TC_CoreInstr_LoadStoreExclusive_hword);
426 __STREXH((uint16_t)~hw, &TC_CoreInstr_LoadStoreExclusive_hword);
428 const uint32_t w = __LDREXW(&TC_CoreInstr_LoadStoreExclusive_word);
429 __STREXW((uint32_t)~w, &TC_CoreInstr_LoadStoreExclusive_word);
433 \brief Helper function for TC_CoreInstr_LoadStoreExclusive to enable test interrupt.
435 This helper function implements interrupt enabling according to target
436 architecture, i.e. Cortex-A or Cortex-M.
438 static void TC_CoreInstr_LoadStoreExclusive_IRQEnable(void) {
439 #if defined(__CORTEX_M)
440 TST_IRQHandler = TC_CoreInstr_LoadStoreExclusive_IRQHandler;
441 NVIC_EnableIRQ(Interrupt0_IRQn);
442 #elif defined(__CORTEX_A)
443 IRQ_SetHandler(SGI0_IRQn, TC_CoreInstr_LoadStoreExclusive_IRQHandler);
444 IRQ_Enable(SGI0_IRQn);
446 #error __CORTEX_M or __CORTEX_A must be defined!
452 \brief Helper function for TC_CoreInstr_LoadStoreExclusive to set test interrupt pending.
454 This helper function implements set pending the test interrupt according to target
455 architecture, i.e. Cortex-A or Cortex-M.
457 static void TC_CoreInstr_LoadStoreExclusive_IRQPend(void) {
458 #if defined(__CORTEX_M)
459 NVIC_SetPendingIRQ(Interrupt0_IRQn);
460 #elif defined(__CORTEX_A)
461 IRQ_SetPending(SGI0_IRQn);
463 #error __CORTEX_M or __CORTEX_A must be defined!
465 for(uint32_t i = 10U; i > 0U; --i) {}
469 \brief Helper function for TC_CoreInstr_LoadStoreExclusive to disable test interrupt.
471 This helper function implements interrupt disabling according to target
472 architecture, i.e. Cortex-A or Cortex-M.
474 static void TC_CoreInstr_LoadStoreExclusive_IRQDisable(void) {
476 #if defined(__CORTEX_M)
477 NVIC_DisableIRQ(Interrupt0_IRQn);
478 TST_IRQHandler = NULL;
479 #elif defined(__CORTEX_A)
480 IRQ_Disable(SGI0_IRQn);
481 IRQ_SetHandler(SGI0_IRQn, NULL);
483 #error __CORTEX_M or __CORTEX_A must be defined!
489 \brief Test case: TC_CoreInstr_LoadStoreExclusive
491 Checks exclusive load and store instructions:
492 - LDREXB, LDREXH, LDREXW
493 - STREXB, STREXH, STREXW
496 void TC_CoreInstr_LoadStoreExclusive (void) {
497 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
498 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
499 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
500 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) || \
501 (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) || \
502 (defined(__CORTEX_A) ) )
504 uint16_t u16, u16Inv;
505 uint32_t u32, u32Inv;
508 /* 1. Test exclusives without interruption */
509 u8 = __LDREXB(&TC_CoreInstr_LoadStoreExclusive_byte);
510 ASSERT_TRUE(u8 == TC_CoreInstr_LoadStoreExclusive_byte);
512 result = __STREXB(u8+1U, &TC_CoreInstr_LoadStoreExclusive_byte);
513 ASSERT_TRUE(result == 0U);
514 ASSERT_TRUE(TC_CoreInstr_LoadStoreExclusive_byte == u8+1U);
516 u16 = __LDREXH(&TC_CoreInstr_LoadStoreExclusive_hword);
517 ASSERT_TRUE(u16 == TC_CoreInstr_LoadStoreExclusive_hword);
519 result = __STREXH(u16+1U, &TC_CoreInstr_LoadStoreExclusive_hword);
520 ASSERT_TRUE(result == 0U);
521 ASSERT_TRUE(TC_CoreInstr_LoadStoreExclusive_hword == u16+1U);
523 u32 = __LDREXW(&TC_CoreInstr_LoadStoreExclusive_word);
524 ASSERT_TRUE(u32 == TC_CoreInstr_LoadStoreExclusive_word);
526 result = __STREXW(u32+1U, &TC_CoreInstr_LoadStoreExclusive_word);
527 ASSERT_TRUE(result == 0U);
528 ASSERT_TRUE(TC_CoreInstr_LoadStoreExclusive_word == u32+1U);
530 /* 2. Test exclusives with clear */
531 u8 = __LDREXB(&TC_CoreInstr_LoadStoreExclusive_byte);
532 ASSERT_TRUE(u8 == TC_CoreInstr_LoadStoreExclusive_byte);
536 result = __STREXB(u8+1U, &TC_CoreInstr_LoadStoreExclusive_byte);
537 ASSERT_TRUE(result == 1U);
538 ASSERT_TRUE(TC_CoreInstr_LoadStoreExclusive_byte == u8);
540 u16 = __LDREXH(&TC_CoreInstr_LoadStoreExclusive_hword);
541 ASSERT_TRUE(u16 == TC_CoreInstr_LoadStoreExclusive_hword);
545 result = __STREXH(u16+1U, &TC_CoreInstr_LoadStoreExclusive_hword);
546 ASSERT_TRUE(result == 1U);
547 ASSERT_TRUE(TC_CoreInstr_LoadStoreExclusive_hword == u16);
549 u32 = __LDREXW(&TC_CoreInstr_LoadStoreExclusive_word);
550 ASSERT_TRUE(u32 == TC_CoreInstr_LoadStoreExclusive_word);
554 result = __STREXW(u32+1U, &TC_CoreInstr_LoadStoreExclusive_word);
555 ASSERT_TRUE(result == 1U);
556 ASSERT_TRUE(TC_CoreInstr_LoadStoreExclusive_word == u32);
558 /* 3. Test exclusives with interruption */
559 TC_CoreInstr_LoadStoreExclusive_IRQEnable();
561 u8 = __LDREXB(&TC_CoreInstr_LoadStoreExclusive_byte);
562 ASSERT_TRUE(u8 == TC_CoreInstr_LoadStoreExclusive_byte);
564 TC_CoreInstr_LoadStoreExclusive_IRQPend();
566 result = __STREXB(u8+1U, &TC_CoreInstr_LoadStoreExclusive_byte);
567 ASSERT_TRUE(result == 1U);
568 u8Inv = (uint8_t)~u8;
569 ASSERT_TRUE(u8Inv == TC_CoreInstr_LoadStoreExclusive_byte);
571 u16 = __LDREXH(&TC_CoreInstr_LoadStoreExclusive_hword);
572 ASSERT_TRUE(u16 == TC_CoreInstr_LoadStoreExclusive_hword);
574 TC_CoreInstr_LoadStoreExclusive_IRQPend();
576 result = __STREXH(u16+1U, &TC_CoreInstr_LoadStoreExclusive_hword);
577 ASSERT_TRUE(result == 1U);
578 u16Inv = (uint16_t)~u16;
579 ASSERT_TRUE(u16Inv == TC_CoreInstr_LoadStoreExclusive_hword);
581 u32 = __LDREXW(&TC_CoreInstr_LoadStoreExclusive_word);
582 ASSERT_TRUE(u32 == TC_CoreInstr_LoadStoreExclusive_word);
584 TC_CoreInstr_LoadStoreExclusive_IRQPend();
586 result = __STREXW(u32+1U, &TC_CoreInstr_LoadStoreExclusive_word);
587 ASSERT_TRUE(result == 1U);
588 u32Inv = (uint32_t)~u32;
589 ASSERT_TRUE(u32Inv == TC_CoreInstr_LoadStoreExclusive_word);
591 TC_CoreInstr_LoadStoreExclusive_IRQDisable();
595 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
596 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
597 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
598 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
599 (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) )
601 /// byte value unprivileged access
602 static volatile uint8_t TC_CoreInstr_LoadStoreUnpriv_byte = 0x47U;
604 /// halfword value unprivileged access
605 static volatile uint16_t TC_CoreInstr_LoadStoreUnpriv_hword = 0x0815U;
607 /// word value unprivileged access
608 static volatile uint32_t TC_CoreInstr_LoadStoreUnpriv_word = 0x08154711U;
613 \brief Test case: TC_CoreInstr_LoadStoreUnpriv
615 Checks load/store unprivileged instructions:
619 void TC_CoreInstr_LoadStoreUnpriv (void) {
620 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
621 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
622 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
623 (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) )
628 /* 1. Test without interruption */
629 u8 = __LDRBT(&TC_CoreInstr_LoadStoreUnpriv_byte);
630 ASSERT_TRUE(u8 == TC_CoreInstr_LoadStoreUnpriv_byte);
632 __STRBT(u8+1U, &TC_CoreInstr_LoadStoreUnpriv_byte);
633 ASSERT_TRUE(TC_CoreInstr_LoadStoreUnpriv_byte == u8+1U);
635 u16 = __LDRHT(&TC_CoreInstr_LoadStoreUnpriv_hword);
636 ASSERT_TRUE(u16 == TC_CoreInstr_LoadStoreUnpriv_hword);
638 __STRHT(u16+1U, &TC_CoreInstr_LoadStoreUnpriv_hword);
639 ASSERT_TRUE(TC_CoreInstr_LoadStoreUnpriv_hword == u16+1U);
641 u32 = __LDRT(&TC_CoreInstr_LoadStoreUnpriv_word);
642 ASSERT_TRUE(u32 == TC_CoreInstr_LoadStoreUnpriv_word);
644 __STRT(u32+1U, &TC_CoreInstr_LoadStoreUnpriv_word);
645 ASSERT_TRUE(TC_CoreInstr_LoadStoreUnpriv_word == u32+1U);
649 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
650 #if ((defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) || \
651 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
652 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
654 /// byte value unprivileged access
655 static volatile uint8_t TC_CoreInstr_LoadStoreAcquire_byte = 0x47U;
657 /// halfword value unprivileged access
658 static volatile uint16_t TC_CoreInstr_LoadStoreAcquire_hword = 0x0815U;
660 /// word value unprivileged access
661 static volatile uint32_t TC_CoreInstr_LoadStoreAcquire_word = 0x08154711U;
666 \brief Test case: TC_CoreInstr_LoadStoreAquire
668 Checks Load-Acquire and Store-Release instructions:
672 void TC_CoreInstr_LoadStoreAcquire (void) {
673 #if ((defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) || \
674 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
675 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
680 /* 1. Test without interruption */
681 u8 = __LDAB(&TC_CoreInstr_LoadStoreAcquire_byte);
682 ASSERT_TRUE(u8 == TC_CoreInstr_LoadStoreAcquire_byte);
684 __STLB(u8+1U, &TC_CoreInstr_LoadStoreAcquire_byte);
685 ASSERT_TRUE(TC_CoreInstr_LoadStoreAcquire_byte == u8+1U);
687 u16 = __LDAH(&TC_CoreInstr_LoadStoreAcquire_hword);
688 ASSERT_TRUE(u16 == TC_CoreInstr_LoadStoreAcquire_hword);
690 __STLH(u16+1U, &TC_CoreInstr_LoadStoreAcquire_hword);
691 ASSERT_TRUE(TC_CoreInstr_LoadStoreAcquire_hword == u16+1U);
693 u32 = __LDA(&TC_CoreInstr_LoadStoreAcquire_word);
694 ASSERT_TRUE(u32 == TC_CoreInstr_LoadStoreAcquire_word);
696 __STL(u32+1U, &TC_CoreInstr_LoadStoreAcquire_word);
697 ASSERT_TRUE(TC_CoreInstr_LoadStoreAcquire_word == u32+1U);
701 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
702 #if ((defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) || \
703 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
704 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
706 /// byte value unprivileged access
707 static volatile uint8_t TC_CoreInstr_LoadStoreAcquireExclusive_byte = 0x47U;
709 /// halfword value unprivileged access
710 static volatile uint16_t TC_CoreInstr_LoadStoreAcquireExclusive_hword = 0x0815U;
712 /// word value unprivileged access
713 static volatile uint32_t TC_CoreInstr_LoadStoreAcquireExclusive_word = 0x08154711U;
718 \brief Test case: TC_CoreInstr_LoadStoreAquire
720 Checks Load-Acquire and Store-Release exclusive instructions:
721 - LDAEXB, LDAEXH, LDAEX
722 - STLEXB, STLEXH, STLEX
724 void TC_CoreInstr_LoadStoreAcquireExclusive (void) {
725 #if ((defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) || \
726 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
727 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
731 uint32_t result = 0U;
733 /* 1. Test without interruption */
734 u8 = __LDAEXB(&TC_CoreInstr_LoadStoreAcquireExclusive_byte);
735 ASSERT_TRUE(u8 == TC_CoreInstr_LoadStoreAcquireExclusive_byte);
737 result = __STLEXB(u8+1U, &TC_CoreInstr_LoadStoreAcquireExclusive_byte);
738 ASSERT_TRUE(result == 0U);
739 ASSERT_TRUE(TC_CoreInstr_LoadStoreAcquireExclusive_byte == u8+1U);
741 u16 = __LDAEXH(&TC_CoreInstr_LoadStoreAcquireExclusive_hword);
742 ASSERT_TRUE(u16 == TC_CoreInstr_LoadStoreAcquireExclusive_hword);
744 result = __STLEXH(u16+1U, &TC_CoreInstr_LoadStoreAcquireExclusive_hword);
745 ASSERT_TRUE(result == 0U);
746 ASSERT_TRUE(TC_CoreInstr_LoadStoreAcquireExclusive_hword == u16+1U);
748 u32 = __LDAEX(&TC_CoreInstr_LoadStoreAcquireExclusive_word);
749 ASSERT_TRUE(u32 == TC_CoreInstr_LoadStoreAcquireExclusive_word);
751 result = __STLEX(u32+1U, &TC_CoreInstr_LoadStoreAcquireExclusive_word);
752 ASSERT_TRUE(result == 0U);
753 ASSERT_TRUE(TC_CoreInstr_LoadStoreAcquireExclusive_word == u32+1U);
759 \brief Test case: TC_CoreInstr_UnalignedUint16
761 Checks macro functions to access unaligned uint16_t values:
762 - __UNALIGNED_UINT16_READ
763 - __UNALIGNED_UINT16_WRITE
765 void TC_CoreInstr_UnalignedUint16(void) {
766 uint8_t buffer[3] = { 0U, 0U, 0U };
769 for(int i=0; i<2; i++) {
770 __UNALIGNED_UINT16_WRITE(&(buffer[i]), 0x4711U);
771 ASSERT_TRUE(buffer[i] == 0x11U);
772 ASSERT_TRUE(buffer[i+1] == 0x47U);
773 ASSERT_TRUE(buffer[(i+2)%3] == 0x00U);
778 val = __UNALIGNED_UINT16_READ(&(buffer[i]));
779 ASSERT_TRUE(val == 0x4612U);
788 \brief Test case: TC_CoreInstr_UnalignedUint32
790 Checks macro functions to access unaligned uint32_t values:
791 - __UNALIGNED_UINT32_READ
792 - __UNALIGNED_UINT32_WRITE
794 void TC_CoreInstr_UnalignedUint32(void) {
795 uint8_t buffer[7] = { 0U, 0U, 0U, 0U, 0U, 0U, 0U };
798 for(int i=0; i<4; i++) {
799 __UNALIGNED_UINT32_WRITE(&(buffer[i]), 0x08154711UL);
800 ASSERT_TRUE(buffer[i+0] == 0x11U);
801 ASSERT_TRUE(buffer[i+1] == 0x47U);
802 ASSERT_TRUE(buffer[i+2] == 0x15U);
803 ASSERT_TRUE(buffer[i+3] == 0x08U);
804 ASSERT_TRUE(buffer[(i+4)%7] == 0x00U);
805 ASSERT_TRUE(buffer[(i+5)%7] == 0x00U);
806 ASSERT_TRUE(buffer[(i+6)%7] == 0x00U);
813 val = __UNALIGNED_UINT32_READ(&(buffer[i]));
814 ASSERT_TRUE(val == 0x09144612UL);