Skip to content

Commit 23d2a99

Browse files
committed
Make csp_buffer_get_always() internal
csp_buffer_get_always() is used in critical execution paths where a buffer must be allocated or the mission fails. It’s not intended as a general-purpose convenience function. This change hides it within libcsp, removing it from the public API. Signed-off-by: Yasushi SHOJI <[email protected]>
1 parent 948334a commit 23d2a99

File tree

8 files changed

+43
-32
lines changed

8 files changed

+43
-32
lines changed

doc/api/csp_buffer_h.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,3 @@ Interface Functions
1515
.. autocfunction:: csp_buffer.h::csp_buffer_remaining
1616
.. autocfunction:: csp_buffer.h::csp_buffer_init
1717
.. autocfunction:: csp_buffer.h::csp_buffer_refc_inc
18-
.. autocfunction:: csp_buffer.h::csp_buffer_get_always
19-
.. autocfunction:: csp_buffer.h::csp_buffer_get_always_isr

include/csp/csp_buffer.h

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,6 @@
1111
extern "C" {
1212
#endif
1313

14-
/**
15-
* Number of buffers reserved by CSP for fault-tolerant operations.
16-
*
17-
* These reserved buffers are used for operations that can tolerate allocation failure,
18-
* such as client requests with proper error handling, or services that may timeout
19-
* safely when memory is low.
20-
*/
21-
#define CSP_BUFFER_RESERVE 2
22-
2314
/**
2415
* Get free buffer from task context.
2516
*
@@ -28,20 +19,6 @@ extern "C" {
2819
*/
2920
csp_packet_t * csp_buffer_get(size_t unused);
3021

31-
/**
32-
* Get a buffer or get killed (from task context)
33-
*
34-
* This function return a buffer or kill the whole program when it
35-
* failed. DO NOT USE THIS FUNCTION if you don't know what you are
36-
* doing. Never use this function from application layer. This
37-
* function should be an internal function and will be sonn.
38-
*
39-
* https://github.com/libcsp/libcsp/issues/864
40-
*
41-
* @return Buffer (pointer to #csp_packet_t)
42-
*/
43-
csp_packet_t * csp_buffer_get_always(void);
44-
4522
/**
4623
* Get free buffer (from ISR context).
4724
*
@@ -50,12 +27,6 @@ csp_packet_t * csp_buffer_get_always(void);
5027
*/
5128
csp_packet_t * csp_buffer_get_isr(size_t unused);
5229

53-
/**
54-
* Get a buffer or get killed (from ISR context)
55-
* @return Buffer (pointer to #csp_packet_t)
56-
*/
57-
csp_packet_t * csp_buffer_get_always_isr(void);
58-
5930
/**
6031
* Free buffer (from task context).
6132
*

src/csp_buffer.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@
88
#include <csp/csp_hooks.h>
99
#include <csp/csp_id.h>
1010

11+
#include "csp_buffer_private.h"
12+
13+
/**
14+
* Number of buffers reserved by CSP for fault-tolerant operations.
15+
*
16+
* These reserved buffers are used for operations that can tolerate allocation failure,
17+
* such as client requests with proper error handling, or services that may timeout
18+
* safely when memory is low.
19+
*/
20+
#define CSP_BUFFER_RESERVE 2
21+
1122
/** Internal buffer header */
1223
typedef struct csp_skbf_s {
1324
unsigned int refcount;

src/csp_buffer_private.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#pragma once
2+
3+
#include <csp/csp_types.h>
4+
5+
/**
6+
* Get a buffer or get killed (from task context)
7+
*
8+
* This function return a buffer or kill the whole program when it
9+
* failed. DO NOT USE THIS FUNCTION if you don't know what you are
10+
* doing. Never use this function from application layer. It is
11+
* intended for internal use only and must not be used from
12+
* application-level code.
13+
*
14+
* https://github.com/libcsp/libcsp/issues/864
15+
*
16+
* @return Buffer (pointer to #csp_packet_t)
17+
*/
18+
csp_packet_t * csp_buffer_get_always(void);
19+
20+
/**
21+
* Get a buffer or get killed (from ISR context)
22+
* @return Buffer (pointer to #csp_packet_t)
23+
*/
24+
csp_packet_t * csp_buffer_get_always_isr(void);

src/interfaces/csp_if_can_pbuf.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <csp/arch/csp_time.h>
88
#include <csp/interfaces/csp_if_can.h>
99

10+
#include "../csp_buffer_private.h"
11+
1012
/* Buffer element timeout in ms */
1113
#define PBUF_TIMEOUT_MS 1000
1214

src/interfaces/csp_if_kiss.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <csp/csp_crc32.h>
1515
#include <csp/csp_id.h>
1616

17+
#include "../csp_buffer_private.h"
18+
1719
#define FEND 0xC0
1820
#define FESC 0xDB
1921
#define TFEND 0xDC

unittests/buffer.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include "../include/csp/csp.h"
33
#include "../include/csp/csp_id.h"
44

5+
#include "../src/csp_buffer_private.h"
6+
57
#define CSP_ID2_HEADER_SIZE 6
68

79
/* https://github.com/libcsp/libcsp/issues/734 */
@@ -42,7 +44,7 @@ START_TEST(test_clone_frame_begin_fixed)
4244
/* Simulate a packet with no header*/
4345
memcpy(src->data, "hello", 6);
4446
src->length = 6;
45-
47+
4648
/* Add header to simulate a prepared to send packet */
4749
csp_id_prepend(src);
4850

unittests/hmac.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "../include/csp/csp.h"
33
#include "../include/csp/csp_id.h"
44
#include "../include/csp/crypto/csp_hmac.h"
5+
#include "../src/csp_buffer_private.h"
56

67
START_TEST(test_hmac_append_no_header)
78
{

0 commit comments

Comments
 (0)