/******************************************************************
** scheduler.h  Timetable scheduler
**
** 22.10.2010 li
** 27.05.2011 li nur noch relative zeiten
** 15.05.2012 li Wenn SCHED_LONG gesetzt, dann unsigned long Zeitwerte
** 20.07.2012 li Prozess id dazu und value auf unsigned char
*/
#ifndef _SCHEDULER_H_
#define _SCHEDULER_H_

#include <stdlib.h>
//#include "config.h"
                                         // Zielfunktions pointer
typedef void (*_ptarget)(unsigned char);

typedef struct                           // Time Table Entry
{
   unsigned char value;                  // uebergabewert
#ifdef PROZESS_TRACE
   char          pid;                    // prozess id
#endif
   _ptarget fp;                          // Pointer auf Ziel-Funktion
#ifdef SCHED_LONG
   unsigned long  c_time;                // time
   unsigned long  target_time;           // Zieltime
#else
   unsigned int  c_time;                 // time
   unsigned int  target_time;            // Zieltime
#endif
} TIME_TABLE;


typedef struct
{
#ifdef TT_COMPUTE_MAX
   unsigned char timetable_max; 
   unsigned char timetable_cnt; 
#endif   
   volatile int error;         // errors
} S_SCHEDULE;


void Scheduler_Init(void);               // Init time table (clear)

void Delete_TT_Entry( _ptarget fp );

#ifdef SCHED_LONG
                                         // return: 1 = OK, 0 = Time Table voll
#ifdef PROZESS_TRACE
unsigned char Insert_TT_Entry( unsigned long ms, _ptarget fp, unsigned char wert, char pid);
#else   // PROZESS_TRACE
unsigned char Insert_TT_Entry( unsigned long ms, _ptarget fp, unsigned char wert);
#endif  // PROZESS_TRACE
#else   // SCHED_LONG
#ifdef PROZESS_TRACE
unsigned char Insert_TT_Entry( unsigned int ms, _ptarget fp, unsigned char wert, char pid);
#else   // PROZESS_TRACE
unsigned char Insert_TT_Entry( unsigned int ms, _ptarget fp, unsigned char wert);
#endif  // PROZESS_TRACE
#endif  // SCHED_LONG

void schedule( unsigned char tick );     // timetable auswerten (je tick aufrufen)

#endif // _SCHEDULER_H_

