#include <rtl.h>
#define TASK_CONTROL_FIFO_OFFSET 3
void *thread_code(void *t)
{
// 省略
}
int my_handler(unsigned int fifo)
{
struct my_msg_struct msg;
int err;
while ((err = rtf_get(COM_FIFO, &msg,
sizeof(msg)))
== sizeof(msg)) {
rtf_put (msg.task + TASK_CTRL_FIFO_OFFSET,
&msg, sizeof(msg));
rtl_printf("FIFO handler: sending the \"%d\"
command to task %d; period %d\n",
msg.command,
msg.task, msg.period);
pthread_wakeup_np (task);
}
return 0;
}
int init_module(void)
{
rtf_destroy(1);
rtf_destroy(2);
rtf_destroy(3);
c[0] = rtf_create(1, 4000);
c[1] = rtf_create(2, 200);
c[2] = rtf_create(3, 200);
/******* USB Control ********/
//buffer allocation
PciScan();
CreateSharedMemory();
GetUsbControlMemory();
/****************************/
pthread_attr_init (&attr);
sched_param.sched_priority = 4;
pthread_attr_setschedparam (&attr, &sched_param);
ret = pthread_create (&task, &attr,
thread_code, (void *)1);
rtf_create_handler(COMMAND_FIFO, &my_handler);
pthread_setfp_np(task, 1); // use float
return 0;
}
void cleanup_module(void)
{
rtf_destroy(1);
rtf_destroy(2);
rtf_destroy(3);
pthread_setfp_np(task, 0); // no use float
pthread_cancel (task);
pthread_join (task, NULL);
/******* USB Control ********/
CloseSharedMemory();
ReleaseUsbControlMemory();
/****************************/
}
void *thread_code(void *t)
{
while (1) {
ret = pthread_wait_np();
if ((err = rtf_get (taskno +
TASK_CONTROL_FIFO_OFFSET, &msg,
sizeof(msg)))
== sizeof(msg)) {
rtl_printf("Task %d: executing the \"%d\"
command to task %d; period %d\n",
fifo - 1, msg.command, msg.task,
msg.period);
switch (msg.command) {
case START_TASK:
printk("task start\n");
pthread_make_periodic_np(pthread_self(),
gethrtime(), msg.period * 1000);
break;
case STOP_TASK:
pthread_suspend_np(pthread_self());
printk("task stop\n");
rtf_put(1, "task stop \n",
sizeof("task stop \n"));
break;
default:
rtl_printf("RTLinux task: bad command\n");
return 0;
}
}
////sample code
/******* USB Control ********/
PlugCheck();
ModeControl();
SendToken();
/****************************/
}
}