/* * main.c - main C entry * by uratan! 2012.10.9 */ //#define __MAIN_C__ /* <== inform common.h to alloc variables */ #include "common.h" #include "LPC1830.h" /* * reset myself if SPIFI is configured unproperly */ #define ENABLE_SPIFI_RETRY 0 /* * */ typedef VOLATILE unsigned char v_u_c; /* * functions */ int main(void); void nops(void); void Exception_Handler(void) __attribute__ ((interrupt)); void NMI_Handler(void) __attribute__ ((interrupt)); void HardFault_Handler(void) __attribute__ ((interrupt)); void MemManage_Handler(void) __attribute__ ((interrupt)); void BusFault_Handler(void) __attribute__ ((interrupt)); void UsageFault_Handler(void) __attribute__ ((interrupt)); void SVCall_Handler(void) __attribute__ ((interrupt)); void DebugMon_Handler(void) __attribute__ ((interrupt)); void PendSV_Handler(void) __attribute__ ((interrupt)); void SysTick_Handler(void) __attribute__ ((interrupt)); /* in spifi.c */ extern void spifi_c_init(void); extern void spifi_set_clock(int try_18MHz); extern int spifi_initial_flash(void); /* * */ int main(void) { u_char c; int i, m; /* * setup LED2(green) and LED3(blue), and P2_7, P1_8, etc */ cm_initial_GPIO(); cm_init_uart(57600); /* * use GPIO3[5] (P6_9) for monitor */ #define SCU_SFS_P6_9 *(_v_u_l *)(LPC_SCU_BASE + 0x324) #define GPIO3_DIR *(_v_u_l *)(LPC_GPIO_BASE + 0x00c) #define GPIO3_SET *(_v_u_l *)(LPC_GPIO_BASE + 0x20c) #define GPIO3_CLR *(_v_u_l *)(LPC_GPIO_BASE + 0x28c) #define GPIO3_NOT *(_v_u_l *)(LPC_GPIO_BASE + 0x30c) #define G3_5_MONI (1 <<5) SCU_SFS_P6_9 = SFS_FUNC_0 | SFS_DisPUP | SFS_EnINPUT; GPIO3_DIR |= G3_5_MONI; GPIO3_SET = G3_5_MONI; rprintf( "" "\r\n" "/*" "\r\n" " * test SPIFI-flash" "\r\n" " */" "\r\n" "" "\r\n" ); rprintf("run @ 0x%08x (M3_MEMMAP: 0x%08x)\r\n", (u_long)main, M3_MEMMAP); rprintf("\r\n"); if(M3_MEMMAP >= 0x80000000) { /* * booted from SPIFI, confirm SPIFI initialization properness */ rprintf("IDIVB_CTRL is: 0x%08x\r\n", IDIVB_CTRL); #if ENABLE_SPIFI_RETRY if(IDIVB_CTRL != 0x09000820) { VOLATILE u_long t; rprintf("retry SPIFI\r\n"); for(t=0; t auto-clear */ while(1) ; } #endif /* ENABLE_SPIFI_RETRY */ } else { /* * maybe booted from USART3 */ spifi_c_init(); spifi_set_clock(/*try_18MHz=*/ 1); spifi_initial_flash(); } rprintf("select test\r\n"); while(1) { GPIO3_SET = G3_5_MONI; c = cm_getchar(); switch(c) { case 'c': rprintf("clear cache\r\n"); for(i=0; i<256; i++) { m = *(v_u_c *)(0x80100000 + i); } break; case '1': rprintf("test #1\r\n"); GPIO3_CLR = G3_5_MONI; for(i=0; i<16; i++) { m = *(v_u_c *)(0x80000000 + i); GPIO3_NOT = G3_5_MONI; } break; case '2': rprintf("test #2\r\n"); GPIO3_CLR = G3_5_MONI; for(i=0; i<16*16; i+=16) { m = *(v_u_c *)(0x80000000 + i); GPIO3_NOT = G3_5_MONI; } break; case '3': rprintf("test #3\r\n"); GPIO3_CLR = G3_5_MONI; for(i=0; i<16*16; i+=16) { m = *(v_u_c *)(0x8000000f + i); GPIO3_NOT = G3_5_MONI; } break; case '4': rprintf("test #4\r\n"); GPIO3_CLR = G3_5_MONI; for(i=0; i<16*8; i+=8) { m = *(v_u_c *)(0x80000000 + i); GPIO3_NOT = G3_5_MONI; } break; case '5': rprintf("test #5\r\n"); GPIO3_CLR = G3_5_MONI; for(i=0; i<16*8; i+=8) { m = *(v_u_c *)(0x80000007 + i); GPIO3_NOT = G3_5_MONI; } break; case 'z': rprintf("clear cache-z\r\n"); for(i=0; i<256; i++) { m = *(v_u_c *)(0x14100000 + i); } break; case 'a': rprintf("test #1a\r\n"); GPIO3_CLR = G3_5_MONI; for(i=0; i<16; i++) { m = *(v_u_c *)(0x14000000 + i); GPIO3_NOT = G3_5_MONI; } break; case 's': rprintf("test #2s\r\n"); GPIO3_CLR = G3_5_MONI; for(i=0; i<16*16; i+=16) { m = *(v_u_c *)(0x14000000 + i); GPIO3_NOT = G3_5_MONI; } break; case 'd': rprintf("test #3d\r\n"); GPIO3_CLR = G3_5_MONI; for(i=0; i<16*16; i+=16) { m = *(v_u_c *)(0x1400000f + i); GPIO3_NOT = G3_5_MONI; } break; case 'n': rprintf("run nops()\r\n"); GPIO3_CLR = G3_5_MONI; while(1) { nops(); GPIO3_NOT = G3_5_MONI; } break; /* never */ default: break; } } /* never return */ } /* * */ void nops(void) { /* 256 bytes of nops to fill full of cache */ __asm("nop;nop;nop;nop;nop;nop;nop;nop;"); __asm("nop;nop;nop;nop;nop;nop;nop;nop;"); __asm("nop;nop;nop;nop;nop;nop;nop;nop;"); __asm("nop;nop;nop;nop;nop;nop;nop;nop;"); __asm("nop;nop;nop;nop;nop;nop;nop;nop;"); __asm("nop;nop;nop;nop;nop;nop;nop;nop;"); __asm("nop;nop;nop;nop;nop;nop;nop;nop;"); __asm("nop;nop;nop;nop;nop;nop;nop;nop;"); __asm("nop;nop;nop;nop;nop;nop;nop;nop;"); __asm("nop;nop;nop;nop;nop;nop;nop;nop;"); __asm("nop;nop;nop;nop;nop;nop;nop;nop;"); __asm("nop;nop;nop;nop;nop;nop;nop;nop;"); __asm("nop;nop;nop;nop;nop;nop;nop;nop;"); __asm("nop;nop;nop;nop;nop;nop;nop;nop;"); __asm("nop;nop;nop;nop;nop;nop;nop;nop;"); __asm("nop;nop;nop;nop;nop;nop;nop;nop;"); /* a little more */ __asm("nop;nop;nop;nop;nop;nop;nop;nop;"); } /* =============================================================== */ /* * try to catch exceptions */ void Exception_Handler(void) { rprintf("! some Exception\r\n"); while(1) ; /* never return */ } void NMI_Handler(void) { rprintf("! NMI\r\n"); while(1) ; /* never return */ } void HardFault_Handler(void) { rprintf("! HardFault\r\n"); while(1) ; /* never return */ } void MemManage_Handler(void) { rprintf("! MemManage\r\n"); while(1) ; /* never return */ } void BusFault_Handler(void) { rprintf("! BusFault\r\n"); while(1) ; /* never return */ } void UsageFault_Handler(void) { rprintf("! UsageFault\r\n"); while(1) ; /* never return */ } void SVCall_Handler(void) { rprintf("! SVCall\r\n"); while(1) ; /* never return */ } void DebugMon_Handler(void) { rprintf("! DebugMon\r\n"); while(1) ; /* never return */ } void PendSV_Handler(void) { rprintf("! PendSV\r\n"); while(1) ; /* never return */ } void SysTick_Handler(void) { rprintf("! SysTick\r\n"); while(1) ; /* never return */ } /* =============================================================== */