sc_timer_service.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * sc_timer.h
  3. *
  4. * Created on: 13.04.2016
  5. * Author: korsisnki, terfloth
  6. */
  7. #ifndef SC_TIMER_SERCICE_H_
  8. #define SC_TIMER_SERCICE_H_
  9. #include "../sc/sc_types.h"
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. /*! file/ Interface definition of a POSIX thread based timer service for YAKINDU SCT stet machines. */
  14. struct sc_timer_service;
  15. /* internal arguments of a timer pthread */
  16. typedef struct {
  17. sc_integer time_ms;
  18. sc_boolean periodic;
  19. sc_integer elapsed_time_ms;
  20. sc_eventid pt_evid;
  21. void* handle;
  22. struct sc_timer_service *service;
  23. } sc_timer_t;
  24. /*! Function pointer type for state machines runCycle function. */
  25. typedef void (*sc_raise_time_event_fp)(void *handle, sc_eventid evid);
  26. typedef struct sc_timer_service {
  27. sc_integer timer_count;
  28. sc_timer_t *timers;
  29. sc_raise_time_event_fp raise_event;
  30. } sc_timer_service_t;
  31. /*! Initializes a timer service with a set of timers. */
  32. extern void sc_timer_service_init(sc_timer_service_t *tservice,
  33. sc_timer_t *timers,
  34. sc_integer count,
  35. sc_raise_time_event_fp raise_event);
  36. extern void sc_timer_service_proceed(sc_timer_service_t *timer_service, const sc_integer time_ms);
  37. /*! Starts a timer with the specified parameters. */
  38. extern void sc_timer_start (
  39. sc_timer_service_t *timer_service,
  40. void* handle,
  41. const sc_eventid evid,
  42. const sc_integer time_ms,
  43. const sc_boolean periodic);
  44. /*! Cancels a timer for the specified time event. */
  45. extern void sc_timer_cancel(sc_timer_service_t *timer_service, const sc_eventid evid);
  46. #ifdef __cplusplus
  47. }
  48. #endif
  49. #endif /* SC_TIMER_SERCICE_H_ */