360 likes | 955 Views
REX & UI. S/W 3 team 박 성 진. Contents. 1. REX 1.1 Real-Time OS 1.2 Tasks 1.2.1 Tasks 1.2.2 Stacks 1.2.3 Task Control Block 1.2.4 Task list 1.3 Scheduling 1.3.1 Priories & Scheduling 1.3.2 Context switching 1.3.3 Inter-task communication. 1.4 Interrupts
E N D
REX & UI S/W 3 team 박 성 진
Contents 1. REX 1.1 Real-Time OS 1.2 Tasks 1.2.1 Tasks 1.2.2 Stacks 1.2.3 Task Control Block 1.2.4 Task list 1.3 Scheduling 1.3.1 Priories & Scheduling 1.3.2 Context switching 1.3.3 Inter-task communication 1.4 Interrupts 1.6 Mutual exclusion 1.7 Signal & Timer 2. User Interface 2.1 Tasks create 2.2 UI tasks 2.3 State machine
Real Time OS 1. Real-time System - Soft Real time System - Hard Real time System 2. Real-time OS - Real time system 에 embedded 되어 사용 - 특징 Service 요구에 대한 빠른 Response Task Scheduling 제공 최소의 Interrupt latency time
Tasks Tasks - Treats Independently - Task Stack - Task Priority (stored in TCB) - Task Control Block Task creation - The task create function : rex_def_task() * TCB , stack , priority , task start func , task param * Scheduler 호출 * Task 의 선점을 보장하지는 않음 * Ready to run task
Stacks Stacks - Each task has its own stack that is active whenever the task is running - Running time task and context switching
Task Control Block TCB - Each task has a TCB - TCB is keep track of the task context Fields of TCB - sp : the pointer to the top of stack - stack_limit : the stack limit for this task`s stack - sigs : the signals currently set for this task - wait : the signals on which this task is waiting - pri : task`s priority
rex_task_list TCB_type Running Task Head node Task List Task List - 모든 TCB 는 Queue 로 관리 - 이러한 Queue 는 Double Linked List 로 구현 - TCB is sorted by priority - rex_task_list : the head-node of this queue - rex_task_list->next_ptr : highest priority task in the system - Highest priority ready task : Looking for a TCB with a wait filed equal to zero High priority Ready tasks Low priority
Priority & Scheduling Priority - Each task has a priority, It stored in TCB - Positive 32 bit Integer , nonzero (zero=Idle task) - Lower values indicating lower priority - rex_set_pri(), rex_get_pri(), rex_task_pri() Scheduling - REX always chooses the highest priority ready task - The chosen task will continue to execute until : * it voluntarily suspends * an interrupt occurs that reactivate a higher priority task - When all task are suspended, the Idle task is execute
Priority & Scheduling Scheduler - The scheduler function : rex_sched() 1. It is internal to REX and should not be called by applications directly 2. It is executed with interrupts disable 3. The calling function must set the global variable rex_best_task before calling rex_sched() - rex_best_task : The highest priority ready task in system - rex_curr_task : The currently running task in system
New task Task Highest Priority sorting Best_task Task list Curr_task Curr_task = Best_task Return Best_task == Curr_task Context switching Best_task != Curr_task Priority & Scheduling Scheduler - The Basic algorithm of the scheduler is :
Low priority task A High priority task B TCB A TCB B Stack A Proc. Stack B [ Structure of REX task ] Context Switching Context Switching Before Switching - Task A : Running Task B : Ready to run - Reg : SP , R1 ~ R3 , PC , PSW - CPU`s SP register is pointing a stack address of running task - Context Switching : from task A to task B
Low priority task A High priority task B Low priority task A High priority task B TCB A TCB B TCB A TCB B Stack A Proc. Stack B Stack A Proc. Stack B sp sp [ Before Switching ] [ After Switching ] Context Switching Context Switching After Switching - Task A : Ready to run Task B : Running Reg Reg PC PC PSW PSW
Inter-task communication Inter- task communication - Inter task communication is possible by message Queue that is each tasks shared - Each task has a own message Queue for the passing the commands - One Task is send the signal after insert to command in the command Queue - Another task is receive the command throughout the command Queue
Task A Task B Free Queue Free Queue Command Queue SIGNAL Command Queue [ Inter task communication ] Inter-task communication Inter- task communication
Interrupts Interrupts - Asynchronous event 를 system 에게 알리는 mechanism - Event가 감지되었을 때 : * processor stores task`s context * process the ISR(interrupt service routine) - REX implements a preemptive kernel - On returning from an interrupt : 1. Preemptive kernel : * control is passed to the highest priority ready task 2. Non-preemptive kernel : * control is passed to the task on occurred interrupt
Mutual Exclusion Mutual Exclusion - Critical section : The block of code that accesses a shared resource - Mutual Exclusion : 두개의 task 가 하나의 공통자원을 공유할 때, 그 조작의 정당성을 확보하기 위해 한번에 하나의 task 만 자원을 점유하도록 제어 - REX provides two way that for locking shared resources : * Locking interrupts * Using functions that can be locked and freed command resources
Signals Signals - 각각의 task 는 task 의 control block 내에 general purpose signal flag 를 갖는다 - 이들의 signal flag 는 어떤 종류의 event 가 발생되었는지 task 에게 알려준다 - Task 의 signal 은 어떠한 다른 task 에 의해서 혹은 interrupt handler 에 의해서 ser 또는 clear 되어질 수 있다
Signals Signals - REX provides signals as an intertask communication mechanism It is possible for any task to read, set, and clear any other task`s signals. * rex_get_sigs() : to read state of the signals * rex_set_sigs() : to set signals ( 1 set) * rex_clr_sigs() : to clear signals ( 1 clear) - rex_wait() : A task can wait on any subset of its own signals to be set * If a task requests to wait when a signal from its wait mask is already set, the wait will return immediately without suspending the task.
Timers Timers - Timer 는 REX 내에서 software interval timing 을 위해 사용 - When using a timer a task specifies : * The interval to be timed and * A signal-mask to be set when the timer expires. - Timer 는 timeout 이 감지 되었을 때, 특정 event 가 수행 되 도록 다른 event 와 결합하여 사용 가능 - REX 는 모든 active timer 를 관리하는 timer list 를 제공하며 이는 timer 가 set/expire 될 때 마다 list 에 insert/delete 함
Timers Timers - Define a new timer : rex_def_timer() - Used by tasks to perform S/W interval timing * rex_set_timer() : start a timer * rex_get_timer() : read the time remaining in a timer * rex_pause_timer() : pauses a timer * rex_resume_timer() : restart a paused timer * rex_timed_wait() : waiting for a signal with timer
main() rex_init() mc_task() mc_init_*() mc_define_tasks() mc_start_service_task() HS task NV task UI task CM task Sleep task Tasks creation Tasks creation
UI Task Concept - The UI task is the layer between the actually user of phone and its software - It provides interfaces to phone hardware to provide display, sound, and key entry
UI Task Architecture [ UI Architecture ]
ui_task() Initialize signal Loop wait [UI task dispaycher] UI Task Dispatcher layer - The dispatcher layer is the top layer of UI - It is giant loop that receives the input and directs it to proper function on which to perform the operation - Init task -> Loop -> Dispatch
UI Task ui_signal( sigs, &ui_cmd_q ); while ( ui.getkeys && ( ui_event.head != ui_event.tail )) { ui_event.tail = ( ui_event.tail+1 ) % UI_EVENT_SIZE; ui_do_event( ui_event.buf[ ui_event.tail ] ); } (void) uiscrn_refresh(); } // end of for loop } // end of ui_task function void ui_task ( dword dummy ) { static rex_sigs_type sigs; ui_init(); for( ;; ) { sigs = rex_wait( UI_RPT_TIMER_SIG | UI_KEY_SIG | UI_CMD_Q_SIG | UI_MULTI_STOP_SIG | UI_TIMERS_SIG | UI_RING_SIG | TASK_OFFLINE_SIG | TASK_STOP_SIG ); Signal 처리 UI task와 관련된 초기화 Event 처리 Screen 갱신 특정 signal 을 기다림
Handler Layer Signal handler Key H Cmd H CB-T H UI Task Handler layer – signal - Signal handler - Key handler - Command handler - Callback timer handler - This module handles most of the signals that received by the UI task (ui_signals()) - Converted the signal into the events and feeds them to the state machine for processing
UI Task Command 처리 void ui_signal ( rex_sigs_type sigs, q_type *ui_cmd_q_ptr ) { static ui_cmd_type *cmd_ptr; static rex_tcb_type *ctask_ptr; static rex_sigs_type csigs; if( sigs & UI_RPT_TIMER_SIG ) { ui_kick_dog(); } if( sigs & UI_KEY_SIG ) { (void) rex_clr_sigs( rex_self(), UI_KEY_SIG ); handle_keys(); } /* key signal set */ if( sigs & UI_CMD_Q_SIG ) { (void) rex_clr_sigs( &ui_tcb, UI_CMD_Q_SIG ); while( ( cmd_ptr = (ui_cmd_type *) q_get( ui_cmd_q_ptr )) != NULL ) { ui_handle_cmds( cmd_ptr ); ctask_ptr = cmd_ptr->hdr.task_ptr; csigs = cmd_ptr->hdr.sigs; if( cmd_ptr->hdr.done_q_ptr ) { q_put( cmd_ptr->hdr.done_q_ptr, &cmd_ptr->hdr.link ); } if( ctask_ptr ) { (void) rex_set_sigs( ctask_ptr, csigs ); } } // end of while } Timer signal 처리 Key signal 처리
UI Task Handler layer – callback timer - 적절한 interval time 에 signal 을 얻으며 이러한 signal 은 다양한 operation 수행에서 사용 - The function : handle_timer() * time flags 라는 전역변수를 사용 * a bit is set or reset when timer is started or expired * signal 을 state machine 에서 사용 할 event 로 변환
UI Task Handler layer – command - Command handler는 다른 task로 부터 들어오는 message를 event로 변환하여 이를 state machine으로 넘겨서 처리 - The function : ui_cmd() * UI received the signal , UI_CMD_Q_SIG * UI reads the command queue * Determine what should be do
State machine State machine - This layer is main processing unit of the UI - It it processes the input from other tasks and drivers - The state : * Stack data structure (push or pop) - The states are divided into two states: * Major state – uistate.c * Minor state – uis*.c
State machine State machine - Major state machine * The major state machine processes all of the incoming events to the UI * Based on current state, the major state machine calls the corresponding minor state machine to to handle the events
State machine State machine - Minor state machine * Each major state has multiple minor states * All states use UI_POP_S to return to previous state on the stack
Implement The unit changer
Q & A Question ?