Skip to content
Snippets Groups Projects
Commit 69108e86 authored by dylanling2's avatar dylanling2
Browse files

debut ordonnanceur

parent d18e10fc
Branches
No related tags found
No related merge requests found
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <avr/io.h> // for the input/output register
#include <util/delay.h> // for the _delay_ms
#include <avr/interrupt.h>
struct process{
int* stackPointer;
void (*ptask)(); //pointer fonction
char* state;
};
void init_timer()
{
TCCR1B |= _BV(WGM12); // CTC mode with value in OCR1A
TCCR1B |= _BV(CS12); // CS12 = 1; CS11 = 0; CS10 =1 => CLK/1024 prescaler
TCCR1B |= _BV(CS10);
OCR1A = NB_TICK;
TIMSK1 |= _BV(OCIE1A);
}
struct process process_tab[2];
process_tab[0].ptask = &task_led_green;
process_tab[1].ptask = &task_led_red;
void scheduler()
{
}
ISR(TIMER1_COMPA_vect,ISR_NAKED)
{
/* Sauvegarde du contexte de la tâche interrompue */
//PC est automatiquement mis sur la pile
//on met les registres d'etat sur la pile
#define portSAVE_CONTEXT() \
asm volatile ( \
"push r0 \n\t" \
"in r0, __SREG__ \n\t" \//push SREG
"cli \n\t" \
"push r0 \n\t" \
"push r1 \n\t" \
"clr r1 \n\t" \
"push r2 \n\t" \
"push r3 \n\t" \
"push r4 \n\t" \
"push r5 \n\t" \
"push r6 \n\t" \
"push r7 \n\t" \
"push r8 \n\t" \
"push r9 \n\t" \
"push r10 \n\t" \
"push r11 \n\t" \
"push r12 \n\t" \
"push r13 \n\t" \
"push r14 \n\t" \
"push r15 \n\t" \
"push r16 \n\t" \
"push r17 \n\t" \
"push r18 \n\t" \
"push r19 \n\t" \
"push r20 \n\t" \
"push r21 \n\t" \
"push r22 \n\t" \
"push r23 \n\t" \
"push r24 \n\t" \
"push r25 \n\t" \
"push r26 \n\t" \
"push r27 \n\t" \
"push r28 \n\t" \
"push r29 \n\t" \
"push r30 \n\t" \
"push r31 \n\t" \
);
current_process.stackPointer = SP;
/* Appel à l'ordonnanceur */
scheduler();
/* Récupération du contexte de la tâche ré-activée */
...
asm volatile ( "reti" );
}
void task_led_red(void)
{
}
void task_led_green(void)
{
}
int main()
{
process_tab[0].ptask = &task_led_green;
process_tab[1].ptask = &task_led_red;
process_tab[0].state = "sleep";
process_tab[1].state = "sleep";
init_timer();
while(1)
{
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment