1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/core/include/sched.h

109 lines
2.5 KiB
C
Raw Normal View History

/**
* @ingroup kernel
* @{
2013-06-21 22:37:14 +02:00
* @file sched.h
* @author Freie Universität Berlin, Computer Systems & Telematics
* @author Kaspar Schleiser <kaspar@schleiser.de>
*/
#ifndef _SCHEDULER_H
#define _SCHEDULER_H
#include <stddef.h>
#include <bitarithm.h>
#include "tcb.h"
#define MAXTHREADS 32
#if ARCH_32_BIT
#define SCHED_PRIO_LEVELS 32
#else
#define SCHED_PRIO_LEVELS 16
#endif
2013-08-14 13:04:19 +02:00
/**
* @brief Initializes thread table, active thread information, and runqueues
*/
void sched_init(void);
2013-08-14 13:04:19 +02:00
/**
2013-08-14 14:15:11 +02:00
* @brief Triggers the scheduler to schedule the next task
2013-08-14 13:04:19 +02:00
*/
void sched_run(void);
2013-08-14 13:04:19 +02:00
/**
* @brief Set the status of the specified process
*
* @param[in] process Pointer to the thread control block of the
* targeted process
* @param[in] status The new status of this thread
*/
void sched_set_status(tcb_t *process, unsigned int status);
2013-08-14 13:04:19 +02:00
/**
2013-08-14 14:15:11 +02:00
* @brief Compare thread priorities and yield() (or set
* sched_context_switch_request if in_isr) when other_prio is higher
* (has a lower value) than current_prio
2013-08-14 13:04:19 +02:00
*
* @param[in] current_prio The priority of the current thread
* @param[in] other_prio The priority of the target thread
2013-08-14 14:15:11 +02:00
* @param[in] in_isr 1 if currently in interrupt context, 0 otherwise
*/
2010-11-11 11:22:45 +01:00
void sched_switch(uint16_t current_prio, uint16_t other_prio, int in_isr);
2013-08-14 13:04:19 +02:00
/**
* @brief Call context switching at task exit
*/
void cpu_switch_context_exit(void);
2013-08-14 13:04:19 +02:00
/**
2013-08-14 14:15:11 +02:00
* Flag indicating whether a context switch is necessary after handling an
* interrupt. Supposed to be set in an ISR.
2013-08-14 13:04:19 +02:00
*/
extern volatile unsigned int sched_context_switch_request;
2013-08-14 13:04:19 +02:00
/**
* Thread table
*/
extern volatile tcb_t *sched_threads[MAXTHREADS];
2013-08-14 13:04:19 +02:00
/**
* Currently active thread
*/
extern volatile tcb_t *active_thread;
2013-08-14 13:04:19 +02:00
/**
* Number of running (non-terminated) threads
*/
extern volatile int num_tasks;
2013-08-14 13:04:19 +02:00
/**
* Process ID of active thread
*/
extern volatile int thread_pid;
#if SCHEDSTATISTICS
2013-08-14 13:04:19 +02:00
/**
* Scheduler statistics
*/
typedef struct {
2013-08-14 13:04:19 +02:00
unsigned int laststart; /*< Time stamp of the last time this thread was
scheduled to run */
unsigned int schedules; /*< How often the thread was scheduled to run */
unsigned long runtime_ticks; /*< The total runtime of this thread in ticks */
} schedstat;
2013-08-14 13:04:19 +02:00
/**
* Thread statistics table
*/
extern schedstat pidlist[MAXTHREADS];
2013-08-14 13:04:19 +02:00
/**
2013-08-14 14:15:11 +02:00
* Register a callback that will be called on every scheduler run
2013-08-14 13:04:19 +02:00
*/
void sched_register_cb(void (*callback)(uint32_t, uint32_t));
#endif
/** @} */
#endif // _SCHEDULER_H