| |||
| Home > The Cycle Accurate Simulation Interface > The save/restore interface CASISaveRestore > Enabling save/restore support |
For a component to support the advanced save and restore feature:
The component must be derived from CASISaveRestore:
class MyModel : public CASIModule, public CASISaveRestore {
The getProperty() function
must return yes for the CASI_PROP_SAVE_RESTORE property.
This informs the simulation environment about the save/restore capability
of the component.
The Save/Restore functionality of the component
now exists but has not been initialized. If the initialization method
is not called, it is not possible to save the component’s state.
To initialize the Save/Restore functionality, call initStream(this) from
the component’s constructor.
Two pure virtual methods inherited from CASISaveRestore must
be implemented. These methods must implement the details of saving
and restoring of the component’s state information.
Example 2.29. saveData and restoreData
// Implementation of CASISaveRestore interface to save state
bool MyModel::saveData( CASIODataStream &data )
{
// return save was successful
return true;
}
// Implementation of CASISaveRestore interface to restore state
bool MyModel::restoreData( CASIODataStream &data )
{
// return restore was successful
return true;
}
The above two methods are valid for a component that has no state information to save, but is required to support this feature so more complex systems that include the model can use Save/Restore.
It is not unusual for components to not have any state to save. For example, a Fan Out component (FOUT) that distributes a signal to several components, completes its task in one cycle and has no state that must be saved. But for more complex components, there might be a lot of information that must be remembered.