UCOSIII System Internal tasks

Source: Internet
Author: User
Tags data structures cpu usage

1. Idle Tasks

Idle task is the first task created by UCOSIII
Idle tasks are ucosiii that must be created
Idle task priority is always os_cfg_prio_mak-1
You cannot call any function in an idle task that causes the idle task to enter the waiting state

#define OS_CFG_PRIO_MAX 64u/* Defines the maximum number of task priorities (see Os_prio data type) */Os_idletaskinit (P _ERR); /* Initialize the Idle Task */void Os_idletaskinit (Os_err *p_err) {#ifdef os_safety_critical if (P_err = = (os_er
        R *) 0) {os_safety_critical_exception ();
    Return

    } #endif osidletaskctr = (os_idle_ctr) 0;
                 Ostaskcreate ((OS_TCB *) &OSIDLETASKTCB, (Cpu_char *) ((void *) "UC/OS-III Idle Task"), (OS_TASK_PTR) Os_idletask, (void *) 0, (Os_prio) (os_cfg_prio_max-1u), (CP U_STK *) Oscfg_idletaskstkbaseptr, (cpu_stk_size) Oscfg_idletaskstklimit, (cpu_stk_size       ) Oscfg_idletaskstksize, (Os_msg_qty) 0u, (Os_tick) 0u, (void *) 0, (os_opt) (Os_opt_task_stk_chk | OS_OPT_TASK_STK_CLR | OS_OPT_TASK_NO_TLS), (OS_err *) p_err);

    } void Os_idletask (void *p_arg) {cpu_sr_alloc (); P_arg = P_arg;
        /* Prevent compiler warning for not using ' p_arg ' */while (def_on) {cpu_critical_enter ();
osidletaskctr++;
#if os_cfg_stat_task_en > 0u osstattaskctr++;

        #endif cpu_critical_exit (); Osidletaskhook (); /* Call user definable HOOK */}}

2. Clock Tempo task

Used to track task delays and task wait timeouts
is a task that UCOSIII must create
Task priority is defined with macro Os_cfg_tick_task_prio

Os_prio Const Oscfg_ticktaskprio = (Os_prio) Os_cfg_tick_task_prio;

#define Os_cfg_tick_task_prio 1u/* Priority clock-beat task, generally set a relatively high precedence */Os_ticktaskinit (P_ERR); void Os_ticktaskinit (Os_err *p_err) {#ifdef os_safety_critical if (P_err = = (Os_err *) 0) {Os_safety_criti
        Cal_exception ();
    Return } #endif ostickctr = (os_tick) 0u;


    /* Clear The Tick counter */Osticktasktimemax = (cpu_ts) 0u; Os_ticklistinit (); /* Initialize The Tick list data structures */if (oscfg_ticktaskstkbaseptr = = (CPU_STK *) 0) {*p_err = Os_err
        _tick_stk_invalid;
    Return
        } if (Oscfg_ticktaskstksize < oscfg_stksizemin) {*p_err = Os_err_tick_stk_size_invalid;
    Return if (Oscfg_ticktaskprio >= (os_cfg_prio_max-1u)) {/* Only one task is at the ' Idle task ' priority */*p_er
        R = os_err_tick_prio_invalid;
    Return } ostaskcreate ((OS_TCB *) &AMP;OSTICKTASKTCB, (Cpu_char *) ((void *) "UC/OS-III Tick Task"), (Os_task_ptr) Os_ticktask, (void *) 0, (Os_prio) Oscfg_ticktaskprio, (CPU_STK *) oscfg_ticktaskstkbaseptr, (cpu_stk_size) oscfg_ticktask Stklimit, (Cpu_stk_size) oscfg_ticktaskstksize, (Os_msg_qty) 0u, (Os_ti CK) 0u, (void *) 0, (os_opt) (Os_opt_task_stk_chk | OS_OPT_TASK_STK_CLR |
OS_OPT_TASK_NO_TLS), (Os_err *) p_err); }

3. Statistical Tasks

can be used to count CPU usage, CPU usage per task, and stack usage for each task
Statistical tasks are not created by default

Create the procedure: OS_CFG_STAT_TASK_EN the macro 1 in a task created by the main function, call the function Osstattaskcpuusageinit () priority is set by the macro Os_cfg_stat_task_prio. General Settings Os_cfg_prio_max-2, which is the second-to-last priority

Os_prio Const Oscfg_stattaskprio = (Os_prio) Os_cfg_stat_task_prio;
#define  Os_cfg_stat_task_prio (OS_CFG_PRIO_MAX-2U)/* Priority Stats Task Priorities */

#if os_cfg_stat_task_en > 0u
   Osstattaskcpuusageinit (&err);
#endif

4. Scheduled Tasks

UCOSIII software timer function, scheduled tasks are optional

CREATE PROCEDURE: Setting the macro os_cfg_tmr_en to 1 in Osinit () will call the function Os_tmrinit () priority defined by the macro Os_cfg_tmr_task_prio. The timer task priority is set to 2 by default

Os_prio Const Oscfg_tmrtaskprio = (Os_prio) Os_cfg_tmr_task_prio;
#define  Os_cfg_tmr_task_prio 2u/* Priority of ' Timer task ' timed tasks priorities */

#if os_cfg_tmr_en > 0u/* Initialize the Timer Manager Module *
    /Os_tmrinit (p_err);
    if (*p_err! = os_err_none) {
        return;
    }
#endif

5. Interrupt Service Management Tasks
When the ISR (Interrupt service function) invokes the "POST" function provided by UCOSIII, the data to be sent and the destination to be sent are stored in a special buffer queue, and when all nested ISR are executed, UCOSIII will do the task switch, run the Interrupt Service management task, This task will re-send the information stored in the cache queue to the appropriate task

The benefit of this is that you can reduce the time of the interrupt shutdown

Create a process: OS_CFG_ISR_POST_DEFERRED_EN a macro 1 The priority of the Interrupt Service Management task is always 0 and cannot be changed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.