bouncebuffer.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. bouncebuffer code for supporting ChibiOS drivers that use DMA, but may be passed memory that
  3. is not DMA safe.
  4. This API assumes that there will be only one user of a bouncebuffer at a time
  5. */
  6. #pragma once
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. struct bouncebuffer_t {
  11. uint8_t *dma_buf;
  12. uint8_t *orig_buf;
  13. uint32_t size;
  14. bool busy;
  15. bool is_sdcard;
  16. };
  17. /*
  18. initialise a bouncebuffer
  19. */
  20. void bouncebuffer_init(struct bouncebuffer_t **bouncebuffer, uint32_t prealloc_bytes, bool sdcard);
  21. /*
  22. setup for reading from a device into memory, allocating a bouncebuffer if needed
  23. */
  24. void bouncebuffer_setup_read(struct bouncebuffer_t *bouncebuffer, uint8_t **buf, uint32_t size);
  25. /*
  26. finish a read operation
  27. */
  28. void bouncebuffer_finish_read(struct bouncebuffer_t *bouncebuffer, const uint8_t *buf, uint32_t size);
  29. /*
  30. setup for reading from memory to a device, allocating a bouncebuffer if needed
  31. */
  32. void bouncebuffer_setup_write(struct bouncebuffer_t *bouncebuffer, const uint8_t **buf, uint32_t size);
  33. /*
  34. finish a write operation
  35. */
  36. void bouncebuffer_finish_write(struct bouncebuffer_t *bouncebuffer, const uint8_t *buf);
  37. #ifdef __cplusplus
  38. }
  39. #endif