samples: bindesc: Add hello_bindesc sample
Add the hello_bindesc sample which shows the basic usage of binary descriptors. Signed-off-by: Yonatan Schachter <yonatan.schachter@gmail.com>
This commit is contained in:
parent
c42a7dff4d
commit
fd5fe8fe10
10
samples/subsys/bindesc/bindesc.rst
Normal file
10
samples/subsys/bindesc/bindesc.rst
Normal file
|
@ -0,0 +1,10 @@
|
|||
.. _bindesc_samples:
|
||||
|
||||
Binary Descriptor Samples
|
||||
#########################
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
:glob:
|
||||
|
||||
**/*
|
8
samples/subsys/bindesc/hello_bindesc/CMakeLists.txt
Normal file
8
samples/subsys/bindesc/hello_bindesc/CMakeLists.txt
Normal file
|
@ -0,0 +1,8 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(hello_bindesc)
|
||||
|
||||
target_sources(app PRIVATE src/main.c)
|
26
samples/subsys/bindesc/hello_bindesc/README.rst
Normal file
26
samples/subsys/bindesc/hello_bindesc/README.rst
Normal file
|
@ -0,0 +1,26 @@
|
|||
.. _hello_bindesc-sample:
|
||||
|
||||
hello_bindesc Sample Application
|
||||
################################
|
||||
|
||||
Overview
|
||||
********
|
||||
|
||||
A simple sample of binary descriptor definition and usage.
|
||||
|
||||
Building and Running
|
||||
********************
|
||||
|
||||
Follow these steps to build the `hello_bindesc` sample application:
|
||||
|
||||
.. zephyr-app-commands::
|
||||
:zephyr-app: samples/subsys/bindesc/hello_bindesc
|
||||
:board: <board to use>
|
||||
:goals: build
|
||||
:compact:
|
||||
|
||||
To see all binary descriptors, run:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
west bindesc dump build/zephyr/zephyr.bin
|
5
samples/subsys/bindesc/hello_bindesc/VERSION
Normal file
5
samples/subsys/bindesc/hello_bindesc/VERSION
Normal file
|
@ -0,0 +1,5 @@
|
|||
VERSION_MAJOR = 1
|
||||
VERSION_MINOR = 0
|
||||
PATCHLEVEL = 0
|
||||
VERSION_TWEAK = 0
|
||||
EXTRAVERSION =
|
21
samples/subsys/bindesc/hello_bindesc/prj.conf
Normal file
21
samples/subsys/bindesc/hello_bindesc/prj.conf
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Enable binary descriptors
|
||||
CONFIG_BINDESC=y
|
||||
|
||||
# Enable definition of binary descriptors
|
||||
CONFIG_BINDESC_DEFINE=y
|
||||
|
||||
# Enable default build time binary descriptors
|
||||
CONFIG_BINDESC_DEFINE_BUILD_TIME=y
|
||||
CONFIG_BINDESC_BUILD_DATE_TIME_STRING=y
|
||||
|
||||
# Enable default version binary descriptors
|
||||
CONFIG_BINDESC_DEFINE_VERSION=y
|
||||
CONFIG_BINDESC_KERNEL_VERSION_STRING=y
|
||||
CONFIG_BINDESC_KERNEL_VERSION_MAJOR=y
|
||||
|
||||
CONFIG_BINDESC_APP_VERSION_STRING=y
|
||||
|
||||
# Enable default host info binary descriptors
|
||||
CONFIG_BINDESC_DEFINE_HOST_INFO=y
|
||||
CONFIG_BINDESC_C_COMPILER_NAME=y
|
||||
CONFIG_BINDESC_C_COMPILER_VERSION=y
|
9
samples/subsys/bindesc/hello_bindesc/sample.yaml
Normal file
9
samples/subsys/bindesc/hello_bindesc/sample.yaml
Normal file
|
@ -0,0 +1,9 @@
|
|||
sample:
|
||||
name: Hello Bindesc
|
||||
tests:
|
||||
sample.bindesc:
|
||||
tags: bindesc
|
||||
filter: CONFIG_ARCH_SUPPORTS_ROM_START
|
||||
build_only: true
|
||||
integration_platforms:
|
||||
- native_posix
|
35
samples/subsys/bindesc/hello_bindesc/src/main.c
Normal file
35
samples/subsys/bindesc/hello_bindesc/src/main.c
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Yonatan Schachter
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/bindesc.h>
|
||||
|
||||
BINDESC_STR_DEFINE(my_string, 1, "Hello world!");
|
||||
BINDESC_UINT_DEFINE(my_int, 2, 5);
|
||||
BINDESC_BYTES_DEFINE(my_bytes, 3, ({1, 2, 3, 4}));
|
||||
|
||||
int main(void)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
/* Builtin descriptors */
|
||||
printk("Zephyr version: %s\n", BINDESC_GET_STR(kernel_version_string));
|
||||
printk("App version: %s\n", BINDESC_GET_STR(app_version_string));
|
||||
printk("Build time: %s\n", BINDESC_GET_STR(build_date_time_string));
|
||||
printk("Compiler: %s %s\n", BINDESC_GET_STR(c_compiler_name),
|
||||
BINDESC_GET_STR(c_compiler_version));
|
||||
|
||||
/* Custom descriptors */
|
||||
printk("my_string: %s\n", BINDESC_GET_STR(my_string));
|
||||
printk("my_int: %d\n", BINDESC_GET_UINT(my_int));
|
||||
printk("my_bytes: ");
|
||||
for (i = 0; i < BINDESC_GET_SIZE(my_bytes); i++) {
|
||||
printk("%02x ", BINDESC_GET_BYTES(my_bytes)[i]);
|
||||
}
|
||||
printk("\n");
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue