no_block_test.lua 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. local function spiTest(id)
  2. local txlen = 20480
  3. local txbuff = zbuff.create(txlen)
  4. local rxbuff = zbuff.create(txlen)
  5. local cbTopic = "SPI" .. id .. "DONE"
  6. local result, succ, errorCode
  7. if id ~= spi.HSPI_0 then
  8. spi.setup(id, nil, 0, 0, 8, 24000000)
  9. else
  10. spi.setup(id, nil, 0, 0, 8, 48000000)
  11. log.info("hspi")
  12. end
  13. while true do
  14. log.info("spi"..id, "传输开始")
  15. result = spi.xfer(id,txbuff,rxbuff,txlen,cbTopic)
  16. if result then
  17. result, succ, errorCode = sys.waitUntil(cbTopic, 1000)
  18. end
  19. if not result or not succ then
  20. log.info("spi"..id, "传输失败")
  21. else
  22. result,errorCode = txbuff:isEqual(nil, rxbuff, nil, txlen)
  23. if not result then
  24. log.info("spi"..id, "传输发生错误", errorCode, txbuff[errorCode], rxbuff[errorCode])
  25. else
  26. log.info("spi"..id, "传输成功")
  27. end
  28. end
  29. sys.wait(1000)
  30. end
  31. end
  32. sys.taskInit(spiTest, spi.SPI_1)
  33. sys.taskInit(spiTest, spi.SPI_2)
  34. sys.taskInit(spiTest, spi.HSPI_0)