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.
 
 
 
 
 
 

103 rivejä
3.3 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 发 1 段 2000Hz / 1000 脉冲,H00 完成,梯形曲线
  9. * 数据源为静态数组,仅自测使用(正式 D 设备适配器见 Modbus 阶段)。 */
  10. #define SELF_TEST_WORD_CAPACITY (64U)
  11. #define SELF_TEST_S0_BASE (10U)
  12. #define SELF_TEST_S1_BASE (30U)
  13. #define SELF_TEST_DIR_POINT (4U)
  14. static uint16_t SelfTestWords[3][SELF_TEST_WORD_CAPACITY];
  15. static uint8_t SelfTestValidateWords(void *context,
  16. PLSR_DEVICE_TYPE device,
  17. uint32_t firstAddress,
  18. uint32_t wordCount)
  19. {
  20. (void)context;
  21. if ((device > PLSR_DEVICE_FD) || (wordCount == 0UL))
  22. {
  23. return 0U;
  24. }
  25. return (((uint64_t)firstAddress + wordCount)
  26. <= SELF_TEST_WORD_CAPACITY)
  27. ? 1U
  28. : 0U;
  29. }
  30. static uint8_t SelfTestReadWord(void *context,
  31. PLSR_DEVICE_TYPE device,
  32. uint32_t address,
  33. uint16_t *value)
  34. {
  35. (void)context;
  36. if ((device > PLSR_DEVICE_FD) || (value == NULL)
  37. || (address >= SELF_TEST_WORD_CAPACITY))
  38. {
  39. return 0U;
  40. }
  41. *value = SelfTestWords[device][address];
  42. return 1U;
  43. }
  44. static uint8_t SelfTestReadBit(void *context,
  45. PLSR_DEVICE_TYPE device,
  46. uint32_t address,
  47. uint8_t *value)
  48. {
  49. (void)context;
  50. (void)device;
  51. (void)address;
  52. *value = 0U;
  53. return 1U;
  54. }
  55. static void SelfTestWriteDword(PLSR_DEVICE_TYPE device,
  56. uint32_t address,
  57. uint32_t value)
  58. {
  59. SelfTestWords[device][address] = (uint16_t)(value & 0xFFFFUL);
  60. SelfTestWords[device][address + 1UL] = (uint16_t)(value >> 16U);
  61. }
  62. PLSR_RESULT PlsrSelfTestQueue(void)
  63. {
  64. PLSR_CALL call;
  65. (void)memset(SelfTestWords, 0, sizeof(SelfTestWords));
  66. /* 方向端子 Y4(PULSE/DIR 模式必需,接线参数)。 */
  67. (void)PlcDeviceWriteSfd(906U, SELF_TEST_DIR_POINT);
  68. /* S0:1 段,2000Hz / 1000 脉冲,H00 完成,顺序跳转。 */
  69. SelfTestWriteDword(PLSR_DEVICE_D, SELF_TEST_S0_BASE, 1U);
  70. SelfTestWriteDword(PLSR_DEVICE_D, SELF_TEST_S0_BASE + 10U, 2000UL);
  71. SelfTestWriteDword(PLSR_DEVICE_D, SELF_TEST_S0_BASE + 12U, 1000UL);
  72. /* S1:相对模式,起始段 0(=段1)。 */
  73. SelfTestWriteDword(PLSR_DEVICE_D, SELF_TEST_S1_BASE, 0U);
  74. (void)memset(&call, 0, sizeof(call));
  75. call.sequence = 0xA5A5UL;
  76. call.source.context = NULL;
  77. call.source.validateWords = SelfTestValidateWords;
  78. call.source.readWord = SelfTestReadWord;
  79. call.source.readBit = SelfTestReadBit;
  80. call.s0.device = PLSR_DEVICE_D;
  81. call.s0.address = SELF_TEST_S0_BASE;
  82. call.s1.device = PLSR_DEVICE_D;
  83. call.s1.address = SELF_TEST_S1_BASE;
  84. call.s2.type = PLSR_OPERAND_CONSTANT;
  85. call.s2.constant = 1;
  86. call.dAxis = 0U;
  87. call.outputModeOverride = PLSR_OUTPUT_MODE_FROM_SFD;
  88. return PlsrPostCall(&call);
  89. }