1 /*-----------------------------------------------------------------------------
3 * Purpose: CMSIS CORE validation tests implementation
4 *-----------------------------------------------------------------------------
5 * Copyright (c) 2017 - 2021 Arm Limited. All rights reserved.
6 *----------------------------------------------------------------------------*/
8 #include "cmsis_compiler.h"
10 #include "CV_Framework.h"
13 #if defined(__CORTEX_M)
14 #elif defined(__CORTEX_A)
17 #error __CORTEX_M or __CORTEX_A must be defined!
20 /*-----------------------------------------------------------------------------
22 *----------------------------------------------------------------------------*/
24 /*-----------------------------------------------------------------------------
26 *----------------------------------------------------------------------------*/
28 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
30 \brief Test case: TC_CoreInstr_NOP
32 - Check if __NOP instrinsic is available
33 - No real assertion is deployed, just a compile time check.
35 void TC_CoreInstr_NOP (void) {
37 ASSERT_TRUE(1U == 1U);
40 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
42 \brief Test case: TC_CoreInstr_SEV
44 - Check if __SEV instrinsic is available
45 - No real assertion is deployed, just a compile time check.
47 void TC_CoreInstr_SEV (void) {
49 ASSERT_TRUE(1U == 1U);
52 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
54 \brief Test case: TC_CoreInstr_BKPT
56 - Check if __BKPT instrinsic is available
57 - No real assertion is deployed, just a compile time check.
59 void TC_CoreInstr_BKPT (void) {
61 ASSERT_TRUE(1U == 1U);
64 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
66 \brief Test case: TC_CoreInstr_ISB
68 - Check if __ISB instrinsic is available
69 - No real assertion is deployed, just a compile time check.
71 void TC_CoreInstr_ISB (void) {
73 ASSERT_TRUE(1U == 1U);
76 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
78 \brief Test case: TC_CoreInstr_DSB
80 - Check if __DSB instrinsic is available
81 - No real assertion is deployed, just a compile time check.
83 void TC_CoreInstr_DSB (void) {
85 ASSERT_TRUE(1U == 1U);
88 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
90 \brief Test case: TC_CoreInstr_DMB
92 - Check if __DNB instrinsic is available
93 - No real assertion is deployed, just a compile time check.
95 void TC_CoreInstr_DMB (void) {
97 ASSERT_TRUE(1U == 1U);
100 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
102 \brief Test case: TC_CoreInstr_WFI
104 - Check if __WFI instrinsic is available
105 - No real assertion is deployed, just a compile time check.
107 void TC_CoreInstr_WFI (void) {
109 ASSERT_TRUE(1U == 1U);
112 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
114 \brief Test case: TC_CoreInstr_WFE
116 - Check if __WFE instrinsic is available
117 - No real assertion is deployed, just a compile time check.
119 void TC_CoreInstr_WFE (void) {
121 ASSERT_TRUE(1U == 1U);
124 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
126 \brief Test case: TC_CoreInstr_REV
128 - Check if __REV instrinsic swaps all bytes in a word.
130 void TC_CoreInstr_REV (void) {
131 volatile uint32_t op1_u32;
132 volatile uint32_t res_u32;
134 op1_u32 = 0x47110815U;
135 res_u32 = __REV(op1_u32);
136 ASSERT_TRUE(res_u32 == 0x15081147U);
138 op1_u32 = 0x80000000U;
139 res_u32 = __REV(op1_u32);
140 ASSERT_TRUE(res_u32 == 0x00000080U);
142 op1_u32 = 0x00000080U;
143 res_u32 = __REV(op1_u32);
144 ASSERT_TRUE(res_u32 == 0x80000000U);
147 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
149 \brief Test case: TC_CoreInstr_REV16
151 - Check if __REV16 instrinsic swaps the bytes in both halfwords independendly.
153 void TC_CoreInstr_REV16(void) {
154 volatile uint32_t op1_u32;
155 volatile uint32_t res_u32;
157 op1_u32 = 0x47110815U;
158 res_u32 = __REV16(op1_u32);
159 ASSERT_TRUE(res_u32 == 0x11471508U);
161 op1_u32 = 0x00001234U;
162 res_u32 = __REV16(op1_u32);
163 ASSERT_TRUE(res_u32 == 0x00003412U);
166 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
168 \brief Test case: TC_CoreInstr_REVSH
170 - Check if __REVSH instrinsic swaps bytes in a signed halfword keeping the sign.
172 void TC_CoreInstr_REVSH(void) {
173 volatile int16_t value = 0U;
177 result = __REVSH(value);
178 ASSERT_TRUE(result == 0x1147);
180 value = (int16_t)0x8000;
181 result = __REVSH(value);
182 ASSERT_TRUE(result == 0x0080);
185 result = __REVSH(value);
186 ASSERT_TRUE(result == (int16_t)0x8000);
189 result = __REVSH(value);
190 ASSERT_TRUE(result == (int16_t)0xcced);
193 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
195 \brief Test case: TC_CoreInstr_RBIT
197 - Check if __RBIT instrinsic revserses the bit order of arbitrary words.
199 void TC_CoreInstr_RBIT (void) {
200 volatile uint32_t value = 0U;
201 uint32_t result = 0U;
204 result = __RBIT(value);
205 ASSERT_TRUE(result == 0x55555555U);
208 result = __RBIT(value);
209 ASSERT_TRUE(result == 0xAAAAAAAAU);
212 result = __RBIT(value);
213 ASSERT_TRUE(result == 0x80000000U);
216 result = __RBIT(value);
217 ASSERT_TRUE(result == 0x00000001U);
220 result = __RBIT(value);
221 ASSERT_TRUE(result == 0xF77DB57BU);
224 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
226 \brief Test case: TC_CoreInstr_ROR
228 - Check if __ROR instrinsic moves all bits as expected.
230 void TC_CoreInstr_ROR(void) {
231 volatile uint32_t value = 0U;
232 uint32_t result = 0U;
235 result = __ROR(value, 1U);
236 ASSERT_TRUE(result == 0x80000000U);
239 result = __ROR(value, 1U);
240 ASSERT_TRUE(result == 0x40000000U);
243 result = __ROR(value, 30U);
244 ASSERT_TRUE(result == 0x00000001U);
247 result = __ROR(value, 32U);
248 ASSERT_TRUE(result == 0x00000001U);
251 result = __ROR(value, 8U);
252 ASSERT_TRUE(result == 0x11081547U);
255 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
257 \brief Test case: TC_CoreInstr_CLZ
259 - Check if __CLZ instrinsic counts leading zeros.
261 void TC_CoreInstr_CLZ (void) {
262 volatile uint32_t value = 0U;
263 uint32_t result = 0U;
266 result = __CLZ(value);
267 ASSERT_TRUE(result == 32);
270 result = __CLZ(value);
271 ASSERT_TRUE(result == 31);
274 result = __CLZ(value);
275 ASSERT_TRUE(result == 1);
278 result = __CLZ(value);
279 ASSERT_TRUE(result == 0);
282 result = __CLZ(value);
283 ASSERT_TRUE(result == 0);
286 result = __CLZ(value);
287 ASSERT_TRUE(result == 0);
290 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
292 \brief Test case: TC_CoreInstr_SSAT
294 - Check if __SSAT instrinsic saturates signed integer values.
296 void TC_CoreInstr_SSAT (void) {
297 volatile int32_t value = 0;
301 result = __SSAT(value, 32U);
302 ASSERT_TRUE(result == INT32_MAX);
305 result = __SSAT(value, 16U);
306 ASSERT_TRUE(result == INT16_MAX);
309 result = __SSAT(value, 8U);
310 ASSERT_TRUE(result == INT8_MAX);
313 result = __SSAT(value, 1U);
314 ASSERT_TRUE(result == 0);
317 result = __SSAT(value, 32U);
318 ASSERT_TRUE(result == INT32_MIN);
321 result = __SSAT(value, 16U);
322 ASSERT_TRUE(result == INT16_MIN);
325 result = __SSAT(value, 8U);
326 ASSERT_TRUE(result == INT8_MIN);
329 result = __SSAT(value, 1U);
330 ASSERT_TRUE(result == -1);
333 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
335 \brief Test case: TC_CoreInstr_USAT
337 - Check if __USAT instrinsic saturates unsigned integer values.
339 void TC_CoreInstr_USAT (void) {
340 volatile int32_t value = 0U;
341 uint32_t result = 0U;
344 result = __USAT(value, 31U);
345 ASSERT_TRUE(result == (UINT32_MAX >> 1U));
348 result = __USAT(value, 16U);
349 ASSERT_TRUE(result == UINT16_MAX);
352 result = __USAT(value, 8U);
353 ASSERT_TRUE(result == UINT8_MAX);
356 result = __USAT(value, 0U);
357 ASSERT_TRUE(result == 0U);
360 result = __USAT(value, 31U);
361 ASSERT_TRUE(result == 0U);
364 result = __USAT(value, 16U);
365 ASSERT_TRUE(result == 0U);
368 result = __USAT(value, 8U);
369 ASSERT_TRUE(result == 0U);
372 result = __USAT(value, 0U);
373 ASSERT_TRUE(result == 0U);
376 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
378 \brief Test case: TC_CoreInstr_RRX
380 - Check if __USAT instrinsic saturates unsigned integer values.
382 void TC_CoreInstr_RRX (void) {
383 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
384 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
385 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
386 (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) )
388 volatile uint32_t value = 0U;
389 volatile uint32_t result = 0U;
390 volatile xPSR_Type xPSR;
393 xPSR.w = __get_xPSR();
394 result = __RRX(value);
395 ASSERT_TRUE(result == (0x40000001 | (uint32_t)(xPSR.b.C << 31)));
399 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
400 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
401 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
402 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
403 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) || \
404 (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) || \
405 (defined(__CORTEX_A) ) )
407 /// Exclusive byte value
408 static volatile uint8_t TC_CoreInstr_LoadStoreExclusive_byte = 0x47U;
410 /// Exclusive halfword value
411 static volatile uint16_t TC_CoreInstr_LoadStoreExclusive_hword = 0x0815U;
413 /// Exclusive word value
414 static volatile uint32_t TC_CoreInstr_LoadStoreExclusive_word = 0x08154711U;
417 \brief Interrupt function for TC_CoreInstr_LoadStoreExclusive
419 The interrupt manipulates all the global data
420 which disrupts the exclusive sequences in the test
422 static void TC_CoreInstr_LoadStoreExclusive_IRQHandler(void) {
424 const uint8_t b = __LDREXB(&TC_CoreInstr_LoadStoreExclusive_byte);
425 __STREXB((uint8_t)~b, &TC_CoreInstr_LoadStoreExclusive_byte);
427 const uint16_t hw = __LDREXH(&TC_CoreInstr_LoadStoreExclusive_hword);
428 __STREXH((uint16_t)~hw, &TC_CoreInstr_LoadStoreExclusive_hword);
430 const uint32_t w = __LDREXW(&TC_CoreInstr_LoadStoreExclusive_word);
431 __STREXW((uint32_t)~w, &TC_CoreInstr_LoadStoreExclusive_word);
435 \brief Helper function for TC_CoreInstr_LoadStoreExclusive to enable test interrupt.
437 This helper function implements interrupt enabling according to target
438 architecture, i.e. Cortex-A or Cortex-M.
440 static void TC_CoreInstr_LoadStoreExclusive_IRQEnable(void) {
441 #if defined(__CORTEX_M)
442 TST_IRQHandler = TC_CoreInstr_LoadStoreExclusive_IRQHandler;
443 NVIC_EnableIRQ(Interrupt0_IRQn);
444 #elif defined(__CORTEX_A)
445 IRQ_SetHandler(SGI0_IRQn, TC_CoreInstr_LoadStoreExclusive_IRQHandler);
446 IRQ_Enable(SGI0_IRQn);
448 #error __CORTEX_M or __CORTEX_A must be defined!
454 \brief Helper function for TC_CoreInstr_LoadStoreExclusive to set test interrupt pending.
456 This helper function implements set pending the test interrupt according to target
457 architecture, i.e. Cortex-A or Cortex-M.
459 static void TC_CoreInstr_LoadStoreExclusive_IRQPend(void) {
460 #if defined(__CORTEX_M)
461 NVIC_SetPendingIRQ(Interrupt0_IRQn);
462 #elif defined(__CORTEX_A)
463 IRQ_SetPending(SGI0_IRQn);
465 #error __CORTEX_M or __CORTEX_A must be defined!
467 for(uint32_t i = 10U; i > 0U; --i) {}
471 \brief Helper function for TC_CoreInstr_LoadStoreExclusive to disable test interrupt.
473 This helper function implements interrupt disabling according to target
474 architecture, i.e. Cortex-A or Cortex-M.
476 static void TC_CoreInstr_LoadStoreExclusive_IRQDisable(void) {
478 #if defined(__CORTEX_M)
479 NVIC_DisableIRQ(Interrupt0_IRQn);
480 TST_IRQHandler = NULL;
481 #elif defined(__CORTEX_A)
482 IRQ_Disable(SGI0_IRQn);
483 IRQ_SetHandler(SGI0_IRQn, NULL);
485 #error __CORTEX_M or __CORTEX_A must be defined!
491 \brief Test case: TC_CoreInstr_LoadStoreExclusive
493 Checks exclusive load and store instructions:
494 - LDREXB, LDREXH, LDREXW
495 - STREXB, STREXH, STREXW
498 void TC_CoreInstr_LoadStoreExclusive (void) {
499 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
500 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
501 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
502 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) || \
503 (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) || \
504 (defined(__CORTEX_A) ) )
506 uint16_t u16, u16Inv;
507 uint32_t u32, u32Inv;
510 /* 1. Test exclusives without interruption */
511 u8 = __LDREXB(&TC_CoreInstr_LoadStoreExclusive_byte);
512 ASSERT_TRUE(u8 == TC_CoreInstr_LoadStoreExclusive_byte);
514 result = __STREXB(u8+1U, &TC_CoreInstr_LoadStoreExclusive_byte);
515 ASSERT_TRUE(result == 0U);
516 ASSERT_TRUE(TC_CoreInstr_LoadStoreExclusive_byte == u8+1U);
518 u16 = __LDREXH(&TC_CoreInstr_LoadStoreExclusive_hword);
519 ASSERT_TRUE(u16 == TC_CoreInstr_LoadStoreExclusive_hword);
521 result = __STREXH(u16+1U, &TC_CoreInstr_LoadStoreExclusive_hword);
522 ASSERT_TRUE(result == 0U);
523 ASSERT_TRUE(TC_CoreInstr_LoadStoreExclusive_hword == u16+1U);
525 u32 = __LDREXW(&TC_CoreInstr_LoadStoreExclusive_word);
526 ASSERT_TRUE(u32 == TC_CoreInstr_LoadStoreExclusive_word);
528 result = __STREXW(u32+1U, &TC_CoreInstr_LoadStoreExclusive_word);
529 ASSERT_TRUE(result == 0U);
530 ASSERT_TRUE(TC_CoreInstr_LoadStoreExclusive_word == u32+1U);
532 /* 2. Test exclusives with clear */
533 u8 = __LDREXB(&TC_CoreInstr_LoadStoreExclusive_byte);
534 ASSERT_TRUE(u8 == TC_CoreInstr_LoadStoreExclusive_byte);
538 result = __STREXB(u8+1U, &TC_CoreInstr_LoadStoreExclusive_byte);
539 ASSERT_TRUE(result == 1U);
540 ASSERT_TRUE(TC_CoreInstr_LoadStoreExclusive_byte == u8);
542 u16 = __LDREXH(&TC_CoreInstr_LoadStoreExclusive_hword);
543 ASSERT_TRUE(u16 == TC_CoreInstr_LoadStoreExclusive_hword);
547 result = __STREXH(u16+1U, &TC_CoreInstr_LoadStoreExclusive_hword);
548 ASSERT_TRUE(result == 1U);
549 ASSERT_TRUE(TC_CoreInstr_LoadStoreExclusive_hword == u16);
551 u32 = __LDREXW(&TC_CoreInstr_LoadStoreExclusive_word);
552 ASSERT_TRUE(u32 == TC_CoreInstr_LoadStoreExclusive_word);
556 result = __STREXW(u32+1U, &TC_CoreInstr_LoadStoreExclusive_word);
557 ASSERT_TRUE(result == 1U);
558 ASSERT_TRUE(TC_CoreInstr_LoadStoreExclusive_word == u32);
560 /* 3. Test exclusives with interruption */
561 TC_CoreInstr_LoadStoreExclusive_IRQEnable();
563 u8 = __LDREXB(&TC_CoreInstr_LoadStoreExclusive_byte);
564 ASSERT_TRUE(u8 == TC_CoreInstr_LoadStoreExclusive_byte);
566 TC_CoreInstr_LoadStoreExclusive_IRQPend();
568 result = __STREXB(u8+1U, &TC_CoreInstr_LoadStoreExclusive_byte);
569 ASSERT_TRUE(result == 1U);
570 u8Inv = (uint8_t)~u8;
571 ASSERT_TRUE(u8Inv == TC_CoreInstr_LoadStoreExclusive_byte);
573 u16 = __LDREXH(&TC_CoreInstr_LoadStoreExclusive_hword);
574 ASSERT_TRUE(u16 == TC_CoreInstr_LoadStoreExclusive_hword);
576 TC_CoreInstr_LoadStoreExclusive_IRQPend();
578 result = __STREXH(u16+1U, &TC_CoreInstr_LoadStoreExclusive_hword);
579 ASSERT_TRUE(result == 1U);
580 u16Inv = (uint16_t)~u16;
581 ASSERT_TRUE(u16Inv == TC_CoreInstr_LoadStoreExclusive_hword);
583 u32 = __LDREXW(&TC_CoreInstr_LoadStoreExclusive_word);
584 ASSERT_TRUE(u32 == TC_CoreInstr_LoadStoreExclusive_word);
586 TC_CoreInstr_LoadStoreExclusive_IRQPend();
588 result = __STREXW(u32+1U, &TC_CoreInstr_LoadStoreExclusive_word);
589 ASSERT_TRUE(result == 1U);
590 u32Inv = (uint32_t)~u32;
591 ASSERT_TRUE(u32Inv == TC_CoreInstr_LoadStoreExclusive_word);
593 TC_CoreInstr_LoadStoreExclusive_IRQDisable();
597 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
598 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
599 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
600 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
601 (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) )
603 /// byte value unprivileged access
604 static volatile uint8_t TC_CoreInstr_LoadStoreUnpriv_byte = 0x47U;
606 /// halfword value unprivileged access
607 static volatile uint16_t TC_CoreInstr_LoadStoreUnpriv_hword = 0x0815U;
609 /// word value unprivileged access
610 static volatile uint32_t TC_CoreInstr_LoadStoreUnpriv_word = 0x08154711U;
615 \brief Test case: TC_CoreInstr_LoadStoreUnpriv
617 Checks load/store unprivileged instructions:
621 void TC_CoreInstr_LoadStoreUnpriv (void) {
622 #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
623 (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
624 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
625 (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) )
630 /* 1. Test without interruption */
631 u8 = __LDRBT(&TC_CoreInstr_LoadStoreUnpriv_byte);
632 ASSERT_TRUE(u8 == TC_CoreInstr_LoadStoreUnpriv_byte);
634 __STRBT(u8+1U, &TC_CoreInstr_LoadStoreUnpriv_byte);
635 ASSERT_TRUE(TC_CoreInstr_LoadStoreUnpriv_byte == u8+1U);
637 u16 = __LDRHT(&TC_CoreInstr_LoadStoreUnpriv_hword);
638 ASSERT_TRUE(u16 == TC_CoreInstr_LoadStoreUnpriv_hword);
640 __STRHT(u16+1U, &TC_CoreInstr_LoadStoreUnpriv_hword);
641 ASSERT_TRUE(TC_CoreInstr_LoadStoreUnpriv_hword == u16+1U);
643 u32 = __LDRT(&TC_CoreInstr_LoadStoreUnpriv_word);
644 ASSERT_TRUE(u32 == TC_CoreInstr_LoadStoreUnpriv_word);
646 __STRT(u32+1U, &TC_CoreInstr_LoadStoreUnpriv_word);
647 ASSERT_TRUE(TC_CoreInstr_LoadStoreUnpriv_word == u32+1U);
651 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
652 #if ((defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) || \
653 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
654 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
656 /// byte value unprivileged access
657 static volatile uint8_t TC_CoreInstr_LoadStoreAcquire_byte = 0x47U;
659 /// halfword value unprivileged access
660 static volatile uint16_t TC_CoreInstr_LoadStoreAcquire_hword = 0x0815U;
662 /// word value unprivileged access
663 static volatile uint32_t TC_CoreInstr_LoadStoreAcquire_word = 0x08154711U;
668 \brief Test case: TC_CoreInstr_LoadStoreAquire
670 Checks Load-Acquire and Store-Release instructions:
674 void TC_CoreInstr_LoadStoreAcquire (void) {
675 #if ((defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) || \
676 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
677 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
682 /* 1. Test without interruption */
683 u8 = __LDAB(&TC_CoreInstr_LoadStoreAcquire_byte);
684 ASSERT_TRUE(u8 == TC_CoreInstr_LoadStoreAcquire_byte);
686 __STLB(u8+1U, &TC_CoreInstr_LoadStoreAcquire_byte);
687 ASSERT_TRUE(TC_CoreInstr_LoadStoreAcquire_byte == u8+1U);
689 u16 = __LDAH(&TC_CoreInstr_LoadStoreAcquire_hword);
690 ASSERT_TRUE(u16 == TC_CoreInstr_LoadStoreAcquire_hword);
692 __STLH(u16+1U, &TC_CoreInstr_LoadStoreAcquire_hword);
693 ASSERT_TRUE(TC_CoreInstr_LoadStoreAcquire_hword == u16+1U);
695 u32 = __LDA(&TC_CoreInstr_LoadStoreAcquire_word);
696 ASSERT_TRUE(u32 == TC_CoreInstr_LoadStoreAcquire_word);
698 __STL(u32+1U, &TC_CoreInstr_LoadStoreAcquire_word);
699 ASSERT_TRUE(TC_CoreInstr_LoadStoreAcquire_word == u32+1U);
703 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
704 #if ((defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) || \
705 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
706 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
708 /// byte value unprivileged access
709 static volatile uint8_t TC_CoreInstr_LoadStoreAcquireExclusive_byte = 0x47U;
711 /// halfword value unprivileged access
712 static volatile uint16_t TC_CoreInstr_LoadStoreAcquireExclusive_hword = 0x0815U;
714 /// word value unprivileged access
715 static volatile uint32_t TC_CoreInstr_LoadStoreAcquireExclusive_word = 0x08154711U;
720 \brief Test case: TC_CoreInstr_LoadStoreAquire
722 Checks Load-Acquire and Store-Release exclusive instructions:
723 - LDAEXB, LDAEXH, LDAEX
724 - STLEXB, STLEXH, STLEX
726 void TC_CoreInstr_LoadStoreAcquireExclusive (void) {
727 #if ((defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) || \
728 (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
729 (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
733 uint32_t result = 0U;
735 /* 1. Test without interruption */
736 u8 = __LDAEXB(&TC_CoreInstr_LoadStoreAcquireExclusive_byte);
737 ASSERT_TRUE(u8 == TC_CoreInstr_LoadStoreAcquireExclusive_byte);
739 result = __STLEXB(u8+1U, &TC_CoreInstr_LoadStoreAcquireExclusive_byte);
740 ASSERT_TRUE(result == 0U);
741 ASSERT_TRUE(TC_CoreInstr_LoadStoreAcquireExclusive_byte == u8+1U);
743 u16 = __LDAEXH(&TC_CoreInstr_LoadStoreAcquireExclusive_hword);
744 ASSERT_TRUE(u16 == TC_CoreInstr_LoadStoreAcquireExclusive_hword);
746 result = __STLEXH(u16+1U, &TC_CoreInstr_LoadStoreAcquireExclusive_hword);
747 ASSERT_TRUE(result == 0U);
748 ASSERT_TRUE(TC_CoreInstr_LoadStoreAcquireExclusive_hword == u16+1U);
750 u32 = __LDAEX(&TC_CoreInstr_LoadStoreAcquireExclusive_word);
751 ASSERT_TRUE(u32 == TC_CoreInstr_LoadStoreAcquireExclusive_word);
753 result = __STLEX(u32+1U, &TC_CoreInstr_LoadStoreAcquireExclusive_word);
754 ASSERT_TRUE(result == 0U);
755 ASSERT_TRUE(TC_CoreInstr_LoadStoreAcquireExclusive_word == u32+1U);
761 \brief Test case: TC_CoreInstr_UnalignedUint16
763 Checks macro functions to access unaligned uint16_t values:
764 - __UNALIGNED_UINT16_READ
765 - __UNALIGNED_UINT16_WRITE
767 void TC_CoreInstr_UnalignedUint16(void) {
768 uint8_t buffer[3] = { 0U, 0U, 0U };
771 for(int i=0; i<2; i++) {
772 __UNALIGNED_UINT16_WRITE(&(buffer[i]), 0x4711U);
773 ASSERT_TRUE(buffer[i] == 0x11U);
774 ASSERT_TRUE(buffer[i+1] == 0x47U);
775 ASSERT_TRUE(buffer[(i+2)%3] == 0x00U);
780 val = __UNALIGNED_UINT16_READ(&(buffer[i]));
781 ASSERT_TRUE(val == 0x4612U);
790 \brief Test case: TC_CoreInstr_UnalignedUint32
792 Checks macro functions to access unaligned uint32_t values:
793 - __UNALIGNED_UINT32_READ
794 - __UNALIGNED_UINT32_WRITE
796 void TC_CoreInstr_UnalignedUint32(void) {
797 uint8_t buffer[7] = { 0U, 0U, 0U, 0U, 0U, 0U, 0U };
800 for(int i=0; i<4; i++) {
801 __UNALIGNED_UINT32_WRITE(&(buffer[i]), 0x08154711UL);
802 ASSERT_TRUE(buffer[i+0] == 0x11U);
803 ASSERT_TRUE(buffer[i+1] == 0x47U);
804 ASSERT_TRUE(buffer[i+2] == 0x15U);
805 ASSERT_TRUE(buffer[i+3] == 0x08U);
806 ASSERT_TRUE(buffer[(i+4)%7] == 0x00U);
807 ASSERT_TRUE(buffer[(i+5)%7] == 0x00U);
808 ASSERT_TRUE(buffer[(i+6)%7] == 0x00U);
815 val = __UNALIGNED_UINT32_READ(&(buffer[i]));
816 ASSERT_TRUE(val == 0x09144612UL);