/**
 * Default constructor for the task that stores its unique ID and
 * compute/period time pair. All time values are assumed to be milliseconds.
 *
 * @param id - the task's unique ID
 * @param computeTime - the tasks's compute time
 * @param periodTime - the tasks's period time
 */
Task::Task(int id, int computeTime, int periodTime)
{
	int result;

	// Attempt to initialize the execution semaphore.
	result = sem_init(&sem, 0, SEM_COUNT);
	if (result != 0)
	{
		cerr << "Error initializing execution semaphore for task " <<
				id << endl;
		uid = -1;
	}
	else
	{
		// Initialize the rest of the task's variables.
		this->uid = id;
		this->computeTime = computeTime;
		this->currentComputeTime = 0;
		this->periodTime = periodTime;
		this->deadline = periodTime;
		this->deadlinesMissed = 0;
		this->deadlineEvents = 0;
		this->totalComputationTimeMissed = 0;
		this->totalComputationTime = 0;
		this->totalComputationCycles = 0;
		this->averageTaskPeriod = 0;
		this->realComputeTime = 0;
		this->computeTransitionTime = 0;

		// Initialize the burn time quantum.
		this->burnTime.tv_nsec = REAL_TIME_QUANTUM;

		// Configure the period timer.
		configureTimer();
	}
}
Example #2
0
void RFduino_Timer2::start(void)
{
	configureTimer();
	NRF_TIMER2->TASKS_START = 1;
}