示例#1
0
void PLC_cleanup_all(void)
{
    if (PLC_state & PLC_STATE_TASK_CREATED) {
        rt_task_delete(&PLC_task);
        PLC_state &= ~PLC_STATE_TASK_CREATED;
    }

    if (PLC_state & PLC_STATE_WAITDEBUG_PIPE_CREATED) {
        rt_pipe_delete(&WaitDebug_pipe);
        PLC_state &= ~PLC_STATE_WAITDEBUG_PIPE_CREATED;
    }

    if (PLC_state & PLC_STATE_WAITDEBUG_FILE_OPENED) {
        close(WaitDebug_pipe_fd);
        PLC_state &= ~PLC_STATE_WAITDEBUG_FILE_OPENED;
    }

    if (PLC_state & PLC_STATE_WAITPYTHON_PIPE_CREATED) {
        rt_pipe_delete(&WaitPython_pipe);
        PLC_state &= ~PLC_STATE_WAITPYTHON_PIPE_CREATED;
    }

    if (PLC_state & PLC_STATE_WAITPYTHON_FILE_OPENED) {
        close(WaitPython_pipe_fd);
        PLC_state &= ~PLC_STATE_WAITPYTHON_FILE_OPENED;
    }

    if (PLC_state & PLC_STATE_DEBUG_PIPE_CREATED) {
        rt_pipe_delete(&Debug_pipe);
        PLC_state &= ~PLC_STATE_DEBUG_PIPE_CREATED;
    }

    if (PLC_state & PLC_STATE_DEBUG_FILE_OPENED) {
        close(Debug_pipe_fd);
        PLC_state &= ~PLC_STATE_DEBUG_FILE_OPENED;
    }

    if (PLC_state & PLC_STATE_PYTHON_PIPE_CREATED) {
        rt_pipe_delete(&Python_pipe);
        PLC_state &= ~PLC_STATE_PYTHON_PIPE_CREATED;
    }

    if (PLC_state & PLC_STATE_PYTHON_FILE_OPENED) {
        close(Python_pipe_fd);
        PLC_state &= ~PLC_STATE_PYTHON_FILE_OPENED;
    }

}
RealtimeController::~RealtimeController()
{
    // signaloidaan säikeelle että sen pitää sammuttaa itsensä
    if(write(pipefd, "theEnd", sizeof("theEnd")) < 0)
        qDebug("error %d : %s\n", -errno, strerror(-errno));
    // odotetaan kunnes säie on sammunut, erillistä deleteä EI saa tehdä
    rt_task_join(&task_desc);
    // vapautetaan pipen resurssit
    rt_pipe_delete(&pipe_desc);
}
示例#3
0
void AuxTaskNonRT::cleanup(){
	close(pipe_fd);
#ifdef XENOMAI_SKIN_native
	rt_task_delete(&task);
	rt_pipe_delete(&pipe);
#endif
#ifdef XENOMAI_SKIN_posix
	// TODO: someone needs to be done to terminate the tasks appropriately
	// Currently they are probably just hanging on the pipes
	// However the three lines below cause a segfault after the first time they are run
	// char ptr[1];
	// int ret = __wrap_sendto(pipeSocket, ptr, 1, 0, NULL, 0); // unblock the pipe
	// pthread_cancel(thread);
	// also we should join them!
#endif
}
示例#4
0
void cleanup_mpu9150_irq(void)
{
	rtdm_printk("MPU9150-IRQ: Releasing IRQ resources...\n");

	if( irq_requested )
	{
		rtdm_irq_disable( &mpu9150_irq );
		rtdm_irq_free( &mpu9150_irq );
	}

	if( irq_gpio_requested )
		gpio_free( mpu9150_irq_desc.gpio_desc.gpio );

	// Close the pipe
	rt_pipe_delete( &pipe_desc );

	rtdm_printk("MPU9150-IRQ: IRQ resources released\n");
}
示例#5
0
void AuxTaskNonRT::__create(){
	// create the xenomai task
	int priority = 0;
	int stackSize = 65536 * 4;
#ifdef XENOMAI_SKIN_native //posix skin does evertything in one go below
	if (int ret = rt_task_create(&task, name, stackSize, priority, T_JOINABLE))

	{
		fprintf(stderr, "Unable to create AuxTaskNonRT %s: %i\n", name, ret);
		return;
	}
#endif
	// create an rt_pipe
	char p_name [30];
	sprintf (p_name, "p_%s", name);
#ifdef XENOMAI_SKIN_native
	rt_pipe_delete(&pipe);
	int ret = rt_pipe_create(&pipe, p_name, P_MINOR_AUTO, 0);
	if(ret < 0)
#endif
#ifdef XENOMAI_SKIN_posix
	int pipeSize = 65536 * 10;
	int ret = createXenomaiPipe(p_name, pipeSize);
	pipeSocket = ret;
	if(ret <= 0)
#endif
	{
		fprintf(stderr, "Unable to create AuxTaskNonRT %s pipe %s: (%i) %s\n", name, p_name, ret, strerror(ret));
		return;
	}
	// start the xenomai task
#ifdef XENOMAI_SKIN_native
	if (int ret = rt_task_start(&task, AuxTaskNonRT::loop, this))
#endif
#ifdef XENOMAI_SKIN_posix
	if(int ret = create_and_start_thread(&thread, name, priority, stackSize, (pthread_callback_t*)AuxTaskNonRT::loop, this))
#endif
	{
		fprintf(stderr, "Unable to start AuxTaskNonRT %s: %i, %s\n", name, ret, strerror(ret));
		return;
	}
}
示例#6
0
static int __init klat_mod_init(void)
{
	char devname[RTDM_MAX_DEVNAME_LEN + 1];
	unsigned dev_nr;
	int err;

	err = rt_pipe_create(&klat_pipe, "klat_pipe", pipe, 4096);
	if (err) {
		printk("rt_pipe_create(klat_pipe): %d\n", err);
		return err;
	}

	err = rt_task_create(&klat_srvr, "klat_srvr", 0, 0, 0);
	if (err) {
		printk("rt_task_create(klat_srvr): %d\n", err);
		goto err_close_pipe;
	}

	pkt.config.mode = mode;
	pkt.config.priority = priority;
	pkt.config.period = period * 1000;
	pkt.config.warmup_loops = 1;
	pkt.config.histogram_size = 0;
	pkt.config.freeze_max = freeze_max;

	for (dev_nr = 0; dev_nr < DEV_NR_MAX; dev_nr++) {
		snprintf(devname, sizeof(devname),
			 "rttest-timerbench%d",
			 dev_nr);
		fd = rt_dev_open(devname, O_RDONLY);
		if (fd < 0)
			continue;

		err = rt_dev_ioctl(fd, RTTST_RTIOC_TMBENCH_START, &pkt.config);
		if (err == -ENOTTY) {
			rt_dev_close(fd);
			continue;
		}

		if (err < 0) {
			printk("rt_dev_ioctl(RTTST_RTIOC_TMBENCH_START): %d\n",
			       err);
			goto err_destroy_task;
		}

		break;
	}
	if (fd < 0) {
		printk("rt_dev_open: could not find rttest device\n"
		       "(modprobe timerbench?)");
		err = fd;
		goto err_destroy_task;
	}

	err = rt_task_start(&klat_srvr, &klat_server, NULL);
	if (err) {
		printk("rt_task_start: %d\n", err);
		goto err_close_dev;
	}

	return 0;

  err_close_dev:
	rt_dev_close(fd);
  err_destroy_task:
	rt_task_delete(&klat_srvr);
  err_close_pipe:
	rt_pipe_delete(&klat_pipe);
	return err;
}
示例#7
0
static void klat_mod_exit(void)
{
	rt_dev_close(fd);
	rt_task_delete(&klat_srvr);
	rt_pipe_delete(&klat_pipe);
}
示例#8
0
int main(void)
{
	unsigned long long before;
	RT_ALARM nalrm;
	RT_BUFFER nbuf;
	RT_COND ncond;
	RT_EVENT nevt;
	RT_HEAP nheap;
	RT_MUTEX nmtx;
	RT_PIPE npipe;
	RT_QUEUE nq;
	RT_SEM nsem;
	RT_TASK ntsk;
	int failed = 0;

	mlockall(MCL_CURRENT|MCL_FUTURE);

	rt_print_auto_init(1);

	rt_fprintf(stderr, "Checking for leaks in native skin services\n");
	before = get_used();
	check_native(rt_alarm_create(&nalrm, NULL));
	check_native(rt_alarm_delete(&nalrm));
	check_used("alarm", before, failed);

	before = get_used();
	check_native(rt_buffer_create(&nbuf, NULL, 16384, B_PRIO));
	check_native(rt_buffer_delete(&nbuf));
	check_used("buffer", before, failed);

	before = get_used();
	check_native(rt_cond_create(&ncond, NULL));
	check_native(rt_cond_delete(&ncond));
	check_used("cond", before, failed);

	before = get_used();
	check_native(rt_event_create(&nevt, NULL, 0, EV_PRIO));
	check_native(rt_event_delete(&nevt));
	check_used("event", before, failed);

	before = get_used();
	check_native(rt_heap_create(&nheap, "heap", 16384, H_PRIO | H_SHARED));
	check_native(rt_heap_delete(&nheap));
	check_used("heap", before, failed);

	before = get_used();
	check_native(rt_mutex_create(&nmtx, NULL));
	check_native(rt_mutex_delete(&nmtx));
	check_used("mutex", before, failed);

	before = get_used();
	check_native(rt_pipe_create(&npipe, NULL, P_MINOR_AUTO, 0));
	check_native(rt_pipe_delete(&npipe));
	check_used("pipe", before, failed);

	before = get_used();
	check_native(rt_queue_create(&nq, "queue", 16384, Q_UNLIMITED, Q_PRIO));
	check_native(rt_queue_delete(&nq));
	check_used("queue", before, failed);

	before = get_used();
	check_native(rt_sem_create(&nsem, NULL, 0, S_PRIO));
	check_native(rt_sem_delete(&nsem));
	check_used("sem", before, failed);

	before = get_used();
	check_native(rt_task_spawn(&ntsk, NULL, 0, 1, T_JOINABLE, empty, NULL));
	check_native(rt_task_join(&ntsk));
	sleep(1);		/* Leave some time for xnheap
				 * deferred free */
	check_used("task", before, failed);

	return failed ? EXIT_FAILURE : EXIT_SUCCESS;
}