rseq.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #include "core/config.h"
  2. #if CONFIG_AUTOMAT_MODE || CONFIG_LEDS
  3. #ifndef ROUTINE_SEQUENCE_H
  4. #define ROUTINE_SEQUENCE_H
  5. #include <stdint.h>
  6. #include <stdbool.h>
  7. #define RSA_STRICT_CHECKS 0
  8. #define RSA_USE_LOCKERS 1
  9. typedef bool fRoutine_t( void * arg );
  10. //------------------------------------------------------------------------------
  11. typedef struct
  12. {
  13. int32_t idx; // pending routine index
  14. uint32_t count; // amount of routines in list
  15. uint32_t size; // size of routine list
  16. fRoutine_t ** papfRoutineList; // routine list
  17. void * arg; // user argument to be passed
  18. #if RSA_USE_LOCKERS > 0
  19. fRoutine_t * fLocker;
  20. fRoutine_t * fUnlocker;
  21. #endif
  22. }
  23. sRoutineSequence_t; //=Routine Sequence Entry
  24. //------------------------------------------------------------------------------
  25. // rsa_sequence_init()
  26. // Initialize sRoutineSequence_t before any operations
  27. // Params:
  28. // * IN/OUT [ sRoutineSequence_t ] @pSeq - the sequence to be initialized
  29. // * IN [ void * ] @arg - an user argument to be passed into each routine
  30. // * IN [ fRoutine_t ** ] @papfRoutineList - the routine list to hold the values
  31. // * IN [ uint32_t ] @size - the size of routine list array @papfRoutineList
  32. // Returns:
  33. // [ bool ], result of operation, true = success, false = error
  34. bool rsa_sequence_init( sRoutineSequence_t * pSeq, void * arg, fRoutine_t ** papfRoutineList, uint32_t size );
  35. //------------------------------------------------------------------------------
  36. #if RSA_USE_LOCKERS > 0
  37. // rsa_sequence_setlockers()
  38. // Specifies a special Lock/Unlock function to be used during all procedures
  39. // Params:
  40. // * IN/OUT [ sRoutineSequence_t ] @pSeq - the sequence to be initialized
  41. // * IN [ fRoutine_t * ] @fLocker - a function to be used to lock the object @pSeq
  42. // * IN [ fRoutine_t * ] @fUnlocker - a function to be used to unlock the object @pSeq
  43. // Returns:
  44. // [ bool ], result of operation, true = success, false = error
  45. bool rsa_sequence_setlockers( sRoutineSequence_t * pSeq, fRoutine_t * fLocker, fRoutine_t * fUnlocker );
  46. #endif
  47. // -----------------------------------------------------------------------------
  48. // rsa_sequence_insert_routine()
  49. // Inserts a routine into the routine sequence
  50. // Params:
  51. // * IN/OUT [ sRoutineSequence_t ] @pSeq - the sequence to be modified
  52. // * IN [ fRoutine_t * ] @routine - a routine to be inserted
  53. // Returns:
  54. // [ bool ], result of operation, true = success, false = error
  55. bool rsa_sequence_insert_routine( sRoutineSequence_t * pSeq, fRoutine_t * routine );
  56. #if RSA_USE_LOCKERS > 0
  57. bool rsa_sequence_iinsert_routine( sRoutineSequence_t * pSeq, fRoutine_t * routine );
  58. #endif
  59. // -----------------------------------------------------------------------------
  60. // rsa_sequence_remove_routine()
  61. // Removes the lastest routine from the routine sequence
  62. // Params:
  63. // * IN/OUT [ sRoutineSequence_t ] @pSeq - the sequence to be modified
  64. // Returns:
  65. // [ bool ], result of operation, true = success, false = error
  66. bool rsa_sequence_remove_routine( sRoutineSequence_t * pSeq );
  67. #if RSA_USE_LOCKERS > 0
  68. bool rsa_sequence_iremove_routine( sRoutineSequence_t * pSeq );
  69. #endif
  70. // -----------------------------------------------------------------------------
  71. // rsa_sequence_call()
  72. // Implements an ordinar call of the routines sequence
  73. // Params:
  74. // * IN/OUT [ sRoutineSequence_t ] @pSeq - the sequence to be modified
  75. // Returns:
  76. // [ bool ], end of sequence sign, true = sequence completed, false = sequence is in progress
  77. bool rsa_sequence_call( sRoutineSequence_t * pSeq );
  78. #if RSA_USE_LOCKERS > 0
  79. bool rsa_sequence_icall( sRoutineSequence_t * pSeq );
  80. #endif
  81. // -----------------------------------------------------------------------------
  82. // rsa_sequence_reset()
  83. // Resets the routines sequence and makes it to be restarted
  84. // Params:
  85. // * IN/OUT [ sRoutineSequence_t ] @pSeq - the sequence to be modified
  86. // Returns:
  87. // [ bool ], result of operation, true = success, false = error
  88. bool rsa_sequence_reset( sRoutineSequence_t * pSeq );
  89. #if RSA_USE_LOCKERS > 0
  90. bool rsa_sequence_ireset( sRoutineSequence_t * pSeq );
  91. #endif
  92. // -----------------------------------------------------------------------------
  93. // rsa_sequence_clear()
  94. // Clears all the routines in the sequence
  95. // Params:
  96. // * IN/OUT [ sRoutineSequence_t ] @pSeq - the sequence to be modified
  97. // Returns:
  98. // [ bool ], result of operation, true = success, false = error
  99. bool rsa_sequence_clear( sRoutineSequence_t * pSeq );
  100. #if RSA_USE_LOCKERS > 0
  101. bool rsa_sequence_iclear( sRoutineSequence_t * pSeq );
  102. #endif
  103. // -----------------------------------------------------------------------------
  104. // rsa_sequence_skip_routine()
  105. // Skips the current routine into the routine sequence
  106. // Params:
  107. // * IN/OUT [ sRoutineSequence_t ] @pSeq - the sequence to be modified
  108. // Returns:
  109. // [ bool ], result of operation, true = success, false = error
  110. #if RSA_USE_LOCKERS > 0
  111. bool rsa_sequence_skip_routine( sRoutineSequence_t * pSeq );
  112. bool rsa_sequence_iskip_routine( sRoutineSequence_t * pSeq );
  113. #else
  114. bool rsa_sequence_iskip_routine( sRoutineSequence_t * pSeq );
  115. #endif
  116. // -----------------------------------------------------------------------------
  117. // rsa_sequence_back_routine()
  118. // Rolls the routine sequence back and make the previous routine to be called
  119. // Params:
  120. // * IN/OUT [ sRoutineSequence_t ] @pSeq - the sequence to be modified
  121. // Returns:
  122. // [ bool ], result of operation, true = success, false = error
  123. #if RSA_USE_LOCKERS > 0
  124. bool rsa_sequence_back_routine( sRoutineSequence_t * pSeq );
  125. bool rsa_sequence_iback_routine( sRoutineSequence_t * pSeq );
  126. #else
  127. bool rsa_sequence_iback_routine( sRoutineSequence_t * pSeq );
  128. #endif
  129. #endif
  130. #endif