xyControl  0.1
Quadrotor Flight Controller on AVR Basis
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups
Files | Data Structures | Typedefs | Functions | Variables
Task Handler

System for registering different tasks that will be called regularly, one after another. More...

Files

file  tasks.h
 Task API Header.
 
file  tasks.c
 Task API Implementation.
 

Data Structures

struct  TaskElement
 Single-Linked Task List. More...
 

Typedefs

typedef void(* Task )(void)
 A Task has no arguments and returns nothing. More...
 

Functions

uint8_t addTask (Task func)
 Adds another task that will be called regularly. More...
 
uint8_t removeTask (Task func)
 Removes an already registered Task. More...
 
void tasks (void)
 Executes registered Tasks. More...
 
uint8_t tasksRegistered (void)
 Get the number of registered Tasks. More...
 

Variables

TaskElementtaskList
 List of registered Tasks. More...
 
TaskElementtaskList = NULL
 List of registered Tasks. More...
 

Detailed Description

System for registering different tasks that will be called regularly, one after another.

Typedef Documentation

typedef void(* Task)(void)

A Task has no arguments and returns nothing.

Definition at line 44 of file tasks.h.

Function Documentation

uint8_t addTask ( Task  func)

Adds another task that will be called regularly.

Parameters
funcTask to be executed
Returns
0 on success
Examples:
hardwareTest.c, and uartFlight.c.

Definition at line 57 of file tasks.c.

References BANK_GENERIC, MEMSWITCH, MEMSWITCHBACK, TaskElement::next, TaskElement::task, and taskList.

Referenced by xyInit().

57  {
59  TaskElement *p = (TaskElement *)malloc(sizeof(TaskElement));
60  if (p == NULL) {
62  return 1;
63  }
64  p->task = func;
65  p->next = taskList;
66  taskList = p;
68  return 0;
69 }
uint8_t removeTask ( Task  func)

Removes an already registered Task.

Parameters
funcTask to be removed
Returns
0 on success

Definition at line 71 of file tasks.c.

References BANK_GENERIC, MEMSWITCH, MEMSWITCHBACK, TaskElement::next, TaskElement::task, and taskList.

71  {
73  TaskElement *p = taskList;
74  TaskElement *prev = NULL;
75  while (p != NULL) {
76  if (p->task == func) {
77  if (prev == NULL) {
78  taskList = p->next;
79  } else {
80  prev->next = p->next;
81  }
82  free(p);
84  return 0;
85  }
86  prev = p;
87  p = p->next;
88  }
90  return 1;
91 }
void tasks ( void  )

Executes registered Tasks.

Call this in your Main Loop!

Examples:
hardwareTest.c, test.c, and uartFlight.c.

Definition at line 93 of file tasks.c.

References BANK_GENERIC, MEMSWITCH, MEMSWITCHBACK, TaskElement::next, TaskElement::task, and taskList.

93  {
95  static TaskElement *p = NULL;
96  if (p == NULL) {
97  p = taskList;
98  }
99  if (p != NULL) {
100  p->task();
101  p = p->next;
102  }
104 }
uint8_t tasksRegistered ( void  )

Get the number of registered Tasks.

Returns
Count of registered Tasks

Definition at line 47 of file tasks.c.

References BANK_GENERIC, MEMSWITCH, MEMSWITCHBACK, and TaskElement::next.

47  {
48  uint8_t c = 0;
50  for (TaskElement *p = taskList; p != NULL; p = p->next) {
51  c++;
52  }
54  return c;
55 }

Variable Documentation

TaskElement* taskList = NULL

List of registered Tasks.

Definition at line 45 of file tasks.c.

Referenced by addTask(), removeTask(), and tasks().

TaskElement* taskList

List of registered Tasks.

Definition at line 45 of file tasks.c.

Referenced by addTask(), removeTask(), and tasks().