uint8 InitDevice()//TODO:异常处理 { uint8 r=0,t=0; //GPIO PinInit(); IO0DIR=1<<29|1<<30;//P0.29,P0.30必须同为输出才能输出(SSP0的片选). //GpioSpeedHigh();//全局高速模式,因为P0.29问题无法使用。 //指示系统启动 LED1ON(); //UART0-GCS r+=UARTInit(FCUARTPORT,FCUARTBPS);//UART0-PC UARTSendChar(FCUARTPORT,0x40); UARTSendChar(FCUARTPORT,0x40); //UART2-INS r+=UARTInit(INSUARTPORT,INSUARTBPS); //UARTSendChar(2,0x40); //UARTSendChar(2,0x40); //SSP0-FPGA r+=SSP0FPGAMode(); //r+=SPIInit(); //while(1) //{ t=FPGACheck(); //} if(t==TRUE) { FCEventSend(OKFPGA); } else { FCEventSend(ErrFPGA); } r+=t; //SSP1-FLASH r+=FlashInit(FlashQueueSize); //Timer0-MainLoop r+=TimerInit(0,1000/MainLoopHz); TimerDisable(0); //TimerEnable(0); //Timer1-Time+LED1 r+=TimerInit(1,1000); TimerEnable(1); //Timer2-Working-LED2 r+=TimerInit(2,100); TimerDisable(2); //启动中断 IRQEnable(); return r; }
/* description: initial the timer0 // function: void Timer0Init (void) // @param: //return value: */ void Timer0Init (void) { T0IR = 0xffffffff; //clear all the interrupt flag T0TCR = 0x03; //open the counter and reset it T0TC = 0; T0PR = 0; T0MCR = 0x03; //when MRO=TC,give interrupt and clear TC T0MR0 = (Fpclk / 2500); T0TCR = 0x01; IRQEnable(); vicIrqFuncSet(4,0,(INT32U)Timer0_Handler); }