pw_stream_uart_mcuxpresso: Implement DoRead DMA

This change implements the DoRead version for USART
DMA transfers.

The DoRead function copies data from the RX ring buffer
into the caller provided buffer.

The RX ring buffer gets filled through DMA RX requests
that are getting started when the
UsartStreamDmaMcuxpresso::Init function executes. Each
RX transaction is usually kUsartDmaTransferCount bytes
long, but may be truncated to deal with the wrap around
of the ring buffer, or when a caller's DoRead request
couldn't be completely satisifed by the ring buffer itself,
but further transactions have to complete.

If a caller waits for transactions to complete to satisfy
its request, it depends whether the current transaction will
satisfy the request, or whether at least one more transaction
in addition to the in-flight transaction have to complete.

If only the current transaction has to complete, we will abort
the current transaction, so that a transaction can be started
that waits to receive exactly as many bytes as are required
by the caller. Since the abort may take some time, it might
be that the entire transaction still completes. If that is the
case the DMA interrupt will be delivered and the callback will
be executed.

If the abort request completes before the transaction has
completed, the transfer's dataSize will be fixed up to
account for the data that hasn't been transferred yet and the
completion_size will be set, so that the completion callback can
be executed by the DoRead caller itself and wake up the DoRead
caller when the remaining data has been received.

If more than one transaction is required to satisfy the DoRead
request, we don't need to abort the current transaction, since
we know that we can safely set completion_size and that it will
be picked up by the RX completion callback.

Change-Id: Ib5764edfd630a8d6cd21e1d82108c135a7bd0df4
Bug: 325514698
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/192893
Commit-Queue: Christoph Klee <chklee@google.com>
Reviewed-by: Austin Foxley <afoxley@google.com>
2 files changed
tree: 72422f2e9b334c1ad826f20e36b7d64c2da7d9f1
  1. .allstar/
  2. .vscode/
  3. build_overrides/
  4. docker/
  5. docs/
  6. kudzu/
  7. pw_alignment/
  8. pw_allocator/
  9. pw_analog/
  10. pw_android_toolchain/
  11. pw_arduino_build/
  12. pw_assert/
  13. pw_assert_basic/
  14. pw_assert_log/
  15. pw_assert_tokenized/
  16. pw_assert_zephyr/
  17. pw_async/
  18. pw_async2/
  19. pw_async2_basic/
  20. pw_async_basic/
  21. pw_base64/
  22. pw_bloat/
  23. pw_blob_store/
  24. pw_bluetooth/
  25. pw_bluetooth_hci/
  26. pw_bluetooth_profiles/
  27. pw_bluetooth_sapphire/
  28. pw_boot/
  29. pw_boot_cortex_m/
  30. pw_build/
  31. pw_build_info/
  32. pw_build_mcuxpresso/
  33. pw_bytes/
  34. pw_channel/
  35. pw_checksum/
  36. pw_chre/
  37. pw_chrono/
  38. pw_chrono_embos/
  39. pw_chrono_freertos/
  40. pw_chrono_rp2040/
  41. pw_chrono_stl/
  42. pw_chrono_threadx/
  43. pw_chrono_zephyr/
  44. pw_cli/
  45. pw_compilation_testing/
  46. pw_config_loader/
  47. pw_console/
  48. pw_containers/
  49. pw_cpu_exception/
  50. pw_cpu_exception_cortex_m/
  51. pw_crypto/
  52. pw_digital_io/
  53. pw_digital_io_mcuxpresso/
  54. pw_digital_io_rp2040/
  55. pw_docgen/
  56. pw_doctor/
  57. pw_emu/
  58. pw_env_setup/
  59. pw_env_setup_zephyr/
  60. pw_file/
  61. pw_format/
  62. pw_function/
  63. pw_fuzzer/
  64. pw_grpc/
  65. pw_hdlc/
  66. pw_hex_dump/
  67. pw_i2c/
  68. pw_i2c_linux/
  69. pw_i2c_mcuxpresso/
  70. pw_ide/
  71. pw_interrupt/
  72. pw_interrupt_cortex_m/
  73. pw_interrupt_xtensa/
  74. pw_interrupt_zephyr/
  75. pw_intrusive_ptr/
  76. pw_json/
  77. pw_kvs/
  78. pw_libc/
  79. pw_libcxx/
  80. pw_log/
  81. pw_log_android/
  82. pw_log_basic/
  83. pw_log_null/
  84. pw_log_rpc/
  85. pw_log_string/
  86. pw_log_tokenized/
  87. pw_log_zephyr/
  88. pw_malloc/
  89. pw_malloc_freelist/
  90. pw_malloc_freertos/
  91. pw_metric/
  92. pw_minimal_cpp_stdlib/
  93. pw_module/
  94. pw_multibuf/
  95. pw_multisink/
  96. pw_package/
  97. pw_perf_test/
  98. pw_persistent_ram/
  99. pw_polyfill/
  100. pw_preprocessor/
  101. pw_presubmit/
  102. pw_protobuf/
  103. pw_protobuf_compiler/
  104. pw_random/
  105. pw_result/
  106. pw_ring_buffer/
  107. pw_router/
  108. pw_rpc/
  109. pw_rpc_transport/
  110. pw_rust/
  111. pw_snapshot/
  112. pw_software_update/
  113. pw_span/
  114. pw_spi/
  115. pw_spi_mcuxpresso/
  116. pw_spi_rp2040/
  117. pw_status/
  118. pw_stm32cube_build/
  119. pw_stream/
  120. pw_stream_shmem_mcuxpresso/
  121. pw_stream_uart_linux/
  122. pw_stream_uart_mcuxpresso/
  123. pw_string/
  124. pw_symbolizer/
  125. pw_sync/
  126. pw_sync_baremetal/
  127. pw_sync_embos/
  128. pw_sync_freertos/
  129. pw_sync_stl/
  130. pw_sync_threadx/
  131. pw_sync_zephyr/
  132. pw_sys_io/
  133. pw_sys_io_ambiq_sdk/
  134. pw_sys_io_arduino/
  135. pw_sys_io_baremetal_lm3s6965evb/
  136. pw_sys_io_baremetal_stm32f429/
  137. pw_sys_io_emcraft_sf2/
  138. pw_sys_io_mcuxpresso/
  139. pw_sys_io_rp2040/
  140. pw_sys_io_stdio/
  141. pw_sys_io_stm32cube/
  142. pw_sys_io_zephyr/
  143. pw_system/
  144. pw_target_runner/
  145. pw_thread/
  146. pw_thread_embos/
  147. pw_thread_freertos/
  148. pw_thread_stl/
  149. pw_thread_threadx/
  150. pw_thread_zephyr/
  151. pw_tls_client/
  152. pw_tls_client_boringssl/
  153. pw_tls_client_mbedtls/
  154. pw_tokenizer/
  155. pw_toolchain/
  156. pw_toolchain_bazel/
  157. pw_trace/
  158. pw_trace_tokenized/
  159. pw_transfer/
  160. pw_unit_test/
  161. pw_unit_test_zephyr/
  162. pw_varint/
  163. pw_watch/
  164. pw_web/
  165. pw_work_queue/
  166. seed/
  167. targets/
  168. third_party/
  169. ts/
  170. zephyr/
  171. .bazelignore
  172. .bazelrc
  173. .black.toml
  174. .clang-format
  175. .clang-tidy
  176. .eslintrc.cjs
  177. .git-blame-ignore-revs
  178. .gitattributes
  179. .gitignore
  180. .gn
  181. .mypy.ini
  182. .prettierignore
  183. .prettierrc.cjs
  184. .pw_ide.yaml
  185. .pylintrc
  186. activate.bat
  187. Android.bp
  188. AUTHORS
  189. bootstrap.bat
  190. bootstrap.sh
  191. BUILD.bazel
  192. BUILD.gn
  193. BUILDCONFIG.gn
  194. CMakeLists.txt
  195. jest.config.ts
  196. Kconfig.zephyr
  197. LICENSE
  198. modules.gni
  199. OWNERS
  200. package-lock.json
  201. package.json
  202. pigweed.json
  203. PIGWEED_MODULES
  204. README.md
  205. rollup.config.js
  206. tsconfig.json
  207. WORKSPACE
README.md

Pigweed

Pigweed is an open source collection of embedded-targeted libraries–or as we like to call them, modules. These modules are building blocks and infrastructure that enable faster and more reliable development on small-footprint MMU-less 32-bit microcontrollers like the STMicroelectronics STM32L452 or the Nordic nRF52832.

For more information please see our website: https://pigweed.dev/.

Links