E D R , A S I H C RSS

LIB_3

μ΄μ œλŠ” μŠ€μΌ€μ„링을 λ‹΄λ‹Ήν•˜λŠ” μ†ŒμŠ€λΌ μ‚΄νŽ΄ 보겠닀.

μš°μ„  λ‚΄κ°€ λ§Œλ“  ν”„λ‘œκ·Έλž¨μ—μ„œ μŠ€μΌ€μ„링을 λ‹΄λ‹Ήν•˜λŠ” νλŠ” λŒ€λž΅
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 νμ—μ„œ λΉΌμ€λ‹€...... μ”μ”μ”
~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 μ™€μ˜ μ‹€ν–‰ 속도 μ°¨μ΄λŠ” λ¬΄μ§€ν•˜κ²Œ 크닀. μ΄μœ λŠ” μ†ŒμŠ€λΌ λ³΄λ©΄ μ•Œ 것이닀..

μ—¬ν•˜νŠΌ..ν•˜μ§€λ§Œ..κ·Έλž˜λ„ λ‚΄ μ†ŒμŠ€κ°€ 더 보기 쉽지 μ•Šλ‚˜?? γ…‹γ…‹γ…‹γ…‹γ…‹

싀행속도가 μ°¨μ΄λŠ” λ‚˜μ§€λ§Œ κ·Έλž˜λ„ λ‚˜λ¦„λŒ€λ‘œμ˜ λ°©μ‹μœΌλ‘œ λ§Œλ“€λ €κ³  λ…Έλ ₯ν–ˆλ‹€..κ·Έλž˜μ„œ

이λͺ¨μ–‘ 이꼴인 μ˜€μ—μŠ€κ°€ λ˜μ—ˆμ§€λ§Œ............


Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:37
Processing time 0.0175 sec