Beispiel #1
0
// --- Main Program ----------------------------------
int main(void) {
	//init PortC
	//Pins C.1 to C.3 for controlling sonars
	//Pins C.5, C.6 and C.7 for front, left and right motors respectively
	DDRC = 0xff;

	//init ADC
	adc_init();

	//init the UART -- trt_uart_init() is in trtUart.c
	trt_uart_init();
	stdout = stdin = stderr = &uart_str;
	fprintf(stdout,"\n\r Start TRT\n\r\n\r");
		
	// start TRT
	trtInitKernel(80); // 80 bytes for the idle task stack
	
	// --- create semaphores ----------
	trtCreateSemaphore(SEM_RANGE, 1) ; // protect ranging
	
	// --- create tasks  ----------------
	trtCreateTask(readSonar1, 500, SECONDS2TICKS(0.1), SECONDS2TICKS(0.1), &(args[0]));
	trtCreateTask(readSonar2, 500, SECONDS2TICKS(0.1), SECONDS2TICKS(0.1), &(args[1]));
	trtCreateTask(readSonar3, 500, SECONDS2TICKS(0.1), SECONDS2TICKS(0.1), &(args[2]));
	trtCreateTask(navLogic, 400, SECONDS2TICKS(0.1), SECONDS2TICKS(0.1), &(args[3]));
	trtCreateTask(sonar3Feedback, 400, SECONDS2TICKS(0.1), SECONDS2TICKS(0.1), &(args[0]));
	
	// --- Idle task --------------------------------------
	while (1) 
	{
		// Do Nothing
	}
}
Beispiel #2
0
// --- Main Program ----------------------------------
int main(void) {
	int args[2]; 
	DDRD = 0b11111011;
	PORTD = 0;
	
	//Initialize the MCU  
	initialize();
	
	// start TRT
	trtInitKernel(128); // 80 bytes for the idle task stack
	
	// variable protection
	trtCreateSemaphore(SEM_T_REF, 1) ; // protect shared variables
	trtCreateSemaphore(SEM_T, 1) ; // protect shared variables
	trtCreateSemaphore(SEM_T_WATER_REF, 1) ; // protect shared variables
	trtCreateSemaphore(SEM_T_WATER, 1) ; // protect shared variables
	trtCreateSemaphore(SEM_MAT_PROP, 1) ; // protect shared variables
	trtCreateSemaphore(SEM_THICKNESS, 1);
	// --- creat tasks  ----------------
	trtCreateTask(pidControl, 256, SECONDS2TICKS(0.05), SECONDS2TICKS(0.05), &(args[0]));
	trtCreateTask(keypadComm, 256, SECONDS2TICKS(0.1), SECONDS2TICKS(0.1), &(args[1]));
	trtCreateTask(displayTemp, 256, SECONDS2TICKS(0.1), SECONDS2TICKS(0.1), &(args[1]));
	
	sei();
	// --- Idle task --------------------------------------
	// just sleeps the cpu to save power 
	// every time it executes
	set_sleep_mode(SLEEP_MODE_IDLE);
	sleep_enable();
	while (1) 
	{
		sleep_cpu();
	}
	
}
Beispiel #3
0
int main(void)
{
	initialize();

	trt_uart_init();

	/* Print a statement to the serial communication terminal when the system is reset. */
	stdout = stdin = stderr = &uart_str;
	fprintf(stdout,"TinyRealTime: 2/9/09\n\r");

	/* Sets up the kernel data structures.
	 * The parameter is the desired starck size of the idle task.
	 * For a null idle task, a stack size of 80 should be sufficient. */
	trtInitKernel(80);

	/* Creates semaphores with identifer semnumber and initial values initval. */
	trtCreateSemaphore(SEM_RX_ISR_SIGNAL, 0);
	trtCreateSemaphore(SEM_STRING_DONE  , 0);
	trtCreateSemaphore(SEM_S            , 1);
	trtCreateSemaphore(SEM_P            , 1);
	trtCreateSemaphore(SEM_I            , 1);
	trtCreateSemaphore(SEM_D            , 1);

	/* Identifies the three functions to the kernel as threads.
	 * The parameters specify pointers to the functions, the
	 * desired stack size, the initial release time, the initial deadline time,
	 * and an abitrary data input structure */
	trtCreateTask(serialTask  , 200, SECONDS2TICKS(0.1), SECONDS2TICKS(0.2 ), &(args[0]));
	trtCreateTask(motorTask   , 200, SECONDS2TICKS(0.3), SECONDS2TICKS(0.32), &(args[1]));

	/* Choose our preferred sleep mode */
	set_sleep_mode(SLEEP_MODE_IDLE);
	/* Set sleep enable (SE) bit */
	sleep_enable();

	/* Sleep the CPU when a task isn't running. */
	while (1) {
		sleep_cpu();
	}

}
Beispiel #4
0
//==============================================================
// trtCreatMutex
// All mutex are created UNLOCKED with no owner
void trtCreateMutex(uint8_t mutex_number) {
	trtCreateSemaphore(mutex_number, UNLOCKED) ;
	mutex[mutex_number].state = UNLOCKED ;
	mutex[mutex_number].owner = NONE ;
} //void trtCreateMutex(uint8_t mutex_number)
Beispiel #5
0
// --- Main Program ----------------------------------
int main(void) {

    DDRD = 0b11111011;
    PORTD = 0;
    //init the UART -- trt_uart_init() is in trtUart.c
    trt_uart_init();
    stdout = stdin = stderr = &uart_str;
    fprintf(stdout,"\n\r TRT 9feb2009\n\r\n\r");

    //enable ADC and set prescaler to 1/128*16MHz=125,000
    //and clear interupt enable
    //and start a conversion
    ADCSRA = (1<<ADEN) + 7;

    // Set analog comp to connect to timer capture input
    // and turn on the band gap reference on the positive input
    ACSR =  (1<<ACIC) ; //0b01000100  ;

    //initialize Timer2 and the external interrupt
    //set up INT0
    EIMSK = 1<<INT1 ; // turn on int0
    EICRA = 1 << ISC10 ;       // trigger on any edge edge
    // turn on timer 2 to be read in int0 ISR
    TCCR2B = 7 ; // divide by 1024
    // turn on timer 2 overflow ISR for double precision time
    TIMSK2 = 1;


    //setup Timer 0
    // Set the timer for fast PWM mode, clear OC0A on Compare Match, set OC0A
    // at BOTTOM (non-inverting mode)
    TCCR0A = (1 << COM0A1) | (1 << WGM01) | (1 << WGM00); //Set the timer

    //Set the prescalar to 256 so the PWM runs at less than 1000 Hz
    TCCR0B = (1 << CS02) | (1 << CS00);

    OCR0A = 127;

    // start TRT
    trtInitKernel(128); // 80 bytes for the idle task stack

    // --- create semaphores ----------
    // You must creat the first two semaphores if you use the uart
    trtCreateSemaphore(SEM_RX_ISR_SIGNAL, 0) ; // uart receive ISR semaphore
    trtCreateSemaphore(SEM_STRING_DONE,0) ;  // user typed <enter>

    // variable protection
    trtCreateSemaphore(SEM_TEMP_REF, 1) ; // protect shared variables
    trtCreateSemaphore(SEM_TEMP, 1) ; // protect shared variables
    trtCreateSemaphore(SEM_OVERFLOW, 1) ; // protect shared variables
    trtCreateSemaphore(SEM_THICKNESS, 1) ; // protect shared variables
    trtCreateSemaphore(SEM_START_HEATING, 0) ; // protect shared variables
    trtCreateSemaphore(SEM_SONAR, 1); // Condition Variable for sonar measurement

// --- creat tasks  ----------------
    trtCreateTask(pidControl, 256, SECONDS2TICKS(0.05), SECONDS2TICKS(0.05), &(args[0]));
// trtCreateTask(serialComm, 256, SECONDS2TICKS(0.1), SECONDS2TICKS(0.1), &(args[1]));
// trtCreateTask(displayParams, 256, SECONDS2TICKS(0.1), SECONDS2TICKS(0.1), &(args[1]));
    trtCreateTask(sonar, 256, SECONDS2TICKS(0.05), SECONDS2TICKS(0.05), &(args[0]));

    sei();
    // --- Idle task --------------------------------------
    // just sleeps the cpu to save power
    // every time it executes
    set_sleep_mode(SLEEP_MODE_IDLE);
    sleep_enable();
    while (1)
    {
        sleep_cpu();
    }

} // main