From f995c26de92eadbf3d961ad3e0fb233410798dd2 Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Mon, 2 Jan 2023 19:49:56 +0000 Subject: [PATCH] buflib: Add CONFIG_BUFLIB_BACKEND for selecting a buflib backend Defaults to the normal "mempool" backend, which is currently the only implementation. Change-Id: I56d034a6e0f5edc90c39526d1551945eec6ca336 --- apps/plugin.h | 2 +- firmware/SOURCES | 2 ++ firmware/buflib_mempool.c | 2 +- firmware/core_alloc.c | 2 +- firmware/export/config.h | 7 +++++++ firmware/include/buflib.h | 30 ++++++++++++++++++++++++++++++ firmware/include/buflib_mempool.h | 4 ++++ firmware/include/chunk_alloc.h | 2 +- firmware/include/core_alloc.h | 2 +- 9 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 firmware/include/buflib.h diff --git a/apps/plugin.h b/apps/plugin.h index ea69cbe2b2..850e7484d9 100644 --- a/apps/plugin.h +++ b/apps/plugin.h @@ -100,7 +100,7 @@ int plugin_open(const char *plugin, const char *parameter); #include "list.h" #include "tree.h" #include "color_picker.h" -#include "buflib_mempool.h" +#include "buflib.h" #include "buffering.h" #include "tagcache.h" #include "viewport.h" diff --git a/firmware/SOURCES b/firmware/SOURCES index c8789756aa..02e962c0c3 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -4,7 +4,9 @@ ata_idle_notify.c events.c backlight.c +#if CONFIG_BUFLIB_BACKEND == BUFLIB_BACKEND_MEMPOOL buflib_mempool.c +#endif core_alloc.c general.c powermgmt.c diff --git a/firmware/buflib_mempool.c b/firmware/buflib_mempool.c index 18e4f118ff..cb35290c03 100644 --- a/firmware/buflib_mempool.c +++ b/firmware/buflib_mempool.c @@ -29,7 +29,7 @@ #include /* for abs() */ #include /* for snprintf() */ #include /* for ptrdiff_t */ -#include "buflib_mempool.h" +#include "buflib.h" #include "string-extra.h" /* strmemccpy() */ #include "debug.h" #include "panic.h" diff --git a/firmware/core_alloc.c b/firmware/core_alloc.c index 6f6c385597..948911b973 100644 --- a/firmware/core_alloc.c +++ b/firmware/core_alloc.c @@ -3,7 +3,7 @@ #include #include "system.h" #include "core_alloc.h" -#include "buflib_mempool.h" +#include "buflib.h" /* not static so it can be discovered by core_get_data() */ struct buflib_context core_ctx; diff --git a/firmware/export/config.h b/firmware/export/config.h index 8726a8d6f4..d8674c40f2 100644 --- a/firmware/export/config.h +++ b/firmware/export/config.h @@ -380,6 +380,9 @@ Lyre prototype 1 */ #define IMX233_FREESCALE (1 << 0) /* Freescale I.MX233 nonstandard two-level MBR */ #define IMX233_CREATIVE (1 << 1) /* Creative MBLK windowing */ +/* CONFIG_BUFLIB_BACKEND */ +#define BUFLIB_BACKEND_MEMPOOL 0 /* Default memory pool backed buflib */ + /* now go and pick yours */ #if defined(IRIVER_H100) #include "config/iriverh100.h" @@ -606,6 +609,10 @@ Lyre prototype 1 */ #undef CONFIG_STORAGE #endif +#ifndef CONFIG_BUFLIB_BACKEND +# define CONFIG_BUFLIB_BACKEND BUFLIB_BACKEND_MEMPOOL +#endif + #ifdef APPLICATION #define CONFIG_CPU 0 #endif diff --git a/firmware/include/buflib.h b/firmware/include/buflib.h new file mode 100644 index 0000000000..36d171963a --- /dev/null +++ b/firmware/include/buflib.h @@ -0,0 +1,30 @@ +/************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2023 Aidan MacDonald + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#ifndef _BUFLIB_H_ +#define _BUFLIB_H_ + +#include "config.h" + +#if CONFIG_BUFLIB_BACKEND == BUFLIB_BACKEND_MEMPOOL +#include "buflib_mempool.h" +#endif + +#endif /* _BUFLIB_H_ */ diff --git a/firmware/include/buflib_mempool.h b/firmware/include/buflib_mempool.h index 61fe2168b0..f261d4abda 100644 --- a/firmware/include/buflib_mempool.h +++ b/firmware/include/buflib_mempool.h @@ -26,6 +26,10 @@ #ifndef _BUFLIB_MEMPOOL_H_ #define _BUFLIB_MEMPOOL_H_ +#ifndef _BUFLIB_H_ +# error "include buflib.h instead" +#endif + #include #include #include diff --git a/firmware/include/chunk_alloc.h b/firmware/include/chunk_alloc.h index f589cc0870..7d64d4b591 100644 --- a/firmware/include/chunk_alloc.h +++ b/firmware/include/chunk_alloc.h @@ -24,7 +24,7 @@ #include #include #include "config.h" -#include "buflib_mempool.h" +#include "buflib.h" #define CHUNK_ALLOC_INVALID ((size_t)-1) diff --git a/firmware/include/core_alloc.h b/firmware/include/core_alloc.h index 382200dd75..22cc1988da 100644 --- a/firmware/include/core_alloc.h +++ b/firmware/include/core_alloc.h @@ -4,7 +4,7 @@ #include #include #include "config.h" -#include "buflib_mempool.h" +#include "buflib.h" #include "chunk_alloc.h" /* All functions below are wrappers for functions in buflib.h, except