philips sysol me training session - read.pudn.comread.pudn.com/downloads8/ebook/24805/sysol...
TRANSCRIPT
Philips Semiconductors, Greater China Communications Applications Laboratory 2
RTK
Agenda:• Introduction of RTK-E• RTK-E Mechanism and Service• Example: Add a New Process • Q&A
Philips Semiconductors, Greater China Communications Applications Laboratory 3
RTK
Agenda:• Introduction of RTK-E• RTK-E Mechanism and Service• Example: Add a New Process • Q&A
Philips Semiconductors, Greater China Communications Applications Laboratory 4
Introduction of RTK-E
This part covers:T• RTK-E Overview• Purpose of Using RTK-E• Terminology Used In RTK-E
Philips Semiconductors, Greater China Communications Applications Laboratory 5
RTK-E overview
• RTK-E : Real Time Kernel a real time operation system
• Used in 3 generations of PHILIPS GSM products
• Offer multi-tasking system with priority based pre-emptive scheduling
Philips Semiconductors, Greater China Communications Applications Laboratory 6
Purpose of using RTK-E• Be able to divide the "total job" of the embedded
software into easily managed tasks.• Tasks can be developed independently of each
other (to a certain extent) and rely on the operating system to bring them together. – The RTK-E provides task scheduling– The RTK-E provides system services
• Optimized for key driving factors.– Low size (RAM, ROM).– Low power consumption.
Philips Semiconductors, Greater China Communications Applications Laboratory 7
Purpose of using RTK-E• Fits for the special requirements of a GSM handheld.
– Two-level concurrent activities: tasks and processes.– Finite state machine layer for process design.– Special interfaces for sleep mode.– Timers with different precisions.– Pool oriented memory management.
• Easy to porting.– 95% of the RTK is written in high level language (C
language).– 5% are coded in low level language (CPU target
assembler) especially for the task context switching.
Philips Semiconductors, Greater China Communications Applications Laboratory 8
Terminology used in RTK-E• RTK-E
– Philips Real Time Kernel.• CPU
– Processor Control Unit.• Task
– RTK-E asynchronous entity which can take the CPU.• Scheduler
– The scheduler elects the ready task having the highest priority and gives to it the CPU. The processor context is saved in the current task descriptor and the processor context of the elected task is restored so that the execution can continue on.
Philips Semiconductors, Greater China Communications Applications Laboratory 9
Terminology used in RTK-E• Object
– Data structure.• Message
– A part of a memory used for data exchanges between tasks.
• Timer– Object used to signal a task that a certain amount of
time has expired.• Semaphore
– Object used for inter-task synchronization or for concurrent access to a unique resource.
• Event– Inter-task signal.
Philips Semiconductors, Greater China Communications Applications Laboratory 10
Terminology used in RTK-E
• Mailbox– Object consisting of a queue of messages and timers.
Each task has its own mailbox.• Envelope
– Structure allowing to link objects in queues.• Cluster
– Amount of memory used for static memory allocation.• Memory block
– Amount of memory provided by the dynamic memory allocation.
Philips Semiconductors, Greater China Communications Applications Laboratory 11
RTK
Agenda:• Introduction of RTK-E• RTK-E Mechanism and Service• Example: Add a New Process • Q&A
Philips Semiconductors, Greater China Communications Applications Laboratory 12
RTK-E Mechanism and Service
This part covers:T• RTK-E Global Layers Architecture• KERNEL Layer• PROCESS Runner Layer• Exceptions• Code Generator• RTK initialization
Philips Semiconductors, Greater China Communications Applications Laboratory 13
RTK-E Global Layers ArchitectureRTK-E GLOBAL LAYERS
KERNEL LAYER: MANAGE APPLICATION TASKS
PROCESS RUNNER LAYER: MANAGE PROCESS
Philips Semiconductors, Greater China Communications Applications Laboratory 14
KERNEL LAYERThis part covers:T• PREEMPTION Mechanism• TASK Management• CRITICAL REGION Management• EVENT Management• MAILBOX Management• SEMPHORE Management• TIMER Management• MEMORY Management• QUEUE Management• INTERRUPT Management
Philips Semiconductors, Greater China Communications Applications Laboratory 15
PREEMPTION Mechanism
Philips Semiconductors, Greater China Communications Applications Laboratory 16
TASK Management
This part covers:T• Description of a TASK• Schedule of TASKs• Primatives for TASK Management• States Transition
Philips Semiconductors, Greater China Communications Applications Laboratory 17
Description of a TASK• Identity
– Exclusive Identify the Task• States
– Tasks have different states– NON, STOPPED, STOPPED & SUSPENDED REDAY,
SUSPENDED, WAITING, WAIT & SUSPENDED – Change by execution of Primitive.
• Priority– Scheduling relies on Task priority. The scheduler selects the task
with the highest priority value– value from 0 to 255, but only the background task can equal to– all tasks must have different priorities, otherwise exception will
be called.
Philips Semiconductors, Greater China Communications Applications Laboratory 18
Description of a TASK• Identity
– Stack, code segment, data segment and register– Whenever the kernel (scheduler) selects a new task to be run, it
has to perform a context switch, i.e, to change the current context to the next task’s context
Philips Semiconductors, Greater China Communications Applications Laboratory 19
Schedule of TASKs
Low Priority Task
High Priority TaskISR
ISR makes the highpriority task ready Time
Philips Semiconductors, Greater China Communications Applications Laboratory 20
PRIMATIVES for TASK Management• MC_RTK_CURRENT_TASK
– Returns current task number.• MC_RTK_INIT_TASK
– Initialize a task context(give a priority, task number, start address, stack)
• MC_RTK_START_TASK– Set a task in ready state
• MC_RTK_SUSPEND_TASK– Suspend a task by putting it in suspend state
• MC_RTK_RESUME_TASK– Resumes the task by reseting the suspended state
• MC_RTK_CURRENT_TASK– Return current task number
Philips Semiconductors, Greater China Communications Applications Laboratory 21
States Transition
This presentation covers:T• Introduction of RTK-E• RTK-E Mechanism and Service• Example of add a process
X:MC_RTK_WAIT_EV_SYS_MSGMC_RTK_RECEIVE MC_RTK_WAIT_EVENTSMC_RTK_SEM_CONSUME
Y:MC_RTK_SET_EVENTMC_RTK_TIMER_SENDMC_RTK_SENDMC_RTK_SEM_PRODUCE
Task Transition State Diagram
Philips Semiconductors, Greater China Communications Applications Laboratory 22
CRITICAL REGION Management
• Offers the possibility to enable or disable the task scheduler.
• When the task scheduler is blocked, it means that none operation which places the task in wait state can be run before the task scheduler is enabled.
Philips Semiconductors, Greater China Communications Applications Laboratory 23
CRITICAL REGION Management
Critical Region Management Primitives• MC_RTK_ENTER_REGION : RtkEnterRegion()
– Enters critical section, where task scheduling is disabled.• MC_RTK_LEAVE_REGION : RtkLeaveRegion()
– Leaves a critical section, enables task scheduling
Philips Semiconductors, Greater China Communications Applications Laboratory 24
EVENT Management• Event flags are used by a task to synchronize with the
occurrence of multiple events• Fast inter-task signalling can be performed with user
events (without data change). • There are 16 system event flags and 16 user events
available for each task.
• Only the first four listed process of each task may use the events management system.
Philips Semiconductors, Greater China Communications Applications Laboratory 25
EVENT Management• Receiving process is expected to set a mask to watch for
events in its own four bits.USER EVENT DIVISION DIAGRAM
Philips Semiconductors, Greater China Communications Applications Laboratory 26
EVENT Management
EVENTS MATCH DIAGRAM
Philips Semiconductors, Greater China Communications Applications Laboratory 27
EVENT Management
USER EVENTS PRIMITIVEST• MC_RTK_WAIT_EVENTS : RtkWaitEvents(EventList)
– This primitive checks if at least one event among the waited events had occurred. In this case, this primitive returns to thecalling task with the occurred events. Otherwise the calling task is pre-empted, its state is set to wait event state, and the scheduler is activated.
• MC_RTK_SET_EVENT :RtkSetEvent(TaskID,BitNumber)– Signals a user event to a task. Events are not queued in order to
implement fast inter-task communication. This call will set the corresponding event flag and trigger the scheduler.
Philips Semiconductors, Greater China Communications Applications Laboratory 28
EVENT Management
• MC_RTK_CLEAR_EVENTS:RtkClearEvent(EventList)– This primitive clears all events of the current task
• MC_RTK_TEST_WAIT_EVENTS:RtkTestWaitEvents(EventList)– Returns the event flags which are being waited for
Philips Semiconductors, Greater China Communications Applications Laboratory 29
MAILBOX Management• RTK system is a message oriented system, so it consist
sending and receiving messages from mailbox • Inter-task communication can be performed through
mailboxes• Each task has its own mailbox• A task wishing to send a message or a timer message to
another task, places it in the mailbox of the receiving task.
• A mailbox has two FIFO ordered queues:1. Memorized by receiving task (Normal Queue)2. Not claimed by receiving task (Memorized Queue)
Philips Semiconductors, Greater China Communications Applications Laboratory 30
MAILBOX ManagementMAILBOX STRUCTURE
Timer ObjectMessage Object
Philips Semiconductors, Greater China Communications Applications Laboratory 31
MAILBOX Management
• Object transferred through mailbox– Messages– Timers
• RTK Message Structure
Length TX ID RX ID Op Type Body of Message
Philips Semiconductors, Greater China Communications Applications Laboratory 32
MAILBOX Management
MAILBOX QUEUES
Memorized Queue
Normal Queue
Message Object
Timer Object
Philips Semiconductors, Greater China Communications Applications Laboratory 35
MAILBOX ManagementMailbox Management Primitives :T• MC_RTK_INIT_MAILBOX: RtkInitMailBox(Mailbox)
– Initialise a task’s mailbox.• MC_RTK_SEND: RtkSend(Mailbox, MessageToSend)
– Sends a message to the mailbox of receiving task. And the message is linked at the endend of the message queue
• MC_RTK_SEND_PRIO:RtkSendWithPrio(Mailbox, MessageToSend)– Sends a message to the mailbox of receiving task. And the
message is linked at the top top of the message queue.• MC_RTK_RECEIVE:
RtkReceive(Mailbox, ReceivedObjectAddr)– Receives a message or a timer message from a mailbox. If at least
one message is available in the task mailbox queue, then the first message is dequeued and consumed, else the task is pre-empted.
Philips Semiconductors, Greater China Communications Applications Laboratory 36
MAILBOX Management• MC_RTK_TEST_RECEIVE:
RtkTestReceive(Mailbox, ReceivedObjectAddr)– If a message is available in task’s mailbox, it will be de-queued,
otherwise RTK_NO_MESSAGE will be returned.• MC_RTK_NUMBER_MSG_IN_MAILBOX:
RtkNumberMsgInMailBox(Mailbox, RTK_ALL_QUEUE_MAILBOX)– Returns the number of messages in a mailbox.
• MC_RTK_SAVE_MSG_QUEUE:RtkSaveMsgQueue(Msg, Type)– Queue the object in the memorized queue.
• MC_RTK_RESTORE_MSG_QUEUE:RtkRestoreMsgQueue()– Transfert the content of the memorized queue in normal queue
(task object queue)
Philips Semiconductors, Greater China Communications Applications Laboratory 37
SEMAPHORE ManagementWhat is a SEMAPHORE?
Ensure that each task has exclusive access to theshared resources to avoid contention and data corruption.
TASK 1
TASK 2
PRINTERSEMAPHORE
Acquire Semaphore
Acquire Semaphore
"I am task #2!"
"I am task #1!"
KEY:SEMAPHORE
Philips Semiconductors, Greater China Communications Applications Laboratory 38
SEMAPHORE ManagementTypes of Semaphore
• Binary Semaphore: 0 or 1• Counting Semaphore:
Current value =0
Max value = 1
Last Pointer
First Pointer
Curent value = 1
Max value = 10
Last Pointer
First Pointer
Binary Semaphore Counting Semaphore0 to 10
0 or 1
Philips Semiconductors, Greater China Communications Applications Laboratory 39
SEMAPHORE ManagementSemaphore Architecture
Current Value = -2
Max Value = 1
Last Pointer
First Pointer
Pointer to the task descriptor
NULL
Pointer to the task descriptor
Linked list of tasks waiting for semaphore
Resource counter
Task queue
Philips Semiconductors, Greater China Communications Applications Laboratory 40
SEMAPHORE ManagementSEMAPHORE Management Primitive:• MC_RTK_INIT_SEM:
RtkInitSem(SemNo, InitValue, MaxValue)– Initialise the initial and max value of semaphore unit
• MC_RTK_SEM_CONSUME:RtkSemConsume(SemNo)– This function is called when a task requires the use of
a semaphore protected resource, it decrements the semaphore counter by one and uses the protected semaphore resource. If the semaphore counter is less zero, it means that the resource is not available, then the calling task will be queued to that resource queue.
Philips Semiconductors, Greater China Communications Applications Laboratory 41
SEMAPHORE Management
• MC_RTK_SEM_PRODUCE:RtkSemProduce(SemNo)– Release a semaphore protected resource and increments the
semaphore counter by one.• MC_RTK_SEM_TEST_CONSUME:
RtkSemTestConsume(SemNo)– Verifies if the semaphore is available. If yes it consumes it,
otherwise returns to the task with the status.
Philips Semiconductors, Greater China Communications Applications Laboratory 42
TIMER Management
• The RTK-E offers a timer management allowing a task to be pending on a mailbox while the timers are running. A time unit is decremented and when its value reaches zero, the timer object is sent to the task.
• Timer Mechanism is showed as following figure:
Philips Semiconductors, Greater China Communications Applications Laboratory 43
TIMER Management
Application Task
Task Mailbox
Timer HandlerDecrement
timers and send expired timers to
Tasks via its mailbox
Timer Interrupt
Timer Expire
Stop Timer
Clear Timer
Start Timer
Read in Mailbox
List of free timers
List of active timers
Philips Semiconductors, Greater China Communications Applications Laboratory 44
TIMER Management• MC_RTK_START_TIMER:
RtkStartTimer(TimerId, Mailbox, Count, 0, 0)– Starts an ordinary one shot timer.
• MC_RTK_START_AUTO_RELOAD_TIMER:RtkStartTimer(TimerId, Mailbox, Count, 1, 0)Starts an auto-reloaded timer.
• MC_RTK_START_TIMER_WP:RtkStartTimer(TimerId, Mailbox, Count, 0, Precision)– Starts a one shot timer with a tolerance.
• MC_RTK_START_AR_TIMER_WP:RtkStartTimer(TimerId, Mailbox, Count, 1, Precision)– Starts a auto reload timer with tolerance.
• MC_RTK_TIMER_EXTRACT_VALUE:RtkTimerExtractValue(TimerId)– Returns the remaining value of a timer.
Philips Semiconductors, Greater China Communications Applications Laboratory 45
TIMER Management• MC_RTK_GET_HEAD_TIMER:
RtkGetHeadTimer– If the used timer queue is not empty, the remaining value of the
first used timer will be returned.• MC_RTK_UPDATE_HEAD_TIMER:
RtkUpdateHeadTimer(Value)– If the used timer queue is not empty, this primitive will update the
counter value of the first used timer.• MC_RTK_STOP_TIMER:
RtkStopTimer(TimerId)– Stops a timer.
• MC_RTK_DETERMINE_SLEEP:RtkDetermineSleep()– Returns the maximum sleep time duration in number of ticks by
checking all the running timers and their tolerances.
Philips Semiconductors, Greater China Communications Applications Laboratory 46
TIMER Management• MC_RTK_UPDATE_TIMER_AFTER_SLEEP:
RtkUpdateTimerAfterSleep(SleepDuration)– This primitive updates all timers after a sleep mode. The sleep
time duration is given as parameter.• MC_RTK_CLEAR_TIMER:
Rtk8_ClearTimer (TimerId)– Cancels a pending timer from the current tasks timer queue.
NoteThe timer tick period is system configuration dependent. (1 Tick = 2 GSM frames: 4.615x2 = 9.23ms).
Philips Semiconductors, Greater China Communications Applications Laboratory 47
MEMORY Management• Provides memory allocation and memory
release system • Uses pools and clusters within pools in order to
optimise the overall RAM requirements.• Prevent memory from becoming fragment, so we
don’t need a garbage collection system.• The memory pools & clusters for RTK-E system
are set in Kernel initialisation.• You may have any number of memory pools, (up to the
limit of memory) and within each pool you may dimension the clusters. All clusters within a pool must be the same size.
Philips Semiconductors, Greater China Communications Applications Laboratory 48
MEMORY Management
Example of memory configuration
32 32 32
256
Pool 1 of 24 clusters X8 bit
Pool 2 of 6 clusters X32 bit32 32 32
8 8 8 8 8 8 8 8 8 8 8 88 8 8 8 8 8 8 8 8 8 8 8
Pool 3 of 1clusters X256 bit
Philips Semiconductors, Greater China Communications Applications Laboratory 49
MEMORY Management
STATIC CLUSTER FORMAT
Link Pointer
Pool Number
Link Counter
Debug Info
Cluster Header Memory Block
Philips Semiconductors, Greater China Communications Applications Laboratory 50
MEMORY ManagementDYNAMIC CLUSTER FORMAT
Philips Semiconductors, Greater China Communications Applications Laboratory 51
MEMORY Management
POOL FORMAT
Link Pointer
Cluster Header
Mem Block
Link Pointer
Cluster Header
Mem Block
Link Pointer
Cluster Header
Mem Block
Pointer to the first free cluster
NULL
Philips Semiconductors, Greater China Communications Applications Laboratory 52
MEMORY ManagementSTATIC POOL ORGANIZATION
STATIC POOL
Philips Semiconductors, Greater China Communications Applications Laboratory 53
MEMORY ManagementDYNAMIC POOL ORGANIZATION
Philips Semiconductors, Greater China Communications Applications Laboratory 54
MEMORY ManagementStatic Memory Management Primitives• MC_RTK_GET_MEMORY
– Looks for a free cluster of memory large enough to accommodate the requested size, and returns a pointer to that memory location.
• MC_RTK_GET_POOL_MEMORY– Looks for a free cluster in the pool passed in the parameter and
returns a pointer to the first free cluster. If no free cluster is found then an exception is raised.
• MC_RTK_GET_POOL_MEMORY_NO_TRAP– Looks for a free cluster in the pool passed in the parameter and
returns a pointer to the first free cluster. If no free cluster is found then a NULL pointer is returned.
Philips Semiconductors, Greater China Communications Applications Laboratory 55
MEMORY ManagementStatic Memory Management Primitives• MC_RTK_GET_DYNMEMORY
– Extracts from the default pool a memory block with a length corresponding to requested size. If no block available it enter an exception.
• MC_RTK_GET_DYNMEORY_NO_TRAY– Extracts from the default pool a memory block with a length
corresponding to requested size. If no block available return a NULL address.
• MC_RTK_GET_DYNPOOL_MEMORY– Extracts from the pool passed in parameter a memory block with
a length corresponding to requested size.If no block avaiable it enter an exception.
Philips Semiconductors, Greater China Communications Applications Laboratory 56
MEMORY Management• MC_RTK_GET_DYNPOOL_MEORY_NO_TRAY
– Extracts from the pool passed in parameter a memory block with a length corresponding to requested size. If no block available return a NULL address.
• MC_RTK_REDUCE_BLOCK_SIZE– Releases the end of a memory block which is not
used.• MC_RTK_AVAILABLE_DYN_POOL_SIZE
– Returns the size avaiable in the pool.• MC_RTK_INITIAL_DYN_POOL_SIZE
– Returns the initial size of the pool.
Philips Semiconductors, Greater China Communications Applications Laboratory 57
MEMORY Management• Primitives Common To Static And Dynamic Memory
Management:• MC_RTK_FREE_MEMORY:
– Releases a memory block.• MC_RTK_IS_MRMORY:
– Verify if the pointer points to a memory block located in RTK-E pools.
• MC_RTK_LINK_MRMORY:– Links a memory block.
• MC_RTK_GET_POOL_IDENTIFIER:– Returns the pool number in which the memory block was taken.
Philips Semiconductors, Greater China Communications Applications Laboratory 58
MEMORY ManagementLINK COUNTERThe link counter is:• Set to 1 from a Get Memory primitive,• Incremented from MC_RTK_LINK_MRMORY primitive• Decremented from MC_RTK_FREE_MRMORY primitive
The memory block is only released if it reach 0 after decrementation.
This mechanism can be used to:• Send a message to several destinations.• Preserve a message from automatic release of the
process runner.
Philips Semiconductors, Greater China Communications Applications Laboratory 59
QUEUE Management
• QUEUE is a method of communication between two tasks.T
• There are basically two queue types:– Queues using envelopes (where an element can be
queued in more than one queue).– Queues which do not use envelopes.
TASK2
TASK1 TASK3
Queue
post get
message
Philips Semiconductors, Greater China Communications Applications Laboratory 60
QUEUE Management
Pointer to the last queue object
Pointer to the first queue object
Object ObjectNULLObject
QUEUES without envelops structure
Philips Semiconductors, Greater China Communications Applications Laboratory 61
QUEUE ManagementQUEUE with envelope structure
Pointer to the last queue object
Pointer to the first queue object
Pointer to object
Pointer to object
NULLPointer to
object
objectobjectobject
Philips Semiconductors, Greater China Communications Applications Laboratory 62
QUEUE Management• MC_RTK_INSERT_QUEUE_ENV
– Inserts an element behind the one passed in parameter.• MC_RTK_DELETE_QUEUE_ENV
– Dequeues the referenced element from the queue.• MC_RTK_QUEUE_ENV
– Adds the element passed in the parameter to the tail end of the queue.
• MC_RTK_QUEUE_FIRST_ENV– Inserts the element passed in the parameter at the head of the
queue.
Philips Semiconductors, Greater China Communications Applications Laboratory 63
QUEUE Management
• MC_RTK_DEQUEUE_ENV– Dequeues the first element of the queue.
• MC_RTK_INIT_QUEUE_ENV– Initialises the queue as an empty queue.
• MC_RTK_TOP_QUEUE_ENV– Returns a pointer to the first element of the queue without it
being dequeued.• MC_RTK_NEXT_QUEUE_ENV
– Returns a pointer to the second element of the queue.• MC_RTK_OBJ_QUEUE_ENV
– Returns an address of the object that is pointed to by the envelope passed in parameter.
Philips Semiconductors, Greater China Communications Applications Laboratory 64
QUEUE Management• MC_RTK_INSERT_QUEUE
– Inserts an element behind the one passed in parameter.• MC_RTK_DELETE_QUEUE
– Dequeues the referenced element from the queue.• MC_RTK_QUEUE
– Adds the element passed in the parameter to the tail end of the queue.
• MC_RTK_QUEUE_FIRST– Inserts the element passed in parameter at the front of the queue.
• MC_RTK_DEQUEUE– Dequeues the first element of the queue.
• MC_RTK_INIT_QUEUE– Initialises the queue as an empty queue.
Philips Semiconductors, Greater China Communications Applications Laboratory 65
QUEUE Management
• MC_RTK_TOP_QUEUE– Returns a pointer to the first element of the queue without it
being dequeued.• MC_RTK_NEXT_QUEUE
– Returns a pointer to the second element of the queue.• MC_RTK_OBJ_QUEUE
– Returns a pointer to an object which is pointed to by the queue address.
Philips Semiconductors, Greater China Communications Applications Laboratory 66
INTERRUPT Management
Philips Semiconductors, Greater China Communications Applications Laboratory 67
Process Management
This part covers:T• Services • Data Structure used• Implementation• FSM Mechanism• Example
Philips Semiconductors, Greater China Communications Applications Laboratory 68
Process ManagementPROCESS MANAGEMENT ARCHITECTURE
Philips Semiconductors, Greater China Communications Applications Laboratory 69
Process Management• A task may be divided into processes.• Each FSM process can manage up to 256 instances.• A process may be either a C function or a FSM (finite
state machine).• The Process Runner takes care of the running of the
processes. The process runner makes processes to wait for inputs, and when an input occurs, executes the operation associated with the process which is concerned by the input.
• The process runner release the received objects after usage by:
- Clear received events- Release a received message memory block- Clear a received timer
Philips Semiconductors, Greater China Communications Applications Laboratory 70
Process ManagementData Structure for Process Management
Instance
Process Name
Transmitter and Receiver Structure
Operation Type Structure
U8U16Operation
U8
Message StructureTimer ID Structure
Length of Data
Transmitter
Receiver
Operation Type
User Data User Defined
U16U16ReceiverU16
U16U16Operation
U16
Philips Semiconductors, Greater China Communications Applications Laboratory 71
Process ManagementEVENT STRUCTURE
Only first 4 processes
Philips Semiconductors, Greater China Communications Applications Laboratory 72
Process Management• Process Runner is a system for dividing a “TASK” into a
system of processes• Process Runner looks for inputs in its mailbox and
depending on the addressed process of these inputs run the process associated with that input
• Process rely on the one mailbox of the parent task• The system is described by:
– Task Descriptor Table– Process Descriptor Table– FSM Instance Context– Operation Descriptor Table
Philips Semiconductors, Greater China Communications Applications Laboratory 73
Process Management
Task descriptorTask IdentityMailbox IDNumber of Process in TaskPointer to Process Descriptor Table
Process descriptorProcess type (function or FSM)Pointer to that FSMPointer to 1st FSM state
Process descriptorProcess type (function or FSM)Pointer to that FSMPointer to 1st FSM state
Process descriptorProcess type (function or FSM)Pointer to that FSM (function)Pointer to 1st FSM state
StateOperation Type Function Called Next State
FSM instance contextInstance ID
Active statePointer to next instance
Previous state
Pointer to user data struct
Implementation for Processes in Tasks
Philips Semiconductors, Greater China Communications Applications Laboratory 75
Process ManagementFSM management is based on operation descriptor tables:• Every FSM state has its own table, so a FSM has so much tables as
states and a state is the address of the descriptor table• The process runner search in the currents state table the operation
type associated to the received object IF the operation type is found in the table the assocated transition function is called.
• After execution the FSM state is set to the next state given in the table IF end of table is reached without found the operation type, a default function is called Events have an implicit operation type equal to USER_EVT
A descriptor table can also contain:• a link to an other table. (This permit to realize factorization and more
clear and concise state machines)• Commands to memorize objects which can not be treated in the
current state.
Philips Semiconductors, Greater China Communications Applications Laboratory 77
Process Management
State 1
State 2
Operation Type 1_1
Operation Type 2_2
Operation Type 2_1
Operation Type 1_2
State 2 table
Operation Type 1_1
Function 1_1 SAME
Operation Type 1_2
Function 1_2 State 2
Others Function for “others”
UNKNOWN
Operation Type 2_1
Function 2_1 State1
Operation Type 2_2
Function 2_2 SAME
Others Function for “others”
UNKNOWN
Events Transitions Next states
State 1 tableEvents Transitions Next states
Philips Semiconductors, Greater China Communications Applications Laboratory 78
Process Management
/*Generic state 1*/MC_RTK_DFSM( s_State_1 )MC_RTK_OFSM( OPER1_1, TreatementFunction1_1, SAME)MC_RTK_OFSM( OPER1_2, TreatementFunction1_2, State_2)MC_RTK_FFSM( Error, UNKNOW) /*End of table + default function*/
/*Generic state 1*/MC_RTK_DFSM( s_State_2 )MC_RTK_OFSM( OPER2_1, TreatementFunction2_1, State_1)MC_RTK_OFSM( OPER2_2, TreatementFunction2_2, SAME)MC_RTK_FFSM( Error, UNKNOW) /*End of table + default function*/
Philips Semiconductors, Greater China Communications Applications Laboratory 79
Process Management
MC_RTK_DFSM(s_State_1)MC_RTK_OFSM(OPER1, TraiteSemantic1, SAME)MC_RTK_OFSM(OPER2, TraiteSemantic2, SAME)MC_RTK_FFSM(ERROR, SAME)
MC_RTK_DFSM(s_State_11)MC_RTK_OFSM(OPER11, TraiteSemantic11, SAME)MC_RTK_OFSM(OPER12, TraiteSemantic12, s_State_12)MC_RTK_NTAB(s_State_1)
MC_RTK_DFSM(s_State_12)MC_RTK_OFSM(OPER11, TraiteSemantic11, UNKNOW)MC_RTK_OFSM(OPER2, TraiteSemantic12, SAME)MC_RTK_NTAB(s_State_1)
STATE CHARTS
EXAMPLE
Philips Semiconductors, Greater China Communications Applications Laboratory 80
Process Management
MC_RTK_DFSM(s_State_111)MC_RTK_OFSM(OPER111, TraiteSemantic111, SAME)MC_RTK_OFSM(OPER112, TraiteSemantic112, UNKNOW)MC_RTK_OFSM(OPER1, TraiteSemantic13, SAME)MC_RTK_NTAB(s_State_11)
MC_RTK_DFSM(s_State_112)MC_RTK_OFSM(OPER111, TraiteSemantic111, s_State_1)MC_RTK_OFSM(OPER112, TraiteSemantic112, SAME)MC_RTK_NTAB(s_State_1)
Philips Semiconductors, Greater China Communications Applications Laboratory 81
Process ManagementMemorization of Objects• If in a given state an object can not be used it must be
memorized until the process change state• This is possible through a memorization command
placed in descriptor table• This command point on a table which contains operation
types of objects to memorize• If a process change state the memorized messages are
restored(memorized queue is transferred at top of normal queue in tasks mailbox)
• Only Messages and Timers can be memorized (not events)
Philips Semiconductors, Greater China Communications Applications Laboratory 82
Process ManagementMC_RTK_DEVTM(MemoTable)MC_RTK_OPMEM(OPER3)MC_RTK_OPMEM(OPER4) MC_RTK_FEVTM
MC_RTK_DFSM(s_FirstState)MC_RTK_OFSM(OPER2, TraiteSemantic1, s_SecondState )MC_RTK_MFSM(MemoTable) MC_RTK_FFSM(Error, SAME)
MC_RTK_DFSM(s_SecondState)MC_RTK_OFSM(OPER3, TraiteSemantic2, s_FirstState )MC_RTK_MFSM(NULL) MC_RTK_FFSM(Error, SAME)
Philips Semiconductors, Greater China Communications Applications Laboratory 83
Process Management• Application function prototype
– for a C function: void p_Function(t_RtkObject *p_Object); for a FSM : t_OperationDescriptor *p_Function(t_RtkObject *p_Object);
– The type t_OperationDescriptor * is a pointer on a FSM table so it is the new FSM state if the new specified state in table is UNKNOW
• Descriptor of t_RtkObject structure:typedef struct st_RtkObject{u8 v_TypeOfObj; /*Type of object in the union(EVENTS, TIMER,MSG)*/u32 v_UserData; /*Set by MC_RTK_SET_PROCESS_INST_USR_DATA*/
/* Can be used as pointer on instance private data */u16 v_UserEventMask; /* User events to wait for next centrailized wait */union{
u16 v_UserEvent; /* Received user events*/t_TimerID v_TimerID; /* ID of received timer*/PACKED struct st_MsgHeader *p_MessageAddress;
}u_ReceivedObj;}t_RtkObject;
Message
Header“t_MsgHeader”
User datastructure
Philips Semiconductors, Greater China Communications Applications Laboratory 84
Process Management• MC_RTK_RUN_PROCESS
– This is a "for ever loop" which takes care of running the FSM engine which waits for inputs for processes implemented within atask. It also runs the C function associated with the input when it receives one, according to the relevant process and its state.
• MC_RTK_SEND_MSG_TO_PROCESS– Sends a message to a process.
• MC_RTK_SEND_MSG_PRIO_TO_PROCESS– Send a high priority message to a process.
• MC_RTK_SEND_FMSG_TO_PROCESS– Send a message to a process with the message header is
already filled in.
Philips Semiconductors, Greater China Communications Applications Laboratory 85
Process Management• MC_RTK_SEND_FMSG_PRIO_TO_PROCESS
– Send a high priority message to a process, with the message header is already filled in.
• MC_RTK_PROCESS_SET_EVENT– Set an event of a process.
• MC_RTK_PROCESS_START_TIMER– Starts a one shot timer to be returned to the process when
expired.• MC_RTK_PROCESS_START_AR_TIMER
– Starts an auto reload timer to be returned to the calling process.• MC_RTK_PROCESS_START_TIMER_WP
– Starts a one shot timer with a tolerance to be returned to the calling process.
Philips Semiconductors, Greater China Communications Applications Laboratory 86
Process Management• MC_RTK_PROCESS_START_AR_TIMER_W
– Starts an auto reloaded timer with a tolerance to be returned to the calling process.
• MC_RTK_CREATE_PROCESS_INSTANCE– Creates an instance of a finite state machine process.
• MC_RTK_DELETE_PROCESS_INSTANCE– Delete an existing instance of a finite state machine
process.• MC_RTK_SET_PROCESS_INST_USR_DATA
– Initializes a process instance data area with a user defined data structure.
Philips Semiconductors, Greater China Communications Applications Laboratory 87
Process Management• MC_RTK_GET_PROCESS_INSTANCE
– Indicates which process instance is currently running.• MC_RTK_GET_PREC_PROCESS_STATE
– Indicates what was the preceding state of a finite state machineprocess.
• MC_RTK_GET_ACTIVE_PROCESS_STATE– Indicates what is the current state of a finite state machine
process.• MC_RTK_REPLACE_PROCESS
– Replaces a process by another one as the effective addressee when sending a message.
• MC_RTK_PROCESS_MAILBOX_NUMBER– Returns the number of the task (and therefore the mailbox
number) in which a process runs.
Philips Semiconductors, Greater China Communications Applications Laboratory 88
Exceptions• The exception routine is specified within the definition file
of RTK-E initialization.• To respect parameter passing, the user exception
routine must have the following prototype .• The name of the function is given as example only the
parameters types must be the same:void ExcptHandler ( u8 vp_Blocking , u32
vp_CompactedParameters);- vp_Blocking indicate that the calling of the exception
routined is or not blocking- vp_CompactedParameters contains compacted on 32
bits:* in bits [31..24] the task number in which the error has
accur
Philips Semiconductors, Greater China Communications Applications Laboratory 89
Exceptions
*in bits [23..16] the RTK-E file number in which the error has accur
* in bits [15..8] the RTK-E procedure number in which the error has accur,
* in bits [7..0] the error number.* RTK_NOT_BLOCKED* RTK_BLOCKED in this case no return to RTK-E is
possible• At kernel initialization, an exception routine address is
set. This user-written routine will be executed each time an RTK-E exception will occur.
Philips Semiconductors, Greater China Communications Applications Laboratory 90
CODE Generator• RTK-E integrates a code generator which
generate C code from a definition file• This code generator reserve all variables
needed from Create an initialization function which must be called
• For specific targets create some interrupt connexions at initialization ( named Rtk00Go() )the application.this generator is called RTKGENTO
Philips Semiconductors, Greater China Communications Applications Laboratory 91
RTK initialization• The RTK initialisation function is called to start the RTK
running:• All memory pools• All task mail boxes• All task descriptors• All process descriptors• All semaphores
• All the RTK tasks and any associated FSM‘s are started.• Lastly the INIT module call back function is called to
generate the start up message.
Philips Semiconductors, Greater China Communications Applications Laboratory 92
RTK initialization• The INIT module contains a call back function to
generate the start up message.
• The message is sent to the ENV module to indicate the reason for the mobile switch on.
• This function is called at the end of the RTK initialisation.
• The possible reasons are:
• Normal mobile switch on
• Restart after error
• Factory test mode
Philips Semiconductors, Greater China Communications Applications Laboratory 93
RTK initialization
Automatically generated parts for the RTK-E initialisation
master.def
rtk00go.c
RTKGEN
Text file for RTK set up
rtk00go.hec
rtk01go.crtk04dbg.c
rtk00go.hep
rtk00go.hev
rtk00go.hic
rtk00go.hiv
Philips Semiconductors, Greater China Communications Applications Laboratory 94
RTK initialization
Taskdescription
Priority
Entry Point
Stack Size
Process Runner
Taskdescription
Priority
Entry Point
Stack Size
Process Runner
Task setup
Taskdescription
Priority
Entry Point
Stack Size
Process Runner
Virtual Processes setup
Memory setup
ClusterClusterCluster
Object setup
Semaphores Timers
Interrupt setup
master.def
The organisation ofthe master.def file
Philips Semiconductors, Greater China Communications Applications Laboratory 95
RTK
Agenda:• Introduction of RTK-E• RTK-E Mechanism and Service• Example: Add a New Process • Q&A
Philips Semiconductors, Greater China Communications Applications Laboratory 96
Example: Add a New ProcessThree steps for “Adding a New Process”
1. Add a New process• Process definition• Finite State Machine(FSM)• Creation of an instance of the process
2. Define a new module for compilation3. Define New Message
• Creation of Operation type• Creation of Operation name• Creation of Operation Type• Concatenate operation name and type
• Definition of structure for this message• Sending receiving message
Philips Semiconductors, Greater China Communications Applications Laboratory 97
Example: Add a New ProcessThree steps for “Adding a New Process”
1. Add a New process• Process definition• Finite State Machine(FSM)• Creation of an instance of the process
2. Define a new module for compilation3. Define New Message
• Creation of Operation type• Creation of Operation name• Creation of Operation Type• Concatenate operation name and type
• Definition of structure for this message• Sending receiving message
Philips Semiconductors, Greater China Communications Applications Laboratory 98
Example: Add a New Process1. Add a New process
Process definitionA simple declarations of process and task for RTK is made in Master.der.Thanks to RTK generation, some files (rtk00go.c, rtk00go.h*, …) are generated to provide system with the RTK description.
Example “Adding two tasks”
Task OneTASK ( PRIORITY = 60, ENTRY_POINT = RtkTaskAddProcCust1(), STACK_SIZE = 512 ) :
{ PROCESS_RUNNER :
{ PROCESS_FSM : PROCESS_NAME = PROCESS_ADD_PROC_CUST1, INITIAL_STATE = a_cust1_Init;
PROCESS_FSM : PROCESS_NAME = PROCESS_ADD_PROC_CUST2, INITIAL_STATE = a_cust2_Init;
}
}
Philips Semiconductors, Greater China Communications Applications Laboratory 99
Example: Add a New ProcessTask TwoTASK ( PRIORITY = 55, ENTRY_POINT = RtkTaskAddProcCust2(), STACK_SIZE = 512
) :
{ PROCESS_RUNNER :
{ PROCESS_FSM : PROCESS_NAME = PROCESS_ADD_PROC_CUST3, INITIAL_STATE = a_cust3_Init;
PROCESS_FSM : PROCESS_NAME = PROCESS_ADD_PROC_CUST4, INITIAL_STATE = a_cust4_Init;
} }
Philips Semiconductors, Greater China Communications Applications Laboratory 100
Example: Add a New ProcessFinite State Machine (FSM)
A process is a FSM described via table where you specify each state and its transitions.
FSM tables can be found in files xxxx_tab.c
C function for transition can be found either in the same or in separated files.
Philips Semiconductors, Greater China Communications Applications Laboratory 101
Example: Add a New ProcessCreation of an instance of the process
One or several instance of a process can be created.
Creation of instance can be done dynamically whenever you want in the software.
We take the advantage of the initialisation of the task to create one instance for the 4 customer process
Example:void RtkTaskAddProcCust1(void)
{ byte vl_InstanceId;
MC_RTK_CREATE_PROCESS_INSTANCE( PROCESS_ADD_PROC_CUST1, &vl_InstanceId );
MC_RTK_CREATE_PROCESS_INSTANCE( PROCESS_ADD_PROC_CUST2, &vl_InstanceId );
MC_RTK_RUN_PROCESS( &TaskDesc25 );
}
Philips Semiconductors, Greater China Communications Applications Laboratory 102
Example: Add a New ProcessThree steps for “Adding a New Process”
1. Add a New process• Process definition• Finite State Machine(FSM)• Creation of an instance of the process
2. Define a new module for compilation3. Define New Message
• Creation of Operation type• Creation of Operation name• Creation of Operation Type• Concatenate operation name and type
• Definition of structure for this message• Sending receiving message
Philips Semiconductors, Greater China Communications Applications Laboratory 103
Example: Add a New Process2. Define a new module for compilation• create a new directory
• “inc subfolder ” for include files
• “srce” subfolder for source files
• An empty file “process_name.ident” which will indicate that there is a new module named:process_name
• Modify in compile file– add process_name in the list of module to be compiles in cust1.gen(or
vyp105a.gen)– create a file process_name in “srce” folder of your new module to give
rules of compilation to compiler.
Philips Semiconductors, Greater China Communications Applications Laboratory 104
Example: Add a New ProcessThree steps for “Adding a New Process”
1. Add a New process• Process definition• Finite State Machine(FSM)• Creation of an instance of the process
2. Define a new module for compilation3. Define New Message
• Creation of Operation type• Creation of Operation name• Creation of Operation Type• Concatenate operation name and type
• Definition of structure for this message• Sending receiving message
Philips Semiconductors, Greater China Communications Applications Laboratory 105
Example: Add a New Process3. Define New Message• Creation of Operation type
- Creation of Operation name in customer.hec
Example:enum{F_MSG_CUST1};
Interface = Process 7 bits Operation name: 6 bits Type:3 bits
Philips Semiconductors, Greater China Communications Applications Laboratory 106
Example: Add a New Process- Creation of Operation TypeMC_PCC_FUNCTION_TYPE in customer.hec
Example:/*Fsm messages :*/#define F_MSG_CUST1_REQ MC_PCC_FUNCTION_TYPE( F_MSG_CUST1, PCC_T_REQ )#define F_MSG_CUST1_CNF MC_PCC_FUNCTION_TYPE( F_MSG_CUST1, PCC_T_CNF)
- Concatenate operation name and typeMC_RTK_PROCESS_OPERATION in customer.het
Example:MC_RTK_PROCESS_OPERATION(PROCESS_ADD_PROC_CU1, F_MSG_CUST1_REQ)
Philips Semiconductors, Greater China Communications Applications Laboratory 107
Example: Add a New Process• Definition of structure for this message macro
used:MC_PCC_BEGIN_STRUCMC_PCC_FIELD(definition of all the data field)MC_PCC_FIELDMC_PCC_FILL_STRUCT3|(in order to have a data structure as a multiple of U32 cf pccdef.hem)MC_PCC_END_STRUC
Example cutomer1.hetMC_PCC_BEGIN_STRUC( t_cust1_state )MC_PCC_FIELD( u8, v_state )MC_PCC_FILL_STRUCT3MC_PCC_END_STRUC( t_cust1_state )
Philips Semiconductors, Greater China Communications Applications Laboratory 108
Example: Add a New Process• Sending receiving message
– Declare a variable with the structure– Reserve memory from RTK(MC_RTK_GET_MEMORY)– Set values of a field of the data structure– Send the message
Example: cust10_tab.ct_cust1_state *p_MsgSendCnf;p_MsgSendCnf=(t_cust1_state *) MC_RTK_GET_MEMORY (sizeof(t_cust1_state));p_MsgSendCnf->v_state=0;MC_RTK_SEND_MSG_TO_PROCESS(PROCESS_ADD_PROC_CUST1,0,PROCESS_MMI,0,MSG_CUST1_CNF,(t_MsgHeader *) p_MsgSendCnf);