What happens on a single device, The scheduler, When clauses – Echelon Neuron C User Manual

Page 28

Advertising
background image

16

Focusing on a Single Device

What Happens on a Single Device?

In this chapter, you begin to learn about programming a Neuron Chip or Smart

Transceiver by focusing first on a single device. Each Neuron Chip and each
Smart Transceiver has standard firmware, called the

Neuron firmware

, and

hardware support that implement a scheduler, timers, and I/O device drivers and

interfaces. Series 5000 chips also provide hardware support for interrupts; see

Interrupts

on page 153 for more information.

The Neuron C language includes predefined objects that provide access to these

firmware features. These objects are described briefly here, and in more detail
later in this chapter:

• The Neuron firmware's

event scheduler

handles task scheduling for the

application program. This chapter explains how to use the Neuron C

language to define events and tasks, how the scheduler evaluates

nonpriority events, and how you can define priority events.

• The Neuron C language offers two types of

timer

objects: millisecond and

second timers. These timers can be used to affect the scheduling of tasks,
as described in

Timers

on page 25.

• A number of

I/O objects

can be declared using Neuron C extensions to

ANSI C. These I/O objects, as well as related I/O functions and events,

are described in

Input/Output

on page 27.

The Scheduler

The scheduling of application program tasks is event driven: when a given
condition becomes TRUE, a body of code (called a

task

) associated with that

condition is executed. The scheduler allows you to define tasks that run as the

result of certain events, such as a change in the state of an input pin, receiving a
new value for a network variable, or the expiration of a timer. You can also

specify certain tasks as priority

tasks, so that they receive preferential service

(see

Priority When Clauses

on page 23). Series 5000 chips also allow you to

specify interrupt tasks that are serviced independently of the scheduler; see

Interrupts

on page 153 for more information.

When Clauses

Events are defined through when clauses. A when clause contains an expression
that, if evaluated as TRUE, causes the body of code (the

task

) following the

expression to be executed to completion. Multiple when clauses can be associated
with a single task. A simple when clause and its associated task are shown

below. The when clause or clauses and the associated task are frequently

referred to as one entity known as a

when task

or a

when statement

.

when (timer_expires(led timer))

{

// Turn off the LED

io_out(io_led, OFF);

}

when clause

task

Advertising