PERFORMANCE COMPARISON OF USART COMMUNICATION BETWEEN REAL TIME OPERATING SYSTEM AND NATIVE INTERRUPT

Comunication between microcontrollers is one of the crucial point in embedded sytems. On the other hand, embedded system must be able to run many parallel task simultaneously. To handle this, we need a reliabe system that can do a multitasking without decreasing every task’s performance. The most widely used methods for multitasking in embedded systems are using Interrupt Service Routine (ISR) or using Real Time Operating System (RTOS). This research compared perfomance of USART communication on system with RTOS to a system that use interrupt. Experiments run on two identical development board XMega A3BU-Xplained which used intenal sensor (light and temperature) and used servo as external component. Perfomance comparison done by counting ping time (elapsing time to transmit data and get a reply as a mark that data has been received) and compare it. This experiments divided into two scenarios: (1) system loaded with many tasks, (2) system loaded with few tasks. Result of the experiments show that communication will be faster if system only loaded with few tasks. System with RTOS has won from interrupt in case (1), but lose to interrupt in case (2).


Introduction
Nowadays the usage of embedded systems are widely spread in every aspects of our life.It is because embedded systems are the right solution to implant an automatic behaviour or responses into physical world which is small, low-powered, and specific to one dedicated purpose.Implementation of embedded system are everywhere, start from daily utensils like refrigerator, television, calcula-tor, until many device that runs daily life like traffic light, automatic gate in the railstation, etc.
Although one embedded systems can be only dedi-cated to specific purposes, its purposes itself may contain some tasks.Because of that, one of a capability that embedded system must have is an ability to handle multiple tasks without fail.To do that, the system that can handle parallel computation in small and low computational ability is urgently needed.One of the solution by using Inter-44 Jurnal Ilmu Komputer dan Informasi (Journal of Computer Science and Information), Volume 9, Issue 1, February 2016 rupt Service Routine (ISR) to run tasks as a process that interrupting its main program simultaneusly.Another solution is Real Time Operating System (RTOS), a tiny operating system that can fit into embedded system's device and run processes as tasks that run in specific time slice.Either interrupt or RTOS have its own advantages and disadvantages, depends on needs of the system.
Another crucial point for embedded system is an ability to communicate and exchange data from one microcontroller to another.With communicating each other, the functionality of the system can be increased and can be made as a wider system that can coordinate each other.There is many methods to do a communication between device, one of them is communication using USART (Universal Synchronous Asynchronous Receiver Transmitter) method.
Communication between system usually followed with another tasks that run in parallel, e.g.sensor reading or move an actuator.However, sometimes comunication process disturbed by another task, so in result communication process can be slower than expected and/or occurred an error that cause data loss.To overcome that, the system that capable to run parallel processes without reduce any process's performance is needed.
Several research about embedded system and RTOS have been conducted in recent years.The latest one, Manju Nanda et al. [1] conducted research about qualifying RTOS for use in safety critical applications using formal methods due to effectiveness and preciseness.Manju Nanda et al [4] provides guidelines for development and implementation of formal approach to qualify a Commercially off the Shelf (COTS) RTOS as per the civil aerospace standard RTCA DO-178C.
Yonghyun Hwan et al. [2] present an accurate timed RTOS model within transaction level models (TLMs).There are two key features used in this research.The RTOS behavior model provides dynamic scheduling, IPC (inter-process communication), and external communication for timing annotated user applications.The RTOS overhead model has processor to specific pre-characterized overhead information to provide cycle approximate estimation.To demonstrate the model, Yonhyun Hwan et al [2] used a multicore platform executed a JPEG encoder and provide results that RTOS model present high accuracy.
Su-Lim TAN and Tran Nguyen Bao Anh [3] present a research about RTOS for small microcontroller.Su-Lim TAN and Tran Nguyen Bao Anh [3] used 16 bit microcontroller to perform RTOS multitasking.To demonstrate the ease of RTOS platform migration, the mTKernel RTOS is chosen for porting to the H8S/2377 16-bit microcontroller.
Ji Chan Maeng et al [4] present a research about produce an RTOS specific code using an automated tool and model-driven approach embedded software development.Generic RTOS APIs was defined to capture most of typical RTOS ser-vices and for describing application's RTOS related behaviour at an early stage.Generic RTOS APIs have been transformed into RTOS specific APIs using an automated transformation tool.
Fabiano Hessel [5] present a research about abstract RTOS model that allows refining the abstract model to an implementation model at lower abstraction levels.Fabiano Hessel [5] used C language with some extension to build the model and as a results fifty task with four priority levels shows the usefulness of this model.
Our previous research [6], do a comparison between RTOS and Interrupt using ultrasonic sensor and rack movement mechanism where it will move from distance 0 cm to 10 cm repeatedly.Defined threshold at a certain distance that is beginning, middle and end.Ultrasonic sensor will indicated "HIT" if distance between assigned threshold and rack movement is equal.Result shows that RTOS has higher accuracy performance than Interrupt butlesser precision.In this research, the peformance comparison between RTOS and native interrupt will be investigated in the case of serial communication between microcontroller.This research will test performance of USART communication while undergoing another some other tasks.
The rest of this paper is organized as follows.Section 2 describe the methodology used in this research.Section 3 presents results and analysis of experiment.Finally, section 4 presents conclusions of this paper.

Methods
This research focused on testing the performance of USART communication on various multitasking environment.Performance in this research measured by two aspects: (1) communication speed, and (2) communication reliability.Experiments conducted on two multitasking system which connected each other with USART communication.Each board have an identic environment and specifications, either hardware or software.
Communication speed can be measured by obtaining data of amount of elapsed communication time.This aspect tested by conduct "ping" process and count its elapsed time.Similar to ping in networking [7], ping is a process to check a reachability of destination device.Ping conducted by sending a packet of data to destination device and get a reply data as a sign that the data has been received.For experiment on this research, ping conducted as character sending and receiving process.Ping function transmit character 't' to destination board, and the destination board will reply with character 'r'.Elapsed time obtained by count the time differences between data sending and receiving process.For each experiment, ping conducted several times and the mean of ping time become the result.Detail of experiment process explained in sub-section 2.2, on experiment scenarios subsection.
Reliability of communication conducted to see how much error occurred when USART runs on various condition.To see the system's error, experiment still use the same process as ping does, but it now focused on the amount of data that transmiited and received.As explained above, each experiment conducted ping several times.To check reliability of the system, this experiment will count the differences between the amount of data which is received and retransmitted.This aspect obtained in each board separately.The amount of received ping accumulated on the destination board, and the amount of obtained reply data that comes from destination board accumulated in source board.The amount of differences between received ping and received reply become amount of packet that loss on ping process.From amount of loss packet, relia-bility of the system can be measured and analyzed.Detail of this aspect explained in section 4, subsection experiment scenarios.

RTOS and Native Interrupt
RTOS is a new approach as an alternative of interrupt in microcontroller world.Its capability of undertaking multitask performance better than native interrupt has become an attraction for many of researchers.RTOS eminences comprise flexibility of architecture can be empowered, reliable for many tasks, actively developed, simple, and many others [8].
The main difference between RTOS and native interrupt is illustrated in Figure 1 and Figure 2. Figure 1 shows the task management in RTOS.If there is task whose higher priority, the lower priority task will be suspended and the high priority task will be executed.Whereas in native interrupt, the task which is inside the interrupt cannot be interrupted by another task before the previous task finished (Figure 2).
The utilization of RTOS (in this research free-RTOS was employed) due to its capability of multi-tasking.Multitasking is highly related to setting the priorities of tasks.In the freeRTOS the priorities of tasks can be determined by utilizing FreeRTOSConfig.h.The aforementioned priorities are ranging from 0 to (configMAX_PRIORITIES-1) [9].The value of (configMAX_PRIORITIES-1) could be defined freely, as long as it does not exceed the RAM capacity.However, if the chosen value is 1 (one) for configUSE_PORT_OPTIMISED _TASK_SELECTION in the FreeRTOSConfig.h,the value of configMAX_PRIORITIES is limited to 32.Whereas the task whose priority of 0 is called tskIDLE_PRIORITY.
In this research, native interrupt was also empowered to be compared with RTOS.The priorities of the above mentioned interrupt are listed in the microcontroller datasheet [10].To cite an instance, RESET whose the highest priority.To assign the interrupt, Interrupt Service Routine (ISR) must be written in the source code.Further-more, to activete the global interrupt in order to make the interrupt executed, macro sei() was assigned.
Interrupt employed to the system by activate the timer interrupt feature.Timer interrupt will interrupt main program with specific task in a specific time slice.Timer interrupt will execute the task after the timer is overflow.The amount of tick required (TC) to make timer overflow can be determined by put a value to the Timer Counter Register (TCCR) from equation(1) as follows: Illustration of differences between parallel and serial communication can be seen on Figure 3. Universal Synchronous Asynchronous Receiver Transmitter (USART) is one of a serial communication protocol.In general it uses two ports, one for transmitting data (TX port), and another one is for receiving data (RX port).If necessary, it can use one additional port as a clock for synchronous communication.USART can be activated via USART register in microcontroller.USART have three modes, asynchronous normal mode, asynchronous double speed, and synchronous mode.
Similar to interrupt, performance of USART depends on system clock and baud rate.System clock can be defined based on specification of microcontroller used on the system.Baud rate is a term of how many data/symbol can be transmitted in one time, which one symbol can contain more than one bit.
If N is an amount of bits in one symbol, required symbol to be sent is  =   .Baud rate can  However, current FreeRTOS version is not compatible to Xmega-family microcontroller yet.To overcome this, the additional configuration from [11] has been used in configur-ation file of Free-RTOS.Timer counter used as data logger in arduino was Timer1 library from Arduino Library [12].Timer1 provide library for timer counter in mili-second up to two decimal places.

Multitasking Configurations
This reseach conduct two type of multi-tasking system: (1) system with primitive Interrupt Service Routine (ISR) and ( 2) system with RTOS.Both system loaded with five parallel tasks : LCD display, servo, temperature sensor, USART receive process, and USART transmit process.Each of them scheduled in specific time.Detail of parallel tasks described in Table III.
This experiment use interrupt library from Atmel Software Framework (ASF): Programmable Multi-level Interrupt Controller (PMIC) module, specifically use timer interrupt.Based on feature of XMegaA256ABU, microcontroller used for this experiment provide four timer/counter register: C, D,E,F with each of them have two channel, channel 0 and 1.For this experiment, timer counter used for parallel task are C1 (USART: transmit), D0 (LCD), D1 (Temperature Sensor), E0(servo), E1 (USART: receive).
Configuration used in this research followed the standard of FreeRTOS, which configuration of system is defined in FreeRTOSConfig.hfile and when the task is created via the xTask-Create() function.For this research, every task is configured with the identical settings.Each task assigned to the same priority (priority 0) to assure they have the same amount of time slice.Moreover, each task have the same depth of stack, 500.

Software Interface Configurations
System used for experiment have sensor as input simulation and display and actuator as output simulation.For software driver, system use ASF modules to simpify implementation process.Internal temperature sensor from XMega board used to simulate input via Analog to Digital Converter (ADC) module, which connected to ADC register A. System also use GFX Monochrome module to print data from system.PWM used in this system run via direct register access on register C0.

USART Configurations
USART for this experiment also use ASF's implementation, which need some parameters to specify its feature.This experiment use two values for baud rate, 4800 and 9600, which will be explained in experiment scenario.As the system would transmit 48 Jurnal Ilmu Komputer dan Informasi (Journal of Computer Science and Information), Volume 9, Issue 1, February 2016 and receive data in character form, capacity of data for each packet is 8-bit length.USART for this experiment not use any parity bit and stop bit.

Experiment Scenarios
The experiments are divided into two main scenarios: (1) count and compare elapsed time of USART communication between two board, and (2) compared USART's reliability by comparing transmited and received data in the destination board.Scenario (1) itself also have two sub-scenarios: count time when system is (1.a) heavy-loaded (run many tasks) and (1.b) light-loaded (only run fewer tasks than first scenario).Scenario (2) has two components: (2.a) check differences of on amount of sent data with amount of received data and (2.b) send and receive string as sequence of characters.Table 4 shows scenario conducted in this research.Table 5 shows experimental parameter used in the scenario.
In details, scenario (1) counts ping time.For each experiment, ping is performed 100 times.Ping time obtained from total 100 ping time divided with 100 as a mean time.For scenario (1), both systems with RTOS and interrupt use same process and same amount of tasks.For sub-scenario (1.a), system is loaded with 5 different tasks: LCD, button, light sensor, temperature sensor, and servo, and in subscenario (1.b), system is only loaded with button and LCD with minimum display.See Table III for detail of task descriptions.
Scenario (2) will test data transmission and reception realibility.As same as scenario (1), each sub-scenario, (2.a) and (2.b) tested with three configurations: heavy-loaded, light-loaded and hybrid (heavy-light) loaded.Scenario (2.a) counts and compares amount of data received on destination board respect to replied data received on sender board.Scenario (2.b) tests data consistency by sending string as sequence of characters.Received string on destination board will be compared to sent string on source board to find whether any error or not.

Results and Analysis
Figure 5 shows the ping time comparison between RTOS and Interrupt if multitasking is run in heavy loaded system or light loaded system in baud rate 4800.The RTOS in light loaded outperformed the Interrupt.On the contrary, the Inter-rupt shows better performance in heavy loaded task.In RTOS, multitasking will be done within the specified time, which means that each task will be done when the specified time arrives.On the other hand, at the Interrupt task will be done by interrupting main process.
Results from the experiments show that average ping time for the RTOS in heavy loaded is 74.011 ms and the Interrupt in the same configuration is 33.249 ms.In light loaded experiment, the average ping time for the RTOS is 3.912 ms and the Interrupt is 11.943 ms.From experiments above, we can infer that communication's performance in RTOS depends on how many tasks loaded into the system.Figure 7 shows data loss comparison between RTOS and Interrupt if multitasking is run in heavy loaded system or light loaded system in baud rate 4800.The Interrupt both in heavy and light loaded systems shows better performance than the RTOS.This is due to multitasking in RTOS which would be done within the specified time.It means that each task would be done when the specified time arrives.It could cause a loss of data when the task has not yet completed but had moved on to another task.On the other hand, a task will be done by interrupting another task and do not swich to another task until that task was completed in the Interrupt.
From the experiment, we show that average data loss for the RTOS in heavy loaded is 7.7% data whereas the Interrupt in the same loaded is only 0.7% data.In light loaded experiment, the average data loss for the RTOS is 3.4% data and the Interrupt is 0.4% data.
Figure 8 shows data loss comparison between RTOS and Interrupt if the multitasking is run in heavy-loaded system or light loaded syste, in baud rate 9600.The Interrupt in heavy or light loaded experiment shows better performance than RTOS.Results the experiments shows that average data   6 shows experiment results of ping time scenario in hybrid loaded task.Ping time results show that light loaded task combined with heavy loaded task in interrupt method is the best in all baud rate.In details, if transmitter is light-loaded and the receiver is heavy-loaded then the ping time is faster than in reverse configuration.This result occurred because communication perf-ormance follows the heaviest side of the system, in this case is heavy-loaded side.Because of that, performance in hybrid configuration is almost similar for each configuration.However, just like the previous scenario, RTOS in heavy-loaded conf-iguration gives the worst result.From these results, we can say that both cases is not good for RTOS.However, RTOS in heavy loaded task combined with light loaded task gives the best standard deviation in all baud rate.
Table VII shows experiment results of data loss scenario in hybrid loaded task.The results show us that RTOS in light loaded combined with heavy loaded task gives the best performance with no loss of data.In contrary, RTOS in heavy loaded combined with light loaded task gives the worst performance with more than 1000 data loss.Received data from RTOS with heavy loaded task will be responded quickly in RTOS with light loaded task due to there is no other task interfere.Because of that, each response in RTOS with light-loaded configuration will be counted as data res-ponse and it will made data loss in the system.In contrary, transmitted data from RTOS with light loaded task will be responded slowly in RTOS with heavy loaded task due to there are many tasks pro-cessed in the system.So, RTOS with light loaded task will be waiting data response from RTOS with heavy loaded task and it made no loss of data.From Table 7, the Interrupt shows stable performan-ce with just 3.5 data loss in every baud rate and light-heavy load hybrid systems.

Conclusion
Inter-microcontroller communication is one of the crucial aspects in embedded systems.To do fast and reliable communication, the system have to manage its resources and do a simultaneus processes without interfering another tasks.Methods that can be used to manage the microcontroller's resources are Interrupt Service Routine (ISR) and Real Time Operating System.Interrupt and RTOS have different system workflows, so they have their own advantages and disadvantages.
From experiments conducted in this research, the results show that interrupt and RTOS give a competitive performance, either in communication speed and data reliability.In details, interrupt give better result in speed and data reliability than RTOS if loaded with many tasks.However, if the task load is minimum, RTOS give the best result in term of speed but still lose in data reliability.It is because each task in RTOS assigned its resource to the main CPU, so If the system contains combined task load (heavy-loaded board connected with light-loaded board), interrupt is the most stable system form speed and reliability.Specific in RTOS, data loss of the system which placed heavy system as transmitter will give the worst result, but in vice versa it give the best data accuracy.
In the end, speed and reliability of multi-tasking system to conduct inter-microcontroller communication depends on the task load of the system.Interrupt give better if the system want to focus on communication.However, interrupt only can handle a small amount of tasks because the limited amount of available timer counter register.If the main purpose of the system is to run a large amount of tasks, then RTOS is recommended.

Figure 3 .
Figure 3. Illustration of comparison between parallel and serial communication

TABLE 1 SPECIFICATION
(2)ian Habibie, et al., Performance Comparison of USART Communication 47be converted as bit rate by counting  =      .Correlation of system clock and baud rate, known as BSEL, used as input value to UBBR register.For example, the value for UBBR in USART asynchronous normal mode can be obtained from equation(2).Which   is clock of microcontroller,  is parameter to tune  to make it as close as its real value, and   is a desired value of baud rate.Common used baud rate are 4800, 9600, 19200, and so on.

50 Jurnal Ilmu Komputer dan Informasi (Journal of Computer Science and Information),
Volume 9, Issue 1, February 2016 loss for the RTOS in heavy-loaded is 7.2% data whereas the Interrupt in the same loaded has data loss of 0.3% of data.In light loaded experiment, the average data loss for the RTOS is 8.1% data and the Interrupt is 1.1% data.Table