Beruflich Dokumente
Kultur Dokumente
Embedded Labworks
Embedded Labworks
SOBRE O INSTRUTOR
Embedded Labworks
AGENDA DO TREINAMENTO
Embedded Labworks
FreeRTOS
Embedded Labworks
Embedded Labworks
Embedded Labworks
CLASSIFICAO
Embedded Labworks
DESENVOLVIMENTO
Embedded Labworks
FOREGROUND/BACKGROUND
Embedded Labworks
O SUPER-LOOP
intmain(void)
{
init_hardware();
while(1){
I2C_ReadPkg();
UART_Receive();
USB_GetPacket();
Audio_Play();
ADC_Convert();
LCD_Show();
...
}
}
voidUSB_ISR(void)
{
Limpainterrupo;
Lpacote;
}
BACKGROUND
FOREGROUND
voidUART_ISR(void)
{
Limpainterrupo;
Tratabyterecebido;
}
Embedded Labworks
O SUPER-LOOP (cont.)
Foreground (ISR2)
Foreground (ISR1)
Background
----- Funo #1 ------
Linha de Tempo
Funo #3
Embedded Labworks
VANTAGENS DO SUPER-LOOP
Embedded Labworks
DEFICINCIAS DO SUPER-LOOP
Embedded Labworks
voidADC_Read(void){
configure_ADC();
while(conv_rdy==0){
;
}
...
}
Embedded Labworks
Embedded Labworks
voidUSB_ISR(void){
clear_interrupt();
read_packet();
}
Embedded Labworks
Embedded Labworks
A SOLUO
Embedded Labworks
Embedded Labworks
MULTITAREFA
TAREFA 1
TAREFA 2
TAREFA 3
t1
t2
Tempo
tn
Embedded Labworks
MULTITAREFA (cont.)
TAREFA 1
TAREFA 2
TAREFA 3
t1
t2
Tempo
tn
Embedded Labworks
MULTITAREFA (cont.)
Embedded Labworks
MUDANA DE CONTEXTO
Embedded Labworks
O ESCALONADOR
Embedded Labworks
Round-robin scheduling.
Embedded Labworks
Embedded Labworks
RTOS E KERNEL
Embedded Labworks
AS VANTAGENS DE UM RTOS
Embedded Labworks
Embedded Labworks
CONSUMO DE RECURSOS
Embedded Labworks
FreeRTOS
Embedded Labworks
Embedded Labworks
FRDM-KL46Z
Embedded Labworks
FRDM-KL46Z (cont.)
Embedded Labworks
FRDM-KL46Z (cont.)
Embedded Labworks
DOCUMENTAO
KL46Z Reference
microcontrolador).
Manual.pdf
(manual
de
referncia
do
Embedded Labworks
REFERNCIAS
Embedded Labworks
AMBIENTE DE DESENVOLVIMENTO
Embedded Labworks
Embedded Labworks
Embedded Labworks
DOCUMENTAO DO KDS
Embedded Labworks
LABORATRIO
A primeira aplicao
Embedded Labworks
FreeRTOS
Introduo ao FreeRTOS
Embedded Labworks
O FreeRTOS
Criado por volta do ano 2000 por Richard Barry, e hoje mantindo
pela empresa Real Time Engineers Ltd.
http://www.freertos.org/
Embedded Labworks
O FreeRTOS (cont.)
Embedded Labworks
POSIO NO MERCADO
Linux
Funcionalidades
uClinux
FreeRTOS
Bare metal
Capacidade de processamento
Embedded Labworks
CARACTERSTICAS
Embedded Labworks
CARACTERSTICAS (cont.)
Embedded Labworks
CARACTERSTICAS (cont.)
Embedded Labworks
CDIGO-FONTE
FreeRTOS
Source
croutine.c
event_groups.c
include
list.c
portable
queue.c
readme.txt
tasks.c
timers.c
Demo
Common
CORTEX_A2F200_IAR_and_Keil
CORTEX_A2F200_SoftConsole
CORTEX_A5_SAMA5D3x_Xplained_IAR
License
license.txt
readme.txt
Embedded Labworks
CDIGO-FONTE (PORTE)
portable/
CCS
ARM_CortexR4
MSP430X
GCC
ARM7_AT91FR40008
ARM7_AT91SAM7S
ARM_CM0
port.c
portmacro.h
IAR
78K0R
ARM_CM0
V850ES
MemMang
heap_1.c
heap_2.c
heap_3.c
heap_4.c
heap_5.c
Embedded Labworks
FreeRTOSConfig.h
#defineconfigUSE_PREEMPTION1
#defineconfigCPU_CLOCK_HZ58982400
#defineconfigTICK_RATE_HZ250
#defineconfigMAX_PRIORITIES5
#defineconfigMINIMAL_STACK_SIZE128
#defineconfigTOTAL_HEAP_SIZE10240
#defineconfigMAX_TASK_NAME_LEN16
#defineconfigUSE_MUTEXES0
...
#defineINCLUDE_vTaskDelete1
#defineINCLUDE_vTaskDelay1
#defineINCLUDE_xTaskGetCurrentTaskHandle1
#defineINCLUDE_uxTaskGetStackHighWaterMark0
#defineINCLUDE_xTaskGetIdleTaskHandle0
...
http://www.freertos.org/a00110.html
Embedded Labworks
PADRO DE CODIFICAO
Embedded Labworks
CONVENES
Embedded Labworks
LICENA
O FreeRTOS licenciado pela Real Time Engineers Ltd., sob uma verso
modificada da GPL.
Tem cdigo fonte aberto, no precisa pagar royalties e pode ser usado
livremente em aplicaes comerciais.
No precisa liberar os fontes da sua aplicao, desde que voc no crie
nenhuma funcionalidade j fornecida pelo FreeRTOS.
Precisa indicar que usa o FreeRTOS (um link para o site suficiente).
Embedded Labworks
OPENRTOS
Embedded Labworks
SAFERTOS
Embedded Labworks
LABORATRIO
Embedded Labworks
FreeRTOS
Gerenciamento de tarefas
Embedded Labworks
GERENCIAMENTO DE TAREFAS
Embedded Labworks
Embedded Labworks
Embedded Labworks
TCB E STACK
Tarefa X
Nome
Prioridade
Top of Stack
Stack Pointer
..........
0x1845
0x43BF
0x5FA4
0x96BF
Stack
Embedded Labworks
Embedded Labworks
INICIANDO O ESCALONADOR
#include"FreeRTOS.h"
#include"task.h"
intmain(void)
{
[...]
/*createtask1*/
xTaskCreate(task1,(signedchar*)"Task1",
configMINIMAL_STACK_SIZE,(void*)NULL,
1,NULL);
/*startthescheduler*/
vTaskStartScheduler();
/*shouldneverreachhere!*/
for(;;);
}
Embedded Labworks
Embedded Labworks
voidvTaskDelete(TaskHandle_txTask);
Embedded Labworks
Embedded Labworks
LABORATRIO
Embedded Labworks
TAREFAS EM EXECUO
TAREFA 1
TAREFA 2
t1
t2
Tempo
tn
Embedded Labworks
PRIORIDADES
Embedded Labworks
PRIORIDADES E O ESCALONADOR
Embedded Labworks
MODO COLABORATIVO
Embedded Labworks
USANDO taskYIELD
#include"task.h"
voidATaskFunction(void*pvParameters)
{
for(;;){
process_something();
taskYIELD();
}
}
Embedded Labworks
MODO PREEMPTIVO
Embedded Labworks
TICK INTERRUPT
Embedded Labworks
KERNEL
TAREFA 1
TAREFA 2
t1
t2
Tempo
tn
Embedded Labworks
Esta funo pode ser usada para executar uma rotina peridica.
Como esta rotina roda em contexto de interrupo, mantenha seu
processamento o mais breve possvel.
Habilite
opo configUSE_TICK_HOOK
FreeRTOSConfig.h e implemente a funo:
voidvApplicationTickHook(void);
no
arquivo
Embedded Labworks
LABORATRIO
Prioridades e escalonamento
Embedded Labworks
EVENTOS
Embedded Labworks
Embedded Labworks
ESTADO BLOCKED
Embedded Labworks
ROTINAS DE DELAY
#include"task.h"
/*delayataskforagivennumberofticks*/
voidvTaskDelay(
constTickType_txTicksToDelay
);
/*delayataskuntilaspecifiedtime*/
voidvTaskDelayUntil(
TickType_t*pxPreviousWakeTime,
constTickType_txTimeIncrement
);
Embedded Labworks
Embedded Labworks
ESTADO SUSPENDED
Embedded Labworks
ESTADO READY
Embedded Labworks
Blocking API
vTaskSuspend
Ready
vTaskResume
xTaskCreate
Suspended
vTaskSuspend
Not running
Event
Blocked
Embedded Labworks
LABORATRIO
Rotinas de delay
Embedded Labworks
TAREFA IDLE
Embedded Labworks
TAREFAS EM EXECUO
TAREFA 1
TAREFA 2
TAREFA IDLE
t1
t2
Tempo
tn
Embedded Labworks
Embedded Labworks
Embedded Labworks
Embedded Labworks
Embedded Labworks
ECONOMIA DE ENERGIA
Embedded Labworks
Embedded Labworks
Embedded Labworks
LABORATRIO
Embedded Labworks
UM RESUMO DO ESCALONADOR
Embedded Labworks
O KERNEL DO FREERTOS
Fixed Priority Preemptive Scheduling
TAREFA 1 (P3)
TAREFA 2 (P2)
TAREFA 3 (P1)
IDLE (P0)
t1
t2
Tempo
tn
Embedded Labworks
FreeRTOS
Gerenciamento de queues
Embedded Labworks
GERENCIAMENTO DE QUEUE
Embedded Labworks
EXEMPLO
QUEUE
3
TAREFA 1
TAREFA 2
Send
Embedded Labworks
EXEMPLO (cont.)
QUEUE
8
TAREFA 1
3
TAREFA 2
Send
Embedded Labworks
EXEMPLO (cont.)
QUEUE
TAREFA 1
TAREFA 2
Receive
Embedded Labworks
EXEMPLO (cont.)
QUEUE
8
TAREFA 1
TAREFA 2
Embedded Labworks
O QUEUE
Cada item do queue pode ter um tamanho fixo de bytes (item size).
Embedded Labworks
Embedded Labworks
USANDO UM QUEUE
Embedded Labworks
LENDO DO QUEUE
Embedded Labworks
Embedded Labworks
Embedded Labworks
Embedded Labworks
ESCREVENDO NO QUEUE
Embedded Labworks
Embedded Labworks
Embedded Labworks
Embedded Labworks
EM INTERRUPES
xQueueSendToFrontFromISR() .
xQueueSendToBackFromISR().
xQueueReceiveFromISR().
Embedded Labworks
LABORATRIO
Embedded Labworks
FreeRTOS
Embedded Labworks
INTERRUPO
Embedded Labworks
Embedded Labworks
Embedded Labworks
ISR
TAREFA 2 (P2)
HANDLER
TAREFA 1 (P1)
IDLE (P0)
Tempo
Embedded Labworks
MECANISMOS DE SINCRONIZAO
Queues.
Embedded Labworks
SEMFOROS BINRIOS
Embedded Labworks
EXEMPLO
SEMFORO BINRIO
ISR
Take
TASK
HANDLER
Embedded Labworks
EXEMPLO (cont.)
SEMFORO BINRIO
ISR
Give
Take
TASK
HANDLER
Embedded Labworks
EXEMPLO (cont.)
SEMFORO BINRIO
ISR
Take
TASK
HANDLER
Embedded Labworks
Embedded Labworks
Embedded Labworks
Embedded Labworks
Embedded Labworks
EXEMPLO ISR
voiddummyISR(void)
{
BaseType_txHigherPriorityTaskWoken=pdFALSE;
/*ACKinterrupt,receivedata,etc*/
handle_dummy_int();
/*givesemaphoretounblockthetask*/
xSemaphoreGiveFromISR(dummy_semaphore,
&xHigherPriorityTaskWoken);
/*switchtotaskifit'sthehighestprioritytask
readytorun*/
portEND_SWITCHING_ISR(xHigherPriorityTaskWoken);
}
Embedded Labworks
LABORATRIO
Embedded Labworks
SEMFOROS CONTADORES
Embedded Labworks
EXEMPLO
SEMFORO CONTADOR
ISR
Take
TASK
HANDLER
Embedded Labworks
EXEMPLO (cont.)
SEMFORO CONTADOR
ISR
Give
Take
TASK
HANDLER
Embedded Labworks
EXEMPLO (cont.)
SEMFORO CONTADOR
ISR
Take
TASK
HANDLER
Embedded Labworks
EXEMPLO (cont.)
SEMFORO CONTADOR
ISR
Give
TASK
HANDLER
Embedded Labworks
EXEMPLO (cont.)
SEMFORO CONTADOR
ISR
Give
TASK
HANDLER
Embedded Labworks
Embedded Labworks
GERENCIANDO RECURSOS
Embedded Labworks
EXEMPLO
SEMFORO CONTADOR
TAREFA 1
TAREFA 2
TAREFA 3
Embedded Labworks
EXEMPLO (cont.)
SEMFORO CONTADOR
Take
TAREFA 1
TAREFA 2
TAREFA 3
Embedded Labworks
EXEMPLO (cont.)
SEMFORO CONTADOR
Take
TAREFA 1
TAREFA 2
TAREFA 3
Embedded Labworks
EXEMPLO (cont.)
SEMFORO CONTADOR
Take
TAREFA 1
TAREFA 2
TAREFA 3
Embedded Labworks
EXEMPLO (cont.)
SEMFORO CONTADOR
Give
TAREFA 1
TAREFA 2
TAREFA 3
Embedded Labworks
LABORATRIO
Embedded Labworks
Embedded Labworks
ESCREVENDO NO QUEUE
#include"queue.h"
/*postanitemtothefrontofaqueue(fromanISR)*/
BaseType_txQueueSendToFrontFromISR(
QueueHandle_txQueue,
constvoid*pvItemToQueue,
BaseType_t*pxHigherPriorityTaskWoken);
/*postanitemtothebackofaqueue(fromanISR)*/
BaseType_txQueueSendToBackFromISR(
QueueHandle_txQueue,
constvoid*pvItemToQueue,
BaseType_t*pxHigherPriorityTaskWoken);
Embedded Labworks
Embedded Labworks
LENDO DO QUEUE
#include"queue.h"
/*receiveanitemfromaqueue(fromanISR)*/
BaseType_txQueueReceiveFromISR(
QueueHandle_txQueue,
void*pvBuffer,
BaseType_t*pxHigherPriorityTaskWoken);
/*receiveanitemfromaqueuewithoutremoving
theitemfromthequeue(fromanISR)*/
BaseType_txQueuePeekFromISR(
QueueHandle_txQueue,
void*pvBuffer);
Embedded Labworks
Embedded Labworks
LABORATRIO
Embedded Labworks
Embedded Labworks
INTERRUPO NO FREERTOS
Embedded Labworks
CONFIGURANDO AS PRIORIDADES
configMAX_SYSCALL_INTERRUPT_PRIORITY :
define
a
interrupo de maior prioridade que pode usar a API do FreeRTOS.
Isso porque, ao executar uma seo crtica, o kernel desabilita todas
as interrupes de prioridade menor ou igual definida por esta
constante. Isso significa que o FreeRTOS nunca desabilita todas as
interrupes por completo, mesmo dentro de sees crticas!
Embedded Labworks
EXEMPLO
configKERNEL_INTERRUPT_PRIORITY=15
configMAX_SYSCALL_INTERRUPT_PRIORITY=5
Prioridade 0
...
Interrupes que NO usam
a API do FreeRTOS podem
ter qualquer prioridade.
Prioridade 4
Prioridade 5
Prioridade 6
...
Prioridade 15
Embedded Labworks
NA PRTICA
Embedded Labworks
FreeRTOS
Gerenciamento de recursos
Embedded Labworks
GERENCIAMENTO DE RECURSOS
Acesso perifricos.
Compartilhamento de cdigo.
Embedded Labworks
Embedded Labworks
Neste caso, como a varivel global pode ser acessada por mais de
uma tarefa ao mesmo tempo, necessrio um controle no acesso
esta varivel para garantir sua consistncia.
Embedded Labworks
ACESSO PERIFRICOS
Embedded Labworks
FUNES THREAD-SAFE
Embedded Labworks
EXEMPLO
//EstaimplementaoNO
//threadsafe
...
LOCK()
getDate();
UNLOCK();
...
LOCK();
d.day=getDay();
d.month=getMon();
d.year=getYear();
UNLOCK();
structDated;
voidgetDate()
{
d.day=getDay();
d.month=getMon();
d.year=getYear();
}
Embedded Labworks
Embedded Labworks
Para uma tarefa acessar o recurso, ela precisa antes pegar o token (take).
Embedded Labworks
EXEMPLO
TAREFA 1
MUTEX
TAREFA 2
RECURSO
COMPARTILHADO
Embedded Labworks
EXEMPLO (cont.)
TAREFA 1
Take
MUTEX
TAREFA 2
RECURSO
COMPARTILHADO
Embedded Labworks
EXEMPLO (cont.)
TAREFA 1
MUTEX
TAREFA 2
RECURSO
COMPARTILHADO
Embedded Labworks
EXEMPLO (cont.)
TAREFA 1
MUTEX
Take
TAREFA 2
RECURSO
COMPARTILHADO
Embedded Labworks
EXEMPLO (cont.)
Give
TAREFA 1
MUTEX
Take
TAREFA 2
RECURSO
COMPARTILHADO
Embedded Labworks
EXEMPLO (cont.)
TAREFA 1
MUTEX
Take
TAREFA 2
RECURSO
COMPARTILHADO
Embedded Labworks
EXEMPLO (cont.)
TAREFA 1
MUTEX
TAREFA 2
RECURSO
COMPARTILHADO
Embedded Labworks
USANDO UM MUTEX
#include"semphr.h"
/*createamutex*/
SemaphoreHandle_txSemaphoreCreateMutex(void);
/*obtainamutex*/
BaseType_txSemaphoreTake(
SemaphoreHandle_txSemaphore,
TickType_txTicksToWait);
/*releaseamutex*/
BaseType_txSemaphoreGive(
SemaphoreHandle_txSemaphore);
Embedded Labworks
Embedded Labworks
PAUSANDO O ESCALONADOR
Cdigo do kernel.
Bibliotecas utilizadas pelo kernel (Ex: rotinas de alocao de
memria).
Embedded Labworks
reiniciar
xTaskResumeAll().
escalonador,
pode-se
usar
funo
Embedded Labworks
Embedded Labworks
Embedded Labworks
DESABILITANDO INTERRUPES
taskDISABLE_INTERRUPTS() e taskENABLE_INTERRUPTS() :
Embedded Labworks
Embedded Labworks
Embedded Labworks
RESUMO
Embedded Labworks
LABORATRIO
Embedded Labworks
INVERSO DE PRIORIDADE
1) T1 pega o mutex e interrompida
para a execuo da tarefa T3.
2) T3 tenta usar o mutex, mas dorme
porque o mutex esta com T1.
3) T1 resume execuo, e antes de
liberar o mutex interrompida
por T2, que tem maior prioridade.
4) T2 executada, e enquanto isso,
T3, que tem maior prioridade,
continua esperando!
2
High priority task T3
4
Medium priority task T2
1
Low priority task T1
Tempo
Embedded Labworks
HERANA DE PRIORIDADE
Embedded Labworks
1
Low priority task T1
Tempo
Embedded Labworks
DEADLOCK
TAREFA 1
MUTEX A
MUTEX B
TAREFA 2
Embedded Labworks
DEADLOCK (cont.)
TAREFA 1
MUTEX A
Take
MUTEX B
TAREFA 2
Embedded Labworks
DEADLOCK (cont.)
TAREFA 1
MUTEX A
MUTEX B
Take
TAREFA 2
B
Embedded Labworks
DEADLOCK (cont.)
TAREFA 1
A
MUTEX A
MUTEX B
Take
TAREFA 2
B
Embedded Labworks
DEADLOCK (cont.)
TAREFA 1
Take
MUTEX A
MUTEX B
Take
TAREFA 2
B
Embedded Labworks
DEADLOCK (cont.)
Embedded Labworks
GATEKEEPER
Embedded Labworks
GATEKEEPER (cont.)
QUEUE
MSG1
TAREFA 1
RECURSO
MSG2
TAREFA
GATEKEEPER
TAREFA 2
Embedded Labworks
LABORATRIO
Embedded Labworks
FreeRTOS
Gerenciamento de memria
Embedded Labworks
GERENCIAMENTO DE MEMRIA
Embedded Labworks
GERENCIAMENTO DE MEMRIA
Determinismo.
Algoritmo de desfragmentao.
Embedded Labworks
GERENCIAMENTO DE MEMRIA
Embedded Labworks
ALOCAO NO FREERTOS
Embedded Labworks
heap_3.c:
heap_4.c:
heap_5.c:
Embedded Labworks
HEAP_1
No implementa vPortFree().
Embedded Labworks
HEAP_1 (cont.)
Embedded Labworks
HEAP_2
Embedded Labworks
HEAP_2 (cont.)
Embedded Labworks
HEAP_3
Embedded Labworks
HEAP_3 (cont.)
Embedded Labworks
HEAP_4
desalocam
Embedded Labworks
HEAP_5
Embedded Labworks
HEAP_5 (cont.)
/*allocatetwoblocksofRAMforusebytheheap*/
constHeapRegion_txHeapRegions[]=
{
{(uint8_t*)0x80000000UL,0x10000},
{(uint8_t*)0x90000000UL,0xa0000},
{NULL,0}
};
/*passthearrayintovPortDefineHeapRegions()*/
vPortDefineHeapRegions(xHeapRegions);
Embedded Labworks
Embedded Labworks
128K
HEAP
0X1FFFF
STACK
Embedded Labworks
LABORATRIO
Embedded Labworks
STACK
Embedded Labworks
STACK OVERFLOW
Embedded Labworks
Embedded Labworks
Embedded Labworks
LABORATRIO
Embedded Labworks
mecanismos
so
habilitados
configCHECK_FOR_STACK_OVERFLOW
FreeRTOSConfig.h.
atravs
no
da
constante
arquivo
Embedded Labworks
Embedded Labworks
MTODO 1
Embedded Labworks
MTODO 2
Embedded Labworks
LABORATRIO
Embedded Labworks
FreeRTOS
Embedded Labworks
Embedded Labworks
typedefstruct
{
intid;
void*data;
}AppEvent;
Embedded Labworks
Embedded Labworks
QUEUE SETS
Embedded Labworks
Embedded Labworks
[...]
Embedded Labworks
DESVANTAGENS
Embedded Labworks
QUANDO USAR?
Embedded Labworks
EVENT GROUPS
Event
Group
pode
xEventGroupCreate().
ser
criado
com
funo
Embedded Labworks
Embedded Labworks
Embedded Labworks
CASOS DE USO
Avalie o uso desta API sempre que uma tarefa precisar esperar por
mais de um evento do sistema.
Usando semforos e Queue Sets, podemos ter uma funcionalidade
parecida com a oferecida por esta API.
Mas alm de ser mais leve, esta API possui algumas diferenas
conceituais bem importantes:
Uma tarefa consegue ser notificada apenas quando um grupo de Event Bits
forem setados.
Quando vrias tarefas estiverem esperando no mesmo bit do Event Group,
todas sero acordadas quando o evento acontecer (broadcast).
Embedded Labworks
SOFTWARE TIMER
Embedded Labworks
Embedded Labworks
Embedded Labworks
HABILITANDO
tarefa de timer.
de timer.
Embedded Labworks
Embedded Labworks
Embedded Labworks
CO-ROUTINES
Embedded Labworks
CO-ROUTINES (cont.)
As
prioridades
de
uma
co-routine
vo de 0 at
configMAX_CO_ROUTINE_PRIORITIES 1 , definida no arquivo
FreeRTOSConfig.h.
Embedded Labworks
Embedded Labworks
Embedded Labworks
Embedded Labworks
ESCALONANDO CO-ROUTINES
/*schedulethecoroutinesintheidletaskhook*/
voidvApplicationIdleHook(void)
{
vCoRoutineSchedule(void);
}
Embedded Labworks
FreeRTOS
Embedded Labworks
INTEGRAO DE BIBLIOTECAS
Embedded Labworks
Thread-safe.
Consumo de recursos.
Determinismo.
Licena.
Acesso ao cdigo-fonte.
Embedded Labworks
FreeRTOS+
Embedded Labworks
FreeRTOS+ (cont.)
Embedded Labworks
FreeRTOS+ (cont.)
Embedded Labworks
FreeRTOS LABS
Embedded Labworks
BIBLIOTECAS DA COMUNIDADE
Embedded Labworks
BIBLIOTECAS DE FABRICANTES
NXP: LPCWare.
ST: STM32Cube.
Embedded Labworks
Embedded Labworks
Embedded Labworks
FreeRTOS
Ferramentas
Embedded Labworks
Embedded Labworks
Embedded Labworks
ESTATSTICAS DE EXECUO
Embedded Labworks
RUNTIME STATISTICS
Embedded Labworks
HABILITANDO
Habilitar
as
opes
configGENERATE_RUN_TIME_STATS
configUSE_STATS_FORMATTING_FUNCTIONS.
Esta rotina s deve ser usada para fins de teste e depurao, porque ela
lenta e desabilita todas as interrupes durante sua execuo.
Embedded Labworks
uxTaskGetSystemState
Embedded Labworks
uxTaskGetSystemState (cont)
#include"task.h"
/*returnsthestateofthesystem,populatinga
TaskStatus_tstructureforeachtask*/
UBaseType_tuxTaskGetSystemState(
TaskStatus_t*constpxTaskStatusArray,
constUBaseType_tuxArraySize,
unsignedlong*constpulTotalRunTime);
);
Embedded Labworks
uxTaskGetSystemState (cont)
typedefstructxTASK_STATUS
{
TaskHandle_txHandle;
constsignedchar*pcTaskName;
UBaseType_txTaskNumber;
eTaskStateeCurrentState;
UBaseType_tuxCurrentPriority;
UBaseType_tuxBasePriority;
unsignedlongulRunTimeCounter;
unsignedshortusStackHighWaterMark;
}TaskStatus_t;
Embedded Labworks
LABORATRIO
Embedded Labworks
TRACING
Embedded Labworks
depois
usar
as funes vTaskStartTrace()
ulTaskEndTrace() para iniciar e finalizar o tracing.
Embedded Labworks
Embedded Labworks
Embedded Labworks
Embedded Labworks
Embedded Labworks
Embedded Labworks
Embedded Labworks
EXEMPLO 1
voidvTask1(void*pvParameters)
{
vTaskSetApplicationTaskTag(NULL,(void*)1);
for(;;)
{
}
}
voidvTask1(void*pvParameters)
{
vTaskSetApplicationTaskTag(NULL,(void*)2);
for(;;)
{
}
}
#definetraceTASK_SWITCHED_IN()\
vSetAnalogueOutput(0,(int)pxCurrentTCB>pxTaskTag)
Embedded Labworks
EXEMPLO 2
#definetraceBLOCKING_ON_QUEUE_RECEIVE(pxQueue)\
ulSwitchReason=reasonBLOCKING_ON_QUEUE_READ;
#definetraceBLOCKING_ON_QUEUE_SEND(pxQueue)\
ulSwitchReason=reasonBLOCKING_ON_QUEUE_SEND;
...
#definetraceTASK_SWITCHED_OUT()\
log_event(pxCurrentTCB,ulSwitchReason);
Embedded Labworks
MACROS DE TRACING
Embedded Labworks
FreeRTOS+TRACE
Embedded Labworks
STATEVIEWER PLUGIN
Embedded Labworks
SATEVIEWER NO IAR
Embedded Labworks
SIMULADORES
Embedded Labworks
FreeRTOS
Embedded Labworks
DEFININDO TAREFAS
Embedded Labworks
Embedded Labworks
DIVIDINDO EM TAREFAS
Embedded Labworks
Embedded Labworks
DEFININDO PRIORIDADES
Embedded Labworks
Embedded Labworks
FRMULA RMS
Embedded Labworks
TABELA RMS
Embedded Labworks
Embedded Labworks
OUTRAS TCNICAS
Embedded Labworks
TAMANHO DO STACK
Embedded Labworks
Embedded Labworks
STACK OVERFLOW
Embedded Labworks
Embedded Labworks
Embedded Labworks
INTERRUPES
Embedded Labworks
INTERRUPES (cont.)
Embedded Labworks
HEAP
Embedded Labworks
ESCALONADOR
Colaborativo.
Preemptivo.
Embedded Labworks
Colaborativo
SIM
NO
NO
SIM
SIM
SIM
NO
SIM
Preemptivo
SIM
SIM
SIM
SIM
Embedded Labworks
QUAL USAR?
Embedded Labworks
LABORATRIO
Projeto final
Embedded Labworks
FreeRTOS
E agora?
Embedded Labworks
RECURSOS ONLINE
Site do projeto:
http://freertos.org
Forum do projeto:
http://sourceforge.net/p/freertos/discussion/
Blog do Sergio Prado:
http://sergioprado.org
Embedded Labworks
BRTOS:
http://code.google.com/p/brtos/
BeRTOS:
http://www.bertos.org/
eCos:
http://ecos.sourceware.org/
Embedded Labworks
Embedded Labworks
UC/OS-III (Micrium):
http://micrium.com/page/products/rtos/os-iii
MQX (Freescale):
http://www.freescale.com/mqx
TI-RTOS (Texas Instruments):
http://www.ti.com/tool/ti-rtos
RTX (Keil):
http://www.keil.com/rtos/
Embedded Labworks
Embedded Labworks
LIVROS FREERTOS
Embedded Labworks
OUTROS LIVROS
Embedded Labworks
OBRIGADO!
E-mail
Website
sergio.prado@e-labworks.com
http://e-labworks.com
Embedded Labworks