Examples Problems in RTOS
Examples Problems in RTOS
1. Introduction.
This document describes the IDE68K Integrated Development Environment and the C/OS-II development flow. IDE68K gives you the ability to build simple C/OS-II applications for the 68000 or 68020 processor quickly and running them on the 68000/68020 Visual Simulator or the Command Line simulator. It is assumed that the reader has a working knowledge of: The basics of editing and compiling files with IDE68K. Assembly and C language programming. Addressing peripheral devices in the 680x0 architecture. More information on these subjects can be found in the Getting started with IDE68K document. It is assumed that IDE68K version 3.0 is installed on the PC (Windows 7, Vista or XP) and that the non-CPU specific files for C/OS-II are obtained from Micrim and copied to the C:\Ide68k\uCOSII directory as described in the Installing uCOS-II on IDE68K document. This tutorial provides step-by-step instructions for building and running a simple program based on the 68000 architecture and the C/OS-II RTOS.
-1-
2.1 Directories. Chose menu Options->Directories and set the default directory, the library directories and include directories as shown below. Chose your own default directory name that is meaningful to you. By default, this is the directory where the examples for IDE68K are stored. Change this to C:\Ide68k\OS Examples if you intend to run the example programs with C/OS-II. You only have to do this once, the first time you start IDE68K. The directory you specify is where IDE68K will save your source files and any IDE68K generated files. Library directories are the directories that are searched by the assembler when the INCLUDE directive is found in the source text. Include directories are the directories that are searched by the C compiler when the
#include <> preprocessor statement is found in the source text. Change the
Include directories entry to two directories, C:\Ide68k\Include where the standard header files are found and C:\Ide68k\uCOSII where C/OS-II specific header files are stored, both separated by a semicolon. Use the button to browse for the desired directories. Directories shown below are the directories used for running C/OS-II.
! !
2.2 Editor. Chose menu Options->Editor and set the properties for the editor and tabs as shown below. You can change the settings as you like. Note that there are three tab-settings for Assembly programs, C programs and other files. You only have to do this once, the first time you start IDE68K. Settings are saved automatically when you quit the program, or chose menu item Options->Save options.
-2-
2.3 Templates. Chose menu Options->Templates where you can set files that are used as templates. When you start a new file or project, the content of the template file is automatically inserted into the new file or project. No templates are set during the installation of IDE68K. Use the button to browse for the desired files.
-3-
2.4 Processor.
Chose menu Options->Processor and select the target processor (see below). You only have to do this only once, the first time you start IDE68K. Note that you cannot select the floating point coprocessor with the 68000 processor. This confirms with the hardware characteristics of the 68000, this CPU has no coprocessor interface.
3. Loading a project.
Programming for C/OS-II starts with loading an existing project or building a new project. A description of how to build a new C/OS-II project can be found in paragraph 6. To start with an existing project select menu-item Project->Open project, type the F5 function key or click on the toolbar button. A standard open file dialog is shown. Select Example_6(.prj) and click on the
-4-
Open button. The project edit dialog is displayed showing all the files for the project (see below).
C/OS-II kernel
To open a file for editing, select Example_6.c and click on the Open button. Clicking the OK button closes the dialog. You can also double-click on Example_6.c. The contents of the file are displayed in an edit window. Select menu-item Project->Project edit, type the F6 function key or click on the button to display the project edit dialog again.
-5-
-6-
Watch the program run, LED 0 will flash once every 2 seconds to indicate that the program is running. Place the mouse cursor on the slider button and move it up and down. The 7-segment display will indicated the slider position, 0 255. Menu-item Execute->Reset, typing the Ctrl+Break keys or clicking on the resets the simulator. toolbar button
Now insert the application file(s) in the project. This can be one file with the source code for all tasks but, when tasks become larger, the program code can be split in multiple files, one per task. Finally insert the library file. This file can be omitted when compiling for the 68020 and no library functions like sprintf() of strlen() are used. The 68000 always needs the library for functions to multiply or divide 32-bit numbers.
-7-
7. Examples.
A number of example projects are in directory C:\Ide68k\OS Examples. These programs have two purposes: (1) To test the RTOS running on IDE68K and (2) to get insight on how to program for multi-tasking. Example 1. This is a minimal program to verify multitasking. Two tasks are created, Task #1 prints This is task 1, task #2 prints This is task 2. However, simple and small as it is, there is a serious flaw in the program. The device to print on is a shared resource! The error can be observed as sometimes printing of task #2 is interrupted and the higher priority task #1 prints This is task 1 in the middle of This is task 2. A mutex or semaphore is required to synchronize both tasks. Example 2. This program checks the accuracy of the timer interrupt tick. The program prints the real-time clock time, then waits 1000 ticks and prints again. Printing should be at exactly 10 seconds intervals. The timer tick, at 10 ms intervals (100 interrupts per second) is generated by an internal timer in the Windows operating system.
-8-
Example 3. This program is basically the same as example 2 but uses a timer task. Example 4. This program uses a 1 second timer to cycle leds 0 and 1. Select the LED display in the Visual Simulator. Example 5. This program is basically identical to switches.asm or cswitches.c but uses tasks that communicate through a mailbox. Task #1 checks the switches at 1 second intervals. When the state of one or more switches has changed, a message is posted to task #2. This task displays the message, that is the state of the switches, on the LED display. Select Switches and LED display in the Visual Simulator. Example 6. This program has 3 tasks, task #1 checks the position of the slider control at 100 milliseconds interval. When the state of slider has changed, a message is posted to task #2. This task displays the message, that is the state of the slider (0 255) on the 7 segment display. A third task (the watchdog) flashes led nr. 0 of the LED array at 2 seconds interval to verify that the program is running. Select LEDs, Slider and 7-segment display in the Visual Simulator. Example 7. This program has 3 tasks, task #1, the LED-display task, sends a query to task #2, the slider-read task, pending on the query mailbox. After reception of the query message, task #2 reads the slider position and posts it back to task #1. Task #1 shifts the active LED one position to the right and then waits for the number of timer ticks derived from the slider position received from task #2. A flag is set every four shifts to signal this event to task #3. Task #3 waits on this flag and when set, generates a short tone on the PC speaker. Select LED's and Slider in the Visual Simulator.
-9-
Example 8. This program is basically Example #1 in the book MicroC/OS-II, The Real-Time
Kernel adapted to run on IDE68K instead of an IBM PC with MS-DOS. The program
creates 7 identical tasks that print their arguments, passed at creation time, at a random position on the display. The color corresponds to the argument value, 1 is blue (RGB = 001), 2 is green (RGB = 010), 3 is yellow (RGB = 011) and so on. The display is not the memory mapped display of the IBM PC but the much slower drawpad device of the simulator, in reality a bitmap in Windows. Characters are printed with a size of 20 x 10 (h x w) pixels. With a drawpad size set to 800 x 500 pixels, this corresponds to a text display of 25 lines, 80 characters per line. Another file, called display.c must be added to the project list. (See the project list for Example_8.prj) This file can be regarded as the display driver for the drawpad device. It isolates the drawpad specific I/O operations from the task program. Example 9. This program is basically Example #4 in the book MicroC/OS-II, The Real Time
- 10 -