Projekte
workwind
Multitasking 1
main.c
Projekte
Forum
Doku
Öffentliche Projekte
Startseite
Beispielprogramme
Projekte von anderen
Welcome
Username
Passwort
Eingeloggt bleiben
Zugangsdaten vergessen?
Registrieren
Projektverwaltung
⇨ Please choose! ⇦
——————————————————
✎ Create new project...
★ Browse existing projects...
——————————————————
⚬ MotorTest#1
⚬ C Tutorial 8#1
⚬ NIBO2 C Project#1
⚙ C Tutorial 15#1
⚬ 2010_11_18_el_test001#1
Multitasking 1
cdll.c
cdll.h
main.c
scheduler.S
thread.c
thread.h
Project details
Compiler settings
Nachrichten
Sie sind nicht eingeloggt.
Neuigkeiten
★
NiboRoboLib 3.6
2017-01-17: Neue Version 3.6
★
NiboRoboLib 3.4.1
2016-04-16: Neue Version 3.4.1
★
Coding Tutorial
2015-11-22: Jetzt auch für den NIBO burger!
Site-Statistic
7433 private projects
378 public projects
16180353 lines compiled
58212 builds
NIBO
@
multitasking_1/main.c [read only]
#include <nibo/niboconfig.h> #include <nibo/leds.h> #include <avr/interrupt.h> #include "thread.h" /* zum Testen setzen wir die Ticks auf 100 Hz (10ms) ThreadA blinkt alle 0.5 sec ThreadB blinkt alle 0.3 sec ThreadC wartet auf ein Signal und blinkt 1.0 sec auf Das Signal wird vom einem Interrupt geschickt */ #define MS_TO_TICKS(ms) (ms/10) thread_t threadA; thread_t threadB; thread_t threadC; uint8_t stackA[256]; uint8_t stackB[256]; uint8_t stackC[256]; uint8_t tastenStatus; // system ticks for scheduler ISR(TIMER3_COMPA_vect, ISR_NAKED) { __asm__ volatile ("jmp scheduler_timer"); } // normaler IRQ ISR(TIMER0_OVF_vect) { uint8_t v = PIND & _BV(4); if (v != tastenStatus) { tastenStatus = v; if (v==0) { thread_signalISR(&threadC); } } } void threadMainA (void * arg) { while (true) { PORTE |= _BV(3); thread_waitTimeout(MS_TO_TICKS(500)); PORTE &= ~_BV(3); thread_waitTimeout(MS_TO_TICKS(500)); } } void threadMainB (void * arg) { while (true) { PORTE |= _BV(4); thread_waitTimeout(MS_TO_TICKS(300)); PORTE &= ~_BV(4); thread_waitTimeout(MS_TO_TICKS(300)); } } void threadMainC (void * arg) { while (true) { PORTE &= ~_BV(5); thread_wait(); PORTE |= _BV(5); thread_waitTimeout(MS_TO_TICKS(1000)); } } int main() { leds_init(); // setup Timer 3: 100 Hz OCR3A = ((F_CPU/64)/100)-1; TCCR3B = _BV(WGM32) | _BV(CS31) | _BV(CS30); ETIMSK |= _BV(OCIE3A); // setup Timer 0 -> slow.... TCCR0 = _BV(CS02) | _BV(CS01) | _BV(CS00); TIMSK |= _BV(TOV0); thread_create(&threadA, stackA, 256, 0); thread_create(&threadB, stackB, 256, 0); thread_create(&threadC, stackC, 256, 0); // diesen thread als mainThread initialisieren und den scheduler starten: thread_startScheduler(0); // jetzt läuft 1 Thread: // threadMain thread_start(&threadA, &threadMainA, 0); thread_start(&threadB, &threadMainB, 0); thread_start(&threadC, &threadMainC, 0); thread_signal(&threadA); thread_signal(&threadB); thread_signal(&threadC); // jetzt laufen 3 Threads: // threadMain // threadA // threadB while (true) { thread_wait(); } }
Compiler results:
Werbung
Online
christenacrow193023
deloresgoodin345909
francescapasso764
iolabellew89408370
mohammadspeckman039