Upload
willis-poole
View
230
Download
4
Embed Size (px)
Citation preview
RTX - 51
ObjectivesObjectives
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.
SystemISRs
ApplicationISRs
Application Tasks
System Tasks
Architecture Of RTX 51Architecture Of RTX 51
Sched
uler Int.Handler
Dispatcher
Kernel
• External (XDATA) RAM: - Minimum of 450 bytes.
• Timer 0 or 1 for system clock.
Components of RTX - 51
• Task Management• Memory Management
* Memory pools • Intertask Communication
* Mail-Box• Intertask Synchronization
* Signals* Semaphores
Scheduler Scheduler
Dispatcher
Dispatcher
Task Management
* Scheduler * Scheduler
Task Classification Task Classification
Standard Tasks
Standard Tasks
Fast Tasks
Fast Tasks
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.
.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.
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.
ReadyReady SleepingSleeping
RunningRunning BlockedBlocked
Task State DiagramTask State Diagram
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.
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
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
-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.
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
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)
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
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.
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)
- 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).
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)
- 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)
-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)
- 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.
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)
* 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.
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)
- 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.
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)
* 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.
(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.
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)
- 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.
(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.
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)
(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.
(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.
(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.
(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.
End Of The Session!
Thank You!