主函数分析 不管是从什么时候开始,看主函数永远是第一的
void Main(void) { char *mode; int i; U8 key; U32 mpll_val = 0 ; //U32 divn_upll = 0 ; #if ADS10 // __rt_lib_init(); //for ADS 1.0 #endif Port_Init(); Isr_Init(); i = 2 ; //don't use 100M! switch ( i ) { case 0: //200 key = 12; mpll_val = (92<<12)|(4<<4)|(1); break; case 1: //300 key = 13; mpll_val = (67<<12)|(1<<4)|(1); break; case 2: //400 key = 14; mpll_val = (92<<12)|(1<<4)|(1); break; case 3: //440!!! key = 14; mpll_val = (102<<12)|(1<<4)|(1); break; default: key = 14; mpll_val = (92<<12)|(1<<4)|(1); break; } //init FCLK=400M, so change MPLL first ChangeMPllValue((mpll_val>>12)&0xff, (mpll_val>>4)&0x3f, mpll_val&3); ChangeClockDivider(key, 12); cal_cpu_bus_clk(); consoleNum = 0; // Uart 1 select for debug. Uart_Init( 0,115200 ); Uart_Select( consoleNum ); Beep(2000, 100); Uart_SendByte('\n'); Uart_Printf("<***************************************>\n"); Uart_Printf(" TQ2440 Test Program\n"); Uart_Printf(" www.embedsky.net\n"); // Uart_Printf(" Build time is: %s %s\n", __DATE__ , __TIME__ ); Uart_Printf("<***************************************>\n"); rMISCCR=rMISCCR&~(1<<3); // USBD is selected instead of USBH1 rMISCCR=rMISCCR&~(1<<13); // USB port 1 is enabled. rDSC0 = 0x2aa; rDSC1 = 0x2aaaaaaa; //Enable NAND, USBD, PWM TImer, UART0,1 and GPIO clock, //the others must be enabled in OS!!! rCLKCON = 0xfffff0; MMU_Init(); // pISR_SWI=(_ISR_STARTADDRESS+0xf0); //for pSOS Led_Display(0x66); mode="DMA"; Clk0_Disable(); Clk1_Disable(); mpll_val = rMPLLCON; Lcd_TFT_Init() ; // LCD initial download_run=1; //The default menu is the Download & Run mode. while(1) { U8 idx; Uart_Printf("\nPlease select function : \n"); for(i=0; CmdTip[i].fun!=0; i++) Uart_Printf("%d : %s\n", i, CmdTip[i].tip); idx = Uart_GetIntNum_GJ() ; if(idx<i) { (*CmdTip[idx].fun)(); Delay(20); Uart_Init( 0,115200 ); } } }
关键的东西在这里,主函数里面就一些初始化,看看datasheet就过去了,后面才是主要的
void Temp_function() { Uart_Printf("\nPlease input 1-11 to select test!!!\n"); } struct { void (*fun)(void); char *tip; }CmdTip[] = { { Temp_function, "Please input 1-11 to select test" } , { BUZZER_PWM_Test, "Test PWM" } , { RTC_Display, "RTC time display" } , { Test_Adc, "Test ADC" } , { KeyScan_Test, "Test interrupt and key scan" } , { Test_Touchpanel, "Test Touchpanel" } , { Lcd_TFT_Test, "Test TFT LCD" } , { Test_Iic, "Test IIC EEPROM" } , { PlayMusicTest, "UDA1341 play music" } , { RecordTest, "UDA1341 record voice" } , { Test_SDI, "Test SD Card" } , { Camera_Test, "Test CMOS Camera"}, { 0, 0} };