Renamed rt module to rtimer
This commit is contained in:
parent
2114e7f847
commit
503b76266b
@ -28,15 +28,15 @@
|
|||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* This file is part of the Contiki operating system.
|
||||||
*
|
*
|
||||||
* @(#)$Id: rt.c,v 1.1 2007/03/19 00:16:13 adamdunkels Exp $
|
* @(#)$Id: rtimer.c,v 1.1 2007/03/25 17:10:30 adamdunkels Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "sys/rt.h"
|
#include "sys/rtimer.h"
|
||||||
#include "contiki.h"
|
#include "contiki.h"
|
||||||
|
|
||||||
#define LIST_SIZE 16
|
#define LIST_SIZE 16
|
||||||
|
|
||||||
static struct rt_task *tasks[LIST_SIZE];
|
static struct rtimer *rtimers[LIST_SIZE];
|
||||||
static u8_t next, firstempty;
|
static u8_t next, firstempty;
|
||||||
|
|
||||||
#define DEBUG 0
|
#define DEBUG 0
|
||||||
@ -49,105 +49,105 @@ static u8_t next, firstempty;
|
|||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
rt_init(void)
|
rtimer_init(void)
|
||||||
{
|
{
|
||||||
next = 0;
|
next = 0;
|
||||||
firstempty = 0;
|
firstempty = 0;
|
||||||
rt_arch_init();
|
rtimer_arch_init();
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
int
|
int
|
||||||
rt_post(struct rt_task *task, rt_clock_t time, rt_clock_t duration)
|
rtimer_set(struct rtimer *rtimer, rt_clock_t time, rt_clock_t duration,
|
||||||
|
void (* func)(struct rtimer *t, void *ptr), void *ptr)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
PRINTF("rt_post time %d\n", time);
|
PRINTF("rtimer_set time %d\n", time);
|
||||||
|
|
||||||
/* Check if task queue is full. */
|
/* Check if rtimer queue is full. */
|
||||||
if(firstempty == (next - 1) % LIST_SIZE) {
|
if(firstempty == (next - 1) % LIST_SIZE) {
|
||||||
PRINTF("rt_post: next %d firstempty %d full\n", next, firstempty);
|
PRINTF("rtimer_set: next %d firstempty %d full\n", next, firstempty);
|
||||||
return RT_ERR_FULL;
|
return RTIMER_ERR_FULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if it is possible to run this task at the requested
|
/* Check if it is possible to run this rtimer at the requested
|
||||||
time. */
|
time. */
|
||||||
for(i = next; i != firstempty;
|
for(i = next; i != firstempty;
|
||||||
i = (i + 1) % LIST_SIZE) {
|
i = (i + 1) % LIST_SIZE) {
|
||||||
|
|
||||||
/* XXX: should check a range of time not just the same precise
|
/* XXX: should check a range of time not just the same precise
|
||||||
moment. */
|
moment. */
|
||||||
if(tasks[i]->time == time) {
|
if(rtimers[i]->time == time) {
|
||||||
PRINTF("rt_post: next %d firstempty %d time %d == %d\n",
|
PRINTF("rtimer_set: next %d firstempty %d time %d == %d\n",
|
||||||
next, firstempty, tasks[i]->time, time);
|
next, firstempty, rtimers[i]->time, time);
|
||||||
return RT_ERR_TIME;
|
return RTIMER_ERR_TIME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Put the task at the end of the task list. */
|
/* Put the rtimer at the end of the rtimer list. */
|
||||||
task->time = time;
|
rtimer->time = time;
|
||||||
tasks[firstempty] = task;
|
rtimers[firstempty] = rtimer;
|
||||||
PRINTF("rt_post: putting task %s as %d\n", task->name, firstempty);
|
PRINTF("rt_post: putting rtimer %s as %d\n", rtimer->name, firstempty);
|
||||||
|
|
||||||
firstempty = (firstempty + 1) % LIST_SIZE;
|
firstempty = (firstempty + 1) % LIST_SIZE;
|
||||||
|
|
||||||
/* PRINTF("rt_post: next %d firstempty %d scheduling soon\n",
|
/* PRINTF("rt_post: next %d firstempty %d scheduling soon\n",
|
||||||
next, firstempty);*/
|
next, firstempty);*/
|
||||||
|
|
||||||
/* Check if this is the first task on the list. If so, we need to
|
/* Check if this is the first rtimer on the list. If so, we need to
|
||||||
run the rt_arch_schedule() function to get the ball rolling. */
|
run the rt_arch_schedule() function to get the ball rolling. */
|
||||||
if(firstempty == (next + 1) % LIST_SIZE) {
|
if(firstempty == (next + 1) % LIST_SIZE) {
|
||||||
|
|
||||||
PRINTF("rt_post scheduling %d %s (%d)\n",
|
PRINTF("rtimer_set scheduling %d %s (%d)\n",
|
||||||
next, tasks[next]->name, tasks[next]->time);
|
next, rtimers[next]->name, rtimers[next]->time);
|
||||||
rt_arch_schedule(time);
|
rtimer
|
||||||
}
|
}
|
||||||
|
|
||||||
return RT_OK;
|
return RTIMER_OK;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
rt_task_run(void)
|
rtimer_run_next(void)
|
||||||
{
|
{
|
||||||
int i, n;
|
int i, n;
|
||||||
struct rt_task *t;
|
struct rtimer *t;
|
||||||
|
|
||||||
t = tasks[next];
|
t = rtimers[next];
|
||||||
|
|
||||||
/* Increase the pointer to the next task. */
|
/* Increase the pointer to the next rtimer. */
|
||||||
next = (next + 1) % LIST_SIZE;
|
next = (next + 1) % LIST_SIZE;
|
||||||
|
|
||||||
/* Run the task. */
|
/* Run the rtimer. */
|
||||||
PRINTF("rt_task_run running %s\n", t->name);
|
PRINTF("rtimer_run_next running %s\n", t->name);
|
||||||
t->func(t, t->ptr);
|
t->func(t, t->ptr);
|
||||||
|
|
||||||
if(next == firstempty) {
|
if(next == firstempty) {
|
||||||
PRINTF("rt_task_run: empty task list\n");
|
PRINTF("rtimer_run_next: empty rtimer list\n");
|
||||||
/* The list is empty, no more tasks to schedule. */
|
/* The list is empty, no more rtimers to schedule. */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Find the next task to run. */
|
/* Find the next rtimer to run. */
|
||||||
n = next;
|
n = next;
|
||||||
for(i = next; i != firstempty; i = (i + 1) % LIST_SIZE) {
|
for(i = next; i != firstempty; i = (i + 1) % LIST_SIZE) {
|
||||||
PRINTF("rt_task_run checking %s (%d) against %s (%d)\n",
|
PRINTF("rtimer_run_next checking %s (%d) against %s (%d)\n",
|
||||||
tasks[i]->name, tasks[i]->time,
|
rtimers[i]->name, rtimers[i]->time,
|
||||||
tasks[n]->name, tasks[n]->time);
|
rtimers[n]->name, rtimers[n]->time);
|
||||||
if(tasks[i]->prio >= tasks[n]->prio &&
|
if(RT_CLOCK_LT(rtimers[i]->time, rtimers[n]->time)) {
|
||||||
RT_CLOCK_LT(tasks[i]->time, tasks[n]->time)) {
|
|
||||||
n = i;
|
n = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PRINTF("rt_task_run next task is %d %s (%d)\n",
|
PRINTF("rtimer_run_next next rtimer is %d %s (%d)\n",
|
||||||
n, tasks[n]->name, tasks[n]->time);
|
n, rtimers[n]->name, rtimers[n]->time);
|
||||||
|
|
||||||
/* Put the next task first in the task list. */
|
/* Put the next rtimer first in the rtimer list. */
|
||||||
t = tasks[next];
|
t = rtimers[next];
|
||||||
tasks[next] = tasks[n];
|
rtimers[next] = rtimers[n];
|
||||||
tasks[n] = t;
|
rtimers[n] = t;
|
||||||
|
|
||||||
PRINTF("rt_task_run scheduling %d %s (%d)\n",
|
PRINTF("rtimer_run_next scheduling %d %s (%d)\n",
|
||||||
next, tasks[next]->name, tasks[next]->time);
|
next, rtimers[next]->name, rtimers[next]->time);
|
||||||
|
|
||||||
rt_arch_schedule(tasks[next]->time);
|
rtimer_arch_schedule(rtimers[next]->time);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
@ -45,13 +45,13 @@
|
|||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* This file is part of the Contiki operating system.
|
||||||
*
|
*
|
||||||
* @(#)$Id: rt.h,v 1.1 2007/03/19 00:16:13 adamdunkels Exp $
|
* @(#)$Id: rtimer.h,v 1.1 2007/03/25 17:11:02 adamdunkels Exp $
|
||||||
*/
|
*/
|
||||||
#ifndef __RT_H__
|
#ifndef __RTIMER_H__
|
||||||
#define __RT_H__
|
#define __RTIMER_H__
|
||||||
|
|
||||||
typedef unsigned short rt_clock_t;
|
typedef unsigned short rtimer_clock_t;
|
||||||
#define RT_CLOCK_LT(a,b) ((signed short)((a)-(b)) < 0)
|
#define RTIMER_CLOCK_LT(a,b) ((signed short)((a)-(b)) < 0)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Initialize the real-time scheduler.
|
* \brief Initialize the real-time scheduler.
|
||||||
@ -60,7 +60,7 @@ typedef unsigned short rt_clock_t;
|
|||||||
* must be called at boot-up, before any other functions
|
* must be called at boot-up, before any other functions
|
||||||
* from the real-time scheduler is called.
|
* from the real-time scheduler is called.
|
||||||
*/
|
*/
|
||||||
void rt_init(void);
|
void rtimer_init(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Repressentation of a real-time task
|
* \brief Repressentation of a real-time task
|
||||||
@ -69,37 +69,21 @@ void rt_init(void);
|
|||||||
* by the real-time module and the architecture specific
|
* by the real-time module and the architecture specific
|
||||||
* support module for the real-time module.
|
* support module for the real-time module.
|
||||||
*/
|
*/
|
||||||
struct rt_task {
|
struct rtimer {
|
||||||
char *name;
|
rtimer_clock_t time;
|
||||||
rt_clock_t time;
|
void (* func)(struct rtimer *t, void *ptr);
|
||||||
void (* func)(struct rt_task *t, void *ptr);
|
|
||||||
unsigned char prio;
|
|
||||||
void *ptr;
|
void *ptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Declare a real-time task.
|
|
||||||
* \param name The name of the task state variable.
|
|
||||||
* \param func The function implementing the real-time task.
|
|
||||||
* \param prio The priority of the task.
|
|
||||||
* \param ptr An opaque pointer that is passed to the real-time task
|
|
||||||
* when it is executed.
|
|
||||||
*
|
|
||||||
* This macro declares a real-time task.
|
|
||||||
*
|
|
||||||
* \hideinitializer
|
|
||||||
*/
|
|
||||||
#define RT_TASK(name, func, prio, ptr) { name, 0, func, prio, ptr }
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
RT_OK,
|
RTIMER_OK,
|
||||||
RT_ERR_FULL,
|
RTIMER_ERR_FULL,
|
||||||
RT_ERR_TIME,
|
RTIMER_ERR_TIME,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Post a real-time task.
|
* \brief Post a real-time task.
|
||||||
* \param task A pointer to the task variable previously declared with RT_TASK().
|
* \param task A pointer to the task variable previously declared with RTIMER_TASK().
|
||||||
* \param time The time when the task is to be executed.
|
* \param time The time when the task is to be executed.
|
||||||
* \return Non-zero (true) if the task could be scheduled, zero
|
* \return Non-zero (true) if the task could be scheduled, zero
|
||||||
* (false) if the task could not be scheduled.
|
* (false) if the task could not be scheduled.
|
||||||
@ -108,7 +92,8 @@ enum {
|
|||||||
* time in the future.
|
* time in the future.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int rt_post(struct rt_task *task, rt_clock_t time, rt_clock_t duration);
|
int rtimer_set(struct rtimer *t, rtimer_clock_t time, rtimer_clock_t duration,
|
||||||
|
void (* func)(struct rtimer *t, void *ptr), void *ptr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Execute the next real-time task and schedule the next task, if any
|
* \brief Execute the next real-time task and schedule the next task, if any
|
||||||
@ -117,7 +102,7 @@ int rt_post(struct rt_task *task, rt_clock_t time, rt_clock_t duration);
|
|||||||
* code to execute and schedule the next real-time task.
|
* code to execute and schedule the next real-time task.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void rt_task_run(void);
|
void rtimer_next(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Get the current clock time
|
* \brief Get the current clock time
|
||||||
@ -129,7 +114,7 @@ void rt_task_run(void);
|
|||||||
*
|
*
|
||||||
* \hideinitializer
|
* \hideinitializer
|
||||||
*/
|
*/
|
||||||
#define RT_NOW() rt_arch_now()
|
#define RTIMER_NOW() rtimer_arch_now()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Get the time that a task last was executed
|
* \brief Get the time that a task last was executed
|
||||||
@ -142,15 +127,14 @@ void rt_task_run(void);
|
|||||||
*
|
*
|
||||||
* \hideinitializer
|
* \hideinitializer
|
||||||
*/
|
*/
|
||||||
#define RT_TASK_TIME(task) ((task)->time)
|
#define RTIMER_TIME(task) ((task)->time)
|
||||||
|
|
||||||
void rt_arch_init(void);
|
void rtimer_arch_init(void);
|
||||||
void rt_arch_schedule(rt_clock_t t);
|
void rtimer_arch_schedule(rtimer_clock_t t);
|
||||||
rt_clock_t rt_arch_now(void);
|
rtimer_clock_t rtimer_arch_now(void);
|
||||||
|
|
||||||
|
#include "rtimer-arch.h"
|
||||||
|
|
||||||
#include "rt-arch.h"
|
#endif /* __RTIMER_H__ */
|
||||||
|
|
||||||
#endif /* __RT_H__ */
|
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
Loading…
Reference in New Issue
Block a user