Skip to content

Commit 1045aec

Browse files
committed
added more comments
1 parent 82e7992 commit 1045aec

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

decoder/decoder/src/decoder_context.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,14 @@ impl<T: Pod> FlashEntry<T> {
4646
}
4747
}
4848

49+
/// Every flash entry stores a status section at the end of the page indicating if it contains valid data or not.
50+
///
51+
/// This returns address of status section.
4952
fn status_address(&self) -> usize {
5053
self.address + FLASH_PAGE_SIZE - 16
5154
}
5255

56+
/// Retreive status indicating if `FlashEntry` contains data or not.
5357
fn status(&self) -> u32 {
5458
let ptr = self.status_address() as *const u32;
5559

@@ -124,6 +128,7 @@ pub struct SubscriptionEntry {
124128
}
125129

126130
impl SubscriptionEntry {
131+
/// Gets subtrees which are in use for the subscription.
127132
pub fn active_subtrees(&self) -> &[KeySubtree] {
128133
&self.subtrees[..self.subtree_count as usize]
129134
}
@@ -142,6 +147,7 @@ pub struct KeySubtree {
142147
}
143148

144149
impl KeySubtree {
150+
/// Checks if the leaf key node corresponding to `timestamp` lies within this subtree.
145151
pub fn contains(&self, timestamp: u64) -> bool {
146152
self.lowest_timestamp <= timestamp && timestamp <= self.highest_timestamp
147153
}
@@ -182,6 +188,13 @@ struct ChannelInfo {
182188
}
183189

184190
impl ChannelInfo {
191+
/// Constructs new `ChannelInfo` object by reading from flash which may or may not contain subscription data.
192+
///
193+
/// # Safety
194+
///
195+
/// `flash_data_addr` must be the address of the start of a flash page used for storing subscription entries.
196+
///
197+
/// It cannot point to code for example.
185198
unsafe fn new(flash_data_addr: usize) -> Self {
186199
let flash_entry: FlashEntry<SubscriptionEntry> = unsafe {
187200
FlashEntry::new(flash_data_addr)
@@ -217,7 +230,7 @@ pub enum DecoderContextError {
217230
TooManySubscriptions,
218231
}
219232

220-
/// Information about channel sent back to tv for list channels
233+
/// Format of information about channel sent back to tv host tools for list channels command.
221234
#[repr(C, packed)]
222235
#[derive(Debug, Clone, Copy, Default, Pod, Zeroable)]
223236
pub struct DecoderChannelInfoResult {
@@ -241,6 +254,7 @@ pub struct DecoderContext {
241254
}
242255

243256
impl DecoderContext {
257+
/// Initialize decoder state and setup all necessary peripherals.
244258
pub fn new() -> Self {
245259
let Peripherals { mut trng, mut mpu, .. } =
246260
Peripherals::take().expect("could not initialize peripherals");
@@ -347,6 +361,9 @@ impl DecoderContext {
347361
.find(|channel_info| channel_info.channel_id().is_none())
348362
}
349363

364+
/// Retreives bot nonvalatile and volatile cached information about a subscription on the given `channel_id`.
365+
///
366+
/// Returns `None` if no subscription exists for the given channel.
350367
pub fn get_subscription_for_channel(
351368
&mut self,
352369
channel_id: u32,
@@ -359,6 +376,11 @@ impl DecoderContext {
359376
Some((flash_entry.get().unwrap(), cache.as_mut().unwrap()))
360377
}
361378

379+
/// Updates subscription information using provided `subscription`.
380+
///
381+
/// If a subscription with the same channel id already exists, it is overwritten.
382+
/// If no such subscription exists, a new slot is used to store the subscription.
383+
/// If all 8 subscription slots have been taken, `update_subscription` will return an error.
362384
pub fn update_subscription(
363385
&mut self,
364386
subscription: &SubscriptionEntry,

decoder/decoder/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ pub enum DecoderError {
5050
DecoderContextError(#[from] DecoderContextError),
5151
}
5252

53+
/// Performs the list channels functionality required by host tools.
5354
fn list_channels(context: &mut DecoderContext) -> Result<(), DecoderError> {
5455
let channel_info = context.list_channels();
5556

@@ -77,7 +78,7 @@ fn main() -> ! {
7778

7879
loop {
7980
if let Ok(mut message) = Message::read() {
80-
let opcode = message.opcode;
81+
//let opcode = message.opcode;
8182
//println!("got message: {opcode:?}");
8283
let result = match message.opcode {
8384
Opcode::List => list_channels(&mut context),

decoder/decoder/src/subscribe.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::message::{Message, Opcode};
77
use crate::utils::{Cursor, CursorError};
88
use crate::{crypto::decrypt_decoder_payload, decoder_context::DecoderContext, DecoderError};
99

10+
/// Parses subscription entry from subecription data plaintext.
1011
fn read_subscription(data: &[u8]) -> Result<SubscriptionEntry, DecoderError> {
1112
let mut data_cursor = Cursor::new(data);
1213

@@ -78,6 +79,7 @@ struct SubscriptionAssociatedData {
7879
decoder_id: u32,
7980
}
8081

82+
/// Performs subscribe functionality required by host tools.
8183
pub fn subscribe(
8284
context: &mut DecoderContext,
8385
subscribe_data: &mut [u8],

0 commit comments

Comments
 (0)