{"id":3547,"date":"2023-06-24T00:01:00","date_gmt":"2023-06-23T18:31:00","guid":{"rendered":"https:\/\/cthecosmos.com\/?p=3547"},"modified":"2023-06-24T00:01:00","modified_gmt":"2023-06-23T18:31:00","slug":"initialization-of-os-in-microc-os-ii","status":"publish","type":"post","link":"https:\/\/cthecosmos.com\/?p=3547","title":{"rendered":"Initialization of OS in MicroC\/OS-II"},"content":{"rendered":"\n<div class=\"wp-block-group has-black-color has-text-color has-background\" style=\"background-color:#f7f7f7;font-size:15px;line-height:1.7\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<p>One of the key strengths of \ud835\udc2e\ud835\udc02\/\ud835\udc0e\ud835\udc12-\ud835\udc08\ud835\udc08 lies in its lightweight and independent task model. Each task executes specific functions or operations, allowing for efficient task switching and context switching.<\/p>\n\n\n\n<p>Let&#8217;s start by unraveling the software file structure, which sets the foundation for a deep dive into the workings of \ud835\udc0e\ud835\udc12_\ud835\udc08\ud835\udc27\ud835\udc22\ud835\udc2d(). We&#8217;ll delve into the initialization process of the uC\/OS-II kernel, with a special focus on the \ud835\udc0e\ud835\udc12_\ud835\udc08\ud835\udc27\ud835\udc22\ud835\udc2d() function. This crucial function initializes the uC\/OS-II kernel and prepares the system for multitasking.<br><br>uC\/OS-II is a compact, portable, and highly efficient RTOS designed specifically for embedded systems. It provides a robust framework for multitasking, task scheduling, inter-task communication, and resource management, making it an excellent choice for applications with real-time constraints.<\/p>\n\n\n\n<p>uC\/OS-II is built upon a preemptive, priority-based scheduling algorithm. This means that tasks with higher priorities are executed before lower-priority tasks, ensuring that time-critical operations receive immediate attention. The kernel&#8217;s small footprint and low interrupt latency make it suitable for a wide range of resource-constrained microcontrollers and microprocessors.<\/p>\n\n\n\n<p>Tasks in uC\/OS-II are lightweight and independent entities that execute specific functions or operations. Each task has its own stack space and execution context, allowing for efficient task switching and context switching. The kernel provides services such as task creation, deletion, suspension, and synchronization to facilitate task management. Following is the Software file structure followed in uC\/OS-II continued with the explanation of an example on the working of <strong>OS_Init()<\/strong> in uC\/OS-II.<\/p>\n\n\n\n<p>The Software file structure in \u03bc\ud835\udc02\/\ud835\udc0e\ud835\udc12-\ud835\udc08\ud835\udc08<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"652\" height=\"598\" data-attachment-id=\"3549\" data-permalink=\"https:\/\/cthecosmos.com\/?attachment_id=3549\" data-orig-file=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2023\/06\/image-7.png?fit=652%2C598&amp;ssl=1\" data-orig-size=\"652,598\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image-7\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2023\/06\/image-7.png?fit=300%2C275&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2023\/06\/image-7.png?fit=652%2C598&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2023\/06\/image-7.png?resize=652%2C598&#038;ssl=1\" alt=\"\" class=\"wp-image-3549\" \/><\/figure>\n\n\n\n<p><strong>\u03bc<\/strong>\ud835\udc02\/\ud835\udc0e\ud835\udc12-\ud835\udc08\ud835\udc08 provides two macro functions to disable and enable the interrupts.<br><strong>OS_ENTER_CRITICAL()<\/strong> and <strong>OS_EXIT_CRITICAL()<\/strong>, present in <strong>OS_CPU.h.<\/strong><\/p>\n\n\n\n<p>These are used a wrap whenever there is a need to access critical code section.<br>Pseudo Syntax:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; highlight: [20]; title: ; notranslate\" title=\"\">\n#include\u201dheaders.h\u201d\n#define TASK1_STACK_SIZE 128\n#define TASK2_STACK_SIZE 128\n\nvoid task1(void *pdata)\n{\nwhile(1){\n\u2026.\n}\n}\n\nvoid task2(void *pdata)\n{\nwhile(1){\n\u2026.\n}\n}\nint main(void)\n{\nOSInit();\nOSTaskCreate(task1,NULL,&amp;task1_stack&#x5B;TASK1_STACK_SIZE-1],0);\nOSTaskCreate(task2,NULL,&amp;task2_stack&#x5B;TASK2_STACK_SIZE-1],0);\nOSStart();\nreturn 0;\n}\n<\/pre><\/div>\n\n\n<p><br><strong>OS_Init()<\/strong> initialized the uC\/OS-II kernel and sets up the system for multitasking. This function must be called prior to creating any uC\/OS-II object prior to calling <strong>OSStart()<\/strong>. OS_Init() is the first function that is called in main.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nvoid  OSInit (void)\n{\n#if OS_TASK_CREATE_EXT_EN &gt; 0u\n#if defined(OS_TLS_TBL_SIZE) &amp;&amp; (OS_TLS_TBL_SIZE &gt; 0u)\n    INT8U  err;\n#endif\n#endif\n\n    OSInitHookBegin();                                           \/* Call port specific initialization code   *\/\n\n    OS_InitMisc();                                               \/* Initialize miscellaneous variables       *\/\n\n    OS_InitRdyList();                                            \/* Initialize the Ready List                *\/\n\n    OS_InitTCBList();                                            \/* Initialize the free list of OS_TCBs      *\/\n\n    OS_InitEventList();                                          \/* Initialize the free list of OS_EVENTs    *\/\n\n#if (OS_FLAG_EN &gt; 0u) &amp;&amp; (OS_MAX_FLAGS &gt; 0u)\n    OS_FlagInit();                                               \/* Initialize the event flag structures     *\/\n#endif\n\n#if (OS_MEM_EN &gt; 0u) &amp;&amp; (OS_MAX_MEM_PART &gt; 0u)\n    OS_MemInit();                                                \/* Initialize the memory manager            *\/\n#endif\n\n#if (OS_Q_EN &gt; 0u) &amp;&amp; (OS_MAX_QS &gt; 0u)\n    OS_QInit();                                                  \/* Initialize the message queue structures  *\/\n#endif\n\n#if OS_TASK_CREATE_EXT_EN &gt; 0u\n#if defined(OS_TLS_TBL_SIZE) &amp;&amp; (OS_TLS_TBL_SIZE &gt; 0u)\n    OS_TLS_Init(&amp;err);                                           \/* Initialize TLS, before creating tasks    *\/\n    if (err != OS_ERR_NONE) {\n        return;\n    }\n#endif\n#endif\n\n    OS_InitTaskIdle();                                           \/* Create the Idle Task                     *\/\n#if OS_TASK_STAT_EN &gt; 0u\n    OS_InitTaskStat();                                           \/* Create the Statistic Task                *\/\n#endif\n\n#if OS_TMR_EN &gt; 0u\n    OSTmr_Init();                                                \/* Initialize the Timer Manager             *\/\n#endif\n\n    OSInitHookEnd();                                             \/* Call port specific init. code            *\/\n\n#if OS_DEBUG_EN &gt; 0u\n    OSDebugInit();\n#endif\n}\n<\/pre><\/div>\n\n\n<p>1) The Kernel data structure is initialized by calling <strong>OSInitHookBegin()<\/strong>. This function is a user-defined hook that can be implemented to perform any additional initialization or setup required by the application.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>The <strong>OSInitHookBegin()<\/strong> calls the <strong>CPU_IntInit()<\/strong> that initializes the critical section objects.<ol><li>The Critical section is created by calling the <strong>CreateMutex()<\/strong> in <strong>CPU_IntInit()<\/strong>. The parameters for <strong>CreateMutex()<\/strong> by default are set to NULL,FALSE,NULL. Here <strong>CreateMutex()<\/strong> is a Windows API to create a mutex. The first parameter (Security attributes) is set to NULL indicating default security settings. The second parameter defines initial ownership state of the mutex, when set to FALSE, it is unowned. The third parameter is the mutex name, set to NULL indicating that the mutex is unnamed. It returns an object.<\/li><\/ol><\/li>\n\n\n\n<li>After this, <strong>InitializeCriticalSection()<\/strong> is called to initialize the critical section. This is a windows API. The parameter it takes is the address of the object created by the <strong>CreateMutex()<\/strong> call.<br><\/li>\n<\/ol>\n\n\n\n<p>2) <strong>OS_InitMisc()<\/strong> is called to initialize miscellaneous variables. It performs various initialization tasks related to miscellaneous features and options within the uC\/OS-II kernel. The actions that are performed are:<br>a)  <span style=\"color: initial\">Clear the 32-bit OS System clock.<\/span><br>b) <span style=\"color: initial\">Clear the interrupt nesting counter.<\/span><br>c) <span style=\"color: initial\">Clear the scheduling lock counter.<\/span><br>d) <span style=\"color: initial\">Clear the number of tasks.<\/span><br>e) <span style=\"color: initial\">Indicate the OS that the multitasking has not started.<\/span><br>f) <span style=\"color: initial\">Clear the context switch counter.<\/span><br>g) <span style=\"color: initial\">Let know the kernel that Statistic task is not ready.<\/span><br>h) <span style=\"color: initial\">Initialize the <\/span><strong style=\"color: initial\">OSSafetyCriticalStartFlag<\/strong><span style=\"color: initial\">(Related to windows) to FALSE indicating safety functionality is not yet enabled or active.<\/span><br>i) Initialize the task register ID.<br><\/p>\n\n\n\n<p>3) <strong>OS_InitRdyList()<\/strong> is called to initialize the ready list. The ready list is the task of priorities maintained by the kernel. It keeps tracks of which tasks are ready to run based on the priority levels. It is called to ensure that the ready list is in clean state before the scheduler starts scheduling. All the values in the ready table is set to 0 by this function. The Ready table size is defined by the macro <strong>OS_RDY_TBL_SIZE<\/strong> in uC\/OS-II . It is defined as:<br><strong>#define OS_RDY_TBL_SIZE ((OS_LOWEST\/PRIO) \/ 8u +1u)<\/strong>.\u00a0 The OS_LOWEST is 63 that can be found in os_cfg_r.h of uC\/OS-II source code.<br><br>4) <strong>OS_InitTCBList()<\/strong> is called to initialize the free list of OS_TCBs. The initialization process typically involves setting up the necessary data structures and variables to manage the free list. This includes linking the TCBs together in the list and configuring any associated fields or flags within the TCBs.<br><br>The free list of TCBs acts as a pool from which the uC\/OS-II kernel can allocate TCBs for new tasks during runtime. When a new task is created, the kernel retrieves a TCB from the free list and initializes it with the necessary task-specific information, such as the task&#8217;s entry point, stack size, priority, and other relevant attributes.<br><br>Once a task has completed or is deleted, its TCB is returned to the free list, making it available for reuse by other tasks in the future. This allows for efficient task management and dynamic allocation of TCBs as needed.<br><\/p>\n\n\n\n<p>5) <strong>OS_InitEventList()<\/strong> is called to initialize the free list of OS_EVENTs. It initializes the free list of event control blocks.<br><br>The free list of OS_EVENTs acts as a pool from which the uC\/OS-II kernel can allocate OS_EVENTs for various synchronization objects during runtime. When a synchronization object (such as a semaphore or message queue) is created, the kernel retrieves an OS_EVENT from the free list and initializes it with the necessary information specific to the synchronization mechanism.<br><br>Once a synchronization object is no longer needed or is deleted, its corresponding OS_EVENT is returned to the free list, making it available for reuse by other synchronization objects in the future. This allows for efficient management and dynamic allocation of OS_EVENTs as needed.<br><br>The initialization of the free event control blocks starts by clearing the event table by calling the <strong>OS_MemCLr()<\/strong> function.<br><\/p>\n\n\n\n<p>6) <strong>OS_FlagInit()<\/strong> is called to initialize the flag structures. Event flags allow tasks to wait for specific combinations of events to occur before proceeding with their execution. Tasks can wait for specific events by specifying a pattern or mask of event flags they are interested in. When the desired combination of event flags matches the specified pattern, the waiting task is signaled and can resume execution.<br><br>The event flag structures managed by OS_FlagInit() facilitate this synchronization mechanism. They provide the necessary storage and control mechanisms for event flag operations, such as setting, clearing, and testing event flags, as well as managing the tasks waiting for specific event flag patterns.<br><br>If the <strong>OS_MAX_FLAGS<\/strong> is set to <strong>1<\/strong> then only one event flag group is set. If more than 1 is set, then the function first clears the flag group table by calling the <strong>OS_MemClr()<\/strong> on<strong> OSFlagTbl<\/strong>. Once it\u2019s done, the names of the flags are set to unknown (?) until given.<br><br>The structure used for this is:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\ntypedef struct os_flag_grp {                \/* Event Flag \nGroup                                        *\/\nINT8U         OSFlagType;               \/* Should be set to OS_EVENT_TYPE_FLAG                     *\/\nvoid         *OSFlagWaitList;           \/* Pointer to first NODE of task waiting on event flag     *\/\nOS_FLAGS      OSFlagFlags;              \/* 8, 16 or 32 bit flags                                   *\/\n#if OS_FLAG_NAME_EN &gt; 0u\nINT8U        *OSFlagName;\n#endif\n} OS_FLAG_GRP;\n\n<\/pre><\/div>\n\n\n<p>7) <strong>OS_MemInit()<\/strong> is called to Initialize the memory partition manager. This prepares the memory management subsystem for dynamic memory allocation and deallocation. If the <strong>OS_MAX_MEM_PART<\/strong> is set to more than 1, then. It clears the memory partition table for each memory partition, it sets the <strong>OSMemFreeList<\/strong> pointer to the next memory partition in the table, creating a linked list of free partitions. If memory partition names are enabled, it sets the name of each partition to &#8220;?&#8221;.<\/p>\n\n\n\n<p>At last, Finally, the code sets<strong> OSMemFreeList<\/strong> to point to the beginning of the free list, which is the first memory partition in the table.<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The structure used for this is:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nstruct os_mem {                                             \/* MEMORY CONTROL BLOCK                                   *\/\n#if (OS_OBJ_TYPE_REQ == DEF_ENABLED)\n    OS_OBJ_TYPE          Type;                              \/* Should be set to OS_OBJ_TYPE_MEM                       *\/\n#endif\n#if (OS_CFG_DBG_EN == DEF_ENABLED)\n    CPU_CHAR            *NamePtr;\n#endif\n    void                *AddrPtr;                           \/* Pointer to beginning of memory partition               *\/\n    void                *FreeListPtr;                       \/* Pointer to list of free memory blocks                  *\/\n    OS_MEM_SIZE          BlkSize;                           \/* Size (in bytes) of each block of memory                *\/\n    OS_MEM_QTY           NbrMax;                            \/* Total number of blocks in this partition               *\/\n    OS_MEM_QTY           NbrFree;                           \/* Number of memory blocks remaining in this partition    *\/\n#if (OS_CFG_DBG_EN == DEF_ENABLED)\n    OS_MEM              *DbgPrevPtr;\n    OS_MEM              *DbgNextPtr;\n#endif\n#if (defined(OS_CFG_TRACE_EN) &amp;&amp; (OS_CFG_TRACE_EN == DEF_ENABLED))\n    CPU_INT16U           MemID;                             \/* Unique ID for third-party debuggers and tracers.       *\/\n#endif\n};\n<\/pre><\/div>\n\n\n<p>8) <strong>OS_QInit():<\/strong> It is called to initialize the message queue module. A loop is executed to initialize the list of free QUEUE control blocks. For each queue in the table except the last one, it sets the <strong>OSQPtr<\/strong> field of the current queue (pq1) to point to the next queue (pq2). This establishes a linked list of free queues.<\/p>\n\n\n\n<p>After the loop completes, the last queue in the table is handled separately. The <strong>OSQPtr<\/strong> field of the last queue is set to (OS_Q *)0, indicating the end of the linked list.<\/p>\n\n\n\n<p>The <strong>OSQFreeList<\/strong> is set to point to the first element of the queue table, which represents the head of the free list of queues.<\/p>\n\n\n\n<p>The structure used by this function is :<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nstruct  os_q {                                              \/* Message \nQueue                                          *\/\n                                                            \/* ------------------ GENERIC  MEMBERS ------------------ *\/\n#if (OS_OBJ_TYPE_REQ == DEF_ENABLED)\n    OS_OBJ_TYPE          Type;                              \/* Should be set to OS_OBJ_TYPE_Q                         *\/\n#endif\n#if (OS_CFG_DBG_EN == DEF_ENABLED)\n    CPU_CHAR            *NamePtr;                           \/* Pointer to Message Queue Name (NUL terminated ASCII)   *\/\n#endif\n    OS_PEND_LIST         PendList;                          \/* List of tasks waiting on message queue                 *\/\n#if (OS_CFG_DBG_EN == DEF_ENABLED)\n    OS_Q                *DbgPrevPtr;\n    OS_Q                *DbgNextPtr;\n    CPU_CHAR            *DbgNamePtr;\n#endif\n                                                            \/* ------------------ SPECIFIC MEMBERS ------------------ *\/\n    OS_MSG_Q             MsgQ;                              \/* List of messages                                       *\/\n};\n<\/pre><\/div>\n\n\n<p>\u00a0 \u00a0 <\/p>\n\n\n\n<p>9) <strong>OS_TLS_Init():<\/strong> It is called to Initialize TLS before creating a task. TLS is nothing is Thread Local Storage. The purpose of initializing TLS before creating tasks is to ensure that TLS is set up correctly and ready to be used by tasks when they are created. TLS allows each task to have its own unique data that is local to that task and not shared with other tasks. By initializing TLS early in the system initialization process, the tasks can rely on having access to TLS when they start running.<\/p>\n\n\n\n<p>10) <strong>OSInitTaskIdle()<\/strong>: It is called to create an ideal task. To ensure that the CPU is never left idle, an idle task is created by uC\/OS-II using this function call. The function begins by checking <strong>OS_TASK_NAME_EN<\/strong> is enabled. If <strong>OS_TASK_CREATE_EXT_EN<\/strong> is defined\/enabled, the idle task is created by using <strong>OSTaskCreateExt()<\/strong>, else it is created by using <strong>OSTaskCreate()<\/strong>. The entry point of the function is set to <strong>OS_TaskIdle<\/strong>.<\/p>\n\n\n\n<p><strong>OS_TaskIdle()<\/strong> is a function that runs when no other higher priority tasks execute . It allocates storage for CPU status register by using <strong>OS_CPU_SR<\/strong> type. It also initializes the tasks and prevents the compiler warning for not using <strong>p_arg<\/strong>. The stack for the idle task is specified based on the <strong>OS_STK_GROWTH<\/strong> configuration option. If <strong>OS_STK_GROWTH<\/strong> is set to <strong>1<\/strong>, the stack pointer is set to the last element of the <strong>OSTaskIdleStk<\/strong> array. The idle task priority is set to <strong>OS_TASK_IDLE_PRIO<\/strong> which is the lowest. The final functionality is, if setting task names is enabled, set the name of the task by calling <strong>OSTaskNameSet()<\/strong> function.<\/p>\n\n\n\n<p>11) <strong>OS_InitTaskStat<\/strong>() It is called to create the static task. It allows the programmer to gather the information about the execution time and other statistics of each task in the system. It first checks if the task static feature is enabled by comparing the macro <strong>OS_TASK_STAT_EN<\/strong> &gt;0 . When enabled, it sets up the necessary data structures like <strong>OSTaskStatTbl[].<\/strong> The priority is set to one higher than idle task by using the macro <strong>OS_TASK_STAT_PRIO<\/strong>, sets task stat id, sets bottom of the stack by passing address of <strong>OSTASKStatStk[0]<\/strong>, no TCB extension and enabling stack checking and clearing as parameters to OSTaskCreate()\/OSTaskCreateExt(). To collect the task statistics of a specific task, <strong>OSTCBCtrPtr<\/strong> should be made to set in the OS_TCB.<\/p>\n\n\n\n<p>12) <strong>OSTmr_Init():<\/strong> It is called to initialize the free list of the timer manager. (OS_TMR). This function uses the timer data type as seen below.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nstruct  os_tmr {\n#if (OS_OBJ_TYPE_REQ == DEF_ENABLED)\n    OS_OBJ_TYPE          Type;\n#endif\n#if (OS_CFG_DBG_EN == DEF_ENABLED)\n    CPU_CHAR            *NamePtr;                           \/* Name to give the timer                                 *\/\n#endif\n    OS_TMR_CALLBACK_PTR  CallbackPtr;                       \/* Function to call when timer expires                    *\/\n    void                *CallbackPtrArg;                    \/* Argument to pass to function when timer expires        *\/\n    OS_TMR              *NextPtr;                           \/* Double link list pointers                              *\/\n    OS_TMR              *PrevPtr;\n    OS_TICK              Remain;                            \/* Amount of time remaining before timer expires          *\/\n    OS_TICK              Dly;                               \/* Delay before start of repeat                           *\/\n    OS_TICK              Period;                            \/* Period to repeat timer                                 *\/\n    OS_OPT               Opt;                               \/* Options (see OS_OPT_TMR_xxx)                           *\/\n    OS_STATE             State;\n#if (OS_CFG_DBG_EN == DEF_ENABLED)\n    OS_TMR              *DbgPrevPtr;\n    OS_TMR              *DbgNextPtr;\n#endif\n};\n<\/pre><\/div>\n\n\n<p>It is used to create and manage software timers in our application. Functions such as <strong>OSTmrStart(),<\/strong> <strong>OSTmrStop()<\/strong> and <strong>OSTmrSet()<\/strong> can be used to start, stop and set the timer.<\/p>\n\n\n\n<p>The actions performed by this function include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Initializes the software timer tick counter (OSTmrTickCtr) to 0.<\/li>\n\n\n\n<li>Initializes the software timer list (OSTmrList), which is a linked list that holds all the active software timers.<\/li>\n\n\n\n<li>Initializes the software timer task control block (OSTmrTaskTCB), which represents the timer task responsible for managing the software timers.<\/li>\n\n\n\n<li>Creates the timer task by calling OSTaskCreate() or OSTaskCreateExt(), depending on the configuration (<strong>OS_TASK_CREATE_EXT_EN<\/strong>).<\/li>\n\n\n\n<li>Sets the timer task priority and stack size.<\/li>\n\n\n\n<li>Sets up the timer task stack (OSTmrTaskStk) with the specified size.<\/li>\n\n\n\n<li>If task names are enabled, it assigns a name to the timer task using OSTaskNameSet().<\/li>\n\n\n\n<li>Starts the timer task by calling OSTaskResume().<\/li>\n<\/ul>\n\n\n\n<p>13) <strong>OSInitHookEnd():<\/strong> Is called to call port specific initialization code and is called at the end of OSInit().<\/p>\n\n\n\n<p>14) <strong>OSDebuInit()<\/strong>: It is called in the end if <strong>OS_DEBUG_EN<\/strong> is set or enabled. It is used to make sure that the debug variables that are unused in the application are not optimized away. This function can be optional and can be used for debugging.<\/p>\n\n\n\n<p>This ends the working of <strong>OSInit()<\/strong> function that is called first and then begins the execution of tasks.<\/p>\n\n\n\n<p><strong>References:<\/strong><br>uC\/OS-II source code and user manual.<br><br><strong>Environment:<\/strong><br>Eclipse IDE on Ubuntu VM.<\/p>\n\n\n\n<p><strong>Article By:<\/strong> Yashwanth Naidu Tikkisetty<\/p>\n\n\n\n<p class=\"has-black-color has-text-color\">Follow <strong>#oswithyash<\/strong> on LinkedIn(<a href=\"https:\/\/www.linkedin.com\/in\/t-yashwanth-naidu-887633156\/\">T Yashwanth Naidu<\/a>)to get updates related to Embedded Systems, Space and Technology.<\/p>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>One of the key strengths of \ud835\udc2e\ud835\udc02\/\ud835\udc0e\ud835\udc12-\ud835\udc08\ud835\udc08 lies in its lightweight and independent task model. Each task executes specific functions or operations, allowing for efficient task switching and context switching. Let&#8217;s start by unraveling the software file structure, which sets the foundation for a deep dive into the workings of \ud835\udc0e\ud835\udc12_\ud835\udc08\ud835\udc27\ud835\udc22\ud835\udc2d(). We&#8217;ll delve into the [&hellip;]<\/p>\n<a href=\"https:\/\/cthecosmos.com\/?p=3547\" class=\"more-link\">Read More <span class=\"screen-reader-text\">Initialization of OS in MicroC\/OS-II<\/span><\/a>","protected":false},"author":120055267,"featured_media":3580,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":false,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_wpas_customize_per_network":false},"categories":[1],"tags":[1634593,1706979,763368988,38887748,10969655,772321180,763368961,763368965,763368959,557290590,3383,763368987,772321190],"class_list":{"0":"post-3547","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","6":"hentry","7":"category-uncategorized","8":"tag-c-2","9":"tag-cprogramming","10":"tag-cthecosmos","11":"tag-embedded-2","12":"tag-embeddedsystems","13":"tag-linux","14":"tag-micrium-2","15":"tag-microc-os-ii","16":"tag-microc-osii","17":"tag-microcosii","18":"tag-os","19":"tag-oswithyash","20":"tag-rtos","22":"fallback-thumbnail"},"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/cthecosmos.com\/wp-content\/uploads\/2023\/06\/initialization-of-os.png?fit=1362%2C1053&ssl=1","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8CiEf-Vd","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/cthecosmos.com\/index.php?rest_route=\/wp\/v2\/posts\/3547","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cthecosmos.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cthecosmos.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cthecosmos.com\/index.php?rest_route=\/wp\/v2\/users\/120055267"}],"replies":[{"embeddable":true,"href":"https:\/\/cthecosmos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3547"}],"version-history":[{"count":25,"href":"https:\/\/cthecosmos.com\/index.php?rest_route=\/wp\/v2\/posts\/3547\/revisions"}],"predecessor-version":[{"id":3581,"href":"https:\/\/cthecosmos.com\/index.php?rest_route=\/wp\/v2\/posts\/3547\/revisions\/3581"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cthecosmos.com\/index.php?rest_route=\/wp\/v2\/media\/3580"}],"wp:attachment":[{"href":"https:\/\/cthecosmos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3547"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cthecosmos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3547"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cthecosmos.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3547"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}