|
|
|
@ -45,8 +45,9 @@ void bouncebuffer_init(struct bouncebuffer_t **bouncebuffer, uint32_t prealloc_b
@@ -45,8 +45,9 @@ void bouncebuffer_init(struct bouncebuffer_t **bouncebuffer, uint32_t prealloc_b
|
|
|
|
|
(*bouncebuffer)->is_sdcard = sdcard; |
|
|
|
|
if (prealloc_bytes) { |
|
|
|
|
(*bouncebuffer)->dma_buf = sdcard?malloc_sdcard_dma(prealloc_bytes):malloc_dma(prealloc_bytes); |
|
|
|
|
osalDbgAssert(((*bouncebuffer)->dma_buf != NULL), "bouncebuffer preallocate"); |
|
|
|
|
(*bouncebuffer)->size = prealloc_bytes; |
|
|
|
|
if ((*bouncebuffer)->dma_buf) { |
|
|
|
|
(*bouncebuffer)->size = prealloc_bytes; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -55,11 +56,11 @@ void bouncebuffer_init(struct bouncebuffer_t **bouncebuffer, uint32_t prealloc_b
@@ -55,11 +56,11 @@ void bouncebuffer_init(struct bouncebuffer_t **bouncebuffer, uint32_t prealloc_b
|
|
|
|
|
Note that *buf can be NULL, in which case we allocate DMA capable memory, but don't |
|
|
|
|
copy to it in bouncebuffer_finish_read(). This avoids DMA failures in dummyrx in the SPI LLD |
|
|
|
|
*/ |
|
|
|
|
void bouncebuffer_setup_read(struct bouncebuffer_t *bouncebuffer, uint8_t **buf, uint32_t size) |
|
|
|
|
bool bouncebuffer_setup_read(struct bouncebuffer_t *bouncebuffer, uint8_t **buf, uint32_t size) |
|
|
|
|
{ |
|
|
|
|
if (!bouncebuffer || IS_DMA_SAFE(*buf)) { |
|
|
|
|
// nothing needs to be done
|
|
|
|
|
return; |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
osalDbgAssert((bouncebuffer->busy == false), "bouncebuffer read");
|
|
|
|
|
bouncebuffer->orig_buf = *buf; |
|
|
|
@ -68,7 +69,10 @@ void bouncebuffer_setup_read(struct bouncebuffer_t *bouncebuffer, uint8_t **buf,
@@ -68,7 +69,10 @@ void bouncebuffer_setup_read(struct bouncebuffer_t *bouncebuffer, uint8_t **buf,
|
|
|
|
|
free(bouncebuffer->dma_buf); |
|
|
|
|
} |
|
|
|
|
bouncebuffer->dma_buf = bouncebuffer->is_sdcard?malloc_sdcard_dma(size):malloc_dma(size); |
|
|
|
|
osalDbgAssert((bouncebuffer->dma_buf != NULL), "bouncebuffer read allocate"); |
|
|
|
|
if (!bouncebuffer->dma_buf) { |
|
|
|
|
bouncebuffer->size = 0; |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
bouncebuffer->size = size; |
|
|
|
|
} |
|
|
|
|
*buf = bouncebuffer->dma_buf; |
|
|
|
@ -77,6 +81,7 @@ void bouncebuffer_setup_read(struct bouncebuffer_t *bouncebuffer, uint8_t **buf,
@@ -77,6 +81,7 @@ void bouncebuffer_setup_read(struct bouncebuffer_t *bouncebuffer, uint8_t **buf,
|
|
|
|
|
stm32_cacheBufferInvalidate(*buf, (size+31)&~31); |
|
|
|
|
#endif |
|
|
|
|
bouncebuffer->busy = true; |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
@ -97,11 +102,11 @@ void bouncebuffer_finish_read(struct bouncebuffer_t *bouncebuffer, const uint8_t
@@ -97,11 +102,11 @@ void bouncebuffer_finish_read(struct bouncebuffer_t *bouncebuffer, const uint8_t
|
|
|
|
|
/*
|
|
|
|
|
setup for reading from memory to a device, allocating a bouncebuffer if needed |
|
|
|
|
*/ |
|
|
|
|
void bouncebuffer_setup_write(struct bouncebuffer_t *bouncebuffer, const uint8_t **buf, uint32_t size) |
|
|
|
|
bool bouncebuffer_setup_write(struct bouncebuffer_t *bouncebuffer, const uint8_t **buf, uint32_t size) |
|
|
|
|
{ |
|
|
|
|
if (!bouncebuffer || IS_DMA_SAFE(*buf)) { |
|
|
|
|
// nothing needs to be done
|
|
|
|
|
return; |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
osalDbgAssert((bouncebuffer->busy == false), "bouncebuffer write");
|
|
|
|
|
if (bouncebuffer->size < size) { |
|
|
|
@ -109,7 +114,10 @@ void bouncebuffer_setup_write(struct bouncebuffer_t *bouncebuffer, const uint8_t
@@ -109,7 +114,10 @@ void bouncebuffer_setup_write(struct bouncebuffer_t *bouncebuffer, const uint8_t
|
|
|
|
|
free(bouncebuffer->dma_buf); |
|
|
|
|
} |
|
|
|
|
bouncebuffer->dma_buf = bouncebuffer->is_sdcard?malloc_sdcard_dma(size):malloc_dma(size); |
|
|
|
|
osalDbgAssert((bouncebuffer->dma_buf != NULL), "bouncebuffer write allocate"); |
|
|
|
|
if (!bouncebuffer->dma_buf) { |
|
|
|
|
bouncebuffer->size = 0; |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
bouncebuffer->size = size; |
|
|
|
|
} |
|
|
|
|
if (*buf) { |
|
|
|
@ -121,6 +129,7 @@ void bouncebuffer_setup_write(struct bouncebuffer_t *bouncebuffer, const uint8_t
@@ -121,6 +129,7 @@ void bouncebuffer_setup_write(struct bouncebuffer_t *bouncebuffer, const uint8_t
|
|
|
|
|
stm32_cacheBufferFlush(*buf, (size+31)&~31); |
|
|
|
|
#endif |
|
|
|
|
bouncebuffer->busy = true; |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -134,3 +143,13 @@ void bouncebuffer_finish_write(struct bouncebuffer_t *bouncebuffer, const uint8_
@@ -134,3 +143,13 @@ void bouncebuffer_finish_write(struct bouncebuffer_t *bouncebuffer, const uint8_
|
|
|
|
|
bouncebuffer->busy = false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
abort an operation |
|
|
|
|
*/ |
|
|
|
|
void bouncebuffer_abort(struct bouncebuffer_t *bouncebuffer) |
|
|
|
|
{ |
|
|
|
|
if (bouncebuffer) { |
|
|
|
|
bouncebuffer->busy = false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|