Move certain debug related functionality into header/source, feature gated by DEBUG flag
This commit is contained in:
parent
3308e61dc1
commit
259c048bd5
3 changed files with 35 additions and 16 deletions
21
driver.c
21
driver.c
|
@ -4,27 +4,16 @@
|
|||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define rb_size_t size_t
|
||||
#ifndef DEBUG
|
||||
#define DEBUG
|
||||
#endif
|
||||
|
||||
// #define rb_size_t size_t
|
||||
// #define rb_size_t int
|
||||
#include "ringbuf.h"
|
||||
|
||||
typedef int DATATYPE;
|
||||
|
||||
/**
|
||||
* @brief Debug print and empty the ringbuf
|
||||
*/
|
||||
void
|
||||
rb_debug_empty(struct RingBuf *rb)
|
||||
{
|
||||
int d;
|
||||
if(rb->count == 0)
|
||||
return;
|
||||
printf("Debug Data: [");
|
||||
while(rb_pop_front(rb, &d, memcpy) == ReadOk)
|
||||
printf("%d,", d);
|
||||
printf("\b]\n");
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
|
|
17
ringbuf.c
17
ringbuf.c
|
@ -131,6 +131,21 @@ rb_pop_front(struct RingBuf *rb, void *item, MEMCPY_T memcpy_fn)
|
|||
return ReadOk;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
#include <stdio.h>
|
||||
|
||||
void
|
||||
rb_debug_empty(struct RingBuf *rb)
|
||||
{
|
||||
int d;
|
||||
if(rb->count == 0)
|
||||
return;
|
||||
printf("Debug Data: [");
|
||||
while(rb_pop_front(rb, &d, memcpy) == ReadOk)
|
||||
printf("%d,", d);
|
||||
printf("\b]\n");
|
||||
}
|
||||
|
||||
void
|
||||
rb_debug_print(struct RingBuf *rb)
|
||||
{
|
||||
|
@ -147,3 +162,5 @@ rb_debug_print(struct RingBuf *rb)
|
|||
|
||||
DEBUG_PRINT("============%s\n", "");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
13
ringbuf.h
13
ringbuf.h
|
@ -111,12 +111,25 @@ enum ReadResult rb_pop_front(struct RingBuf *rb, void *item,
|
|||
|
||||
/**
|
||||
* @brief Free the ring buffer
|
||||
*
|
||||
* @details This function is idempotent, consecutive calls will not result in a
|
||||
* double free.
|
||||
*
|
||||
* @param rb The ring buffer
|
||||
* @param free The free function
|
||||
*/
|
||||
void rb_destroy(struct RingBuf *rb, void(free)());
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
/**
|
||||
* @brief Debug print
|
||||
*/
|
||||
void rb_debug_print(struct RingBuf *rb);
|
||||
|
||||
/**
|
||||
* @brief Debug print and empty the ringbuf
|
||||
*/
|
||||
void rb_debug_empty(struct RingBuf *rb);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue