VxWorks/Workbench

Transcrição

VxWorks/Workbench
Laboratório de Mecatrônica
EESC/USP
SEM 0544
VxWorks/Workbench
Jean M.S.C. Yabarrena
30/04/10
Motivação
Como interagir com o VxWorks e como
utilizar seus recursos
30/04/2010
Jean M. S. C. Yabarrena
Objetivos
• Utilizar uma utilidade que utiliza o clock para
medir o tempo de execução de uma tarefa.
• Entender como trabalha o VxWorks com
múltlipas tarefas.
• Entender e implementar uma aplicação com
semáforos.
• Entender e implementar uma aplicação que
envia e receba mensagens.
30/04/2010
Jean M. S. C. Yabarrena
Wind Microkernel
30/04/2010
Jean M. S. C. Yabarrena
Memory Protection –
Real-Time Processes (RTPs)
30/04/2010
Jean M. S. C. Yabarrena
Arquivos e tipos de Projetos
1. Project Files in VxWorks Image Projects (VIP)
vxWorks (default)
vxWorks.bin (default)
vxWorks.hex (default)
2. Project Files in VxWorks Source Build Projects
3. Project Files in Downloadable Kernel Module
Projects (DKM)
TargetName.out
TargetName_partialImage.o
30/04/2010
Jean M. S. C. Yabarrena
Arquivos e tipos de Projetos
4. Project Files in Real-Time Process Projects
(RTP)
TargetName.vxe (BuildSpec [- debug])
fully linked VxWorks executable.
Librarian build tool
5. Project Files in Shared Library Projects
TargetName.so
The shared library used by the VxWorks
executable
30/04/2010
Jean M. S. C. Yabarrena
VxWorks content
30/04/2010
Jean M. S. C. Yabarrena
Tempo de execução # 1 - DKM
30/04/2010
Jean M. S. C. Yabarrena
Tempo # 1.5 – DKM
Baseado no exemplo Embry-Riddle Real-Time Laboratory
#include "vxWorks.h" /* Always include this as the first thing in every program */
#include "timexLib.h"
#include "stdio.h"
#define ITERATIONS 500 /* 0x1F4 */
int printit(void);
void timing() /* Function to perform the timing */
{
FUNCPTR function_ptr = printit; /* a pointer to the function "printit" */
timex(function_ptr,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL); /* Timing the "print" function */
}
int printit(void) /* Function being timed */
{
int i;
for(i=0; i < ITERATIONS; i++) /* Printing the task id number and the increment variable "i" */
printf("Sou a tarefa %x e execução No = %d\n",taskIdSelf(),i);
return 0;
}
30/04/2010
Jean M. S. C. Yabarrena
Tempo # 2 - DKM
30/04/2010
Jean M. S. C. Yabarrena
Tempo # 3 - DKM
30/04/2010
Jean M. S. C. Yabarrena
Tempo # 4 – DKM 200
30/04/2010
Jean M. S. C. Yabarrena
Tempo # 6 – DKM timing
30/04/2010
Jean M. S. C. Yabarrena
Tempo # 7 – DKM timexN
30/04/2010
Jean M. S. C. Yabarrena
Multitarefa #1
• Comandos do shell importantes
lkup ["substr"]
List symbols in system symbol table
lkAddr address
List symbol table entries near address
checkStack [task]
List task stack sizes and usage
i
[task]
Summary of tasks' TCBs
ti
task
Complete info on TCB for task
td
task
Delete a task
devs
List devices
ld
[syms[,noAbort][,"name"]] Load stdin, or file, into memory
(syms = add symbols to table:
h
[n]
Print (or set) shell history
•
•
•
•
•
•
•
•
30/04/2010
Jean M. S. C. Yabarrena
Multitarefa #2
• sysClkRateGet ( )
• value = 60 = 0x3c = '<‘
30/04/2010
Jean M. S. C. Yabarrena
Multitarefa #3
A task's context includes:
• a thread of execution; that is, the task's program counter
• the tasks' virtual memory context (if process support is included)
• the CPU registers and (optionally) coprocessor registers
• stacks for dynamic variables and function calls
• I/O assignments for standard input, output, and error
• a delay timer
• a time-slice timer
• kernel control structures
• signal handlers
• task private environment (for environment variables) error status (errno)
• debugging and performance monitoring values
30/04/2010
Jean M. S. C. Yabarrena
Multitarefa #4
#include "vxworks.h"
#include "taskLib.h"
#include "stdio.h"
#define ITERATIONS 10
#define LOOP 20000000 /* 20 10^6*/
void print(void);
30/04/2010
Jean M. S. C. Yabarrena
Multitarefa #5
gerar_tarefas() /* Rotina que executa o spawning */
{
int i, taskId;
for(i=0; i < ITERATIONS; i++) /* Cria 10 tarefas */
taskId = taskSpawn("tPrint",70,0x100,2000,(FUNCPTR)print,0,0,0,0,0,0,0,0,0,0);
}
void print(void) /* Subroutine to be spawned */
{
int i;
/*nanosleep(1000);*/
taskDelay(300); /*Bloqueamos a tarefa por 5 segundos*/
for(i=0; i < LOOP; i++);
printf("Saindo da tarefa %x\n",taskIdSelf()); /* Impressão task Id */
}
30/04/2010
Jean M. S. C. Yabarrena
Multitarefa #5.5
30/04/2010
Jean M. S. C. Yabarrena
Multitarefa #6
30/04/2010
Jean M. S. C. Yabarrena
Multitarefa #7
30/04/2010
Jean M. S. C. Yabarrena
Multitarefa #8
30/04/2010
Jean M. S. C. Yabarrena
Semáforos #1
30/04/2010
Jean M. S. C. Yabarrena
Semáforos #1
30/04/2010
Jean M. S. C. Yabarrena
Semáforos #1
#include "vxWorks.h"
#include "taskLib.h"
#include "semLib.h"
#include "stdio.h"
/* function prototypes */
void taskOne(void);
void taskTwo(void);
/* globals */
#define ITER 10
SEM_ID semBinary;
int global = 0;
30/04/2010
Jean M. S. C. Yabarrena
Semáforos #2
void binary(void)
{
int taskIdOne, taskIdTwo;
/* cria um semáforo baseado em FIFO */
semBinary = semBCreate(SEM_Q_FIFO, SEM_FULL);
/* Nota 1: Bloqueio o semáforo */
semTake(semBinary,WAIT_FOREVER);
/* spawn as 2 tarefas */
taskIdOne = taskSpawn("t1",90,0x100,2000,(FUNCPTR)taskOne,0,0,0,0,0,0,0,0,0,0);
taskIdTwo = taskSpawn("t2",89,0x100,2000,(FUNCPTR)taskTwo,0,0,0,0,0,0,0,0,0,0);
}
30/04/2010
Jean M. S. C. Yabarrena
Semáforos #2.5
void taskOne(void)
{
int i;
for (i=0; i < ITER; i++)
{
semTake(semBinary,WAIT_FOREVER); /* espera indefinidamente pelo semáforo */
printf("Sou a taskOne, o valor do recurso compartilhado = %d\n", ++global);
semGive(semBinary); /* entrega semáforo */
}
}
30/04/2010
Jean M. S. C. Yabarrena
Semáforos #2.7
void taskTwo(void)
{
int i;
semGive(semBinary); /* Nota 2: O escalonador entrega o semáforo */
for (i=0; i < ITER; i++)
{
semTake(semBinary,WAIT_FOREVER); /* espera indefinidamente pelo semáforo */
printf("Sou a taskTwo, o valor do recurso compartilhado = %d\n", --global);
semGive(semBinary); /* entrega semáforo */
}
}
30/04/2010
Jean M. S. C. Yabarrena
Semáforos #3
30/04/2010
Jean M. S. C. Yabarrena
Semáforos #3
30/04/2010
Jean M. S. C. Yabarrena
Filas de mensagens
Modern real-time applications are constructed as a set
of independent but cooperating tasks. While
semaphores provide a high-speed mechanism for the
synchronization and interlocking of tasks, often a
higher-level mechanism is necessary to allow
cooperating tasks to communicate with each other.
In VxWorks, the primary intertask communication
mechanism within a single CPU is message queues.
30/04/2010
Jean M. S. C. Yabarrena
Filas de mensagens
30/04/2010
Jean M. S. C. Yabarrena
Filas de mensagens
#include "vxWorks.h"
#include "msgQLib.h"
/* function prototypes */
void taskOne_q(void);
void taskTwo_q(void);
/* defines */
#define MAX_MESSAGES 100
#define MAX_MESSAGE_LENGTH 50
/* globals */
MSG_Q_ID mesgQueueId; /* Identificador do recurso compartilhado */
30/04/2010
Jean M. S. C. Yabarrena
Filas de mensagens
void message(void) /* Cria uma fila de mensagens e 2 tarefas */
{
int taskIdOne, taskIdTwo;
/* cria fila de mensagens */
if ((mesgQueueId = msgQCreate(MAX_MESSAGES,MAX_MESSAGE_LENGTH,MSG_Q_FIFO))
== NULL)
printf("msgQCreate in failed\n");
/* spawn 2 tarefas que utilizarão a fila */
if((taskIdOne = taskSpawn("t1_q",90,0x100,2000,(FUNCPTR)taskOne_q,0,0,0,0,0,0,0,
0,0,0)) == ERROR)
printf("taskSpawn taskOne failed\n");
if((taskIdTwo = taskSpawn("t2_q",90,0x100,2000,(FUNCPTR)taskTwo_q,0,0,0,0,0,0,0,
0,0,0)) == ERROR)
printf("taskSpawn taskTwo failed\n");
}
30/04/2010
Jean M. S. C. Yabarrena
Filas de mensagens
void taskOne_q(void) /* tarefa escreve na fila de mensagems */
{
char message[] = "Recibi a mensagem da taskOne";
/* envia mensagem */
if((msgQSend(mesgQueueId,message,MAX_MESSAGE_LENGTH, WAIT_FOREVER,
MSG_PRI_NORMAL)) == ERROR)
printf("msgQSend in taskOne failed\n");
}
void taskTwo_q(void) /* tarefa lê a fila de mensagens */
{
char msgBuf[MAX_MESSAGE_LENGTH];
/* receve mensagem */
if(msgQReceive(mesgQueueId,msgBuf,MAX_MESSAGE_LENGTH, WAIT_FOREVER)
== ERROR)
printf("msgQReceive in taskTwo failed\n");
else
printf("%s\n",msgBuf);
msgQDelete(mesgQueueId);
/* apago a fila */Jean M. S. C. Yabarrena
30/04/2010
}
Multitarefa #9
30/04/2010
Jean M. S. C. Yabarrena
Multitarefa #10
30/04/2010
Jean M. S. C. Yabarrena
Multitarefa #11
30/04/2010
Jean M. S. C. Yabarrena

Documentos relacionados

Wind River Commercial Extensions

Wind River Commercial Extensions  29MRO: Mars Reconnaissance Orbiter  MSL: Mars Science Laboratory 2009

Leia mais