50
Porting FreeRTOS on OpenRISC SpeakerYi-Chiao Lin

Porting FreeRTOS on OpenRISC

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Porting FreeRTOS   on   OpenRISC

Porting FreeRTOS on OpenRISC

Speaker:Yi-Chiao Lin

Page 2: Porting FreeRTOS   on   OpenRISC

• Motivation

• OpenRISC

• Porting FreeRTOS on OpenRISC

• Experiments

Outline

Page 3: Porting FreeRTOS   on   OpenRISC

Multi-Tasking Management Support

• Round-Robin 、 FIFO ……

Memory Management Unit Support

• TLB、Page Table ……

On-chip Memory Architecture Support

• Cache and SPM (scratch pad memory)

Motivation

Page 4: Porting FreeRTOS   on   OpenRISC

Scratch Pad Memory(SPM)

• Software controlled on-chip memory

• Consume less energy than cache

SPM (scratch pad memory)

Page 5: Porting FreeRTOS   on   OpenRISC

• Motivation

• OpenRISC

• Porting FreeRTOS on OpenRISC

• Experiments

Outline

Page 6: Porting FreeRTOS   on   OpenRISC

Or1200 Open Hardware CPU released

Implemented in the Verilog

5-stage pipeline

32 register

Special-Purpose Registers

OpenRISC

Page 7: Porting FreeRTOS   on   OpenRISC

l.mfspr / l.mtspr

MMU、Cache、Interrupt……

OpenRISC

Enable/Disable

Page 8: Porting FreeRTOS   on   OpenRISC

• Motivation

• OpenRISC

• Porting FreeRTOS on OpenRISC

• Experiments

Outline

Page 9: Porting FreeRTOS   on   OpenRISC

Real time operating system

Designed to be small and simple(2k~3k)

Stack can be shared between tasks

For free!!

FreeRTOS benefit

Page 10: Porting FreeRTOS   on   OpenRISC

Task Create

xTaskCreate(

pdTASK_CODE pvTaskCode,

const portCHAR * const pcName,

unsigned portSHORT usStackDepth,

void *pvParameters,

unsigned portBASE_TYPE uxPriority,

xTaskHandle *pvCreatedTask )

Page 11: Porting FreeRTOS   on   OpenRISC

void vRtosTask(void *pvParameters){

while(1){

.........

}

}

Task

Page 12: Porting FreeRTOS   on   OpenRISC

xTaskCreate

prvAllocateTCBAndStack( usStackDepth, puxStackBuffer

);

prvInitialiseTaskLists();

prvInitialiseTCBVariables( pxNewTCB, pcName, uxPriority, xRegions,

usStackDepth );

prvAddTaskToReadyQueue( pxNewTCB );

Page 13: Porting FreeRTOS   on   OpenRISC

• FreeRTOS porting file :

1. Port.c

2. Portmacro.h

3. Portasm.S

4. Port_spr_def.h(OpenRISC)

(Definition of special-purpose registers)

FreeRTOS/Source/portable/[Platform]

FreeRTOS Porting

Page 14: Porting FreeRTOS   on   OpenRISC

FreeRTOS Porting

Ported layer Port.c Portmacro.c Portasm.S Port_spr_def.h

Kernel layer

Application layer

Pagetable.c

TLB-miss ISR

Software(FreeRTOS)

Timer ISR

task.c

Data Moving ISR TLB.c

cache.c Interrupt handler

Reset.S

Hardware(OpenRISC) SPM Redirector

Page miss

Bookkeeping

Page 15: Porting FreeRTOS   on   OpenRISC

Port_spr_def.h

Page 16: Porting FreeRTOS   on   OpenRISC

Portmacro.h

Define Kernel Type

Page 17: Porting FreeRTOS   on   OpenRISC

pxPortInitialiseStack

vPortDisableInterrupts

vPortEnableInterrupts

prvSetupTimerInterrupt

xPortStartScheduler

port.c

Page 18: Porting FreeRTOS   on   OpenRISC

port.c (*pxPortInitialiseStack)

PxCode

uTaskSR

r31:0x00000031

r30:0x00000030

r29:0x00000029

.

.

.

High address

Low address

Page 19: Porting FreeRTOS   on   OpenRISC

vPortDisableInterrupts

vPortEnableInterrupts

port.c

Page 20: Porting FreeRTOS   on   OpenRISC

Exception Handler Exception type Vector offect[11:0] Example

Reset 0x100 Caused by Software or

Hardware reset

Bus error 0x200

Data Page fault 0x300

Instruction Page fault 0x400

Tick Timer 0x500 Timer interrupt

Alignment 0x600

Illegal Instruction 0x700

External interrupt 0x800 External interrupt asserted

D-TLB miss 0x900 No matching entry in DTLB

I-TLB miss 0xA00 No matching entry in ITLB

Range 0xB00

System call 0xC00

Float Point 0xD00

Trap 0xE00

Page 21: Porting FreeRTOS   on   OpenRISC

Exception Program Counter Registers

Exception Supervision Registers

Exception Effective Address Register

Exception Register

Page 22: Porting FreeRTOS   on   OpenRISC

Maximum timer count of 2^32 clock cycles

Tick Timer

TTMR

TTCR

RISC Clk Tick INT

Page 23: Porting FreeRTOS   on   OpenRISC

Tick Timer Mode Register

Page 24: Porting FreeRTOS   on   OpenRISC

Tick Timer Counter

Page 25: Porting FreeRTOS   on   OpenRISC

prvSetupTimerInterrupt

Port.c

Page 26: Porting FreeRTOS   on   OpenRISC

xPortStartScheduler

Task 1

Task2

Memory

Stack_TCB

Stack_TCB

Setup Timer

Load register

Load TCB

Page 27: Porting FreeRTOS   on   OpenRISC

• Context Switch

portSAVE_CONTEXT

portRESTORE_CONTEXT

Portasm.S

Task1 Task2

Stack_TCB Stack_TCB

Page 28: Porting FreeRTOS   on   OpenRISC

Portasm.S (Tick Handler)

Page 29: Porting FreeRTOS   on   OpenRISC

Reset register

Set Stack point、Clear BSS

Reset Cache、MMU、UART

Reset.S(Booting)

Page 30: Porting FreeRTOS   on   OpenRISC

OpenRISC Start at 0x100

Clear general-purpose registers

Reset register

Page 31: Porting FreeRTOS   on   OpenRISC

Set Stack Pointer

Clear BSS

Clear BSS (Block Started by Symbol)

Page 32: Porting FreeRTOS   on   OpenRISC

• Flush Cache

Data Cache Block Invalidate Register

Cache

Page 33: Porting FreeRTOS   on   OpenRISC

D-cache 8k 512Line 4word

PPN[31:13] 0x1[12:4] 0x8[3:0]

Physical [31:13]

Physical [31:13]

Physical [31:13]

Physical [31:13] WORD

WORD

WORD

WORD

WORD

Physical [31:13] V

V

V

V

V WORD

WORD

WORD

WORD 0

1

2

3

4

5

6

7

2047

0

1

2

3

511

13:2 12:4

Page 34: Porting FreeRTOS   on   OpenRISC

Task address space isolation

Allow safe sharing of memory among multiple tasks

Why OS need MMU Support?

CPU

Task1

Task2

Virtual

Task 1

Task2

Memory

Physical

Page 35: Porting FreeRTOS   on   OpenRISC

Page Index Level 1[31:24] Page Offset[12:0] Page Index Level 2[23:13]

0

255

PTE

PTE2

+

0

2047

Physical Page Number Page Offset[12:0]

+

Address

Page 36: Porting FreeRTOS   on   OpenRISC

Page Table entry

Physical Page Number D A WBC CI CC WOM W R W R REV

Entry Store in Memory

Set in Data Translation Lookaside Buffer Translate Registers when

DTLB-MISS

Page 37: Porting FreeRTOS   on   OpenRISC

TLB miss Handler

TLB MISS

Find the Task

Find Page Table

Set TLB register

Page 38: Porting FreeRTOS   on   OpenRISC

Exception Effective Address Registers

or1200_except.v

Exception Effective Address Registers

Page 39: Porting FreeRTOS   on   OpenRISC

DTLB Architecture

Virtial address[19:31] Index[13:18] Offset[12:0]

VPN [19:31] V

VPN [19:31] V

VPN [19:31] V

VPN [19:31] V

PPN [13:31]

PPN [13:31]

PPN[13:31]

PPN [13:31]

PPN [13:31] VPN [19:31] V

Direct mapped

相等

&& V=1

Physical address[13:31] Offset

DTLB miss

DTLB Match Register

DTLB Translate Regidter

EEAR:0x6000

W R W R CI

W R W R CI

W R W R CI

W R W R CI

W R W R CI

Super User

W R W R CI

Page 40: Porting FreeRTOS   on   OpenRISC

Waveform

DTLB Miss

0x900

Interrupt ->

Dmmu Disable

0x100->0x20000100

Interrupt ->

Dmmu Disable

0x100->0x20000100

Page 41: Porting FreeRTOS   on   OpenRISC

FreeRTOSConfig.h

Set Total Stack、SYSCLK……

Page 42: Porting FreeRTOS   on   OpenRISC

• Set Uart Base Address、System CLK……

• Cache size set……

Board.h

Page 43: Porting FreeRTOS   on   OpenRISC

Modify OpenRISC memory architecture

CPU

D-MMU

Data ram

Wishbone bus

Redirector

D-Cache SPM

Page miss

Bookkeeping

circuit

Interrupt

Page 44: Porting FreeRTOS   on   OpenRISC

PIC (Programmable Interrupt Controller)

Page miss

Bookkeeping

circuit

or1200_cpu.v external_interrupt.v

or1200_pic.v

spr_cs

spr_we

spr_addr

spr_dat_i

intr

spr_dat_o

clk

rst

pic_int[31:0]

Page 45: Porting FreeRTOS   on   OpenRISC

SPM data moving interrupt handler

Free SPM

space?

Interrupt

Select a victim page and

move it to Data ram

Move the page into SPM

No

Yes

Update D-TLB

Translate Regidter

Update Page table

Page 46: Porting FreeRTOS   on   OpenRISC

• Motivation

• OpenRISC

• Porting FreeRTOS on OpenRISC

• Experiments

Outline

Page 47: Porting FreeRTOS   on   OpenRISC

Verify on FPGA Board

Page 48: Porting FreeRTOS   on   OpenRISC

Verify on FPGA Board

VeriComm

Dump Counter

Page 49: Porting FreeRTOS   on   OpenRISC

學習移植OS與底層硬體的整合

善加運用身邊工具Debug

更加了解CPU之運作

Summary

Page 50: Porting FreeRTOS   on   OpenRISC

Thank You for Listening

Contact us.

E-mail : [email protected]