Projekte
workwind
Multitasking optimiert
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
Multitask...optimiert
cdll.c
cdll.h
condition.c
condition.h
main.c
mutex.c
mutex.h
scheduler.S
semaphore.c
semaphore.h
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
7426 private projects
385 public projects
16180353 lines compiled
58212 builds
NIBO
@
multitasking_opt/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(); // Timer Formel: // // (TOP+1) * F * PS = F_CPU // // F: Frequenz des Interrupts // PS: Prescaler des Timers // F_CPU: Systemtakt // Normal Mode: // Interrupt : TOVx (Timer Overflow) / TIMERx_OVF_vect // TOP: 0xff==255 für 8 Bit Timer // 0xffff==65535 für 16 Bit Timer // CTC Mode: // Interrupt : OCx (Output Compare) / TIMERx_COMP_vect // TOP: OCRx Register // setup Timer 3: 100 Hz // 16 Bit Timer, Prescaler 64, CTC Mode OCR3A = ((F_CPU/64)/100)-1; TCCR3B = _BV(WGM32) | _BV(CS31) | _BV(CS30); ETIMSK |= _BV(OCIE3A); // setup Timer 0: So langsam wie möglich.... // 8 Bit Timer, Prescaler 1024, Normal Mode // resultierende Freqquenz bei 16MHz Systemtakt: 61.035 Hz TCCR0 = _BV(CS02) | _BV(CS01) | _BV(CS00); TIMSK |= _BV(TOV0); thread_init(&threadA, stackA, 256, 0); thread_init(&threadB, stackB, 256, 0); thread_init(&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
dtsjada1842883129
elidabaylee669745
giahill891542995
janinalomax603906209