μ΄μ λ μ€μΌμ€λ§μ λ΄λΉνλ μμ€λ₯Ό μ΄ν΄ λ³΄κ² λ€.
μ°μ λ΄κ° λ§λ νλ‘κ·Έλ¨μμ μ€μΌμ€λ§μ λ΄λΉνλ νλ λλ΅
WAIT μ SUSPEND κ·Έλ¦¬κ³ FREE νλ‘ λλμ΄ μ§ μ μλ€.
WAITμ μ€ν κ°λ₯νμ§λ§ λ©μΆ° μ§ νμ€ν¬λ₯Ό μν ν
SUSPENDλ μΈν°λ½νΈλ₯Ό λκΈ°νλκ°? μλ λκ°λ₯Ό κΈ°λ€λ¦¬κΈ° μν΄ μ€νμ΄ μ€μ§λ μν? μμμ΄κ² μ°?
κ·Έλ¦¬κ³ FREE νλ λ©λͺ¨λ¦¬μμ μ‘΄μ¬νμ§λ§ μ£½μ νμ€ν¬λ₯Ό λ΄μ λμ ν.....μ―μ―μ― λΆμλ ν΄λΌ.
μ..μ΄λ κ² λλμ΄μ§κ³ WAITνμ 0λ²μ§Έ νμ€ν¬κ° μ§κΈ μ€ν μ€μΈ νμ€ν¬λ₯Ό μ§μΉνλ€.
μ..μ¬ννΌ μ΄λ κ² λ§νμΌλ κ·ΈλΌ μμ€λ₯Ό μ€λͺ ν΄ λ³ΌκΉ?
κ·Έλ¦¬κ³ λμ μ§κΈμ κ°μ₯ λμ νμ€ν¬λ₯Ό μ€ννΈ TCBλ‘ μ§μΉν΄ μ€λ€.μ΄κΈ°ν λ
μ°μ λ΄κ° λ§λ νλ‘κ·Έλ¨μμ μ€μΌμ€λ§μ λ΄λΉνλ νλ λλ΅
WAIT μ SUSPEND κ·Έλ¦¬κ³ FREE νλ‘ λλμ΄ μ§ μ μλ€.
WAITμ μ€ν κ°λ₯νμ§λ§ λ©μΆ° μ§ νμ€ν¬λ₯Ό μν ν
SUSPENDλ μΈν°λ½νΈλ₯Ό λκΈ°νλκ°? μλ λκ°λ₯Ό κΈ°λ€λ¦¬κΈ° μν΄ μ€νμ΄ μ€μ§λ μν? μμμ΄κ² μ°?
κ·Έλ¦¬κ³ FREE νλ λ©λͺ¨λ¦¬μμ μ‘΄μ¬νμ§λ§ μ£½μ νμ€ν¬λ₯Ό λ΄μ λμ ν.....μ―μ―μ― λΆμλ ν΄λΌ.
μ..μ΄λ κ² λλμ΄μ§κ³ WAITνμ 0λ²μ§Έ νμ€ν¬κ° μ§κΈ μ€ν μ€μΈ νμ€ν¬λ₯Ό μ§μΉνλ€.
μ..μ¬ννΌ μ΄λ κ² λ§νμΌλ κ·ΈλΌ μμ€λ₯Ό μ€λͺ ν΄ λ³ΌκΉ?
~cpp #if !defined(LIB_SCHE_CPP) #define LIB_SCHE_CPP /* Init The Scheduler List */μ΄ ν¨μλ μ€μΌμ₯΄λ§μ μν μ€λΉ κ³Όμ TCBλ€μ λ€ μ΄κΈ°ν ν΄ μ€λ€.. κ²μ΄ λ§μμ κ·Έλ₯ λ€ μ΄κΈ°ν ν΄μ€¬λ€.
κ·Έλ¦¬κ³ λμ μ§κΈμ κ°μ₯ λμ νμ€ν¬λ₯Ό μ€ννΈ TCBλ‘ μ§μΉν΄ μ€λ€.μ΄κΈ°ν λ
~cpp void LIB_Init_Schedu(){ for (int count = 0;count<LIB_MAX_HEAP;count++) { pSuspend_heap[count] = NULL; pReady_heap[count] = NULL; pFreeTCB[count] = &TCB[count]; TCB[count].priority = NULL; TCB[count].StackSeg = NULL; TCB[count].StackOff = NULL; TCB[count].NextEvent = NULL; } LIB_INT_COUNT = 0; High_Task = &START_TCB; ready_tcb_ptr = 0; suspend_tcb_ptr = 0; free_tcb_ptr = LIB_MAX_HEAP; }μ¬κΈ°μλ FREE νμ€μμ μΈ μ μλ νκ° μλ μμλ³Έλ€?? μ΄κ±΄ μ νμ°???
~cpp /* Get Free TCB */ LIB_TCB* LIB_free_TCB() { LIB_TCB *Temp; free_tcb_ptr--; Temp = pFreeTCB[free_tcb_ptr]; pFreeTCB[free_tcb_ptr] = NULL; return Temp; }μ¬κΈ°μλ MAINμμ λ³Έ λ― νμ€ν¬λ₯Ό λ§λ€μ΄ μ£Όλ ν¨μ
~cpp /* Create The Task */ void LIB_create_task (char *task_name,int priority,void (*task)(void),INT16U * Stack) { // Init The Stack LIB_STACK_INIT(task,Stack); <-------- μ€νμ μ΄κΈ°ν ν΄μ€λ€..... if ( priority < LIB_MIN_PRIORITY || priority > LIB_MAX_PRIORITY ) return; <--------- μ°μ μμκ° μ§λ κ°μΌλ©΄ κ·Έλ₯ λλΈλ€. // Insert Prio Queue; pReady_heap[ready_tcb_ptr] = LIB_free_TCB(); // Init the TCB by argument <----- ν¨μμμ μ»μ λ³μλ€λ‘... μ΄κΈ°ν...ok??? pReady_heap[ready_tcb_ptr]->Task_Name = task_name; pReady_heap[ready_tcb_ptr]->delay = 0; pReady_heap[ready_tcb_ptr]->priority = priority; pReady_heap[ready_tcb_ptr]->StackSeg = (INT16U)FP_SEG(Stack); pReady_heap[ready_tcb_ptr]->StackOff = INT16U(Stack) - 28; pReady_heap[ready_tcb_ptr]->Stack = Stack; /// μ¬κΈ°μ λΆν°λ μ°μ μμ νλ₯Ό μ΄λ€.... μ΄λΌ κ°λ¨νλ λ°... <----- μ¬μ€μ μ°μ μμ νκ° λͺλ°±λ² λ λ€μλ κ·Έ νμ μνλ₯Ό μ μ§νλ κ²μ΄ μ’ μ΄λ €μ λ€.. μ½κ² λ§ν΄ μμΌλ‘ νμ€ν ν λ νμ νμ€ν¬λ₯Ό λ£μλ€ λΉΌλ©΄ λλ κ±° κ°μ§λ§ μ»΄ν¨ν°κ° 컨ν μ€νΈ μ€μμΉμ μν΄ λͺλ°±λ² νμ λ£μλ€ λΊλ° ν λλ ν¬ν¬ κ°μκΈ° λ»λ μν©μ΄ μ¬ν.... -------> int temp_count = ready_tcb_ptr; LIB_TCB *Temp_TCB; ready_tcb_ptr++; while (1) { if ( pReady_heap[temp_count]->priority > pReady_heap[tree_parent(temp_count)]->priority ){ Temp_TCB = pReady_heap[temp_count]; pReady_heap[temp_count] = pReady_heap[tree_parent(temp_count)]; pReady_heap[tree_parent(temp_count)] = Temp_TCB; temp_count = tree_parent(temp_count); } else { break; } } }SUSPEND λ TASK λ€μ λ€μ μ΄λ €μ£Όλ κ³ λ§μ΄ νμ
~cpp /* Resume task */ void LIB_resume_task(INT16U priority ){ if ( priority == 0 ) return; LIB_ENTER_CRITICAL(); int temp; for ( int i = 0; i<= suspend_tcb_ptr ; i++ ) { if ( pSuspend_heap[i]->priority == priority ) { pReady_heap[ready_tcb_ptr] = pSuspend_heap[i]; pSuspend_heap[i] = pSuspend_heap[suspend_tcb_ptr]; pSuspend_heap[suspend_tcb_ptr] = NULL; suspend_tcb_ptr--; temp = ready_tcb_ptr; goto EX_LOOP1; } } LIB_VRAM_STRING(0,15,"CAUTION !!!",0x07); return; EX_LOOP1: LIB_TCB *temp_tcb; while (1) { if ( pReady_heap[temp]->priority > pReady_heap[tree_parent(temp)]->priority ) { temp_tcb = pReady_heap[tree_parent(temp)]; pReady_heap[tree_parent(temp)] = pReady_heap[temp]; pReady_heap[temp] = temp_tcb; temp = tree_parent(temp); } else break; } ready_tcb_ptr++; LIB_EXIT_CRITICAL(); LIB_context_sw(); }
/// νμ€ν¬ μμ€ν¬λ νκΈ°......λ μ΄μ μ’ μ¬μ΄λΌ...
SUSPEND νμ λ£μ΄μ£Όκ³
WAIT νμμ λΉΌμ€λ€...... μ―μ―μ―
μ€νμ μ€μ§μν€κΈ° μν΄μλ FREEνμ νμ€ν¬λ₯Ό λ£μ΄μ€λ€.....
μ¬μ€ λ΄κ° λ§λ κ²κ³Ό U_C_OS μμ μ€ν μλ μ°¨μ΄λ 무μ§νκ² ν¬λ€. μ΄μ λ μμ€λ₯Ό 보면 μ κ²μ΄λ€..
μ¬ννΌ..νμ§λ§..κ·Έλλ λ΄ μμ€κ° λ 보기 μ½μ§ μλ?? γ γ γ γ γ
μ€νμλκ° μ°¨μ΄λ λμ§λ§ κ·Έλλ λλ¦λλ‘μ λ°©μμΌλ‘ λ§λ€λ €κ³ λ Έλ ₯νλ€..κ·Έλμ
μ΄λͺ¨μ μ΄κΌ΄μΈ μ€μμ€κ° λμμ§λ§............
SUSPEND νμ λ£μ΄μ£Όκ³
WAIT νμμ λΉΌμ€λ€...... μ―μ―μ―
~cpp /* Wait task */ void LIB_suspend_task(INT16U priority){ LIB_ENTER_CRITICAL(); int temp; for(int i = 0 ; i <= ready_tcb_ptr ; i++ ) { if ( pReady_heap[i]->priority == priority ){ // ready -> suspend pSuspend_heap[++suspend_tcb_ptr] = pReady_heap[i]; // ready queue sort pReady_heap[i] = pReady_heap[ready_tcb_ptr-1]; pReady_heap[ready_tcb_ptr-1] = NULL; temp = i; ready_tcb_ptr--; goto EX_LOOP; } } LIB_VRAM_STRING(0,15,"CAUTION !!!",0x07); return; EX_LOOP: LIB_TCB *temp_tcb; while (1) { if ( pReady_heap[tree_left(temp)]->priority > pReady_heap[temp]->priority ) { temp_tcb = pReady_heap[tree_left(temp)]; pReady_heap[tree_left(temp)] = pReady_heap[temp]; pReady_heap[temp] = temp_tcb; temp = tree_left(temp); } else if ( pReady_heap[tree_right(temp)]->priority > pReady_heap[temp]->priority ) { temp_tcb = pReady_heap[tree_right(temp)]; pReady_heap[tree_right(temp)] = pReady_heap[temp]; pReady_heap[temp] = temp_tcb; temp = tree_right(temp); } else break; } LIB_EXIT_CRITICAL(); LIB_context_sw(); }μ£½μ νμ€ν¬λ€μ FREEνλ‘ κ°κ±°λΌ...μλ μ£½μμμ...
μ€νμ μ€μ§μν€κΈ° μν΄μλ FREEνμ νμ€ν¬λ₯Ό λ£μ΄μ€λ€.....
~cpp /* Delete the Task */ int LIB_del_task(LIB_TCB *task){ int temp_count; LIB_TCB *Temp_TCB; for ( int i = 0; i < LIB_MAX_HEAP ; i++ ){ if ( pReady_heap[i] == task ) { free_tcb_ptr++; pFreeTCB[free_tcb_ptr] = pReady_heap[i]; pReady_heap[i] = pReady_heap[ready_tcb_ptr]; pReady_heap[ready_tcb_ptr] = NULL; temp_count = i; ready_tcb_ptr--; while (1) { if ( pReady_heap[tree_left(temp_count)] != NULL) { if ( pReady_heap[tree_left(temp_count)]->priority > pReady_heap[temp_count]->priority ){ Temp_TCB = pReady_heap[temp_count]; pReady_heap[temp_count] = pReady_heap[tree_left(temp_count)]; pReady_heap[tree_left(temp_count)] = Temp_TCB; temp_count = tree_left(temp_count); } else break; } else break; } } if ( pSuspend_heap[i] == task) { free_tcb_ptr++; pFreeTCB[free_tcb_ptr] = pSuspend_heap[i]; pSuspend_heap[i] = pSuspend_heap[suspend_tcb_ptr]; pSuspend_heap[suspend_tcb_ptr] = NULL; suspend_tcb_ptr--; return success; } } LIB_Schedul(); return fail; } /* Resume task */ void LIB_resume_list(INT16U priority ){ int temp; for ( int i = 0; i<= suspend_tcb_ptr ; i++ ) { if ( pSuspend_heap[i]->priority == priority ) { pReady_heap[ready_tcb_ptr] = pSuspend_heap[i]; pSuspend_heap[i] = pSuspend_heap[suspend_tcb_ptr]; pSuspend_heap[suspend_tcb_ptr] = NULL; suspend_tcb_ptr--; temp = ready_tcb_ptr; goto EX_LOOP1; } } return; EX_LOOP1: LIB_TCB *temp_tcb; while (1) { if ( pReady_heap[temp]->priority > pReady_heap[tree_parent(temp)]->priority ) { temp_tcb = pReady_heap[tree_parent(temp)]; pReady_heap[tree_parent(temp)] = pReady_heap[temp]; pReady_heap[temp] = temp_tcb; } else break; } ready_tcb_ptr++; }κ°μ₯ μ°μ μμκ° λμ κ±Έ μ°Ύμμ€λ€...
~cpp /* Find Ready Task & Run the Task */ void LIB_Schedul() { High_Task = pReady_heap[0]; } #endif LIB_SCHE_CPPμ..λ΄κ° κ΅μλ μλκ³ μ€μΌμ₯΄λ§μ΄ μ€μμ€μμ κ°μ₯ μ€μν κ²μ΄λ€.. κ·ΈλΌμλ λΆκ΅¬νκ³ νμ νλ€.
μ¬μ€ λ΄κ° λ§λ κ²κ³Ό U_C_OS μμ μ€ν μλ μ°¨μ΄λ 무μ§νκ² ν¬λ€. μ΄μ λ μμ€λ₯Ό 보면 μ κ²μ΄λ€..
μ¬ννΌ..νμ§λ§..κ·Έλλ λ΄ μμ€κ° λ 보기 μ½μ§ μλ?? γ γ γ γ γ
μ€νμλκ° μ°¨μ΄λ λμ§λ§ κ·Έλλ λλ¦λλ‘μ λ°©μμΌλ‘ λ§λ€λ €κ³ λ Έλ ₯νλ€..κ·Έλμ
μ΄λͺ¨μ μ΄κΌ΄μΈ μ€μμ€κ° λμμ§λ§............