evolution of microcontroller firmware development david benjamin

24
Evolution of Microcontroller Firmware Development David Benjamin

Upload: bridget-owens

Post on 24-Dec-2015

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Evolution of Microcontroller Firmware Development David Benjamin

Evolution of Microcontroller Firmware Development

David Benjamin

Page 2: Evolution of Microcontroller Firmware Development David Benjamin

Overview

Traditional microcontroller firmware Polling Interrupts

Real-time Operating Systems Demonstration

Page 3: Evolution of Microcontroller Firmware Development David Benjamin

Polling

Polling is when a process continually evaluates the status of a register in an effort to synchronize program execution.

Polling is not widely used because it is an inefficient use of microcontroller resources.

Page 4: Evolution of Microcontroller Firmware Development David Benjamin

Polling Example

void main ( void ){

while(1){

while (!button1_pressed);turn_on_led;while (!button1_pressed);turn_off_led;

}}

Page 5: Evolution of Microcontroller Firmware Development David Benjamin

Interrupts

Interrupt as defined by Merriam Webster to break in upon an action

Interrupt An event that causes the Program Counter (PC) to

change. These events can be internal or external.

Interrupt Service Routine (ISR) Set of instructions that is executed when an

interrupt occurs

Interrupt Vector Memory address of the first instruction in the ISR.

Page 6: Evolution of Microcontroller Firmware Development David Benjamin

Interrupts

Why should one use interrupts? Provides more efficient use of

microcontroller resources. Provides a means to create firmware that

can “multi-task”.

Page 7: Evolution of Microcontroller Firmware Development David Benjamin

Interrupts

Interrupts are often prioritized within the system and are associated with a variety of on-chip and off-chip peripherals Timers, A/D D/A converters, UART, GP I/O

A majority of the C interrupts can be enabled or disabled. Globally Individually Those interrupts that cannot be disabled are called Non-

Maskable Interrupts (NMI). Interrupts can be nested. Interrupts can occur at anyplace, at anytime.

ISRs should be kept short and fast.

Page 8: Evolution of Microcontroller Firmware Development David Benjamin
Page 9: Evolution of Microcontroller Firmware Development David Benjamin

What happens when an interrupt occurs?

Page 10: Evolution of Microcontroller Firmware Development David Benjamin

Interrupts

The current program instruction completes execution.

Main()

{

some code

turn_on_led1; 0x08A2

turn_off_led1; 0x08A3

}

__interrupt void port1_ISR(void)

{

disable_interrupts 0x0FE0

...

reti

}

The PC and status register values are placed on the stack.

The interrupt vector is loaded into the PC and SR is updated.

Program execution resumes with the first step of the ISR.

When the ISR has completed execution, the values of the PC and status registers are restored.

Program execution resumes with next instruction that would have occurred had the interrupt not taken place.

PC = 0x08A2

SR = 0xFE

PC = 0x0FE0

SR = 0x7E

PC = 0x8A3

SR = 0xFE

XXX

XXX

0x08A3

0xFE

STACK

Page 11: Evolution of Microcontroller Firmware Development David Benjamin

Interrupts vs. Polling

Allowed for more efficient use of the microcontroller. Faster program execution Multi-tasking

Facilitated the development of complex firmware. Supports a modular approach to firmware

design.

Page 12: Evolution of Microcontroller Firmware Development David Benjamin

Real-time Operating Systems

Page 13: Evolution of Microcontroller Firmware Development David Benjamin

Real-time Operating System

A real-time operating system (RTOS) is a multi-tasking operating system intended for real-time applications. Mainly used in embedded applications. Facilitates the creation of a real-time

system. Tool for the real-time software developer. Provides a layer abstraction between the

hardware and software.

Page 14: Evolution of Microcontroller Firmware Development David Benjamin

Real-time Operating System

State A unique operating condition of the system.

Task A single thread of execution through a group of

related states.

Task Manager Responsible for maintaining the current state of

each task. Responsible for providing each task with execution

time.

Page 15: Evolution of Microcontroller Firmware Development David Benjamin

Real-time Operating System

Collection of Tasks…

Single Task

Initial State

Idle State

Work State 1

Work State 2Work State 3

Work State 4Completion

State

Page 16: Evolution of Microcontroller Firmware Development David Benjamin

Real-time Operating System

A more detailed explanation state A function

void idleState ( void ); Should be kept short and fast Should represent a logical step in the task

i.e. Evaluating different parts of an incoming message.

Page 17: Evolution of Microcontroller Firmware Development David Benjamin

Real-time Operating System

void idleState( void ){

if (rx_buffer_full){

read_rxBuffer; if (syncByte_received)

{ transition_to_workState1;

} else

{ stay_in_idleState; }

} else {

stay_in_idleState; }}

Initial State

Idle State

Work State 1

Work State 2Work State 3

Work State 4Completion

State

Page 18: Evolution of Microcontroller Firmware Development David Benjamin

Real-time Operating System

Event-driven Tasks are granted

execution time, based on an event (interrupt).

Tasks of higher priority are executed first (interrupt priorities).

Time sharing Each task is granted a given

amount of time to execute. Tasks may also be granted

execution time based on events.

“Round-robin” approach Creates a more deterministic

multi-tasking system.

Page 19: Evolution of Microcontroller Firmware Development David Benjamin

Real-time Operating Systems

Initial State

State2

State2State2

State2

Initial State

State2

State2State2

State2

Receive Msg Process

Initial State

State2

State2State2

State2

Transmitt Responsevoid main ( void ){

initSystem();

while (1){

work();sleep();

}}void work (void){

doTask(RecieveMsg);doTask(Process);doTask(TransmittResponse);

}__interrupt void Timer_A (void){

wakeUp();}

Page 20: Evolution of Microcontroller Firmware Development David Benjamin

Real-time Operating System

Available commercially TinyOS -an open source component-based

operating system and platform targeting wireless sensor networks (WSNs).

Salvo - an RTOS developed by Pumpkin Inc. FreeRTOS - free RTOS that runs on several

architectures. DrRTOS - works with ARM 7

Implement a custom RTOS Can be highly optimized to suit your application

Page 21: Evolution of Microcontroller Firmware Development David Benjamin

Real-time Operating Systems

A tool for real-time software developers. Allows increasingly complex systems to

be developed in less time. Provides a level abstraction between

software and hardware. Continues the evolution microcontroller

system design.

Page 22: Evolution of Microcontroller Firmware Development David Benjamin

Application

Example Implementation

Example of RTOS application that requires wireless communication.

CC1100 HAL

Radio Operation Layer

Protocol

Application

Hardware abstraction layer for the radio. Performs low-level interaction between C and radio.

Groups low-level interactions from the HAL into higher-level functions.

Sending a packet

Middle-ware that provides a gateway between the application and RTOS.

Application

Page 23: Evolution of Microcontroller Firmware Development David Benjamin

Demonstration

Page 24: Evolution of Microcontroller Firmware Development David Benjamin

Questions?