ELT048 - Embedded Operational Systems: Rodrigo Maximiano Antunes de Almeida @rmaalmeida Universidade Federal de Itajubá
ELT048 - Embedded Operational Systems: Rodrigo Maximiano Antunes de Almeida @rmaalmeida Universidade Federal de Itajubá
ELT048 - Embedded Operational Systems: Rodrigo Maximiano Antunes de Almeida @rmaalmeida Universidade Federal de Itajubá
Systems
Rodrigo Maximiano Antunes de
Almeida
rmaalmeida@gmail.com
@rmaalmeida
Universidade Federal de Itajubá
Creative Commons License
U
UNN II F
FEE II
Schedule
1. Intro / Pointers / Buffers 1. FreeRTOS
2. Function pointers / tasks 2. Heap Memory
/ kernel 3. Task Management
3. Scheduler / Cooperative 4. Queues
kernel / priorities
(RMS) 5. Resource Management
4. Timing requirements 6. *Soft Timers & Int
5. Drivers 7. 2nd Test
6. Drivers Controller 8. Substitutive test
7. 1st Test
8. Preemptive Kernel,
U
UNscheduler
N II F
FEE II
Labs Schedules
• L1 – Circular buffer & function pointers
• L2 – Kernel + Priorities
• L3 – Kernel + Timing
• L4 – Drivers
• L5 – FreeRTOS
• L6 – Tasks Management
• L7 – Queues
• L8 – Mutexes & Semaphores
U
UNN II F
FEE II
Fast Intro
U
UNN II F
FEE II
Moore Law
U
UNN II F
FEE II
LPC800
U
UNN II F
FEE II
LPC800
U
UNN II F
FEE II
LPC800
U
UNN II F
FEE II
KL02
U
UNN II F
FEE II
KL02
• MKL02Z32CAF4RTR-
ND
32K flash
4k ram
US$1,76
U
UNN II F
FEE II
The OS
What is a kernel?
What is a kernel?
U
UNN II F
FEE II
What is a kernel?
• Kernel tasks:
Manage and coordinate the processes execution using
“some criteria”
Manage the free memory and coordinate the processes
access to it
Intermediate the communication between the hardware
drivers and the processes
U
UNN II F
FEE II
What is a kernel?
Interface Internal
System logic
actions routines
C/C++
GUI Extra libs
libraries
Kernel
Context switch
File system Drivers
U
UNN II F
FEE II
Develop my own
kernel?
Why not?
Develop my own kernel?
• Kernel overhead (both in time and memory)
• Free and paid alternatives
• Time intensive project
• Continuous development
U
UNN II F
FEE II
Kernel Project
• Source code size (millions of lines)
FreeBSD – 8.8
IOS – 80
Linux (2.6.0) – 5.2
Linux (3.6) – 15.9
Debian 7.0 – 419
Mac OS X 10.4 – 86
OpenSolaris – 9.7
Windows NT – 11
Windows XP – 45
Windows Vista – 66
U
UNN II F
FEE II
Develop my own kernel?
• Alternatives
Windows Embedded Compact®
VxWorks®
X RTOS®
uClinux
FreeRTOS
BRTOS
U
UNN II F
FEE II
Programming
concepts
Pointers
https://xkcd.com/
Pointers
• They are variables that store the address (location)
of memory.
In these memory addresses it is possible to enter values.
• The type of the value placed in the memory pointed
by the address is defined in the declaration of the
pointer.
The type that tells the compiler how much memory is
needed to store the values.
• A pointer variable points to a variable of a certain
type (char, int, float, double, ...).
U
UNN II F
FEE II
Pointers
• It is necessary in the • Sintax:
declaration of a pointer, • type *variableName;
to specify for which
type of variable it will
point.
• Pointers are declared
with a * before the
variable name.
U
UNN II F
FEE II
Pointers
• aux, temp, and pont are int *aux;
variables that store float *temp;
memory addresses and char *pont;
not variable of the types
int, float, or char.
• * is used when you
want to access the value
that is in the memory
location and not the
memory address.
U
UNN II F
FEE II
Pointers
U
UNN II F
FEE II
Pointers
• Operator &: • Operator *:
Always gets the address The * operator does the
of a variable opposite of the &
Since pointers are also operator.
variables, they also Given a pointer, the *
occupy memory. operator accesses the
You can get the pointer content pointed to by it.
address and have
pointers to pointers
(multiples *).
U
UNN II F
FEE II
Pointers
• Operator &: • Operator *:
“get the address of” “dereference”
“saved in” “through”
“pointed by”
U
UNN II F
FEE II
Pointers
#include <stdio.h>
U
UNN II F
FEE II
Parameter passing
• When sending, the parameters are copied to a
temporary variable, so that changes in its value are
lost after the end of the function.
• The initial variable is not changed
• To avoid this situation it is common to pass the
parameter by reference.
• When passing by reference, the address of the
variable is passed instead the value. Therefore the
function can change the value of the original
variable.
U
UNN II F
FEE II
Parameter passing
void incrementa(int a){
a += 1;
}
incrementa(x);
return 0;
}
U
UNN II F
FEE II
Rotina Principal Função
void main(void){
int x = 10;
incrementa(x);
void incrementa(int a){
a+=1;
return;
}
return 0;
}
U
UNN II F
FEE II
Rotina Principal Função Variáveis
void main(void)
{
int x = 10; x=10
U
UNN II F
FEE II
Rotina Principal Função Variáveis
void main(void)
{
int x = 10; x=10
temp=10
inc(x); void inc(int a){
a += 1;
return;
}
return 0;
}
U
UNN II F
FEE II
Rotina Principal Função Variáveis
void main(void)
{
int x = 10; x=10
a=10
inc(x); void inc(int a){
a += 1;
return;
}
return 0;
}
U
UNN II F
FEE II
Rotina Principal Função Variáveis
void main(void)
{
int x = 10; x=10
a=11
inc(x); void inc(int a){
a += 1;
return;
}
return 0;
}
U
UNN II F
FEE II
Rotina Principal Função Variáveis
void main(void)
{
int x = 10; x=10
descartado
inc(x); void inc(int a){
a += 1;
return;
}
return 0;
}
U
UNN II F
FEE II
void incrementaptr(int* a){
(*a) += 1;
}
int main(int argc, char *argv[]){
int x = 10;
incrementaptr(&x);
return 0;
} //end main
U
UNN II F
FEE II
Rotina Principal Função Variáveis
void main(void)
{
int x = 10; x=10
U
UNN II F
FEE II
Rotina Principal Função Variáveis
void main(void)
{
int x = 10; x=10
temp=&x
incptr(&x); void incptr
(int* a){
(*a) += 1;
return;
}
return 0;
}
U
UNN II F
FEE II
Rotina Principal Função Variáveis
void main(void)
{
int x = 10; x=10
a=&x
incptr(&x); void incptr
(int* a){
(*a) += 1;
return;
}
return 0;
}
U
UNN II F
FEE II
Rotina Principal Função Variáveis
void main(void)
{
int x = 10; x=11
a=&x
incptr(&x); void incptr
(int* a){
*
(*a) += 1;
return;
}
return 0;
}
U
UNN II F
FEE II
Rotina Principal Função Variáveis
void main(void)
{
int x = 10; x=11
descartado
incptr(&x); void incptr
(int* a){
(*a) += 1;
return;
}
return 0;
}
U
UNN II F
FEE II
Parameter passing
• Passing parameters by reference allows a function
to "return" more than one parameter at a time.
• This is done by passing a variable via reference so
that the function can write to it.
U
UNN II F
FEE II
//a e b são dados de entrada
//d e r são dados de saída
void main(void){
int d, r;
div(10, 3, &d, &r);
//d = 3 e r = 1;
return;
}
U
UNN II F
FEE II
Structs
Structs
• Structs are composed variables.
• Group lots of information as if they were one single
variable.
• A vector that each position stores a different type
// struct declaration
typedef struct{
unsigned short int age;
char name[51];
float weight;
}people;
U
UNN II F
FEE II
Structs
void main(void){
people someone = {26, "Name", 70.5};
someone.age = 27;
return 0;
}
Structs
• The access of the
typedef struct{
internal members of char nome[20];
structures, pointed by int idade;
pointers, can actually be int *p_dado;
}t_aluno;
done through the
operator -> t_aluno *a1;
(*a1).idade = 18;
a1->idade = 18;
U
UNN II F
FEE II
Structs
void main(void){
int dado = 10;
t_aluno aluno = {"Nome",17,&dado};
t_aluno *a1;
a1 = &aluno;
(*a1).idade = 18;
printf("Age: %d\n", (*a1).idade);
a1->idade = 19;
printf("Age: %d\n", a1->idade);
*(aluno.p_dado) = 11;
printf("dado: %d\n", dado);
//aluno->p_dado = 12; //erro
//printf("dado: %d\n", dado);
*((*a1).p_dado) = 12;
printf("dado: %d\n", dado);
*(a1->p_dado) = 13;
printf("dado: %d\n", dado);
return 0;
}