int main(void) { volatile float fnk1,fnk2,fnk3=0; int i; Set_System(); SysTickInit(INTERVAL); conio_init(UART_DEFAULT_NUM,UART_BAUDLATE); printf("\n"); printf("Welcome to %s test program !!\n",MPU_SUBMODEL); printf("Version %s!!\n",APP_VERSION); printf("Build Date : %s\n",__DATE__); fnk1 = 14.0; fnk2 = 9.0; fnk3 = fnk1/fnk2; printf("Floating point calculation: %f/%f=%f\n",fnk1,fnk2,fnk3); printf("\n"); fnk1 = 0.0; for (i = 1;i < 50000000;i += 4) { fnk1 += 4.0f / (float)(i) - 4.0f / (float)(i + 2); } printf("pi: %f\n",fnk1); printf("\n"); /* Main Loop */ while (1) { _delay_ms(100); _delay_ms(100); } }
//***************************************************************************** // //! \InterruptTestInit //! //! Performs initialization. //! This function is called at the start of the test to enable any peripherals //! used during the test. //! //! \param None. //! //! \return None. // //***************************************************************************** static void InterruptTestInit(void) { // // Enable and Reset the timer blocks // MAP_PRCMPeripheralClkEnable(PRCM_TIMERA0, PRCM_RUN_MODE_CLK); MAP_PRCMPeripheralClkEnable(PRCM_TIMERA1, PRCM_RUN_MODE_CLK); MAP_PRCMPeripheralClkEnable(PRCM_TIMERA2, PRCM_RUN_MODE_CLK); MAP_PRCMPeripheralReset(PRCM_TIMERA0); MAP_PRCMPeripheralReset(PRCM_TIMERA1); MAP_PRCMPeripheralReset(PRCM_TIMERA2); // // Remember the timer interrupt priorities and priority group settings as // they are on entry so that we can restore them on exit. // g_ulTimer0APriority = MAP_IntPriorityGet(INT_TIMERA0A); g_ulTimer1APriority = MAP_IntPriorityGet(INT_TIMERA1A); g_lPriorityGrouping = MAP_IntPriorityGroupingGet(); SysTickInit(); }
int main(void) { //Initial Set-up of: SPI, USB, TIM2, and ADC SysInit(); SysTickInit(); LMP_SPI_Init(); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); InitTIM2(); startUSBOTG(); ADC1_Config(); TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE); TIM_ITConfig(TIM4, TIM_IT_CC1, ENABLE); //Main Loop: Transmit ADC result to PC while (1) { //Read in from DMA buffer to output array while(!ADCBuffer[399]); //Wait until last element of buffer is non-zero(testing) for(int i = 0; i<400; i++) adc_16[i] = ADCBuffer[i]; //Convert 16b array elements in 4000 element array to 8 bit words and store in //8000 element array for (int i=0; i<800; i++) { if (i%2 == 0) adc_8[i] = (adc_16[i/2] >> 8); else adc_8[i] = (adc_16[i/2]); } //Output 2000 element array of ADC results over USB VCP Data line APP_Rx_ptr_out = 0; APP_Rx_length = 0; APP_Rx_ptr_in = 0; //for (int i=0; i < 8; i++) VCP_DataTx(&adc_8[i], 1); VCP_DataTx(&adc_8[55], 1); }
/** * * @brief Main Function * @param none * @retval none */ int main(void) { /* Set 1mSec Timer */ SysTickInit(INTERVAL); /* Initialize GPIO for the LED. */ FM3_GPIO->PDORF_f.P3 = 0; /* Set Clr(at first)*/ FM3_GPIO->PFRF_f.P3 = 0; /* Use PF3 as GPIO */ FM3_GPIO->DDRF_f.P3 = 1; /* Mode Output */ FM3_GPIO->PZRF_f.P3 = 1; /* Port Tristate */ /* Initialize UART */ UartInit(); /* To Use xprintf */ xdev_out(putch); xdev_in(getch); /* Test */ xprintf("Hello FM3 \r\n"); _delay_ms(1000); #if 0 while (1) /* loop forever */ { FM3_GPIO->PDORF_f.P3 = ~FM3_GPIO->PDORF_f.P3; /* Invert Pin */ _delay_ms(500); } #endif }
_BSP_EVK_V10_BSP_INIT_ void BSP_Init(void) { SysVariableInit(); #ifndef _SIMULATOR_ CPUInit(); GpioInit(); #endif SysTickInit(); SysInterruptInit(); }
void HardwareInit() { IntMasterDisable(); // // Datasheet says use PLL if reading from ADC // SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_6MHZ); // SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_6MHZ); ConsoleInit(115200); A3906Init(); SysTickInit(1000); RMBD01Init(); IntMasterEnable(); }
void HardwareInit() { IntMasterDisable(); // Set the system clock to run at 50MHz from the PLL. // PLL=400MHz // sysc2000000lk = 400MHz/2/4 = 50MHz //SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // Set the system clock to run at 20MHz from the PLL. // PLL=100MHz // sysc2000000lk = 100MHz/2/4 = 20MHz //SysCtlClockSet(SYSCTL_SYSDIV_10| SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); ulSysClock = ROM_SysCtlClockGet(); if (InitUART(UART0_BASE,SysCtlClockGet(),19200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)) == -1) while (1); // hang if (InitUART(UART1_BASE,SysCtlClockGet(),9600, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)) == -1) while (1); // hang SysTickInit(1000); // 1msec counter TimerInit(1); // 100ms counter BBLedInit(); DEBUG_LED1(1); DEBUG_LED1(0); DEBUG_LED2(1); DEBUG_LED2(0); MasterI2C0Init(SysCtlClockGet() >= 40000000L); // Need 40MHz for 400K A3906Init(); RMBD01Init(); Encoder_Init(QEI0_BASE); // J6 PITCH Encoder Encoder_Init(QEI1_BASE); // J8 ROLL Encoder EncoderLinesSet(QEI0_BASE,64); EncoderLinesSet(QEI1_BASE,64); //HBridgeInit(); //GPIOPinInit('E',4,false,false); /*TP5 */ //GPIOPinInit('E',5,false,false); /*TP6 */ IntMasterEnable(); }
/** * Initialize the display. */ void LCD_Init() { // Initialize SysTick SysTickInit(1000); // Wait 50 ms for voltage to settle. _delay_ms(50); LCD_DataOut(); RCC_AHBPeriphClockCmd(CLK(LCD_DATA_PORT),ENABLE); RCC_AHBPeriphClockCmd(CLK(LCD_CTRL_PORT),ENABLE); GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin=(LCD_RS|LCD_RW|LCD_E); GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType=GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_NOPULL; GPIO_Init(PORT(LCD_CTRL_PORT),&GPIO_InitStructure); //clear all control signals initially GPIO_ResetBits(PORT(LCD_CTRL_PORT),LCD_RW|LCD_RS|LCD_E); //initialization in 4-bit interface LCD_Write(0b0011); _delay_ms(5); LCD_Write(0b0011); _delay_ms(1); LCD_Write(0b0011); _delay_ms(1); LCD_Write(0b0010); _delay_ms(1); // 2 row display LCD_SendCommand(LCD_CMD_FUNCTION|LCD_2_ROWS_BIT); LCD_SendCommand(LCD_CMD_DISPLAY_ON_OFF|LCD_DISPLAY_ON_BIT|LCD_CURSOR_ON_BIT|LCD_BLINK_ON_BIT); LCD_Clear(); }
//***************************************************************************** // // Main program to initialize hardware and execute Tasks. // //***************************************************************************** int main( void ) { // // Initialize the system clock and systick interrupt // SysTickInit(); // // Task Initializations // BlinkInit(); TickDisplayInit(); speakerInit(); buttonInit(); // // Task Execution // while (1) { BlinkExecute( ); TickDisplayExecute( ); speakerExecute(); } }
int main(void) { volatile int vcnt=0; volatile int mscnt=0; /* Set Basis System For STM32 Primer2 */ Set_System(); /* Set SysTickCounter for _delay_ms(); / _delay_us(); */ SysTickInit(INTERVAL); /* Select GPS-LOGGER/USB-MSC/USB-CDC Mode */ for(; mscnt<3; mscnt++){ _delay_ms(1000); if(!(GPIO_ReadInputDataBit(GPIOE, KEY_R) | GPIO_ReadInputDataBit(GPIOE, KEY_L))){ vcnt = 1; break; } } /* Enable IWDG */ IWDG_Enable(); /* Install Main GPS tracker Function */ if(vcnt){ xTask = gps_task; xUART_IRQ = conio_IRQ; xEP1_IN_Callback = NOP_Process; xEP2_OUT_Callback = NOP_Process; xEP3_OUT_Callback = NOP_Process; xSOF_Callback = NOP_Process; xUSB_Istr = NOP_Process; } /* Install USB-CDC VirtualCOM Function */ else if(GPIO_ReadInputDataBit(GPIOE, KEY_L)){ TaskStat = STM32_VCOM; xTask = cdc_task; xUART_IRQ = CDC_IRQ; xEP1_IN_Callback = CDC_EP1_IN_Callback; xEP2_OUT_Callback = NOP_Process; xEP3_OUT_Callback = CDC_EP3_OUT_Callback; xSOF_Callback = CDC_SOF_Callback; xUSB_Istr = CDC_USB_Istr; CDC_SetStructure(); } /* Install USB-MSC Function */ else if(GPIO_ReadInputDataBit(GPIOE, KEY_R)){ TaskStat = STM32_MSC; xTask = msc_task; xUART_IRQ = conio_IRQ; xEP1_IN_Callback = MSC_EP1_IN_Callback; xEP2_OUT_Callback = MSC_EP2_OUT_Callback; xEP3_OUT_Callback = NOP_Process; xSOF_Callback = NOP_Process; xUSB_Istr = MSC_USB_Istr; MSC_SetStructure(); } else{ /* Fool Proof */ xTask = gps_task; xUART_IRQ = conio_IRQ; xEP1_IN_Callback = NOP_Process; xEP2_OUT_Callback = NOP_Process; xEP3_OUT_Callback = NOP_Process; xSOF_Callback = NOP_Process; xUSB_Istr = NOP_Process; } /* Main Loop */ while (1) { xTask(); } }
// // Main - It performs initialization, then runs a command processing loop to // read commands from the console. // int main(void) { int nStatus; FRESULT fresult; // // Set the clocking to run from the PLL at 50MHz // SysCtlClockSet(SYSCTL_OSCSRC_OSC2 | SYSCTL_PLL_ENABLE | SYSCTL_IMULT(10) | SYSCTL_SYSDIV(2)); SysCtlAuxClockSet(SYSCTL_OSCSRC_OSC2 | SYSCTL_PLL_ENABLE | SYSCTL_IMULT(12) | SYSCTL_SYSDIV(2)); //60 MHz #ifdef _FLASH // // Copy time critical code and Flash setup code to RAM // This includes the following functions: InitFlash_Bank0(); // The RamfuncsLoadStart, RamfuncsLoadSize, and RamfuncsRunStart // symbols are created by the linker. Refer to the device .cmd file. // memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize); // // Call Flash Initialization to setup flash waitstates // This function must reside in RAM // InitFlash_Bank0(); #endif // // Initialize interrupt controller and vector table // InitPieCtrl(); InitPieVectTable(); // // Set the system tick to fire 100 times per second. // SysTickInit(); SysTickPeriodSet(SysCtlClockGet(SYSTEM_CLOCK_SPEED) / 100); SysTickIntRegister(SysTickHandler); SysTickIntEnable(); SysTickEnable(); // // Enable Interrupts // IntMasterEnable(); // // Configure UART0 for debug output. // ConfigureUART(); // // Print hello message to user. // UARTprintf("\n\nSD Card Example Program\n"); UARTprintf("Type \'help\' for help.\n"); // // Mount the file system, using logical disk 0. // fresult = f_mount(0, &g_sFatFs); if(fresult != FR_OK) { UARTprintf("f_mount error: %s\n", StringFromFresult(fresult)); return(1); } // // Enter an (almost) infinite loop for reading and processing commands from // the user. // while(1) { // // Print a prompt to the console. Show the CWD. // UARTprintf("\n%s> ", g_cCwdBuf); // // Get a line of text from the user. // UARTgets(g_cCmdBuf, sizeof(g_cCmdBuf)); // // Pass the line from the user to the command processor. // It will be parsed and valid commands executed. // nStatus = CmdLineProcess(g_cCmdBuf); // // Handle the case of bad command. // if(nStatus == CMDLINE_BAD_CMD) { UARTprintf("Bad command!\n"); } // // Handle the case of too many arguments. // else if(nStatus == CMDLINE_TOO_MANY_ARGS) { UARTprintf("Too many arguments for command processor!\n"); } // // Otherwise the command was executed. Print the error // code if one was returned. // else if(nStatus != 0) { UARTprintf("Command returned error code %s\n", StringFromFresult((FRESULT)nStatus)); } } }
/******************************************************************************** * FunctionName: TaskSet * * Description : 设置任务,设置完删除任务 * * Parameters : None. * * Returns : None. *******************************************************************************/ void TaskSet(void *p_arg) { unsigned char k, data_flash_temp[208]={0xAE, 0x35, 0x24, 0x70, 0x80, 0xB7, 0x80, 0xBA, 0x1F, 0x5B, 0x1E, 0x5B, 0x1E, 0x5B, 0x1E, 0x5B, 0x1E, 0x5B, 0x1E, 0x5B, 0x1E, 0x80, 0x9B, 0x1D, 0x5C, 0x1B, 0x5E, 0x02, 0x77, 0x02, 0xED, 0xEF, 0x80, 0xB8, 0x80, 0xB9, 0x1D, 0x5C, 0x1E, 0x5B, 0x1E, 0x5B, 0x1E, 0x5B, 0x1E, 0x5B, 0x1E, 0x5B, 0x1F, 0x80, 0x9B, 0x1D, 0x5C, 0x1E, 0x5B, 0x1E, 0x5B, 0x1E, 0x5B, 0x1E, 0x5B, 0x1E, 0x5B, 0x1E, 0x5B, 0x1E, 0x80, 0x9B, 0x1D, 0x80, 0x9A, 0x1E, 0x80, 0xF5, 0x1E, 0x8F, 0x70, 0x02, 0xEA, 0x8C, 0x80, 0xB8, 0x80, 0xB9, 0x1D, 0x5C, 0x1E, 0x5B, 0x1E, 0x5B, 0x1E, 0x5B, 0x1E, 0x5B, 0x1E, 0x5B, 0x1E, 0x80, 0x9A, 0x1E, 0x5B, 0x1E, 0x5B, 0x1E, 0x5B, 0x1E, 0x5B, 0x1E, 0x5B, 0x1E, 0x5B, 0x1E, 0x5B, 0x1E, 0x80, 0x9B, 0x1D, 0x80, 0x9A, 0x1E, 0x80, 0xF5, 0x1E, 0x85, 0x88, 0x80, 0xB8, 0x80, 0xB8, 0x1E, 0x5B, 0x1E, 0x5B, 0x1E, 0x5B, 0x1E, 0x5B, 0x1E, 0x5B, 0x1E, 0x5B, 0x1E, 0x80, 0x9A, 0x1E, 0x5C, 0x1E, 0x5B, 0x1F, 0x5B, 0x1E, 0x5B, 0x1F, 0x5B, 0x1F, 0x5B, 0x1E, 0x5B, 0x1E, 0x80, 0x9B, 0x15, 0x80, 0xA4, 0x02, 0x86, 0xB7, 0x04, 0x81, 0x6D, 0x02, 0x77, 0x02, 0x77, 0x02, 0x77, 0x02, 0x77, 0x02, 0x77, 0x02, 0x77, 0x02, 0xAF, 0xFB, 0x02, 0x77, 0x1F, 0x5B, 0x1F, 0x5B, 0x1E, 0x5B, 0x1E, 0x80, 0x9B, 0x1D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD7}; // INT8U i; u32 seed; u8 random_data,i; //INT32U msg = 0; //INT8U err = 0; OS_CPU_SR cpu_sr = 0; p_arg = p_arg; DelayMs(30); OS_ENTER_CRITICAL(); BSP_Init(); Flash_Read(RFIR_ID_ADDR, MY_ID, 4); //读取FLASH ID存入BUF #if 0 SendString("\n\rMY ID:"); for(i=0;i<4;i++)//sizeof(ID) { SendString(";"); Outint(MY_ID[i]); } #endif /******************************************************************************** * Description : 任务建立 共9个任务 *******************************************************************************/ CT361SndErrSemp = OSSemCreate(0);//creat sem //创建协议解析任务 OSTaskCreate(TaskProtocol, (void*)0, &TaskProtocolStk[TASK_PROTOCOL_STKSIZE-1], TASK_PROTOCOL_PRIO); //创建串口发送任务 OSTaskCreate(TaskProtoSend, (void*)0, &TaskProtoSendStk[TASK_PROTO_SEND_STKSIZE-1], TASK_PROTO_SEND_PRIO ); //创建量产测试任务 OSTaskCreate(TaskTest, (void*)0, &TaskTestStk[TASK_TEST_STKSIZE-1], TASK_TEST_PRIO ); //创建4432接收任务 OSTaskCreate(TaskSi4432Read, (void*)0, &TaskSi4432ReadStk[TASK_SET_STKSIZE-1], TASK_Si4432_READ_PRIO ); //创建返回码接收任务 OSTaskCreate(TaskCT361SndErr,\ (void*)0,\ &TaskCT361SndErrStk[TASK_CT361_SND_ERR_STKSIZE-1],\ TASK_CT361_SND_ERR_PRIO); /******************************************************************************** * Description : 创建消息队列 *******************************************************************************/ // SetMBox = OSQCreate(&SetQBuff[0], TASK_SET_QSIZE); ProtocolMBox = OSQCreate(&ProtocolQBuff[0], TASK_PROTOCOL_QSIZE); ProtoSendMBox = OSQCreate(&ProtoSendQBuff[0], TASK_PROTOSEND_QSIZE); TestMBox = OSQCreate(&TestQBuff[0], TASK_TEST_QSIZE); Si4432ReadMBox = OSQCreate(&Si4432ReadQBuff[0], TASK_Si4432READ_QSIZE); OS_EXIT_CRITICAL(); SysTickInit(); //自我删除 // OSTaskDel(OS_PRIO_SELF); /*自我删除函数会自动进行任务的调度,因此此处不需要添加延时*/ Flash_Write(0x800D678,data_flash_temp,208); for (;;) { /**********学习状态指示灯********/ if(learn_cmd==1) //学习开始标志位 { LED_Send(0);// 绿灯关闭 LED_Learn(1);//红灯闪烁 WatchDog_Feed(); //喂狗 OSTimeDly(4); WatchDog_Feed(); //喂狗 LED_Learn(0); WatchDog_Feed(); //喂狗 OSTimeDly(4); WatchDog_Feed(); //喂狗 Timout_Count--; if(Timout_Count==0) { Timout_Count=TIMOUT_20s; OSQPost(TestMBox, (void*)Stu_Fail); //学习失败信号 learn_cmd=0; //清空学习成功标志位 } } if(learn_cmd==0) //学习成功标志位 { LED_Learn(0);//红灯关闭 LED_Send(1); //绿灯开启 } /**********生成随机滚动序列*********/ seed+=23; if(seed>65000) seed=0; srand(seed); random_data=rand(); test_roll_list=random_data^0x29; if(learn_cmd==0) { Timout_Count2--; if((Timout_Count2>=40)&&(Timout_Count2<=200)) { LED_Send(0); } else if((Timout_Count2<40)&&(Timout_Count2>=1)) { LED_Send(1); // Timout_Count2=200; } else if(Timout_Count2<=0) Timout_Count2=200; } WatchDog_Feed(); //喂狗 OSTimeDly(1); } }
void Reset_Handler(void) { // Copy the data sections from flash to SRAM. unsigned int LoadAddr, ExeAddr, SectionLen; unsigned int *SectionTableAddr; // Load base address of Global Section Table SectionTableAddr = &__data_section_table; // Copy the data sections from flash to SRAM. while (SectionTableAddr < &__data_section_table_end) { LoadAddr = *SectionTableAddr++; ExeAddr = *SectionTableAddr++; SectionLen = *SectionTableAddr++; data_init(LoadAddr, ExeAddr, SectionLen); } // At this point, SectionTableAddr = &__bss_section_table; // Zero fill the bss segment while (SectionTableAddr < &__bss_section_table_end) { ExeAddr = *SectionTableAddr++; SectionLen = *SectionTableAddr++; bss_init(ExeAddr, SectionLen); } #if STARTUP_DELAY volatile unsigned int i; for(i=0; i<STARTUP_DELAY; i++); #endif // Set clock mode, DEFAULT_CLOCK is defined in config.h, and the default behaviour // is to set the clock to 72MHz from the external crystal. Using defines here to // reduce code space #if DEFAULT_CLOCK == XTAL ClockModeXTAL(); #elif DEFAULT_CLOCK == IRC72 ClockModeIRC72(); #elif DEFAULT_CLOCK == IRC12 ClockModeIRC12(); #endif LPC_SYSCON->SYSAHBCLKDIV = 1; LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 6) | (1 << 16); // Set all pins to digital inputs (except P0[0] which is the reset button) #if PORT_STARTUP_INIT Port0Init(ALL & ~PIN0); Port1Init(ALL); #endif // Initialise and start the system tick timer if allowed by the SYSTICK_EN // definition in config.h, if the system tick timer is running, then the Delay() // function will use it, otherwise Delay() will use a fixed loop which is not // accurate when there are interrupts running, as any interrupt would stop the // loop and cuase the delay to be longer than expected #if SYSTICK_EN && SYSTICK_STARTUP SysTickInit(); #endif // Run the user-supplied setup() function if it exists if(setup) { setup(); } // Run the user-supplied main() function if it exists if(main) { main(); } // Loop the user-supplied setup() function if it exists if(loop) { while(1) loop(); } // Do nothing (except handle interrupts) while(1); }
/** * @brief clock tick initialization * * This function initializes the Timer 0 in the AVR to * generate an interrupt ever 10 ms. */ void hwclock_init(void) { SysTickInit(); hwclockRestart (0); }
// *** This is the startup code void Reset_Handler(void) { unsigned long *pSrc, *pDest; unsigned int i; // Initialise RAM pSrc = &_etext; for(pDest=&__data; pDest<&__edata; ) { *pDest++ = *pSrc++; } for(pDest=&__bss; pDest<&__ebss; ) { *pDest++ = 0; } // Initialise the uninitialised variable described in section 19.2.1 of UM10365 *((uint32_t *)(0x10000054)) = 0x0; #if STARTUP_DELAY for(i=0; i<STARTUP_DELAY; i++); #endif // Set clock mode, DEFAULT_CLOCK is defined in config.h, and the default behaviour // is to set the clock to 72MHz from the external crystal. Using defines here to // reduce code space #if DEFAULT_CLOCK == XTAL LPC_SYSCON->PDRUNCFG &= ~(1 << 5); // Power up system oscillator for(i = 0; i < 100; i++); // Brief delay LPC_SYSCON->SYSOSCCTRL = 0; // System oscillator setup - not bypass, 1-20MHz range LPC_SYSCON->SYSPLLCLKSEL = 0x01; // Select system oscillator as PLL source LPC_SYSCON->SYSPLLCLKUEN = 0x00; // Update clock source LPC_SYSCON->SYSPLLCLKUEN = 0x01; while(!(LPC_SYSCON->SYSPLLCLKUEN & 0x01)); // Wait for update LPC_SYSCON->MAINCLKSEL = 0x01; // Select sys osc as main clock source LPC_SYSCON->MAINCLKUEN = 0x00; // Update clock source LPC_SYSCON->MAINCLKUEN = 0x01; while (!(LPC_SYSCON->MAINCLKUEN & 0x01)); // Wait for clock update LPC_SYSCON->SYSPLLCTRL = 0x25; // Select PLL divider to 6 (12MHz - 72MHz) LPC_SYSCON->PDRUNCFG &= ~(1 << 7); // Power up PLL while(!(LPC_SYSCON->SYSPLLSTAT & 0x01)); // Wait for PLL lock LPC_SYSCON->MAINCLKSEL = 0x03; // Select PLL as main clock source LPC_SYSCON->MAINCLKUEN = 0x00; // Update clock source LPC_SYSCON->MAINCLKUEN = 0x01; while (!(LPC_SYSCON->MAINCLKUEN & 0x01)); // Wait for clock update #elif DEFAULT_CLOCK == IRC72 LPC_SYSCON->PDRUNCFG &= ~((1<<0) | (1<<1)); // Power up IRC oscillator for(i = 0; i < 100; i++); // Brief delay LPC_SYSCON->MAINCLKSEL = 0x00; // Select IRC as main clock source LPC_SYSCON->MAINCLKUEN = 0x00; // Update clock source LPC_SYSCON->MAINCLKUEN = 0x01; while (!(LPC_SYSCON->MAINCLKUEN & 0x01)); // Wait for clock update LPC_SYSCON->SYSPLLCLKSEL = 0x00; // Select IRC as PLL source LPC_SYSCON->SYSPLLCLKUEN = 0x00; // Update clock source LPC_SYSCON->SYSPLLCLKUEN = 0x01; while(!(LPC_SYSCON->SYSPLLCLKUEN & 0x01)); // Wait for update LPC_SYSCON->SYSPLLCTRL = 0x25; // Select PLL divider to 6 (12MHz - 72MHz) LPC_SYSCON->PDRUNCFG &= ~(1<<7); // Power up PLL while(!(LPC_SYSCON->SYSPLLSTAT & 0x01)); // Wait for PLL lock LPC_SYSCON->MAINCLKSEL = 0x03; // Select PLL as main clock source LPC_SYSCON->MAINCLKUEN = 0x00; // Update clock source LPC_SYSCON->MAINCLKUEN = 0x01; while (!(LPC_SYSCON->MAINCLKUEN & 0x01)); // Wait for clock update LPC_SYSCON->PDRUNCFG |= (1<<5); // Power down system oscillator #elif DEFAULT_CLOCK == IRC12 LPC_SYSCON->PDRUNCFG &= ~((1<<0) | (1<<1)); // Power up IRC oscillator for(i = 0; i < 100; i++); // Brief delay LPC_SYSCON->MAINCLKSEL = 0x00; // Select IRC as main clock source LPC_SYSCON->MAINCLKUEN = 0x00; // Update clock source LPC_SYSCON->MAINCLKUEN = 0x01; while (!(LPC_SYSCON->MAINCLKUEN & 0x01)); // Wait for clock update LPC_SYSCON->PDRUNCFG |= ((1<<5) | (1<<7)); // Power down system oscillator and IRC #endif // Set all pins to digital inputs (except P0[0] which is the reset button) #if PORT_STARTUP_INIT Port0Init(ALL & ~PIN0); Port1Init(ALL); Port2Init(ALL); Port3Init(ALL); #endif // Initialise and start the system tick timer if allowed by the SYSTICK_EN // definition in config.h, if the system tick timer is running, then the Delay() // function will use it, otherwise Delay() will use a fixed loop which is not // accurate when there are interrupts running, as any interrupt would stop the // loop and cuase the delay to be longer than expected #if SYSTICK_EN && SYSTICK_STARTUP SysTickInit(); #endif // Run the user-supplied setup() function if it exists if(setup) { setup(); } // Run the user-supplied main() function if it exists if(main) { main(); } // Loop the user-supplied setup() function if it exists if(loop) { while(1) loop(); } // Do nothing (except handle interrupts) while(1); }
/******************************************************************************* * Function Name :void TaskStart(void) * Description :任务启动 * Input : * Output : * Other : * Date :2012.04.18 11:48:23 *******************************************************************************/ static void TaskStart(void) { OS_ERR err; led_init(); usart1_init(115200); SPI_Config() ; SysTickInit(); OSTaskCreate( (OS_TCB *)&task1TCB, (CPU_CHAR *)"Task1", (OS_TASK_PTR)Task1, (void *)0, (OS_PRIO )TASK1_PRIO, (CPU_STK *)&task1_stk[0], (CPU_STK_SIZE)TASK1_STK_SIZE / 10, (CPU_STK_SIZE)TASK1_STK_SIZE, (OS_MSG_QTY )0, (OS_TICK )0, (void *)0, (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), (OS_ERR *)&err); OSTaskCreate( (OS_TCB *)&task2TCB, (CPU_CHAR *)"Task2", (OS_TASK_PTR)Task2, (void *)0, (OS_PRIO ) TASK2_PRIO, (CPU_STK *)&task2_stk[0], (CPU_STK_SIZE)TASK2_STK_SIZE / 10, (CPU_STK_SIZE)TASK2_STK_SIZE, (OS_MSG_QTY )0, (OS_TICK )0, (void *)0, (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), (OS_ERR *)&err); OSTaskCreate( (OS_TCB *)&task3TCB, (CPU_CHAR *)"Task3", (OS_TASK_PTR)Task3, (void *)0, (OS_PRIO )TASK3_PRIO, (CPU_STK *)&task3_stk[0], (CPU_STK_SIZE)TASK3_STK_SIZE / 10, (CPU_STK_SIZE)TASK3_STK_SIZE, (OS_MSG_QTY )0, (OS_TICK )0, (void *)0, (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), (OS_ERR *)&err); OSTaskCreate( (OS_TCB *)&dispTCB, (CPU_CHAR *)"LCD display", (OS_TASK_PTR)MainTask, (void *)0, (OS_PRIO )Disp_PRIO, (CPU_STK *)&dispStk[0], (CPU_STK_SIZE)TASK4_STK_SIZE / 10, (CPU_STK_SIZE)TASK4_STK_SIZE, (OS_MSG_QTY )0, (OS_TICK )0, (void *)0, (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), (OS_ERR *)&err); OSTaskCreate( (OS_TCB *)&schedTaskEx1TCB, (CPU_CHAR *)"Sched Task Example1", (OS_TASK_PTR)SchedEx1Task, (void *)0, (OS_PRIO )Disp_PRIO, (CPU_STK *)&dispStk[0], (CPU_STK_SIZE)SCHED_TASK_STK_SIZE / 10, (CPU_STK_SIZE)SCHED_TASK_STK_SIZE, (OS_MSG_QTY )0, (OS_TICK )0, (void *)0, (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), (OS_ERR *)&err); OSTaskCreate( (OS_TCB *)&schedTaskEx2TCB, (CPU_CHAR *)"Sched Task Example1", (OS_TASK_PTR)SchedEx2Task, (void *)0, (OS_PRIO )Disp_PRIO, (CPU_STK *)&dispStk[0], (CPU_STK_SIZE)SCHED_TASK_STK_SIZE / 10, (CPU_STK_SIZE)SCHED_TASK_STK_SIZE, (OS_MSG_QTY )0, (OS_TICK )0, (void *)0, (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), (OS_ERR *)&err); OSSemCreate( (OS_SEM *)&taskSem, (CPU_CHAR *)"taskSem", (OS_SEM_CTR )0, (OS_ERR *)err); OSTaskDel( (OS_TCB *)&taskStartTCB, (OS_ERR *)&err); }