From 69108e86135d2d5725f5a8f62ad552d9754b1ff1 Mon Sep 17 00:00:00 2001 From: dylanling2 <dylan.ling@polytech-lille.net> Date: Wed, 11 Oct 2023 10:56:40 +0200 Subject: [PATCH] debut ordonnanceur --- PicoShield/CarteMerePicoB6/ordonnanceur.c | 108 ++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 PicoShield/CarteMerePicoB6/ordonnanceur.c diff --git a/PicoShield/CarteMerePicoB6/ordonnanceur.c b/PicoShield/CarteMerePicoB6/ordonnanceur.c new file mode 100644 index 0000000..589ba41 --- /dev/null +++ b/PicoShield/CarteMerePicoB6/ordonnanceur.c @@ -0,0 +1,108 @@ +#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) + { + + } +} -- GitLab