48
Rapid product development with Actel's ARM-based SmartFusion and Micrium's μC/OS-III Matt Gordon, Micrium Wendy Lockhart, Actel

Smart Fusion Micrium Webinar

Embed Size (px)

Citation preview

Page 1: Smart Fusion Micrium Webinar

Rapid product development with Actel's ARM-based SmartFusion and Micrium's µC/OS-III

Matt Gordon, Micrium

Wendy Lockhart, Actel

Page 2: Smart Fusion Micrium Webinar

Actel Corporation Confidential © 2010 2

What is SmartFusion?

Page 3: Smart Fusion Micrium Webinar

Actel Corporation Confidential © 2010 3

SmartFusion: Innovative, Intelligent, Integration

Proven FPGA fabric

Complete ARM® Cortex™-M3 MCU subsystem...& it’s ‘hard’

Programmable analog

In a flash-based device

In production now!

Page 4: Smart Fusion Micrium Webinar

Actel Corporation Confidential © 2010 4

No-Compromise Microcontroller Subsystem (MSS)

100 MHz 32-bit ARM Cortex-M3 processor

Bus matrix with up to 16 Gbpsthroughput

10/100 Ethernet MAC SPI, I2C, UART, 32-bit Timers Up to 512 KB flash and 64 KB of

SRAM External memory controller 8-channel DMA controller Up to 41 MSS I/Os

Page 5: Smart Fusion Micrium Webinar

Actel Corporation Confidential © 2010 5

Programmable Analog

Analog compute engine (ACE) offloads CPU from analog tasks

Voltage, current and temp monitors 12-bit (SAR) ADCs @ up to 600 Ksps Sigma-Delta DACs Up to ten 50 ns high-speed comparators Up to 32 analog inputs and 3 outputs

Page 6: Smart Fusion Micrium Webinar

Actel Corporation Confidential © 2010 6

No-Compromise FPGA Fabric

Proven flash-based FPGA fabric 60,000 to 500,000 system gates 350 MHz system performance Embedded SRAMs and FIFOs Up to 128 FPGA I/Os

Page 7: Smart Fusion Micrium Webinar

Actel Corporation Confidential © 2010 7

Innovative Intelligent Integration

Page 8: Smart Fusion Micrium Webinar

Actel Corporation Confidential © 2010 8

SmartFusion Design Environment

Full-featured traditional FPGA design flow

Industry-leading software IDEs for embedded design

Simulation, timing and power analysis reduce debug time

Debug through FlashPro or standard RealView® header

Page 9: Smart Fusion Micrium Webinar

Actel Corporation Confidential © 2010 9

MSS Configurator

Configure the MSS peripherals and I/Os

Create or import hardware configuration

Automatically generate drivers for peripherals

Configure programmable analog components

Enables connection of FPGA fabric designs and IP to MSS

MSS configurator enables co-design between multiple users

Page 10: Smart Fusion Micrium Webinar

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

An Introduction to Real-Time Kernels

Page 11: Smart Fusion Micrium Webinar

Real-Time Operating Systems

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

A real-time operating system, or RTOS, is a collection of software that provides useful services to application code

Application

RTOS

Hardware

File SystemGUI

TCP/IP

USBBluetooth

RS-232

Kernel

Page 12: Smart Fusion Micrium Webinar

Real-Time Kernels

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

A kernel is a key RTOS component– Essentially a task scheduler – The glue that holds the other components together

Application developers can use a real-time kernel to achieve deterministic performance

Most common alternative is the foreground/background system

Page 13: Smart Fusion Micrium Webinar

A Foreground/Background Example

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

Background

int main (void)

{

Perform initializations;

while (1) {

ADC_Read();

SPI_Read();

USB_Packet();

LCD_Update();

Audio_Decode();

File_Write();

}

}

Foreground

void App_ISRUSB (void)

{

Clear interrupt;

Read packet;

}

Page 14: Smart Fusion Micrium Webinar

A Kernel-Based Example

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

Tasks

void App_TaskADC (void *p_arg)

{

while (1) {

ADC_Read();

Sleep for 1 ms;

}

}

void App_TaskUSB (void *p_arg)

{

while (1) {

Wait for signal from ISR;

USB_Packet();

}

}

ISRs

void App_ISRUSB (void)

{

Clear interrupt;

Signal USB Task;

}

Page 15: Smart Fusion Micrium Webinar

Tasks

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

C functions

Usually periodic

Can be treated almost as if they are separate programs

Managed by the kernel

Page 16: Smart Fusion Micrium Webinar

Tasks (Cont.)

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

static void App_TaskExample (void *p_arg){

Perform initializations;

while (1) {Work toward task’s goals;

}}

Page 17: Smart Fusion Micrium Webinar

Data StructuresAssociated with Tasks

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

Task Control Block (TCB)

Allows the kernel to keep track of a task’s state

Page 18: Smart Fusion Micrium Webinar

Data StructuresAssociated with Tasks

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

StkLimitPtr

StkPtr

ExtPtr

NextPtr

PrevPtr

Page 19: Smart Fusion Micrium Webinar

Data StructuresAssociated with Tasks

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

StkLimitPtr

StkPtr

ExtPtr

NextPtr

PrevPtr

Used to save register values during context switches

Stack

Page 20: Smart Fusion Micrium Webinar

Data StructuresAssociated with Tasks

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

StkLimitPtr

StkPtr

ExtPtr

NextPtr

PrevPtr

R4 = 0x04040404

R5 = 0x05050505

R6 = 0x06060606

R7 = 0x07070707

R8 = 0x08080808

R9 = 0x09090909

R10 = 0x10101010

R11 = 0x11111111

R0 = p_arg

R1 = 0x01010101

R2 = 0x02020202

R3 = 0x03030303

R12 = 0x12121212

LR = OS_TaskReturn

PC = task

xPSR = 0x01000000

Page 21: Smart Fusion Micrium Webinar

Task Creation

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

void OSTaskCreate (OS_TCB *p_tcb,CPU_CHAR *p_name, OS_TASK_PTR *p_task,void *p_arg,OS_PRIO prio,CPU_STK *p_stk_base,CPU_STK *p_stk_limit,OS_STK_SIZE stk_size,OS_MSG_QTY q_size,OS_TICK time_quanta,void *p_ext,OS_OPT opt,OS_ERR *p_err);

The task’s priority

The actual task

The task’s stack

The task’s TCB

Page 22: Smart Fusion Micrium Webinar

Understanding Kernel Services

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

Page 23: Smart Fusion Micrium Webinar

Foreground/Background Scheduling

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

while (1) {ADC_Read();LCD_Update();SPI_Read();USB_Packet();LCD_Update();Audio_Decode();File_Write();LCD_Update();

}

Functions must be called repeatedly in order to produce expected behavior

Page 24: Smart Fusion Micrium Webinar

Kernel Scheduling

The kernel is responsible for running tasks

There are two common schemes– Cooperative scheduling– Preemptive scheduling

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

Page 25: Smart Fusion Micrium Webinar

Cooperative Scheduling

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

ADC Task

USB Task

ISR

Time

Interrupt signals the availability of the USB Task’s data

The USB task cannot run until the ADC task completes

Page 26: Smart Fusion Micrium Webinar

Preemptive Scheduling

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

ADC Task(Low Priority)

USB Task(High Priority)

ISR

Time

Interrupt signals the availability of the high-priority task’s data

The high-priority task is scheduled by the kernel

Page 27: Smart Fusion Micrium Webinar

Setting Execution Rates in a Foreground/Background System

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

int main (void) {unsigned short i;

i = 0;

while (1) {ADC_Read();if ((i % 8192) == 0) {

SPI_Read();}USB_Packet();LCD_Update();if ((i % 1024) == 0) {

Audio_Decode();}File_Write();i++;

}}

All rates are based on the total execution time of the loop

Page 28: Smart Fusion Micrium Webinar

Setting Execution Rates with a Kernel

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

static void App_TaskStart (void *p_arg){

OS_ERR err;

Perform initializations;

while (1) {

Toggle LED;OSTimeDlyHMSM(0, 0, 0, 100,

OS_OPT_TIME_HMSM_STRICT,

&err);}

}

Kernel delays task for 100 ms

Page 29: Smart Fusion Micrium Webinar

Round-Robin Scheduling

Multiple tasks are assigned the same priority– Kernel runs each task for a period of time set by the application developer

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

Task C

Task B

Task A

TimeTime Quantum

Page 30: Smart Fusion Micrium Webinar

Synchronization in a Foreground/Background System

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

int main (void)

{

Perform initializations;

while (1) {

ADC_Rd();

SPI_Rd();

USB_Pkt();

LCD_Update();

}

}

void App_ISRUSB (void)

{

Clear interrupt;

App_PktRxd++;

}

void USB_Pkt (void)

{

while (App_PktRxd > 0) {

Read packet;

Send response;

App_PktRxd--;

}

}

A global variable is used to signal packet reception

Page 31: Smart Fusion Micrium Webinar

Synchronization in a Kernel

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

void App_TaskUSB (void *p_arg)

{

Perform initializations;

while (1) {

Pend on semaphore;

Read packet;

Send response;

}

}

void App_ISRUSB (void)

{

Clear interrupt;

Post semaphore;

}

Signaling is accomplished with a kernel primitive called a semaphore

Page 32: Smart Fusion Micrium Webinar

Semaphores

Essentially counters– A zero value indicates no activity– A non-zero value indicates that events have taken place

Two primary operations– Pend: Wait for events to occur– Post: Signal occurrence of events

While one task is waiting, the kernel runs other tasks

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

Page 33: Smart Fusion Micrium Webinar

Event Flags

Another means of synchronization

Implemented with 8-, 16-, or 32-bit variables– Each bit corresponds to an event

Pend and post operations– Tasks can wait for multiple events to take place

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

Page 34: Smart Fusion Micrium Webinar

Resource Protection in a Foreground/Background System

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

int main (void)

{

Perform initializations;

while (1) {

ADC_Rd();

SPI_Rd();

UART_Write();

LCD_Update();

}

}

void App_ISRUART (void)

{

Clear interrupt;

Read received character;

}

void UART_Write (void)

{

Disable interrupts;

Write message;

Re-enable interrupts;

}

Interrupts must be disabled while the shared resource (the UART) is accessed

Page 35: Smart Fusion Micrium Webinar

Resource Protection in a Kernel

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

void App_TaskUART (void *p_arg)

{

Perform initializations;

while (1) {

Acquire mutex;

Write message;

Release mutex;

Delay for 1s;

}

}

void App_TaskFS (void *p_arg)

{

Perform initializations;

while (1) {

Read file;

Acquire mutex;

Write status to UART;

Release mutex;

}

}A kernel primitive called a mutex is used to protect shared resources

Page 36: Smart Fusion Micrium Webinar

Mutexes

Implemented much like semaphores– Counter is normally initialized to a value of one

Only effective when used every time a shared resource is accessed

May offer protection against priority inversion

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

Page 37: Smart Fusion Micrium Webinar

Additional Means of Resource Protection

Locking and Unlocking the scheduler

Disabling and Re-enabling interrupts– The only effective technique for resources that are accessed by ISRs

Semaphores– Use for resource protection is discouraged due to potential for priority

inversion

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

Page 38: Smart Fusion Micrium Webinar

Summary of Kernels and Kernel Services

A kernel facilitates development of multi-task applications

Most kernels are either cooperative are preemptive– In a preemptive kernel, high priority tasks run as soon as they are made ready

Task management is not the only service provided by a typical kernel– Other services include synchronization and resource protection

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

Page 39: Smart Fusion Micrium Webinar

µC/OS-III Example #1

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

Page 40: Smart Fusion Micrium Webinar

Required Tools and Software

Libero IDE and SoftConsole– Available from http://www.actel.com/download/software/libero/files.aspx

µC/OS-III example projects and µC/Probe– Available from http://micrium.com/page/downloads/ports/actel

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

Page 41: Smart Fusion Micrium Webinar

Hardware

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

Page 42: Smart Fusion Micrium Webinar

Programming the Board

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

1. Extract contents of uCOS-III-Actel-SmartFusionEvalKit.zip

2. Jumper JP7 to USB PROG and JP10 to FPGA

3. Connect board to PC– Two USB connections

4. Run FlashPro

5. Create New Project

6. Specify PDB file and program– MICRIUM\Software\EvalBoards\Actel\SmartFusionEvalKit\Hardware\SmartFusion.pdb

Page 43: Smart Fusion Micrium Webinar

Building and Running the Example

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

1. Start SoftConsole– Choose workspace location

2. Import examples

3. Set path and environment variables

4. Build first project, Ex1_OS

5. Open Debug Dialog– Jumper JP10 should be in M3 position

6. Run code

Page 44: Smart Fusion Micrium Webinar

app.c, main()

OSInit(&os_err);

OSTaskCreate((OS_TCB *)&App_TaskStartTCB,

(CPU_CHAR *)"Start",

(OS_TASK_PTR )App_TaskStart,

(void *)0,

(OS_PRIO )APP_CFG_TASK_START_PRIO,

(CPU_STK *)&App_TaskStartStk[0],

(CPU_STK_SIZE )APP_CFG_TASK_START_STK_SIZE_LIMIT,

(CPU_STK_SIZE )APP_CFG_TASK_START_STK_SIZE,

(OS_MSG_QTY )0u,

(OS_TICK )0u,

(void *)0,

(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),

(OS_ERR *)&os_err);

OSStart(&os_err);

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

Page 45: Smart Fusion Micrium Webinar

app.c, App_TaskStart()

/* Initializations */

App_TaskCreate();

App_ObjCreate();

while (DEF_TRUE) {

BSP_LED_Toggle(1);

OSTimeDlyHMSM(0u, 0u, 0, 100u,

OS_OPT_TIME_HMSM_STRICT,

&err);

}

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

Page 46: Smart Fusion Micrium Webinar

µC/OS-III Example #2

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

Page 47: Smart Fusion Micrium Webinar

µC/Probe

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

Page 48: Smart Fusion Micrium Webinar

Contact Information

© 2009, Micriµm, All Rights Reservedwww.Micrium.com

Sales questions:Robert Langley, Sales RepresentativePhone: +1 954 217 2036 Ext. 104E-mail: [email protected]

Other inquiries:Matt Gordon, Sr. Applications EngineerPhone: +1 954 217 2036 Ext. 102E-mail: [email protected]