ESP-IDF: use static queue for blockbuf#245
Conversation
Signed-off-by: Mike Szczys <michael.szczys@canonical.com>
Expose the pouch_timeout_to_freertos_ticks() function to the port layer so it may be used whenever we need to convert pouch_timeout_t to FreeRTOS ticks. To avoid circular include issues, this functions uses the underlying int32_t instead of pouch_timeout_t. Signed-off-by: Mike Szczys <michael.szczys@canonical.com>
Use statically allocated memory handled by FreeRTOS's queue system to allocate and free blockbuf memory. This maps closely to the memory slabs used by the Zephyr implementation. Signed-off-by: Mike Szczys <michael.szczys@canonical.com>
| * Time | ||
| *------------------------------------------------*/ | ||
|
|
||
| int32_t pouch_timeout_to_freertos_ticks(int32_t pouch_timeout); |
There was a problem hiding this comment.
There is some code smell here because we are not using pouch_timeout_t as the type. To do so we'd need to move other code around to avoid circular dependencies. I thought this a better solution than copying the same function into blockbuf.c. The only real risk here is if the underlying type of pouch_timeout_t changes in the future.
|
|
||
| BaseType_t err = xQueueSend(_blockbuf_queue_handle, &buf, 0); | ||
| /* This can only return errQUEUE_FULL which should never happen */ | ||
| configASSERT(pdPASS == err); |
There was a problem hiding this comment.
I hemmed and hawed on this. Asserting here is not fantastic, especially if assertions are turned off in the build, we won't catch this at all. I initially had a log here, but it's the only logging in the whole file which seems like overkill to register a tag just for this.
This is unlikely to happen. The only way I can think of is if someone frees a buffer that has already been freed. We wouldn't be able to put it into the queue (full) so we should fail hard on that anyway.
Move from using dynamic allocation in blockbuf.c to using static allocation based on FreeRTOS queues. This maps well to the memory slabs used in the Zephyr implementation.
resolves: https://github.com/golioth/firmware-issue-tracker/issues/960