Commit d8927986803e847c9916570d9b35c99ed592c681
1 parent
6601d4de
test ordonnanceur concluant
Showing
1 changed file
with
70 additions
and
20 deletions
Show diff stats
tests/atmega2560/ordonanceur/ordonanceur.c
@@ -84,10 +84,49 @@ asm volatile ( \ | @@ -84,10 +84,49 @@ asm volatile ( \ | ||
84 | "pop r0 \n\t" \ | 84 | "pop r0 \n\t" \ |
85 | ); | 85 | ); |
86 | 86 | ||
87 | +/** Configure les ports */ | ||
88 | +void init_ports(){ | ||
89 | + //TODO DDRXs | ||
90 | +} | ||
91 | + | ||
92 | +/** ----- Liaison serie ----- */ | ||
93 | +void init_serial(int speed){ | ||
94 | + UBRR0 = CPU_FREQ/(((unsigned long int)speed)<<4)-1; //Set baud rate | ||
95 | + UCSR0B = (1<<TXEN0 | 1<<RXEN0); //Enable transmitter & receiver | ||
96 | + UCSR0C = (1<<UCSZ01 | 1<<UCSZ00); //Set 8 bits character and 1 stop bit | ||
97 | + UCSR0A &= ~(1 << U2X0); //Set off UART baud doubler | ||
98 | +} | ||
99 | +void send_serial(unsigned char c){ | ||
100 | + loop_until_bit_is_set(UCSR0A, UDRE0); | ||
101 | + UDR0 = c; | ||
102 | +} | ||
103 | +unsigned char get_serial(void){ | ||
104 | + loop_until_bit_is_set(UCSR0A, RXC0); | ||
105 | + return UDR0; | ||
106 | +} | ||
107 | + | ||
108 | +/** ----- Taches ----- */ | ||
109 | +void task_print_a(void){ | ||
110 | + while(1){ | ||
111 | + send_serial('a'); | ||
112 | + _delay_ms(1000); | ||
113 | + } | ||
114 | +} | ||
115 | +void task_print_b(void){ | ||
116 | + while(1){ | ||
117 | + send_serial('b'); | ||
118 | + _delay_ms(700); | ||
119 | + } | ||
120 | +} | ||
121 | + | ||
122 | +/** ----- Ordonnancement ----- */ | ||
87 | struct task{ | 123 | struct task{ |
88 | uint16_t sp_vise; | 124 | uint16_t sp_vise; |
89 | - uint8_t state; | ||
90 | }; | 125 | }; |
126 | +uint8_t cpt = 0; | ||
127 | +uint8_t premier_lancement = 0; | ||
128 | +struct task print_a = {0x0300}; | ||
129 | +struct task print_b = {0x0500}; | ||
91 | 130 | ||
92 | /** Démarre le timer pour l'ordonnancement */ | 131 | /** Démarre le timer pour l'ordonnancement */ |
93 | void init_timer(){ | 132 | void init_timer(){ |
@@ -97,32 +136,43 @@ void init_timer(){ | @@ -97,32 +136,43 @@ void init_timer(){ | ||
97 | OCR1A = NB_TICK; | 136 | OCR1A = NB_TICK; |
98 | TIMSK1 |= _BV(OCIE1A); | 137 | TIMSK1 |= _BV(OCIE1A); |
99 | } | 138 | } |
100 | - | ||
101 | -/** Configure les ports */ | ||
102 | -void init_ports(){ | ||
103 | - //TODO DDRXs | ||
104 | -} | ||
105 | - | ||
106 | -/** Alumme la LED 13 pour témoigné du bon fonctionnement de la carte */ | ||
107 | -void temoin_allumage(){ | ||
108 | - DDRA = 0x01; | ||
109 | - PORTA = 0x01; | ||
110 | - _delay_ms(500); | ||
111 | - PORTA = 0x00; | ||
112 | -} | ||
113 | - | ||
114 | -/** Reception de l'interruption généré par le timer (changement de contexte) */ | 139 | +/** Changement de contexte */ |
115 | ISR(TIMER1_COMPA_vect){ | 140 | ISR(TIMER1_COMPA_vect){ |
116 | - // TODO | 141 | + if(premier_lancement == 0){ |
142 | + premier_lancement++; | ||
143 | + sei(); | ||
144 | + SP = print_a.sp_vise; | ||
145 | + task_print_a(); | ||
146 | + }else if(premier_lancement == 1){ | ||
147 | + SAVE_CONTEXT(); | ||
148 | + print_a.sp_vise = SP; | ||
149 | + premier_lancement++; | ||
150 | + sei(); | ||
151 | + SP = print_b.sp_vise; | ||
152 | + task_print_b(); | ||
153 | + }else{ | ||
154 | + if(cpt==0){ | ||
155 | + SAVE_CONTEXT(); | ||
156 | + print_b.sp_vise = SP; | ||
157 | + SP = print_a.sp_vise; | ||
158 | + RESTORE_CONTEXT(); | ||
159 | + cpt++; | ||
160 | + }else if(cpt==1){ | ||
161 | + SAVE_CONTEXT(); | ||
162 | + print_a.sp_vise = SP; | ||
163 | + SP = print_b.sp_vise; | ||
164 | + RESTORE_CONTEXT(); | ||
165 | + cpt = 0; | ||
166 | + } | ||
167 | + } | ||
117 | sei(); | 168 | sei(); |
118 | } | 169 | } |
119 | 170 | ||
120 | int main(void){ | 171 | int main(void){ |
121 | - temoin_allumage(); | ||
122 | - | ||
123 | // Initialisation | 172 | // Initialisation |
124 | init_timer(); | 173 | init_timer(); |
125 | - init_port(); | 174 | + init_ports(); |
175 | + init_serial(9600); | ||
126 | sei(); | 176 | sei(); |
127 | 177 | ||
128 | while(1){} | 178 | while(1){} |