Contiki 2.5
Files | Macros | Functions
COFFEE-based persistent Storage

Files

file  storage_coffee.c
 

Macros

#define STORAGE_FILE_NAME_LENGTH   15
 How long can a filename possibly be?
 
#define STORAGE_COFFEE_FLAGS_LOCKED   0x1
 Flags for the storage.
 
#define RADIO_SAFE_STATE_ON()   NETSTACK_MAC.off(0)
 COFFEE is so slow, that we are loosing radio packets while using the flash. More...
 

Functions

void storage_coffee_prune ()
 "Internal" functions More...
 
uint16_t storage_coffee_delete_bundle (uint32_t bundle_number, uint8_t reason)
 deletes a bundle form storage More...
 
struct mmem * storage_coffee_read_bundle (uint32_t bundle_number)
 reads a bundle from storage More...
 
void storage_coffee_reconstruct_bundles ()
 Restore bundles stored in CFS.
 
void storage_coffee_init (void)
 called by agent at startup
 
void storage_coffee_reinit (void)
 Sets the storage to its initial state.
 
uint8_t storage_coffee_make_room (struct mmem *bundlemem)
 This function delete as many bundles from the storage as necessary to have at least one slot free. More...
 
uint8_t storage_coffee_save_bundle (struct mmem *bundlemem, uint32_t **bundle_number_ptr)
 saves a bundle in storage More...
 
uint16_t storage_coffee_get_free_space (struct mmem *bundlemem)
 checks if there is space for a bundle More...
 
uint16_t storage_coffee_get_bundle_numbers (void)
 Get the number of slots available in storage. More...
 
struct storage_entry_tstorage_coffee_get_bundles (void)
 Get the bundle list. More...
 
uint8_t storage_coffee_lock_bundle (uint32_t bundle_num)
 Mark a bundle as locked so that it will not be deleted even if we are running out of space. More...
 
void storage_coffee_unlock_bundle (uint32_t bundle_num)
 Mark a bundle as unlocked after being locked previously.
 

Detailed Description

Macro Definition Documentation

#define RADIO_SAFE_STATE_ON ( )    NETSTACK_MAC.off(0)

COFFEE is so slow, that we are loosing radio packets while using the flash.

Unfortunately, the radio is sending LL ACKs for these packets, so the other side does not know. Therefore, we have to disable the radio while reading or writing COFFEE, to avoid sending ACKs for packets that we cannot read out of the buffer.

FIXME: This HACK is very ugly and poor design.

Definition at line 94 of file storage_coffee.c.

Referenced by storage_coffee_delete_bundle(), storage_coffee_init(), storage_coffee_read_bundle(), storage_coffee_reconstruct_bundles(), and storage_coffee_save_bundle().

Function Documentation

uint16_t storage_coffee_delete_bundle ( uint32_t  bundle_number,
uint8_t  reason 
)

deletes a bundle form storage

Parameters
bundle_numberbundle number to be deleted
reasonreason code
Returns
1 on success or 0 on error

Definition at line 562 of file storage_coffee.c.

References bundle_decrement(), cfs_remove(), entry, list_head(), list_item_next(), list_remove(), memb_free(), MMEM_PTR, NULL, RADIO_SAFE_STATE_ON, STATUSREPORT, storage_coffee_read_bundle(), and STORAGE_FILE_NAME_LENGTH.

Referenced by storage_coffee_make_room(), storage_coffee_prune(), and storage_coffee_reinit().

uint16_t storage_coffee_get_bundle_numbers ( void  )

Get the number of slots available in storage.

Returns
the number of free slots

Definition at line 746 of file storage_coffee.c.

struct storage_entry_t* storage_coffee_get_bundles ( void  )
read

Get the bundle list.

Returns
pointer to first bundle list entry

Definition at line 754 of file storage_coffee.c.

References list_head().

uint16_t storage_coffee_get_free_space ( struct mmem *  bundlemem)

checks if there is space for a bundle

Parameters
bundlemempointer to a bundle struct (not used here)
Returns
number of free slots

Definition at line 737 of file storage_coffee.c.

References BUNDLE_STORAGE_SIZE.

uint8_t storage_coffee_lock_bundle ( uint32_t  bundle_num)

Mark a bundle as locked so that it will not be deleted even if we are running out of space.

Parameters
bundle_numBundle number
Returns
1 on success or 0 on error

Definition at line 765 of file storage_coffee.c.

References entry, list_head(), list_item_next(), NULL, and STORAGE_COFFEE_FLAGS_LOCKED.

uint8_t storage_coffee_make_room ( struct mmem *  bundlemem)

This function delete as many bundles from the storage as necessary to have at least one slot free.

Parameters
bundlememPointer to the MMEM struct containing the bundle
Returns
1 on success, 0 if no room could be made free

Definition at line 298 of file storage_coffee.c.

References BUNDLE_STORAGE_SIZE, entry, list_head(), list_item_next(), MMEM_PTR, NULL, storage_coffee_delete_bundle(), STORAGE_COFFEE_FLAGS_LOCKED, and storage_coffee_prune().

Referenced by storage_coffee_save_bundle().

void storage_coffee_prune ( )

"Internal" functions

deletes expired bundles from storage

Definition at line 251 of file storage_coffee.c.

References ctimer_restart(), entry, list_head(), list_item_next(), NULL, and storage_coffee_delete_bundle().

Referenced by storage_coffee_init(), and storage_coffee_make_room().

struct mmem * storage_coffee_read_bundle ( uint32_t  bundle_number)
read

reads a bundle from storage

Parameters
bundle_numberbundle number to read
Returns
pointer to the MMEM struct containing the bundle (caller has to free)

Definition at line 642 of file storage_coffee.c.

References bundle_create_bundle(), bundle_decrement(), cfs_close(), cfs_open(), CFS_READ, entry, list_head(), list_item_next(), MMEM_PTR, mmem_realloc(), NULL, RADIO_SAFE_STATE_ON, and STORAGE_FILE_NAME_LENGTH.

Referenced by storage_coffee_delete_bundle(), and storage_coffee_reconstruct_bundles().

uint8_t storage_coffee_save_bundle ( struct mmem *  bundlemem,
uint32_t **  bundle_number_ptr 
)

saves a bundle in storage

Parameters
bundlemempointer to the MMEM struct containing the bundle
bundle_number_ptrThe pointer to the bundle number will be stored here
Returns
1 on success, 0 otherwise

Definition at line 421 of file storage_coffee.c.

References bundle_decrement(), cfs_close(), cfs_coffee_reserve(), cfs_open(), cfs_remove(), CFS_WRITE, entry, list_add(), list_head(), list_item_next(), memb_alloc(), memb_free(), MMEM_PTR, NULL, RADIO_SAFE_STATE_ON, storage_coffee_make_room(), and STORAGE_FILE_NAME_LENGTH.