This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
lab8 [2015/12/08 17:43] dan.tudose |
lab8 [2018/11/16 08:22] (current) dan.tudose [Instalare si configurare] |
||
|---|---|---|---|
| Line 10: | Line 10: | ||
| Biblioteca o puteti descarca de {{: | Biblioteca o puteti descarca de {{: | ||
| + | |||
| + | Un exemplu de folosire a bibliotecii il aveti in exemplul de mai jos: | ||
| + | |||
| + | <code C> | ||
| + | #include < | ||
| + | |||
| + | spinlock_t testLock; | ||
| + | |||
| + | // Create instance of OS multitasker | ||
| + | AVR_OS os = AVR_OS(); | ||
| + | |||
| + | // Define task 1 | ||
| + | void task1(void *arg) { | ||
| + | | ||
| + | |||
| + | while(1) { | ||
| + | os.spinlock_acquire(& | ||
| + | Serial.println(" | ||
| + | os.spinlock_release(& | ||
| + | os.os_sleep(10000); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | // Define task 2 | ||
| + | void task2(void *arg) { | ||
| + | int x = 0; | ||
| + | uint8_t val = 0; | ||
| + | while(1) { | ||
| + | |||
| + | os.spinlock_acquire(& | ||
| + | Serial.println(" | ||
| + | os.spinlock_release(& | ||
| + | os.os_sleep(1000); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | // Define task 3 | ||
| + | void task3(void *arg) { | ||
| + | while(1) { | ||
| + | os.spinlock_acquire(& | ||
| + | Serial.println(" | ||
| + | os.spinlock_release(& | ||
| + | os.os_sleep(15000); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | void setup() { | ||
| + | |||
| + | Serial.begin(115200); | ||
| + | Serial.println(" | ||
| + | |||
| + | os.spinlock_init(& | ||
| + | |||
| + | os.os_schedule_task(task1, | ||
| + | os.os_schedule_task(task2, | ||
| + | os.os_schedule_task(task3, | ||
| + | } | ||
| + | |||
| + | void loop() { | ||
| + | os.os_loop(); | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | Task-urile sunt declarate ca functii apoi inscrise in planificator la initializare, | ||
| + | |||
| + | < | ||
| + | < | ||
| + | < | ||