Dear all,

Iam trying to communicate two process using message . In one process i
called a dummy function (doing nothing except printing something for 2000
times) .

Iam trying to calculate the time elapsed for this process to process
communication .

1. The program working fine if i print or execute something for once  like
rt_printf("xenomai"); But if i used

for (i=0; i<2000; i++)

{

rt_printf("xenomai");

}

if i used like this the execution stops after printing for some 100 times or
so on my Pandaboard.  Please find the attached program.


Thanks
Suresh balijepalli
Rosenehim,Baveria.
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <sys/mman.h>
#include <stdlib.h>
 
#include <native/task.h>
#include <native/timer.h>
#include <native/sem.h>
#include <native/mutex.h>
#include <native/queue.h>
 
#include  <rtdk.h>
 
#define NTASKS 2
 
#define QUEUE_SIZE 255
#define MAX_MESSAGE_LENGTH 40
 
RT_TASK task_struct[NTASKS];
 
#define QUEUE_SIZE 255
RT_QUEUE myqueue;
RT_QUEUE myqueue1;
double timed_delay = 0;

 int processing(void)
 {
     int k=0;/*k=0,i=3000;
     char * buffer;
     char a='a' ;
 dummy operation*/
rt_printf("xenomai");

return k;
}

void taskOne(void *arg)
{
    int retval,retval1,t1;
    char message[] = "Message from taskOne";
    char msgBuf1[MAX_MESSAGE_LENGTH];
    RTIME start_tsc = rt_timer_tsc();
    rt_printf("starting tics: %.3f\n",
    rt_timer_tsc2ns(start_tsc)*1e-6);
    /* send message */
    
    retval = rt_queue_write(&myqueue,message,sizeof(message),Q_NORMAL);
 
    if (retval < 0 ) {
       rt_printf("Sending error\n");
    } else {
       rt_printf("taskOne sent message to mailbox\n");
    } 

/* receive message */

retval1 =rt_queue_read(&myqueue1,msgBuf1,sizeof(msgBuf1),TM_INFINITE);
    if (retval1 < 0 ) {
          rt_printf("Receiving error\n");
    } else {
        rt_printf("task1 received message: %s\n",msgBuf1);
        rt_printf("with length %d\n",retval1);
    }
t1=processing();
    rt_printf("%d",t1);
RTIME tsc=rt_timer_tsc();
rt_printf("end tics: %.3f\n",
rt_timer_tsc2ns(tsc)*1e-6);
/*rt_printf("end tics: %.3f\n",
rt_timer_tsc2ns(tsc)*1e-6);
rt_printf(" time taken: %.3f\n",
rt_timer_ns2tsc(0.55)*1e-6);*/
timed_delay = rt_timer_tsc2ns(tsc-start_tsc)*1e-9;	
rt_printf(" %.3f ms\n",
 timed_delay * 1e3);	
}
 
void taskTwo(void *arg)
{
    
     int retval,retval1;
     char msgBuf[MAX_MESSAGE_LENGTH];
     char message1[] = "Message from tasktwo";
     

/* receive message */
    retval = rt_queue_read(&myqueue,msgBuf,sizeof(msgBuf),TM_INFINITE);
    if (retval < 0 ) {
          rt_printf("Receiving error\n");
    } else {
        rt_printf("taskTwo received message: %s\n",msgBuf);
        rt_printf("with length %d\n",retval);
    } 
/* send message */
    retval1 = rt_queue_write(&myqueue1,message1,sizeof(message1),Q_NORMAL);

    if (retval1 < 0 ) {
       rt_printf("Sending error\n");
    } else {
       rt_printf("tasktwo sent message to mailbox\n");
       }

     
}
 
//startup code
void startup()
{
  int i,t1;
  char  str[10] ;
 
  void (*task_func[NTASKS]) (void *arg);
  task_func[0]=taskOne;
  task_func[1]=taskTwo;
 
  rt_queue_create(&myqueue,"myqueue",QUEUE_SIZE,10,Q_FIFO);
  rt_queue_create(&myqueue1,"myqueue1",QUEUE_SIZE,10,Q_FIFO); 
  rt_timer_set_mode(0);// set timer to tick in nanoseconds and not in jiffies
  for(i=0; i < NTASKS; i++) {
    rt_printf("start task  : %d\n",i);
    sprintf(str,"task%d",i);
    rt_task_create(&task_struct[i], str, 0, 50, 0);
    rt_task_start(&task_struct[i], task_func[i], &i);
    
  }
}
 
void init_xenomai() {
  /* Avoids memory swapping for this program */
  mlockall(MCL_CURRENT|MCL_FUTURE);
 
  /* Perform auto-init of rt_print buffers if the task doesn't do so */
  rt_print_auto_init(1);
}
 
int main(int argc, char* argv[])
{
  printf("\nType CTRL-C to end this program\n\n" );
 
  // code to set things to run xenomai
  init_xenomai();
 
  //startup code
  startup();
 
  pause();
}
_______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help

Reply via email to