Skip to content

Commit e823c22

Browse files
committed
rust: Create 'sys' module
The `zephyr-sys` crate contains all of the generated bindings to the C API in Zephyr. The `zephyr::sys` module wraps these abstractions in as thin of a way as possible, but still allowing them to be used without 'unsafe'. Although the interfaces are "safe", because they are just wrappers around C calls, most aren't directly useful without unsafe, and this crate provides higher-level abstractions around these underlying primitives. This commit adds a definition for `K_FOREVER`, and `K_NO_WAIT`, which are too complicated for bindgen to autogenerate bindings for. We will rely on a test to ensure that the values match those in the C headers. Signed-off-by: David Brown <[email protected]>
1 parent b5b8d92 commit e823c22

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/rust/zephyr/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#![no_std]
1010
#![allow(unexpected_cfgs)]
1111

12+
pub mod sys;
1213
pub mod time;
1314

1415
// Bring in the generated kconfig module

lib/rust/zephyr/src/sys.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2024 Linaro LTD
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
//! Zephyr 'sys' module.
5+
//!
6+
//! The `zephyr-sys` crate contains the direct C bindings to the Zephyr API. All of these are
7+
//! unsafe.
8+
//!
9+
//! This module `zephyr::sys` contains thin wrappers to these C bindings, that can be used without
10+
//! unsafe, but as unchanged as possible.
11+
12+
use zephyr_sys::k_timeout_t;
13+
14+
// These two constants are not able to be captured by bindgen. It is unlikely that these values
15+
// would change in the Zephyr headers, but there will be an explicit test to make sure they are
16+
// correct.
17+
pub const K_FOREVER: k_timeout_t = k_timeout_t { ticks: -1 };
18+
pub const K_NO_WAIT: k_timeout_t = k_timeout_t { ticks: 0 };

0 commit comments

Comments
 (0)