Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

167 строки
6.6 KiB

  1. #ifndef PLSR_PLATFORM_H
  2. #define PLSR_PLATFORM_H
  3. #include "plsr_internal.h"
  4. #include <stdint.h>
  5. typedef enum
  6. {
  7. PLSR_PLATFORM_STOP_COMPLETE = 0,
  8. PLSR_PLATFORM_STOP_PENDING,
  9. PLSR_PLATFORM_STOP_FORCED_FAULT
  10. } PLSR_PLATFORM_STOP_RESULT;
  11. typedef enum
  12. {
  13. PLSR_PLATFORM_QUEUE_FAILED = 0,
  14. PLSR_PLATFORM_QUEUE_APPLIED,
  15. PLSR_PLATFORM_QUEUE_STALE
  16. } PLSR_PLATFORM_QUEUE_RESULT;
  17. typedef enum
  18. {
  19. PLSR_PLATFORM_SERVICE_FAILED = 0,
  20. PLSR_PLATFORM_SERVICE_READY,
  21. PLSR_PLATFORM_SERVICE_DEFERRED
  22. } PLSR_PLATFORM_SERVICE_RESULT;
  23. typedef struct
  24. {
  25. uint32_t actualFrequencyHz;
  26. uint16_t prescaler;
  27. uint16_t pairPrescaler;
  28. uint16_t period;
  29. uint16_t compare;
  30. } PLSR_PLATFORM_TIMER_SETTING;
  31. typedef struct
  32. {
  33. PLSR_PLATFORM_TIMER_SETTING setting;
  34. uint32_t pulseCount;
  35. uint32_t segmentPulseOffset;
  36. uint8_t segmentNumber;
  37. uint8_t completesSegment;
  38. uint8_t updatesWithSegment;
  39. } PLSR_PLATFORM_FINITE_STEP;
  40. uint8_t PlsrPlatformInit(void);
  41. uint8_t PlsrPlatformPrepare(uint8_t pulseOutput,
  42. uint8_t directionOutput,
  43. uint8_t directionLevel,
  44. uint8_t outputMode,
  45. uint8_t directionPositive);
  46. uint8_t PlsrPlatformStartPulse(uint8_t pulseOutput,
  47. uint32_t firstFrequencyHz,
  48. uint32_t queuedFrequencyHz,
  49. uint32_t *actualFirstFrequencyHz,
  50. uint32_t *actualQueuedFrequencyHz);
  51. uint8_t PlsrPlatformBuildTimerSetting(
  52. uint8_t pulseOutput,
  53. uint8_t outputMode,
  54. uint32_t requestedFrequencyHz,
  55. PLSR_PLATFORM_TIMER_SETTING *setting);
  56. uint8_t PlsrPlatformStartPrepared(
  57. uint8_t pulseOutput,
  58. const PLSR_PLATFORM_TIMER_SETTING *firstSetting,
  59. const PLSR_PLATFORM_TIMER_SETTING *queuedSetting,
  60. uint32_t *actualFirstFrequencyHz,
  61. uint32_t *actualQueuedFrequencyHz);
  62. uint8_t PlsrPlatformSupportsFinitePulseTrain(void);
  63. uint8_t PlsrPlatformStartFinitePrepared(
  64. uint8_t pulseOutput,
  65. const PLSR_PLATFORM_TIMER_SETTING *setting,
  66. uint32_t pulseCount,
  67. uint32_t *actualFrequencyHz);
  68. uint8_t PlsrPlatformStartCountedStreamPrepared(
  69. uint8_t pulseOutput,
  70. const PLSR_PLATFORM_TIMER_SETTING *setting,
  71. uint32_t pulseCount,
  72. uint32_t *actualFrequencyHz);
  73. uint8_t PlsrPlatformStartFiniteSequencePrepared(
  74. uint8_t pulseOutput,
  75. PLSR_PLATFORM_FINITE_STEP *steps,
  76. uint16_t stepCount,
  77. uint32_t *actualFrequencyHz);
  78. PLSR_PLATFORM_QUEUE_RESULT PlsrPlatformUpdateFinitePrepared(
  79. uint8_t pulseOutput,
  80. const PLSR_PLATFORM_TIMER_SETTING *setting,
  81. uint32_t *actualFrequencyHz);
  82. uint8_t PlsrPlatformRetargetFiniteStop(uint8_t pulseOutput,
  83. uint32_t drainPulses);
  84. uint8_t PlsrPlatformRequestFiniteCut(uint8_t pulseOutput);
  85. uint8_t PlsrPlatformFiniteRetargetReady(uint8_t pulseOutput,
  86. uint32_t *activeFrequencyHz);
  87. uint8_t PlsrPlatformFinitePipelineSnapshot(uint8_t pulseOutput,
  88. uint64_t *observedPulses,
  89. uint32_t *committedPulses,
  90. uint64_t *committedTimeUs,
  91. uint32_t *tailFrequencyHz,
  92. uint8_t *startsNextSegment);
  93. uint8_t PlsrPlatformFiniteProgress(uint8_t pulseOutput,
  94. uint32_t *completedPulses);
  95. uint8_t PlsrPlatformTakeFiniteCompletion(uint8_t pulseOutput,
  96. uint32_t *completedPulses);
  97. uint8_t PlsrPlatformTakeFiniteBoundary(uint8_t pulseOutput,
  98. uint8_t *segmentNumber,
  99. uint32_t *completedPulses,
  100. uint8_t *sequenceContinues,
  101. uint32_t *activeFrequencyHz);
  102. /* Counted-stream callbacks are owned by the executor in plsr.c. The
  103. platform invokes them only at a hardware counter run boundary. These
  104. callbacks must only latch events/snapshots; all bookkeeping runs in the
  105. 1 ms task. */
  106. uint8_t PlsrExecTakeCountedRunIrq(
  107. uint8_t pulseOutput,
  108. PLSR_PLATFORM_TIMER_SETTING *setting,
  109. uint32_t *pulseCount,
  110. uint8_t *startsNextSegment);
  111. void PlsrExecCountedSegmentBoundaryIrq(uint8_t pulseOutput,
  112. uint32_t completedPulses);
  113. void PlsrExecCountedStreamFaultIrq(uint8_t pulseOutput);
  114. /* EXTI callback: records an armed WAIT or active EXT input edge. */
  115. void PlsrWaitInputExtiIrq(uint8_t inputSelection);
  116. PLSR_PLATFORM_QUEUE_RESULT PlsrPlatformLoadPreparedFromIrq(
  117. uint8_t pulseOutput,
  118. const PLSR_PLATFORM_TIMER_SETTING *setting,
  119. uint32_t *actualFrequencyHz);
  120. void PlsrPlatformGateFromIrq(uint8_t pulseOutput);
  121. PLSR_PLATFORM_QUEUE_RESULT PlsrPlatformQueueFrequency(
  122. uint8_t pulseOutput,
  123. uint32_t frequencyHz,
  124. uint32_t *actualFrequencyHz);
  125. void PlsrPlatformDrainPendingPulse(uint8_t pulseOutput);
  126. uint32_t PlsrPlatformActiveFrequency(uint8_t pulseOutput);
  127. uint8_t PlsrPlatformExpectedFrequency(uint8_t pulseOutput,
  128. uint8_t outputMode,
  129. uint32_t requestedFrequencyHz,
  130. uint32_t *actualFrequencyHz);
  131. uint64_t PlsrPlatformObservedPulses(uint8_t pulseOutput);
  132. /* Returns 0, PLSR diagnostic reason 2 (frequency), or 3 (curve/order). */
  133. uint16_t PlsrPlatformDiagnosticFault(void);
  134. /* Caller must hold the platform critical section. */
  135. PLSR_PLATFORM_STOP_RESULT PlsrPlatformRequestStopLocked(
  136. uint8_t pulseOutput,
  137. uint8_t requireZeroBoundary);
  138. uint8_t PlsrPlatformQueueFinalArmFromIrq(uint8_t pulseOutput);
  139. void PlsrPlatformStopPulse(uint8_t pulseOutput);
  140. uint8_t PlsrPlatformReadInput(uint8_t inputSelection);
  141. /* Called from the counted-boundary IRQ before the EXT capture context moves
  142. to the next segment. Returns and clears a rising edge pending in EXTI. */
  143. uint8_t PlsrPlatformTakeInputExtiPending(uint8_t inputSelection);
  144. uint8_t PlsrPlatformLoad(PLSR_PERSIST_PAYLOAD *payload);
  145. PLSR_PLATFORM_SERVICE_RESULT PlsrPlatformServicePersistence(void);
  146. uint8_t PlsrPlatformSave(const PLSR_PERSIST_PAYLOAD *payload);
  147. void PlsrPlatformCheckpointConfig(const PLSR_CONFIG *config);
  148. void PlsrPlatformCheckpointPosition(int32_t position,
  149. uint8_t positionValid,
  150. uint8_t wasBusy);
  151. void PlsrPlatformForceSafeOutputsFromFault(void);
  152. uint32_t PlsrPlatformEnterCritical(void);
  153. void PlsrPlatformExitCritical(uint32_t state);
  154. #endif /* PLSR_PLATFORM_H */