Вы находитесь на странице: 1из 48

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

Matt Gordon, Micrium Wendy Lockhart, Actel

What is SmartFusion?

Actel Corporation Confidential 2010

SmartFusion: Innovative, Intelligent, Integration

Proven FPGA fabric Complete ARM Cortex-M3 MCU subsystem...& its hard Programmable analog In a flash-based device In production now!

Actel Corporation Confidential 2010

No-Compromise Microcontroller Subsystem (MSS)


100 MHz 32-bit ARM Cortex-M3 processor Bus matrix with up to 16 Gbps throughput 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

Actel Corporation Confidential 2010

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

Actel Corporation Confidential 2010

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

Actel Corporation Confidential 2010

Innovative Intelligent Integration

Actel Corporation Confidential 2010

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

Actel Corporation Confidential 2010

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

Actel Corporation Confidential 2010

An Introduction to RealTime Kernels

2009, Micrim, All Rights Reserved

www.Micrium.com

Real-Time Operating Systems


A real-time operating system, or RTOS, is a collection of software that provides useful services to application code
Application
File System GUI TCP/IP Kernel RTOS USB Bluetooth RS-232

Hardware
www.Micrium.com

2009, Micrim, All Rights Reserved

Real-Time Kernels
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

2009, Micrim, All Rights Reserved

www.Micrium.com

A Foreground/Background Example
Background
int { Perform initializations; while (1) { ADC_Read(); SPI_Read(); USB_Packet(); LCD_Update(); Audio_Decode(); File_Write(); } } } main (void)

Foreground
void { Clear interrupt; Read packet; App_ISRUSB (void)

2009, Micrim, All Rights Reserved

www.Micrium.com

A Kernel-Based Example
Tasks
void { while (1) { ADC_Read(); Sleep for 1 ms; } } void { while (1) { Wait for signal from ISR; USB_Packet(); } } App_TaskUSB (void *p_arg) } App_TaskADC (void *p_arg)

ISRs
void { Clear interrupt; Signal USB Task; App_ISRUSB (void)

2009, Micrim, All Rights Reserved

www.Micrium.com

Tasks
C functions Usually periodic Can be treated almost as if they are separate programs Managed by the kernel

2009, Micrim, All Rights Reserved

www.Micrium.com

Tasks (Cont.)
static void App_TaskExample (void *p_arg) { Perform initializations; while (1) { Work toward tasks goals; } }

2009, Micrim, All Rights Reserved

www.Micrium.com

Data Structures Associated with Tasks


Task Control Block (TCB)
Allows the kernel to keep track of a tasks state

2009, Micrim, All Rights Reserved

www.Micrium.com

Data Structures Associated with Tasks

StkPtr ExtPtr StkLimitPtr NextPtr PrevPtr

2009, Micrim, All Rights Reserved

www.Micrium.com

Data Structures Associated with Tasks


Stack
Used to save register values during context switches

StkPtr ExtPtr StkLimitPtr NextPtr PrevPtr

2009, Micrim, All Rights Reserved

www.Micrium.com

Data Structures Associated with Tasks

R4 R5 R6 R7 R8 R9 R10 R11 StkPtr ExtPtr StkLimitPtr NextPtr PrevPtr R0 R1 R2 R3 R12 LR PC

= 0x04040404 = 0x05050505 = 0x06060606 = 0x07070707 = 0x08080808 = 0x09090909 = 0x10101010 = 0x11111111 = p_arg = 0x01010101 = 0x02020202 = 0x03030303 = 0x12121212 = OS_TaskReturn = task

xPSR = 0x01000000
www.Micrium.com

2009, Micrim, All Rights Reserved

Task Creation
void OSTaskCreate (OS_TCB CPU_CHAR OS_TASK_PTR void OS_PRIO CPU_STK CPU_STK The tasks OS_STK_SIZE priority OS_MSG_QTY OS_TICK void OS_OPT OS_ERR *p_tcb, The tasks TCB *p_name, *p_task, *p_arg, The actual task prio, *p_stk_base, *p_stk_limit, The tasks stk_size, stack q_size, time_quanta, *p_ext, opt, *p_err);

2009, Micrim, All Rights Reserved

www.Micrium.com

Understanding Kernel Services

2009, Micrim, All Rights Reserved

www.Micrium.com

Foreground/Background Scheduling
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

2009, Micrim, All Rights Reserved

www.Micrium.com

Kernel Scheduling
The kernel is responsible for running tasks There are two common schemes Cooperative scheduling Preemptive scheduling

2009, Micrim, All Rights Reserved

www.Micrium.com

Cooperative Scheduling

Interrupt signals the availability of the USB Tasks data

ISR

USB Task

ADC Task

The USB task cannot run until the ADC task completes
Time

2009, Micrim, All Rights Reserved

www.Micrium.com

Preemptive Scheduling

Interrupt signals the availability of the highpriority tasks data

ISR

The high-priority task is scheduled by the kernel

USB Task (High Priority)

ADC Task (Low Priority)


Time
www.Micrium.com

2009, Micrim, All Rights Reserved

Setting Execution Rates in a Foreground/Background System


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(); } All rates are based on the total File_Write(); execution time of the loop i++; } }
2009, Micrim, All Rights Reserved www.Micrium.com

Setting Execution Rates with a Kernel


static void App_TaskStart (void *p_arg) { OS_ERR err; Perform initializations; Kernel delays task while (1) { for 100 ms Toggle LED; OSTimeDlyHMSM(0, 0, 0, 100, OS_OPT_TIME_HMSM_STRICT, &err); } }
www.Micrium.com

2009, Micrim, All Rights Reserved

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

Task A

Task B

Task C
Time Quantum Time
www.Micrium.com

2009, Micrim, All Rights Reserved

Synchronization in a Foreground/Background System


int { Perform initializations; while (1) { ADC_Rd(); SPI_Rd(); USB_Pkt(); LCD_Update(); } } void { while (App_PktRxd > 0) { Read packet; Send response; App_PktRxd--; } }
2009, Micrim, All Rights Reserved www.Micrium.com

main (void)

void {

App_ISRUSB (void) Clear interrupt; App_PktRxd++;

A global variable is used to signal packet reception


USB_Pkt (void)

Synchronization in a Kernel
void { Perform initializations; while (1) { Pend on semaphore; Read packet; Send response; } } } App_TaskUSB (void *p_arg) void { Clear interrupt; Post semaphore; App_ISRUSB (void)

Signaling is accomplished with a kernel primitive called a semaphore

2009, Micrim, All Rights Reserved

www.Micrium.com

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, Micrim, All Rights Reserved

www.Micrium.com

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, Micrim, All Rights Reserved

www.Micrium.com

Resource Protection in a Foreground/Background System


int { Perform initializations; while (1) { ADC_Rd(); SPI_Rd(); UART_Write(); LCD_Update(); } } void { Disable interrupts; Write message; UART_Write (void) } main (void) void { Clear interrupt; Read received character; App_ISRUART (void)

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

Re-enable interrupts; }

2009, Micrim, All Rights Reserved

www.Micrium.com

Resource Protection in a Kernel


void { Perform initializations; while (1) { Acquire mutex; Write message; Release mutex; Delay for 1s; } } } App_TaskUART (void *p_arg) void { Perform initializations; while (1) { Read file; Acquire mutex; Write status to UART; Release mutex; App_TaskFS (void *p_arg)

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

2009, Micrim, All Rights Reserved

www.Micrium.com

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, Micrim, All Rights Reserved

www.Micrium.com

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, Micrim, All Rights Reserved

www.Micrium.com

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, Micrim, All Rights Reserved

www.Micrium.com

C/OS-III Example #1

2009, Micrim, All Rights Reserved

www.Micrium.com

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, Micrim, All Rights Reserved

www.Micrium.com

Hardware

2009, Micrim, All Rights Reserved

www.Micrium.com

Programming the Board


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
2009, Micrim, All Rights Reserved www.Micrium.com

Building and Running the Example


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
2009, Micrim, All Rights Reserved www.Micrium.com

app.c, main()
OSInit(&os_err); OSTaskCreate((OS_TCB (CPU_CHAR (OS_TASK_PTR (void (OS_PRIO (CPU_STK *)&App_TaskStartTCB, *)"Start", )App_TaskStart, *)0, )APP_CFG_TASK_START_PRIO, *)&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 (OS_TICK (void (OS_OPT (OS_ERR OSStart(&os_err);
2009, Micrim, All Rights Reserved www.Micrium.com

)0u, )0u, *)0, )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), *)&os_err);

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, Micrim, All Rights Reserved

www.Micrium.com

C/OS-III Example #2

2009, Micrim, All Rights Reserved

www.Micrium.com

C/Probe

2009, Micrim, All Rights Reserved

www.Micrium.com

Contact Information
Sales questions:
Robert Langley, Sales Representative Phone: +1 954 217 2036 Ext. 104 E-mail: robert.langley@micrium.com

Other inquiries:
Matt Gordon, Sr. Applications Engineer Phone: +1 954 217 2036 Ext. 102 E-mail: matt.gordon@micrium.com

2009, Micrim, All Rights Reserved

www.Micrium.com

Вам также может понравиться