K-FSW v1.2.1-59-gcaca356
KFSW: modular flight software on Zephyr, for small satellites
Loading...
Searching...
No Matches
Parameters

Public Headers

file  parameter.h
 

Data Structures

union  kfsw_param_scalar
 
struct  kfsw_param_value
 
struct  kfsw_param_info
 
struct  kfsw_param_table_info
 
struct  kfsw_param_definition
 
struct  kfsw_param_definition_set
 
struct  kfsw_param_stats
 

Macros

#define KFSW_PARAM_STRING_MAX   CONFIG_KFSW_PARAM_STRING_MAX
 
#define KFSW_PARAM_WIRE_BYTES   58U
 
#define KFSW_PARAM_TABLE_WIRE_MAX   2048U
 
#define KFSW_PARAM_DESCRIPTION_MAX   64U
 
#define KFSW_PARAM_TABLE_FITS_THE_LINK(definitions)
 
#define KFSW_PARAM_NAME_MAX   32U
 
#define KFSW_PARAM_TABLE_INVALID   0U
 
#define KFSW_PARAM_TABLE_CORE_FIRST   1U
 
#define KFSW_PARAM_TABLE_CORE_LAST   24U
 
#define KFSW_PARAM_TABLE_SERVICE_FIRST   25U
 
#define KFSW_PARAM_TABLE_SERVICE_LAST   49U
 
#define KFSW_PARAM_TABLE_MODULE_FIRST   50U
 
#define KFSW_PARAM_TABLE_MODULE_LAST   99U
 
#define KFSW_PARAM_OFFSET_MAX   255U
 
#define KFSW_PARAM_FLAG_READ_ONLY   0x00000001UL
 
#define KFSW_PARAM_FLAG_CONFIGURATION   0x00000004UL
 
#define KFSW_PARAM_FLAG_SYSTEM_INFO   0x00000040UL
 
#define KFSW_PARAM_FLAG_DEBUG   0x00000200UL
 
#define KFSW_PARAM_FLAG_PERSISTENT   0x00010000UL
 
#define KFSW_PARAM_FLAG_OWNER_STORE   0x00080000UL
 
#define KFSW_PARAM_FLAG_LIVE   0x00020000UL
 
#define KFSW_PARAM_FLAG_LOCAL_ONLY   0x00040000UL
 
#define KFSW_PARAM_ID(table, offset)   ((uint16_t)(((uint16_t)(table) << 8) | (uint8_t)(offset)))
 
#define KFSW_PARAM_PARAM_TABLE_ID   26U
 
#define KFSW_PARAM_PARAM_TABLE_NAME   "param"
 

Types

typedef int(* kfsw_param_validator_t) (const union kfsw_param_scalar *value)
 
typedef int(* kfsw_param_text_validator_t) (const char *text)
 
typedef int(* kfsw_param_data_validator_t) (const uint8_t *data, size_t size)
 
typedef int(* kfsw_param_apply_t) (const union kfsw_param_scalar *value)
 
typedef void(* kfsw_param_changed_t) (const union kfsw_param_scalar *value)
 
typedef void(* kfsw_param_text_changed_t) (const char *text)
 
typedef void(* kfsw_param_data_changed_t) (const uint8_t *data, size_t size)
 
typedef void(* kfsw_param_sample_t) (void *value)
 
typedef bool(* kfsw_param_visitor_t) (const struct kfsw_param_info *info, void *context)
 
typedef bool(* kfsw_param_table_visitor_t) (const struct kfsw_param_table_info *info, void *context)
 

Enumerations

enum  kfsw_param_type {
  KFSW_PARAM_U8 , KFSW_PARAM_U16 , KFSW_PARAM_U32 , KFSW_PARAM_U64 ,
  KFSW_PARAM_I8 , KFSW_PARAM_I16 , KFSW_PARAM_I32 , KFSW_PARAM_I64 ,
  KFSW_PARAM_X8 , KFSW_PARAM_X16 , KFSW_PARAM_X32 , KFSW_PARAM_X64 ,
  KFSW_PARAM_FLOAT , KFSW_PARAM_DOUBLE , KFSW_PARAM_STRING , KFSW_PARAM_DATA ,
  KFSW_PARAM_INVALID
}
 

Functions

int kfsw_param_init (const struct kfsw_param_definition_set *const *sets, size_t set_count)
 
bool kfsw_param_is_initialized (void)
 
int kfsw_param_parse_text (const char *text, struct kfsw_param_value *value)
 
int kfsw_param_get (const char *name, struct kfsw_param_value *value)
 
int kfsw_param_set (const char *name, const struct kfsw_param_value *value)
 
int kfsw_param_get_by_id (uint16_t id, struct kfsw_param_value *value)
 
int kfsw_param_get_info (const char *name, struct kfsw_param_info *info)
 
int kfsw_param_visit (kfsw_param_visitor_t visitor, void *context)
 
int kfsw_param_visit_tables (kfsw_param_table_visitor_t visitor, void *context)
 
int kfsw_param_remote_tables (uint16_t node, kfsw_param_table_visitor_t visitor, void *context)
 
size_t kfsw_param_table_count (void)
 
int kfsw_param_get_stats (struct kfsw_param_stats *stats)
 
bool kfsw_param_autosave_enabled (void)
 
const char * kfsw_param_band_name (uint8_t table)
 
const char * kfsw_param_mode_name (uint32_t flags)
 
int kfsw_param_persist_save (void)
 
int kfsw_param_persist_load (void)
 
int kfsw_param_persist_clear (void)
 
int kfsw_param_persist_table_count (uint8_t table, uint16_t *count)
 
uint32_t kfsw_param_persist_bytes (void)
 
uint32_t kfsw_param_persist_max_bytes (void)
 
int kfsw_param_restore_defaults (void)
 
int kfsw_param_server_start (void)
 
int kfsw_param_remote_refresh (uint16_t node)
 
int kfsw_param_remote_get (uint16_t node, const char *name, struct kfsw_param_value *value)
 
int kfsw_param_remote_get_many (uint16_t node, const char *const *names, size_t count, struct kfsw_param_value *values)
 
int kfsw_param_remote_get_many_until (uint16_t node, const char *const *names, size_t count, struct kfsw_param_value *values, int64_t deadline)
 
int kfsw_param_remote_visit_until (uint16_t node, kfsw_param_visitor_t visitor, void *context, int64_t deadline)
 
int kfsw_param_remote_set (uint16_t node, const char *name, const struct kfsw_param_value *value)
 
int kfsw_param_remote_visit (uint16_t node, kfsw_param_visitor_t visitor, void *context)
 
int kfsw_param_remote_visit_table (uint16_t node, uint8_t table, kfsw_param_visitor_t visitor, void *context)
 
const char * kfsw_param_type_name (enum kfsw_param_type type)
 

Variables

const struct kfsw_param_definition_set kfsw_param_param_definitions
 

Description

Local tables and persistence with optional remote CSP access.

Initialize the local table with kfsw_param_init(). The application restores persistence independently of CSP. When CONFIG_KFSW_PARAM_CSP is enabled, kfsw_param_server_start() exposes the same table through the CSP adapter.

Macro Documentation

◆ KFSW_PARAM_DESCRIPTION_MAX

#define KFSW_PARAM_DESCRIPTION_MAX   64U

#include <parameter.h>

Longest description a parameter or a table may carry.

A remote table listing carries the description on the wire and the receiver holds it in a buffer this size, so a longer one makes the listing fail rather than truncate. It also keeps a param describe line, which starts the description at column 71, inside 140 columns.

◆ KFSW_PARAM_FLAG_CONFIGURATION

#define KFSW_PARAM_FLAG_CONFIGURATION   0x00000004UL

#include <parameter.h>

Parameter controls operator-selected configuration.

◆ KFSW_PARAM_FLAG_DEBUG

#define KFSW_PARAM_FLAG_DEBUG   0x00000200UL

#include <parameter.h>

Parameter exists for diagnostic or test behavior.

◆ KFSW_PARAM_FLAG_LIVE

#define KFSW_PARAM_FLAG_LIVE   0x00020000UL

#include <parameter.h>

User flag: a write takes effect immediately.

Set for every definition with a change callback; a definition that reads its value every cycle can set it too.

◆ KFSW_PARAM_FLAG_LOCAL_ONLY

#define KFSW_PARAM_FLAG_LOCAL_ONLY   0x00040000UL

#include <parameter.h>

Parameter may be configured locally, but remote writes are refused.

◆ KFSW_PARAM_FLAG_OWNER_STORE

#define KFSW_PARAM_FLAG_OWNER_STORE   0x00080000UL

#include <parameter.h>

Owner persists writes; exclude from snapshot save/load and RAM defaults.

◆ KFSW_PARAM_FLAG_PERSISTENT

#define KFSW_PARAM_FLAG_PERSISTENT   0x00010000UL

#include <parameter.h>

User flag: the value survives reset.

Uses the snapshot unless OWNER_STORE.

◆ KFSW_PARAM_FLAG_READ_ONLY

#define KFSW_PARAM_FLAG_READ_ONLY   0x00000001UL

#include <parameter.h>

Parameter cannot be changed through local or remote set operations.

◆ KFSW_PARAM_FLAG_SYSTEM_INFO

#define KFSW_PARAM_FLAG_SYSTEM_INFO   0x00000040UL

#include <parameter.h>

Parameter reports build or runtime system identity.

◆ KFSW_PARAM_ID

#define KFSW_PARAM_ID (   table,
  offset 
)    ((uint16_t)(((uint16_t)(table) << 8) | (uint8_t)(offset)))

#include <parameter.h>

Build the wire ID for a table and offset.

◆ KFSW_PARAM_NAME_MAX

#define KFSW_PARAM_NAME_MAX   32U

#include <parameter.h>

Longest parameter name, excluding the terminator.

Longer names are refused.

◆ KFSW_PARAM_OFFSET_MAX

#define KFSW_PARAM_OFFSET_MAX   255U

#include <parameter.h>

Largest offset addressable within one table.

◆ KFSW_PARAM_PARAM_TABLE_ID

#define KFSW_PARAM_PARAM_TABLE_ID   26U

#include <parameter.h>

Parameter table of the parameter service, in the service band.

◆ KFSW_PARAM_PARAM_TABLE_NAME

#define KFSW_PARAM_PARAM_TABLE_NAME   "param"

#include <parameter.h>

Parameter table name.

◆ KFSW_PARAM_STRING_MAX

#define KFSW_PARAM_STRING_MAX   CONFIG_KFSW_PARAM_STRING_MAX

#include <parameter.h>

Longest string parameter, including the terminator.

◆ KFSW_PARAM_TABLE_CORE_FIRST

#define KFSW_PARAM_TABLE_CORE_FIRST   1U

#include <parameter.h>

First and last table of the application, platform and comms layers.

◆ KFSW_PARAM_TABLE_FITS_THE_LINK

#define KFSW_PARAM_TABLE_FITS_THE_LINK (   definitions)

#include <parameter.h>

Value:
BUILD_ASSERT(ARRAY_SIZE(definitions) * KFSW_PARAM_WIRE_BYTES <= KFSW_PARAM_TABLE_WIRE_MAX, \
"a parameter table must fit 2 KB on a 4800 baud link")
#define KFSW_PARAM_WIRE_BYTES
Bytes one descriptor takes on the link.
Definition parameter.h:61
#define KFSW_PARAM_TABLE_WIRE_MAX
Largest a table may be on the link.
Definition parameter.h:70

Refuse at build time a table too large for the slowest link.

Place it next to the definition set it guards.

◆ KFSW_PARAM_TABLE_INVALID

#define KFSW_PARAM_TABLE_INVALID   0U

#include <parameter.h>

Table ID bands.

A parameter is addressed by table and offset, and the band shows whether a table is core, service or module. Zero is reserved.

◆ KFSW_PARAM_TABLE_MODULE_FIRST

#define KFSW_PARAM_TABLE_MODULE_FIRST   50U

#include <parameter.h>

First and last module table.

◆ KFSW_PARAM_TABLE_SERVICE_FIRST

#define KFSW_PARAM_TABLE_SERVICE_FIRST   25U

#include <parameter.h>

First and last service table.

◆ KFSW_PARAM_TABLE_WIRE_MAX

#define KFSW_PARAM_TABLE_WIRE_MAX   2048U

#include <parameter.h>

Largest a table may be on the link.

4800 baud is the slowest link this has to work on, and carries 480 bytes a second, so 2 KB is 4.2 seconds: inside the refresh budget with room for a retry. A table that outgrows this is split, not carried.

◆ KFSW_PARAM_WIRE_BYTES

#define KFSW_PARAM_WIRE_BYTES   58U

#include <parameter.h>

Bytes one descriptor takes on the link.

The record without the help text, which is not sent: the ground reads it from the interface document.

Type Documentation

◆ kfsw_param_apply_t

typedef int(* kfsw_param_apply_t) (const union kfsw_param_scalar *value)

#include <parameter.h>

Apply a validated scalar before committing storage.

Return zero on success or a negative errno without changing owner state on failure. Runs under the table lock and must not call the parameter API. Remote writes must contain only this value. Registry initialization copies defaults without calling this callback.

◆ kfsw_param_changed_t

typedef void(* kfsw_param_changed_t) (const union kfsw_param_scalar *value)

#include <parameter.h>

Called after the stored scalar changes.

◆ kfsw_param_data_changed_t

typedef void(* kfsw_param_data_changed_t) (const uint8_t *data, size_t size)

#include <parameter.h>

Called after the stored byte array changes.

◆ kfsw_param_data_validator_t

typedef int(* kfsw_param_data_validator_t) (const uint8_t *data, size_t size)

#include <parameter.h>

Validate the whole proposed byte array; return zero to accept it.

The same side-effect-free contract as the scalar validator applies.

◆ kfsw_param_sample_t

typedef void(* kfsw_param_sample_t) (void *value)

#include <parameter.h>

Refresh the stored value just before it is read.

Runs under the table lock, so it must not call the parameter API.

◆ kfsw_param_text_changed_t

typedef void(* kfsw_param_text_changed_t) (const char *text)

#include <parameter.h>

Called after the stored string changes.

◆ kfsw_param_text_validator_t

typedef int(* kfsw_param_text_validator_t) (const char *text)

#include <parameter.h>

Validate a proposed string; return zero to accept it.

Separate from the scalar validator because a string does not fit the scalar union. The same side-effect-free contract applies.

◆ kfsw_param_validator_t

typedef int(* kfsw_param_validator_t) (const union kfsw_param_scalar *value)

#include <parameter.h>

Validate a proposed scalar value; return zero to accept it.

Validators must not change stored values or apply side effects. Packet preflight may validate a value and later reject the packet. Apply accepted values in the changed callback instead, or use apply for work that can fail.

Enumeration Documentation

◆ kfsw_param_type

#include <parameter.h>

Enumerator
KFSW_PARAM_DATA 

Fixed-length byte array, such as per-module log levels.

Function Documentation

◆ kfsw_param_autosave_enabled()

bool kfsw_param_autosave_enabled ( void  )

#include <parameter.h>

Whether an accepted change to a persistent value writes a snapshot.

◆ kfsw_param_band_name()

const char * kfsw_param_band_name ( uint8_t  table)

#include <parameter.h>

Name of the band a table ID falls in.

Returns
"core", "service", "module", or "invalid" for an unallocated value.

◆ kfsw_param_get_by_id()

int kfsw_param_get_by_id ( uint16_t  id,
struct kfsw_param_value *  value 
)

#include <parameter.h>

Read a parameter by its wire ID.

Samples the value like kfsw_param_get().

◆ kfsw_param_get_info()

int kfsw_param_get_info ( const char *  name,
struct kfsw_param_info *  info 
)

#include <parameter.h>

Read one local parameter's description by name.

Parameters
nameParameter name.
[out]infoDestination description.
Return values
0The description was written.
-EINVALname or info is NULL.
-EACCESThe local table is not initialized.
-ENOENTNo parameter of that name is registered.

◆ kfsw_param_get_stats()

int kfsw_param_get_stats ( struct kfsw_param_stats *  stats)

#include <parameter.h>

Read service counters.

Returns -EINVAL for a NULL destination.

◆ kfsw_param_init()

int kfsw_param_init ( const struct kfsw_param_definition_set *const *  sets,
size_t  set_count 
)

#include <parameter.h>

Aggregate, validate, and enable the supplied component definition sets.

◆ kfsw_param_is_initialized()

bool kfsw_param_is_initialized ( void  )

#include <parameter.h>

Return whether the local parameter table was initialized successfully.

◆ kfsw_param_mode_name()

const char * kfsw_param_mode_name ( uint32_t  flags)

#include <parameter.h>

Write behaviour implied by a parameter's flags.

Returns
"r" read-only, "w" applied immediately, "b" stored until reboot, "wb" both.

How a parameter can be written, as letters.

r read-only w writable p persistent: the value survives a reset b boot: the write is read when the node next starts

The returned pointer is a string literal.

◆ kfsw_param_parse_text()

int kfsw_param_parse_text ( const char *  text,
struct kfsw_param_value *  value 
)

#include <parameter.h>

Read a scalar local parameter by name.

Read a value of this parameter's type from text.

The type in value chooses how the text is read and what range is accepted. The scalar is written only when the whole text parses and fits.

Return values
0on success.
-EINVALwhen the text is not a value of that type.
-ERANGEwhen it does not fit the type.

◆ kfsw_param_persist_bytes()

uint32_t kfsw_param_persist_bytes ( void  )

#include <parameter.h>

Space the last built snapshot occupied, in bytes.

◆ kfsw_param_persist_clear()

int kfsw_param_persist_clear ( void  )

#include <parameter.h>

Delete the active persistent snapshot and any abandoned temporary file.

◆ kfsw_param_persist_load()

int kfsw_param_persist_load ( void  )

#include <parameter.h>

Load a valid snapshot, ignoring unknown names and incompatible entries.

A snapshot holds only persistent values, and registration refuses a persistent parameter with an apply callback, so no entry applies a fallible scalar. Application errors are returned to the caller.

◆ kfsw_param_persist_max_bytes()

uint32_t kfsw_param_persist_max_bytes ( void  )

#include <parameter.h>

Most space a snapshot is allowed to occupy, in bytes.

◆ kfsw_param_persist_save()

int kfsw_param_persist_save ( void  )

#include <parameter.h>

Save all explicitly persistent local parameters as one atomic snapshot.

◆ kfsw_param_persist_table_count()

int kfsw_param_persist_table_count ( uint8_t  table,
uint16_t *  count 
)

#include <parameter.h>

Count persistent parameters in a table.

Parameters
tableTable identifier.
[out]countPersistent parameters in that table.
Return values
0Counted.
-EINVALNULL destination.
-ENOENTNo such table.

◆ kfsw_param_remote_get()

int kfsw_param_remote_get ( uint16_t  node,
const char *  name,
struct kfsw_param_value *  value 
)

#include <parameter.h>

Read a scalar parameter with the bounded retry policy of kfsw_param_remote_get_many().

◆ kfsw_param_remote_get_many()

int kfsw_param_remote_get_many ( uint16_t  node,
const char *const *  names,
size_t  count,
struct kfsw_param_value *  values 
)

#include <parameter.h>

Read several parameters from one node in as few exchanges as possible.

The whole operation shares one time budget, and each receive is also limited by CONFIG_KFSW_PARAM_TIMEOUT_MS. values must hold count entries. All names are resolved before anything is requested. Returns 0 with every value filled, or an errno if any value is missing. Only -ETIMEDOUT is retried, with at most three total read attempts within the original budget. Earlier batches may be read again; this is not a snapshot.

◆ kfsw_param_remote_get_many_until()

int kfsw_param_remote_get_many_until ( uint16_t  node,
const char *const *  names,
size_t  count,
struct kfsw_param_value *  values,
int64_t  deadline 
)

#include <parameter.h>

Same read with an absolute k_uptime_get() deadline, including mutex waits.

◆ kfsw_param_remote_refresh()

int kfsw_param_remote_refresh ( uint16_t  node)

#include <parameter.h>

Refresh a node's indexed v4 list; publish it only after count and CRC verification.

◆ kfsw_param_remote_set()

int kfsw_param_remote_set ( uint16_t  node,
const char *  name,
const struct kfsw_param_value *  value 
)

#include <parameter.h>

Write a scalar parameter on a selected CSP node.

◆ kfsw_param_remote_tables()

int kfsw_param_remote_tables ( uint16_t  node,
kfsw_param_table_visitor_t  visitor,
void *  context 
)

#include <parameter.h>

Visit the tables another node carries, without its descriptors.

One exchange instead of one for every parameter in them, and the names come from the node, so a table this build does not carry is still named. The description is NULL: it is not carried.

Return values
0when every table was visited.
-ENOTSUPwhen the node does not answer this request.
-EMSGSIZEwhen the node has more tables than one reply holds.

◆ kfsw_param_remote_visit()

int kfsw_param_remote_visit ( uint16_t  node,
kfsw_param_visitor_t  visitor,
void *  context 
)

#include <parameter.h>

Visit a node's descriptors.

Copy borrowed strings before the callback returns.

◆ kfsw_param_remote_visit_table()

int kfsw_param_remote_visit_table ( uint16_t  node,
uint8_t  table,
kfsw_param_visitor_t  visitor,
void *  context 
)

#include <parameter.h>

Visit one table of another node.

A whole node does not fit the refresh budget on a slow link; one table does.

Return values
0on success, a negative errno otherwise.
-EINVALwhen table is zero.

◆ kfsw_param_remote_visit_until()

int kfsw_param_remote_visit_until ( uint16_t  node,
kfsw_param_visitor_t  visitor,
void *  context,
int64_t  deadline 
)

#include <parameter.h>

Visit within an absolute uptime deadline.

Copy names before returning from the callback. The callback must not call remote PARAM operations or block indefinitely.

◆ kfsw_param_restore_defaults()

int kfsw_param_restore_defaults ( void  )

#include <parameter.h>

Restore snapshot parameters to compiled defaults in RAM; owner stores stay.

Registration refuses a persistent parameter with an apply callback, so the reset applies no fallible scalar. Application errors are returned to the caller.

◆ kfsw_param_server_start()

int kfsw_param_server_start ( void  )

#include <parameter.h>

Register the optional CSP parameter and parameter-list endpoints once.

◆ kfsw_param_set()

int kfsw_param_set ( const char *  name,
const struct kfsw_param_value *  value 
)

#include <parameter.h>

Write a scalar local parameter after exact type/size validation.

◆ kfsw_param_table_count()

size_t kfsw_param_table_count ( void  )

#include <parameter.h>

Registered local tables.

◆ kfsw_param_type_name()

const char * kfsw_param_type_name ( enum kfsw_param_type  type)

#include <parameter.h>

Return a stable printable name for a K-FSW parameter type.

◆ kfsw_param_visit()

int kfsw_param_visit ( kfsw_param_visitor_t  visitor,
void *  context 
)

#include <parameter.h>

Visit local parameter descriptions, ordered by table then offset.

◆ kfsw_param_visit_tables()

int kfsw_param_visit_tables ( kfsw_param_table_visitor_t  visitor,
void *  context 
)

#include <parameter.h>

Visit each registered local table once, in ascending identifier order.

Variable Documentation

◆ kfsw_param_param_definitions

const struct kfsw_param_definition_set kfsw_param_param_definitions
extern

#include <parameter.h>

Parameter service counters and settings.