21 lines
901 B
C
21 lines
901 B
C
// SPDX-License-Identifier: MPL-2.0
|
|
#ifndef SH_LIB_RING_H
|
|
#define SH_LIB_RING_H
|
|
#include "std/type.h"
|
|
#include "std/status.h"
|
|
// Ring buffer header structure
|
|
typedef struct {
|
|
sh_uint32 head;
|
|
sh_uint32 tail;
|
|
sh_uint32 buffer_bytes_size;
|
|
sh_uint8* data_start;
|
|
sh_uint64 total_bytes_written;
|
|
} sh_ring_RING_BUFFER_HEADER;
|
|
// Write a byte into the provided ring buffer
|
|
SH_STATUS sh_ring_write_byte(sh_ring_RING_BUFFER_HEADER *ring_buffer,sh_uint8 byte);
|
|
// Write a null terminated string into the provided ring buffer
|
|
SH_STATUS sh_ring_write_string(sh_ring_RING_BUFFER_HEADER *ring_buffer,char *string);
|
|
// Read bytes_count from the provided ring buffer, and put it into output. Return SH_STATUS_TOO_MUCH_DATA if bytes_count>buf.buffer_size_bytes, setting the entire buffer to 0x00
|
|
SH_STATUS sh_ring_read_bytes(sh_ring_RING_BUFFER_HEADER *ring_buffer,sh_uint32 bytes_count,void *output);
|
|
#endif
|