University of Waterloo

CS 452/652 - Real-time Programming

     I hear the train a comin'
     It's rollin' 'round the bend
     And I ain't seen the sunshine
     Since I don't know when...

     Johnny Cash

Winter 2022

Comp Sec Camp Loc Time Days/Date Bldg Room Instructor
LEC 001UW U1:30-2:20 MWFMC 4045Martin Karsten

Instructor's Name Office Location Contact Office Hours
Martin Karsten DC 3506 open door / by appointment

Registrar's Schedule of Classes

Teaching Assistants

Course Overview

The course presents tools and techniques for real-time programming, including system support for real-time applications and calibrating interfaces to hardware. One part of the course is writing a small, real-time-capable operating system that runs on stand-alone computers and provides a low-level interface to control electric trains. The second part is concerned with building a control application for the trains.

Course Objectives

At the end of the course, successful students will be able to:
  1. program low level system services in assembly language,
  2. program hardware interfaces in C/C++,
  3. develop a multi-tasking runtime kernel providing message passing,
  4. develop a multi-task application based on message passing, and
  5. develop a calibrated control application for external hardware.


Piazza is used as the primary communication channel for announcements, clarifications, questions, discussions, etc. It is expected that all students are familiar with all material posted and discussed on Piazza. There are different Q&A folders for (more might be added as needed):

For any personal matters, please email the instructor.

Contingency Plans for COVID-19

Note: Please be aware of all University regulations concerning COVID-19.

The course will start with in-person teaching and lab access on Jan 5. The lecture hall MC 4045 is large enough to accommodate all registered students even with a 50% capacity limit. However, the course and its learning objectives critically depend on software development and testing in the trains lab MC 3018.

Depending on capacity limits for MC 3018 and final enrolment numbers it might become necessary to restrict and manage lab access using an online reservation system. In this case, it might be necessary to adjust assignment deadlines to give all students sufficient opportunity to develop and test their software in the lab. Such changes will be communicated on Piazza and by adding updates to the course outline.

In case of a short-term (e.g., one week) cancellation of in-person activities, classes and discussions will be held online during the assigned time slots. Assignment deadlines will be adjusted to accommodate for periods of time when the lab might not be available.

In case of a longer cancellation of in-person activities, the course will pivot to teaching advanced operating system design and implementation. Online lectures will be accompanied by software assignments that can be completed at home or remotely using university servers.

IMPORTANT: If the COVID situation deteriorates to make it impossible to complete at least the first train control assignment TC1, the course will not be credited as CS 452/652, but instead as CS 489/689 (more explicitly, students in CS 452 would instead receive a credit for CS 489, and students in CS 652 would receive a credit for CS 689). In this case, students will be able to retake a complete offering of CS 452/652 in a future term - potentially with slightly adjusted expectations depending on the overlap between W22 and a future offering. Note that TC1 is currently scheduled for March 9. Please review all academic deadlines with respect to this contingency.


If a student needs to self-isolate due to COVID protocols, individual adjustments will be made to assignment deadlines and/or weighting depending on the particular circumstances.

Lecture Notes

Lecture notes will be posted here after class. They are telegraphic, so they are not a substitute for the lectures. But if you attend the lecture they will most likely be a good memory prosthetic.


Assignment A0 is to be completed independently by each student. Afterwards, groups of 2 students (or 3 in exceptional circumstances) work on the remaining assignments.

IMPORTANT: Late assignment submissions will not be accepted. Plagiarism detection software will be used. Students might be asked to meet with TAs and explain their code. See below for further information about academic integrity and appeals. Also see Notes on Assignments.

Due dates below are tentative until the assignment is published.

AssignmentLink to AssignmentDue DateNotes
A0Polling LoopWed, Jan 12, 9:00amCommunication with Trains and Terminal
K1Kernel (Part 1)Wed, Jan 26, 9:00amContext-Switch, Task Scheduling
K2Kernel (Part 2)Mon, Jan 31, 9:00amMessage Passing, Name Server
K3Kernel (Part 3)Mon, Feb 7, 9:00amEvent Notification, Clock Server
KCSKernel Context SwitchWed, Feb 9, 9:00amIn-Class Presentations on Feb 9 and 11
K4Kernel (Part 4)Fri, Feb 18, 9:00amUART Server(s)
TC1Train Control (Part 1)Wed, Mar 9, 9:00amDemo: control one train
Final Project - ProposalWed, Mar 16, 9:00am
TC2Train Control (Part 2)Wed, Mar 23, 9:00amDemo: control multiple trains
Final ProjectMon, Apr 4, 9:00amDemo

Exams and Marking

Final Exam30%

The final exam is scheduled for Monday, April 11 and will cover material from the entire course. It will be given as take-home exam and be made available here on April 10, 10am. Exam answers have to be submitted by email to the instructor by April 11, 10pm.

Different instructors emphasize different topics in various ways. Also, course material is continuously updated. With that in mind, previous exams are available in the hope that they will be useful, but WITHOUT ANY WARRANTY!

Note: Downloads require UW authentication.

UW Final Exam Regulations
Math Faculty INC Rules



The lab room is MC 3018. The lab is for the exclusive use of CS 452 students. The access code is announced in class. Do not give the code to other students! The usual rules apply, such as no food. Please see CSCF Teaching Lab Policies for details.

The workstations in the main room run Ubuntu Linux with access to the regular linux.student.cs environment. The workstations in the inner room run a slightly different Linux setup with a default login and are connected to grey boxes that contain the embedded ARM computers. Two of those are connected to train tracks. You can use the gtkterm terminal emulator to communicate with the ARM computer via serial interface.

ARM Computer

The ARM computer in the grey box is a TS-7200 single-board computer based on the EP9302 system-on-a-chip (SoC) that uses an ARM 920T processor. The processor implements ARM architecture version ARMv4T. The most relevant manuals are provided here: Additional documentation for reference:

Train Set

The track and trains are controlled by sending commands via the serial interface.


cross compiler:/u/cs452/public/xdev/bin/arm-none-eabi-gcc
example code:/u/cs452/public/iotest/ (see README)




Providing Course Materials to Third-Party Organization

In short: Do not provide course materials to third-party organizations. See
these guidelines for details.

Academic Integrity

In order to maintain a culture of academic integrity, members of the University of Waterloo community are expected to promote honesty, trust, fairness, respect and responsibility. [Check the Office of Academic Integrity for more information.]


A student who believes that a decision affecting some aspect of their university life has been unfair or unreasonable may have grounds for initiating a grievance. Read Policy 70, Student Petitions and Grievances, Section 4. When in doubt please be certain to contact the department's administrative assistant who will provide further assistance.


A student is expected to know what constitutes academic integrity to avoid committing an academic offence, and to take responsibility for their actions. [Check the Office of Academic Integrity for more information.] A student who is unsure whether an action constitutes an offence, or who needs help in learning how to avoid offences (e.g., plagiarism, cheating) or about "rules" for group work/collaboration should seek guidance from the course instructor, academic advisor, or the undergraduate associate dean. For information on categories of offences and types of penalties, students should refer to Policy 71, Student Discipline. For typical penalties, check Guidelines for the Assessment of Penalties.


A decision made or a penalty imposed under Policy 70, Student Petitions and Grievances (other than a petition) or Policy 71, Student Discipline may be appealed if there is a ground. A student who believes they have a ground for an appeal should refer to Policy 72, Student Appeals.

Note for Students With Disabilities

AccessAbility Services located in Needles Hall, Room 1401, collaborates with all academic departments to arrange appropriate accommodations for students with disabilities without compromising the academic integrity of the curriculum. If you require academic accommodations to lessen the impact of your disability, please register with AccessAbility Services at the beginning of each academic term.

Text matching software (Turnitin©) may be used to screen assignments in this course. Turnitin© is used to verify that all materials and sources in assignments are documented. Students' submissions are stored on a U.S. server, therefore students must be given an alternative (e.g., scaffolded assignment or annotated bibliography), if they are concerned about their privacy and/or security. Students will be given due notice, in the first week of the term and/or at the time assignment details are provided, about arrangements and alternatives for the use of Turnitin in this course.

It is the responsibility of the student to notify the instructor if they, in the first week of term or at the time assignment details are provided, wish to submit alternate assignment.