Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

110 lignes
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. * - 方向端子设为 Y4(SFD906=4),其余用出厂默认参数(K1)
  8. * - 任务:Q0 发 3 段脉冲(H00 完成,顺序衔接),同时验证段间跳转:
  9. * 段1:2000Hz / 1000 脉冲(已单段验证)
  10. * 段2:5000Hz / 6000 脉冲(加速 500ms + 匀速 200ms + 减速 500ms)
  11. * 段3:1000Hz / 500 脉冲
  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, SELF_TEST_S0_BASE + 32U, 500UL);
  79. /* S1:相对模式,起始段 0(=段1)。 */
  80. SelfTestWriteDword(PLSR_DEVICE_D, SELF_TEST_S1_BASE, 0U);
  81. (void)memset(&call, 0, sizeof(call));
  82. call.sequence = 0xA5A5UL;
  83. call.source.context = NULL;
  84. call.source.validateWords = SelfTestValidateWords;
  85. call.source.readWord = SelfTestReadWord;
  86. call.source.readBit = SelfTestReadBit;
  87. call.s0.device = PLSR_DEVICE_D;
  88. call.s0.address = SELF_TEST_S0_BASE;
  89. call.s1.device = PLSR_DEVICE_D;
  90. call.s1.address = SELF_TEST_S1_BASE;
  91. call.s2.type = PLSR_OPERAND_CONSTANT;
  92. call.s2.constant = 1;
  93. call.dAxis = 0U;
  94. call.outputModeOverride = PLSR_OUTPUT_MODE_FROM_SFD;
  95. return PlsrPostCall(&call);
  96. }