Beispiel #1
0
void Task1() {
	uint16_t cnt;
	int8_t v;

	cnt = 0;
	while (1) {
		nrk_led_toggle(ORANGE_LED);
//		printf("Task1 cnt=%d\r\n", cnt);
//		nrk_kprintf(PSTR("Task1 accessing semaphore\r\n"));
//		printf("T1_next_period = %u \n", nrk_cur_task_TCB->next_period);
		v = nrk_sem_pend(sem1);
		if (v == NRK_ERROR)
			nrk_kprintf(PSTR("T1 error pend\r\n"));
//		nrk_kprintf(PSTR("Task1 holding semaphore\r\n"));
//		printf("In T1 sys_ceiling = %u \n", system_ceiling);
		printf("In T1 Q --- ");
		nrk_print_readyQ();
		printf("\n");
		// to something within the critical section
		nrk_wait_until_next_period();
		v = nrk_sem_post(sem1);
		if (v == NRK_ERROR)
			nrk_kprintf(PSTR("T1 error post\r\n"));
//		nrk_kprintf(PSTR("Task1 released semaphore\r\n"));
		nrk_wait_until_next_period();

		if (cnt == 3)
			break;
		cnt++;
	}
	nrk_stats_display_all();
}
Beispiel #2
0
void Task2() {
	uint8_t cnt;
	int8_t v;

	cnt = 0;
	while (1) {
		nrk_led_toggle(BLUE_LED);
//		printf("Task2 cnt=%d\r\n", cnt);
//		nrk_kprintf(PSTR("Task2 accessing semaphore\r\n"));
//		printf("T2_next_period = %u \n", nrk_cur_task_TCB->next_period);

		v = nrk_sem_pend(sem1);

		if (v == NRK_ERROR)
			nrk_kprintf(PSTR("T2 error pend\r\n"));
//		nrk_kprintf(PSTR("Task2 holding semaphore\r\n"));
//		printf("In T2 sys_ceiling = %u \n", system_ceiling);
		printf("In T2 Q --- ");
		nrk_print_readyQ();
		printf("\n");
		// to something within the critical section
		nrk_wait_until_next_period();
		v = nrk_sem_post(sem1);
		if (v == NRK_ERROR)
			nrk_kprintf(PSTR("T2 error post\r\n"));
//		nrk_kprintf(PSTR("Task2 released semaphore\r\n"));
		nrk_wait_until_next_period();

		cnt++;
	}

}
Beispiel #3
0
void Task4() {
	uint8_t cnt;
	cnt = 0;
	while (1) {
		nrk_led_toggle(GREEN_LED);
		printf("In T4 sys_ceiling = %u \n", system_ceiling);
		printf("In T4 Q --- ");
		nrk_print_readyQ();
		printf("\n");
		nrk_wait_until_next_period();
		cnt++;
	}
}
Beispiel #4
0
void Task3() {
	uint8_t cnt;
	cnt = 0;
	while (1) {
		nrk_led_toggle(GREEN_LED);
//		nrk_sem_pend(sem1);
//		printf("In T3 sys_ceiling = %u \n", system_ceiling);
		printf("In T3 Q --- ");
		nrk_print_readyQ();
		printf("\n");
		nrk_wait_until_next_period();
//		nrk_sem_post(sem1);
		nrk_wait_until_next_period();
		cnt++;
	}

}
Beispiel #5
0
void nrk_add_to_readyQ(int8_t task_ID) {
	nrk_queue *NextNode;
	nrk_queue *CurNode;

	printf("nrk_add_to_readyQ %d\n", task_ID);
	// nrk_queue full
	if (_free_node == NULL) {
		return;
	}

	NextNode = _head_node;
	CurNode = _free_node;

	if (EDF_ON == 1) {
		if (_head_node != NULL) {
			while (NextNode != NULL) {
				if (nrk_task_TCB[NextNode->task_ID].abs_deadline
						> nrk_task_TCB[task_ID].abs_deadline) {
					break;
				}
				NextNode = NextNode->Next;
			}
		}
	} else {
		if (_head_node != NULL) {

			while (NextNode != NULL) {
				if (nrk_task_TCB[NextNode->task_ID].elevated_prio_flag)
					if (nrk_task_TCB[NextNode->task_ID].task_prio_ceil
							< nrk_task_TCB[task_ID].task_prio)
						break;
				if (nrk_task_TCB[task_ID].elevated_prio_flag)
					if (nrk_task_TCB[NextNode->task_ID].task_prio
							< nrk_task_TCB[task_ID].task_prio_ceil)
						break;
				if (nrk_task_TCB[NextNode->task_ID].task_prio
						< nrk_task_TCB[task_ID].task_prio)
					break;

				NextNode = NextNode->Next;
			}

			//      while ((NextNode != NULL) && ((nrk_task_TCB[NextNode->task_ID].task_prio >= nrk_task_TCB[task_ID].task_prio)|| ) {
			//              NextNode = NextNode->Next;}
			// Stop if nextNode is freenode or next node less prio or (equal and elevated
			// Issues - 1 comes, becomes 2', 1 more comes (2' 1) then 2 comes where should it be placed ?
			// 2' 2  1 or 2 2' 1 in ready q , what happens after 2'->1, what if 2'->2

		}
	}

	CurNode->task_ID = task_ID;
	_free_node = _free_node->Next;

	if (NextNode == _head_node) {
		//at start
		if (_head_node != NULL) {
			CurNode->Next = _head_node;
			CurNode->Prev = NULL;
			_head_node->Prev = CurNode;
		} else {
			CurNode->Next = NULL;
			CurNode->Prev = NULL;
			_free_node->Prev = CurNode;
		}
		_head_node = CurNode;

	} else {
		if (NextNode != _free_node) {
			// Insert  in middle

			CurNode->Prev = NextNode->Prev;
			CurNode->Next = NextNode;
			(NextNode->Prev)->Next = CurNode;
			NextNode->Prev = CurNode;
		} else {
			//insert at end
			CurNode->Next = NULL;
			CurNode->Prev = _free_node->Prev;
			_free_node->Prev = CurNode;
		}

	}

	// Print out for debug all tasks in readyQ after addition.
	printf("Modified Contents of Ready Q: ");
	nrk_print_readyQ();
	printf("\r\n");

}