Skip to content

Instantly share code, notes, and snippets.

@danielhenrymantilla
Last active October 15, 2019 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielhenrymantilla/ac7756ef11dd6fabe7a715f8afddba59 to your computer and use it in GitHub Desktop.
Save danielhenrymantilla/ac7756ef11dd6fabe7a715f8afddba59 to your computer and use it in GitHub Desktop.
extract.h ported to Rust
#![allow(bad_style)]
use ::std::{
cell::UnsafeCell,
mem::size_of,
os::raw::{
c_int,
c_uint,
c_ulong,
},
};
#[repr(transparent)]
pub
struct Mut<T> /* = */ (
UnsafeCell<T>,
);
impl<T> Mut<T> {
#[inline]
pub
const
fn new (value: T) -> Self
{
Self(UnsafeCell::new(value))
}
pub
fn get (self: &'_ Self)
-> &'_ T
{
unsafe { &*self.0.get() }
}
pub
fn get_mut (self: &'_ mut Self)
-> &'_ mut T
{
unsafe { &mut *self.0.get() }
}
/// # Safety
///
/// - The lifetime `'mut_unchecked` cannot overlap with any
/// `.get()` or `.get_mut()` borrow.
pub
unsafe
fn get_mut_unchecked<'mut_unchecked> (self: &'mut_unchecked Self)
-> &'mut_unchecked mut T
{
&mut *self.0.get()
}
}
/// # Safety
///
/// - No non-`unsafe` public API can be used to trigger a data race
unsafe impl<T : Sync + Send> Sync for Mut<T> {}
macro_rules! const_assert {
(
$T:ident : $($rest:tt)*
) => (
const _: () = {
fn check () where
$T : $($rest)*
{}
};
);
(
$(
$condition:expr
),+ $(,)?
) => (
$(
const _: [(); 1] = {
const CONDITION: bool = $condition;
[(); CONDITION as usize]
};
)+
);
}
#[repr(C)]
pub
union IntOrPtr<T : 'static> {
int: usize,
ptr: Option<&'static T>,
}
const_assert!(
size_of::<usize>() == size_of::<Option<&'static ()>>()
);
macro_rules! addresses {
(
@acc
[ $($ret:expr ,)* ]
@parsing
& $expr:expr
$(, $($rest:tt)*)?
) => (addresses!(
@acc
[ $($ret ,)* IntOrPtr { ptr: Some(&$expr) }, ]
@parsing
$( $($rest)* )?
));
(
@acc
[ $($ret:expr ,)* ]
@parsing
$expr:expr
$(, $($rest:tt)*)?
) => (addresses!(
@acc
[ $($ret ,)* IntOrPtr { int: $expr }, ]
@parsing
$( $($rest)* )?
));
(
@acc
$ret:tt
@parsing
// nothing left to parse
) => (
$ret
);
(
$($input:tt)*
) => (addresses!(
@acc
[]
@parsing
$($input)*
));
}
type irCalConfig_t = [u8; 26];
#[no_mangle]
pub
static irCalConfig: irCalConfig_t = [
25, 71, 3, 6, 4, 16, 0, 1, 1, 3, 1, 6, 0,
16, 39, 0, 0, 5, 0, 1, 1, 0, 0, 0, 0, 0,
];
pub
type channelConfigEntryAttr_t = Mut<[[c_ulong; 1]; 1]>;
#[no_mangle]
pub
static channelConfigEntryAttr: channelConfigEntryAttr_t = Mut::new([
[ 0xFFFFFFFF, ],
]);
macro_rules! NULL {() => (0)}
type phyInfo_t = [IntOrPtr<irCalConfig_t>; 10];
#[no_mangle]
pub
static phyInfo: phyInfo_t = addresses![
3,
0x000F0F0F, // 15.0588235294
NULL!(),
&irCalConfig,
// #ifdef RADIO_CONFIG_ENABLE_TIMING
// &Channel_Group_1_timing,
// #else
NULL!(),
// #endif
0x00000000,
10200000,
35700000,
50000,
((1 << 8) | 1) as _,
];
type Protocol_Configuration_modemConfigBase_t = [IntOrPtr<phyInfo_t>; 118];
#[no_mangle]
pub
static Protocol_Configuration_modemConfigBase
:
Protocol_Configuration_modemConfigBase_t
=
addresses![
0x01041FF0, 0x003F003F,
/* 1FF4 */ 0x00000000,
/* 1FF8 */ &phyInfo,
/* 1FFC */ 0x00000000,
0x00020004, 0x00000000,
/* 0008 */ 0x00000000,
0x00020018, 0x0000000F,
/* 001C */ 0x00000000,
0x00070028, 0x00000000,
/* 002C */ 0x00000000,
/* 0030 */ 0x00000000,
/* 0034 */ 0x00000000,
/* 0038 */ 0x00000000,
/* 003C */ 0x00000000,
/* 0040 */ 0x00000700,
0x00010048, 0x00000000,
0x00020054, 0x00000000,
/* 0058 */ 0x00000000,
0x000400A0, 0x00004CFF,
/* 00A4 */ 0x00000000,
/* 00A8 */ 0x00004DFF,
/* 00AC */ 0x00000000,
0x00012000, 0x00000744,
0x00012010, 0x00000000,
0x00012018, 0x0000A001,
0x00013008, 0x0100AC13,
0x00023030, 0x00104000,
/* 3034 */ 0x00000003,
0x00013040, 0x00000000,
0x000140A0, 0x0F0027AA,
0x000140B8, 0x0023C000,
0x000140F4, 0x00001020,
0x00024134, 0x00000880,
/* 4138 */ 0x000087F6,
0x00024140, 0x008800E0,
/* 4144 */ 0x4D52E6C1,
0x00044160, 0x00000000,
/* 4164 */ 0x00000000,
/* 4168 */ 0x00000006,
/* 416C */ 0x00000006,
0x00086014, 0x00000010,
/* 6018 */ 0x04000000,
/* 601C */ 0x0002C00F,
/* 6020 */ 0x00006000,
/* 6024 */ 0x000AD000,
/* 6028 */ 0x03000000,
/* 602C */ 0x00000000,
/* 6030 */ 0x00000000,
0x00066050, 0x00FF5FA0,
/* 6054 */ 0x00000E2D,
/* 6058 */ 0x00000108,
/* 605C */ 0x00140012,
/* 6060 */ 0x0000B16F,
/* 6064 */ 0x00000000,
0x000C6078, 0x06A0071B,
/* 607C */ 0x00000000,
/* 6080 */ 0x00220390,
/* 6084 */ 0x00000000,
/* 6088 */ 0x00000000,
/* 608C */ 0x22140A04,
/* 6090 */ 0x4F4A4132,
/* 6094 */ 0x00000000,
/* 6098 */ 0x00000000,
/* 609C */ 0x00000000,
/* 60A0 */ 0x00000000,
/* 60A4 */ 0x00000000,
0x000760E4, 0x04000080,
/* 60E8 */ 0x00000000,
/* 60EC */ 0x07830464,
/* 60F0 */ 0x3AC81388,
/* 60F4 */ 0x0006209C,
/* 60F8 */ 0x00206100,
/* 60FC */ 0x208556B7,
0x00036104, 0x00108000,
/* 6108 */ 0x00003020,
/* 610C */ 0x0000BB88,
0x00016120, 0x00000000,
0x00077014, 0x000270FE,
/* 7018 */ 0x00000300,
/* 701C */ 0x834A0060,
/* 7020 */ 0x00000000,
/* 7024 */ 0x00000082,
/* 7028 */ 0x00000000,
/* 702C */ 0x000000D5,
0x00027048, 0x0000383E,
/* 704C */ 0x000025BC,
0x00037070, 0x00120105,
/* 7074 */ 0x00083019,
/* 7078 */ 0x006D8480,
0xFFFFFFFF,
]
;
#[repr(C)]
pub
struct RAIL_ChannelConfigEntry_t {
phyConfigDeltaAdd: usize, // ?
baseFrequency: c_int, // ?
channelSpacing: c_int, // ?
physicalChannelOffset: c_int, // ?
channelNumberStart: c_int, // ?
channelNumberEnd: c_int, // ?
maxPower: c_int, // ?
attr: Option<&'static channelConfigEntryAttr_t>,
}
const_assert!(
channelConfigEntryAttr_t : Sized,
);
/// ?
const RAIL_TX_POWER_MAX: c_int = 0;
type Protocol_Configuration_channels_t = [RAIL_ChannelConfigEntry_t; 1];
#[no_mangle]
pub
static Protocol_Configuration_channels: Protocol_Configuration_channels_t =
[
RAIL_ChannelConfigEntry_t {
phyConfigDeltaAdd: NULL!(),
baseFrequency: 915000000,
channelSpacing: 1000000,
physicalChannelOffset: 0,
channelNumberStart: 0,
channelNumberEnd: 20,
maxPower: RAIL_TX_POWER_MAX,
attr: Some(&channelConfigEntryAttr),
},
]
;
#[repr(C)]
pub
struct RAIL_ChannelConfig_t {
phyConfigBase: Option<&'static Protocol_Configuration_modemConfigBase_t>,
phyConfigDeltaSubtract: usize, // ?
configs: Option<&'static Protocol_Configuration_channels_t>,
length: c_uint, // ?
signature: c_ulong, // ?
}
const_assert!(
Protocol_Configuration_modemConfigBase_t : Sized,
Protocol_Configuration_channels_t : Sized,
);
#[no_mangle]
pub
static Protocol_Configuration_channelConfig: RAIL_ChannelConfig_t =
RAIL_ChannelConfig_t {
phyConfigBase: Some(&Protocol_Configuration_modemConfigBase),
phyConfigDeltaSubtract: NULL!(),
configs: Some(&Protocol_Configuration_channels),
length: 1,
signature: 0,
}
;
type channelConfigs_t = [Option<&'static RAIL_ChannelConfig_t>; 2];
const_assert!(
RAIL_ChannelConfig_t : Sized
);
#[no_mangle]
pub
static channelConfigs: channelConfigs_t = [
Some(&Protocol_Configuration_channelConfig),
None
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment