コード例 #1
0
ファイル: slave.c プロジェクト: chrmorais/miniemc2
/* part of the Linux kernel module that kicks off the timer task */
int rtapi_app_main(void)
{
    int retval;
    int slave_prio;

    module = rtapi_init("SEM_SLAVE");
    if (module < 0) {
	rtapi_print("sem slave init: rtapi_init returned %d\n", module);
	return -1;
    }

    /* open the semaphore */
    slave_sem = rtapi_sem_new(SEM_KEY, module);
    if (slave_sem < 0) {
	rtapi_print("sem slave init: rtapi_sem_new returned %d\n", slave_sem);
	rtapi_exit(module);
	return -1;
    }

    /* set the task priority to the lowest one; the master is higher */
    slave_prio = rtapi_prio_lowest();

    /* create the slave task */
    slave_task = rtapi_task_new(slave_code, 0 /* arg */ , slave_prio, module,
	SLAVE_STACKSIZE, RTAPI_NO_FP);
    if (slave_task < 0) {
	rtapi_print("sem slave init: rtapi_task_new returned %d\n",
	    slave_task);
	rtapi_exit(module);
	return -1;
    }

    /* start the slave task */
    retval = rtapi_task_resume(slave_task);
    if (retval != RTAPI_SUCCESS) {
	rtapi_print("sem slave init: rtapi_task_start returned %d\n", retval);
	rtapi_exit(module);
	return -1;
    }

    rtapi_print("sem slave init: started slave task\n");

    return 0;
}
コード例 #2
0
/* part of the Linux kernel module that kicks off the fifo task */
int rtapi_app_main(void)
{
    int retval;
    int fifo_prio;
    long period;

    module = rtapi_init("FIFOTASK");
    if (module < 0) {
	rtapi_print("fifotask init: rtapi_init failed with %d\n", module);
	return -1;
    }

    /* allocate and initialize the fifo */
    fifo = rtapi_fifo_new(FIFO_KEY, module, FIFO_SIZE, 'W');
    if (fifo < 0) {
	rtapi_print("fifotask init: rtapi_fifo_new failed with %d\n", fifo);
	rtapi_exit(module);
	return -1;
    }

    rtapi_print("fifotask: created fifo\n");

    /* is timer started? if so, what period? */
    period = rtapi_clock_set_period(0);
    if (period == 0) {
	/* not running, start it */
	rtapi_print("fifotask init: starting timer with period %ld\n",
	    TIMER_PERIOD_NSEC);
	period = rtapi_clock_set_period(TIMER_PERIOD_NSEC);
	if (period < 0) {
	    rtapi_print
		("fifotask init: rtapi_clock_set_period failed with %ld\n",
		period);
	    rtapi_exit(module);
	    return -1;
	}
    }
    /* make sure period <= desired period (allow 1% roundoff error) */
    if (period > (TIMER_PERIOD_NSEC + (TIMER_PERIOD_NSEC / 100))) {
	/* timer period too long */
	rtapi_print("fifotask init: clock period too long: %ld\n", period);
	rtapi_exit(module);
	return -1;
    }
    rtapi_print("fifotask init: desired clock %ld, actual %ld\n",
	TIMER_PERIOD_NSEC, period);

    /* set the task priority to lowest, since we only have one task */
    fifo_prio = rtapi_prio_lowest();

    /* create the fifo task */
    fifo_task = rtapi_task_new(fifo_code, 0 /* arg */ , fifo_prio, module,
	FIFO_STACKSIZE, RTAPI_NO_FP);
    if (fifo_task < 0) {
	rtapi_print("fifotask init: rtapi_task_new failed with %d\n",
	    fifo_task);
	rtapi_exit(module);
	return -1;
    }

    /* start the fifo task */
    retval = rtapi_task_start(fifo_task, FIFO_PERIOD_NSEC);
    if (retval < 0) {
	rtapi_print("fifotask init: rtapi_task_start failed with %d\n",
	    retval);
	rtapi_exit(module);
	return -1;
    }

    rtapi_print("fifotask: started fifo task\n");

    return 0;
}
コード例 #3
0
ファイル: timertask.c プロジェクト: CNCBASHER/linuxcnc-1
/* rtapi_app_main() is expanded to init_module() via a macro in
   rtapi_app.h */
int rtapi_app_main(void)
{
    int retval;
    int timer_prio;
    long period;

    module = rtapi_init("TIMERTASK");
    if (module < 0) {
	rtapi_print("timertask init: rtapi_init returned %d\n", module);
	return -1;
    }

    /* is timer started? if so, what period? */
    period = rtapi_clock_set_period(0);
    if (period == 0) {
	/* not running, start it */
	rtapi_print("timertask init: starting timer with period %ld\n",
	    TIMER_PERIOD_NSEC);
	period = rtapi_clock_set_period(TIMER_PERIOD_NSEC);
	if (period < 0) {
	    rtapi_print
		("timertask init: rtapi_clock_set_period failed with %ld\n",
		period);
	    rtapi_exit(module);
	    return -1;
	}
    }
    /* make sure period <= desired period (allow 1% roundoff error) */
    if (period > (TIMER_PERIOD_NSEC + (TIMER_PERIOD_NSEC / 100))) {
	/* timer period too long */
	rtapi_print("timertask init: clock period too long: %ld\n", period);
	rtapi_exit(module);
	return -1;
    }
    rtapi_print("timertask init: desired clock %ld, actual %ld\n",
	TIMER_PERIOD_NSEC, period);

    /* set the task priority to second lowest, since we only have one task */
    timer_prio = rtapi_prio_next_higher(rtapi_prio_lowest());

    /* create the timer task */
    /* the second arg is an abitrary int that is passed to the timer task on
       the first iterration */
    timer_task = rtapi_task_new(timer_code, 0 /* arg */ , timer_prio, module,
	TIMER_STACKSIZE, RTAPI_NO_FP);
    if (timer_task < 0) {
	/* See rtapi.h for the error codes returned */
	rtapi_print("timertask init: rtapi_task_new returned %d\n",
	    timer_task);
	rtapi_exit(module);
	return -1;
    }
    /* start the task running */
    retval = rtapi_task_start(timer_task, TASK_PERIOD_NSEC);
    if (retval < 0) {
	rtapi_print("timertask init: rtapi_task_start returned %d\n", retval);
	rtapi_exit(module);
	return -1;
    }
    rtapi_print("timertask init: started timer task\n");
    rtapi_print("timertask init: max delay = %ld\n", rtapi_delay_max());
    return 0;
}
コード例 #4
0
ファイル: shmemtask.c プロジェクト: CNCBASHER/linuxcnc-1
/* part of the Linux kernel module that kicks off the shmem task */
int rtapi_app_main(void)
{
    int retval;
    int shmem_prio;
    long period;

    module = rtapi_init("SHMEMTASK");
    if (module < 0) {
	rtapi_print("shmemtask init: rtapi_init returned %d\n", module);
	return -1;
    }
    /* allocate and initialize the shared memory structure */
    shmem_mem = rtapi_shmem_new(key, module, sizeof(SHMEM_STRUCT));
    if (shmem_mem < 0) {
	rtapi_print("shmemtask init: rtapi_shmem_new returned %d\n",
	    shmem_mem);
	rtapi_exit(module);
	return -1;
    }
    retval = rtapi_shmem_getptr(shmem_mem, (void **) &shmem_struct);
    if (retval < 0) {
	rtapi_print("shmemtask init: rtapi_shmem_getptr returned %d\n",
	    retval);
	rtapi_exit(module);
	return -1;
    }

    shmem_struct->heartbeat = 0;

    /* is timer started? if so, what period? */
    period = rtapi_clock_set_period(0);
    if (period == 0) {
	/* not running, start it */
	rtapi_print("shmemtask init: starting timer with period %ld\n",
	    TIMER_PERIOD_NSEC);
	period = rtapi_clock_set_period(TIMER_PERIOD_NSEC);
	if (period < 0) {
	    rtapi_print
		("shmemtask init: rtapi_clock_set_period failed with %ld\n",
		period);
	    rtapi_exit(module);
	    return -1;
	}
    }
    /* make sure period <= desired period (allow 1% roundoff error) */
    if (period > (TIMER_PERIOD_NSEC + (TIMER_PERIOD_NSEC / 100))) {
	/* timer period too long */
	rtapi_print("shmemtask init: clock period too long: %ld\n", period);
	rtapi_exit(module);
	return -1;
    }
    rtapi_print("shmemtask init: desired clock %ld, actual %ld\n",
	TIMER_PERIOD_NSEC, period);

    /* set the task priority to lowest, since we only have one task */
    shmem_prio = rtapi_prio_lowest();

    /* create the shmem task */
    shmem_task = rtapi_task_new(shmem_code, 0 /* arg */ , shmem_prio, module,
	SHMEM_STACKSIZE, RTAPI_NO_FP);
    if (shmem_task < 0) {
	rtapi_print("shmemtask init: rtapi_task_new returned %d\n",
	    shmem_task);
	rtapi_exit(module);
	return -1;
    }

    /* start the shmem task */
    retval = rtapi_task_start(shmem_task, SHMEM_PERIOD_NSEC);
    if (retval < 0) {
	rtapi_print("shmemtask init: rtapi_task_start returned %d\n", retval);
	rtapi_exit(module);
	return -1;
    }

    rtapi_print("shmemtask init: started shmem task\n");

    return 0;
}