No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

105 líneas
4.0 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. PLSR_RESULT PlsrHwStopPulse(uint8_t axis);
  34. /* Batch related multi-axis DIR changes into one short GPIO commit window. */
  35. void PlsrHwBeginDirectionBatch(void);
  36. void PlsrHwEndDirectionBatch(void);
  37. uint8_t PlsrHwIsPulseActive(uint8_t axis);
  38. PLSR_HW_STATE PlsrHwGetState(uint8_t axis);
  39. uint32_t PlsrHwGetTimerClockHz(uint8_t axis);
  40. uint32_t PlsrHwGetCurrentFrequencyHz(uint8_t axis);
  41. int64_t PlsrHwGetEmittedPulses(uint8_t axis);
  42. uint8_t PlsrHwIsAbStartupPriming(uint8_t axis);
  43. uint8_t PlsrHwUsesHardwareCounter(uint8_t axis);
  44. uint32_t PlsrHwGetMaxOutputIsrCycles(void);
  45. uint32_t PlsrHwGetMaxCounterIsrCycles(void);
  46. uint32_t PlsrHwGetMaxControlIsrCycles(void);
  47. /* Fast gate from the final AB 00 boundary; budget is one 100kHz quarter
  48. * period (420 cycles at 168MHz). */
  49. uint32_t PlsrHwGetMaxAbGateCycles(void);
  50. /* Atomically sample the free-running CPU counter and the accumulated time
  51. * spent inside PLSR timer ISRs. PlsrProcess uses the pair to distinguish its
  52. * own CPU cost from wall-clock response time under high-rate preemption. */
  53. void PlsrHwGetCycleSnapshot(uint32_t *cycleCount,
  54. uint64_t *plsrIsrCycles);
  55. /* 每 1ms tick 推进 HAL 状态机(DIR 延时等)。 */
  56. void PlsrHwTick(uint8_t axis);
  57. /* 输出定时器更新中断入口(生产由 IRQHandler 调用,host 由测试调用)。 */
  58. void PlsrHwOnTimerUpdate(uint8_t axis);
  59. /* 输出点(Y0~Y20)引脚映射表:DIR 点解析用。 */
  60. uint8_t PlsrHwResolveDirectionPoint(uint8_t pointNumber);
  61. #ifdef PLSR_HOST_TEST
  62. /* 模拟寄存器访问与中断触发(测试用)。 */
  63. uint32_t PlsrHwTestGetArr(uint8_t axis);
  64. uint32_t PlsrHwTestGetCcr(uint8_t axis);
  65. uint32_t PlsrHwTestGetCnt(uint8_t axis);
  66. uint32_t PlsrHwTestGetCcmr1(uint8_t axis);
  67. uint32_t PlsrHwTestGetCr1(uint8_t axis);
  68. uint32_t PlsrHwTestGetPsc(uint8_t axis);
  69. uint8_t PlsrHwTestGetPwmEnabled(uint8_t axis);
  70. uint8_t PlsrHwTestGetCc1PolarityInverted(uint8_t axis);
  71. uint8_t PlsrHwTestGetDirLevel(uint8_t axis);
  72. uint8_t PlsrHwTestGetAbPhaseA(uint8_t axis);
  73. uint8_t PlsrHwTestGetAbPhaseB(uint8_t axis);
  74. uint8_t PlsrHwTestGetAbQuarter(uint8_t axis);
  75. /* Model the short source-CNT/ITR synchronization window without advancing
  76. * the slave raw counter. */
  77. void PlsrHwTestSetAbQuarterWithoutCounter(uint8_t axis, uint8_t quarter);
  78. void PlsrHwTestTriggerUpdate(uint8_t axis);
  79. void PlsrHwTestTriggerUpdateAndCompare(uint8_t axis);
  80. void PlsrHwTestTriggerCompare(uint8_t axis);
  81. void PlsrHwTestAdvanceAbQuarter(uint8_t axis);
  82. uint32_t PlsrHwTestGetAbFullGateCount(void);
  83. void PlsrHwTestSignalDualAbFinalBoundary(uint8_t firstAxis);
  84. void PlsrHwTestSignalDualAbStaggeredFinalBoundary(uint8_t firstAxis);
  85. #endif
  86. #ifdef __cplusplus
  87. }
  88. #endif
  89. #endif /* PLSR_HAL_F407_H */