Revision 1545

View differences:

trunk/code/projects/scheduler/scheduler.c
81 81
}
82 82

  
83 83
void scheduler(void){
84
	static uint8_t task_i;
84
	static uint8_t task_i = 1;
85 85
	uint8_t i;
86 86
	int current_time = rtc_get();
87 87
	
......
92 92
			
93 93
			current_task = task_i;	
94 94
			PCB[task_i].next += PCB[task_i].period;
95
			create_launch_stack(task_i);
95 96
			task_i++;
97
			break;
98
		}
96 99

  
100
		if( 	PCB[task_i].running ) {
101
			current_task = task_i;
102
			task_i++
97 103
			break;
98 104
		}
99 105
		
100 106
		//Loop back to 0 if necessary.
101 107
		task_i++;
102 108
		if(task_i >= nactive_tasks) 
103
			task_i = 0;
109
			task_i = 1;
104 110
	}
111
	
112
	//If no task was selected to run,
113
	if(i == 0) { 
114
		//Return to main.
115
		current_task = 0;	
116
	}
105 117
}
106 118

  
107 119
void store_task(void) { 
......
223 235
	 	"pop r0 \n" \
224 236
	 	"pop r0 \n");
225 237
	
238
	PCB[current_task].running = 0;
226 239
	scheduler();
240
	PCB[current_task].running = 1;
227 241
	restore_task();
228 242
}
229 243

  

Also available in: Unified diff