Featured Post

Setting In Tess Of The Durbervilles Essay Example For Students

Setting In Tess Of The Durbervilles Essay The Role of Setting In the novel Tess of the DUrbervilles by Thomas Hardy, Tess is confronted w...

Saturday, December 7, 2019

FreeRTOS and Implementation of Context Switch

Question: Write a report on the FreeRTOS and how the context switch isimplemented. Answer: Introduction FreeRTOS is a real time operating system for the embedded devices. It is designed to be small as well as simple. It provides methods for various threads, tasks as well as software timers. FreeRTOS is the market leading real time operating system as well as a standard solution for both microcontrollers as well as small microprocessors (Chen and Wang 2015). It is most trusted real time operating system as it is professionally developed, robust, free to use for the commercial products, quality controlled, supported. Without the requirement it can exposed to the source code as well as it has no IP infringement risks. The report is based on the concept of FreeRTOS with reflection on the context switch that is being implemented. It also reflects on the real time kernel context switching source code commencing the bottom up. As FreeRTOS is a real time kernel, therefore it is ported to number of variety of architectures of the microcontroller. The report discusses about the implementation of the context switch between two of the tasks. Implementation of context switch FreeRTOS abstracts the details of peripheral interface such as implementation of the interrupt service routines that are required. Various data transfer modes are catered using various techniques to read as well as write the data makes the FreeRTOS applicable to wide range of applications (Strnadel and Rajnoha 2012). The task within the context switch is a sequential piece of code that it does not recognize if it is going to suspend such as swap out or switch out and resume such as swap in or switch in by the kernel. As the task is executed, it utilizes the processor as well as microcontroller registers with accessing the RAM as well as ROM to another program. The resources such as processor, stack as well as registers comprise the execution of task context. When the task is suspended before execution of the instruction, then it sums up the value that contains in two processor registers. When the task is balanced as well as other tasks are executed, then it may modify the processor r egister values (Cheng, Woodcock and DSouza 2014). Upon resumption of the task, it will not distinguish if the processor registers, then it modifies if it used the customized values the outline results into incorrect value. In order to prevent the error within the task, it is required that the resumption of the task has some context identical prior to the suspension (Stangaciu, Micea and Cretu 2015). The operating system kernel is used to make sure that it does by saving the context of the task as the task is suspended. When the task is resumed, then it saves the context that is restored by the operating system kernel prior to the execution. Th process to save the task context being suspended as well as restored the task context being resumed is defined as the context switching. In order to switch two established context, it is required to save all the registers on current and switch slacks. It restores all the registers of the new stack (Ferreira et al. 2014). This operation is called as thread_switch. The following are the implementation steps that are followed: Pushing all the callee-save registers onto the current stack. Saving the current stack pointer (%rsp) into the old thread control block. Loading of the stack pointer from new thread control block into %rsp. Pop all the callee-save registers from the new stack. Then Return. The FreeRTOS real time kernel events the time using the tick count variable. The timer interrupt increases the tick count with strictly temporal accuracy (Simonovic and Saranovac 2013). It allows the real time kernel in order to calculate time to resolution of selected timer interrupt frequency. A the time the tick count is incremented, the real time kernel ensures to observe if it is the time to unlock the tasks (Mistry, Naylor and Woodcock 2013). If it is probable that the task is unblocked throughout the tick ISR, then it has the priority higher than that to interrupt the tasks. In the case when the tick ISR returns, then it unblocks the tasks while interrupting one task but recurring to another (Freertos.org 2015). The context switch occurs in such a way that it is called Preemptive as the interrupted task preempts with no delaying itself. The context switching refers to the control of the flow jump, which occurs when one of the threads gives up the central processing unit as well as another thread that takes over (Okas, Krzak and Worek 2015). Like a function of call, the context switching involves with a push values onto the system stack. It also manipulates the registers of the CPU. Apart from this, unlike a call function, the context switches explicit entry as well as exit points. The context switching can happen at any time without any of the warning (Guan et al. 2016). If both the stack as well as the set of the registers represent as the user need to know about the flow of control, then the result is that the entire context must be saved before it is switched to another one. Context switches between two of the tasks The following are the steps to implement the FreeRTOS context switch implementation between two tasks as follows: It is assumed that the task A is running currently. Figure 1: Context of the Task A that is running (Source: Mistry, Naylor and Woodcock 2013, pp-1132) The RTOS tick occurs which also generates hardware interrupt. The hardware interrupt saves the register of the program counter automatically which points to the next instruction of the task A within the program stick of Task A. Figure 2: Program counter saved by the hardware within the slack of Task A at the time of interruption (Source: Mistry, Naylor and Woodcock 2013, pp-1132) The next step is that it has to imagine that the timer code saves the context that is beig executed. The stack pointer of the task A is stored by Kernel. Figure 3: Context of the task A that is saved within the program stack of the task A (Source: Mistry, Naylor and Woodcock 2013, pp-1133) The stored stack pointer of the task B is to be copied onto the stack pointer register of the Multi-point Control Unit (MCU). Figure 4: MCU stack pointer that points to top of the context of task B (Source: Mistry, Naylor and Woodcock 2013, pp-1134) It has imagined that the timer code restores the context of the task B that is already being executed. Figure 5: Context of the task B that is restored (Source: Mistry, Naylor and Woodcock 2013, pp-1135) The program counter register restores by the hardware automatically and then the task B s being resumed for executing. Figure 6: Execution of the task B (Source: Mistry, Naylor and Woodcock 2013, pp-1135) Conclusion It is concluded that the FreeRTOS is a real time operating system that leads in the marketplace due to some of its functions, as it is a standard solution for both microcontrollers as well as small microprocessors. The main functions of the FreeRTOS are that it is developed professionally, and use for the commercial products. It has good quality controlled, supported. Without the requirement it can exposed to the source code as well as it has no IP infringement risks. FreeRTOS also measures the time using the tick count variable. The interruption of the timer increases the tick count with accuracy of the time. References Chen, W. and Wang, J., 2015. Design of RFID Card Reading System Based on LWIP and FreeRTOS.AMM, 734, pp.916-920. Cheng, S., Woodcock, J. and DSouza, D., 2014. Using formal reasoning on a model of tasks for FreeRTOS.Formal Aspects of Computing, 27(1), pp.167-192. Ferreira, J., Gherghina, C., He, G., Qin, S. and Chin, W., 2014. Automated verification of the FreeRTOS scheduler in Hip/Sleek.International Journal on Software Tools for Technology Transfer, 16(4), pp.381-397. Guan, F., Peng, L., Perneel, L. and Timmerman, M., 2016. Open source FreeRTOS as a case study in real-time operating system evolution.Journal of Systems and Software, 118, pp.19-35. Mistry, J., Naylor, M. and Woodcock, J. (2013). Adapting FreeRTOS for multicores: an experience report.Softw. Pract. Exper., 44(9), pp.1129-1154. Okas, P., Krzak, Ã…Â . and Worek, C., 2015. C++14 concurrency on ARM Cortex-M using FreeRTOS and GCC.IFAC-PapersOnLine, 48(4), pp.262-267. Simonovic, M. and Saranovac, L., 2013. Power management implementation in FreeRTOS on LM3S3748.Serb J Electr Eng, 10(1), pp.199-208. Stangaciu, C., Micea, M. and Cretu, V., 2015. An Analysis of a Hard Real-Time Execution Environment Extension for FreeRTOS.Advances in Electrical and Computer Engineering, 15(3), pp.79-86. Strnadel, J. and Rajnoha, P., 2012. Reflecting RTOS Model During WCET Timing Analysis: MSP430/Freertos Case Study.Acta Electrotechnica et Informatica, 12(4).

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.