forked from SZV10X_Software/SZV103_FM33A0xxEV_SiZhu

jinlicong
2024-05-29 6c7e61a54ef9b96f79704f0b965664e89f57dd52
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
 * fault_test.c
 *
 *  Created on: 2016/12/25
 *      Author: Armink
 */
 
#include <stdio.h>
 
 
 
void fault_test_by_unalign(void) {
    volatile int * SCB_CCR = (volatile int *) 0xE000ED14; // SCB->CCR
    volatile int * p;
    volatile int value;
 
    *SCB_CCR |= (1 << 3); /* bit3: UNALIGN_TRP. */
 
    p = (int *) 0x00;
    value = *p;
    printf("addr:0x%02X value:0x%08X\r\n", (int) p, value);
 
    p = (int *) 0x04;
    value = *p;
    printf("addr:0x%02X value:0x%08X\r\n", (int) p, value);
 
    p = (int *) 0x03;
    value = *p;
    printf("addr:0x%02X value:0x%08X\r\n", (int) p, value);
}
 
void fault_test_by_div0(void) {
    volatile int * SCB_CCR = (volatile int *) 0xE000ED14; // SCB->CCR
    int x, y, z;
 
    *SCB_CCR |= (1 << 4); /* bit4: DIV_0_TRP. */
 
    x = 10;
    y = 0;
    z = x / y;
    printf("z:%d\n", z);
}