Exemplo n.º 1
0
Arquivo: tbx1.c Projeto: ArcEye/RTAI
static void Task4(long t)
{
	int wakedup;
    
	rt_printk("\nTask4 (%p) starting\n", rt_whoami());
	while (count < MAXCOUNT) {
		count++;
		wakedup = rt_tbx_broadcast(&bx, msg2, sizeof(msg2));
		rt_printk("\nTask4=%lu, sending broadcast, wakedup=%d\n", count, wakedup);
		rt_sleep(nano2count(DELAY + SHIFT));
	}
	rt_printk("\nTask4 suspends itself\n");
	rt_task_suspend(rt_whoami());
}                                        
Exemplo n.º 2
0
Arquivo: tbx1.c Projeto: ArcEye/RTAI
static void Task1(long t)
{
	int unsent;
    
	rt_printk("\nTask1 (%p) starting\n", rt_whoami());
	while (count < MAXCOUNT) {
		count++;
		unsent = rt_tbx_send(&bx, msg1, sizeof(msg1));
		rt_printk("\nTask1=%lu, simple sending, unsent=%d %d\n", count, unsent, sizeof(msg1));
		rt_sleep(nano2count(DELAY));
	}
	rt_printk("\nTask1 suspends itself\n");
	rt_task_suspend(rt_whoami());
}                                        
Exemplo n.º 3
0
Arquivo: tbx1.c Projeto: ArcEye/RTAI
static void Task7(long t)
{
	int unsent;
    
	rt_printk("\nTask7 (%p) starting\n", rt_whoami());
	while (count < MAXCOUNT) {
		count++;
		unsent = rt_tbx_urgent(&bx, msg3, sizeof(msg3));
		rt_printk("\nTask7=%lu, urgent sending, unsent=%d\n", count, unsent);
		rt_sleep(nano2count(3*DELAY + 2*SHIFT));
	}
	rt_printk("\nTask7 suspends itself\n");
	cleanup = 1;
	rt_task_suspend(rt_whoami());
}       
Exemplo n.º 4
0
int rt_tbx_receive_until(TBX *tbx, void *msg, int msg_size, RTIME time)
{
	unsigned char type = TYPE_NONE, lock = 0;
	char* temp;
	RT_TASK *rt_current;

	CHK_TBX_MAGIC;
	if ((msg_size + sizeof(type)) > tbx->size) {
		return -EMSGSIZE;
	}
	if (tbx_smx_wait_until(tbx, &(tbx->rcvsmx), time, rt_current = rt_whoami())) {
		return msg_size;
	}
	temp = msg;
	if (tbx_wait_msg_until(tbx, &tbx->avbs, msg_size + sizeof(type), time, &type, rt_current)) {
		tbx_smx_signal(tbx, &(tbx->rcvsmx));
		return msg_size;
	}
	tbx_receive_core(tbx, msg, &msg_size, type, &lock);
	tbx_signal(tbx);
	tbx_smx_signal(tbx, &(tbx->rcvsmx));
	if(lock == 1) {
		rt_sem_wait(&(tbx->bcbsmx));
	}
	return msg_size;
}
Exemplo n.º 5
0
static void driver(int t)
{
	RT_TASK *thread[NTASKS];
	int i, l;
	unsigned int msg = 0;
	RTIME now;

	for (i = 1; i < NTASKS; i++) {
		thread[0] = rt_receive(0, &msg);
		thread[msg] = thread[0];
	}
	for (i = 1; i < NTASKS; i++) {
		rt_return(thread[i], i);
	}
	now = rt_get_time();
	rt_task_make_periodic(rt_whoami(), now + NTASKS*tick_period, tick_period);

	msg = 0;
	l = LOOPS;
	while(l--) {
		for (i = 1; i < NTASKS; i++) {
			cpu_used[hard_cpu_id()]++;
			if (i%2) {
				rt_rpc(thread[i], msg, &msg);
			} else {
				rt_send(thread[i], msg);
				msg = 1 - msg;
			}
			rt_task_wait_period();
		}
	}
	for (i = 1; i < NTASKS; i++) {
		rt_send(thread[i], END);
	}
}
Exemplo n.º 6
0
int rt_tbx_broadcast_until(TBX *tbx, void *msg, int msg_size, RTIME time)
{
	unsigned char type = TYPE_BROADCAST; 
	int wakedup;
	RT_TASK *rt_current;
    
	CHK_TBX_MAGIC;
	if ((msg_size + sizeof(type)) > tbx->size) {
        	return -EMSGSIZE;
	}
	wakedup = tbx->waiting_nr;
	if (wakedup == 0) {
        	return wakedup;
	}
	if (tbx_smx_wait_until(tbx, &(tbx->sndsmx), time, rt_current = rt_whoami())) {
		return 0;
	}
	if (tbx_wait_room_until(tbx, &tbx->frbs, (msg_size + sizeof(type)), time, rt_current)) {
		tbx_smx_signal(tbx, &(tbx->sndsmx));
		return 0;
	}
	msg_size = tbxput(tbx, (char **)(&msg), msg_size, type);
	tbx_signal(tbx);
	tbx_smx_signal(tbx, &(tbx->sndsmx));
	return wakedup;
}
Exemplo n.º 7
0
Arquivo: tbx3.c Projeto: cjecho/RTAI
static void Task1(long t)
{
	int unsent;
	MSG msg;

	rt_printk("\nTask1 (%p) starting\n", rt_whoami());
	while (count < MAXCOUNT) {
		count++;
		msg.progressive = count;
		msg.sending_task = 1;
		unsent = rt_tbx_send_if(&bx, (char*)&msg, sizeof(msg));
		rt_printk("\nTask1=%lu, simple sending, unsent=%d\n", count, unsent);
		rt_sleep(nano2count(DELAY));
	}
	rt_printk("\nTask1 suspends itself\n");
	rt_task_suspend(rt_whoami());
}
Exemplo n.º 8
0
static void Task4(long t)
{
	int wakedup;
	MSG msg;

	rt_printk("\nTask4 (%p) starting\n", rt_whoami());
	while (count < MAXCOUNT) {
		count++;
		msg.progressive = count;
		msg.sending_task = 4;
		wakedup = rt_tbx_broadcast(&bx, (char*)&msg, sizeof(msg));
		rt_printk("\nTask4=%lu, sent broadcast, wakedup=%d\n", count, wakedup);
		rt_sleep(nano2count(DELAY + SHIFT));
	}
	rt_printk("\nTask4 suspends itself\n");
	rt_task_suspend(rt_whoami());
}
Exemplo n.º 9
0
Arquivo: kern.c Projeto: ArcEye/RTAI
static void sighdl(void)
{
	static unsigned long cnt = 0, rpt = 1000000000/PERIOD;
	if (++cnt > rpt) {
	        rt_printk("FUN SIGHDL > # sw: %lu, tsk: %p.\n", rpt, rt_whoami());
		rpt += 1000000000/PERIOD;
	}
}
Exemplo n.º 10
0
Arquivo: tbx3.c Projeto: cjecho/RTAI
static void Task3(long t)
{
	int status;
	MSG buf;

	rt_printk("\nTask3 (%p) starting\n", rt_whoami());
	while (count < MAXCOUNT) {
		memset((char*)&buf, 0, sizeof(buf));
		status = rt_tbx_receive_if(&bx, (char*)&buf, sizeof(buf));
		if (status == 0) {
			rt_printk("\nTask3 received msgnr %u from task %u, status=%d\n", buf.progressive, buf.sending_task, status);
		}
		rt_sleep(nano2count(TIMEBASE));
	}
	rt_printk("\nTask3 suspends itself\n");
	rt_task_suspend(rt_whoami());
}
Exemplo n.º 11
0
//-----------------------------------------------------------------------------
void child_func(int arg) {

int i;
size_t n = 0;
char inBuf[50];
uint priority = 0;
int nMsgs = 0;
struct mq_attr my_attrs ={0,0,0,0};
mode_t my_mode = 0;
int my_oflags = (O_RDONLY | O_NONBLOCK);
mqd_t rx_q = INVALID_PQUEUE;


  rt_printk("Starting child task %d\n", arg);
  for(i = 0; i < 3; i++) {

    rt_printk("child task %d, loop count %d\n", arg, i);

  }
  //Open the queue for reading
  rx_q = mq_open("my_queue", my_oflags, my_mode, &my_attrs);
  if (rx_q <= 0) {
    rt_printk("ERROR: child cannot open my_queue\n");
  } else {

    //Get the message(s) off the pQueue
    n = mq_getattr(rx_q, &my_attrs);
    nMsgs = my_attrs.mq_curmsgs;
    rt_printk("There are %d messages on the queue\n", nMsgs);

    while(nMsgs-- > 0) {
      n = mq_receive(rx_q, inBuf, sizeof(inBuf), &priority);
      inBuf[n] = '\0';

      //Report what happened
      rt_printk("Child got >%s<, %d bytes at priority %d\n", inBuf,n, priority);
    }
  }

  mq_close(rx_q);
  mq_unlink("my_queue");
  free_z_apps(rt_whoami());
  rt_task_delete(rt_whoami());

}
Exemplo n.º 12
0
static void Task7(long t)
{
	int unsent;
	MSG msg;

	rt_printk("\nTask7 (%p) starting\n", rt_whoami());
	while (count < MAXCOUNT) {
		count++;
		msg.progressive = count;
		msg.sending_task = 7;
		unsent = rt_tbx_urgent(&bx, (char*)&msg, sizeof(msg));
		rt_printk("\nTask7=%lu, urgent sending, unsent=%d\n", count, unsent);
		rt_sleep(nano2count(3*DELAY + 2*SHIFT));
	}
	rt_printk("\nTask7 suspends itself\n");
	cleanup = 1;
	rt_task_suspend(rt_whoami());
}
Exemplo n.º 13
0
Arquivo: tbx3.c Projeto: cjecho/RTAI
static void Task2(long t)
{
	int status;
	MSG buf;

	rt_printk("\nTask2 (%p) starting\n", rt_whoami());
	while (count < MAXCOUNT) {
		memset((char*)&buf, 0, sizeof(buf));
		status = rt_tbx_receive_timed(&bx, (char*)&buf, sizeof(buf),nano2count(TIMEOUT));
		if (status == sizeof(buf)) {
			rt_printk("\nTask2 receive timed out\n");
		} else {
			rt_printk("\nTask2 received msgnr %u from task %u, status=%d\n", buf.progressive, buf.sending_task, status);
		}
		rt_sleep(nano2count(DELAY));
	}
	rt_printk("\nTask2 suspends itself\n");
	rt_task_suspend(rt_whoami());
}
Exemplo n.º 14
0
RTAI_SYSCALL_MODE int rt_comedi_register_callback(void *dev, unsigned int subdev, unsigned int mask, int (*callback)(unsigned int, void *), void *task)
{
	if (task == NULL) {
		task = rt_whoami();
	}
	((RT_TASK *)task)->resumsg = 0;
	RTAI_COMEDI_LOCK(dev, subdev);
	rt_printk("COMEDI REGISTER CALLBACK: dev = %p, subdev = %u, mask = %u, callback = %p, task = %p.\n", dev, subdev, mask, callback, task);
	RTAI_COMEDI_UNLOCK(dev, subdev);
	return 0;
}
Exemplo n.º 15
0
void child_func(int arg) 
{
    int *explode = 0;

    rt_printk("Starting child task %d\n", arg);
    for(counters[arg] = 0; counters[arg] < 10; counters[arg]++) {
	// rt_printk("Child task %d, loop count %d\n", arg, counters[arg]);
	rt_task_wait_period();
    }
    *explode = 0;
    rt_task_suspend(rt_whoami());
}
Exemplo n.º 16
0
void parent_func(int arg) 
{
    int i;

    rt_printk("Starting parent task %d\n", arg);
    for (i = 0; i < NUM_CHILDREN; i++) {
    	rt_task_init(&child_task[i], child_func, i, STACK_SIZE, PRIORITY, 0, 0);
	rt_set_task_trap_handler(&child_task[i], 14, my_trap_handler);
	rt_task_make_periodic(&child_task[i], rt_get_time() + period, period*i);
    }
    rt_task_suspend(rt_whoami());
}
Exemplo n.º 17
0
static void Task2(long t)
{
	int status;
	MSG buf;

	rt_printk("\nTask2 (%p) starting\n", rt_whoami());
	while (1) {
		memset((char*)&buf, 0, sizeof(buf));
		status = rt_tbx_receive(&bx, (char*)&buf, sizeof(buf));
		rt_printk("\nTask2 received msgnr %u from task %u, status=%d\n", buf.progressive, buf.sending_task, status);
	}
}
Exemplo n.º 18
0
Arquivo: tbx1.c Projeto: ArcEye/RTAI
static void Task3(long t) 
{   
	int status;
	char buf[100];
    
	rt_printk("\nTask3 (%p) starting\n", rt_whoami());
	while (1) {
		status = rt_tbx_receive(&bx, buf, sizeof(msg1)); 
		rt_printk("\nTask3 received %s, status=%d\n", buf, status);
		memset(buf, 0, sizeof(buf));    
	}
}
Exemplo n.º 19
0
static void SomeOtherThingsTodo( void *var1, int var2 )
{
// This function acts like a synchronous thread.
// Function rt_qReceive(...) does whatever is necessary to receive proxies,
// messages and schedule the execution of both static and dynamic QBLK's.
rt_printk( "QBLK Says: Hello World\n" );

count++;

// Reschedule for execution in one second.
if(count < 12) rt_qBlkWait( &Main, nano2count( 1000000000 ));
else rt_task_suspend(rt_whoami());
}
Exemplo n.º 20
0
void *thread_func(void *arg) {

  int i;
  int r_c;
  int my_policy;
  pthread_t self;
  struct sched_param my_param;
  RT_TASK *rtai_task_ptr;


  self = pthread_self();

  rt_printk("Starting pthread: %s, id: %ld\n", (char *)arg, self);

  if(( r_c = pthread_getschedparam(self, &my_policy, &my_param)) != 0) {
    rt_printk("pthread: %s, pthread_getschedparam error: %d\n", (char *)arg, r_c);
  }

  rt_printk("pthread: %s, Created with following scheduling parameters.\n", (char *)arg);
  rt_printk("pthread: %s, running at %s/%d\n", (char *)arg,
          (my_policy == SCHED_FIFO ? "FIFO"
          : (my_policy == SCHED_RR ? "RR"
          : (my_policy == SCHED_OTHER ? "OTHER"
          : "unknown"))),
          my_param.sched_priority);

  rtai_task_ptr = rt_whoami();
  rt_printk("pthread: %s, RTAI priority: %d\n", (char *)arg, rtai_task_ptr->priority);

  if(( r_c = pthread_mutex_lock(&test_op.lock)) != 0) {
    rt_printk("pthread %s, Cannot gain mutex: %d\n", (char *)arg, r_c);
  }


  for(i = 0; i < 5; i++) {

    rt_printk("pthread: %s, loop count %d\n", (char *)arg, i);
    test_op.t_buffer_data[test_op.t_buffer_pos] = self + i;
    test_op.t_buffer_tid[test_op.t_buffer_pos] = self;
    test_op.t_buffer_pos++;
  }

  if(( r_c = pthread_mutex_unlock(&test_op.lock)) != 0) {
    rt_printk("pthread %s - Error unlocking mutex: %d\n", (char *)arg, r_c);
  }

  pthread_exit("b");

  return(NULL);

}
Exemplo n.º 21
0
/****
 * Proxy txqueue wakeup manager.
 *
 * Waits blocking for a wakeup message in its mailbox and calls the rtdevice
 * specific wakeup function (if one is registered) after a message arrived.
 */
void proxy_wakeup_manager_task (int mgr_id) {
        struct rtnet_msg msg;
	struct rtnet_mgr *mgr = (struct rtnet_mgr *)mgr_id;

        rt_printk("RTnet: Proxy txqueue wakeup manager started. (%p)\n", rt_whoami());
        while(1) {
                rt_mbx_receive(&(mgr->mbx), &msg, sizeof(struct rtnet_msg));
                if ((msg.msg_type==WAKEUP) && (msg.rtdev)) {
			if (msg.rtdev->rt_wakeup_xmit) {
				msg.rtdev->proxy_wakeup_xmit(msg.rtdev);
			}
		}
	}
}
Exemplo n.º 22
0
Arquivo: tbx3.c Projeto: cjecho/RTAI
static void Task4(long t)
{
	int wakedup;
	MSG msg;

	rt_printk("\nTask4 (%p) starting\n", rt_whoami());
	while (count < MAXCOUNT) {
		count++;
		msg.progressive = count;
		msg.sending_task = 4;
	        /*
        	 * Please note that tasks using rt_receive_if() will not receive
	         * this message because they aren't sleeping

		 */
		wakedup = rt_tbx_broadcast_if(&bx, (char*)&msg, sizeof(msg));
		if (wakedup > 0) {
			rt_printk("\nTask4=%lu, sent broadcast, wakedup=%d\n", count, wakedup);
		}
		rt_sleep(nano2count(DELAY + SHIFT));
	}
	rt_printk("\nTask4 suspends itself\n");
	rt_task_suspend(rt_whoami());
}
Exemplo n.º 23
0
/****
 * Realtime txqueue wakeup manager.
 *
 * Waits blocking for a wakeup message in its mailbox and calls the rtdevice
 * specific wakeup function (if one is registered) after a message arrived.
 * After processing the realtime txqueue, a wakeup message is sent to the
 * proxy wakeup manager.
 */
void rt_wakeup_manager_task (int mgr_id) {
        struct rtnet_msg msg;
	struct rtnet_mgr *mgr = (struct rtnet_mgr *)mgr_id;

        rt_printk("RTnet: Realtime txqueue wakeup manager started. (%p)\n", rt_whoami());
        while(1) {
                rt_mbx_receive(&(mgr->mbx), &msg, sizeof(struct rtnet_msg));
                if ((msg.msg_type==WAKEUP) && (msg.rtdev)) {
			if (msg.rtdev->rt_wakeup_xmit) {
				msg.rtdev->rt_wakeup_xmit(msg.rtdev);
			}
		}
		// The next call should depend on the not yet specified returncode of rt_wakeup_xmit().
		rt_mbx_send_if(&(proxy_wakeup_manager.mbx), &msg, sizeof (struct rtnet_msg));
	}
}
Exemplo n.º 24
0
void fun(int t)
{
	char buf[64];
	pid_t from;
	int msglen;

	rt_printk("Task %p starts.\n", rt_lxrt_whoami());

	// init a qBlk
	rt_InitTickQueue();
	rt_qBlkInit( &Main, SomeOtherThingsTodo, 0, 0);
	rt_qBlkWait( &Main, nano2count(1000000000));

        from = rt_qReceive( 0, buf, sizeof(buf), &msglen);

	rt_task_suspend(rt_whoami());
	rt_printk("Task %p Oops.\n", rt_lxrt_whoami());
}
Exemplo n.º 25
0
int rt_tbx_send(TBX *tbx, void *msg, int msg_size)
{
	unsigned char type = TYPE_NORMAL;
	RT_TASK *rt_current;
    
	CHK_TBX_MAGIC;
	if ((msg_size + sizeof(type)) > tbx->size) {
		return -EMSGSIZE;
	}
	if (tbx_smx_wait(tbx, &(tbx->sndsmx), rt_current = rt_whoami())) {
		return msg_size;
	}
   	if (tbx_wait_room(tbx, &tbx->frbs, msg_size + sizeof(type), rt_current)) {
		tbx_smx_signal(tbx, &(tbx->sndsmx));
		return msg_size;
	}
	msg_size = tbxput(tbx, (char **)(&msg), msg_size, type);
	tbx_signal(tbx);
	tbx_smx_signal(tbx, &(tbx->sndsmx));
	return msg_size;
}
Exemplo n.º 26
0
int _rtapi_task_self_hook(void) {
    RT_TASK *ptr;
    int n;

    /* ask OS for pointer to its data for the current task */
    ptr = rt_whoami();
    if (ptr == NULL) {
	/* called from outside a task? */
	return -EINVAL;
    }
    /* find matching entry in task array */
    n = 1;
    while (n <= RTAPI_MAX_TASKS) {
	if (ostask_array[n] == ptr) {
	    /* found a match */
	    return n;
	}
	n++;
    }
    return -EINVAL;
}
Exemplo n.º 27
0
int rt_tbx_urgent_until(TBX *tbx, void *msg, int msg_size, RTIME time)
{
	unsigned char type = TYPE_URGENT;
	RT_TASK *rt_current;
    
	CHK_TBX_MAGIC;
	if ((msg_size + sizeof(type)) > tbx->size) {
        	return -EMSGSIZE;
	}
	if (tbx_smx_wait_until(tbx, &(tbx->sndsmx), time, rt_current = rt_whoami())) {
		return msg_size;
	}
	if (tbx_wait_room_until(tbx, &tbx->frbs, (msg_size + sizeof(type)), time, rt_current)) {
	        tbx_smx_signal(tbx, &(tbx->sndsmx));
        	return msg_size;
	}
	msg_size = tbxbackput(tbx, (char **)(&msg), msg_size, type);
    	tbx_signal(tbx);
	tbx_smx_signal(tbx, &(tbx->sndsmx));
	return msg_size;
}
Exemplo n.º 28
0
void *control_func(void *arg) {

  int i;
  int r_c;
  int my_policy;
  pthread_t self;
  pthread_t thread_id = 0;
  pthread_attr_t new_attr;
  struct sched_param my_param;
  RT_TASK *rtai_task_ptr;


  self = pthread_self();

  rt_printk("Starting control pthread: %s, id: %ld\n", (char *)arg, self);

  if(( r_c = pthread_getschedparam(self, &my_policy, &my_param)) != 0) {
    rt_printk("pthread: %s, pthread_getschedparam error: %d\n", (char *)arg, r_c);
  }

  rt_printk("pthread: %s, Created with following scheduling parameters.\n", (char *)arg);
  rt_printk("pthread: %s, running at %s/%d\n", (char *)arg,
          (my_policy == SCHED_FIFO ? "FIFO"
          : (my_policy == SCHED_RR ? "RR"
          : (my_policy == SCHED_OTHER ? "OTHER"
          : "unknown"))),
          my_param.sched_priority);

  rtai_task_ptr = rt_whoami();
  rt_printk("pthread: %s, RTAI priority: %d\n", (char *)arg, rtai_task_ptr->priority);

// Initialise & lock the mutex: test_op
  pthread_mutex_init(&test_op.lock, NULL);
  test_op.t_buffer_pos = 0;
  for(i = 0; i < T_BUFFER_SIZE; i++) {
    test_op.t_buffer_data[i] = 0;
    test_op.t_buffer_tid[i] = 0;
  }

  if(( r_c = pthread_mutex_lock(&test_op.lock)) != 0) {
    rt_printk("pthread %s, Cannot gain mutex: %d\n", (char *)arg, r_c);
  }


// Create an application thread.
  if(( r_c = pthread_attr_init(&new_attr) ) != 0 ) {
    rt_printk("pthread %s, Error initialising thread attributes: %d\n", (char *)arg, r_c);
  }

  if(( r_c = pthread_attr_setschedpolicy(&new_attr, SCHED_FIFO) ) != 0 ) {
    rt_printk("pthread %s, Error setting thread attribute scheduling parameters: %d\n", (char *)arg, r_c);
  }


// Create NUM_THREADS application pthreads, each thread with increasing priority.
  for(i = 0; i < NUM_THREADS; i++) {

    my_param.sched_priority = 12 + i;
    if(( r_c = pthread_attr_setschedparam(&new_attr, &my_param) ) != 0 ) {
      rt_printk("pthread %s, Error setting thread attribute scheduling parameters: %d\n", (char *)arg, r_c);
    }

    if(( r_c = pthread_create(&thread_id, &new_attr, thread_func, "application pthread mutex tester")) != 0 ) {

      rt_printk("mutex priority inheritance test - Application thread creation failed:  %d\n", r_c);
    }

  }


// Display control thread priority.
  if(( r_c = pthread_getschedparam(self, &my_policy, &my_param)) != 0) {
    rt_printk("pthread: %s, pthread_getschedparam error: %d\n", (char *)arg, r_c);
  }


  rt_printk("pthread: %s, Priority should now be raised due to inheritance.\n", (char *)arg);
  rt_printk("pthread: %s, running at %s/%d\n", (char *)arg,
          (my_policy == SCHED_FIFO ? "FIFO"
          : (my_policy == SCHED_RR ? "RR"
          : (my_policy == SCHED_OTHER ? "OTHER"
          : "unknown"))),
          my_param.sched_priority);

  rt_printk("pthread: %s, RTAI priority: %d\n", (char *)arg, rtai_task_ptr->priority);


  rt_printk("pthread: %s, id: %ld, about to unlock mutex.\n", (char *)arg, self);

  if(( r_c = pthread_mutex_unlock(&test_op.lock)) != 0) {
    rt_printk("pthread %s - Error unlocking mutex: %d\n", (char *)arg, r_c);
  }

  rt_printk("pthread: %s, Priority should now be back to original.\n", (char *)arg);
  rt_printk("pthread: %s, running at %s/%d\n", (char *)arg,
          (my_policy == SCHED_FIFO ? "FIFO"
          : (my_policy == SCHED_RR ? "RR"
          : (my_policy == SCHED_OTHER ? "OTHER"
          : "unknown"))),
          my_param.sched_priority);

  rt_printk("pthread: %s, RTAI priority: %d\n", (char *)arg, rtai_task_ptr->priority);


  pthread_exit("a");

  return(NULL);

}
Exemplo n.º 29
0
void parent_func(int arg) {
int i;
int my_oflags, n = 0;
mode_t my_mode;
struct mq_attr my_attrs;
char inBuf[50];
uint priority = 0;

static const char str1[23] = "Test string number one\0";
static const char str2[28] = "This is test string num 2!!\0";
static const char str3[22] = "Test string number 3!\0";
static const char str4[34] = "This is test string number four!!\0";
 
struct Msg {
    const char *str;
    int str_size;
    uint prio;
};

uint nMsgs = 4;
static const struct Msg myMsgs[4] =
{
    {str1, 23, 5},
    {str2, 28, 1},
    {str3, 22, 6},
    {str4, 34, 7},
};

#ifdef STEP_TRACE
  //Wait for the debugger to say GO!
  while(!zdbg) {
	rt_task_wait_period();
  }
#endif

  rt_printk("Starting parent task %d\n", arg);
  for(i = 0; i < 5; i++) {
    rt_printk("parent task %d, loop count %d\n", arg, i);
  }
  //Create and open a queue
  my_oflags = O_RDWR | O_CREAT | O_NONBLOCK;
  my_mode = S_IRUSR | S_IWUSR | S_IRGRP;
  my_attrs.mq_maxmsg = 10;
  my_attrs.mq_msgsize = 50;
  my_q = mq_open("my_queue", my_oflags, my_mode, &my_attrs);

  if (my_q > 0) {
    rt_printk("Putting %d messages on queue\n", nMsgs);

    for (i = 0; i < nMsgs; i++) {

      //Put messages on the queue
      rt_printk("Sending: %s\n", myMsgs[i].str);
      n = mq_send(my_q, myMsgs[i].str, myMsgs[i].str_size, myMsgs[i].prio); 
      rt_printk("Parent put message 1 of %d bytes on queue at priority %d\n",
					n, myMsgs[i].prio);
    }
  } else {
      rt_printk("ERROR: could not create my_queue\n");
  }

  //Now receive stuff back from the queue
  for(i = 0; i < nMsgs; i++) {
    n = mq_receive(my_q, inBuf, sizeof(inBuf), &priority);  
    if (n > 0) {
      inBuf[n] = '\0';
      rt_printk("Parent got >%s< from queue\n", inBuf); 
    }
  }
  mq_close(my_q);
  mq_unlink("my_queue");
  free_z_apps(rt_whoami());
  rt_task_delete(rt_whoami());

}
Exemplo n.º 30
0
void
__default_terminate(void)
{
	while(1)
		rt_task_suspend(rt_whoami());
}