<s>
DioneOS	B-Operating_System
(	O
pronounced	O
/djoneos/	O
)	O
is	O
a	O
multitasking	B-Operating_System
preemptive	B-Operating_System
,	O
real-time	B-Operating_System
operating	I-Operating_System
system	I-Operating_System
(	O
RTOS	B-Operating_System
)	O
.	O
</s>
<s>
The	O
system	O
is	O
designed	O
for	O
microcontrollers	B-Architecture
,	O
originally	O
released	O
on	O
2	O
February	O
2011	O
for	O
the	O
Texas	O
Instruments	O
TI	O
MSP430x	O
,	O
and	O
then	O
on	O
29	O
March	O
2013	O
for	O
the	O
ARM	O
Cortex-M3	O
.	O
</s>
<s>
Target	O
microcontroller	B-Architecture
platforms	O
have	O
limited	O
resources	O
,	O
i.e.	O
,	O
system	O
clock	O
frequency	O
of	O
tens	O
of	O
MHz	O
,	O
and	O
memory	O
amounts	O
of	O
tens	O
to	O
a	O
few	O
hundred	O
kilobytes	O
(	O
KB	O
)	O
.	O
</s>
<s>
The	O
RTOS	B-Operating_System
is	O
adapted	O
to	O
such	O
conditions	O
by	O
providing	O
a	O
compact	O
and	O
efficient	O
image	O
.	O
</s>
<s>
The	O
efficiency	O
term	O
here	O
means	O
minimizing	O
further	O
central	B-General_Concept
processing	I-General_Concept
unit	I-General_Concept
(	O
CPU	O
)	O
load	O
caused	O
by	O
system	O
use	O
.	O
</s>
<s>
According	O
to	O
this	O
definition	O
,	O
the	O
system	O
is	O
more	O
effective	O
when	O
it	O
consumes	O
less	O
CPU	O
time	O
to	O
execute	O
its	O
internal	O
parts	O
,	O
e.g.	O
,	O
managing	O
threads	B-Operating_System
.	O
</s>
<s>
The	O
DioneOS	B-Operating_System
system	O
is	O
intended	O
for	O
autonomic	O
devices	O
where	O
user	O
interface	O
has	O
limited	O
functions	O
.	O
</s>
<s>
The	O
core	O
functions	O
provided	O
by	O
the	O
system	O
is	O
an	O
environment	O
for	O
building	O
multitasking	B-Operating_System
firmware	B-Application
by	O
means	O
of	O
standard	O
,	O
well	O
known	O
concepts	O
(	O
e.g.	O
</s>
<s>
semaphores	B-Operating_System
,	O
timers	O
,	O
etc	O
.	O
)	O
.	O
</s>
<s>
Because	O
of	O
the	O
target	O
domain	O
of	O
application	O
,	O
the	O
system	O
uses	O
a	O
command-line	B-Application
interface	I-Application
and	O
has	O
no	O
graphical	B-Application
user	I-Application
interface	I-Application
.	O
</s>
<s>
Texas	O
Instruments	O
company	O
manufactures	O
a	O
wide	O
range	O
of	O
microcontrollers	B-Architecture
that	O
use	O
the	O
MSP430	B-Architecture
core	O
.	O
</s>
<s>
Depending	O
on	O
the	O
version	O
,	O
the	O
processor	O
contains	O
different	O
amount	O
of	O
flash	B-Device
memory	I-Device
and	O
random-access	B-Architecture
memory	I-Architecture
(	O
RAM	B-Architecture
)	O
,	O
e.g.	O
,	O
MSP430f2201	O
has	O
1KB/128B	O
correspondingly	O
,	O
but	O
MSP430f5438	O
has	O
256KB/16KB	O
.	O
</s>
<s>
When	O
the	O
size	O
of	O
the	O
memory	O
exceeds	O
64KB	O
limit	O
,	O
as	O
happens	O
when	O
the	O
memory	O
cannot	O
fit	O
in	O
a	O
range	O
0	O
–	O
64KB	O
,	O
16-bit	B-Device
addressing	O
is	O
insufficient	O
.	O
</s>
<s>
This	O
version	O
of	O
the	O
processor	O
has	O
wider	O
registers	O
(	O
20-bit	O
)	O
and	O
new	O
instructions	B-General_Concept
for	O
processing	O
them	O
.	O
</s>
<s>
The	O
DioneOS	B-Operating_System
supports	O
the	O
far	O
model	O
for	O
code	O
modules	O
,	O
so	O
large	O
firmware	B-Application
that	O
uses	O
extended	O
can	O
be	O
developed	O
and	O
run	O
under	O
the	O
system	O
's	O
control	O
.	O
</s>
<s>
The	O
firmware	B-Application
started	O
under	O
the	O
DioneOS	B-Operating_System
system	O
consists	O
of	O
threads	B-Operating_System
that	O
are	O
executed	O
in	O
pseudo-parallel	O
way	O
.	O
</s>
<s>
Each	O
thread	B-Operating_System
has	O
its	O
own	O
,	O
unique	O
priority	O
used	O
for	O
ordering	O
the	O
threads	B-Operating_System
,	O
from	O
most	O
important	O
to	O
least	O
.	O
</s>
<s>
The	O
thread	B-Operating_System
priority	O
value	O
defines	O
a	O
precedence	O
for	O
running	O
over	O
others	O
.	O
</s>
<s>
In	O
the	O
DioneOS	B-Operating_System
system	O
the	O
thread	B-Operating_System
can	O
be	O
in	O
one	O
of	O
following	O
states	O
:	O
</s>
<s>
Running	O
-	O
the	O
thread	B-Operating_System
is	O
currently	O
executed	O
by	O
processor	O
,	O
</s>
<s>
Ready	O
-	O
the	O
thread	B-Operating_System
is	O
ready	O
to	O
be	O
run	O
,	O
</s>
<s>
Waiting	O
-	O
the	O
thread	B-Operating_System
is	O
blocked	O
and	O
waits	O
on	O
some	O
synchronization	O
object	O
.	O
</s>
<s>
Because	O
there	O
is	O
only	O
one	O
core	O
in	O
the	O
processor	O
,	O
only	O
one	O
thread	B-Operating_System
can	O
be	O
in	O
Running	O
state	O
.	O
</s>
<s>
This	O
is	O
the	O
thread	B-Operating_System
that	O
has	O
the	O
highest	O
priority	O
from	O
all	O
threads	B-Operating_System
that	O
are	O
not	O
in	O
Waiting	O
state	O
.	O
</s>
<s>
Change	O
of	O
the	O
thread	B-Operating_System
state	O
can	O
be	O
caused	O
by	O
:	O
</s>
<s>
triggering	O
an	O
object	O
,	O
that	O
hold	O
the	O
thread	B-Operating_System
,	O
</s>
<s>
a	O
mutex	B-Operating_System
that	O
is	O
owned	O
by	O
someone	O
else	O
)	O
,	O
</s>
<s>
state	O
change	O
of	O
another	O
thread	B-Operating_System
,	O
that	O
may	O
lead	O
to	O
preemption	B-Operating_System
.	O
</s>
<s>
The	O
system	O
handles	O
up	O
to	O
16	O
threads	B-Operating_System
,	O
including	O
idle	O
one	O
with	O
the	O
lowest	O
priority	O
.	O
</s>
<s>
The	O
idle	O
thread	B-Operating_System
should	O
be	O
always	O
ready	O
to	O
be	O
run	O
,	O
and	O
never	O
switched	O
to	O
Waiting	O
state	O
,	O
so	O
it	O
is	O
not	O
permitted	O
to	O
call	O
any	O
functions	O
that	O
would	O
block	O
from	O
inside	O
this	O
thread	B-Operating_System
.	O
</s>
<s>
The	O
idle	O
thread	B-Operating_System
can	O
be	O
used	O
to	O
determine	O
total	O
system	O
load	O
.	O
</s>
<s>
The	O
DioneOS	B-Operating_System
system	O
provides	O
:	O
</s>
<s>
items	O
for	O
synchronisation	O
:	O
mutexes	B-Operating_System
and	O
counting	B-Operating_System
semaphores	I-Operating_System
,	O
used	O
for	O
thread	B-Operating_System
synchronization	O
,	O
signalling	O
from	O
ISR	B-Architecture
to	O
a	O
thread	B-Operating_System
and	O
guarding	O
shared	O
resources	O
,	O
</s>
<s>
methods	O
for	O
time	O
management	O
:	O
timers	O
,	O
thread	B-Operating_System
sleeping	O
,	O
timeouts	O
,	O
</s>
<s>
communications	O
items	O
implemented	O
by	O
events	O
and	O
queues	B-Application
available	O
as	O
circular	B-Data_Structure
buffers	I-Data_Structure
,	O
</s>
<s>
memory	O
management	O
by	O
memory	B-General_Concept
pool	I-General_Concept
that	O
allocates	O
memory	O
only	O
in	O
fixed-size	O
blocks	O
but	O
is	O
free	O
of	O
fragmentation	O
issues	O
that	O
may	O
appear	O
when	O
heap	B-Application
is	O
used	O
.	O
</s>
<s>
Regular	O
allocation	O
by	O
malloc/free	O
on	O
heap	B-Application
is	O
also	O
available	O
,	O
it	O
is	O
provided	O
by	O
standard	O
C	B-Language
libraries	B-Library
.	O
</s>
<s>
As	O
it	O
was	O
stated	O
in	O
the	O
'	O
Threads	B-Operating_System
Management	O
 '	O
chapter	O
,	O
the	O
firmware	B-Application
consists	O
of	O
pseudo-parallel	O
threads	B-Operating_System
.	O
</s>
<s>
Each	O
thread	B-Operating_System
has	O
its	O
own	O
context	O
,	O
that	O
contains	O
core	O
registers	O
of	O
the	O
processor	O
,	O
last	O
execution	O
address	O
and	O
private	O
stack	O
.	O
</s>
<s>
During	O
the	O
switch	O
between	O
threads	B-Operating_System
the	O
system	O
saves	O
the	O
context	O
of	O
stopped	O
thread	B-Operating_System
and	O
recovers	O
the	O
context	O
of	O
the	O
one	O
being	O
run	O
.	O
</s>
<s>
This	O
state	O
saving	O
makes	O
possible	O
breaking	O
the	O
thread	B-Operating_System
execution	O
and	O
further	O
continuation	O
,	O
even	O
if	O
between	O
them	O
other	O
thread	B-Operating_System
has	O
been	O
executed	O
.	O
</s>
<s>
Note	O
that	O
preemption	B-Operating_System
followed	O
by	O
context	B-Operating_System
switch	I-Operating_System
may	O
happen	O
in	O
any	O
moment	O
,	O
even	O
if	O
no	O
system	O
function	O
is	O
called	O
in	O
the	O
thread	B-Operating_System
.	O
</s>
<s>
Although	O
it	O
may	O
happen	O
in	O
unexpected	O
location	O
in	O
the	O
executed	O
code	O
,	O
the	O
thread	B-Operating_System
work	O
is	O
not	O
distorted	O
due	O
to	O
the	O
system	O
and	O
the	O
context	O
saving	O
.	O
</s>
<s>
From	O
the	O
thread	B-Operating_System
point	O
of	O
view	O
,	O
the	O
switch	O
can	O
be	O
done	O
in	O
background	O
.	O
</s>
<s>
The	O
context	B-Operating_System
switch	I-Operating_System
is	O
critical	O
operation	O
in	O
the	O
system	O
and	O
the	O
time	O
of	O
its	O
execution	O
determines	O
if	O
how	O
effective	O
the	O
system	O
is	O
.	O
</s>
<s>
Because	O
of	O
that	O
the	O
context	B-Operating_System
switch	I-Operating_System
in	O
the	O
DioneOS	B-Operating_System
system	O
was	O
optimized	O
for	O
short	O
time	O
.	O
</s>
<s>
The	O
most	O
important	O
parts	O
were	O
written	O
in	O
assembler	B-Language
,	O
so	O
the	O
switch	O
can	O
be	O
done	O
in	O
12	O
–	O
17μs	O
(	O
for	O
fosc	O
=	O
25MHz	O
)	O
.	O
</s>
<s>
In	O
the	O
DioneOS	B-Operating_System
system	O
the	O
context	B-Operating_System
switch	I-Operating_System
can	O
be	O
initiated	O
from	O
interrupt	B-General_Concept
handler	I-General_Concept
(	O
interrupt	B-General_Concept
service	I-General_Concept
routine	I-General_Concept
)	O
.	O
</s>
<s>
This	O
property	O
is	O
useful	O
for	O
moving	O
an	O
event	O
handling	O
to	O
the	O
thread	B-Operating_System
and	O
commonly	O
implemented	O
in	O
two-layer	O
architecture	O
:	O
</s>
<s>
the	O
interrupt	B-General_Concept
handler	I-General_Concept
-	O
is	O
called	O
after	O
hardware	O
interrupt	O
has	O
occurred	O
.	O
</s>
<s>
higher	O
layer	O
-	O
processing	O
in	O
separated	O
thread	B-Operating_System
without	O
blocking	O
interrupts	O
;	O
this	O
thread	B-Operating_System
can	O
be	O
preempted	O
.	O
</s>
<s>
Constraints	O
are	O
not	O
so	O
tight	O
here	O
as	O
in	O
the	O
interrupt	B-General_Concept
handler	I-General_Concept
.	O
</s>
<s>
The	O
context	B-Operating_System
switch	I-Operating_System
measured	O
from	O
signaling	O
point	O
in	O
ISR	B-Architecture
to	O
other	O
thread	B-Operating_System
recovery	O
takes	O
10us	O
(	O
for	O
fosc	O
=	O
25MHz	O
)	O
in	O
the	O
DioneOS	B-Operating_System
system	O
.	O
</s>
<s>
The	O
DioneOS	B-Operating_System
has	O
multiple	O
configuration	O
options	O
that	O
affects	O
features	O
inserted	O
in	O
the	O
compiled	O
image	O
of	O
the	O
system	O
.	O
</s>
<s>
A	O
lot	O
of	O
them	O
are	O
source	O
code	O
switches	O
that	O
are	O
gathered	O
in	O
configuration	B-Protocol
file	I-Protocol
and	O
can	O
be	O
altered	O
by	O
a	O
developer	O
of	O
firmware	B-Application
.	O
</s>
<s>
Example	O
of	O
a	O
fragment	O
of	O
configuration	B-Protocol
file	I-Protocol
:	O
</s>
