Commit e873cff7eec328a612ab225a116f50af089194e2

Authored by root
1 parent 0f803f1d

application real-time ~OK (bug intermittent)

Showing 1 changed file with 33 additions and 33 deletions   Show diff stats
RIOT/examples/real_time_app/main.c
@@ -80,6 +80,7 @@ @@ -80,6 +80,7 @@
80 80
81 #define PWM_FREQ 100 81 #define PWM_FREQ 100
82 #define PWM_RES 100 82 #define PWM_RES 100
  83 +#define DEADLINE 70000
83 84
84 // addr ipv6 link local node 1: fe80::3734:510e:3317:3402 85 // addr ipv6 link local node 1: fe80::3734:510e:3317:3402
85 uint8_t node1[16]={0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x37,0x34,0x51,0x0e,0x33,0x17,0x34,0x02}; 86 uint8_t node1[16]={0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x37,0x34,0x51,0x0e,0x33,0x17,0x34,0x02};
@@ -102,6 +103,7 @@ kernel_pid_t server, client, time_server; @@ -102,6 +103,7 @@ kernel_pid_t server, client, time_server;
102 int ordre = 0; 103 int ordre = 0;
103 int64_t offset = 0; 104 int64_t offset = 0;
104 int timer_run = 0; 105 int timer_run = 0;
  106 +int tourne = 0;
105 sock_udp_ep_t local = SOCK_IPV6_EP_ANY; 107 sock_udp_ep_t local = SOCK_IPV6_EP_ANY;
106 sock_udp_t sock; 108 sock_udp_t sock;
107 sock_udp_ep_t local_ntp = SOCK_IPV6_EP_ANY; 109 sock_udp_ep_t local_ntp = SOCK_IPV6_EP_ANY;
@@ -151,7 +153,7 @@ void *sock_time_server_thread(void *arg) @@ -151,7 +153,7 @@ void *sock_time_server_thread(void *arg)
151 } 153 }
152 return NULL; 154 return NULL;
153 } 155 }
154 -void *pwm_thread(void *arg) 156 +/*void *pwm_thread(void *arg)
155 { 157 {
156 (void) arg; 158 (void) arg;
157 int tourne = 0; 159 int tourne = 0;
@@ -173,7 +175,7 @@ void *pwm_thread(void *arg) @@ -173,7 +175,7 @@ void *pwm_thread(void *arg)
173 175
174 } 176 }
175 return NULL; 177 return NULL;
176 -} 178 +}*/
177 179
178 void *sock_server_thread(void *arg) 180 void *sock_server_thread(void *arg)
179 { 181 {
@@ -190,9 +192,6 @@ void *sock_server_thread(void *arg) @@ -190,9 +192,6 @@ void *sock_server_thread(void *arg)
190 return NULL; 192 return NULL;
191 } 193 }
192 194
193 - //sntp_sync(&local,5000);  
194 - //printf("temps : %i\n",(int)sntp_get_offset());  
195 -  
196 while (1) { 195 while (1) {
197 sock_udp_ep_t remote; 196 sock_udp_ep_t remote;
198 ssize_t res; 197 ssize_t res;
@@ -211,38 +210,38 @@ void *sock_server_thread(void *arg) @@ -211,38 +210,38 @@ void *sock_server_thread(void *arg)
211 offset = sntp_get_offset(); 210 offset = sntp_get_offset();
212 deadline = xtimer_now_usec() + offset - buf.heure_actuelle; 211 deadline = xtimer_now_usec() + offset - buf.heure_actuelle;
213 printf("tps de transmission : %i\n",deadline); 212 printf("tps de transmission : %i\n",deadline);
214 - printf("compteur : %d\n",compteur);  
215 - if(deadline<=70000 && compteur >=5)  
216 - {  
217 - ordre = 1;  
218 - timer_clear(TIMER_DEV(1),0);  
219 - }  
220 - else if(deadline<=70000 && (ordre == 2 || ordre ==0))  
221 - {  
222 - compteur++;  
223 - }  
224 - else 213 +
  214 + if(deadline >= DEADLINE && compteur >=5)
225 { 215 {
226 - ordre = 2; 216 + //ordre = 2;
227 compteur = 0; 217 compteur = 0;
  218 + if(tourne == 1)
  219 + pwm_set(PWM_DEV(0),1,31);
228 if(timer_run == 0) 220 if(timer_run == 0)
229 { 221 {
230 timer_set(TIMER_DEV(1),0,25200); 222 timer_set(TIMER_DEV(1),0,25200);
  223 + printf("relance timer\n");
231 timer_run = 1; 224 timer_run = 1;
232 } 225 }
233 } 226 }
234 -  
235 - /*if(strcmp((char *)buf,"go")==0)  
236 - {  
237 - ordre = 1;  
238 - timer_set(XTIMER_DEV,0,8400);  
239 - timer_clear(TIMER_DEV(1),0);  
240 - }  
241 - else  
242 - {  
243 - ordre = 0;  
244 - }  
245 - }*/ 227 + if(deadline >= DEADLINE && compteur < 5)
  228 + {
  229 + compteur = 0;
  230 + }
  231 + if(deadline<=DEADLINE && compteur >=5)
  232 + {
  233 + //ordre = 1;
  234 + pwm_set(PWM_DEV(0),1,45);
  235 + tourne = 1;
  236 + timer_clear(TIMER_DEV(1),0);
  237 + printf("clear timer\n");
  238 + }
  239 + if(deadline<=DEADLINE && compteur <5)
  240 + {
  241 + compteur++;
  242 + }
  243 +
  244 + printf("compteur : %d\n",compteur);
246 memset(&buf,0,sizeof(buf)); 245 memset(&buf,0,sizeof(buf));
247 } 246 }
248 } 247 }
@@ -274,15 +273,16 @@ void *sock_client_thread(void *arg) @@ -274,15 +273,16 @@ void *sock_client_thread(void *arg)
274 if (sock_udp_send(NULL, &data, sizeof(data), &remote) < 0) { 273 if (sock_udp_send(NULL, &data, sizeof(data), &remote) < 0) {
275 puts("Error sending message"); 274 puts("Error sending message");
276 } 275 }
277 - xtimer_sleep(1); 276 + xtimer_sleep(2);
278 } 277 }
279 return NULL; 278 return NULL;
280 } 279 }
281 280
282 static void arret_urgence(void *arg,int channel) 281 static void arret_urgence(void *arg,int channel)
283 { 282 {
284 - //pwm_set(PWM_DEV(0),1,0);  
285 - ordre=0; 283 + pwm_set(PWM_DEV(0),1,0);
  284 + tourne = 0;
  285 + //ordre=0;
286 timer_run = 0; 286 timer_run = 0;
287 printf("Arret d'urgence\n"); 287 printf("Arret d'urgence\n");
288 } 288 }
@@ -310,7 +310,7 @@ static void _init_pwm(void) @@ -310,7 +310,7 @@ static void _init_pwm(void)
310 pwm_init(PWM_DEV(0), PWM_LEFT, PWM_FREQ, PWM_RES); 310 pwm_init(PWM_DEV(0), PWM_LEFT, PWM_FREQ, PWM_RES);
311 pwm_set(PWM_DEV(0),1,0); 311 pwm_set(PWM_DEV(0),1,0);
312 312
313 - thread_create(pwm_stack,sizeof(pwm_stack),8,THREAD_CREATE_STACKTEST,pwm_thread,NULL,"pwm_thread"); 313 +// thread_create(pwm_stack,sizeof(pwm_stack),7,THREAD_CREATE_STACKTEST,pwm_thread,NULL,"pwm_thread");
314 } 314 }
315 315
316 316