sc_timer_service.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Timer Service for SCTUnit
  3. */
  4. #ifndef SC_TIMER_SERVICE_H_
  5. #define SC_TIMER_SERVICE_H_
  6. #include "sc_types.h"
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. /*! file/ Interface definition of a POSIX thread based timer service for YAKINDU SCT stet machines. */
  11. typedef struct {
  12. sc_integer rel_time_ms;
  13. sc_integer abs_time_ms;
  14. sc_boolean periodic;
  15. sc_eventid pt_evid;
  16. sc_integer priority;
  17. sc_boolean isRunCycle;
  18. } sc_timer_t;
  19. typedef struct sc_timer_task_s {
  20. sc_timer_t timer;
  21. struct sc_timer_task_s * next;
  22. } sc_timer_task_t;
  23. /*! Function pointer type for state machines raiseEvent function. */
  24. typedef void (*sc_raise_time_event_fp)(void *handle, sc_eventid evid);
  25. typedef void (*sc_run_cycle_fp)(void *handle);
  26. typedef struct {
  27. sc_timer_task_t * tasks;
  28. sc_raise_time_event_fp raise_event_func;
  29. sc_run_cycle_fp run_cycle_func;
  30. sc_boolean event_driven;
  31. sc_integer cycle_period;
  32. void* handle;
  33. sc_integer current_time_ms;
  34. } sc_unit_timer_service_t;
  35. void sc_timer_service_init(
  36. sc_unit_timer_service_t * ts,
  37. sc_raise_time_event_fp raise_event_func,
  38. sc_run_cycle_fp run_cycle_func,
  39. sc_boolean event_driven,
  40. sc_integer cycle_period,
  41. void* handle
  42. );
  43. void sc_timer_init(
  44. sc_timer_t * t,
  45. sc_integer time_ms,
  46. sc_boolean periodic,
  47. sc_eventid evid
  48. );
  49. void sc_timer_service_proceed_time(sc_unit_timer_service_t * ts, sc_integer time_ms);
  50. void sc_timer_service_proceed_cycles(sc_unit_timer_service_t * ts, sc_integer cycles);
  51. sc_timer_t sc_timer_service_proceed(sc_unit_timer_service_t * ts);
  52. void insert_timer(sc_unit_timer_service_t * ts, sc_timer_t te);
  53. void delete_task(sc_unit_timer_service_t * ts, sc_timer_task_t* task);
  54. sc_timer_task_t * find_time_event(sc_unit_timer_service_t * ts, sc_eventid evid);
  55. sc_timer_task_t * pop_task(sc_unit_timer_service_t * ts);
  56. sc_integer compare(sc_timer_t * a, sc_timer_t * b);
  57. #ifdef __cplusplus
  58. }
  59. #endif
  60. #endif /* SC_TIMER_SERVICE_H_ */