Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

112 wiersze
3.7 KiB

  1. #include "plsr_self_test.h"
  2. #include "plc_device.h"
  3. #include "plsr_core.h"
  4. #include "plsr_job.h"
  5. #include <string.h>
  6. /* 上电自测(验证后可删除):
  7. * - AB 模式使用 Q0(A)/Q1(B),其余用出厂默认参数(K1)
  8. * - 任务:3 段完整 AB 周期(H00 完成,顺序衔接):
  9. * 段1:2000Hz / +1000 周期(A 超前 B)
  10. * 段2:5000Hz / +6000 周期(A 超前 B)
  11. * 段3:1000Hz / -500 周期(B 超前 A,验证反向)
  12. * 数据源为静态数组,仅自测使用(正式 D 设备适配器见 Modbus 阶段)。 */
  13. #define SELF_TEST_WORD_CAPACITY (64U)
  14. #define SELF_TEST_S0_BASE (10U)
  15. #define SELF_TEST_S1_BASE (60U)
  16. #define SELF_TEST_DIR_POINT (4U)
  17. static uint16_t SelfTestWords[3][SELF_TEST_WORD_CAPACITY];
  18. static uint8_t SelfTestValidateWords(void *context,
  19. PLSR_DEVICE_TYPE device,
  20. uint32_t firstAddress,
  21. uint32_t wordCount)
  22. {
  23. (void)context;
  24. if ((device > PLSR_DEVICE_FD) || (wordCount == 0UL))
  25. {
  26. return 0U;
  27. }
  28. return (((uint64_t)firstAddress + wordCount)
  29. <= SELF_TEST_WORD_CAPACITY)
  30. ? 1U
  31. : 0U;
  32. }
  33. static uint8_t SelfTestReadWord(void *context,
  34. PLSR_DEVICE_TYPE device,
  35. uint32_t address,
  36. uint16_t *value)
  37. {
  38. (void)context;
  39. if ((device > PLSR_DEVICE_FD) || (value == NULL)
  40. || (address >= SELF_TEST_WORD_CAPACITY))
  41. {
  42. return 0U;
  43. }
  44. *value = SelfTestWords[device][address];
  45. return 1U;
  46. }
  47. static uint8_t SelfTestReadBit(void *context,
  48. PLSR_DEVICE_TYPE device,
  49. uint32_t address,
  50. uint8_t *value)
  51. {
  52. (void)context;
  53. (void)device;
  54. (void)address;
  55. *value = 0U;
  56. return 1U;
  57. }
  58. static void SelfTestWriteDword(PLSR_DEVICE_TYPE device,
  59. uint32_t address,
  60. uint32_t value)
  61. {
  62. SelfTestWords[device][address] = (uint16_t)(value & 0xFFFFUL);
  63. SelfTestWords[device][address + 1UL] = (uint16_t)(value >> 16U);
  64. }
  65. PLSR_RESULT PlsrSelfTestQueue(void)
  66. {
  67. PLSR_CALL call;
  68. (void)memset(SelfTestWords, 0, sizeof(SelfTestWords));
  69. /* 方向端子 Y4(PULSE/DIR 模式必需,接线参数)。 */
  70. (void)PlcDeviceWriteSfd(906U, SELF_TEST_DIR_POINT);
  71. /* S0:3 段,H00 完成,顺序跳转。 */
  72. SelfTestWriteDword(PLSR_DEVICE_D, SELF_TEST_S0_BASE, 3U);
  73. SelfTestWriteDword(PLSR_DEVICE_D, SELF_TEST_S0_BASE + 10U, 2000UL);
  74. SelfTestWriteDword(PLSR_DEVICE_D, SELF_TEST_S0_BASE + 12U, 1000UL);
  75. SelfTestWriteDword(PLSR_DEVICE_D, SELF_TEST_S0_BASE + 20U, 5000UL);
  76. SelfTestWriteDword(PLSR_DEVICE_D, SELF_TEST_S0_BASE + 22U, 6000UL);
  77. SelfTestWriteDword(PLSR_DEVICE_D, SELF_TEST_S0_BASE + 30U, 1000UL);
  78. SelfTestWriteDword(PLSR_DEVICE_D,
  79. SELF_TEST_S0_BASE + 32U,
  80. (uint32_t)(int32_t)-500);
  81. /* S1:相对模式,起始段 0(=段1)。 */
  82. SelfTestWriteDword(PLSR_DEVICE_D, SELF_TEST_S1_BASE, 0U);
  83. (void)memset(&call, 0, sizeof(call));
  84. call.sequence = 0xA5A5UL;
  85. call.source.context = NULL;
  86. call.source.validateWords = SelfTestValidateWords;
  87. call.source.readWord = SelfTestReadWord;
  88. call.source.readBit = SelfTestReadBit;
  89. call.s0.device = PLSR_DEVICE_D;
  90. call.s0.address = SELF_TEST_S0_BASE;
  91. call.s1.device = PLSR_DEVICE_D;
  92. call.s1.address = SELF_TEST_S1_BASE;
  93. call.s2.type = PLSR_OPERAND_CONSTANT;
  94. call.s2.constant = 1;
  95. call.dAxis = 0U;
  96. call.outputModeOverride = PLSR_OUTPUT_AB;
  97. return PlsrPostCall(&call);
  98. }