static void AppTaskStart (void *p_arg) { OS_ERR err; #if (APP_CFG_TCPIP_MODULE_EN > 0u) NET_ERR net_err; #endif (void)&p_arg; BSP_Init(); /* Initialize BSP functions */ CPU_Init(); /* Initialize the uC/CPU services */ OS_CPU_TickInit(); /* Init uC/OS periodic time src (SysTick). */ #if (OS_CFG_STAT_TASK_EN > 0u) OSStatTaskCPUUsageInit(&err); /* Compute CPU capacity with no task running */ #endif Mem_Init(); /* Initialize mem mgmt module, required for TCP-IP. */ #if (APP_CFG_PROBE_COM_MODULE_EN > 0u) AppProbe_Init(); /* Initialize uC/Probe modules */ #endif OSTaskCreate((OS_TCB *)&AppBlinkyTaskTCB, /* Create the start task */ (CPU_CHAR *)"Blinky Task", (OS_TASK_PTR ) AppBlinkyTask, (void *) 0, (OS_PRIO ) BLINKY_TASK_PRIO, (CPU_STK *)&AppBlinkyTaskStk[0], (CPU_STK_SIZE) BLINKY_TASK_STK_SIZE / 10u, (CPU_STK_SIZE) BLINKY_TASK_STK_SIZE, (OS_MSG_QTY ) 0u, (OS_TICK ) 0u, (void *) 0, (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), (OS_ERR *)&err); BSP_GraphLCD_Init(); AppGraphLCD_Hdr(); #if (APP_CFG_TCPIP_MODULE_EN > 0u) AppTCPIP_Init(&net_err); /* Initialize uC/TCP-IP & associated applications. */ AppCloud_Init(0); #endif #ifdef CPU_CFG_INT_DIS_MEAS_EN CPU_IntDisMeasMaxCurReset(); #endif AppTCPIP_Cfg = DEF_TRUE; OSTaskDel(&AppTaskStartTCB, /* Delete task because its work is complete */ &err); while (DEF_ON) { ; /* Should not get here! */ } }
//--------------------------------------------------------------------------------------------------- // Tâches de démarrages, init du hardware et création des tâches de l'applicaiton //--------------------------------------------------------------------------------------------------- static void AppTaskStart(void *p_arg) { OS_ERR aErr; // Pour le warning du compilateur (void)p_arg; // Start BSP and tick initialization BSP_Init(); // Start Tick Initialization BSP_Tick_Init(); mLeds_Setup(); #if OS_CFG_STAT_TASK_EN > 0u // Compute CPU capacity with no task running */ OSStatTaskCPUUsageInit(&aErr); #endif OSTaskCreate((OS_TCB *)&Task1_Tcb, (CPU_CHAR *)"Task1", (OS_TASK_PTR ) Task1, (void *) 0, (OS_PRIO ) kTask1Pr, (CPU_STK *)&sTask1Stk[0], (CPU_STK )(kStackSize / 10u), (CPU_STK_SIZE) kStackSize, (OS_MSG_QTY ) 0, (OS_TICK ) 0, (void *) 0, (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), (OS_ERR *)&aErr); OSTaskCreate((OS_TCB *)&Task2_Tcb, (CPU_CHAR *)"Task2", (OS_TASK_PTR ) Task2, (void *) 0, (OS_PRIO ) kTask2Pr, (CPU_STK *)&sTask2Stk[0], (CPU_STK )(kStackSize / 10u), (CPU_STK_SIZE) kStackSize, (OS_MSG_QTY ) 0, (OS_TICK ) 0, (void *) 0, (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), (OS_ERR *)&aErr); while (DEF_TRUE) { OSTaskDel(&sAppTaskStartTCB,&aErr); } }
static void App_TaskStart (void *p_arg) { OS_ERR os_err; (void)p_arg; /* See Note #1. */ BSP_Init(); /* Start BSP and tick initialization. */ BSP_Tick_Init(); /* Start Tick Initialization. */ BSP_UART_Init(BSP_UART_DEFAULT, /* Start UART Initialization */ BSP_BUSCLK, 9600); BSP_LCD_Init(); /* Initialize the seven-segment display panel. */ #if OS_CFG_STAT_TASK_EN > 0u OSStatTaskCPUUsageInit(&os_err); /* Compute CPU capacity with no task running */ #endif #ifdef CPU_CFG_INT_DIS_MEAS_EN CPU_IntDisMeasMaxCurReset(); #endif APP_TRACE_INFO(("Creating Application Events...\n\r")); App_ObjCreate(); /* Create Applicaton kernel objects. */ APP_TRACE_INFO(("Creating Application Tasks...\n\r")); App_TaskCreate(); /* Create Application tasks. */ while (DEF_TRUE) { /* Task body, always written as an infinite loop. */ OSTimeDlyHMSM(0, 0, 2, 0, OS_OPT_TIME_HMSM_STRICT, &os_err); // BSP_UART_Send_String(BSP_UART_1, // "Hello\n"); uart_printf("Hello world\n"); OSTimeDly(10, OS_OPT_TIME_HMSM_STRICT, &os_err); uart_printf("os_err = %d\n", os_err); // while (BSP_SW_Read (BSP_SW_1) != DEF_ON) { // OSTimeDly(1, OS_OPT_TIME_HMSM_STRICT, &os_err); // } // BSP_LED_Toggle(BSP_LED_RED); // // BSP_UART_Send_String(BSP_UART_1, // "Hello\n"); // // while (BSP_SW_Read (BSP_SW_1) == DEF_OFF) { // OSTimeDly(1, OS_OPT_TIME_HMSM_STRICT, &os_err); // } } }
/* ********************************************************************************************************* * STARTUP TASK * * Description : This is an example of a startup task. As mentioned in the book's text, you MUST * initialize the ticker only once multitasking has started. * * Arguments : p_arg is the argument passed to 'AppTaskStart()' by 'OSTaskCreate()'. * * Returns : none * * Notes : 1) The first line of code is used to prevent a compiler warning because 'p_arg' is not * used. The compiler should not generate any code for this statement. ********************************************************************************************************* */ static void AppTaskStart (void *p_arg) { OS_ERR err; (void)p_arg; BSP_Init(); /* Initialize BSP functions */ BSP_Tick_Init(); /* Initialize Tick Services. */ App_OS_SetAllHooks(); MEM_Init(); DR_Init(); #if OS_CFG_STAT_TASK_EN > 0u OSStatTaskCPUUsageInit(&err); /* Compute CPU capacity with no task running */ #endif #ifdef CPU_CFG_INT_DIS_MEAS_EN CPU_IntDisMeasMaxCurReset(); #endif DR_LED_Off(0u); /* Turn Off LEDs after initialization */ APP_TRACE_DBG(("Creating Application Kernel Objects\n\r")); AppObjCreate(); /* Create Applicaiton kernel objects */ APP_TRACE_DBG(("Creating Application Tasks\n\r")); AppDataAcqCreate(); /* Create Application tasks */ while (DEF_TRUE) { /* Task body, always written as an infinite loop. */ DR_LED_On(1u); OSTimeDlyHMSM(0u, 0u, 0u, 10u, OS_OPT_TIME_HMSM_STRICT, &err); DR_LED_Off(1u); OSTimeDlyHMSM(0u, 0u, 1u, 0u, OS_OPT_TIME_HMSM_STRICT, &err); } }
static void AppTaskStart (void *p_arg) { CPU_INT32U clk_freq; CPU_INT32U cnts; OS_ERR err; (void)&p_arg; BSP_Init(); /* Initialize BSP functions */ CPU_Init(); /* Initialize the uC/CPU services */ clk_freq = BSP_CPU_ClkFreq(); /* Determine SysTick reference freq. */ cnts = clk_freq / (CPU_INT32U)OSCfg_TickRate_Hz; /* Determine nbr SysTick increments */ OS_CPU_SysTickInit(cnts); /* Init uC/OS periodic time src (SysTick). */ CPU_TS_TmrFreqSet(clk_freq); #if (OS_CFG_STAT_TASK_EN > 0u) OSStatTaskCPUUsageInit(&err); /* Compute CPU capacity with no task running */ #endif CPU_IntDisMeasMaxCurReset(); App_ProbeInit(); BSP_LED_On(1); BSP_LED_Off(2); AppDisplayTaskCreate(); while (DEF_ON) { /* Task body, always written as an infinite loop. */ OSTimeDlyHMSM(0u, 0u, 1u, 0u, OS_OPT_TIME_HMSM_STRICT, &err); BSP_LED_Toggle(0); /* Toggle both LEDs every second. */ bLED[0] ^= DEF_TRUE; bLED[1] ^= DEF_TRUE; } }
static void AppTaskStart (void *p_arg) { CPU_INT32U cpu_clk_freq; CPU_INT32U cnts; OS_ERR err; CPU_TS ts; (void)p_arg; OSSemCreate(&AppSem, "Test Sem", 0, &err); BSP_Init(); /* Initialize BSP functions */ CPU_Init(); /* Initialize the uC/CPU services */ cpu_clk_freq = BSP_CPU_ClkFreq(); /* Determine SysTick reference freq. */ cnts = cpu_clk_freq / (CPU_INT32U)OSCfg_TickRate_Hz; /* Determine nbr SysTick increments */ OS_CPU_SysTickInit(cnts); /* Init uC/OS periodic time src (SysTick). */ #if OS_CFG_STAT_TASK_EN > 0u OSStatTaskCPUUsageInit(&err); /* Compute CPU capacity with no task running */ #endif CPU_IntDisMeasMaxCurReset(); BSP_LED_Off(0); while (DEF_TRUE) { /* Task body, always written as an infinite loop. */ BSP_LED_Toggle(0); #if 0 OSTimeDlyHMSM(0, 0, 0, 100, OS_OPT_TIME_HMSM_STRICT, &err); #endif OSSemPend(&AppSem, 100, OS_OPT_PEND_BLOCKING, &ts, &err); } }
static void AppTaskStart (void *p_arg) { OS_ERR err; (void)p_arg; BSP_Init(); /* Initialize BSP functions */ CPU_Init(); /* Initialize uC/CPU services */ #if OS_CFG_STAT_TASK_EN > 0u OSStatTaskCPUUsageInit(&err); /* Compute CPU capacity with no task running */ #endif APP_TRACE_DBG(("uCOS-II is Running...\n\r")); while (DEF_ON) { /* Task body, always written as an infinite loop. */ OSTimeDlyHMSM(0, 0, 1, 0); APP_TRACE_DBG(("Time: %d\n\r", OSTimeGet(&err))); } }
//开始任务函数 void start_task(void *p_arg) { OS_ERR err; CPU_SR_ALLOC(); p_arg = p_arg; CPU_Init(); #if OS_CFG_STAT_TASK_EN > 0u OSStatTaskCPUUsageInit(&err); //统计任务 #endif #ifdef CPU_CFG_INT_DIS_MEAS_EN //如果使能了测量中断关闭时间 CPU_IntDisMeasMaxCurReset(); #endif #if OS_CFG_SCHED_ROUND_ROBIN_EN //当使用时间片轮转的时候 //使能时间片轮转调度功能,时间片长度为1个系统时钟节拍,既1*5=5ms OSSchedRoundRobinCfg(DEF_ENABLED,1,&err); #endif OS_CRITICAL_ENTER(); //进入临界区 OSTaskCreate((OS_TCB * )&Led0TaskTCB, (CPU_CHAR * )"led0 task", (OS_TASK_PTR )led0_task, (void * )0, (OS_PRIO )LED0_TASK_PRIO, (CPU_STK * )&LED0_TASK_STK[0], (CPU_STK_SIZE)LED0_STK_SIZE/10, (CPU_STK_SIZE)LED0_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); OS_TaskSuspend((OS_TCB*)&StartTaskTCB,&err); //挂起开始任务 OS_CRITICAL_EXIT(); //进入临界区 }
static void AppTaskStart (void *p_arg) { CPU_INT32U cpu_clk_freq; CPU_INT32U cnts; OS_ERR err; (void)p_arg; BSP_Init(); /* Initialize BSP functions */ CPU_Init(); cpu_clk_freq = BSP_CPU_ClkFreq(); cnts = cpu_clk_freq / (CPU_INT32U)OSCfg_TickRate_Hz;/* Determine nbr SysTick increments */ OS_CPU_SysTickInit(cnts); /* Init uC/OS periodic time src (SysTick). */ #if OS_CFG_STAT_TASK_EN > 0u OSStatTaskCPUUsageInit(&err); /* Compute CPU capacity with no task running */ #endif CPU_IntDisMeasMaxCurReset(); //init USART1 BSP_Ser_Init(9600); BSP_Ser_WrStr("start"); //init ADC1, ACC sensor TERM_init_adc(); //init PWM TERM_init_pwm(); //AppTaskCreate(); /* Create application tasks */ TERM_createTask(); }
static void App_TaskStart (void *p_arg) { OS_ERR os_err; (void)p_arg; /* See Note #1. */ BSP_Init(); /* Start BSP and tick initialization. */ BSP_Tick_Init(); /* Start Tick Initialization. */ BSP_LCD_Init(); /* Initialize the seven-segment display panel. */ #if OS_CFG_STAT_TASK_EN > 0u OSStatTaskCPUUsageInit(&os_err); /* Compute CPU capacity with no task running */ #endif #ifdef CPU_CFG_INT_DIS_MEAS_EN CPU_IntDisMeasMaxCurReset(); #endif APP_TRACE_INFO(("Creating Application Events...\n\r")); App_ObjCreate(); /* Create Applicaton kernel objects. */ APP_TRACE_INFO(("Creating Application Tasks...\n\r")); App_TaskCreate(); /* Create Application tasks. */ while (DEF_TRUE) { /* Task body, always written as an infinite loop. */ BSP_LED_Toggle(BSP_LED_RED); OSTimeDlyHMSM(0, 0, 0, 200, OS_OPT_TIME_HMSM_STRICT, &os_err); BSP_LED_Toggle(BSP_LED_GREEN); OSTimeDlyHMSM(0, 0, 0, 200, OS_OPT_TIME_HMSM_STRICT, &os_err); } }
static void AppTaskStart (void *p_arg) { CPU_INT32U freq; CPU_INT32U cnts; OS_ERR err; (void)p_arg; BSP_Init(); /* Initialize BSP functions */ CPU_Init(); /* Initialize the uC/CPU services */ freq = BSP_CPU_ClkFreq(); /* Determine SysTick reference freq. */ cnts = freq / (CPU_INT32U)OSCfg_TickRate_Hz; /* Determine nbr SysTick increments */ OS_CPU_SysTickInit(cnts); /* Init uC/OS periodic time src (SysTick). */ #if OS_CFG_STAT_TASK_EN > 0u OSStatTaskCPUUsageInit(&err); /* Compute CPU capacity with no task running */ #endif #ifdef CPU_CFG_INT_DIS_MEAS_EN CPU_IntDisMeasMaxCurReset(); #endif AppEventCreate(); /* Create Application Kernel objects */ AppTaskCreate(); /* Create application tasks */ while (DEF_TRUE) { /* Task body, always written as an infinite loop. */ OSTimeDlyHMSM(0, 0, 0, 200, /* Delay task for 200 ms */ OS_OPT_TIME_HMSM_STRICT, &err); } }
static void AppTaskStart (void *p_arg) { OS_ERR err; (void)p_arg; BSP_Tick_Init(); bsp_Init(); CPU_Init(); //Mem_Init(); //内存管理模块 // Math_Init(); #if OS_CFG_STAT_TASK_EN > 0u OSStatTaskCPUUsageInit(&err); #endif #ifdef CPU_CFG_INT_DIS_MEAS_EN CPU_IntDisMeasMaxCurReset(); #endif AppTimerCreate(); AppObjCreate(); AppTaskCreate(); while (1) { //GPIOG->ODR ^= GPIO_Pin_10; //添加LED指示灯,指示星务计算机工作状态 2014/10/18 BSP_OS_TimeDlyMs(2000); //printf("living!\r\n"); //bsp_LedToggle(1); //bsp_LedToggle(2); //bsp_LedToggle(3); } }
//开始任务函数 void start_task(void *p_arg) { OS_ERR err; CPU_SR_ALLOC(); p_arg = p_arg; CPU_Init(); #if OS_CFG_STAT_TASK_EN > 0u OSStatTaskCPUUsageInit(&err); //统计任务 #endif #ifdef CPU_CFG_INT_DIS_MEAS_EN //如果使能了测量中断关闭时间 CPU_IntDisMeasMaxCurReset(); #endif #if OS_CFG_SCHED_ROUND_ROBIN_EN //当使用时间片轮转的时候 //使能时间片轮转调度功能,时间片长度为1个系统时钟节拍,既1*5=5ms OSSchedRoundRobinCfg(DEF_ENABLED,1,&err); #endif OS_CRITICAL_ENTER(); //进入临界区 //创建信号量Test_Sem1 OSSemCreate ((OS_SEM* )&Test_Sem1, (CPU_CHAR* )"Test_Sem1", (OS_SEM_CTR)0, (OS_ERR* )&err); //创建信号量Test_Sem2 OSSemCreate ((OS_SEM* )&Test_Sem2, (CPU_CHAR* )"Test_Sem2", (OS_SEM_CTR)0, (OS_ERR* )&err); //创建消息队列 OSQCreate ((OS_Q* )&Test_Q, //消息队列 (CPU_CHAR* )"KEY Msg", //消息队列名称 (OS_MSG_QTY )QUEUE_NUM, //消息队列长度 (OS_ERR* )&err); //错误码 //创建TASK1任务 OSTaskCreate((OS_TCB * )&Task1_TaskTCB, (CPU_CHAR * )"Task1 task", (OS_TASK_PTR )task1_task, (void * )0, (OS_PRIO )TASK1_TASK_PRIO, (CPU_STK * )&TASK1_TASK_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); //创建MULTI测试任务 OSTaskCreate((OS_TCB * )&Multi_TaskTCB, (CPU_CHAR * )"Multi task", (OS_TASK_PTR )multi_task, (void * )0, (OS_PRIO )MULTI_TASK_PRIO, (CPU_STK * )&MULTI_TASK_STK[0], (CPU_STK_SIZE)MULTI_STK_SIZE/10, (CPU_STK_SIZE)MULTI_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); OS_CRITICAL_EXIT(); //退出临界区 OSTaskDel((OS_TCB*)0,&err); //删除start_task任务自身 }
static void AppTaskStart (void *p_arg) { OS_ERR err; #if (APP_CFG_TCPIP_MODULE_EN > 0u) NET_ERR net_err; #endif (void)&p_arg; BSP_Init(); /* Initialize BSP functions */ CPU_Init(); /* Initialize the uC/CPU services */ OS_CPU_TickInit(); /* Init uC/OS periodic time src (SysTick). */ #if (OS_CFG_STAT_TASK_EN > 0u) OSStatTaskCPUUsageInit(&err); /* Compute CPU capacity with no task running */ #endif Mem_Init(); /* Initialize mem mgmt module, required for TCP-IP. */ #if (APP_CFG_PROBE_COM_MODULE_EN > 0u) AppProbe_Init(); /* Initialize uC/Probe modules */ #endif OSTaskCreate((OS_TCB *)&AppAccelTaskTCB, /* Create the accelerometer task */ (CPU_CHAR *)"Accel Task", (OS_TASK_PTR ) AppAccelTask, (void *) 0, (OS_PRIO ) ACCEL_TASK_PRIO, (CPU_STK *)&AppAccelTaskStk[0], (CPU_STK_SIZE) ACCEL_TASK_STK_SIZE / 10u, (CPU_STK_SIZE) ACCEL_TASK_STK_SIZE, (OS_MSG_QTY ) 0u, (OS_TICK ) 0u, (void *) 0, (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), (OS_ERR *)&err); OSTaskCreate((OS_TCB *)&AppTempTaskTCB, /* Create the temperature task */ (CPU_CHAR *)"Temp Task", (OS_TASK_PTR ) AppTempTask, (void *) 0, (OS_PRIO ) TEMPERATURE_TASK_PRIO, (CPU_STK *)&AppTempTaskStk[0], (CPU_STK_SIZE) TEMPERATURE_TASK_STK_SIZE / 10u, (CPU_STK_SIZE) TEMPERATURE_TASK_STK_SIZE, (OS_MSG_QTY ) 0u, (OS_TICK ) 0u, (void *) 0, (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), (OS_ERR *)&err); BSP_GraphLCD_Init(); AppGraphLCD_Hdr(); #if (APP_CFG_TCPIP_MODULE_EN > 0u) AppTCPIP_Init(&net_err); /* Initialize uC/TCP-IP & associated applications. */ AppCloud_Init(0); #endif #ifdef CPU_CFG_INT_DIS_MEAS_EN CPU_IntDisMeasMaxCurReset(); #endif AppTCPIP_Cfg = DEF_TRUE; while (DEF_ON) { OSTimeDlyHMSM(0u, 0u, 0u, 100u, OS_OPT_TIME_HMSM_STRICT, &err); } }
static void Task_Start (void *p_arg) { CPU_INT32U cpu_clk_freq; CPU_INT32U cnts; OS_ERR err_os; (void)&p_arg; BSP_Init(); /* Initialize BSP functions */ cpu_clk_freq = BSP_SysClkFreqGet(); /* Determine SysTick reference freq. */ cnts = cpu_clk_freq /* Determine nbr SysTick increments */ / (CPU_INT32U)OSCfg_TickRate_Hz; OS_CPU_SysTickInit(cnts); CPU_Init(); /* Initialize the uC/CPU services */ #if (OS_CFG_STAT_TASK_EN > 0u) OSStatTaskCPUUsageInit(&err_os); /* Compute CPU capacity with no task running */ #endif Mem_Init(); #ifdef CPU_CFG_INT_DIS_MEAS_EN CPU_IntDisMeasMaxCurReset(); #endif // AppTaskCreate(); /* Creates all the necessary application tasks. */ // while (DEF_ON) { // BSP_LED_Toggle(0); // OSTimeDlyHMSM(0, 0, 0, 500, // OS_OPT_TIME_HMSM_STRICT, // &err_os); // } // Set the pinout for the board, including required pins for Ethernet // operation. PinoutSet(0,1); g_ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); UARTStdioConfig(0, 115200, g_ui32SysClock); //cpu_clk_freq); UARTprintf("\033[2J\033[H"); UARTprintf("Welcome to the Connected LaunchPad!!\n"); UARTprintf("Internet of Things Demo\n"); UARTprintf("Type \'help\' for help.\n\n"); //create task LED1 OSTaskCreate((OS_TCB *)&LED_TCB, (CPU_CHAR *)"LED", (OS_TASK_PTR )Task_LED, (void *)0, (OS_PRIO )TASK_LED_PRIO, (CPU_STK *)&LED_Stk[0], (CPU_STK_SIZE)TASK_LED_STK_SIZE/10, (CPU_STK_SIZE)TASK_LED_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_os); // createe test task OSTaskCreate((OS_TCB *)&Tmr_TCB, (CPU_CHAR *)"TS", (OS_TASK_PTR )Task_Tmr, (void *)0, (OS_PRIO )TASK_DBG_PRIO, (CPU_STK *)&Tmr_Stk[0], (CPU_STK_SIZE)TASK_TMR_STK_SIZE/10, (CPU_STK_SIZE)TASK_TMR_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_os); // remove the startup task. OSTaskDel(&StartUp_TCB,&err_os); }
//开始任务函数 void start_task(void *p_arg) { OS_ERR err; CPU_SR_ALLOC(); p_arg = p_arg; CPU_Init(); #if OS_CFG_STAT_TASK_EN > 0u OSStatTaskCPUUsageInit(&err); //统计任务 #endif #ifdef CPU_CFG_INT_DIS_MEAS_EN //如果使能了测量中断关闭时间 CPU_IntDisMeasMaxCurReset(); #endif #if OS_CFG_SCHED_ROUND_ROBIN_EN //当使用时间片轮转的时候 //使能时间片轮转调度功能,时间片长度为1个系统时钟节拍,既1*5=5ms OSSchedRoundRobinCfg(DEF_ENABLED,1,&err); #endif OS_CRITICAL_ENTER(); //进入临界区 //创建定时器1 OSTmrCreate((OS_TMR *)&tmr1, //定时器1 (CPU_CHAR *)"tmr1", //定时器名字 (OS_TICK )0, //0ms (OS_TICK )50, //50*10=500ms (OS_OPT )OS_OPT_TMR_PERIODIC, //周期模式 (OS_TMR_CALLBACK_PTR)tmr1_callback,//定时器1回调函数 (void *)0, //参数为0 (OS_ERR *)&err); //返回的错误码 //创建主任务 OSTaskCreate((OS_TCB * )&Main_TaskTCB, (CPU_CHAR * )"Main task", (OS_TASK_PTR )main_task, (void * )0, (OS_PRIO )MAIN_TASK_PRIO, (CPU_STK * )&MAIN_TASK_STK[0], (CPU_STK_SIZE)MAIN_STK_SIZE/10, (CPU_STK_SIZE)MAIN_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); //创建MSGDIS任务 OSTaskCreate((OS_TCB * )&Msgdis_TaskTCB, (CPU_CHAR * )"Msgdis task", (OS_TASK_PTR )msgdis_task, (void * )0, (OS_PRIO )MSGDIS_TASK_PRIO, (CPU_STK * )&MSGDIS_TASK_STK[0], (CPU_STK_SIZE)MSGDIS_STK_SIZE/10, (CPU_STK_SIZE)MSGDIS_STK_SIZE, (OS_MSG_QTY )TASK_Q_NUM, //任务Msgdis_task需要使用内建消息队列,消息队列长度为4 (OS_TICK )0, (void * )0, (OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR, (OS_ERR * )&err); OS_CRITICAL_EXIT(); //退出临界区 OSTaskDel((OS_TCB*)0,&err); //删除start_task任务自身 }
void AppTaskStart (void *p_arg) { CPU_INT32U cpu_clk_freq; CPU_INT32U cnts; OS_ERR err; (void)p_arg; BSP_Init(); /* Initialize BSP functions */ cpu_clk_freq = BSP_CPU_ClkFreq(); /* Determine SysTick reference freq. */ cnts = cpu_clk_freq / (CPU_INT32U)OSCfg_TickRate_Hz; /* Determine nbr SysTick increments */ OS_CPU_SysTickInit(cnts); /* Init uC/OS periodic time src (SysTick). */ //OS_CPU_SysTickInit(720000); OSSemCreate(&AppSem, "Test Sem", 0, &err); OSTaskCreate((OS_TCB *)&LEDATaskStkTCB, (CPU_CHAR *)"leda task", (OS_TASK_PTR)leda_task_core, (void * )0, (OS_PRIO)OS_TASK_LEDA_PRIO, (CPU_STK *)&LEDATaskStk[0], (CPU_STK_SIZE)OS_LEDA_TASK_STACK_SIZE/10, (CPU_STK_SIZE)OS_LEDA_TASK_STACK_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 *)&LEDBTaskStkTCB, (CPU_CHAR *)"ledb task", (OS_TASK_PTR)ledb_task_core, (void * )0, (OS_PRIO)OS_TASK_LEDB_PRIO, (CPU_STK *)&LEDBTaskStk[0], (CPU_STK_SIZE)OS_LEDB_TASK_STACK_SIZE/10, (CPU_STK_SIZE)OS_LEDB_TASK_STACK_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); #if OS_CFG_STAT_TASK_EN > 0u OSStatTaskCPUUsageInit(&err); /* Compute CPU capacity with no task running */ #endif #if OS_CFG_APP_HOOKS_EN > 0u App_OS_SetAllHooks(); #endif while (1) { /* Task body, always written as an infinite loop. */ GPIOG->ODR^=1<<0; OSTimeDlyHMSM(0, 0, 0, 500,OS_OPT_TIME_HMSM_STRICT,&err); } }
static void AppTaskStart (void *p_arg) { CPU_INT08U seq; OS_ERR err; #if (APP_CFG_TCPIP_MODULE_EN > 0u) NET_ERR net_err; #endif (void)&p_arg; BSP_Init(); /* Initialize BSP functions */ CPU_Init(); /* Initialize the uC/CPU services */ OS_CPU_TickInit(); /* Init uC/OS periodic time src (SysTick). */ BSP_Ser_Init(BSP_CFG_SER_BAUDRATE); #if (OS_CFG_STAT_TASK_EN > 0u) OSStatTaskCPUUsageInit(&err); /* Compute CPU capacity with no task running */ #endif Mem_Init(); /* Initialize mem mgmt module, required for TCP-IP. */ BSP_GraphLCD_Init(); AppGraphLCD_Hdr(); #if (APP_CFG_FS_EN > 0u) App_FS_Init(); #endif #if (APP_CFG_TCPIP_MODULE_EN > 0u) AppTCPIP_Init(&net_err); /* Initialize uC/TCP-IP & associated applications. */ if ((net_err == NET_ERR_NONE) || (net_err == NET_IF_ERR_LINK_DOWN)) { AppTCPIP_Cfg = DEF_TRUE; } #if (APP_CFG_TFTPs_MODULE_EN > 0u) TFTPs_Init(); #endif AppCloud_Init(1); #else AppTCPIP_Cfg = DEF_TRUE; #endif #if OS_CFG_SCHED_ROUND_ROBIN_EN > 0u OSSchedRoundRobinCfg(DEF_ENABLED, 5, &err); #endif #if (APP_CFG_AUDIO_EN > 0u) AppAudio_Init(); #endif #ifdef CPU_CFG_INT_DIS_MEAS_EN CPU_IntDisMeasMaxCurReset(); #endif seq = 0; LED_Off(0); /* turn all LEDs off */ while (DEF_ON) { /* Task body, always written as an infinite loop. */ if (AppTCPIP_Cfg == DEF_FALSE) { LED_Toggle(14); /* simple LED flash */ LED_Toggle( 5); LED_Toggle( 8); LED_Toggle(11); OSTimeDlyHMSM(0u, 0u, 0u, 100u, OS_OPT_TIME_HMSM_STRICT, &err); } else { switch (seq){ case 0: LEDDisplay_Seq0(); seq++; break; case 1: LEDDisplay_Seq1(); seq++; break; case 2: LEDDisplay_Seq2(); seq++; break; case 3: LEDDisplay_Seq3(); seq = 0; break; default: seq = 0; break; } } } }
static void AppTaskStart (void *p_arg) { OS_ERR err; CPU_INT32U r0; CPU_INT32U r1; CPU_INT32U r2; CPU_INT32U r3; CPU_INT32U r4; CPU_INT32U r5; CPU_INT32U r6; CPU_INT32U r7; CPU_INT32U r8; CPU_INT32U r9; CPU_INT32U r10; CPU_INT32U r11; CPU_INT32U r12; (void)p_arg; r0 = 0u; /* Initialize local variables. */ r1 = 1u; r2 = 2u; r3 = 3u; r4 = 4u; r5 = 5u; r6 = 6u; r7 = 7u; r8 = 8u; r9 = 9u; r10 = 10u; r11 = 11u; r12 = 12u; BSP_Init(); /* Initialize BSP functions */ CPU_Init(); /* Initialize the uC/CPU services */ #if OS_CFG_STAT_TASK_EN > 0u OSStatTaskCPUUsageInit(&err); /* Compute CPU capacity with no task running */ #endif #ifdef CPU_CFG_INT_DIS_MEAS_EN CPU_IntDisMeasMaxCurReset(); #endif #if (APP_CFG_SERIAL_EN == DEF_ENABLED) App_SerialInit(); /* Initialize Serial Communication for Application ... */ #endif APP_TRACE_DBG(("Creating Application kernel objects\n\r")); AppObjCreate(); /* Create Applicaiton kernel objects */ APP_TRACE_DBG(("Creating Application Tasks\n\r")); AppTaskCreate(); /* Create Application tasks */ BSP_LED_Off(0u); while (DEF_TRUE) { /* Task body, always written as an infinite loop. */ BSP_LED_Toggle(0u); OSTimeDlyHMSM(0u, 0u, 0u, 100u, OS_OPT_TIME_HMSM_STRICT, &err); if ((r0 != 0u) || /* Check task context. */ (r1 != 1u) || (r2 != 2u) || (r3 != 3u) || (r4 != 4u) || (r5 != 5u) || (r6 != 6u) || (r7 != 7u) || (r8 != 8u) || (r9 != 9u) || (r10 != 10u) || (r11 != 11u) || (r12 != 12u)) { APP_TRACE_INFO(("Context Error\n")); } } }
//开始任务函数 void start_task(void *p_arg) { OS_ERR err; CPU_SR_ALLOC(); p_arg = p_arg; CPU_Init(); #if OS_CFG_STAT_TASK_EN > 0u OSStatTaskCPUUsageInit(&err); //统计任务 #endif #ifdef CPU_CFG_INT_DIS_MEAS_EN //如果使能了测量中断关闭时间 CPU_IntDisMeasMaxCurReset(); #endif #if OS_CFG_SCHED_ROUND_ROBIN_EN //当使用时间片轮转的时候 //使能时间片轮转调度功能,时间片长度为1个系统时钟节拍,既1*5=5ms OSSchedRoundRobinCfg(DEF_ENABLED,1,&err); #endif OS_CRITICAL_ENTER(); //进入临界区 OSFlagCreate((OS_FLAG_GRP *)&event_flag, (CPU_CHAR *)"event flag", (OS_FLAGS)0x00, (OS_ERR *)&err ); OSTaskCreate((OS_TCB * )&Led0TaskTCB, (CPU_CHAR * )"led0 task", (OS_TASK_PTR )led0_task, (void * )0, (OS_PRIO )LED0_TASK_PRIO, (CPU_STK * )&LED0_TASK_STK[0], (CPU_STK_SIZE)LED0_STK_SIZE/10, (CPU_STK_SIZE)LED0_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 * )&FloatTaskTCB, (CPU_CHAR * )"float test task", (OS_TASK_PTR )float_task, (void * )0, (OS_PRIO )FLOAT_TASK_PRIO, (CPU_STK * )&FLOAT_TASK_STK[0], (CPU_STK_SIZE)FLOAT_STK_SIZE/10, (CPU_STK_SIZE)FLOAT_STK_SIZE, (OS_MSG_QTY )5, (OS_TICK )0, (void * )0, (OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR, (OS_ERR * )&err); //创建协议处理任务 OSTaskCreate((OS_TCB * )&ProtocolTaskTCB, (CPU_CHAR * )"protocol task", (OS_TASK_PTR )protocol_task, (void * )0, (OS_PRIO )Protocol_TASK_PRIO, (CPU_STK * )&Protocol_TASK_STK[0], (CPU_STK_SIZE)Protocol_STK_SIZE/10, (CPU_STK_SIZE)Protocol_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); OS_CRITICAL_EXIT(); //进入临界区 OSTaskDel(NULL,&err); }