agileRTOS (zrtos)  Version 0.8.0 (ghostbuster)
cbuffer.h File Reference
#include <stdarg.h>
#include <zrtos/types.h>
#include <zrtos/error.h>
#include <zrtos/list.h>
#include <zrtos/malloc_limit.h>
#include <zrtos/assert.h>
#include <zrtos/cast.h>
Include dependency graph for cbuffer.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  _zrtos_cbuffer_node_t
 
struct  _zrtos_cbuffer_t
 
struct  _zrtos_cbuffer_write_transaction_t
 

Macros

#define ZRTOS_CBUFFER__CFG_DATA_LENGTH   16
 
#define ZRTOS_CBUFFER__CFG_MALLOC_LIMIT   200
 

Typedefs

typedef struct _zrtos_cbuffer_node_t zrtos_cbuffer_node_t
 
typedef struct _zrtos_cbuffer_t zrtos_cbuffer_t
 
typedef struct _zrtos_cbuffer_write_transaction_t zrtos_cbuffer_write_transaction_t
 

Functions

 ZRTOS_ASSERT__STATIC_IS_POWER_OF_TWO (ZRTOS_CBUFFER__CFG_DATA_LENGTH)
 
zrtos_cbuffer_node_tzrtos_cbuffer__get_first_node (zrtos_cbuffer_t *thiz)
 
zrtos_cbuffer_node_tzrtos_cbuffer__get_last_node (zrtos_cbuffer_t *thiz)
 
zrtos_cbuffer_node_tzrtos_cbuffer_node__get_next_node (zrtos_cbuffer_node_t *thiz)
 
bool zrtos_cbuffer_node__init (zrtos_cbuffer_node_t *thiz, zrtos_cbuffer_t *ctx)
 
zrtos_cbuffer_node_tzrtos_cbuffer_node__new (zrtos_cbuffer_t *ctx)
 
void zrtos_cbuffer_node__free (zrtos_cbuffer_node_t *thiz, zrtos_cbuffer_t *ctx)
 
bool zrtos_cbuffer__init (zrtos_cbuffer_t *thiz)
 
void zrtos_cbuffer__deinit_callback (zrtos_list_t *thiz, zrtos_list_node_t *node)
 
void zrtos_cbuffer__deinit (zrtos_cbuffer_t *thiz)
 
void zrtos_cbuffer__start_write_transaction (zrtos_cbuffer_t *thiz, zrtos_cbuffer_write_transaction_t *txn)
 
void zrtos_cbuffer__rollback_write_transaction (zrtos_cbuffer_t *thiz, zrtos_cbuffer_write_transaction_t *txn)
 
static size_t zrtos_cbuffer_node__get_length (zrtos_cbuffer_node_t *thiz)
 
bool zrtos_cbuffer_node__is_empty (zrtos_cbuffer_node_t *thiz)
 
static size_t zrtos_cbuffer_node__get_free_space (zrtos_cbuffer_node_t *thiz)
 
zrtos_error_t zrtos_cbuffer_node__put (zrtos_cbuffer_node_t *thiz, zrtos_cbuffer_t *ctx, uint8_t val)
 
zrtos_error_t zrtos_cbuffer_node__get (zrtos_cbuffer_node_t *thiz, zrtos_cbuffer_t *ctx, uint8_t *out)
 
zrtos_error_t zrtos_cbuffer_node__peek (zrtos_cbuffer_node_t *thiz, uint8_t *out)
 
zrtos_error_t zrtos_cbuffer__hash (zrtos_cbuffer_t *thiz, size_t length, void(*callback)(void *callback_args, uint8_t ch), void *callback_args)
 
zrtos_error_t zrtos_cbuffer__put (zrtos_cbuffer_t *thiz, uint8_t val)
 
zrtos_error_t zrtos_cbuffer__put_ex (zrtos_cbuffer_t *thiz, size_t len, size_t *outlen,...)
 
zrtos_error_t zrtos_cbuffer__peek (zrtos_cbuffer_t *thiz, uint8_t *out)
 
zrtos_error_t zrtos_cbuffer__get (zrtos_cbuffer_t *thiz, uint8_t *out)
 
zrtos_error_t zrtos_cbuffer__get_ex (zrtos_cbuffer_t *thiz, void *data, size_t len, size_t *outlen)
 
zrtos_error_t zrtos_cbuffer__pop (zrtos_cbuffer_t *thiz)
 
bool zrtos_cbuffer__is_empty (zrtos_cbuffer_t *thiz)
 
void zrtos_cbuffer__clear (zrtos_cbuffer_t *thiz)
 
zrtos_error_t zrtos_cbuffer__can_read (zrtos_cbuffer_t *thiz)
 
bool zrtos_cbuffer__can_read_length (zrtos_cbuffer_t *thiz, size_t length)
 
size_t zrtos_cbuffer__get_length (zrtos_cbuffer_t *thiz)
 
zrtos_error_t zrtos_cbuffer__can_write (zrtos_cbuffer_t *thiz)
 
zrtos_error_t zrtos_cbuffer__pipe (zrtos_cbuffer_t *thiz, zrtos_cbuffer_t *src, size_t length, size_t *outlen)
 

Variables

zrtos_malloc_limit_t zrtos_cbuffer__malloc_limit = ZRTOS_MALLOC_LIMIT__INIT()
 

Macro Definition Documentation

◆ ZRTOS_CBUFFER__CFG_DATA_LENGTH

#define ZRTOS_CBUFFER__CFG_DATA_LENGTH   16

Definition at line 25 of file cbuffer.h.

◆ ZRTOS_CBUFFER__CFG_MALLOC_LIMIT

#define ZRTOS_CBUFFER__CFG_MALLOC_LIMIT   200

Definition at line 29 of file cbuffer.h.

Typedef Documentation

◆ zrtos_cbuffer_node_t

◆ zrtos_cbuffer_t

◆ zrtos_cbuffer_write_transaction_t

Function Documentation

◆ ZRTOS_ASSERT__STATIC_IS_POWER_OF_TWO()

ZRTOS_ASSERT__STATIC_IS_POWER_OF_TWO ( ZRTOS_CBUFFER__CFG_DATA_LENGTH  )

◆ zrtos_cbuffer__can_read()

zrtos_error_t zrtos_cbuffer__can_read ( zrtos_cbuffer_t thiz)

Definition at line 373 of file cbuffer.h.

375  {
376  return zrtos_cbuffer__is_empty(thiz)
379  ;
380 }
bool zrtos_cbuffer__is_empty(zrtos_cbuffer_t *thiz)
Definition: cbuffer.h:357
Try again.
Definition: error.h:35
Successful program execution status.
Definition: error.h:22
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_cbuffer__can_read_length()

bool zrtos_cbuffer__can_read_length ( zrtos_cbuffer_t thiz,
size_t  length 
)

Definition at line 382 of file cbuffer.h.

385  {
387 
388  while(node
389  && length
390  && !zrtos_cbuffer_node__is_empty(node)){
391  length -= ZRTOS_TYPES__MIN(
392  ((size_t)(node->head - node->tail))
393  ,length
394  );
396  }
397 
398  return length == 0;
399 }
zrtos_cbuffer_node_t * zrtos_cbuffer__get_first_node(zrtos_cbuffer_t *thiz)
Definition: cbuffer.h:57
#define ZRTOS_TYPES__MIN(a, b)
Definition: types.h:78
bool zrtos_cbuffer_node__is_empty(zrtos_cbuffer_node_t *thiz)
Definition: cbuffer.h:175
zrtos_cbuffer_node_t * zrtos_cbuffer_node__get_next_node(zrtos_cbuffer_node_t *thiz)
Definition: cbuffer.h:75
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_cbuffer__can_write()

zrtos_error_t zrtos_cbuffer__can_write ( zrtos_cbuffer_t thiz)

Definition at line 415 of file cbuffer.h.

417  {
418  return ZRTOS_ERROR__SUCCESS;
419 }
Successful program execution status.
Definition: error.h:22
Here is the caller graph for this function:

◆ zrtos_cbuffer__clear()

void zrtos_cbuffer__clear ( zrtos_cbuffer_t thiz)

Definition at line 362 of file cbuffer.h.

362  {
364 
365  while(zrtos_list_node__has_next_node(&node->node)){
366  zrtos_cbuffer_node__free(node,thiz);
367  node = zrtos_cbuffer__get_first_node(thiz);
368  }
369 
370  node->head = node->tail = 0;
371 }
bool zrtos_list_node__has_next_node(zrtos_list_node_t *node)
Definition: list.h:45
zrtos_cbuffer_node_t * zrtos_cbuffer__get_first_node(zrtos_cbuffer_t *thiz)
Definition: cbuffer.h:57
zrtos_list_node_t node
Definition: cbuffer.h:39
void zrtos_cbuffer_node__free(zrtos_cbuffer_node_t *thiz, zrtos_cbuffer_t *ctx)
Definition: cbuffer.h:110
Here is the call graph for this function:

◆ zrtos_cbuffer__deinit()

void zrtos_cbuffer__deinit ( zrtos_cbuffer_t thiz)

Definition at line 140 of file cbuffer.h.

142  {
144 }
void zrtos_cbuffer__deinit_callback(zrtos_list_t *thiz, zrtos_list_node_t *node)
Definition: cbuffer.h:122
void zrtos_list__deinit(zrtos_list_t *thiz, void(*callback)(zrtos_list_t *thiz, zrtos_list_node_t *node))
Definition: list.h:115
zrtos_list_t root
Definition: cbuffer.h:46
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_cbuffer__deinit_callback()

void zrtos_cbuffer__deinit_callback ( zrtos_list_t thiz,
zrtos_list_node_t node 
)

Definition at line 122 of file cbuffer.h.

125  {
128  node
130  ,node
131  )
133  thiz
135  ,root
136  )
137  );
138 }
#define zrtos_types__get_container_of(ptr, type, member)
Definition: types.h:69
void zrtos_cbuffer_node__free(zrtos_cbuffer_node_t *thiz, zrtos_cbuffer_t *ctx)
Definition: cbuffer.h:110
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_cbuffer__get()

zrtos_error_t zrtos_cbuffer__get ( zrtos_cbuffer_t thiz,
uint8_t out 
)

Definition at line 327 of file cbuffer.h.

327  {
331  ,node
332  );
333  return zrtos_cbuffer_node__get(node,thiz,out);
334 }
zrtos_list_node_t * zrtos_list__get_first_node(zrtos_list_t *thiz)
Definition: list.h:26
#define zrtos_types__get_container_of(ptr, type, member)
Definition: types.h:69
zrtos_error_t zrtos_cbuffer_node__get(zrtos_cbuffer_node_t *thiz, zrtos_cbuffer_t *ctx, uint8_t *out)
Definition: cbuffer.h:213
zrtos_list_t root
Definition: cbuffer.h:46
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_cbuffer__get_ex()

zrtos_error_t zrtos_cbuffer__get_ex ( zrtos_cbuffer_t thiz,
void *  data,
size_t  len,
size_t outlen 
)

Definition at line 336 of file cbuffer.h.

341  {
343  uint8_t *tmp = ZRTOS_CAST(uint8_t*,data);
344  while(len--
345  && ZRTOS_ERROR__SUCCESS == (ret = zrtos_cbuffer__get(thiz,tmp++))){
346  ;
347  }
348  *outlen = zrtos_types__ptr_get_byte_distance(tmp,data);
349  return ret;
350 }
#define ZRTOS_CAST(type, value)
Definition: cast.h:18
zrtos_error_t zrtos_cbuffer__get(zrtos_cbuffer_t *thiz, uint8_t *out)
Definition: cbuffer.h:327
size_t zrtos_types__ptr_get_byte_distance(void *bigger, void *smaller)
Definition: types.h:43
Successful program execution status.
Definition: error.h:22
static uint8_t
Definition: mcp2515.h:159
zrtos_error_t
Definition: error.h:20
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_cbuffer__get_first_node()

zrtos_cbuffer_node_t* zrtos_cbuffer__get_first_node ( zrtos_cbuffer_t thiz)

Definition at line 57 of file cbuffer.h.

57  {
61  ,node
62  );
63  return node;
64 }
zrtos_list_node_t * zrtos_list__get_first_node(zrtos_list_t *thiz)
Definition: list.h:26
#define zrtos_types__get_container_of(ptr, type, member)
Definition: types.h:69
zrtos_list_t root
Definition: cbuffer.h:46
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_cbuffer__get_last_node()

zrtos_cbuffer_node_t* zrtos_cbuffer__get_last_node ( zrtos_cbuffer_t thiz)

Definition at line 66 of file cbuffer.h.

66  {
70  ,node
71  );
72  return node;
73 }
zrtos_list_node_t * zrtos_list__get_last_node(zrtos_list_t *thiz)
Definition: list.h:30
#define zrtos_types__get_container_of(ptr, type, member)
Definition: types.h:69
zrtos_list_t root
Definition: cbuffer.h:46
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_cbuffer__get_length()

size_t zrtos_cbuffer__get_length ( zrtos_cbuffer_t thiz)

Definition at line 401 of file cbuffer.h.

403  {
405  size_t length = 0;
406 
407  while(node){
408  length += zrtos_cbuffer_node__get_length(node);
410  }
411 
412  return length == 0;
413 }
zrtos_cbuffer_node_t * zrtos_cbuffer__get_first_node(zrtos_cbuffer_t *thiz)
Definition: cbuffer.h:57
zrtos_cbuffer_node_t * zrtos_cbuffer_node__get_next_node(zrtos_cbuffer_node_t *thiz)
Definition: cbuffer.h:75
static size_t zrtos_cbuffer_node__get_length(zrtos_cbuffer_node_t *thiz)
Definition: cbuffer.h:169
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_cbuffer__hash()

zrtos_error_t zrtos_cbuffer__hash ( zrtos_cbuffer_t thiz,
size_t  length,
void(*)(void *callback_args, uint8_t ch)  callback,
void *  callback_args 
)

Definition at line 245 of file cbuffer.h.

250  {
252  size_t tail;
253  size_t head;
254 
255  while(node && length){
256  head = node->head;
257  tail = node->tail;
258 
259  while(tail != head && length--){
260  callback(callback_args,node->data[tail++]);
261  }
262 
264  }
265 
266  return length == 0 ? ZRTOS_ERROR__SUCCESS : ZRTOS_ERROR__INVAL;
267 }
zrtos_cbuffer_node_t * zrtos_cbuffer__get_first_node(zrtos_cbuffer_t *thiz)
Definition: cbuffer.h:57
Successful program execution status.
Definition: error.h:22
uint8_t data[ZRTOS_CBUFFER__CFG_DATA_LENGTH]
Definition: cbuffer.h:40
Invalid argument.
Definition: error.h:46
zrtos_cbuffer_node_t * zrtos_cbuffer_node__get_next_node(zrtos_cbuffer_node_t *thiz)
Definition: cbuffer.h:75
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_cbuffer__init()

bool zrtos_cbuffer__init ( zrtos_cbuffer_t thiz)

Definition at line 115 of file cbuffer.h.

117  {
118  zrtos_list__init(&thiz->root);
119  return zrtos_cbuffer_node__new(thiz) != 0;
120 }
zrtos_cbuffer_node_t * zrtos_cbuffer_node__new(zrtos_cbuffer_t *ctx)
Definition: cbuffer.h:95
bool zrtos_list__init(zrtos_list_t *thiz)
Definition: list.h:51
zrtos_list_t root
Definition: cbuffer.h:46
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_cbuffer__is_empty()

bool zrtos_cbuffer__is_empty ( zrtos_cbuffer_t thiz)

Definition at line 357 of file cbuffer.h.

357  {
359  return zrtos_cbuffer_node__is_empty(node);
360 }
zrtos_cbuffer_node_t * zrtos_cbuffer__get_first_node(zrtos_cbuffer_t *thiz)
Definition: cbuffer.h:57
bool zrtos_cbuffer_node__is_empty(zrtos_cbuffer_node_t *thiz)
Definition: cbuffer.h:175
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_cbuffer__peek()

zrtos_error_t zrtos_cbuffer__peek ( zrtos_cbuffer_t thiz,
uint8_t out 
)

Definition at line 318 of file cbuffer.h.

318  {
322  ,node
323  );
324  return zrtos_cbuffer_node__peek(node,out);
325 }
zrtos_list_node_t * zrtos_list__get_first_node(zrtos_list_t *thiz)
Definition: list.h:26
#define zrtos_types__get_container_of(ptr, type, member)
Definition: types.h:69
zrtos_list_t root
Definition: cbuffer.h:46
zrtos_error_t zrtos_cbuffer_node__peek(zrtos_cbuffer_node_t *thiz, uint8_t *out)
Definition: cbuffer.h:232
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_cbuffer__pipe()

zrtos_error_t zrtos_cbuffer__pipe ( zrtos_cbuffer_t thiz,
zrtos_cbuffer_t src,
size_t  length,
size_t outlen 
)

Definition at line 421 of file cbuffer.h.

426  {
428  uint8_t tmp;
429 
430  *outlen = length;
431 
432  while(length){
433  if(zrtos_error__is_success((ret = zrtos_cbuffer__peek(src,&tmp)))
434  && zrtos_error__is_success((ret = zrtos_cbuffer__put(thiz,tmp)))
435  ){
436  length--;
437  zrtos_cbuffer__pop(src);
438  }else{
439  break;
440  }
441  }
442 
443  *outlen -= length;
444 
445  return ret;
446 }
zrtos_error_t zrtos_cbuffer__put(zrtos_cbuffer_t *thiz, uint8_t val)
Definition: cbuffer.h:269
zrtos_error_t zrtos_cbuffer__pop(zrtos_cbuffer_t *thiz)
Definition: cbuffer.h:352
zrtos_error_t zrtos_cbuffer__peek(zrtos_cbuffer_t *thiz, uint8_t *out)
Definition: cbuffer.h:318
bool zrtos_error__is_success(zrtos_error_t thiz)
Definition: error.h:152
Successful program execution status.
Definition: error.h:22
static uint8_t
Definition: mcp2515.h:159
zrtos_error_t
Definition: error.h:20
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_cbuffer__pop()

zrtos_error_t zrtos_cbuffer__pop ( zrtos_cbuffer_t thiz)

Definition at line 352 of file cbuffer.h.

352  {
353  uint8_t out;
354  return zrtos_cbuffer__get(thiz,&out);
355 }
zrtos_error_t zrtos_cbuffer__get(zrtos_cbuffer_t *thiz, uint8_t *out)
Definition: cbuffer.h:327
static uint8_t
Definition: mcp2515.h:159
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_cbuffer__put()

zrtos_error_t zrtos_cbuffer__put ( zrtos_cbuffer_t thiz,
uint8_t  val 
)

Definition at line 269 of file cbuffer.h.

269  {
273  ,node
274  );
275  return zrtos_cbuffer_node__put(node,thiz,val);
276 }
zrtos_list_node_t * zrtos_list__get_last_node(zrtos_list_t *thiz)
Definition: list.h:30
#define zrtos_types__get_container_of(ptr, type, member)
Definition: types.h:69
zrtos_error_t zrtos_cbuffer_node__put(zrtos_cbuffer_node_t *thiz, zrtos_cbuffer_t *ctx, uint8_t val)
Definition: cbuffer.h:188
zrtos_list_t root
Definition: cbuffer.h:46
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_cbuffer__put_ex()

zrtos_error_t zrtos_cbuffer__put_ex ( zrtos_cbuffer_t thiz,
size_t  len,
size_t outlen,
  ... 
)

Definition at line 278 of file cbuffer.h.

287  {
289  uint8_t *data;
290  size_t data_len;
291  va_list args;
293 
294  va_start(args,outlen);
295 
297 
298  while(len-- && zrtos_error__is_success(ret)){
299  data = ZRTOS_CAST(uint8_t*,va_arg(args,void*));
300  data_len = va_arg(args,size_t);
301  while(data_len-- && zrtos_error__is_success(ret)){
302  ret = zrtos_cbuffer__put(
303  thiz
304  ,*data++
305  );
306  }
307  }
308 
309  if(zrtos_error__is_error(ret)){
311  }
312 
313  va_end(args);
314 
315  return ret;
316 }
#define ZRTOS_CAST(type, value)
Definition: cast.h:18
void zrtos_cbuffer__rollback_write_transaction(zrtos_cbuffer_t *thiz, zrtos_cbuffer_write_transaction_t *txn)
Definition: cbuffer.h:154
zrtos_error_t zrtos_cbuffer__put(zrtos_cbuffer_t *thiz, uint8_t val)
Definition: cbuffer.h:269
bool zrtos_error__is_error(zrtos_error_t thiz)
Definition: error.h:156
void zrtos_cbuffer__start_write_transaction(zrtos_cbuffer_t *thiz, zrtos_cbuffer_write_transaction_t *txn)
Definition: cbuffer.h:146
bool zrtos_error__is_success(zrtos_error_t thiz)
Definition: error.h:152
Successful program execution status.
Definition: error.h:22
static uint8_t
Definition: mcp2515.h:159
zrtos_error_t
Definition: error.h:20
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_cbuffer__rollback_write_transaction()

void zrtos_cbuffer__rollback_write_transaction ( zrtos_cbuffer_t thiz,
zrtos_cbuffer_write_transaction_t txn 
)

Definition at line 154 of file cbuffer.h.

157  {
158  zrtos_cbuffer_node_t *next;
160  node->head = txn->head;
161  while((next = zrtos_cbuffer_node__get_next_node(node))){
163  next
164  ,thiz
165  );
166  }
167 }
zrtos_cbuffer_node_t * zrtos_cbuffer__get_last_node(zrtos_cbuffer_t *thiz)
Definition: cbuffer.h:66
zrtos_cbuffer_node_t * zrtos_cbuffer_node__get_next_node(zrtos_cbuffer_node_t *thiz)
Definition: cbuffer.h:75
void zrtos_cbuffer_node__free(zrtos_cbuffer_node_t *thiz, zrtos_cbuffer_t *ctx)
Definition: cbuffer.h:110
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_cbuffer__start_write_transaction()

void zrtos_cbuffer__start_write_transaction ( zrtos_cbuffer_t thiz,
zrtos_cbuffer_write_transaction_t txn 
)

Definition at line 146 of file cbuffer.h.

149  {
150  txn->thiz = *thiz;
151  txn->head = zrtos_cbuffer__get_last_node(thiz)->head;
152 }
zrtos_cbuffer_node_t * zrtos_cbuffer__get_last_node(zrtos_cbuffer_t *thiz)
Definition: cbuffer.h:66
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_cbuffer_node__free()

void zrtos_cbuffer_node__free ( zrtos_cbuffer_node_t thiz,
zrtos_cbuffer_t ctx 
)

Definition at line 110 of file cbuffer.h.

110  {
111  zrtos_list__delete(&ctx->root,&thiz->node);
113 }
void zrtos_list__delete(zrtos_list_t *thiz, zrtos_list_node_t *node)
Definition: list.h:96
void zrtos_malloc_limit__free(zrtos_malloc_limit_t *thiz, void *ptr)
Definition: malloc_limit.h:41
zrtos_malloc_limit_t zrtos_cbuffer__malloc_limit
Definition: cbuffer.h:55
zrtos_list_node_t node
Definition: cbuffer.h:39
zrtos_list_t root
Definition: cbuffer.h:46
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_cbuffer_node__get()

zrtos_error_t zrtos_cbuffer_node__get ( zrtos_cbuffer_node_t thiz,
zrtos_cbuffer_t ctx,
uint8_t out 
)

Definition at line 213 of file cbuffer.h.

217  {
219  if(!zrtos_cbuffer_node__is_empty(thiz)){
220  *out = thiz->data[thiz->tail++];
221  thiz->tail &= (ZRTOS_CBUFFER__CFG_DATA_LENGTH - 1);
224  zrtos_cbuffer_node__free(thiz,ctx);
225  }
226  }else{
227  ret = ZRTOS_ERROR__AGAIN;
228  }
229  return ret;
230 }
#define ZRTOS_CBUFFER__CFG_DATA_LENGTH
Definition: cbuffer.h:25
Try again.
Definition: error.h:35
bool zrtos_list_node__has_next_node(zrtos_list_node_t *node)
Definition: list.h:45
Successful program execution status.
Definition: error.h:22
bool zrtos_cbuffer_node__is_empty(zrtos_cbuffer_node_t *thiz)
Definition: cbuffer.h:175
uint8_t data[ZRTOS_CBUFFER__CFG_DATA_LENGTH]
Definition: cbuffer.h:40
zrtos_list_node_t node
Definition: cbuffer.h:39
void zrtos_cbuffer_node__free(zrtos_cbuffer_node_t *thiz, zrtos_cbuffer_t *ctx)
Definition: cbuffer.h:110
zrtos_error_t
Definition: error.h:20
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_cbuffer_node__get_free_space()

static size_t zrtos_cbuffer_node__get_free_space ( zrtos_cbuffer_node_t thiz)
static

Definition at line 180 of file cbuffer.h.

182  {
183  return (ZRTOS_CBUFFER__CFG_DATA_LENGTH - 1)
185  ;
186 }
#define ZRTOS_CBUFFER__CFG_DATA_LENGTH
Definition: cbuffer.h:25
static size_t zrtos_cbuffer_node__get_length(zrtos_cbuffer_node_t *thiz)
Definition: cbuffer.h:169
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_cbuffer_node__get_length()

static size_t zrtos_cbuffer_node__get_length ( zrtos_cbuffer_node_t thiz)
static

Definition at line 169 of file cbuffer.h.

171  {
172  return (thiz->head - thiz->tail) & (ZRTOS_CBUFFER__CFG_DATA_LENGTH - 1);
173 }
#define ZRTOS_CBUFFER__CFG_DATA_LENGTH
Definition: cbuffer.h:25
Here is the caller graph for this function:

◆ zrtos_cbuffer_node__get_next_node()

zrtos_cbuffer_node_t* zrtos_cbuffer_node__get_next_node ( zrtos_cbuffer_node_t thiz)

Definition at line 75 of file cbuffer.h.

75  {
79  ,node
80  );
81  return node;
82 }
zrtos_list_node_t * zrtos_list_node__get_next_node(zrtos_list_node_t *node)
Definition: list.h:39
#define zrtos_types__get_container_of(ptr, type, member)
Definition: types.h:69
zrtos_list_node_t node
Definition: cbuffer.h:39
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_cbuffer_node__init()

bool zrtos_cbuffer_node__init ( zrtos_cbuffer_node_t thiz,
zrtos_cbuffer_t ctx 
)

Definition at line 84 of file cbuffer.h.

87  {
89  zrtos_list__push(&ctx->root,&thiz->node);
90  thiz->head = 0;
91  thiz->tail = 0;
92  return true;
93 }
bool zrtos_list_node__init(zrtos_list_node_t *thiz)
Definition: list.h:34
bool zrtos_list__push(zrtos_list_t *thiz, zrtos_list_node_t *node)
Definition: list.h:57
zrtos_list_node_t node
Definition: cbuffer.h:39
zrtos_list_t root
Definition: cbuffer.h:46
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_cbuffer_node__is_empty()

bool zrtos_cbuffer_node__is_empty ( zrtos_cbuffer_node_t thiz)

Definition at line 175 of file cbuffer.h.

175  {
176  //return zrtos_cbuffer_node__get_length(thiz) == 0;
177  return thiz->head == thiz->tail;
178 }
Here is the caller graph for this function:

◆ zrtos_cbuffer_node__new()

zrtos_cbuffer_node_t* zrtos_cbuffer_node__new ( zrtos_cbuffer_t ctx)

Definition at line 95 of file cbuffer.h.

95  {
100  ,sizeof(zrtos_cbuffer_node_t)
102  )
103  );
104  if(ret){
105  zrtos_cbuffer_node__init(ret,ctx);
106  }
107  return ret;
108 }
#define ZRTOS_CAST(type, value)
Definition: cast.h:18
bool zrtos_cbuffer_node__init(zrtos_cbuffer_node_t *thiz, zrtos_cbuffer_t *ctx)
Definition: cbuffer.h:84
zrtos_malloc_limit_t zrtos_cbuffer__malloc_limit
Definition: cbuffer.h:55
#define ZRTOS_CBUFFER__CFG_MALLOC_LIMIT
Definition: cbuffer.h:29
void * zrtos_malloc_limit__malloc(zrtos_malloc_limit_t *thiz, size_t length, size_t limit)
Definition: malloc_limit.h:25
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_cbuffer_node__peek()

zrtos_error_t zrtos_cbuffer_node__peek ( zrtos_cbuffer_node_t thiz,
uint8_t out 
)

Definition at line 232 of file cbuffer.h.

235  {
237  if(!zrtos_cbuffer_node__is_empty(thiz)){
238  *out = thiz->data[thiz->tail];
239  }else{
240  ret = ZRTOS_ERROR__AGAIN;
241  }
242  return ret;
243 }
Try again.
Definition: error.h:35
Successful program execution status.
Definition: error.h:22
bool zrtos_cbuffer_node__is_empty(zrtos_cbuffer_node_t *thiz)
Definition: cbuffer.h:175
uint8_t data[ZRTOS_CBUFFER__CFG_DATA_LENGTH]
Definition: cbuffer.h:40
zrtos_error_t
Definition: error.h:20
Here is the call graph for this function:
Here is the caller graph for this function:

◆ zrtos_cbuffer_node__put()

zrtos_error_t zrtos_cbuffer_node__put ( zrtos_cbuffer_node_t thiz,
zrtos_cbuffer_t ctx,
uint8_t  val 
)

Definition at line 188 of file cbuffer.h.

192  {
194 
195  if(zrtos_cbuffer_node__get_free_space(thiz) >= 1){
196  thiz->data[thiz->head++] = val;
197  thiz->head &= (ZRTOS_CBUFFER__CFG_DATA_LENGTH - 1);
198  }else{
200  if(node){
202  node
203  ,ctx
204  ,val
205  );
206  }else{
207  ret = ZRTOS_ERROR__NOMEM;
208  }
209  }
210  return ret;
211 }
#define ZRTOS_CBUFFER__CFG_DATA_LENGTH
Definition: cbuffer.h:25
zrtos_cbuffer_node_t * zrtos_cbuffer_node__new(zrtos_cbuffer_t *ctx)
Definition: cbuffer.h:95
Successful program execution status.
Definition: error.h:22
static size_t zrtos_cbuffer_node__get_free_space(zrtos_cbuffer_node_t *thiz)
Definition: cbuffer.h:180
uint8_t data[ZRTOS_CBUFFER__CFG_DATA_LENGTH]
Definition: cbuffer.h:40
Out of memory.
Definition: error.h:36
zrtos_error_t zrtos_cbuffer_node__put(zrtos_cbuffer_node_t *thiz, zrtos_cbuffer_t *ctx, uint8_t val)
Definition: cbuffer.h:188
zrtos_error_t
Definition: error.h:20
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ zrtos_cbuffer__malloc_limit

zrtos_malloc_limit_t zrtos_cbuffer__malloc_limit = ZRTOS_MALLOC_LIMIT__INIT()
Todo:
mutex lock zrtos_cbuffer__malloc_limit

Definition at line 55 of file cbuffer.h.