Skip to content

Commit 77b2bdb

Browse files
committed
Merge branch 'develop'
2 parents 1aea601 + 2b53a83 commit 77b2bdb

File tree

11 files changed

+194
-137
lines changed

11 files changed

+194
-137
lines changed

.clang-format

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ ObjCBlockIndentWidth: 2
122122
ObjCBreakBeforeNestedBlockParam: true
123123
ObjCSpaceAfterProperty: false
124124
ObjCSpaceBeforeProtocolList: true
125-
PenaltyBreakAssignment: 2
126-
PenaltyBreakBeforeFirstCallParameter: 19
125+
PenaltyBreakAssignment: 50
126+
PenaltyBreakBeforeFirstCallParameter: 9
127127
PenaltyBreakComment: 300
128128
PenaltyBreakFirstLessLess: 120
129129
PenaltyBreakOpenParenthesis: 0

AUTHORS

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Tilen Majerle <[email protected]>
2+
Tofik Sonono <[email protected]>
3+
Jackistang <[email protected]>
24
Tilen Majerle <[email protected]>
3-
Jaedeok Kim <[email protected]>
4-
Thomas Devoogdt <[email protected]>
5-
LinJieqiang <[email protected]>
6-
75
Junde Yhi <[email protected]>
8-
Jackistang <[email protected]>
9-
Tofik Sonono <[email protected]>
6+
7+
LinJieqiang <[email protected]>
8+
Thomas Devoogdt <[email protected]>
9+
Jaedeok Kim <[email protected]>

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## Develop
44

5+
## v3.2.0
6+
7+
- Add user argument option
8+
- Improve the variable names to better conform *LLVM* tidy config
9+
510
## v3.1.0
611

712
- Preparation for `v3.1`
@@ -17,7 +22,7 @@
1722
- Add `lwrb_move` and `lwrb_overwrite`
1823
- Fix `lwrb_find` which failed to properly search for tokens at corner cases
1924

20-
## v3.1.0-RC1
25+
## v3.0.0-RC1
2126

2227
- Split CMakeLists.txt files between library and executable
2328
- Change license year to 2022

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023 Tilen MAJERLE
3+
Copyright (c) 2024 Tilen MAJERLE
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

dev/main.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ main() {
3636

3737
#define RW_TEST(_w_exp_, _r_exp_, _rw_len_, _rw_exp_len_) \
3838
do { \
39-
printf("W ptr: %u, R ptr: %u, R/W len: %u, as_expected: %u\r\n", (unsigned)buff.w, (unsigned)buff.r, \
39+
printf("W ptr: %u, R ptr: %u, R/W len: %u, as_expected: %u\r\n", (unsigned)buff.w_ptr, (unsigned)buff.r_ptr, \
4040
(unsigned)(_rw_len_), \
41-
(unsigned)(buff.w == (_w_exp_) && buff.r == (_r_exp_) && (_rw_len_) == (_rw_exp_len_))); \
41+
(unsigned)(buff.w_ptr == (_w_exp_) && buff.r_ptr == (_r_exp_) && (_rw_len_) == (_rw_exp_len_))); \
4242
} while (0)
4343

4444
lwrb_reset(&buff);
@@ -65,9 +65,9 @@ main() {
6565

6666
#define RW_TEST(_w_exp_, _r_exp_, _success_, _rw_len_, _rw_exp_len_) \
6767
do { \
68-
printf("W ptr: %u, R ptr: %u, R/W success: %u, R/W len: %u, as_expected: %u\r\n", (unsigned)buff.w, \
69-
(unsigned)buff.r, (unsigned)(_success_), (unsigned)(_rw_len_), \
70-
(unsigned)(buff.w == (_w_exp_) && buff.r == (_r_exp_) && (_rw_len_) == (_rw_exp_len_))); \
68+
printf("W ptr: %u, R ptr: %u, R/W success: %u, R/W len: %u, as_expected: %u\r\n", (unsigned)buff.w_ptr, \
69+
(unsigned)buff.r_ptr, (unsigned)(_success_), (unsigned)(_rw_len_), \
70+
(unsigned)(buff.w_ptr == (_w_exp_) && buff.r_ptr == (_r_exp_) && (_rw_len_) == (_rw_exp_len_))); \
7171
} while (0)
7272

7373
lwrb_reset(&buff);
@@ -190,8 +190,8 @@ main() {
190190
FIND_TEST("678", 3, 0, 1);
191191

192192
/* Restart by setting write and read as empty with offset */
193-
buff.w = 6;
194-
buff.r = 6;
193+
buff.w_ptr = 6;
194+
buff.r_ptr = 6;
195195
lwrb_write(&buff, "12345678", 8);
196196

197197
FIND_TEST("123", 3, 0, 1); /* Must find it */
@@ -200,8 +200,8 @@ main() {
200200

201201
/* Restart by setting write and read as empty with offset */
202202
/* This should generate data for search in overflow mode */
203-
buff.w = 8;
204-
buff.r = 8;
203+
buff.w_ptr = 8;
204+
buff.r_ptr = 8;
205205
lwrb_write(&buff, "12345678", 8);
206206

207207
FIND_TEST("1234", 3, 0, 1); /* Must find it */

docs/get-started/index.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,22 @@ Update cloned to latest version
5757
Add library to project
5858
^^^^^^^^^^^^^^^^^^^^^^
5959

60-
At this point it is assumed that you have successfully download library, either cloned it or from releases page.
60+
At this point it is assumed that you have successfully download library, either with ``git clone`` command or with manual download from the library releases page.
6161
Next step is to add the library to the project, by means of source files to compiler inputs and header files in search path.
6262

6363
*CMake* is the main supported build system. Package comes with the ``CMakeLists.txt`` and ``library.cmake`` files, both located in the ``lwrb`` directory:
6464

65-
* ``CMakeLists.txt``: Is a wrapper and only includes ``library.cmake`` file. It is used if target application uses ``add_subdirectory`` and then uses ``target_link_libraries`` to include the library in the project
66-
* ``library.cmake``: It is a fully configured set of variables. User must use ``include(path/to/library.cmake)`` to include the library and must manually add files/includes to the final target
65+
* ``library.cmake``: It is a fully configured set of variables and with library definition. User can include this file to the project file with ``include(path/to/library.cmake)`` and then manually use the variables provided by the file, such as list of source files, include paths or necessary compiler definitions. It is up to the user to properly use the this file on its own.
66+
* ``CMakeLists.txt``: It is a wrapper-only file and includes ``library.cmake`` file. It is used for when user wants to include the library to the main project by simply calling ``add_subdirectory`` **CMake** command, followed by ``target_link_libraries`` to add library as an external library.
6767

6868
.. tip::
69-
Open ``library.cmake`` file and manually analyze all the possible variables you can set for full functionality.
69+
Open ``library.cmake`` and analyze the provided information. Among variables, you can also find list of all possible exposed libraries for the user.
7070

7171
If you do not use the *CMake*, you can do the following:
7272

7373
* Copy ``lwrb`` folder to your project, it contains library files
7474
* Add ``lwrb/src/include`` folder to `include path` of your toolchain. This is where `C/C++` compiler can find the files during compilation process. Usually using ``-I`` flag
75-
* Add source files from ``lwrb/src/`` folder to toolchain build. These files are built by `C/C++` compiler. CMake configuration comes with the library, allows users to include library in the project as **subdirectory** and **library**.y
75+
* Add source files from ``lwrb/src/`` folder to toolchain build. These files are built by `C/C++` compilery
7676
* Build the project
7777

7878
Minimal example code

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "LwRB",
3-
"version": "3.1.0",
3+
"version": "3.2.0",
44
"description": "Lightweight general purpose ring buffer with optimizations for embedded systems",
55
"keywords": "buffer, ring buffer, library, rb, cyclic",
66
"repository": {

lwrb/library.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#
2+
# LIB_PREFIX: LWRB
3+
#
24
# This file provides set of variables for end user
35
# and also generates one (or more) libraries, that can be added to the project using target_link_libraries(...)
46
#
@@ -8,6 +10,9 @@
810
# LWRB_COMPILE_DEFINITIONS: If defined, it provides "-D" definitions to the library build
911
#
1012

13+
# Custom include directory
14+
set(LWRB_CUSTOM_INC_DIR ${CMAKE_CURRENT_BINARY_DIR}/lib_inc)
15+
1116
# Library core sources
1217
set(lwrb_core_SRCS
1318
${CMAKE_CURRENT_LIST_DIR}/src/lwrb/lwrb.c
@@ -21,6 +26,7 @@ set(lwrb_ex_SRCS
2126
# Setup include directories
2227
set(lwrb_include_DIRS
2328
${CMAKE_CURRENT_LIST_DIR}/src/include
29+
${LWPKT_CUSTOM_INC_DIR}
2430
)
2531

2632
# Register library to the system

lwrb/src/include/lwrb/lwrb.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
/*
7-
* Copyright (c) 2023 Tilen MAJERLE
7+
* Copyright (c) 2024 Tilen MAJERLE
88
*
99
* Permission is hereby granted, free of charge, to any person
1010
* obtaining a copy of this software and associated documentation
@@ -29,7 +29,7 @@
2929
* This file is part of LwRB - Lightweight ring buffer library.
3030
*
3131
* Author: Tilen MAJERLE <[email protected]>
32-
* Version: v3.1.0
32+
* Version: v3.2.0
3333
*/
3434
#ifndef LWRB_HDR_H
3535
#define LWRB_HDR_H
@@ -99,25 +99,30 @@ typedef void (*lwrb_evt_fn)(struct lwrb* buff, lwrb_evt_type_t evt, lwrb_sz_t bp
9999
typedef struct lwrb {
100100
uint8_t* buff; /*!< Pointer to buffer data. Buffer is considered initialized when `buff != NULL` and `size > 0` */
101101
lwrb_sz_t size; /*!< Size of buffer data. Size of actual buffer is `1` byte less than value holds */
102-
lwrb_sz_atomic_t r; /*!< Next read pointer. Buffer is considered empty when `r == w` and full when `w == r - 1` */
103-
lwrb_sz_atomic_t w; /*!< Next write pointer. Buffer is considered empty when `r == w` and full when `w == r - 1` */
104-
lwrb_evt_fn evt_fn; /*!< Pointer to event callback function */
102+
lwrb_sz_atomic_t r_ptr; /*!< Next read pointer.
103+
Buffer is considered empty when `r == w` and full when `w == r - 1` */
104+
lwrb_sz_atomic_t w_ptr; /*!< Next write pointer.
105+
Buffer is considered empty when `r == w` and full when `w == r - 1` */
106+
lwrb_evt_fn evt_fn; /*!< Pointer to event callback function */
107+
void* arg; /*!< Event custom user argument */
105108
} lwrb_t;
106109

107110
uint8_t lwrb_init(lwrb_t* buff, void* buffdata, lwrb_sz_t size);
108111
uint8_t lwrb_is_ready(lwrb_t* buff);
109112
void lwrb_free(lwrb_t* buff);
110113
void lwrb_reset(lwrb_t* buff);
111114
void lwrb_set_evt_fn(lwrb_t* buff, lwrb_evt_fn fn);
115+
void lwrb_set_arg(lwrb_t* buff, void* arg);
116+
void* lwrb_get_arg(lwrb_t* buff);
112117

113118
/* Read/Write functions */
114119
lwrb_sz_t lwrb_write(lwrb_t* buff, const void* data, lwrb_sz_t btw);
115120
lwrb_sz_t lwrb_read(lwrb_t* buff, void* data, lwrb_sz_t btr);
116121
lwrb_sz_t lwrb_peek(const lwrb_t* buff, lwrb_sz_t skip_count, void* data, lwrb_sz_t btp);
117122

118123
/* Extended read/write functions */
119-
uint8_t lwrb_write_ex(lwrb_t* buff, const void* data, lwrb_sz_t btw, lwrb_sz_t* bw, uint16_t flags);
120-
uint8_t lwrb_read_ex(lwrb_t* buff, void* data, lwrb_sz_t btr, lwrb_sz_t* br, uint16_t flags);
124+
uint8_t lwrb_write_ex(lwrb_t* buff, const void* data, lwrb_sz_t btw, lwrb_sz_t* bwritten, uint16_t flags);
125+
uint8_t lwrb_read_ex(lwrb_t* buff, void* data, lwrb_sz_t btr, lwrb_sz_t* bread, uint16_t flags);
121126

122127
/* Buffer size information */
123128
lwrb_sz_t lwrb_get_free(const lwrb_t* buff);

0 commit comments

Comments
 (0)