diff options
-rw-r--r-- | board/hyperdebug/gpio.c | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/board/hyperdebug/gpio.c b/board/hyperdebug/gpio.c index 53a4929b3c..fff62ee233 100644 --- a/board/hyperdebug/gpio.c +++ b/board/hyperdebug/gpio.c @@ -12,7 +12,6 @@ #include "gpio.h" #include "hooks.h" #include "registers.h" -#include "shared_mem.h" #include "task.h" #include "timer.h" #include "util.h" @@ -101,6 +100,36 @@ struct monitoring_slot_t { struct monitoring_slot_t monitoring_slots[16]; /* + * Memory area used for allocation of cyclic buffers. (Currently the + * implementation supports only a single allocation.) + */ +uint8_t buffer_area[sizeof(struct cyclic_buffer_header_t) + 8192]; +bool buffer_area_in_use = false; + +static struct cyclic_buffer_header_t *allocate_cyclic_buffer(size_t size) +{ + struct cyclic_buffer_header_t *res = + (struct cyclic_buffer_header_t *)buffer_area; + if (buffer_area_in_use) { + /* No support for multiple smaller allocations, yet. */ + return 0; + } + if (sizeof(struct cyclic_buffer_header_t) + size > + sizeof(buffer_area)) { + /* Requested size exceeds the capacity of the area. */ + return 0; + } + buffer_area_in_use = true; + res->size = size; + return res; +} + +static void free_cyclic_buffer(struct cyclic_buffer_header_t *buf) +{ + buffer_area_in_use = false; +} + +/* * Counts unacknowledged buffer overflows. Whenever non-zero, the red LED * will flash. */ @@ -251,7 +280,7 @@ static void stop_all_gpio_monitoring(void) num_cur_monitoring--; if (buffer_header->overflow) atomic_sub(&num_cur_error_conditions, 1); - shared_mem_release((char *)buffer_header); + free_cyclic_buffer(buffer_header); } } @@ -521,14 +550,13 @@ static int command_gpio_monitoring_start(int argc, const char **argv) * All the requested signals were available for monitoring, and their * slots have been marked as reserved for the respective signal. */ - rv = shared_mem_acquire(sizeof(struct cyclic_buffer_header_t) + - cyclic_buffer_size, - (char **)&buf); - if (rv != EC_SUCCESS) + buf = allocate_cyclic_buffer(cyclic_buffer_size); + if (!buf) { + rv = EC_ERROR_BUSY; goto out_cleanup; + } buf->head = buf->tail = 0; - buf->size = cyclic_buffer_size; buf->overflow = 0; buf->num_signals = gpio_num; buf->signal_bits = 0; @@ -790,7 +818,7 @@ static int command_gpio_monitoring_stop(int argc, const char **argv) if (buf->overflow) atomic_sub(&num_cur_error_conditions, 1); - shared_mem_release((char *)buf); + free_cyclic_buffer(buf); return EC_SUCCESS; } |