// --- 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 } }
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(); } }