150 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			150 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
/****************************************************************************
 | 
						|
 | 
						|
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
 | 
						|
 | 
						|
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
 | 
						|
be copied by any method or incorporated into another program without
 | 
						|
the express written consent of Aerospace C.Power. This Information or any portion
 | 
						|
thereof remains the property of Aerospace C.Power. The Information contained herein
 | 
						|
is believed to be accurate and Aerospace C.Power assumes no responsibility or
 | 
						|
liability for its use in any way and conveys no license or title under
 | 
						|
any patent or copyright and makes no representation or warranty that this
 | 
						|
Information is free from patent or copyright infringement.
 | 
						|
 | 
						|
****************************************************************************/
 | 
						|
/* os shim includes */
 | 
						|
#include "os_types.h"
 | 
						|
#include "os_task.h"
 | 
						|
#include "os_utils.h"
 | 
						|
 | 
						|
/* common includes */
 | 
						|
#include "iot_io.h"
 | 
						|
#include "iot_bitops.h"
 | 
						|
#include "iot_pkt_api.h"
 | 
						|
#include "iot_ipc.h"
 | 
						|
#include "iot_plc_lib.h"
 | 
						|
#include "iot_dbglog_api.h"
 | 
						|
#include "iot_config.h"
 | 
						|
 | 
						|
/* driver includes */
 | 
						|
#include "iot_clock.h"
 | 
						|
#include "iot_uart.h"
 | 
						|
 | 
						|
/* cli includes */
 | 
						|
#include "iot_cli.h"
 | 
						|
 | 
						|
/* debug includes*/
 | 
						|
#include "dbg_io.h"
 | 
						|
 | 
						|
typedef void (*jump)(void);
 | 
						|
 | 
						|
void div_zero()
 | 
						|
{
 | 
						|
    int a = 0;
 | 
						|
    int b = 1;
 | 
						|
    int c;
 | 
						|
    c = b/a;
 | 
						|
    iot_printf("div zero : c=%d\r\n", c);
 | 
						|
}
 | 
						|
 | 
						|
void invalid_addr_access()  // mcause: 5/7 load/store address fault
 | 
						|
{
 | 
						|
    int *buf = (int *)0x90000000;
 | 
						|
    //*buf = 0xaabbccdd;
 | 
						|
    iot_printf("align test a: %08x\r\n", *(buf));
 | 
						|
}
 | 
						|
 | 
						|
void misalign_access()    // mcause: 4/6 load/store address misaligned
 | 
						|
{
 | 
						|
    uint32_t *a = (uint32_t *) 0x1003ffd1;
 | 
						|
    //*a = 0xaabb;
 | 
						|
    //*(a+1) = 0xccdd;
 | 
						|
    iot_printf("align test a: %08x\r\n", *(a));
 | 
						|
    iot_printf("align test a: %08x\r\n", *(a+1));
 | 
						|
}
 | 
						|
 | 
						|
void instruction_illegal()   // mcause: 2  illegal instruction
 | 
						|
{
 | 
						|
    void (*pgm_start)(void) = (void*) 0x001003d1;
 | 
						|
    pgm_start();
 | 
						|
}
 | 
						|
 | 
						|
void invalid_instruction_access()  // mcause: 1 instruction fault
 | 
						|
{
 | 
						|
    void (*pgm_start)(void) = (void*) 0x80000040;
 | 
						|
    pgm_start();
 | 
						|
}
 | 
						|
 | 
						|
void instruction_misalign()
 | 
						|
{
 | 
						|
    int a = 10;
 | 
						|
    iot_printf("a=%d\n", a);
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
void back_d()
 | 
						|
{
 | 
						|
    iot_printf("back 4.......\r\n");
 | 
						|
    misalign_access();
 | 
						|
}
 | 
						|
 | 
						|
struct test_t {
 | 
						|
    void (*callback)(void);
 | 
						|
};
 | 
						|
 | 
						|
struct test_t g_test = {0};
 | 
						|
 | 
						|
void back_c()
 | 
						|
{
 | 
						|
    iot_printf("back 3.......\r\n");
 | 
						|
    g_test.callback = back_d;
 | 
						|
    g_test.callback();
 | 
						|
}
 | 
						|
 | 
						|
void back_b()
 | 
						|
{
 | 
						|
    iot_printf("back 2.......\r\n");
 | 
						|
    back_c();
 | 
						|
}
 | 
						|
 | 
						|
void back_a()
 | 
						|
{
 | 
						|
    iot_printf("back 1.......\r\n");
 | 
						|
    back_b();
 | 
						|
}
 | 
						|
 | 
						|
void trap_back_test()
 | 
						|
{
 | 
						|
    back_a();
 | 
						|
}
 | 
						|
 | 
						|
int main(void)
 | 
						|
{
 | 
						|
  dbg_uart_init();
 | 
						|
   int i = 100;
 | 
						|
   int a = 100;
 | 
						|
   int b = 10;
 | 
						|
   int c = 100;
 | 
						|
   int d = 100;
 | 
						|
   iot_printf("%d %d %d %d %d\r\n", a,b,c,d,i);
 | 
						|
 | 
						|
   //trap_back_test();
 | 
						|
 | 
						|
  int j = 0;
 | 
						|
   while(i)
 | 
						|
   {
 | 
						|
        //div_zero();
 | 
						|
        //invalid_instruction_access();  // mcause: 1
 | 
						|
        //instruction_illegal();          // mcause: 2
 | 
						|
        //misalign_access();            // mcause: 6
 | 
						|
        //invalid_addr_access();        // mcause: 7
 | 
						|
        //instruction_misalign();
 | 
						|
        
 | 
						|
        iot_printf("count i: %d\r\n", i);
 | 
						|
 | 
						|
        for(j = 0; j<10000;j++);
 | 
						|
        i--;
 | 
						|
   }
 | 
						|
   return 0;
 | 
						|
}
 |