rtx - 51 objectives resources needed architecture components of rtx-51 - task - memory pools -...

43
RTX - 51

Upload: willis-poole

Post on 14-Jan-2016

219 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

RTX - 51

Page 2: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

ObjectivesObjectives

Resources needed

Architecture

Components of RTX-51 - Task

- Memory pools- Mail box- Signals

Page 3: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

Resources NeededResources Needed

RTX - 51 requires the following 8051 systemresources:• Code memory: - Approx. 6 to 8 KB of memory.

• Internal (Data & IData) RAM: - 40 to 46 bytes for system data. - 20 to 200 bytes for stack. - Register bank 0 for standard tasks. - Register banks 1,2,3 for fast tasks.

Page 4: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

SystemISRs

ApplicationISRs

Application Tasks

System Tasks

Architecture Of RTX 51Architecture Of RTX 51

Sched

uler Int.Handler

Dispatcher

Kernel

Page 5: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

• External (XDATA) RAM: - Minimum of 450 bytes.

• Timer 0 or 1 for system clock.

Page 6: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

Components of RTX - 51

• Task Management• Memory Management

* Memory pools • Intertask Communication

* Mail-Box• Intertask Synchronization

* Signals* Semaphores

Page 7: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

Scheduler Scheduler

Dispatcher

Dispatcher

Task Management

Page 8: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

* Scheduler * Scheduler

Task Classification Task Classification

Standard Tasks

Standard Tasks

Fast Tasks

Fast Tasks

Page 9: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

Task Classes:

1) Standard tasks:- More time for task switching.- Share common stack and register bank.- Register bank 0.- Interrupted by fast tasks.- Interrupt themselves mutually.- Contains context area in external memory- Maximum of 16 standard tasks.- Priorities 0,1,2.

Page 10: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

.2) Fast tasks:

- Short responses.- Contains separate register bank and stack area.- Register banks 1,2,3- Contains highest priority(3) & can therefore interrupt standard tasks.- Cannot mutually interrupt.- Maximum of 3 fast tasks can be active in system.

Page 11: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

Scheduling Algorithms1) Cooperative(or)Round-robin:

- Process currently running must give up CPU time slices to other processes.- Application must have special code loop

that yields control to allow other application to execute.- When fails to yield, it “hogs” the CPU.- Ex: Macintosh, Win3.X

2) Preemptive:- OS schedules CPU time and an application can be preempted by OS at any time.- Ex: Win95, WinNT, Unix.

Page 12: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

ReadyReady SleepingSleeping

RunningRunning BlockedBlocked

Task State DiagramTask State Diagram

Page 13: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

Task States:

READY:- All tasks which can run are READY.One of these tasks is the RUNNING task.

RUNNING:- Task which is currently being executed by processor.- Only one task can be in this state at a time

BLOCKED:- Task waits for an event.

Page 14: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

SLEEPING:- All tasks which were not started or which have terminated themselves are in this

state.

By default preemption method is used in RTX-51

Page 15: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

Task1Task1

InitializeInitialize

Function tobe performed

Function tobe performed

System call:wait for an event

System call:wait for an event

Task2Task2

InitializeInitialize

Function tobe performed

Function tobe performed

System call:delete itselfSystem call:delete itself

StopStop

Task Layout Task Layout

Page 16: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

-Task1 has to perform certain action each time an event occurs.After completion it will wait for a new event.

- Task2 after performing one event, will delete itself. Ex:Self-test-has to be executed once at every power-up.

Page 17: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

Stack-Area for Normal task

Stack Area for Fast Task 3

Stack Area for Fast Task 2

Stack Area for Fast Task 1

Reg. bank 3 for Fast Task3

Reg. bank 2 for Fast Task 2

Reg. bank 1 for Fast Task 1

Reg.bank 0 for Normal Tasks

Normal-TaskContext

Normal-TaskContext

Normal-TaskContext

Context Switching of

Dispatcher

Page 18: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

Task Management Task Management

Services offered by task management are:

* To start and initialize system.(os_start_system)

* To declare a task.

* To create a task(os_create_task)

* To delete a task(os_delete_task)

Page 19: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

To Initialize and start the system:signed char os_start_system(unsigned char task_id)

- task_id identifies first task to be started.- During this command following steps will take place:

* disable all interrupts* clear memory space* initialize system clock hardware* creation of first user task* initialize interrupt hardware* enable interrupts* start dispatcher

Page 20: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

To declare a Task: void func(void) _task_ <task no.>

_priority_ <priority no.>

- func. is variable name for task to be declared. - Cannot return a value. - No parameter values are passed. - <task no.> ranges from 0…255.Maximum of 256 tasks can be defined. - Only 19 tasks can be active at a time. - Declare task will reside in SLEEPING state.

Page 21: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

1) Task Management1) Task Management

(a) To create a task:signed char os_create_task(unsigned char task_id)

- task_id identifies task to be started.- starts a function defined with C51 attribute _task_ as RTX-51 task.- task is placed in list of READY tasks.

(b) To delete a task:signed char os_delete_task(unsigned char task_id)

Page 22: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

- task_id identifies task to be deleted.- Only created task can be deleted.

(c ) To determine running task_id: signed char os_running_task_id(void)

- Number of the task currently being executed by the processor is returned.

- Task number corresponds to number used in task declaration(0…255).

Page 23: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

1) Memory Management 1) Memory Management

Services offered by memory management are:

* To generate memory pool(os_create_pool)

* To request memory block from pool(os_get_block)

* To return memory block to pool(os_free_block)

Page 24: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

- Dynamic memory space is desired for storing intermediate results.

- 16 memory pools- 255 memory blocks in each pool

Functions supported are:(a) Generate memory pool :signed char os_create_pool(unsigned int

block_size,void xdata *memory,unsigned int mem_size)

Page 25: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

-block size defines usable size of individual blocks.only one pool can be defined per block size.-*memory designs start address of memory area to be managed.-mem_size designs size of area.-Pools with various block sizes.-Pool is stored and managed in XDATA area.

(b) Request memory block from pool:void xdata os_get_block(unsigned int block_size)

-block size defines usable size of individual blocks.only one pool can be defined per block size.-*memory designs start address of memory area to be managed.-mem_size designs size of area.-Pools with various block sizes.-Pool is stored and managed in XDATA area.

(b) Request memory block from pool:void xdata os_get_block(unsigned int block_size)

Page 26: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

- gets memory block from memory pool referenced by block size.

- block_size is desired block size.pool with blocks of required size must exist.

(c ) Return memory block to pool:signed char os_free_block(unsigned int block_size,

void xdata *block)

- returns memory block to associated pool.- block designates returned block.

- gets memory block from memory pool referenced by block size.

- block_size is desired block size.pool with blocks of required size must exist.

(c ) Return memory block to pool:signed char os_free_block(unsigned int block_size,

void xdata *block)

- returns memory block to associated pool.- block designates returned block.

Page 27: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

3) Intertask Communication 3) Intertask Communication

Services offered by memory management are:

* To send a message(os_send_message)

* To read a message(os_wait)

Page 28: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

* Mailboxes:

-Messages can be exchanged free of conflicts between individual tasks.-Fixed number of 8 mailboxes.(0…7)-Messages can be exchanged in words (2 bytes).-Identified with a mailbox number.-Freely used by all tasks.

* Mailboxes:

-Messages can be exchanged free of conflicts between individual tasks.-Fixed number of 8 mailboxes.(0…7)-Messages can be exchanged in words (2 bytes).-Identified with a mailbox number.-Freely used by all tasks.

Page 29: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

Functions supported are:(a) Send a message:signed char os_send_message(unsigned char

mailbox,unsigned int message,unsigned char timeout)

-mailbox is identification of mailbox.-message is 2-byte value.-timeout is time limit for wait time for a full message.

(b) Read a message:signed char os_wait(unsigned char

event_selector, unsigned char timer_ticks, unsigned int xdata *message)

Functions supported are:(a) Send a message:signed char os_send_message(unsigned char

mailbox,unsigned int message,unsigned char timeout)

-mailbox is identification of mailbox.-message is 2-byte value.-timeout is time limit for wait time for a full message.

(b) Read a message:signed char os_wait(unsigned char

event_selector, unsigned char timer_ticks, unsigned int xdata *message)

Page 30: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

- event_selector = event1+event2..specifies the events which are to be waited for. Ex: K_MBX+mailbox number.- selects mail-box from which message is to be received.- timer_ticks determines number of system intervals to occur until time_out event occurs, if K_TMO was specified. ! must be 0 if no wait. ! 255 for endless waiting.

- event_selector = event1+event2..specifies the events which are to be waited for. Ex: K_MBX+mailbox number.- selects mail-box from which message is to be received.- timer_ticks determines number of system intervals to occur until time_out event occurs, if K_TMO was specified. ! must be 0 if no wait. ! 255 for endless waiting.

Page 31: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

3) Inter task synchronization3) Inter task synchronization

Services offered by memory management are:

* Signals- To send a signal(os_send_signal)

- To wait for a signal(os_wait)

- To clear a signal(os_clear_signal)* Semaphores

- Wait for a token(os_wait)

- Send a token(os_send_token)

Page 32: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

* Signals:- Used when task synchronization is required without data exchange.

Functions supported are:(a) send a signal:signed char os_send_signal(unsigned char task_id)

- task_id is where signal is to be sent.- if task is already waiting,it is made

READY.- Otherwise signal is stored in signal flag.

* Signals:- Used when task synchronization is required without data exchange.

Functions supported are:(a) send a signal:signed char os_send_signal(unsigned char task_id)

- task_id is where signal is to be sent.- if task is already waiting,it is made

READY.- Otherwise signal is stored in signal flag.

Page 33: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

(b) Wait for a signal:os_wait(K_SIG, timer_ticks, 0) - Since there is no data transfer denote message as 0.

(c ) Clear a signal:signed char os_clear_signal(unsigned char task_id)

- task_id denotes the task whose signal flag is to be cleared.

* Semaphores:- Used to control access to shared resources.- resources can be shared free of conflicts.

(b) Wait for a signal:os_wait(K_SIG, timer_ticks, 0) - Since there is no data transfer denote message as 0.

(c ) Clear a signal:signed char os_clear_signal(unsigned char task_id)

- task_id denotes the task whose signal flag is to be cleared.

* Semaphores:- Used to control access to shared resources.- resources can be shared free of conflicts.

Page 34: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

Functions supported are:(a) Wait for a token:

os_wait(K_MBX+sem.no., timer_ticks, 0)- Semaphore number ranges from 8…15.- Since no data transfer, message is 0.- Task requesting a resource controlled by

semaphore can obtain a token from this. this semaphore.- If token is available, task will continue its execution.

(b) Send a token:signed char os_send_token(unsigned char semaphore)

Functions supported are:(a) Wait for a token:

os_wait(K_MBX+sem.no., timer_ticks, 0)- Semaphore number ranges from 8…15.- Since no data transfer, message is 0.- Task requesting a resource controlled by

semaphore can obtain a token from this. this semaphore.- If token is available, task will continue its execution.

(b) Send a token:signed char os_send_token(unsigned char semaphore)

Page 35: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

- semaphore is the number of desired semaphore.- After completing its operation, a task will return related token to semaphore.

System clock Management:

(a) To set system time interval:signed char os_set_slice(unsigned int timeslice)

- timeslice defines time interval in number of processor cycles.Permissible values are 1000…40000.- default time interval is 20000.

- semaphore is the number of desired semaphore.- After completing its operation, a task will return related token to semaphore.

System clock Management:

(a) To set system time interval:signed char os_set_slice(unsigned int timeslice)

- timeslice defines time interval in number of processor cycles.Permissible values are 1000…40000.- default time interval is 20000.

Page 36: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

(b) To wait for time-out:os_wait( K_TMO, timer-ticks, 0)- K_TMO is event selector.- System will wait for time_out.If ticks is 0, then no wait for time_out. If 255, then endless waiting.

(b) To wait for time-out:os_wait( K_TMO, timer-ticks, 0)- K_TMO is event selector.- System will wait for time_out.If ticks is 0, then no wait for time_out. If 255, then endless waiting.

Page 37: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

Interrupt Management Interrupt Management

Services offered by memory management are:

* To assign an interrupt to calling task(os_attach_interrupt)* To detach interrupt(os_detach_interrupt)* To enable interrupt(os_enable_isr)* To disable interrupt(os_disable_isr)

Page 38: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

(a) To attach interrupt:signed char os_attach_interrupt(unsigned

char interrupt)

- interrupt designates vector number of interrupt source.(values are 0….31) - Assigns an interrupt source to calling task. - each interrupt source cannot be assigned to more than one task. - several interrupt source can be assigned to one task.

(a) To attach interrupt:signed char os_attach_interrupt(unsigned

char interrupt)

- interrupt designates vector number of interrupt source.(values are 0….31) - Assigns an interrupt source to calling task. - each interrupt source cannot be assigned to more than one task. - several interrupt source can be assigned to one task.

Page 39: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

(b) To detach interrupt:signed char os_detach_interrupt(unsigned

char interrupt)

- interrupt designates vector number of interrupt source.(values are 0….31) - Cancels the assignment of interrupt source to calling task.

(b) To detach interrupt:signed char os_detach_interrupt(unsigned

char interrupt)

- interrupt designates vector number of interrupt source.(values are 0….31) - Cancels the assignment of interrupt source to calling task.

Page 40: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

(c) To enable interrupt source:signed char os_enable_isr(unsigned

char interrupt)

- interrupt designates vector number of interrupt source assigned to.(values are 0….31) - Enables an interrupt source which is assigned to interrupt function.

Page 41: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

(d) To disable interrupt source:signed char os_disable_isr(unsigned

char interrupt)

- interrupt designates vector number of interrupt source assigned to.(values are 0….31) - Disables an interrupt source which is assigned to interrupt function.

Page 42: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

End Of The Session!

Page 43: RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals

Thank You!