Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 40 additions & 43 deletions include/param/param.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include <stdint.h>
#include <csp/csp_types.h>
#include <vmem/vmem.h>

#include <libparam.h>

Expand Down Expand Up @@ -90,37 +89,36 @@ typedef enum {
/**
* Parameter description structure
* Note: this is not packed in order to maximise run-time efficiency
* But the order of the elements is chosen to minimize padding.
* So we start by largest types first, down to smallest types.
*/
typedef struct param_s {

uint64_t vaddr; /* Virtual address in case of VMEM */

/* Parameter declaration */
uint16_t id;
uint16_t * node;
param_type_e type;
uint32_t mask;
char *name;
char *unit;
char *docstr;

/* Storage */
void * addr; /* Physical address */
uint64_t vaddr; /* Virtual address in case of VMEM */
struct vmem_s * vmem;
int array_size;
int array_step;
const struct vmem_s * vmem;
void (*callback)(const struct param_s * param, int offset);

/* Local info */
void (*callback)(struct param_s * param, int offset);
#ifdef PARAM_HAVE_TIMESTAMP
#ifdef PARAM_HAVE_TIMESTAMP
csp_timestamp_t * timestamp;
#endif

#ifdef PARAM_HAVE_SYS_QUEUE
#endif
#ifdef PARAM_HAVE_SYS_QUEUE
/* single linked list:
* The weird definition format comes from sys/queue.h SLINST_ENTRY() macro */
* The weird definition format comes from sys/queue.h SLINST_ENTRY() macro */
struct { struct param_s *sle_next; } next;
#endif
#endif

uint32_t mask;
uint16_t id;
uint16_t array_step; // Deliberate use of 16-bit to balance speed and size
uint16_t array_size; // Deliberate use of 16-bit to balance speed and size
uint16_t type; // Deliberate use of 16-bit to balance speed and size

} param_t;

Expand Down Expand Up @@ -149,16 +147,16 @@ typedef struct param_s {
#define PARAM_TIMESTAMP_INIT(_name)
#endif

static const uint16_t node_self = 0;

#define PARAM_DEFINE_STATIC_RAM(_id, _name, _type, _array_count, _array_step, _flags, _callback, _unit, _physaddr, _docstr) \
; /* Catch const param defines */ \
PARAM_TIMESTAMP_DECL(_name) \
uint16_t _node_##_name = 0; \
__attribute__((section("param"))) \
__attribute__((used, no_reorder)) \
param_t _name = { \
__attribute__((used, aligned(8))) \
const param_t _name = { \
.vmem = NULL, \
.node = &_node_##_name, \
.node = (uint16_t *) &node_self, \
.id = _id, \
.type = _type, \
.name = #_name, \
Expand All @@ -176,11 +174,10 @@ typedef struct param_s {
#define PARAM_DEFINE_STATIC_VMEM(_id, _name, _type, _array_count, _array_step, _flags, _callback, _unit, _vmem_name, _vmem_addr, _docstr) \
; /* Catch const param defines */ \
PARAM_TIMESTAMP_DECL(_name) \
uint16_t _node_##_name = 0; \
__attribute__((section("param"))) \
__attribute__((used, no_reorder)) \
param_t _name = { \
.node = &_node_##_name, \
__attribute__((used, aligned(8))) \
const param_t _name = { \
.node = (uint16_t *) &node_self, \
.id = _id, \
.type = _type, \
.name = #_name, \
Expand All @@ -202,8 +199,8 @@ typedef struct param_s {
; /* Catch const param defines */ \
PARAM_TIMESTAMP_DECL(_name) \
__attribute__((section("param"))) \
__attribute__((used, no_reorder)) \
param_t _name = { \
__attribute__((used, aligned(8))) \
const param_t _name = { \
.node = _nodeaddr, \
.id = _id, \
.type = _type, \
Expand Down Expand Up @@ -239,8 +236,8 @@ typedef struct param_s {

/* Native getter functions, will return native types */
#define PARAM_GET(type, name) \
type param_get_##name(param_t * param); \
type param_get_##name##_array(param_t * param, unsigned int i);
type param_get_##name(const param_t * param); \
type param_get_##name##_array(const param_t * param, unsigned int i);
PARAM_GET(uint8_t, uint8)
PARAM_GET(uint16_t, uint16)
PARAM_GET(uint32_t, uint32)
Expand All @@ -255,10 +252,10 @@ PARAM_GET(double, double)

/* Native setter functions, these take a native type as argument */
#define PARAM_SET(type, name) \
void param_set_##name(param_t * param, type value); \
void param_set_##name##_nocallback(param_t * param, type value); \
void param_set_##name##_array(param_t * param, unsigned int i, type value); \
void param_set_##name##_array_nocallback(param_t * param, unsigned int i, type value);
void param_set_##name(const param_t * param, type value); \
void param_set_##name##_nocallback(const param_t * param, type value); \
void param_set_##name##_array(const param_t * param, unsigned int i, type value); \
void param_set_##name##_array_nocallback(const param_t * param, unsigned int i, type value);
PARAM_SET(uint8_t, uint8)
PARAM_SET(uint16_t, uint16)
PARAM_SET(uint32_t, uint32)
Expand All @@ -272,24 +269,24 @@ PARAM_SET(double, double)
#undef PARAM_SET

/* Non-native types needs to go through a function which includes a void pointer and the length */
void param_set_data(param_t * param, const void * inbuf, int len);
void param_set_data_nocallback(param_t * param, const void * inbuf, int len);
void param_get_data(param_t * param, void * outbuf, int len);
void param_set_string(param_t * param, const char * inbuf, int len);
void param_set_data(const param_t * param, const void * inbuf, int len);
void param_set_data_nocallback(const param_t * param, const void * inbuf, int len);
void param_get_data(const param_t * param, void * outbuf, int len);
void param_set_string(const param_t * param, const char * inbuf, int len);
#define param_get_string param_get_data

/* Generic setter function:
* This function can be used to set data of any type
*/
void param_set(param_t * param, unsigned int offset, void * value);
void param_get(param_t * param, unsigned int offset, void * value);
void param_set(const param_t * param, unsigned int offset, void * value);
void param_get(const param_t * param, unsigned int offset, void * value);

/* Returns the size of a native type */
int param_typesize(param_type_e type);
int param_size(param_t * param);
int param_size(const param_t * param);

/* Copies from one parameter to another */
void param_copy(param_t * dest, param_t * src);
void param_copy(const param_t * dest, const param_t * src);

/* External hooks to get atomic writes */
extern __attribute__((weak)) void param_enter_critical(void);
Expand Down
4 changes: 2 additions & 2 deletions include/param/param_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* @param version 1 or 2
* @return 0 = ok, -1 on network error
*/
int param_pull_single(param_t *param, int offset, int prio, int verbose, int host, int timeout, int version);
int param_pull_single(const param_t *param, int offset, int prio, int verbose, int host, int timeout, int version);

/**
* PULL all
Expand Down Expand Up @@ -65,7 +65,7 @@ int param_pull_all(int prio, int verbose, int host, uint32_t include_mask, uint3
* @param ack_with_pull ack with param queue
* @return 0 = OK, -1 on network error
*/
int param_push_single(param_t *param, int offset, int prio, void *value, int verbose, int host, int timeout, int version, bool ack_with_pull);
int param_push_single(const param_t *param, int offset, int prio, void *value, int verbose, int host, int timeout, int version, bool ack_with_pull);

/**
* QUEUE PARAMETER API
Expand Down
16 changes: 8 additions & 8 deletions include/param/param_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ extern "C" {

typedef struct param_list_iterator_s {
int phase; // Hybrid iterator has multiple phases (0 == Static, 1 == Dynamic List)
param_t * element;
const param_t * element;
} param_list_iterator;

param_t * param_list_iterate(param_list_iterator * iterator);
const param_t * param_list_iterate(param_list_iterator * iterator);

int param_list_add(param_t * item);

Expand All @@ -40,13 +40,13 @@ int param_list_remove(int node, uint8_t verbose);
* @param verbose Whether to print the removed parameter.
* @return int 1 if the parameter was found and removed.
*/
void param_list_remove_specific(param_t * param, uint8_t verbose, int destroy);
param_t * param_list_find_id(int node, int id);
param_t * param_list_find_name(int node, const char * name);
void param_list_remove_specific(const param_t * param, uint8_t verbose, int destroy);
const param_t * param_list_find_id(int node, int id);
const param_t * param_list_find_name(int node, const char * name);
void param_list_print(uint32_t mask, int node, const char * globstr, int verbosity);
uint32_t param_maskstr_to_mask(const char * str);

param_t * param_list_from_line(const char * line);
const param_t * param_list_from_line(const char * line);

/**
* @brief
Expand All @@ -64,8 +64,8 @@ param_t * param_list_from_line(const char * line);
*/
param_t * param_list_create_remote(int id, int node, int type, uint32_t mask, int array_size, char * name, char * unit, char * help, int storage_type);

void param_list_destroy(param_t * param);
void param_print(param_t * param, int offset, int nodes[], int nodes_count, int verbose, uint32_t ref_timestamp);
void param_list_destroy(const param_t * param);
void param_print(const param_t * param, int offset, int nodes[], int nodes_count, int verbose, uint32_t ref_timestamp);

unsigned int param_list_packed_size(int list_version);
int param_list_unpack(int node, void * data, int length, int list_version, int include_remotes);
Expand Down
2 changes: 1 addition & 1 deletion include/param/param_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ typedef struct param_queue_s {

void param_queue_init(param_queue_t * queue, void * buffer, int buffer_size, int used, param_queue_type_e type, int version);

int param_queue_add(param_queue_t *queue, param_t *param, int offset, void *value);
int param_queue_add(param_queue_t *queue, const param_t *param, int offset, void *value);

/**
* @brief Applies the content of a queue to memory.
Expand Down
6 changes: 3 additions & 3 deletions include/param/param_serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
#include <csp/csp.h>
#include <mpack/mpack.h>

void param_serialize_id(mpack_writer_t *writer, param_t * param, int offset, param_queue_t * queue);
void param_serialize_id(mpack_writer_t *writer, const param_t * param, int offset, param_queue_t * queue);
void param_deserialize_id(mpack_reader_t *reader, int *id, int *node, csp_timestamp_t *timestamp, int *offset, param_queue_t * queue);

int param_serialize_to_mpack(param_t * param, int offset, mpack_writer_t * writer, void * value, param_queue_t * queue);
void param_deserialize_from_mpack_to_param(void * context, void * queue, param_t * param, int offset, mpack_reader_t * reader);
int param_serialize_to_mpack(const param_t * param, int offset, mpack_writer_t * writer, void * value, param_queue_t * queue);
void param_deserialize_from_mpack_to_param(void * context, void * queue, const param_t * param, int offset, mpack_reader_t * reader);

#endif /* SRC_PARAM_PARAM_SERIALIZER_H_ */
39 changes: 0 additions & 39 deletions include/param/param_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,42 +74,3 @@ typedef enum {
* @param packet
*/
void param_serve(csp_packet_t * packet);

#if PARAM_NUM_PUBLISHQUEUES > 4
#error A maximum number of four param queues are supported
#endif

#if PARAM_NUM_PUBLISHQUEUES > 0
typedef struct param_publish_s {
param_t * param;
uint32_t queue;
} param_publish_t;

typedef enum {
PARAM_PUBLISHQUEUE_0 = 0,
#if PARAM_NUM_PUBLISHQUEUES >= 2
PARAM_PUBLISHQUEUE_1 = 1,
#endif
#if PARAM_NUM_PUBLISHQUEUES >= 3
PARAM_PUBLISHQUEUE_2 = 2,
#endif
#if PARAM_NUM_PUBLISHQUEUES >= 4
PARAM_PUBLISHQUEUE_3 = 3,
#endif
} param_publish_id_t;

#define PARAM_ADD_PUBLISH(paramname, queueid) \
param_publish_t __param_publish_##paramname##queueid = { \
.param = &paramname, \
.queue = queueid, \
}; \
__attribute__((section("param_publish"))) \
param_publish_t const * _param_publish_##paramname##queueid = & __param_publish_##paramname##queueid;

typedef bool (*param_shall_publish_t)(uint8_t queue);

void param_publish_periodic(void);
void param_publish_configure(param_publish_id_t queueid, uint16_t destination, uint16_t periodicity_ms, csp_prio_t csp_prio);
void param_publish_init(param_shall_publish_t criteria_cb);

#endif
4 changes: 2 additions & 2 deletions include/param/param_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

#include <param/param.h>

void param_value_str(param_t *param, unsigned int i, char * out, int len);
void param_value_str(const param_t *param, unsigned int i, char * out, int len);
int param_str_to_value(param_type_e type, char * in, void * out);
void param_type_str(param_type_e type, char * out, int len);
void param_print(param_t * param, int offset, int nodes[], int nodes_count, int verbose, uint32_t ref_timestamp);
void param_print(const param_t * param, int offset, int nodes[], int nodes_count, int verbose, uint32_t ref_timestamp);
uint32_t param_maskstr_to_mask(const char * str);
uint32_t param_umaskstr_to_mask(const char * str);
uint32_t param_typestr_to_typeid(const char * str);
Expand Down
15 changes: 3 additions & 12 deletions include/vmem/vmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ enum vmem_types{

typedef struct vmem_s {
int type;
void (*read)(struct vmem_s * vmem, uint64_t addr, void * dataout, uint32_t len);
void (*write)(struct vmem_s * vmem, uint64_t addr, const void * datain, uint32_t len);
int (*flush)(struct vmem_s * vmem);
void (*read)(const struct vmem_s * vmem, uint64_t addr, void * dataout, uint32_t len);
void (*write)(const struct vmem_s * vmem, uint64_t addr, const void * datain, uint32_t len);
int (*flush)(const struct vmem_s * vmem);
/* This anonymous union is needed to be able to handle 64-bit and 32-bit
* systems interchangeably. Since the VMEM backend always expects 64-bit
* vaddr, and we are not able to initialize the 64-bit vaddr field with
Expand Down Expand Up @@ -149,15 +149,6 @@ int vmem_flush(vmem_t *vmem);
*/
void vmem_add(vmem_t * start, vmem_t * stop);

/**
* @brief linker-generated symbol for the first VMEM element in the linker "vmem" section
*/
extern vmem_t __start_vmem __attribute__((weak));
/**
* @brief linker-generated symbol for the last VMEM element in the linker "vmem" section
*/
extern vmem_t __stop_vmem __attribute__((weak));

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions include/vmem/vmem_block.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ typedef struct vmem_block_region_s {
.options = options_in, \
}; \
__attribute__((section("vmem"))) \
__attribute__((__aligned__(__alignof__(vmem_t)))) \
__attribute__((__aligned__(8))) \
__attribute__((used)) \
vmem_t vmem_##name_in = { \
const vmem_t vmem_##name_in = { \
.type = VMEM_TYPE_BLOCK, \
.read = vmem_block_read, \
.write = vmem_block_write, \
Expand Down
8 changes: 4 additions & 4 deletions include/vmem/vmem_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ void vmem_file_write(vmem_t * vmem, uint64_t addr, const void * datain, uint32_t
.filename = filename_in, \
}; \
__attribute__((section("vmem"))) \
__attribute__((aligned(__alignof__(vmem_t)))) \
__attribute__((aligned(8))) \
__attribute__((used)) \
vmem_t vmem_##name_in = { \
const vmem_t vmem_##name_in = { \
.type = VMEM_TYPE_FILE, \
.name = strname, \
.size = size_in, \
Expand All @@ -63,9 +63,9 @@ void vmem_file_write(vmem_t * vmem, uint64_t addr, const void * datain, uint32_t
.filename = filename_in, \
}; \
__attribute__((section("vmem"))) \
__attribute__((aligned(__alignof__(vmem_t)))) \
__attribute__((aligned(8))) \
__attribute__((used)) \
vmem_t vmem_##name_in = { \
const vmem_t vmem_##name_in = { \
.type = VMEM_TYPE_FILE, \
.name = strname, \
.size = size_in, \
Expand Down
8 changes: 4 additions & 4 deletions include/vmem/vmem_fram.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ typedef struct {
.fram_addr = fram_addr_in, \
}; \
__attribute__((section("vmem"))) \
__attribute__((__aligned__(__alignof__(vmem_t)))) \
__attribute__((__aligned__(8))) \
__attribute__((used)) \
vmem_t vmem_##name_in = { \
const vmem_t vmem_##name_in = { \
.type = VMEM_TYPE_FRAM, \
.name = strname, \
.size = size_in, \
Expand All @@ -32,8 +32,8 @@ typedef struct {
.ack_with_pull = 1, \
};

void vmem_fram_read(vmem_t * vmem, uint64_t addr, void * dataout, uint32_t len);
void vmem_fram_write(vmem_t * vmem, uint64_t addr, const void * datain, uint32_t len);
void vmem_fram_read(const vmem_t * vmem, uint64_t addr, void * dataout, uint32_t len);
void vmem_fram_write(const vmem_t * vmem, uint64_t addr, const void * datain, uint32_t len);


#endif /* SRC_PARAM_VMEM_FRAM_H_ */
Loading
Loading