@@ -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
126130impl 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
144149impl 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
184190impl 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 ) ]
223236pub struct DecoderChannelInfoResult {
@@ -241,6 +254,7 @@ pub struct DecoderContext {
241254}
242255
243256impl 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 ,
0 commit comments