mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-02 12:14:32 +02:00
esp_ringbuf: move ringbuf to seperate component
Signed-off-by: Mahavir Jain <mahavir@espressif.com>
This commit is contained in:
@@ -23,6 +23,6 @@ set(COMPONENT_SRCS "can.c"
|
|||||||
set(COMPONENT_ADD_INCLUDEDIRS "include")
|
set(COMPONENT_ADD_INCLUDEDIRS "include")
|
||||||
set(COMPONENT_PRIV_INCLUDEDIRS "include/driver")
|
set(COMPONENT_PRIV_INCLUDEDIRS "include/driver")
|
||||||
|
|
||||||
set(COMPONENT_REQUIRES)
|
set(COMPONENT_REQUIRES esp_ringbuf)
|
||||||
|
|
||||||
register_component()
|
register_component()
|
||||||
|
6
components/esp_ringbuf/CMakeLists.txt
Normal file
6
components/esp_ringbuf/CMakeLists.txt
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
set(COMPONENT_ADD_INCLUDEDIRS "include")
|
||||||
|
set(COMPONENT_SRCS "ringbuf.c")
|
||||||
|
|
||||||
|
set(COMPONENT_REQUIRES)
|
||||||
|
|
||||||
|
register_component()
|
0
components/esp_ringbuf/component.mk
Normal file
0
components/esp_ringbuf/component.mk
Normal file
@@ -14,10 +14,10 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "task.h"
|
#include "freertos/task.h"
|
||||||
#include "semphr.h"
|
#include "freertos/semphr.h"
|
||||||
#include "ringbuf.h"
|
#include "freertos/ringbuf.h"
|
||||||
|
|
||||||
//32-bit alignment macros
|
//32-bit alignment macros
|
||||||
#define rbALIGN_SIZE( xSize ) ( ( xSize + portBYTE_ALIGNMENT_MASK ) & ~portBYTE_ALIGNMENT_MASK )
|
#define rbALIGN_SIZE( xSize ) ( ( xSize + portBYTE_ALIGNMENT_MASK ) & ~portBYTE_ALIGNMENT_MASK )
|
||||||
@@ -566,7 +566,7 @@ static BaseType_t prvReceiveGeneric(Ringbuffer_t *pxRingbuffer, void **pvItem1,
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Semaphore obtained, check if item can be retrieved
|
//Semaphore obtained, check if item can be retrieved
|
||||||
taskENTER_CRITICAL(&pxRingbuffer->mux);
|
portENTER_CRITICAL(&pxRingbuffer->mux);
|
||||||
if (prvCheckItemAvail(pxRingbuffer) == pdTRUE) {
|
if (prvCheckItemAvail(pxRingbuffer) == pdTRUE) {
|
||||||
//Item is available for retrieval
|
//Item is available for retrieval
|
||||||
BaseType_t xIsSplit;
|
BaseType_t xIsSplit;
|
||||||
@@ -591,14 +591,14 @@ static BaseType_t prvReceiveGeneric(Ringbuffer_t *pxRingbuffer, void **pvItem1,
|
|||||||
if (pxRingbuffer->xItemsWaiting > 0) {
|
if (pxRingbuffer->xItemsWaiting > 0) {
|
||||||
xReturnSemaphore = pdTRUE;
|
xReturnSemaphore = pdTRUE;
|
||||||
}
|
}
|
||||||
taskEXIT_CRITICAL(&pxRingbuffer->mux);
|
portEXIT_CRITICAL(&pxRingbuffer->mux);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//No item available for retrieval, adjust ticks and take the semaphore again
|
//No item available for retrieval, adjust ticks and take the semaphore again
|
||||||
if (xTicksToWait != portMAX_DELAY) {
|
if (xTicksToWait != portMAX_DELAY) {
|
||||||
xTicksRemaining = xTicksEnd - xTaskGetTickCount();
|
xTicksRemaining = xTicksEnd - xTaskGetTickCount();
|
||||||
}
|
}
|
||||||
taskEXIT_CRITICAL(&pxRingbuffer->mux);
|
portEXIT_CRITICAL(&pxRingbuffer->mux);
|
||||||
/*
|
/*
|
||||||
* Gap between critical section and re-acquiring of the semaphore. If
|
* Gap between critical section and re-acquiring of the semaphore. If
|
||||||
* semaphore is given now, priority inversion might occur (see docs)
|
* semaphore is given now, priority inversion might occur (see docs)
|
||||||
@@ -616,7 +616,7 @@ static BaseType_t prvReceiveGenericFromISR(Ringbuffer_t *pxRingbuffer, void **pv
|
|||||||
BaseType_t xReturn = pdFALSE;
|
BaseType_t xReturn = pdFALSE;
|
||||||
BaseType_t xReturnSemaphore = pdFALSE;
|
BaseType_t xReturnSemaphore = pdFALSE;
|
||||||
|
|
||||||
taskENTER_CRITICAL_ISR(&pxRingbuffer->mux);
|
portENTER_CRITICAL_ISR(&pxRingbuffer->mux);
|
||||||
if(prvCheckItemAvail(pxRingbuffer) == pdTRUE) {
|
if(prvCheckItemAvail(pxRingbuffer) == pdTRUE) {
|
||||||
BaseType_t xIsSplit;
|
BaseType_t xIsSplit;
|
||||||
if (pxRingbuffer->uxRingbufferFlags & rbBYTE_BUFFER_FLAG) {
|
if (pxRingbuffer->uxRingbufferFlags & rbBYTE_BUFFER_FLAG) {
|
||||||
@@ -641,7 +641,7 @@ static BaseType_t prvReceiveGenericFromISR(Ringbuffer_t *pxRingbuffer, void **pv
|
|||||||
xReturnSemaphore = pdTRUE;
|
xReturnSemaphore = pdTRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
taskEXIT_CRITICAL_ISR(&pxRingbuffer->mux);
|
portEXIT_CRITICAL_ISR(&pxRingbuffer->mux);
|
||||||
|
|
||||||
if (xReturnSemaphore == pdTRUE) {
|
if (xReturnSemaphore == pdTRUE) {
|
||||||
xSemaphoreGiveFromISR(pxRingbuffer->xItemsBufferedSemaphore, NULL); //Give semaphore back so other tasks can retrieve
|
xSemaphoreGiveFromISR(pxRingbuffer->xItemsBufferedSemaphore, NULL); //Give semaphore back so other tasks can retrieve
|
||||||
@@ -766,7 +766,7 @@ BaseType_t xRingbufferSend(RingbufHandle_t xRingbuffer, const void *pvItem, size
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//Semaphore obtained, check if item can fit
|
//Semaphore obtained, check if item can fit
|
||||||
taskENTER_CRITICAL(&pxRingbuffer->mux);
|
portENTER_CRITICAL(&pxRingbuffer->mux);
|
||||||
if(pxRingbuffer->xCheckItemFits(pxRingbuffer, xItemSize) == pdTRUE) {
|
if(pxRingbuffer->xCheckItemFits(pxRingbuffer, xItemSize) == pdTRUE) {
|
||||||
//Item will fit, copy item
|
//Item will fit, copy item
|
||||||
pxRingbuffer->vCopyItem(pxRingbuffer, pvItem, xItemSize);
|
pxRingbuffer->vCopyItem(pxRingbuffer, pvItem, xItemSize);
|
||||||
@@ -775,14 +775,14 @@ BaseType_t xRingbufferSend(RingbufHandle_t xRingbuffer, const void *pvItem, size
|
|||||||
if (prvGetFreeSize(pxRingbuffer) > 0) {
|
if (prvGetFreeSize(pxRingbuffer) > 0) {
|
||||||
xReturnSemaphore = pdTRUE;
|
xReturnSemaphore = pdTRUE;
|
||||||
}
|
}
|
||||||
taskEXIT_CRITICAL(&pxRingbuffer->mux);
|
portEXIT_CRITICAL(&pxRingbuffer->mux);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//Item doesn't fit, adjust ticks and take the semaphore again
|
//Item doesn't fit, adjust ticks and take the semaphore again
|
||||||
if (xTicksToWait != portMAX_DELAY) {
|
if (xTicksToWait != portMAX_DELAY) {
|
||||||
xTicksRemaining = xTicksEnd - xTaskGetTickCount();
|
xTicksRemaining = xTicksEnd - xTaskGetTickCount();
|
||||||
}
|
}
|
||||||
taskEXIT_CRITICAL(&pxRingbuffer->mux);
|
portEXIT_CRITICAL(&pxRingbuffer->mux);
|
||||||
/*
|
/*
|
||||||
* Gap between critical section and re-acquiring of the semaphore. If
|
* Gap between critical section and re-acquiring of the semaphore. If
|
||||||
* semaphore is given now, priority inversion might occur (see docs)
|
* semaphore is given now, priority inversion might occur (see docs)
|
||||||
@@ -815,7 +815,7 @@ BaseType_t xRingbufferSendFromISR(RingbufHandle_t xRingbuffer, const void *pvIte
|
|||||||
//Attempt to send an item
|
//Attempt to send an item
|
||||||
BaseType_t xReturn;
|
BaseType_t xReturn;
|
||||||
BaseType_t xReturnSemaphore = pdFALSE;
|
BaseType_t xReturnSemaphore = pdFALSE;
|
||||||
taskENTER_CRITICAL_ISR(&pxRingbuffer->mux);
|
portENTER_CRITICAL_ISR(&pxRingbuffer->mux);
|
||||||
if (pxRingbuffer->xCheckItemFits(xRingbuffer, xItemSize) == pdTRUE) {
|
if (pxRingbuffer->xCheckItemFits(xRingbuffer, xItemSize) == pdTRUE) {
|
||||||
pxRingbuffer->vCopyItem(xRingbuffer, pvItem, xItemSize);
|
pxRingbuffer->vCopyItem(xRingbuffer, pvItem, xItemSize);
|
||||||
xReturn = pdTRUE;
|
xReturn = pdTRUE;
|
||||||
@@ -826,7 +826,7 @@ BaseType_t xRingbufferSendFromISR(RingbufHandle_t xRingbuffer, const void *pvIte
|
|||||||
} else {
|
} else {
|
||||||
xReturn = pdFALSE;
|
xReturn = pdFALSE;
|
||||||
}
|
}
|
||||||
taskEXIT_CRITICAL_ISR(&pxRingbuffer->mux);
|
portEXIT_CRITICAL_ISR(&pxRingbuffer->mux);
|
||||||
|
|
||||||
if (xReturn == pdTRUE) {
|
if (xReturn == pdTRUE) {
|
||||||
//Indicate item was successfully sent
|
//Indicate item was successfully sent
|
||||||
@@ -997,9 +997,9 @@ void vRingbufferReturnItem(RingbufHandle_t xRingbuffer, void *pvItem)
|
|||||||
configASSERT(pxRingbuffer);
|
configASSERT(pxRingbuffer);
|
||||||
configASSERT(pvItem != NULL);
|
configASSERT(pvItem != NULL);
|
||||||
|
|
||||||
taskENTER_CRITICAL(&pxRingbuffer->mux);
|
portENTER_CRITICAL(&pxRingbuffer->mux);
|
||||||
pxRingbuffer->vReturnItem(pxRingbuffer, (uint8_t *)pvItem);
|
pxRingbuffer->vReturnItem(pxRingbuffer, (uint8_t *)pvItem);
|
||||||
taskEXIT_CRITICAL(&pxRingbuffer->mux);
|
portEXIT_CRITICAL(&pxRingbuffer->mux);
|
||||||
xSemaphoreGive(pxRingbuffer->xFreeSpaceSemaphore);
|
xSemaphoreGive(pxRingbuffer->xFreeSpaceSemaphore);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1009,9 +1009,9 @@ void vRingbufferReturnItemFromISR(RingbufHandle_t xRingbuffer, void *pvItem, Bas
|
|||||||
configASSERT(pxRingbuffer);
|
configASSERT(pxRingbuffer);
|
||||||
configASSERT(pvItem != NULL);
|
configASSERT(pvItem != NULL);
|
||||||
|
|
||||||
taskENTER_CRITICAL_ISR(&pxRingbuffer->mux);
|
portENTER_CRITICAL_ISR(&pxRingbuffer->mux);
|
||||||
pxRingbuffer->vReturnItem(pxRingbuffer, (uint8_t *)pvItem);
|
pxRingbuffer->vReturnItem(pxRingbuffer, (uint8_t *)pvItem);
|
||||||
taskEXIT_CRITICAL_ISR(&pxRingbuffer->mux);
|
portEXIT_CRITICAL_ISR(&pxRingbuffer->mux);
|
||||||
xSemaphoreGiveFromISR(pxRingbuffer->xFreeSpaceSemaphore, pxHigherPriorityTaskWoken);
|
xSemaphoreGiveFromISR(pxRingbuffer->xFreeSpaceSemaphore, pxHigherPriorityTaskWoken);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1045,9 +1045,9 @@ size_t xRingbufferGetCurFreeSize(RingbufHandle_t xRingbuffer)
|
|||||||
configASSERT(pxRingbuffer);
|
configASSERT(pxRingbuffer);
|
||||||
|
|
||||||
size_t xFreeSize;
|
size_t xFreeSize;
|
||||||
taskENTER_CRITICAL(&pxRingbuffer->mux);
|
portENTER_CRITICAL(&pxRingbuffer->mux);
|
||||||
xFreeSize = pxRingbuffer->xGetCurMaxSize(pxRingbuffer);
|
xFreeSize = pxRingbuffer->xGetCurMaxSize(pxRingbuffer);
|
||||||
taskEXIT_CRITICAL(&pxRingbuffer->mux);
|
portEXIT_CRITICAL(&pxRingbuffer->mux);
|
||||||
return xFreeSize;
|
return xFreeSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1057,7 +1057,7 @@ BaseType_t xRingbufferAddToQueueSetRead(RingbufHandle_t xRingbuffer, QueueSetHan
|
|||||||
configASSERT(pxRingbuffer);
|
configASSERT(pxRingbuffer);
|
||||||
|
|
||||||
BaseType_t xReturn;
|
BaseType_t xReturn;
|
||||||
taskENTER_CRITICAL(&pxRingbuffer->mux);
|
portENTER_CRITICAL(&pxRingbuffer->mux);
|
||||||
//Cannot add semaphore to queue set if semaphore is not empty. Temporarily hold semaphore
|
//Cannot add semaphore to queue set if semaphore is not empty. Temporarily hold semaphore
|
||||||
BaseType_t xHoldSemaphore = xSemaphoreTake(pxRingbuffer->xItemsBufferedSemaphore, 0);
|
BaseType_t xHoldSemaphore = xSemaphoreTake(pxRingbuffer->xItemsBufferedSemaphore, 0);
|
||||||
xReturn = xQueueAddToSet(pxRingbuffer->xItemsBufferedSemaphore, xQueueSet);
|
xReturn = xQueueAddToSet(pxRingbuffer->xItemsBufferedSemaphore, xQueueSet);
|
||||||
@@ -1065,7 +1065,7 @@ BaseType_t xRingbufferAddToQueueSetRead(RingbufHandle_t xRingbuffer, QueueSetHan
|
|||||||
//Return semaphore if temporarily held
|
//Return semaphore if temporarily held
|
||||||
configASSERT(xSemaphoreGive(pxRingbuffer->xItemsBufferedSemaphore) == pdTRUE);
|
configASSERT(xSemaphoreGive(pxRingbuffer->xItemsBufferedSemaphore) == pdTRUE);
|
||||||
}
|
}
|
||||||
taskEXIT_CRITICAL(&pxRingbuffer->mux);
|
portEXIT_CRITICAL(&pxRingbuffer->mux);
|
||||||
return xReturn;
|
return xReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1083,7 +1083,7 @@ BaseType_t xRingbufferRemoveFromQueueSetRead(RingbufHandle_t xRingbuffer, QueueS
|
|||||||
configASSERT(pxRingbuffer);
|
configASSERT(pxRingbuffer);
|
||||||
|
|
||||||
BaseType_t xReturn;
|
BaseType_t xReturn;
|
||||||
taskENTER_CRITICAL(&pxRingbuffer->mux);
|
portENTER_CRITICAL(&pxRingbuffer->mux);
|
||||||
//Cannot remove semaphore from queue set if semaphore is not empty. Temporarily hold semaphore
|
//Cannot remove semaphore from queue set if semaphore is not empty. Temporarily hold semaphore
|
||||||
BaseType_t xHoldSemaphore = xSemaphoreTake(pxRingbuffer->xItemsBufferedSemaphore, 0);
|
BaseType_t xHoldSemaphore = xSemaphoreTake(pxRingbuffer->xItemsBufferedSemaphore, 0);
|
||||||
xReturn = xQueueRemoveFromSet(pxRingbuffer->xItemsBufferedSemaphore, xQueueSet);
|
xReturn = xQueueRemoveFromSet(pxRingbuffer->xItemsBufferedSemaphore, xQueueSet);
|
||||||
@@ -1091,7 +1091,7 @@ BaseType_t xRingbufferRemoveFromQueueSetRead(RingbufHandle_t xRingbuffer, QueueS
|
|||||||
//Return semaphore if temporarily held
|
//Return semaphore if temporarily held
|
||||||
configASSERT(xSemaphoreGive(pxRingbuffer->xItemsBufferedSemaphore) == pdTRUE);
|
configASSERT(xSemaphoreGive(pxRingbuffer->xItemsBufferedSemaphore) == pdTRUE);
|
||||||
}
|
}
|
||||||
taskEXIT_CRITICAL(&pxRingbuffer->mux);
|
portEXIT_CRITICAL(&pxRingbuffer->mux);
|
||||||
return xReturn;
|
return xReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1100,7 +1100,7 @@ void vRingbufferGetInfo(RingbufHandle_t xRingbuffer, UBaseType_t *uxFree, UBaseT
|
|||||||
Ringbuffer_t *pxRingbuffer = (Ringbuffer_t *)xRingbuffer;
|
Ringbuffer_t *pxRingbuffer = (Ringbuffer_t *)xRingbuffer;
|
||||||
configASSERT(pxRingbuffer);
|
configASSERT(pxRingbuffer);
|
||||||
|
|
||||||
taskENTER_CRITICAL(&pxRingbuffer->mux);
|
portENTER_CRITICAL(&pxRingbuffer->mux);
|
||||||
if (uxFree != NULL) {
|
if (uxFree != NULL) {
|
||||||
*uxFree = (UBaseType_t)(pxRingbuffer->pucFree - pxRingbuffer->pucHead);
|
*uxFree = (UBaseType_t)(pxRingbuffer->pucFree - pxRingbuffer->pucHead);
|
||||||
}
|
}
|
||||||
@@ -1113,7 +1113,7 @@ void vRingbufferGetInfo(RingbufHandle_t xRingbuffer, UBaseType_t *uxFree, UBaseT
|
|||||||
if (uxItemsWaiting != NULL) {
|
if (uxItemsWaiting != NULL) {
|
||||||
*uxItemsWaiting = (UBaseType_t)(pxRingbuffer->xItemsWaiting);
|
*uxItemsWaiting = (UBaseType_t)(pxRingbuffer->xItemsWaiting);
|
||||||
}
|
}
|
||||||
taskEXIT_CRITICAL(&pxRingbuffer->mux);
|
portEXIT_CRITICAL(&pxRingbuffer->mux);
|
||||||
}
|
}
|
||||||
|
|
||||||
void xRingbufferPrintInfo(RingbufHandle_t xRingbuffer)
|
void xRingbufferPrintInfo(RingbufHandle_t xRingbuffer)
|
5
components/esp_ringbuf/test/component.mk
Normal file
5
components/esp_ringbuf/test/component.mk
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
#
|
||||||
|
#Component Makefile
|
||||||
|
#
|
||||||
|
|
||||||
|
COMPONENT_ADD_LDFLAGS = -Wl,--whole-archive -l$(COMPONENT_NAME) -Wl,--no-whole-archive
|
@@ -7,7 +7,6 @@ set(COMPONENT_SRCS "FreeRTOS-openocd.c"
|
|||||||
"port.c"
|
"port.c"
|
||||||
"portasm.S"
|
"portasm.S"
|
||||||
"queue.c"
|
"queue.c"
|
||||||
"ringbuf.c"
|
|
||||||
"tasks.c"
|
"tasks.c"
|
||||||
"timers.c"
|
"timers.c"
|
||||||
"xtensa_context.S"
|
"xtensa_context.S"
|
||||||
@@ -28,7 +27,6 @@ set_source_files_properties(
|
|||||||
event_groups.c
|
event_groups.c
|
||||||
timers.c
|
timers.c
|
||||||
queue.c
|
queue.c
|
||||||
ringbuf.c
|
|
||||||
PROPERTIES COMPILE_DEFINITIONS
|
PROPERTIES COMPILE_DEFINITIONS
|
||||||
_ESP_FREERTOS_INTERNAL
|
_ESP_FREERTOS_INTERNAL
|
||||||
)
|
)
|
||||||
|
@@ -179,7 +179,8 @@ INPUT = \
|
|||||||
../../components/freertos/include/freertos/semphr.h \
|
../../components/freertos/include/freertos/semphr.h \
|
||||||
../../components/freertos/include/freertos/timers.h \
|
../../components/freertos/include/freertos/timers.h \
|
||||||
../../components/freertos/include/freertos/event_groups.h \
|
../../components/freertos/include/freertos/event_groups.h \
|
||||||
../../components/freertos/include/freertos/ringbuf.h \
|
### Ringbuffer
|
||||||
|
../../components/esp_ringbuf/include/freertos/ringbuf.h \
|
||||||
### Helper functions for error codes
|
### Helper functions for error codes
|
||||||
../../components/esp32/include/esp_err.h \
|
../../components/esp32/include/esp_err.h \
|
||||||
### System APIs
|
### System APIs
|
||||||
|
Reference in New Issue
Block a user