Handling Delays without Blocking


This entry is part 3 of 3 in the series RTOS Alternatives.

RTOS Alternatives

In an earlier article we looked at the design and implementation of a time-triggered scheduler, but we didn’t consider the implications of actually using it. This can take some getting used to if you have never used such a system before. Imagine that we wanted to create a simple traffic light system… in a more traditional event-triggered design, it might look something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
typedef enum {
    LIGHT_RED,
    LIGHT_RED_AMBER,
    LIGHT_GREEN,
    LIGHT_AMBER
} traffic_light_state;

// Event triggered RTOS version.
void Traffic_Light_Controller(void *parameters) {
    while (1) {
        Set_Lights(LIGHT_RED);
        Delay(15000); // wait 15 seconds
        Set_Lights(LIGHT_RED_AMBER);
        Delay(2000); // wait 2 seconds
        Set_Lights(LIGHT_GREEN);
        Delay(15000);
        Set_Lights(LIGHT_AMBER);
        Delay(2000);
    }
}

In a typical RTOS, calling the Delay function will cause the task to become blocked for the given duration (it is often hard to tell from the documentation if the delay is up to or at least the value — I have seen both). Blocking a task involves removing it from the list of tasks that the scheduler can execute (the ready list) and using a context switch to resume another task instead. Obviously this functionality is not available in our simple scheduler, as we do not have the ability to save and restore contexts (which generally requires platform-specific assembly code).

Continue reading Handling Delays without Blocking →


Simple Co-Operative Scheduling


This entry is part 2 of 3 in the series RTOS Alternatives.

RTOS Alternatives

Last time, I looked at some of the simplest alternatives to using a Real-Time Operating System. The problem is, as soon as you need both accurate timing and prioritised tasks, you are out of luck — a foreground/background system would need a separate interrupt source per task priority, which can bring its own problems to the table:

Graph of predictability and functionality against number of interrupt sources

In order to meet our requirements and avoid these issues, we really need a scheduler… luckily, they aren’t too hard to write. The simplest of all schedulers is the Time-Triggered Co-operative (TTC) scheduler, in which tasks are released by a single timer interrupt (hitting the green ‘sweet spot’ on the above graph). This differs from foreground/background scheduling in that tasks are actually executed from the main function and not from the interrupt handler itself.

Continue reading Simple Co-Operative Scheduling →


Super Loops, Sandwich Delays and Foreground/Background Scheduling


This entry is part 1 of 3 in the series RTOS Alternatives.

RTOS Alternatives

As microcontrollers increase in speed and capacity, it’s becoming much more tempting to simply fit a full Real-Time Operating System (RTOS) into a design, without considering other options. This is a shame, because over time a number of alternatives have been developed that can be simple and effective. In this series, I will be discussing some of these, starting with the very simplest — the super loop.

Continue reading Super Loops, Sandwich Delays and Foreground/Background Scheduling →


Software Team Trade-Offs


A quote from Rands about the interaction in software development teams:

Time. Quality. Features. It’s usually described as a triangle, which somehow represents the state of your product or your feature. I believe the idea is that in a perfect and unattainable world, this triangle is perfect, equilateral, and seemingly at rest. There is balance among the time you have to release, the quality you are seeking to attain, and the features you want to ship.

In reality, this triangle is never at rest. It’s constantly shifting and, well, I don’t think it’s actually a triangle. It’s just a mental model that gives you just enough ammunition to lie.

The whole article is worth reading — I like the concept of “Bits”, “Features” and “Truth” as roles for certain people on the team. It seems more approachable than the traditional engineering manager, product manager and program manager titles.

I’m the Bits” does sound wrong, though.


The Case Against File Comments


Ville Laurikari, in an older post that recently made the Hacker News front page, talks about the evils of source-code templates:

Most projects have some kind of standard source code template which has the copyright and license text and placeholders for things like a description. All I have to say is: You don’t need a template. Stop using it.

He’s referring to things like this, found at the top of most source-code files:

1
2
3
4
5
/*
 * File: filename.c
 * Author: Peter J. Vidler
 * Copyright (c) 2010.  All rights reserved.
 */

Actually, that one’s fairly trivial — see the actual post for much worse example. His post actually seems to be about file-level comments, rather than comment templates, but it’s still worth a read.


Central Repositories in Mercurial


This entry is part 3 of 3 in the series Bite-Sized Mercurial.

Bite-Sized Mercurial

As a distributed version control system, Mercurial allows us to push and pull changes between any two repositories in an ad hoc manner. In reality, most projects can benefit from a central server (even if it’s just a repository on the lead developer’s machine) — somewhere accessible to keep an authoritative copy of the project.

In this article, I’ll look at one way to work with a remote central repository in order to share code with other developers.

Continue reading Central Repositories in Mercurial →


The C++ Confidence Curve


Louis Brandy on why you should never trust a programmer who says he knows C++:

Programmers (especially those coming from C) can very quickly get up to speed in C++ and feel quite proficient. These programmers will tell you that they know C++. They are lying. As a programmer continues in C++, he goes through this valley of frustration where he fully comes to terms with the full complexity of the language.

Very true, and worth a look just for the diagram.


Issues with the Ogg Container Format


With all the recent talk about Ogg Theora, H.264 and patent issues, it’s nice to read an article about the Ogg container format itself that is focussed entirely on technical details:

The Ogg container format is being promoted by the Xiph Foundation for use with its Vorbis and Theora codecs. Unfortunately, a number of technical shortcomings in the format render it ill-suited to most, if not all, use cases.

I have no idea how accurate the article is, but it was certainly refreshing.


Release Management in Mercurial


This entry is part 2 of 3 in the series Bite-Sized Mercurial.

Bite-Sized Mercurial

As I discussed previously there are many possible workflows to use with Mercurial; I will only be looking at some very specific scenarios. For example, it’s often the case that we want to separate work being done on cutting edge development from bug-fixes that get applied to the latest stable release. This is often done with branching — you have a main development branch and a separate branch for every significant release.

As with everything else, there are many ways to branch in Mercurial. I’ll start in this article by looking specifically at the use of named branches.

Continue reading Release Management in Mercurial →


Force Field Armour?


According to the Telegraph, the Defence Science and Technology Laboratory are developing a new type of armour for vehicles:

When a threat from incoming fire is detected by the vehicle, the energy stored in the supercapacitor can be rapidly dumped onto the metal plating on the outside of the vehicle, producing a strong electromagnetic field.

Polarise the hull plating?