summaryrefslogtreecommitdiff
path: root/firmware/include/buflib.h
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/include/buflib.h')
-rw-r--r--firmware/include/buflib.h47
1 files changed, 29 insertions, 18 deletions
diff --git a/firmware/include/buflib.h b/firmware/include/buflib.h
index 349e4a3e7a..49e4db11c0 100644
--- a/firmware/include/buflib.h
+++ b/firmware/include/buflib.h
@@ -23,15 +23,21 @@
23* KIND, either express or implied. 23* KIND, either express or implied.
24* 24*
25****************************************************************************/ 25****************************************************************************/
26
27#ifndef _BUFLIB_H_ 26#ifndef _BUFLIB_H_
28#define _BUFLIB_H_ 27#define _BUFLIB_H_
28
29#include <stdint.h> 29#include <stdint.h>
30#include <stdbool.h> 30#include <stdbool.h>
31#include <string.h> 31#include <string.h>
32 32
33/* enable single block debugging */ 33/* add extra checks to buflib_get_data to catch bad handles */
34#define BUFLIB_DEBUG_BLOCK_SINGLE 34//#define BUFLIB_DEBUG_GET_DATA
35
36/* support integrity check */
37//#define BUFLIB_DEBUG_CHECK_VALID
38
39/* support debug printing of memory blocks */
40//#define BUFLIB_DEBUG_PRINT
35 41
36union buflib_data 42union buflib_data
37{ 43{
@@ -260,12 +266,12 @@ int buflib_alloc_maximum(struct buflib_context* ctx,
260 * 266 *
261 * Returns: The start pointer of the allocation 267 * Returns: The start pointer of the allocation
262 */ 268 */
263#ifdef DEBUG 269#ifdef BUFLIB_DEBUG_GET_DATA
264void* buflib_get_data(struct buflib_context *ctx, int handle); 270void *buflib_get_data(struct buflib_context *ctx, int handle);
265#else 271#else
266static inline void* buflib_get_data(struct buflib_context *ctx, int handle) 272static inline void *buflib_get_data(struct buflib_context *ctx, int handle)
267{ 273{
268 return (void*)(ctx->handle_table[-handle].alloc); 274 return (void *)ctx->handle_table[-handle].alloc;
269} 275}
270#endif 276#endif
271 277
@@ -342,29 +348,34 @@ void* buflib_buffer_out(struct buflib_context *ctx, size_t *size);
342 */ 348 */
343void buflib_buffer_in(struct buflib_context *ctx, int size); 349void buflib_buffer_in(struct buflib_context *ctx, int size);
344 350
345/* debugging */ 351#ifdef BUFLIB_DEBUG_PRINT
346
347/** 352/**
348 * Gets the number of blocks in the entire buffer, allocated or unallocated 353 * Return the number of blocks in the buffer, allocated or unallocated.
349 * 354 *
350 * Only available if BUFLIB_DEBUG_BLOCK_SIGNLE is defined 355 * Only available if BUFLIB_DEBUG_PRINT is defined.
351 */ 356 */
352int buflib_get_num_blocks(struct buflib_context *ctx); 357int buflib_get_num_blocks(struct buflib_context *ctx);
353 358
354/** 359/**
355 * Print information about a single block as indicated by block_num 360 * Write a string describing the block at index block_num to the
356 * into buf 361 * provided buffer. The buffer will always be null terminated and
362 * there is no provision to detect truncation. (A 40-byte buffer
363 * is enough to contain any returned string.)
357 * 364 *
358 * buflib_get_num_blocks() beforehand to get the total number of blocks, 365 * Returns false if the block index is out of bounds, and writes
359 * as passing an block_num higher than that is undefined 366 * an empty string.
360 * 367 *
361 * Only available if BUFLIB_DEBUG_BLOCK_SIGNLE is defined 368 * Only available if BUFLIB_DEBUG_PRINT is defined.
362 */ 369 */
363void buflib_print_block_at(struct buflib_context *ctx, int block_num, 370bool buflib_print_block_at(struct buflib_context *ctx, int block_num,
364 char* buf, size_t bufsize); 371 char *buf, size_t bufsize);
372#endif
365 373
374#ifdef BUFLIB_DEBUG_CHECK_VALID
366/** 375/**
367 * Check integrity of given buflib context 376 * Check integrity of given buflib context
368 */ 377 */
369void buflib_check_valid(struct buflib_context *ctx); 378void buflib_check_valid(struct buflib_context *ctx);
370#endif 379#endif
380
381#endif /* _BUFLIB_H_ */