- Main Page
- Modules
- Data Structures
- Files
- Directories

# e_agenda_fast.c File Reference

Manage the fast agendas (timer1, 2, 3). More...

`#include "e_agenda_fast.h"`
`#include "../../e_epuck_ports.h"`
`#include <stdlib.h>`

## Defines
#define | EXIT_OK 1
## Functions
unsigned | compute_gcd (unsigned u, unsigned v)
unsigned | my_ceil (float a)
void | e_set_timer_speed (int timer, unsigned speed)
int | search_best_fit (unsigned cycle)
void | recompute_speeds ()
Agenda * | find_function (void(*func)(void))
unsigned | assign_agenda (Agenda *agenda)
void | migrate (int timer)
void | e_start_agendas_processing (void)
| Initialise the accounting structure.
void | e_configure_timer (int timer)
| Configure the timer(s) used.
void | e_start_timer_processing (int timer)
| Start the timer(s) used.
void | e_end_agendas_processing (int timer)
| Stop an agenda running.
void | e_activate_agenda (void(*func)(void), unsigned cycle)
| Activate a fast agenda.
void | e_activate_motors (void(*func1)(void), void(*func2)(void))
int | e_set_motor_speed (void(*func)(void), unsigned cycle)
int | e_destroy_agenda (void(*func)(void))
| Destroy an agenda.
int | e_set_agenda_cycle (void(*func)(void), unsigned cycle)
int | e_reset_agenda (void(*func)(void))
| Reset an agenda.
int | e_pause_agenda (void(*func)(void))
| Pause an agenda.
int | e_restart_agenda (void(*func)(void))
| Restart an agenda previously paused.
void | __attribute__ ((__interrupt__, auto_psv))
| Interrupt from timer1.
## Variables
static struct AgendaList | agenda_list

## Detailed Description

Manage the fast agendas (timer1, 2, 3).

This module manage the fast agendas with the timer1, 2, 3.
An agenda is a structure made to work as chained list. It containts: the function you want to launch, the time setup between two launching events, a counter to measure the current time, a pointer to the next element of the list.
Each times the timer1, 2, 3 has an interrupt, the corresponding agenda chained list is scanned to look if an agenda has to be treated according to the cycle value and current counter value.
If one (or more) agenda has to be treated, his callback function is launch.

Author:
  Code: Julien Hubert
  Doc: Jonathan Besuchet

## Define Documentation

#define EXIT_OK 1

## Function Documentation

void __attribute__ | ( | (__interrupt__, auto_psv) |  | ) |

Interrupt from timer1.

Interrupt from timer3.

Interrupt from timer2.

Parse the chained list of agenda.
Increment counter only.
Check if agenda has to be treated according to the cycle value and current counter value.
Do it for number of cycle positive or null.
Check if a service has to be activated.

unsigned assign_agenda | ( | Agenda * | agenda | ) |

unsigned compute_gcd | ( | unsigned | u,
|  | unsigned | v |
| ) |  |  |

void e_activate_agenda | ( | void(*)(void) | func,
|  | unsigned | cycle |
| ) |  |  |

Activate a fast agenda.

Activate an agenda and allocate memory for him if there isn't already an agenda with the same callback function (the agenda is active but isn't processed if he have a null cycle value).
The appropriate timer is automatically selected.

Parameters:

  | func | function called if the cycle value is reached by the counter
  | cycle | cycle value in millisec/10

void e_activate_motors | ( | void(*)(void) | func1,
|  | void(*)(void) | func2 |
| ) |  |  |

void e_configure_timer | ( | int | timer | ) |

Configure the timer(s) used.

Configure one or all the timers to be used by the agenda

Parameters:

  | timer | the timer's number to configure (between [0-3] with 0 configuring all of them)

int e_destroy_agenda | ( | void(*)(void) | func | ) |

Destroy an agenda.

Destroy the agenda with a given callback function

Parameters:

  | func | function to test

Returns:
  int return the success of the destruction (EXIT_OK for successfull, AG_NOT_FOUND for unsuccessfull).

void e_end_agendas_processing | ( | int | timer | ) |

Stop an agenda running.

Stop the agendas running on one particular timer (the memory allocated for the agenda isn't freed, use e_destroy_agenda for that).

Parameters:

  | timer | the timer's number [0-3]. 0 stops all the timers.

See also:
  e_destroy_agenda

int e_pause_agenda | ( | void(*)(void) | func | ) |

Pause an agenda.

Pause an agenda but do not reset its information.

Parameters:

  | func | function to pause

int e_reset_agenda | ( | void(*)(void) | func | ) |

Reset an agenda.

Reset an agenda's counter.

Reset an agenda's counter with a given callback function

Parameters:

  | func | function to reset

int e_restart_agenda | ( | void(*)(void) | func | ) |

Restart an agenda previously paused.

Restart an agenda previously paused

Parameters:

  | func | function to restart

int e_set_agenda_cycle | ( | void(*)(void) | func,
|  | unsigned | cycle |
| ) |  |  |

int e_set_motor_speed | ( | void(*)(void) | func,
|  | unsigned | cycle |
| ) |  |  |

void e_set_timer_speed | ( | int | timer,
|  | unsigned | speed |
| ) |  |  |

void e_start_agendas_processing | ( | void |  | ) |

Initialise the accounting structure.

Start the agendas processing.

Start the agendas processing by initialising the accounting structures.
Don't activate any timer which is done by e_start_timer_processing.

See also:
  e_start_timer_processing

void e_start_timer_processing | ( | int | timer | ) |

Start the timer(s) used.

Activate one or all the timers to be used by the agenda.

Parameters:

  | timer | the timer's number to activate (between [0-3] with 0 activating all of them)

Agenda* find_function | ( | void(*)(void) | func | ) |

void migrate | ( | int | timer | ) |

unsigned my_ceil | ( | float | a | ) |

void recompute_speeds | ( |  | ) |

int search_best_fit | ( | unsigned | cycle | ) |

## Variable Documentation

struct AgendaList agenda_list`[static]`