Projekte
workwind
Multitasking optimiert
scheduler.S
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/scheduler.S [read only]
#include <avr/io.h> /* Context: | IDLE | normal | register | | IRQ | FN | ---------+------+-----+----+ PC lo | * | * | * | PC hi | * | * | * | ---------+------+-----+----+ r24 | * | * | * | SREG | * | * | * | ---------+------+-----+----+ MCUCR | * | | | ---------+------+-----+----+ r0 | | * | | r1 | | * | | RAMPZ | | * | | (only AVR >64 kFlash) r31 | | * | | r30 | | * | | r27 | | * | | r26 | | * | | r25 | | * | | r23 | | * | | r22 | | * | | r21 | | * | | r20 | | * | | r19 | | * | | r18 | | * | | ---------+------+-----+----+ r29 | | * | * | r28 | | * | * | r17 | | * | * | r16 | | * | * | r15 | | * | * | r14 | | * | * | r13 | | * | * | r12 | | * | * | r11 | | * | * | r10 | | * | * | r9 | | * | * | r8 | | * | * | r7 | | * | * | r6 | | * | * | r5 | | * | * | r4 | | * | * | r3 | | * | * | r2 | | * | * | ---------+------+-----+----+ status | * | * | * | ---------+------+-----+----+ */ #define SCHEDULER_IS_IDLE 0 #define SCHEDULER_HAS_NEXT 1 #define SCHEDULER_FROM_IRQ 2 #define SCHEDULER_TIMER 3 .section .text .global scheduler_yield .global scheduler_irq .global scheduler_timer .global scheduler_idle .extern scheduler_status /* uint8_t thread_selectNext(uint8_t status); */ /* uint8_t thread_handleTimer(uint8_t status); */ .extern thread_selectNext .extern thread_handleTimer scheduler_idle: sleep; rjmp scheduler_idle; // called from thread_xxx() funktion (called by jsr) // stack must only contain the return address scheduler_yield: push r24 in r24, _SFR_IO_ADDR(SREG) push r24 lds r24, scheduler_status rjmp check_first // generic interrupt function (called by jmp) // stack must only contain the return address scheduler_irq: push r24 in r24, _SFR_IO_ADDR(SREG) push r24 lds r24, scheduler_status sbr r24, _BV(SCHEDULER_FROM_IRQ) rjmp check_first // timer interrupt function (called directly or by jmp) // stack must only contain the return address scheduler_timer: push r24 in r24, _SFR_IO_ADDR(SREG) push r24 lds r24, scheduler_status sbr r24, _BV(SCHEDULER_FROM_IRQ) sbr r24, _BV(SCHEDULER_TIMER) check_first: sbrc r24, SCHEDULER_IS_IDLE rjmp store_idle sbrc r24, SCHEDULER_FROM_IRQ rjmp store_clobber rjmp store_clobber_skip store_idle: in r0, _SFR_IO_ADDR(MCUCR) push r0 clr r0 out _SFR_IO_ADDR(MCUCR), r0 rjmp store_clobber_skip store_clobber: push r0 push r1 clr r1 #ifdef RAMPZ in r0, _SFR_IO_ADDR(RAMPZ) push r0 #endif push r31 push r30 push r27 push r26 push r25 // r24 push r23 push r22 push r21 push r20 push r19 push r18 store_clobber_skip: call_functions: sbrc r24, SCHEDULER_TIMER call thread_handleTimer cbr r24, _BV(SCHEDULER_TIMER) sbrs r24, SCHEDULER_HAS_NEXT call thread_selectNext sbrc r24, SCHEDULER_HAS_NEXT rjmp store_called /* we don't need to switch */ sbrc r24, SCHEDULER_IS_IDLE rjmp restore_idle sbrs r24, SCHEDULER_FROM_IRQ rjmp restore_clobber_skip rjmp restore_clobber /* we really need a task switch */ store_called: cbr r24, _BV(SCHEDULER_HAS_NEXT) /* clear next Flag*/ sbrc r24, SCHEDULER_IS_IDLE /* store called only if not idle thread */ rjmp store_called_skip push r29 push r28 push r17 push r16 push r15 push r14 push r13 push r12 push r11 push r10 push r9 push r8 push r7 push r6 push r5 push r4 push r3 push r2 store_called_skip: store_stackpointer: push r24 /* store scheduler status */ lds r30, running_thread+0 lds r31, running_thread+1 in r16, _SFR_IO_ADDR(SPL) in r17, _SFR_IO_ADDR(SPH) std Z+10, r16 std Z+11, r17 /* now we should switch the running_thread... */ switch_task: lds r30, next_thread+0 lds r31, next_thread+1 sts running_thread+0, r30 sts running_thread+1, r31 restore_stackpointer: /* r30 and r31 are already loaded */ ldd r16, Z+10 ldd r17, Z+11 out _SFR_IO_ADDR(SPL), r16 out _SFR_IO_ADDR(SPH), r17 pop r24 /* restore scheduler status */ sbrc r24, SCHEDULER_IS_IDLE /* restore called only if not idle thread */ rjmp restore_idle restore_called: pop r2 pop r3 pop r4 pop r5 pop r6 pop r7 pop r8 pop r9 pop r10 pop r11 pop r12 pop r13 pop r14 pop r15 pop r16 pop r17 pop r28 pop r29 restore_called_skip: sbrs r24, SCHEDULER_FROM_IRQ rjmp restore_clobber_skip rjmp restore_clobber /* we don't need to switch and we are the idle task */ restore_idle: pop r0 out _SFR_IO_ADDR(MCUCR), r0 rjmp restore_urgent restore_clobber: pop r18 pop r19 pop r20 pop r21 pop r22 pop r23 // r24 pop r25 pop r26 pop r27 pop r30 pop r31 #ifdef RAMPZ pop r0 out _SFR_IO_ADDR(RAMPZ), r0 #endif pop r1 pop r0 restore_clobber_skip: restore_urgent: sbrc r24, SCHEDULER_FROM_IRQ rjmp restore_urgentIRQ sts scheduler_status, r24 pop r24 out _SFR_IO_ADDR(SREG),r24 pop r24 ret restore_urgentIRQ: cbr r24, _BV(SCHEDULER_FROM_IRQ) sts scheduler_status, r24 pop r24 out _SFR_IO_ADDR(SREG),r24 pop r24 reti
Compiler results:
Werbung
Online
charlesvallejos297
FloKre
frederickajustice19
hopewyman5990749
jnplatesha8912130544
kaceywinters6603326
scotcornett35376
wthjohnson00956