// test TRT with two tasks and one mutex: // Task 1 reads the buttons (PORTB), // and blinks an LED if it owns the mutex // Task 2 reads the buttons (PORTB), // and blinks an LED if it owns the mutex #include "trtSettings.h" #include "trtkernel644.c" #include "trtMutex.c" #include #include // serial communication library // Don't mess with the semaphores #define SEM_RX_ISR_SIGNAL 1 #define SEM_STRING_DONE 2 // user hit #include "trtUart.h" #include "trtUart.c" // UART file descriptor // putchar and getchar are in uart.c FILE uart_str = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW); // semaphore to protect shared variable #define SEM_MUTEX 3 // the usual #define begin { #define end } // --- control LEDs from buttons and uart ------------------- // input arguments to each thread // not actually used in this example int args[2] ; // shared led status uint8_t led ; // --- define task 1 ---------------------------------------- void mutex1(void* args) begin uint32_t rel, dead ; uint8_t sw ; while(1) begin // read the buttons // if button 7 is pushed grab the mutex // if button 6 is pushed drop the mutex sw = ~PINB ; if (sw & (1< // resource protection trtCreateMutex(SEM_MUTEX) ; // protect shared LEDs // --- creat tasks ---------------- trtCreateTask(mutex1, 100, SECONDS2TICKS(0.1), SECONDS2TICKS(0.1), &(args[0])); trtCreateTask(mutex2, 100, SECONDS2TICKS(0.1), SECONDS2TICKS(0.1), &(args[1])); // --- Idle task -------------------------------------- // sleeps the cpu to save power // every time it executes set_sleep_mode(SLEEP_MODE_IDLE); sleep_enable(); while (1) begin sleep_cpu(); end } // main