rtos

24
BK TP.HCM 2010 dce Một số RTOS Free RTOS RTX

Upload: ngat-sky

Post on 26-Oct-2014

78 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: RTOS

BKTP.HCM

2010dce

Một số RTOS

Free RTOS

RTX

Page 2: RTOS

BKTP.HCM

2010dce

Free RTOS

http://www.freertos.org/

Page 3: RTOS

2010dce

Tính năng

• Real-time kernel cho các hệ thống nhúng nhỏ– Preemtive, cooperative,hybrid

• Hỗ trợ cho 23 kiến trúc– Altera Nios II– ARM7, ARM9, Cortex M3– AVR, PIC, 8051– SH, H8S, PowerPC, x86

• Kích thước code (đã biên dịch) 4KB – 9KB• Ngôn ngữ C• Object hỗ trợ: task, queues, semaphore, mutex

©2010, Phan Dinh Khoi 3Embedded system

Page 4: RTOS

2010dce

LicenseIs it free? Yes

Can I use it in a commercial application? Yes

Is it royalty free? YesDo I have to open source my application code that makes use of the FreeRTOS services?

No, as long as the code provides functionality that is distinct from that

provided by FreeRTOSDo I have to open source my changes to the kernel?

Yes

Do I have to document that my product uses FreeRTOS?

Yes a WEB link to the FreeRTOS.org site is sufficient

Do I have to offer to provide the FreeRTOS code to users of my application?

Yes

Can I receive professional technical support on a commercial basis?

No, FreeRTOS is supported by an online community

Is a warranty provided? No

Is legal protection provided? No

©2010, Phan Dinh Khoi 4Embedded system

Page 5: RTOS

2010dce

©2008, Dr. Dinh Duc Anh Vu 5Data Communication and Computer Networks

Task• Độ ưu tiên:

– 0 – giá trị max do người dùng config

– Giá trị nhỏ = độ ưu tiên thấp

• Idle task– Độ ưu tiên 0– Dọn dẹp bộ nhớ đã cấp phát

cho các task– Cho phép người dùng hiện

thực một hàm để gọi khi task chạy (idle hook)

Page 6: RTOS

2010dce

Co-routine • Co-routine

– Dùng chung stack– Scheduling: preemtive so với các

co-routine nhưng độ ưu tiên thấp hơn task nếu sử dụng chung

– Chỉ giao tiếp với các co-routine– Hiện thực bằng macro

• Độ ưu tiên: – 0 – giá trị max do người dùng

config– Giá trị nhỏ = độ ưu tiên thấp– Luôn thấp hơn task

• Không tự động scheduling– Gọi vCoRoutineSchedule()

©2010, Phan Dinh Khoi 6Embedded system

Page 7: RTOS

2010dce

Queue

• FIFO• Giao tiếp giữa các task• Giao tiếp giữa task và ISR• Item có kích thước cố định

©2010, Phan Dinh Khoi 7Embedded system

Page 8: RTOS

2010dce

Queue API• xQueueCreate • xQueueSend • xQueueSendToBack • xQueueSendToFront • xQueueReceive • xQueuePeek • xQueueSendFromISR • xQueueSendToBackFromISR • xQueueSendToFrontFromISR • xQueueReceiveFromISR • vQueueAddToRegistry • vQueueUnregisterQueue

©2010, Phan Dinh Khoi 8Embedded system

Page 9: RTOS

2010dce

Binary semaphore

• Đồng bộ giữa các task• Đồng bộ giữa interrupt và task

©2010, Phan Dinh Khoi 9Embedded system

Page 10: RTOS

2010dce

Counting semaphore

• Đếm event• Quản lý resource

©2010, Phan Dinh Khoi 10Embedded system

Page 11: RTOS

2010dce

Mutex

• Chung API với semaphore• Priority inheritance• Recursive

©2010, Phan Dinh Khoi 11Embedded system

Page 12: RTOS

2010dce

Semaphore API

• vSemaphoreCreateBinary • vSemaphoreCreateCounting • xSemaphoreCreateMutex • xSemaphoreCreateRecursiveMutex • xSemaphoreTake • xSemaphoreTakeRecursive • xSemaphoreGive • xSemaphoreGiveRecursive • xSemaphoreGiveFromISR

©2010, Phan Dinh Khoi 12Embedded system

Page 13: RTOS

BKTP.HCM

2010dce

Keil RL-RTX

http://www.keil.com

Page 14: RTOS

2010dce

Tính năng

• RTOS cho ARM7, ARM9, Cortex-M3• Ngôn ngữ C, Realview compiler• Preemtive scheduling• Object hỗ trợ: event flag, semaphore, mutex

(priority inheritance), mailbox

©2010, Phan Dinh Khoi 14Embedded system

Page 15: RTOS

2010dce

Thông số kỹ thuậtDescription ARM7™/ARM9™ Cortex™-M

Defined Tasks Unlimited Unlimited

Active Tasks 250 max 250 max

Mailboxes Unlimited Unlimited

Semaphores Unlimited Unlimited

Mutexes Unlimited Unlimited

Signals / Events 16 per task 16 per task

User Timers Unlimited Unlimited

Code Space <4.2 Kbytes <4.0 Kbytes

RAM Space for Kernel300 bytes +80 bytes User Stack

300 bytes +128 bytes Main Stack

RAM Space for a Task TaskStackSize + 52 bytes TaskStackSize + 52 bytes

RAM Space for a Mailbox MaxMessages * 4 + 16 bytes MaxMessages * 4 + 16 bytes

RAM Space for a Semaphore 8 bytes 8 bytes

RAM Space for a Mutex 12 bytes 12 bytes

RAM Space for a User Timer 8 bytes 8 bytes

Hardware Requirements One on-chip timer SysTick timer

User task priorities 1 - 254 1 - 254

Context switch time <7 µsec @ 60 MHz <4 µsec @ 72 MHz

Interrupt lockout time 3.1 µsec @ 60 MHz Not disabled by RTX

©2010, Phan Dinh Khoi 15Embedded system

Page 16: RTOS

2010dce

Task• Trạng thái

– RUNNING– READY– WAIT– INACTIVE

• Idle task– for (;;); – Idle mode: dừng thực thi chương trình cho tới khi có 1 interrupt xảy

ra– Cho phép người dùng thêm code vào

• Scheduling– Pre-emtive– Round-robin– Co-operative multitasking

• Task cùng độ ưu tiên• Không có round-robin• Task tự gọi nhau hoặc chuyển task khi vào trạng thái blocking

©2010, Phan Dinh Khoi 16Embedded system

Page 17: RTOS

2010dce

Task APIRoutine Description

os_sys_init Initializes and starts RL-RTX.

os_sys_init_prio Initializes and starts RL-RTX assigning a priority to the starting task.

os_sys_init_user Initializes and starts RL-RTX assigning a priority and custom stack to the starting task.

os_tsk_create Creates and starts a new task.

os_tsk_create_ex Creates, starts, and passes an argument pointer to a new task.

os_tsk_create_user Creates, starts, and assigns a custom stack to a new task.

os_tsk_create_user_ex Creates, starts, assigns a custom stack, and passes an argument pointer to a new task.

os_tsk_delete Stops and deletes a task.

os_tsk_delete_self Stops and deletes the currently running task.

os_tsk_pass Passes control to the next task of the same priority.

os_tsk_prio Changes a task's priority.

os_tsk_prio_self Changes the currently running task's priority.

os_tsk_self Obtains the task ID of the currently running task.

isr_tsk_get Obtains the task ID of the interrupted task.

©2010, Phan Dinh Khoi 17Embedded system

Page 18: RTOS

2010dce

Mailbox• Truyền con trỏ giữa các task hoặc giữa task và ISR• Ứng dụng tự quản lý dữ liệu• Có thể dùng để truyền dữ liệu 8 bit, 16 bit, 32 bit

thay vì con trỏ

©2010, Phan Dinh Khoi 18Embedded system

Page 19: RTOS

2010dce

Mailbox APIRoutine Description

os_mbx_check Determines the number of messages that can still be added to the mailbox.

os_mbx_declare Creates a mailbox object.

os_mbx_init Initializes a mailbox so that it can be used.

os_mbx_send Sends a message to a mailbox.

os_mbx_wait Gets the next message from a mailbox, or waits if the mailbox is empty.

isr_mbx_check Determines the number of messages that can still be added to the mailbox.

isr_mbx_receive Gets the next message from a mailbox.

isr_mbx_send Sends a message to a mailbox.

©2010, Phan Dinh Khoi 19Embedded system

Page 20: RTOS

2010dce

Mutex API

©2010, Phan Dinh Khoi 20Embedded system

Routine Description

os_mut_init Initializes a mutex object.

os_mut_release Releases a mutex object.

os_mut_waitWaits for a mutex object to become available.

Page 21: RTOS

2010dce

Semaphore API

©2010, Phan Dinh Khoi 21Embedded system

Routine Description

os_sem_init Initializes a semaphore object.

os_sem_send Sends a signal (token) to the semaphore.

os_sem_waitWaits for a signal (token) from the semaphore.

isr_sem_send Sends a signal (token) to the semaphore.

Page 22: RTOS

2010dce

Event flag API

©2010, Phan Dinh Khoi 22Embedded system

Routine Description

os_evt_clr Clears one or more event flags of a task.

os_evt_getRetrieves the event flags that caused os_evt_wait_or to complete.

os_evt_set Sets one or more event flags of a task.

os_evt_wait_and Waits for one or more event flags to be set.

os_evt_wait_or Waits for any one event flag to be set.

isr_evt_set Sets one or more event flags of a task.

Page 23: RTOS

2010dce

Timer API

©2010, Phan Dinh Khoi 23Embedded system

Routine Description

os_tmr_createStarts a countdown timer to call the os_tmr_call function.

os_tmr_kill Aborts a user defined timer.

os_tmr_callUser customizable function that gets called when the user defined timer expires.

Page 24: RTOS

2010dce

Ngoại vi

• RL-FlashFS• RL-TCPnet• RL-CAN• USB drivers

©2010, Phan Dinh Khoi 24Embedded system