#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <alchemy/task.h>
#include <nucleus/intr.h>
#define IRQ_NUMBER 7 /* Intercept interrupt #7 */
#define TASK_STKSZ 0 /* Stack size (use default one) */
#define TASK_PRIO 99 /* Highest RT priority */
#define TASK_MODE 0 /* No flags */
static RT_INTR intr_desc;
static RT_TASK task_00;
static int count = 1;
#if 1
void cleanup (void)
{
rt_intr_delete(&intr_desc);
rt_task_delete(&task_desc);
}
#endif
{
int err;
for (;;) {
/* Wait for the next interrupt on channel #7. */
err = rt_intr_wait(&intr_desc,TM_INFINITE);
if (err > 0) { //rt_intr_wait正常返回一个正数,代表未处理中断的数量
/* Process interrupt. */
}
}
#if 1
static void task_00_01 (void *cookie)
{
for (;;) {
/* ... "cookie" should be NULL ... */
fprintf(stderr, "task_00 is run %d", count);
count++;
}
}
#endif
#if 1
static void task_00_02 (void *cookie)
{
for (;;) {
/* ... "cookie" should be NULL ... */
fprintf(stderr, "task_01 is run %d", count);
count++;
}
}
#endif
int main (int argc, char *argv[])
{
int err;
mlockall(MCL_CURRENT|MCL_FUTURE);
/* ... */
err = rt_intr_create(&intr_desc,"MyIrq",IRQ_NUMBER,0);
err = rt_task_create(&task_00,
"Task_00_Name",
TASK_STKSZ,
TASK_PRIO,
TASK_MODE);
if (!err)
rt_task_start(&task_00,&task_00_00,NULL);
rt_task_start(&task_00,&task_00_01,NULL);
rt_task_start(&task_00,&task_00_02,NULL);
rt_intr_enable(&intr_desc); //开中断
/* ... */
cleanup ();
exit(0);//return 0;
}
#include <stdlib.h>
#include <sys/mman.h>
#include <alchemy/task.h>
#include <nucleus/intr.h>
#define IRQ_NUMBER 7 /* Intercept interrupt #7 */
#define TASK_STKSZ 0 /* Stack size (use default one) */
#define TASK_PRIO 99 /* Highest RT priority */
#define TASK_MODE 0 /* No flags */
static RT_INTR intr_desc;
static RT_TASK task_00;
static int count = 1;
#if 1
void cleanup (void)
{
rt_intr_delete(&intr_desc);
rt_task_delete(&task_desc);
}
#endif
#if 1
{
int err;
for (;;) {
/* Wait for the next interrupt on channel #7. */
err = rt_intr_wait(&intr_desc,TM_INFINITE);
if (err > 0) { //rt_intr_wait正常返回一个正数,代表未处理中断的数量
/* Process interrupt. */
}
}
}
#endif
#if 1
static void task_00_01 (void *cookie)
{
for (;;) {
/* ... "cookie" should be NULL ... */
fprintf(stderr, "task_00 is run %d", count);
count++;
}
}
#endif
#if 1
static void task_00_02 (void *cookie)
{
for (;;) {
/* ... "cookie" should be NULL ... */
fprintf(stderr, "task_01 is run %d", count);
count++;
}
}
#endif
int main (int argc, char *argv[])
{
int err;
mlockall(MCL_CURRENT|MCL_FUTURE);
/* ... */
err = rt_intr_create(&intr_desc,"MyIrq",IRQ_NUMBER,0);
err = rt_task_create(&task_00,
"Task_00_Name",
TASK_STKSZ,
TASK_PRIO,
TASK_MODE);
if (!err)
rt_task_start(&task_00,&task_00_00,NULL);
rt_task_start(&task_00,&task_00_01,NULL);
rt_task_start(&task_00,&task_00_02,NULL);
rt_intr_enable(&intr_desc); //开中断
/* ... */
cleanup ();
exit(0);//return 0;
}
本文介绍了一个使用实时任务和中断处理机制的示例程序。该程序通过创建实时任务来响应特定中断,并展示了如何配置和启动这些任务。此外,还演示了如何在任务中处理中断并打印运行状态。

被折叠的 条评论
为什么被折叠?



