Skip to content

Commit fd5fe8f

Browse files
yonschnashif
authored andcommitted
samples: bindesc: Add hello_bindesc sample
Add the hello_bindesc sample which shows the basic usage of binary descriptors. Signed-off-by: Yonatan Schachter <[email protected]>
1 parent c42a7df commit fd5fe8f

File tree

7 files changed

+114
-0
lines changed

7 files changed

+114
-0
lines changed

samples/subsys/bindesc/bindesc.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.. _bindesc_samples:
2+
3+
Binary Descriptor Samples
4+
#########################
5+
6+
.. toctree::
7+
:maxdepth: 1
8+
:glob:
9+
10+
**/*
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(hello_bindesc)
7+
8+
target_sources(app PRIVATE src/main.c)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.. _hello_bindesc-sample:
2+
3+
hello_bindesc Sample Application
4+
################################
5+
6+
Overview
7+
********
8+
9+
A simple sample of binary descriptor definition and usage.
10+
11+
Building and Running
12+
********************
13+
14+
Follow these steps to build the `hello_bindesc` sample application:
15+
16+
.. zephyr-app-commands::
17+
:zephyr-app: samples/subsys/bindesc/hello_bindesc
18+
:board: <board to use>
19+
:goals: build
20+
:compact:
21+
22+
To see all binary descriptors, run:
23+
24+
.. code-block:: bash
25+
26+
west bindesc dump build/zephyr/zephyr.bin
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
VERSION_MAJOR = 1
2+
VERSION_MINOR = 0
3+
PATCHLEVEL = 0
4+
VERSION_TWEAK = 0
5+
EXTRAVERSION =
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Enable binary descriptors
2+
CONFIG_BINDESC=y
3+
4+
# Enable definition of binary descriptors
5+
CONFIG_BINDESC_DEFINE=y
6+
7+
# Enable default build time binary descriptors
8+
CONFIG_BINDESC_DEFINE_BUILD_TIME=y
9+
CONFIG_BINDESC_BUILD_DATE_TIME_STRING=y
10+
11+
# Enable default version binary descriptors
12+
CONFIG_BINDESC_DEFINE_VERSION=y
13+
CONFIG_BINDESC_KERNEL_VERSION_STRING=y
14+
CONFIG_BINDESC_KERNEL_VERSION_MAJOR=y
15+
16+
CONFIG_BINDESC_APP_VERSION_STRING=y
17+
18+
# Enable default host info binary descriptors
19+
CONFIG_BINDESC_DEFINE_HOST_INFO=y
20+
CONFIG_BINDESC_C_COMPILER_NAME=y
21+
CONFIG_BINDESC_C_COMPILER_VERSION=y
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
sample:
2+
name: Hello Bindesc
3+
tests:
4+
sample.bindesc:
5+
tags: bindesc
6+
filter: CONFIG_ARCH_SUPPORTS_ROM_START
7+
build_only: true
8+
integration_platforms:
9+
- native_posix
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) 2023 Yonatan Schachter
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
#include <zephyr/bindesc.h>
9+
10+
BINDESC_STR_DEFINE(my_string, 1, "Hello world!");
11+
BINDESC_UINT_DEFINE(my_int, 2, 5);
12+
BINDESC_BYTES_DEFINE(my_bytes, 3, ({1, 2, 3, 4}));
13+
14+
int main(void)
15+
{
16+
size_t i;
17+
18+
/* Builtin descriptors */
19+
printk("Zephyr version: %s\n", BINDESC_GET_STR(kernel_version_string));
20+
printk("App version: %s\n", BINDESC_GET_STR(app_version_string));
21+
printk("Build time: %s\n", BINDESC_GET_STR(build_date_time_string));
22+
printk("Compiler: %s %s\n", BINDESC_GET_STR(c_compiler_name),
23+
BINDESC_GET_STR(c_compiler_version));
24+
25+
/* Custom descriptors */
26+
printk("my_string: %s\n", BINDESC_GET_STR(my_string));
27+
printk("my_int: %d\n", BINDESC_GET_UINT(my_int));
28+
printk("my_bytes: ");
29+
for (i = 0; i < BINDESC_GET_SIZE(my_bytes); i++) {
30+
printk("%02x ", BINDESC_GET_BYTES(my_bytes)[i]);
31+
}
32+
printk("\n");
33+
34+
return 0;
35+
}

0 commit comments

Comments
 (0)