- Introduction
- Embedded Hardware
- Embedded Software
- Embedded Development Tools
Saturday, April 30, 2011
Introduction to Embedded Systems
Saturday, May 29, 2010
Adding Interrupts to uCOS-II Running on Microsoft Windows
In the past few days, I was asked that question many times. So, I decided to make a small software example to show how uCOS-II interrupts can be simulated under Windows.
I modified the uCOS-II port to support 8 interrupts at the same level of priority. Moreover, these interrupts can occur simultaneously but their ISR execution order depends on the implementation. I followed the uCOS-II tasks's priority schema with interrupts (i.e. the smaller the interrupt number, the faster it will be executed).
The implementation core is done by creating a Win32 thread as a generic IRQ handler in os_cpu.c. In addition, 2 utilities were added in the file pc.c. They are used to register and unregister user ISRs. ISRs will be written only in C.
Testing the Interrupts Implementation
My test code is based on the 1st example in uCOS-II book. I modified this code to have 5 tasks with the highest priority to be interrupt-driven. Each task of the 5 will wait for a semaphore before printing its number on the screen. ISRs will trigger these tasks by signaling the semaphores. The test code can be found here.
To automate this test, I wrote a utility that generates these 5 interrupts randomly every 2 milliseconds. The code for this utility can be found here. I just run my test code then run the interrupt generation utility. To distinguish the interrupt-driven tasks from others, I modified their code to print their IDs in a new color scheme. The interrupt generation utility code is found here.
Fig 1 shows the application running with interrupts. Numbers with blue background are those printed by tasks driven by interrupts.
Figure 1: Example 1 Modified to Run with Interrupts
Friday, May 28, 2010
Running Timer's of uCOS-II to Measure Cycle Average Execution Time
Embedded applications need to schedule future events. This can be accomplished using timers and timers' services.
Timers are an integral part of any real-time system. A timer can be seen as an event scheduling according to a predefined time value in the future, exactly like setting an alarm clock.
Embedded systems that have time-sensitive activities use 2 types of timers; hard-timers and soft-timers. Hard timers are based on physical timers on the chip that directly interrupt the CPU. A hard-timer is a must in case of an application demanding high precision and predication. On the other hand soft-timers are scheduled through a software facility that enables soft-timer's maintenance, installation, and removal.
But if hard-timers are more accurate than their soft counterparts, why are they used? The answer is in their nature. The can be programmed with timeouts of course granularity. In addition, the high-precision is not always needed in most of embedded systems. Another prevailing reason is reducing system interrupt overhead. Facilities of soft-timers are built using only 1 hardware-timer.
Software Timers in uCOS-II
Starting from uCOS-II V2.8x, uCOS-II added the soft-timers feature. uCOS-II timers have 2 modes of operations; periodic and 1-shot modes. Whenever a timer timeouts, a callback function is executed. This service is implemented as a uCOS-II task. This task is assigned a stack size and priority defined the macros OS_TASK_TMR_STK_SIZE and OS_TASK_TMR_PRIO respectively. This task is signaled from the tick ISR at a constant rate defined by the macro OS_TMR_CFG_TICKS_PER_SEC. Whenever signaled, it updates the soft timers created by the user and make calls to callback functions if they expire. The design structure used for timers implementation is wheel spoke. Like any other uCOS-II service, this service is highly configurable. In order to use it you have to:
1. Define OS_TMR_EN to a value greater than zero
2. Define OS_TASK_TMR_STK_SIZE and OS_TASK_TMR_PRIO
3. Define frequency of timers update through OS_TMR_CFG_TICKS_PER_SEC
4. Enable hooks
5. Modify OSTimeTickHook to signals the timers manager task as explained here
6. Use any of timers management APIs in your application
Measuring Execution Time
To test the execution time of a cyclic task, you should use the OSTimeGet API at its start and end to measure the execution time. You should accumulate the total execution time and the number of cycles executed in order to calculate average cycle execution time. The soft-timer will be used to calculate this average at periodic rates. A code example is can be found here.
Fig 1 shows the result of running that code.
Figure 1: Timer Measuring Execution Time
Thursday, April 29, 2010
Running FreeRTOS with Microsoft Windows Vista in 1 Hour
FreeRTOS is a real-time operating system for embedded systems, being ported to several microcontrollers. It is distributed under the GPL with an optional exception. The exception permits users' proprietary code to remain closed source while maintaining the kernel itself as open source, thereby facilitating the use of FreeRTOS in proprietary applications.
FreeRTOS is designed to be small and simple. The kernel itself consists of only three or four C files. To make the code readable, easy to port, and maintainable, it is written mostly in C, but there are a few assembler functions included where needed (mostly in architecture specific scheduler routines). The download contains prepared configurations and demonstrations for every port and compiler, allowing rapid application design.
Another related project is OpenRTOS, which has an identical code base to FreeRTOS but with different licensing. The OpenRTOS license removes all reference to the GPL and its implications. For example, one of the conditions of using FreeRTOS in a commercial product is that the user is made aware of the use of FreeRTOS and the source code must be provided upon request. OpenRTOS doesn't have this requirement.
SafeRTOS is a derivative version of FreeRTOS that has been analyzed, documented and tested to meet the stringent requirements of the IEC 61508 safety standard. Complete safety lifecycle documentation artifacts have been created and independently audited to verify IEC 61508 SIL 3 conformance.
FreeRTOS and Windows Simulation
Can the Industrial PC port run under Windows? The answer is yes. In FreeRTOS, there is an x86 port that can run in a dos emulation box. But you should take care that it is a simulation and won't give you the correct response. In addition, there is an ARM port that can be simulated within Keil.
Steps to Run the x86 Port Under Microsoft Windows
1. Download the latest FreeRTOS from here
2. Unpack it under C Drive
3. Download the OpenWatcom tools for windows from here and install it under C drive
4. Open the Open Watcom project in the FreeRTOS/Demo/PC directory - it is called rtosdemo.wpj
5. In main.c, comment the line "vStartComTestTasks( mainCOM_TEST_PRIORITY, serCOM1, ser115200 );" or you will get errors about COM1 not available
Figure 1: FreeRTOS Running Under Microsoft Windows Vista
Next
I think the next step is to make a complete free course about FreeRTOS. This tutorial will serve as a starting point to build complete labs based on windows simulation. I hope, they will be a success like the uCOS-II courses I made earlier.
Tuesday, April 27, 2010
uC/TCP-IP Book Companion Software Now Available From Micrium Website
uC/TCP-IP
uC/TCP-IP is a compact reliable, and high-performance stack that was built from the ground up by Micrium. Unlike other available TCP/IP stacks, Micrium's µC/TCP-IP has the quality, scalability, and reliability that translate into a rapid configuration of required network options, remarkable ease-of-use, and rapid time-to-market. This stackis described in the book "uC/TCP-IP The Embedded Protocol Stack". The stack is highly CPU independent and has been ported to numerous devices. The software provided together with the book and via the web site may be evaluated. Windows evaluation is also available via this link.
uC/TCP-IP Win32 Simulation
The uC/TCP-IP allows you to test your application on a PC even before your target HW is ready. Many tutorials are freely available for developing and debugging applications on top of uC/TCP-IP. These tutorials include:


