A(rduino) OS
Simple Task Scheduler for Arduino Development Board
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
aos_sched.c File Reference

scheduler routines implementation More...

#include "aos_sched.h"
#include "aos_common.h"
#include "aos_constants.h"
#include "aos_list.h"
#include "aos_timer.h"
#include <avr/io.h>
#include <avr/interrupt.h>

Go to the source code of this file.

Functions

static uint8_t _aos_sched_calculate_quanta (uint8_t a_prio)
 Translates priority to quanta. More...
 
static void _aos_sched_task_hold (struct task_cb *a_task, uint8_t a_suspend)
 generic implementation for sleeping/suspending tasks More...
 
static void _aos_sched_task_bring_back (struct task_cb *a_task, uint8_t a_resume, uint8_t a_ft)
 generic implementation for awaking/resuming tasks More...
 
void _aos_sched_tick_yield ()
 called from tick interrupt as a request to reschedule a task More...
 
void _aos_sched_reschedule ()
 called when quanta of the current task expired. More...
 
__inline__ void aos_sched_task_sleep (struct task_cb *a_task)
 will sleep the task -> put it in the beginning of the wait queue, until task is resumed More...
 
__inline__ void aos_sched_task_awake (struct task_cb *a_task)
 will bring the task back from it's sleep state. More...
 
__inline__ void aos_sched_task_suspend (struct task_cb *a_task)
 will suspend the task -> put it at the end of the wait queue. More...
 
__inline__ void aos_sched_task_resume (struct task_cb *a_task)
 resume a task, previously suspended More...
 
 __attribute__ ((naked))
 

Variables

volatile struct aos_sys _g_sys
 global system context defined in aos_common More...
 

Detailed Description

scheduler routines implementation

Definition in file aos_sched.c.

Function Documentation

__attribute__ ( (naked)  )

Definition at line 191 of file aos_sched.c.

static uint8_t _aos_sched_calculate_quanta ( uint8_t  a_prio)
static

Translates priority to quanta.

Parameters
a_priopriority
Returns
number of quantas which process of given priority should receive

Definition at line 219 of file aos_sched.c.

void _aos_sched_reschedule ( )

called when quanta of the current task expired.

This routine goes through run list and search for a new task to be scheduled. If no task can be found, it will set the idle task as the current one.

This function is private and shouldn't be called from outside of the system itself.

Definition at line 114 of file aos_sched.c.

static void _aos_sched_task_bring_back ( struct task_cb a_task,
uint8_t  a_resume,
uint8_t  a_ft 
)
static

generic implementation for awaking/resuming tasks

Parameters
a_tasktask to be awaken/resumed
a_resume1 - resume, 0 - awake
a_ft1 - called from tick interrupt, 0 - called from normal processing flow

Definition at line 265 of file aos_sched.c.

static void _aos_sched_task_hold ( struct task_cb a_task,
uint8_t  a_suspend 
)
static

generic implementation for sleeping/suspending tasks

Parameters
a_tasktask to be put to sleep/suspended
a_suspend1 - suspend, 0 - sleep

Definition at line 231 of file aos_sched.c.

void _aos_sched_tick_yield ( )

called from tick interrupt as a request to reschedule a task

This is a private API and should not be used outside the system code.

Definition at line 74 of file aos_sched.c.

__inline__ void aos_sched_task_awake ( struct task_cb a_task)

will bring the task back from it's sleep state.

The task will be rescheduled immediately if it has higher priority than the current one

Parameters
a_tasktask to be awoken
Examples:
sched_01.c.

Definition at line 174 of file aos_sched.c.

__inline__ void aos_sched_task_resume ( struct task_cb a_task)

resume a task, previously suspended

Parameters
a_tasktask to be resumed

Definition at line 186 of file aos_sched.c.

__inline__ void aos_sched_task_sleep ( struct task_cb a_task)

will sleep the task -> put it in the beginning of the wait queue, until task is resumed

Parameters
a_tasktask to be paused
Examples:
sched_01.c.

Definition at line 168 of file aos_sched.c.

__inline__ void aos_sched_task_suspend ( struct task_cb a_task)

will suspend the task -> put it at the end of the wait queue.

The difference between sleeping a task and suspending it is very subtle. In fact, it is only a logical distinction. The sleep state should be treated as a more temporary state, while suspend state is meant to be more permanent. The only difference in implementation is that task being put to sleep are placed at the beginning of the list - so they can be found quicker.

Parameters
a_tasktask to be suspended

Definition at line 180 of file aos_sched.c.

Variable Documentation

volatile struct aos_sys _g_sys

global system context defined in aos_common

global system context defined in aos_common

Definition at line 40 of file aos_common.c.