From e873cff7eec328a612ab225a116f50af089194e2 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 1 Feb 2017 14:25:56 +0100 Subject: [PATCH] application real-time ~OK (bug intermittent) --- RIOT/examples/real_time_app/main.c | 66 +++++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/RIOT/examples/real_time_app/main.c b/RIOT/examples/real_time_app/main.c index 419d36d..45289ff 100644 --- a/RIOT/examples/real_time_app/main.c +++ b/RIOT/examples/real_time_app/main.c @@ -80,6 +80,7 @@ #define PWM_FREQ 100 #define PWM_RES 100 +#define DEADLINE 70000 // addr ipv6 link local node 1: fe80::3734:510e:3317:3402 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; int ordre = 0; int64_t offset = 0; int timer_run = 0; +int tourne = 0; sock_udp_ep_t local = SOCK_IPV6_EP_ANY; sock_udp_t sock; sock_udp_ep_t local_ntp = SOCK_IPV6_EP_ANY; @@ -151,7 +153,7 @@ void *sock_time_server_thread(void *arg) } return NULL; } -void *pwm_thread(void *arg) +/*void *pwm_thread(void *arg) { (void) arg; int tourne = 0; @@ -173,7 +175,7 @@ void *pwm_thread(void *arg) } return NULL; -} +}*/ void *sock_server_thread(void *arg) { @@ -190,9 +192,6 @@ void *sock_server_thread(void *arg) return NULL; } - //sntp_sync(&local,5000); - //printf("temps : %i\n",(int)sntp_get_offset()); - while (1) { sock_udp_ep_t remote; ssize_t res; @@ -211,38 +210,38 @@ void *sock_server_thread(void *arg) offset = sntp_get_offset(); deadline = xtimer_now_usec() + offset - buf.heure_actuelle; printf("tps de transmission : %i\n",deadline); - printf("compteur : %d\n",compteur); - if(deadline<=70000 && compteur >=5) - { - ordre = 1; - timer_clear(TIMER_DEV(1),0); - } - else if(deadline<=70000 && (ordre == 2 || ordre ==0)) - { - compteur++; - } - else + + if(deadline >= DEADLINE && compteur >=5) { - ordre = 2; + //ordre = 2; compteur = 0; + if(tourne == 1) + pwm_set(PWM_DEV(0),1,31); if(timer_run == 0) { timer_set(TIMER_DEV(1),0,25200); + printf("relance timer\n"); timer_run = 1; } } - - /*if(strcmp((char *)buf,"go")==0) - { - ordre = 1; - timer_set(XTIMER_DEV,0,8400); - timer_clear(TIMER_DEV(1),0); - } - else - { - ordre = 0; - } - }*/ + if(deadline >= DEADLINE && compteur < 5) + { + compteur = 0; + } + if(deadline<=DEADLINE && compteur >=5) + { + //ordre = 1; + pwm_set(PWM_DEV(0),1,45); + tourne = 1; + timer_clear(TIMER_DEV(1),0); + printf("clear timer\n"); + } + if(deadline<=DEADLINE && compteur <5) + { + compteur++; + } + + printf("compteur : %d\n",compteur); memset(&buf,0,sizeof(buf)); } } @@ -274,15 +273,16 @@ void *sock_client_thread(void *arg) if (sock_udp_send(NULL, &data, sizeof(data), &remote) < 0) { puts("Error sending message"); } - xtimer_sleep(1); + xtimer_sleep(2); } return NULL; } static void arret_urgence(void *arg,int channel) { - //pwm_set(PWM_DEV(0),1,0); - ordre=0; + pwm_set(PWM_DEV(0),1,0); + tourne = 0; + //ordre=0; timer_run = 0; printf("Arret d'urgence\n"); } @@ -310,7 +310,7 @@ static void _init_pwm(void) pwm_init(PWM_DEV(0), PWM_LEFT, PWM_FREQ, PWM_RES); pwm_set(PWM_DEV(0),1,0); - thread_create(pwm_stack,sizeof(pwm_stack),8,THREAD_CREATE_STACKTEST,pwm_thread,NULL,"pwm_thread"); +// thread_create(pwm_stack,sizeof(pwm_stack),7,THREAD_CREATE_STACKTEST,pwm_thread,NULL,"pwm_thread"); } -- libgit2 0.21.2