Книга: Embedded Linux development using Eclipse

5.2 Thermostat Internals

Let’s take a closer look at how the thermostat program is organized before we run it under the debugger. As shown in Figure 5.5, thermostat consists of three modules:

• thermostat.c — The main()function that implements the thermostat state machine and outputs the current temperature to stdout. main() takes a run-time argument that is the delay between samples in seconds. The default is two seconds.

• simdrive.c — A set of simulated device driver functions for an A to D converter and digital output.

• monitor.c — A separate thread that monitors the keyboard for operator input to change the thermostat operating parameters — setpoint, limit, and deadband.


Figure 5.5: Simulated thermostat.

simdrive uses a shared memory region to communicate with the simulated devices program. devices uses the ncurses library to create a pseudo-graphical user interface. It just reads A/D input values entered by the user and depends on a signal sent by thermostat_s to indicate a change in one of the output bits. Entering a non-numeric value for the A/D terminates the program.

The command syntax for changing parameter values is fairly simple. It’s just a single lower case letter followed by a number:

• s — setpoint

• l — limit

• d — deadband

The monitor thread just sets the new value into the corresponding global variable. Although it’s probably not strictly necessary in this case, access to the global variables is protected by a mutex because that’s the right thing to do.

Have a look through the four source files to see how it all hangs together.

Оглавление книги

Оглавление статьи/книги

Генерация: 0.031. Запросов К БД/Cache: 0 / 0
поделиться
Вверх Вниз