• Nenhum resultado encontrado

1-intro-struct-circular-buffer

N/A
N/A
Protected

Academic year: 2021

Share "1-intro-struct-circular-buffer"

Copied!
72
0
0

Texto

(1)

ELT048 – Embedded

Operational Systems

Rodrigo Maximiano Antunes de Almeida

rmaalmeida@gmail.com @rmaalmeida

(2)

The work ”Embedded System Design: From Electronics to Microkernel Development” of Rodrigo Maximiano Antunes de Almeida was licensed with Creative Commons 3.0 – Attribution – Non Commercial – Share Alike

license.

Additional permission can be given by the author through direct contact using the e-mail: rmaalmeida@gmail.com

(3)
(4)

U N I F E I U N I F E I

Initial comments

ClassesWed 7:00 to 9:30LEC II1st Test 13/092nd Test 08/11

(5)

U N I F E I

U N I F E I

Embedded OS

(6)

U N I F E I

U N I F E I

(7)

U N I F E I

U N I F E I

(8)

U N I F E I

U N I F E I

(9)

U N I F E I

U N I F E I

(10)

U N I F E I

U N I F E I

(11)

U N I F E I U N I F E I

KL02

MKL02Z32CAF4RTR -ND  32K flash4k ramUS$1,76

(12)

U N I F E I U N I F E I

Schedule

01) Intro / Pointers / Buffers • 02) void and function pointers • 03) Tasks04) Cooperative kernel • 05) Timing requirements • 06) Drivers08) Drivers Controller • 09) Callbacks10) Preemptive Kernel, scheduler • 11) Real time12) Mutex & Semaphores • 13) Message Prsing

(13)

U N I F E I

U N I F E I

void main (void){

//variable declaration kernel_project(1); //initialization concepts(2); //hard-work microkernel(3); device_driver_controller(4); }

(14)

void kernel_project (float i){ what_is_a_kernel(1.1); alternatives(1.2); monolithic_vs_microkernel(1.3); kernel_design_decisions(1.4); this_course_decisions(1.5); }

(15)

U N I F E I

U N I F E I

kernel_project

(

1

);

(16)

U N I F E I

U N I F E I

(17)

U N I F E I

U N I F E I

kernel_project

(

1

);

Kernel tasks:

1. Manage and coordinate the processes execution using “some criteria”

2. Manage the free memory and coordinate the processes access to it

3. Intermediate the communication between the hardware drivers and the processes

(18)

U N I F E I U N I F E I I/O CPU Memory Kernel Drivers Extra libs

File system Context switch GUI

C/C++

libraries

Interface

actions System logic

Internal routines

kernel_project

(

1

);

(19)

kernel_project

(

1

);

Develop my own kernel?

Why?

(20)

U N I F E I

U N I F E I

kernel_project

(

1

);

Improve home design

Reuse code more efficiently

Full control over the source

Specific tweeks to the kernel

Faster context switch routine

(21)

kernel_project

(

1

);

Develop my own kernel?

Why

not

?

(22)

U N I F E I

U N I F E I

kernel_project

(

1

);

Kernel overhead (both in time and

memory)

Free and paid alternatives

Time intensive project

(23)

U N I F E I

U N I F E I

Kernel Project

Source code size (millions of lines)  FreeBSD – 8.8  IOS – 80Linux (2.6.0) – 5.2Linux (3.6) – 15.9Debian 7.0 – 419Mac OS X 10.4 – 86OpenSolaris – 9.7Windows NT – 11Windows XP – 45Windows Vista – 66

(24)

U N I F E I

U N I F E I

kernel_project

(

1

);

Alternatives

Windows Embedded Compact®VxWorks®

X RTOS®uClinuxFreeRTOSBRTOS

(25)

U N I F E I

U N I F E I

kernel_project

(

1

);

Monolithic kernel versus microkernel

(26)

U N I F E I

U N I F E I

kernel_project

(

1

);

Kernel design decisions

I/O devices managementProcess management

(27)

U N I F E I U N I F E I

kernel_project

(

1

);

Our decisions:MicrokernelNon-preemptiveCooperativeNo memory management

Process scheduled based on timerIsolate drivers using a controller

(28)

U N I F E I

U N I F E I

Practical Activities

Boards

NEO201 – Pic18f4550

LPCxpresso base board – LPC1100

Development environment

MPLABXEclipse

(29)

void concepts (float i){ pointers(2.1); structs(2.2); circular_buffers(2.3); temporal_conditions(2.4); void_pointers(2.5); }

(30)

U N I F E I

U N I F E I

concepts

(

2

);

(31)

U N I F E I

U N I F E I

Pointers

(32)

U N I F E I

U N I F E I

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

(33)

U N I F E I U N I F E I

Pointers

It is necessary in the declaration of a pointer, to

specify for which type of variable it will point.

Pointers are

declared with a * before the variable name.

Sintax:

type

(34)

U N I F E I U N I F E I int *aux; float *temp; char *pont;

Pointers

aux, temp, and pont

are variables that store memory

addresses and 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

(35)

U N I F E I

U N I F E I

(36)

U N I F E I

U N I F E I

Pointers

Operator &:

Always gets the

address of a variable  Since pointers are

also variables, they also occupy memory.  You can get the

pointer address and have pointers to

pointers (multiples *).

Operator *:

The * operator

does the opposite of the & operator.

Given a pointer,

the * operator accesses the

content pointed to by it.

(37)

U N I F E I

U N I F E I

Ponteiros

Operator &:

“get the address

of”  “saved in”Operator *:“dereference”“through”“pointed by”

(38)

U N I F E I

U N I F E I

Pointers

#include <stdio.h>

int main(int argc, char *argv[]){

int x=10;

int *p1=&x; //ponteiro para um inteiro

printf("x = %d\n\n", x); *p1=20; //ou p1[0]=20; printf("p1 = %u\n", p1); printf("x = %d\n", x); printf("*p1 = %d\n", *p1); printf("p1[0] = %d\n\n", p1[0]); return 0; } //end main

(39)

U N I F E I

U N I F E I

Parameter passing

C-language functions can receive

multiple parameters and can return one.

The method of sending the parameters

can be done through the stack or through registers.

The stack allows several parameters to

be passed at once

The registers have a lower overhead,

therefore being faster and with smaller code size

(40)

U N I F E I

U N I F E I

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.

(41)

U N I F E I

U N I F E I

void incrementa(int a){ a += 1;

}

int main(int argc, char *argv[]){ int x = 10;

incrementa(x); return 0;

}

(42)

U N I F E I

U N I F E I

void main(void){ int x = 10; incrementa(x);

return 0; }

void incrementa(int a){ a+=1;

return; }

(43)

U N I F E I

U N I F E I

void main(void) {

int x = 10; inc(x);

return 0; }

void inc(int a){ a += 1;

return; }

Rotina Principal Função Variáveis

(44)

U N I F E I

U N I F E I

Rotina Principal Função Variáveis

x=10 a=10

void main(void) {

int x = 10; inc(x);

return 0; }

void inc(int a){ a += 1;

return; }

(45)

U N I F E I

U N I F E I

Rotina Principal Função Variáveis

x=10 a=11

void main(void) {

int x = 10; inc(x);

return 0; }

void inc(int a){ a += 1;

return; }

(46)

U N I F E I

U N I F E I

Rotina Principal Função Variáveis

x=10 descartado

void main(void) {

int x = 10; inc(x);

return 0; }

void inc(int a){ a += 1;

return; }

(47)

U N I F E I

U N I F E I

void incrementaptr(int* a){ (*a) += 1;

}

int main(int argc, char *argv[]){ int x = 10;

incrementaptr(&x); return 0;

(48)

U N I F E I

U N I F E I

void main(void) { int x = 10; incptr(&x); return 0; } void incptr (int* a){ (*a) += 1; return; }

Rotina Principal Função Variáveis

(49)

U N I F E I

U N I F E I

Rotina Principal Função Variáveis

x=10 temp=&x

void main(void) { int x = 10; incptr(&x); return 0; } void incptr (int* a){ (*a) += 1; return; }

(50)

U N I F E I

U N I F E I

Rotina Principal Função Variáveis

x=10 a=&x

void main(void) { int x = 10; incptr(&x); return 0; } void incptr (int* a){ (*a) += 1; return; }

(51)

U N I F E I

U N I F E I

Rotina Principal Função Variáveis

x=11 a=&x

*

void main(void) { int x = 10; incptr(&x); return 0; } void incptr (int* a){ (*a) += 1; return; }

(52)

U N I F E I

U N I F E I

Rotina Principal Função Variáveis

x=11 descartado

void main(void) { int x = 10; incptr(&x); return 0; } void incptr (int* a){ (*a) += 1; return; }

(53)

U N I F E I

U N I F E I

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.

(54)

U N I F E I

U N I F E I

//a e b são dados de entrada //d e r são dados de saída

void div(int a, int b, int* d, int* r){ (*d) = a / b;

(*r) = a % b; return;

}

void main(void){ int d, r;

div(10, 3, &d, &r); //d = 3 e r = 1;

return; }

(55)

U N I F E I

U N I F E I

concepts

(

2

);

(56)

U N I F E I

U N I F E I

concepts

(

2

);

// struct declaration

typedef struct{

unsigned short int age; char name[51];

float weight; }people;

Structs are composed variables.

Group lots of information as if they were

one single variable.

A vector that each position stores a

(57)

U N I F E I

U N I F E I

void main(void){

struct people myself = {26, "Rodrigo", 70.5};

myself.age = 27;

//using each variable from the struct

printf("Age: %d\n", myself.age);

printf("Name: %s\n", myself.name);

printf("Weight: %f\n", myself.weight); return 0;

}

(58)

// struct declaration

typedef struct{

unsigned short int *age;

char *name[51];

float *weight;

}people;

void main(void){

struct people myself = {26, "Rodrigo", 70.5};

//using each variable from the struct

printf("Age: %d\n", myself->age);

printf("Name: %s\n", myself->name);

printf("Weight: %f\n", myself->weight);

return 0;

}

(59)

U N I F E I U N I F E I typedef struct{ char nome[20]; int idade; }t_aluno; t_aluno *a1; (*a1).nome = "Joao"; (*a1).idade = 18; a1->nome = "Joao"; a1->idade = 18;

Structs

The access of the

internal members of structures, pointed by pointers, can actually be done through the operator ->

(60)

U N I F E I

U N I F E I

concepts

(

2

);

(61)

U N I F E I

U N I F E I

concepts

(

2

);

Circular Buffers

“Endless” memory spacesUse FIFO aproach

Store temporary data

(62)

U N I F E I

U N I F E I

concepts

(

2

);

Vector implementation

Uses less space

Need special caution when cycling

(63)

[0]

[1]

[2]

[3]

[4]

(64)

[0] [1] [2] [3] [4] fim=0

ini=0

? ? ? ? ?

(65)

[0] [1] [2] [3] [4] fim=2

ini=0

'A'

'B'

? ? ?

(66)

[0] [1] [2] [3] [4] fim=2

ini=1

'A'

'B'

? ? ?

(67)

[0] [1] [2] [3] [4] fim=4

ini=1

'A'

'B'

'C'

'D'

?

(68)

[0] [1] [2] [3] [4] fim=0

ini=1

'A'

'B'

'C'

'D'

'E'

(69)

U N I F E I

U N I F E I

#define CB_SIZE 10

int circular_buffer[CB_SIZE]; int index=0;

for(;;){

//do anything with the buffer

circular_buffer[index] = index;

//increment the index

index = (index+1)%CB_SIZE; }

(70)

concepts

(

2

);

#define CB_SIZE 10

int circular_buffer[CB_SIZE]; int start=0, end=0;

char AddBuff(int newData) {

//check if there is space to add a number

if ( ((end+1)%CB_SIZE) != start)

{

circular_buffer[end] = newData;

end = (end+1)%CB_SIZE;

return SUCCESS;

}

return FAIL; }

(71)

U N I F E I

U N I F E I

Exercise

Implement a circular buffer

Use a 10-position vector

Each element of the vector is a structure

with two variables

char * ProcessNameint Time

Create one function to add new elements

Referências

Documentos relacionados

Os filmes de Cláudio Assis apontam para algumas conclusões, portanto, as quais poderiam ser esquematizadas da seguinte forma: (a) a emancipação é da ordem do

As estratégias como a luta radical pela vida contra a necropolítica que domina hoje a governança de nações como a brasileira – além de se espalhar numa escala global, com o

Enquanto o poder soberano se expressa a partir da limitação, exclusão e negatividade, a biopolítica manifesta-se na produtividade de um poder que constrói, fabrica e

Desse modo, ainda que consideremos a gramática dos direitos a partir de uma apreciação genealógica das dinâmicas políticas que lhe deram origem, podemos observar o efeito

O objetivo do artigo é examinar a atuação política do procurador-geral da República no período de transição democrática (1979-1988), em especial seu papel no controle de

Desvinculada das lutas do presente e fortemente atacada por práticas e discursos oficiais de deslegitimação de seus trabalhos — sobretudo a partir do governo de Jair

O MPT, no interior da estrutura do Ministério Público da União, foi o primeiro a apresentar um plano de ação para atuar frente à pandemia, tanto internamente, com o investimento e

É importante lembrar aqui que es- tou buscando o sentido do gênero encontrado no discurso dos Ministros, assim, alguns foram excluídos, como por exemplo trechos em que