You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

114 lines
4.5 KiB

  1. #ifndef PLSR_HAL_F407_H
  2. #define PLSR_HAL_F407_H
  3. #include "plsr_types.h"
  4. #include <stdint.h>
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. #define PLSR_HW_AXIS_COUNT (PLSR_AXIS_COUNT)
  9. #define PLSR_HW_DIR_POINT_NONE (0xFFU)
  10. typedef enum
  11. {
  12. PLSR_HW_STATE_IDLE = 0,
  13. PLSR_HW_STATE_DIR_SETTLING, /* DIR 已置位,等待方向建立延时 */
  14. PLSR_HW_STATE_PWM_PENDING, /* 延时已到,等待首个非零频率启动 PWM */
  15. PLSR_HW_STATE_RUNNING, /* PWM 输出中,更新中断计数 */
  16. PLSR_HW_STATE_DONE
  17. } PLSR_HW_STATE;
  18. typedef struct
  19. {
  20. uint32_t frequencyHz; /* 初始频率(起始速度,可为 0) */
  21. int64_t targetPulses; /* 本段目标脉冲数 */
  22. PLSR_OUTPUT_MODE outputMode; /* PULSE/DIR、AB 或 CW/CCW */
  23. uint8_t directionPoint; /* DIR 输出点(Y 点号,0xFF=无) */
  24. uint8_t directionPositive;
  25. uint8_t directionNegativeLogic; /* SFD900 Bit1: 1 reverses DIR ON/OFF */
  26. uint16_t directionDelayMs;
  27. } PLSR_HW_START_PARAMS;
  28. PLSR_RESULT PlsrHwInit(void);
  29. PLSR_RESULT PlsrHwStartPulse(uint8_t axis, const PLSR_HW_START_PARAMS *params);
  30. PLSR_RESULT PlsrHwSetFrequency(uint8_t axis, uint32_t frequencyHz);
  31. /* Re-arm a PAUSE-stopped timer without clearing its emitted/target counters. */
  32. PLSR_RESULT PlsrHwResumePulse(uint8_t axis);
  33. /* Complete the in-flight PULSE/DIR period, then stop and post
  34. * PLSR_EVENT_SEGMENT_COMPLETE. Used by asynchronous ACT/EXT path exits. */
  35. PLSR_RESULT PlsrHwStopPulseAtBoundary(uint8_t axis);
  36. PLSR_RESULT PlsrHwStopPulse(uint8_t axis);
  37. /* Batch related multi-axis DIR changes into one short GPIO commit window. */
  38. void PlsrHwBeginDirectionBatch(void);
  39. void PlsrHwEndDirectionBatch(void);
  40. uint8_t PlsrHwIsPulseActive(uint8_t axis);
  41. PLSR_HW_STATE PlsrHwGetState(uint8_t axis);
  42. uint32_t PlsrHwGetTimerClockHz(uint8_t axis);
  43. uint32_t PlsrHwGetCurrentFrequencyHz(uint8_t axis);
  44. int64_t PlsrHwGetEmittedPulses(uint8_t axis);
  45. uint8_t PlsrHwIsAbStartupPriming(uint8_t axis);
  46. uint8_t PlsrHwUsesHardwareCounter(uint8_t axis);
  47. uint32_t PlsrHwGetMaxOutputIsrCycles(void);
  48. uint32_t PlsrHwGetMaxCounterIsrCycles(void);
  49. uint32_t PlsrHwGetMaxControlIsrCycles(void);
  50. /* Fast gate from the final AB 00 boundary; budget is one 100kHz quarter
  51. * period (420 cycles at 168MHz). */
  52. uint32_t PlsrHwGetMaxAbGateCycles(void);
  53. /* Atomically sample the free-running CPU counter and the accumulated time
  54. * spent inside PLSR timer ISRs. PlsrProcess uses the pair to distinguish its
  55. * own CPU cost from wall-clock response time under high-rate preemption. */
  56. void PlsrHwGetCycleSnapshot(uint32_t *cycleCount,
  57. uint64_t *plsrIsrCycles);
  58. /* 每 1ms tick 推进 HAL 状态机(DIR 延时等)。 */
  59. void PlsrHwTick(uint8_t axis);
  60. /* 输出定时器更新中断入口(生产由 IRQHandler 调用,host 由测试调用)。 */
  61. void PlsrHwOnTimerUpdate(uint8_t axis);
  62. /* 输出点(Y0~Y20)引脚映射表:DIR 点解析用。 */
  63. uint8_t PlsrHwResolveDirectionPoint(uint8_t pointNumber);
  64. /* Validation-only slow digital output control. It is deliberately restricted
  65. * to Y1..Y4 and is used by the P19 physical-input loopback fixture. */
  66. PLSR_RESULT PlsrHwSetValidationOutput(uint8_t pointNumber, uint8_t terminalOn);
  67. void PlsrHwValidationOutputsOff(void);
  68. #ifdef PLSR_HOST_TEST
  69. /* 模拟寄存器访问与中断触发(测试用)。 */
  70. uint32_t PlsrHwTestGetArr(uint8_t axis);
  71. uint32_t PlsrHwTestGetCcr(uint8_t axis);
  72. uint32_t PlsrHwTestGetCnt(uint8_t axis);
  73. uint32_t PlsrHwTestGetCcmr1(uint8_t axis);
  74. uint32_t PlsrHwTestGetCr1(uint8_t axis);
  75. uint32_t PlsrHwTestGetPsc(uint8_t axis);
  76. uint8_t PlsrHwTestGetPwmEnabled(uint8_t axis);
  77. uint8_t PlsrHwTestGetCc1PolarityInverted(uint8_t axis);
  78. uint8_t PlsrHwTestGetDirLevel(uint8_t axis);
  79. uint8_t PlsrHwTestGetAbPhaseA(uint8_t axis);
  80. uint8_t PlsrHwTestGetAbPhaseB(uint8_t axis);
  81. uint8_t PlsrHwTestGetAbQuarter(uint8_t axis);
  82. /* Model the short source-CNT/ITR synchronization window without advancing
  83. * the slave raw counter. */
  84. void PlsrHwTestSetAbQuarterWithoutCounter(uint8_t axis, uint8_t quarter);
  85. void PlsrHwTestTriggerUpdate(uint8_t axis);
  86. void PlsrHwTestSetUpdatePending(uint8_t axis);
  87. void PlsrHwTestTriggerUpdateAndCompare(uint8_t axis);
  88. void PlsrHwTestTriggerCompare(uint8_t axis);
  89. void PlsrHwTestAdvanceAbQuarter(uint8_t axis);
  90. uint32_t PlsrHwTestGetAbFullGateCount(void);
  91. void PlsrHwTestSignalDualAbFinalBoundary(uint8_t firstAxis);
  92. void PlsrHwTestSignalDualAbStaggeredFinalBoundary(uint8_t firstAxis);
  93. #endif
  94. #ifdef __cplusplus
  95. }
  96. #endif
  97. #endif /* PLSR_HAL_F407_H */