shellmatta_ymodem.dox 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /**
  2. @page shellmatta_ymodem Shellmatta ymodem
  3. To be able to pass binary files to the shellmatta there is a ymodem module
  4. implemented.
  5. The ymodem reception can be started from a shellmatta command and handles
  6. the handshaking as well as the data transmission.
  7. As the shellmatta does not use dynamic memory every packet is passed
  8. directly to the application using a callback.
  9. Only the currently received packet is stored in the shellmatta internally.
  10. In order to transmit the start characters to the sender you need to poll the
  11. shellmatta_processData() function cyclically even if no new data has been
  12. received.
  13. Do this in 0.1s - 1s periods (depending on the latency you are after).
  14. When the transmission is complete the shellmatta requires to be polled
  15. #YMODEM_POLL_NUMBER times. This ensures a short wait time to flush all
  16. unwanted bytes from the transmitter.
  17. The shellmatta_ymodem_init() function will return and the command it was
  18. called from will not be executed again. The rest of the ymodem processing
  19. will be handled by the shellmatta. The data will be passed using the
  20. callbacks registered during the start.
  21. To cancel the ymodem (e.g. timeout) just call shellmatta_ymodem_cancel()
  22. @section shellmatta_ymodem_sequence Basic sequence
  23. @startuml
  24. Application -> Shellmatta: shellmatta_ymodem_init()
  25. Shellmatta -> Host: send C to start transmission
  26. Shellmatta -> Application: return
  27. loop until ymodem transmission starts (or is canceled)
  28. Application -> Shellmatta: shellmatta_processData(null)
  29. Shellmatta -> Host: send C to start transmission
  30. end
  31. Application -> Shellmatta: shellmatta_processData(first packet)
  32. Shellmatta -> Application: packetHeader(fileSize, FileName) callback
  33. loop until shellmatta transmission is complete
  34. Host -> Shellmatta: Data transmission
  35. Shellmatta -> Application: packetRcv() callback
  36. end
  37. Shellmatta -> Application: transmissionComplete() callback
  38. @enduml
  39. While the ymodem is active no command can be executed.
  40. When the ymodem is canceled from the Host the data received afterwards will
  41. be processed as usual.
  42. @warning Ymodem cannot cooperate with optional transport layer.
  43. When the transport layer is enabled but not mandatory it is
  44. forced to stay in the mode it was when the ymodem transfer
  45. starts.
  46. When the transport layer was active it has to keep active.
  47. If it is inactive it cannot be activated during the ymodem
  48. transfer.
  49. @section shellmatta_ymodem_internal_buffer Internal buffer
  50. To save some memory you can use the shellmatta ymodem module using the
  51. internal buffer which usually is used to cache normal input before
  52. processing it.
  53. Just set the recvBuffer to NULL in #shellmatta_ymodem_init calls.
  54. @warning Ensure that your shellmattas buffer is at least
  55. #YMODEM_PACKET_SIZE_1K large to fit the ymodem packet.
  56. This is checked during initialization.
  57. @section shellmatta_ymodem_paused_mode Paused mode
  58. When the application requires time to process the currently received packet
  59. the application can call #shellmatta_ymodem_pause from the callbacks.
  60. This will prevent the shellmatta from sending the ACK to the sender.
  61. When the processing is done just call #shellmatta_ymodem_resume.
  62. @section shellmatta_ymodem_crc CRC calculation
  63. The shellmatta ymodem uses the CRC16 algorithm to secure the
  64. transmission (0x1021).
  65. By default the shellmatta crc implementation uses a lookup table to
  66. calculate the crc in a performant way.
  67. This uses quite a lot of read only memory on the device. If the memory
  68. consumption is an Issue you can switch to a slower implementation without
  69. the lookup table. This will increase CPU load quite a bit, but saves nearly
  70. 0.5K of read only memory.
  71. To enable the lookup table less CRC just define
  72. ``SHELLMATTA_YMODEM_CRC_NO_LOOKUP`` during compilation.
  73. */