Embedded Systems Design
Program Flows
Program Flows
-
Pooling
-
Interrupt Driven
Combination
Handling Concurrency
-
RTOS
Pooling
Basic Structure
void Setup()
{
// Initialization code goes here
}
void Loop()
{
// Your code goes here
}
Pooling
void Setup()
{
// Initialization code goes here
Initialization();
}
void Loop()
{
// Your code goes here
if(Peripheral_A)
{
ProcessA();
}
if(Peripheral_B)
{
ProcessB();
}
if(Peripheral_C)
{
ProcessC();
}
}
Interrupt Driven
Basic Structure
void Setup()
{
// Initialization code goes here
}
void Loop()
{
// Your code goes here
}
Interrupt Driven
void Setup()
{
// Initialization code goes here
Initialization();
}
void Loop()
{
// Empty. Things are done in Interrupts
}
void ISR(Routine_A)
{
ProcessA();
}
void ISR(Routine_B)
{
ProcessB();
}
void ISR(Routine_C)
{
ProcessC();
}
Combination
Basic Structure
void Setup()
{
// Initialization code goes here
}
void Loop()
{
// Your code goes here
}
Combination
volatile char isr_flag_a = 0;
void Setup()
{
// Initialization code goes here
Initialization();
}
void Loop()
{
// Your code goes here
if(isr_flag_a == 1)
{
isr_flag_a = 0; // Clear Flag
Process_A();
}
}
void ISR(Routine_A)
{
isr_flag_a = 1;
}
RTOS
Basic Structure
void Setup()
{
// Initialization code goes here
}
void Loop()
{
// Your code goes here
}
RTOS
#include <Arduino_FreeRTOS.h>
/* Additional Variables will be declared here... */
void Setup()
{
// Initialization code goes here
xTaskCreate(Task_A); // Note: abstract representation
}
void Loop()
{
// Empty. Things are done in Tasks
}
void Task_A()
{
// your code goes here...
}