RTOS & Applications for LPC2148 Aman Arora Ashmita Sinha Karthik Shankar 1 EE382M | Advanced...

24
RTOS & Applications for LPC2148 Aman Arora Ashmita Sinha Karthik Shankar 1 EE382M | Advanced Embedded Systems Architecture Spring 2011 | Project Presentation

Transcript of RTOS & Applications for LPC2148 Aman Arora Ashmita Sinha Karthik Shankar 1 EE382M | Advanced...

Page 1: RTOS & Applications for LPC2148 Aman Arora Ashmita Sinha Karthik Shankar 1 EE382M | Advanced Embedded Systems Architecture Spring 2011 | Project Presentation.

RTOS & Applications for LPC2148Aman AroraAshmita SinhaKarthik Shankar

1

EE38

2M |

Adv

ance

d Em

bedd

ed S

yste

ms

Arch

itect

ure

Sp

ring

2011

| P

roje

ct P

rese

ntati

on

Page 2: RTOS & Applications for LPC2148 Aman Arora Ashmita Sinha Karthik Shankar 1 EE382M | Advanced Embedded Systems Architecture Spring 2011 | Project Presentation.

Agenda• Objective• Overview• FreeRTOS• Porting• MCB2140 & LPC2148• CLI & Applications• Results and Status• Demo

2

Page 3: RTOS & Applications for LPC2148 Aman Arora Ashmita Sinha Karthik Shankar 1 EE382M | Advanced Embedded Systems Architecture Spring 2011 | Project Presentation.

Objective• To port an RTOS on LPC2148• ARM7 based SOC from NXP• Development board - MCB2140 from KEIL

• To develop applications on top of the RTOS

• Most importantly, LEARN !!!

3

Page 4: RTOS & Applications for LPC2148 Aman Arora Ashmita Sinha Karthik Shankar 1 EE382M | Advanced Embedded Systems Architecture Spring 2011 | Project Presentation.

Overview

4

LPC 2148 (ARM7)

FreeRTOS

FLASHMUSICLED

CLI

RTOS Selection

Understanding FreeRTOS

Understanding MCB2140 & LPC2148

Porting

CLI & Application Development

Testing & Debugging

Page 5: RTOS & Applications for LPC2148 Aman Arora Ashmita Sinha Karthik Shankar 1 EE382M | Advanced Embedded Systems Architecture Spring 2011 | Project Presentation.

Tasks and divisionTask Who?

Choosing a RTOS Aman, Karthik, Ashmita

Understanding the board and the SOC

Aman, Karthik, Ashmita

Understanding the concepts of FreeRTOS

Aman, Karthik, Ashmita

Porting the RTOS and writing the LED Task

Karthik, Ashmita

The Music Task Aman, Karthik

The Flash Task Aman, Karthik

Command Line Interface Aman, Ashmita

Porting FatFS Karthik, Ashmita5

Page 6: RTOS & Applications for LPC2148 Aman Arora Ashmita Sinha Karthik Shankar 1 EE382M | Advanced Embedded Systems Architecture Spring 2011 | Project Presentation.

FreeRTOS• Why FreeRTOS?• Free!• Active project• Low footprint – 4K to 7K• Good documentation

• Features• Written mostly in C• Supports tasks and co-routines• Many communication and synchronization primitives• Version 6.1.1• Mini-real time kernel• freeRTOSConfig.h

6

Page 7: RTOS & Applications for LPC2148 Aman Arora Ashmita Sinha Karthik Shankar 1 EE382M | Advanced Embedded Systems Architecture Spring 2011 | Project Presentation.

FreeRTOS• Scheduler• Supports preemptive, cooperative or hybrid scheduling• Threads are maintained in a queue• Scheduling algorithm – highest priority first

• Threads which are runnable and have highest priority are scheduled• Threads with same priority run with round robin scheduling

• Preemption implemented• Tick count – Tasks can mention the max time to be blocked

• Will be waken up after the time

7

Page 8: RTOS & Applications for LPC2148 Aman Arora Ashmita Sinha Karthik Shankar 1 EE382M | Advanced Embedded Systems Architecture Spring 2011 | Project Presentation.

FreeRTOS• Tasks• Running, Ready, Blocked or Suspended state• Task priority – 0 to (configMAX_PRIORITIES - 1)

• 0 – lowest• APIs

• xTaskCreate, vTaskResume, vTaskSuspend, xTaskHandle, vTaskDelete• Idle task – priority 0

• Idle task hook (called during each cycle of idle task)

• Co-routines• Only intended for very small processors with severe RAM

constraints• Shared stack• Complex

8

Page 9: RTOS & Applications for LPC2148 Aman Arora Ashmita Sinha Karthik Shankar 1 EE382M | Advanced Embedded Systems Architecture Spring 2011 | Project Presentation.

FreeRTOS• Inter process communication• Queues

• Passed by value• Blocking or Non-Blocking• Zero time out creates non-blocking• Used in ISRs

• Mutex• With priority inversion

• Semaphore

9

Page 10: RTOS & Applications for LPC2148 Aman Arora Ashmita Sinha Karthik Shankar 1 EE382M | Advanced Embedded Systems Architecture Spring 2011 | Project Presentation.

Porting• Used FreeRTOS for LPC2888 as reference

• Existing port used Rowley-GCC compiler

• Modified Startup.s• Reduced stack size for FIQ• Kept the same values for PLL• Removed EMC configurations

• Modified SOC specific register addresses (LPC214x.h)• Removed extra hardware configurations from prvSetupHardware

function (like I2S, USB, etc.)• Modified compiler dependent ISR definitions• Redid project files/makefiles for Keil uVision• Reduced the functionalities in the RTOS due to compiler limitations• Removed the ErrorChecking task• Enabled vTaskDelete

10

Page 11: RTOS & Applications for LPC2148 Aman Arora Ashmita Sinha Karthik Shankar 1 EE382M | Advanced Embedded Systems Architecture Spring 2011 | Project Presentation.

MCB2140

LPC2148

SD Card Slot

Potentiometer

Speaker

LED

COM ports

Reset

USB/Power

11

Page 12: RTOS & Applications for LPC2148 Aman Arora Ashmita Sinha Karthik Shankar 1 EE382M | Advanced Embedded Systems Architecture Spring 2011 | Project Presentation.

flash_task(R/W)

Communication(Programming & hyperterminal)

music_task

12led_task (P1:16 –23)

LPC2148

Page 13: RTOS & Applications for LPC2148 Aman Arora Ashmita Sinha Karthik Shankar 1 EE382M | Advanced Embedded Systems Architecture Spring 2011 | Project Presentation.

Program Flow

ledTask

CLI Task

flashTask

musicTask

mt

dm

fm

Reset

Startup.s

main

13

Page 14: RTOS & Applications for LPC2148 Aman Arora Ashmita Sinha Karthik Shankar 1 EE382M | Advanced Embedded Systems Architecture Spring 2011 | Project Presentation.

Command Line Interface• Interface to the user through COM port

• Some commands implemented• TOP• CLEAR• START LED• STOP LED• START FLASH

• MT• FM• DM

• STOP FLASH• START MUSIC• STOP MUSIC• ECHO

14

Page 15: RTOS & Applications for LPC2148 Aman Arora Ashmita Sinha Karthik Shankar 1 EE382M | Advanced Embedded Systems Architecture Spring 2011 | Project Presentation.

LED Task• Mainly used for debugging purpose• LEDs mapped to P1.16 -> P1.23 implement 8 bit counter

LED Port Init

LED Toggle

Delay

LED Clear

LED Task Delete and

Update Task List

LED Task Create

TASK 15

start led stop led

Page 16: RTOS & Applications for LPC2148 Aman Arora Ashmita Sinha Karthik Shankar 1 EE382M | Advanced Embedded Systems Architecture Spring 2011 | Project Presentation.

Music Task• Uses both ADC & DAC

• Timer Interrupt period determined based on

POT position (Timer1)

• Registered ISR using VICVectAddr & VICIntEnable

registers

Potentiometer

ADC

Timer Interrupt

Sine Wave Sample

Generation

DAC

Speaker16

Page 17: RTOS & Applications for LPC2148 Aman Arora Ashmita Sinha Karthik Shankar 1 EE382M | Advanced Embedded Systems Architecture Spring 2011 | Project Presentation.

Flash Task• Used APIs for SPI and MMC communication (Source: NXP)

• Modified hardware specific initializations (Init function)• CLK freq• Block /Sector Configuration

• Changed bare metal calls to RTOS level calls

• Resolved conflicts in register addresses

17

Page 18: RTOS & Applications for LPC2148 Aman Arora Ashmita Sinha Karthik Shankar 1 EE382M | Advanced Embedded Systems Architecture Spring 2011 | Project Presentation.

Flash Task

mmc_write_block(block)MMCWR -> data

MT

FM

DM

EXIT

mmc_write_block(block)mmc_read_block(block)

Compare MMCWR & MMCRD

mmc_read_block(block)MMCRD -> data

Flash Prompt Parse command

18Update Task ListDelete Flash Task

Page 19: RTOS & Applications for LPC2148 Aman Arora Ashmita Sinha Karthik Shankar 1 EE382M | Advanced Embedded Systems Architecture Spring 2011 | Project Presentation.

Flash Task APIs

MMC_Init

Send CMD0(Idle State Cmd)

CMD1(SEND_OP_COND)

CMD16(SET_BLOCKLEN)

MMC_Read_Block

Generate Address

corresponding to given block

number

CMD17(READ_SINGLE_BLOCK)

SPI_Receive

MMC_Write_Block

Generate Address

corresponding to given block

number

CMD24(WRITE_SINGLE_BLOCK)SPI_Send

19

Page 20: RTOS & Applications for LPC2148 Aman Arora Ashmita Sinha Karthik Shankar 1 EE382M | Advanced Embedded Systems Architecture Spring 2011 | Project Presentation.

FatFS• Generic FAT filesystem module for small embedded systems

• Provides application interface (fopen, fclose, fmount) and disk

• I/O interface (disk initialize, disk read/write)

• Found existing implementation for OLIMEX ARM7 board

• Issues faced:• Port was for MMC interface - had different pinout• Unable to initialize disk• Compiler Issues

20

Page 21: RTOS & Applications for LPC2148 Aman Arora Ashmita Sinha Karthik Shankar 1 EE382M | Advanced Embedded Systems Architecture Spring 2011 | Project Presentation.

Results and Status• Successfully ported FreeRTOS on LPC2148

• Created Command Line Interface through UART

• Successfully developed/ported applications• LED• Music• Flash

• Block read and write only

• Struggling with FatFS porting 21

Page 22: RTOS & Applications for LPC2148 Aman Arora Ashmita Sinha Karthik Shankar 1 EE382M | Advanced Embedded Systems Architecture Spring 2011 | Project Presentation.

Next Time…• Port a more complex Operating System

• Start early on FatFS port!!!

• Add USB interface to SD card

22

Page 23: RTOS & Applications for LPC2148 Aman Arora Ashmita Sinha Karthik Shankar 1 EE382M | Advanced Embedded Systems Architecture Spring 2011 | Project Presentation.

References• http://www.freertos.org/• http://www.keil.com/mcb2140/• LPC2148 user manual• http://efsl.be/• http://ics.nxp.com/support/documents/microcontrollers/pdf/

an10406.pdf

23

Page 24: RTOS & Applications for LPC2148 Aman Arora Ashmita Sinha Karthik Shankar 1 EE382M | Advanced Embedded Systems Architecture Spring 2011 | Project Presentation.

DEMO …

24